tests: rework tests on AM_PATH_PYTHON
[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 * Cygnus::                      The effect of @option{--cygnus} (deprecated, soon to be removed)
119 * Not Enough::                  When Automake is not Enough
120 * Distributing::                Distributing the Makefile.in
121 * API Versioning::              About compatibility between Automake versions
122 * Upgrading::                   Upgrading to a Newer Automake Version
123 * FAQ::                         Frequently Asked Questions
124 * Copying This Manual::         How to make copies of this manual
125 * Indices::                     Indices of variables, macros, and concepts
126
127 @detailmenu
128  --- The Detailed Node Listing ---
129
130 An Introduction to the Autotools
131
132 * GNU Build System::            Introducing the GNU Build System
133 * Use Cases::                   Use Cases for the GNU Build System
134 * Why Autotools::               How Autotools Help
135 * Hello World::                 A Small Hello World Package
136
137 Use Cases for the GNU Build System
138
139 * Basic Installation::          Common installation procedure
140 * Standard Targets::            A list of standard Makefile targets
141 * Standard Directory Variables::  A list of standard directory variables
142 * Standard Configuration Variables::  Using configuration variables
143 * config.site::                 Using a config.site file
144 * VPATH Builds::                Parallel build trees
145 * Two-Part Install::            Installing data and programs separately
146 * Cross-Compilation::           Building for other architectures
147 * Renaming::                    Renaming programs at install time
148 * DESTDIR::                     Building binary packages with DESTDIR
149 * Preparing Distributions::     Rolling out tarballs
150 * Dependency Tracking::         Automatic dependency tracking
151 * Nested Packages::             The GNU Build Systems can be nested
152
153 A Small Hello World
154
155 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
156 * amhello's configure.ac Setup Explained::
157 * amhello's Makefile.am Setup Explained::
158
159 General ideas
160
161 * General Operation::           General operation of Automake
162 * Strictness::                  Standards conformance checking
163 * Uniform::                     The Uniform Naming Scheme
164 * Length Limitations::          Staying below the command line length limit
165 * Canonicalization::            How derived variables are named
166 * User Variables::              Variables reserved for the user
167 * Auxiliary Programs::          Programs automake might require
168
169 Some example packages
170
171 * Complete::                    A simple example, start to finish
172 * true::                        Building true and false
173
174 Scanning @file{configure.ac}, using @command{aclocal}
175
176 * Requirements::                Configuration requirements
177 * Optional::                    Other things Automake recognizes
178 * aclocal Invocation::          Auto-generating aclocal.m4
179 * Macros::                      Autoconf macros supplied with Automake
180
181 Auto-generating aclocal.m4
182
183 * aclocal Options::             Options supported by aclocal
184 * Macro Search Path::           How aclocal finds .m4 files
185 * Extending aclocal::           Writing your own aclocal macros
186 * Local Macros::                Organizing local macros
187 * Serials::                     Serial lines in Autoconf macros
188 * Future of aclocal::           aclocal's scheduled death
189
190 Autoconf macros supplied with Automake
191
192 * Public Macros::               Macros that you can use.
193 * Obsolete Macros::             Macros that will soon be removed.
194 * Private Macros::              Macros that you should not use.
195
196 Directories
197
198 * Subdirectories::              Building subdirectories recursively
199 * Conditional Subdirectories::  Conditionally not building directories
200 * Alternative::                 Subdirectories without recursion
201 * Subpackages::                 Nesting packages
202
203 Conditional Subdirectories
204
205 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
206 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
207 * Subdirectories with AC_SUBST::  Another way for conditional recursion
208 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
209
210 Building Programs and Libraries
211
212 * A Program::                   Building a program
213 * A Library::                   Building a library
214 * A Shared Library::            Building a Libtool library
215 * Program and Library Variables::  Variables controlling program and
216                                 library builds
217 * Default _SOURCES::            Default source files
218 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
219 * Program Variables::           Variables used when building a program
220 * Yacc and Lex::                Yacc and Lex support
221 * C++ Support::                 Compiling C++ sources
222 * Objective C Support::         Compiling Objective C sources
223 * Objective C++ Support::       Compiling Objective C++ sources
224 * Unified Parallel C Support::  Compiling Unified Parallel C sources
225 * Assembly Support::            Compiling assembly sources
226 * Fortran 77 Support::          Compiling Fortran 77 sources
227 * Fortran 9x Support::          Compiling Fortran 9x sources
228 * Java Support with gcj::       Compiling Java sources using gcj
229 * Vala Support::                Compiling Vala sources
230 * Support for Other Languages::  Compiling other languages
231 * Dependencies::                Automatic dependency tracking
232 * EXEEXT::                      Support for executable extensions
233
234 Building a program
235
236 * Program Sources::             Defining program sources
237 * Linking::                     Linking with libraries or extra objects
238 * Conditional Sources::         Handling conditional sources
239 * Conditional Programs::        Building a program conditionally
240
241 Building a Shared Library
242
243 * Libtool Concept::             Introducing Libtool
244 * Libtool Libraries::           Declaring Libtool Libraries
245 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
246 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
247 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
248 * Libtool Modules::             Building Libtool Modules
249 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
250 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
251 * Libtool Issues::              Common Issues Related to Libtool's Use
252
253 Common Issues Related to Libtool's Use
254
255 * Error required file ltmain.sh not found::  The need to run libtoolize
256 * Objects created both with libtool and without::  Avoid a specific build race
257
258 Fortran 77 Support
259
260 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
261 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
262 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
263
264 Mixing Fortran 77 With C and C++
265
266 * How the Linker is Chosen::    Automatic linker selection
267
268 Fortran 9x Support
269
270 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
271
272 Other Derived Objects
273
274 * Scripts::                     Executable scripts
275 * Headers::                     Header files
276 * Data::                        Architecture-independent data files
277 * Sources::                     Derived sources
278
279 Built Sources
280
281 * Built Sources Example::       Several ways to handle built sources.
282
283 Other GNU Tools
284
285 * Emacs Lisp::                  Emacs Lisp
286 * gettext::                     Gettext
287 * Libtool::                     Libtool
288 * Java::                        Java bytecode compilation (deprecated)
289 * Python::                      Python
290
291 Building documentation
292
293 * Texinfo::                     Texinfo
294 * Man Pages::                   Man pages
295
296 What Gets Installed
297
298 * Basics of Installation::      What gets installed where
299 * The Two Parts of Install::    Installing data and programs separately
300 * Extending Installation::      Adding your own rules for installation
301 * Staged Installs::             Installation in a temporary location
302 * Install Rules for the User::  Useful additional rules
303
304 What Goes in a Distribution
305
306 * Basics of Distribution::      Files distributed by default
307 * Fine-grained Distribution Control::  @code{dist_} and @code{nodist_} prefixes
308 * The dist Hook::               A target for last-minute distribution changes
309 * Checking the Distribution::   @samp{make distcheck} explained
310 * The Types of Distributions::  A variety of formats and compression methods
311
312 Support for test suites
313
314 * Generalities about Testing::  Generic concepts and terminology about testing
315 * Simple Tests::                Listing test scripts in @code{TESTS}
316 * Custom Test Drivers::         Writing and using custom test drivers
317 * Using the TAP test protocol:: Integrating test scripts that use the TAP protocol
318 * DejaGnu Tests::               Interfacing with the @command{dejagnu} testing framework
319 * Install Tests::               Running tests on installed packages
320
321 Simple Tests
322
323 * Scripts-based Testsuites::    Automake-specific concepts and terminology
324 * Serial Test Harness::         Older (and obsolescent) serial test harness
325 * Parallel Test Harness::       Generic concurrent test harness
326
327 Using the TAP test protocol
328
329 * Introduction to TAP::
330 * Use TAP with the Automake test harness::
331 * Incompatibilities with other TAP parsers and drivers::
332 * Links and external resources on TAP::
333
334 Custom Test Drivers
335
336 * Overview of Custom Test Drivers Support::
337 * Declaring Custom Test Drivers::
338 * API for Custom Test Drivers::
339
340 API for Custom Test Drivers
341
342 * Command-line arguments for test drivers::
343 * Log files generation and test results recording::
344 * Testsuite progress output::
345
346 Changing Automake's Behavior
347
348 * Options generalities::        Semantics of Automake option
349 * List of Automake options::    A comprehensive list of Automake options
350
351 Miscellaneous Rules
352
353 * Tags::                        Interfacing to cscope, etags and mkid
354 * Suffixes::                    Handling new file extensions
355
356 Conditionals
357
358 * Usage of Conditionals::       Declaring conditional content
359 * Limits of Conditionals::      Enclosing complete statements
360
361 Silencing Make
362
363 * Make verbosity::               Make is verbose by default
364 * Tricks For Silencing Make::    Standard and generic ways to silence make
365 * Automake silent-rules Option:: How Automake can help in silencing make
366
367 When Automake Isn't Enough
368
369 * Extending::                   Adding new rules or overriding existing ones.
370 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
371
372 Frequently Asked Questions about Automake
373
374 * CVS::                         CVS and generated files
375 * maintainer-mode::             missing and AM_MAINTAINER_MODE
376 * Wildcards::                   Why doesn't Automake support wildcards?
377 * Limitations on File Names::   Limitations on source and installed file names
378 * Errors with distclean::       Files left in build directory after distclean
379 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
380 * Renamed Objects::             Why are object files sometimes renamed?
381 * Per-Object Flags::            How to simulate per-object flags?
382 * Multiple Outputs::            Writing rules for tools with many output files
383 * Hard-Coded Install Paths::    Installing to hard-coded locations
384 * Debugging Make Rules::        Strategies when things don't work as expected
385 * Reporting Bugs::              Feedback on bugs and feature requests
386
387 Copying This Manual
388
389 * GNU Free Documentation License::  License for copying this manual
390
391 Indices
392
393 * Macro Index::                 Index of Autoconf macros
394 * Variable Index::              Index of Makefile variables
395 * General Index::               General index
396
397 @end detailmenu
398 @end menu
399
400 @end ifnottex
401
402
403 @node Introduction
404 @chapter Introduction
405
406 Automake is a tool for automatically generating @file{Makefile.in}s
407 from files called @file{Makefile.am}.  Each @file{Makefile.am} is
408 basically a series of @command{make} variable
409 definitions@footnote{These variables are also called @dfn{make macros}
410 in Make terminology, however in this manual we reserve the term
411 @dfn{macro} for Autoconf's macros.}, with rules being thrown in
412 occasionally.  The generated @file{Makefile.in}s are compliant with
413 the GNU Makefile standards.
414
415 @cindex GNU Makefile standards
416
417 The GNU Makefile Standards Document
418 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
419 is long, complicated, and subject to change.  The goal of Automake is to
420 remove the burden of Makefile maintenance from the back of the
421 individual GNU maintainer (and put it on the back of the Automake
422 maintainers).
423
424 The typical Automake input file is simply a series of variable definitions.
425 Each such file is processed to create a @file{Makefile.in}.  There
426 should generally be one @file{Makefile.am} per directory of a project.
427
428 @cindex Constraints of Automake
429 @cindex Automake constraints
430
431 Automake does constrain a project in certain ways; for instance, it
432 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
433 autoconf, The Autoconf Manual}), and enforces certain restrictions on
434 the @file{configure.ac} contents.
435
436 @cindex Automake requirements
437 @cindex Requirements, Automake
438
439 Automake requires @command{perl} in order to generate the
440 @file{Makefile.in}s.  However, the distributions created by Automake are
441 fully GNU standards-compliant, and do not require @command{perl} in order
442 to be built.
443
444 @cindex Bugs, reporting
445 @cindex Reporting bugs
446 @cindex E-mail, bug reports
447
448 For more information on bug reports, @xref{Reporting Bugs}.
449
450 @node Autotools Introduction
451 @chapter An Introduction to the Autotools
452
453 If you are new to Automake, maybe you know that it is part of a set of
454 tools called @emph{The Autotools}.  Maybe you've already delved into a
455 package full of files named @file{configure}, @file{configure.ac},
456 @file{Makefile.in}, @file{Makefile.am}, @file{aclocal.m4}, @dots{},
457 some of them claiming to be @emph{generated by} Autoconf or Automake.
458 But the exact purpose of these files and their relations is probably
459 fuzzy.  The goal of this chapter is to introduce you to this machinery,
460 to show you how it works and how powerful it is.  If you've never
461 installed or seen such a package, do not worry: this chapter will walk
462 you through it.
463
464 If you need some teaching material, more illustrations, or a less
465 @command{automake}-centered continuation, some slides for this
466 introduction are available in Alexandre Duret-Lutz's
467 @uref{http://www.lrde.epita.fr/@/~adl/@/autotools.html,
468 Autotools Tutorial}.
469 This chapter is the written version of the first part of his tutorial.
470
471 @menu
472 * GNU Build System::            Introducing the GNU Build System
473 * Use Cases::                   Use Cases for the GNU Build System
474 * Why Autotools::               How Autotools Help
475 * Hello World::                 A Small Hello World Package
476 @end menu
477
478 @node GNU Build System
479 @section Introducing the GNU Build System
480 @cindex GNU Build System, introduction
481
482 It is a truth universally acknowledged, that as a developer in
483 possession of a new package, you must be in want of a build system.
484
485 In the Unix world, such a build system is traditionally achieved using
486 the command @command{make} (@pxref{Top, , Overview, make, The GNU Make
487 Manual}).  You express the recipe to build your package in a
488 @file{Makefile}.  This file is a set of rules to build the files in
489 the package.  For instance the program @file{prog} may be built by
490 running the linker on the files @file{main.o}, @file{foo.o}, and
491 @file{bar.o}; the file @file{main.o} may be built by running the
492 compiler on @file{main.c}; etc.  Each time @command{make} is run, it
493 reads @file{Makefile}, checks the existence and modification time of
494 the files mentioned, decides what files need to be built (or rebuilt),
495 and runs the associated commands.
496
497 When a package needs to be built on a different platform than the one
498 it was developed on, its @file{Makefile} usually needs to be adjusted.
499 For instance the compiler may have another name or require more
500 options.  In 1991, David J. MacKenzie got tired of customizing
501 @file{Makefile} for the 20 platforms he had to deal with.  Instead, he
502 handcrafted a little shell script called @file{configure} to
503 automatically adjust the @file{Makefile} (@pxref{Genesis, , Genesis,
504 autoconf, The Autoconf Manual}).  Compiling his package was now
505 as simple as running @code{./configure && make}.
506
507 @cindex GNU Coding Standards
508
509 Today this process has been standardized in the GNU project.  The GNU
510 Coding Standards (@pxref{Managing Releases, The Release Process, ,
511 standards, The GNU Coding Standards}) explains how each package of the
512 GNU project should have a @file{configure} script, and the minimal
513 interface it should have.  The @file{Makefile} too should follow some
514 established conventions.  The result?  A unified build system that
515 makes all packages almost indistinguishable by the installer.  In its
516 simplest scenario, all the installer has to do is to unpack the
517 package, run @code{./configure && make && make install}, and repeat
518 with the next package to install.
519
520 We call this build system the @dfn{GNU Build System}, since it was
521 grown out of the GNU project.  However it is used by a vast number of
522 other packages: following any existing convention has its advantages.
523
524 @cindex Autotools, introduction
525
526 The Autotools are tools that will create a GNU Build System for your
527 package.  Autoconf mostly focuses on @file{configure} and Automake on
528 @file{Makefile}s.  It is entirely possible to create a GNU Build
529 System without the help of these tools.  However it is rather
530 burdensome and error-prone.  We will discuss this again after some
531 illustration of the GNU Build System in action.
532
533 @node Use Cases
534 @section Use Cases for the GNU Build System
535 @cindex GNU Build System, use cases
536 @cindex GNU Build System, features
537 @cindex Features of the GNU Build System
538 @cindex Use Cases for the GNU Build System
539 @cindex @file{amhello-1.0.tar.gz}, location
540 @cindex @file{amhello-1.0.tar.gz}, use cases
541
542 In this section we explore several use cases for the GNU Build System.
543 You can replay all of these examples on the @file{amhello-1.0.tar.gz}
544 package distributed with Automake.  If Automake is installed on your
545 system, you should find a copy of this file in
546 @file{@var{prefix}/share/doc/automake/amhello-1.0.tar.gz}, where
547 @var{prefix} is the installation prefix specified during configuration
548 (@var{prefix} defaults to @file{/usr/local}, however if Automake was
549 installed by some GNU/Linux distribution it most likely has been set
550 to @file{/usr}).  If you do not have a copy of Automake installed,
551 you can find a copy of this file inside the @file{doc/} directory of
552 the Automake package.
553
554 Some of the following use cases present features that are in fact
555 extensions to the GNU Build System.  Read: they are not specified by
556 the GNU Coding Standards, but they are nonetheless part of the build
557 system created by the Autotools.  To keep things simple, we do not
558 point out the difference.  Our objective is to show you many of the
559 features that the build system created by the Autotools will offer to
560 you.
561
562 @menu
563 * Basic Installation::          Common installation procedure
564 * Standard Targets::            A list of standard Makefile targets
565 * Standard Directory Variables::  A list of standard directory variables
566 * Standard Configuration Variables::  Using configuration variables
567 * config.site::                 Using a config.site file
568 * VPATH Builds::                Parallel build trees
569 * Two-Part Install::            Installing data and programs separately
570 * Cross-Compilation::           Building for other architectures
571 * Renaming::                    Renaming programs at install time
572 * DESTDIR::                     Building binary packages with DESTDIR
573 * Preparing Distributions::     Rolling out tarballs
574 * Dependency Tracking::         Automatic dependency tracking
575 * Nested Packages::             The GNU Build Systems can be nested
576 @end menu
577
578 @node Basic Installation
579 @subsection Basic Installation
580 @cindex Configuration, basics
581 @cindex Installation, basics
582 @cindex GNU Build System, basics
583
584 The most common installation procedure looks as follows.
585
586 @example
587 ~ % @kbd{tar zxf amhello-1.0.tar.gz}
588 ~ % @kbd{cd amhello-1.0}
589 ~/amhello-1.0 % @kbd{./configure}
590 @dots{}
591 config.status: creating Makefile
592 config.status: creating src/Makefile
593 @dots{}
594 ~/amhello-1.0 % @kbd{make}
595 @dots{}
596 ~/amhello-1.0 % @kbd{make check}
597 @dots{}
598 ~/amhello-1.0 % @kbd{su}
599 Password:
600 /home/adl/amhello-1.0 # @kbd{make install}
601 @dots{}
602 /home/adl/amhello-1.0 # @kbd{exit}
603 ~/amhello-1.0 % @kbd{make installcheck}
604 @dots{}
605 @end example
606
607 @cindex Unpacking
608
609 The user first unpacks the package.  Here, and in the following
610 examples, we will use the non-portable @code{tar zxf} command for
611 simplicity.  On a system without GNU @command{tar} installed, this
612 command should read @code{gunzip -c amhello-1.0.tar.gz | tar xf -}.
613
614 The user then enters the newly created directory to run the
615 @file{configure} script.  This script probes the system for various
616 features, and finally creates the @file{Makefile}s.  In this toy
617 example there are only two @file{Makefile}s, but in real-world projects,
618 there may be many more, usually one @file{Makefile} per directory.
619
620 It is now possible to run @code{make}.  This will construct all the
621 programs, libraries, and scripts that need to be constructed for the
622 package.  In our example, this compiles the @file{hello} program.
623 All files are constructed in place, in the source tree; we will see
624 later how this can be changed.
625
626 @code{make check} causes the package's tests to be run.  This step is
627 not mandatory, but it is often good to make sure the programs that
628 have been built behave as they should, before you decide to install
629 them.  Our example does not contain any tests, so running @code{make
630 check} is a no-op.
631
632 @cindex su, before @code{make install}
633 After everything has been built, and maybe tested, it is time to
634 install it on the system.  That means copying the programs,
635 libraries, header files, scripts, and other data files from the
636 source directory to their final destination on the system.  The
637 command @code{make install} will do that.  However, by default
638 everything will be installed in subdirectories of @file{/usr/local}:
639 binaries will go into @file{/usr/local/bin}, libraries will end up in
640 @file{/usr/local/lib}, etc.  This destination is usually not writable
641 by any user, so we assume that we have to become root before we can
642 run @code{make install}.  In our example, running @code{make install}
643 will copy the program @file{hello} into @file{/usr/local/bin}
644 and @file{README} into @file{/usr/local/share/doc/amhello}.
645
646 A last and optional step is to run @code{make installcheck}.  This
647 command may run tests on the installed files.  @code{make check} tests
648 the files in the source tree, while @code{make installcheck} tests
649 their installed copies.  The tests run by the latter can be different
650 from those run by the former.  For instance, there are tests that
651 cannot be run in the source tree.  Conversely, some packages are set
652 up so that @code{make installcheck} will run the very same tests as
653 @code{make check}, only on different files (non-installed
654 vs.@: installed).  It can make a difference, for instance when the
655 source tree's layout is different from that of the installation.
656 Furthermore it may help to diagnose an incomplete installation.
657
658 Presently most packages do not have any @code{installcheck} tests
659 because the existence of @code{installcheck} is little known, and its
660 usefulness is neglected.  Our little toy package is no better: @code{make
661 installcheck} does nothing.
662
663 @node Standard Targets
664 @subsection Standard @file{Makefile} Targets
665
666 So far we have come across four ways to run @command{make} in the GNU
667 Build System: @code{make}, @code{make check}, @code{make install}, and
668 @code{make installcheck}.  The words @code{check}, @code{install}, and
669 @code{installcheck}, passed as arguments to @command{make}, are called
670 @dfn{targets}.  @code{make} is a shorthand for @code{make all},
671 @code{all} being the default target in the GNU Build System.
672
673 Here is a list of the most useful targets that the GNU Coding Standards
674 specify.
675
676 @table @code
677 @item make all
678 @trindex all
679 Build programs, libraries, documentation, etc.@: (same as @code{make}).
680 @item make install
681 @trindex install
682 Install what needs to be installed, copying the files from the
683 package's tree to system-wide directories.
684 @item make install-strip
685 @trindex install-strip
686 Same as @code{make install}, then strip debugging symbols.  Some
687 users like to trade space for useful bug reports@enddots{}
688 @item make uninstall
689 @trindex uninstall
690 The opposite of @code{make install}: erase the installed files.
691 (This needs to be run from the same build tree that was installed.)
692 @item make clean
693 @trindex clean
694 Erase from the build tree the files built by @code{make all}.
695 @item make distclean
696 @trindex distclean
697 Additionally erase anything @code{./configure} created.
698 @item make check
699 @trindex check
700 Run the test suite, if any.
701 @item make installcheck
702 @trindex installcheck
703 Check the installed programs or libraries, if supported.
704 @item make dist
705 @trindex dist
706 Recreate @file{@var{package}-@var{version}.tar.gz} from all the source
707 files.
708 @end table
709
710 @node Standard Directory Variables
711 @subsection Standard Directory Variables
712 @cindex directory variables
713
714 The GNU Coding Standards also specify a hierarchy of variables to
715 denote installation directories.  Some of these are:
716
717 @multitable {Directory variable} {@code{$@{datarootdir@}/doc/$@{PACKAGE@}}}
718 @headitem Directory variable    @tab Default value
719 @item @code{prefix}              @tab @code{/usr/local}
720 @item @w{@ @ @code{exec_prefix}} @tab @code{$@{prefix@}}
721 @item @w{@ @ @ @ @code{bindir}}  @tab @code{$@{exec_prefix@}/bin}
722 @item @w{@ @ @ @ @code{libdir}}  @tab @code{$@{exec_prefix@}/lib}
723 @item @w{@ @ @ @ @dots{}}
724 @item @w{@ @ @code{includedir}}  @tab @code{$@{prefix@}/include}
725 @item @w{@ @ @code{datarootdir}} @tab @code{$@{prefix@}/share}
726 @item @w{@ @ @ @ @code{datadir}} @tab @code{$@{datarootdir@}}
727 @item @w{@ @ @ @ @code{mandir}}  @tab @code{$@{datarootdir@}/man}
728 @item @w{@ @ @ @ @code{infodir}} @tab @code{$@{datarootdir@}/info}
729 @item @w{@ @ @ @ @code{docdir}}  @tab @code{$@{datarootdir@}/doc/$@{PACKAGE@}}
730 @item @w{@ @ @dots{}}
731 @end multitable
732
733 @c We should provide a complete table somewhere, but not here.  The
734 @c complete list of directory variables it too confusing as-is.  It
735 @c requires some explanations that are too complicated for this
736 @c introduction.  Besides listing directories like localstatedir
737 @c would make the explanations in ``Two-Part Install'' harder.
738
739 Each of these directories has a role which is often obvious from its
740 name.  In a package, any installable file will be installed in one of
741 these directories.  For instance in @code{amhello-1.0}, the program
742 @file{hello} is to be installed in @var{bindir}, the directory for
743 binaries.  The default value for this directory is
744 @file{/usr/local/bin}, but the user can supply a different value when
745 calling @command{configure}.  Also the file @file{README} will be
746 installed into @var{docdir}, which defaults to
747 @file{/usr/local/share/doc/amhello}.
748
749 @opindex --prefix
750
751 As a user, if you wish to install a package on your own account, you
752 could proceed as follows:
753
754 @example
755 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
756 @dots{}
757 ~/amhello-1.0 % @kbd{make}
758 @dots{}
759 ~/amhello-1.0 % @kbd{make install}
760 @dots{}
761 @end example
762
763 This would install @file{~/usr/bin/hello} and
764 @file{~/usr/share/doc/amhello/README}.
765
766 The list of all such directory options is shown by
767 @code{./configure --help}.
768
769 @node Standard Configuration Variables
770 @subsection Standard Configuration Variables
771 @cindex configuration variables, overriding
772
773 The GNU Coding Standards also define a set of standard configuration
774 variables used during the build.  Here are some:
775
776 @table @asis
777 @item @code{CC}
778 C compiler command
779 @item @code{CFLAGS}
780 C compiler flags
781 @item @code{CXX}
782 C++ compiler command
783 @item @code{CXXFLAGS}
784 C++ compiler flags
785 @item @code{LDFLAGS}
786 linker flags
787 @item @code{CPPFLAGS}
788 C/C++ preprocessor flags
789 @item @dots{}
790 @end table
791
792 @command{configure} usually does a good job at setting appropriate
793 values for these variables, but there are cases where you may want to
794 override them.  For instance you may have several versions of a
795 compiler installed and would like to use another one, you may have
796 header files installed outside the default search path of the
797 compiler, or even libraries out of the way of the linker.
798
799 Here is how one would call @command{configure} to force it to use
800 @command{gcc-3} as C compiler, use header files from
801 @file{~/usr/include} when compiling, and libraries from
802 @file{~/usr/lib} when linking.
803
804 @example
805 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
806 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
807 @end example
808
809 Again, a full list of these variables appears in the output of
810 @code{./configure --help}.
811
812 @node config.site
813 @subsection Overriding Default Configuration Setting with @file{config.site}
814 @cindex @file{config.site} example
815
816 When installing several packages using the same setup, it can be
817 convenient to create a file to capture common settings.
818 If a file named @file{@var{prefix}/share/config.site} exists,
819 @command{configure} will source it at the beginning of its execution.
820
821 Recall the command from the previous section:
822
823 @example
824 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
825 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
826 @end example
827
828 Assuming we are installing many package in @file{~/usr}, and will
829 always want to use these definitions of @code{CC}, @code{CPPFLAGS}, and
830 @code{LDFLAGS}, we can automate this by creating the following
831 @file{~/usr/share/config.site} file:
832
833 @example
834 test -z "$CC" && CC=gcc-3
835 test -z "$CPPFLAGS" && CPPFLAGS=-I$HOME/usr/include
836 test -z "$LDFLAGS" && LDFLAGS=-L$HOME/usr/lib
837 @end example
838
839 Now, any time a @file{configure} script is using the @file{~/usr}
840 prefix, it will execute the above @file{config.site} and define
841 these three variables.
842
843 @example
844 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
845 configure: loading site script /home/adl/usr/share/config.site
846 @dots{}
847 @end example
848
849 @xref{Site Defaults, , Setting Site Defaults, autoconf, The Autoconf
850 Manual}, for more information about this feature.
851
852
853 @node VPATH Builds
854 @subsection Parallel Build Trees (a.k.a.@: VPATH Builds)
855 @cindex Parallel build trees
856 @cindex VPATH builds
857 @cindex source tree and build tree
858 @cindex build tree and source tree
859 @cindex trees, source vs.@: build
860
861 The GNU Build System distinguishes two trees: the source tree, and
862 the build tree.
863
864 The source tree is rooted in the directory containing
865 @file{configure}.  It contains all the sources files (those that are
866 distributed), and may be arranged using several subdirectories.
867
868 The build tree is rooted in the directory in which @file{configure}
869 was run, and is populated with all object files, programs, libraries,
870 and other derived files built from the sources (and hence not
871 distributed).  The build tree usually has the same subdirectory layout
872 as the source tree; its subdirectories are created automatically by
873 the build system.
874
875 If @file{configure} is executed in its own directory, the source and
876 build trees are combined: derived files are constructed in the same
877 directories as their sources.  This was the case in our first
878 installation example (@pxref{Basic Installation}).
879
880 A common request from users is that they want to confine all derived
881 files to a single directory, to keep their source directories
882 uncluttered.  Here is how we could run @file{configure} to build
883 everything in a subdirectory called @file{build/}.
884
885 @example
886 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
887 ~ % @kbd{cd amhello-1.0}
888 ~/amhello-1.0 % @kbd{mkdir build && cd build}
889 ~/amhello-1.0/build % @kbd{../configure}
890 @dots{}
891 ~/amhello-1.0/build % @kbd{make}
892 @dots{}
893 @end example
894
895 These setups, where source and build trees are different, are often
896 called @dfn{parallel builds} or @dfn{VPATH builds}.  The expression
897 @emph{parallel build} is misleading: the word @emph{parallel} is a
898 reference to the way the build tree shadows the source tree, it is not
899 about some concurrency in the way build commands are run.  For this
900 reason we refer to such setups using the name @emph{VPATH builds} in
901 the following.  @emph{VPATH} is the name of the @command{make} feature
902 used by the @file{Makefile}s to allow these builds (@pxref{General
903 Search, , @code{VPATH} Search Path for All Prerequisites, make, The
904 GNU Make Manual}).
905
906 @cindex multiple configurations, example
907 @cindex debug build, example
908 @cindex optimized build, example
909
910 VPATH builds have other interesting uses.  One is to build the same
911 sources with multiple configurations.  For instance:
912
913 @c Keep in sync with amhello-cflags.sh
914 @example
915 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
916 ~ % @kbd{cd amhello-1.0}
917 ~/amhello-1.0 % @kbd{mkdir debug optim && cd debug}
918 ~/amhello-1.0/debug % @kbd{../configure CFLAGS='-g -O0'}
919 @dots{}
920 ~/amhello-1.0/debug % @kbd{make}
921 @dots{}
922 ~/amhello-1.0/debug % cd ../optim
923 ~/amhello-1.0/optim % @kbd{../configure CFLAGS='-O3 -fomit-frame-pointer'}
924 @dots{}
925 ~/amhello-1.0/optim % @kbd{make}
926 @dots{}
927 @end example
928
929 With network file systems, a similar approach can be used to build the
930 same sources on different machines.  For instance, suppose that the
931 sources are installed on a directory shared by two hosts: @code{HOST1}
932 and @code{HOST2}, which may be different platforms.
933
934 @example
935 ~ % @kbd{cd /nfs/src}
936 /nfs/src % @kbd{tar zxf ~/amhello-1.0.tar.gz}
937 @end example
938
939 On the first host, you could create a local build directory:
940 @example
941 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
942 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
943 ...
944 [HOST1] /tmp/amh % @kbd{make && sudo make install}
945 ...
946 @end example
947
948 @noindent
949 (Here we assume that the installer has configured @command{sudo} so it
950 can execute @code{make install} with root privileges; it is more convenient
951 than using @command{su} like in @ref{Basic Installation}).
952
953 On the second host, you would do exactly the same, possibly at
954 the same time:
955 @example
956 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
957 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
958 ...
959 [HOST2] /tmp/amh % @kbd{make && sudo make install}
960 ...
961 @end example
962
963 @cindex read-only source tree
964 @cindex source tree, read-only
965
966 In this scenario, nothing forbids the @file{/nfs/src/amhello-1.0}
967 directory from being read-only.  In fact VPATH builds are also a means
968 of building packages from a read-only medium such as a CD-ROM.  (The
969 FSF used to sell CD-ROM with unpacked source code, before the GNU
970 project grew so big.)
971
972 @node Two-Part Install
973 @subsection Two-Part Installation
974
975 In our last example (@pxref{VPATH Builds}), a source tree was shared
976 by two hosts, but compilation and installation were done separately on
977 each host.
978
979 The GNU Build System also supports networked setups where part of the
980 installed files should be shared amongst multiple hosts.  It does so
981 by distinguishing architecture-dependent files from
982 architecture-independent files, and providing two @file{Makefile}
983 targets to install each of these classes of files.
984
985 @trindex install-exec
986 @trindex install-data
987
988 These targets are @code{install-exec} for architecture-dependent files
989 and @code{install-data} for architecture-independent files.
990 The command we used up to now, @code{make install}, can be thought of
991 as a shorthand for @code{make install-exec install-data}.
992
993 From the GNU Build System point of view, the distinction between
994 architecture-dependent files and architecture-independent files is
995 based exclusively on the directory variable used to specify their
996 installation destination.  In the list of directory variables we
997 provided earlier (@pxref{Standard Directory Variables}), all the
998 variables based on @var{exec-prefix} designate architecture-dependent
999 directories whose files will be installed by @code{make install-exec}.
1000 The others designate architecture-independent directories and will
1001 serve files installed by @code{make install-data}.  @xref{The Two Parts
1002 of Install}, for more details.
1003
1004 Here is how we could revisit our two-host installation example,
1005 assuming that (1) we want to install the package directly in
1006 @file{/usr}, and (2) the directory @file{/usr/share} is shared by the
1007 two hosts.
1008
1009 On the first host we would run
1010 @example
1011 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1012 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1013 ...
1014 [HOST1] /tmp/amh % @kbd{make && sudo make install}
1015 ...
1016 @end example
1017
1018 On the second host, however, we need only install the
1019 architecture-specific files.
1020 @example
1021 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1022 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1023 ...
1024 [HOST2] /tmp/amh % @kbd{make && sudo make install-exec}
1025 ...
1026 @end example
1027
1028 In packages that have installation checks, it would make sense to run
1029 @code{make installcheck} (@pxref{Basic Installation}) to verify that
1030 the package works correctly despite the apparent partial installation.
1031
1032 @node Cross-Compilation
1033 @subsection Cross-Compilation
1034 @cindex cross-compilation
1035
1036 To @dfn{cross-compile} is to build on one platform a binary that will
1037 run on another platform.  When speaking of cross-compilation, it is
1038 important to distinguish between the @dfn{build platform} on which
1039 the compilation is performed, and the @dfn{host platform} on which the
1040 resulting executable is expected to run.  The following
1041 @command{configure} options are used to specify each of them:
1042
1043 @table @option
1044 @item --build=@var{build}
1045 @opindex --build=@var{build}
1046 The system on which the package is built.
1047 @item --host=@var{host}
1048 @opindex --host=@var{host}
1049 The system where built programs and libraries will run.
1050 @end table
1051
1052 When the @option{--host} is used, @command{configure} will search for
1053 the cross-compiling suite for this platform.  Cross-compilation tools
1054 commonly have their target architecture as prefix of their name.  For
1055 instance my cross-compiler for MinGW32 has its binaries called
1056 @code{i586-mingw32msvc-gcc}, @code{i586-mingw32msvc-ld},
1057 @code{i586-mingw32msvc-as}, etc.
1058
1059 @cindex MinGW cross-compilation example
1060 @cindex cross-compilation example
1061
1062 Here is how we could build @code{amhello-1.0} for
1063 @code{i586-mingw32msvc} on a GNU/Linux PC.
1064
1065 @c Keep in sync with amhello-cross-compile.sh
1066 @smallexample
1067 ~/amhello-1.0 % @kbd{./configure --build i686-pc-linux-gnu --host i586-mingw32msvc}
1068 checking for a BSD-compatible install... /usr/bin/install -c
1069 checking whether build environment is sane... yes
1070 checking for gawk... gawk
1071 checking whether make sets $(MAKE)... yes
1072 checking for i586-mingw32msvc-strip... i586-mingw32msvc-strip
1073 checking for i586-mingw32msvc-gcc... i586-mingw32msvc-gcc
1074 checking for C compiler default output file name... a.exe
1075 checking whether the C compiler works... yes
1076 checking whether we are cross compiling... yes
1077 checking for suffix of executables... .exe
1078 checking for suffix of object files... o
1079 checking whether we are using the GNU C compiler... yes
1080 checking whether i586-mingw32msvc-gcc accepts -g... yes
1081 checking for i586-mingw32msvc-gcc option to accept ANSI C...
1082 @dots{}
1083 ~/amhello-1.0 % @kbd{make}
1084 @dots{}
1085 ~/amhello-1.0 % @kbd{cd src; file hello.exe}
1086 hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable
1087 @end smallexample
1088
1089 The @option{--host} and @option{--build} options are usually all we
1090 need for cross-compiling.  The only exception is if the package being
1091 built is itself a cross-compiler: we need a third option to specify
1092 its target architecture.
1093
1094 @table @option
1095 @item --target=@var{target}
1096 @opindex --target=@var{target}
1097 When building compiler tools: the system for which the tools will
1098 create output.
1099 @end table
1100
1101 For instance when installing GCC, the GNU Compiler Collection, we can
1102 use @option{--target=@/@var{target}} to specify that we want to build
1103 GCC as a cross-compiler for @var{target}.  Mixing @option{--build} and
1104 @option{--target}, we can actually cross-compile a cross-compiler;
1105 such a three-way cross-compilation is known as a @dfn{Canadian cross}.
1106
1107 @xref{Specifying Names, , Specifying the System Type, autoconf, The
1108 Autoconf Manual}, for more information about these @command{configure}
1109 options.
1110
1111 @node Renaming
1112 @subsection Renaming Programs at Install Time
1113 @cindex Renaming programs
1114 @cindex Transforming program names
1115 @cindex Programs, renaming during installation
1116
1117 The GNU Build System provides means to automatically rename
1118 executables and manpages before they are installed (@pxref{Man Pages}).
1119 This is especially convenient
1120 when installing a GNU package on a system that already has a
1121 proprietary implementation you do not want to overwrite.  For instance,
1122 you may want to install GNU @command{tar} as @command{gtar} so you can
1123 distinguish it from your vendor's @command{tar}.
1124
1125 This can be done using one of these three @command{configure} options.
1126
1127 @table @option
1128 @item --program-prefix=@var{prefix}
1129 @opindex --program-prefix=@var{prefix}
1130 Prepend @var{prefix} to installed program names.
1131 @item --program-suffix=@var{suffix}
1132 @opindex --program-suffix=@var{suffix}
1133 Append @var{suffix} to installed program names.
1134 @item --program-transform-name=@var{program}
1135 @opindex --program-transform-name=@var{program}
1136 Run @code{sed @var{program}} on installed program names.
1137 @end table
1138
1139 The following commands would install @file{hello}
1140 as @file{/usr/local/bin/test-hello}, for instance.
1141
1142 @example
1143 ~/amhello-1.0 % @kbd{./configure --program-prefix test-}
1144 @dots{}
1145 ~/amhello-1.0 % @kbd{make}
1146 @dots{}
1147 ~/amhello-1.0 % @kbd{sudo make install}
1148 @dots{}
1149 @end example
1150
1151 @node DESTDIR
1152 @subsection Building Binary Packages Using DESTDIR
1153 @vindex DESTDIR
1154
1155 The GNU Build System's @code{make install} and @code{make uninstall}
1156 interface does not exactly fit the needs of a system administrator
1157 who has to deploy and upgrade packages on lots of hosts.  In other
1158 words, the GNU Build System does not replace a package manager.
1159
1160 Such package managers usually need to know which files have been
1161 installed by a package, so a mere @code{make install} is
1162 inappropriate.
1163
1164 @cindex Staged installation
1165
1166 The @code{DESTDIR} variable can be used to perform a staged
1167 installation.  The package should be configured as if it was going to
1168 be installed in its final location (e.g., @code{--prefix /usr}), but
1169 when running @code{make install}, the @code{DESTDIR} should be set to
1170 the absolute name of a directory into which the installation will be
1171 diverted.  From this directory it is easy to review which files are
1172 being installed where, and finally copy them to their final location
1173 by some means.
1174
1175 @cindex Binary package
1176
1177 For instance here is how we could create a binary package containing a
1178 snapshot of all the files to be installed.
1179
1180 @c Keep in sync with amhello-binpkg.sh
1181 @example
1182 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1183 @dots{}
1184 ~/amhello-1.0 % @kbd{make}
1185 @dots{}
1186 ~/amhello-1.0 % @kbd{make DESTDIR=$HOME/inst install}
1187 @dots{}
1188 ~/amhello-1.0 % @kbd{cd ~/inst}
1189 ~/inst % @kbd{find . -type f -print > ../files.lst}
1190 ~/inst % @kbd{tar zcvf ~/amhello-1.0-i686.tar.gz `cat ../files.lst`}
1191 ./usr/bin/hello
1192 ./usr/share/doc/amhello/README
1193 @end example
1194
1195 After this example, @code{amhello-1.0-i686.tar.gz} is ready to be
1196 uncompressed in @file{/} on many hosts.  (Using @code{`cat ../files.lst`}
1197 instead of @samp{.} as argument for @command{tar} avoids entries for
1198 each subdirectory in the archive: we would not like @command{tar} to
1199 restore the modification time of @file{/}, @file{/usr/}, etc.)
1200
1201 Note that when building packages for several architectures, it might
1202 be convenient to use @code{make install-data} and @code{make
1203 install-exec} (@pxref{Two-Part Install}) to gather
1204 architecture-independent files in a single package.
1205
1206 @xref{Install}, for more information.
1207
1208 @c We should document PRE_INSTALL/POST_INSTALL/NORMAL_INSTALL and their
1209 @c UNINSTALL counterparts.
1210
1211 @node Preparing Distributions
1212 @subsection Preparing Distributions
1213 @cindex Preparing distributions
1214 @cindex Packages, preparation
1215 @cindex Distributions, preparation
1216
1217 We have already mentioned @code{make dist}.  This target collects all
1218 your source files and the necessary parts of the build system to
1219 create a tarball named @file{@var{package}-@var{version}.tar.gz}.
1220
1221 @cindex @code{distcheck} better than @code{dist}
1222
1223 Another, more useful command is @code{make distcheck}.  The
1224 @code{distcheck} target constructs
1225 @file{@var{package}-@var{version}.tar.gz} just as well as @code{dist},
1226 but it additionally ensures most of the use cases presented so far
1227 work:
1228
1229 @itemize @bullet
1230 @item
1231 It attempts a full compilation of the package (@pxref{Basic
1232 Installation}), unpacking the newly constructed tarball, running
1233 @code{make}, @code{make check}, @code{make install}, as well as
1234 @code{make installcheck}, and even @code{make dist},
1235 @item
1236 it tests VPATH builds with read-only source tree (@pxref{VPATH Builds}),
1237 @item
1238 it makes sure @code{make clean}, @code{make distclean}, and @code{make
1239 uninstall} do not omit any file (@pxref{Standard Targets}),
1240 @item
1241 and it checks that @code{DESTDIR} installations work (@pxref{DESTDIR}).
1242 @end itemize
1243
1244 All of these actions are performed in a temporary subdirectory, so
1245 that no root privileges are required.
1246
1247 Releasing a package that fails @code{make distcheck} means that one of
1248 the scenarios we presented will not work and some users will be
1249 disappointed.  Therefore it is a good practice to release a package
1250 only after a successful @code{make distcheck}.  This of course does
1251 not imply that the package will be flawless, but at least it will
1252 prevent some of the embarrassing errors you may find in packages
1253 released by people who have never heard about @code{distcheck} (like
1254 @code{DESTDIR} not working because of a typo, or a distributed file
1255 being erased by @code{make clean}, or even @code{VPATH} builds not
1256 working).
1257
1258 @xref{Creating amhello}, to recreate @file{amhello-1.0.tar.gz} using
1259 @code{make distcheck}.  @xref{Checking the Distribution}, for more
1260 information about @code{distcheck}.
1261
1262 @node Dependency Tracking
1263 @subsection Automatic Dependency Tracking
1264 @cindex Dependency tracking
1265
1266 Dependency tracking is performed as a side-effect of compilation.
1267 Each time the build system compiles a source file, it computes its
1268 list of dependencies (in C these are the header files included by the
1269 source being compiled).  Later, any time @command{make} is run and a
1270 dependency appears to have changed, the dependent files will be
1271 rebuilt.
1272
1273 Automake generates code for automatic dependency tracking by default,
1274 unless the developer chooses to override it; for more information,
1275 @pxref{Dependencies}.
1276
1277 When @command{configure} is executed, you can see it probing each
1278 compiler for the dependency mechanism it supports (several mechanisms
1279 can be used):
1280
1281 @example
1282 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1283 @dots{}
1284 checking dependency style of gcc... gcc3
1285 @dots{}
1286 @end example
1287
1288 Because dependencies are only computed as a side-effect of the
1289 compilation, no dependency information exists the first time a package
1290 is built.  This is OK because all the files need to be built anyway:
1291 @code{make} does not have to decide which files need to be rebuilt.
1292 In fact, dependency tracking is completely useless for one-time builds
1293 and there is a @command{configure} option to disable this:
1294
1295 @table @option
1296 @item --disable-dependency-tracking
1297 @opindex --disable-dependency-tracking
1298 Speed up one-time builds.
1299 @end table
1300
1301 Some compilers do not offer any practical way to derive the list of
1302 dependencies as a side-effect of the compilation, requiring a separate
1303 run (maybe of another tool) to compute these dependencies.  The
1304 performance penalty implied by these methods is important enough to
1305 disable them by default.  The option @option{--enable-dependency-tracking}
1306 must be passed to @command{configure} to activate them.
1307
1308 @table @option
1309 @item --enable-dependency-tracking
1310 @opindex --enable-dependency-tracking
1311 Do not reject slow dependency extractors.
1312 @end table
1313
1314 @xref{Dependency Tracking Evolution, , Dependency Tracking Evolution,
1315 automake-history, Brief History of Automake}, for some discussion about
1316 the different dependency tracking schemes used by Automake over the years.
1317
1318 @node Nested Packages
1319 @subsection Nested Packages
1320 @cindex Nested packages
1321 @cindex Packages, nested
1322 @cindex Subpackages
1323
1324 Although nesting packages isn't something we would recommend to
1325 someone who is discovering the Autotools, it is a nice feature worthy
1326 of mention in this small advertising tour.
1327
1328 Autoconfiscated packages (that means packages whose build system have
1329 been created by Autoconf and friends) can be nested to arbitrary
1330 depth.
1331
1332 A typical setup is that package A will distribute one of the libraries
1333 it needs in a subdirectory.  This library B is a complete package with
1334 its own GNU Build System.  The @command{configure} script of A will
1335 run the @command{configure} script of B as part of its execution,
1336 building and installing A will also build and install B.  Generating a
1337 distribution for A will also include B.
1338
1339 It is possible to gather several packages like this.  GCC is a heavy
1340 user of this feature.  This gives installers a single package to
1341 configure, build and install, while it allows developers to work on
1342 subpackages independently.
1343
1344 When configuring nested packages, the @command{configure} options
1345 given to the top-level @command{configure} are passed recursively to
1346 nested @command{configure}s.  A package that does not understand an
1347 option will ignore it, assuming it is meaningful to some other
1348 package.
1349
1350 @opindex --help=recursive
1351
1352 The command @code{configure --help=recursive} can be used to display
1353 the options supported by all the included packages.
1354
1355 @xref{Subpackages}, for an example setup.
1356
1357 @node Why Autotools
1358 @section How Autotools Help
1359 @cindex Autotools, purpose
1360
1361 There are several reasons why you may not want to implement the GNU
1362 Build System yourself (read: write a @file{configure} script and
1363 @file{Makefile}s yourself).
1364
1365 @itemize @bullet
1366 @item
1367 As we have seen, the GNU Build System has a lot of
1368 features (@pxref{Use Cases}).
1369 Some users may expect features you have not implemented because
1370 you did not need them.
1371 @item
1372 Implementing these features portably is difficult and exhausting.
1373 Think of writing portable shell scripts, and portable
1374 @file{Makefile}s, for systems you may not have handy.  @xref{Portable
1375 Shell, , Portable Shell Programming, autoconf, The Autoconf Manual}, to
1376 convince yourself.
1377 @item
1378 You will have to upgrade your setup to follow changes to the GNU
1379 Coding Standards.
1380 @end itemize
1381
1382 The GNU Autotools take all this burden off your back and provide:
1383
1384 @itemize @bullet
1385 @item
1386 Tools to create a portable, complete, and self-contained GNU Build
1387 System, from simple instructions.
1388 @emph{Self-contained} meaning the resulting build system does not
1389 require the GNU Autotools.
1390 @item
1391 A central place where fixes and improvements are made:
1392 a bug-fix for a portability issue will benefit every package.
1393 @end itemize
1394
1395 Yet there also exist reasons why you may want NOT to use the
1396 Autotools@enddots{} For instance you may be already using (or used to)
1397 another incompatible build system.  Autotools will only be useful if
1398 you do accept the concepts of the GNU Build System.  People who have their
1399 own idea of how a build system should work will feel frustrated by the
1400 Autotools.
1401
1402 @node Hello World
1403 @section A Small Hello World
1404 @cindex Example Hello World
1405 @cindex Hello World example
1406 @cindex @file{amhello-1.0.tar.gz}, creation
1407
1408 In this section we recreate the @file{amhello-1.0} package from
1409 scratch.  The first subsection shows how to call the Autotools to
1410 instantiate the GNU Build System, while the second explains the
1411 meaning of the @file{configure.ac} and @file{Makefile.am} files read
1412 by the Autotools.
1413
1414 @anchor{amhello Explained}
1415 @menu
1416 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
1417 * amhello's configure.ac Setup Explained::
1418 * amhello's Makefile.am Setup Explained::
1419 @end menu
1420
1421 @node Creating amhello
1422 @subsection Creating @file{amhello-1.0.tar.gz}
1423
1424 Here is how we can recreate @file{amhello-1.0.tar.gz} from scratch.
1425 The package is simple enough so that we will only need to write 5
1426 files.  (You may copy them from the final @file{amhello-1.0.tar.gz}
1427 that is distributed with Automake if you do not want to write them.)
1428
1429 Create the following files in an empty directory.
1430
1431 @itemize @bullet
1432
1433 @item
1434 @file{src/main.c} is the source file for the @file{hello} program.  We
1435 store it in the @file{src/} subdirectory, because later, when the package
1436 evolves, it will ease the addition of a @file{man/} directory for man
1437 pages, a @file{data/} directory for data files, etc.
1438 @example
1439 ~/amhello % @kbd{cat src/main.c}
1440 #include <config.h>
1441 #include <stdio.h>
1442
1443 int
1444 main (void)
1445 @{
1446   puts ("Hello World!");
1447   puts ("This is " PACKAGE_STRING ".");
1448   return 0;
1449 @}
1450 @end example
1451
1452 @item
1453 @file{README} contains some very limited documentation for our little
1454 package.
1455 @example
1456 ~/amhello % @kbd{cat README}
1457 This is a demonstration package for GNU Automake.
1458 Type 'info Automake' to read the Automake manual.
1459 @end example
1460
1461 @item
1462 @file{Makefile.am} and @file{src/Makefile.am} contain Automake
1463 instructions for these two directories.
1464
1465 @example
1466 ~/amhello % @kbd{cat src/Makefile.am}
1467 bin_PROGRAMS = hello
1468 hello_SOURCES = main.c
1469 ~/amhello % @kbd{cat Makefile.am}
1470 SUBDIRS = src
1471 dist_doc_DATA = README
1472 @end example
1473
1474 @item
1475 Finally, @file{configure.ac} contains Autoconf instructions to
1476 create the @command{configure} script.
1477
1478 @example
1479 ~/amhello % @kbd{cat configure.ac}
1480 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1481 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1482 AC_PROG_CC
1483 AC_CONFIG_HEADERS([config.h])
1484 AC_CONFIG_FILES([
1485  Makefile
1486  src/Makefile
1487 ])
1488 AC_OUTPUT
1489 @end example
1490 @end itemize
1491
1492 @cindex @command{autoreconf}, example
1493
1494 Once you have these five files, it is time to run the Autotools to
1495 instantiate the build system.  Do this using the @command{autoreconf}
1496 command as follows:
1497
1498 @example
1499 ~/amhello % @kbd{autoreconf --install}
1500 configure.ac: installing './install-sh'
1501 configure.ac: installing './missing'
1502 src/Makefile.am: installing './depcomp'
1503 @end example
1504
1505 At this point the build system is complete.
1506
1507 In addition to the three scripts mentioned in its output, you can see
1508 that @command{autoreconf} created four other files: @file{configure},
1509 @file{config.h.in}, @file{Makefile.in}, and @file{src/Makefile.in}.
1510 The latter three files are templates that will be adapted to the
1511 system by @command{configure} under the names @file{config.h},
1512 @file{Makefile}, and @file{src/Makefile}.  Let's do this:
1513
1514 @example
1515 ~/amhello % @kbd{./configure}
1516 checking for a BSD-compatible install... /usr/bin/install -c
1517 checking whether build environment is sane... yes
1518 checking for gawk... no
1519 checking for mawk... mawk
1520 checking whether make sets $(MAKE)... yes
1521 checking for gcc... gcc
1522 checking for C compiler default output file name... a.out
1523 checking whether the C compiler works... yes
1524 checking whether we are cross compiling... no
1525 checking for suffix of executables...
1526 checking for suffix of object files... o
1527 checking whether we are using the GNU C compiler... yes
1528 checking whether gcc accepts -g... yes
1529 checking for gcc option to accept ISO C89... none needed
1530 checking for style of include used by make... GNU
1531 checking dependency style of gcc... gcc3
1532 configure: creating ./config.status
1533 config.status: creating Makefile
1534 config.status: creating src/Makefile
1535 config.status: creating config.h
1536 config.status: executing depfiles commands
1537 @end example
1538
1539 @trindex distcheck
1540 @cindex @code{distcheck} example
1541
1542 You can see @file{Makefile}, @file{src/Makefile}, and @file{config.h}
1543 being created at the end after @command{configure} has probed the
1544 system.  It is now possible to run all the targets we wish
1545 (@pxref{Standard Targets}).  For instance:
1546
1547 @example
1548 ~/amhello % @kbd{make}
1549 @dots{}
1550 ~/amhello % @kbd{src/hello}
1551 Hello World!
1552 This is amhello 1.0.
1553 ~/amhello % @kbd{make distcheck}
1554 @dots{}
1555 =============================================
1556 amhello-1.0 archives ready for distribution:
1557 amhello-1.0.tar.gz
1558 =============================================
1559 @end example
1560
1561 Note that running @command{autoreconf} is only needed initially when
1562 the GNU Build System does not exist.  When you later change some
1563 instructions in a @file{Makefile.am} or @file{configure.ac}, the
1564 relevant part of the build system will be regenerated automatically
1565 when you execute @command{make}.
1566
1567 @command{autoreconf} is a script that calls @command{autoconf},
1568 @command{automake}, and a bunch of other commands in the right order.
1569 If you are beginning with these tools, it is not important to figure
1570 out in which order all of these tools should be invoked and why.  However,
1571 because Autoconf and Automake have separate manuals, the important
1572 point to understand is that @command{autoconf} is in charge of
1573 creating @file{configure} from @file{configure.ac}, while
1574 @command{automake} is in charge of creating @file{Makefile.in}s from
1575 @file{Makefile.am}s and @file{configure.ac}.  This should at least
1576 direct you to the right manual when seeking answers.
1577
1578
1579 @node amhello's configure.ac Setup Explained
1580 @subsection @code{amhello}'s @file{configure.ac} Setup Explained
1581
1582 @cindex @file{configure.ac}, Hello World
1583
1584 Let us begin with the contents of @file{configure.ac}.
1585
1586 @example
1587 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1588 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1589 AC_PROG_CC
1590 AC_CONFIG_HEADERS([config.h])
1591 AC_CONFIG_FILES([
1592  Makefile
1593  src/Makefile
1594 ])
1595 AC_OUTPUT
1596 @end example
1597
1598 This file is read by both @command{autoconf} (to create
1599 @file{configure}) and @command{automake} (to create the various
1600 @file{Makefile.in}s).  It contains a series of M4 macros that will be
1601 expanded as shell code to finally form the @file{configure} script.
1602 We will not elaborate on the syntax of this file, because the Autoconf
1603 manual has a whole section about it (@pxref{Writing Autoconf Input, ,
1604 Writing @file{configure.ac}, autoconf, The Autoconf Manual}).
1605
1606 The macros prefixed with @code{AC_} are Autoconf macros, documented
1607 in the Autoconf manual (@pxref{Autoconf Macro Index, , Autoconf Macro
1608 Index, autoconf, The Autoconf Manual}).  The macros that start with
1609 @code{AM_} are Automake macros, documented later in this manual
1610 (@pxref{Macro Index}).
1611
1612 The first two lines of @file{configure.ac} initialize Autoconf and
1613 Automake.  @code{AC_INIT} takes in as parameters the name of the package,
1614 its version number, and a contact address for bug-reports about the
1615 package (this address is output at the end of @code{./configure
1616 --help}, for instance).  When adapting this setup to your own package,
1617 by all means please do not blindly copy Automake's address: use the
1618 mailing list of your package, or your own mail address.
1619
1620 @opindex -Wall
1621 @opindex -Werror
1622 @opindex foreign
1623
1624 The argument to @code{AM_INIT_AUTOMAKE} is a list of options for
1625 @command{automake} (@pxref{Options}).  @option{-Wall} and
1626 @option{-Werror} ask @command{automake} to turn on all warnings and
1627 report them as errors.  We are speaking of @strong{Automake} warnings
1628 here, such as dubious instructions in @file{Makefile.am}.  This has
1629 absolutely nothing to do with how the compiler will be called, even
1630 though it may support options with similar names.  Using @option{-Wall
1631 -Werror} is a safe setting when starting to work on a package: you do
1632 not want to miss any issues.  Later you may decide to relax things a
1633 bit.  The @option{foreign} option tells Automake that this package
1634 will not follow the GNU Standards.  GNU packages should always
1635 distribute additional files such as @file{ChangeLog}, @file{AUTHORS},
1636 etc.  We do not want @command{automake} to complain about these
1637 missing files in our small example.
1638
1639 The @code{AC_PROG_CC} line causes the @command{configure} script to
1640 search for a C compiler and define the variable @code{CC} with its
1641 name.  The @file{src/Makefile.in} file generated by Automake uses the
1642 variable @code{CC} to build @file{hello}, so when @command{configure}
1643 creates @file{src/Makefile} from @file{src/Makefile.in}, it will define
1644 @code{CC} with the value it has found.  If Automake is asked to create
1645 a @file{Makefile.in} that uses @code{CC} but @file{configure.ac} does
1646 not define it, it will suggest you add a call to @code{AC_PROG_CC}.
1647
1648 The @code{AC_CONFIG_HEADERS([config.h])} invocation causes the
1649 @command{configure} script to create a @file{config.h} file gathering
1650 @samp{#define}s defined by other macros in @file{configure.ac}.  In our
1651 case, the @code{AC_INIT} macro already defined a few of them.  Here
1652 is an excerpt of @file{config.h} after @command{configure} has run:
1653
1654 @smallexample
1655 @dots{}
1656 /* Define to the address where bug reports for this package should be sent. */
1657 #define PACKAGE_BUGREPORT "@value{PACKAGE_BUGREPORT}"
1658
1659 /* Define to the full name and version of this package. */
1660 #define PACKAGE_STRING "amhello 1.0"
1661 @dots{}
1662 @end smallexample
1663
1664 As you probably noticed, @file{src/main.c} includes @file{config.h} so
1665 it can use @code{PACKAGE_STRING}.  In a real-world project,
1666 @file{config.h} can grow really big, with one @samp{#define} per
1667 feature probed on the system.
1668
1669 The @code{AC_CONFIG_FILES} macro declares the list of files that
1670 @command{configure} should create from their @file{*.in} templates.
1671 Automake also scans this list to find the @file{Makefile.am} files it must
1672 process.  (This is important to remember: when adding a new directory
1673 to your project, you should add its @file{Makefile} to this list,
1674 otherwise Automake will never process the new @file{Makefile.am} you
1675 wrote in that directory.)
1676
1677 Finally, the @code{AC_OUTPUT} line is a closing command that actually
1678 produces the part of the script in charge of creating the files
1679 registered with @code{AC_CONFIG_HEADERS} and @code{AC_CONFIG_FILES}.
1680
1681 @cindex @command{autoscan}
1682
1683 When starting a new project, we suggest you start with such a simple
1684 @file{configure.ac}, and gradually add the other tests it requires.
1685 The command @command{autoscan} can also suggest a few of the tests
1686 your package may need (@pxref{autoscan Invocation, , Using
1687 @command{autoscan} to Create @file{configure.ac}, autoconf, The
1688 Autoconf Manual}).
1689
1690
1691 @node amhello's Makefile.am Setup Explained
1692 @subsection @code{amhello}'s @file{Makefile.am} Setup Explained
1693
1694 @cindex @file{Makefile.am}, Hello World
1695
1696 We now turn to @file{src/Makefile.am}.  This file contains
1697 Automake instructions to build and install @file{hello}.
1698
1699 @example
1700 bin_PROGRAMS = hello
1701 hello_SOURCES = main.c
1702 @end example
1703
1704 A @file{Makefile.am} has the same syntax as an ordinary
1705 @file{Makefile}.  When @command{automake} processes a
1706 @file{Makefile.am} it copies the entire file into the output
1707 @file{Makefile.in} (that will be later turned into @file{Makefile} by
1708 @command{configure}) but will react to certain variable definitions
1709 by generating some build rules and other variables.
1710 Often @file{Makefile.am}s contain only a list of variable definitions as
1711 above, but they can also contain other variable and rule definitions that
1712 @command{automake} will pass along without interpretation.
1713
1714 Variables that end with @code{_PROGRAMS} are special variables
1715 that list programs that the resulting @file{Makefile} should build.
1716 In Automake speak, this @code{_PROGRAMS} suffix is called a
1717 @dfn{primary}; Automake recognizes other primaries such as
1718 @code{_SCRIPTS}, @code{_DATA}, @code{_LIBRARIES}, etc.@: corresponding
1719 to different types of files.
1720
1721 The @samp{bin} part of the @code{bin_PROGRAMS} tells
1722 @command{automake} that the resulting programs should be installed in
1723 @var{bindir}.  Recall that the GNU Build System uses a set of variables
1724 to denote destination directories and allow users to customize these
1725 locations (@pxref{Standard Directory Variables}).  Any such directory
1726 variable can be put in front of a primary (omitting the @code{dir}
1727 suffix) to tell @command{automake} where to install the listed files.
1728
1729 Programs need to be built from source files, so for each program
1730 @code{@var{prog}} listed in a @code{@w{_PROGRAMS}} variable,
1731 @command{automake} will look for another variable named
1732 @code{@var{prog}_SOURCES} listing its source files.  There may be more
1733 than one source file: they will all be compiled and linked together.
1734
1735 Automake also knows that source files need to be distributed when
1736 creating a tarball (unlike built programs).  So a side-effect of this
1737 @code{hello_SOURCES} declaration is that @file{main.c} will be
1738 part of the tarball created by @code{make dist}.
1739
1740 Finally here are some explanations regarding the top-level
1741 @file{Makefile.am}.
1742
1743 @example
1744 SUBDIRS = src
1745 dist_doc_DATA = README
1746 @end example
1747
1748 @code{SUBDIRS} is a special variable listing all directories that
1749 @command{make} should recurse into before processing the current
1750 directory.  So this line is responsible for @command{make} building
1751 @file{src/hello} even though we run it from the top-level.  This line
1752 also causes @code{make install} to install @file{src/hello} before
1753 installing @file{README} (not that this order matters).
1754
1755 The line @code{dist_doc_DATA = README} causes @file{README} to be
1756 distributed and installed in @var{docdir}.  Files listed with the
1757 @code{_DATA} primary are not automatically part of the tarball built
1758 with @code{make dist}, so we add the @code{dist_} prefix so they get
1759 distributed.  However, for @file{README} it would not have been
1760 necessary: @command{automake} automatically distributes any
1761 @file{README} file it encounters (the list of other files
1762 automatically distributed is presented by @code{automake --help}).
1763 The only important effect of this second line is therefore to install
1764 @file{README} during @code{make install}.
1765
1766 One thing not covered in this example is accessing the installation
1767 directory values (@pxref{Standard Directory Variables}) from your
1768 program code, that is, converting them into defined macros.  For this,
1769 @pxref{Defining Directories,,, autoconf, The Autoconf Manual}.
1770
1771
1772 @node Generalities
1773 @chapter General ideas
1774
1775 The following sections cover a few basic ideas that will help you
1776 understand how Automake works.
1777
1778 @menu
1779 * General Operation::           General operation of Automake
1780 * Strictness::                  Standards conformance checking
1781 * Uniform::                     The Uniform Naming Scheme
1782 * Length Limitations::          Staying below the command line length limit
1783 * Canonicalization::            How derived variables are named
1784 * User Variables::              Variables reserved for the user
1785 * Auxiliary Programs::          Programs automake might require
1786 @end menu
1787
1788
1789 @node General Operation
1790 @section General Operation
1791
1792 Automake works by reading a @file{Makefile.am} and generating a
1793 @file{Makefile.in}.  Certain variables and rules defined in the
1794 @file{Makefile.am} instruct Automake to generate more specialized code;
1795 for instance, a @code{bin_PROGRAMS} variable definition will cause rules
1796 for compiling and linking programs to be generated.
1797
1798 @cindex Non-standard targets
1799 @cindex @code{git-dist}, non-standard example
1800 @trindex git-dist
1801
1802 The variable definitions and rules in the @file{Makefile.am} are
1803 copied mostly verbatim into the generated file, with all variable
1804 definitions preceding all rules.  This allows you to add almost
1805 arbitrary code into the generated @file{Makefile.in}.  For instance,
1806 the Automake distribution includes a non-standard rule for the
1807 @code{git-dist} target, which the Automake maintainer uses to make
1808 distributions from the source control system.
1809
1810 @cindex GNU make extensions
1811
1812 Note that most GNU make extensions are not recognized by Automake.  Using
1813 such extensions in a @file{Makefile.am} will lead to errors or confusing
1814 behavior.
1815
1816 @cindex Append operator
1817 @cmindex +=
1818 A special exception is that the GNU make append operator, @samp{+=}, is
1819 supported.  This operator appends its right hand argument to the variable
1820 specified on the left.  Automake will translate the operator into
1821 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
1822
1823 Automake tries to keep comments grouped with any adjoining rules or
1824 variable definitions.
1825
1826 @cindex Limitations of automake parser
1827 @cindex Automake parser, limitations of
1828 @cindex indentation in Makefile.am
1829 Generally, Automake is not particularly smart in the parsing of unusual
1830 Makefile constructs, so you're advised to avoid fancy constructs or
1831 ``creative'' use of whitespaces.
1832 @c Keep this in sync with doc-parsing-buglets-tabs.sh
1833 For example, @key{TAB} characters cannot be used between a target name
1834 and the following ``@code{:}'' character, and variable assignments
1835 shouldn't be indented with @key{TAB} characters.
1836 @c Keep this in sync with doc-parsing-buglets-colneq-subst.sh
1837 Also, using more complex macro in target names can cause trouble:
1838
1839 @example
1840 % @kbd{cat Makefile.am}
1841 $(FOO:=x): bar
1842 % @kbd{automake}
1843 Makefile.am:1: bad characters in variable name '$(FOO'
1844 Makefile.am:1: ':='-style assignments are not portable
1845 @end example
1846
1847 @cindex Make targets, overriding
1848 @cindex Make rules, overriding
1849 @cindex Overriding make rules
1850 @cindex Overriding make targets
1851
1852 A rule defined in @file{Makefile.am} generally overrides any such
1853 rule of a similar name that would be automatically generated by
1854 @command{automake}.  Although this is a supported feature, it is generally
1855 best to avoid making use of it, as sometimes the generated rules are
1856 very particular.
1857
1858 @cindex Variables, overriding
1859 @cindex Overriding make variables
1860
1861 Similarly, a variable defined in @file{Makefile.am} or
1862 @code{AC_SUBST}ed from @file{configure.ac} will override any
1863 definition of the variable that @command{automake} would ordinarily
1864 create.  This feature is more often useful than the ability to
1865 override a rule.  Be warned that many of the variables generated by
1866 @command{automake} are considered to be for internal use only, and their
1867 names might change in future releases.
1868
1869 @cindex Recursive operation of Automake
1870 @cindex Automake, recursive operation
1871 @cindex Example of recursive operation
1872
1873 When examining a variable definition, Automake will recursively examine
1874 variables referenced in the definition.  For example, if Automake is
1875 looking at the content of @code{foo_SOURCES} in this snippet
1876
1877 @c Keep in sync with interp.sh
1878 @example
1879 xs = a.c b.c
1880 foo_SOURCES = c.c $(xs)
1881 @end example
1882
1883 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
1884 contents of @code{foo_SOURCES}.
1885
1886 @cindex @code{##} (special Automake comment)
1887 @cindex Special Automake comment
1888 @cindex Comment, special to Automake
1889
1890 Automake also allows a form of comment that is @emph{not} copied into
1891 the output; all lines beginning with @samp{##} (leading spaces allowed)
1892 are completely ignored by Automake.
1893
1894 It is customary to make the first line of @file{Makefile.am} read:
1895
1896 @cindex Makefile.am, first line
1897 @cindex First line of Makefile.am
1898
1899 @example
1900 ## Process this file with automake to produce Makefile.in
1901 @end example
1902
1903 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
1904 @c I don't know quite what to say.
1905
1906 @c FIXME document customary ordering of Makefile.am here!
1907
1908
1909 @node Strictness
1910 @section Strictness
1911
1912 @cindex Non-GNU packages
1913
1914 While Automake is intended to be used by maintainers of GNU packages, it
1915 does make some effort to accommodate those who wish to use it, but do
1916 not want to use all the GNU conventions.
1917
1918 @cindex Strictness, defined
1919 @cindex Strictness, @option{foreign}
1920 @cindex @option{foreign} strictness
1921 @cindex Strictness, @option{gnu}
1922 @cindex @option{gnu} strictness
1923 @cindex Strictness, @option{gnits}
1924 @cindex @option{gnits} strictness
1925
1926 To this end, Automake supports three levels of @dfn{strictness}---the
1927 strictness indicating how stringently Automake should check standards
1928 conformance.
1929
1930 The valid strictness levels are:
1931
1932 @table @option
1933 @item foreign
1934 Automake will check for only those things that are absolutely
1935 required for proper operations.  For instance, whereas GNU standards
1936 dictate the existence of a @file{NEWS} file, it will not be required in
1937 this mode.  This strictness will also turn off some warnings by default
1938 (among them, portability warnings).
1939 The name comes from the fact that Automake is intended to be
1940 used for GNU programs; these relaxed rules are not the standard mode of
1941 operation.
1942
1943 @item gnu
1944 Automake will check---as much as possible---for compliance to the GNU
1945 standards for packages.  This is the default.
1946
1947 @item gnits
1948 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
1949 standards}.  These are based on the GNU standards, but are even more
1950 detailed.  Unless you are a Gnits standards contributor, it is
1951 recommended that you avoid this option until such time as the Gnits
1952 standard is actually published (which may never happen).
1953 @end table
1954
1955 @xref{Gnits}, for more information on the precise implications of the
1956 strictness level.
1957
1958 Automake also has a special (and @emph{today deprecated}) ``cygnus'' mode
1959 that is similar to strictness but handled differently.  This mode is
1960 useful for packages that are put into a ``Cygnus'' style tree (e.g., older
1961 versions of the GCC and gdb trees).  @xref{Cygnus}, for more information
1962 on this mode.  Please note that this mode @emph{is deprecated and will be
1963 removed in the next major Automake release (1.13)}; you must avoid its use
1964 in new packages, and should stop using it in existing packages as well.
1965
1966
1967 @node Uniform
1968 @section The Uniform Naming Scheme
1969
1970 @cindex Uniform naming scheme
1971
1972 Automake variables generally follow a @dfn{uniform naming scheme} that
1973 makes it easy to decide how programs (and other derived objects) are
1974 built, and how they are installed.  This scheme also supports
1975 @command{configure} time determination of what should be built.
1976
1977 @cindex @code{_PROGRAMS} primary variable
1978 @cindex @code{PROGRAMS} primary variable
1979 @cindex Primary variable, @code{PROGRAMS}
1980 @cindex Primary variable, defined
1981 @vindex _PROGRAMS
1982
1983 At @command{make} time, certain variables are used to determine which
1984 objects are to be built.  The variable names are made of several pieces
1985 that are concatenated together.
1986
1987 The piece that tells @command{automake} what is being built is commonly called
1988 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
1989 list of programs that are to be compiled and linked.
1990 @vindex PROGRAMS
1991
1992 @cindex @code{pkgdatadir}, defined
1993 @cindex @code{pkgincludedir}, defined
1994 @cindex @code{pkglibdir}, defined
1995 @cindex @code{pkglibexecdir}, defined
1996
1997 @vindex pkgdatadir
1998 @vindex pkgincludedir
1999 @vindex pkglibdir
2000 @vindex pkglibexecdir
2001
2002 @cindex @code{PACKAGE}, directory
2003 A different set of names is used to decide where the built objects
2004 should be installed.  These names are prefixes to the primary, and they
2005 indicate which standard directory should be used as the installation
2006 directory.  The standard directory names are given in the GNU standards
2007 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
2008 Automake extends this list with @code{pkgdatadir}, @code{pkgincludedir},
2009 @code{pkglibdir}, and @code{pkglibexecdir}; these are the same as the
2010 non-@samp{pkg} versions, but with @samp{$(PACKAGE)} appended.  For instance,
2011 @code{pkglibdir} is defined as @samp{$(libdir)/$(PACKAGE)}.
2012
2013 @cindex @code{EXTRA_}, prepending
2014 For each primary, there is one additional variable named by prepending
2015 @samp{EXTRA_} to the primary name.  This variable is used to list
2016 objects that may or may not be built, depending on what
2017 @command{configure} decides.  This variable is required because Automake
2018 must statically know the entire list of objects that may be built in
2019 order to generate a @file{Makefile.in} that will work in all cases.
2020
2021 @cindex @code{EXTRA_PROGRAMS}, defined
2022 @cindex Example, @code{EXTRA_PROGRAMS}
2023 @cindex @command{cpio} example
2024
2025 For instance, @command{cpio} decides at configure time which programs
2026 should be built.  Some of the programs are installed in @code{bindir},
2027 and some are installed in @code{sbindir}:
2028
2029 @example
2030 EXTRA_PROGRAMS = mt rmt
2031 bin_PROGRAMS = cpio pax
2032 sbin_PROGRAMS = $(MORE_PROGRAMS)
2033 @end example
2034
2035 Defining a primary without a prefix as a variable, e.g.,
2036 @samp{PROGRAMS}, is an error.
2037
2038 Note that the common @samp{dir} suffix is left off when constructing the
2039 variable names; thus one writes @samp{bin_PROGRAMS} and not
2040 @samp{bindir_PROGRAMS}.
2041
2042 Not every sort of object can be installed in every directory.  Automake
2043 will flag those attempts it finds in error (but see below how to override
2044 the check if you really need to).
2045 Automake will also diagnose obvious misspellings in directory names.
2046
2047 @cindex Extending list of installation directories
2048 @cindex Installation directories, extending list
2049
2050 Sometimes the standard directories---even as augmented by
2051 Automake---are not enough.  In particular it is sometimes useful, for
2052 clarity, to install objects in a subdirectory of some predefined
2053 directory.  To this end, Automake allows you to extend the list of
2054 possible installation directories.  A given prefix (e.g., @samp{zar})
2055 is valid if a variable of the same name with @samp{dir} appended is
2056 defined (e.g., @samp{zardir}).
2057
2058 For instance, the following snippet will install @file{file.xml} into
2059 @samp{$(datadir)/xml}.
2060
2061 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2062 @example
2063 xmldir = $(datadir)/xml
2064 xml_DATA = file.xml
2065 @end example
2066
2067 This feature can also be used to override the sanity checks Automake
2068 performs to diagnose suspicious directory/primary couples (in the
2069 unlikely case these checks are undesirable, and you really know what
2070 you're doing).  For example, Automake would error out on this input:
2071
2072 @c Should be tested in primary-prefix-invalid-couples.sh
2073 @example
2074 # Forbidden directory combinations, automake will error out on this.
2075 pkglib_PROGRAMS = foo
2076 doc_LIBRARIES = libquux.a
2077 @end example
2078
2079 @noindent
2080 but it will succeed with this:
2081
2082 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2083 @example
2084 # Work around forbidden directory combinations.  Do not use this
2085 # without a very good reason!
2086 my_execbindir = $(pkglibdir)
2087 my_doclibdir = $(docdir)
2088 my_execbin_PROGRAMS = foo
2089 my_doclib_LIBRARIES = libquux.a
2090 @end example
2091
2092 The @samp{exec} substring of the @samp{my_execbindir} variable lets
2093 the files be installed at the right time (@pxref{The Two Parts of
2094 Install}).
2095
2096 @cindex @samp{noinst_} primary prefix, definition
2097 @vindex noinst_
2098
2099 The special prefix @samp{noinst_} indicates that the objects in question
2100 should be built but not installed at all.  This is usually used for
2101 objects required to build the rest of your package, for instance static
2102 libraries (@pxref{A Library}), or helper scripts.
2103
2104 @cindex @samp{check_} primary prefix, definition
2105 @vindex check_
2106
2107 The special prefix @samp{check_} indicates that the objects in question
2108 should not be built until the @samp{make check} command is run.  Those
2109 objects are not installed either.
2110
2111 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
2112 @samp{LTLIBRARIES}, @samp{LISP}, @samp{PYTHON}, @samp{JAVA},
2113 @samp{SCRIPTS}, @samp{DATA}, @samp{HEADERS}, @samp{MANS}, and
2114 @samp{TEXINFOS}.
2115 @vindex PROGRAMS
2116 @vindex LIBRARIES
2117 @vindex LTLIBRARIES
2118 @vindex LISP
2119 @vindex PYTHON
2120 @vindex JAVA
2121 @vindex SCRIPTS
2122 @vindex DATA
2123 @vindex HEADERS
2124 @vindex MANS
2125 @vindex TEXINFOS
2126
2127 Some primaries also allow additional prefixes that control other
2128 aspects of @command{automake}'s behavior.  The currently defined prefixes
2129 are @samp{dist_}, @samp{nodist_}, @samp{nobase_}, and @samp{notrans_}.
2130 These prefixes are explained later (@pxref{Program and Library Variables})
2131 (@pxref{Man Pages}).
2132
2133
2134 @node Length Limitations
2135 @section Staying below the command line length limit
2136
2137 @cindex command line length limit
2138 @cindex ARG_MAX
2139
2140 Traditionally, most unix-like systems have a length limitation for the
2141 command line arguments and environment contents when creating new
2142 processes (see for example
2143 @uref{http://www.in-ulm.de/@/~mascheck/@/various/@/argmax/} for an
2144 overview on this issue),
2145 which of course also applies to commands spawned by @command{make}.
2146 POSIX requires this limit to be at least 4096 bytes, and most modern
2147 systems have quite high limits (or are unlimited).
2148
2149 In order to create portable Makefiles that do not trip over these
2150 limits, it is necessary to keep the length of file lists bounded.
2151 Unfortunately, it is not possible to do so fully transparently within
2152 Automake, so your help may be needed.  Typically, you can split long
2153 file lists manually and use different installation directory names for
2154 each list.  For example,
2155
2156 @example
2157 data_DATA = file1 @dots{} file@var{N} file@var{N+1} @dots{} file@var{2N}
2158 @end example
2159
2160 @noindent
2161 may also be written as
2162
2163 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2164 @example
2165 data_DATA = file1 @dots{} file@var{N}
2166 data2dir = $(datadir)
2167 data2_DATA = file@var{N+1} @dots{} file@var{2N}
2168 @end example
2169
2170 @noindent
2171 and will cause Automake to treat the two lists separately during
2172 @code{make install}.  See @ref{The Two Parts of Install} for choosing
2173 directory names that will keep the ordering of the two parts of
2174 installation Note that @code{make dist} may still only work on a host
2175 with a higher length limit in this example.
2176
2177 Automake itself employs a couple of strategies to avoid long command
2178 lines.  For example, when @samp{$@{srcdir@}/} is prepended to file
2179 names, as can happen with above @code{$(data_DATA)} lists, it limits
2180 the amount of arguments passed to external commands.
2181
2182 Unfortunately, some system's @command{make} commands may prepend
2183 @code{VPATH} prefixes like @samp{$@{srcdir@}/} to file names from the
2184 source tree automatically (@pxref{Automatic Rule Rewriting, , Automatic
2185 Rule Rewriting, autoconf, The Autoconf Manual}).  In this case, the user
2186 may have to switch to use GNU Make, or refrain from using VPATH builds,
2187 in order to stay below the length limit.
2188
2189 For libraries and programs built from many sources, convenience archives
2190 may be used as intermediates in order to limit the object list length
2191 (@pxref{Libtool Convenience Libraries}).
2192
2193
2194 @node Canonicalization
2195 @section How derived variables are named
2196
2197 @cindex canonicalizing Automake variables
2198
2199 Sometimes a Makefile variable name is derived from some text the
2200 maintainer supplies.  For instance, a program name listed in
2201 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
2202 variable.  In cases like this, Automake canonicalizes the text, so that
2203 program names and the like do not have to follow Makefile variable naming
2204 rules.  All characters in the name except for letters, numbers, the
2205 strudel (@@), and the underscore are turned into underscores when making
2206 variable references.
2207
2208 For example, if your program is named @file{sniff-glue}, the derived
2209 variable name would be @samp{sniff_glue_SOURCES}, not
2210 @samp{sniff-glue_SOURCES}.  Similarly the sources for a library named
2211 @file{libmumble++.a} should be listed in the
2212 @samp{libmumble___a_SOURCES} variable.
2213
2214 The strudel is an addition, to make the use of Autoconf substitutions in
2215 variable names less obfuscating.
2216
2217
2218 @node User Variables
2219 @section Variables reserved for the user
2220
2221 @cindex variables, reserved for the user
2222 @cindex user variables
2223
2224 Some @file{Makefile} variables are reserved by the GNU Coding Standards
2225 for the use of the ``user''---the person building the package.  For
2226 instance, @code{CFLAGS} is one such variable.
2227
2228 Sometimes package developers are tempted to set user variables such as
2229 @code{CFLAGS} because it appears to make their job easier.  However,
2230 the package itself should never set a user variable, particularly not
2231 to include switches that are required for proper compilation of the
2232 package.  Since these variables are documented as being for the
2233 package builder, that person rightfully expects to be able to override
2234 any of these variables at build time.
2235
2236 To get around this problem, Automake introduces an automake-specific
2237 shadow variable for each user flag variable.  (Shadow variables are
2238 not introduced for variables like @code{CC}, where they would make no
2239 sense.)  The shadow variable is named by prepending @samp{AM_} to the
2240 user variable's name.  For instance, the shadow variable for
2241 @code{YFLAGS} is @code{AM_YFLAGS}.  The package maintainer---that is,
2242 the author(s) of the @file{Makefile.am} and @file{configure.ac}
2243 files---may adjust these shadow variables however necessary.
2244
2245 @xref{Flag Variables Ordering}, for more discussion about these
2246 variables and how they interact with per-target variables.
2247
2248 @node Auxiliary Programs
2249 @section Programs automake might require
2250
2251 @cindex Programs, auxiliary
2252 @cindex Auxiliary programs
2253
2254 Automake sometimes requires helper programs so that the generated
2255 @file{Makefile} can do its work properly.  There are a fairly large
2256 number of them, and we list them here.
2257
2258 Although all of these files are distributed and installed with
2259 Automake, a couple of them are maintained separately.  The Automake
2260 copies are updated before each release, but we mention the original
2261 source in case you need more recent versions.
2262
2263 @table @code
2264 @item ar-lib
2265 This is a wrapper primarily for the Microsoft lib archiver, to make
2266 it more POSIX-like.
2267
2268 @item compile
2269 This is a wrapper for compilers that do not accept options @option{-c}
2270 and @option{-o} at the same time.  It is only used when absolutely
2271 required.  Such compilers are rare, with the Microsoft C/C++ Compiler
2272 as the most notable exception. This wrapper also makes the following
2273 common options available for that compiler, while performing file name
2274 translation where needed: @option{-I}, @option{-L}, @option{-l},
2275 @option{-Wl,} and @option{-Xlinker}.
2276
2277 @item config.guess
2278 @itemx config.sub
2279 These two programs compute the canonical triplets for the given build,
2280 host, or target architecture.  These programs are updated regularly to
2281 support new architectures and fix probes broken by changes in new
2282 kernel versions.  Each new release of Automake comes with up-to-date
2283 copies of these programs.  If your copy of Automake is getting old,
2284 you are encouraged to fetch the latest versions of these files from
2285 @url{http://savannah.gnu.org/git/?group=config} before making a
2286 release.
2287
2288 @item depcomp
2289 This program understands how to run a compiler so that it will
2290 generate not only the desired output but also dependency information
2291 that is then used by the automatic dependency tracking feature
2292 (@pxref{Dependencies}).
2293
2294 @item elisp-comp
2295 This program is used to byte-compile Emacs Lisp code.
2296
2297 @item install-sh
2298 This is a replacement for the @command{install} program that works on
2299 platforms where @command{install} is unavailable or unusable.
2300
2301 @item mdate-sh
2302 This script is used to generate a @file{version.texi} file.  It examines
2303 a file and prints some date information about it.
2304
2305 @item missing
2306 This wraps a number of programs that are typically only required by
2307 maintainers.  If the program in question doesn't exist,
2308 @command{missing} prints an informative warning and attempts to fix
2309 things so that the build can continue.
2310
2311 @item mkinstalldirs
2312 This script used to be a wrapper around @samp{mkdir -p}, which is not
2313 portable.  Now we prefer to use @samp{install-sh -d} when @command{configure}
2314 finds that @samp{mkdir -p} does not work, this makes one less script to
2315 distribute.
2316
2317 For backward compatibility @file{mkinstalldirs} is still used and
2318 distributed when @command{automake} finds it in a package.  But it is no
2319 longer installed automatically, and it should be safe to remove it.
2320
2321 @item py-compile
2322 This is used to byte-compile Python scripts.
2323
2324 @item test-driver
2325 This implements the default test driver offered by the parallel
2326 testsuite harness.
2327
2328 @item texinfo.tex
2329 Not a program, this file is required for @samp{make dvi}, @samp{make
2330 ps} and @samp{make pdf} to work when Texinfo sources are in the
2331 package.  The latest version can be downloaded from
2332 @url{http://www.gnu.org/software/texinfo/}.
2333
2334 @item ylwrap
2335 This program wraps @command{lex} and @command{yacc} to rename their
2336 output files.  It also ensures that, for instance, multiple
2337 @command{yacc} instances can be invoked in a single directory in
2338 parallel.
2339
2340 @end table
2341
2342
2343 @node Examples
2344 @chapter Some example packages
2345
2346 This section contains two small examples.
2347
2348 The first example (@pxref{Complete}) assumes you have an existing
2349 project already using Autoconf, with handcrafted @file{Makefile}s, and
2350 that you want to convert it to using Automake.  If you are discovering
2351 both tools, it is probably better that you look at the Hello World
2352 example presented earlier (@pxref{Hello World}).
2353
2354 The second example (@pxref{true}) shows how two programs can be built
2355 from the same file, using different compilation parameters.  It
2356 contains some technical digressions that are probably best skipped on
2357 first read.
2358
2359 @menu
2360 * Complete::                    A simple example, start to finish
2361 * true::                        Building true and false
2362 @end menu
2363
2364
2365 @node Complete
2366 @section A simple example, start to finish
2367
2368 @cindex Complete example
2369
2370 Let's suppose you just finished writing @code{zardoz}, a program to make
2371 your head float from vortex to vortex.  You've been using Autoconf to
2372 provide a portability framework, but your @file{Makefile.in}s have been
2373 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
2374
2375 @cindex @code{AM_INIT_AUTOMAKE}, example use
2376
2377 The first step is to update your @file{configure.ac} to include the
2378 commands that @command{automake} needs.  The way to do this is to add an
2379 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
2380
2381 @example
2382 AC_INIT([zardoz], [1.0])
2383 AM_INIT_AUTOMAKE
2384 @dots{}
2385 @end example
2386
2387 Since your program doesn't have any complicating factors (e.g., it
2388 doesn't use @code{gettext}, it doesn't want to build a shared library),
2389 you're done with this part.  That was easy!
2390
2391 @cindex @command{aclocal} program, introduction
2392 @cindex @file{aclocal.m4}, preexisting
2393 @cindex @file{acinclude.m4}, defined
2394
2395 Now you must regenerate @file{configure}.  But to do that, you'll need
2396 to tell @command{autoconf} how to find the new macro you've used.  The
2397 easiest way to do this is to use the @command{aclocal} program to
2398 generate your @file{aclocal.m4} for you.  But wait@dots{} maybe you
2399 already have an @file{aclocal.m4}, because you had to write some hairy
2400 macros for your program.  The @command{aclocal} program lets you put
2401 your own macros into @file{acinclude.m4}, so simply rename and then
2402 run:
2403
2404 @example
2405 mv aclocal.m4 acinclude.m4
2406 aclocal
2407 autoconf
2408 @end example
2409
2410 @cindex @command{zardoz} example
2411
2412 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
2413 Since @code{zardoz} is a user program, you want to install it where the
2414 rest of the user programs go: @code{bindir}.  Additionally,
2415 @code{zardoz} has some Texinfo documentation.  Your @file{configure.ac}
2416 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
2417 @samp{$(LIBOBJS)}.  So here's what you'd write:
2418
2419 @example
2420 bin_PROGRAMS = zardoz
2421 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
2422 zardoz_LDADD = $(LIBOBJS)
2423
2424 info_TEXINFOS = zardoz.texi
2425 @end example
2426
2427 Now you can run @samp{automake --add-missing} to generate your
2428 @file{Makefile.in} and grab any auxiliary files you might need, and
2429 you're done!
2430
2431
2432 @node true
2433 @section Building true and false
2434
2435 @cindex Example, @command{false} and @command{true}
2436 @cindex @command{false} Example
2437 @cindex @command{true} Example
2438
2439 Here is another, trickier example.  It shows how to generate two
2440 programs (@code{true} and @code{false}) from the same source file
2441 (@file{true.c}).  The difficult part is that each compilation of
2442 @file{true.c} requires different @code{cpp} flags.
2443
2444 @example
2445 bin_PROGRAMS = true false
2446 false_SOURCES =
2447 false_LDADD = false.o
2448
2449 true.o: true.c
2450         $(COMPILE) -DEXIT_CODE=0 -c true.c
2451
2452 false.o: true.c
2453         $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
2454 @end example
2455
2456 Note that there is no @code{true_SOURCES} definition.  Automake will
2457 implicitly assume that there is a source file named @file{true.c}
2458 (@pxref{Default _SOURCES}), and
2459 define rules to compile @file{true.o} and link @file{true}.  The
2460 @samp{true.o: true.c} rule supplied by the above @file{Makefile.am},
2461 will override the Automake generated rule to build @file{true.o}.
2462
2463 @code{false_SOURCES} is defined to be empty---that way no implicit value
2464 is substituted.  Because we have not listed the source of
2465 @file{false}, we have to tell Automake how to link the program.  This is
2466 the purpose of the @code{false_LDADD} line.  A @code{false_DEPENDENCIES}
2467 variable, holding the dependencies of the @file{false} target will be
2468 automatically generated by Automake from the content of
2469 @code{false_LDADD}.
2470
2471 The above rules won't work if your compiler doesn't accept both
2472 @option{-c} and @option{-o}.  The simplest fix for this is to introduce a
2473 bogus dependency (to avoid problems with a parallel @command{make}):
2474
2475 @example
2476 true.o: true.c false.o
2477         $(COMPILE) -DEXIT_CODE=0 -c true.c
2478
2479 false.o: true.c
2480         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
2481 @end example
2482
2483 As it turns out, there is also a much easier way to do this same task.
2484 Some of the above technique is useful enough that we've kept the
2485 example in the manual.  However if you were to build @code{true} and
2486 @code{false} in real life, you would probably use per-program
2487 compilation flags, like so:
2488
2489 @c Keep in sync with specflg7.sh and specflg8.sh
2490 @example
2491 bin_PROGRAMS = false true
2492
2493 false_SOURCES = true.c
2494 false_CPPFLAGS = -DEXIT_CODE=1
2495
2496 true_SOURCES = true.c
2497 true_CPPFLAGS = -DEXIT_CODE=0
2498 @end example
2499
2500 In this case Automake will cause @file{true.c} to be compiled twice,
2501 with different flags.  In this instance, the names of the object files
2502 would be chosen by automake; they would be @file{false-true.o} and
2503 @file{true-true.o}. (The name of the object files rarely matters.)
2504
2505 @node automake Invocation
2506 @chapter Creating a @file{Makefile.in}
2507 @c This node used to be named "Invoking automake".  This @anchor
2508 @c allows old links to still work.
2509 @anchor{Invoking automake}
2510
2511 @cindex Multiple @file{configure.ac} files
2512 @cindex Invoking @command{automake}
2513 @cindex @command{automake}, invoking
2514 @cindex Invocation of @command{automake}
2515 @cindex @command{automake}, invocation
2516
2517 To create all the @file{Makefile.in}s for a package, run the
2518 @command{automake} program in the top level directory, with no
2519 arguments.  @command{automake} will automatically find each
2520 appropriate @file{Makefile.am} (by scanning @file{configure.ac};
2521 @pxref{configure}) and generate the corresponding @file{Makefile.in}.
2522 Note that @command{automake} has a rather simplistic view of what
2523 constitutes a package; it assumes that a package has only one
2524 @file{configure.ac}, at the top.  If your package has multiple
2525 @file{configure.ac}s, then you must run @command{automake} in each
2526 directory holding a @file{configure.ac}.  (Alternatively, you may rely
2527 on Autoconf's @command{autoreconf}, which is able to recurse your
2528 package tree and run @command{automake} where appropriate.)
2529
2530 You can optionally give @command{automake} an argument; @file{.am} is
2531 appended to the argument and the result is used as the name of the
2532 input file.  This feature is generally only used to automatically
2533 rebuild an out-of-date @file{Makefile.in}.  Note that
2534 @command{automake} must always be run from the topmost directory of a
2535 project, even if being used to regenerate the @file{Makefile.in} in
2536 some subdirectory.  This is necessary because @command{automake} must
2537 scan @file{configure.ac}, and because @command{automake} uses the
2538 knowledge that a @file{Makefile.in} is in a subdirectory to change its
2539 behavior in some cases.
2540
2541 @vindex AUTOCONF
2542 Automake will run @command{autoconf} to scan @file{configure.ac} and
2543 its dependencies (i.e., @file{aclocal.m4} and any included file),
2544 therefore @command{autoconf} must be in your @env{PATH}.  If there is
2545 an @env{AUTOCONF} variable in your environment it will be used
2546 instead of @command{autoconf}, this allows you to select a particular
2547 version of Autoconf.  By the way, don't misunderstand this paragraph:
2548 @command{automake} runs @command{autoconf} to @strong{scan} your
2549 @file{configure.ac}, this won't build @file{configure} and you still
2550 have to run @command{autoconf} yourself for this purpose.
2551
2552 @cindex @command{automake} options
2553 @cindex Options, @command{automake}
2554 @cindex Strictness, command line
2555
2556 @command{automake} accepts the following options:
2557
2558 @cindex Extra files distributed with Automake
2559 @cindex Files distributed with Automake
2560 @cindex @file{config.guess}
2561
2562 @table @code
2563 @item -a
2564 @itemx --add-missing
2565 @opindex -a
2566 @opindex --add-missing
2567 Automake requires certain common files to exist in certain situations;
2568 for instance, @file{config.guess} is required if @file{configure.ac} invokes
2569 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
2570 files (@pxref{Auxiliary Programs}); this option will cause the missing
2571 ones to be automatically added to the package, whenever possible.  In
2572 general if Automake tells you a file is missing, try using this option.
2573 By default Automake tries to make a symbolic link pointing to its own
2574 copy of the missing file; this can be changed with @option{--copy}.
2575
2576 Many of the potentially-missing files are common scripts whose
2577 location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
2578 Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
2579 file is considered missing, and where the missing file is added
2580 (@pxref{Optional}).
2581
2582 In some strictness modes, additional files are installed, see @ref{Gnits}
2583 for more information.
2584
2585 @item --libdir=@var{dir}
2586 @opindex --libdir
2587 Look for Automake data files in directory @var{dir} instead of in the
2588 installation directory.  This is typically used for debugging.
2589
2590 @item --print-libdir
2591 @opindex --print-libdir
2592 Print the path of the installation directory containing Automake-provided
2593 scripts and data files (like e.g., @file{texinfo.texi} and
2594 @file{install-sh}).
2595
2596 @item -c
2597 @opindex -c
2598 @itemx --copy
2599 @opindex --copy
2600 When used with @option{--add-missing}, causes installed files to be
2601 copied.  The default is to make a symbolic link.
2602
2603 @item --cygnus
2604 @opindex --cygnus
2605 Causes the generated @file{Makefile.in}s to follow Cygnus rules, instead
2606 of GNU or Gnits rules.  For more information, see @ref{Cygnus}.
2607 Note that @emph{this mode of operation is deprecated, and will be removed}
2608 in the next major Automake release (1.13).
2609
2610 @item -f
2611 @opindex -f
2612 @itemx --force-missing
2613 @opindex --force-missing
2614 When used with @option{--add-missing}, causes standard files to be reinstalled
2615 even if they already exist in the source tree.  This involves removing
2616 the file from the source tree before creating the new symlink (or, with
2617 @option{--copy}, copying the new file).
2618
2619 @item --foreign
2620 @opindex --foreign
2621 Set the global strictness to @option{foreign}.  For more information, see
2622 @ref{Strictness}.
2623
2624 @item --gnits
2625 @opindex --gnits
2626 Set the global strictness to @option{gnits}.  For more information, see
2627 @ref{Gnits}.
2628
2629 @item --gnu
2630 @opindex --gnu
2631 Set the global strictness to @option{gnu}.  For more information, see
2632 @ref{Gnits}.  This is the default strictness.
2633
2634 @item --help
2635 @opindex --help
2636 Print a summary of the command line options and exit.
2637
2638 @item -i
2639 @itemx --ignore-deps
2640 @opindex -i
2641 This disables the dependency tracking feature in generated
2642 @file{Makefile}s; see @ref{Dependencies}.
2643
2644 @item --include-deps
2645 @opindex --include-deps
2646 This enables the dependency tracking feature.  This feature is enabled
2647 by default.  This option is provided for historical reasons only and
2648 probably should not be used.
2649
2650 @item --no-force
2651 @opindex --no-force
2652 Ordinarily @command{automake} creates all @file{Makefile.in}s mentioned in
2653 @file{configure.ac}.  This option causes it to only update those
2654 @file{Makefile.in}s that are out of date with respect to one of their
2655 dependents.
2656
2657 @item -o @var{dir}
2658 @itemx --output-dir=@var{dir}
2659 @opindex -o
2660 @opindex --output-dir
2661 Put the generated @file{Makefile.in} in the directory @var{dir}.
2662 Ordinarily each @file{Makefile.in} is created in the directory of the
2663 corresponding @file{Makefile.am}.  This option is deprecated and will be
2664 removed in a future release.
2665
2666 @item -v
2667 @itemx --verbose
2668 @opindex -v
2669 @opindex --verbose
2670 Cause Automake to print information about which files are being read or
2671 created.
2672
2673 @item --version
2674 @opindex --version
2675 Print the version number of Automake and exit.
2676
2677 @item -W CATEGORY
2678 @itemx --warnings=@var{category}
2679 @opindex -W
2680 @opindex --warnings
2681 Output warnings falling in @var{category}.  @var{category} can be
2682 one of:
2683 @table @code
2684 @item gnu
2685 warnings related to the GNU Coding Standards
2686 (@pxref{Top, , , standards, The GNU Coding Standards}).
2687 @item obsolete
2688 obsolete features or constructions
2689 @item override
2690 user redefinitions of Automake rules or variables
2691 @item portability
2692 portability issues (e.g., use of @command{make} features that are
2693 known to be not portable)
2694 @item extra-portability
2695 extra portability issues related to obscure tools.  One example of such
2696 a tool is the Microsoft @command{lib} archiver.
2697 @item syntax
2698 weird syntax, unused variables, typos
2699 @item unsupported
2700 unsupported or incomplete features
2701 @item all
2702 all the warnings
2703 @item none
2704 turn off all the warnings
2705 @item error
2706 treat warnings as errors
2707 @end table
2708
2709 A category can be turned off by prefixing its name with @samp{no-}.  For
2710 instance, @option{-Wno-syntax} will hide the warnings about unused
2711 variables.
2712
2713 The categories output by default are @samp{syntax} and
2714 @samp{unsupported}.  Additionally, @samp{gnu} and @samp{portability}
2715 are enabled in @option{--gnu} and @option{--gnits} strictness.
2716 On the other hand, the @option{silent-rules} options (@pxref{Options})
2717 turns off portability warnings about recursive variable expansions.
2718
2719 @c Checked by extra-portability.sh
2720 Turning off @samp{portability} will also turn off @samp{extra-portability},
2721 and similarly turning on @samp{extra-portability} will also turn on
2722 @samp{portability}.  However, turning on @samp{portability} or turning
2723 off @samp{extra-portability} will not affect the other category.
2724
2725 @vindex WARNINGS
2726 The environment variable @env{WARNINGS} can contain a comma separated
2727 list of categories to enable.  It will be taken into account before the
2728 command-line switches, this way @option{-Wnone} will also ignore any
2729 warning category enabled by @env{WARNINGS}.  This variable is also used
2730 by other tools like @command{autoconf}; unknown categories are ignored
2731 for this reason.
2732
2733 @end table
2734
2735 @vindex AUTOMAKE_JOBS
2736 If the environment variable @env{AUTOMAKE_JOBS} contains a positive
2737 number, it is taken as the maximum number of Perl threads to use in
2738 @command{automake} for generating multiple @file{Makefile.in} files
2739 concurrently.  This is an experimental feature.
2740
2741
2742 @node configure
2743 @chapter Scanning @file{configure.ac}, using @command{aclocal}
2744
2745 @cindex @file{configure.ac}, scanning
2746 @cindex Scanning @file{configure.ac}
2747 @cindex Using @command{aclocal}
2748 @cindex @command{aclocal}, using
2749
2750 Automake scans the package's @file{configure.ac} to determine certain
2751 information about the package.  Some @command{autoconf} macros are required
2752 and some variables must be defined in @file{configure.ac}.  Automake
2753 will also use information from @file{configure.ac} to further tailor its
2754 output.
2755
2756 Automake also supplies some Autoconf macros to make the maintenance
2757 easier.  These macros can automatically be put into your
2758 @file{aclocal.m4} using the @command{aclocal} program.
2759
2760 @menu
2761 * Requirements::                Configuration requirements
2762 * Optional::                    Other things Automake recognizes
2763 * aclocal Invocation::          Auto-generating aclocal.m4
2764 * Macros::                      Autoconf macros supplied with Automake
2765 @end menu
2766
2767
2768 @node Requirements
2769 @section Configuration requirements
2770
2771 @cindex Automake requirements
2772 @cindex Requirements of Automake
2773
2774 @acindex AM_INIT_AUTOMAKE
2775 The one real requirement of Automake is that your @file{configure.ac}
2776 call @code{AM_INIT_AUTOMAKE}.  This macro does several things that are
2777 required for proper Automake operation (@pxref{Macros}).
2778
2779 Here are the other macros that Automake requires but which are not run
2780 by @code{AM_INIT_AUTOMAKE}:
2781
2782 @table @code
2783 @item AC_CONFIG_FILES
2784 @itemx AC_OUTPUT
2785 @acindex AC_CONFIG_FILES
2786 @acindex AC_OUTPUT
2787 These two macros are usually invoked as follows near the end of
2788 @file{configure.ac}.
2789
2790 @example
2791 @dots{}
2792 AC_CONFIG_FILES([
2793   Makefile
2794   doc/Makefile
2795   src/Makefile
2796   src/lib/Makefile
2797   @dots{}
2798 ])
2799 AC_OUTPUT
2800 @end example
2801
2802 Automake uses these to determine which files to create (@pxref{Output, ,
2803 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
2804 is considered to be an Automake generated @file{Makefile} if there
2805 exists a file with the same name and the @file{.am} extension appended.
2806 Typically, @samp{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
2807 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
2808
2809 When using @code{AC_CONFIG_FILES} with multiple input files, as in
2810
2811 @example
2812 AC_CONFIG_FILES([Makefile:top.in:Makefile.in:bot.in])
2813 @end example
2814
2815 @noindent
2816 @command{automake} will generate the first @file{.in} input file for
2817 which a @file{.am} file exists.  If no such file exists the output
2818 file is not considered to be generated by Automake.
2819
2820 Files created by @code{AC_CONFIG_FILES}, be they Automake
2821 @file{Makefile}s or not, are all removed by @samp{make distclean}.
2822 Their inputs are automatically distributed, unless they
2823 are the output of prior @code{AC_CONFIG_FILES} commands.
2824 Finally, rebuild rules are generated in the Automake @file{Makefile}
2825 existing in the subdirectory of the output file, if there is one, or
2826 in the top-level @file{Makefile} otherwise.
2827
2828 The above machinery (cleaning, distributing, and rebuilding) works
2829 fine if the @code{AC_CONFIG_FILES} specifications contain only
2830 literals.  If part of the specification uses shell variables,
2831 @command{automake} will not be able to fulfill this setup, and you will
2832 have to complete the missing bits by hand.  For instance, on
2833
2834 @c Keep in sync with output11.sh
2835 @example
2836 file=input
2837 @dots{}
2838 AC_CONFIG_FILES([output:$file],, [file=$file])
2839 @end example
2840
2841 @noindent
2842 @command{automake} will output rules to clean @file{output}, and
2843 rebuild it.  However the rebuild rule will not depend on @file{input},
2844 and this file will not be distributed either.  (You must add
2845 @samp{EXTRA_DIST = input} to your @file{Makefile.am} if @file{input} is a
2846 source file.)
2847
2848 Similarly
2849
2850 @c Keep in sync with output11.sh
2851 @example
2852 file=output
2853 file2=out:in
2854 @dots{}
2855 AC_CONFIG_FILES([$file:input],, [file=$file])
2856 AC_CONFIG_FILES([$file2],, [file2=$file2])
2857 @end example
2858
2859 @noindent
2860 will only cause @file{input} to be distributed.  No file will be
2861 cleaned automatically (add @samp{DISTCLEANFILES = output out}
2862 yourself), and no rebuild rule will be output.
2863
2864 Obviously @command{automake} cannot guess what value @samp{$file} is
2865 going to hold later when @file{configure} is run, and it cannot use
2866 the shell variable @samp{$file} in a @file{Makefile}.  However, if you
2867 make reference to @samp{$file} as @samp{$@{file@}} (i.e., in a way
2868 that is compatible with @command{make}'s syntax) and furthermore use
2869 @code{AC_SUBST} to ensure that @samp{$@{file@}} is meaningful in a
2870 @file{Makefile}, then @command{automake} will be able to use
2871 @samp{$@{file@}} to generate all of these rules.  For instance, here is
2872 how the Automake package itself generates versioned scripts for its
2873 test suite:
2874
2875 @example
2876 AC_SUBST([APIVERSION], @dots{})
2877 @dots{}
2878 AC_CONFIG_FILES(
2879   [tests/aclocal-$@{APIVERSION@}:tests/aclocal.in],
2880   [chmod +x tests/aclocal-$@{APIVERSION@}],
2881   [APIVERSION=$APIVERSION])
2882 AC_CONFIG_FILES(
2883   [tests/automake-$@{APIVERSION@}:tests/automake.in],
2884   [chmod +x tests/automake-$@{APIVERSION@}])
2885 @end example
2886
2887 @noindent
2888 Here cleaning, distributing, and rebuilding are done automatically,
2889 because @samp{$@{APIVERSION@}} is known at @command{make}-time.
2890
2891 Note that you should not use shell variables to declare
2892 @file{Makefile} files for which @command{automake} must create
2893 @file{Makefile.in}.  Even @code{AC_SUBST} does not help here, because
2894 @command{automake} needs to know the file name when it runs in order
2895 to check whether @file{Makefile.am} exists.  (In the very hairy case
2896 that your setup requires such use of variables, you will have to tell
2897 Automake which @file{Makefile.in}s to generate on the command-line.)
2898
2899 It is possible to let @command{automake} emit conditional rules for
2900 @code{AC_CONFIG_FILES} with the help of @code{AM_COND_IF}
2901 (@pxref{Optional}).
2902
2903 To summarize:
2904 @itemize @bullet
2905 @item
2906 Use literals for @file{Makefile}s, and for other files whenever possible.
2907 @item
2908 Use @samp{$file} (or @samp{$@{file@}} without @samp{AC_SUBST([file])})
2909 for files that @command{automake} should ignore.
2910 @item
2911 Use @samp{$@{file@}} and @samp{AC_SUBST([file])} for files
2912 that @command{automake} should not ignore.
2913 @end itemize
2914
2915 @end table
2916
2917
2918 @node Optional
2919 @section Other things Automake recognizes
2920
2921 @cindex Macros Automake recognizes
2922 @cindex Recognized macros by Automake
2923
2924 Every time Automake is run it calls Autoconf to trace
2925 @file{configure.ac}.  This way it can recognize the use of certain
2926 macros and tailor the generated @file{Makefile.in} appropriately.
2927 Currently recognized macros and their effects are:
2928
2929 @ftable @code
2930 @item AC_CANONICAL_BUILD
2931 @itemx AC_CANONICAL_HOST
2932 @itemx AC_CANONICAL_TARGET
2933 @vindex build_triplet
2934 @vindex host_triplet
2935 @vindex target_triplet
2936 Automake will ensure that @file{config.guess} and @file{config.sub}
2937 exist.  Also, the @file{Makefile} variables @code{build_triplet},
2938 @code{host_triplet} and @code{target_triplet} are introduced.  See
2939 @ref{Canonicalizing, , Getting the Canonical System Type, autoconf,
2940 The Autoconf Manual}.
2941
2942 @item AC_CONFIG_AUX_DIR
2943 Automake will look for various helper scripts, such as
2944 @file{install-sh}, in the directory named in this macro invocation.
2945 @c This list is accurate relative to version 1.11
2946 (The full list of scripts is:
2947 @file{ar-lib},
2948 @file{config.guess},
2949 @file{config.sub},
2950 @file{depcomp},
2951 @file{elisp-comp},
2952 @file{compile},
2953 @file{install-sh},
2954 @file{ltmain.sh},
2955 @file{mdate-sh},
2956 @file{missing},
2957 @file{mkinstalldirs},
2958 @file{py-compile},
2959 @file{test-driver},
2960 @file{texinfo.tex},
2961 @file{ylwrap}.)
2962 Not all scripts are always searched for; some scripts
2963 will only be sought if the generated @file{Makefile.in} requires them.
2964
2965 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
2966 their standard locations.  For @file{mdate-sh},
2967 @file{texinfo.tex}, and @file{ylwrap}, the standard location is the
2968 source directory corresponding to the current @file{Makefile.am}.  For
2969 the rest, the standard location is the first one of @file{.}, @file{..},
2970 or @file{../..} (relative to the top source directory) that provides any
2971 one of the helper scripts.  @xref{Input, , Finding `configure' Input,
2972 autoconf, The Autoconf Manual}.
2973
2974 Required files from @code{AC_CONFIG_AUX_DIR} are automatically
2975 distributed, even if there is no @file{Makefile.am} in this directory.
2976
2977 @item AC_CONFIG_LIBOBJ_DIR
2978 Automake will require the sources file declared with
2979 @code{AC_LIBSOURCE} (see below) in the directory specified by this
2980 macro.
2981
2982 @item AC_CONFIG_HEADERS
2983 Automake will generate rules to rebuild these headers.  Older versions
2984 of Automake required the use of @code{AM_CONFIG_HEADER}
2985 (@pxref{Macros}); this is no longer the case.
2986
2987 As with @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2988 specification using shell variables will be ignored as far as
2989 cleaning, distributing, and rebuilding is concerned.
2990
2991 @item AC_CONFIG_LINKS
2992 Automake will generate rules to remove @file{configure} generated
2993 links on @samp{make distclean} and to distribute named source files as
2994 part of @samp{make dist}.
2995
2996 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2997 specification using shell variables will be ignored as far as cleaning
2998 and distributing is concerned.  (There are no rebuild rules for links.)
2999
3000 @item AC_LIBOBJ
3001 @itemx AC_LIBSOURCE
3002 @itemx AC_LIBSOURCES
3003 @vindex LIBOBJS
3004 Automake will automatically distribute any file listed in
3005 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
3006
3007 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}.  So if
3008 an Autoconf macro is documented to call @samp{AC_LIBOBJ([file])}, then
3009 @file{file.c} will be distributed automatically by Automake.  This
3010 encompasses many macros like @code{AC_FUNC_ALLOCA},
3011 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
3012
3013 By the way, direct assignments to @code{LIBOBJS} are no longer
3014 supported.  You should always use @code{AC_LIBOBJ} for this purpose.
3015 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
3016 autoconf, The Autoconf Manual}.
3017
3018 @item AC_PROG_RANLIB
3019 This is required if any libraries are built in the package.
3020 @xref{Particular Programs, , Particular Program Checks, autoconf, The
3021 Autoconf Manual}.
3022
3023 @item AC_PROG_CXX
3024 This is required if any C++ source is included.  @xref{Particular
3025 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3026
3027 @item AC_PROG_OBJC
3028 This is required if any Objective C source is included.  @xref{Particular
3029 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3030
3031 @item AC_PROG_OBJCXX
3032 This is required if any Objective C++ source is included.  @xref{Particular
3033 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3034
3035 @item AC_PROG_F77
3036 This is required if any Fortran 77 source is included.  @xref{Particular
3037 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3038
3039 @item AC_F77_LIBRARY_LDFLAGS
3040 This is required for programs and shared libraries that are a mixture of
3041 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
3042 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
3043
3044 @item AC_FC_SRCEXT
3045 Automake will add the flags computed by @code{AC_FC_SRCEXT} to compilation
3046 of files with the respective source extension (@pxref{Fortran Compiler, ,
3047 Fortran Compiler Characteristics, autoconf, The Autoconf Manual}).
3048
3049 @item AC_PROG_FC
3050 This is required if any Fortran 90/95 source is included.  This macro is
3051 distributed with Autoconf version 2.58 and later.  @xref{Particular
3052 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3053
3054 @item AC_PROG_LIBTOOL
3055 Automake will turn on processing for @command{libtool} (@pxref{Top, ,
3056 Introduction, libtool, The Libtool Manual}).
3057
3058 @item AC_PROG_YACC
3059 @vindex YACC
3060 If a Yacc source file is seen, then you must either use this macro or
3061 define the variable @code{YACC} in @file{configure.ac}.  The former is
3062 preferred (@pxref{Particular Programs, , Particular Program Checks,
3063 autoconf, The Autoconf Manual}).
3064
3065 @item AC_PROG_LEX
3066 If a Lex source file is seen, then this macro must be used.
3067 @xref{Particular Programs, , Particular Program Checks, autoconf, The
3068 Autoconf Manual}.
3069
3070 @item AC_REQUIRE_AUX_FILE
3071 For each @code{AC_REQUIRE_AUX_FILE([@var{file}])},
3072 @command{automake} will ensure that @file{@var{file}} exists in the
3073 aux directory, and will complain otherwise.  It
3074 will also automatically distribute the file.  This macro should be
3075 used by third-party Autoconf macros that require some supporting
3076 files in the aux directory specified with @code{AC_CONFIG_AUX_DIR}
3077 above.  @xref{Input, , Finding @command{configure} Input, autoconf,
3078 The Autoconf Manual}.
3079
3080 @item AC_SUBST
3081 The first argument is automatically defined as a variable in each
3082 generated @file{Makefile.in}, unless @code{AM_SUBST_NOTMAKE} is also
3083 used for this variable.  @xref{Setting Output Variables, , Setting
3084 Output Variables, autoconf, The Autoconf Manual}.
3085
3086 For every substituted variable @var{var}, @command{automake} will add
3087 a line @code{@var{var} = @var{value}} to each @file{Makefile.in} file.
3088 Many Autoconf macros invoke @code{AC_SUBST} to set output variables
3089 this way, e.g., @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and
3090 @code{X_LIBS}.  Thus, you can access these variables as
3091 @code{$(X_CFLAGS)} and @code{$(X_LIBS)} in any @file{Makefile.am}
3092 if @code{AC_PATH_XTRA} is called.
3093
3094 @item AM_CONDITIONAL
3095 This introduces an Automake conditional (@pxref{Conditionals}).
3096
3097 @item AM_COND_IF
3098 This macro allows @code{automake} to detect subsequent access within
3099 @file{configure.ac} to a conditional previously introduced with
3100 @code{AM_CONDITIONAL}, thus enabling conditional @code{AC_CONFIG_FILES}
3101 (@pxref{Usage of Conditionals}).
3102
3103 @item AM_GNU_GETTEXT
3104 This macro is required for packages that use GNU gettext
3105 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
3106 this macro it ensures that the package meets some of gettext's
3107 requirements.
3108
3109 @item AM_GNU_GETTEXT_INTL_SUBDIR
3110 This macro specifies that the @file{intl/} subdirectory is to be built,
3111 even if the @code{AM_GNU_GETTEXT} macro was invoked with a first argument
3112 of @samp{external}.
3113
3114 @item AM_MAINTAINER_MODE(@ovar{default-mode})
3115 @opindex --enable-maintainer-mode
3116 @opindex --disable-maintainer-mode
3117 This macro adds an @option{--enable-maintainer-mode} option to
3118 @command{configure}.  If this is used, @command{automake} will cause
3119 ``maintainer-only'' rules to be turned off by default in the
3120 generated @file{Makefile.in}s, unless @var{default-mode} is
3121 @samp{enable}.  This macro defines the @code{MAINTAINER_MODE}
3122 conditional, which you can use in your own @file{Makefile.am}.
3123 @xref{maintainer-mode}.
3124
3125 @item AM_SUBST_NOTMAKE(@var{var})
3126 Prevent Automake from defining a variable @var{var}, even if it is
3127 substituted by @command{config.status}.  Normally, Automake defines a
3128 @command{make} variable for each @command{configure} substitution,
3129 i.e., for each @code{AC_SUBST([@var{var}])}.  This macro prevents that
3130 definition from Automake.  If @code{AC_SUBST} has not been called
3131 for this variable, then @code{AM_SUBST_NOTMAKE} has no effects.
3132 Preventing variable definitions may be useful for substitution of
3133 multi-line values, where @code{@var{var} = @@@var{value}@@} might yield
3134 unintended results.
3135
3136 @item m4_include
3137 Files included by @file{configure.ac} using this macro will be
3138 detected by Automake and automatically distributed.  They will also
3139 appear as dependencies in @file{Makefile} rules.
3140
3141 @code{m4_include} is seldom used by @file{configure.ac} authors, but
3142 can appear in @file{aclocal.m4} when @command{aclocal} detects that
3143 some required macros come from files local to your package (as opposed to
3144 macros installed in a system-wide directory, @pxref{aclocal Invocation}).
3145
3146 @end ftable
3147
3148 @node aclocal Invocation
3149 @section Auto-generating aclocal.m4
3150 @c This node used to be named "Invoking automake".  This @anchor
3151 @c allows old links to still work.
3152 @anchor{Invoking aclocal}
3153
3154 @cindex Invocation of @command{aclocal}
3155 @cindex @command{aclocal}, Invocation
3156 @cindex Invoking @command{aclocal}
3157 @cindex @command{aclocal}, Invoking
3158
3159 Automake includes a number of Autoconf macros that can be used in
3160 your package (@pxref{Macros}); some of them are actually required by
3161 Automake in certain situations.  These macros must be defined in your
3162 @file{aclocal.m4}; otherwise they will not be seen by
3163 @command{autoconf}.
3164
3165 The @command{aclocal} program will automatically generate
3166 @file{aclocal.m4} files based on the contents of @file{configure.ac}.
3167 This provides a convenient way to get Automake-provided macros,
3168 without having to search around.  The @command{aclocal} mechanism
3169 allows other packages to supply their own macros (@pxref{Extending
3170 aclocal}).  You can also use it to maintain your own set of custom
3171 macros (@pxref{Local Macros}).
3172
3173 At startup, @command{aclocal} scans all the @file{.m4} files it can
3174 find, looking for macro definitions (@pxref{Macro Search Path}).  Then
3175 it scans @file{configure.ac}.  Any mention of one of the macros found
3176 in the first step causes that macro, and any macros it in turn
3177 requires, to be put into @file{aclocal.m4}.
3178
3179 @emph{Putting} the file that contains the macro definition into
3180 @file{aclocal.m4} is usually done by copying the entire text of this
3181 file, including unused macro definitions as well as both @samp{#} and
3182 @samp{dnl} comments.  If you want to make a comment that will be
3183 completely ignored by @command{aclocal}, use @samp{##} as the comment
3184 leader.
3185
3186 When a file selected by @command{aclocal} is located in a subdirectory
3187 specified as a relative search path with @command{aclocal}'s @option{-I}
3188 argument, @command{aclocal} assumes the file belongs to the package
3189 and uses @code{m4_include} instead of copying it into
3190 @file{aclocal.m4}.  This makes the package smaller, eases dependency
3191 tracking, and cause the file to be distributed automatically.
3192 (@xref{Local Macros}, for an example.)  Any macro that is found in a
3193 system-wide directory, or via an absolute search path will be copied.
3194 So use @samp{-I `pwd`/reldir} instead of @samp{-I reldir} whenever
3195 some relative directory should be considered outside the package.
3196
3197 The contents of @file{acinclude.m4}, if this file exists, are also
3198 automatically included in @file{aclocal.m4}.  We recommend against
3199 using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
3200
3201 @vindex AUTOM4TE
3202 @cindex autom4te
3203 While computing @file{aclocal.m4}, @command{aclocal} runs
3204 @command{autom4te} (@pxref{Using autom4te, , Using @command{Autom4te},
3205 autoconf, The Autoconf Manual}) in order to trace the macros that are
3206 really used, and omit from @file{aclocal.m4} all macros that are
3207 mentioned but otherwise unexpanded (this can happen when a macro is
3208 called conditionally).  @command{autom4te} is expected to be in the
3209 @env{PATH}, just as @command{autoconf}.  Its location can be
3210 overridden using the @env{AUTOM4TE} environment variable.
3211
3212 @menu
3213 * aclocal Options::             Options supported by aclocal
3214 * Macro Search Path::           How aclocal finds .m4 files
3215 * Extending aclocal::           Writing your own aclocal macros
3216 * Local Macros::                Organizing local macros
3217 * Serials::                     Serial lines in Autoconf macros
3218 * Future of aclocal::           aclocal's scheduled death
3219 @end menu
3220
3221 @node aclocal Options
3222 @subsection aclocal Options
3223
3224 @cindex @command{aclocal}, Options
3225 @cindex Options, @command{aclocal}
3226
3227 @command{aclocal} accepts the following options:
3228
3229 @table @code
3230 @item --automake-acdir=@var{dir}
3231 @opindex --automake-acdir
3232 Look for the automake-provided macro files in @var{dir} instead of
3233 in the installation directory.  This is typically used for debugging.
3234
3235 @item --system-acdir=@var{dir}
3236 @opindex --system-acdir
3237 Look for the system-wide third-party macro files (and the special
3238 @file{dirlist} file) in @var{dir} instead of in the installation
3239 directory.  This is typically used for debugging.
3240
3241 @item --diff[=@var{command}]
3242 @opindex --diff
3243 Run @var{command} on M4 file that would be installed or overwritten
3244 by @option{--install}.  The default @var{command} is @samp{diff -u}.
3245 This option implies @option{--install} and @option{--dry-run}.
3246
3247 @item --dry-run
3248 @opindex --dry-run
3249 Do not actually overwrite (or create) @file{aclocal.m4} and M4
3250 files installed by @option{--install}.
3251
3252 @item --help
3253 @opindex --help
3254 Print a summary of the command line options and exit.
3255
3256 @item -I @var{dir}
3257 @opindex -I
3258 Add the directory @var{dir} to the list of directories searched for
3259 @file{.m4} files.
3260
3261 @item --install
3262 @opindex --install
3263 Install system-wide third-party macros into the first directory
3264 specified with @samp{-I @var{dir}} instead of copying them in the
3265 output file.
3266 @c Keep in sync with aclocal-install-absdir.sh
3267 Note that this will happen also if @var{dir} is an absolute path.
3268
3269 @cindex serial number and @option{--install}
3270 When this option is used, and only when this option is used,
3271 @command{aclocal} will also honor @samp{#serial @var{number}} lines
3272 that appear in macros: an M4 file is ignored if there exists another
3273 M4 file with the same basename and a greater serial number in the
3274 search path (@pxref{Serials}).
3275
3276 @item --force
3277 @opindex --force
3278 Always overwrite the output file.  The default is to overwrite the output
3279 file only when really needed, i.e., when its contents changes or if one
3280 of its dependencies is younger.
3281
3282 This option forces the update of @file{aclocal.m4} (or the file
3283 specified with @file{--output} below) and only this file, it has
3284 absolutely no influence on files that may need to be installed by
3285 @option{--install}.
3286
3287 @item --output=@var{file}
3288 @opindex --output
3289 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
3290
3291 @item --print-ac-dir
3292 @opindex --print-ac-dir
3293 Prints the name of the directory that @command{aclocal} will search to
3294 find third-party @file{.m4} files.  When this option is given, normal
3295 processing is suppressed.  This option was used @emph{in the past} by
3296 third-party packages to determine where to install @file{.m4} macro
3297 files, but @emph{this usage is today discouraged}, since it causes
3298 @samp{$(prefix)} not to be thoroughly honoured (which violates the
3299 GNU Coding Standards), and a similar semantics can be better obtained
3300 with the @env{ACLOCAL_PATH} environment variable; @pxref{Extending aclocal}.
3301
3302 @item --verbose
3303 @opindex --verbose
3304 Print the names of the files it examines.
3305
3306 @item --version
3307 @opindex --version
3308 Print the version number of Automake and exit.
3309
3310 @item -W CATEGORY
3311 @item --warnings=@var{category}
3312 @opindex -W
3313 @opindex --warnings
3314 Output warnings falling in @var{category}.  @var{category} can be
3315 one of:
3316 @table @code
3317 @item syntax
3318 dubious syntactic constructs, underquoted macros, unused macros, etc.
3319 @item unsupported
3320 unknown macros
3321 @item all
3322 all the warnings, this is the default
3323 @item none
3324 turn off all the warnings
3325 @item error
3326 treat warnings as errors
3327 @end table
3328
3329 All warnings are output by default.
3330
3331 @vindex WARNINGS
3332 The environment variable @env{WARNINGS} is honored in the same
3333 way as it is for @command{automake} (@pxref{automake Invocation}).
3334
3335 @end table
3336
3337 @node Macro Search Path
3338 @subsection Macro Search Path
3339
3340 @cindex Macro search path
3341 @cindex @command{aclocal} search path
3342
3343 By default, @command{aclocal} searches for @file{.m4} files in the following
3344 directories, in this order:
3345
3346 @table @code
3347 @item @var{acdir-APIVERSION}
3348 This is where the @file{.m4} macros distributed with Automake itself
3349 are stored.  @var{APIVERSION} depends on the Automake release used;
3350 for example, for Automake 1.11.x, @var{APIVERSION} = @code{1.11}.
3351
3352 @item @var{acdir}
3353 This directory is intended for third party @file{.m4} files, and is
3354 configured when @command{automake} itself is built.  This is
3355 @file{@@datadir@@/aclocal/}, which typically
3356 expands to @file{$@{prefix@}/share/aclocal/}.  To find the compiled-in
3357 value of @var{acdir}, use the @option{--print-ac-dir} option
3358 (@pxref{aclocal Options}).
3359 @end table
3360
3361 As an example, suppose that @command{automake-1.11.2} was configured with
3362 @option{--prefix=@-/usr/local}.  Then, the search path would be:
3363
3364 @enumerate
3365 @item @file{/usr/local/share/aclocal-1.11.2/}
3366 @item @file{/usr/local/share/aclocal/}
3367 @end enumerate
3368
3369 The paths for the @var{acdir} and @var{acdir-APIVERSION} directories can
3370 be changed respectively through aclocal options @option{--system-acdir}
3371 and @option{--automake-acdir} (@pxref{aclocal Options}).  Note however
3372 that these options are only intended for use by the internal Automake
3373 test suite, or for debugging under highly unusual situations; they are
3374 not ordinarily needed by end-users.
3375
3376 As explained in (@pxref{aclocal Options}), there are several options that
3377 can be used to change or extend this search path.
3378
3379 @subsubheading Modifying the Macro Search Path: @samp{-I @var{dir}}
3380
3381 Any extra directories specified using @option{-I} options
3382 (@pxref{aclocal Options}) are @emph{prepended} to this search list.  Thus,
3383 @samp{aclocal -I /foo -I /bar} results in the following search path:
3384
3385 @enumerate
3386 @item @file{/foo}
3387 @item @file{/bar}
3388 @item @var{acdir}-@var{APIVERSION}
3389 @item @var{acdir}
3390 @end enumerate
3391
3392 @subsubheading Modifying the Macro Search Path: @file{dirlist}
3393 @cindex @file{dirlist}
3394
3395 There is a third mechanism for customizing the search path.  If a
3396 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
3397 contain a list of directory patterns, one per line.  @command{aclocal}
3398 expands these patterns to directory names, and adds them to the search
3399 list @emph{after} all other directories.  @file{dirlist} entries may
3400 use shell wildcards such as @samp{*}, @samp{?}, or @code{[...]}.
3401
3402 For example, suppose
3403 @file{@var{acdir}/dirlist} contains the following:
3404
3405 @example
3406 /test1
3407 /test2
3408 /test3*
3409 @end example
3410
3411 @noindent
3412 and that @command{aclocal} was called with the @samp{-I /foo -I /bar} options.
3413 Then, the search path would be
3414
3415 @c @code looks better than @file here
3416 @enumerate
3417 @item @code{/foo}
3418 @item @code{/bar}
3419 @item @var{acdir}-@var{APIVERSION}
3420 @item @var{acdir}
3421 @item @code{/test1}
3422 @item @code{/test2}
3423 @end enumerate
3424
3425 @noindent
3426 and all directories with path names starting with @code{/test3}.
3427
3428 If the @option{--system-acdir=@var{dir}} option is used, then
3429 @command{aclocal} will search for the @file{dirlist} file in
3430 @var{dir}; but remember the warnings  above against the use of
3431 @option{--system-acdir}.
3432
3433 @file{dirlist} is useful in the following situation: suppose that
3434 @command{automake} version @code{1.11.2} is installed with
3435 @samp{--prefix=/usr} by the system vendor.  Thus, the default search
3436 directories are
3437
3438 @c @code looks better than @file here
3439 @enumerate
3440 @item @code{/usr/share/aclocal-1.11/}
3441 @item @code{/usr/share/aclocal/}
3442 @end enumerate
3443
3444 However, suppose further that many packages have been manually
3445 installed on the system, with $prefix=/usr/local, as is typical.  In
3446 that case, many of these ``extra'' @file{.m4} files are in
3447 @file{/usr/local/share/aclocal}.  The only way to force
3448 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files is to
3449 always call @samp{aclocal -I /usr/local/share/aclocal}.  This is
3450 inconvenient.  With @file{dirlist}, one may create a file
3451 @file{/usr/share/aclocal/dirlist} containing only the single line
3452
3453 @example
3454 /usr/local/share/aclocal
3455 @end example
3456
3457 Now, the ``default'' search path on the affected system is
3458
3459 @c @code looks better than @file here
3460 @enumerate
3461 @item @code{/usr/share/aclocal-1.11/}
3462 @item @code{/usr/share/aclocal/}
3463 @item @code{/usr/local/share/aclocal/}
3464 @end enumerate
3465
3466 without the need for @option{-I} options; @option{-I} options can be reserved
3467 for project-specific needs (@file{my-source-dir/m4/}), rather than
3468 using it to work around local system-dependent tool installation
3469 directories.
3470
3471 Similarly, @file{dirlist} can be handy if you have installed a local
3472 copy of Automake in your account and want @command{aclocal} to look for
3473 macros installed at other places on the system.
3474
3475 @anchor{ACLOCAL_PATH}
3476 @subsubheading Modifying the Macro Search Path: @file{ACLOCAL_PATH}
3477 @cindex @env{ACLOCAL_PATH}
3478
3479 The fourth and last mechanism to customize the macro search path is
3480 also the simplest.  Any directory included in the colon-separated
3481 environment variable @env{ACLOCAL_PATH} is added to the search path
3482 @c Keep in sync with aclocal-path-precedence.sh
3483 and takes precedence over system directories (including those found via
3484 @file{dirlist}), with the exception of the versioned directory
3485 @var{acdir-APIVERSION} (@pxref{Macro Search Path}).  However, directories
3486 passed via @option{-I} will take precedence over directories in
3487 @env{ACLOCAL_PATH}.
3488
3489 @c Keep in sync with aclocal-path-installed.sh
3490 Also note that, if the @option{--install} option is used, any @file{.m4}
3491 file containing a required macro that is found in a directory listed in
3492 @env{ACLOCAL_PATH} will be installed locally.
3493 @c Keep in sync with aclocal-path-installed-serial.sh
3494 In this case, serial numbers in @file{.m4} are honoured too,
3495 @pxref{Serials}.
3496
3497 Conversely to @file{dirlist}, @env{ACLOCAL_PATH} is useful if you are
3498 using a global copy of Automake and want @command{aclocal} to look for
3499 macros somewhere under your home directory.
3500
3501 @subsubheading Planned future incompatibilities
3502
3503 The order in which the directories in the macro search path are currently
3504 looked up is confusing and/or suboptimal in various aspects, and is
3505 probably going to be changed in the future Automake release.  In
3506 particular, directories in @env{ACLOCAL_PATH} and @file{@var{acdir}}
3507 might end up taking precedence over @file{@var{acdir-APIVERSION}}, and
3508 directories in @file{@var{acdir}/dirlist} might end up taking precedence
3509 over @file{@var{acdir}}.  @emph{This is a possible future incompatibility!}
3510
3511 @node Extending aclocal
3512 @subsection Writing your own aclocal macros
3513
3514 @cindex @command{aclocal}, extending
3515 @cindex Extending @command{aclocal}
3516
3517 The @command{aclocal} program doesn't have any built-in knowledge of any
3518 macros, so it is easy to extend it with your own macros.
3519
3520 This can be used by libraries that want to supply their own Autoconf
3521 macros for use by other programs.  For instance, the @command{gettext}
3522 library supplies a macro @code{AM_GNU_GETTEXT} that should be used by
3523 any package using @command{gettext}.  When the library is installed, it
3524 installs this macro so that @command{aclocal} will find it.
3525
3526 A macro file's name should end in @file{.m4}.  Such files should be
3527 installed in @file{$(datadir)/aclocal}.  This is as simple as writing:
3528
3529 @c Keep in sync with primary-prefix-couples-documented-valid.sh
3530 @example
3531 aclocaldir = $(datadir)/aclocal
3532 aclocal_DATA = mymacro.m4 myothermacro.m4
3533 @end example
3534
3535 @noindent
3536 Please do use @file{$(datadir)/aclocal}, and not something based on
3537 the result of @samp{aclocal --print-ac-dir} (@pxref{Hard-Coded Install
3538 Paths}, for arguments).  It might also be helpful to suggest to
3539 the user to add the @file{$(datadir)/aclocal} directory to his
3540 @env{ACLOCAL_PATH} variable (@pxref{ACLOCAL_PATH}) so that
3541 @command{aclocal} will find the @file{.m4} files installed by your
3542 package automatically.
3543
3544 A file of macros should be a series of properly quoted
3545 @code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
3546 Autoconf Manual}).  The @command{aclocal} programs also understands
3547 @code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
3548 Autoconf Manual}), so it is safe to put each macro in a separate file.
3549 Each file should have no side effects but macro definitions.
3550 Especially, any call to @code{AC_PREREQ} should be done inside the
3551 defined macro, not at the beginning of the file.
3552
3553 @cindex underquoted @code{AC_DEFUN}
3554 @acindex AC_DEFUN
3555 @acindex AC_PREREQ
3556
3557 Starting with Automake 1.8, @command{aclocal} will warn about all
3558 underquoted calls to @code{AC_DEFUN}.  We realize this will annoy a
3559 lot of people, because @command{aclocal} was not so strict in the past
3560 and many third party macros are underquoted; and we have to apologize
3561 for this temporary inconvenience.  The reason we have to be stricter
3562 is that a future implementation of @command{aclocal} (@pxref{Future of
3563 aclocal}) will have to temporarily include all of these third party
3564 @file{.m4} files, maybe several times, including even files that are
3565 not actually needed.  Doing so should alleviate many problems of the
3566 current implementation, however it requires a stricter style from the
3567 macro authors.  Hopefully it is easy to revise the existing macros.
3568 For instance,
3569
3570 @example
3571 # bad style
3572 AC_PREREQ(2.68)
3573 AC_DEFUN(AX_FOOBAR,
3574 [AC_REQUIRE([AX_SOMETHING])dnl
3575 AX_FOO
3576 AX_BAR
3577 ])
3578 @end example
3579
3580 @noindent
3581 should be rewritten as
3582
3583 @example
3584 AC_DEFUN([AX_FOOBAR],
3585 [AC_PREREQ([2.68])dnl
3586 AC_REQUIRE([AX_SOMETHING])dnl
3587 AX_FOO
3588 AX_BAR
3589 ])
3590 @end example
3591
3592 Wrapping the @code{AC_PREREQ} call inside the macro ensures that
3593 Autoconf 2.68 will not be required if @code{AX_FOOBAR} is not actually
3594 used.  Most importantly, quoting the first argument of @code{AC_DEFUN}
3595 allows the macro to be redefined or included twice (otherwise this
3596 first argument would be expanded during the second definition).  For
3597 consistency we like to quote even arguments such as @code{2.68} that
3598 do not require it.
3599
3600 If you have been directed here by the @command{aclocal} diagnostic but
3601 are not the maintainer of the implicated macro, you will want to
3602 contact the maintainer of that macro.  Please make sure you have the
3603 latest version of the macro and that the problem hasn't already been
3604 reported before doing so: people tend to work faster when they aren't
3605 flooded by mails.
3606
3607 Another situation where @command{aclocal} is commonly used is to
3608 manage macros that are used locally by the package, @ref{Local
3609 Macros}.
3610
3611 @node Local Macros
3612 @subsection Handling Local Macros
3613
3614 Feature tests offered by Autoconf do not cover all needs.  People
3615 often have to supplement existing tests with their own macros, or
3616 with third-party macros.
3617
3618 There are two ways to organize custom macros in a package.
3619
3620 The first possibility (the historical practice) is to list all your
3621 macros in @file{acinclude.m4}.  This file will be included in
3622 @file{aclocal.m4} when you run @command{aclocal}, and its macro(s) will
3623 henceforth be visible to @command{autoconf}.  However if it contains
3624 numerous macros, it will rapidly become difficult to maintain, and it
3625 will be almost impossible to share macros between packages.
3626
3627 @vindex ACLOCAL_AMFLAGS
3628 The second possibility, which we do recommend, is to write each macro
3629 in its own file and gather all of these files in a directory.  This
3630 directory is usually called @file{m4/}.  To build @file{aclocal.m4},
3631 one should therefore instruct @command{aclocal} to scan @file{m4/}.
3632 From the command line, this is done with @samp{aclocal -I m4}.  The
3633 top-level @file{Makefile.am} should also be updated to define
3634
3635 @example
3636 ACLOCAL_AMFLAGS = -I m4
3637 @end example
3638
3639 @code{ACLOCAL_AMFLAGS} contains options to pass to @command{aclocal}
3640 when @file{aclocal.m4} is to be rebuilt by @command{make}.  This line is
3641 also used by @command{autoreconf} (@pxref{autoreconf Invocation, ,
3642 Using @command{autoreconf} to Update @file{configure} Scripts,
3643 autoconf, The Autoconf Manual}) to run @command{aclocal} with suitable
3644 options, or by @command{autopoint} (@pxref{autopoint Invocation, ,
3645 Invoking the @command{autopoint} Program, gettext, GNU gettext tools})
3646 and @command{gettextize} (@pxref{gettextize Invocation, , Invoking the
3647 @command{gettextize} Program, gettext, GNU gettext tools}) to locate
3648 the place where Gettext's macros should be installed.  So even if you
3649 do not really care about the rebuild rules, you should define
3650 @code{ACLOCAL_AMFLAGS}.
3651
3652 When @samp{aclocal -I m4} is run, it will build an @file{aclocal.m4}
3653 that @code{m4_include}s any file from @file{m4/} that defines a
3654 required macro.  Macros not found locally will still be searched in
3655 system-wide directories, as explained in @ref{Macro Search Path}.
3656
3657 Custom macros should be distributed for the same reason that
3658 @file{configure.ac} is: so that other people have all the sources of
3659 your package if they want to work on it.  Actually, this distribution
3660 happens automatically because all @code{m4_include}d files are
3661 distributed.
3662
3663 However there is no consensus on the distribution of third-party
3664 macros that your package may use.  Many libraries install their own
3665 macro in the system-wide @command{aclocal} directory (@pxref{Extending
3666 aclocal}).  For instance, Guile ships with a file called
3667 @file{guile.m4} that contains the macro @code{GUILE_FLAGS} that can
3668 be used to define setup compiler and linker flags appropriate for
3669 using Guile.  Using @code{GUILE_FLAGS} in @file{configure.ac} will
3670 cause @command{aclocal} to copy @file{guile.m4} into
3671 @file{aclocal.m4}, but as @file{guile.m4} is not part of the project,
3672 it will not be distributed.  Technically, that means a user who
3673 needs to rebuild @file{aclocal.m4} will have to install Guile first.
3674 This is probably OK, if Guile already is a requirement to build the
3675 package.  However, if Guile is only an optional feature, or if your
3676 package might run on architectures where Guile cannot be installed,
3677 this requirement will hinder development.  An easy solution is to copy
3678 such third-party macros in your local @file{m4/} directory so they get
3679 distributed.
3680
3681 Since Automake 1.10, @command{aclocal} offers an option to copy these
3682 system-wide third-party macros in your local macro directory, solving
3683 the above problem.  Simply use:
3684
3685 @example
3686 ACLOCAL_AMFLAGS = -I m4 --install
3687 @end example
3688
3689 @noindent
3690 With this setup, system-wide macros will be copied to @file{m4/}
3691 the first time you run @command{autoreconf}.  Then the locally
3692 installed macros will have precedence over the system-wide installed
3693 macros each time @command{aclocal} is run again.
3694
3695 One reason why you should keep @option{--install} in the flags even
3696 after the first run is that when you later edit @file{configure.ac}
3697 and depend on a new macro, this macro will be installed in your
3698 @file{m4/} automatically.  Another one is that serial numbers
3699 (@pxref{Serials}) can be used to update the macros in your source tree
3700 automatically when new system-wide versions are installed.  A serial
3701 number should be a single line of the form
3702
3703 @example
3704 #serial @var{nnn}
3705 @end example
3706
3707 @noindent
3708 where @var{nnn} contains only digits and dots.  It should appear in
3709 the M4 file before any macro definition.  It is a good practice to
3710 maintain a serial number for each macro you distribute, even if you do
3711 not use the @option{--install} option of @command{aclocal}: this allows
3712 other people to use it.
3713
3714
3715 @node Serials
3716 @subsection Serial Numbers
3717 @cindex serial numbers in macros
3718 @cindex macro serial numbers
3719 @cindex @code{#serial} syntax
3720 @cindex @command{aclocal} and serial numbers
3721
3722 Because third-party macros defined in @file{*.m4} files are naturally
3723 shared between multiple projects, some people like to version them.
3724 This makes it easier to tell which of two M4 files is newer.  Since at
3725 least 1996, the tradition is to use a @samp{#serial} line for this.
3726
3727 A serial number should be a single line of the form
3728
3729 @example
3730 # serial @var{version}
3731 @end example
3732
3733 @noindent
3734 where @var{version} is a version number containing only digits and
3735 dots.  Usually people use a single integer, and they increment it each
3736 time they change the macro (hence the name of ``serial'').  Such a
3737 line should appear in the M4 file before any macro definition.
3738
3739 The @samp{#} must be the first character on the line,
3740 and it is OK to have extra words after the version, as in
3741
3742 @example
3743 #serial @var{version} @var{garbage}
3744 @end example
3745
3746 Normally these serial numbers are completely ignored by
3747 @command{aclocal} and @command{autoconf}, like any genuine comment.
3748 However when using @command{aclocal}'s @option{--install} feature, these
3749 serial numbers will modify the way @command{aclocal} selects the
3750 macros to install in the package: if two files with the same basename
3751 exist in your search path, and if at least one of them uses a
3752 @samp{#serial} line, @command{aclocal} will ignore the file that has
3753 the older @samp{#serial} line (or the file that has none).
3754
3755 Note that a serial number applies to a whole M4 file, not to any macro
3756 it contains.  A file can contains multiple macros, but only one
3757 serial.
3758
3759 Here is a use case that illustrates the use of @option{--install} and
3760 its interaction with serial numbers.  Let's assume we maintain a
3761 package called MyPackage, the @file{configure.ac} of which requires a
3762 third-party macro @code{AX_THIRD_PARTY} defined in
3763 @file{/usr/share/aclocal/thirdparty.m4} as follows:
3764
3765 @example
3766 # serial 1
3767 AC_DEFUN([AX_THIRD_PARTY], [...])
3768 @end example
3769
3770 MyPackage uses an @file{m4/} directory to store local macros as
3771 explained in @ref{Local Macros}, and has
3772
3773 @example
3774 ACLOCAL_AMFLAGS = -I m4 --install
3775 @end example
3776
3777 @noindent
3778 in its top-level @file{Makefile.am}.
3779
3780 Initially the @file{m4/} directory is empty.  The first time we run
3781 @command{autoreconf}, it will fetch the options to pass to
3782 @command{aclocal} in @file{Makefile.am}, and run @samp{aclocal -I m4
3783 --install}.  @command{aclocal} will notice that
3784
3785 @itemize @bullet
3786 @item
3787 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3788 @item
3789 No local macros define @code{AX_THIRD_PARTY}
3790 @item
3791 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3792 with serial 1.
3793 @end itemize
3794
3795 @noindent
3796 Because @file{/usr/share/aclocal/thirdparty.m4} is a system-wide macro
3797 and @command{aclocal} was given the @option{--install} option, it will
3798 copy this file in @file{m4/thirdparty.m4}, and output an
3799 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3800
3801 The next time @samp{aclocal -I m4 --install} is run (either via
3802 @command{autoreconf}, by hand, or from the @file{Makefile} rebuild
3803 rules) something different happens.  @command{aclocal} notices that
3804
3805 @itemize @bullet
3806 @item
3807 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3808 @item
3809 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3810 with serial 1.
3811 @item
3812 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3813 with serial 1.
3814 @end itemize
3815
3816 @noindent
3817 Because both files have the same serial number, @command{aclocal} uses
3818 the first it found in its search path order (@pxref{Macro Search
3819 Path}).  @command{aclocal} therefore ignores
3820 @file{/usr/share/aclocal/thirdparty.m4} and outputs an
3821 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3822
3823 Local directories specified with @option{-I} are always searched before
3824 system-wide directories, so a local file will always be preferred to
3825 the system-wide file in case of equal serial numbers.
3826
3827 Now suppose the system-wide third-party macro is changed.  This can
3828 happen if the package installing this macro is updated.  Let's suppose
3829 the new macro has serial number 2.  The next time @samp{aclocal -I m4
3830 --install} is run the situation is the following:
3831
3832 @itemize @bullet
3833 @item
3834 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3835 @item
3836 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3837 with serial 1.
3838 @item
3839 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3840 with serial 2.
3841 @end itemize
3842
3843 @noindent
3844 When @command{aclocal} sees a greater serial number, it immediately
3845 forgets anything it knows from files that have the same basename and a
3846 smaller serial number.  So after it has found
3847 @file{/usr/share/aclocal/thirdparty.m4} with serial 2,
3848 @command{aclocal} will proceed as if it had never seen
3849 @file{m4/thirdparty.m4}.  This brings us back to a situation similar
3850 to that at the beginning of our example, where no local file defined
3851 the macro.  @command{aclocal} will install the new version of the
3852 macro in @file{m4/thirdparty.m4}, in this case overriding the old
3853 version.  MyPackage just had its macro updated as a side effect of
3854 running @command{aclocal}.
3855
3856 If you are leery of letting @command{aclocal} update your local macro,
3857 you can run @samp{aclocal -I m4 --diff} to review the changes
3858 @samp{aclocal -I m4 --install} would perform on these macros.
3859
3860 Finally, note that the @option{--force} option of @command{aclocal} has
3861 absolutely no effect on the files installed by @option{--install}.  For
3862 instance, if you have modified your local macros, do not expect
3863 @option{--install --force} to replace the local macros by their
3864 system-wide versions.  If you want to do so, simply erase the local
3865 macros you want to revert, and run @samp{aclocal -I m4 --install}.
3866
3867
3868 @node Future of aclocal
3869 @subsection The Future of @command{aclocal}
3870 @cindex @command{aclocal}'s scheduled death
3871
3872 @command{aclocal} is expected to disappear.  This feature really
3873 should not be offered by Automake.  Automake should focus on
3874 generating @file{Makefile}s; dealing with M4 macros really is
3875 Autoconf's job.  The fact that some people install Automake just to use
3876 @command{aclocal}, but do not use @command{automake} otherwise is an
3877 indication of how that feature is misplaced.
3878
3879 The new implementation will probably be done slightly differently.
3880 For instance, it could enforce the @file{m4/}-style layout discussed in
3881 @ref{Local Macros}.
3882
3883 We have no idea when and how this will happen.  This has been
3884 discussed several times in the past, but someone still has to commit
3885 to that non-trivial task.
3886
3887 From the user point of view, @command{aclocal}'s removal might turn
3888 out to be painful.  There is a simple precaution that you may take to
3889 make that switch more seamless: never call @command{aclocal} yourself.
3890 Keep this guy under the exclusive control of @command{autoreconf} and
3891 Automake's rebuild rules.  Hopefully you won't need to worry about
3892 things breaking, when @command{aclocal} disappears, because everything
3893 will have been taken care of.  If otherwise you used to call
3894 @command{aclocal} directly yourself or from some script, you will
3895 quickly notice the change.
3896
3897 Many packages come with a script called @file{bootstrap.sh} or
3898 @file{autogen.sh}, that will just call @command{aclocal},
3899 @command{libtoolize}, @command{gettextize} or @command{autopoint},
3900 @command{autoconf}, @command{autoheader}, and @command{automake} in
3901 the right order.  Actually this is precisely what @command{autoreconf}
3902 can do for you.  If your package has such a @file{bootstrap.sh} or
3903 @file{autogen.sh} script, consider using @command{autoreconf}.  That
3904 should simplify its logic a lot (less things to maintain, yum!), it's
3905 even likely you will not need the script anymore, and more to the point
3906 you will not call @command{aclocal} directly anymore.
3907
3908 For the time being, third-party packages should continue to install
3909 public macros into @file{/usr/share/aclocal/}.  If @command{aclocal}
3910 is replaced by another tool it might make sense to rename the
3911 directory, but supporting @file{/usr/share/aclocal/} for backward
3912 compatibility should be really easy provided all macros are properly
3913 written (@pxref{Extending aclocal}).
3914
3915
3916
3917 @node Macros
3918 @section Autoconf macros supplied with Automake
3919
3920 Automake ships with several Autoconf macros that you can use from your
3921 @file{configure.ac}.  When you use one of them it will be included by
3922 @command{aclocal} in @file{aclocal.m4}.
3923
3924 @menu
3925 * Public Macros::               Macros that you can use.
3926 * Obsolete Macros::             Macros that will soon be removed.
3927 * Private Macros::              Macros that you should not use.
3928 @end menu
3929
3930 @c consider generating the following subsections automatically from m4 files.
3931
3932 @node Public Macros
3933 @subsection Public Macros
3934
3935 @table @code
3936
3937 @item AM_INIT_AUTOMAKE([OPTIONS])
3938 @acindex AM_INIT_AUTOMAKE
3939 Runs many macros required for proper operation of the generated Makefiles.
3940
3941 @vindex AUTOMAKE_OPTIONS
3942 Today, @code{AM_INIT_AUTOMAKE} is called with a single argument: a
3943 space-separated list of Automake options that should
3944 be applied to every @file{Makefile.am} in the tree.  The effect is as if
3945 each option were listed in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
3946
3947 @acindex AC_INIT
3948 This macro can also be called in @emph{another, deprecated form} (support
3949 for which will be @emph{removed in the next major Automake release (1.13)}):
3950 @code{AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])}.  In this form,
3951 there are two required arguments: the package and the version number.
3952 This form is obsolete because the @var{package} and @var{version} can
3953 be obtained from Autoconf's @code{AC_INIT} macro (which itself has an
3954 old and a new form).
3955
3956 @anchor{Modernize AM_INIT_AUTOMAKE invocation}
3957 If your @file{configure.ac} has:
3958
3959 @example
3960 AC_INIT([src/foo.c])
3961 AM_INIT_AUTOMAKE([mumble], [1.5])
3962 @end example
3963
3964 @noindent
3965 you should modernize it as follows:
3966
3967 @example
3968 AC_INIT([mumble], [1.5])
3969 AC_CONFIG_SRCDIR([src/foo.c])
3970 AM_INIT_AUTOMAKE
3971 @end example
3972
3973 Note that if you're upgrading your @file{configure.ac} from an earlier
3974 version of Automake, it is not always correct to simply move the
3975 package and version arguments from @code{AM_INIT_AUTOMAKE} directly to
3976 @code{AC_INIT}, as in the example above.  The first argument to
3977 @code{AC_INIT} should be the name of your package (e.g., @samp{GNU
3978 Automake}), not the tarball name (e.g., @samp{automake}) that you used
3979 to pass to @code{AM_INIT_AUTOMAKE}.  Autoconf tries to derive a
3980 tarball name from the package name, which should work for most but not
3981 all package names.  (If it doesn't work for yours, you can use the
3982 four-argument form of @code{AC_INIT} to provide the tarball name
3983 explicitly).
3984
3985 @cindex @code{PACKAGE}, prevent definition
3986 @cindex @code{VERSION}, prevent definition
3987 @opindex no-define
3988 By default this macro @code{AC_DEFINE}'s @code{PACKAGE} and
3989 @code{VERSION}.  This can be avoided by passing the @option{no-define}
3990 option:
3991 @example
3992 AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
3993 @end example
3994
3995 @item AM_PATH_LISPDIR
3996 @acindex AM_PATH_LISPDIR
3997 @vindex EMACS
3998 @vindex lispdir
3999 Searches for the program @command{emacs}, and, if found, sets the
4000 output variable @code{lispdir} to the full path to Emacs' site-lisp
4001 directory.
4002
4003 Note that this test assumes the @command{emacs} found to be a version
4004 that supports Emacs Lisp (such as GNU Emacs or XEmacs).  Other
4005 emacsen can cause this test to hang (some, like old versions of
4006 MicroEmacs, start up in interactive mode, requiring @kbd{C-x C-c} to
4007 exit, which is hardly obvious for a non-emacs user).  In most cases,
4008 however, you should be able to use @kbd{C-c} to kill the test.  In
4009 order to avoid problems, you can set @env{EMACS} to ``no'' in the
4010 environment, or use the @option{--with-lispdir} option to
4011 @command{configure} to explicitly set the correct path (if you're sure
4012 you have an @command{emacs} that supports Emacs Lisp).
4013
4014 @item AM_PROG_AR(@ovar{act-if-fail})
4015 @acindex AM_PROG_AR
4016 @vindex AR
4017 You must use this macro when you use the archiver in your project, if
4018 you want support for unusual archivers such as Microsoft @command{lib}.
4019 The content of the optional argument is executed if the archiver
4020 interface is not recognized; the default action is to abort configure
4021 with an error message.
4022
4023 @item AM_PROG_AS
4024 @acindex AM_PROG_AS
4025 @vindex CCAS
4026 @vindex CCASFLAGS
4027 Use this macro when you have assembly code in your project.  This will
4028 choose the assembler for you (by default the C compiler) and set
4029 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
4030
4031 @item AM_PROG_CC_C_O
4032 @acindex AM_PROG_CC_C_O
4033 @acindex AC_PROG_CC_C_O
4034 This is like @code{AC_PROG_CC_C_O}, but it generates its results in
4035 the manner required by Automake.  You must use this instead of
4036 @code{AC_PROG_CC_C_O} when you need this functionality, that is, when
4037 using per-target flags or subdir-objects with C sources.
4038
4039 @item AM_PROG_LEX
4040 @acindex AM_PROG_LEX
4041 @acindex AC_PROG_LEX
4042 @cindex HP-UX 10, @command{lex} problems
4043 @cindex @command{lex} problems with HP-UX 10
4044 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
4045 Program Checks, autoconf, The Autoconf Manual}), but uses the
4046 @command{missing} script on systems that do not have @command{lex}.
4047 HP-UX 10 is one such system.
4048
4049 @item AM_PROG_GCJ
4050 @acindex AM_PROG_GCJ
4051 @vindex GCJ
4052 @vindex GCJFLAGS
4053 This macro finds the @command{gcj} program or causes an error.  It sets
4054 @code{GCJ} and @code{GCJFLAGS}.  @command{gcj} is the Java front-end to the
4055 GNU Compiler Collection.
4056
4057 @item AM_PROG_UPC([@var{compiler-search-list}])
4058 @acindex AM_PROG_UPC
4059 @vindex UPC
4060 Find a compiler for Unified Parallel C and define the @code{UPC}
4061 variable.  The default @var{compiler-search-list} is @samp{upcc upc}.
4062 This macro will abort @command{configure} if no Unified Parallel C
4063 compiler is found.
4064
4065 @item AM_MISSING_PROG(@var{name}, @var{program})
4066 @acindex AM_MISSING_PROG
4067 @vindex MISSING
4068 Find a maintainer tool @var{program} and define the @var{name}
4069 environment variable with its location.  If @var{program} is not
4070 detected, then @var{name} will instead invoke the @command{missing}
4071 script, in order to give useful advice to the user about the missing
4072 maintainer tool.  @xref{maintainer-mode}, for more information on when
4073 the @command{missing} script is appropriate.
4074
4075 @item AM_SILENT_RULES
4076 @acindex AM_SILENT_RULES
4077 Enable the machinery for less verbose build output (@pxref{Options}).
4078
4079 @item AM_WITH_DMALLOC
4080 @acindex AM_WITH_DMALLOC
4081 @cindex @command{dmalloc}, support for
4082 @vindex WITH_DMALLOC
4083 @opindex --with-dmalloc
4084 Add support for the @uref{http://dmalloc.com/, Dmalloc package}.  If
4085 the user runs @command{configure} with @option{--with-dmalloc}, then
4086 define @code{WITH_DMALLOC} and add @option{-ldmalloc} to @code{LIBS}.
4087
4088 @end table
4089
4090
4091 @node Obsolete Macros
4092 @subsection Obsolete Macros
4093 @cindex obsolete macros
4094 @cindex autoupdate
4095
4096 Although using some of the following macros was required in past
4097 releases, you should not use any of them in new code.  @emph{All
4098 these macros will be removed in the next major Automake version};
4099 if you are still using them, running @command{autoupdate} should
4100 adjust your @file{configure.ac} automatically (@pxref{autoupdate
4101 Invocation, , Using @command{autoupdate} to Modernize
4102 @file{configure.ac}, autoconf, The Autoconf Manual}).
4103 @emph{Do it NOW!}
4104
4105 @table @code
4106
4107 @item AM_CONFIG_HEADER
4108 @acindex AM_CONFIG_HEADER
4109 Automake will generate rules to automatically regenerate the config
4110 header.  This obsolete macro is a synonym of @code{AC_CONFIG_HEADERS}
4111 today (@pxref{Optional}).
4112
4113 @item AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
4114 @acindex AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
4115 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
4116 define @code{GWINSZ_IN_SYS_IOCTL}.  Otherwise @code{TIOCGWINSZ} can be
4117 found in @file{<termios.h>}.  This macro is obsolete, you should
4118 use Autoconf's @code{AC_HEADER_TIOCGWINSZ} instead.
4119
4120 @item AM_PROG_MKDIR_P
4121 @acindex AM_PROG_MKDIR_P
4122 @cindex @code{mkdir -p}, macro check
4123 @vindex MKDIR_P
4124 @vindex mkdir_p
4125
4126 From Automake 1.8 to 1.9.6 this macro used to define the output
4127 variable @code{mkdir_p} to one of @code{mkdir -p}, @code{install-sh
4128 -d}, or @code{mkinstalldirs}.
4129
4130 Nowadays Autoconf provides a similar functionality with
4131 @code{AC_PROG_MKDIR_P} (@pxref{Particular Programs, , Particular
4132 Program Checks, autoconf, The Autoconf Manual}), however this defines
4133 the output variable @code{MKDIR_P} instead.  In case you are still
4134 using the @code{AM_PROG_MKDIR_P} macro in your @file{configure.ac},
4135 or its provided variable @code{$(mkdir_p)} in your @file{Makefile.am},
4136 you are advised to switch ASAP to the more modern Autoconf-provided
4137 interface instead; both the macro and the variable @emph{will be
4138 removed} in the next major Automake release.
4139
4140 @item AM_SYS_POSIX_TERMIOS
4141 @acindex AM_SYS_POSIX_TERMIOS
4142 @cindex POSIX termios headers
4143 @cindex termios POSIX headers
4144 Check to see if POSIX termios headers and functions are available on the
4145 system.  If so, set the shell variable @code{am_cv_sys_posix_termios} to
4146 @samp{yes}.  If not, set the variable to @samp{no}.  This macro is obsolete,
4147 you should use Autoconf's @code{AC_SYS_POSIX_TERMIOS} instead.
4148
4149 @end table
4150
4151
4152 @node Private Macros
4153 @subsection Private Macros
4154
4155 The following macros are private macros you should not call directly.
4156 They are called by the other public macros when appropriate.  Do not
4157 rely on them, as they might be changed in a future version.  Consider
4158 them as implementation details; or better, do not consider them at all:
4159 skip this section!
4160
4161 @ftable @code
4162 @item _AM_DEPENDENCIES
4163 @itemx AM_SET_DEPDIR
4164 @itemx AM_DEP_TRACK
4165 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
4166 These macros are used to implement Automake's automatic dependency
4167 tracking scheme.  They are called automatically by Automake when
4168 required, and there should be no need to invoke them manually.
4169
4170 @item AM_MAKE_INCLUDE
4171 This macro is used to discover how the user's @command{make} handles
4172 @code{include} statements.  This macro is automatically invoked when
4173 needed; there should be no need to invoke it manually.
4174
4175 @item AM_PROG_INSTALL_STRIP
4176 This is used to find a version of @code{install} that can be used to
4177 strip a program at installation time.  This macro is automatically
4178 included when required.
4179
4180 @item AM_SANITY_CHECK
4181 This checks to make sure that a file created in the build directory is
4182 newer than a file in the source directory.  This can fail on systems
4183 where the clock is set incorrectly.  This macro is automatically run
4184 from @code{AM_INIT_AUTOMAKE}.
4185
4186 @end ftable
4187
4188
4189 @node Directories
4190 @chapter Directories
4191
4192 For simple projects that distribute all files in the same directory
4193 it is enough to have a single @file{Makefile.am} that builds
4194 everything in place.
4195
4196 In larger projects, it is common to organize files in different
4197 directories, in a tree.  For example, there could be a directory
4198 for the program's source, one for the testsuite, and one for the
4199 documentation; or, for very large projects, there could be one
4200 directory per program, per library or per module.
4201
4202 The traditional approach is to build these subdirectories recursively,
4203 employing @emph{make recursion}: each directory contains its
4204 own @file{Makefile}, and when @command{make} is run from the top-level
4205 directory, it enters each subdirectory in turn, and invokes there a
4206 new @command{make} instance to build the directory's contents.
4207
4208 Because this approach is very widespread, Automake offers built-in
4209 support for it.  However, it is worth nothing that the use of make
4210 recursion has its own serious issues and drawbacks, and that it's
4211 well possible to have packages with a multi directory layout that
4212 make little or no use of such recursion (examples of such packages
4213 are GNU Bison and GNU Automake itself); see also the @ref{Alternative}
4214 section below.
4215
4216 @menu
4217 * Subdirectories::              Building subdirectories recursively
4218 * Conditional Subdirectories::  Conditionally not building directories
4219 * Alternative::                 Subdirectories without recursion
4220 * Subpackages::                 Nesting packages
4221 @end menu
4222
4223 @node Subdirectories
4224 @section Recursing subdirectories
4225
4226 @cindex @code{SUBDIRS}, explained
4227
4228 In packages using make recursion, the top level @file{Makefile.am} must
4229 tell Automake which subdirectories are to be built.  This is done via
4230 the @code{SUBDIRS} variable.
4231 @vindex SUBDIRS
4232
4233 The @code{SUBDIRS} variable holds a list of subdirectories in which
4234 building of various sorts can occur.  The rules for many targets
4235 (e.g., @code{all}) in the generated @file{Makefile} will run commands
4236 both locally and in all specified subdirectories.  Note that the
4237 directories listed in @code{SUBDIRS} are not required to contain
4238 @file{Makefile.am}s; only @file{Makefile}s (after configuration).
4239 This allows inclusion of libraries from packages that do not use
4240 Automake (such as @code{gettext}; see also @ref{Third-Party
4241 Makefiles}).
4242
4243 In packages that use subdirectories, the top-level @file{Makefile.am} is
4244 often very short.  For instance, here is the @file{Makefile.am} from the
4245 GNU Hello distribution:
4246
4247 @example
4248 EXTRA_DIST = BUGS ChangeLog.O README-alpha
4249 SUBDIRS = doc intl po src tests
4250 @end example
4251
4252 When Automake invokes @command{make} in a subdirectory, it uses the value
4253 of the @code{MAKE} variable.  It passes the value of the variable
4254 @code{AM_MAKEFLAGS} to the @command{make} invocation; this can be set in
4255 @file{Makefile.am} if there are flags you must always pass to
4256 @command{make}.
4257 @vindex MAKE
4258 @vindex AM_MAKEFLAGS
4259
4260 The directories mentioned in @code{SUBDIRS} are usually direct
4261 children of the current directory, each subdirectory containing its
4262 own @file{Makefile.am} with a @code{SUBDIRS} pointing to deeper
4263 subdirectories.  Automake can be used to construct packages of
4264 arbitrary depth this way.
4265
4266 By default, Automake generates @file{Makefiles} that work depth-first
4267 in postfix order: the subdirectories are built before the current
4268 directory.  However, it is possible to change this ordering.  You can
4269 do this by putting @samp{.} into @code{SUBDIRS}.  For instance,
4270 putting @samp{.} first will cause a prefix ordering of
4271 directories.
4272
4273 Using
4274
4275 @example
4276 SUBDIRS = lib src . test
4277 @end example
4278
4279 @noindent
4280 will cause @file{lib/} to be built before @file{src/}, then the
4281 current directory will be built, finally the @file{test/} directory
4282 will be built.  It is customary to arrange test directories to be
4283 built after everything else since they are meant to test what has
4284 been constructed.
4285
4286 @node Conditional Subdirectories
4287 @section Conditional Subdirectories
4288 @cindex Subdirectories, building conditionally
4289 @cindex Conditional subdirectories
4290 @cindex @code{SUBDIRS}, conditional
4291 @cindex Conditional @code{SUBDIRS}
4292
4293 It is possible to define the @code{SUBDIRS} variable conditionally if,
4294 like in the case of GNU Inetutils, you want to only build a subset of
4295 the entire package.
4296
4297 To illustrate how this works, let's assume we have two directories
4298 @file{src/} and @file{opt/}.  @file{src/} should always be built, but we
4299 want to decide in @command{configure} whether @file{opt/} will be built
4300 or not.  (For this example we will assume that @file{opt/} should be
4301 built when the variable @samp{$want_opt} was set to @samp{yes}.)
4302
4303 Running @command{make} should thus recurse into @file{src/} always, and
4304 then maybe in @file{opt/}.
4305
4306 However @samp{make dist} should always recurse into both @file{src/}
4307 and @file{opt/}.  Because @file{opt/} should be distributed even if it
4308 is not needed in the current configuration.  This means
4309 @file{opt/Makefile} should be created @emph{unconditionally}.
4310
4311 There are two ways to setup a project like this.  You can use Automake
4312 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
4313 variables (@pxref{Setting Output Variables, , Setting Output
4314 Variables, autoconf, The Autoconf Manual}).  Using Automake
4315 conditionals is the preferred solution.  Before we illustrate these
4316 two possibilities, let's introduce @code{DIST_SUBDIRS}.
4317
4318 @menu
4319 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
4320 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
4321 * Subdirectories with AC_SUBST::  Another way for conditional recursion
4322 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
4323 @end menu
4324
4325 @node SUBDIRS vs DIST_SUBDIRS
4326 @subsection @code{SUBDIRS} vs.@: @code{DIST_SUBDIRS}
4327 @cindex @code{DIST_SUBDIRS}, explained
4328
4329 Automake considers two sets of directories, defined by the variables
4330 @code{SUBDIRS} and @code{DIST_SUBDIRS}.
4331
4332 @code{SUBDIRS} contains the subdirectories of the current directory
4333 that must be built (@pxref{Subdirectories}).  It must be defined
4334 manually; Automake will never guess a directory is to be built.  As we
4335 will see in the next two sections, it is possible to define it
4336 conditionally so that some directory will be omitted from the build.
4337
4338 @code{DIST_SUBDIRS} is used in rules that need to recurse in all
4339 directories, even those that have been conditionally left out of the
4340 build.  Recall our example where we may not want to build subdirectory
4341 @file{opt/}, but yet we want to distribute it?  This is where
4342 @code{DIST_SUBDIRS} comes into play: @samp{opt} may not appear in
4343 @code{SUBDIRS}, but it must appear in @code{DIST_SUBDIRS}.
4344
4345 Precisely, @code{DIST_SUBDIRS} is used by @samp{make
4346 maintainer-clean}, @samp{make distclean} and @samp{make dist}.  All
4347 other recursive rules use @code{SUBDIRS}.
4348
4349 If @code{SUBDIRS} is defined conditionally using Automake
4350 conditionals, Automake will define @code{DIST_SUBDIRS} automatically
4351 from the possible values of @code{SUBDIRS} in all conditions.
4352
4353 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
4354 @code{DIST_SUBDIRS} will not be defined correctly because Automake
4355 does not know the possible values of these variables.  In this case
4356 @code{DIST_SUBDIRS} needs to be defined manually.
4357
4358 @node Subdirectories with AM_CONDITIONAL
4359 @subsection Subdirectories with @code{AM_CONDITIONAL}
4360 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
4361 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
4362
4363 @c Keep in sync with subdir-am-cond.sh
4364
4365 @file{configure} should output the @file{Makefile} for each directory
4366 and define a condition into which @file{opt/} should be built.
4367
4368 @example
4369 @dots{}
4370 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
4371 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4372 @dots{}
4373 @end example
4374
4375 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
4376 as follows.
4377
4378 @example
4379 if COND_OPT
4380   MAYBE_OPT = opt
4381 endif
4382 SUBDIRS = src $(MAYBE_OPT)
4383 @end example
4384
4385 As you can see, running @command{make} will rightly recurse into
4386 @file{src/} and maybe @file{opt/}.
4387
4388 @vindex DIST_SUBDIRS
4389 As you can't see, running @samp{make dist} will recurse into both
4390 @file{src/} and @file{opt/} directories because @samp{make dist}, unlike
4391 @samp{make all}, doesn't use the @code{SUBDIRS} variable.  It uses the
4392 @code{DIST_SUBDIRS} variable.
4393
4394 In this case Automake will define @samp{DIST_SUBDIRS = src opt}
4395 automatically because it knows that @code{MAYBE_OPT} can contain
4396 @samp{opt} in some condition.
4397
4398 @node Subdirectories with AC_SUBST
4399 @subsection Subdirectories with @code{AC_SUBST}
4400 @cindex @code{SUBDIRS} and @code{AC_SUBST}
4401 @cindex @code{AC_SUBST} and @code{SUBDIRS}
4402
4403 @c Keep in sync with subdir-ac-subst.sh
4404
4405 Another possibility is to define @code{MAYBE_OPT} from
4406 @file{./configure} using @code{AC_SUBST}:
4407
4408 @example
4409 @dots{}
4410 if test "$want_opt" = yes; then
4411   MAYBE_OPT=opt
4412 else
4413   MAYBE_OPT=
4414 fi
4415 AC_SUBST([MAYBE_OPT])
4416 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4417 @dots{}
4418 @end example
4419
4420 In this case the top-level @file{Makefile.am} should look as follows.
4421
4422 @example
4423 SUBDIRS = src $(MAYBE_OPT)
4424 DIST_SUBDIRS = src opt
4425 @end example
4426
4427 The drawback is that since Automake cannot guess what the possible
4428 values of @code{MAYBE_OPT} are, it is necessary to define
4429 @code{DIST_SUBDIRS}.
4430
4431 @node Unconfigured Subdirectories
4432 @subsection Unconfigured Subdirectories
4433 @cindex Subdirectories, configured conditionally
4434
4435 The semantics of @code{DIST_SUBDIRS} are often misunderstood by some
4436 users that try to @emph{configure and build} subdirectories
4437 conditionally.  Here by configuring we mean creating the
4438 @file{Makefile} (it might also involve running a nested
4439 @command{configure} script: this is a costly operation that explains
4440 why people want to do it conditionally, but only the @file{Makefile}
4441 is relevant to the discussion).
4442
4443 The above examples all assume that every @file{Makefile} is created,
4444 even in directories that are not going to be built.  The simple reason
4445 is that we want @samp{make dist} to distribute even the directories
4446 that are not being built (e.g., platform-dependent code), hence
4447 @file{make dist} must recurse into the subdirectory, hence this
4448 directory must be configured and appear in @code{DIST_SUBDIRS}.
4449
4450 Building packages that do not configure every subdirectory is a tricky
4451 business, and we do not recommend it to the novice as it is easy to
4452 produce an incomplete tarball by mistake.  We will not discuss this
4453 topic in depth here, yet for the adventurous here are a few rules to
4454 remember.
4455
4456 @cartouche
4457 @itemize
4458 @item @code{SUBDIRS} should always be a subset of @code{DIST_SUBDIRS}.
4459
4460 It makes little sense to have a directory in @code{SUBDIRS} that
4461 is not in @code{DIST_SUBDIRS}.  Think of the former as a way to tell
4462 which directories listed in the latter should be built.
4463 @item Any directory listed in @code{DIST_SUBDIRS} and @code{SUBDIRS}
4464 must be configured.
4465
4466 I.e., the @file{Makefile} must exists or the recursive @command{make}
4467 rules will not be able to process the directory.
4468 @item Any configured directory must be listed in @code{DIST_SUBDIRS}.
4469
4470 So that the cleaning rules remove the generated @file{Makefile}s.
4471 It would be correct to see @code{DIST_SUBDIRS} as a variable that
4472 lists all the directories that have been configured.
4473 @end itemize
4474 @end cartouche
4475
4476 In order to prevent recursion in some unconfigured directory you
4477 must therefore ensure that this directory does not appear in
4478 @code{DIST_SUBDIRS} (and @code{SUBDIRS}).  For instance, if you define
4479 @code{SUBDIRS} conditionally using @code{AC_SUBST} and do not define
4480 @code{DIST_SUBDIRS} explicitly, it will be default to
4481 @samp{$(SUBDIRS)}; another possibility is to force @code{DIST_SUBDIRS
4482 = $(SUBDIRS)}.
4483
4484 Of course, directories that are omitted from @code{DIST_SUBDIRS} will
4485 not be distributed unless you make other arrangements for this to
4486 happen (for instance, always running @samp{make dist} in a
4487 configuration where all directories are known to appear in
4488 @code{DIST_SUBDIRS}; or writing a @code{dist-hook} target to
4489 distribute these directories).
4490
4491 @cindex Subdirectories, not distributed
4492 In few packages, unconfigured directories are not even expected to
4493 be distributed.  Although these packages do not require the
4494 aforementioned extra arrangements, there is another pitfall.  If the
4495 name of a directory appears in @code{SUBDIRS} or @code{DIST_SUBDIRS},
4496 @command{automake} will make sure the directory exists.  Consequently
4497 @command{automake} cannot be run on such a distribution when one
4498 directory has been omitted.  One way to avoid this check is to use the
4499 @code{AC_SUBST} method to declare conditional directories; since
4500 @command{automake} does not know the values of @code{AC_SUBST}
4501 variables it cannot ensure the corresponding directory exists.
4502
4503 @node Alternative
4504 @section An Alternative Approach to Subdirectories
4505
4506 If you've ever read Peter Miller's excellent paper,
4507 @uref{http://miller.emu.id.au/pmiller/books/rmch/,
4508 Recursive Make Considered Harmful}, the preceding sections on the use of
4509 make recursion will probably come as unwelcome advice.  For those who
4510 haven't read the paper, Miller's main thesis is that recursive
4511 @command{make} invocations are both slow and error-prone.
4512
4513 Automake provides sufficient cross-directory support @footnote{We
4514 believe.  This work is new and there are probably warts.
4515 @xref{Introduction}, for information on reporting bugs.} to enable you
4516 to write a single @file{Makefile.am} for a complex multi-directory
4517 package.
4518
4519 By default an installable file specified in a subdirectory will have its
4520 directory name stripped before installation.  For instance, in this
4521 example, the header file will be installed as
4522 @file{$(includedir)/stdio.h}:
4523
4524 @example
4525 include_HEADERS = inc/stdio.h
4526 @end example
4527
4528 @vindex nobase_
4529 @cindex @code{nobase_} prefix
4530 @cindex Path stripping, avoiding
4531 @cindex Avoiding path stripping
4532
4533 However, the @samp{nobase_} prefix can be used to circumvent this path
4534 stripping.  In this example, the header file will be installed as
4535 @file{$(includedir)/sys/types.h}:
4536
4537 @example
4538 nobase_include_HEADERS = sys/types.h
4539 @end example
4540
4541 @cindex @code{nobase_} and @code{dist_} or @code{nodist_}
4542 @cindex @code{dist_} and @code{nobase_}
4543 @cindex @code{nodist_} and @code{nobase_}
4544 @vindex dist_
4545 @vindex nodist_
4546
4547 @samp{nobase_} should be specified first when used in conjunction with
4548 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
4549 Control}).  For instance:
4550
4551 @example
4552 nobase_dist_pkgdata_DATA = images/vortex.pgm sounds/whirl.ogg
4553 @end example
4554
4555 Finally, note that a variable using the @samp{nobase_} prefix can
4556 often be replaced by several variables, one for each destination
4557 directory (@pxref{Uniform}).  For instance, the last example could be
4558 rewritten as follows:
4559
4560 @c Keep in sync with primary-prefix-couples-documented-valid.sh
4561 @example
4562 imagesdir = $(pkgdatadir)/images
4563 soundsdir = $(pkgdatadir)/sounds
4564 dist_images_DATA = images/vortex.pgm
4565 dist_sounds_DATA = sounds/whirl.ogg
4566 @end example
4567
4568 @noindent
4569 This latter syntax makes it possible to change one destination
4570 directory without changing the layout of the source tree.
4571
4572 Currently, @samp{nobase_*_LTLIBRARIES} are the only exception to this
4573 rule, in that there is no particular installation order guarantee for
4574 an otherwise equivalent set of variables without @samp{nobase_} prefix.
4575
4576 @node Subpackages
4577 @section Nesting Packages
4578 @cindex Nesting packages
4579 @cindex Subpackages
4580 @acindex AC_CONFIG_SUBDIRS
4581 @acindex AC_CONFIG_AUX_DIR
4582
4583
4584 In the GNU Build System, packages can be nested to arbitrary depth.
4585 This means that a package can embed other packages with their own
4586 @file{configure}, @file{Makefile}s, etc.
4587
4588 These other packages should just appear as subdirectories of their
4589 parent package.  They must be listed in @code{SUBDIRS} like other
4590 ordinary directories.  However the subpackage's @file{Makefile}s
4591 should be output by its own @file{configure} script, not by the
4592 parent's @file{configure}.  This is achieved using the
4593 @code{AC_CONFIG_SUBDIRS} Autoconf macro (@pxref{Subdirectories,
4594 AC_CONFIG_SUBDIRS, Configuring Other Packages in Subdirectories,
4595 autoconf, The Autoconf Manual}).
4596
4597 Here is an example package for an @code{arm} program that links with
4598 a @code{hand} library that is a nested package in subdirectory
4599 @file{hand/}.
4600
4601 @code{arm}'s @file{configure.ac}:
4602
4603 @example
4604 AC_INIT([arm], [1.0])
4605 AC_CONFIG_AUX_DIR([.])
4606 AM_INIT_AUTOMAKE
4607 AC_PROG_CC
4608 AC_CONFIG_FILES([Makefile])
4609 # Call hand's ./configure script recursively.
4610 AC_CONFIG_SUBDIRS([hand])
4611 AC_OUTPUT
4612 @end example
4613
4614 @code{arm}'s @file{Makefile.am}:
4615
4616 @example
4617 # Build the library in the hand subdirectory first.
4618 SUBDIRS = hand
4619
4620 # Include hand's header when compiling this directory.
4621 AM_CPPFLAGS = -I$(srcdir)/hand
4622
4623 bin_PROGRAMS = arm
4624 arm_SOURCES = arm.c
4625 # link with the hand library.
4626 arm_LDADD = hand/libhand.a
4627 @end example
4628
4629 Now here is @code{hand}'s @file{hand/configure.ac}:
4630
4631 @example
4632 AC_INIT([hand], [1.2])
4633 AC_CONFIG_AUX_DIR([.])
4634 AM_INIT_AUTOMAKE
4635 AC_PROG_CC
4636 AM_PROG_AR
4637 AC_PROG_RANLIB
4638 AC_CONFIG_FILES([Makefile])
4639 AC_OUTPUT
4640 @end example
4641
4642 @noindent
4643 and its @file{hand/Makefile.am}:
4644
4645 @example
4646 lib_LIBRARIES = libhand.a
4647 libhand_a_SOURCES = hand.c
4648 @end example
4649
4650 When @samp{make dist} is run from the top-level directory it will
4651 create an archive @file{arm-1.0.tar.gz} that contains the @code{arm}
4652 code as well as the @file{hand} subdirectory.  This package can be
4653 built and installed like any ordinary package, with the usual
4654 @samp{./configure && make && make install} sequence (the @code{hand}
4655 subpackage will be built and installed by the process).
4656
4657 When @samp{make dist} is run from the hand directory, it will create a
4658 self-contained @file{hand-1.2.tar.gz} archive.  So although it appears
4659 to be embedded in another package, it can still be used separately.
4660
4661 The purpose of the @samp{AC_CONFIG_AUX_DIR([.])} instruction is to
4662 force Automake and Autoconf to search for auxiliary scripts in the
4663 current directory.  For instance, this means that there will be two
4664 copies of @file{install-sh}: one in the top-level of the @code{arm}
4665 package, and another one in the @file{hand/} subdirectory for the
4666 @code{hand} package.
4667
4668 The historical default is to search for these auxiliary scripts in
4669 the parent directory and the grandparent directory.  So if the
4670 @samp{AC_CONFIG_AUX_DIR([.])} line was removed from
4671 @file{hand/configure.ac}, that subpackage would share the auxiliary
4672 script of the @code{arm} package.  This may looks like a gain in size
4673 (a few kilobytes), but it is actually a loss of modularity as the
4674 @code{hand} subpackage is no longer self-contained (@samp{make dist}
4675 in the subdirectory will not work anymore).
4676
4677 Packages that do not use Automake need more work to be integrated this
4678 way.  @xref{Third-Party Makefiles}.
4679
4680 @node Programs
4681 @chapter Building Programs and Libraries
4682
4683 A large part of Automake's functionality is dedicated to making it easy
4684 to build programs and libraries.
4685
4686 @menu
4687 * A Program::                   Building a program
4688 * A Library::                   Building a library
4689 * A Shared Library::            Building a Libtool library
4690 * Program and Library Variables::  Variables controlling program and
4691                                 library builds
4692 * Default _SOURCES::            Default source files
4693 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
4694 * Program Variables::           Variables used when building a program
4695 * Yacc and Lex::                Yacc and Lex support
4696 * C++ Support::                 Compiling C++ sources
4697 * Objective C Support::         Compiling Objective C sources
4698 * Objective C++ Support::       Compiling Objective C++ sources
4699 * Unified Parallel C Support::  Compiling Unified Parallel C sources
4700 * Assembly Support::            Compiling assembly sources
4701 * Fortran 77 Support::          Compiling Fortran 77 sources
4702 * Fortran 9x Support::          Compiling Fortran 9x sources
4703 * Java Support with gcj::       Compiling Java sources using gcj
4704 * Vala Support::                Compiling Vala sources
4705 * Support for Other Languages::  Compiling other languages
4706 * Dependencies::                Automatic dependency tracking
4707 * EXEEXT::                      Support for executable extensions
4708 @end menu
4709
4710
4711 @node A Program
4712 @section Building a program
4713
4714 In order to build a program, you need to tell Automake which sources
4715 are part of it, and which libraries it should be linked with.
4716
4717 This section also covers conditional compilation of sources or
4718 programs.  Most of the comments about these also apply to libraries
4719 (@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
4720
4721 @menu
4722 * Program Sources::             Defining program sources
4723 * Linking::                     Linking with libraries or extra objects
4724 * Conditional Sources::         Handling conditional sources
4725 * Conditional Programs::        Building a program conditionally
4726 @end menu
4727
4728 @node Program Sources
4729 @subsection Defining program sources
4730
4731 @cindex @code{PROGRAMS}, @code{bindir}
4732 @vindex _PROGRAMS
4733 @vindex bin_PROGRAMS
4734 @vindex sbin_PROGRAMS
4735 @vindex libexec_PROGRAMS
4736 @vindex pkglibexec_PROGRAMS
4737 @vindex noinst_PROGRAMS
4738 @vindex check_PROGRAMS
4739
4740 In a directory containing source that gets built into a program (as
4741 opposed to a library or a script), the @code{PROGRAMS} primary is used.
4742 Programs can be installed in @code{bindir}, @code{sbindir},
4743 @code{libexecdir}, @code{pkglibexecdir}, or not at all
4744 (@code{noinst_}).  They can also be built only for @samp{make check}, in
4745 which case the prefix is @samp{check_}.
4746
4747 For instance:
4748
4749 @example
4750 bin_PROGRAMS = hello
4751 @end example
4752
4753 In this simple case, the resulting @file{Makefile.in} will contain code
4754 to generate a program named @code{hello}.
4755
4756 Associated with each program are several assisting variables that are
4757 named after the program.  These variables are all optional, and have
4758 reasonable defaults.  Each variable, its use, and default is spelled out
4759 below; we use the ``hello'' example throughout.
4760
4761 The variable @code{hello_SOURCES} is used to specify which source files
4762 get built into an executable:
4763
4764 @example
4765 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
4766 @end example
4767
4768 This causes each mentioned @file{.c} file to be compiled into the
4769 corresponding @file{.o}.  Then all are linked to produce @file{hello}.
4770
4771 @cindex @code{_SOURCES} primary, defined
4772 @cindex @code{SOURCES} primary, defined
4773 @cindex Primary variable, @code{SOURCES}
4774 @vindex _SOURCES
4775
4776 If @code{hello_SOURCES} is not specified, then it defaults to the single
4777 file @file{hello.c} (@pxref{Default _SOURCES}).
4778 @vindex _SOURCES
4779 @vindex SOURCES
4780
4781 Multiple programs can be built in a single directory.  Multiple programs
4782 can share a single source file, which must be listed in each
4783 @code{_SOURCES} definition.
4784
4785 @cindex Header files in @code{_SOURCES}
4786 @cindex @code{_SOURCES} and header files
4787
4788 Header files listed in a @code{_SOURCES} definition will be included in
4789 the distribution but otherwise ignored.  In case it isn't obvious, you
4790 should not include the header file generated by @file{configure} in a
4791 @code{_SOURCES} variable; this file should not be distributed.  Lex
4792 (@file{.l}) and Yacc (@file{.y}) files can also be listed; see @ref{Yacc
4793 and Lex}.
4794
4795
4796 @node Linking
4797 @subsection Linking the program
4798
4799 If you need to link against libraries that are not found by
4800 @command{configure}, you can use @code{LDADD} to do so.  This variable is
4801 used to specify additional objects or libraries to link with; it is
4802 inappropriate for specifying specific linker flags, you should use
4803 @code{AM_LDFLAGS} for this purpose.
4804 @vindex LDADD
4805 @vindex AM_LDFLAGS
4806
4807 @cindex @code{prog_LDADD}, defined
4808
4809 Sometimes, multiple programs are built in one directory but do not share
4810 the same link-time requirements.  In this case, you can use the
4811 @code{@var{prog}_LDADD} variable (where @var{prog} is the name of the
4812 program as it appears in some @code{_PROGRAMS} variable, and usually
4813 written in lowercase) to override @code{LDADD}.  If this variable exists
4814 for a given program, then that program is not linked using @code{LDADD}.
4815 @vindex maude_LDADD
4816
4817 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
4818 linked against the library @file{libcpio.a}.  However, @code{rmt} is
4819 built in the same directory, and has no such link requirement.  Also,
4820 @code{mt} and @code{rmt} are only built on certain architectures.  Here
4821 is what cpio's @file{src/Makefile.am} looks like (abridged):
4822
4823 @example
4824 bin_PROGRAMS = cpio pax $(MT)
4825 libexec_PROGRAMS = $(RMT)
4826 EXTRA_PROGRAMS = mt rmt
4827
4828 LDADD = ../lib/libcpio.a $(INTLLIBS)
4829 rmt_LDADD =
4830
4831 cpio_SOURCES = @dots{}
4832 pax_SOURCES = @dots{}
4833 mt_SOURCES = @dots{}
4834 rmt_SOURCES = @dots{}
4835 @end example
4836
4837 @cindex @code{_LDFLAGS}, defined
4838 @vindex maude_LDFLAGS
4839 @code{@var{prog}_LDADD} is inappropriate for passing program-specific
4840 linker flags (except for @option{-l}, @option{-L}, @option{-dlopen} and
4841 @option{-dlpreopen}).  So, use the @code{@var{prog}_LDFLAGS} variable for
4842 this purpose.
4843
4844 @cindex @code{_DEPENDENCIES}, defined
4845 @vindex maude_DEPENDENCIES
4846 @vindex EXTRA_maude_DEPENDENCIES
4847 It is also occasionally useful to have a program depend on some other
4848 target that is not actually part of that program.  This can be done
4849 using either the @code{@var{prog}_DEPENDENCIES} or the
4850 @code{EXTRA_@var{prog}_DEPENDENCIES} variable.  Each program depends on
4851 the contents both variables, but no further interpretation is done.
4852
4853 Since these dependencies are associated to the link rule used to
4854 create the programs they should normally list files used by the link
4855 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la}
4856 files.  In rare cases you may need to add other kinds of files such as
4857 linker scripts, but @emph{listing a source file in
4858 @code{_DEPENDENCIES} is wrong}.  If some source file needs to be built
4859 before all the components of a program are built, consider using the
4860 @code{BUILT_SOURCES} variable instead (@pxref{Sources}).
4861
4862 If @code{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
4863 Automake.  The automatically-assigned value is the contents of
4864 @code{@var{prog}_LDADD}, with most configure substitutions, @option{-l},
4865 @option{-L}, @option{-dlopen} and @option{-dlpreopen} options removed.  The
4866 configure substitutions that are left in are only @samp{$(LIBOBJS)} and
4867 @samp{$(ALLOCA)}; these are left because it is known that they will not
4868 cause an invalid value for @code{@var{prog}_DEPENDENCIES} to be
4869 generated.
4870
4871 @ref{Conditional Sources} shows a situation where @code{_DEPENDENCIES}
4872 may be used.
4873
4874 The @code{EXTRA_@var{prog}_DEPENDENCIES} may be useful for cases where
4875 you merely want to augment the @command{automake}-generated
4876 @code{@var{prog}_DEPENDENCIES} rather than replacing it.
4877
4878 @cindex @code{LDADD} and @option{-l}
4879 @cindex @option{-l} and @code{LDADD}
4880 We recommend that you avoid using @option{-l} options in @code{LDADD}
4881 or @code{@var{prog}_LDADD} when referring to libraries built by your
4882 package.  Instead, write the file name of the library explicitly as in
4883 the above @code{cpio} example.  Use @option{-l} only to list
4884 third-party libraries.  If you follow this rule, the default value of
4885 @code{@var{prog}_DEPENDENCIES} will list all your local libraries and
4886 omit the other ones.
4887
4888
4889 @node Conditional Sources
4890 @subsection Conditional compilation of sources
4891
4892 You can't put a configure substitution (e.g., @samp{@@FOO@@} or
4893 @samp{$(FOO)} where @code{FOO} is defined via @code{AC_SUBST}) into a
4894 @code{_SOURCES} variable.  The reason for this is a bit hard to
4895 explain, but suffice to say that it simply won't work.  Automake will
4896 give an error if you try to do this.
4897
4898 Fortunately there are two other ways to achieve the same result.  One is
4899 to use configure substitutions in @code{_LDADD} variables, the other is
4900 to use an Automake conditional.
4901
4902 @subsubheading Conditional Compilation using @code{_LDADD} Substitutions
4903
4904 @cindex @code{EXTRA_prog_SOURCES}, defined
4905
4906 Automake must know all the source files that could possibly go into a
4907 program, even if not all the files are built in every circumstance.  Any
4908 files that are only conditionally built should be listed in the
4909 appropriate @code{EXTRA_} variable.  For instance, if
4910 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
4911 in @code{hello}, the @file{Makefile.am} would contain:
4912
4913 @example
4914 bin_PROGRAMS = hello
4915 hello_SOURCES = hello-common.c
4916 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
4917 hello_LDADD = $(HELLO_SYSTEM)
4918 hello_DEPENDENCIES = $(HELLO_SYSTEM)
4919 @end example
4920
4921 @noindent
4922 You can then setup the @samp{$(HELLO_SYSTEM)} substitution from
4923 @file{configure.ac}:
4924
4925 @example
4926 @dots{}
4927 case $host in
4928   *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
4929   *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
4930 esac
4931 AC_SUBST([HELLO_SYSTEM])
4932 @dots{}
4933 @end example
4934
4935 In this case, the variable @code{HELLO_SYSTEM} should be replaced by
4936 either @file{hello-linux.o} or @file{hello-generic.o}, and added to
4937 both @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be
4938 built and linked in.
4939
4940 @subsubheading Conditional Compilation using Automake Conditionals
4941
4942 An often simpler way to compile source files conditionally is to use
4943 Automake conditionals.  For instance, you could use this
4944 @file{Makefile.am} construct to build the same @file{hello} example:
4945
4946 @example
4947 bin_PROGRAMS = hello
4948 if LINUX
4949 hello_SOURCES = hello-linux.c hello-common.c
4950 else
4951 hello_SOURCES = hello-generic.c hello-common.c
4952 endif
4953 @end example
4954
4955 In this case, @file{configure.ac} should setup the @code{LINUX}
4956 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
4957
4958 When using conditionals like this you don't need to use the
4959 @code{EXTRA_} variable, because Automake will examine the contents of
4960 each variable to construct the complete list of source files.
4961
4962 If your program uses a lot of files, you will probably prefer a
4963 conditional @samp{+=}.
4964
4965 @example
4966 bin_PROGRAMS = hello
4967 hello_SOURCES = hello-common.c
4968 if LINUX
4969 hello_SOURCES += hello-linux.c
4970 else
4971 hello_SOURCES += hello-generic.c
4972 endif
4973 @end example
4974
4975 @node Conditional Programs
4976 @subsection Conditional compilation of programs
4977 @cindex Conditional programs
4978 @cindex Programs, conditional
4979
4980 Sometimes it is useful to determine the programs that are to be built
4981 at configure time.  For instance, GNU @code{cpio} only builds
4982 @code{mt} and @code{rmt} under special circumstances.  The means to
4983 achieve conditional compilation of programs are the same you can use
4984 to compile source files conditionally: substitutions or conditionals.
4985
4986 @subsubheading Conditional Programs using @command{configure} Substitutions
4987
4988 @vindex EXTRA_PROGRAMS
4989 @cindex @code{EXTRA_PROGRAMS}, defined
4990 In this case, you must notify Automake of all the programs that can
4991 possibly be built, but at the same time cause the generated
4992 @file{Makefile.in} to use the programs specified by @command{configure}.
4993 This is done by having @command{configure} substitute values into each
4994 @code{_PROGRAMS} definition, while listing all optionally built programs
4995 in @code{EXTRA_PROGRAMS}.
4996
4997 @example
4998 bin_PROGRAMS = cpio pax $(MT)
4999 libexec_PROGRAMS = $(RMT)
5000 EXTRA_PROGRAMS = mt rmt
5001 @end example
5002
5003 As explained in @ref{EXEEXT}, Automake will rewrite
5004 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
5005 @code{EXTRA_PROGRAMS}, appending @samp{$(EXEEXT)} to each binary.
5006 Obviously it cannot rewrite values obtained at run-time through
5007 @command{configure} substitutions, therefore you should take care of
5008 appending @samp{$(EXEEXT)} yourself, as in @samp{AC_SUBST([MT],
5009 ['mt$@{EXEEXT@}'])}.
5010
5011 @subsubheading Conditional Programs using Automake Conditionals
5012
5013 You can also use Automake conditionals (@pxref{Conditionals}) to
5014 select programs to be built.  In this case you don't have to worry
5015 about @samp{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
5016
5017 @c Keep in sync with exeext.sh
5018 @example
5019 bin_PROGRAMS = cpio pax
5020 if WANT_MT
5021   bin_PROGRAMS += mt
5022 endif
5023 if WANT_RMT
5024   libexec_PROGRAMS = rmt
5025 endif
5026 @end example
5027
5028
5029 @node A Library
5030 @section Building a library
5031
5032 @cindex @code{_LIBRARIES} primary, defined
5033 @cindex @code{LIBRARIES} primary, defined
5034 @cindex Primary variable, @code{LIBRARIES}
5035 @vindex _LIBRARIES
5036
5037 @vindex lib_LIBRARIES
5038 @vindex pkglib_LIBRARIES
5039 @vindex noinst_LIBRARIES
5040
5041 Building a library is much like building a program.  In this case, the
5042 name of the primary is @code{LIBRARIES}.  Libraries can be installed in
5043 @code{libdir} or @code{pkglibdir}.
5044
5045 @xref{A Shared Library}, for information on how to build shared
5046 libraries using libtool and the @code{LTLIBRARIES} primary.
5047
5048 Each @code{_LIBRARIES} variable is a list of the libraries to be built.
5049 For instance, to create a library named @file{libcpio.a}, but not install
5050 it, you would write:
5051
5052 @example
5053 noinst_LIBRARIES = libcpio.a
5054 libcpio_a_SOURCES = @dots{}
5055 @end example
5056
5057 The sources that go into a library are determined exactly as they are
5058 for programs, via the @code{_SOURCES} variables.  Note that the library
5059 name is canonicalized (@pxref{Canonicalization}), so the @code{_SOURCES}
5060 variable corresponding to @file{libcpio.a} is @samp{libcpio_a_SOURCES},
5061 not @samp{libcpio.a_SOURCES}.
5062
5063 @vindex maude_LIBADD
5064 Extra objects can be added to a library using the
5065 @code{@var{library}_LIBADD} variable.  This should be used for objects
5066 determined by @command{configure}.  Again from @code{cpio}:
5067
5068 @c Keep in sync with pr401c.sh
5069 @example
5070 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
5071 @end example
5072
5073 In addition, sources for extra objects that will not exist until
5074 configure-time must be added to the @code{BUILT_SOURCES} variable
5075 (@pxref{Sources}).
5076
5077 Building a static library is done by compiling all object files, then
5078 by invoking @samp{$(AR) $(ARFLAGS)} followed by the name of the
5079 library and the list of objects, and finally by calling
5080 @samp{$(RANLIB)} on that library.  You should call
5081 @code{AC_PROG_RANLIB} from your @file{configure.ac} to define
5082 @code{RANLIB} (Automake will complain otherwise).  You should also
5083 call @code{AM_PROG_AR} to define @code{AR}, in order to support unusual
5084 archivers such as Microsoft lib.  @code{ARFLAGS} will default to
5085 @code{cru}; you can override this variable by setting it in your
5086 @file{Makefile.am} or by @code{AC_SUBST}ing it from your
5087 @file{configure.ac}.  You can override the @code{AR} variable by
5088 defining a per-library @code{maude_AR} variable (@pxref{Program and
5089 Library Variables}).
5090
5091 @cindex Empty libraries
5092 Be careful when selecting library components conditionally.  Because
5093 building an empty library is not portable, you should ensure that any
5094 library always contains at least one object.
5095
5096 To use a static library when building a program, add it to
5097 @code{LDADD} for this program.  In the following example, the program
5098 @file{cpio} is statically linked with the library @file{libcpio.a}.
5099
5100 @example
5101 noinst_LIBRARIES = libcpio.a
5102 libcpio_a_SOURCES = @dots{}
5103
5104 bin_PROGRAMS = cpio
5105 cpio_SOURCES = cpio.c @dots{}
5106 cpio_LDADD = libcpio.a
5107 @end example
5108
5109
5110 @node A Shared Library
5111 @section Building a Shared Library
5112
5113 @cindex Shared libraries, support for
5114
5115 Building shared libraries portably is a relatively complex matter.
5116 For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
5117 Libtool Manual}) was created to help build shared libraries in a
5118 platform-independent way.
5119
5120 @menu
5121 * Libtool Concept::             Introducing Libtool
5122 * Libtool Libraries::           Declaring Libtool Libraries
5123 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
5124 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
5125 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
5126 * Libtool Modules::             Building Libtool Modules
5127 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
5128 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
5129 * Libtool Issues::              Common Issues Related to Libtool's Use
5130 @end menu
5131
5132 @node Libtool Concept
5133 @subsection The Libtool Concept
5134
5135 @cindex @command{libtool}, introduction
5136 @cindex libtool library, definition
5137 @cindex suffix @file{.la}, defined
5138 @cindex @file{.la} suffix, defined
5139
5140 Libtool abstracts shared and static libraries into a unified concept
5141 henceforth called @dfn{libtool libraries}.  Libtool libraries are
5142 files using the @file{.la} suffix, and can designate a static library,
5143 a shared library, or maybe both.  Their exact nature cannot be
5144 determined until @file{./configure} is run: not all platforms support
5145 all kinds of libraries, and users can explicitly select which
5146 libraries should be built.  (However the package's maintainers can
5147 tune the default, @pxref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
5148 macro, libtool, The Libtool Manual}.)
5149
5150 @cindex suffix @file{.lo}, defined
5151 Because object files for shared and static libraries must be compiled
5152 differently, libtool is also used during compilation.  Object files
5153 built by libtool are called @dfn{libtool objects}: these are files
5154 using the @file{.lo} suffix.  Libtool libraries are built from these
5155 libtool objects.
5156
5157 You should not assume anything about the structure of @file{.la} or
5158 @file{.lo} files and how libtool constructs them: this is libtool's
5159 concern, and the last thing one wants is to learn about libtool's
5160 guts.  However the existence of these files matters, because they are
5161 used as targets and dependencies in @file{Makefile}s rules when
5162 building libtool libraries.  There are situations where you may have
5163 to refer to these, for instance when expressing dependencies for
5164 building source files conditionally (@pxref{Conditional Libtool
5165 Sources}).
5166
5167 @cindex @file{libltdl}, introduction
5168
5169 People considering writing a plug-in system, with dynamically loaded
5170 modules, should look into @file{libltdl}: libtool's dlopening library
5171 (@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
5172 This offers a portable dlopening facility to load libtool libraries
5173 dynamically, and can also achieve static linking where unavoidable.
5174
5175 Before we discuss how to use libtool with Automake in details, it
5176 should be noted that the libtool manual also has a section about how
5177 to use Automake with libtool (@pxref{Using Automake, , Using Automake
5178 with Libtool, libtool, The Libtool Manual}).
5179
5180 @node Libtool Libraries
5181 @subsection Building Libtool Libraries
5182
5183 @cindex @code{_LTLIBRARIES} primary, defined
5184 @cindex @code{LTLIBRARIES} primary, defined
5185 @cindex Primary variable, @code{LTLIBRARIES}
5186 @cindex Example of shared libraries
5187 @vindex lib_LTLIBRARIES
5188 @vindex pkglib_LTLIBRARIES
5189 @vindex _LTLIBRARIES
5190
5191 Automake uses libtool to build libraries declared with the
5192 @code{LTLIBRARIES} primary.  Each @code{_LTLIBRARIES} variable is a
5193 list of libtool libraries to build.  For instance, to create a libtool
5194 library named @file{libgettext.la}, and install it in @code{libdir},
5195 write:
5196
5197 @example
5198 lib_LTLIBRARIES = libgettext.la
5199 libgettext_la_SOURCES = gettext.c gettext.h @dots{}
5200 @end example
5201
5202 Automake predefines the variable @code{pkglibdir}, so you can use
5203 @code{pkglib_LTLIBRARIES} to install libraries in
5204 @samp{$(libdir)/@@PACKAGE@@/}.
5205
5206 If @file{gettext.h} is a public header file that needs to be installed
5207 in order for people to use the library, it should be declared using a
5208 @code{_HEADERS} variable, not in @code{libgettext_la_SOURCES}.
5209 Headers listed in the latter should be internal headers that are not
5210 part of the public interface.
5211
5212 @example
5213 lib_LTLIBRARIES = libgettext.la
5214 libgettext_la_SOURCES = gettext.c @dots{}
5215 include_HEADERS = gettext.h @dots{}
5216 @end example
5217
5218 A package can build and install such a library along with other
5219 programs that use it.  This dependency should be specified using
5220 @code{LDADD}.  The following example builds a program named
5221 @file{hello} that is linked with @file{libgettext.la}.
5222
5223 @example
5224 lib_LTLIBRARIES = libgettext.la
5225 libgettext_la_SOURCES = gettext.c @dots{}
5226
5227 bin_PROGRAMS = hello
5228 hello_SOURCES = hello.c @dots{}
5229 hello_LDADD = libgettext.la
5230 @end example
5231
5232 @noindent
5233 Whether @file{hello} is statically or dynamically linked with
5234 @file{libgettext.la} is not yet known: this will depend on the
5235 configuration of libtool and the capabilities of the host.
5236
5237
5238 @node Conditional Libtool Libraries
5239 @subsection Building Libtool Libraries Conditionally
5240 @cindex libtool libraries, conditional
5241 @cindex conditional libtool libraries
5242
5243 Like conditional programs (@pxref{Conditional Programs}), there are
5244 two main ways to build conditional libraries: using Automake
5245 conditionals or using Autoconf @code{AC_SUBST}itutions.
5246
5247 The important implementation detail you have to be aware of is that
5248 the place where a library will be installed matters to libtool: it
5249 needs to be indicated @emph{at link-time} using the @option{-rpath}
5250 option.
5251
5252 For libraries whose destination directory is known when Automake runs,
5253 Automake will automatically supply the appropriate @option{-rpath}
5254 option to libtool.  This is the case for libraries listed explicitly in
5255 some installable @code{_LTLIBRARIES} variables such as
5256 @code{lib_LTLIBRARIES}.
5257
5258 However, for libraries determined at configure time (and thus
5259 mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
5260 final installation directory.  For such libraries you must add the
5261 @option{-rpath} option to the appropriate @code{_LDFLAGS} variable by
5262 hand.
5263
5264 The examples below illustrate the differences between these two methods.
5265
5266 Here is an example where @code{WANTEDLIBS} is an @code{AC_SUBST}ed
5267 variable set at @file{./configure}-time to either @file{libfoo.la},
5268 @file{libbar.la}, both, or none.  Although @samp{$(WANTEDLIBS)}
5269 appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
5270 relates to @file{libfoo.la} or @file{libbar.la} at the time it creates
5271 the link rule for these two libraries.  Therefore the @option{-rpath}
5272 argument must be explicitly supplied.
5273
5274 @c Keep in sync with ltcond.sh
5275 @example
5276 EXTRA_LTLIBRARIES = libfoo.la libbar.la
5277 lib_LTLIBRARIES = $(WANTEDLIBS)
5278 libfoo_la_SOURCES = foo.c @dots{}
5279 libfoo_la_LDFLAGS = -rpath '$(libdir)'
5280 libbar_la_SOURCES = bar.c @dots{}
5281 libbar_la_LDFLAGS = -rpath '$(libdir)'
5282 @end example
5283
5284 Here is how the same @file{Makefile.am} would look using Automake
5285 conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}.  Now
5286 Automake is able to compute the @option{-rpath} setting itself, because
5287 it's clear that both libraries will end up in @samp{$(libdir)} if they
5288 are installed.
5289
5290 @c Keep in sync with ltcond.sh
5291 @example
5292 lib_LTLIBRARIES =
5293 if WANT_LIBFOO
5294 lib_LTLIBRARIES += libfoo.la
5295 endif
5296 if WANT_LIBBAR
5297 lib_LTLIBRARIES += libbar.la
5298 endif
5299 libfoo_la_SOURCES = foo.c @dots{}
5300 libbar_la_SOURCES = bar.c @dots{}
5301 @end example
5302
5303 @node Conditional Libtool Sources
5304 @subsection Libtool Libraries with Conditional Sources
5305
5306 Conditional compilation of sources in a library can be achieved in the
5307 same way as conditional compilation of sources in a program
5308 (@pxref{Conditional Sources}).  The only difference is that
5309 @code{_LIBADD} should be used instead of @code{_LDADD} and that it
5310 should mention libtool objects (@file{.lo} files).
5311
5312 So, to mimic the @file{hello} example from @ref{Conditional Sources},
5313 we could build a @file{libhello.la} library using either
5314 @file{hello-linux.c} or @file{hello-generic.c} with the following
5315 @file{Makefile.am}.
5316
5317 @c Keep in sync with ltcond2.sh
5318 @example
5319 lib_LTLIBRARIES = libhello.la
5320 libhello_la_SOURCES = hello-common.c
5321 EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
5322 libhello_la_LIBADD = $(HELLO_SYSTEM)
5323 libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
5324 @end example
5325
5326 @noindent
5327 And make sure @command{configure} defines @code{HELLO_SYSTEM} as
5328 either @file{hello-linux.lo} or @file{hello-@-generic.lo}.
5329
5330 Or we could simply use an Automake conditional as follows.
5331
5332 @c Keep in sync with ltcond2.sh
5333 @example
5334 lib_LTLIBRARIES = libhello.la
5335 libhello_la_SOURCES = hello-common.c
5336 if LINUX
5337 libhello_la_SOURCES += hello-linux.c
5338 else
5339 libhello_la_SOURCES += hello-generic.c
5340 endif
5341 @end example
5342
5343 @node Libtool Convenience Libraries
5344 @subsection Libtool Convenience Libraries
5345 @cindex convenience libraries, libtool
5346 @cindex libtool convenience libraries
5347 @vindex noinst_LTLIBRARIES
5348 @vindex check_LTLIBRARIES
5349
5350 Sometimes you want to build libtool libraries that should not be
5351 installed.  These are called @dfn{libtool convenience libraries} and
5352 are typically used to encapsulate many sublibraries, later gathered
5353 into one big installed library.
5354
5355 Libtool convenience libraries are declared by directory-less variables
5356 such as @code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
5357 @code{EXTRA_LTLIBRARIES}.  Unlike installed libtool libraries they do
5358 not need an @option{-rpath} flag at link time (actually this is the only
5359 difference).
5360
5361 Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
5362 built.  Those listed in @code{check_LTLIBRARIES} are built only upon
5363 @samp{make check}.  Finally, libraries listed in
5364 @code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
5365 rules to build them, but if the library does not appear as a Makefile
5366 dependency anywhere it won't be built (this is why
5367 @code{EXTRA_LTLIBRARIES} is used for conditional compilation).
5368
5369 Here is a sample setup merging libtool convenience libraries from
5370 subdirectories into one main @file{libtop.la} library.
5371
5372 @c Keep in sync with ltconv.sh
5373 @example
5374 # -- Top-level Makefile.am --
5375 SUBDIRS = sub1 sub2 @dots{}
5376 lib_LTLIBRARIES = libtop.la
5377 libtop_la_SOURCES =
5378 libtop_la_LIBADD = \
5379   sub1/libsub1.la \
5380   sub2/libsub2.la \
5381   @dots{}
5382
5383 # -- sub1/Makefile.am --
5384 noinst_LTLIBRARIES = libsub1.la
5385 libsub1_la_SOURCES = @dots{}
5386
5387 # -- sub2/Makefile.am --
5388 # showing nested convenience libraries
5389 SUBDIRS = sub2.1 sub2.2 @dots{}
5390 noinst_LTLIBRARIES = libsub2.la
5391 libsub2_la_SOURCES =
5392 libsub2_la_LIBADD = \
5393   sub21/libsub21.la \
5394   sub22/libsub22.la \
5395   @dots{}
5396 @end example
5397
5398 When using such setup, beware that @command{automake} will assume
5399 @file{libtop.la} is to be linked with the C linker.  This is because
5400 @code{libtop_la_SOURCES} is empty, so @command{automake} picks C as
5401 default language.  If @code{libtop_la_SOURCES} was not empty,
5402 @command{automake} would select the linker as explained in @ref{How
5403 the Linker is Chosen}.
5404
5405 If one of the sublibraries contains non-C source, it is important that
5406 the appropriate linker be chosen.  One way to achieve this is to
5407 pretend that there is such a non-C file among the sources of the
5408 library, thus forcing @command{automake} to select the appropriate
5409 linker.  Here is the top-level @file{Makefile} of our example updated
5410 to force C++ linking.
5411
5412 @example
5413 SUBDIRS = sub1 sub2 @dots{}
5414 lib_LTLIBRARIES = libtop.la
5415 libtop_la_SOURCES =
5416 # Dummy C++ source to cause C++ linking.
5417 nodist_EXTRA_libtop_la_SOURCES = dummy.cxx
5418 libtop_la_LIBADD = \
5419   sub1/libsub1.la \
5420   sub2/libsub2.la \
5421   @dots{}
5422 @end example
5423
5424 @samp{EXTRA_*_SOURCES} variables are used to keep track of source
5425 files that might be compiled (this is mostly useful when doing
5426 conditional compilation using @code{AC_SUBST}, @pxref{Conditional
5427 Libtool Sources}), and the @code{nodist_} prefix means the listed
5428 sources are not to be distributed (@pxref{Program and Library
5429 Variables}).  In effect the file @file{dummy.cxx} does not need to
5430 exist in the source tree.  Of course if you have some real source file
5431 to list in @code{libtop_la_SOURCES} there is no point in cheating with
5432 @code{nodist_EXTRA_libtop_la_SOURCES}.
5433
5434
5435 @node Libtool Modules
5436 @subsection Libtool Modules
5437 @cindex modules, libtool
5438 @cindex libtool modules
5439 @cindex @option{-module}, libtool
5440
5441 These are libtool libraries meant to be dlopened.  They are
5442 indicated to libtool by passing @option{-module} at link-time.
5443
5444 @example
5445 pkglib_LTLIBRARIES = mymodule.la
5446 mymodule_la_SOURCES = doit.c
5447 mymodule_la_LDFLAGS = -module
5448 @end example
5449
5450 Ordinarily, Automake requires that a library's name start with
5451 @code{lib}.  However, when building a dynamically loadable module you
5452 might wish to use a "nonstandard" name.  Automake will not complain
5453 about such nonstandard names if it knows the library being built is a
5454 libtool module, i.e., if @option{-module} explicitly appears in the
5455 library's @code{_LDFLAGS} variable (or in the common @code{AM_LDFLAGS}
5456 variable when no per-library @code{_LDFLAGS} variable is defined).
5457
5458 As always, @code{AC_SUBST} variables are black boxes to Automake since
5459 their values are not yet known when @command{automake} is run.
5460 Therefore if @option{-module} is set via such a variable, Automake
5461 cannot notice it and will proceed as if the library was an ordinary
5462 libtool library, with strict naming.
5463
5464 If @code{mymodule_la_SOURCES} is not specified, then it defaults to
5465 the single file @file{mymodule.c} (@pxref{Default _SOURCES}).
5466
5467 @node Libtool Flags
5468 @subsection @code{_LIBADD}, @code{_LDFLAGS}, and @code{_LIBTOOLFLAGS}
5469 @cindex @code{_LIBADD}, libtool
5470 @cindex @code{_LDFLAGS}, libtool
5471 @cindex @code{_LIBTOOLFLAGS}, libtool
5472 @vindex AM_LIBTOOLFLAGS
5473 @vindex LIBTOOLFLAGS
5474 @vindex maude_LIBTOOLFLAGS
5475
5476 As shown in previous sections, the @samp{@var{library}_LIBADD}
5477 variable should be used to list extra libtool objects (@file{.lo}
5478 files) or libtool libraries (@file{.la}) to add to @var{library}.
5479
5480 The @samp{@var{library}_LDFLAGS} variable is the place to list
5481 additional libtool linking flags, such as @option{-version-info},
5482 @option{-static}, and a lot more.  @xref{Link mode, , Link mode,
5483 libtool, The Libtool Manual}.
5484
5485 The @command{libtool} command has two kinds of options: mode-specific
5486 options and generic options.  Mode-specific options such as the
5487 aforementioned linking flags should be lumped with the other flags
5488 passed to the tool invoked by @command{libtool} (hence the use of
5489 @samp{@var{library}_LDFLAGS} for libtool linking flags).  Generic
5490 options include @option{--tag=@var{tag}} and @option{--silent}
5491 (@pxref{Invoking libtool, , Invoking @command{libtool}, libtool, The
5492 Libtool Manual} for more options) should appear before the mode
5493 selection on the command line; in @file{Makefile.am}s they should
5494 be listed in the @samp{@var{library}_LIBTOOLFLAGS} variable.
5495
5496 If @samp{@var{library}_LIBTOOLFLAGS} is not defined, then the variable
5497 @code{AM_LIBTOOLFLAGS} is used instead.
5498
5499 These flags are passed to libtool after the @option{--tag=@var{tag}}
5500 option computed by Automake (if any), so
5501 @samp{@var{library}_LIBTOOLFLAGS} (or @code{AM_LIBTOOLFLAGS}) is a
5502 good place to override or supplement the @option{--tag=@var{tag}}
5503 setting.
5504
5505 The libtool rules also use a @code{LIBTOOLFLAGS} variable that should
5506 not be set in @file{Makefile.am}: this is a user variable (@pxref{Flag
5507 Variables Ordering}.  It allows users to run @samp{make
5508 LIBTOOLFLAGS=--silent}, for instance.  Note that the verbosity of
5509 @command{libtool} can also be influenced with the Automake
5510 @option{silent-rules} option (@pxref{Options}).
5511
5512
5513 @node LTLIBOBJS, Libtool Issues, Libtool Flags, A Shared Library
5514 @subsection @code{LTLIBOBJS} and @code{LTALLOCA}
5515 @cindex @code{LTLIBOBJS}, special handling
5516 @cindex @code{LIBOBJS}, and Libtool
5517 @cindex @code{LTALLOCA}, special handling
5518 @cindex @code{ALLOCA}, and Libtool
5519 @vindex LTLIBOBJS
5520 @vindex LIBOBJS
5521 @vindex LTALLOCA
5522 @vindex ALLOCA
5523 @acindex AC_LIBOBJ
5524
5525 Where an ordinary library might include @samp{$(LIBOBJS)} or
5526 @samp{$(ALLOCA)} (@pxref{LIBOBJS}), a libtool library must use
5527 @samp{$(LTLIBOBJS)} or @samp{$(LTALLOCA)}.  This is required because
5528 the object files that libtool operates on do not necessarily end in
5529 @file{.o}.
5530
5531 Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
5532 performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
5533 @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual}).
5534
5535 @node Libtool Issues
5536 @subsection Common Issues Related to Libtool's Use
5537
5538 @menu
5539 * Error required file ltmain.sh not found::  The need to run libtoolize
5540 * Objects created both with libtool and without::  Avoid a specific build race
5541 @end menu
5542
5543 @node Error required file ltmain.sh not found
5544 @subsubsection Error: @samp{required file `./ltmain.sh' not found}
5545 @cindex @file{ltmain.sh} not found
5546 @cindex @command{libtoolize}, no longer run by @command{automake}
5547 @cindex @command{libtoolize} and @command{autoreconf}
5548 @cindex @command{autoreconf} and @command{libtoolize}
5549 @cindex @file{bootstrap.sh} and @command{autoreconf}
5550 @cindex @file{autogen.sh} and @command{autoreconf}
5551
5552 Libtool comes with a tool called @command{libtoolize} that will
5553 install libtool's supporting files into a package.  Running this
5554 command will install @file{ltmain.sh}.  You should execute it before
5555 @command{aclocal} and @command{automake}.
5556
5557 People upgrading old packages to newer autotools are likely to face
5558 this issue because older Automake versions used to call
5559 @command{libtoolize}.  Therefore old build scripts do not call
5560 @command{libtoolize}.
5561
5562 Since Automake 1.6, it has been decided that running
5563 @command{libtoolize} was none of Automake's business.  Instead, that
5564 functionality has been moved into the @command{autoreconf} command
5565 (@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
5566 The Autoconf Manual}).  If you do not want to remember what to run and
5567 when, just learn the @command{autoreconf} command.  Hopefully,
5568 replacing existing @file{bootstrap.sh} or @file{autogen.sh} scripts by
5569 a call to @command{autoreconf} should also free you from any similar
5570 incompatible change in the future.
5571
5572 @node Objects created both with libtool and without
5573 @subsubsection Objects @samp{created with both libtool and without}
5574
5575 Sometimes, the same source file is used both to build a libtool
5576 library and to build another non-libtool target (be it a program or
5577 another library).
5578
5579 Let's consider the following @file{Makefile.am}.
5580
5581 @example
5582 bin_PROGRAMS = prog
5583 prog_SOURCES = prog.c foo.c @dots{}
5584
5585 lib_LTLIBRARIES = libfoo.la
5586 libfoo_la_SOURCES = foo.c @dots{}
5587 @end example
5588
5589 @noindent
5590 (In this trivial case the issue could be avoided by linking
5591 @file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
5592 @code{prog_SOURCES}.  But let's assume we really want to keep
5593 @file{prog} and @file{libfoo.la} separate.)
5594
5595 Technically, it means that we should build @file{foo.$(OBJEXT)} for
5596 @file{prog}, and @file{foo.lo} for @file{libfoo.la}.  The problem is
5597 that in the course of creating @file{foo.lo}, libtool may erase (or
5598 replace) @file{foo.$(OBJEXT)}, and this cannot be avoided.
5599
5600 Therefore, when Automake detects this situation it will complain
5601 with a message such as
5602 @example
5603 object 'foo.$(OBJEXT)' created both with libtool and without
5604 @end example
5605
5606 A workaround for this issue is to ensure that these two objects get
5607 different basenames.  As explained in @ref{Renamed Objects}, this
5608 happens automatically when per-targets flags are used.
5609
5610 @example
5611 bin_PROGRAMS = prog
5612 prog_SOURCES = prog.c foo.c @dots{}
5613 prog_CFLAGS = $(AM_CFLAGS)
5614
5615 lib_LTLIBRARIES = libfoo.la
5616 libfoo_la_SOURCES = foo.c @dots{}
5617 @end example
5618
5619 @noindent
5620 Adding @samp{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
5621 when the @code{prog_CFLAGS} is defined, it is used instead of
5622 @code{AM_CFLAGS}.  However as a side effect it will cause
5623 @file{prog.c} and @file{foo.c} to be compiled as
5624 @file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)}, which solves
5625 the issue.
5626
5627 @node Program and Library Variables
5628 @section Program and Library Variables
5629
5630 Associated with each program is a collection of variables that can be
5631 used to modify how that program is built.  There is a similar list of
5632 such variables for each library.  The canonical name of the program (or
5633 library) is used as a base for naming these variables.
5634
5635 In the list below, we use the name ``maude'' to refer to the program or
5636 library.  In your @file{Makefile.am} you would replace this with the
5637 canonical name of your program.  This list also refers to ``maude'' as a
5638 program, but in general the same rules apply for both static and dynamic
5639 libraries; the documentation below notes situations where programs and
5640 libraries differ.
5641
5642 @vtable @code
5643 @item maude_SOURCES
5644 This variable, if it exists, lists all the source files that are
5645 compiled to build the program.  These files are added to the
5646 distribution by default.  When building the program, Automake will cause
5647 each source file to be compiled to a single @file{.o} file (or
5648 @file{.lo} when using libtool).  Normally these object files are named
5649 after the source file, but other factors can change this.  If a file in
5650 the @code{_SOURCES} variable has an unrecognized extension, Automake
5651 will do one of two things with it.  If a suffix rule exists for turning
5652 files with the unrecognized extension into @file{.o} files, then
5653 @command{automake} will treat this file as it will any other source file
5654 (@pxref{Support for Other Languages}).  Otherwise, the file will be
5655 ignored as though it were a header file.
5656
5657 The prefixes @code{dist_} and @code{nodist_} can be used to control
5658 whether files listed in a @code{_SOURCES} variable are distributed.
5659 @code{dist_} is redundant, as sources are distributed by default, but it
5660 can be specified for clarity if desired.
5661
5662 It is possible to have both @code{dist_} and @code{nodist_} variants of
5663 a given @code{_SOURCES} variable at once; this lets you easily
5664 distribute some files and not others, for instance:
5665
5666 @example
5667 nodist_maude_SOURCES = nodist.c
5668 dist_maude_SOURCES = dist-me.c
5669 @end example
5670
5671 By default the output file (on Unix systems, the @file{.o} file) will
5672 be put into the current build directory.  However, if the option
5673 @option{subdir-objects} is in effect in the current directory then the
5674 @file{.o} file will be put into the subdirectory named after the
5675 source file.  For instance, with @option{subdir-objects} enabled,
5676 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
5677 people prefer this mode of operation.  You can specify
5678 @option{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
5679 @cindex Subdirectory, objects in
5680 @cindex Objects in subdirectory
5681
5682
5683 @item EXTRA_maude_SOURCES
5684 Automake needs to know the list of files you intend to compile
5685 @emph{statically}.  For one thing, this is the only way Automake has of
5686 knowing what sort of language support a given @file{Makefile.in}
5687 requires.  @footnote{There are other, more obscure reasons for
5688 this limitation as well.}  This means that, for example, you can't put a
5689 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
5690 variable.  If you intend to conditionally compile source files and use
5691 @file{configure} to substitute the appropriate object names into, e.g.,
5692 @code{_LDADD} (see below), then you should list the corresponding source
5693 files in the @code{EXTRA_} variable.
5694
5695 This variable also supports @code{dist_} and @code{nodist_} prefixes.
5696 For instance, @code{nodist_EXTRA_maude_SOURCES} would list extra
5697 sources that may need to be built, but should not be distributed.
5698
5699 @item maude_AR
5700 A static library is created by default by invoking @samp{$(AR)
5701 $(ARFLAGS)} followed by the name of the library and then the objects
5702 being put into the library.  You can override this by setting the
5703 @code{_AR} variable.  This is usually used with C++; some C++
5704 compilers require a special invocation in order to instantiate all the
5705 templates that should go into a library.  For instance, the SGI C++
5706 compiler likes this variable set like so:
5707 @example
5708 libmaude_a_AR = $(CXX) -ar -o
5709 @end example
5710
5711 @item maude_LIBADD
5712 Extra objects can be added to a @emph{library} using the @code{_LIBADD}
5713 variable.  For instance, this should be used for objects determined by
5714 @command{configure} (@pxref{A Library}).
5715
5716 In the case of libtool libraries, @code{maude_LIBADD} can also refer
5717 to other libtool libraries.
5718
5719 @item maude_LDADD
5720 Extra objects (@file{*.$(OBJEXT)}) and libraries (@file{*.a},
5721 @file{*.la}) can be added to a @emph{program} by listing them in the
5722 @code{_LDADD} variable.  For instance, this should be used for objects
5723 determined by @command{configure} (@pxref{Linking}).
5724
5725 @code{_LDADD} and @code{_LIBADD} are inappropriate for passing
5726 program-specific linker flags (except for @option{-l}, @option{-L},
5727 @option{-dlopen} and @option{-dlpreopen}).  Use the @code{_LDFLAGS} variable
5728 for this purpose.
5729
5730 For instance, if your @file{configure.ac} uses @code{AC_PATH_XTRA}, you
5731 could link your program against the X libraries like so:
5732
5733 @example
5734 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
5735 @end example
5736
5737 We recommend that you use @option{-l} and @option{-L} only when
5738 referring to third-party libraries, and give the explicit file names
5739 of any library built by your package.  Doing so will ensure that
5740 @code{maude_DEPENDENCIES} (see below) is correctly defined by default.
5741
5742 @item maude_LDFLAGS
5743 This variable is used to pass extra flags to the link step of a program
5744 or a shared library.  It overrides the @code{AM_LDFLAGS} variable.
5745
5746 @item maude_LIBTOOLFLAGS
5747 This variable is used to pass extra options to @command{libtool}.
5748 It overrides the @code{AM_LIBTOOLFLAGS} variable.
5749 These options are output before @command{libtool}'s @option{--mode=@var{mode}}
5750 option, so they should not be mode-specific options (those belong to
5751 the compiler or linker flags).  @xref{Libtool Flags}.
5752
5753 @item maude_DEPENDENCIES
5754 @itemx EXTRA_maude_DEPENDENCIES
5755 It is also occasionally useful to have a target (program or library)
5756 depend on some other file that is not actually part of that target.
5757 This can be done using the @code{_DEPENDENCIES} variable.  Each
5758 target depends on the contents of such a variable, but no further
5759 interpretation is done.
5760
5761 Since these dependencies are associated to the link rule used to
5762 create the programs they should normally list files used by the link
5763 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la} files
5764 for programs; @file{*.lo} and @file{*.la} files for Libtool libraries;
5765 and @file{*.$(OBJEXT)} files for static libraries.  In rare cases you
5766 may need to add other kinds of files such as linker scripts, but
5767 @emph{listing a source file in @code{_DEPENDENCIES} is wrong}.  If
5768 some source file needs to be built before all the components of a
5769 program are built, consider using the @code{BUILT_SOURCES} variable
5770 (@pxref{Sources}).
5771
5772 If @code{_DEPENDENCIES} is not supplied, it is computed by Automake.
5773 The automatically-assigned value is the contents of @code{_LDADD} or
5774 @code{_LIBADD}, with most configure substitutions, @option{-l}, @option{-L},
5775 @option{-dlopen} and @option{-dlpreopen} options removed.  The configure
5776 substitutions that are left in are only @samp{$(LIBOBJS)} and
5777 @samp{$(ALLOCA)}; these are left because it is known that they will not
5778 cause an invalid value for @code{_DEPENDENCIES} to be generated.
5779
5780 @code{_DEPENDENCIES} is more likely used to perform conditional
5781 compilation using an @code{AC_SUBST} variable that contains a list of
5782 objects.  @xref{Conditional Sources}, and @ref{Conditional Libtool
5783 Sources}.
5784
5785 The @code{EXTRA_*_DEPENDENCIES} variable may be useful for cases where
5786 you merely want to augment the @command{automake}-generated
5787 @code{_DEPENDENCIES} variable rather than replacing it.
5788
5789 @item maude_LINK
5790 You can override the linker on a per-program basis.  By default the
5791 linker is chosen according to the languages used by the program.  For
5792 instance, a program that includes C++ source code would use the C++
5793 compiler to link.  The @code{_LINK} variable must hold the name of a
5794 command that can be passed all the @file{.o} file names and libraries
5795 to link against as arguments.  Note that the name of the underlying
5796 program is @emph{not} passed to @code{_LINK}; typically one uses
5797 @samp{$@@}:
5798
5799 @example
5800 maude_LINK = $(CCLD) -magic -o $@@
5801 @end example
5802
5803 If a @code{_LINK} variable is not supplied, it may still be generated
5804 and used by Automake due to the use of per-target link flags such as
5805 @code{_CFLAGS}, @code{_LDFLAGS} or @code{_LIBTOOLFLAGS}, in cases where
5806 they apply.
5807
5808 @item maude_CCASFLAGS
5809 @itemx maude_CFLAGS
5810 @itemx maude_CPPFLAGS
5811 @itemx maude_CXXFLAGS
5812 @itemx maude_FFLAGS
5813 @itemx maude_GCJFLAGS
5814 @itemx maude_LFLAGS
5815 @itemx maude_OBJCFLAGS
5816 @itemx maude_OBJCXXFLAGS
5817 @itemx maude_RFLAGS
5818 @itemx maude_UPCFLAGS
5819 @itemx maude_YFLAGS
5820 @cindex per-target compilation flags, defined
5821 Automake allows you to set compilation flags on a per-program (or
5822 per-library) basis.  A single source file can be included in several
5823 programs, and it will potentially be compiled with different flags for
5824 each program.  This works for any language directly supported by
5825 Automake.  These @dfn{per-target compilation flags} are
5826 @samp{_CCASFLAGS},
5827 @samp{_CFLAGS},
5828 @samp{_CPPFLAGS},
5829 @samp{_CXXFLAGS},
5830 @samp{_FFLAGS},
5831 @samp{_GCJFLAGS},
5832 @samp{_LFLAGS},
5833 @samp{_OBJCFLAGS},
5834 @samp{_OBJCXXFLAGS},
5835 @samp{_RFLAGS},
5836 @samp{_UPCFLAGS}, and
5837 @samp{_YFLAGS}.
5838
5839 When using a per-target compilation flag, Automake will choose a
5840 different name for the intermediate object files.  Ordinarily a file
5841 like @file{sample.c} will be compiled to produce @file{sample.o}.
5842 However, if the program's @code{_CFLAGS} variable is set, then the
5843 object file will be named, for instance, @file{maude-sample.o}.  (See
5844 also @ref{Renamed Objects}.)  The use of per-target compilation flags
5845 with C sources requires that the macro @code{AM_PROG_CC_C_O} be called
5846 from @file{configure.ac}.
5847
5848 In compilations with per-target flags, the ordinary @samp{AM_} form of
5849 the flags variable is @emph{not} automatically included in the
5850 compilation (however, the user form of the variable @emph{is} included).
5851 So for instance, if you want the hypothetical @file{maude} compilations
5852 to also use the value of @code{AM_CFLAGS}, you would need to write:
5853
5854 @example
5855 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
5856 @end example
5857
5858 @xref{Flag Variables Ordering}, for more discussion about the
5859 interaction between user variables, @samp{AM_} shadow variables, and
5860 per-target variables.
5861
5862 @item maude_SHORTNAME
5863 On some platforms the allowable file names are very short.  In order to
5864 support these systems and per-target compilation flags at the same
5865 time, Automake allows you to set a ``short name'' that will influence
5866 how intermediate object files are named.  For instance, in the following
5867 example,
5868
5869 @example
5870 bin_PROGRAMS = maude
5871 maude_CPPFLAGS = -DSOMEFLAG
5872 maude_SHORTNAME = m
5873 maude_SOURCES = sample.c @dots{}
5874 @end example
5875
5876 @noindent
5877 the object file would be named @file{m-sample.o} rather than
5878 @file{maude-sample.o}.
5879
5880 This facility is rarely needed in practice,
5881 and we recommend avoiding it until you find it is required.
5882 @end vtable
5883
5884 @node Default _SOURCES
5885 @section Default @code{_SOURCES}
5886
5887 @vindex _SOURCES
5888 @vindex SOURCES
5889 @cindex @code{_SOURCES}, default
5890 @cindex default @code{_SOURCES}
5891 @vindex AM_DEFAULT_SOURCE_EXT
5892
5893 @code{_SOURCES} variables are used to specify source files of programs
5894 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
5895 libraries (@pxref{A Shared Library}).
5896
5897 When no such variable is specified for a target, Automake will define
5898 one itself.  The default is to compile a single C file whose base name
5899 is the name of the target itself, with any extension replaced by
5900 @code{AM_DEFAULT_SOURCE_EXT}, which defaults to @file{.c}.
5901
5902 For example if you have the following somewhere in your
5903 @file{Makefile.am} with no corresponding @code{libfoo_a_SOURCES}:
5904
5905 @example
5906 lib_LIBRARIES = libfoo.a sub/libc++.a
5907 @end example
5908
5909 @noindent
5910 @file{libfoo.a} will be built using a default source file named
5911 @file{libfoo.c}, and @file{sub/libc++.a} will be built from
5912 @file{sub/libc++.c}.  (In older versions @file{sub/libc++.a}
5913 would be built from @file{sub_libc___a.c}, i.e., the default source
5914 was the canonized name of the target, with @file{.c} appended.
5915 We believe the new behavior is more sensible, but for backward
5916 compatibility @command{automake} will use the old name if a file or a rule
5917 with that name exists and @code{AM_DEFAULT_SOURCE_EXT} is not used.)
5918
5919 @cindex @code{check_PROGRAMS} example
5920 @vindex check_PROGRAMS
5921 Default sources are mainly useful in test suites, when building many
5922 test programs each from a single source.  For instance, in
5923
5924 @example
5925 check_PROGRAMS = test1 test2 test3
5926 AM_DEFAULT_SOURCE_EXT = .cpp
5927 @end example
5928
5929 @noindent
5930 @file{test1}, @file{test2}, and @file{test3} will be built
5931 from @file{test1.cpp}, @file{test2.cpp}, and @file{test3.cpp}.
5932 Without the last line, they will be built from @file{test1.c},
5933 @file{test2.c}, and @file{test3.c}.
5934
5935 @cindex Libtool modules, default source example
5936 @cindex default source, Libtool modules example
5937 Another case where this is convenient is building many Libtool modules
5938 (@file{module@var{n}.la}), each defined in its own file
5939 (@file{module@var{n}.c}).
5940
5941 @example
5942 AM_LDFLAGS = -module
5943 lib_LTLIBRARIES = module1.la module2.la module3.la
5944 @end example
5945
5946 @cindex empty @code{_SOURCES}
5947 @cindex @code{_SOURCES}, empty
5948 Finally, there is one situation where this default source computation
5949 needs to be avoided: when a target should not be built from sources.
5950 We already saw such an example in @ref{true}; this happens when all
5951 the constituents of a target have already been compiled and just need
5952 to be combined using a @code{_LDADD} variable.  Then it is necessary
5953 to define an empty @code{_SOURCES} variable, so that @command{automake}
5954 does not compute a default.
5955
5956 @example
5957 bin_PROGRAMS = target
5958 target_SOURCES =
5959 target_LDADD = libmain.a libmisc.a
5960 @end example
5961
5962 @node LIBOBJS
5963 @section Special handling for @code{LIBOBJS} and @code{ALLOCA}
5964
5965 @cindex @code{LIBOBJS}, example
5966 @cindex @code{ALLOCA}, example
5967 @cindex @code{LIBOBJS}, special handling
5968 @cindex @code{ALLOCA}, special handling
5969 @vindex LTLIBOBJS
5970 @vindex LIBOBJS
5971 @vindex LTALLOCA
5972 @vindex ALLOCA
5973
5974 The @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} variables list object
5975 files that should be compiled into the project to provide an
5976 implementation for functions that are missing or broken on the host
5977 system.  They are substituted by @file{configure}.
5978
5979 @acindex AC_LIBOBJ
5980
5981 These variables are defined by Autoconf macros such as
5982 @code{AC_LIBOBJ}, @code{AC_REPLACE_FUNCS} (@pxref{Generic Functions, ,
5983 Generic Function Checks, autoconf, The Autoconf Manual}), or
5984 @code{AC_FUNC_ALLOCA} (@pxref{Particular Functions, , Particular
5985 Function Checks, autoconf, The Autoconf Manual}).  Many other Autoconf
5986 macros call @code{AC_LIBOBJ} or @code{AC_REPLACE_FUNCS} to
5987 populate @samp{$(LIBOBJS)}.
5988
5989 @acindex AC_LIBSOURCE
5990
5991 Using these variables is very similar to doing conditional compilation
5992 using @code{AC_SUBST} variables, as described in @ref{Conditional
5993 Sources}.  That is, when building a program, @samp{$(LIBOBJS)} and
5994 @samp{$(ALLOCA)} should be added to the associated @samp{*_LDADD}
5995 variable, or to the @samp{*_LIBADD} variable when building a library.
5996 However there is no need to list the corresponding sources in
5997 @samp{EXTRA_*_SOURCES} nor to define @samp{*_DEPENDENCIES}.  Automake
5998 automatically adds @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} to the
5999 dependencies, and it will discover the list of corresponding source
6000 files automatically (by tracing the invocations of the
6001 @code{AC_LIBSOURCE} Autoconf macros).  If you have already defined
6002 @samp{*_DEPENDENCIES} explicitly for an unrelated reason, then you
6003 either need to add these variables manually, or use
6004 @samp{EXTRA_*_DEPENDENCIES} instead of @samp{*_DEPENDENCIES}.
6005
6006 These variables are usually used to build a portability library that
6007 is linked with all the programs of the project.  We now review a
6008 sample setup.  First, @file{configure.ac} contains some checks that
6009 affect either @code{LIBOBJS} or @code{ALLOCA}.
6010
6011 @example
6012 # configure.ac
6013 @dots{}
6014 AC_CONFIG_LIBOBJ_DIR([lib])
6015 @dots{}
6016 AC_FUNC_MALLOC             dnl May add malloc.$(OBJEXT) to LIBOBJS
6017 AC_FUNC_MEMCMP             dnl May add memcmp.$(OBJEXT) to LIBOBJS
6018 AC_REPLACE_FUNCS([strdup]) dnl May add strdup.$(OBJEXT) to LIBOBJS
6019 AC_FUNC_ALLOCA             dnl May add alloca.$(OBJEXT) to ALLOCA
6020 @dots{}
6021 AC_CONFIG_FILES([
6022   lib/Makefile
6023   src/Makefile
6024 ])
6025 AC_OUTPUT
6026 @end example
6027
6028 @acindex AC_CONFIG_LIBOBJ_DIR
6029
6030 The @code{AC_CONFIG_LIBOBJ_DIR} tells Autoconf that the source files
6031 of these object files are to be found in the @file{lib/} directory.
6032 Automake can also use this information, otherwise it expects the
6033 source files are to be in the directory where the @samp{$(LIBOBJS)}
6034 and @samp{$(ALLOCA)} variables are used.
6035
6036 The @file{lib/} directory should therefore contain @file{malloc.c},
6037 @file{memcmp.c}, @file{strdup.c}, @file{alloca.c}.  Here is its
6038 @file{Makefile.am}:
6039
6040 @example
6041 # lib/Makefile.am
6042
6043 noinst_LIBRARIES = libcompat.a
6044 libcompat_a_SOURCES =
6045 libcompat_a_LIBADD = $(LIBOBJS) $(ALLOCA)
6046 @end example
6047
6048 The library can have any name, of course, and anyway it is not going
6049 to be installed: it just holds the replacement versions of the missing
6050 or broken functions so we can later link them in.  Many projects
6051 also include extra functions, specific to the project, in that
6052 library: they are simply added on the @code{_SOURCES} line.
6053
6054 @cindex Empty libraries and @samp{$(LIBOBJS)}
6055 @cindex @samp{$(LIBOBJS)} and empty libraries
6056 There is a small trap here, though: @samp{$(LIBOBJS)} and
6057 @samp{$(ALLOCA)} might be empty, and building an empty library is not
6058 portable.  You should ensure that there is always something to put in
6059 @file{libcompat.a}.  Most projects will also add some utility
6060 functions in that directory, and list them in
6061 @code{libcompat_a_SOURCES}, so in practice @file{libcompat.a} cannot
6062 be empty.
6063
6064 Finally here is how this library could be used from the @file{src/}
6065 directory.
6066
6067 @example
6068 # src/Makefile.am
6069
6070 # Link all programs in this directory with libcompat.a
6071 LDADD = ../lib/libcompat.a
6072
6073 bin_PROGRAMS = tool1 tool2 @dots{}
6074 tool1_SOURCES = @dots{}
6075 tool2_SOURCES = @dots{}
6076 @end example
6077
6078 When option @option{subdir-objects} is not used, as in the above
6079 example, the variables @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} can only
6080 be used in the directory where their sources lie.  E.g., here it would
6081 be wrong to use @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} in
6082 @file{src/Makefile.am}.  However if both @option{subdir-objects} and
6083 @code{AC_CONFIG_LIBOBJ_DIR} are used, it is OK to use these variables
6084 in other directories.  For instance @file{src/Makefile.am} could be
6085 changed as follows.
6086
6087 @example
6088 # src/Makefile.am
6089
6090 AUTOMAKE_OPTIONS = subdir-objects
6091 LDADD = $(LIBOBJS) $(ALLOCA)
6092
6093 bin_PROGRAMS = tool1 tool2 @dots{}
6094 tool1_SOURCES = @dots{}
6095 tool2_SOURCES = @dots{}
6096 @end example
6097
6098 Because @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} contain object
6099 file names that end with @samp{.$(OBJEXT)}, they are not suitable for
6100 Libtool libraries (where the expected object extension is @file{.lo}):
6101 @code{LTLIBOBJS} and @code{LTALLOCA} should be used instead.
6102
6103 @code{LTLIBOBJS} is defined automatically by Autoconf and should not
6104 be defined by hand (as in the past), however at the time of writing
6105 @code{LTALLOCA} still needs to be defined from @code{ALLOCA} manually.
6106 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
6107 autoconf, The Autoconf Manual}.
6108
6109
6110 @node Program Variables
6111 @section Variables used when building a program
6112
6113 Occasionally it is useful to know which @file{Makefile} variables
6114 Automake uses for compilations, and in which order (@pxref{Flag
6115 Variables Ordering}); for instance, you might need to do your own
6116 compilation in some special cases.
6117
6118 Some variables are inherited from Autoconf; these are @code{CC},
6119 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
6120 @code{LIBS}.
6121 @vindex CC
6122 @vindex CFLAGS
6123 @vindex CPPFLAGS
6124 @vindex DEFS
6125 @vindex LDFLAGS
6126 @vindex LIBS
6127
6128 There are some additional variables that Automake defines on its own:
6129
6130 @vtable @code
6131 @item AM_CPPFLAGS
6132 The contents of this variable are passed to every compilation that invokes
6133 the C preprocessor; it is a list of arguments to the preprocessor.  For
6134 instance, @option{-I} and @option{-D} options should be listed here.
6135
6136 Automake already provides some @option{-I} options automatically, in a
6137 separate variable that is also passed to every compilation that invokes
6138 the C preprocessor.  In particular it generates @samp{-I.},
6139 @samp{-I$(srcdir)}, and a @option{-I} pointing to the directory holding
6140 @file{config.h} (if you've used @code{AC_CONFIG_HEADERS} or
6141 @code{AM_CONFIG_HEADER}).  You can disable the default @option{-I}
6142 options using the @option{nostdinc} option.
6143
6144 When a file to be included is generated during the build and not part
6145 of a distribution tarball, its location is under @code{$(builddir)},
6146 not under @code{$(srcdir)}.  This matters especially for packages that
6147 use header files placed in sub-directories and want to allow builds
6148 outside the source tree (@pxref{VPATH Builds}). In that case we
6149 recommend to use a pair of @option{-I} options, such as, e.g.,
6150 @samp{-Isome/subdir -I$(srcdir)/some/subdir} or
6151 @samp{-I$(top_builddir)/some/subdir -I$(top_srcdir)/some/subdir}.
6152 Note that the reference to the build tree should come before the
6153 reference to the source tree, so that accidentally leftover generated
6154 files in the source directory are ignored.
6155
6156 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
6157 per-library) @code{_CPPFLAGS} variable if it is defined.
6158
6159 @item INCLUDES
6160 This does the same job as @code{AM_CPPFLAGS} (or any per-target
6161 @code{_CPPFLAGS} variable if it is used).  It is an older name for the
6162 same functionality.  This variable is deprecated; we suggest using
6163 @code{AM_CPPFLAGS} and per-target @code{_CPPFLAGS} instead.
6164
6165 @item AM_CFLAGS
6166 This is the variable the @file{Makefile.am} author can use to pass
6167 in additional C compiler flags.  It is more fully documented elsewhere.
6168 In some situations, this is not used, in preference to the
6169 per-executable (or per-library) @code{_CFLAGS}.
6170
6171 @item COMPILE
6172 This is the command used to actually compile a C source file.  The
6173 file name is appended to form the complete command line.
6174
6175 @item AM_LDFLAGS
6176 This is the variable the @file{Makefile.am} author can use to pass
6177 in additional linker flags.  In some situations, this is not used, in
6178 preference to the per-executable (or per-library) @code{_LDFLAGS}.
6179
6180 @item LINK
6181 This is the command used to actually link a C program.  It already
6182 includes @samp{-o $@@} and the usual variable references (for instance,
6183 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
6184 and libraries to link in.  This variable is not used when the linker is
6185 overridden with a per-target @code{_LINK} variable or per-target flags
6186 cause Automake to define such a @code{_LINK} variable.
6187 @end vtable
6188
6189
6190 @node Yacc and Lex
6191 @section Yacc and Lex support
6192
6193 Automake has somewhat idiosyncratic support for Yacc and Lex.
6194
6195 Automake assumes that the @file{.c} file generated by @command{yacc}
6196 (or @command{lex}) should be named using the basename of the input
6197 file.  That is, for a yacc source file @file{foo.y}, Automake will
6198 cause the intermediate file to be named @file{foo.c} (as opposed to
6199 @file{y.tab.c}, which is more traditional).
6200
6201 The extension of a yacc source file is used to determine the extension
6202 of the resulting C or C++ source and header files.  Note that header
6203 files are generated only when the @option{-d} Yacc option is used; see
6204 below for more information about this flag, and how to specify it.
6205 Files with the extension @file{.y} will thus be turned into @file{.c}
6206 sources and @file{.h} headers; likewise, @file{.yy} will become
6207 @file{.cc} and @file{.hh}, @file{.y++} will become @file{c++} and
6208 @file{h++}, @file{.yxx} will become @file{.cxx} and @file{.hxx},
6209 and @file{.ypp} will become @file{.cpp} and @file{.hpp}.
6210
6211 Similarly, lex source files can be used to generate C or C++; the
6212 extensions @file{.l}, @file{.ll}, @file{.l++}, @file{.lxx}, and
6213 @file{.lpp} are recognized.
6214
6215 You should never explicitly mention the intermediate (C or C++) file
6216 in any @code{SOURCES} variable; only list the source file.
6217
6218 The intermediate files generated by @command{yacc} (or @command{lex})
6219 will be included in any distribution that is made.  That way the user
6220 doesn't need to have @command{yacc} or @command{lex}.
6221
6222 If a @command{yacc} source file is seen, then your @file{configure.ac} must
6223 define the variable @code{YACC}.  This is most easily done by invoking
6224 the macro @code{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
6225 Program Checks, autoconf, The Autoconf Manual}).
6226
6227 @vindex YFLAGS
6228 @vindex AM_YFLAGS
6229 When @code{yacc} is invoked, it is passed @code{AM_YFLAGS} and
6230 @code{YFLAGS}.  The latter is a user variable and the former is
6231 intended for the @file{Makefile.am} author.
6232
6233 @code{AM_YFLAGS} is usually used to pass the @option{-d} option to
6234 @command{yacc}.  Automake knows what this means and will automatically
6235 adjust its rules to update and distribute the header file built by
6236 @samp{yacc -d}@footnote{Please note that @command{automake} recognizes
6237 @option{-d} in @code{AM_YFLAGS} only if it is not clustered with other
6238 options; for example, it won't be recognized if @code{AM_YFLAGS} is
6239 @option{-dt}, but it will be if @code{AM_YFLAGS} is @option{-d -t} or
6240 @option{-t -d}.}.
6241 What Automake cannot guess, though, is where this
6242 header will be used: it is up to you to ensure the header gets built
6243 before it is first used.  Typically this is necessary in order for
6244 dependency tracking to work when the header is included by another
6245 file.  The common solution is listing the header file in
6246 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
6247
6248 @example
6249 BUILT_SOURCES = parser.h
6250 AM_YFLAGS = -d
6251 bin_PROGRAMS = foo
6252 foo_SOURCES = @dots{} parser.y @dots{}
6253 @end example
6254
6255 If a @command{lex} source file is seen, then your @file{configure.ac}
6256 must define the variable @code{LEX}.  You can use @code{AC_PROG_LEX}
6257 to do this (@pxref{Particular Programs, , Particular Program Checks,
6258 autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
6259 (@pxref{Macros}) is recommended.
6260
6261 @vindex LFLAGS
6262 @vindex AM_LFLAGS
6263 When @command{lex} is invoked, it is passed @code{AM_LFLAGS} and
6264 @code{LFLAGS}.  The latter is a user variable and the former is
6265 intended for the @file{Makefile.am} author.
6266
6267 When @code{AM_MAINTAINER_MODE} (@pxref{maintainer-mode}) is used, the
6268 rebuild rule for distributed Yacc and Lex sources are only used when
6269 @code{maintainer-mode} is enabled, or when the files have been erased.
6270
6271 @cindex @command{ylwrap}
6272 @cindex @command{yacc}, multiple parsers
6273 @cindex Multiple @command{yacc} parsers
6274 @cindex Multiple @command{lex} lexers
6275 @cindex @command{lex}, multiple lexers
6276
6277 When @command{lex} or @command{yacc} sources are used, @code{automake
6278 -i} automatically installs an auxiliary program called
6279 @command{ylwrap} in your package (@pxref{Auxiliary Programs}).  This
6280 program is used by the build rules to rename the output of these
6281 tools, and makes it possible to include multiple @command{yacc} (or
6282 @command{lex}) source files in a single directory.  (This is necessary
6283 because yacc's output file name is fixed, and a parallel make could
6284 conceivably invoke more than one instance of @command{yacc}
6285 simultaneously.)
6286
6287 For @command{yacc}, simply managing locking is insufficient.  The output of
6288 @command{yacc} always uses the same symbol names internally, so it isn't
6289 possible to link two @command{yacc} parsers into the same executable.
6290
6291 We recommend using the following renaming hack used in @command{gdb}:
6292 @example
6293 #define yymaxdepth c_maxdepth
6294 #define yyparse c_parse
6295 #define yylex   c_lex
6296 #define yyerror c_error
6297 #define yylval  c_lval
6298 #define yychar  c_char
6299 #define yydebug c_debug
6300 #define yypact  c_pact
6301 #define yyr1    c_r1
6302 #define yyr2    c_r2
6303 #define yydef   c_def
6304 #define yychk   c_chk
6305 #define yypgo   c_pgo
6306 #define yyact   c_act
6307 #define yyexca  c_exca
6308 #define yyerrflag c_errflag
6309 #define yynerrs c_nerrs
6310 #define yyps    c_ps
6311 #define yypv    c_pv
6312 #define yys     c_s
6313 #define yy_yys  c_yys
6314 #define yystate c_state
6315 #define yytmp   c_tmp
6316 #define yyv     c_v
6317 #define yy_yyv  c_yyv
6318 #define yyval   c_val
6319 #define yylloc  c_lloc
6320 #define yyreds  c_reds
6321 #define yytoks  c_toks
6322 #define yylhs   c_yylhs
6323 #define yylen   c_yylen
6324 #define yydefred c_yydefred
6325 #define yydgoto  c_yydgoto
6326 #define yysindex c_yysindex
6327 #define yyrindex c_yyrindex
6328 #define yygindex c_yygindex
6329 #define yytable  c_yytable
6330 #define yycheck  c_yycheck
6331 #define yyname   c_yyname
6332 #define yyrule   c_yyrule
6333 @end example
6334
6335 For each define, replace the @samp{c_} prefix with whatever you like.
6336 These defines work for @command{bison}, @command{byacc}, and
6337 traditional @code{yacc}s.  If you find a parser generator that uses a
6338 symbol not covered here, please report the new name so it can be added
6339 to the list.
6340
6341
6342 @node C++ Support
6343 @section C++ Support
6344
6345 @cindex C++ support
6346 @cindex Support for C++
6347
6348 Automake includes full support for C++.
6349
6350 Any package including C++ code must define the output variable
6351 @code{CXX} in @file{configure.ac}; the simplest way to do this is to use
6352 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
6353 Program Checks, autoconf, The Autoconf Manual}).
6354
6355 A few additional variables are defined when a C++ source file is seen:
6356
6357 @vtable @code
6358 @item CXX
6359 The name of the C++ compiler.
6360
6361 @item CXXFLAGS
6362 Any flags to pass to the C++ compiler.
6363
6364 @item AM_CXXFLAGS
6365 The maintainer's variant of @code{CXXFLAGS}.
6366
6367 @item CXXCOMPILE
6368 The command used to actually compile a C++ source file.  The file name
6369 is appended to form the complete command line.
6370
6371 @item CXXLINK
6372 The command used to actually link a C++ program.
6373 @end vtable
6374
6375
6376 @node Objective C Support
6377 @section Objective C Support
6378
6379 @cindex Objective C support
6380 @cindex Support for Objective C
6381
6382 Automake includes some support for Objective C.
6383
6384 Any package including Objective C code must define the output variable
6385 @code{OBJC} in @file{configure.ac}; the simplest way to do this is to use
6386 the @code{AC_PROG_OBJC} macro (@pxref{Particular Programs, , Particular
6387 Program Checks, autoconf, The Autoconf Manual}).
6388
6389 A few additional variables are defined when an Objective C source file
6390 is seen:
6391
6392 @vtable @code
6393 @item OBJC
6394 The name of the Objective C compiler.
6395
6396 @item OBJCFLAGS
6397 Any flags to pass to the Objective C compiler.
6398
6399 @item AM_OBJCFLAGS
6400 The maintainer's variant of @code{OBJCFLAGS}.
6401
6402 @item OBJCCOMPILE
6403 The command used to actually compile an Objective C source file.  The
6404 file name is appended to form the complete command line.
6405
6406 @item OBJCLINK
6407 The command used to actually link an Objective C program.
6408 @end vtable
6409
6410
6411 @node Objective C++ Support
6412 @section Objective C++ Support
6413
6414 @cindex Objective C++ support
6415 @cindex Support for Objective C++
6416
6417 Automake includes some support for Objective C++.
6418
6419 Any package including Objective C++ code must define the output variable
6420 @code{OBJCXX} in @file{configure.ac}; the simplest way to do this is to use
6421 the @code{AC_PROG_OBJCXX} macro (@pxref{Particular Programs, , Particular
6422 Program Checks, autoconf, The Autoconf Manual}).
6423
6424 A few additional variables are defined when an Objective C++ source file
6425 is seen:
6426
6427 @vtable @code
6428 @item OBJCXX
6429 The name of the Objective C++ compiler.
6430
6431 @item OBJCXXFLAGS
6432 Any flags to pass to the Objective C++ compiler.
6433
6434 @item AM_OBJCXXFLAGS
6435 The maintainer's variant of @code{OBJCXXFLAGS}.
6436
6437 @item OBJCXXCOMPILE
6438 The command used to actually compile an Objective C++ source file.  The
6439 file name is appended to form the complete command line.
6440
6441 @item OBJCXXLINK
6442 The command used to actually link an Objective C++ program.
6443 @end vtable
6444
6445
6446 @node Unified Parallel C Support
6447 @section Unified Parallel C Support
6448
6449 @cindex Unified Parallel C support
6450 @cindex Support for Unified Parallel C
6451
6452 Automake includes some support for Unified Parallel C.
6453
6454 Any package including Unified Parallel C code must define the output
6455 variable @code{UPC} in @file{configure.ac}; the simplest way to do
6456 this is to use the @code{AM_PROG_UPC} macro (@pxref{Public Macros}).
6457
6458 A few additional variables are defined when a Unified Parallel C
6459 source file is seen:
6460
6461 @vtable @code
6462 @item UPC
6463 The name of the Unified Parallel C compiler.
6464
6465 @item UPCFLAGS
6466 Any flags to pass to the Unified Parallel C compiler.
6467
6468 @item AM_UPCFLAGS
6469 The maintainer's variant of @code{UPCFLAGS}.
6470
6471 @item UPCCOMPILE
6472 The command used to actually compile a Unified Parallel C source file.
6473 The file name is appended to form the complete command line.
6474
6475 @item UPCLINK
6476 The command used to actually link a Unified Parallel C program.
6477 @end vtable
6478
6479
6480 @node Assembly Support
6481 @section Assembly Support
6482
6483 Automake includes some support for assembly code.  There are two forms
6484 of assembler files: normal (@file{*.s}) and preprocessed by @code{CPP}
6485 (@file{*.S} or @file{*.sx}).
6486
6487 @vindex CCAS
6488 @vindex CCASFLAGS
6489 @vindex CPPFLAGS
6490 @vindex AM_CCASFLAGS
6491 @vindex AM_CPPFLAGS
6492 The variable @code{CCAS} holds the name of the compiler used to build
6493 assembly code.  This compiler must work a bit like a C compiler; in
6494 particular it must accept @option{-c} and @option{-o}.  The values of
6495 @code{CCASFLAGS} and @code{AM_CCASFLAGS} (or its per-target
6496 definition) is passed to the compilation.  For preprocessed files,
6497 @code{DEFS}, @code{DEFAULT_INCLUDES}, @code{INCLUDES}, @code{CPPFLAGS}
6498 and @code{AM_CPPFLAGS} are also used.
6499
6500 The autoconf macro @code{AM_PROG_AS} will define @code{CCAS} and
6501 @code{CCASFLAGS} for you (unless they are already set, it simply sets
6502 @code{CCAS} to the C compiler and @code{CCASFLAGS} to the C compiler
6503 flags), but you are free to define these variables by other means.
6504
6505 Only the suffixes @file{.s}, @file{.S}, and @file{.sx} are recognized by
6506 @command{automake} as being files containing assembly code.
6507
6508
6509 @node Fortran 77 Support
6510 @comment  node-name,  next,  previous,  up
6511 @section Fortran 77 Support
6512
6513 @cindex Fortran 77 support
6514 @cindex Support for Fortran 77
6515
6516 Automake includes full support for Fortran 77.
6517
6518 Any package including Fortran 77 code must define the output variable
6519 @code{F77} in @file{configure.ac}; the simplest way to do this is to use
6520 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
6521 Program Checks, autoconf, The Autoconf Manual}).
6522
6523 A few additional variables are defined when a Fortran 77 source file is
6524 seen:
6525
6526 @vtable @code
6527
6528 @item F77
6529 The name of the Fortran 77 compiler.
6530
6531 @item FFLAGS
6532 Any flags to pass to the Fortran 77 compiler.
6533
6534 @item AM_FFLAGS
6535 The maintainer's variant of @code{FFLAGS}.
6536
6537 @item RFLAGS
6538 Any flags to pass to the Ratfor compiler.
6539
6540 @item AM_RFLAGS
6541 The maintainer's variant of @code{RFLAGS}.
6542
6543 @item F77COMPILE
6544 The command used to actually compile a Fortran 77 source file.  The file
6545 name is appended to form the complete command line.
6546
6547 @item FLINK
6548 The command used to actually link a pure Fortran 77 program or shared
6549 library.
6550
6551 @end vtable
6552
6553 Automake can handle preprocessing Fortran 77 and Ratfor source files in
6554 addition to compiling them@footnote{Much, if not most, of the
6555 information in the following sections pertaining to preprocessing
6556 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
6557 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
6558 also contains some support for creating programs and shared libraries
6559 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
6560 Fortran 77 With C and C++}).
6561
6562 These issues are covered in the following sections.
6563
6564 @menu
6565 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
6566 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
6567 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
6568 @end menu
6569
6570
6571 @node Preprocessing Fortran 77
6572 @comment  node-name,  next,  previous,  up
6573 @subsection Preprocessing Fortran 77
6574
6575 @cindex Preprocessing Fortran 77
6576 @cindex Fortran 77, Preprocessing
6577 @cindex Ratfor programs
6578
6579 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
6580 rule runs just the preprocessor to convert a preprocessable Fortran 77
6581 or Ratfor source file into a strict Fortran 77 source file.  The precise
6582 command used is as follows:
6583
6584 @table @file
6585
6586 @item .F
6587 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6588 $(AM_FFLAGS) $(FFLAGS)}
6589
6590 @item .r
6591 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6592
6593 @end table
6594
6595
6596 @node Compiling Fortran 77 Files
6597 @comment  node-name,  next,  previous,  up
6598 @subsection Compiling Fortran 77 Files
6599
6600 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
6601 @file{N.r} by running the Fortran 77 compiler.  The precise command used
6602 is as follows:
6603
6604 @table @file
6605
6606 @item .f
6607 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
6608
6609 @item .F
6610 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6611 $(AM_FFLAGS) $(FFLAGS)}
6612
6613 @item .r
6614 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6615
6616 @end table
6617
6618
6619 @node Mixing Fortran 77 With C and C++
6620 @comment  node-name,  next,  previous,  up
6621 @subsection Mixing Fortran 77 With C and C++
6622
6623 @cindex Fortran 77, mixing with C and C++
6624 @cindex Mixing Fortran 77 with C and C++
6625 @cindex Linking Fortran 77 with C and C++
6626 @cindex cfortran
6627 @cindex Mixing Fortran 77 with C and/or C++
6628
6629 Automake currently provides @emph{limited} support for creating programs
6630 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
6631 However, there are many other issues related to mixing Fortran 77 with
6632 other languages that are @emph{not} (currently) handled by Automake, but
6633 that are handled by other packages@footnote{For example,
6634 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
6635 addresses all of these inter-language issues, and runs under nearly all
6636 Fortran 77, C and C++ compilers on nearly all platforms.  However,
6637 @command{cfortran} is not yet Free Software, but it will be in the next
6638 major release.}.
6639
6640 Automake can help in two ways:
6641
6642 @enumerate
6643 @item
6644 Automatic selection of the linker depending on which combinations of
6645 source code.
6646
6647 @item
6648 Automatic selection of the appropriate linker flags (e.g., @option{-L} and
6649 @option{-l}) to pass to the automatically selected linker in order to link
6650 in the appropriate Fortran 77 intrinsic and run-time libraries.
6651
6652 @cindex @code{FLIBS}, defined
6653 @vindex FLIBS
6654 These extra Fortran 77 linker flags are supplied in the output variable
6655 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro.
6656 @xref{Fortran Compiler, , Fortran Compiler Characteristics, autoconf,
6657 The Autoconf Manual}.
6658 @end enumerate
6659
6660 If Automake detects that a program or shared library (as mentioned in
6661 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
6662 code that is a mixture of Fortran 77 and C and/or C++, then it requires
6663 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
6664 @file{configure.ac}, and that either @code{$(FLIBS)}
6665 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
6666 (for shared libraries) variables.  It is the responsibility of the
6667 person writing the @file{Makefile.am} to make sure that @samp{$(FLIBS)}
6668 appears in the appropriate @code{_LDADD} or
6669 @code{_LIBADD} variable.
6670
6671 @cindex Mixed language example
6672 @cindex Example, mixed language
6673
6674 For example, consider the following @file{Makefile.am}:
6675
6676 @example
6677 bin_PROGRAMS = foo
6678 foo_SOURCES  = main.cc foo.f
6679 foo_LDADD    = libfoo.la $(FLIBS)
6680
6681 pkglib_LTLIBRARIES = libfoo.la
6682 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
6683 libfoo_la_LIBADD   = $(FLIBS)
6684 @end example
6685
6686 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
6687 is mentioned in @file{configure.ac}.  Also, if @samp{$(FLIBS)} hadn't
6688 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
6689 Automake would have issued a warning.
6690
6691 @menu
6692 * How the Linker is Chosen::    Automatic linker selection
6693 @end menu
6694
6695 @node How the Linker is Chosen
6696 @comment  node-name,  next,  previous,  up
6697 @subsubsection How the Linker is Chosen
6698
6699 @cindex Automatic linker selection
6700 @cindex Selecting the linker automatically
6701
6702 When a program or library mixes several languages, Automake choose the
6703 linker according to the following priorities.  (The names in
6704 parentheses are the variables containing the link command.)
6705
6706 @enumerate
6707 @item
6708 @vindex GCJLINK
6709 Native Java (@code{GCJLINK})
6710 @item
6711 @vindex OBJCXXLINK
6712 Objective C++ (@code{OBJCXXLINK})
6713 @item
6714 @vindex CXXLINK
6715 C++ (@code{CXXLINK})
6716 @item
6717 @vindex F77LINK
6718 Fortran 77 (@code{F77LINK})
6719 @item
6720 @vindex FCLINK
6721 Fortran (@code{FCLINK})
6722 @item
6723 @vindex OBJCLINK
6724 Objective C (@code{OBJCLINK})
6725 @item
6726 @vindex UPCLINK
6727 Unified Parallel C (@code{UPCLINK})
6728 @item
6729 @vindex LINK
6730 C (@code{LINK})
6731 @end enumerate
6732
6733 For example, if Fortran 77, C and C++ source code is compiled
6734 into a program, then the C++ linker will be used.  In this case, if the
6735 C or Fortran 77 linkers required any special libraries that weren't
6736 included by the C++ linker, then they must be manually added to an
6737 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
6738 @file{Makefile.am}.
6739
6740 Automake only looks at the file names listed in @file{_SOURCES}
6741 variables to choose the linker, and defaults to the C linker.
6742 Sometimes this is inconvenient because you are linking against a
6743 library written in another language and would like to set the linker
6744 more appropriately.  @xref{Libtool Convenience Libraries}, for a
6745 trick with @code{nodist_EXTRA_@dots{}_SOURCES}.
6746
6747 A per-target @code{_LINK} variable will override the above selection.
6748 Per-target link flags will cause Automake to write a per-target
6749 @code{_LINK} variable according to the language chosen as above.
6750
6751
6752 @node Fortran 9x Support
6753 @comment  node-name,  next,  previous,  up
6754 @section Fortran 9x Support
6755
6756 @cindex Fortran 9x support
6757 @cindex Support for Fortran 9x
6758
6759 Automake includes support for Fortran 9x.
6760
6761 Any package including Fortran 9x code must define the output variable
6762 @code{FC} in @file{configure.ac}; the simplest way to do this is to use
6763 the @code{AC_PROG_FC} macro (@pxref{Particular Programs, , Particular
6764 Program Checks, autoconf, The Autoconf Manual}).
6765
6766 A few additional variables are defined when a Fortran 9x source file is
6767 seen:
6768
6769 @vtable @code
6770
6771 @item FC
6772 The name of the Fortran 9x compiler.
6773
6774 @item FCFLAGS
6775 Any flags to pass to the Fortran 9x compiler.
6776
6777 @item AM_FCFLAGS
6778 The maintainer's variant of @code{FCFLAGS}.
6779
6780 @item FCCOMPILE
6781 The command used to actually compile a Fortran 9x source file.  The file
6782 name is appended to form the complete command line.
6783
6784 @item FCLINK
6785 The command used to actually link a pure Fortran 9x program or shared
6786 library.
6787
6788 @end vtable
6789
6790 @menu
6791 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
6792 @end menu
6793
6794 @node Compiling Fortran 9x Files
6795 @comment  node-name,  next,  previous,  up
6796 @subsection Compiling Fortran 9x Files
6797
6798 @file{@var{file}.o} is made automatically from @file{@var{file}.f90},
6799 @file{@var{file}.f95}, @file{@var{file}.f03}, or @file{@var{file}.f08}
6800 by running the Fortran 9x compiler.  The precise command used
6801 is as follows:
6802
6803 @table @file
6804
6805 @item .f90
6806 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f90) $<}
6807
6808 @item .f95
6809 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f95) $<}
6810
6811 @item .f03
6812 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f03) $<}
6813
6814 @item .f08
6815 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f08) $<}
6816
6817 @end table
6818
6819 @node Java Support with gcj
6820 @comment  node-name,  next,  previous,  up
6821 @section Compiling Java sources using gcj
6822
6823 @cindex Java support with gcj
6824 @cindex Support for Java with gcj
6825 @cindex Java to native code, compilation
6826 @cindex Compilation of Java to native code
6827
6828 Automake includes support for natively compiled Java, using @command{gcj},
6829 the Java front end to the GNU Compiler Collection (rudimentary support
6830 for compiling Java to bytecode using the @command{javac} compiler is
6831 also present, @emph{albeit deprecated}; @pxref{Java}).
6832
6833 Any package including Java code to be compiled must define the output
6834 variable @code{GCJ} in @file{configure.ac}; the variable @code{GCJFLAGS}
6835 must also be defined somehow (either in @file{configure.ac} or
6836 @file{Makefile.am}).  The simplest way to do this is to use the
6837 @code{AM_PROG_GCJ} macro.
6838
6839 @vindex GCJFLAGS
6840
6841 By default, programs including Java source files are linked with
6842 @command{gcj}.
6843
6844 As always, the contents of @code{AM_GCJFLAGS} are passed to every
6845 compilation invoking @command{gcj} (in its role as an ahead-of-time
6846 compiler, when invoking it to create @file{.class} files,
6847 @code{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
6848 options to @command{gcj} from @file{Makefile.am}, this variable, and not
6849 the user variable @code{GCJFLAGS}, should be used.
6850
6851 @vindex AM_GCJFLAGS
6852
6853 @command{gcj} can be used to compile @file{.java}, @file{.class},
6854 @file{.zip}, or @file{.jar} files.
6855
6856 When linking, @command{gcj} requires that the main class be specified
6857 using the @option{--main=} option.  The easiest way to do this is to use
6858 the @code{_LDFLAGS} variable for the program.
6859
6860
6861 @node Vala Support
6862 @comment  node-name,  next,  previous,  up
6863 @section Vala Support
6864
6865 @cindex Vala Support
6866 @cindex Support for Vala
6867
6868 Automake provides initial support for Vala
6869 (@uref{http://www.vala-project.org/}).
6870 This requires valac version 0.7.0 or later, and currently requires
6871 the user to use GNU @command{make}.
6872
6873 @example
6874 foo_SOURCES = foo.vala bar.vala zardoc.c
6875 @end example
6876
6877 Any @file{.vala} file listed in a @code{_SOURCES} variable will be
6878 compiled into C code by the Vala compiler. The generated @file{.c} files are
6879 distributed. The end user does not need to have a Vala compiler installed.
6880
6881 Automake ships with an Autoconf macro called @code{AM_PROG_VALAC}
6882 that will locate the Vala compiler and optionally check its version
6883 number.
6884
6885 @defmac AM_PROG_VALAC (@ovar{minimum-version})
6886 Try to find a Vala compiler in @env{PATH}. If it is found, the variable
6887 @code{VALAC} is set. Optionally a minimum release number of the compiler
6888 can be requested:
6889
6890 @example
6891 AM_PROG_VALAC([0.7.0])
6892 @end example
6893 @end defmac
6894
6895 There are a few variables that are used when compiling Vala sources:
6896
6897 @vtable @code
6898 @item VALAC
6899 Path to the Vala compiler.
6900
6901 @item VALAFLAGS
6902 Additional arguments for the Vala compiler.
6903
6904 @item AM_VALAFLAGS
6905 The maintainer's variant of @code{VALAFLAGS}.
6906
6907 @example
6908 lib_LTLIBRARIES = libfoo.la
6909 libfoo_la_SOURCES = foo.vala
6910 @end example
6911 @end vtable
6912
6913 Note that currently, you cannot use per-target @code{*_VALAFLAGS}
6914 (@pxref{Renamed Objects}) to produce different C files from one Vala
6915 source file.
6916
6917
6918 @node Support for Other Languages
6919 @comment  node-name,  next,  previous,  up
6920 @section Support for Other Languages
6921
6922 Automake currently only includes full support for C, C++ (@pxref{C++
6923 Support}), Objective C (@pxref{Objective C Support}),
6924 Objective C++ (@pxref{Objective C++ Support}),
6925 Fortran 77
6926 (@pxref{Fortran 77 Support}), Fortran 9x (@pxref{Fortran 9x Support}),
6927 and Java (@pxref{Java Support with gcj}).  There is only rudimentary
6928 support for other languages, support for which will be improved based
6929 on user demand.
6930
6931 Some limited support for adding your own languages is available via the
6932 suffix rule handling (@pxref{Suffixes}).
6933
6934 @node Dependencies
6935 @section Automatic dependency tracking
6936
6937 As a developer it is often painful to continually update the
6938 @file{Makefile.am} whenever the include-file dependencies change in a
6939 project.  Automake supplies a way to automatically track dependency
6940 changes (@pxref{Dependency Tracking}).
6941
6942 @cindex Dependency tracking
6943 @cindex Automatic dependency tracking
6944
6945 Automake always uses complete dependencies for a compilation,
6946 including system headers.  Automake's model is that dependency
6947 computation should be a side effect of the build.  To this end,
6948 dependencies are computed by running all compilations through a
6949 special wrapper program called @command{depcomp}.  @command{depcomp}
6950 understands how to coax many different C and C++ compilers into
6951 generating dependency information in the format it requires.
6952 @samp{automake -a} will install @command{depcomp} into your source
6953 tree for you.  If @command{depcomp} can't figure out how to properly
6954 invoke your compiler, dependency tracking will simply be disabled for
6955 your build.
6956
6957 @cindex @command{depcomp}
6958
6959 Experience with earlier versions of Automake (@pxref{Dependency Tracking
6960 Evolution, , Dependency Tracking Evolution, automake-history, Brief History
6961 of Automake}) taught us that it is not reliable to generate dependencies
6962 only on the maintainer's system, as configurations vary too much.  So
6963 instead Automake implements dependency tracking at build time.
6964
6965 Automatic dependency tracking can be suppressed by putting
6966 @option{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
6967 passing @option{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
6968 (this should be the preferred way).  Or, you can invoke @command{automake}
6969 with the @option{-i} option.  Dependency tracking is enabled by default.
6970
6971 @vindex AUTOMAKE_OPTIONS
6972 @opindex no-dependencies
6973
6974 The person building your package also can choose to disable dependency
6975 tracking by configuring with @option{--disable-dependency-tracking}.
6976
6977 @cindex Disabling dependency tracking
6978 @cindex Dependency tracking, disabling
6979
6980
6981 @node EXEEXT
6982 @section Support for executable extensions
6983
6984 @cindex Executable extension
6985 @cindex Extension, executable
6986 @cindex Windows
6987
6988 On some platforms, such as Windows, executables are expected to have an
6989 extension such as @file{.exe}.  On these platforms, some compilers (GCC
6990 among them) will automatically generate @file{foo.exe} when asked to
6991 generate @file{foo}.
6992
6993 Automake provides mostly-transparent support for this.  Unfortunately
6994 @emph{mostly} doesn't yet mean @emph{fully}.  Until the English
6995 dictionary is revised, you will have to assist Automake if your package
6996 must support those platforms.
6997
6998 One thing you must be aware of is that, internally, Automake rewrites
6999 something like this:
7000
7001 @example
7002 bin_PROGRAMS = liver
7003 @end example
7004
7005 to this:
7006
7007 @example
7008 bin_PROGRAMS = liver$(EXEEXT)
7009 @end example
7010
7011 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
7012 extension.
7013
7014 The variables @code{TESTS} and @code{XFAIL_TESTS} (@pxref{Simple Tests})
7015 are also rewritten if they contain filenames that have been declared as
7016 programs in the same @file{Makefile}.  (This is mostly useful when some
7017 programs from @code{check_PROGRAMS} are listed in @code{TESTS}.)
7018
7019 However, Automake cannot apply this rewriting to @command{configure}
7020 substitutions.  This means that if you are conditionally building a
7021 program using such a substitution, then your @file{configure.ac} must
7022 take care to add @samp{$(EXEEXT)} when constructing the output variable.
7023
7024 Sometimes maintainers like to write an explicit link rule for their
7025 program.  Without executable extension support, this is easy---you
7026 simply write a rule whose target is the name of the program.  However,
7027 when executable extension support is enabled, you must instead add the
7028 @samp{$(EXEEXT)} suffix.
7029
7030 This might be a nuisance for maintainers who know their package will
7031 never run on a platform that has
7032 executable extensions.  For those maintainers, the @option{no-exeext}
7033 option (@pxref{Options}) will disable this feature.  This works in a
7034 fairly ugly way; if @option{no-exeext} is seen, then the presence of a
7035 rule for a target named @code{foo} in @file{Makefile.am} will override
7036 an @command{automake}-generated rule for @samp{foo$(EXEEXT)}.  Without
7037 the @option{no-exeext} option, this use will give a diagnostic.
7038
7039
7040 @node Other Objects
7041 @chapter Other Derived Objects
7042
7043 Automake can handle derived objects that are not C programs.  Sometimes
7044 the support for actually building such objects must be explicitly
7045 supplied, but Automake will still automatically handle installation and
7046 distribution.
7047
7048 @menu
7049 * Scripts::                     Executable scripts
7050 * Headers::                     Header files
7051 * Data::                        Architecture-independent data files
7052 * Sources::                     Derived sources
7053 @end menu
7054
7055
7056 @node Scripts
7057 @section Executable Scripts
7058
7059 @cindex @code{_SCRIPTS} primary, defined
7060 @cindex @code{SCRIPTS} primary, defined
7061 @cindex Primary variable, @code{SCRIPTS}
7062 @vindex _SCRIPTS
7063 @cindex Installing scripts
7064
7065 It is possible to define and install programs that are scripts.  Such
7066 programs are listed using the @code{SCRIPTS} primary name.  When the
7067 script is distributed in its final, installable form, the
7068 @file{Makefile} usually looks as follows:
7069 @vindex SCRIPTS
7070
7071 @example
7072 # Install my_script in $(bindir) and distribute it.
7073 dist_bin_SCRIPTS = my_script
7074 @end example
7075
7076 Scripts are not distributed by default; as we have just seen, those
7077 that should be distributed can be specified using a @code{dist_}
7078 prefix as with other primaries.
7079
7080 @cindex @code{SCRIPTS}, installation directories
7081 @vindex bin_SCRIPTS
7082 @vindex sbin_SCRIPTS
7083 @vindex libexec_SCRIPTS
7084 @vindex pkgdata_SCRIPTS
7085 @vindex pkglibexec_SCRIPTS
7086 @vindex noinst_SCRIPTS
7087 @vindex check_SCRIPTS
7088
7089 Scripts can be installed in @code{bindir}, @code{sbindir},
7090 @code{libexecdir}, @code{pkglibexecdir}, or @code{pkgdatadir}.
7091
7092 Scripts that need not be installed can be listed in
7093 @code{noinst_SCRIPTS}, and among them, those which are needed only by
7094 @samp{make check} should go in @code{check_SCRIPTS}.
7095
7096 When a script needs to be built, the @file{Makefile.am} should include
7097 the appropriate rules.  For instance the @command{automake} program
7098 itself is a Perl script that is generated from @file{automake.in}.
7099 Here is how this is handled:
7100
7101 @example
7102 bin_SCRIPTS = automake
7103 CLEANFILES = $(bin_SCRIPTS)
7104 EXTRA_DIST = automake.in
7105
7106 do_subst = sed -e 's,[@@]datadir[@@],$(datadir),g' \
7107             -e 's,[@@]PERL[@@],$(PERL),g' \
7108             -e 's,[@@]PACKAGE[@@],$(PACKAGE),g' \
7109             -e 's,[@@]VERSION[@@],$(VERSION),g' \
7110             @dots{}
7111
7112 automake: automake.in Makefile
7113         $(do_subst) < $(srcdir)/automake.in > automake
7114         chmod +x automake
7115 @end example
7116
7117 Such scripts for which a build rule has been supplied need to be
7118 deleted explicitly using @code{CLEANFILES} (@pxref{Clean}), and their
7119 sources have to be distributed, usually with @code{EXTRA_DIST}
7120 (@pxref{Basics of Distribution}).
7121
7122 Another common way to build scripts is to process them from
7123 @file{configure} with @code{AC_CONFIG_FILES}.  In this situation
7124 Automake knows which files should be cleaned and distributed, and what
7125 the rebuild rules should look like.
7126
7127 For instance if @file{configure.ac} contains
7128
7129 @example
7130 AC_CONFIG_FILES([src/my_script], [chmod +x src/my_script])
7131 @end example
7132
7133 @noindent
7134 to build @file{src/my_script} from @file{src/my_script.in}, then a
7135 @file{src/Makefile.am} to install this script in @code{$(bindir)} can
7136 be as simple as
7137
7138 @example
7139 bin_SCRIPTS = my_script
7140 CLEANFILES = $(bin_SCRIPTS)
7141 @end example
7142
7143 @noindent
7144 There is no need for @code{EXTRA_DIST} or any build rule: Automake
7145 infers them from @code{AC_CONFIG_FILES} (@pxref{Requirements}).
7146 @code{CLEANFILES} is still useful, because by default Automake will
7147 clean targets of @code{AC_CONFIG_FILES} in @code{distclean}, not
7148 @code{clean}.
7149
7150 Although this looks simpler, building scripts this way has one
7151 drawback: directory variables such as @code{$(datadir)} are not fully
7152 expanded and may refer to other directory variables.
7153
7154 @node Headers
7155 @section Header files
7156
7157 @cindex @code{_HEADERS} primary, defined
7158 @cindex @code{HEADERS} primary, defined
7159 @cindex Primary variable, @code{HEADERS}
7160 @vindex _HEADERS
7161 @vindex noinst_HEADERS
7162 @cindex @code{HEADERS}, installation directories
7163 @cindex Installing headers
7164 @vindex include_HEADERS
7165 @vindex oldinclude_HEADERS
7166 @vindex pkginclude_HEADERS
7167
7168
7169 Header files that must be installed are specified by the
7170 @code{HEADERS} family of variables.  Headers can be installed in
7171 @code{includedir}, @code{oldincludedir}, @code{pkgincludedir} or any
7172 other directory you may have defined (@pxref{Uniform}).  For instance,
7173
7174 @example
7175 include_HEADERS = foo.h bar/bar.h
7176 @end example
7177
7178 @noindent
7179 will install the two files as @file{$(includedir)/foo.h} and
7180 @file{$(includedir)/bar.h}.
7181
7182 The @code{nobase_} prefix is also supported,
7183
7184 @example
7185 nobase_include_HEADERS = foo.h bar/bar.h
7186 @end example
7187
7188 @noindent
7189 will install the two files as @file{$(includedir)/foo.h} and
7190 @file{$(includedir)/bar/bar.h} (@pxref{Alternative}).
7191
7192 @vindex noinst_HEADERS
7193 Usually, only header files that accompany installed libraries need to
7194 be installed.  Headers used by programs or convenience libraries are
7195 not installed.  The @code{noinst_HEADERS} variable can be used for
7196 such headers.  However when the header actually belongs to a single
7197 convenience library or program, we recommend listing it in the
7198 program's or library's @code{_SOURCES} variable (@pxref{Program
7199 Sources}) instead of in @code{noinst_HEADERS}.  This is clearer for
7200 the @file{Makefile.am} reader.  @code{noinst_HEADERS} would be the
7201 right variable to use in a directory containing only headers and no
7202 associated library or program.
7203
7204 All header files must be listed somewhere; in a @code{_SOURCES}
7205 variable or in a @code{_HEADERS} variable.  Missing ones will not
7206 appear in the distribution.
7207
7208 For header files that are built and must not be distributed, use the
7209 @code{nodist_} prefix as in @code{nodist_include_HEADERS} or
7210 @code{nodist_prog_SOURCES}.  If these generated headers are needed
7211 during the build, you must also ensure they exist before they are
7212 used (@pxref{Sources}).
7213
7214
7215 @node Data
7216 @section Architecture-independent data files
7217
7218 @cindex @code{_DATA} primary, defined
7219 @cindex @code{DATA} primary, defined
7220 @cindex Primary variable, @code{DATA}
7221 @vindex _DATA
7222
7223 Automake supports the installation of miscellaneous data files using the
7224 @code{DATA} family of variables.
7225 @vindex DATA
7226
7227 @vindex data_DATA
7228 @vindex sysconf_DATA
7229 @vindex sharedstate_DATA
7230 @vindex localstate_DATA
7231 @vindex pkgdata_DATA
7232
7233 Such data can be installed in the directories @code{datadir},
7234 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
7235 @code{pkgdatadir}.
7236
7237 By default, data files are @emph{not} included in a distribution.  Of
7238 course, you can use the @code{dist_} prefix to change this on a
7239 per-variable basis.
7240
7241 Here is how Automake declares its auxiliary data files:
7242
7243 @example
7244 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
7245 @end example
7246
7247
7248 @node Sources
7249 @section Built Sources
7250
7251 Because Automake's automatic dependency tracking works as a side-effect
7252 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
7253 target should not be compiled before its dependencies are made, but
7254 these dependencies are unknown until the target is first compiled.
7255
7256 Ordinarily this is not a problem, because dependencies are distributed
7257 sources: they preexist and do not need to be built.  Suppose that
7258 @file{foo.c} includes @file{foo.h}.  When it first compiles
7259 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
7260 @file{foo.c}.  As a side-effect of this compilation @command{depcomp}
7261 records the @file{foo.h} dependency so that following invocations of
7262 @command{make} will honor it.  In these conditions, it's clear there is
7263 no problem: either @file{foo.o} doesn't exist and has to be built
7264 (regardless of the dependencies), or accurate dependencies exist and
7265 they can be used to decide whether @file{foo.o} should be rebuilt.
7266
7267 It's a different story if @file{foo.h} doesn't exist by the first
7268 @command{make} run.  For instance, there might be a rule to build
7269 @file{foo.h}.  This time @file{file.o}'s build will fail because the
7270 compiler can't find @file{foo.h}.  @command{make} failed to trigger the
7271 rule to build @file{foo.h} first by lack of dependency information.
7272
7273 @vindex BUILT_SOURCES
7274 @cindex @code{BUILT_SOURCES}, defined
7275
7276 The @code{BUILT_SOURCES} variable is a workaround for this problem.  A
7277 source file listed in @code{BUILT_SOURCES} is made on @samp{make all}
7278 or @samp{make check} (or even @samp{make install}) before other
7279 targets are processed.  However, such a source file is not
7280 @emph{compiled} unless explicitly requested by mentioning it in some
7281 other @code{_SOURCES} variable.
7282
7283 So, to conclude our introductory example, we could use
7284 @samp{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
7285 any other target (including @file{foo.o}) during @samp{make all} or
7286 @samp{make check}.
7287
7288 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
7289 must be created early in the build process can be listed in this
7290 variable.  Moreover, all built sources do not necessarily have to be
7291 listed in @code{BUILT_SOURCES}.  For instance, a generated @file{.c} file
7292 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
7293 another source), because it's a known dependency of the associated
7294 object.
7295
7296 It might be important to emphasize that @code{BUILT_SOURCES} is
7297 honored only by @samp{make all}, @samp{make check} and @samp{make
7298 install}.  This means you cannot build a specific target (e.g.,
7299 @samp{make foo}) in a clean tree if it depends on a built source.
7300 However it will succeed if you have run @samp{make all} earlier,
7301 because accurate dependencies are already available.
7302
7303 The next section illustrates and discusses the handling of built sources
7304 on a toy example.
7305
7306 @menu
7307 * Built Sources Example::       Several ways to handle built sources.
7308 @end menu
7309
7310 @node Built Sources Example
7311 @subsection Built Sources Example
7312
7313 Suppose that @file{foo.c} includes @file{bindir.h}, which is
7314 installation-dependent and not distributed: it needs to be built.  Here
7315 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
7316 value of the @command{make} variable @code{bindir} (inherited from
7317 @file{configure}).
7318
7319 We suggest several implementations below.  It's not meant to be an
7320 exhaustive listing of all ways to handle built sources, but it will give
7321 you a few ideas if you encounter this issue.
7322
7323 @subsubheading First Try
7324
7325 This first implementation will illustrate the bootstrap issue mentioned
7326 in the previous section (@pxref{Sources}).
7327
7328 Here is a tentative @file{Makefile.am}.
7329
7330 @example
7331 # This won't work.
7332 bin_PROGRAMS = foo
7333 foo_SOURCES = foo.c
7334 nodist_foo_SOURCES = bindir.h
7335 CLEANFILES = bindir.h
7336 bindir.h: Makefile
7337         echo '#define bindir "$(bindir)"' >$@@
7338 @end example
7339
7340 This setup doesn't work, because Automake doesn't know that @file{foo.c}
7341 includes @file{bindir.h}.  Remember, automatic dependency tracking works
7342 as a side-effect of compilation, so the dependencies of @file{foo.o} will
7343 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
7344 The symptom is as follows.
7345
7346 @example
7347 % make
7348 source='foo.c' object='foo.o' libtool=no \
7349 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7350 depmode=gcc /bin/sh ./depcomp \
7351 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7352 foo.c:2: bindir.h: No such file or directory
7353 make: *** [foo.o] Error 1
7354 @end example
7355
7356 In this example @file{bindir.h} is not distributed nor installed, and
7357 it is not even being built on-time.  One may wonder if the
7358 @samp{nodist_foo_SOURCES = bindir.h} line has any use at all.  This
7359 line simply states that @file{bindir.h} is a source of @code{foo}, so
7360 for instance, it should be inspected while generating tags
7361 (@pxref{Tags}).  In other words, it does not help our present problem,
7362 and the build would fail identically without it.
7363
7364 @subsubheading Using @code{BUILT_SOURCES}
7365
7366 A solution is to require @file{bindir.h} to be built before anything
7367 else.  This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
7368
7369 @example
7370 bin_PROGRAMS = foo
7371 foo_SOURCES = foo.c
7372 nodist_foo_SOURCES = bindir.h
7373 BUILT_SOURCES = bindir.h
7374 CLEANFILES = bindir.h
7375 bindir.h: Makefile
7376         echo '#define bindir "$(bindir)"' >$@@
7377 @end example
7378
7379 See how @file{bindir.h} gets built first:
7380
7381 @example
7382 % make
7383 echo '#define bindir "/usr/local/bin"' >bindir.h
7384 make  all-am
7385 make[1]: Entering directory `/home/adl/tmp'
7386 source='foo.c' object='foo.o' libtool=no \
7387 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7388 depmode=gcc /bin/sh ./depcomp \
7389 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7390 gcc  -g -O2   -o foo  foo.o
7391 make[1]: Leaving directory `/home/adl/tmp'
7392 @end example
7393
7394 However, as said earlier, @code{BUILT_SOURCES} applies only to the
7395 @code{all}, @code{check}, and @code{install} targets.  It still fails
7396 if you try to run @samp{make foo} explicitly:
7397
7398 @example
7399 % make clean
7400 test -z "bindir.h" || rm -f bindir.h
7401 test -z "foo" || rm -f foo
7402 rm -f *.o
7403 % : > .deps/foo.Po # Suppress previously recorded dependencies
7404 % make foo
7405 source='foo.c' object='foo.o' libtool=no \
7406 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7407 depmode=gcc /bin/sh ./depcomp \
7408 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7409 foo.c:2: bindir.h: No such file or directory
7410 make: *** [foo.o] Error 1
7411 @end example
7412
7413 @subsubheading Recording Dependencies manually
7414
7415 Usually people are happy enough with @code{BUILT_SOURCES} because they
7416 never build targets such as @samp{make foo} before @samp{make all}, as
7417 in the previous example.  However if this matters to you, you can
7418 avoid @code{BUILT_SOURCES} and record such dependencies explicitly in
7419 the @file{Makefile.am}.
7420
7421 @example
7422 bin_PROGRAMS = foo
7423 foo_SOURCES = foo.c
7424 nodist_foo_SOURCES = bindir.h
7425 foo.$(OBJEXT): bindir.h
7426 CLEANFILES = bindir.h
7427 bindir.h: Makefile
7428         echo '#define bindir "$(bindir)"' >$@@
7429 @end example
7430
7431 You don't have to list @emph{all} the dependencies of @file{foo.o}
7432 explicitly, only those that might need to be built.  If a dependency
7433 already exists, it will not hinder the first compilation and will be
7434 recorded by the normal dependency tracking code.  (Note that after
7435 this first compilation the dependency tracking code will also have
7436 recorded the dependency between @file{foo.o} and
7437 @file{bindir.h}; so our explicit dependency is really useful to
7438 the first build only.)
7439
7440 Adding explicit dependencies like this can be a bit dangerous if you are
7441 not careful enough.  This is due to the way Automake tries not to
7442 overwrite your rules (it assumes you know better than it).
7443 @samp{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
7444 output to build @samp{foo.$(OBJEXT)}.  It happens to work in this case
7445 because Automake doesn't have to output any @samp{foo.$(OBJEXT):}
7446 target: it relies on a suffix rule instead (i.e., @samp{.c.$(OBJEXT):}).
7447 Always check the generated @file{Makefile.in} if you do this.
7448
7449 @subsubheading Build @file{bindir.h} from @file{configure}
7450
7451 It's possible to define this preprocessor macro from @file{configure},
7452 either in @file{config.h} (@pxref{Defining Directories, , Defining
7453 Directories, autoconf, The Autoconf Manual}), or by processing a
7454 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
7455 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
7456 Autoconf Manual}).
7457
7458 At this point it should be clear that building @file{bindir.h} from
7459 @file{configure} works well for this example.  @file{bindir.h} will exist
7460 before you build any target, hence will not cause any dependency issue.
7461
7462 The Makefile can be shrunk as follows.  We do not even have to mention
7463 @file{bindir.h}.
7464
7465 @example
7466 bin_PROGRAMS = foo
7467 foo_SOURCES = foo.c
7468 @end example
7469
7470 However, it's not always possible to build sources from
7471 @file{configure}, especially when these sources are generated by a tool
7472 that needs to be built first.
7473
7474 @subsubheading Build @file{bindir.c}, not @file{bindir.h}.
7475
7476 Another attractive idea is to define @code{bindir} as a variable or
7477 function exported from @file{bindir.o}, and build @file{bindir.c}
7478 instead of @file{bindir.h}.
7479
7480 @example
7481 noinst_PROGRAMS = foo
7482 foo_SOURCES = foo.c bindir.h
7483 nodist_foo_SOURCES = bindir.c
7484 CLEANFILES = bindir.c
7485 bindir.c: Makefile
7486         echo 'const char bindir[] = "$(bindir)";' >$@@
7487 @end example
7488
7489 @file{bindir.h} contains just the variable's declaration and doesn't
7490 need to be built, so it won't cause any trouble.  @file{bindir.o} is
7491 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
7492 first.
7493
7494 @subsubheading Which is best?
7495
7496 There is no panacea, of course.  Each solution has its merits and
7497 drawbacks.
7498
7499 You cannot use @code{BUILT_SOURCES} if the ability to run @samp{make
7500 foo} on a clean tree is important to you.
7501
7502 You won't add explicit dependencies if you are leery of overriding
7503 an Automake rule by mistake.
7504
7505 Building files from @file{./configure} is not always possible, neither
7506 is converting @file{.h} files into @file{.c} files.
7507
7508
7509 @node Other GNU Tools
7510 @chapter Other GNU Tools
7511
7512 Since Automake is primarily intended to generate @file{Makefile.in}s for
7513 use in GNU programs, it tries hard to interoperate with other GNU tools.
7514
7515 @menu
7516 * Emacs Lisp::                  Emacs Lisp
7517 * gettext::                     Gettext
7518 * Libtool::                     Libtool
7519 * Java::                        Java bytecode compilation (deprecated)
7520 * Python::                      Python
7521 @end menu
7522
7523
7524 @node Emacs Lisp
7525 @section Emacs Lisp
7526
7527 @cindex @code{_LISP} primary, defined
7528 @cindex @code{LISP} primary, defined
7529 @cindex Primary variable, @code{LISP}
7530
7531 @vindex _LISP
7532 @vindex lisp_LISP
7533 @vindex noinst_LISP
7534
7535 Automake provides some support for Emacs Lisp.  The @code{LISP} primary
7536 is used to hold a list of @file{.el} files.  Possible prefixes for this
7537 primary are @code{lisp_} and @code{noinst_}.  Note that if
7538 @code{lisp_LISP} is defined, then @file{configure.ac} must run
7539 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
7540
7541 @vindex dist_lisp_LISP
7542 @vindex dist_noinst_LISP
7543 Lisp sources are not distributed by default.  You can prefix the
7544 @code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
7545 @code{dist_noinst_LISP}, to indicate that these files should be
7546 distributed.
7547
7548 Automake will byte-compile all Emacs Lisp source files using the Emacs
7549 found by @code{AM_PATH_LISPDIR}, if any was found.
7550
7551 Byte-compiled Emacs Lisp files are not portable among all versions of
7552 Emacs, so it makes sense to turn this off if you expect sites to have
7553 more than one version of Emacs installed.  Furthermore, many packages
7554 don't actually benefit from byte-compilation.  Still, we recommend
7555 that you byte-compile your Emacs Lisp sources.  It is probably better
7556 for sites with strange setups to cope for themselves than to make the
7557 installation less nice for everybody else.
7558
7559 There are two ways to avoid byte-compiling.  Historically, we have
7560 recommended the following construct.
7561
7562 @example
7563 lisp_LISP = file1.el file2.el
7564 ELCFILES =
7565 @end example
7566
7567 @noindent
7568 @code{ELCFILES} is an internal Automake variable that normally lists
7569 all @file{.elc} files that must be byte-compiled.  Automake defines
7570 @code{ELCFILES} automatically from @code{lisp_LISP}.  Emptying this
7571 variable explicitly prevents byte-compilation.
7572
7573 Since Automake 1.8, we now recommend using @code{lisp_DATA} instead:
7574
7575 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7576 @example
7577 lisp_DATA = file1.el file2.el
7578 @end example
7579
7580 Note that these two constructs are not equivalent.  @code{_LISP} will
7581 not install a file if Emacs is not installed, while @code{_DATA} will
7582 always install its files.
7583
7584 @node gettext
7585 @section Gettext
7586
7587 @cindex GNU Gettext support
7588 @cindex Gettext support
7589 @cindex Support for GNU Gettext
7590
7591 If @code{AM_GNU_GETTEXT} is seen in @file{configure.ac}, then Automake
7592 turns on support for GNU gettext, a message catalog system for
7593 internationalization
7594 (@pxref{Top, , Introduction, gettext, GNU gettext utilities}).
7595
7596 The @code{gettext} support in Automake requires the addition of one or
7597 two subdirectories to the package: @file{po} and possibly also @file{intl}.
7598 The latter is needed if @code{AM_GNU_GETTEXT} is not invoked with the
7599 @samp{external} argument, or if @code{AM_GNU_GETTEXT_INTL_SUBDIR} is used.
7600 Automake ensures that these directories exist and are mentioned in
7601 @code{SUBDIRS}.
7602
7603 @node Libtool
7604 @section Libtool
7605
7606 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
7607 libtool, The Libtool Manual}) with the @code{LTLIBRARIES} primary.
7608 @xref{A Shared Library}.
7609
7610
7611 @node Java
7612 @section Java bytecode compilation (deprecated)
7613
7614 @cindex @code{_JAVA} primary, defined
7615 @cindex @code{JAVA} primary, defined
7616 @cindex Primary variable, @code{JAVA}
7617 @cindex Java to bytecode, compilation
7618 @cindex Compilation of Java to bytecode
7619
7620 Automake provides some minimal support for Java bytecode compilation with
7621 the @code{JAVA} primary (in addition to the support for compiling Java to
7622 native machine code; @pxref{Java Support with gcj}).  Note however that
7623 @emph{the interface and most features described here are deprecated}; the
7624 next automake release will strive to provide a better and cleaner
7625 interface, which however @emph{won't be backward-compatible}; the present
7626 interface will probably be removed altogether in future automake releases
7627 (1.13 or later), so don't use it in new code.
7628
7629 Any @file{.java} files listed in a @code{_JAVA} variable will be
7630 compiled with @code{JAVAC} at build time.  By default, @file{.java}
7631 files are not included in the distribution, you should use the
7632 @code{dist_} prefix to distribute them.
7633
7634 Here is a typical setup for distributing @file{.java} files and
7635 installing the @file{.class} files resulting from their compilation.
7636
7637 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7638 @example
7639 javadir = $(datadir)/java
7640 dist_java_JAVA = a.java b.java @dots{}
7641 @end example
7642
7643 @cindex @code{JAVA} restrictions
7644 @cindex Restrictions for @code{JAVA}
7645
7646 Currently Automake enforces the restriction that only one @code{_JAVA}
7647 primary can be used in a given @file{Makefile.am}.  The reason for this
7648 restriction is that, in general, it isn't possible to know which
7649 @file{.class} files were generated from which @file{.java} files, so
7650 it would be impossible to know which files to install where.  For
7651 instance, a @file{.java} file can define multiple classes; the resulting
7652 @file{.class} file names cannot be predicted without parsing the
7653 @file{.java} file.
7654
7655 There are a few variables that are used when compiling Java sources:
7656
7657 @vtable @code
7658 @item JAVAC
7659 The name of the Java compiler.  This defaults to @samp{javac}.
7660
7661 @item JAVACFLAGS
7662 The flags to pass to the compiler.  This is considered to be a user
7663 variable (@pxref{User Variables}).
7664
7665 @item AM_JAVACFLAGS
7666 More flags to pass to the Java compiler.  This, and not
7667 @code{JAVACFLAGS}, should be used when it is necessary to put Java
7668 compiler flags into @file{Makefile.am}.
7669
7670 @item JAVAROOT
7671 The value of this variable is passed to the @option{-d} option to
7672 @code{javac}.  It defaults to @samp{$(top_builddir)}.
7673
7674 @item CLASSPATH_ENV
7675 This variable is a shell expression that is used to set the
7676 @env{CLASSPATH} environment variable on the @code{javac} command line.
7677 (In the future we will probably handle class path setting differently.)
7678 @end vtable
7679
7680
7681 @node Python
7682 @section Python
7683
7684 @cindex @code{_PYTHON} primary, defined
7685 @cindex @code{PYTHON} primary, defined
7686 @cindex Primary variable, @code{PYTHON}
7687 @vindex _PYTHON
7688
7689 Automake provides support for Python compilation with the
7690 @code{PYTHON} primary.  A typical setup is to call
7691 @code{AM_PATH_PYTHON} in @file{configure.ac} and use a line like the
7692 following in @file{Makefile.am}:
7693
7694 @example
7695 python_PYTHON = tree.py leave.py
7696 @end example
7697
7698 Any files listed in a @code{_PYTHON} variable will be byte-compiled
7699 with @command{py-compile} at install time.  @command{py-compile}
7700 actually creates both standard (@file{.pyc}) and optimized
7701 (@file{.pyo}) byte-compiled versions of the source files.  Note that
7702 because byte-compilation occurs at install time, any files listed in
7703 @code{noinst_PYTHON} will not be compiled.  Python source files are
7704 included in the distribution by default, prepend @code{nodist_} (as in
7705 @code{nodist_python_PYTHON}) to omit them.
7706
7707 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON}
7708 that will determine some Python-related directory variables (see
7709 below).  If you have called @code{AM_PATH_PYTHON} from
7710 @file{configure.ac}, then you may use the variables
7711 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7712 @code{python_PYTHON} or @code{pkgpython_PYTHON} to list Python source
7713 files in your @file{Makefile.am}, depending on where you want your files
7714 installed (see the definitions of @code{pythondir} and
7715 @code{pkgpythondir} below).
7716
7717 @defmac AM_PATH_PYTHON (@ovar{version}, @ovar{action-if-found},
7718   @ovar{action-if-not-found})
7719
7720 Search for a Python interpreter on the system.  This macro takes three
7721 optional arguments.  The first argument, if present, is the minimum
7722 version of Python required for this package: @code{AM_PATH_PYTHON}
7723 will skip any Python interpreter that is older than @var{version}.
7724 If an interpreter is found and satisfies @var{version}, then
7725 @var{action-if-found} is run.  Otherwise, @var{action-if-not-found} is
7726 run.
7727
7728 If @var{action-if-not-found} is not specified, as in the following
7729 example, the default is to abort @command{configure}.
7730
7731 @example
7732 AM_PATH_PYTHON([2.2])
7733 @end example
7734
7735 @noindent
7736 This is fine when Python is an absolute requirement for the package.
7737 If Python >= 2.5 was only @emph{optional} to the package,
7738 @code{AM_PATH_PYTHON} could be called as follows.
7739
7740 @example
7741 AM_PATH_PYTHON([2.5],, [:])
7742 @end example
7743
7744 If the @env{PYTHON} variable is set when @code{AM_PATH_PYTHON} is
7745 called, then that will be the only Python interpreter that is tried.
7746
7747 @code{AM_PATH_PYTHON} creates the following output variables based on
7748 the Python installation found during configuration.
7749 @end defmac
7750
7751 @vtable @code
7752 @item PYTHON
7753 The name of the Python executable, or @samp{:} if no suitable
7754 interpreter could be found.
7755
7756 Assuming @var{action-if-not-found} is used (otherwise @file{./configure}
7757 will abort if Python is absent), the value of @code{PYTHON} can be used
7758 to setup a conditional in order to disable the relevant part of a build
7759 as follows.
7760
7761 @example
7762 AM_PATH_PYTHON(,, [:])
7763 AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
7764 @end example
7765
7766 @item PYTHON_VERSION
7767 The Python version number, in the form @var{major}.@var{minor}
7768 (e.g., @samp{2.5}).  This is currently the value of
7769 @samp{sys.version[:3]}.
7770
7771 @item PYTHON_PREFIX
7772 The string @samp{$@{prefix@}}.  This term may be used in future work
7773 that needs the contents of Python's @samp{sys.prefix}, but general
7774 consensus is to always use the value from @command{configure}.
7775
7776 @item PYTHON_EXEC_PREFIX
7777 The string @samp{$@{exec_prefix@}}.  This term may be used in future work
7778 that needs the contents of Python's @samp{sys.exec_prefix}, but general
7779 consensus is to always use the value from @command{configure}.
7780
7781 @item PYTHON_PLATFORM
7782 The canonical name used by Python to describe the operating system, as
7783 given by @samp{sys.platform}.  This value is sometimes needed when
7784 building Python extensions.
7785
7786 @item pythondir
7787 The directory name for the @file{site-packages} subdirectory of the
7788 standard Python install tree.
7789
7790 @item pkgpythondir
7791 This is the directory under @code{pythondir} that is named after the
7792 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
7793 as a convenience.
7794
7795 @item pyexecdir
7796 This is the directory where Python extension modules (shared libraries)
7797 should be installed.  An extension module written in C could be declared
7798 as follows to Automake:
7799
7800 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7801 @example
7802 pyexec_LTLIBRARIES = quaternion.la
7803 quaternion_la_SOURCES = quaternion.c support.c support.h
7804 quaternion_la_LDFLAGS = -avoid-version -module
7805 @end example
7806
7807 @item pkgpyexecdir
7808 This is a convenience variable that is defined as
7809 @samp{$(pyexecdir)/$(PACKAGE)}.
7810 @end vtable
7811
7812 All of these directory variables have values that start with either
7813 @samp{$@{prefix@}} or @samp{$@{exec_prefix@}} unexpanded.  This works
7814 fine in @file{Makefiles}, but it makes these variables hard to use in
7815 @file{configure}.  This is mandated by the GNU coding standards, so
7816 that the user can run @samp{make prefix=/foo install}.  The Autoconf
7817 manual has a section with more details on this topic
7818 (@pxref{Installation Directory Variables, , Installation Directory
7819 Variables, autoconf, The Autoconf Manual}).  See also @ref{Hard-Coded
7820 Install Paths}.
7821
7822
7823 @node Documentation
7824 @chapter Building documentation
7825
7826 Currently Automake provides support for Texinfo and man pages.
7827
7828 @menu
7829 * Texinfo::                     Texinfo
7830 * Man Pages::                   Man pages
7831 @end menu
7832
7833
7834 @node Texinfo
7835 @section Texinfo
7836
7837 @cindex @code{_TEXINFOS} primary, defined
7838 @cindex @code{TEXINFOS} primary, defined
7839 @cindex Primary variable, @code{TEXINFOS}
7840 @cindex HTML output using Texinfo
7841 @cindex PDF output using Texinfo
7842 @cindex PS output using Texinfo
7843 @cindex DVI output using Texinfo
7844 @vindex _TEXINFOS
7845 @vindex info_TEXINFOS
7846
7847 If the current directory contains Texinfo source, you must declare it
7848 with the @code{TEXINFOS} primary.  Generally Texinfo files are converted
7849 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
7850 here.  Any Texinfo source file must end in the @file{.texi},
7851 @file{.txi}, or @file{.texinfo} extension.  We recommend @file{.texi}
7852 for new manuals.
7853
7854 Automake generates rules to build @file{.info}, @file{.dvi},
7855 @file{.ps}, @file{.pdf} and @file{.html} files from your Texinfo
7856 sources.  Following the GNU Coding Standards, only the @file{.info}
7857 files are built by @samp{make all} and installed by @samp{make
7858 install} (unless you use @option{no-installinfo}, see below).
7859 Furthermore, @file{.info} files are automatically distributed so that
7860 Texinfo is not a prerequisite for installing your package.
7861
7862 @trindex dvi
7863 @trindex html
7864 @trindex pdf
7865 @trindex ps
7866 @trindex install-dvi
7867 @trindex install-html
7868 @trindex install-pdf
7869 @trindex install-ps
7870 Other documentation formats can be built on request by @samp{make
7871 dvi}, @samp{make ps}, @samp{make pdf} and @samp{make html}, and they
7872 can be installed with @samp{make install-dvi}, @samp{make install-ps},
7873 @samp{make install-pdf} and @samp{make install-html} explicitly.
7874 @samp{make uninstall} will remove everything: the Texinfo
7875 documentation installed by default as well as all the above optional
7876 formats.
7877
7878 All of these targets can be extended using @samp{-local} rules
7879 (@pxref{Extending}).
7880
7881 @cindex Texinfo flag, @code{VERSION}
7882 @cindex Texinfo flag, @code{UPDATED}
7883 @cindex Texinfo flag, @code{EDITION}
7884 @cindex Texinfo flag, @code{UPDATED-MONTH}
7885
7886 @cindex @code{VERSION} Texinfo flag
7887 @cindex @code{UPDATED} Texinfo flag
7888 @cindex @code{EDITION} Texinfo flag
7889 @cindex @code{UPDATED-MONTH} Texinfo flag
7890
7891 @cindex @file{mdate-sh}
7892
7893 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
7894 that file will be automatically generated.  The file @file{version.texi}
7895 defines four Texinfo flag you can reference using
7896 @code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
7897 @code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
7898
7899 @table @code
7900 @item EDITION
7901 @itemx VERSION
7902 Both of these flags hold the version number of your program.  They are
7903 kept separate for clarity.
7904
7905 @item UPDATED
7906 This holds the date the primary @file{.texi} file was last modified.
7907
7908 @item UPDATED-MONTH
7909 This holds the name of the month in which the primary @file{.texi} file
7910 was last modified.
7911 @end table
7912
7913 The @file{version.texi} support requires the @command{mdate-sh}
7914 script; this script is supplied with Automake and automatically
7915 included when @command{automake} is invoked with the
7916 @option{--add-missing} option.
7917
7918 If you have multiple Texinfo files, and you want to use the
7919 @file{version.texi} feature, then you have to have a separate version
7920 file for each Texinfo file.  Automake will treat any include in a
7921 Texinfo file that matches @file{vers*.texi} just as an automatically
7922 generated version file.
7923
7924 Sometimes an info file actually depends on more than one @file{.texi}
7925 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
7926 @file{fdl.texi}.  You can tell Automake about these dependencies using
7927 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
7928 @vindex TEXINFOS
7929 @vindex _TEXINFOS
7930
7931 @example
7932 info_TEXINFOS = hello.texi
7933 hello_TEXINFOS = fdl.texi
7934 @end example
7935
7936 @cindex @file{texinfo.tex}
7937
7938 By default, Automake requires the file @file{texinfo.tex} to appear in
7939 the same directory as the @file{Makefile.am} file that lists the
7940 @file{.texi} files.  If you used @code{AC_CONFIG_AUX_DIR} in
7941 @file{configure.ac} (@pxref{Input, , Finding `configure' Input,
7942 autoconf, The Autoconf Manual}), then @file{texinfo.tex} is looked for
7943 there.  In both cases, @command{automake} then supplies @file{texinfo.tex} if
7944 @option{--add-missing} is given, and takes care of its distribution.
7945 However, if you set the @code{TEXINFO_TEX} variable (see below),
7946 it overrides the location of the file and turns off its installation
7947 into the source as well as its distribution.
7948
7949 The option @option{no-texinfo.tex} can be used to eliminate the
7950 requirement for the file @file{texinfo.tex}.  Use of the variable
7951 @code{TEXINFO_TEX} is preferable, however, because that allows the
7952 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
7953
7954 @cindex Option, @code{no-installinfo}
7955 @cindex Target, @code{install-info}
7956 @cindex @code{install-info} target
7957 @cindex @code{no-installinfo} option
7958
7959 @opindex no-installinfo
7960 @trindex install-info
7961
7962 Automake generates an @code{install-info} rule; some people apparently
7963 use this.  By default, info pages are installed by @samp{make
7964 install}, so running @code{make install-info} is pointless.  This can
7965 be prevented via the @code{no-installinfo} option.  In this case,
7966 @file{.info} files are not installed by default, and user must
7967 request this explicitly using @samp{make install-info}.
7968
7969 @vindex AM_UPDATE_INFO_DIR
7970 By default, @code{make install-info} and @code{make install-info}
7971 will try to run the @command{install-info} program (if available)
7972 to update (or create) the @file{@code{$@{infodir@}}/dir} index.
7973 If this is undesired, it can be prevented by exporting the
7974 @code{AM_UPDATE_INFO_DIR} variable to "@code{no}".
7975
7976 The following variables are used by the Texinfo build rules.
7977
7978 @vtable @code
7979 @item MAKEINFO
7980 The name of the program invoked to build @file{.info} files.  This
7981 variable is defined by Automake.  If the @command{makeinfo} program is
7982 found on the system then it will be used by default; otherwise
7983 @command{missing} will be used instead.
7984
7985 @item MAKEINFOHTML
7986 The command invoked to build @file{.html} files.  Automake
7987 defines this to @samp{$(MAKEINFO) --html}.
7988
7989 @item MAKEINFOFLAGS
7990 User flags passed to each invocation of @samp{$(MAKEINFO)} and
7991 @samp{$(MAKEINFOHTML)}.  This user variable (@pxref{User Variables}) is
7992 not expected to be defined in any @file{Makefile}; it can be used by
7993 users to pass extra flags to suit their needs.
7994
7995 @item AM_MAKEINFOFLAGS
7996 @itemx AM_MAKEINFOHTMLFLAGS
7997 Maintainer flags passed to each @command{makeinfo} invocation.  Unlike
7998 @code{MAKEINFOFLAGS}, these variables are meant to be defined by
7999 maintainers in @file{Makefile.am}.  @samp{$(AM_MAKEINFOFLAGS)} is
8000 passed to @code{makeinfo} when building @file{.info} files; and
8001 @samp{$(AM_MAKEINFOHTMLFLAGS)} is used when building @file{.html}
8002 files.
8003
8004 @c Keep in sync with txinfo21.sh
8005 For instance, the following setting can be used to obtain one single
8006 @file{.html} file per manual, without node separators.
8007 @example
8008 AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
8009 @end example
8010
8011 @code{AM_MAKEINFOHTMLFLAGS} defaults to @samp{$(AM_MAKEINFOFLAGS)}.
8012 This means that defining @code{AM_MAKEINFOFLAGS} without defining
8013 @code{AM_MAKEINFOHTMLFLAGS} will impact builds of both @file{.info}
8014 and @file{.html} files.
8015
8016 @item TEXI2DVI
8017 The name of the command that converts a @file{.texi} file into a
8018 @file{.dvi} file.  This defaults to @samp{texi2dvi}, a script that ships
8019 with the Texinfo package.
8020
8021 @item TEXI2PDF
8022 The name of the command that translates a @file{.texi} file into a
8023 @file{.pdf} file.  This defaults to @samp{$(TEXI2DVI) --pdf --batch}.
8024
8025 @item DVIPS
8026 The name of the command that builds a @file{.ps} file out of a
8027 @file{.dvi} file.  This defaults to @samp{dvips}.
8028
8029 @item TEXINFO_TEX
8030
8031 If your package has Texinfo files in many directories, you can use the
8032 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
8033 @file{texinfo.tex} for your package.  The value of this variable should
8034 be the relative path from the current @file{Makefile.am} to
8035 @file{texinfo.tex}:
8036
8037 @example
8038 TEXINFO_TEX = ../doc/texinfo.tex
8039 @end example
8040 @end vtable
8041
8042
8043 @node Man Pages
8044 @section Man Pages
8045
8046 @cindex @code{_MANS} primary, defined
8047 @cindex @code{MANS} primary, defined
8048 @cindex Primary variable, @code{MANS}
8049
8050 @vindex _MANS
8051 @vindex man_MANS
8052 A package can also include man pages (but see the GNU standards on this
8053 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
8054 pages are declared using the @code{MANS} primary.  Generally the
8055 @code{man_MANS} variable is used.  Man pages are automatically installed in
8056 the correct subdirectory of @code{mandir}, based on the file extension.
8057
8058 File extensions such as @file{.1c} are handled by looking for the valid
8059 part of the extension and using that to determine the correct
8060 subdirectory of @code{mandir}.  Valid section names are the digits
8061 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
8062
8063 Sometimes developers prefer to name a man page something like
8064 @file{foo.man} in the source, and then rename it to have the correct
8065 suffix, for example @file{foo.1}, when installing the file.  Automake
8066 also supports this mode.  For a valid section named @var{section},
8067 there is a corresponding directory named @samp{man@var{section}dir},
8068 and a corresponding @code{_MANS} variable.  Files listed in such a
8069 variable are installed in the indicated section.  If the file already
8070 has a valid suffix, then it is installed as-is; otherwise the file
8071 suffix is changed to match the section.
8072
8073 For instance, consider this example:
8074 @example
8075 man1_MANS = rename.man thesame.1 alsothesame.1c
8076 @end example
8077
8078 @noindent
8079 In this case, @file{rename.man} will be renamed to @file{rename.1} when
8080 installed, but the other files will keep their names.
8081
8082 @cindex Target, @code{install-man}
8083 @cindex Option, @option{no-installman}
8084 @cindex @code{install-man} target
8085 @cindex @option{no-installman} option
8086 @opindex no-installman
8087 @trindex install-man
8088
8089 By default, man pages are installed by @samp{make install}.  However,
8090 since the GNU project does not require man pages, many maintainers do
8091 not expend effort to keep the man pages up to date.  In these cases, the
8092 @option{no-installman} option will prevent the man pages from being
8093 installed by default.  The user can still explicitly install them via
8094 @samp{make install-man}.
8095
8096 For fast installation, with many files it is preferable to use
8097 @samp{man@var{section}_MANS} over @samp{man_MANS} as well as files that
8098 do not need to be renamed.
8099
8100 Man pages are not currently considered to be source, because it is not
8101 uncommon for man pages to be automatically generated.  Therefore they
8102 are not automatically included in the distribution.  However, this can
8103 be changed by use of the @code{dist_} prefix.  For instance here is
8104 how to distribute and install the two man pages of GNU @command{cpio}
8105 (which includes both Texinfo documentation and man pages):
8106
8107 @example
8108 dist_man_MANS = cpio.1 mt.1
8109 @end example
8110
8111 The @code{nobase_} prefix is meaningless for man pages and is
8112 disallowed.
8113
8114 @vindex notrans_
8115 @cindex @code{notrans_} prefix
8116 @cindex Man page renaming, avoiding
8117 @cindex Avoiding man page renaming
8118
8119 Executables and manpages may be renamed upon installation
8120 (@pxref{Renaming}).  For manpages this can be avoided by use of the
8121 @code{notrans_} prefix.  For instance, suppose an executable @samp{foo}
8122 allowing to access a library function @samp{foo} from the command line.
8123 The way to avoid renaming of the @file{foo.3} manpage is:
8124
8125 @example
8126 man_MANS = foo.1
8127 notrans_man_MANS = foo.3
8128 @end example
8129
8130 @cindex @code{notrans_} and @code{dist_} or @code{nodist_}
8131 @cindex @code{dist_} and @code{notrans_}
8132 @cindex @code{nodist_} and @code{notrans_}
8133
8134 @samp{notrans_} must be specified first when used in conjunction with
8135 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
8136 Control}).  For instance:
8137
8138 @example
8139 notrans_dist_man3_MANS = bar.3
8140 @end example
8141
8142 @node Install
8143 @chapter What Gets Installed
8144
8145 @cindex Installation support
8146 @cindex @samp{make install} support
8147
8148 Naturally, Automake handles the details of actually installing your
8149 program once it has been built.  All files named by the various
8150 primaries are automatically installed in the appropriate places when the
8151 user runs @samp{make install}.
8152
8153 @menu
8154 * Basics of Installation::      What gets installed where
8155 * The Two Parts of Install::    Installing data and programs separately
8156 * Extending Installation::      Adding your own rules for installation
8157 * Staged Installs::             Installation in a temporary location
8158 * Install Rules for the User::  Useful additional rules
8159 @end menu
8160
8161 @node Basics of Installation
8162 @section Basics of Installation
8163
8164 A file named in a primary is installed by copying the built file into
8165 the appropriate directory.  The base name of the file is used when
8166 installing.
8167
8168 @example
8169 bin_PROGRAMS = hello subdir/goodbye
8170 @end example
8171
8172 In this example, both @samp{hello} and @samp{goodbye} will be installed
8173 in @samp{$(bindir)}.
8174
8175 Sometimes it is useful to avoid the basename step at install time.  For
8176 instance, you might have a number of header files in subdirectories of
8177 the source tree that are laid out precisely how you want to install
8178 them.  In this situation you can use the @code{nobase_} prefix to
8179 suppress the base name step.  For example:
8180
8181 @example
8182 nobase_include_HEADERS = stdio.h sys/types.h
8183 @end example
8184
8185 @noindent
8186 will install @file{stdio.h} in @samp{$(includedir)} and @file{types.h}
8187 in @samp{$(includedir)/sys}.
8188
8189 For most file types, Automake will install multiple files at once, while
8190 avoiding command line length issues (@pxref{Length Limitations}).  Since
8191 some @command{install} programs will not install the same file twice in
8192 one invocation, you may need to ensure that file lists are unique within
8193 one variable such as @samp{nobase_include_HEADERS} above.
8194
8195 You should not rely on the order in which files listed in one variable
8196 are installed.  Likewise, to cater for parallel make, you should not
8197 rely on any particular file installation order even among different
8198 file types (library dependencies are an exception here).
8199
8200
8201 @node The Two Parts of Install
8202 @section The Two Parts of Install
8203
8204 Automake generates separate @code{install-data} and @code{install-exec}
8205 rules, in case the installer is installing on multiple machines that
8206 share directory structure---these targets allow the machine-independent
8207 parts to be installed only once.  @code{install-exec} installs
8208 platform-dependent files, and @code{install-data} installs
8209 platform-independent files.  The @code{install} target depends on both
8210 of these targets.  While Automake tries to automatically segregate
8211 objects into the correct category, the @file{Makefile.am} author is, in
8212 the end, responsible for making sure this is done correctly.
8213 @trindex install-data
8214 @trindex install-exec
8215 @trindex install
8216 @cindex Install, two parts of
8217
8218 Variables using the standard directory prefixes @samp{data},
8219 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
8220 @samp{pkgdata}, or @samp{pkginclude} are installed by
8221 @code{install-data}.
8222
8223 Variables using the standard directory prefixes @samp{bin},
8224 @samp{sbin}, @samp{libexec}, @samp{sysconf}, @samp{localstate},
8225 @samp{lib}, or @samp{pkglib} are installed by @code{install-exec}.
8226
8227 For instance, @code{data_DATA} files are installed by @code{install-data},
8228 while @code{bin_PROGRAMS} files are installed by @code{install-exec}.
8229
8230 Any variable using a user-defined directory prefix with
8231 @samp{exec} in the name (e.g.,
8232 @c Keep in sync with primary-prefix-couples-documented-valid.sh
8233 @code{myexecbin_PROGRAMS}) is installed by @code{install-exec}.  All
8234 other user-defined prefixes are installed by @code{install-data}.
8235
8236 @node Extending Installation
8237 @section Extending Installation
8238
8239 It is possible to extend this mechanism by defining an
8240 @code{install-exec-local} or @code{install-data-local} rule.  If these
8241 rules exist, they will be run at @samp{make install} time.  These
8242 rules can do almost anything; care is required.
8243 @trindex install-exec-local
8244 @trindex install-data-local
8245
8246 Automake also supports two install hooks, @code{install-exec-hook} and
8247 @code{install-data-hook}.  These hooks are run after all other install
8248 rules of the appropriate type, exec or data, have completed.  So, for
8249 instance, it is possible to perform post-installation modifications
8250 using an install hook.  @xref{Extending}, for some examples.
8251 @cindex Install hook
8252
8253 @node Staged Installs
8254 @section Staged Installs
8255
8256 @vindex DESTDIR
8257 Automake generates support for the @code{DESTDIR} variable in all
8258 install rules.  @code{DESTDIR} is used during the @samp{make install}
8259 step to relocate install objects into a staging area.  Each object and
8260 path is prefixed with the value of @code{DESTDIR} before being copied
8261 into the install area.  Here is an example of typical DESTDIR usage:
8262
8263 @example
8264 mkdir /tmp/staging &&
8265 make DESTDIR=/tmp/staging install
8266 @end example
8267
8268 The @command{mkdir} command avoids a security problem if the attacker
8269 creates a symbolic link from @file{/tmp/staging} to a victim area;
8270 then @command{make} places install objects in a directory tree built under
8271 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
8272 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
8273 would install @file{/tmp/staging/gnu/bin/foo} and
8274 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
8275
8276 This feature is commonly used to build install images and packages
8277 (@pxref{DESTDIR}).
8278
8279 Support for @code{DESTDIR} is implemented by coding it directly into
8280 the install rules.  If your @file{Makefile.am} uses a local install
8281 rule (e.g., @code{install-exec-local}) or an install hook, then you
8282 must write that code to respect @code{DESTDIR}.
8283
8284 @xref{Makefile Conventions, , , standards, The GNU Coding Standards},
8285 for another usage example.
8286
8287 @node Install Rules for the User
8288 @section Install Rules for the User
8289
8290 Automake also generates rules for targets @code{uninstall},
8291 @code{installdirs}, and @code{install-strip}.
8292 @trindex uninstall
8293 @trindex installdirs
8294 @trindex install-strip
8295
8296 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
8297 There is no notion of separate uninstalls for ``exec'' and ``data'', as
8298 these features would not provide additional functionality.
8299
8300 Note that @code{uninstall} is not meant as a replacement for a real
8301 packaging tool.
8302
8303
8304 @node Clean
8305 @chapter What Gets Cleaned
8306
8307 @cindex @samp{make clean} support
8308
8309 The GNU Makefile Standards specify a number of different clean rules.
8310 @xref{Standard Targets, , Standard Targets for Users, standards,
8311 The GNU Coding Standards}.
8312
8313 Generally the files that can be cleaned are determined automatically by
8314 Automake.  Of course, Automake also recognizes some variables that can
8315 be defined to specify additional files to clean.  These variables are
8316 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
8317 @code{MAINTAINERCLEANFILES}.
8318 @vindex MOSTLYCLEANFILES
8319 @vindex CLEANFILES
8320 @vindex DISTCLEANFILES
8321 @vindex MAINTAINERCLEANFILES
8322
8323 @trindex mostlyclean-local
8324 @trindex clean-local
8325 @trindex distclean-local
8326 @trindex maintainer-clean-local
8327 When cleaning involves more than deleting some hard-coded list of
8328 files, it is also possible to supplement the cleaning rules with your
8329 own commands.  Simply define a rule for any of the
8330 @code{mostlyclean-local}, @code{clean-local}, @code{distclean-local},
8331 or @code{maintainer-clean-local} targets (@pxref{Extending}).  A common
8332 case is deleting a directory, for instance, a directory created by the
8333 test suite:
8334
8335 @example
8336 clean-local:
8337         -rm -rf testSubDir
8338 @end example
8339
8340 Since @command{make} allows only one set of rules for a given target,
8341 a more extensible way of writing this is to use a separate target
8342 listed as a dependency:
8343
8344 @example
8345 clean-local: clean-local-check
8346 .PHONY: clean-local-check
8347 clean-local-check:
8348         -rm -rf testSubDir
8349 @end example
8350
8351 As the GNU Standards aren't always explicit as to which files should
8352 be removed by which rule, we've adopted a heuristic that we believe
8353 was first formulated by Fran@,{c}ois Pinard:
8354
8355 @itemize @bullet
8356 @item
8357 If @command{make} built it, and it is commonly something that one would
8358 want to rebuild (for instance, a @file{.o} file), then
8359 @code{mostlyclean} should delete it.
8360
8361 @item
8362 Otherwise, if @command{make} built it, then @code{clean} should delete it.
8363
8364 @item
8365 If @command{configure} built it, then @code{distclean} should delete it.
8366
8367 @item
8368 If the maintainer built it (for instance, a @file{.info} file), then
8369 @code{maintainer-clean} should delete it.  However
8370 @code{maintainer-clean} should not delete anything that needs to exist
8371 in order to run @samp{./configure && make}.
8372 @end itemize
8373
8374 We recommend that you follow this same set of heuristics in your
8375 @file{Makefile.am}.
8376
8377
8378 @node Dist
8379 @chapter What Goes in a Distribution
8380
8381 @menu
8382 * Basics of Distribution::      Files distributed by default
8383 * Fine-grained Distribution Control::  @code{dist_} and @code{nodist_} prefixes
8384 * The dist Hook::               A target for last-minute distribution changes
8385 * Checking the Distribution::   @samp{make distcheck} explained
8386 * The Types of Distributions::  A variety of formats and compression methods
8387 @end menu
8388
8389 @node Basics of Distribution
8390 @section Basics of Distribution
8391
8392 @cindex @samp{make dist}
8393
8394 @vindex PACKAGE
8395 @vindex VERSION
8396 @trindex dist
8397 The @code{dist} rule in the generated @file{Makefile.in} can be used
8398 to generate a gzipped @code{tar} file and other flavors of archive for
8399 distribution.  The file is named based on the @code{PACKAGE} and
8400 @code{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
8401 (@pxref{Macros}); more precisely the gzipped @code{tar} file is named
8402 @samp{@var{package}-@var{version}.tar.gz}.
8403 @vindex GZIP_ENV
8404 You can use the @command{make} variable @code{GZIP_ENV} to control how gzip
8405 is run.  The default setting is @option{--best}.
8406
8407 @cindex @code{m4_include}, distribution
8408 @cindex @code{include}, distribution
8409 @acindex m4_include
8410 @cmindex include
8411 For the most part, the files to distribute are automatically found by
8412 Automake: all source files are automatically included in a distribution,
8413 as are all @file{Makefile.am} and @file{Makefile.in} files.  Automake also
8414 has a built-in list of commonly used files that are automatically
8415 included if they are found in the current directory (either physically,
8416 or as the target of a @file{Makefile.am} rule); this list is printed by
8417 @samp{automake --help}.  Note that some files in this list are actually
8418 distributed only if other certain conditions hold (for example,
8419 @c Keep in sync with autodist-config-headers.sh
8420 the @file{config.h.top} and @file{config.h.bot} files are automatically
8421 distributed only if, e.g., @samp{AC_CONFIG_HEADERS([config.h])} is used
8422 in @file{configure.ac}).  Also, files that are read by @command{configure}
8423 (i.e.@: the source files corresponding to the files specified in various
8424 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
8425 automatically distributed.  Files included in a @file{Makefile.am} (using
8426 @code{include}) or in @file{configure.ac} (using @code{m4_include}), and
8427 helper scripts installed with @samp{automake --add-missing} are also
8428 distributed.
8429
8430 @vindex EXTRA_DIST
8431 Still, sometimes there are files that must be distributed, but which
8432 are not covered in the automatic rules.  These files should be listed in
8433 the @code{EXTRA_DIST} variable.  You can mention files from
8434 subdirectories in @code{EXTRA_DIST}.
8435
8436 You can also mention a directory in @code{EXTRA_DIST}; in this case the
8437 entire directory will be recursively copied into the distribution.
8438 Please note that this will also copy @emph{everything} in the directory,
8439 including, e.g., Subversion's @file{.svn} private directories or CVS/RCS
8440 version control files.  We recommend against using this feature.
8441
8442 @vindex SUBDIRS
8443 @vindex DIST_SUBDIRS
8444 If you define @code{SUBDIRS}, Automake will recursively include the
8445 subdirectories in the distribution.  If @code{SUBDIRS} is defined
8446 conditionally (@pxref{Conditionals}), Automake will normally include
8447 all directories that could possibly appear in @code{SUBDIRS} in the
8448 distribution.  If you need to specify the set of directories
8449 conditionally, you can set the variable @code{DIST_SUBDIRS} to the
8450 exact list of subdirectories to include in the distribution
8451 (@pxref{Conditional Subdirectories}).
8452
8453
8454 @node Fine-grained Distribution Control
8455 @section Fine-grained Distribution Control
8456
8457 @vindex dist_
8458 @vindex nodist_
8459 Sometimes you need tighter control over what does @emph{not} go into the
8460 distribution; for instance, you might have source files that are
8461 generated and that you do not want to distribute.  In this case
8462 Automake gives fine-grained control using the @code{dist} and
8463 @code{nodist} prefixes.  Any primary or @code{_SOURCES} variable can be
8464 prefixed with @code{dist_} to add the listed files to the distribution.
8465 Similarly, @code{nodist_} can be used to omit the files from the
8466 distribution.
8467
8468 As an example, here is how you would cause some data to be distributed
8469 while leaving some source code out of the distribution:
8470
8471 @example
8472 dist_data_DATA = distribute-this
8473 bin_PROGRAMS = foo
8474 nodist_foo_SOURCES = do-not-distribute.c
8475 @end example
8476
8477 @node The dist Hook
8478 @section The dist Hook
8479
8480 @trindex dist-hook
8481
8482 Occasionally it is useful to be able to change the distribution before
8483 it is packaged up.  If the @code{dist-hook} rule exists, it is run
8484 after the distribution directory is filled, but before the actual
8485 distribution archives are created.  One way to use this is for
8486 removing unnecessary files that get recursively included by specifying
8487 a directory in @code{EXTRA_DIST}:
8488
8489 @example
8490 EXTRA_DIST = doc
8491 dist-hook:
8492         rm -rf `find $(distdir)/doc -type d -name .svn`
8493 @end example
8494
8495 @c The caveates described here should be documented in 'disthook.sh'.
8496 @noindent
8497 Note that the @code{dist-hook} recipe shouldn't assume that the regular
8498 files in the distribution directory are writable; this might not be the
8499 case if one is packaging from a read-only source tree, or when a
8500 @code{make distcheck} is being done.  For similar reasons, the recipe
8501 shouldn't assume that the subdirectories put into the distribution
8502 directory as effect of having them listed in @code{EXTRA_DIST} are
8503 writable.  So, if the @code{dist-hook} recipe wants to modify the
8504 content of an existing file (or @code{EXTRA_DIST} subdirectory) in the
8505 distribution directory, it should explicitly to make it writable first:
8506
8507 @example
8508 EXTRA_DIST = README doc
8509 dist-hook:
8510         chmod u+w $(distdir)/README $(distdir)/doc
8511         echo "Distribution date: `date`" >> README
8512         rm -f $(distdir)/doc/HACKING
8513 @end example
8514
8515 @vindex distdir
8516 @vindex top_distdir
8517 Two variables that come handy when writing @code{dist-hook} rules are
8518 @samp{$(distdir)} and @samp{$(top_distdir)}.
8519
8520 @samp{$(distdir)} points to the directory where the @code{dist} rule
8521 will copy files from the current directory before creating the
8522 tarball.  If you are at the top-level directory, then @samp{distdir =
8523 $(PACKAGE)-$(VERSION)}.  When used from subdirectory named
8524 @file{foo/}, then @samp{distdir = ../$(PACKAGE)-$(VERSION)/foo}.
8525 @samp{$(distdir)} can be a relative or absolute path, do not assume
8526 any form.
8527
8528 @samp{$(top_distdir)} always points to the root directory of the
8529 distributed tree.  At the top-level it's equal to @samp{$(distdir)}.
8530 In the @file{foo/} subdirectory
8531 @samp{top_distdir = ../$(PACKAGE)-$(VERSION)}.
8532 @samp{$(top_distdir)} too can be a relative or absolute path.
8533
8534 Note that when packages are nested using @code{AC_CONFIG_SUBDIRS}
8535 (@pxref{Subpackages}), then @samp{$(distdir)} and
8536 @samp{$(top_distdir)} are relative to the package where @samp{make
8537 dist} was run, not to any sub-packages involved.
8538
8539 @node Checking the Distribution
8540 @section Checking the Distribution
8541
8542 @cindex @samp{make distcheck}
8543 @trindex distcheck
8544 Automake also generates a @code{distcheck} rule that can be of help
8545 to ensure that a given distribution will actually work.  Simplifying
8546 a bit, we can say this rule first makes a distribution, and then,
8547 @emph{operating from it}, takes the following steps:
8548 @itemize
8549 @item
8550 tries to do a @code{VPATH} build (@pxref{VPATH Builds}), with the
8551 @code{srcdir} and all its content made @emph{read-only};
8552 @item
8553 runs the test suite (with @command{make check}) on this fresh build;
8554 @item
8555 installs the package in a temporary directory (with @command{make
8556 install}), and tries runs the test suite on the resulting installation
8557 (with @command{make installcheck});
8558 @item
8559 checks that the package can be correctly uninstalled (by @command{make
8560 uninstall}) and cleaned (by @code{make distclean});
8561 @item
8562 finally, makes another tarball to ensure the distribution is
8563 self-contained.
8564 @end itemize
8565
8566 @vindex AM_DISTCHECK_CONFIGURE_FLAGS
8567 @vindex DISTCHECK_CONFIGURE_FLAGS
8568 @subheading DISTCHECK_CONFIGURE_FLAGS
8569 Building the package involves running @samp{./configure}.  If you need
8570 to supply additional flags to @command{configure}, define them in the
8571 @code{AM_DISTCHECK_CONFIGURE_FLAGS} variable in your top-level
8572 @file{Makefile.am}.  The user can still extend or override the flags
8573 provided there by defining the @code{DISTCHECK_CONFIGURE_FLAGS} variable,
8574 on the command line when invoking @command{make}.
8575
8576 Still, developers are encouraged to strive to make their code buildable
8577 without requiring any special configure option; thus, in general, you
8578 shouldn't define @code{AM_DISTCHECK_CONFIGURE_FLAGS}. However, there
8579 might be few scenarios in which the use of this variable is justified.
8580 GNU @command{m4} offers an example.  GNU @command{m4} configures by
8581 default with its experimental and seldom used "changeword" feature
8582 disabled; so in its case it is useful to have @command{make distcheck}
8583 run configure with the @option{--with-changeword} option, to ensure that
8584 the code for changeword support still compiles correctly.
8585 GNU @command{m4} also employs the @code{AM_DISTCHECK_CONFIGURE_FLAGS}
8586 variable to stress-test the use of @option{--program-prefix=g}, since at
8587 one point the @command{m4} build system had a bug where @command{make
8588 installcheck} was wrongly assuming it could blindly test "@command{m4}",
8589 rather than the just-installed "@command{gm4}".
8590
8591 @trindex distcheck-hook
8592 @subheading distcheck-hook
8593 If the @code{distcheck-hook} rule is defined in your top-level
8594 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
8595 the new distribution has been unpacked, but before the unpacked copy
8596 is configured and built.  Your @code{distcheck-hook} can do almost
8597 anything, though as always caution is advised.  Generally this hook is
8598 used to check for potential distribution errors not caught by the
8599 standard mechanism.  Note that @code{distcheck-hook} as well as
8600 @code{AM_DISTCHECK_CONFIGURE_FLAGS} and @code{DISTCHECK_CONFIGURE_FLAGS}
8601 are not honored in a subpackage @file{Makefile.am}, but the flags from
8602 @code{AM_DISTCHECK_CONFIGURE_FLAGS} and @code{DISTCHECK_CONFIGURE_FLAGS}
8603 are passed down to the @command{configure} script of the subpackage.
8604
8605 @cindex @samp{make distcleancheck}
8606 @trindex distcleancheck
8607 @vindex DISTCLEANFILES
8608 @vindex distcleancheck_listfiles
8609
8610 @subheading distcleancheck
8611 Speaking of potential distribution errors, @code{distcheck} also
8612 ensures that the @code{distclean} rule actually removes all built
8613 files.  This is done by running @samp{make distcleancheck} at the end of
8614 the @code{VPATH} build.  By default, @code{distcleancheck} will run
8615 @code{distclean} and then make sure the build tree has been emptied by
8616 running @samp{$(distcleancheck_listfiles)}.  Usually this check will
8617 find generated files that you forgot to add to the @code{DISTCLEANFILES}
8618 variable (@pxref{Clean}).
8619
8620 The @code{distcleancheck} behavior should be OK for most packages,
8621 otherwise you have the possibility to override the definition of
8622 either the @code{distcleancheck} rule, or the
8623 @samp{$(distcleancheck_listfiles)} variable.  For instance, to disable
8624 @code{distcleancheck} completely, add the following rule to your
8625 top-level @file{Makefile.am}:
8626
8627 @example
8628 distcleancheck:
8629         @@:
8630 @end example
8631
8632 If you want @code{distcleancheck} to ignore built files that have not
8633 been cleaned because they are also part of the distribution, add the
8634 following definition instead:
8635
8636 @c Keep in sync with distcleancheck.sh
8637 @example
8638 distcleancheck_listfiles = \
8639   find . -type f -exec sh -c 'test -f $(srcdir)/$$1 || echo $$1' \
8640        sh '@{@}' ';'
8641 @end example
8642
8643 The above definition is not the default because it's usually an error if
8644 your Makefiles cause some distributed files to be rebuilt when the user
8645 build the package.  (Think about the user missing the tool required to
8646 build the file; or if the required tool is built by your package,
8647 consider the cross-compilation case where it can't be run.)  There is
8648 an entry in the FAQ about this (@pxref{Errors with distclean}), make
8649 sure you read it before playing with @code{distcleancheck_listfiles}.
8650
8651 @cindex @samp{make distuninstallcheck}
8652 @trindex distuninstallcheck
8653 @vindex distuninstallcheck_listfiles
8654
8655 @subheading distuninstallcheck
8656 @code{distcheck} also checks that the @code{uninstall} rule works
8657 properly, both for ordinary and @code{DESTDIR} builds.  It does this
8658 by invoking @samp{make uninstall}, and then it checks the install tree
8659 to see if any files are left over.  This check will make sure that you
8660 correctly coded your @code{uninstall}-related rules.
8661
8662 By default, the checking is done by the @code{distuninstallcheck} rule,
8663 and the list of files in the install tree is generated by
8664 @samp{$(distuninstallcheck_listfiles)} (this is a variable whose value is
8665 a shell command to run that prints the list of files to stdout).
8666
8667 Either of these can be overridden to modify the behavior of
8668 @code{distcheck}.  For instance, to disable this check completely, you
8669 would write:
8670
8671 @example
8672 distuninstallcheck:
8673         @@:
8674 @end example
8675
8676 @node The Types of Distributions
8677 @section The Types of Distributions
8678
8679 Automake generates rules to provide archives of the project for
8680 distributions in various formats.  Their targets are:
8681
8682 @table @asis
8683 @vindex BZIP2
8684 @item @code{dist-bzip2}
8685 Generate a bzip2 tar archive of the distribution.  bzip2 archives are
8686 frequently smaller than gzipped archives.
8687 By default, this rule makes @samp{bzip2} use a compression option of @option{-9}.
8688 To make it use a different one, set the @env{BZIP2} environment variable.
8689 For example, @samp{make dist-bzip2 BZIP2=-7}.
8690 @trindex dist-bzip2
8691
8692 @item @code{dist-gzip}
8693 Generate a gzip tar archive of the distribution.
8694 @trindex dist-gzip
8695
8696 @item @code{dist-lzip}
8697 Generate an @samp{lzip} tar archive of the distribution.  @command{lzip}
8698 archives are frequently smaller than @command{bzip2}-compressed archives.
8699 @trindex dist-lzip
8700
8701 @item @code{dist-shar}
8702 Generate a shar archive of the distribution.
8703 @trindex dist-shar
8704
8705 @vindex XZ_OPT
8706 @item @code{dist-xz}
8707 Generate an @samp{xz} tar archive of the distribution.  @command{xz}
8708 archives are frequently smaller than @command{bzip2}-compressed archives.
8709 By default, this rule makes @samp{xz} use a compression option of
8710 @option{-e}.  To make it use a different one, set the @env{XZ_OPT}
8711 environment variable.  For example, run this command to use the
8712 default compression ratio, but with a progress indicator:
8713 @samp{make dist-xz XZ_OPT=-7e}.
8714 @trindex dist-xz
8715
8716 @item @code{dist-zip}
8717 Generate a zip archive of the distribution.
8718 @trindex dist-zip
8719
8720 @item @code{dist-tarZ}
8721 Generate a compressed tar archive of
8722 the distribution.
8723 @trindex dist-tarZ
8724 @end table
8725
8726 The rule @code{dist} (and its historical synonym @code{dist-all}) will
8727 create archives in all the enabled formats, @ref{Options}.  By
8728 default, only the @code{dist-gzip} target is hooked to @code{dist}.
8729
8730
8731 @node Tests
8732 @chapter Support for test suites
8733
8734 @cindex Test suites
8735 @cindex @code{make check}
8736 @trindex check
8737
8738 Automake can generate code to handle two kinds of test suites.  One is
8739 based on integration with the @command{dejagnu} framework.  The other
8740 (and most used) form is based on the use of generic test scripts, and
8741 its activation is triggered by the definition of the special @code{TESTS}
8742 variable.  This second form allows for various degrees of sophistication
8743 and customization; in particular, it allows for concurrent execution
8744 of test scripts, use of established test protocols such as TAP, and
8745 definition of custom test drivers and test runners.
8746
8747 @noindent
8748 In either case, the testsuite is invoked via @samp{make check}.
8749
8750 @menu
8751 * Generalities about Testing::  Concepts and terminology about testing
8752 * Simple Tests::                Listing test scripts in @code{TESTS}
8753 * Custom Test Drivers::         Writing and using custom test drivers
8754 * Using the TAP test protocol:: Integrating test scripts that use the TAP protocol
8755 * DejaGnu Tests::               Interfacing with the @command{dejagnu} testing framework
8756 * Install Tests::               Running tests on installed packages
8757 @end menu
8758
8759 @node Generalities about Testing
8760 @section Generalities about Testing
8761
8762 The purpose of testing is to determine whether a program or system behaves
8763 as expected (e.g., known inputs produce the expected outputs, error
8764 conditions are correctly handled or reported, and older bugs do not
8765 resurface).
8766
8767 @cindex test case
8768 The minimal unit of testing is usually called @emph{test case}, or simply
8769 @emph{test}.  How a test case is defined or delimited, and even what
8770 exactly @emph{constitutes} a test case, depends heavily on the testing
8771 paradigm and/or framework in use, so we won't attempt any more precise
8772 definition.  The set of the test cases for a given program or system
8773 constitutes its @emph{testsuite}.
8774
8775 @cindex test harness
8776 @cindex testsuite harness
8777 A @emph{test harness} (also @emph{testsuite harness}) is a program or
8778 software component that executes all (or part of) the defined test cases,
8779 analyzes their outcomes, and report or register these outcomes
8780 appropriately.  Again, the details of how this is accomplished (and how
8781 the developer and user can influence it or interface with it) varies
8782 wildly, and we'll attempt no precise definition.
8783
8784 @cindex test pass
8785 @cindex test failure
8786 A test is said to @emph{pass} when it can determine that the condition or
8787 behaviour it means to verify holds, and is said to @emph{fail} when it can
8788 determine that such condition of behaviour does @emph{not} hold.
8789
8790 @cindex test skip
8791 Sometimes, tests can rely on non-portable tools or prerequisites, or
8792 simply make no sense on a given system (for example, a test checking a
8793 Windows-specific feature makes no sense on a GNU/Linux system).  In this
8794 case, accordingly to the definition above, the tests can neither be
8795 considered passed nor failed; instead, they are @emph{skipped} -- i.e.,
8796 they are not run, or their result is anyway ignored for what concerns
8797 the count of failures an successes.  Skips are usually explicitly
8798 reported though, so that the user will be aware that not all of the
8799 testsuite has really run.
8800
8801 @cindex xfail
8802 @cindex expected failure
8803 @cindex expected test failure
8804 @cindex xpass
8805 @cindex unexpected pass
8806 @cindex unexpected test pass
8807 It's not uncommon, especially during early development stages, that some
8808 tests fail for known reasons, and that the developer doesn't want to
8809 tackle these failures immediately (this is especially true when the
8810 failing tests deal with corner cases).  In this situation, the better
8811 policy is to declare that each of those failures is an @emph{expected
8812 failure} (or @emph{xfail}).  In case a test that is expected to fail ends
8813 up passing instead, many testing environments will flag the result as a
8814 special kind of failure called @emph{unexpected pass} (or @emph{xpass}).
8815
8816 @cindex hard error
8817 @cindex Distinction between errors and failures in testsuites
8818 Many testing environments and frameworks distinguish between test failures
8819 and hard errors.  As we've seen, a test failure happens when some invariant
8820 or expected behaviour of the software under test is not met.  An @emph{hard
8821 error} happens when e.g., the set-up of a test case scenario fails, or when
8822 some other unexpected or highly undesirable condition is encountered (for
8823 example, the program under test experiences a segmentation fault).
8824
8825 @emph{TODO}: Links to other test harnesses (esp. those sharing our
8826 terminology)?
8827
8828 @node Simple Tests
8829 @section Simple Tests
8830
8831 @menu
8832 * Scripts-based Testsuites::    Automake-specific concepts and terminology
8833 * Serial Test Harness::         Older (and obsolescent) serial test harness
8834 * Parallel Test Harness::       Generic concurrent test harness
8835 @end menu
8836
8837 @node Scripts-based Testsuites
8838 @subsection Scripts-based Testsuites
8839
8840 If the special variable @code{TESTS} is defined, its value is taken to be
8841 a list of programs or scripts to run in order to do the testing.  Under
8842 the appropriate circumstances, it's possible for @code{TESTS} to list
8843 also data files to be passed to one or more test scripts defined by
8844 different means (the so-called ``log compilers'', @pxref{Parallel Test
8845 Harness}).
8846
8847 Test scripts can be executed serially or concurrently.  Automake
8848 supports both these kinds of test execution, with the serial test harness
8849 being the default (for backward-compatibility reasons only, as its use
8850 is nowadays discouraged).  The concurrent test harness relies on the
8851 concurrence capabilities (if any) offered by the underlying @command{make}
8852 implementation, and can thus only be as good as those are.
8853
8854 By default, only the exit statuses of the test scripts are considered when
8855 determining the testsuite outcome.  But Automake allows also the use of
8856 more complex test protocols, either standard (@pxref{Using the TAP test
8857 protocol}) or custom (@pxref{Custom Test Drivers}).  Note that you can
8858 enable such protocols only when the parallel harness is used: they won't
8859 work with the serial test harness.  In the rest of this section we are
8860 going to concentrate mostly on protocol-less tests, since we cover
8861 test protocols in a later section (again, @pxref{Custom Test Drivers}).
8862
8863 @cindex Exit status 77, special interpretation
8864 @cindex Exit status 99, special interpretation
8865 When no test protocol is in use, an exit status of 0 from a test script will
8866 denote a success, an exit status of 77 a skipped test, an exit status of 99
8867 an hard error, and any other exit status will denote a failure.
8868
8869 @cindex Tests, expected failure
8870 @cindex Expected test failure
8871 @vindex XFAIL_TESTS
8872 @vindex DISABLE_HARD_ERRORS
8873 @cindex Disabling hard errors
8874 You may define the variable @code{XFAIL_TESTS} to a list of tests
8875 (usually a subset of @code{TESTS}) that are expected to fail; this will
8876 effectively reverse the result of those tests (with the provision that
8877 skips and hard errors remain untouched).  You may also instruct the
8878 testsuite harness to treat hard errors like simple failures, by defining
8879 the @code{DISABLE_HARD_ERRORS} make variable to a nonempty value.
8880
8881 Note however that, for tests based on more complex test protocols,
8882 the exact effects of @code{XFAIL_TESTS} and @code{DISABLE_HARD_ERRORS}
8883 might change, or they might even have no effect at all (for example,
8884 @c Keep this in sync with tap-no-disable-hard-errors.sh
8885 in tests using TAP, there is not way to disable hard errors, and the
8886 @code{DISABLE_HARD_ERRORS} variable has no effect on them).
8887
8888 @anchor{Testsuite progress on console}
8889 @cindex Testsuite progress on console
8890 The result of each test case run by the scripts in @code{TESTS} will be
8891 printed on standard output, along with the test name.  For test protocols
8892 that allow more test cases per test script (such as TAP), a number,
8893 identifier and/or brief description specific for the single test case is
8894 expected to be printed in addition to the name of the test script.  The
8895 possible results (whose meanings should be clear from the previous
8896 @ref{Generalities about Testing}) are @code{PASS}, @code{FAIL},
8897 @code{SKIP}, @code{XFAIL}, @code{XPASS} and @code{ERROR}.  Here is an
8898 example of output from an hypothetical testsuite that uses both plain
8899 and TAP tests:
8900 @c Keep in sync with tap-doc.sh
8901 @example
8902 PASS: foo.sh
8903 PASS: zardoz.tap 1 - Daemon started
8904 PASS: zardoz.tap 2 - Daemon responding
8905 SKIP: zardoz.tap 3 - Daemon uses /proc # SKIP /proc is not mounted
8906 PASS: zardoz.tap 4 - Daemon stopped
8907 SKIP: bar.sh
8908 PASS: mu.tap 1
8909 XFAIL: mu.tap 2 # TODO frobnication not yet implemented
8910 @end example
8911
8912 @noindent
8913 A testsuite summary (expected to report at least the number of run,
8914 skipped and failed tests) will be printed at the end of the testsuite
8915 run.
8916
8917 @anchor{Simple tests and color-tests}
8918 @vindex AM_COLOR_TESTS
8919 @cindex Colorized testsuite output
8920 If the Automake option @code{color-tests} is used (@pxref{Options})
8921 and standard output is connected to a capable terminal, then the test
8922 results and the summary are colored appropriately.  The user can disable
8923 colored output by setting the @command{make} variable
8924 @samp{AM_COLOR_TESTS=no}, or force colored output even without a connecting
8925 terminal with @samp{AM_COLOR_TESTS=always}.  It's also worth noting that
8926 some @command{make} implementations, when used in parallel mode, have
8927 slightly different semantics (@pxref{Parallel make,,, autoconf,
8928 The Autoconf Manual}), which can break the automatic detection of a
8929 connection to a capable terminal.  If this is the case, you'll have to
8930 resort to the use of @samp{AM_COLOR_TESTS=always} in order to have the
8931 testsuite output colorized.
8932
8933 Test programs that need data files should look for them in @code{srcdir}
8934 (which is both a make variable and an environment variable made available
8935 to the tests), so that they work when building in a separate directory
8936 (@pxref{Build Directories, , Build Directories , autoconf,
8937 The Autoconf Manual}), and in particular for the @code{distcheck} rule
8938 (@pxref{Checking the Distribution}).
8939
8940 @vindex TESTS
8941 @vindex TESTS_ENVIRONMENT
8942 @vindex AM_TESTS_ENVIRONMENT
8943 The @code{AM_TESTS_ENVIRONMENT} and @code{TESTS_ENVIRONMENT} variables can
8944 be used to run initialization code and set environment variables for the
8945 test scripts.  The former variable is developer-reserved, and can be
8946 defined in the @file{Makefile.am}, while the latter is reserved for the
8947 user, which can employ it to extend or override the settings in the
8948 former; for this to work portably, however, the contents of a non-empty
8949 @code{AM_TESTS_ENVIRONMENT} @emph{must} be terminated by a semicolon.
8950
8951 @vindex AM_TESTS_FD_REDIRECT
8952 The @code{AM_TESTS_FD_REDIRECT} variable can be used to define file
8953 descriptor redirections for the test scripts.  One might think that
8954 @code{AM_TESTS_ENVIRONMENT} could be used for this purpose, but experience
8955 has shown that doing so portably is practically impossible.  The main
8956 hurdle is constituted by Korn shells, which usually set the close-on-exec
8957 flag on file descriptors opened with the @command{exec} builtin, thus
8958 rendering an idiom like @code{AM_TESTS_ENVIRONMENT = exec 9>&2;}
8959 ineffectual.  This issue also affects some Bourne shells, such as the
8960 HP-UX's @command{/bin/sh},
8961 @c FIXME: should we offer a link to the relevant discussions on the
8962 @c bug-autoconf list?
8963
8964 @c Keep in sync with tests-environment-backcompat.sh
8965 @example
8966 AM_TESTS_ENVIRONMENT = \
8967 ## Some environment initializations are kept in a separate shell
8968 ## file 'tests-env.sh', which can make it easier to also run tests
8969 ## from the command line.
8970   . $(srcdir)/tests-env.sh; \
8971 ## On Solaris, prefer more POSIX-compliant versions of the standard
8972 ## tools by default.
8973   if test -d /usr/xpg4/bin; then \
8974     PATH=/usr/xpg4/bin:$$PATH; export PATH; \
8975   fi;
8976 @c $$ restore font-lock
8977 ## With this, the test scripts will be able to print diagnostic
8978 ## messages to the original standard error stream, even if the test
8979 ## driver redirects the stderr of the test scripts to a log file
8980 ## before executing them.
8981 AM_TESTS_FD_REDIRECT = 9>&2
8982 @end example
8983
8984 @noindent
8985 Note however that @code{AM_TESTS_ENVIRONMENT} is, for historical and
8986 implementation reasons, @emph{not} supported by the serial harness
8987 (@pxref{Serial Test Harness}).
8988
8989 Automake ensures that each file listed in @code{TESTS} is built before
8990 it is run; you can list both source and derived programs (or scripts)
8991 in @code{TESTS}; the generated rule will look both in @code{srcdir} and
8992 @file{.}.  For instance, you might want to run a C program as a test.
8993 To do this you would list its name in @code{TESTS} and also in
8994 @code{check_PROGRAMS}, and then specify it as you would any other
8995 program.
8996
8997 Programs listed in @code{check_PROGRAMS} (and @code{check_LIBRARIES},
8998 @code{check_LTLIBRARIES}...) are only built during @code{make check},
8999 not during @code{make all}.  You should list there any program needed
9000 by your tests that does not need to be built by @code{make all}.  Note
9001 that @code{check_PROGRAMS} are @emph{not} automatically added to
9002 @code{TESTS} because @code{check_PROGRAMS} usually lists programs used
9003 by the tests, not the tests themselves.  Of course you can set
9004 @code{TESTS = $(check_PROGRAMS)} if all your programs are test cases.
9005
9006 @node Serial Test Harness
9007 @subsection Serial Test Harness
9008 @cindex @option{serial-tests}, Using
9009
9010 @emph{NOTE:} This harness, while still being the default one, is
9011 obsolescent, and kept mostly for backward-compatibility reasons.  The user
9012 is advised to use the parallel test harness instead (@pxref{Parallel Test
9013 Harness}).  Be warned that future Automake versions might switch to use
9014 that more modern and feature-rich harness by default.
9015
9016 The serial test harness is enabled by the Automake option
9017 @option{serial-tests}. It operates by simply running the tests serially,
9018 one at the time, without any I/O redirection.  It's up to the user to
9019 implement logging of tests' output, if that's requited or desired.
9020 @c TODO: give an example of how this can be done.
9021
9022 For historical and implementation reasons, the @code{AM_TESTS_ENVIRONMENT}
9023 variable is @emph{not} supported by this harness (it will be silently
9024 ignored if defined); only @code{TESTS_ENVIRONMENT} is, and it is to be
9025 considered a developer-reserved variable.  This is done so that, when
9026 using the serial harness, @code{TESTS_ENVIRONMENT} can be defined to an
9027 invocation of an interpreter through which the tests are to be run.
9028 For instance, the following setup may be used to run tests with Perl:
9029
9030 @example
9031 TESTS_ENVIRONMENT = $(PERL) -Mstrict -w
9032 TESTS = foo.pl bar.pl baz.pl
9033 @end example
9034
9035 @noindent
9036 It's important to note that the use of @code{TESTS_ENVIRONMENT} endorsed
9037 here would be @emph{invalid} with the parallel harness.  That harness
9038 provides a more elegant way to achieve the same effect, with the further
9039 benefit of freeing the @code{TESTS_ENVIRONMENT} variable for the user
9040 (@pxref{Parallel Test Harness}).
9041
9042 Another, less serious limit of the serial harness is that it doesn't
9043 really distinguish between simple failures and hard errors; this is
9044 due to historical reasons only, and might be fixed in future Automake
9045 versions.
9046
9047 @node Parallel Test Harness
9048 @subsection Parallel Test Harness
9049 @cindex @option{parallel-tests}, Using
9050
9051 The parallel (or concurrent) test harness is enabled by the Automake option
9052 @option{parallel-tests}.  It features automatic collection of the test
9053 scripts output in @file{.log} files, concurrent execution of tests with
9054 @code{make -j}, specification of inter-test dependencies, lazy reruns of
9055 tests that have not completed in a prior run, and hard errors for exceptional
9056 failures.
9057
9058 This harness is still somewhat experimental and may undergo changes in
9059 order to satisfy additional portability requirements.
9060
9061 @anchor{Basics of test metadata}
9062 @vindex TEST_SUITE_LOG
9063 @vindex TESTS
9064 @cindex @file{.log} files
9065 @cindex @file{.trs} files
9066 @cindex test metadata
9067 The parallel test harness operates by defining a set of @command{make}
9068 rules that run the test scripts listed in @code{TESTS}, and, for each
9069 such script, save its output in a corresponding @file{.log} file and
9070 its results (and other ``metadata'', @pxref{API for Custom Test Drivers})
9071 in a corresponding @file{.trs} (as in @b{T}est @b{R}e@b{S}ults) file.
9072 @c We choose the '.trs' extension also because, at the time of writing,
9073 @c it isn't already used for other significant purposes; see e.g.:
9074 @c   - http://filext.com/file-extension/trs
9075 @c   - http://www.file-extensions.org/search/?searchstring=trs
9076 The @file{.log} file will contain all the output emitted by the test on
9077 its standard output and its standard error.  The @file{.trs} file will
9078 contain, among the other things, the results of the test cases run by
9079 the script.
9080
9081 The parallel test harness will also create a summary log file,
9082 @code{TEST_SUITE_LOG}, which defaults to @file{test-suite.log} and requires
9083 a @file{.log} suffix.  This file depends upon all the @file{.log} and
9084 @file{.trs} files created for the test scripts listed in @code{TESTS}.
9085
9086 @vindex VERBOSE
9087 As with the serial harness above, by default one status line is printed
9088 per completed test, and a short summary after the suite has completed.
9089 However, standard output and standard error of the test are redirected
9090 to a per-test log file, so that parallel execution does not produce
9091 intermingled output.  The output from failed tests is collected in the
9092 @file{test-suite.log} file.  If the variable @samp{VERBOSE} is set, this
9093 file is output after the summary.
9094 @c FIXME: we should be clearer about what we mean exactly here ...
9095 For best results, the tests should be verbose by default now.
9096
9097 @vindex TEST_EXTENSIONS
9098 @vindex TEST_LOGS
9099 Each couple of @file{.log} and @file{.trs} files is created when the
9100 corresponding test has completed.  The set of log files is listed in
9101 the read-only variable @code{TEST_LOGS}, and defaults to @code{TESTS},
9102 with the executable extension if any (@pxref{EXEEXT}), as well as any
9103 suffix listed in @code{TEST_EXTENSIONS} removed, and @file{.log} appended.
9104 Results are undefined if a test file name ends in several concatenated
9105 suffixes.  @code{TEST_EXTENSIONS} defaults to @file{.test}; it can be
9106 overridden by the user, in which case any extension listed in it must be
9107 constituted by a dot, followed by a non-digit alphabetic character,
9108 followed by any number of alphabetic characters.
9109 @c Keep in sync with test-extensions.sh
9110 For example, @samp{.sh}, @samp{.T} and @samp{.t1} are valid extensions,
9111 while @samp{.x-y}, @samp{.6c} and @samp{.t.1} are not.
9112
9113 @vindex _LOG_COMPILE
9114 @vindex _LOG_COMPILER
9115 @vindex _LOG_FLAGS
9116 @vindex LOG_COMPILE
9117 @vindex LOG_COMPILER
9118 @vindex LOG_FLAGS
9119 @vindex @var{ext}_LOG_COMPILE
9120 @vindex @var{ext}_LOG_COMPILER
9121 @vindex @var{ext}_LOG_FLAGS
9122 @vindex AM_@var{ext}_LOG_FLAGS
9123 @vindex AM_LOG_FLAGS
9124 For tests that match an extension @code{.@var{ext}} listed in
9125 @code{TEST_EXTENSIONS}, you can provide a custom ``test runner'' using
9126 the variable @code{@var{ext}_LOG_COMPILER} (note the upper-case
9127 extension) and pass options in @code{AM_@var{ext}_LOG_FLAGS} and allow
9128 the user to pass options in @code{@var{ext}_LOG_FLAGS}.  It will cause
9129 all tests with this extension to be called with this runner.  For all
9130 tests without a registered extension, the variables @code{LOG_COMPILER},
9131 @code{AM_LOG_FLAGS}, and @code{LOG_FLAGS} may be used.  For example,
9132
9133 @c Keep in sync with parallel-tests-log-compiler-example.sh
9134 @example
9135 TESTS = foo.pl bar.py baz
9136 TEST_EXTENSIONS = .pl .py
9137 PL_LOG_COMPILER = $(PERL)
9138 AM_PL_LOG_FLAGS = -w
9139 PY_LOG_COMPILER = $(PYTHON)
9140 AM_PY_LOG_FLAGS = -v
9141 LOG_COMPILER = ./wrapper-script
9142 AM_LOG_FLAGS = -d
9143 @end example
9144
9145 @noindent
9146 will invoke @samp{$(PERL) -w foo.pl}, @samp{$(PYTHON) -v bar.py},
9147 and @samp{./wrapper-script -d baz} to produce @file{foo.log},
9148 @file{bar.log}, and @file{baz.log}, respectively.  The @file{foo.trs},
9149 @file{bar.trs} and @file{baz.trs} files will be automatically produced
9150 as a side-effect.
9151
9152 It's important to note that, differently from what we've seen for the
9153 serial test harness (@pxref{Parallel Test Harness}), the
9154 @code{AM_TESTS_ENVIRONMENT} and @code{TESTS_ENVIRONMENT} variables
9155 @emph{cannot} be use to define a custom test runner; the
9156 @code{LOG_COMPILER} and @code{LOG_FLAGS} (or their extension-specific
9157 counterparts) should be used instead:
9158
9159 @example
9160 ## This is WRONG!
9161 AM_TESTS_ENVIRONMENT = PERL5LIB='$(srcdir)/lib' $(PERL) -Mstrict -w
9162 @end example
9163
9164 @example
9165 ## Do this instead.
9166 AM_TESTS_ENVIRONMENT = PERL5LIB='$(srcdir)/lib'; export PERL5LIB;
9167 LOG_COMPILER = $(PERL)
9168 AM_LOG_FLAGS = -Mstrict -w
9169 @end example
9170
9171 By default, the test suite harness will run all tests, but there are
9172 several ways to limit the set of tests that are run:
9173
9174 @itemize @bullet
9175 @item
9176 You can set the @code{TESTS} variable.  For example, you can use a
9177 command like this to run only a subset of the tests:
9178
9179 @example
9180 env TESTS="foo.test bar.test" make -e check
9181 @end example
9182
9183 Note however that the command above will unconditionally overwrite the
9184 @file{test-suite.log} file, thus clobbering the recorded results
9185 of any previous testsuite run.  This might be undesirable for packages
9186 whose testsuite takes long time to execute.  Luckily, this problem can
9187 easily be avoided by overriding also @code{TEST_SUITE_LOG} at runtime;
9188 for example,
9189
9190 @c Keep in sync with parallel-tests-log-override-2.sh
9191 @example
9192 env TEST_SUITE_LOG=partial.log TESTS="..." make -e check
9193 @end example
9194
9195 will write the result of the partial testsuite runs to the
9196 @file{partial.log}, without touching @file{test-suite.log}.
9197
9198 @item
9199 You can set the @code{TEST_LOGS} variable.  By default, this variable is
9200 computed at @command{make} run time from the value of @code{TESTS} as
9201 described above.  For example, you can use the following:
9202
9203 @example
9204 set x subset*.log; shift
9205 env TEST_LOGS="foo.log $*" make -e check
9206 @end example
9207
9208 The comments made above about @code{TEST_SUITE_LOG} overriding applies
9209 here too.
9210
9211 @item
9212 @vindex RECHECK_LOGS
9213 @cindex lazy test execution
9214 By default, the test harness removes all old per-test @file{.log} and
9215 @file{.trs} files before it starts running tests to regenerate them.  The
9216 variable @code{RECHECK_LOGS} contains the set of @file{.log} (and, by
9217 implication, @file{.trs}) files which are removed.  @code{RECHECK_LOGS}
9218 defaults to @code{TEST_LOGS}, which means all tests need to be rechecked.
9219 By overriding this variable, you can choose which tests need to be
9220 reconsidered.  For example, you can lazily rerun only those tests which
9221 are outdated, i.e., older than their prerequisite test files, by setting
9222 this variable to the empty value:
9223
9224 @example
9225 env RECHECK_LOGS= make -e check
9226 @end example
9227
9228 @item
9229 @trindex recheck
9230 You can ensure that all tests are rerun which have failed or passed
9231 unexpectedly, by running @code{make recheck} in the test directory.
9232 This convenience target will set @code{RECHECK_LOGS} appropriately
9233 before invoking the main test harness.
9234 @end itemize
9235
9236 @noindent
9237 In order to guarantee an ordering between tests even with @code{make
9238 -j@var{N}}, dependencies between the corresponding @file{.log} files
9239 may be specified through usual @command{make} dependencies.  For example,
9240 the following snippet lets the test named @file{foo-execute.test} depend
9241 upon completion of the test @file{foo-compile.test}:
9242
9243 @example
9244 TESTS = foo-compile.test foo-execute.test
9245 foo-execute.log: foo-compile.log
9246 @end example
9247
9248 @noindent
9249 Please note that this ordering ignores the @emph{results} of required
9250 tests, thus the test @file{foo-execute.test} is run even if the test
9251 @file{foo-compile.test} failed or was skipped beforehand.  Further,
9252 please note that specifying such dependencies currently works only for
9253 tests that end in one of the suffixes listed in @code{TEST_EXTENSIONS}.
9254
9255 Tests without such specified dependencies may be run concurrently with
9256 parallel @command{make -j@var{N}}, so be sure they are prepared for
9257 concurrent execution.
9258
9259 @cindex Unit tests
9260 @c Keep in sync with 'parallel-tests-extra-programs.sh'.
9261 The combination of lazy test execution and correct dependencies between
9262 tests and their sources may be exploited for efficient unit testing
9263 during development.  To further speed up the edit-compile-test cycle, it
9264 may even be useful to specify compiled programs in @code{EXTRA_PROGRAMS}
9265 instead of with @code{check_PROGRAMS}, as the former allows intertwined
9266 compilation and test execution (but note that @code{EXTRA_PROGRAMS} are
9267 not cleaned automatically, @pxref{Uniform}).
9268
9269 The variables @code{TESTS} and @code{XFAIL_TESTS} may contain
9270 conditional parts as well as configure substitutions.  In the latter
9271 case, however, certain restrictions apply: substituted test names
9272 must end with a nonempty test suffix like @file{.test}, so that one of
9273 the inference rules generated by @command{automake} can apply.  For
9274 literal test names, @command{automake} can generate per-target rules
9275 to avoid this limitation.
9276
9277 Please note that it is currently not possible to use @code{$(srcdir)/}
9278 or @code{$(top_srcdir)/} in the @code{TESTS} variable.  This technical
9279 limitation is necessary to avoid generating test logs in the source tree
9280 and has the unfortunate consequence that it is not possible to specify
9281 distributed tests that are themselves generated by means of explicit
9282 rules, in a way that is portable to all @command{make} implementations
9283 (@pxref{Make Target Lookup,,, autoconf, The Autoconf Manual}, the
9284 semantics of FreeBSD and OpenBSD @command{make} conflict with this).
9285 In case of doubt you may want to require to use GNU @command{make},
9286 or work around the issue with inference rules to generate the tests.
9287
9288 @node Custom Test Drivers
9289 @section Custom Test Drivers
9290
9291 @menu
9292 * Overview of Custom Test Drivers Support::
9293 * Declaring Custom Test Drivers::
9294 * API for Custom Test Drivers::
9295 @end menu
9296
9297 @node Overview of Custom Test Drivers Support
9298 @subsection Overview of Custom Test Drivers Support
9299
9300 Starting from Automake version 1.12, the parallel test harness allows
9301 the package authors to use third-party custom test drivers, in case the
9302 default ones are inadequate for their purposes, or do not support their
9303 testing protocol of choice.
9304
9305 A custom test driver is expected to properly run the test programs passed
9306 to it (including the command-line arguments passed to those programs, if
9307 any), to analyze their execution and outcome, to create the @file{.log}
9308 and @file{.trs} files associated to these test runs, and to display the test
9309 results on the console. It is responsibility of the author of the test
9310 driver to ensure that it implements all the above steps meaningfully and
9311 correctly; Automake isn't and can't be of any help here.  On the other
9312 hand, the Automake-provided code for testsuite summary generation offers
9313 support for test drivers allowing several test results per test script,
9314 if they take care to register such results properly (@pxref{Log files
9315 generation and test results recording}).
9316
9317 The exact details of how test scripts' results are to be determined and
9318 analyzed is left to the individual drivers.  Some drivers might only
9319 consider the test script exit status (this is done for example by the
9320 default test driver used by the parallel test harness, described
9321 in the previous section).  Other drivers might implement more complex and
9322 advanced test protocols, which might require them to parse and interpreter
9323 the output emitted by the test script they're running (examples of such
9324 protocols are TAP and SubUnit).
9325
9326 It's very important to note that, even when using custom test drivers,
9327 most of the infrastructure described in the previous section about the
9328 parallel harness remains in place; this includes:
9329
9330 @itemize
9331 @item
9332 list of test scripts defined in @code{TESTS}, and overridable at
9333 runtime through the redefinition of @code{TESTS} or @code{TEST_LOGS};
9334 @item
9335 concurrency through the use of @command{make}'s option @option{-j};
9336 @item
9337 per-test @file{.log} and @file{.trs} files, and generation of a summary
9338 @file{.log} file from them;
9339 @item
9340 @code{recheck} target, @code{RECHECK_LOGS} variable, and lazy reruns
9341 of tests;
9342 @item
9343 inter-test dependencies;
9344 @item
9345 support for @code{check_*} variables (@code{check_PROGRAMS},
9346 @code{check_LIBRARIES}, ...);
9347 @item
9348 use of @code{VERBOSE} environment variable to get verbose output on
9349 testsuite failures;
9350 @item
9351 definition and honoring of @code{TESTS_ENVIRONMENT},
9352 @code{AM_TESTS_ENVIRONMENT} and @code{AM_TESTS_FD_REDIRECT}
9353 variables;
9354 @item
9355 definition of generic and extension-specific @code{LOG_COMPILER} and
9356 @code{LOG_FLAGS} variables.
9357 @end itemize
9358
9359 @noindent
9360 On the other hand, the exact semantics of how (and if)
9361 @option{color-tests}, @code{XFAIL_TESTS}, and hard errors are supported
9362 and handled is left to the individual test drivers.
9363
9364 @c TODO: We should really add a working example in the doc/ directory,
9365 @c TODO: and reference if from here.
9366
9367 @node Declaring Custom Test Drivers
9368 @subsection Declaring Custom Test Drivers
9369
9370 @vindex _LOG_DRIVER
9371 @vindex _LOG_DRIVER_FLAGS
9372 @vindex LOG_DRIVER
9373 @vindex LOG_DRIVER_FLAGS
9374 @vindex @var{ext}_LOG_DRIVER
9375 @vindex @var{ext}_LOG_DRIVER_FLAGS
9376 @vindex AM_@var{ext}_LOG_DRIVER_FLAGS
9377 @vindex AM_LOG_DRIVER_FLAGS
9378 Custom testsuite drivers are declared by defining the make variables
9379 @code{LOG_DRIVER} or @code{@var{ext}_LOG_DRIVER} (where @var{ext} must
9380 be declared in @code{TEST_EXTENSIONS}).  They must be defined to
9381 programs or scripts that will be used to drive the execution, logging,
9382 and outcome report of the tests with corresponding extensions (or of
9383 those with no registered extension in the case of @code{LOG_DRIVER}).
9384 Clearly, multiple distinct test drivers can be declared in the same
9385 @file{Makefile.am}.  Note moreover that the @code{LOG_DRIVER} variables
9386 are @emph{not} a substitute for the @code{LOG_COMPILER} variables: the
9387 two sets of variables can, and often do, usefully and legitimately
9388 coexist.
9389
9390 @c TODO: We should really be able to point to a clarifying example here!
9391
9392 The developer-reserved variable @code{AM_LOG_DRIVER_FLAGS} and the
9393 user-reserved variable @code{LOG_DRIVER_FLAGS} can be used to define
9394 flags that will be passed to each invocation of @code{LOG_DRIVER},
9395 with the user-defined flags obviously taking precedence over the
9396 developer-reserved ones.  Similarly, for each extension @var{ext}
9397 declared in @code{TEST_EXTENSIONS}, flags listed in
9398 @code{AM_@var{ext}_LOG_DRIVER_FLAGS} and
9399 @code{@var{ext}_LOG_DRIVER_FLAGS} will be passed to
9400 invocations of @code{@var{ext}_LOG_DRIVER}.
9401
9402 @node API for Custom Test Drivers
9403 @subsection API for Custom Test Drivers
9404
9405 Note that @emph{the APIs described here are still highly experimental},
9406 and will very likely undergo tightenings and likely also extensive changes
9407 in the future, to accommodate for new features or to satisfy additional
9408 portability requirements.
9409
9410 The main characteristic of these APIs is that they are designed to share
9411 as much infrastructure, semantics, and implementation details as possible
9412 with the parallel test harness and its default driver.
9413
9414 @menu
9415 * Command-line arguments for test drivers::
9416 * Log files generation and test results recording::
9417 * Testsuite progress output::
9418 @end menu
9419
9420 @node Command-line arguments for test drivers
9421 @subsubsection Command-line arguments for test drivers
9422
9423 A custom driver can rely on various command-line options and arguments
9424 being passed to it automatically by the Automake's @option{parallel-tests}
9425 harness.  It is @emph{mandatory} that it understands all of them (even
9426 if the exact interpretation of the associated semantics can legitimately
9427 change between a test driver and another, and even be a no-op in some
9428 drivers).
9429
9430 @noindent
9431 Here is the list of options:
9432
9433 @table @option
9434 @item --test-name=@var{NAME}
9435 The name of the test, with VPATH prefix (if any) removed.  This can have a
9436 suffix and a directory component (as in e.g., @file{sub/foo.test}), and is
9437 mostly meant to be used in console reports about testsuite advancements and
9438 results (@pxref{Testsuite progress output}).
9439 @item --log-file=@file{@var{PATH}.log}
9440 The @file{.log} file the test driver must create (@pxref{Basics of
9441 test metadata}).  If it has a directory component (as in e.g.,
9442 @file{sub/foo.log}), the test harness will ensure that such directory
9443 exists @emph{before} the test driver is called.
9444 @item --trs-file=@file{@var{PATH}.trs}
9445 The @file{.trs} file the test driver must create (@pxref{Basics of
9446 test metadata}).  If it has a directory component (as in e.g.,
9447 @file{sub/foo.trs}), the test harness will ensure that such directory
9448 exists @emph{before} the test driver is called.
9449 @item --color-tests=@{yes|no@}
9450 Whether the console output should be colorized or not (@pxref{Simple
9451 tests and color-tests}, to learn when this option gets activated and
9452 when it doesn't).
9453 @item --expect-failure=@{yes|no@}
9454 Whether the tested program is expected to fail.
9455 @item --enable-hard-errors=@{yes|no@}
9456 Whether ``hard errors'' in the tested program should be treated differently
9457 from normal failures or not (the default should be @code{yes}).  The exact
9458 meaning of ``hard error'' is highly dependent from the test protocols or
9459 conventions in use.
9460 @item --
9461 Explicitly terminate the list of options.
9462 @end table
9463
9464 @noindent
9465 The first non-option argument passed to the test driver is the program to
9466 be run, and all the following ones are command-line options and arguments
9467 for this program.
9468
9469 Note that the exact semantics attached to the @option{--color-tests},
9470 @option{--expect-failure} and @option{--enable-hard-errors} options are
9471 left up to the individual test drivers.  Still, having a behaviour
9472 compatible or at least similar to that provided by the default
9473 @option{parallel-tests} driver is advised, as that would offer a better
9474 consistency and a more pleasant user experience.
9475
9476 @node Log files generation and test results recording
9477 @subsubsection Log files generation and test results recording
9478
9479 The test driver must correctly generate the files specified by the
9480 @option{--log-file} and @option{--trs-file} option (even when the tested
9481 program fails or crashes).
9482
9483 The @file{.log} file should ideally contain all the output produced by the
9484 tested program, plus optionally other information that might facilitate
9485 debugging or analysis of bug reports.  Apart from that, its format is
9486 basically free.
9487
9488 The @file{.trs} file is used to register some metadata through the use
9489 of custom reStructuredText fields.  This metadata is expected to be
9490 employed in various ways by the parallel test harness; for example, to
9491 count the test results when printing the testsuite summary, or to decide
9492 which tests to re-run upon @command{make reheck}.  Unrecognized metadata
9493 in a @file{.trs} file is currently ignored by the harness, but this might
9494 change in the future. The list of currently recognized metadata follows.
9495
9496 @table @code
9497
9498 @item :test-result:
9499 @cindex Register test result
9500 @cindex Register test case result
9501 @cindex Test result, registering
9502 @cindex Test case result, registering
9503 @cindex @code{:test-result:}
9504 @cindex reStructuredText field, @code{:test-result:}
9505 The test driver must use this field to register the results of @emph{each}
9506 test case run by a test script file.  Several @code{:test-result:} fields
9507 can be present in the same @file{.trs} file; this is done in order to
9508 support test protocols that allow a single test script to run more test
9509 cases.
9510
9511 @c Keep this in sync with lib/am/check-am:$(TEST_SUITE_LOG).
9512 The only recognized test results are currently @code{PASS}, @code{XFAIL},
9513 @code{SKIP}, @code{FAIL}, @code{XPASS} and @code{ERROR}.  These results,
9514 when declared with @code{:test-result:}, can be optionally followed by
9515 text holding the name and/or a brief description of the corresponding
9516 test; the @option{parallel-tests} harness will ignore such extra text when
9517 generating @file{test-suite.log} and preparing the testsuite summary.
9518
9519 @c Keep in sync with 'test-metadata-recheck.sh'.
9520 @item @code{:recheck:}
9521 @cindex :recheck:
9522 @cindex reStructuredText field, @code{:recheck:}
9523 If this field is present and defined to @code{no}, then the corresponding
9524 test script will @emph{not} be run upon a @command{make recheck}.  What
9525 happens when two or more @code{:recheck:} fields are present in the same
9526 @file{.trs} file is undefined behaviour.
9527
9528 @c Keep in sync with 'test-metadata-global-log.sh'.
9529 @item @code{:copy-in-global-log:}
9530 @cindex :copy-in-global-log:
9531 @cindex reStructuredText field, @code{:copy-in-global-log:}
9532 If this field is present and defined to @code{no}, then the content
9533 of the @file{.log} file will @emph{not} be copied into the global
9534 @file{test-suite.log}.  We allow to forsake such copying because, while
9535 it can be useful in debugging and analysis of bug report, it can also be
9536 just a waste of space in normal situations, e.g., when a test script is
9537 successful.  What happens when two or more @code{:copy-in-global-log:}
9538 fields are present in the same @file{.trs} file is undefined behaviour.
9539
9540 @c Keep in sync with 'test-metadata-global-result.sh'.
9541 @item @code{:test-global-result:}
9542 @cindex :test-global-result:
9543 @cindex reStructuredText field, @code{:test-global-result:}
9544 This is used to declare the "global result" of the script.  Currently,
9545 the value of this field is needed only to be reported (more or less
9546 verbatim) in the generated global log file @code{$(TEST_SUITE_LOG)},
9547 so it's quite free-form.  For example, a test script which run 10 test
9548 cases, 6 of which pass and 4 of which are skipped, could reasonably have
9549 a @code{PASS/SKIP} value for this field, while a test script which run
9550 19 successful tests and one failed test could have an @code{ALMOST
9551 PASSED} value.  What happens when two or more @code{:test-global-result:}
9552 fields are present in the same @file{.trs} file is undefined behaviour.
9553 @end table
9554
9555 @noindent
9556 Let's see a small example.  Assume a @file{.trs} file contains the
9557 following lines:
9558
9559 @example
9560 :test-result: PASS server starts
9561 :global-log-copy: no
9562 :test-result: PASS HTTP/1.1 request
9563 :test-result: FAIL HTTP/1.0 request
9564 :recheck: yes
9565 :test-result: SKIP HTTPS request (TLS library wasn't available)
9566 :test-result: PASS server stops
9567 @end example
9568
9569 @noindent
9570 Then the corresponding test script will be re-run by @command{make check},
9571 will contribute with @emph{five} test results to the testsuite summary
9572 (three of these tests being successful, one failed, and one skipped), and
9573 the content of the corresponding @file{.log} file will @emph{not} be
9574 copied in the global log file @file{test-suite.log}.
9575
9576 @node Testsuite progress output
9577 @subsubsection Testsuite progress output
9578
9579 A custom test driver also has the task of displaying, on the standard
9580 output, the test results as soon as they become available.  Depending on
9581 the protocol in use, it can also display the reasons for failures and
9582 skips, and, more generally, any useful diagnostic output (but remember
9583 that each line on the screen is precious, so that cluttering the screen
9584 with overly verbose information is bad idea).  The exact format of this
9585 progress output is left up to the test driver; in fact, a custom test
9586 driver might @emph{theoretically} even decide not to do any such report,
9587 leaving it all to the testsuite summary (that would be a very lousy idea,
9588 of course, and serves only to illustrate the flexibility that is
9589 granted here).
9590
9591 Remember that consistency is good; so, if possible, try to be consistent
9592 with the output of the built-in Automake test drivers, providing a similar
9593 ``look & feel''.  In particular, the testsuite progress output should be
9594 colorized when the @option{--color-tests} is passed to the driver.  On the
9595 other end, if you are using a known and widespread test protocol with
9596 well-established implementations, being consistent with those
9597 implementations' output might be a good idea too.
9598
9599 @c TODO: Give an example, maybe inspired to py.test-style output.
9600 @c TODO: That is a good idea because it shows a test driver that allows
9601 @c TODO: for different levels of verbosity in the progress output (could
9602 @c TODO: be implemented either using a driver cmdline flag, or an
9603 @c TODO: environment variable, or both).
9604
9605 @node Using the TAP test protocol
9606 @section Using the TAP test protocol
9607
9608 @menu
9609 * Introduction to TAP::
9610 * Use TAP with the Automake test harness::
9611 * Incompatibilities with other TAP parsers and drivers::
9612 * Links and external resources on TAP::
9613 @end menu
9614
9615 @node Introduction to TAP
9616 @subsection Introduction to TAP
9617
9618 TAP, the Test Anything Protocol, is a simple text-based interface between
9619 testing modules or programs and a test harness.  The tests (also called
9620 ``TAP producers'' in this context) write test results in a simple format
9621 on standard output; a test harness (also called ``TAP consumer'') will
9622 parse and interpret these results, and properly present them to the user,
9623 and/or register them for later analysis.  The exact details of how this
9624 is accomplished can vary among different test harnesses.  The Automake
9625 parallel harness will present the results on the console in the usual
9626 fashion (@pxref{Testsuite progress on console}), and will use the
9627 @file{.trs} files (@pxref{Basics of test metadata}) to store the test
9628 results and related metadata.  Apart from that, it will try to remain
9629 as much compatible as possible with pre-existing and widespread utilities,
9630 such as the @uref{http://search.cpan.org/~andya/Test-Harness/bin/prove,
9631 @command{prove} utility}, at least for the simpler usages.
9632
9633 TAP started its life as part of the test harness for Perl, but today
9634 it has been (mostly) standardized, and has various independent
9635 implementations in different languages; among them, C, C++, Perl,
9636 Python, PHP, and Java.  For a semi-official specification of the
9637 TAP protocol, please refer to the documentation of
9638 @uref{http://search.cpan.org/~petdance/Test-Harness/lib/Test/Harness/TAP.pod,
9639       @samp{Test::Harness::TAP}}.
9640
9641 The most relevant real-world usages of TAP are obviously in the testsuites
9642 of @command{perl} and of many perl modules.  Still, also other important
9643 third-party packages, such as @uref{http://git-scm.com/, @command{git}},
9644 use TAP in their testsuite.
9645
9646 @node Use TAP with the Automake test harness
9647 @subsection Use TAP with the Automake test harness
9648
9649 Currently, the TAP driver that comes with Automake requires some by-hand
9650 steps on the developer's part (this situation should hopefully be improved
9651 in future Automake versions).  You'll have to grab the @file{tap-driver.sh}
9652 script from the Automake distribution by hand, copy it in your source tree,
9653 add a call to @code{AC_PROG_AWK} in @file{configure.ac} to search for a
9654 proper awk program, and use the Automake support for third-party test
9655 drivers to instruct the harness to use the @file{tap-driver.sh} script
9656 and that awk program to run your TAP-producing tests.  See the example
9657 below for clarification.
9658
9659 Apart from the options common to all the Automake test drivers
9660 (@pxref{Command-line arguments for test drivers}), the @file{tap-driver.sh}
9661 supports the following options, whose names are chosen for enhanced
9662 compatibility with the @command{prove} utility.
9663
9664 @table @option
9665 @c Keep in sync with 'tap-exit.sh' and 'tap-signal.tap'.
9666 @item --ignore-exit
9667 Causes the test driver to ignore the exit status of the test scripts;
9668 by default, the driver will report an error if the script exits with a
9669 non-zero status.  This option has effect also on non-zero exit statuses
9670 due to termination by a signal.
9671 @item --comments
9672 Instruct the test driver to display TAP diagnostic (i.e., lines beginning
9673 with the @samp{#} character) in the testsuite progress output too; by
9674 default, TAP diagnostic is only copied to the @file{.log} file.
9675 @item --no-comments
9676 Revert the effects of @option{--comments}.
9677 @item --merge
9678 Instruct the test driver to merge the test scripts' standard error into
9679 their standard output.  This is necessary if you want to ensure that
9680 diagnostics from the test scripts are displayed in the correct order
9681 relative to test results; this can be of great help in debugging
9682 (especially if your test scripts are shell scripts run with shell
9683 tracing active).  As a downside, this option might cause the test
9684 harness to get confused if anything that appears on standard error
9685 looks like a test result.
9686 @item --no-merge
9687 Revert the effects of @option{--merge}.
9688 @item --diagnostic-string=@var{STRING}
9689 Change the string that introduces TAP diagnostic from the default value
9690 of ``@code{#}'' to @code{@var{STRING}}.  This can be useful if your
9691 TAP-based test scripts produce verbose output on which they have limited
9692 control (because, say, the output comes from other tools invoked in the
9693 scripts), and it might contain text that gets spuriously interpreted as
9694 TAP diagnostic: such an issue can be solved by redefining the string that
9695 activates TAP diagnostic to a value you know won't appear by chance in
9696 the tests' output.  Note however that this feature is non-standard, as
9697 the ``official'' TAP protocol does not allow for such a customization; so
9698 don't use it if you can avoid it.
9699 @end table
9700
9701 @noindent
9702 Here is an example of how the TAP driver can be set up and used.
9703
9704 @c Keep in sync with tap-doc2.sh
9705 @example
9706 % @kbd{cat configure.ac}
9707 AC_INIT([GNU Try Tap], [1.0], [bug-automake@@gnu.org])
9708 AC_CONFIG_AUX_DIR([build-aux])
9709 AM_INIT_AUTOMAKE([foreign parallel-tests -Wall -Werror])
9710 AC_CONFIG_FILES([Makefile])
9711 AC_REQUIRE_AUX_FILE([tap-driver.sh])
9712 AC_PROG_AWK
9713 AC_OUTPUT
9714
9715 % @kbd{cat Makefile.am}
9716 TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
9717                   $(top_srcdir)/build-aux/tap-driver.sh
9718 TESTS = foo.test bar.test baz.test
9719 EXTRA_DIST = $(TESTS)
9720
9721 % @kbd{cat foo.test}
9722 #!/bin/sh
9723 echo 1..4 # Number of tests to be executed.
9724 echo 'ok 1 - Swallows fly'
9725 echo 'not ok 2 - Caterpillars fly # TODO metamorphosis in progress'
9726 echo 'ok 3 - Pigs fly # SKIP not enough acid'
9727 echo '# I just love word plays ...'
9728 echo 'ok 4 - Flies fly too :-)'
9729
9730 % @kbd{cat bar.test}
9731 #!/bin/sh
9732 echo 1..3
9733 echo 'not ok 1 - Bummer, this test has failed.'
9734 echo 'ok 2 - This passed though.'
9735 echo 'Bail out! Ennui kicking in, sorry...'
9736 echo 'ok 3 - This will not be seen.'
9737
9738 % @kbd{cat baz.test}
9739 #!/bin/sh
9740 echo 1..1
9741 echo ok 1
9742 # Exit with error, even if all the tests have been successful.
9743 exit 7
9744
9745 % @kbd{cp @var{PREFIX}/share/automake-@var{APIVERSION}/tap-driver.pl .}
9746 % @kbd{autoreconf -vi && ./configure && make check}
9747 ...
9748 PASS: foo.test 1 - Swallows fly
9749 XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
9750 SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
9751 PASS: foo.test 4 - Flies fly too :-)
9752 FAIL: bar.test 1 - Bummer, this test has failed.
9753 PASS: bar.test 2 - This passed though.
9754 ERROR: bar.test - Bail out! Ennui kicking in, sorry...
9755 PASS: baz.test 1
9756 ERROR: baz.test - exited with status 7
9757 ...
9758 Please report to bug-automake@@gnu.org
9759 ...
9760 % @kbd{echo exit status: $?}
9761 exit status: 1
9762
9763 @c Keep the "skewed" indentation below, it produces pretty PDF output.
9764 % @kbd{env TEST_LOG_DRIVER_FLAGS='--comments --ignore-exit' \
9765       TESTS='foo.test baz.test' make -e check}
9766 ...
9767 PASS: foo.test 1 - Swallows fly
9768 XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
9769 SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
9770 # foo.test: I just love word plays...
9771 PASS: foo.test 4 - Flies fly too :-)
9772 PASS: baz.test 1
9773 ...
9774 % @kbd{echo exit status: $?}
9775 exit status: 0
9776 @end example
9777
9778 @node Incompatibilities with other TAP parsers and drivers
9779 @subsection Incompatibilities with other TAP parsers and drivers
9780
9781 For implementation or historical reasons, the TAP driver and harness as
9782 implemented by Automake have some minors incompatibilities with the
9783 mainstream versions, which you should be aware of.
9784
9785 @itemize @bullet
9786 @item
9787 A @code{Bail out!} directive doesn't stop the whole testsuite, but only
9788 the test script it occurs in.  This doesn't follow TAP specifications,
9789 but on the other hand it maximizes compatibility (and code sharing) with
9790 the ``hard error'' concept of the default @option{parallel-tests} driver.
9791 @item
9792 The @code{version} and @code{pragma} directives are not supported.
9793 @item
9794 The @option{--diagnostic-string} option of our driver allows to modify
9795 the string that introduces TAP diagnostic from the default value
9796 of ``@code{#}''.  The standard TAP protocol has currently no way to
9797 allow this, so if you use it your diagnostic will be lost to more
9798 compliant tools like @command{prove} and @code{Test::Harness}
9799 @item
9800 And there are probably some other small and yet undiscovered
9801 incompatibilities, especially in corner cases or with rare usages.
9802 @end itemize
9803
9804 @node Links and external resources on TAP
9805 @subsection Links and external resources on TAP
9806
9807 @noindent
9808 Here are some links to more extensive official or third-party
9809 documentation and resources about the TAP protocol and related
9810 tools and libraries.
9811 @itemize @bullet
9812 @item
9813 @uref{http://search.cpan.org/~petdance/Test-Harness/lib/Test/Harness/TAP.pod,
9814       @samp{Test::Harness::TAP}},
9815 the (mostly) official documentation about the TAP format and protocol.
9816 @item
9817 @uref{http://search.cpan.org/~andya/Test-Harness/bin/prove,
9818       @command{prove}},
9819 the most famous command-line TAP test driver, included in the distribution
9820 of @command{perl} and
9821 @uref{http://search.cpan.org/~andya/Test-Harness/lib/Test/Harness.pm,
9822       @samp{Test::Harness}}.
9823 @item
9824 The @uref{http://testanything.org/wiki/index.php/Main_Page,TAP wiki}.
9825 @item
9826 A ``gentle introduction'' to testing for perl coders:
9827 @uref{http://search.cpan.org/dist/Test-Simple/lib/Test/Tutorial.pod,
9828       @samp{Test::Tutorial}}.
9829 @item
9830 @uref{http://search.cpan.org/~mschwern/Test-Simple/lib/Test/Simple.pm,
9831       @samp{Test::Simple}}
9832 and
9833 @uref{http://search.cpan.org/~mschwern/Test-Simple/lib/Test/More.pm,
9834       @samp{Test::More}},
9835 the standard perl testing libraries, which are based on TAP.
9836 @item
9837 @uref{http://www.eyrie.org/~eagle/software/c-tap-harness/,C TAP Harness},
9838 a C-based project implementing both a TAP producer and a TAP consumer.
9839 @item
9840 @uref{http://www.tap4j.org/,tap4j},
9841 a Java-based project implementing both a TAP producer and a TAP consumer.
9842 @end itemize
9843
9844 @node DejaGnu Tests
9845 @section DejaGnu Tests
9846
9847 If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @command{dejagnu}} appears in
9848 @code{AUTOMAKE_OPTIONS}, then a @command{dejagnu}-based test suite is
9849 assumed.  The variable @code{DEJATOOL} is a list of names that are
9850 passed, one at a time, as the @option{--tool} argument to
9851 @command{runtest} invocations; it defaults to the name of the package.
9852
9853 The variable @code{RUNTESTDEFAULTFLAGS} holds the @option{--tool} and
9854 @option{--srcdir} flags that are passed to dejagnu by default; this can be
9855 overridden if necessary.
9856 @vindex RUNTESTDEFAULTFLAGS
9857
9858 The variables @code{EXPECT} and @code{RUNTEST} can
9859 also be overridden to provide project-specific values.  For instance,
9860 you will need to do this if you are testing a compiler toolchain,
9861 because the default values do not take into account host and target
9862 names.
9863 @opindex dejagnu
9864 @vindex DEJATOOL
9865 @vindex EXPECT
9866 @vindex RUNTEST
9867
9868 The contents of the variable @code{RUNTESTFLAGS} are passed to the
9869 @code{runtest} invocation.  This is considered a ``user variable''
9870 (@pxref{User Variables}).  If you need to set @command{runtest} flags in
9871 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
9872 @vindex RUNTESTFLAGS
9873 @vindex AM_RUNTESTFLAGS
9874
9875 @cindex @file{site.exp}
9876 Automake will generate rules to create a local @file{site.exp} file,
9877 defining various variables detected by @command{configure}.  This file
9878 is automatically read by DejaGnu.  It is OK for the user of a package
9879 to edit this file in order to tune the test suite.  However this is
9880 not the place where the test suite author should define new variables:
9881 this should be done elsewhere in the real test suite code.
9882 Especially, @file{site.exp} should not be distributed.
9883
9884 Still, if the package author has legitimate reasons to extend
9885 @file{site.exp} at @command{make} time, he can do so by defining
9886 the variable @code{EXTRA_DEJAGNU_SITE_CONFIG}; the files listed
9887 there will be considered @file{site.exp} prerequisites, and their
9888 content will be appended to it (in the same order in which they
9889 appear in @code{EXTRA_DEJAGNU_SITE_CONFIG}).  Note that files are
9890 @emph{not} distributed by default.
9891
9892 For more information regarding DejaGnu test suites, see @ref{Top, , ,
9893 dejagnu, The DejaGnu Manual}.
9894
9895 @node Install Tests
9896 @section Install Tests
9897
9898 The @code{installcheck} target is available to the user as a way to
9899 run any tests after the package has been installed.  You can add tests
9900 to this by writing an @code{installcheck-local} rule.
9901
9902
9903 @node Rebuilding
9904 @chapter Rebuilding Makefiles
9905 @cindex rebuild rules
9906
9907 Automake generates rules to automatically rebuild @file{Makefile}s,
9908 @file{configure}, and other derived files like @file{Makefile.in}.
9909
9910 @acindex AM_MAINTAINER_MODE
9911 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.ac}, then
9912 these automatic rebuilding rules are only enabled in maintainer mode.
9913
9914 @vindex ACLOCAL_AMFLAGS
9915 Sometimes you need to run @command{aclocal} with an argument like
9916 @option{-I} to tell it where to find @file{.m4} files.  Since
9917 sometimes @command{make} will automatically run @command{aclocal}, you
9918 need a way to specify these arguments.  You can do this by defining
9919 @code{ACLOCAL_AMFLAGS}; this holds arguments that are passed verbatim
9920 to @command{aclocal}.  This variable is only useful in the top-level
9921 @file{Makefile.am}.
9922
9923 @vindex CONFIG_STATUS_DEPENDENCIES
9924 @vindex CONFIGURE_DEPENDENCIES
9925 @cindex @file{version.sh}, example
9926 @cindex @file{version.m4}, example
9927
9928 Sometimes it is convenient to supplement the rebuild rules for
9929 @file{configure} or @file{config.status} with additional dependencies.
9930 The variables @code{CONFIGURE_DEPENDENCIES} and
9931 @code{CONFIG_STATUS_DEPENDENCIES} can be used to list these extra
9932 dependencies.  These variables should be defined in all
9933 @file{Makefile}s of the tree (because these two rebuild rules are
9934 output in all them), so it is safer and easier to @code{AC_SUBST} them
9935 from @file{configure.ac}.  For instance, the following statement will
9936 cause @file{configure} to be rerun each time @file{version.sh} is
9937 changed.
9938
9939 @example
9940 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh'])
9941 @end example
9942
9943 @noindent
9944 Note the @samp{$(top_srcdir)/} in the file name.  Since this variable
9945 is to be used in all @file{Makefile}s, its value must be sensible at
9946 any level in the build hierarchy.
9947
9948 Beware not to mistake @code{CONFIGURE_DEPENDENCIES} for
9949 @code{CONFIG_STATUS_DEPENDENCIES}.
9950
9951 @code{CONFIGURE_DEPENDENCIES} adds dependencies to the
9952 @file{configure} rule, whose effect is to run @command{autoconf}.  This
9953 variable should be seldom used, because @command{automake} already tracks
9954 @code{m4_include}d files.  However it can be useful when playing
9955 tricky games with @code{m4_esyscmd} or similar non-recommendable
9956 macros with side effects.
9957
9958 @code{CONFIG_STATUS_DEPENDENCIES} adds dependencies to the
9959 @file{config.status} rule, whose effect is to run @file{configure}.
9960 This variable should therefore carry any non-standard source that may
9961 be read as a side effect of running @command{configure}, like @file{version.sh}
9962 in the example above.
9963
9964 Speaking of @file{version.sh} scripts, we recommend against them
9965 today.  They are mainly used when the version of a package is updated
9966 automatically by a script (e.g., in daily builds).  Here is what some
9967 old-style @file{configure.ac}s may look like:
9968
9969 @example
9970 AC_INIT
9971 . $srcdir/version.sh
9972 AM_INIT_AUTOMAKE([name], $VERSION_NUMBER)
9973 @dots{}
9974 @end example
9975
9976 @noindent
9977 Here, @file{version.sh} is a shell fragment that sets
9978 @code{VERSION_NUMBER}.  The problem with this example is that
9979 @command{automake} cannot track dependencies (listing @file{version.sh}
9980 in @command{CONFIG_STATUS_DEPENDENCIES}, and distributing this file is up
9981 to the user), and that it uses the obsolete form of @code{AC_INIT} and
9982 @code{AM_INIT_AUTOMAKE}.  Upgrading to the new syntax is not
9983 straightforward, because shell variables are not allowed in
9984 @code{AC_INIT}'s arguments.  We recommend that @file{version.sh} be
9985 replaced by an M4 file that is included by @file{configure.ac}:
9986
9987 @example
9988 m4_include([version.m4])
9989 AC_INIT([name], VERSION_NUMBER)
9990 AM_INIT_AUTOMAKE
9991 @dots{}
9992 @end example
9993
9994 @noindent
9995 Here @file{version.m4} could contain something like
9996 @samp{m4_define([VERSION_NUMBER], [1.2])}.  The advantage of this
9997 second form is that @command{automake} will take care of the
9998 dependencies when defining the rebuild rule, and will also distribute
9999 the file automatically.  An inconvenience is that @command{autoconf}
10000 will now be rerun each time the version number is bumped, when only
10001 @file{configure} had to be rerun in the previous setup.
10002
10003
10004 @node Options
10005 @chapter Changing Automake's Behavior
10006
10007 @menu
10008 * Options generalities::        Semantics of Automake option
10009 * List of Automake options::    A comprehensive list of Automake options
10010 @end menu
10011
10012 @node Options generalities
10013 @section Options generalities
10014
10015 Various features of Automake can be controlled by options.  Except where
10016 noted otherwise, options can be specified in one of several ways.  Most
10017 options can be applied on a per-@file{Makefile} basis when listed in a
10018 special @file{Makefile} variable named @code{AUTOMAKE_OPTIONS}.  Some
10019 of these options only make sense when specified in the toplevel
10020 @file{Makefile.am} file.  Options are applied globally to all processed
10021 @file{Makefile} files when listed in the first argument of
10022 @code{AM_INIT_AUTOMAKE} in @file{configure.ac}, and some options which
10023 require changes to the @command{configure} script can only be specified
10024 there.  These are annotated below.
10025
10026 As a general rule, options specified in @code{AUTOMAKE_OPTIONS} take
10027 precedence over those specified in @code{AM_INIT_AUTOMAKE}, which in
10028 turn take precedence over those specified on the command line.
10029
10030 Also, some care must be taken about the interactions among strictness
10031 level and warning categories.  As a general rule, strictness-implied
10032 warnings are overridden by those specified by explicit options.  For
10033 example, even if @samp{portability} warnings are disabled by default
10034 in @option{foreign} strictness, an usage like this will end up enabling
10035 them:
10036
10037 @example
10038 AUTOMAKE_OPTIONS = -Wportability foreign
10039 @end example
10040
10041 However, a strictness level specified in a higher-priority context
10042 will override all the explicit warnings specified in a lower-priority
10043 context.  For example, if @file{configure.ac} contains:
10044
10045 @example
10046 AM_INIT_AUTOMAKE([-Wportability])
10047 @end example
10048
10049 @noindent
10050 and @file{Makefile.am} contains:
10051
10052 @example
10053 AUTOMAKE_OPTIONS = foreign
10054 @end example
10055
10056 @noindent
10057 then @samp{portability} warnings will be @emph{disabled} in
10058 @file{Makefile.am}.
10059
10060 @node List of Automake options
10061 @section List of Automake options
10062
10063 @vindex AUTOMAKE_OPTIONS
10064
10065 @table @asis
10066 @item @option{gnits}
10067 @itemx @option{gnu}
10068 @itemx @option{foreign}
10069 @itemx @option{cygnus}
10070 @cindex Option, @option{gnits}
10071 @cindex Option, @option{gnu}
10072 @cindex Option, @option{foreign}
10073 @cindex Option, @option{cygnus}
10074 @opindex gnits
10075 @opindex gnu
10076 @opindex foreign
10077 @opindex cygnus
10078
10079 Set the strictness as appropriate.  The @option{gnits} option also
10080 implies options @option{readme-alpha} and @option{check-news}.
10081
10082 @item @option{check-news}
10083 @cindex Option, @option{check-news}
10084 @opindex check-news
10085 Cause @samp{make dist} to fail unless the current version number appears
10086 in the first few lines of the @file{NEWS} file.
10087
10088 @item @option{color-tests}
10089 @cindex Option, @option{color-tests}
10090 @opindex color-tests
10091 Cause output of the serial and parallel test harnesses (see @ref{Simple
10092 Tests}) and of properly-written custom test drivers (@pxref{Custom Test
10093 Drivers}) to be colorized on capable terminals.
10094
10095 @item @option{dejagnu}
10096 @cindex Option, @option{dejagnu}
10097 @opindex dejagnu
10098 Cause @command{dejagnu}-specific rules to be generated.  @xref{DejaGnu Tests}.
10099
10100 @item @option{dist-bzip2}
10101 @cindex Option, @option{dist-bzip2}
10102 @opindex dist-bzip2
10103 Hook @code{dist-bzip2} to @code{dist}.
10104 @trindex dist-bzip2
10105
10106 @item @option{dist-lzip}
10107 @cindex Option, @option{dist-lzip}
10108 @opindex dist-lzip
10109 Hook @code{dist-lzip} to @code{dist}.
10110 @trindex dist-lzip
10111
10112 @item @option{dist-shar}
10113 @cindex Option, @option{dist-shar}
10114 @opindex dist-shar
10115 Hook @code{dist-shar} to @code{dist}.
10116 @trindex dist-shar
10117
10118 @item @option{dist-zip}
10119 @cindex Option, @option{dist-zip}
10120 @opindex dist-zip
10121 Hook @code{dist-zip} to @code{dist}.
10122 @trindex dist-zip
10123
10124 @item @option{dist-tarZ}
10125 @cindex Option, @option{dist-tarZ}
10126 @opindex dist-tarZ
10127 Hook @code{dist-tarZ} to @code{dist}.
10128 @trindex dist-tarZ
10129
10130 @item @option{filename-length-max=99}
10131 @cindex Option, @option{filename-length-max=99}
10132 @opindex filename-length-max=99
10133 Abort if file names longer than 99 characters are found during
10134 @samp{make dist}.  Such long file names are generally considered not to
10135 be portable in tarballs.  See the @option{tar-v7} and @option{tar-ustar}
10136 options below.  This option should be used in the top-level
10137 @file{Makefile.am} or as an argument of @code{AM_INIT_AUTOMAKE} in
10138 @file{configure.ac}, it will be ignored otherwise.  It will also be
10139 ignored in sub-packages of nested packages (@pxref{Subpackages}).
10140
10141 @item @option{no-define}
10142 @cindex Option, @option{no-define}
10143 @opindex no-define
10144 This option is meaningful only when passed as an argument to
10145 @code{AM_INIT_AUTOMAKE}.  It will prevent the @code{PACKAGE} and
10146 @code{VERSION} variables from being @code{AC_DEFINE}d.
10147
10148 @item @option{no-dependencies}
10149 @cindex Option, @option{no-dependencies}
10150 @opindex no-dependencies
10151 This is similar to using @option{--ignore-deps} on the command line,
10152 but is useful for those situations where you don't have the necessary
10153 bits to make automatic dependency tracking work
10154 (@pxref{Dependencies}).  In this case the effect is to effectively
10155 disable automatic dependency tracking.
10156
10157 @item @option{no-dist}
10158 @cindex Option, @option{no-dist}
10159 @opindex no-dist
10160 Don't emit any code related to @code{dist} target.  This is useful
10161 when a package has its own method for making distributions.
10162
10163 @item @option{no-dist-gzip}
10164 @cindex Option, @option{no-dist-gzip}
10165 @opindex no-dist-gzip
10166 Do not hook @code{dist-gzip} to @code{dist}.
10167 @trindex no-dist-gzip
10168
10169 @item @option{no-exeext}
10170 @cindex Option, @option{no-exeext}
10171 @opindex no-exeext
10172 If your @file{Makefile.am} defines a rule for target @code{foo}, it
10173 will override a rule for a target named @samp{foo$(EXEEXT)}.  This is
10174 necessary when @code{EXEEXT} is found to be empty.  However, by
10175 default @command{automake} will generate an error for this use.  The
10176 @option{no-exeext} option will disable this error.  This is intended for
10177 use only where it is known in advance that the package will not be
10178 ported to Windows, or any other operating system using extensions on
10179 executables.
10180
10181 @item @option{no-installinfo}
10182 @cindex Option, @option{no-installinfo}
10183 @opindex no-installinfo
10184 The generated @file{Makefile.in} will not cause info pages to be built
10185 or installed by default.  However, @code{info} and @code{install-info}
10186 targets will still be available.  This option is disallowed at
10187 @option{gnu} strictness and above.
10188 @trindex info
10189 @trindex install-info
10190
10191 @item @option{no-installman}
10192 @cindex Option, @option{no-installman}
10193 @opindex no-installman
10194 The generated @file{Makefile.in} will not cause man pages to be
10195 installed by default.  However, an @code{install-man} target will still
10196 be available for optional installation.  This option is disallowed at
10197 @option{gnu} strictness and above.
10198 @trindex install-man
10199
10200 @item @option{nostdinc}
10201 @cindex Option, @option{nostdinc}
10202 @opindex nostdinc
10203 This option can be used to disable the standard @option{-I} options that
10204 are ordinarily automatically provided by Automake.
10205
10206 @item @option{no-texinfo.tex}
10207 @cindex Option, @option{no-texinfo.tex}
10208 @opindex no-texinfo.tex
10209 Don't require @file{texinfo.tex}, even if there are texinfo files in
10210 this directory.
10211
10212 @item @option{parallel-tests}
10213 @cindex Option, @option{parallel-tests}
10214 @opindex parallel-tests
10215 Enable test suite harness for @code{TESTS} that can run tests in parallel
10216 (@pxref{Parallel Test Harness}, for more information).
10217
10218 @item @option{serial-tests}
10219 @cindex Option, @option{serial-tests}
10220 @opindex serial-tests
10221 Enable the older serial test suite harness for @code{TESTS} (@pxref{Serial
10222 Test Harness}, for more information).  This is still the default for the
10223 moment.
10224
10225 @item @option{readme-alpha}
10226 @cindex Option, @option{readme-alpha}
10227 @opindex readme-alpha
10228 If this release is an alpha release, and the file @file{README-alpha}
10229 exists, then it will be added to the distribution.  If this option is
10230 given, version numbers are expected to follow one of two forms.  The
10231 first form is @samp{@var{major}.@var{minor}.@var{alpha}}, where each
10232 element is a number; the final period and number should be left off for
10233 non-alpha releases.  The second form is
10234 @samp{@var{major}.@var{minor}@var{alpha}}, where @var{alpha} is a
10235 letter; it should be omitted for non-alpha releases.
10236
10237 @item @option{silent-rules}
10238 @cindex Option, @option{silent-rules}
10239 @opindex silent-rules
10240 Enable less verbose build rules.  This can be used to let build rules
10241 output status lines of the form:
10242 @example
10243 GEN @var{output-file}
10244  CC @var{object-file}
10245 @end example
10246 @noindent
10247 instead of printing the command that will be executed to update
10248 @var{output-file} or to compile @var{object-file}.  It can also
10249 silence @command{libtool} output.
10250
10251 For more information about how to use, enable, or disable silent
10252 rules, @pxref{Automake silent-rules Option}.
10253
10254 @item @option{std-options}
10255 @cindex Options, @option{std-options}
10256 @cindex @samp{make installcheck}, testing @option{--help} and @option{--version}
10257 @cindex @option{--help} check
10258 @cindex @option{--version} check
10259 @opindex std-options
10260
10261 Make the @code{installcheck} rule check that installed scripts and
10262 programs support the @option{--help} and @option{--version} options.
10263 This also provides a basic check that the program's
10264 run-time dependencies are satisfied after installation.
10265
10266 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
10267 In a few situations, programs (or scripts) have to be exempted from this
10268 test.  For instance, @command{false} (from GNU coreutils) is never
10269 successful, even for @option{--help} or @option{--version}.  You can list
10270 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
10271 Programs (not scripts) listed in this variable should be suffixed by
10272 @samp{$(EXEEXT)} for the sake of Windows or OS/2.  For instance, suppose we
10273 build @file{false} as a program but @file{true.sh} as a script, and that
10274 neither of them support @option{--help} or @option{--version}:
10275
10276 @example
10277 AUTOMAKE_OPTIONS = std-options
10278 bin_PROGRAMS = false ...
10279 bin_SCRIPTS = true.sh ...
10280 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
10281 @end example
10282
10283 @item @option{subdir-objects}
10284 @cindex Options, @option{subdir-objects}
10285 @opindex subdir-objects
10286 If this option is specified, then objects are placed into the
10287 subdirectory of the build directory corresponding to the subdirectory of
10288 the source file.  For instance, if the source file is
10289 @file{subdir/file.cxx}, then the output file would be
10290 @file{subdir/file.o}.
10291
10292 In order to use this option with C sources, you should add
10293 @code{AM_PROG_CC_C_O} to @file{configure.ac}.
10294
10295 @anchor{tar-formats}
10296 @item @option{tar-v7}
10297 @itemx @option{tar-ustar}
10298 @itemx @option{tar-pax}
10299 @cindex Option, @option{tar-v7}
10300 @cindex Option, @option{tar-ustar}
10301 @cindex Option, @option{tar-pax}
10302 @cindex @command{tar} formats
10303 @cindex v7 @command{tar} format
10304 @cindex ustar format
10305 @cindex pax format
10306 @opindex tar-v7
10307 @opindex tar-ustar
10308 @opindex tar-pax
10309
10310 These three mutually exclusive options select the tar format to use
10311 when generating tarballs with @samp{make dist}.  (The tar file created
10312 is then compressed according to the set of @option{no-dist-gzip},
10313 @option{dist-bzip2}, @option{dist-lzip}, @option{dist-xz} and
10314 @option{dist-tarZ} options in use.)
10315
10316 These options must be passed as arguments to @code{AM_INIT_AUTOMAKE}
10317 (@pxref{Macros}) because they can require additional configure checks.
10318 Automake will complain if it sees such options in an
10319 @code{AUTOMAKE_OPTIONS} variable.
10320
10321 @option{tar-v7} selects the old V7 tar format.  This is the historical
10322 default.  This antiquated format is understood by all tar
10323 implementations and supports file names with up to 99 characters.  When
10324 given longer file names some tar implementations will diagnose the
10325 problem while other will generate broken tarballs or use non-portable
10326 extensions.  Furthermore, the V7 format cannot store empty
10327 directories.  When using this format, consider using the
10328 @option{filename-length-max=99} option to catch file names too long.
10329
10330 @option{tar-ustar} selects the ustar format defined by POSIX
10331 1003.1-1988.  This format is believed to be old enough to be portable.
10332 It fully supports empty directories.  It can store file names with up
10333 to 256 characters, provided that the file name can be split at
10334 directory separator in two parts, first of them being at most 155
10335 bytes long.  So, in most cases the maximum file name length will be
10336 shorter than 256 characters.  However you may run against broken tar
10337 implementations that incorrectly handle file names longer than 99
10338 characters (please report them to @email{@value{PACKAGE_BUGREPORT}} so we
10339 can document this accurately).
10340
10341 @option{tar-pax} selects the new pax interchange format defined by POSIX
10342 1003.1-2001.  It does not limit the length of file names.  However,
10343 this format is very young and should probably be restricted to
10344 packages that target only very modern platforms.  There are moves to
10345 change the pax format in an upward-compatible way, so this option may
10346 refer to a more recent version in the future.
10347
10348 @xref{Formats, , Controlling the Archive Format, tar, GNU Tar}, for
10349 further discussion about tar formats.
10350
10351 @command{configure} knows several ways to construct these formats.  It
10352 will not abort if it cannot find a tool up to the task (so that the
10353 package can still be built), but @samp{make dist} will fail.
10354
10355 @item @var{version}
10356 @cindex Option, @var{version}
10357 A version number (e.g., @samp{0.30}) can be specified.  If Automake is not
10358 newer than the version specified, creation of the @file{Makefile.in}
10359 will be suppressed.
10360
10361 @item @option{-W@var{category}} or @option{--warnings=@var{category}}
10362 @cindex Option, warnings
10363 @cindex Option, @option{-W@var{category}}
10364 @cindex Option, @option{--warnings=@var{category}}
10365 These options behave exactly like their command-line counterpart
10366 (@pxref{automake Invocation}).  This allows you to enable or disable some
10367 warning categories on a per-file basis.  You can also setup some warnings
10368 for your entire project; for instance, try @samp{AM_INIT_AUTOMAKE([-Wall])}
10369 in your @file{configure.ac}.
10370
10371 @end table
10372
10373 Unrecognized options are diagnosed by @command{automake}.
10374
10375 If you want an option to apply to all the files in the tree, you can use
10376 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.ac}.
10377 @xref{Macros}.
10378
10379
10380 @node Miscellaneous
10381 @chapter Miscellaneous Rules
10382
10383 There are a few rules and variables that didn't fit anywhere else.
10384
10385 @menu
10386 * Tags::                        Interfacing to cscope, etags and mkid
10387 * Suffixes::                    Handling new file extensions
10388 @end menu
10389
10390
10391 @node Tags
10392 @section Interfacing to @command{etags}
10393
10394 @cindex @file{TAGS} support
10395
10396 Automake will generate rules to generate @file{TAGS} files for use with
10397 GNU Emacs under some circumstances.
10398
10399 @trindex tags
10400 If any C, C++ or Fortran 77 source code or headers are present, then
10401 @code{tags} and @code{TAGS} rules will be generated for the directory.
10402 All files listed using the @code{_SOURCES}, @code{_HEADERS}, and
10403 @code{_LISP} primaries will be used to generate tags.  Note that
10404 generated source files that are not distributed must be declared in
10405 variables like @code{nodist_noinst_HEADERS} or
10406 @code{nodist_@var{prog}_SOURCES} or they will be ignored.
10407
10408 A @code{tags} rule will be output at the topmost directory of a
10409 multi-directory package.  When run from this topmost directory,
10410 @samp{make tags} will generate a @file{TAGS} file that includes by
10411 reference all @file{TAGS} files from subdirectories.
10412
10413 The @code{tags} rule will also be generated if the variable
10414 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
10415 directories that contain taggable source that @command{etags} does
10416 not understand.  The user can use the @code{ETAGSFLAGS} to pass
10417 additional flags to @command{etags}; @code{AM_ETAGSFLAGS} is also
10418 available for use in @file{Makefile.am}.
10419 @vindex ETAGS_ARGS
10420 @vindex ETAGSFLAGS
10421 @vindex AM_ETAGSFLAGS
10422
10423 Here is how Automake generates tags for its source, and for nodes in its
10424 Texinfo file:
10425
10426 @example
10427 ETAGS_ARGS = automake.in --lang=none \
10428  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
10429 @end example
10430
10431 If you add file names to @code{ETAGS_ARGS}, you will probably also
10432 want to define @code{TAGS_DEPENDENCIES}.  The contents of this variable
10433 are added directly to the dependencies for the @code{tags} rule.
10434 @vindex TAGS_DEPENDENCIES
10435
10436 Automake also generates a @code{ctags} rule that can be used to
10437 build @command{vi}-style @file{tags} files.  The variable @code{CTAGS}
10438 is the name of the program to invoke (by default @command{ctags});
10439 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
10440 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
10441
10442 @trindex id
10443 Automake will also generate an @code{ID} rule that will run
10444 @command{mkid} on the source.  This is only supported on a
10445 directory-by-directory basis.
10446
10447 Similarly, the @code{cscope} rule will create a list of all the source
10448 files in the tree and run @command{cscope} to build an inverted index
10449 database.  The variable @code{CSCOPE} is the name of the program to invoke
10450 (by default @command{cscope}); @code{CSCOPEFLAGS} and
10451 @code{CSCOPE_ARGS} can be used by the user to pass additional flags and
10452 file names respectively, while @code{AM_CSCOPEFLAGS} can be used by the
10453 @file{Makefile.am}.  Note that, currently, the Automake-provided
10454 @code{cscope} support, when used in a VPATH build, might not work well
10455 with non-GNU make implementations (especially with make implementations
10456 performing @ref{Automatic Rule Rewriting, , VPATH rewrites, autoconf,
10457 The Autoconf Manual}).
10458
10459 Finally, Automake also emits rules to support the
10460 @uref{http://www.gnu.org/software/global/, GNU Global Tags program}.
10461 The @code{GTAGS} rule runs Global Tags and puts the
10462 result in the top build directory.  The variable @code{GTAGS_ARGS}
10463 holds arguments that are passed to @command{gtags}.
10464 @vindex GTAGS_ARGS
10465
10466
10467 @node Suffixes
10468 @section Handling new file extensions
10469
10470 @cindex Adding new @code{SUFFIXES}
10471 @cindex @code{SUFFIXES}, adding
10472 @vindex SUFFIXES
10473
10474 It is sometimes useful to introduce a new implicit rule to handle a file
10475 type that Automake does not know about.
10476
10477 For instance, suppose you had a compiler that could compile @file{.foo}
10478 files to @file{.o} files.  You would simply define a suffix rule for
10479 your language:
10480
10481 @example
10482 .foo.o:
10483         foocc -c -o $@@ $<
10484 @end example
10485
10486 Then you could directly use a @file{.foo} file in a @code{_SOURCES}
10487 variable and expect the correct results:
10488
10489 @example
10490 bin_PROGRAMS = doit
10491 doit_SOURCES = doit.foo
10492 @end example
10493
10494 This was the simpler and more common case.  In other cases, you will
10495 have to help Automake to figure out which extensions you are defining your
10496 suffix rule for.  This usually happens when your extension does not
10497 start with a dot.  Then, all you have to do is to put a list of new
10498 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
10499 implicit rule.
10500
10501 For instance, the following definition prevents Automake from misinterpreting
10502 the @samp{.idlC.cpp:} rule as an attempt to transform @file{.idlC} files into
10503 @file{.cpp} files.
10504
10505 @c Keep in sync with suffix7.sh
10506 @example
10507 SUFFIXES = .idl C.cpp
10508 .idlC.cpp:
10509         # whatever
10510 @end example
10511
10512 As you may have noted, the @code{SUFFIXES} variable behaves like the
10513 @code{.SUFFIXES} special target of @command{make}.  You should not touch
10514 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
10515 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
10516 @code{SUFFIXES} go at the start of the generated suffixes list, followed
10517 by Automake generated suffixes not already in the list.
10518
10519 @node Include
10520 @chapter Include
10521
10522 @cmindex include
10523 @cindex Including @file{Makefile} fragment
10524 @cindex @file{Makefile} fragment, including
10525
10526 Automake supports an @code{include} directive that  can be used to
10527 include other @file{Makefile} fragments when @command{automake} is run.
10528 Note that these fragments are read and interpreted by @command{automake},
10529 not by @command{make}.  As with conditionals, @command{make} has no idea that
10530 @code{include} is in use.
10531
10532 There are two forms of @code{include}:
10533
10534 @table @code
10535 @item include $(srcdir)/file
10536 Include a fragment that is found relative to the current source
10537 directory.
10538
10539 @item include $(top_srcdir)/file
10540 Include a fragment that is found relative to the top source directory.
10541 @end table
10542
10543 Note that if a fragment is included inside a conditional, then the
10544 condition applies to the entire contents of that fragment.
10545
10546 Makefile fragments included this way are always distributed because
10547 they are needed to rebuild @file{Makefile.in}.
10548
10549 @node Conditionals
10550 @chapter Conditionals
10551
10552 @cindex Conditionals
10553
10554 Automake supports a simple type of conditionals.
10555
10556 These conditionals are not the same as conditionals in
10557 GNU Make.  Automake conditionals are checked at configure time by the
10558 @file{configure} script, and affect the translation from
10559 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
10560 to @file{configure} and on results that @file{configure} has discovered
10561 about the host system.  GNU Make conditionals are checked at @command{make}
10562 time, and are based on variables passed to the make program or defined
10563 in the @file{Makefile}.
10564
10565 Automake conditionals will work with any make program.
10566
10567 @menu
10568 * Usage of Conditionals::       Declaring conditional content
10569 * Limits of Conditionals::      Enclosing complete statements
10570 @end menu
10571
10572 @node Usage of Conditionals
10573 @section Usage of Conditionals
10574
10575 @acindex AM_CONDITIONAL
10576 Before using a conditional, you must define it by using
10577 @code{AM_CONDITIONAL} in the @file{configure.ac} file (@pxref{Macros}).
10578
10579 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
10580 The conditional name, @var{conditional}, should be a simple string
10581 starting with a letter and containing only letters, digits, and
10582 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
10583 that are reserved by Automake.
10584
10585 The shell @var{condition} (suitable for use in a shell @code{if}
10586 statement) is evaluated when @command{configure} is run.  Note that you
10587 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
10588 time @command{configure} is run.  If @code{AM_CONDITIONAL} is run
10589 conditionally (e.g., in a shell @code{if} statement), then the result
10590 will confuse @command{automake}.
10591 @end defmac
10592
10593 @cindex @option{--enable-debug}, example
10594 @cindex Example conditional @option{--enable-debug}
10595 @cindex Conditional example, @option{--enable-debug}
10596
10597 Conditionals typically depend upon options that the user provides to
10598 the @command{configure} script.  Here is an example of how to write a
10599 conditional that is true if the user uses the @option{--enable-debug}
10600 option.
10601
10602 @example
10603 AC_ARG_ENABLE([debug],
10604 [  --enable-debug    Turn on debugging],
10605 [case "$@{enableval@}" in
10606   yes) debug=true ;;
10607   no)  debug=false ;;
10608   *) AC_MSG_ERROR([bad value $@{enableval@} for --enable-debug]) ;;
10609 esac],[debug=false])
10610 AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
10611 @end example
10612
10613 Here is an example of how to use that conditional in @file{Makefile.am}:
10614
10615 @cmindex if
10616 @cmindex endif
10617 @cmindex else
10618
10619 @example
10620 if DEBUG
10621 DBG = debug
10622 else
10623 DBG =
10624 endif
10625 noinst_PROGRAMS = $(DBG)
10626 @end example
10627
10628 This trivial example could also be handled using @code{EXTRA_PROGRAMS}
10629 (@pxref{Conditional Programs}).
10630
10631 You may only test a single variable in an @code{if} statement, possibly
10632 negated using @samp{!}.  The @code{else} statement may be omitted.
10633 Conditionals may be nested to any depth.  You may specify an argument to
10634 @code{else} in which case it must be the negation of the condition used
10635 for the current @code{if}.  Similarly you may specify the condition
10636 that is closed on the @code{endif} line:
10637
10638 @example
10639 if DEBUG
10640 DBG = debug
10641 else !DEBUG
10642 DBG =
10643 endif !DEBUG
10644 @end example
10645
10646 @noindent
10647 Unbalanced conditions are errors.  The @code{if}, @code{else}, and
10648 @code{endif} statements should not be indented, i.e., start on column
10649 one.
10650
10651 The @code{else} branch of the above two examples could be omitted,
10652 since assigning the empty string to an otherwise undefined variable
10653 makes no difference.
10654
10655 @acindex AM_COND_IF
10656 In order to allow access to the condition registered by
10657 @code{AM_CONDITIONAL} inside @file{configure.ac}, and to allow
10658 conditional @code{AC_CONFIG_FILES}, @code{AM_COND_IF} may be used:
10659
10660 @defmac AM_COND_IF (@var{conditional}, @ovar{if-true}, @ovar{if-false})
10661 If @var{conditional} is fulfilled, execute @var{if-true}, otherwise
10662 execute @var{if-false}.  If either branch contains @code{AC_CONFIG_FILES},
10663 it will cause @command{automake} to output the rules for the respective
10664 files only for the given condition.
10665 @end defmac
10666
10667 @code{AM_COND_IF} macros may be nested when m4 quotation is used
10668 properly (@pxref{M4 Quotation, ,, autoconf, The Autoconf Manual}).
10669
10670 @cindex Example conditional @code{AC_CONFIG_FILES}
10671 @cindex @code{AC_CONFIG_FILES}, conditional
10672
10673 Here is an example of how to define a conditional config file:
10674
10675 @example
10676 AM_CONDITIONAL([SHELL_WRAPPER], [test "x$with_wrapper" = xtrue])
10677 AM_COND_IF([SHELL_WRAPPER],
10678            [AC_CONFIG_FILES([wrapper:wrapper.in])])
10679 @end example
10680
10681 @node Limits of Conditionals
10682 @section Limits of Conditionals
10683
10684 Conditionals should enclose complete statements like variables or
10685 rules definitions.  Automake cannot deal with conditionals used inside
10686 a variable definition, for instance, and is not even able to diagnose
10687 this situation.  The following example would not work:
10688
10689 @example
10690 # This syntax is not understood by Automake
10691 AM_CPPFLAGS = \
10692   -DFEATURE_A \
10693 if WANT_DEBUG
10694   -DDEBUG \
10695 endif
10696   -DFEATURE_B
10697 @end example
10698
10699 However the intended definition of @code{AM_CPPFLAGS} can be achieved
10700 with
10701
10702 @example
10703 if WANT_DEBUG
10704   DEBUGFLAGS = -DDEBUG
10705 endif
10706 AM_CPPFLAGS = -DFEATURE_A $(DEBUGFLAGS) -DFEATURE_B
10707 @end example
10708
10709 @noindent
10710 or
10711
10712 @example
10713 AM_CPPFLAGS = -DFEATURE_A
10714 if WANT_DEBUG
10715 AM_CPPFLAGS += -DDEBUG
10716 endif
10717 AM_CPPFLAGS += -DFEATURE_B
10718 @end example
10719
10720 More details and examples of conditionals are described alongside
10721 various Automake features in this manual (@pxref{Conditional
10722 Subdirectories}, @pxref{Conditional Sources}, @pxref{Conditional
10723 Programs}, @pxref{Conditional Libtool Libraries}, @pxref{Conditional
10724 Libtool Sources}).
10725
10726 @node Silencing Make
10727 @chapter Silencing @command{make}
10728
10729 @cindex Silent @command{make}
10730 @cindex Silencing @command{make}
10731 @cindex Silent rules
10732 @cindex Silent @command{make} rules
10733
10734 @menu
10735 * Make verbosity::               Make is verbose by default
10736 * Tricks For Silencing Make::    Standard and generic ways to silence make
10737 * Automake silent-rules Option:: How Automake can help in silencing make
10738 @end menu
10739
10740 @node Make verbosity
10741 @section Make is verbose by default
10742
10743 Normally, when executing the set of rules associated with a target,
10744 @command{make} prints each rule before it is executed.  This behaviour,
10745 while having been in place for a long time, and being even mandated by
10746 the POSIX standard, starkly violates the ``silence is golden'' UNIX
10747 principle@footnote{See also
10748 @uref{http://catb.org/~esr/writings/taoup/html/ch11s09.html}.}:
10749
10750 @quotation
10751 When a program has nothing interesting or surprising to say, it should
10752 say nothing.  Well-behaved Unix programs do their jobs unobtrusively,
10753 with a minimum of fuss and bother.  Silence is golden.
10754 @end quotation
10755
10756 In fact, while such verbosity of @command{make} can theoretically be
10757 useful to track bugs and understand reasons of failures right away, it
10758 can also hide warning and error messages from @command{make}-invoked
10759 tools, drowning them in a flood of uninteresting and seldom useful
10760 messages, and thus allowing them to go easily undetected.
10761
10762 This problem can be very annoying, especially for developers, who usually
10763 know quite well what's going on behind the scenes, and for whom the
10764 verbose output from @command{make} ends up being mostly noise that hampers
10765 the easy detection of potentially important warning messages.
10766
10767 @node Tricks For Silencing Make
10768 @section Standard and generic ways to silence make
10769
10770 Here we describe some common idioms/tricks to obtain a quieter make
10771 output, with their relative advantages and drawbacks.  In the next
10772 section (@ref{Automake silent-rules Option}) we'll see how Automake
10773 can help in this respect.
10774
10775 @itemize @bullet
10776
10777 @item @command{make -s}
10778
10779 This simply causes @command{make} not to print @emph{any} rule before
10780 executing it.
10781
10782 The @option{-s} flag is mandated by POSIX, universally supported, and
10783 its purpose and function are easy to understand.
10784
10785 But it also has its serious limitations too.  First of all, it embodies
10786 an ``all or nothing'' strategy, i.e., either everything is silenced, or
10787 nothing is; this lack of granularity can sometimes be a fatal flaw.
10788 Moreover, when the @option{-s} flag is used, the @command{make} output
10789 might turn out to be too much terse; in case of errors, the user won't
10790 be able to easily see what rule or command have caused them, or even,
10791 in case of tools with poor error reporting, what the errors were!
10792
10793 @item @command{make >/dev/null || make}
10794
10795 Apparently, this perfectly obeys the ``silence is golden'' rule: warnings
10796 from stderr are passed through, output reporting is done only in case of
10797 error, and in that case it should provide a verbose-enough report to allow
10798 an easy determination of the error location and causes.
10799
10800 However, calling @command{make} two times in a row might hide errors
10801 (especially intermittent ones), or subtly change the expected semantic
10802 of the @command{make} calls --- things these which can clearly make
10803 debugging and error assessment very difficult.
10804
10805 @item @command{make --no-print-directory}
10806
10807 This is GNU @command{make} specific.  When called with the
10808 @option{--no-print-directory} option, GNU @command{make} will disable
10809 printing of the working directory by invoked sub-@command{make}s (the
10810 well-known ``@i{Entering/Leaving directory ...}'' messages).  This helps
10811 to decrease the verbosity of the output, but experience has shown that
10812 it can also often render debugging considerably harder in projects using
10813 deeply-nested @command{make} recursion.
10814
10815 As an aside, notice that the @option{--no-print-directory} option is
10816 automatically activated if the @option{-s} flag is used.
10817
10818 @c TODO: Other tricks?
10819 @c TODO: Maybe speak about the @code{.SILENT} target?
10820 @c TODO:  - Pros: More granularity on what to silence.
10821 @c TODO:  - Cons: No easy way to temporarily override.
10822
10823 @end itemize
10824
10825 @node Automake silent-rules Option
10826 @section How Automake can help in silencing make
10827
10828 The tricks and idioms for silencing @command{make} described in the
10829 previous section can be useful from time to time, but we've seen that
10830 they all have their serious drawbacks and limitations.  That's why
10831 automake provides support for a more advanced and flexible way of
10832 obtaining quieter output from @command{make}: the @option{silent-rules}
10833 mode.
10834
10835 @c TODO: Maybe describe in brief the precedent set by the build system
10836 @c of the Linux Kernel, from which Automake took inspiration ... Links?
10837
10838 To give the gist of what @option{silent-rules} can do, here is a simple
10839 comparison between a typical @command{make} output (where silent rules
10840 are disabled) and one with silent rules enabled:
10841
10842 @example
10843 % @kbd{cat Makefile.am}
10844 bin_PROGRAMS = foo
10845 foo_SOURCES = main.c func.c
10846 % @kbd{cat main.c}
10847 int main (void) @{ return func (); @}  /* func used undeclared */
10848 % @kbd{cat func.c}
10849 int func (void) @{ int i; return i; @} /* i used uninitialized */
10850
10851 @i{The make output is by default very verbose.  This causes warnings
10852 from the compiler to be somewhat hidden, and not immediate to spot.}
10853 % @kbd{make CFLAGS=-Wall}
10854 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
10855 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
10856 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT main.o
10857 -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
10858 main.c: In function â€˜main’:
10859 main.c:3:3: warning: implicit declaration of function â€˜func’
10860 mv -f .deps/main.Tpo .deps/main.Po
10861 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
10862 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
10863 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT func.o
10864 -MD -MP -MF .deps/func.Tpo -c -o func.o func.c
10865 func.c: In function â€˜func’:
10866 func.c:4:3: warning: â€˜i’ used uninitialized in this function
10867 mv -f .deps/func.Tpo .deps/func.Po
10868 gcc -Wall -o foo main.o func.o
10869
10870 @i{Clean up, so that we we can rebuild everything from scratch.}
10871 % @kbd{make clean}
10872 test -z "foo" || rm -f foo
10873 rm -f *.o
10874
10875 @i{Silent rules enabled: the output is minimal but informative.  In
10876 particular, the warnings from the compiler stick out very clearly.}
10877 % @kbd{make V=0 CFLAGS=-Wall}
10878   CC     main.o
10879 main.c: In function â€˜main’:
10880 main.c:3:3: warning: implicit declaration of function â€˜func’
10881   CC     func.o
10882 func.c: In function â€˜func’:
10883 func.c:4:3: warning: â€˜i’ used uninitialized in this function
10884   CCLD   foo
10885 @end example
10886
10887 @cindex silent-rules and libtool
10888 Also, in projects using @command{libtool}, the use of silent rules can
10889 automatically enable the @command{libtool}'s @option{--silent} option:
10890
10891 @example
10892 % @kbd{cat Makefile.am}
10893 lib_LTLIBRARIES = libx.la
10894
10895 % @kbd{make # Both make and libtool are verbose by default.}
10896 ...
10897 libtool: compile: gcc -DPACKAGE_NAME=\"foo\" ... -DLT_OBJDIR=\".libs/\"
10898   -I. -g -O2 -MT libx.lo -MD -MP -MF .deps/libx.Tpo -c libx.c -fPIC
10899   -DPIC -o .libs/libx.o
10900 mv -f .deps/libx.Tpo .deps/libx.Plo
10901 /bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -o libx.la -rpath
10902   /usr/local/lib libx.lo
10903 libtool: link: gcc -shared .libs/libx.o -Wl,-soname -Wl,libx.so.0
10904   -o .libs/libx.so.0.0.0
10905 libtool: link: cd .libs && rm -f libx.so && ln -s libx.so.0.0.0 libx.so
10906 ...
10907
10908 % @kbd{make V=0}
10909   CC     libx.lo
10910   CCLD   libx.la
10911 @end example
10912
10913 Let's now see how the @option{silent-rules} mode interfaces with the
10914 package developer and the package user.
10915
10916 To enable the use of @option{silent-rules} in his package, a developer
10917 needs to do either of the following:
10918
10919 @itemize @bullet
10920 @item
10921 Add the @option{silent-rules} option as argument to @code{AM_INIT_AUTOMAKE}.
10922 @item
10923 Call the @code{AM_SILENT_RULES} macro from within the @file{configure.ac}
10924 file.
10925 @end itemize
10926
10927 It is not possible to instead specify @option{silent-rules} in a
10928 @file{Makefile.am} file.
10929
10930 If the developer has done either of the above, then the user of the
10931 package may influence the verbosity at @command{configure} run time as
10932 well as at @command{make} run time:
10933
10934 @itemize @bullet
10935 @item
10936 @opindex --enable-silent-rules
10937 @opindex --disable-silent-rules
10938 Passing @option{--enable-silent-rules} to @command{configure} will cause
10939 build rules to be less verbose; the option @option{--disable-silent-rules}
10940 will cause normal verbose output.
10941 @item
10942 @vindex @code{V}
10943 At @command{make} run time, the default chosen at @command{configure}
10944 time may be overridden: @code{make V=1} will produce verbose output,
10945 @code{make V=0} less verbose output.
10946 @end itemize
10947
10948 @cindex default verbosity for silent-rules
10949 Note that silent rules are @emph{disabled} by default; the user must
10950 enable them explicitly at either @command{configure} run time or at
10951 @command{make} run time.  We think that this is a good policy, since
10952 it provides the casual user with enough information to prepare a good
10953 bug report in case anything breaks.
10954
10955 Still, notwithstanding the rationales above, a developer who wants to
10956 make silent rules enabled by default in his own package can do so by
10957 adding a @samp{yes} argument to the @code{AM_SILENT_RULES} call in
10958 @file{configure.ac}.  We advise against this approach, though.
10959
10960 @c Keep in sync with silent-configsite.sh
10961 Users who prefer to have silent rules enabled by default can edit their
10962 @file{config.site} file to make the variable @code{enable_silent_rules}
10963 default to @samp{yes}.  This should still allow disabling silent rules
10964 at @command{configure} time and at @command{make} time.
10965
10966 @c FIXME: there's really a need to specify this explicitly?
10967 For portability to different @command{make} implementations, package authors
10968 are advised to not set the variable @code{V} inside the @file{Makefile.am}
10969 file, to allow the user to override the value for subdirectories as well.
10970
10971 The current implementation of this feature normally uses nested
10972 variable expansion @samp{$(@var{var1}$(V))}, a @file{Makefile} feature
10973 that is not required by POSIX 2008 but is widely supported in
10974 practice.  The @option{silent-rules} option thus turns off warnings
10975 about recursive variable expansion, which are in turn enabled by
10976 @option{-Wportability} (@pxref{automake Invocation}).  On the rare
10977 @command{make} implementations that do not support nested variable
10978 expansion, whether rules are silent is always determined at configure
10979 time, and cannot be overridden at make time.  Future versions of POSIX
10980 are likely to require nested variable expansion, so this minor
10981 limitation should go away with time.
10982
10983 @vindex @code{AM_V_GEN}
10984 @vindex @code{AM_V_at}
10985 @vindex @code{AM_DEFAULT_VERBOSITY}
10986 @vindex @code{AM_V}
10987 @vindex @code{AM_DEFAULT_V}
10988 To extend the silent mode to your own rules, you have few choices:
10989
10990 @itemize @bullet
10991
10992 @item
10993 You can use the predefined variable @code{AM_V_GEN} as a prefix to
10994 commands that should output a status line in silent mode, and
10995 @code{AM_V_at} as a prefix to commands that should not output anything
10996 in silent mode.  When output is to be verbose, both of these variables
10997 will expand to the empty string.
10998
10999 @item
11000 You can silence a recipe unconditionally with @code{@@}, and then use
11001 the predefined variable @code{AM_V_P} to know whether make is being run
11002 in silent or verbose mode, adjust the verbose information your recipe
11003 displays accordingly:
11004
11005 @example
11006 generate-headers:
11007         @set -e; \
11008         ... [commands defining a shell variable '$headers'] ...; \
11009         if $(AM_V_P); then set -x; else echo " GEN   [headers]"; fi; \
11010         rm -f $$headers && generate-header --flags $$headers
11011 @end example
11012
11013 @item
11014 You can add your own variables, so strings of your own choice are shown.
11015 The following snippet shows how you would define your own equivalent of
11016 @code{AM_V_GEN}:
11017
11018 @example
11019 pkg_verbose = $(pkg_verbose_@@AM_V@@)
11020 pkg_verbose_ = $(pkg_verbose_@@AM_DEFAULT_V@@)
11021 pkg_verbose_0 = @@echo PKG-GEN $@@;
11022
11023 foo: foo.in
11024         $(pkg_verbose)cp $(srcdir)/foo.in $@@
11025 @end example
11026
11027 @end itemize
11028
11029 As a final note, observe that, even when silent rules are enabled,
11030 the @option{--no-print-directory} option is still required with GNU
11031 @command{make} if the ``@i{Entering/Leaving directory ...}'' messages
11032 are to be disabled.
11033
11034 @node Gnits
11035 @chapter The effect of @option{--gnu} and @option{--gnits}
11036
11037 @cindex @option{--gnu}, required files
11038 @cindex @option{--gnu}, complete description
11039
11040 The @option{--gnu} option (or @option{gnu} in the
11041 @code{AUTOMAKE_OPTIONS} variable) causes @command{automake} to check
11042 the following:
11043
11044 @itemize @bullet
11045 @item
11046 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
11047 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
11048 or @file{COPYING}, are required at the topmost directory of the package.
11049
11050 If the @option{--add-missing} option is given, @command{automake} will
11051 add a generic version of the @file{INSTALL} file as well as the
11052 @file{COPYING} file containing the text of the current version of the
11053 GNU General Public License existing at the time of this Automake release
11054 (version 3 as this is written, @uref{http://www.gnu.org/@/copyleft/@/gpl.html}).
11055 However, an existing @file{COPYING} file will never be overwritten by
11056 @command{automake}.
11057
11058 @item
11059 The options @option{no-installman} and @option{no-installinfo} are
11060 prohibited.
11061 @end itemize
11062
11063 Note that this option will be extended in the future to do even more
11064 checking; it is advisable to be familiar with the precise requirements
11065 of the GNU standards.  Also, @option{--gnu} can require certain
11066 non-standard GNU programs to exist for use by various maintainer-only
11067 rules; for instance, in the future @command{pathchk} might be required for
11068 @samp{make dist}.
11069
11070 @cindex @option{--gnits}, complete description
11071
11072 The @option{--gnits} option does everything that @option{--gnu} does, and
11073 checks the following as well:
11074
11075 @itemize @bullet
11076 @item
11077 @samp{make installcheck} will check to make sure that the @option{--help}
11078 and @option{--version} really print a usage message and a version string,
11079 respectively.  This is the @option{std-options} option (@pxref{Options}).
11080
11081 @item
11082 @samp{make dist} will check to make sure the @file{NEWS} file has been
11083 updated to the current version.
11084
11085 @item
11086 @code{VERSION} is checked to make sure its format complies with Gnits
11087 standards.
11088 @c FIXME xref when standards are finished
11089
11090 @item
11091 @cindex @file{README-alpha}
11092 If @code{VERSION} indicates that this is an alpha release, and the file
11093 @file{README-alpha} appears in the topmost directory of a package, then
11094 it is included in the distribution.  This is done in @option{--gnits}
11095 mode, and no other, because this mode is the only one where version
11096 number formats are constrained, and hence the only mode where Automake
11097 can automatically determine whether @file{README-alpha} should be
11098 included.
11099
11100 @item
11101 The file @file{THANKS} is required.
11102 @end itemize
11103
11104
11105 @node Cygnus
11106 @chapter The effect of @option{--cygnus}
11107
11108 @cindex @option{cygnus} strictness
11109
11110 @emph{The features described in this section are deprecated; you must
11111 not use any of them in new code, and should remove their use from older
11112 but still maintained code: they will be withdrawn the next major Automake
11113 release (1.13).}
11114
11115 Some packages, notably GNU GCC and GNU gdb, used to have a build
11116 environment originally written at Cygnus Support (subsequently renamed
11117 Cygnus Solutions, and then later purchased by Red Hat).  Packages with
11118 this ancestry are sometimes referred to as ``Cygnus'' trees.
11119
11120 A Cygnus tree has slightly different rules for how a
11121 @file{Makefile.in} is to be constructed.  Passing @option{--cygnus} to
11122 @command{automake} will cause any generated @file{Makefile.in} to
11123 comply with Cygnus rules.
11124
11125 Here are the precise effects of @option{--cygnus}:
11126
11127 @itemize @bullet
11128
11129 @item
11130 The @option{foreign} strictness is implied.
11131
11132 @item
11133 The options @option{no-installinfo}, @option{no-dependencies} and
11134 @option{no-dist} are implied (@pxref{Options}).
11135
11136 @item
11137 The macro @code{AM_MAINTAINER_MODE} is required.
11138
11139 @item
11140 Info files are always created in the build directory, and not in the
11141 source directory.  Packages that don't use the @option{cygnus} option
11142 can emulate this effect by using the @option{no-installinfo} option
11143 and listing the generated info files in the @code{CLEANFILES} variable.
11144
11145 @item
11146 @file{texinfo.tex} is not required if a Texinfo source file is
11147 specified.  The assumption is that the file will be supplied, but in a
11148 place that Automake cannot find -- it is an artifact of how Cygnus
11149 packages are typically bundled.  This effect can be emulated in
11150 packages not using the @option{cygnus} option with a proper definition
11151 of the @code{TEXINFO_TEX} variable (@pxref{Texinfo}).
11152
11153 @item
11154 Certain tools will be searched for in the build tree as well as in the
11155 user's @env{PATH}.  These tools are @command{runtest}, @command{expect},
11156 @command{makeinfo} and @command{texi2dvi}.
11157
11158 @item
11159 The @code{check} target doesn't depend on @code{all}.
11160 @end itemize
11161
11162
11163 @node Not Enough
11164 @chapter When Automake Isn't Enough
11165
11166 In some situations, where Automake is not up to one task, one has to
11167 resort to handwritten rules or even handwritten @file{Makefile}s.
11168
11169 @menu
11170 * Extending::                   Adding new rules or overriding existing ones.
11171 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
11172 @end menu
11173
11174 @node Extending
11175 @section Extending Automake Rules
11176
11177 With some minor exceptions (for example @code{_PROGRAMS} variables,
11178 @code{TESTS}, or @code{XFAIL_TESTS}) being rewritten to append
11179 @samp{$(EXEEXT)}), the contents of a @file{Makefile.am} is copied to
11180 @file{Makefile.in} verbatim.
11181
11182 @cindex copying semantics
11183
11184 These copying semantics mean that many problems can be worked around
11185 by simply adding some @command{make} variables and rules to
11186 @file{Makefile.am}.  Automake will ignore these additions.
11187
11188 @cindex conflicting definitions
11189 @cindex rules, conflicting
11190 @cindex variables, conflicting
11191 @cindex definitions, conflicts
11192
11193 Since a @file{Makefile.in} is built from data gathered from three
11194 different places (@file{Makefile.am}, @file{configure.ac}, and
11195 @command{automake} itself), it is possible to have conflicting
11196 definitions of rules or variables.  When building @file{Makefile.in}
11197 the following priorities are respected by @command{automake} to ensure
11198 the user always has the last word:
11199
11200 @itemize
11201 @item
11202 User defined variables in @file{Makefile.am} have priority over
11203 variables @code{AC_SUBST}ed from @file{configure.ac}, and
11204 @code{AC_SUBST}ed variables have priority over
11205 @command{automake}-defined variables.
11206 @item
11207 As far as rules are concerned, a user-defined rule overrides any
11208 @command{automake}-defined rule for the same target.
11209 @end itemize
11210
11211 @cindex overriding rules
11212 @cindex overriding semantics
11213 @cindex rules, overriding
11214
11215 These overriding semantics make it possible to fine tune some default
11216 settings of Automake, or replace some of its rules.  Overriding
11217 Automake rules is often inadvisable, particularly in the topmost
11218 directory of a package with subdirectories.  The @option{-Woverride}
11219 option (@pxref{automake Invocation}) comes in handy to catch overridden
11220 definitions.
11221
11222 Note that Automake does not make any distinction between rules with
11223 commands and rules that only specify dependencies.  So it is not
11224 possible to append new dependencies to an @command{automake}-defined
11225 target without redefining the entire rule.
11226
11227 @cindex @option{-local} targets
11228 @cindex local targets
11229
11230 However, various useful targets have a @samp{-local} version you can
11231 specify in your @file{Makefile.am}.  Automake will supplement the
11232 standard target with these user-supplied targets.
11233
11234 @trindex  all
11235 @trindex  all-local
11236 @trindex  info
11237 @trindex  info-local
11238 @trindex  dvi
11239 @trindex  dvi-local
11240 @trindex  ps
11241 @trindex  ps-local
11242 @trindex  pdf
11243 @trindex  pdf-local
11244 @trindex  html
11245 @trindex  html-local
11246 @trindex  check
11247 @trindex  check-local
11248 @trindex  install
11249 @trindex  install-data
11250 @trindex  install-data-local
11251 @trindex  install-dvi
11252 @trindex  install-dvi-local
11253 @trindex  install-exec
11254 @trindex  install-exec-local
11255 @trindex  install-html
11256 @trindex  install-html-local
11257 @trindex  install-info
11258 @trindex  install-info-local
11259 @trindex  install-pdf
11260 @trindex  install-pdf-local
11261 @trindex  install-ps
11262 @trindex  install-ps-local
11263 @trindex  uninstall
11264 @trindex  uninstall-local
11265 @trindex  mostlyclean
11266 @trindex  mostlyclean-local
11267 @trindex  clean
11268 @trindex  clean-local
11269 @trindex  distclean
11270 @trindex  distclean-local
11271 @trindex  installdirs
11272 @trindex  installdirs-local
11273 @trindex  installcheck
11274 @trindex  installcheck-local
11275
11276 The targets that support a local version are @code{all}, @code{info},
11277 @code{dvi}, @code{ps}, @code{pdf}, @code{html}, @code{check},
11278 @code{install-data}, @code{install-dvi}, @code{install-exec},
11279 @code{install-html}, @code{install-info}, @code{install-pdf},
11280 @code{install-ps}, @code{uninstall}, @code{installdirs},
11281 @code{installcheck} and the various @code{clean} targets
11282 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
11283 @code{maintainer-clean}).
11284
11285 Note that there are no @code{uninstall-exec-local} or
11286 @code{uninstall-data-local} targets; just use @code{uninstall-local}.
11287 It doesn't make sense to uninstall just data or just executables.
11288
11289 For instance, here is one way to erase a subdirectory during
11290 @samp{make clean} (@pxref{Clean}).
11291
11292 @example
11293 clean-local:
11294         -rm -rf testSubDir
11295 @end example
11296
11297 You may be tempted to use @code{install-data-local} to install a file
11298 to some hard-coded location, but you should avoid this
11299 (@pxref{Hard-Coded Install Paths}).
11300
11301 With the @code{-local} targets, there is no particular guarantee of
11302 execution order; typically, they are run early, but with parallel
11303 make, there is no way to be sure of that.
11304
11305 @cindex @option{-hook} targets
11306 @cindex hook targets
11307 @trindex install-data-hook
11308 @trindex install-exec-hook
11309 @trindex uninstall-hook
11310 @trindex dist-hook
11311
11312 In contrast, some rules also have a way to run another rule, called a
11313 @dfn{hook}; hooks are always executed after the main rule's work is done.
11314 The hook is named after the principal target, with @samp{-hook} appended.
11315 The targets allowing hooks are @code{install-data},
11316 @code{install-exec}, @code{uninstall}, @code{dist}, and
11317 @code{distcheck}.
11318
11319 For instance, here is how to create a hard link to an installed program:
11320
11321 @example
11322 install-exec-hook:
11323         ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
11324            $(DESTDIR)$(bindir)/proglink$(EXEEXT)
11325 @end example
11326
11327 Although cheaper and more portable than symbolic links, hard links
11328 will not work everywhere (for instance, OS/2 does not have
11329 @command{ln}).  Ideally you should fall back to @samp{cp -p} when
11330 @command{ln} does not work.  An easy way, if symbolic links are
11331 acceptable to you, is to add @code{AC_PROG_LN_S} to
11332 @file{configure.ac} (@pxref{Particular Programs, , Particular Program
11333 Checks, autoconf, The Autoconf Manual}) and use @samp{$(LN_S)} in
11334 @file{Makefile.am}.
11335
11336 @cindex versioned binaries, installing
11337 @cindex installing versioned binaries
11338 @cindex @code{LN_S} example
11339 For instance, here is how you could install a versioned copy of a
11340 program using @samp{$(LN_S)}:
11341
11342 @c Keep in sync with insthook.sh
11343 @example
11344 install-exec-hook:
11345         cd $(DESTDIR)$(bindir) && \
11346           mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
11347           $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
11348 @end example
11349
11350 Note that we rename the program so that a new version will erase the
11351 symbolic link, not the real binary.  Also we @command{cd} into the
11352 destination directory in order to create relative links.
11353
11354 When writing @code{install-exec-hook} or @code{install-data-hook},
11355 please bear in mind that the exec/data distinction is based on the
11356 installation directory, not on the primary used (@pxref{The Two Parts of
11357 Install}).
11358 @c Keep in sync with primary-prefix-couples-documented-valid.sh
11359 So a @code{foo_SCRIPTS} will be installed by
11360 @code{install-data}, and a @code{barexec_SCRIPTS} will be installed by
11361 @code{install-exec}.  You should define your hooks consequently.
11362
11363 @c FIXME should include discussion of variables you can use in these
11364 @c rules
11365
11366 @node Third-Party Makefiles
11367 @section Third-Party @file{Makefile}s
11368
11369 @cindex Third-party packages, interfacing with
11370 @cindex Interfacing with third-party packages
11371
11372 In most projects all @file{Makefile}s are generated by Automake.  In
11373 some cases, however, projects need to embed subdirectories with
11374 handwritten @file{Makefile}s.  For instance, one subdirectory could be
11375 a third-party project with its own build system, not using Automake.
11376
11377 It is possible to list arbitrary directories in @code{SUBDIRS} or
11378 @code{DIST_SUBDIRS} provided each of these directories has a
11379 @file{Makefile} that recognizes all the following recursive targets.
11380
11381 @cindex recursive targets and third-party @file{Makefile}s
11382 When a user runs one of these targets, that target is run recursively
11383 in all subdirectories.  This is why it is important that even
11384 third-party @file{Makefile}s support them.
11385
11386 @table @code
11387 @item all
11388 Compile the entire package.  This is the default target in
11389 Automake-generated @file{Makefile}s, but it does not need to be the
11390 default in third-party @file{Makefile}s.
11391
11392 @item distdir
11393 @trindex distdir
11394 @vindex distdir
11395 @vindex top_distdir
11396 Copy files to distribute into @samp{$(distdir)}, before a tarball is
11397 constructed.  Of course this target is not required if the
11398 @option{no-dist} option (@pxref{Options}) is used.
11399
11400 The variables @samp{$(top_distdir)} and @samp{$(distdir)}
11401 (@pxref{The dist Hook}) will be passed from the outer package to the subpackage
11402 when the @code{distdir} target is invoked.  These two variables have
11403 been adjusted for the directory that is being recursed into, so they
11404 are ready to use.
11405
11406 @item install
11407 @itemx install-data
11408 @itemx install-exec
11409 @itemx uninstall
11410 Install or uninstall files (@pxref{Install}).
11411
11412 @item install-dvi
11413 @itemx install-html
11414 @itemx install-info
11415 @itemx install-ps
11416 @itemx install-pdf
11417 Install only some specific documentation format (@pxref{Texinfo}).
11418
11419 @item installdirs
11420 Create install directories, but do not install any files.
11421
11422 @item check
11423 @itemx installcheck
11424 Check the package (@pxref{Tests}).
11425
11426 @item mostlyclean
11427 @itemx clean
11428 @itemx distclean
11429 @itemx maintainer-clean
11430 Cleaning rules (@pxref{Clean}).
11431
11432 @item dvi
11433 @itemx pdf
11434 @itemx ps
11435 @itemx info
11436 @itemx html
11437 Build the documentation in various formats (@pxref{Texinfo}).
11438
11439 @item tags
11440 @itemx ctags
11441 Build @file{TAGS} and @file{CTAGS} (@pxref{Tags}).
11442 @end table
11443
11444 If you have ever used Gettext in a project, this is a good example of
11445 how third-party @file{Makefile}s can be used with Automake.  The
11446 @file{Makefile}s @command{gettextize} puts in the @file{po/} and
11447 @file{intl/} directories are handwritten @file{Makefile}s that
11448 implement all of these targets.  That way they can be added to
11449 @code{SUBDIRS} in Automake packages.
11450
11451 Directories that are only listed in @code{DIST_SUBDIRS} but not in
11452 @code{SUBDIRS} need only the @code{distclean},
11453 @code{maintainer-clean}, and @code{distdir} rules (@pxref{Conditional
11454 Subdirectories}).
11455
11456 Usually, many of these rules are irrelevant to the third-party
11457 subproject, but they are required for the whole package to work.  It's
11458 OK to have a rule that does nothing, so if you are integrating a
11459 third-party project with no documentation or tag support, you could
11460 simply augment its @file{Makefile} as follows:
11461
11462 @example
11463 EMPTY_AUTOMAKE_TARGETS = dvi pdf ps info html tags ctags
11464 .PHONY: $(EMPTY_AUTOMAKE_TARGETS)
11465 $(EMPTY_AUTOMAKE_TARGETS):
11466 @end example
11467
11468 Another aspect of integrating third-party build systems is whether
11469 they support VPATH builds (@pxref{VPATH Builds}).  Obviously if the
11470 subpackage does not support VPATH builds the whole package will not
11471 support VPATH builds.  This in turns means that @samp{make distcheck}
11472 will not work, because it relies on VPATH builds.  Some people can
11473 live without this (actually, many Automake users have never heard of
11474 @samp{make distcheck}).  Other people may prefer to revamp the
11475 existing @file{Makefile}s to support VPATH@.  Doing so does not
11476 necessarily require Automake, only Autoconf is needed (@pxref{Build
11477 Directories, , Build Directories, autoconf, The Autoconf Manual}).
11478 The necessary substitutions: @samp{@@srcdir@@}, @samp{@@top_srcdir@@},
11479 and @samp{@@top_builddir@@} are defined by @file{configure} when it
11480 processes a @file{Makefile} (@pxref{Preset Output Variables, , Preset
11481 Output Variables, autoconf, The Autoconf Manual}), they are not
11482 computed by the Makefile like the aforementioned @samp{$(distdir)} and
11483 @samp{$(top_distdir)} variables.
11484
11485 It is sometimes inconvenient to modify a third-party @file{Makefile}
11486 to introduce the above required targets.  For instance, one may want to
11487 keep the third-party sources untouched to ease upgrades to new
11488 versions.
11489
11490 @cindex @file{GNUmakefile} including @file{Makefile}
11491 Here are two other ideas.  If GNU make is assumed, one possibility is
11492 to add to that subdirectory a @file{GNUmakefile} that defines the
11493 required targets and includes the third-party @file{Makefile}.  For
11494 this to work in VPATH builds, @file{GNUmakefile} must lie in the build
11495 directory; the easiest way to do this is to write a
11496 @file{GNUmakefile.in} instead, and have it processed with
11497 @code{AC_CONFIG_FILES} from the outer package.  For example if we
11498 assume @file{Makefile} defines all targets except the documentation
11499 targets, and that the @code{check} target is actually called
11500 @code{test}, we could write @file{GNUmakefile} (or
11501 @file{GNUmakefile.in}) like this:
11502
11503 @example
11504 # First, include the real Makefile
11505 include Makefile
11506 # Then, define the other targets needed by Automake Makefiles.
11507 .PHONY: dvi pdf ps info html check
11508 dvi pdf ps info html:
11509 check: test
11510 @end example
11511
11512 @cindex Proxy @file{Makefile} for third-party packages
11513 A similar idea that does not use @code{include} is to write a proxy
11514 @file{Makefile} that dispatches rules to the real @file{Makefile},
11515 either with @samp{$(MAKE) -f Makefile.real $(AM_MAKEFLAGS) target} (if
11516 it's OK to rename the original @file{Makefile}) or with @samp{cd
11517 subdir && $(MAKE) $(AM_MAKEFLAGS) target} (if it's OK to store the
11518 subdirectory project one directory deeper).  The good news is that
11519 this proxy @file{Makefile} can be generated with Automake.  All we
11520 need are @option{-local} targets (@pxref{Extending}) that perform the
11521 dispatch.  Of course the other Automake features are available, so you
11522 could decide to let Automake perform distribution or installation.
11523 Here is a possible @file{Makefile.am}:
11524
11525 @example
11526 all-local:
11527         cd subdir && $(MAKE) $(AM_MAKEFLAGS) all
11528 check-local:
11529         cd subdir && $(MAKE) $(AM_MAKEFLAGS) test
11530 clean-local:
11531         cd subdir && $(MAKE) $(AM_MAKEFLAGS) clean
11532
11533 # Assuming the package knows how to install itself
11534 install-data-local:
11535         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-data
11536 install-exec-local:
11537         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-exec
11538 uninstall-local:
11539         cd subdir && $(MAKE) $(AM_MAKEFLAGS) uninstall
11540
11541 # Distribute files from here.
11542 EXTRA_DIST = subdir/Makefile subdir/program.c ...
11543 @end example
11544
11545 Pushing this idea to the extreme, it is also possible to ignore the
11546 subproject build system and build everything from this proxy
11547 @file{Makefile.am}.  This might sound very sensible if you need VPATH
11548 builds but the subproject does not support them.
11549
11550 @node Distributing
11551 @chapter Distributing @file{Makefile.in}s
11552
11553 Automake places no restrictions on the distribution of the resulting
11554 @file{Makefile.in}s.  We still encourage software authors to
11555 distribute their work under terms like those of the GPL, but doing so
11556 is not required to use Automake.
11557
11558 Some of the files that can be automatically installed via the
11559 @option{--add-missing} switch do fall under the GPL@.  However, these also
11560 have a special exception allowing you to distribute them with your
11561 package, regardless of the licensing you choose.
11562
11563
11564 @node API Versioning
11565 @chapter Automake API Versioning
11566
11567 New Automake releases usually include bug fixes and new features.
11568 Unfortunately they may also introduce new bugs and incompatibilities.
11569 This makes four reasons why a package may require a particular Automake
11570 version.
11571
11572 Things get worse when maintaining a large tree of packages, each one
11573 requiring a different version of Automake.  In the past, this meant that
11574 any developer (and sometimes users) had to install several versions of
11575 Automake in different places, and switch @samp{$PATH} appropriately for
11576 each package.
11577
11578 Starting with version 1.6, Automake installs versioned binaries.  This
11579 means you can install several versions of Automake in the same
11580 @samp{$prefix}, and can select an arbitrary Automake version by running
11581 @command{automake-1.6} or @command{automake-1.7} without juggling with
11582 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
11583 will use @command{automake-1.6} explicitly in their rebuild rules.
11584
11585 The number @samp{1.6} in @command{automake-1.6} is Automake's API version,
11586 not Automake's version.  If a bug fix release is made, for instance
11587 Automake 1.6.1, the API version will remain 1.6.  This means that a
11588 package that works with Automake 1.6 should also work with 1.6.1; after
11589 all, this is what people expect from bug fix releases.
11590
11591 If your package relies on a feature or a bug fix introduced in
11592 a release, you can pass this version as an option to Automake to ensure
11593 older releases will not be used.  For instance, use this in your
11594 @file{configure.ac}:
11595
11596 @example
11597   AM_INIT_AUTOMAKE([1.6.1])    dnl Require Automake 1.6.1 or better.
11598 @end example
11599
11600 @noindent
11601 or, in a particular @file{Makefile.am}:
11602
11603 @example
11604   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
11605 @end example
11606
11607 @noindent
11608 Automake will print an error message if its version is
11609 older than the requested version.
11610
11611
11612 @heading What is in the API
11613
11614 Automake's programming interface is not easy to define.  Basically it
11615 should include at least all @strong{documented} variables and targets
11616 that a @file{Makefile.am} author can use, any behavior associated with
11617 them (e.g., the places where @samp{-hook}'s are run), the command line
11618 interface of @command{automake} and @command{aclocal}, @dots{}
11619
11620 @heading What is not in the API
11621
11622 Every undocumented variable, target, or command line option, is not part
11623 of the API@.  You should avoid using them, as they could change from one
11624 version to the other (even in bug fix releases, if this helps to fix a
11625 bug).
11626
11627 If it turns out you need to use such an undocumented feature, contact
11628 @email{automake@@gnu.org} and try to get it documented and exercised by
11629 the test-suite.
11630
11631 @node Upgrading
11632 @chapter Upgrading a Package to a Newer Automake Version
11633
11634 Automake maintains three kind of files in a package.
11635
11636 @itemize
11637 @item @file{aclocal.m4}
11638 @item @file{Makefile.in}s
11639 @item auxiliary tools like @file{install-sh} or @file{py-compile}
11640 @end itemize
11641
11642 @file{aclocal.m4} is generated by @command{aclocal} and contains some
11643 Automake-supplied M4 macros.  Auxiliary tools are installed by
11644 @samp{automake --add-missing} when needed.  @file{Makefile.in}s are
11645 built from @file{Makefile.am} by @command{automake}, and rely on the
11646 definitions of the M4 macros put in @file{aclocal.m4} as well as the
11647 behavior of the auxiliary tools installed.
11648
11649 Because all of these files are closely related, it is important to
11650 regenerate all of them when upgrading to a newer Automake release.
11651 The usual way to do that is
11652
11653 @example
11654 aclocal # with any option needed (such a -I m4)
11655 autoconf
11656 automake --add-missing --force-missing
11657 @end example
11658
11659 @noindent
11660 or more conveniently:
11661
11662 @example
11663 autoreconf -vfi
11664 @end example
11665
11666 The use of @option{--force-missing} ensures that auxiliary tools will be
11667 overridden by new versions (@pxref{automake Invocation}).
11668
11669 It is important to regenerate all of these files each time Automake is
11670 upgraded, even between bug fixes releases.  For instance, it is not
11671 unusual for a bug fix to involve changes to both the rules generated
11672 in @file{Makefile.in} and the supporting M4 macros copied to
11673 @file{aclocal.m4}.
11674
11675 Presently @command{automake} is able to diagnose situations where
11676 @file{aclocal.m4} has been generated with another version of
11677 @command{aclocal}.  However it never checks whether auxiliary scripts
11678 are up-to-date.  In other words, @command{automake} will tell you when
11679 @command{aclocal} needs to be rerun, but it will never diagnose a
11680 missing @option{--force-missing}.
11681
11682 Before upgrading to a new major release, it is a good idea to read the
11683 file @file{NEWS}.  This file lists all changes between releases: new
11684 features, obsolete constructs, known incompatibilities, and
11685 workarounds.
11686
11687 @node FAQ
11688 @chapter Frequently Asked Questions about Automake
11689
11690 This chapter covers some questions that often come up on the mailing
11691 lists.
11692
11693 @menu
11694 * CVS::                         CVS and generated files
11695 * maintainer-mode::             missing and AM_MAINTAINER_MODE
11696 * Wildcards::                   Why doesn't Automake support wildcards?
11697 * Limitations on File Names::   Limitations on source and installed file names
11698 * Errors with distclean::       Files left in build directory after distclean
11699 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
11700 * Renamed Objects::             Why are object files sometimes renamed?
11701 * Per-Object Flags::            How to simulate per-object flags?
11702 * Multiple Outputs::            Writing rules for tools with many output files
11703 * Hard-Coded Install Paths::    Installing to hard-coded locations
11704 * Debugging Make Rules::        Strategies when things don't work as expected
11705 * Reporting Bugs::              Feedback on bugs and feature requests
11706 @end menu
11707
11708 @node CVS
11709 @section CVS and generated files
11710
11711 @subheading Background: distributed generated Files
11712 @cindex generated files, distributed
11713 @cindex rebuild rules
11714
11715 Packages made with Autoconf and Automake ship with some generated
11716 files like @file{configure} or @file{Makefile.in}.  These files were
11717 generated on the developer's host and are distributed so that
11718 end-users do not have to install the maintainer tools required to
11719 rebuild them.  Other generated files like Lex scanners, Yacc parsers,
11720 or Info documentation, are usually distributed on similar grounds.
11721
11722 Automake outputs rules in @file{Makefile}s to rebuild these files.  For
11723 instance, @command{make} will run @command{autoconf} to rebuild
11724 @file{configure} whenever @file{configure.ac} is changed.  This makes
11725 development safer by ensuring a @file{configure} is never out-of-date
11726 with respect to @file{configure.ac}.
11727
11728 As generated files shipped in packages are up-to-date, and because
11729 @command{tar} preserves times-tamps, these rebuild rules are not
11730 triggered when a user unpacks and builds a package.
11731
11732 @subheading Background: CVS and Timestamps
11733 @cindex timestamps and CVS
11734 @cindex CVS and timestamps
11735
11736 Unless you use CVS keywords (in which case files must be updated at
11737 commit time), CVS preserves timestamp during @samp{cvs commit} and
11738 @samp{cvs import -d} operations.
11739
11740 When you check out a file using @samp{cvs checkout} its timestamp is
11741 set to that of the revision that is being checked out.
11742
11743 However, during @command{cvs update}, files will have the date of the
11744 update, not the original timestamp of this revision.  This is meant to
11745 make sure that @command{make} notices sources files have been updated.
11746
11747 This timestamp shift is troublesome when both sources and generated
11748 files are kept under CVS@.  Because CVS processes files in lexical
11749 order, @file{configure.ac} will appear newer than @file{configure}
11750 after a @command{cvs update} that updates both files, even if
11751 @file{configure} was newer than @file{configure.ac} when it was
11752 checked in.  Calling @command{make} will then trigger a spurious rebuild
11753 of @file{configure}.
11754
11755 @subheading Living with CVS in Autoconfiscated Projects
11756 @cindex CVS and generated files
11757 @cindex generated files and CVS
11758
11759 There are basically two clans amongst maintainers: those who keep all
11760 distributed files under CVS, including generated files, and those who
11761 keep generated files @emph{out} of CVS.
11762
11763 @subsubheading All Files in CVS
11764
11765 @itemize @bullet
11766 @item
11767 The CVS repository contains all distributed files so you know exactly
11768 what is distributed, and you can checkout any prior version entirely.
11769
11770 @item
11771 Maintainers can see how generated files evolve (for instance, you can
11772 see what happens to your @file{Makefile.in}s when you upgrade Automake
11773 and make sure they look OK).
11774
11775 @item
11776 Users do not need the autotools to build a checkout of the project, it
11777 works just like a released tarball.
11778
11779 @item
11780 If users use @command{cvs update} to update their copy, instead of
11781 @command{cvs checkout} to fetch a fresh one, timestamps will be
11782 inaccurate.  Some rebuild rules will be triggered and attempt to
11783 run developer tools such as @command{autoconf} or @command{automake}.
11784
11785 Actually, calls to such tools are all wrapped into a call to the
11786 @command{missing} script discussed later (@pxref{maintainer-mode}).
11787 @command{missing} will take care of fixing the timestamps when these
11788 tools are not installed, so that the build can continue.
11789
11790 @item
11791 In distributed development, developers are likely to have different
11792 version of the maintainer tools installed.  In this case rebuilds
11793 triggered by timestamp lossage will lead to spurious changes
11794 to generated files.  There are several solutions to this:
11795
11796 @itemize
11797 @item
11798 All developers should use the same versions, so that the rebuilt files
11799 are identical to files in CVS@.  (This starts to be difficult when each
11800 project you work on uses different versions.)
11801 @item
11802 Or people use a script to fix the timestamp after a checkout (the GCC
11803 folks have such a script).
11804 @item
11805 Or @file{configure.ac} uses @code{AM_MAINTAINER_MODE}, which will
11806 disable all of these rebuild rules by default.  This is further discussed
11807 in @ref{maintainer-mode}.
11808 @end itemize
11809
11810 @item
11811 Although we focused on spurious rebuilds, the converse can also
11812 happen.  CVS's timestamp handling can also let you think an
11813 out-of-date file is up-to-date.
11814
11815 For instance, suppose a developer has modified @file{Makefile.am} and
11816 has rebuilt @file{Makefile.in}, and then decides to do a last-minute
11817 change to @file{Makefile.am} right before checking in both files
11818 (without rebuilding @file{Makefile.in} to account for the change).
11819
11820 This last change to @file{Makefile.am} makes the copy of
11821 @file{Makefile.in} out-of-date.  Since CVS processes files
11822 alphabetically, when another developer @samp{cvs update}s his or her
11823 tree, @file{Makefile.in} will happen to be newer than
11824 @file{Makefile.am}.  This other developer will not see that
11825 @file{Makefile.in} is out-of-date.
11826
11827 @end itemize
11828
11829 @subsubheading Generated Files out of CVS
11830
11831 One way to get CVS and @command{make} working peacefully is to never
11832 store generated files in CVS, i.e., do not CVS-control files that
11833 are @file{Makefile} targets (also called @emph{derived} files).
11834
11835 This way developers are not annoyed by changes to generated files.  It
11836 does not matter if they all have different versions (assuming they are
11837 compatible, of course).  And finally, timestamps are not lost, changes
11838 to sources files can't be missed as in the
11839 @file{Makefile.am}/@file{Makefile.in} example discussed earlier.
11840
11841 The drawback is that the CVS repository is not an exact copy of what
11842 is distributed and that users now need to install various development
11843 tools (maybe even specific versions) before they can build a checkout.
11844 But, after all, CVS's job is versioning, not distribution.
11845
11846 Allowing developers to use different versions of their tools can also
11847 hide bugs during distributed development.  Indeed, developers will be
11848 using (hence testing) their own generated files, instead of the
11849 generated files that will be released actually.  The developer who
11850 prepares the tarball might be using a version of the tool that
11851 produces bogus output (for instance a non-portable C file), something
11852 other developers could have noticed if they weren't using their own
11853 versions of this tool.
11854
11855 @subheading Third-party Files
11856 @cindex CVS and third-party files
11857 @cindex third-party files and CVS
11858
11859 Another class of files not discussed here (because they do not cause
11860 timestamp issues) are files that are shipped with a package, but
11861 maintained elsewhere.  For instance, tools like @command{gettextize}
11862 and @command{autopoint} (from Gettext) or @command{libtoolize} (from
11863 Libtool), will install or update files in your package.
11864
11865 These files, whether they are kept under CVS or not, raise similar
11866 concerns about version mismatch between developers' tools.  The
11867 Gettext manual has a section about this, see @ref{CVS Issues, CVS
11868 Issues, Integrating with CVS, gettext, GNU gettext tools}.
11869
11870 @node maintainer-mode
11871 @section @command{missing} and @code{AM_MAINTAINER_MODE}
11872
11873 @subheading @command{missing}
11874 @cindex @command{missing}, purpose
11875
11876 The @command{missing} script is a wrapper around several maintainer
11877 tools, designed to warn users if a maintainer tool is required but
11878 missing.  Typical maintainer tools are @command{autoconf},
11879 @command{automake}, @command{bison}, etc.  Because file generated by
11880 these tools are shipped with the other sources of a package, these
11881 tools shouldn't be required during a user build and they are not
11882 checked for in @file{configure}.
11883
11884 However, if for some reason a rebuild rule is triggered and involves a
11885 missing tool, @command{missing} will notice it and warn the user.
11886 Besides the warning, when a tool is missing, @command{missing} will
11887 attempt to fix timestamps in a way that allows the build to continue.
11888 For instance, @command{missing} will touch @file{configure} if
11889 @command{autoconf} is not installed.  When all distributed files are
11890 kept under version control, this feature of @command{missing} allows a
11891 user @emph{with no maintainer tools} to build a package off its version
11892 control repository, bypassing any timestamp inconsistency (implied by
11893 e.g.@: @samp{cvs update} or @samp{git clone}).
11894
11895 If the required tool is installed, @command{missing} will run it and
11896 won't attempt to continue after failures.  This is correct during
11897 development: developers love fixing failures.  However, users with
11898 wrong versions of maintainer tools may get an error when the rebuild
11899 rule is spuriously triggered, halting the build.  This failure to let
11900 the build continue is one of the arguments of the
11901 @code{AM_MAINTAINER_MODE} advocates.
11902
11903 @subheading @code{AM_MAINTAINER_MODE}
11904 @cindex @code{AM_MAINTAINER_MODE}, purpose
11905 @acindex AM_MAINTAINER_MODE
11906
11907 @code{AM_MAINTAINER_MODE} allows you to choose whether the so called
11908 "rebuild rules" should be enabled or disabled.  With
11909 @code{AM_MAINTAINER_MODE([enable])}, they are enabled by default,
11910 otherwise they are disabled by default.  In the latter case, if
11911 you have @code{AM_MAINTAINER_MODE} in @file{configure.ac}, and run
11912 @samp{./configure && make}, then @command{make} will *never* attempt to
11913 rebuild @file{configure}, @file{Makefile.in}s, Lex or Yacc outputs, etc.
11914 I.e., this disables build rules for files that are usually distributed
11915 and that users should normally not have to update.
11916
11917 The user can override the default setting by passing either
11918 @samp{--enable-maintainer-mode} or @samp{--disable-maintainer-mode}
11919 to @command{configure}.
11920
11921 People use @code{AM_MAINTAINER_MODE} either because they do not want their
11922 users (or themselves) annoyed by timestamps lossage (@pxref{CVS}), or
11923 because they simply can't stand the rebuild rules and prefer running
11924 maintainer tools explicitly.
11925
11926 @code{AM_MAINTAINER_MODE} also allows you to disable some custom build
11927 rules conditionally.  Some developers use this feature to disable
11928 rules that need exotic tools that users may not have available.
11929
11930 Several years ago Fran@,{c}ois Pinard pointed out several arguments
11931 against this @code{AM_MAINTAINER_MODE} macro.  Most of them relate to
11932 insecurity.  By removing dependencies you get non-dependable builds:
11933 changes to sources files can have no effect on generated files and this
11934 can be very confusing when unnoticed.  He adds that security shouldn't
11935 be reserved to maintainers (what @option{--enable-maintainer-mode}
11936 suggests), on the contrary.  If one user has to modify a
11937 @file{Makefile.am}, then either @file{Makefile.in} should be updated
11938 or a warning should be output (this is what Automake uses
11939 @command{missing} for) but the last thing you want is that nothing
11940 happens and the user doesn't notice it (this is what happens when
11941 rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
11942
11943 Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro was
11944 swayed by Fran@,{c}ois's arguments, and got rid of
11945 @code{AM_MAINTAINER_MODE} in all of his packages.
11946
11947 Still many people continue to use @code{AM_MAINTAINER_MODE}, because
11948 it helps them working on projects where all files are kept under version
11949 control, and because @command{missing} isn't enough if you have the
11950 wrong version of the tools.
11951
11952
11953 @node Wildcards
11954 @section Why doesn't Automake support wildcards?
11955 @cindex wildcards
11956
11957 Developers are lazy.  They would often like to use wildcards in
11958 @file{Makefile.am}s, so that they would not need to remember to
11959 update @file{Makefile.am}s every time they add, delete, or rename
11960 a file.
11961
11962 There are several objections to this:
11963 @itemize
11964 @item
11965 When using CVS (or similar) developers need to remember they have to
11966 run @samp{cvs add} or @samp{cvs rm} anyway.  Updating
11967 @file{Makefile.am} accordingly quickly becomes a reflex.
11968
11969 Conversely, if your application doesn't compile
11970 because you forgot to add a file in @file{Makefile.am}, it will help
11971 you remember to @samp{cvs add} it.
11972
11973 @item
11974 Using wildcards makes it easy to distribute files by mistake.  For
11975 instance, some code a developer is experimenting with (a test case,
11976 say) that should not be part of the distribution.
11977
11978 @item
11979 Using wildcards it's easy to omit some files by mistake.  For
11980 instance, one developer creates a new file, uses it in many places,
11981 but forgets to commit it.  Another developer then checks out the
11982 incomplete project and is able to run @samp{make dist} successfully,
11983 even though a file is missing. By listing files, @samp{make dist}
11984 @emph{will} complain.
11985
11986 @item
11987 Wildcards are not portable to some non-GNU @command{make} implementations,
11988 e.g., NetBSD @command{make} will not expand globs such as @samp{*} in
11989 prerequisites of a target.
11990
11991 @item
11992 Finally, it's really hard to @emph{forget} to add a file to
11993 @file{Makefile.am}: files that are not listed in @file{Makefile.am} are
11994 not compiled or installed, so you can't even test them.
11995 @end itemize
11996
11997 Still, these are philosophical objections, and as such you may disagree,
11998 or find enough value in wildcards to dismiss all of them.  Before you
11999 start writing a patch against Automake to teach it about wildcards,
12000 let's see the main technical issue: portability.
12001
12002 Although @samp{$(wildcard ...)} works with GNU @command{make}, it is
12003 not portable to other @command{make} implementations.
12004
12005 The only way Automake could support @command{$(wildcard ...)} is by
12006 expending @command{$(wildcard ...)} when @command{automake} is run.
12007 The resulting @file{Makefile.in}s would be portable since they would
12008 list all files and not use @samp{$(wildcard ...)}.  However that
12009 means developers would need to remember to run @command{automake} each
12010 time they add, delete, or rename files.
12011
12012 Compared to editing @file{Makefile.am}, this is a very small gain.  Sure,
12013 it's easier and faster to type @samp{automake; make} than to type
12014 @samp{emacs Makefile.am; make}.  But nobody bothered enough to write a
12015 patch to add support for this syntax.  Some people use scripts to
12016 generate file lists in @file{Makefile.am} or in separate
12017 @file{Makefile} fragments.
12018
12019 Even if you don't care about portability, and are tempted to use
12020 @samp{$(wildcard ...)} anyway because you target only GNU Make, you
12021 should know there are many places where Automake needs to know exactly
12022 which files should be processed.  As Automake doesn't know how to
12023 expand @samp{$(wildcard ...)}, you cannot use it in these places.
12024 @samp{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
12025 variables as far Automake is concerned.
12026
12027 You can get warnings about @samp{$(wildcard ...}) constructs using the
12028 @option{-Wportability} flag.
12029
12030 @node Limitations on File Names
12031 @section Limitations on File Names
12032 @cindex file names, limitations on
12033
12034 Automake attempts to support all kinds of file names, even those that
12035 contain unusual characters or are unusually long.  However, some
12036 limitations are imposed by the underlying operating system and tools.
12037
12038 Most operating systems prohibit the use of the null byte in file
12039 names, and reserve @samp{/} as a directory separator.  Also, they
12040 require that file names are properly encoded for the user's locale.
12041 Automake is subject to these limits.
12042
12043 Portable packages should limit themselves to POSIX file
12044 names.  These can contain ASCII letters and digits,
12045 @samp{_}, @samp{.}, and @samp{-}.  File names consist of components
12046 separated by @samp{/}.  File name components cannot begin with
12047 @samp{-}.
12048
12049 Portable POSIX file names cannot contain components that exceed a
12050 14-byte limit, but nowadays it's normally safe to assume the
12051 more-generous XOPEN limit of 255 bytes.  POSIX
12052 limits file names to 255 bytes (XOPEN allows 1023 bytes),
12053 but you may want to limit a source tarball to file names of 99 bytes
12054 to avoid interoperability problems with old versions of @command{tar}.
12055
12056 If you depart from these rules (e.g., by using non-ASCII
12057 characters in file names, or by using lengthy file names), your
12058 installers may have problems for reasons unrelated to Automake.
12059 However, if this does not concern you, you should know about the
12060 limitations imposed by Automake itself.  These limitations are
12061 undesirable, but some of them seem to be inherent to underlying tools
12062 like Autoconf, Make, M4, and the shell.  They fall into three
12063 categories: install directories, build directories, and file names.
12064
12065 The following characters:
12066
12067 @example
12068 @r{newline} " # $ ' `
12069 @end example
12070
12071 should not appear in the names of install directories.  For example,
12072 the operand of @command{configure}'s @option{--prefix} option should
12073 not contain these characters.
12074
12075 Build directories suffer the same limitations as install directories,
12076 and in addition should not contain the following characters:
12077
12078 @example
12079 & @@ \
12080 @end example
12081
12082 For example, the full name of the directory containing the source
12083 files should not contain these characters.
12084
12085 Source and installation file names like @file{main.c} are limited even
12086 further: they should conform to the POSIX/XOPEN
12087 rules described above.  In addition, if you plan to port to
12088 non-POSIX environments, you should avoid file names that
12089 differ only in case (e.g., @file{makefile} and @file{Makefile}).
12090 Nowadays it is no longer worth worrying about the 8.3 limits of
12091 DOS file systems.
12092
12093 @c FIXME This should probably be moved in the "Checking the Distribution"
12094 @c FIXME section...
12095 @node Errors with distclean
12096 @section Errors with distclean
12097 @cindex @code{distclean}, diagnostic
12098 @cindex @samp{make distclean}, diagnostic
12099 @cindex dependencies and distributed files
12100 @trindex distclean
12101
12102 This is a diagnostic you might encounter while running @samp{make
12103 distcheck}.
12104
12105 As explained in @ref{Checking the Distribution}, @samp{make distcheck}
12106 attempts to build and check your package for errors like this one.
12107
12108 @samp{make distcheck} will perform a @code{VPATH} build of your
12109 package (@pxref{VPATH Builds}), and then call @samp{make distclean}.
12110 Files left in the build directory after @samp{make distclean} has run
12111 are listed after this error.
12112
12113 This diagnostic really covers two kinds of errors:
12114
12115 @itemize @bullet
12116 @item
12117 files that are forgotten by distclean;
12118 @item
12119 distributed files that are erroneously rebuilt.
12120 @end itemize
12121
12122 The former left-over files are not distributed, so the fix is to mark
12123 them for cleaning (@pxref{Clean}), this is obvious and doesn't deserve
12124 more explanations.
12125
12126 The latter bug is not always easy to understand and fix, so let's
12127 proceed with an example.  Suppose our package contains a program for
12128 which we want to build a man page using @command{help2man}.  GNU
12129 @command{help2man} produces simple manual pages from the @option{--help}
12130 and @option{--version} output of other commands (@pxref{Top, , Overview,
12131 help2man, The Help2man Manual}).  Because we don't want to force our
12132 users to install @command{help2man}, we decide to distribute the
12133 generated man page using the following setup.
12134
12135 @example
12136 # This Makefile.am is bogus.
12137 bin_PROGRAMS = foo
12138 foo_SOURCES = foo.c
12139 dist_man_MANS = foo.1
12140
12141 foo.1: foo$(EXEEXT)
12142         help2man --output=foo.1 ./foo$(EXEEXT)
12143 @end example
12144
12145 This will effectively distribute the man page.  However,
12146 @samp{make distcheck} will fail with:
12147
12148 @example
12149 ERROR: files left in build directory after distclean:
12150 ./foo.1
12151 @end example
12152
12153 Why was @file{foo.1} rebuilt?  Because although distributed,
12154 @file{foo.1} depends on a non-distributed built file:
12155 @file{foo$(EXEEXT)}.  @file{foo$(EXEEXT)} is built by the user, so it
12156 will always appear to be newer than the distributed @file{foo.1}.
12157
12158 @samp{make distcheck} caught an inconsistency in our package.  Our
12159 intent was to distribute @file{foo.1} so users do not need to install
12160 @command{help2man}, however since this rule causes this file to be
12161 always rebuilt, users @emph{do} need @command{help2man}.  Either we
12162 should ensure that @file{foo.1} is not rebuilt by users, or there is
12163 no point in distributing @file{foo.1}.
12164
12165 More generally, the rule is that distributed files should never depend
12166 on non-distributed built files.  If you distribute something
12167 generated, distribute its sources.
12168
12169 One way to fix the above example, while still distributing
12170 @file{foo.1} is to not depend on @file{foo$(EXEEXT)}.  For instance,
12171 assuming @command{foo --version} and @command{foo --help} do not
12172 change unless @file{foo.c} or @file{configure.ac} change, we could
12173 write the following @file{Makefile.am}:
12174
12175 @example
12176 bin_PROGRAMS = foo
12177 foo_SOURCES = foo.c
12178 dist_man_MANS = foo.1
12179
12180 foo.1: foo.c $(top_srcdir)/configure.ac
12181         $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
12182         help2man --output=foo.1 ./foo$(EXEEXT)
12183 @end example
12184
12185 This way, @file{foo.1} will not get rebuilt every time
12186 @file{foo$(EXEEXT)} changes.  The @command{make} call makes sure
12187 @file{foo$(EXEEXT)} is up-to-date before @command{help2man}.  Another
12188 way to ensure this would be to use separate directories for binaries
12189 and man pages, and set @code{SUBDIRS} so that binaries are built
12190 before man pages.
12191
12192 We could also decide not to distribute @file{foo.1}.  In
12193 this case it's fine to have @file{foo.1} dependent upon
12194 @file{foo$(EXEEXT)}, since both will have to be rebuilt.
12195 However it would be impossible to build the package in a
12196 cross-compilation, because building @file{foo.1} involves
12197 an @emph{execution} of @file{foo$(EXEEXT)}.
12198
12199 Another context where such errors are common is when distributed files
12200 are built by tools that are built by the package.  The pattern is
12201 similar:
12202
12203 @example
12204 distributed-file: built-tools distributed-sources
12205         build-command
12206 @end example
12207
12208 @noindent
12209 should be changed to
12210
12211 @example
12212 distributed-file: distributed-sources
12213         $(MAKE) $(AM_MAKEFLAGS) built-tools
12214         build-command
12215 @end example
12216
12217 @noindent
12218 or you could choose not to distribute @file{distributed-file}, if
12219 cross-compilation does not matter.
12220
12221 The points made through these examples are worth a summary:
12222
12223 @cartouche
12224 @itemize
12225 @item
12226 Distributed files should never depend upon non-distributed built
12227 files.
12228 @item
12229 Distributed files should be distributed with all their dependencies.
12230 @item
12231 If a file is @emph{intended} to be rebuilt by users, then there is no point
12232 in distributing it.
12233 @end itemize
12234 @end cartouche
12235
12236 @vrindex distcleancheck_listfiles
12237 For desperate cases, it's always possible to disable this check by
12238 setting @code{distcleancheck_listfiles} as documented in @ref{Checking
12239 the Distribution}.
12240 Make sure you do understand the reason why @samp{make distcheck}
12241 complains before you do this.  @code{distcleancheck_listfiles} is a
12242 way to @emph{hide} errors, not to fix them.  You can always do better.
12243
12244 @node Flag Variables Ordering
12245 @section Flag Variables Ordering
12246 @cindex Ordering flag variables
12247 @cindex Flag variables, ordering
12248
12249 @display
12250 What is the difference between @code{AM_CFLAGS}, @code{CFLAGS}, and
12251 @code{mumble_CFLAGS}?
12252 @end display
12253
12254 @display
12255 Why does @command{automake} output @code{CPPFLAGS} after
12256 @code{AM_CPPFLAGS} on compile lines?  Shouldn't it be the converse?
12257 @end display
12258
12259 @display
12260 My @file{configure} adds some warning flags into @code{CXXFLAGS}.  In
12261 one @file{Makefile.am} I would like to append a new flag, however if I
12262 put the flag into @code{AM_CXXFLAGS} it is prepended to the other
12263 flags, not appended.
12264 @end display
12265
12266 @subheading Compile Flag Variables
12267 @cindex Flag Variables, Ordering
12268 @cindex Compile Flag Variables
12269 @cindex @code{AM_CCASFLAGS} and @code{CCASFLAGS}
12270 @cindex @code{AM_CFLAGS} and @code{CFLAGS}
12271 @cindex @code{AM_CPPFLAGS} and @code{CPPFLAGS}
12272 @cindex @code{AM_CXXFLAGS} and @code{CXXFLAGS}
12273 @cindex @code{AM_FCFLAGS} and @code{FCFLAGS}
12274 @cindex @code{AM_FFLAGS} and @code{FFLAGS}
12275 @cindex @code{AM_GCJFLAGS} and @code{GCJFLAGS}
12276 @cindex @code{AM_LDFLAGS} and @code{LDFLAGS}
12277 @cindex @code{AM_LFLAGS} and @code{LFLAGS}
12278 @cindex @code{AM_LIBTOOLFLAGS} and @code{LIBTOOLFLAGS}
12279 @cindex @code{AM_OBJCFLAGS} and @code{OBJCFLAGS}
12280 @cindex @code{AM_OBJCXXFLAGS} and @code{OBJXXCFLAGS}
12281 @cindex @code{AM_RFLAGS} and @code{RFLAGS}
12282 @cindex @code{AM_UPCFLAGS} and @code{UPCFLAGS}
12283 @cindex @code{AM_YFLAGS} and @code{YFLAGS}
12284 @cindex @code{CCASFLAGS} and @code{AM_CCASFLAGS}
12285 @cindex @code{CFLAGS} and @code{AM_CFLAGS}
12286 @cindex @code{CPPFLAGS} and @code{AM_CPPFLAGS}
12287 @cindex @code{CXXFLAGS} and @code{AM_CXXFLAGS}
12288 @cindex @code{FCFLAGS} and @code{AM_FCFLAGS}
12289 @cindex @code{FFLAGS} and @code{AM_FFLAGS}
12290 @cindex @code{GCJFLAGS} and @code{AM_GCJFLAGS}
12291 @cindex @code{LDFLAGS} and @code{AM_LDFLAGS}
12292 @cindex @code{LFLAGS} and @code{AM_LFLAGS}
12293 @cindex @code{LIBTOOLFLAGS} and @code{AM_LIBTOOLFLAGS}
12294 @cindex @code{OBJCFLAGS} and @code{AM_OBJCFLAGS}
12295 @cindex @code{OBJCXXFLAGS} and @code{AM_OBJCXXFLAGS}
12296 @cindex @code{RFLAGS} and @code{AM_RFLAGS}
12297 @cindex @code{UPCFLAGS} and @code{AM_UPCFLAGS}
12298 @cindex @code{YFLAGS} and @code{AM_YFLAGS}
12299
12300 This section attempts to answer all the above questions.  We will
12301 mostly discuss @code{CPPFLAGS} in our examples, but actually the
12302 answer holds for all the compile flags used in Automake:
12303 @code{CCASFLAGS}, @code{CFLAGS}, @code{CPPFLAGS}, @code{CXXFLAGS},
12304 @code{FCFLAGS}, @code{FFLAGS}, @code{GCJFLAGS}, @code{LDFLAGS},
12305 @code{LFLAGS}, @code{LIBTOOLFLAGS}, @code{OBJCFLAGS}, @code{OBJCXXFLAGS},
12306 @code{RFLAGS}, @code{UPCFLAGS}, and @code{YFLAGS}.
12307
12308 @code{CPPFLAGS}, @code{AM_CPPFLAGS}, and @code{mumble_CPPFLAGS} are
12309 three variables that can be used to pass flags to the C preprocessor
12310 (actually these variables are also used for other languages like C++
12311 or preprocessed Fortran).  @code{CPPFLAGS} is the user variable
12312 (@pxref{User Variables}), @code{AM_CPPFLAGS} is the Automake variable,
12313 and @code{mumble_CPPFLAGS} is the variable specific to the
12314 @code{mumble} target (we call this a per-target variable,
12315 @pxref{Program and Library Variables}).
12316
12317 Automake always uses two of these variables when compiling C sources
12318 files.  When compiling an object file for the @code{mumble} target,
12319 the first variable will be @code{mumble_CPPFLAGS} if it is defined, or
12320 @code{AM_CPPFLAGS} otherwise.  The second variable is always
12321 @code{CPPFLAGS}.
12322
12323 In the following example,
12324
12325 @example
12326 bin_PROGRAMS = foo bar
12327 foo_SOURCES = xyz.c
12328 bar_SOURCES = main.c
12329 foo_CPPFLAGS = -DFOO
12330 AM_CPPFLAGS = -DBAZ
12331 @end example
12332
12333 @noindent
12334 @file{xyz.o} will be compiled with @samp{$(foo_CPPFLAGS) $(CPPFLAGS)},
12335 (because @file{xyz.o} is part of the @code{foo} target), while
12336 @file{main.o} will be compiled with @samp{$(AM_CPPFLAGS) $(CPPFLAGS)}
12337 (because there is no per-target variable for target @code{bar}).
12338
12339 The difference between @code{mumble_CPPFLAGS} and @code{AM_CPPFLAGS}
12340 being clear enough, let's focus on @code{CPPFLAGS}.  @code{CPPFLAGS}
12341 is a user variable, i.e., a variable that users are entitled to modify
12342 in order to compile the package.  This variable, like many others,
12343 is documented at the end of the output of @samp{configure --help}.
12344
12345 For instance, someone who needs to add @file{/home/my/usr/include} to
12346 the C compiler's search path would configure a package with
12347
12348 @example
12349 ./configure CPPFLAGS='-I /home/my/usr/include'
12350 @end example
12351
12352 @noindent
12353 and this flag would be propagated to the compile rules of all
12354 @file{Makefile}s.
12355
12356 It is also not uncommon to override a user variable at
12357 @command{make}-time.  Many installers do this with @code{prefix}, but
12358 this can be useful with compiler flags too.  For instance, if, while
12359 debugging a C++ project, you need to disable optimization in one
12360 specific object file, you can run something like
12361
12362 @example
12363 rm file.o
12364 make CXXFLAGS=-O0 file.o
12365 make
12366 @end example
12367
12368 The reason @samp{$(CPPFLAGS)} appears after @samp{$(AM_CPPFLAGS)} or
12369 @samp{$(mumble_CPPFLAGS)} in the compile command is that users
12370 should always have the last say.  It probably makes more sense if you
12371 think about it while looking at the @samp{CXXFLAGS=-O0} above, which
12372 should supersede any other switch from @code{AM_CXXFLAGS} or
12373 @code{mumble_CXXFLAGS} (and this of course replaces the previous value
12374 of @code{CXXFLAGS}).
12375
12376 You should never redefine a user variable such as @code{CPPFLAGS} in
12377 @file{Makefile.am}.  Use @samp{automake -Woverride} to diagnose such
12378 mistakes.  Even something like
12379
12380 @example
12381 CPPFLAGS = -DDATADIR=\"$(datadir)\" @@CPPFLAGS@@
12382 @end example
12383
12384 @noindent
12385 is erroneous.  Although this preserves @file{configure}'s value of
12386 @code{CPPFLAGS}, the definition of @code{DATADIR} will disappear if a
12387 user attempts to override @code{CPPFLAGS} from the @command{make}
12388 command line.
12389
12390 @example
12391 AM_CPPFLAGS = -DDATADIR=\"$(datadir)\"
12392 @end example
12393
12394 @noindent
12395 is all that is needed here if no per-target flags are used.
12396
12397 You should not add options to these user variables within
12398 @file{configure} either, for the same reason.  Occasionally you need
12399 to modify these variables to perform a test, but you should reset
12400 their values afterwards.  In contrast, it is OK to modify the
12401 @samp{AM_} variables within @file{configure} if you @code{AC_SUBST}
12402 them, but it is rather rare that you need to do this, unless you
12403 really want to change the default definitions of the @samp{AM_}
12404 variables in all @file{Makefile}s.
12405
12406 What we recommend is that you define extra flags in separate
12407 variables.  For instance, you may write an Autoconf macro that computes
12408 a set of warning options for the C compiler, and @code{AC_SUBST} them
12409 in @code{WARNINGCFLAGS}; you may also have an Autoconf macro that
12410 determines which compiler and which linker flags should be used to
12411 link with library @file{libfoo}, and @code{AC_SUBST} these in
12412 @code{LIBFOOCFLAGS} and @code{LIBFOOLDFLAGS}.  Then, a
12413 @file{Makefile.am} could use these variables as follows:
12414
12415 @example
12416 AM_CFLAGS = $(WARNINGCFLAGS)
12417 bin_PROGRAMS = prog1 prog2
12418 prog1_SOURCES = @dots{}
12419 prog2_SOURCES = @dots{}
12420 prog2_CFLAGS = $(LIBFOOCFLAGS) $(AM_CFLAGS)
12421 prog2_LDFLAGS = $(LIBFOOLDFLAGS)
12422 @end example
12423
12424 In this example both programs will be compiled with the flags
12425 substituted into @samp{$(WARNINGCFLAGS)}, and @code{prog2} will
12426 additionally be compiled with the flags required to link with
12427 @file{libfoo}.
12428
12429 Note that listing @code{AM_CFLAGS} in a per-target @code{CFLAGS}
12430 variable is a common idiom to ensure that @code{AM_CFLAGS} applies to
12431 every target in a @file{Makefile.in}.
12432
12433 Using variables like this gives you full control over the ordering of
12434 the flags.  For instance, if there is a flag in $(WARNINGCFLAGS) that
12435 you want to negate for a particular target, you can use something like
12436 @samp{prog1_CFLAGS = $(AM_CFLAGS) -no-flag}.  If all of these flags had
12437 been forcefully appended to @code{CFLAGS}, there would be no way to
12438 disable one flag.  Yet another reason to leave user variables to
12439 users.
12440
12441 Finally, we have avoided naming the variable of the example
12442 @code{LIBFOO_LDFLAGS} (with an underscore) because that would cause
12443 Automake to think that this is actually a per-target variable (like
12444 @code{mumble_LDFLAGS}) for some non-declared @code{LIBFOO} target.
12445
12446 @subheading Other Variables
12447
12448 There are other variables in Automake that follow similar principles
12449 to allow user options.  For instance, Texinfo rules (@pxref{Texinfo})
12450 use @code{MAKEINFOFLAGS} and @code{AM_MAKEINFOFLAGS}.  Similarly,
12451 DejaGnu tests (@pxref{DejaGnu Tests}) use @code{RUNTESTDEFAULTFLAGS} and
12452 @code{AM_RUNTESTDEFAULTFLAGS}.  The tags and ctags rules
12453 (@pxref{Tags}) use @code{ETAGSFLAGS}, @code{AM_ETAGSFLAGS},
12454 @code{CTAGSFLAGS}, and @code{AM_CTAGSFLAGS}.  Java rules
12455 (@pxref{Java}) use @code{JAVACFLAGS} and @code{AM_JAVACFLAGS}.  None
12456 of these rules support per-target flags (yet).
12457
12458 To some extent, even @code{AM_MAKEFLAGS} (@pxref{Subdirectories})
12459 obeys this naming scheme.  The slight difference is that
12460 @code{MAKEFLAGS} is passed to sub-@command{make}s implicitly by
12461 @command{make} itself.
12462
12463 However you should not think that all variables ending with
12464 @code{FLAGS} follow this convention.  For instance,
12465 @code{DISTCHECK_CONFIGURE_FLAGS} (@pxref{Checking the Distribution}) and
12466 @code{ACLOCAL_AMFLAGS} (see @ref{Rebuilding} and @ref{Local Macros}),
12467 are two variables that are only useful to the maintainer and have no
12468 user counterpart.
12469
12470 @code{ARFLAGS} (@pxref{A Library}) is usually defined by Automake and
12471 has neither @code{AM_} nor per-target cousin.
12472
12473 Finally you should not think that the existence of a per-target
12474 variable implies the existence of an @code{AM_} variable or of a user
12475 variable.  For instance, the @code{mumble_LDADD} per-target variable
12476 overrides the makefile-wide @code{LDADD} variable (which is not a user
12477 variable), and @code{mumble_LIBADD} exists only as a per-target
12478 variable.  @xref{Program and Library Variables}.
12479
12480
12481 @node Renamed Objects
12482 @section Why are object files sometimes renamed?
12483
12484 This happens when per-target compilation flags are used.  Object
12485 files need to be renamed just in case they would clash with object
12486 files compiled from the same sources, but with different flags.
12487 Consider the following example.
12488
12489 @example
12490 bin_PROGRAMS = true false
12491 true_SOURCES = generic.c
12492 true_CPPFLAGS = -DEXIT_CODE=0
12493 false_SOURCES = generic.c
12494 false_CPPFLAGS = -DEXIT_CODE=1
12495 @end example
12496
12497 @noindent
12498 Obviously the two programs are built from the same source, but it
12499 would be bad if they shared the same object, because @file{generic.o}
12500 cannot be built with both @samp{-DEXIT_CODE=0} @emph{and}
12501 @samp{-DEXIT_CODE=1}.  Therefore @command{automake} outputs rules to
12502 build two different objects: @file{true-generic.o} and
12503 @file{false-generic.o}.
12504
12505 @command{automake} doesn't actually look whether source files are
12506 shared to decide if it must rename objects.  It will just rename all
12507 objects of a target as soon as it sees per-target compilation flags
12508 used.
12509
12510 It's OK to share object files when per-target compilation flags are not
12511 used.  For instance, @file{true} and @file{false} will both use
12512 @file{version.o} in the following example.
12513
12514 @example
12515 AM_CPPFLAGS = -DVERSION=1.0
12516 bin_PROGRAMS = true false
12517 true_SOURCES = true.c version.c
12518 false_SOURCES = false.c version.c
12519 @end example
12520
12521 Note that the renaming of objects is also affected by the
12522 @code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
12523
12524
12525 @node Per-Object Flags
12526 @section Per-Object Flags Emulation
12527 @cindex Per-object flags, emulated
12528
12529 @display
12530 One of my source files needs to be compiled with different flags.  How
12531 do I do?
12532 @end display
12533
12534 Automake supports per-program and per-library compilation flags (see
12535 @ref{Program and Library Variables} and @ref{Flag Variables
12536 Ordering}).  With this you can define compilation flags that apply to
12537 all files compiled for a target.  For instance, in
12538
12539 @example
12540 bin_PROGRAMS = foo
12541 foo_SOURCES = foo.c foo.h bar.c bar.h main.c
12542 foo_CFLAGS = -some -flags
12543 @end example
12544
12545 @noindent
12546 @file{foo-foo.o}, @file{foo-bar.o}, and @file{foo-main.o} will all be
12547 compiled with @samp{-some -flags}.  (If you wonder about the names of
12548 these object files, see @ref{Renamed Objects}.)  Note that
12549 @code{foo_CFLAGS} gives the flags to use when compiling all the C
12550 sources of the @emph{program} @code{foo}, it has nothing to do with
12551 @file{foo.c} or @file{foo-foo.o} specifically.
12552
12553 What if @file{foo.c} needs to be compiled into @file{foo.o} using some
12554 specific flags, that none of the other files requires?  Obviously
12555 per-program flags are not directly applicable here.  Something like
12556 per-object flags are expected, i.e., flags that would be used only
12557 when creating @file{foo-foo.o}.  Automake does not support that,
12558 however this is easy to simulate using a library that contains only
12559 that object, and compiling this library with per-library flags.
12560
12561 @example
12562 bin_PROGRAMS = foo
12563 foo_SOURCES = bar.c bar.h main.c
12564 foo_CFLAGS = -some -flags
12565 foo_LDADD = libfoo.a
12566 noinst_LIBRARIES = libfoo.a
12567 libfoo_a_SOURCES = foo.c foo.h
12568 libfoo_a_CFLAGS = -some -other -flags
12569 @end example
12570
12571 Here @file{foo-bar.o} and @file{foo-main.o} will all be
12572 compiled with @samp{-some -flags}, while @file{libfoo_a-foo.o} will
12573 be compiled using @samp{-some -other -flags}.  Eventually, all
12574 three objects will be linked to form @file{foo}.
12575
12576 This trick can also be achieved using Libtool convenience libraries,
12577 for instance @samp{noinst_LTLIBRARIES = libfoo.la} (@pxref{Libtool
12578 Convenience Libraries}).
12579
12580 Another tempting idea to implement per-object flags is to override the
12581 compile rules @command{automake} would output for these files.
12582 Automake will not define a rule for a target you have defined, so you
12583 could think about defining the @samp{foo-foo.o: foo.c} rule yourself.
12584 We recommend against this, because this is error prone.  For instance,
12585 if you add such a rule to the first example, it will break the day you
12586 decide to remove @code{foo_CFLAGS} (because @file{foo.c} will then be
12587 compiled as @file{foo.o} instead of @file{foo-foo.o}, @pxref{Renamed
12588 Objects}).  Also in order to support dependency tracking, the two
12589 @file{.o}/@file{.obj} extensions, and all the other flags variables
12590 involved in a compilation, you will end up modifying a copy of the
12591 rule previously output by @command{automake} for this file.  If a new
12592 release of Automake generates a different rule, your copy will need to
12593 be updated by hand.
12594
12595 @node Multiple Outputs
12596 @section Handling Tools that Produce Many Outputs
12597 @cindex multiple outputs, rules with
12598 @cindex many outputs, rules with
12599 @cindex rules with multiple outputs
12600
12601 This section describes a @command{make} idiom that can be used when a
12602 tool produces multiple output files.  It is not specific to Automake
12603 and can be used in ordinary @file{Makefile}s.
12604
12605 Suppose we have a program called @command{foo} that will read one file
12606 called @file{data.foo} and produce two files named @file{data.c} and
12607 @file{data.h}.  We want to write a @file{Makefile} rule that captures
12608 this one-to-two dependency.
12609
12610 The naive rule is incorrect:
12611
12612 @example
12613 # This is incorrect.
12614 data.c data.h: data.foo
12615         foo data.foo
12616 @end example
12617
12618 @noindent
12619 What the above rule really says is that @file{data.c} and
12620 @file{data.h} each depend on @file{data.foo}, and can each be built by
12621 running @samp{foo data.foo}.  In other words it is equivalent to:
12622
12623 @example
12624 # We do not want this.
12625 data.c: data.foo
12626         foo data.foo
12627 data.h: data.foo
12628         foo data.foo
12629 @end example
12630
12631 @noindent
12632 which means that @command{foo} can be run twice.  Usually it will not
12633 be run twice, because @command{make} implementations are smart enough
12634 to check for the existence of the second file after the first one has
12635 been built; they will therefore detect that it already exists.
12636 However there are a few situations where it can run twice anyway:
12637
12638 @itemize
12639 @item
12640 The most worrying case is when running a parallel @command{make}.  If
12641 @file{data.c} and @file{data.h} are built in parallel, two @samp{foo
12642 data.foo} commands will run concurrently.  This is harmful.
12643 @item
12644 Another case is when the dependency (here @file{data.foo}) is
12645 (or depends upon) a phony target.
12646 @end itemize
12647
12648 A solution that works with parallel @command{make} but not with
12649 phony dependencies is the following:
12650
12651 @example
12652 data.c data.h: data.foo
12653         foo data.foo
12654 data.h: data.c
12655 @end example
12656
12657 @noindent
12658 The above rules are equivalent to
12659
12660 @example
12661 data.c: data.foo
12662         foo data.foo
12663 data.h: data.foo data.c
12664         foo data.foo
12665 @end example
12666
12667 @noindent
12668 therefore a parallel @command{make} will have to serialize the builds
12669 of @file{data.c} and @file{data.h}, and will detect that the second is
12670 no longer needed once the first is over.
12671
12672 Using this pattern is probably enough for most cases.  However it does
12673 not scale easily to more output files (in this scheme all output files
12674 must be totally ordered by the dependency relation), so we will
12675 explore a more complicated solution.
12676
12677 Another idea is to write the following:
12678
12679 @example
12680 # There is still a problem with this one.
12681 data.c: data.foo
12682         foo data.foo
12683 data.h: data.c
12684 @end example
12685
12686 @noindent
12687 The idea is that @samp{foo data.foo} is run only when @file{data.c}
12688 needs to be updated, but we further state that @file{data.h} depends
12689 upon @file{data.c}.  That way, if @file{data.h} is required and
12690 @file{data.foo} is out of date, the dependency on @file{data.c} will
12691 trigger the build.
12692
12693 This is almost perfect, but suppose we have built @file{data.h} and
12694 @file{data.c}, and then we erase @file{data.h}.  Then, running
12695 @samp{make data.h} will not rebuild @file{data.h}.  The above rules
12696 just state that @file{data.c} must be up-to-date with respect to
12697 @file{data.foo}, and this is already the case.
12698
12699 What we need is a rule that forces a rebuild when @file{data.h} is
12700 missing.  Here it is:
12701
12702 @example
12703 data.c: data.foo
12704         foo data.foo
12705 data.h: data.c
12706 ## Recover from the removal of $@@
12707         @@if test -f $@@; then :; else \
12708           rm -f data.c; \
12709           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12710         fi
12711 @end example
12712
12713 The above scheme can be extended to handle more outputs and more
12714 inputs.  One of the outputs is selected to serve as a witness to the
12715 successful completion of the command, it depends upon all inputs, and
12716 all other outputs depend upon it.  For instance, if @command{foo}
12717 should additionally read @file{data.bar} and also produce
12718 @file{data.w} and @file{data.x}, we would write:
12719
12720 @example
12721 data.c: data.foo data.bar
12722         foo data.foo data.bar
12723 data.h data.w data.x: data.c
12724 ## Recover from the removal of $@@
12725         @@if test -f $@@; then :; else \
12726           rm -f data.c; \
12727           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12728         fi
12729 @end example
12730
12731 However there are now three minor problems in this setup.  One is related
12732 to the timestamp ordering of @file{data.h}, @file{data.w},
12733 @file{data.x}, and @file{data.c}.  Another one is a race condition
12734 if a parallel @command{make} attempts to run multiple instances of the
12735 recover block at once.  Finally, the recursive rule breaks @samp{make -n}
12736 when run with GNU @command{make} (as well as some other @command{make}
12737 implementations), as it may remove @file{data.h} even when it should not
12738 (@pxref{MAKE Variable, , How the @code{MAKE} Variable Works, make,
12739 The GNU Make Manual}).
12740
12741 Let us deal with the first problem.  @command{foo} outputs four files,
12742 but we do not know in which order these files are created.  Suppose
12743 that @file{data.h} is created before @file{data.c}.  Then we have a
12744 weird situation.  The next time @command{make} is run, @file{data.h}
12745 will appear older than @file{data.c}, the second rule will be
12746 triggered, a shell will be started to execute the @samp{if@dots{}fi}
12747 command, but actually it will just execute the @code{then} branch,
12748 that is: nothing.  In other words, because the witness we selected is
12749 not the first file created by @command{foo}, @command{make} will start
12750 a shell to do nothing each time it is run.
12751
12752 A simple riposte is to fix the timestamps when this happens.
12753
12754 @example
12755 data.c: data.foo data.bar
12756         foo data.foo data.bar
12757 data.h data.w data.x: data.c
12758         @@if test -f $@@; then \
12759           touch $@@; \
12760         else \
12761 ## Recover from the removal of $@@
12762           rm -f data.c; \
12763           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12764         fi
12765 @end example
12766
12767 Another solution is to use a different and dedicated file as witness,
12768 rather than using any of @command{foo}'s outputs.
12769
12770 @example
12771 data.stamp: data.foo data.bar
12772         @@rm -f data.tmp
12773         @@touch data.tmp
12774         foo data.foo data.bar
12775         @@mv -f data.tmp $@@
12776 data.c data.h data.w data.x: data.stamp
12777 ## Recover from the removal of $@@
12778         @@if test -f $@@; then :; else \
12779           rm -f data.stamp; \
12780           $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
12781         fi
12782 @end example
12783
12784 @file{data.tmp} is created before @command{foo} is run, so it has a
12785 timestamp older than output files output by @command{foo}.  It is then
12786 renamed to @file{data.stamp} after @command{foo} has run, because we
12787 do not want to update @file{data.stamp} if @command{foo} fails.
12788
12789 This solution still suffers from the second problem: the race
12790 condition in the recover rule.  If, after a successful build, a user
12791 erases @file{data.c} and @file{data.h}, and runs @samp{make -j}, then
12792 @command{make} may start both recover rules in parallel.  If the two
12793 instances of the rule execute @samp{$(MAKE) $(AM_MAKEFLAGS)
12794 data.stamp} concurrently the build is likely to fail (for instance, the
12795 two rules will create @file{data.tmp}, but only one can rename it).
12796
12797 Admittedly, such a weird situation does not arise during ordinary
12798 builds.  It occurs only when the build tree is mutilated.  Here
12799 @file{data.c} and @file{data.h} have been explicitly removed without
12800 also removing @file{data.stamp} and the other output files.
12801 @code{make clean; make} will always recover from these situations even
12802 with parallel makes, so you may decide that the recover rule is solely
12803 to help non-parallel make users and leave things as-is.  Fixing this
12804 requires some locking mechanism to ensure only one instance of the
12805 recover rule rebuilds @file{data.stamp}.  One could imagine something
12806 along the following lines.
12807
12808 @example
12809 data.c data.h data.w data.x: data.stamp
12810 ## Recover from the removal of $@@
12811         @@if test -f $@@; then :; else \
12812           trap 'rm -rf data.lock data.stamp' 1 2 13 15; \
12813 ## mkdir is a portable test-and-set
12814           if mkdir data.lock 2>/dev/null; then \
12815 ## This code is being executed by the first process.
12816             rm -f data.stamp; \
12817             $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
12818             result=$$?; rm -rf data.lock; exit $$result; \
12819           else \
12820 ## This code is being executed by the follower processes.
12821 ## Wait until the first process is done.
12822             while test -d data.lock; do sleep 1; done; \
12823 ## Succeed if and only if the first process succeeded.
12824             test -f data.stamp; \
12825           fi; \
12826         fi
12827 @end example
12828
12829 Using a dedicated witness, like @file{data.stamp}, is very handy when
12830 the list of output files is not known beforehand.  As an illustration,
12831 consider the following rules to compile many @file{*.el} files into
12832 @file{*.elc} files in a single command.  It does not matter how
12833 @code{ELFILES} is defined (as long as it is not empty: empty targets
12834 are not accepted by POSIX).
12835
12836 @example
12837 ELFILES = one.el two.el three.el @dots{}
12838 ELCFILES = $(ELFILES:=c)
12839
12840 elc-stamp: $(ELFILES)
12841         @@rm -f elc-temp
12842         @@touch elc-temp
12843         $(elisp_comp) $(ELFILES)
12844         @@mv -f elc-temp $@@
12845
12846 $(ELCFILES): elc-stamp
12847         @@if test -f $@@; then :; else \
12848 ## Recover from the removal of $@@
12849           trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
12850           if mkdir elc-lock 2>/dev/null; then \
12851 ## This code is being executed by the first process.
12852             rm -f elc-stamp; \
12853             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
12854             rmdir elc-lock; \
12855           else \
12856 ## This code is being executed by the follower processes.
12857 ## Wait until the first process is done.
12858             while test -d elc-lock; do sleep 1; done; \
12859 ## Succeed if and only if the first process succeeded.
12860             test -f elc-stamp; exit $$?; \
12861 @c $$
12862           fi; \
12863         fi
12864 @end example
12865
12866 These solutions all still suffer from the third problem, namely that
12867 they break the promise that @samp{make -n} should not cause any actual
12868 changes to the tree.  For those solutions that do not create lock files,
12869 it is possible to split the recover rules into two separate recipe
12870 commands, one of which does all work but the recursion, and the
12871 other invokes the recursive @samp{$(MAKE)}.  The solutions involving
12872 locking could act upon the contents of the @samp{MAKEFLAGS} variable,
12873 but parsing that portably is not easy (@pxref{The Make Macro MAKEFLAGS,,,
12874 autoconf, The Autoconf Manual}).  Here is an example:
12875
12876 @example
12877 ELFILES = one.el two.el three.el @dots{}
12878 ELCFILES = $(ELFILES:=c)
12879
12880 elc-stamp: $(ELFILES)
12881         @@rm -f elc-temp
12882         @@touch elc-temp
12883         $(elisp_comp) $(ELFILES)
12884         @@mv -f elc-temp $@@
12885
12886 $(ELCFILES): elc-stamp
12887 ## Recover from the removal of $@@
12888         @@dry=; for f in x $$MAKEFLAGS; do \
12889           case $$f in \
12890             *=*|--*);; \
12891             *n*) dry=:;; \
12892           esac; \
12893         done; \
12894         if test -f $@@; then :; else \
12895           $$dry trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
12896           if $$dry mkdir elc-lock 2>/dev/null; then \
12897 ## This code is being executed by the first process.
12898             $$dry rm -f elc-stamp; \
12899             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
12900             $$dry rmdir elc-lock; \
12901           else \
12902 ## This code is being executed by the follower processes.
12903 ## Wait until the first process is done.
12904             while test -d elc-lock && test -z "$$dry"; do \
12905 @c $$
12906               sleep 1; \
12907             done; \
12908 ## Succeed if and only if the first process succeeded.
12909             $$dry test -f elc-stamp; exit $$?; \
12910           fi; \
12911         fi
12912 @end example
12913
12914 For completeness it should be noted that GNU @command{make} is able to
12915 express rules with multiple output files using pattern rules
12916 (@pxref{Pattern Examples, , Pattern Rule Examples, make, The GNU Make
12917 Manual}).  We do not discuss pattern rules here because they are not
12918 portable, but they can be convenient in packages that assume GNU
12919 @command{make}.
12920
12921
12922 @node Hard-Coded Install Paths
12923 @section Installing to Hard-Coded Locations
12924
12925 @display
12926 My package needs to install some configuration file.  I tried to use
12927 the following rule, but @samp{make distcheck} fails.  Why?
12928
12929 @example
12930 # Do not do this.
12931 install-data-local:
12932         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
12933 @end example
12934 @end display
12935
12936 @display
12937 My package needs to populate the installation directory of another
12938 package at install-time.  I can easily compute that installation
12939 directory in @file{configure}, but if I install files therein,
12940 @samp{make distcheck} fails.  How else should I do?
12941 @end display
12942
12943 These two setups share their symptoms: @samp{make distcheck} fails
12944 because they are installing files to hard-coded paths.  In the later
12945 case the path is not really hard-coded in the package, but we can
12946 consider it to be hard-coded in the system (or in whichever tool that
12947 supplies the path).  As long as the path does not use any of the
12948 standard directory variables (@samp{$(prefix)}, @samp{$(bindir)},
12949 @samp{$(datadir)}, etc.), the effect will be the same:
12950 user-installations are impossible.
12951
12952 As a (non-root) user who wants to install a package, you usually have no
12953 right to install anything in @file{/usr} or @file{/usr/local}.  So you
12954 do something like @samp{./configure --prefix ~/usr} to install a
12955 package in your own @file{~/usr} tree.
12956
12957 If a package attempts to install something to some hard-coded path
12958 (e.g., @file{/etc/afile}), regardless of this @option{--prefix} setting,
12959 then the installation will fail.  @samp{make distcheck} performs such
12960 a @option{--prefix} installation, hence it will fail too.
12961
12962 Now, there are some easy solutions.
12963
12964 The above @code{install-data-local} example for installing
12965 @file{/etc/afile} would be better replaced by
12966
12967 @example
12968 sysconf_DATA = afile
12969 @end example
12970
12971 @noindent
12972 by default @code{sysconfdir} will be @samp{$(prefix)/etc}, because
12973 this is what the GNU Standards require.  When such a package is
12974 installed on an FHS compliant system, the installer will have to set
12975 @samp{--sysconfdir=/etc}.  As the maintainer of the package you
12976 should not be concerned by such site policies: use the appropriate
12977 standard directory variable to install your files so that the installer
12978 can easily redefine these variables to match their site conventions.
12979
12980 Installing files that should be used by another package is slightly
12981 more involved.  Let's take an example and assume you want to install
12982 a shared library that is a Python extension module.  If you ask Python
12983 where to install the library, it will answer something like this:
12984
12985 @example
12986 % @kbd{python -c 'from distutils import sysconfig;
12987              print sysconfig.get_python_lib(1,0)'}
12988 /usr/lib/python2.5/site-packages
12989 @end example
12990
12991 If you indeed use this absolute path to install your shared library,
12992 non-root users will not be able to install the package, hence
12993 distcheck fails.
12994
12995 Let's do better.  The @samp{sysconfig.get_python_lib()} function
12996 actually accepts a third argument that will replace Python's
12997 installation prefix.
12998
12999 @example
13000 % @kbd{python -c 'from distutils import sysconfig;
13001              print sysconfig.get_python_lib(1,0,"$@{exec_prefix@}")'}
13002 $@{exec_prefix@}/lib/python2.5/site-packages
13003 @end example
13004
13005 You can also use this new path.  If you do
13006 @itemize @bullet
13007 @item
13008 root users can install your package with the same @option{--prefix}
13009 as Python (you get the behavior of the previous attempt)
13010
13011 @item
13012 non-root users can install your package too, they will have the
13013 extension module in a place that is not searched by Python but they
13014 can work around this using environment variables (and if you installed
13015 scripts that use this shared library, it's easy to tell Python were to
13016 look in the beginning of your script, so the script works in both
13017 cases).
13018 @end itemize
13019
13020 The @code{AM_PATH_PYTHON} macro uses similar commands to define
13021 @samp{$(pythondir)} and @samp{$(pyexecdir)} (@pxref{Python}).
13022
13023 Of course not all tools are as advanced as Python regarding that
13024 substitution of @var{prefix}.  So another strategy is to figure the
13025 part of the installation directory that must be preserved.  For
13026 instance, here is how @code{AM_PATH_LISPDIR} (@pxref{Emacs Lisp})
13027 computes @samp{$(lispdir)}:
13028
13029 @example
13030 $EMACS -batch -q -eval '(while load-path
13031   (princ (concat (car load-path) "\n"))
13032   (setq load-path (cdr load-path)))' >conftest.out
13033 lispdir=`sed -n
13034   -e 's,/$,,'
13035   -e '/.*\/lib\/x*emacs\/site-lisp$/@{
13036         s,.*/lib/\(x*emacs/site-lisp\)$,$@{libdir@}/\1,;p;q;
13037       @}'
13038   -e '/.*\/share\/x*emacs\/site-lisp$/@{
13039         s,.*/share/\(x*emacs/site-lisp\),$@{datarootdir@}/\1,;p;q;
13040       @}'
13041   conftest.out`
13042 @end example
13043
13044 I.e., it just picks the first directory that looks like
13045 @file{*/lib/*emacs/site-lisp} or @file{*/share/*emacs/site-lisp} in
13046 the search path of emacs, and then substitutes @samp{$@{libdir@}} or
13047 @samp{$@{datadir@}} appropriately.
13048
13049 The emacs case looks complicated because it processes a list and
13050 expects two possible layouts, otherwise it's easy, and the benefits for
13051 non-root users are really worth the extra @command{sed} invocation.
13052
13053
13054 @node Debugging Make Rules
13055 @section Debugging Make Rules
13056 @cindex debugging rules
13057 @cindex rules, debugging
13058
13059 The rules and dependency trees generated by @command{automake} can get
13060 rather complex, and leave the developer head-scratching when things
13061 don't work as expected.  Besides the debug options provided by the
13062 @command{make} command (@pxref{Options Summary,,, make, The GNU Make
13063 Manual}), here's a couple of further hints for debugging makefiles
13064 generated by @command{automake} effectively:
13065
13066 @itemize
13067 @item
13068 If less verbose output has been enabled in the package with the
13069 @samp{silent-rules} option (@pxref{Options}), you can use
13070 @code{make V=1} to see the commands being executed.
13071 @item
13072 @code{make -n} can help show what would be done without actually doing
13073 it.  Note however, that this will @emph{still execute} commands prefixed
13074 with @samp{+}, and, when using GNU @command{make}, commands that contain
13075 the strings @samp{$(MAKE)} or @samp{$@{MAKE@}} (@pxref{Instead of
13076 Execution,,, make, The GNU Make Manual}).
13077 Typically, this is helpful to show what recursive rules would do, but it
13078 means that, in your own rules, you should not mix such recursion with
13079 actions that change any files.@footnote{Automake's @samp{dist} and
13080 @samp{distcheck} rules had a bug in this regard in that they created
13081 directories even with @option{-n}, but this has been fixed in Automake
13082 1.11.}  Furthermore, note that GNU @command{make} will update
13083 prerequisites for the @file{Makefile} file itself even with @option{-n}
13084 (@pxref{Remaking Makefiles,,, make, The GNU Make Manual}).
13085 @item
13086 @code{make SHELL="/bin/bash -vx"} can help debug complex rules.
13087 @xref{The Make Macro SHELL,,, autoconf, The Autoconf Manual}, for some
13088 portability quirks associated with this construct.
13089 @item
13090 @code{echo 'print: ; @@echo "$(VAR)"' | make -f Makefile -f - print}
13091 can be handy to examine the expanded value of variables.  You may need
13092 to use a target other than @samp{print} if that is already used or a
13093 file with that name exists.
13094 @item
13095 @url{http://bashdb.sourceforge.net/@/remake/} provides a modified
13096 GNU @command{make} command called @command{remake} that copes with
13097 complex GNU @command{make}-specific Makefiles and allows to trace
13098 execution, examine variables, and call rules interactively, much like
13099 a debugger.
13100 @end itemize
13101
13102
13103 @node Reporting Bugs
13104 @section Reporting Bugs
13105
13106 Most nontrivial software has bugs.  Automake is no exception.  Although
13107 we cannot promise we can or will fix a bug, and we might not even agree
13108 that it is a bug, we want to hear about problems you encounter. Often we
13109 agree they are bugs and want to fix them.
13110
13111 To make it possible for us to fix a bug, please report it. In order to
13112 do so effectively, it helps to know when and how to do it.
13113
13114 Before reporting a bug, it is a good idea to see if it is already known.
13115 You can look at the @uref{http://debbugs.gnu.org/, GNU Bug Tracker}
13116 and the @uref{http://lists.gnu.org/@/archive/@/html/@/bug-automake/,
13117 bug-automake mailing list archives} for previous bug reports.  We
13118 previously used a
13119 @uref{http://sourceware.org/@/cgi-bin/@/gnatsweb.pl?database=automake,
13120 Gnats database} for bug tracking, so some bugs might have been reported
13121 there already.  Please do not use it for new bug reports, however.
13122
13123 If the bug is not already known, it should be reported.  It is very
13124 important to report bugs in a way that is useful and efficient.  For
13125 this, please familiarize yourself with
13126 @uref{http://www.chiark.greenend.org.uk/@/~sgtatham/@/bugs.html, How to
13127 Report Bugs Effectively} and
13128 @uref{http://catb.org/@/~esr/@/faqs/@/smart-questions.html, How to Ask
13129 Questions the Smart Way}.  This helps you and developers to save time
13130 which can then be spent on fixing more bugs and implementing more
13131 features.
13132
13133 For a bug report, a feature request or other suggestions, please send
13134 email to @email{@value{PACKAGE_BUGREPORT}}.  This will then open a new
13135 bug in the @uref{http://debbugs.gnu.org/@/automake, bug tracker}.  Be
13136 sure to include the versions of Autoconf and Automake that you use.
13137 Ideally, post a minimal @file{Makefile.am} and @file{configure.ac} that
13138 reproduces the problem you encounter.  If you have encountered test
13139 suite failures, please attach the @file{test-suite.log} file.
13140
13141 @c ========================================================== Appendices
13142
13143 @page
13144 @node Copying This Manual
13145 @appendix Copying This Manual
13146
13147 @menu
13148 * GNU Free Documentation License::  License for copying this manual
13149 @end menu
13150
13151 @node GNU Free Documentation License
13152 @appendixsec GNU Free Documentation License
13153 @include fdl.texi
13154
13155 @page
13156 @node Indices
13157 @appendix Indices
13158
13159 @menu
13160 * Macro Index::                 Index of Autoconf macros
13161 * Variable Index::              Index of Makefile variables
13162 * General Index::               General index
13163 @end menu
13164
13165 @node Macro Index
13166 @appendixsec Macro Index
13167
13168 @printindex fn
13169
13170 @node Variable Index
13171 @appendixsec Variable Index
13172
13173 @printindex vr
13174
13175 @node General Index
13176 @appendixsec General Index
13177
13178 @printindex cp
13179
13180
13181 @bye
13182
13183 @c  LocalWords:  texinfo setfilename settitle setchapternewpage texi direntry
13184 @c  LocalWords:  dircategory in's aclocal ifinfo titlepage Tromey vskip pt sp
13185 @c  LocalWords:  filll defcodeindex ov cv op tr syncodeindex fn cp vr ifnottex
13186 @c  LocalWords:  dir Automake's ac Dist Gnits gnits cygnus dfn Autoconf's pxref
13187 @c  LocalWords:  cindex Autoconf autoconf perl samp cvs dist trindex SUBST foo
13188 @c  LocalWords:  xs emph FIXME ref vindex pkglibdir pkgincludedir pkgdatadir mt
13189 @c  LocalWords:  pkg libdir cpio bindir sbindir rmt pax sbin zar zardir acindex
13190 @c  LocalWords:  HTML htmldir html noinst TEXINFOS nodist nobase strudel CFLAGS
13191 @c  LocalWords:  libmumble CC YFLAGS itemx de fication config url comp
13192 @c  LocalWords:  depcomp elisp sh mdate mkinstalldirs mkdir py tex dvi ps pdf
13193 @c  LocalWords:  ylwrap zardoz INIT gettext acinclude mv FUNCS LIBOBJS LDADD fr
13194 @c  LocalWords:  uref featureful dnl src LINGUAS es ko nl pl sl sv PROG ISC doc
13195 @c  LocalWords:  POSIX STDC fcntl FUNC ALLOCA blksize struct stat intl po chmod
13196 @c  LocalWords:  ChangeLog SUBDIRS gettextize gpl testdata getopt INTLLIBS cpp
13197 @c  LocalWords:  localedir datadir DLOCALEDIR DEXIT CPPFLAGS autoreconf opindex
13198 @c  LocalWords:  AUX var symlink deps Wno Wnone package's aclocal's distclean
13199 @c  LocalWords:  ltmain xref LIBSOURCE LIBSOURCES LIBOBJ MEMCMP vs RANLIB CXX
13200 @c  LocalWords:  LDFLAGS LIBTOOL libtool XTRA LIBS gettext's acdir APIVERSION
13201 @c  LocalWords:  dirlist noindent usr TIOCGWINSZ sc
13202 @c  LocalWords:  GWINSZ termios SRCDIR tarball bzip LISPDIR lispdir XEmacs CCAS
13203 @c  LocalWords:  emacsen MicroEmacs CCASFLAGS UX GCJ gcj GCJFLAGS posix DMALLOC
13204 @c  LocalWords:  dmalloc ldmalloc REGEX regex DEPDIR DEP DEFUN aclocaldir fi
13205 @c  LocalWords:  mymacro myothermacro AMFLAGS autopoint autogen libtoolize yum
13206 @c  LocalWords:  autoheader README MAKEFLAGS subdir Inetutils sync COND endif
13207 @c  LocalWords:  Miller's installable includedir inc pkgdata EXEEXT libexec bsd
13208 @c  LocalWords:  pkglib libexecdir prog libcpio cpio's dlopen dlpreopen linux
13209 @c  LocalWords:  subsubsection OBJEXT esac lib LTLIBRARIES liblob LIBADD AR ar
13210 @c  LocalWords:  ARFLAGS cru ing maude libgettext lo LTLIBOBJS rpath SGI PRE yy
13211 @c  LocalWords:  libmaude CCLD CXXFLAGS FFLAGS LFLAGS OBJCFLAGS RFLAGS DEFS cc
13212 @c  LocalWords:  OBJCXXFLAGS
13213 @c  LocalWords:  SHORTNAME vtable srcdir nostdinc basename yxx cxx ll lxx gdb
13214 @c  LocalWords:  lexers yymaxdepth maxdepth yyparse yylex yyerror yylval lval
13215 @c  LocalWords:  yychar yydebug yypact yyr yydef def yychk chk yypgo pgo yyact
13216 @c  LocalWords:  yyexca exca yyerrflag errflag yynerrs nerrs yyps yypv pv yys
13217 @c  LocalWords:  yystate yytmp tmp yyv yyval val yylloc lloc yyreds yytoks toks
13218 @c  LocalWords:  yylhs yylen yydefred yydgoto yysindex yyrindex yygindex yyname
13219 @c  LocalWords:  yytable yycheck yyrule byacc CXXCOMPILE CXXLINK FLINK cfortran
13220 @c  LocalWords:  Catalogue preprocessable FLIBS libfoo baz JAVACFLAGS java exe
13221 @c  LocalWords:  SunOS fying basenames exeext uninstalled oldinclude kr FSF's
13222 @c  LocalWords:  pkginclude oldincludedir sysconf sharedstate localstate gcc rm
13223 @c  LocalWords:  sysconfdir sharedstatedir localstatedir preexist CLEANFILES gz
13224 @c  LocalWords:  depfile tmpdepfile depmode const interoperate
13225 @c  LocalWords:  JAVAC javac JAVAROOT builddir CLASSPATH ENV pyc pyo pkgpython
13226 @c  LocalWords:  pyexecdir pkgpyexecdir Python's pythondir pkgpythondir txi ois
13227 @c  LocalWords:  installinfo vers MAKEINFO makeinfo MAKEINFOFLAGS noinstall rf
13228 @c  LocalWords:  mandir thesame alsothesame installman myexecbin DESTDIR Pinard
13229 @c  LocalWords:  uninstall installdirs uninstalls MOSTLYCLEANFILES mostlyclean
13230 @c  LocalWords:  DISTCLEANFILES MAINTAINERCLEANFILES GZIP gzip shar exp
13231 @c  LocalWords:  distdir distcheck distcleancheck listfiles distuninstallcheck
13232 @c  LocalWords:  VPATH tarfile stdout XFAIL DejaGnu dejagnu DEJATOOL runtest ln
13233 @c  LocalWords:  RUNTESTDEFAULTFLAGS toolchain RUNTESTFLAGS asis readme DVIPS
13234 @c  LocalWords:  installcheck gzipped tarZ std utils etags mkid cd
13235 @c  LocalWords:  ARGS taggable ETAGSFLAGS lang ctags CTAGSFLAGS GTAGS gtags idl
13236 @c  LocalWords:  foocc doit idlC multilibs ABIs cmindex defmac ARG enableval FC
13237 @c  LocalWords:  MSG xtrue DBG pathchk CYGWIN afile proglink versioned CVS's TE
13238 @c  LocalWords:  wildcards Autoconfiscated subsubheading autotools Meyering API
13239 @c  LocalWords:  ois's wildcard Wportability cartouche vrindex printindex Duret
13240 @c  LocalWords:  DSOMEFLAG DVERSION automake Lutz insertcopying versioning FAQ
13241 @c  LocalWords:  LTLIBOBJ Libtool's libtool's libltdl dlopening itutions libbar
13242 @c  LocalWords:  WANTEDLIBS libhello sublibraries libtop libsub dlopened Ratfor
13243 @c  LocalWords:  mymodule timestamps timestamp underquoted MAKEINFOHTMLFLAGS te
13244 @c  LocalWords:  GNUmakefile Subpackages subpackage's subpackages aux
13245 @c  LocalWords:  detailmenu Timeline pwd reldir AUTOM autom PREREQ FOOBAR libc
13246 @c  LocalWords:  libhand subpackage moduleN libmain libmisc FCFLAGS FCCOMPILE
13247 @c  LocalWords:  FCLINK subst sed ELCFILES elc MAKEINFOHTML dvips esyscmd ustar
13248 @c  LocalWords:  tarballs Woverride vfi ELFILES djm AutoMake honkin FSF
13249 @c  LocalWords:  fileutils precanned MacKenzie's reimplement termutils Tromey's
13250 @c  LocalWords:  cois gnitsians LIBPROGRAMS progs LIBLIBRARIES Textutils Ulrich
13251 @c  LocalWords:  Matzigkeit Drepper's Gord Matzigkeit's jm Dalley Debian org
13252 @c  LocalWords:  Administrivia ILU CORBA Sourceware Molenda sourceware Elliston
13253 @c  LocalWords:  dep Oliva Akim Demaille Aiieeee Demaillator Akim's sourcequake
13254 @c  LocalWords:  grep backported screenshots libgcj KB unnumberedsubsubsec pre
13255 @c  LocalWords:  precomputing hacky makedepend inline clearmake LD PRELOAD Rel
13256 @c  LocalWords:  syscalls perlhist acl pm multitable headitem fdl appendixsec
13257 @c  LocalWords:  LTALLOCA MALLOC malloc memcmp strdup alloca libcompat xyz DFOO
13258 @c  LocalWords:  unprefixed buildable preprocessed DBAZ DDATADIR WARNINGCFLAGS
13259 @c  LocalWords:  LIBFOOCFLAGS LIBFOOLDFLAGS ftable testSubDir obj LIBTOOLFLAGS
13260 @c  LocalWords:  barexec Pinard's automatize initialize lzip xz cscope