Merge branch 'maint'
[platform/upstream/automake.git] / doc / automake.texi
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename automake.info
4 @settitle automake
5 @setchapternewpage off
6 @c %**end of header
7
8 @include version.texi
9
10 @c @ovar(ARG, DEFAULT)
11 @c -------------------
12 @c The ARG is an optional argument.  To be used for macro arguments in
13 @c their documentation (@defmac).
14 @macro ovar{varname}
15 @r{[}@var{\varname\}@r{]}
16 @end macro
17
18 @set PACKAGE_BUGREPORT bug-automake@@gnu.org
19
20 @copying
21
22 This manual is for GNU Automake (version @value{VERSION},
23 @value{UPDATED}), a program that creates GNU standards-compliant
24 Makefiles from template files.
25
26 Copyright @copyright{} 1995-2012 Free Software Foundation, Inc.
27
28 @quotation
29 Permission is granted to copy, distribute and/or modify this document
30 under the terms of the GNU Free Documentation License,
31 Version 1.3 or any later version published by the Free Software
32 Foundation; with no Invariant Sections, with no Front-Cover texts,
33 and with no Back-Cover Texts.  A copy of the license is included in the
34 section entitled ``GNU Free Documentation License.''
35
36 @end quotation
37 @end copying
38
39 @dircategory Software development
40 @direntry
41 * Automake: (automake).         Making GNU standards-compliant Makefiles.
42 @end direntry
43
44 @dircategory Individual utilities
45 @direntry
46 * aclocal-invocation: (automake)aclocal Invocation.   Generating aclocal.m4.
47 * automake-invocation: (automake)automake Invocation. Generating Makefile.in.
48 @end direntry
49
50 @titlepage
51 @title GNU Automake
52 @subtitle For version @value{VERSION}, @value{UPDATED}
53 @author David MacKenzie
54 @author Tom Tromey
55 @author Alexandre Duret-Lutz
56 @page
57 @vskip 0pt plus 1filll
58 @insertcopying
59 @end titlepage
60
61 @contents
62
63 @c We use the following macros to define indices:
64 @c   @cindex   concepts, and anything that does not fit elsewhere
65 @c   @vindex   Makefile variables
66 @c   @trindex  targets
67 @c   @acindex  Autoconf/Automake/Libtool/M4/... macros
68 @c   @opindex  tool options
69
70 @c Define an index of configure macros.
71 @defcodeindex ac
72 @c Define an index of options.
73 @defcodeindex op
74 @c Define an index of targets.
75 @defcodeindex tr
76 @c Define an index of commands.
77 @defcodeindex cm
78
79 @c Put the macros in the function index.
80 @syncodeindex ac fn
81
82 @c Put everything else into one index (arbitrarily chosen to be the
83 @c concept index).
84 @syncodeindex op cp
85 @syncodeindex tr cp
86 @syncodeindex cm cp
87
88 @ifnottex
89 @node Top
90 @comment  node-name,  next,  previous,  up
91 @top GNU Automake
92
93 @insertcopying
94
95 @menu
96 * Introduction::                Automake's purpose
97 * Autotools Introduction::      An Introduction to the Autotools
98 * Generalities::                General ideas
99 * Examples::                    Some example packages
100 * automake Invocation::         Creating a Makefile.in
101 * configure::                   Scanning configure.ac, using aclocal
102 * Directories::                 Declaring subdirectories
103 * Programs::                    Building programs and libraries
104 * Other Objects::               Other derived objects
105 * Other GNU Tools::             Other GNU Tools
106 * Documentation::               Building documentation
107 * Install::                     What gets installed
108 * Clean::                       What gets cleaned
109 * Dist::                        What goes in a distribution
110 * Tests::                       Support for test suites
111 * Rebuilding::                  Automatic rebuilding of Makefile
112 * Options::                     Changing Automake's behavior
113 * Miscellaneous::               Miscellaneous rules
114 * Include::                     Including extra files in an Automake template
115 * Conditionals::                Conditionals
116 * Silencing Make::              Obtain less verbose output from @command{make}
117 * Gnits::                       The effect of @option{--gnu} and @option{--gnits}
118 * Not Enough::                  When Automake is not Enough
119 * Distributing::                Distributing the Makefile.in
120 * API Versioning::              About compatibility between Automake versions
121 * Upgrading::                   Upgrading to a Newer Automake Version
122 * FAQ::                         Frequently Asked Questions
123 * Copying This Manual::         How to make copies of this manual
124 * Indices::                     Indices of variables, macros, and concepts
125
126 @detailmenu
127  --- The Detailed Node Listing ---
128
129 An Introduction to the Autotools
130
131 * GNU Build System::            Introducing the GNU Build System
132 * Use Cases::                   Use Cases for the GNU Build System
133 * Why Autotools::               How Autotools Help
134 * Hello World::                 A Small Hello World Package
135
136 Use Cases for the GNU Build System
137
138 * Basic Installation::          Common installation procedure
139 * Standard Targets::            A list of standard Makefile targets
140 * Standard Directory Variables::  A list of standard directory variables
141 * Standard Configuration Variables::  Using configuration variables
142 * config.site::                 Using a config.site file
143 * VPATH Builds::                Parallel build trees
144 * Two-Part Install::            Installing data and programs separately
145 * Cross-Compilation::           Building for other architectures
146 * Renaming::                    Renaming programs at install time
147 * DESTDIR::                     Building binary packages with DESTDIR
148 * Preparing Distributions::     Rolling out tarballs
149 * Dependency Tracking::         Automatic dependency tracking
150 * Nested Packages::             The GNU Build Systems can be nested
151
152 A Small Hello World
153
154 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
155 * amhello's configure.ac Setup Explained::
156 * amhello's Makefile.am Setup Explained::
157
158 General ideas
159
160 * General Operation::           General operation of Automake
161 * Strictness::                  Standards conformance checking
162 * Uniform::                     The Uniform Naming Scheme
163 * Length Limitations::          Staying below the command line length limit
164 * Canonicalization::            How derived variables are named
165 * User Variables::              Variables reserved for the user
166 * Auxiliary Programs::          Programs automake might require
167
168 Some example packages
169
170 * Complete::                    A simple example, start to finish
171 * true::                        Building true and false
172
173 Scanning @file{configure.ac}, using @command{aclocal}
174
175 * Requirements::                Configuration requirements
176 * Optional::                    Other things Automake recognizes
177 * aclocal Invocation::          Auto-generating aclocal.m4
178 * Macros::                      Autoconf macros supplied with Automake
179
180 Auto-generating aclocal.m4
181
182 * aclocal Options::             Options supported by aclocal
183 * Macro Search Path::           How aclocal finds .m4 files
184 * Extending aclocal::           Writing your own aclocal macros
185 * Local Macros::                Organizing local macros
186 * Serials::                     Serial lines in Autoconf macros
187 * Future of aclocal::           aclocal's scheduled death
188
189 Autoconf macros supplied with Automake
190
191 * Public Macros::               Macros that you can use.
192 * Private Macros::              Macros that you should not use.
193
194 Directories
195
196 * Subdirectories::              Building subdirectories recursively
197 * Conditional Subdirectories::  Conditionally not building directories
198 * Alternative::                 Subdirectories without recursion
199 * Subpackages::                 Nesting packages
200
201 Conditional Subdirectories
202
203 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
204 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
205 * Subdirectories with AC_SUBST::  Another way for conditional recursion
206 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
207
208 Building Programs and Libraries
209
210 * A Program::                   Building a program
211 * A Library::                   Building a library
212 * A Shared Library::            Building a Libtool library
213 * Program and Library Variables::  Variables controlling program and
214                                 library builds
215 * Default _SOURCES::            Default source files
216 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
217 * Program Variables::           Variables used when building a program
218 * Yacc and Lex::                Yacc and Lex support
219 * C++ Support::                 Compiling C++ sources
220 * Objective C Support::         Compiling Objective C sources
221 * Objective C++ Support::       Compiling Objective C++ sources
222 * Unified Parallel C Support::  Compiling Unified Parallel C sources
223 * Assembly Support::            Compiling assembly sources
224 * Fortran 77 Support::          Compiling Fortran 77 sources
225 * Fortran 9x Support::          Compiling Fortran 9x sources
226 * Java Support with gcj::       Compiling Java sources using gcj
227 * Vala Support::                Compiling Vala sources
228 * Support for Other Languages::  Compiling other languages
229 * Dependencies::                Automatic dependency tracking
230 * EXEEXT::                      Support for executable extensions
231
232 Building a program
233
234 * Program Sources::             Defining program sources
235 * Linking::                     Linking with libraries or extra objects
236 * Conditional Sources::         Handling conditional sources
237 * Conditional Programs::        Building a program conditionally
238
239 Building a Shared Library
240
241 * Libtool Concept::             Introducing Libtool
242 * Libtool Libraries::           Declaring Libtool Libraries
243 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
244 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
245 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
246 * Libtool Modules::             Building Libtool Modules
247 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
248 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
249 * Libtool Issues::              Common Issues Related to Libtool's Use
250
251 Common Issues Related to Libtool's Use
252
253 * Error required file ltmain.sh not found::  The need to run libtoolize
254 * Objects created both with libtool and without::  Avoid a specific build race
255
256 Fortran 77 Support
257
258 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
259 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
260 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
261
262 Mixing Fortran 77 With C and C++
263
264 * How the Linker is Chosen::    Automatic linker selection
265
266 Fortran 9x Support
267
268 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
269
270 Other Derived Objects
271
272 * Scripts::                     Executable scripts
273 * Headers::                     Header files
274 * Data::                        Architecture-independent data files
275 * Sources::                     Derived sources
276
277 Built Sources
278
279 * Built Sources Example::       Several ways to handle built sources.
280
281 Other GNU Tools
282
283 * Emacs Lisp::                  Emacs Lisp
284 * gettext::                     Gettext
285 * Libtool::                     Libtool
286 * Java::                        Java bytecode compilation (deprecated)
287 * Python::                      Python
288
289 Building documentation
290
291 * Texinfo::                     Texinfo
292 * Man Pages::                   Man pages
293
294 What Gets Installed
295
296 * Basics of Installation::      What gets installed where
297 * The Two Parts of Install::    Installing data and programs separately
298 * Extending Installation::      Adding your own rules for installation
299 * Staged Installs::             Installation in a temporary location
300 * Install Rules for the User::  Useful additional rules
301
302 What Goes in a Distribution
303
304 * Basics of Distribution::      Files distributed by default
305 * Fine-grained Distribution Control::  @code{dist_} and @code{nodist_} prefixes
306 * The dist Hook::               A target for last-minute distribution changes
307 * Checking the Distribution::   @samp{make distcheck} explained
308 * The Types of Distributions::  A variety of formats and compression methods
309
310 Support for test suites
311
312 * Generalities about Testing::  Generic concepts and terminology about testing
313 * Simple Tests::                Listing test scripts in @code{TESTS}
314 * Custom Test Drivers::         Writing and using custom test drivers
315 * Using the TAP test protocol:: Integrating test scripts that use the TAP protocol
316 * DejaGnu Tests::               Interfacing with the @command{dejagnu} testing framework
317 * Install Tests::               Running tests on installed packages
318
319 Simple Tests
320
321 * Scripts-based Testsuites::    Automake-specific concepts and terminology
322 * Serial Test Harness::         Older (and obsolescent) serial test harness
323 * Parallel Test Harness::       Generic concurrent test harness
324
325 Using the TAP test protocol
326
327 * Introduction to TAP::
328 * Use TAP with the Automake test harness::
329 * Incompatibilities with other TAP parsers and drivers::
330 * Links and external resources on TAP::
331
332 Custom Test Drivers
333
334 * Overview of Custom Test Drivers Support::
335 * Declaring Custom Test Drivers::
336 * API for Custom Test Drivers::
337
338 API for Custom Test Drivers
339
340 * Command-line arguments for test drivers::
341 * Log files generation and test results recording::
342 * Testsuite progress output::
343
344 Changing Automake's Behavior
345
346 * Options generalities::        Semantics of Automake option
347 * List of Automake options::    A comprehensive list of Automake options
348
349 Miscellaneous Rules
350
351 * Tags::                        Interfacing to cscope, etags and mkid
352 * Suffixes::                    Handling new file extensions
353
354 Conditionals
355
356 * Usage of Conditionals::       Declaring conditional content
357 * Limits of Conditionals::      Enclosing complete statements
358
359 Silencing Make
360
361 * Make verbosity::              Make is verbose by default
362 * Tricks For Silencing Make::   Standard and generic ways to silence make
363 * Automake Silent Rules::       How Automake can help in silencing make
364
365 When Automake Isn't Enough
366
367 * Extending::                   Adding new rules or overriding existing ones.
368 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
369
370 Frequently Asked Questions about Automake
371
372 * CVS::                         CVS and generated files
373 * maintainer-mode::             missing and AM_MAINTAINER_MODE
374 * Wildcards::                   Why doesn't Automake support wildcards?
375 * Limitations on File Names::   Limitations on source and installed file names
376 * Errors with distclean::       Files left in build directory after distclean
377 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
378 * Renamed Objects::             Why are object files sometimes renamed?
379 * Per-Object Flags::            How to simulate per-object flags?
380 * Multiple Outputs::            Writing rules for tools with many output files
381 * Hard-Coded Install Paths::    Installing to hard-coded locations
382 * Debugging Make Rules::        Strategies when things don't work as expected
383 * Reporting Bugs::              Feedback on bugs and feature requests
384
385 Copying This Manual
386
387 * GNU Free Documentation License::  License for copying this manual
388
389 Indices
390
391 * Macro Index::                 Index of Autoconf macros
392 * Variable Index::              Index of Makefile variables
393 * General Index::               General index
394
395 @end detailmenu
396 @end menu
397
398 @end ifnottex
399
400
401 @node Introduction
402 @chapter Introduction
403
404 Automake is a tool for automatically generating @file{Makefile.in}s
405 from files called @file{Makefile.am}.  Each @file{Makefile.am} is
406 basically a series of @command{make} variable
407 definitions@footnote{These variables are also called @dfn{make macros}
408 in Make terminology, however in this manual we reserve the term
409 @dfn{macro} for Autoconf's macros.}, with rules being thrown in
410 occasionally.  The generated @file{Makefile.in}s are compliant with
411 the GNU Makefile standards.
412
413 @cindex GNU Makefile standards
414
415 The GNU Makefile Standards Document
416 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
417 is long, complicated, and subject to change.  The goal of Automake is to
418 remove the burden of Makefile maintenance from the back of the
419 individual GNU maintainer (and put it on the back of the Automake
420 maintainers).
421
422 The typical Automake input file is simply a series of variable definitions.
423 Each such file is processed to create a @file{Makefile.in}.
424
425 @cindex Constraints of Automake
426 @cindex Automake constraints
427
428 Automake does constrain a project in certain ways; for instance, it
429 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
430 autoconf, The Autoconf Manual}), and enforces certain restrictions on
431 the @file{configure.ac} contents.
432
433 @cindex Automake requirements
434 @cindex Requirements, Automake
435
436 Automake requires @command{perl} in order to generate the
437 @file{Makefile.in}s.  However, the distributions created by Automake are
438 fully GNU standards-compliant, and do not require @command{perl} in order
439 to be built.
440
441 @cindex Bugs, reporting
442 @cindex Reporting bugs
443 @cindex E-mail, bug reports
444
445 For more information on bug reports, @xref{Reporting Bugs}.
446
447 @node Autotools Introduction
448 @chapter An Introduction to the Autotools
449
450 If you are new to Automake, maybe you know that it is part of a set of
451 tools called @emph{The Autotools}.  Maybe you've already delved into a
452 package full of files named @file{configure}, @file{configure.ac},
453 @file{Makefile.in}, @file{Makefile.am}, @file{aclocal.m4}, @dots{},
454 some of them claiming to be @emph{generated by} Autoconf or Automake.
455 But the exact purpose of these files and their relations is probably
456 fuzzy.  The goal of this chapter is to introduce you to this machinery,
457 to show you how it works and how powerful it is.  If you've never
458 installed or seen such a package, do not worry: this chapter will walk
459 you through it.
460
461 If you need some teaching material, more illustrations, or a less
462 @command{automake}-centered continuation, some slides for this
463 introduction are available in Alexandre Duret-Lutz's
464 @uref{http://www.lrde.epita.fr/@/~adl/@/autotools.html,
465 Autotools Tutorial}.
466 This chapter is the written version of the first part of his tutorial.
467
468 @menu
469 * GNU Build System::            Introducing the GNU Build System
470 * Use Cases::                   Use Cases for the GNU Build System
471 * Why Autotools::               How Autotools Help
472 * Hello World::                 A Small Hello World Package
473 @end menu
474
475 @node GNU Build System
476 @section Introducing the GNU Build System
477 @cindex GNU Build System, introduction
478
479 It is a truth universally acknowledged, that as a developer in
480 possession of a new package, you must be in want of a build system.
481
482 In the Unix world, such a build system is traditionally achieved using
483 the command @command{make} (@pxref{Top, , Overview, make, The GNU Make
484 Manual}).  You express the recipe to build your package in a
485 @file{Makefile}.  This file is a set of rules to build the files in
486 the package.  For instance the program @file{prog} may be built by
487 running the linker on the files @file{main.o}, @file{foo.o}, and
488 @file{bar.o}; the file @file{main.o} may be built by running the
489 compiler on @file{main.c}; etc.  Each time @command{make} is run, it
490 reads @file{Makefile}, checks the existence and modification time of
491 the files mentioned, decides what files need to be built (or rebuilt),
492 and runs the associated commands.
493
494 When a package needs to be built on a different platform than the one
495 it was developed on, its @file{Makefile} usually needs to be adjusted.
496 For instance the compiler may have another name or require more
497 options.  In 1991, David J. MacKenzie got tired of customizing
498 @file{Makefile} for the 20 platforms he had to deal with.  Instead, he
499 handcrafted a little shell script called @file{configure} to
500 automatically adjust the @file{Makefile} (@pxref{Genesis, , Genesis,
501 autoconf, The Autoconf Manual}).  Compiling his package was now
502 as simple as running @code{./configure && make}.
503
504 @cindex GNU Coding Standards
505
506 Today this process has been standardized in the GNU project.  The GNU
507 Coding Standards (@pxref{Managing Releases, The Release Process, ,
508 standards, The GNU Coding Standards}) explains how each package of the
509 GNU project should have a @file{configure} script, and the minimal
510 interface it should have.  The @file{Makefile} too should follow some
511 established conventions.  The result?  A unified build system that
512 makes all packages almost indistinguishable by the installer.  In its
513 simplest scenario, all the installer has to do is to unpack the
514 package, run @code{./configure && make && make install}, and repeat
515 with the next package to install.
516
517 We call this build system the @dfn{GNU Build System}, since it was
518 grown out of the GNU project.  However it is used by a vast number of
519 other packages: following any existing convention has its advantages.
520
521 @cindex Autotools, introduction
522
523 The Autotools are tools that will create a GNU Build System for your
524 package.  Autoconf mostly focuses on @file{configure} and Automake on
525 @file{Makefile}s.  It is entirely possible to create a GNU Build
526 System without the help of these tools.  However it is rather
527 burdensome and error-prone.  We will discuss this again after some
528 illustration of the GNU Build System in action.
529
530 @node Use Cases
531 @section Use Cases for the GNU Build System
532 @cindex GNU Build System, use cases
533 @cindex GNU Build System, features
534 @cindex Features of the GNU Build System
535 @cindex Use Cases for the GNU Build System
536 @cindex @file{amhello-1.0.tar.gz}, location
537 @cindex @file{amhello-1.0.tar.gz}, use cases
538
539 In this section we explore several use cases for the GNU Build System.
540 You can replay all of these examples on the @file{amhello-1.0.tar.gz}
541 package distributed with Automake.  If Automake is installed on your
542 system, you should find a copy of this file in
543 @file{@var{prefix}/share/doc/automake/amhello-1.0.tar.gz}, where
544 @var{prefix} is the installation prefix specified during configuration
545 (@var{prefix} defaults to @file{/usr/local}, however if Automake was
546 installed by some GNU/Linux distribution it most likely has been set
547 to @file{/usr}).  If you do not have a copy of Automake installed,
548 you can find a copy of this file inside the @file{doc/} directory of
549 the Automake package.
550
551 Some of the following use cases present features that are in fact
552 extensions to the GNU Build System.  Read: they are not specified by
553 the GNU Coding Standards, but they are nonetheless part of the build
554 system created by the Autotools.  To keep things simple, we do not
555 point out the difference.  Our objective is to show you many of the
556 features that the build system created by the Autotools will offer to
557 you.
558
559 @menu
560 * Basic Installation::          Common installation procedure
561 * Standard Targets::            A list of standard Makefile targets
562 * Standard Directory Variables::  A list of standard directory variables
563 * Standard Configuration Variables::  Using configuration variables
564 * config.site::                 Using a config.site file
565 * VPATH Builds::                Parallel build trees
566 * Two-Part Install::            Installing data and programs separately
567 * Cross-Compilation::           Building for other architectures
568 * Renaming::                    Renaming programs at install time
569 * DESTDIR::                     Building binary packages with DESTDIR
570 * Preparing Distributions::     Rolling out tarballs
571 * Dependency Tracking::         Automatic dependency tracking
572 * Nested Packages::             The GNU Build Systems can be nested
573 @end menu
574
575 @node Basic Installation
576 @subsection Basic Installation
577 @cindex Configuration, basics
578 @cindex Installation, basics
579 @cindex GNU Build System, basics
580
581 The most common installation procedure looks as follows.
582
583 @example
584 ~ % @kbd{tar zxf amhello-1.0.tar.gz}
585 ~ % @kbd{cd amhello-1.0}
586 ~/amhello-1.0 % @kbd{./configure}
587 @dots{}
588 config.status: creating Makefile
589 config.status: creating src/Makefile
590 @dots{}
591 ~/amhello-1.0 % @kbd{make}
592 @dots{}
593 ~/amhello-1.0 % @kbd{make check}
594 @dots{}
595 ~/amhello-1.0 % @kbd{su}
596 Password:
597 /home/adl/amhello-1.0 # @kbd{make install}
598 @dots{}
599 /home/adl/amhello-1.0 # @kbd{exit}
600 ~/amhello-1.0 % @kbd{make installcheck}
601 @dots{}
602 @end example
603
604 @cindex Unpacking
605
606 The user first unpacks the package.  Here, and in the following
607 examples, we will use the non-portable @code{tar zxf} command for
608 simplicity.  On a system without GNU @command{tar} installed, this
609 command should read @code{gunzip -c amhello-1.0.tar.gz | tar xf -}.
610
611 The user then enters the newly created directory to run the
612 @file{configure} script.  This script probes the system for various
613 features, and finally creates the @file{Makefile}s.  In this toy
614 example there are only two @file{Makefile}s, but in real-world projects,
615 there may be many more, usually one @file{Makefile} per directory.
616
617 It is now possible to run @code{make}.  This will construct all the
618 programs, libraries, and scripts that need to be constructed for the
619 package.  In our example, this compiles the @file{hello} program.
620 All files are constructed in place, in the source tree; we will see
621 later how this can be changed.
622
623 @code{make check} causes the package's tests to be run.  This step is
624 not mandatory, but it is often good to make sure the programs that
625 have been built behave as they should, before you decide to install
626 them.  Our example does not contain any tests, so running @code{make
627 check} is a no-op.
628
629 @cindex su, before @code{make install}
630 After everything has been built, and maybe tested, it is time to
631 install it on the system.  That means copying the programs,
632 libraries, header files, scripts, and other data files from the
633 source directory to their final destination on the system.  The
634 command @code{make install} will do that.  However, by default
635 everything will be installed in subdirectories of @file{/usr/local}:
636 binaries will go into @file{/usr/local/bin}, libraries will end up in
637 @file{/usr/local/lib}, etc.  This destination is usually not writable
638 by any user, so we assume that we have to become root before we can
639 run @code{make install}.  In our example, running @code{make install}
640 will copy the program @file{hello} into @file{/usr/local/bin}
641 and @file{README} into @file{/usr/local/share/doc/amhello}.
642
643 A last and optional step is to run @code{make installcheck}.  This
644 command may run tests on the installed files.  @code{make check} tests
645 the files in the source tree, while @code{make installcheck} tests
646 their installed copies.  The tests run by the latter can be different
647 from those run by the former.  For instance, there are tests that
648 cannot be run in the source tree.  Conversely, some packages are set
649 up so that @code{make installcheck} will run the very same tests as
650 @code{make check}, only on different files (non-installed
651 vs.@: installed).  It can make a difference, for instance when the
652 source tree's layout is different from that of the installation.
653 Furthermore it may help to diagnose an incomplete installation.
654
655 Presently most packages do not have any @code{installcheck} tests
656 because the existence of @code{installcheck} is little known, and its
657 usefulness is neglected.  Our little toy package is no better: @code{make
658 installcheck} does nothing.
659
660 @node Standard Targets
661 @subsection Standard @file{Makefile} Targets
662
663 So far we have come across four ways to run @command{make} in the GNU
664 Build System: @code{make}, @code{make check}, @code{make install}, and
665 @code{make installcheck}.  The words @code{check}, @code{install}, and
666 @code{installcheck}, passed as arguments to @command{make}, are called
667 @dfn{targets}.  @code{make} is a shorthand for @code{make all},
668 @code{all} being the default target in the GNU Build System.
669
670 Here is a list of the most useful targets that the GNU Coding Standards
671 specify.
672
673 @table @code
674 @item make all
675 @trindex all
676 Build programs, libraries, documentation, etc.@: (same as @code{make}).
677 @item make install
678 @trindex install
679 Install what needs to be installed, copying the files from the
680 package's tree to system-wide directories.
681 @item make install-strip
682 @trindex install-strip
683 Same as @code{make install}, then strip debugging symbols.  Some
684 users like to trade space for useful bug reports@enddots{}
685 @item make uninstall
686 @trindex uninstall
687 The opposite of @code{make install}: erase the installed files.
688 (This needs to be run from the same build tree that was installed.)
689 @item make clean
690 @trindex clean
691 Erase from the build tree the files built by @code{make all}.
692 @item make distclean
693 @trindex distclean
694 Additionally erase anything @code{./configure} created.
695 @item make check
696 @trindex check
697 Run the test suite, if any.
698 @item make installcheck
699 @trindex installcheck
700 Check the installed programs or libraries, if supported.
701 @item make dist
702 @trindex dist
703 Recreate @file{@var{package}-@var{version}.tar.gz} from all the source
704 files.
705 @end table
706
707 @node Standard Directory Variables
708 @subsection Standard Directory Variables
709 @cindex directory variables
710
711 The GNU Coding Standards also specify a hierarchy of variables to
712 denote installation directories.  Some of these are:
713
714 @multitable {Directory variable} {@code{$@{datarootdir@}/doc/$@{PACKAGE@}}}
715 @headitem Directory variable    @tab Default value
716 @item @code{prefix}              @tab @code{/usr/local}
717 @item @w{@ @ @code{exec_prefix}} @tab @code{$@{prefix@}}
718 @item @w{@ @ @ @ @code{bindir}}  @tab @code{$@{exec_prefix@}/bin}
719 @item @w{@ @ @ @ @code{libdir}}  @tab @code{$@{exec_prefix@}/lib}
720 @item @w{@ @ @ @ @dots{}}
721 @item @w{@ @ @code{includedir}}  @tab @code{$@{prefix@}/include}
722 @item @w{@ @ @code{datarootdir}} @tab @code{$@{prefix@}/share}
723 @item @w{@ @ @ @ @code{datadir}} @tab @code{$@{datarootdir@}}
724 @item @w{@ @ @ @ @code{mandir}}  @tab @code{$@{datarootdir@}/man}
725 @item @w{@ @ @ @ @code{infodir}} @tab @code{$@{datarootdir@}/info}
726 @item @w{@ @ @ @ @code{docdir}}  @tab @code{$@{datarootdir@}/doc/$@{PACKAGE@}}
727 @item @w{@ @ @dots{}}
728 @end multitable
729
730 @c We should provide a complete table somewhere, but not here.  The
731 @c complete list of directory variables it too confusing as-is.  It
732 @c requires some explanations that are too complicated for this
733 @c introduction.  Besides listing directories like localstatedir
734 @c would make the explanations in ``Two-Part Install'' harder.
735
736 Each of these directories has a role which is often obvious from its
737 name.  In a package, any installable file will be installed in one of
738 these directories.  For instance in @code{amhello-1.0}, the program
739 @file{hello} is to be installed in @var{bindir}, the directory for
740 binaries.  The default value for this directory is
741 @file{/usr/local/bin}, but the user can supply a different value when
742 calling @command{configure}.  Also the file @file{README} will be
743 installed into @var{docdir}, which defaults to
744 @file{/usr/local/share/doc/amhello}.
745
746 @opindex --prefix
747
748 As a user, if you wish to install a package on your own account, you
749 could proceed as follows:
750
751 @example
752 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
753 @dots{}
754 ~/amhello-1.0 % @kbd{make}
755 @dots{}
756 ~/amhello-1.0 % @kbd{make install}
757 @dots{}
758 @end example
759
760 This would install @file{~/usr/bin/hello} and
761 @file{~/usr/share/doc/amhello/README}.
762
763 The list of all such directory options is shown by
764 @code{./configure --help}.
765
766 @node Standard Configuration Variables
767 @subsection Standard Configuration Variables
768 @cindex configuration variables, overriding
769
770 The GNU Coding Standards also define a set of standard configuration
771 variables used during the build.  Here are some:
772
773 @table @asis
774 @item @code{CC}
775 C compiler command
776 @item @code{CFLAGS}
777 C compiler flags
778 @item @code{CXX}
779 C++ compiler command
780 @item @code{CXXFLAGS}
781 C++ compiler flags
782 @item @code{LDFLAGS}
783 linker flags
784 @item @code{CPPFLAGS}
785 C/C++ preprocessor flags
786 @item @dots{}
787 @end table
788
789 @command{configure} usually does a good job at setting appropriate
790 values for these variables, but there are cases where you may want to
791 override them.  For instance you may have several versions of a
792 compiler installed and would like to use another one, you may have
793 header files installed outside the default search path of the
794 compiler, or even libraries out of the way of the linker.
795
796 Here is how one would call @command{configure} to force it to use
797 @command{gcc-3} as C compiler, use header files from
798 @file{~/usr/include} when compiling, and libraries from
799 @file{~/usr/lib} when linking.
800
801 @example
802 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
803 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
804 @end example
805
806 Again, a full list of these variables appears in the output of
807 @code{./configure --help}.
808
809 @node config.site
810 @subsection Overriding Default Configuration Setting with @file{config.site}
811 @cindex @file{config.site} example
812
813 When installing several packages using the same setup, it can be
814 convenient to create a file to capture common settings.
815 If a file named @file{@var{prefix}/share/config.site} exists,
816 @command{configure} will source it at the beginning of its execution.
817
818 Recall the command from the previous section:
819
820 @example
821 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
822 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
823 @end example
824
825 Assuming we are installing many package in @file{~/usr}, and will
826 always want to use these definitions of @code{CC}, @code{CPPFLAGS}, and
827 @code{LDFLAGS}, we can automate this by creating the following
828 @file{~/usr/share/config.site} file:
829
830 @example
831 test -z "$CC" && CC=gcc-3
832 test -z "$CPPFLAGS" && CPPFLAGS=-I$HOME/usr/include
833 test -z "$LDFLAGS" && LDFLAGS=-L$HOME/usr/lib
834 @end example
835
836 Now, any time a @file{configure} script is using the @file{~/usr}
837 prefix, it will execute the above @file{config.site} and define
838 these three variables.
839
840 @example
841 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
842 configure: loading site script /home/adl/usr/share/config.site
843 @dots{}
844 @end example
845
846 @xref{Site Defaults, , Setting Site Defaults, autoconf, The Autoconf
847 Manual}, for more information about this feature.
848
849
850 @node VPATH Builds
851 @subsection Parallel Build Trees (a.k.a.@: VPATH Builds)
852 @cindex Parallel build trees
853 @cindex VPATH builds
854 @cindex source tree and build tree
855 @cindex build tree and source tree
856 @cindex trees, source vs.@: build
857
858 The GNU Build System distinguishes two trees: the source tree, and
859 the build tree.
860
861 The source tree is rooted in the directory containing
862 @file{configure}.  It contains all the sources files (those that are
863 distributed), and may be arranged using several subdirectories.
864
865 The build tree is rooted in the directory in which @file{configure}
866 was run, and is populated with all object files, programs, libraries,
867 and other derived files built from the sources (and hence not
868 distributed).  The build tree usually has the same subdirectory layout
869 as the source tree; its subdirectories are created automatically by
870 the build system.
871
872 If @file{configure} is executed in its own directory, the source and
873 build trees are combined: derived files are constructed in the same
874 directories as their sources.  This was the case in our first
875 installation example (@pxref{Basic Installation}).
876
877 A common request from users is that they want to confine all derived
878 files to a single directory, to keep their source directories
879 uncluttered.  Here is how we could run @file{configure} to build
880 everything in a subdirectory called @file{build/}.
881
882 @example
883 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
884 ~ % @kbd{cd amhello-1.0}
885 ~/amhello-1.0 % @kbd{mkdir build && cd build}
886 ~/amhello-1.0/build % @kbd{../configure}
887 @dots{}
888 ~/amhello-1.0/build % @kbd{make}
889 @dots{}
890 @end example
891
892 These setups, where source and build trees are different, are often
893 called @dfn{parallel builds} or @dfn{VPATH builds}.  The expression
894 @emph{parallel build} is misleading: the word @emph{parallel} is a
895 reference to the way the build tree shadows the source tree, it is not
896 about some concurrency in the way build commands are run.  For this
897 reason we refer to such setups using the name @emph{VPATH builds} in
898 the following.  @emph{VPATH} is the name of the @command{make} feature
899 used by the @file{Makefile}s to allow these builds (@pxref{General
900 Search, , @code{VPATH} Search Path for All Prerequisites, make, The
901 GNU Make Manual}).
902
903 @cindex multiple configurations, example
904 @cindex debug build, example
905 @cindex optimized build, example
906
907 VPATH builds have other interesting uses.  One is to build the same
908 sources with multiple configurations.  For instance:
909
910 @c Keep in sync with amhello-cflags.sh
911 @example
912 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
913 ~ % @kbd{cd amhello-1.0}
914 ~/amhello-1.0 % @kbd{mkdir debug optim && cd debug}
915 ~/amhello-1.0/debug % @kbd{../configure CFLAGS='-g -O0'}
916 @dots{}
917 ~/amhello-1.0/debug % @kbd{make}
918 @dots{}
919 ~/amhello-1.0/debug % cd ../optim
920 ~/amhello-1.0/optim % @kbd{../configure CFLAGS='-O3 -fomit-frame-pointer'}
921 @dots{}
922 ~/amhello-1.0/optim % @kbd{make}
923 @dots{}
924 @end example
925
926 With network file systems, a similar approach can be used to build the
927 same sources on different machines.  For instance, suppose that the
928 sources are installed on a directory shared by two hosts: @code{HOST1}
929 and @code{HOST2}, which may be different platforms.
930
931 @example
932 ~ % @kbd{cd /nfs/src}
933 /nfs/src % @kbd{tar zxf ~/amhello-1.0.tar.gz}
934 @end example
935
936 On the first host, you could create a local build directory:
937 @example
938 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
939 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
940 ...
941 [HOST1] /tmp/amh % @kbd{make && sudo make install}
942 ...
943 @end example
944
945 @noindent
946 (Here we assume that the installer has configured @command{sudo} so it
947 can execute @code{make install} with root privileges; it is more convenient
948 than using @command{su} like in @ref{Basic Installation}).
949
950 On the second host, you would do exactly the same, possibly at
951 the same time:
952 @example
953 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
954 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
955 ...
956 [HOST2] /tmp/amh % @kbd{make && sudo make install}
957 ...
958 @end example
959
960 @cindex read-only source tree
961 @cindex source tree, read-only
962
963 In this scenario, nothing forbids the @file{/nfs/src/amhello-1.0}
964 directory from being read-only.  In fact VPATH builds are also a means
965 of building packages from a read-only medium such as a CD-ROM.  (The
966 FSF used to sell CD-ROM with unpacked source code, before the GNU
967 project grew so big.)
968
969 @node Two-Part Install
970 @subsection Two-Part Installation
971
972 In our last example (@pxref{VPATH Builds}), a source tree was shared
973 by two hosts, but compilation and installation were done separately on
974 each host.
975
976 The GNU Build System also supports networked setups where part of the
977 installed files should be shared amongst multiple hosts.  It does so
978 by distinguishing architecture-dependent files from
979 architecture-independent files, and providing two @file{Makefile}
980 targets to install each of these classes of files.
981
982 @trindex install-exec
983 @trindex install-data
984
985 These targets are @code{install-exec} for architecture-dependent files
986 and @code{install-data} for architecture-independent files.
987 The command we used up to now, @code{make install}, can be thought of
988 as a shorthand for @code{make install-exec install-data}.
989
990 From the GNU Build System point of view, the distinction between
991 architecture-dependent files and architecture-independent files is
992 based exclusively on the directory variable used to specify their
993 installation destination.  In the list of directory variables we
994 provided earlier (@pxref{Standard Directory Variables}), all the
995 variables based on @var{exec-prefix} designate architecture-dependent
996 directories whose files will be installed by @code{make install-exec}.
997 The others designate architecture-independent directories and will
998 serve files installed by @code{make install-data}.  @xref{The Two Parts
999 of Install}, for more details.
1000
1001 Here is how we could revisit our two-host installation example,
1002 assuming that (1) we want to install the package directly in
1003 @file{/usr}, and (2) the directory @file{/usr/share} is shared by the
1004 two hosts.
1005
1006 On the first host we would run
1007 @example
1008 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1009 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1010 ...
1011 [HOST1] /tmp/amh % @kbd{make && sudo make install}
1012 ...
1013 @end example
1014
1015 On the second host, however, we need only install the
1016 architecture-specific files.
1017 @example
1018 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1019 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1020 ...
1021 [HOST2] /tmp/amh % @kbd{make && sudo make install-exec}
1022 ...
1023 @end example
1024
1025 In packages that have installation checks, it would make sense to run
1026 @code{make installcheck} (@pxref{Basic Installation}) to verify that
1027 the package works correctly despite the apparent partial installation.
1028
1029 @node Cross-Compilation
1030 @subsection Cross-Compilation
1031 @cindex cross-compilation
1032
1033 To @dfn{cross-compile} is to build on one platform a binary that will
1034 run on another platform.  When speaking of cross-compilation, it is
1035 important to distinguish between the @dfn{build platform} on which
1036 the compilation is performed, and the @dfn{host platform} on which the
1037 resulting executable is expected to run.  The following
1038 @command{configure} options are used to specify each of them:
1039
1040 @table @option
1041 @item --build=@var{build}
1042 @opindex --build=@var{build}
1043 The system on which the package is built.
1044 @item --host=@var{host}
1045 @opindex --host=@var{host}
1046 The system where built programs and libraries will run.
1047 @end table
1048
1049 When the @option{--host} is used, @command{configure} will search for
1050 the cross-compiling suite for this platform.  Cross-compilation tools
1051 commonly have their target architecture as prefix of their name.  For
1052 instance my cross-compiler for MinGW32 has its binaries called
1053 @code{i586-mingw32msvc-gcc}, @code{i586-mingw32msvc-ld},
1054 @code{i586-mingw32msvc-as}, etc.
1055
1056 @cindex MinGW cross-compilation example
1057 @cindex cross-compilation example
1058
1059 Here is how we could build @code{amhello-1.0} for
1060 @code{i586-mingw32msvc} on a GNU/Linux PC.
1061
1062 @c Keep in sync with amhello-cross-compile.sh
1063 @smallexample
1064 ~/amhello-1.0 % @kbd{./configure --build i686-pc-linux-gnu --host i586-mingw32msvc}
1065 checking for a BSD-compatible install... /usr/bin/install -c
1066 checking whether build environment is sane... yes
1067 checking for gawk... gawk
1068 checking whether make sets $(MAKE)... yes
1069 checking for i586-mingw32msvc-strip... i586-mingw32msvc-strip
1070 checking for i586-mingw32msvc-gcc... i586-mingw32msvc-gcc
1071 checking for C compiler default output file name... a.exe
1072 checking whether the C compiler works... yes
1073 checking whether we are cross compiling... yes
1074 checking for suffix of executables... .exe
1075 checking for suffix of object files... o
1076 checking whether we are using the GNU C compiler... yes
1077 checking whether i586-mingw32msvc-gcc accepts -g... yes
1078 checking for i586-mingw32msvc-gcc option to accept ANSI C...
1079 @dots{}
1080 ~/amhello-1.0 % @kbd{make}
1081 @dots{}
1082 ~/amhello-1.0 % @kbd{cd src; file hello.exe}
1083 hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable
1084 @end smallexample
1085
1086 The @option{--host} and @option{--build} options are usually all we
1087 need for cross-compiling.  The only exception is if the package being
1088 built is itself a cross-compiler: we need a third option to specify
1089 its target architecture.
1090
1091 @table @option
1092 @item --target=@var{target}
1093 @opindex --target=@var{target}
1094 When building compiler tools: the system for which the tools will
1095 create output.
1096 @end table
1097
1098 For instance when installing GCC, the GNU Compiler Collection, we can
1099 use @option{--target=@/@var{target}} to specify that we want to build
1100 GCC as a cross-compiler for @var{target}.  Mixing @option{--build} and
1101 @option{--target}, we can actually cross-compile a cross-compiler;
1102 such a three-way cross-compilation is known as a @dfn{Canadian cross}.
1103
1104 @xref{Specifying Names, , Specifying the System Type, autoconf, The
1105 Autoconf Manual}, for more information about these @command{configure}
1106 options.
1107
1108 @node Renaming
1109 @subsection Renaming Programs at Install Time
1110 @cindex Renaming programs
1111 @cindex Transforming program names
1112 @cindex Programs, renaming during installation
1113
1114 The GNU Build System provides means to automatically rename
1115 executables and manpages before they are installed (@pxref{Man Pages}).
1116 This is especially convenient
1117 when installing a GNU package on a system that already has a
1118 proprietary implementation you do not want to overwrite.  For instance,
1119 you may want to install GNU @command{tar} as @command{gtar} so you can
1120 distinguish it from your vendor's @command{tar}.
1121
1122 This can be done using one of these three @command{configure} options.
1123
1124 @table @option
1125 @item --program-prefix=@var{prefix}
1126 @opindex --program-prefix=@var{prefix}
1127 Prepend @var{prefix} to installed program names.
1128 @item --program-suffix=@var{suffix}
1129 @opindex --program-suffix=@var{suffix}
1130 Append @var{suffix} to installed program names.
1131 @item --program-transform-name=@var{program}
1132 @opindex --program-transform-name=@var{program}
1133 Run @code{sed @var{program}} on installed program names.
1134 @end table
1135
1136 The following commands would install @file{hello}
1137 as @file{/usr/local/bin/test-hello}, for instance.
1138
1139 @example
1140 ~/amhello-1.0 % @kbd{./configure --program-prefix test-}
1141 @dots{}
1142 ~/amhello-1.0 % @kbd{make}
1143 @dots{}
1144 ~/amhello-1.0 % @kbd{sudo make install}
1145 @dots{}
1146 @end example
1147
1148 @node DESTDIR
1149 @subsection Building Binary Packages Using DESTDIR
1150 @vindex DESTDIR
1151
1152 The GNU Build System's @code{make install} and @code{make uninstall}
1153 interface does not exactly fit the needs of a system administrator
1154 who has to deploy and upgrade packages on lots of hosts.  In other
1155 words, the GNU Build System does not replace a package manager.
1156
1157 Such package managers usually need to know which files have been
1158 installed by a package, so a mere @code{make install} is
1159 inappropriate.
1160
1161 @cindex Staged installation
1162
1163 The @code{DESTDIR} variable can be used to perform a staged
1164 installation.  The package should be configured as if it was going to
1165 be installed in its final location (e.g., @code{--prefix /usr}), but
1166 when running @code{make install}, the @code{DESTDIR} should be set to
1167 the absolute name of a directory into which the installation will be
1168 diverted.  From this directory it is easy to review which files are
1169 being installed where, and finally copy them to their final location
1170 by some means.
1171
1172 @cindex Binary package
1173
1174 For instance here is how we could create a binary package containing a
1175 snapshot of all the files to be installed.
1176
1177 @c Keep in sync with amhello-binpkg.sh
1178 @example
1179 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1180 @dots{}
1181 ~/amhello-1.0 % @kbd{make}
1182 @dots{}
1183 ~/amhello-1.0 % @kbd{make DESTDIR=$HOME/inst install}
1184 @dots{}
1185 ~/amhello-1.0 % @kbd{cd ~/inst}
1186 ~/inst % @kbd{find . -type f -print > ../files.lst}
1187 ~/inst % @kbd{tar zcvf ~/amhello-1.0-i686.tar.gz `cat ../files.lst`}
1188 ./usr/bin/hello
1189 ./usr/share/doc/amhello/README
1190 @end example
1191
1192 After this example, @code{amhello-1.0-i686.tar.gz} is ready to be
1193 uncompressed in @file{/} on many hosts.  (Using @code{`cat ../files.lst`}
1194 instead of @samp{.} as argument for @command{tar} avoids entries for
1195 each subdirectory in the archive: we would not like @command{tar} to
1196 restore the modification time of @file{/}, @file{/usr/}, etc.)
1197
1198 Note that when building packages for several architectures, it might
1199 be convenient to use @code{make install-data} and @code{make
1200 install-exec} (@pxref{Two-Part Install}) to gather
1201 architecture-independent files in a single package.
1202
1203 @xref{Install}, for more information.
1204
1205 @c We should document PRE_INSTALL/POST_INSTALL/NORMAL_INSTALL and their
1206 @c UNINSTALL counterparts.
1207
1208 @node Preparing Distributions
1209 @subsection Preparing Distributions
1210 @cindex Preparing distributions
1211 @cindex Packages, preparation
1212 @cindex Distributions, preparation
1213
1214 We have already mentioned @code{make dist}.  This target collects all
1215 your source files and the necessary parts of the build system to
1216 create a tarball named @file{@var{package}-@var{version}.tar.gz}.
1217
1218 @cindex @code{distcheck} better than @code{dist}
1219
1220 Another, more useful command is @code{make distcheck}.  The
1221 @code{distcheck} target constructs
1222 @file{@var{package}-@var{version}.tar.gz} just as well as @code{dist},
1223 but it additionally ensures most of the use cases presented so far
1224 work:
1225
1226 @itemize @bullet
1227 @item
1228 It attempts a full compilation of the package (@pxref{Basic
1229 Installation}), unpacking the newly constructed tarball, running
1230 @code{make}, @code{make check}, @code{make install}, as well as
1231 @code{make installcheck}, and even @code{make dist},
1232 @item
1233 it tests VPATH builds with read-only source tree (@pxref{VPATH Builds}),
1234 @item
1235 it makes sure @code{make clean}, @code{make distclean}, and @code{make
1236 uninstall} do not omit any file (@pxref{Standard Targets}),
1237 @item
1238 and it checks that @code{DESTDIR} installations work (@pxref{DESTDIR}).
1239 @end itemize
1240
1241 All of these actions are performed in a temporary subdirectory, so
1242 that no root privileges are required.
1243
1244 Releasing a package that fails @code{make distcheck} means that one of
1245 the scenarios we presented will not work and some users will be
1246 disappointed.  Therefore it is a good practice to release a package
1247 only after a successful @code{make distcheck}.  This of course does
1248 not imply that the package will be flawless, but at least it will
1249 prevent some of the embarrassing errors you may find in packages
1250 released by people who have never heard about @code{distcheck} (like
1251 @code{DESTDIR} not working because of a typo, or a distributed file
1252 being erased by @code{make clean}, or even @code{VPATH} builds not
1253 working).
1254
1255 @xref{Creating amhello}, to recreate @file{amhello-1.0.tar.gz} using
1256 @code{make distcheck}.  @xref{Checking the Distribution}, for more
1257 information about @code{distcheck}.
1258
1259 @node Dependency Tracking
1260 @subsection Automatic Dependency Tracking
1261 @cindex Dependency tracking
1262
1263 Dependency tracking is performed as a side-effect of compilation.
1264 Each time the build system compiles a source file, it computes its
1265 list of dependencies (in C these are the header files included by the
1266 source being compiled).  Later, any time @command{make} is run and a
1267 dependency appears to have changed, the dependent files will be
1268 rebuilt.
1269
1270 Automake generates code for automatic dependency tracking by default,
1271 unless the developer chooses to override it; for more information,
1272 @pxref{Dependencies}.
1273
1274 When @command{configure} is executed, you can see it probing each
1275 compiler for the dependency mechanism it supports (several mechanisms
1276 can be used):
1277
1278 @example
1279 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1280 @dots{}
1281 checking dependency style of gcc... gcc3
1282 @dots{}
1283 @end example
1284
1285 Because dependencies are only computed as a side-effect of the
1286 compilation, no dependency information exists the first time a package
1287 is built.  This is OK because all the files need to be built anyway:
1288 @code{make} does not have to decide which files need to be rebuilt.
1289 In fact, dependency tracking is completely useless for one-time builds
1290 and there is a @command{configure} option to disable this:
1291
1292 @table @option
1293 @item --disable-dependency-tracking
1294 @opindex --disable-dependency-tracking
1295 Speed up one-time builds.
1296 @end table
1297
1298 Some compilers do not offer any practical way to derive the list of
1299 dependencies as a side-effect of the compilation, requiring a separate
1300 run (maybe of another tool) to compute these dependencies.  The
1301 performance penalty implied by these methods is important enough to
1302 disable them by default.  The option @option{--enable-dependency-tracking}
1303 must be passed to @command{configure} to activate them.
1304
1305 @table @option
1306 @item --enable-dependency-tracking
1307 @opindex --enable-dependency-tracking
1308 Do not reject slow dependency extractors.
1309 @end table
1310
1311 @xref{Dependency Tracking Evolution, , Dependency Tracking Evolution,
1312 automake-history, Brief History of Automake}, for some discussion about
1313 the different dependency tracking schemes used by Automake over the years.
1314
1315 @node Nested Packages
1316 @subsection Nested Packages
1317 @cindex Nested packages
1318 @cindex Packages, nested
1319 @cindex Subpackages
1320
1321 Although nesting packages isn't something we would recommend to
1322 someone who is discovering the Autotools, it is a nice feature worthy
1323 of mention in this small advertising tour.
1324
1325 Autoconfiscated packages (that means packages whose build system have
1326 been created by Autoconf and friends) can be nested to arbitrary
1327 depth.
1328
1329 A typical setup is that package A will distribute one of the libraries
1330 it needs in a subdirectory.  This library B is a complete package with
1331 its own GNU Build System.  The @command{configure} script of A will
1332 run the @command{configure} script of B as part of its execution,
1333 building and installing A will also build and install B.  Generating a
1334 distribution for A will also include B.
1335
1336 It is possible to gather several packages like this.  GCC is a heavy
1337 user of this feature.  This gives installers a single package to
1338 configure, build and install, while it allows developers to work on
1339 subpackages independently.
1340
1341 When configuring nested packages, the @command{configure} options
1342 given to the top-level @command{configure} are passed recursively to
1343 nested @command{configure}s.  A package that does not understand an
1344 option will ignore it, assuming it is meaningful to some other
1345 package.
1346
1347 @opindex --help=recursive
1348
1349 The command @code{configure --help=recursive} can be used to display
1350 the options supported by all the included packages.
1351
1352 @xref{Subpackages}, for an example setup.
1353
1354 @node Why Autotools
1355 @section How Autotools Help
1356 @cindex Autotools, purpose
1357
1358 There are several reasons why you may not want to implement the GNU
1359 Build System yourself (read: write a @file{configure} script and
1360 @file{Makefile}s yourself).
1361
1362 @itemize @bullet
1363 @item
1364 As we have seen, the GNU Build System has a lot of
1365 features (@pxref{Use Cases}).
1366 Some users may expect features you have not implemented because
1367 you did not need them.
1368 @item
1369 Implementing these features portably is difficult and exhausting.
1370 Think of writing portable shell scripts, and portable
1371 @file{Makefile}s, for systems you may not have handy.  @xref{Portable
1372 Shell, , Portable Shell Programming, autoconf, The Autoconf Manual}, to
1373 convince yourself.
1374 @item
1375 You will have to upgrade your setup to follow changes to the GNU
1376 Coding Standards.
1377 @end itemize
1378
1379 The GNU Autotools take all this burden off your back and provide:
1380
1381 @itemize @bullet
1382 @item
1383 Tools to create a portable, complete, and self-contained GNU Build
1384 System, from simple instructions.
1385 @emph{Self-contained} meaning the resulting build system does not
1386 require the GNU Autotools.
1387 @item
1388 A central place where fixes and improvements are made:
1389 a bug-fix for a portability issue will benefit every package.
1390 @end itemize
1391
1392 Yet there also exist reasons why you may want NOT to use the
1393 Autotools@enddots{} For instance you may be already using (or used to)
1394 another incompatible build system.  Autotools will only be useful if
1395 you do accept the concepts of the GNU Build System.  People who have their
1396 own idea of how a build system should work will feel frustrated by the
1397 Autotools.
1398
1399 @node Hello World
1400 @section A Small Hello World
1401 @cindex Example Hello World
1402 @cindex Hello World example
1403 @cindex @file{amhello-1.0.tar.gz}, creation
1404
1405 In this section we recreate the @file{amhello-1.0} package from
1406 scratch.  The first subsection shows how to call the Autotools to
1407 instantiate the GNU Build System, while the second explains the
1408 meaning of the @file{configure.ac} and @file{Makefile.am} files read
1409 by the Autotools.
1410
1411 @anchor{amhello Explained}
1412 @menu
1413 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
1414 * amhello's configure.ac Setup Explained::
1415 * amhello's Makefile.am Setup Explained::
1416 @end menu
1417
1418 @node Creating amhello
1419 @subsection Creating @file{amhello-1.0.tar.gz}
1420
1421 Here is how we can recreate @file{amhello-1.0.tar.gz} from scratch.
1422 The package is simple enough so that we will only need to write 5
1423 files.  (You may copy them from the final @file{amhello-1.0.tar.gz}
1424 that is distributed with Automake if you do not want to write them.)
1425
1426 Create the following files in an empty directory.
1427
1428 @itemize @bullet
1429
1430 @item
1431 @file{src/main.c} is the source file for the @file{hello} program.  We
1432 store it in the @file{src/} subdirectory, because later, when the package
1433 evolves, it will ease the addition of a @file{man/} directory for man
1434 pages, a @file{data/} directory for data files, etc.
1435 @example
1436 ~/amhello % @kbd{cat src/main.c}
1437 #include <config.h>
1438 #include <stdio.h>
1439
1440 int
1441 main (void)
1442 @{
1443   puts ("Hello World!");
1444   puts ("This is " PACKAGE_STRING ".");
1445   return 0;
1446 @}
1447 @end example
1448
1449 @item
1450 @file{README} contains some very limited documentation for our little
1451 package.
1452 @example
1453 ~/amhello % @kbd{cat README}
1454 This is a demonstration package for GNU Automake.
1455 Type 'info Automake' to read the Automake manual.
1456 @end example
1457
1458 @item
1459 @file{Makefile.am} and @file{src/Makefile.am} contain Automake
1460 instructions for these two directories.
1461
1462 @example
1463 ~/amhello % @kbd{cat src/Makefile.am}
1464 bin_PROGRAMS = hello
1465 hello_SOURCES = main.c
1466 ~/amhello % @kbd{cat Makefile.am}
1467 SUBDIRS = src
1468 dist_doc_DATA = README
1469 @end example
1470
1471 @item
1472 Finally, @file{configure.ac} contains Autoconf instructions to
1473 create the @command{configure} script.
1474
1475 @example
1476 ~/amhello % @kbd{cat configure.ac}
1477 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1478 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1479 AC_PROG_CC
1480 AC_CONFIG_HEADERS([config.h])
1481 AC_CONFIG_FILES([
1482  Makefile
1483  src/Makefile
1484 ])
1485 AC_OUTPUT
1486 @end example
1487 @end itemize
1488
1489 @cindex @command{autoreconf}, example
1490
1491 Once you have these five files, it is time to run the Autotools to
1492 instantiate the build system.  Do this using the @command{autoreconf}
1493 command as follows:
1494
1495 @example
1496 ~/amhello % @kbd{autoreconf --install}
1497 configure.ac: installing './install-sh'
1498 configure.ac: installing './missing'
1499 src/Makefile.am: installing './depcomp'
1500 @end example
1501
1502 At this point the build system is complete.
1503
1504 In addition to the three scripts mentioned in its output, you can see
1505 that @command{autoreconf} created four other files: @file{configure},
1506 @file{config.h.in}, @file{Makefile.in}, and @file{src/Makefile.in}.
1507 The latter three files are templates that will be adapted to the
1508 system by @command{configure} under the names @file{config.h},
1509 @file{Makefile}, and @file{src/Makefile}.  Let's do this:
1510
1511 @example
1512 ~/amhello % @kbd{./configure}
1513 checking for a BSD-compatible install... /usr/bin/install -c
1514 checking whether build environment is sane... yes
1515 checking for gawk... no
1516 checking for mawk... mawk
1517 checking whether make sets $(MAKE)... yes
1518 checking for gcc... gcc
1519 checking for C compiler default output file name... a.out
1520 checking whether the C compiler works... yes
1521 checking whether we are cross compiling... no
1522 checking for suffix of executables...
1523 checking for suffix of object files... o
1524 checking whether we are using the GNU C compiler... yes
1525 checking whether gcc accepts -g... yes
1526 checking for gcc option to accept ISO C89... none needed
1527 checking for style of include used by make... GNU
1528 checking dependency style of gcc... gcc3
1529 configure: creating ./config.status
1530 config.status: creating Makefile
1531 config.status: creating src/Makefile
1532 config.status: creating config.h
1533 config.status: executing depfiles commands
1534 @end example
1535
1536 @trindex distcheck
1537 @cindex @code{distcheck} example
1538
1539 You can see @file{Makefile}, @file{src/Makefile}, and @file{config.h}
1540 being created at the end after @command{configure} has probed the
1541 system.  It is now possible to run all the targets we wish
1542 (@pxref{Standard Targets}).  For instance:
1543
1544 @example
1545 ~/amhello % @kbd{make}
1546 @dots{}
1547 ~/amhello % @kbd{src/hello}
1548 Hello World!
1549 This is amhello 1.0.
1550 ~/amhello % @kbd{make distcheck}
1551 @dots{}
1552 =============================================
1553 amhello-1.0 archives ready for distribution:
1554 amhello-1.0.tar.gz
1555 =============================================
1556 @end example
1557
1558 Note that running @command{autoreconf} is only needed initially when
1559 the GNU Build System does not exist.  When you later change some
1560 instructions in a @file{Makefile.am} or @file{configure.ac}, the
1561 relevant part of the build system will be regenerated automatically
1562 when you execute @command{make}.
1563
1564 @command{autoreconf} is a script that calls @command{autoconf},
1565 @command{automake}, and a bunch of other commands in the right order.
1566 If you are beginning with these tools, it is not important to figure
1567 out in which order all of these tools should be invoked and why.  However,
1568 because Autoconf and Automake have separate manuals, the important
1569 point to understand is that @command{autoconf} is in charge of
1570 creating @file{configure} from @file{configure.ac}, while
1571 @command{automake} is in charge of creating @file{Makefile.in}s from
1572 @file{Makefile.am}s and @file{configure.ac}.  This should at least
1573 direct you to the right manual when seeking answers.
1574
1575
1576 @node amhello's configure.ac Setup Explained
1577 @subsection @code{amhello}'s @file{configure.ac} Setup Explained
1578
1579 @cindex @file{configure.ac}, Hello World
1580
1581 Let us begin with the contents of @file{configure.ac}.
1582
1583 @example
1584 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1585 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1586 AC_PROG_CC
1587 AC_CONFIG_HEADERS([config.h])
1588 AC_CONFIG_FILES([
1589  Makefile
1590  src/Makefile
1591 ])
1592 AC_OUTPUT
1593 @end example
1594
1595 This file is read by both @command{autoconf} (to create
1596 @file{configure}) and @command{automake} (to create the various
1597 @file{Makefile.in}s).  It contains a series of M4 macros that will be
1598 expanded as shell code to finally form the @file{configure} script.
1599 We will not elaborate on the syntax of this file, because the Autoconf
1600 manual has a whole section about it (@pxref{Writing Autoconf Input, ,
1601 Writing @file{configure.ac}, autoconf, The Autoconf Manual}).
1602
1603 The macros prefixed with @code{AC_} are Autoconf macros, documented
1604 in the Autoconf manual (@pxref{Autoconf Macro Index, , Autoconf Macro
1605 Index, autoconf, The Autoconf Manual}).  The macros that start with
1606 @code{AM_} are Automake macros, documented later in this manual
1607 (@pxref{Macro Index}).
1608
1609 The first two lines of @file{configure.ac} initialize Autoconf and
1610 Automake.  @code{AC_INIT} takes in as parameters the name of the package,
1611 its version number, and a contact address for bug-reports about the
1612 package (this address is output at the end of @code{./configure
1613 --help}, for instance).  When adapting this setup to your own package,
1614 by all means please do not blindly copy Automake's address: use the
1615 mailing list of your package, or your own mail address.
1616
1617 @opindex -Wall
1618 @opindex -Werror
1619 @opindex foreign
1620
1621 The argument to @code{AM_INIT_AUTOMAKE} is a list of options for
1622 @command{automake} (@pxref{Options}).  @option{-Wall} and
1623 @option{-Werror} ask @command{automake} to turn on all warnings and
1624 report them as errors.  We are speaking of @strong{Automake} warnings
1625 here, such as dubious instructions in @file{Makefile.am}.  This has
1626 absolutely nothing to do with how the compiler will be called, even
1627 though it may support options with similar names.  Using @option{-Wall
1628 -Werror} is a safe setting when starting to work on a package: you do
1629 not want to miss any issues.  Later you may decide to relax things a
1630 bit.  The @option{foreign} option tells Automake that this package
1631 will not follow the GNU Standards.  GNU packages should always
1632 distribute additional files such as @file{ChangeLog}, @file{AUTHORS},
1633 etc.  We do not want @command{automake} to complain about these
1634 missing files in our small example.
1635
1636 The @code{AC_PROG_CC} line causes the @command{configure} script to
1637 search for a C compiler and define the variable @code{CC} with its
1638 name.  The @file{src/Makefile.in} file generated by Automake uses the
1639 variable @code{CC} to build @file{hello}, so when @command{configure}
1640 creates @file{src/Makefile} from @file{src/Makefile.in}, it will define
1641 @code{CC} with the value it has found.  If Automake is asked to create
1642 a @file{Makefile.in} that uses @code{CC} but @file{configure.ac} does
1643 not define it, it will suggest you add a call to @code{AC_PROG_CC}.
1644
1645 The @code{AC_CONFIG_HEADERS([config.h])} invocation causes the
1646 @command{configure} script to create a @file{config.h} file gathering
1647 @samp{#define}s defined by other macros in @file{configure.ac}.  In our
1648 case, the @code{AC_INIT} macro already defined a few of them.  Here
1649 is an excerpt of @file{config.h} after @command{configure} has run:
1650
1651 @smallexample
1652 @dots{}
1653 /* Define to the address where bug reports for this package should be sent. */
1654 #define PACKAGE_BUGREPORT "@value{PACKAGE_BUGREPORT}"
1655
1656 /* Define to the full name and version of this package. */
1657 #define PACKAGE_STRING "amhello 1.0"
1658 @dots{}
1659 @end smallexample
1660
1661 As you probably noticed, @file{src/main.c} includes @file{config.h} so
1662 it can use @code{PACKAGE_STRING}.  In a real-world project,
1663 @file{config.h} can grow really big, with one @samp{#define} per
1664 feature probed on the system.
1665
1666 The @code{AC_CONFIG_FILES} macro declares the list of files that
1667 @command{configure} should create from their @file{*.in} templates.
1668 Automake also scans this list to find the @file{Makefile.am} files it must
1669 process.  (This is important to remember: when adding a new directory
1670 to your project, you should add its @file{Makefile} to this list,
1671 otherwise Automake will never process the new @file{Makefile.am} you
1672 wrote in that directory.)
1673
1674 Finally, the @code{AC_OUTPUT} line is a closing command that actually
1675 produces the part of the script in charge of creating the files
1676 registered with @code{AC_CONFIG_HEADERS} and @code{AC_CONFIG_FILES}.
1677
1678 @cindex @command{autoscan}
1679
1680 When starting a new project, we suggest you start with such a simple
1681 @file{configure.ac}, and gradually add the other tests it requires.
1682 The command @command{autoscan} can also suggest a few of the tests
1683 your package may need (@pxref{autoscan Invocation, , Using
1684 @command{autoscan} to Create @file{configure.ac}, autoconf, The
1685 Autoconf Manual}).
1686
1687
1688 @node amhello's Makefile.am Setup Explained
1689 @subsection @code{amhello}'s @file{Makefile.am} Setup Explained
1690
1691 @cindex @file{Makefile.am}, Hello World
1692
1693 We now turn to @file{src/Makefile.am}.  This file contains
1694 Automake instructions to build and install @file{hello}.
1695
1696 @example
1697 bin_PROGRAMS = hello
1698 hello_SOURCES = main.c
1699 @end example
1700
1701 A @file{Makefile.am} has the same syntax as an ordinary
1702 @file{Makefile}.  When @command{automake} processes a
1703 @file{Makefile.am} it copies the entire file into the output
1704 @file{Makefile.in} (that will be later turned into @file{Makefile} by
1705 @command{configure}) but will react to certain variable definitions
1706 by generating some build rules and other variables.
1707 Often @file{Makefile.am}s contain only a list of variable definitions as
1708 above, but they can also contain other variable and rule definitions that
1709 @command{automake} will pass along without interpretation.
1710
1711 Variables that end with @code{_PROGRAMS} are special variables
1712 that list programs that the resulting @file{Makefile} should build.
1713 In Automake speak, this @code{_PROGRAMS} suffix is called a
1714 @dfn{primary}; Automake recognizes other primaries such as
1715 @code{_SCRIPTS}, @code{_DATA}, @code{_LIBRARIES}, etc.@: corresponding
1716 to different types of files.
1717
1718 The @samp{bin} part of the @code{bin_PROGRAMS} tells
1719 @command{automake} that the resulting programs should be installed in
1720 @var{bindir}.  Recall that the GNU Build System uses a set of variables
1721 to denote destination directories and allow users to customize these
1722 locations (@pxref{Standard Directory Variables}).  Any such directory
1723 variable can be put in front of a primary (omitting the @code{dir}
1724 suffix) to tell @command{automake} where to install the listed files.
1725
1726 Programs need to be built from source files, so for each program
1727 @code{@var{prog}} listed in a @code{@w{_PROGRAMS}} variable,
1728 @command{automake} will look for another variable named
1729 @code{@var{prog}_SOURCES} listing its source files.  There may be more
1730 than one source file: they will all be compiled and linked together.
1731
1732 Automake also knows that source files need to be distributed when
1733 creating a tarball (unlike built programs).  So a side-effect of this
1734 @code{hello_SOURCES} declaration is that @file{main.c} will be
1735 part of the tarball created by @code{make dist}.
1736
1737 Finally here are some explanations regarding the top-level
1738 @file{Makefile.am}.
1739
1740 @example
1741 SUBDIRS = src
1742 dist_doc_DATA = README
1743 @end example
1744
1745 @code{SUBDIRS} is a special variable listing all directories that
1746 @command{make} should recurse into before processing the current
1747 directory.  So this line is responsible for @command{make} building
1748 @file{src/hello} even though we run it from the top-level.  This line
1749 also causes @code{make install} to install @file{src/hello} before
1750 installing @file{README} (not that this order matters).
1751
1752 The line @code{dist_doc_DATA = README} causes @file{README} to be
1753 distributed and installed in @var{docdir}.  Files listed with the
1754 @code{_DATA} primary are not automatically part of the tarball built
1755 with @code{make dist}, so we add the @code{dist_} prefix so they get
1756 distributed.  However, for @file{README} it would not have been
1757 necessary: @command{automake} automatically distributes any
1758 @file{README} file it encounters (the list of other files
1759 automatically distributed is presented by @code{automake --help}).
1760 The only important effect of this second line is therefore to install
1761 @file{README} during @code{make install}.
1762
1763 One thing not covered in this example is accessing the installation
1764 directory values (@pxref{Standard Directory Variables}) from your
1765 program code, that is, converting them into defined macros.  For this,
1766 @pxref{Defining Directories,,, autoconf, The Autoconf Manual}.
1767
1768
1769 @node Generalities
1770 @chapter General ideas
1771
1772 The following sections cover a few basic ideas that will help you
1773 understand how Automake works.
1774
1775 @menu
1776 * General Operation::           General operation of Automake
1777 * Strictness::                  Standards conformance checking
1778 * Uniform::                     The Uniform Naming Scheme
1779 * Length Limitations::          Staying below the command line length limit
1780 * Canonicalization::            How derived variables are named
1781 * User Variables::              Variables reserved for the user
1782 * Auxiliary Programs::          Programs automake might require
1783 @end menu
1784
1785
1786 @node General Operation
1787 @section General Operation
1788
1789 Automake works by reading a @file{Makefile.am} and generating a
1790 @file{Makefile.in}.  Certain variables and rules defined in the
1791 @file{Makefile.am} instruct Automake to generate more specialized code;
1792 for instance, a @code{bin_PROGRAMS} variable definition will cause rules
1793 for compiling and linking programs to be generated.
1794
1795 @cindex Non-standard targets
1796 @cindex @code{git-dist}, non-standard example
1797 @trindex git-dist
1798
1799 The variable definitions and rules in the @file{Makefile.am} are
1800 copied mostly verbatim into the generated file, with all variable
1801 definitions preceding all rules.  This allows you to add almost
1802 arbitrary code into the generated @file{Makefile.in}.  For instance,
1803 the Automake distribution includes a non-standard rule for the
1804 @code{git-dist} target, which the Automake maintainer uses to make
1805 distributions from the source control system.
1806
1807 @cindex GNU make extensions
1808
1809 Note that most GNU make extensions are not recognized by Automake.  Using
1810 such extensions in a @file{Makefile.am} will lead to errors or confusing
1811 behavior.
1812
1813 @cindex Append operator
1814 @cmindex +=
1815 A special exception is that the GNU make append operator, @samp{+=}, is
1816 supported.  This operator appends its right hand argument to the variable
1817 specified on the left.  Automake will translate the operator into
1818 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
1819
1820 Automake tries to keep comments grouped with any adjoining rules or
1821 variable definitions.
1822
1823 @cindex Limitations of automake parser
1824 @cindex Automake parser, limitations of
1825 @cindex indentation in Makefile.am
1826 Generally, Automake is not particularly smart in the parsing of unusual
1827 Makefile constructs, so you're advised to avoid fancy constructs or
1828 ``creative'' use of whitespaces.
1829 @c Keep this in sync with doc-parsing-buglets-tabs.sh
1830 For example, @key{TAB} characters cannot be used between a target name
1831 and the following ``@code{:}'' character, and variable assignments
1832 shouldn't be indented with @key{TAB} characters.
1833 @c Keep this in sync with doc-parsing-buglets-colneq-subst.sh
1834 Also, using more complex macro in target names can cause trouble:
1835
1836 @example
1837 % @kbd{cat Makefile.am}
1838 $(FOO:=x): bar
1839 % @kbd{automake}
1840 Makefile.am:1: bad characters in variable name '$(FOO'
1841 Makefile.am:1: ':='-style assignments are not portable
1842 @end example
1843
1844 @cindex Make targets, overriding
1845 @cindex Make rules, overriding
1846 @cindex Overriding make rules
1847 @cindex Overriding make targets
1848
1849 A rule defined in @file{Makefile.am} generally overrides any such
1850 rule of a similar name that would be automatically generated by
1851 @command{automake}.  Although this is a supported feature, it is generally
1852 best to avoid making use of it, as sometimes the generated rules are
1853 very particular.
1854
1855 @cindex Variables, overriding
1856 @cindex Overriding make variables
1857
1858 Similarly, a variable defined in @file{Makefile.am} or
1859 @code{AC_SUBST}ed from @file{configure.ac} will override any
1860 definition of the variable that @command{automake} would ordinarily
1861 create.  This feature is more often useful than the ability to
1862 override a rule.  Be warned that many of the variables generated by
1863 @command{automake} are considered to be for internal use only, and their
1864 names might change in future releases.
1865
1866 @cindex Recursive operation of Automake
1867 @cindex Automake, recursive operation
1868 @cindex Example of recursive operation
1869
1870 When examining a variable definition, Automake will recursively examine
1871 variables referenced in the definition.  For example, if Automake is
1872 looking at the content of @code{foo_SOURCES} in this snippet
1873
1874 @c Keep in sync with interp.sh
1875 @example
1876 xs = a.c b.c
1877 foo_SOURCES = c.c $(xs)
1878 @end example
1879
1880 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
1881 contents of @code{foo_SOURCES}.
1882
1883 @cindex @code{##} (special Automake comment)
1884 @cindex Special Automake comment
1885 @cindex Comment, special to Automake
1886
1887 Automake also allows a form of comment that is @emph{not} copied into
1888 the output; all lines beginning with @samp{##} (leading spaces allowed)
1889 are completely ignored by Automake.
1890
1891 It is customary to make the first line of @file{Makefile.am} read:
1892
1893 @cindex Makefile.am, first line
1894 @cindex First line of Makefile.am
1895
1896 @example
1897 ## Process this file with automake to produce Makefile.in
1898 @end example
1899
1900 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
1901 @c I don't know quite what to say.
1902
1903 @c FIXME document customary ordering of Makefile.am here!
1904
1905
1906 @node Strictness
1907 @section Strictness
1908
1909 @cindex Non-GNU packages
1910
1911 While Automake is intended to be used by maintainers of GNU packages, it
1912 does make some effort to accommodate those who wish to use it, but do
1913 not want to use all the GNU conventions.
1914
1915 @cindex Strictness, defined
1916 @cindex Strictness, @option{foreign}
1917 @cindex @option{foreign} strictness
1918 @cindex Strictness, @option{gnu}
1919 @cindex @option{gnu} strictness
1920 @cindex Strictness, @option{gnits}
1921 @cindex @option{gnits} strictness
1922
1923 To this end, Automake supports three levels of @dfn{strictness}---the
1924 strictness indicating how stringently Automake should check standards
1925 conformance.
1926
1927 The valid strictness levels are:
1928
1929 @table @option
1930 @item foreign
1931 Automake will check for only those things that are absolutely
1932 required for proper operations.  For instance, whereas GNU standards
1933 dictate the existence of a @file{NEWS} file, it will not be required in
1934 this mode.  This strictness will also turn off some warnings by default
1935 (among them, portability warnings).
1936 The name comes from the fact that Automake is intended to be
1937 used for GNU programs; these relaxed rules are not the standard mode of
1938 operation.
1939
1940 @item gnu
1941 Automake will check---as much as possible---for compliance to the GNU
1942 standards for packages.  This is the default.
1943
1944 @item gnits
1945 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
1946 standards}.  These are based on the GNU standards, but are even more
1947 detailed.  Unless you are a Gnits standards contributor, it is
1948 recommended that you avoid this option until such time as the Gnits
1949 standard is actually published (which may never happen).
1950 @end table
1951
1952 @xref{Gnits}, for more information on the precise implications of the
1953 strictness level.
1954
1955
1956 @node Uniform
1957 @section The Uniform Naming Scheme
1958
1959 @cindex Uniform naming scheme
1960
1961 Automake variables generally follow a @dfn{uniform naming scheme} that
1962 makes it easy to decide how programs (and other derived objects) are
1963 built, and how they are installed.  This scheme also supports
1964 @command{configure} time determination of what should be built.
1965
1966 @cindex @code{_PROGRAMS} primary variable
1967 @cindex @code{PROGRAMS} primary variable
1968 @cindex Primary variable, @code{PROGRAMS}
1969 @cindex Primary variable, defined
1970 @vindex _PROGRAMS
1971
1972 At @command{make} time, certain variables are used to determine which
1973 objects are to be built.  The variable names are made of several pieces
1974 that are concatenated together.
1975
1976 The piece that tells @command{automake} what is being built is commonly called
1977 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
1978 list of programs that are to be compiled and linked.
1979 @vindex PROGRAMS
1980
1981 @cindex @code{pkgdatadir}, defined
1982 @cindex @code{pkgincludedir}, defined
1983 @cindex @code{pkglibdir}, defined
1984 @cindex @code{pkglibexecdir}, defined
1985
1986 @vindex pkgdatadir
1987 @vindex pkgincludedir
1988 @vindex pkglibdir
1989 @vindex pkglibexecdir
1990
1991 @cindex @code{PACKAGE}, directory
1992 A different set of names is used to decide where the built objects
1993 should be installed.  These names are prefixes to the primary, and they
1994 indicate which standard directory should be used as the installation
1995 directory.  The standard directory names are given in the GNU standards
1996 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
1997 Automake extends this list with @code{pkgdatadir}, @code{pkgincludedir},
1998 @code{pkglibdir}, and @code{pkglibexecdir}; these are the same as the
1999 non-@samp{pkg} versions, but with @samp{$(PACKAGE)} appended.  For instance,
2000 @code{pkglibdir} is defined as @samp{$(libdir)/$(PACKAGE)}.
2001
2002 @cindex @code{EXTRA_}, prepending
2003 For each primary, there is one additional variable named by prepending
2004 @samp{EXTRA_} to the primary name.  This variable is used to list
2005 objects that may or may not be built, depending on what
2006 @command{configure} decides.  This variable is required because Automake
2007 must statically know the entire list of objects that may be built in
2008 order to generate a @file{Makefile.in} that will work in all cases.
2009
2010 @cindex @code{EXTRA_PROGRAMS}, defined
2011 @cindex Example, @code{EXTRA_PROGRAMS}
2012 @cindex @command{cpio} example
2013
2014 For instance, @command{cpio} decides at configure time which programs
2015 should be built.  Some of the programs are installed in @code{bindir},
2016 and some are installed in @code{sbindir}:
2017
2018 @example
2019 EXTRA_PROGRAMS = mt rmt
2020 bin_PROGRAMS = cpio pax
2021 sbin_PROGRAMS = $(MORE_PROGRAMS)
2022 @end example
2023
2024 Defining a primary without a prefix as a variable, e.g.,
2025 @samp{PROGRAMS}, is an error.
2026
2027 Note that the common @samp{dir} suffix is left off when constructing the
2028 variable names; thus one writes @samp{bin_PROGRAMS} and not
2029 @samp{bindir_PROGRAMS}.
2030
2031 Not every sort of object can be installed in every directory.  Automake
2032 will flag those attempts it finds in error (but see below how to override
2033 the check if you really need to).
2034 Automake will also diagnose obvious misspellings in directory names.
2035
2036 @cindex Extending list of installation directories
2037 @cindex Installation directories, extending list
2038
2039 Sometimes the standard directories---even as augmented by
2040 Automake---are not enough.  In particular it is sometimes useful, for
2041 clarity, to install objects in a subdirectory of some predefined
2042 directory.  To this end, Automake allows you to extend the list of
2043 possible installation directories.  A given prefix (e.g., @samp{zar})
2044 is valid if a variable of the same name with @samp{dir} appended is
2045 defined (e.g., @samp{zardir}).
2046
2047 For instance, the following snippet will install @file{file.xml} into
2048 @samp{$(datadir)/xml}.
2049
2050 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2051 @example
2052 xmldir = $(datadir)/xml
2053 xml_DATA = file.xml
2054 @end example
2055
2056 This feature can also be used to override the sanity checks Automake
2057 performs to diagnose suspicious directory/primary couples (in the
2058 unlikely case these checks are undesirable, and you really know what
2059 you're doing).  For example, Automake would error out on this input:
2060
2061 @c Should be tested in primary-prefix-invalid-couples.sh
2062 @example
2063 # Forbidden directory combinations, automake will error out on this.
2064 pkglib_PROGRAMS = foo
2065 doc_LIBRARIES = libquux.a
2066 @end example
2067
2068 @noindent
2069 but it will succeed with this:
2070
2071 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2072 @example
2073 # Work around forbidden directory combinations.  Do not use this
2074 # without a very good reason!
2075 my_execbindir = $(pkglibdir)
2076 my_doclibdir = $(docdir)
2077 my_execbin_PROGRAMS = foo
2078 my_doclib_LIBRARIES = libquux.a
2079 @end example
2080
2081 The @samp{exec} substring of the @samp{my_execbindir} variable lets
2082 the files be installed at the right time (@pxref{The Two Parts of
2083 Install}).
2084
2085 @cindex @samp{noinst_} primary prefix, definition
2086 @vindex noinst_
2087
2088 The special prefix @samp{noinst_} indicates that the objects in question
2089 should be built but not installed at all.  This is usually used for
2090 objects required to build the rest of your package, for instance static
2091 libraries (@pxref{A Library}), or helper scripts.
2092
2093 @cindex @samp{check_} primary prefix, definition
2094 @vindex check_
2095
2096 The special prefix @samp{check_} indicates that the objects in question
2097 should not be built until the @samp{make check} command is run.  Those
2098 objects are not installed either.
2099
2100 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
2101 @samp{LTLIBRARIES}, @samp{LISP}, @samp{PYTHON}, @samp{JAVA},
2102 @samp{SCRIPTS}, @samp{DATA}, @samp{HEADERS}, @samp{MANS}, and
2103 @samp{TEXINFOS}.
2104 @vindex PROGRAMS
2105 @vindex LIBRARIES
2106 @vindex LTLIBRARIES
2107 @vindex LISP
2108 @vindex PYTHON
2109 @vindex JAVA
2110 @vindex SCRIPTS
2111 @vindex DATA
2112 @vindex HEADERS
2113 @vindex MANS
2114 @vindex TEXINFOS
2115
2116 Some primaries also allow additional prefixes that control other
2117 aspects of @command{automake}'s behavior.  The currently defined prefixes
2118 are @samp{dist_}, @samp{nodist_}, @samp{nobase_}, and @samp{notrans_}.
2119 These prefixes are explained later (@pxref{Program and Library Variables})
2120 (@pxref{Man Pages}).
2121
2122
2123 @node Length Limitations
2124 @section Staying below the command line length limit
2125
2126 @cindex command line length limit
2127 @cindex ARG_MAX
2128
2129 Traditionally, most unix-like systems have a length limitation for the
2130 command line arguments and environment contents when creating new
2131 processes (see for example
2132 @uref{http://www.in-ulm.de/@/~mascheck/@/various/@/argmax/} for an
2133 overview on this issue),
2134 which of course also applies to commands spawned by @command{make}.
2135 POSIX requires this limit to be at least 4096 bytes, and most modern
2136 systems have quite high limits (or are unlimited).
2137
2138 In order to create portable Makefiles that do not trip over these
2139 limits, it is necessary to keep the length of file lists bounded.
2140 Unfortunately, it is not possible to do so fully transparently within
2141 Automake, so your help may be needed.  Typically, you can split long
2142 file lists manually and use different installation directory names for
2143 each list.  For example,
2144
2145 @example
2146 data_DATA = file1 @dots{} file@var{N} file@var{N+1} @dots{} file@var{2N}
2147 @end example
2148
2149 @noindent
2150 may also be written as
2151
2152 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2153 @example
2154 data_DATA = file1 @dots{} file@var{N}
2155 data2dir = $(datadir)
2156 data2_DATA = file@var{N+1} @dots{} file@var{2N}
2157 @end example
2158
2159 @noindent
2160 and will cause Automake to treat the two lists separately during
2161 @code{make install}.  See @ref{The Two Parts of Install} for choosing
2162 directory names that will keep the ordering of the two parts of
2163 installation Note that @code{make dist} may still only work on a host
2164 with a higher length limit in this example.
2165
2166 Automake itself employs a couple of strategies to avoid long command
2167 lines.  For example, when @samp{$@{srcdir@}/} is prepended to file
2168 names, as can happen with above @code{$(data_DATA)} lists, it limits
2169 the amount of arguments passed to external commands.
2170
2171 Unfortunately, some system's @command{make} commands may prepend
2172 @code{VPATH} prefixes like @samp{$@{srcdir@}/} to file names from the
2173 source tree automatically (@pxref{Automatic Rule Rewriting, , Automatic
2174 Rule Rewriting, autoconf, The Autoconf Manual}).  In this case, the user
2175 may have to switch to use GNU Make, or refrain from using VPATH builds,
2176 in order to stay below the length limit.
2177
2178 For libraries and programs built from many sources, convenience archives
2179 may be used as intermediates in order to limit the object list length
2180 (@pxref{Libtool Convenience Libraries}).
2181
2182
2183 @node Canonicalization
2184 @section How derived variables are named
2185
2186 @cindex canonicalizing Automake variables
2187
2188 Sometimes a Makefile variable name is derived from some text the
2189 maintainer supplies.  For instance, a program name listed in
2190 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
2191 variable.  In cases like this, Automake canonicalizes the text, so that
2192 program names and the like do not have to follow Makefile variable naming
2193 rules.  All characters in the name except for letters, numbers, the
2194 strudel (@@), and the underscore are turned into underscores when making
2195 variable references.
2196
2197 For example, if your program is named @file{sniff-glue}, the derived
2198 variable name would be @samp{sniff_glue_SOURCES}, not
2199 @samp{sniff-glue_SOURCES}.  Similarly the sources for a library named
2200 @file{libmumble++.a} should be listed in the
2201 @samp{libmumble___a_SOURCES} variable.
2202
2203 The strudel is an addition, to make the use of Autoconf substitutions in
2204 variable names less obfuscating.
2205
2206
2207 @node User Variables
2208 @section Variables reserved for the user
2209
2210 @cindex variables, reserved for the user
2211 @cindex user variables
2212
2213 Some @file{Makefile} variables are reserved by the GNU Coding Standards
2214 for the use of the ``user''---the person building the package.  For
2215 instance, @code{CFLAGS} is one such variable.
2216
2217 Sometimes package developers are tempted to set user variables such as
2218 @code{CFLAGS} because it appears to make their job easier.  However,
2219 the package itself should never set a user variable, particularly not
2220 to include switches that are required for proper compilation of the
2221 package.  Since these variables are documented as being for the
2222 package builder, that person rightfully expects to be able to override
2223 any of these variables at build time.
2224
2225 To get around this problem, Automake introduces an automake-specific
2226 shadow variable for each user flag variable.  (Shadow variables are
2227 not introduced for variables like @code{CC}, where they would make no
2228 sense.)  The shadow variable is named by prepending @samp{AM_} to the
2229 user variable's name.  For instance, the shadow variable for
2230 @code{YFLAGS} is @code{AM_YFLAGS}.  The package maintainer---that is,
2231 the author(s) of the @file{Makefile.am} and @file{configure.ac}
2232 files---may adjust these shadow variables however necessary.
2233
2234 @xref{Flag Variables Ordering}, for more discussion about these
2235 variables and how they interact with per-target variables.
2236
2237 @node Auxiliary Programs
2238 @section Programs automake might require
2239
2240 @cindex Programs, auxiliary
2241 @cindex Auxiliary programs
2242
2243 Automake sometimes requires helper programs so that the generated
2244 @file{Makefile} can do its work properly.  There are a fairly large
2245 number of them, and we list them here.
2246
2247 Although all of these files are distributed and installed with
2248 Automake, a couple of them are maintained separately.  The Automake
2249 copies are updated before each release, but we mention the original
2250 source in case you need more recent versions.
2251
2252 @table @code
2253 @item ar-lib
2254 This is a wrapper primarily for the Microsoft lib archiver, to make
2255 it more POSIX-like.
2256
2257 @item compile
2258 This is a wrapper for compilers that do not accept options @option{-c}
2259 and @option{-o} at the same time.  It is only used when absolutely
2260 required.  Such compilers are rare, with the Microsoft C/C++ Compiler
2261 as the most notable exception. This wrapper also makes the following
2262 common options available for that compiler, while performing file name
2263 translation where needed: @option{-I}, @option{-L}, @option{-l},
2264 @option{-Wl,} and @option{-Xlinker}.
2265
2266 @item config.guess
2267 @itemx config.sub
2268 These two programs compute the canonical triplets for the given build,
2269 host, or target architecture.  These programs are updated regularly to
2270 support new architectures and fix probes broken by changes in new
2271 kernel versions.  Each new release of Automake comes with up-to-date
2272 copies of these programs.  If your copy of Automake is getting old,
2273 you are encouraged to fetch the latest versions of these files from
2274 @url{http://savannah.gnu.org/git/?group=config} before making a
2275 release.
2276
2277 @item depcomp
2278 This program understands how to run a compiler so that it will
2279 generate not only the desired output but also dependency information
2280 that is then used by the automatic dependency tracking feature
2281 (@pxref{Dependencies}).
2282
2283 @item install-sh
2284 This is a replacement for the @command{install} program that works on
2285 platforms where @command{install} is unavailable or unusable.
2286
2287 @item mdate-sh
2288 This script is used to generate a @file{version.texi} file.  It examines
2289 a file and prints some date information about it.
2290
2291 @item missing
2292 This wraps a number of programs that are typically only required by
2293 maintainers.  If the program in question doesn't exist, or seems to old,
2294 @command{missing} will print an informative warning before failing out,
2295 to provide the user with more context and information.
2296
2297 @item mkinstalldirs
2298 This script used to be a wrapper around @samp{mkdir -p}, which is not
2299 portable.  Now we prefer to use @samp{install-sh -d} when @command{configure}
2300 finds that @samp{mkdir -p} does not work, this makes one less script to
2301 distribute.
2302
2303 For backward compatibility @file{mkinstalldirs} is still used and
2304 distributed when @command{automake} finds it in a package.  But it is no
2305 longer installed automatically, and it should be safe to remove it.
2306
2307 @item py-compile
2308 This is used to byte-compile Python scripts.
2309
2310 @item test-driver
2311 This implements the default test driver offered by the parallel
2312 testsuite harness.
2313
2314 @item texinfo.tex
2315 Not a program, this file is required for @samp{make dvi}, @samp{make
2316 ps} and @samp{make pdf} to work when Texinfo sources are in the
2317 package.  The latest version can be downloaded from
2318 @url{http://www.gnu.org/software/texinfo/}.
2319
2320 @item ylwrap
2321 This program wraps @command{lex} and @command{yacc} to rename their
2322 output files.  It also ensures that, for instance, multiple
2323 @command{yacc} instances can be invoked in a single directory in
2324 parallel.
2325
2326 @end table
2327
2328
2329 @node Examples
2330 @chapter Some example packages
2331
2332 This section contains two small examples.
2333
2334 The first example (@pxref{Complete}) assumes you have an existing
2335 project already using Autoconf, with handcrafted @file{Makefile}s, and
2336 that you want to convert it to using Automake.  If you are discovering
2337 both tools, it is probably better that you look at the Hello World
2338 example presented earlier (@pxref{Hello World}).
2339
2340 The second example (@pxref{true}) shows how two programs can be built
2341 from the same file, using different compilation parameters.  It
2342 contains some technical digressions that are probably best skipped on
2343 first read.
2344
2345 @menu
2346 * Complete::                    A simple example, start to finish
2347 * true::                        Building true and false
2348 @end menu
2349
2350
2351 @node Complete
2352 @section A simple example, start to finish
2353
2354 @cindex Complete example
2355
2356 Let's suppose you just finished writing @code{zardoz}, a program to make
2357 your head float from vortex to vortex.  You've been using Autoconf to
2358 provide a portability framework, but your @file{Makefile.in}s have been
2359 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
2360
2361 @cindex @code{AM_INIT_AUTOMAKE}, example use
2362
2363 The first step is to update your @file{configure.ac} to include the
2364 commands that @command{automake} needs.  The way to do this is to add an
2365 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
2366
2367 @example
2368 AC_INIT([zardoz], [1.0])
2369 AM_INIT_AUTOMAKE
2370 @dots{}
2371 @end example
2372
2373 Since your program doesn't have any complicating factors (e.g., it
2374 doesn't use @code{gettext}, it doesn't want to build a shared library),
2375 you're done with this part.  That was easy!
2376
2377 @cindex @command{aclocal} program, introduction
2378 @cindex @file{aclocal.m4}, preexisting
2379 @cindex @file{acinclude.m4}, defined
2380
2381 Now you must regenerate @file{configure}.  But to do that, you'll need
2382 to tell @command{autoconf} how to find the new macro you've used.  The
2383 easiest way to do this is to use the @command{aclocal} program to
2384 generate your @file{aclocal.m4} for you.  But wait@dots{} maybe you
2385 already have an @file{aclocal.m4}, because you had to write some hairy
2386 macros for your program.  The @command{aclocal} program lets you put
2387 your own macros into @file{acinclude.m4}, so simply rename and then
2388 run:
2389
2390 @example
2391 mv aclocal.m4 acinclude.m4
2392 aclocal
2393 autoconf
2394 @end example
2395
2396 @cindex @command{zardoz} example
2397
2398 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
2399 Since @code{zardoz} is a user program, you want to install it where the
2400 rest of the user programs go: @code{bindir}.  Additionally,
2401 @code{zardoz} has some Texinfo documentation.  Your @file{configure.ac}
2402 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
2403 @samp{$(LIBOBJS)}.  So here's what you'd write:
2404
2405 @example
2406 bin_PROGRAMS = zardoz
2407 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
2408 zardoz_LDADD = $(LIBOBJS)
2409
2410 info_TEXINFOS = zardoz.texi
2411 @end example
2412
2413 Now you can run @samp{automake --add-missing} to generate your
2414 @file{Makefile.in} and grab any auxiliary files you might need, and
2415 you're done!
2416
2417
2418 @node true
2419 @section Building true and false
2420
2421 @cindex Example, @command{false} and @command{true}
2422 @cindex @command{false} Example
2423 @cindex @command{true} Example
2424
2425 Here is another, trickier example.  It shows how to generate two
2426 programs (@code{true} and @code{false}) from the same source file
2427 (@file{true.c}).  The difficult part is that each compilation of
2428 @file{true.c} requires different @code{cpp} flags.
2429
2430 @example
2431 bin_PROGRAMS = true false
2432 false_SOURCES =
2433 false_LDADD = false.o
2434
2435 true.o: true.c
2436         $(COMPILE) -DEXIT_CODE=0 -c true.c
2437
2438 false.o: true.c
2439         $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
2440 @end example
2441
2442 Note that there is no @code{true_SOURCES} definition.  Automake will
2443 implicitly assume that there is a source file named @file{true.c}
2444 (@pxref{Default _SOURCES}), and
2445 define rules to compile @file{true.o} and link @file{true}.  The
2446 @samp{true.o: true.c} rule supplied by the above @file{Makefile.am},
2447 will override the Automake generated rule to build @file{true.o}.
2448
2449 @code{false_SOURCES} is defined to be empty---that way no implicit value
2450 is substituted.  Because we have not listed the source of
2451 @file{false}, we have to tell Automake how to link the program.  This is
2452 the purpose of the @code{false_LDADD} line.  A @code{false_DEPENDENCIES}
2453 variable, holding the dependencies of the @file{false} target will be
2454 automatically generated by Automake from the content of
2455 @code{false_LDADD}.
2456
2457 The above rules won't work if your compiler doesn't accept both
2458 @option{-c} and @option{-o}.  The simplest fix for this is to introduce a
2459 bogus dependency (to avoid problems with a parallel @command{make}):
2460
2461 @example
2462 true.o: true.c false.o
2463         $(COMPILE) -DEXIT_CODE=0 -c true.c
2464
2465 false.o: true.c
2466         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
2467 @end example
2468
2469 As it turns out, there is also a much easier way to do this same task.
2470 Some of the above technique is useful enough that we've kept the
2471 example in the manual.  However if you were to build @code{true} and
2472 @code{false} in real life, you would probably use per-program
2473 compilation flags, like so:
2474
2475 @c Keep in sync with specflg7.sh and specflg8.sh
2476 @example
2477 bin_PROGRAMS = false true
2478
2479 false_SOURCES = true.c
2480 false_CPPFLAGS = -DEXIT_CODE=1
2481
2482 true_SOURCES = true.c
2483 true_CPPFLAGS = -DEXIT_CODE=0
2484 @end example
2485
2486 In this case Automake will cause @file{true.c} to be compiled twice,
2487 with different flags.  In this instance, the names of the object files
2488 would be chosen by automake; they would be @file{false-true.o} and
2489 @file{true-true.o}. (The name of the object files rarely matters.)
2490
2491 @node automake Invocation
2492 @chapter Creating a @file{Makefile.in}
2493 @c This node used to be named "Invoking automake".  This @anchor
2494 @c allows old links to still work.
2495 @anchor{Invoking automake}
2496
2497 @cindex Multiple @file{configure.ac} files
2498 @cindex Invoking @command{automake}
2499 @cindex @command{automake}, invoking
2500 @cindex Invocation of @command{automake}
2501 @cindex @command{automake}, invocation
2502
2503 To create all the @file{Makefile.in}s for a package, run the
2504 @command{automake} program in the top level directory, with no
2505 arguments.  @command{automake} will automatically find each
2506 appropriate @file{Makefile.am} (by scanning @file{configure.ac};
2507 @pxref{configure}) and generate the corresponding @file{Makefile.in}.
2508 Note that @command{automake} has a rather simplistic view of what
2509 constitutes a package; it assumes that a package has only one
2510 @file{configure.ac}, at the top.  If your package has multiple
2511 @file{configure.ac}s, then you must run @command{automake} in each
2512 directory holding a @file{configure.ac}.  (Alternatively, you may rely
2513 on Autoconf's @command{autoreconf}, which is able to recurse your
2514 package tree and run @command{automake} where appropriate.)
2515
2516 You can optionally give @command{automake} an argument; @file{.am} is
2517 appended to the argument and the result is used as the name of the
2518 input file.  This feature is generally only used to automatically
2519 rebuild an out-of-date @file{Makefile.in}.  Note that
2520 @command{automake} must always be run from the topmost directory of a
2521 project, even if being used to regenerate the @file{Makefile.in} in
2522 some subdirectory.  This is necessary because @command{automake} must
2523 scan @file{configure.ac}, and because @command{automake} uses the
2524 knowledge that a @file{Makefile.in} is in a subdirectory to change its
2525 behavior in some cases.
2526
2527 @vindex AUTOCONF
2528 Automake will run @command{autoconf} to scan @file{configure.ac} and
2529 its dependencies (i.e., @file{aclocal.m4} and any included file),
2530 therefore @command{autoconf} must be in your @env{PATH}.  If there is
2531 an @env{AUTOCONF} variable in your environment it will be used
2532 instead of @command{autoconf}, this allows you to select a particular
2533 version of Autoconf.  By the way, don't misunderstand this paragraph:
2534 @command{automake} runs @command{autoconf} to @strong{scan} your
2535 @file{configure.ac}, this won't build @file{configure} and you still
2536 have to run @command{autoconf} yourself for this purpose.
2537
2538 @cindex @command{automake} options
2539 @cindex Options, @command{automake}
2540 @cindex Strictness, command line
2541
2542 @command{automake} accepts the following options:
2543
2544 @cindex Extra files distributed with Automake
2545 @cindex Files distributed with Automake
2546 @cindex @file{config.guess}
2547
2548 @table @code
2549 @item -a
2550 @itemx --add-missing
2551 @opindex -a
2552 @opindex --add-missing
2553 Automake requires certain common files to exist in certain situations;
2554 for instance, @file{config.guess} is required if @file{configure.ac} invokes
2555 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
2556 files (@pxref{Auxiliary Programs}); this option will cause the missing
2557 ones to be automatically added to the package, whenever possible.  In
2558 general if Automake tells you a file is missing, try using this option.
2559 By default Automake tries to make a symbolic link pointing to its own
2560 copy of the missing file; this can be changed with @option{--copy}.
2561
2562 Many of the potentially-missing files are common scripts whose
2563 location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
2564 Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
2565 file is considered missing, and where the missing file is added
2566 (@pxref{Optional}).
2567
2568 In some strictness modes, additional files are installed, see @ref{Gnits}
2569 for more information.
2570
2571 @item --libdir=@var{dir}
2572 @opindex --libdir
2573 Look for Automake data files in directory @var{dir} instead of in the
2574 installation directory.  This is typically used for debugging.
2575
2576 @item --print-libdir
2577 @opindex --print-libdir
2578 Print the path of the installation directory containing Automake-provided
2579 scripts and data files (like e.g., @file{texinfo.texi} and
2580 @file{install-sh}).
2581
2582 @item -c
2583 @opindex -c
2584 @itemx --copy
2585 @opindex --copy
2586 When used with @option{--add-missing}, causes installed files to be
2587 copied.  The default is to make a symbolic link.
2588
2589 @item -f
2590 @opindex -f
2591 @itemx --force-missing
2592 @opindex --force-missing
2593 When used with @option{--add-missing}, causes standard files to be reinstalled
2594 even if they already exist in the source tree.  This involves removing
2595 the file from the source tree before creating the new symlink (or, with
2596 @option{--copy}, copying the new file).
2597
2598 @item --foreign
2599 @opindex --foreign
2600 Set the global strictness to @option{foreign}.  For more information, see
2601 @ref{Strictness}.
2602
2603 @item --gnits
2604 @opindex --gnits
2605 Set the global strictness to @option{gnits}.  For more information, see
2606 @ref{Gnits}.
2607
2608 @item --gnu
2609 @opindex --gnu
2610 Set the global strictness to @option{gnu}.  For more information, see
2611 @ref{Gnits}.  This is the default strictness.
2612
2613 @item --help
2614 @opindex --help
2615 Print a summary of the command line options and exit.
2616
2617 @item -i
2618 @itemx --ignore-deps
2619 @opindex -i
2620 This disables the dependency tracking feature in generated
2621 @file{Makefile}s; see @ref{Dependencies}.
2622
2623 @item --include-deps
2624 @opindex --include-deps
2625 This enables the dependency tracking feature.  This feature is enabled
2626 by default.  This option is provided for historical reasons only and
2627 probably should not be used.
2628
2629 @item --no-force
2630 @opindex --no-force
2631 Ordinarily @command{automake} creates all @file{Makefile.in}s mentioned in
2632 @file{configure.ac}.  This option causes it to only update those
2633 @file{Makefile.in}s that are out of date with respect to one of their
2634 dependents.
2635
2636 @item -o @var{dir}
2637 @itemx --output-dir=@var{dir}
2638 @opindex -o
2639 @opindex --output-dir
2640 Put the generated @file{Makefile.in} in the directory @var{dir}.
2641 Ordinarily each @file{Makefile.in} is created in the directory of the
2642 corresponding @file{Makefile.am}.  This option is deprecated and will be
2643 removed in a future release.
2644
2645 @item -v
2646 @itemx --verbose
2647 @opindex -v
2648 @opindex --verbose
2649 Cause Automake to print information about which files are being read or
2650 created.
2651
2652 @item --version
2653 @opindex --version
2654 Print the version number of Automake and exit.
2655
2656 @item -W CATEGORY
2657 @itemx --warnings=@var{category}
2658 @opindex -W
2659 @opindex --warnings
2660 Output warnings falling in @var{category}.  @var{category} can be
2661 one of:
2662 @table @code
2663 @item gnu
2664 warnings related to the GNU Coding Standards
2665 (@pxref{Top, , , standards, The GNU Coding Standards}).
2666 @item obsolete
2667 obsolete features or constructions
2668 @item override
2669 user redefinitions of Automake rules or variables
2670 @item portability
2671 portability issues (e.g., use of @command{make} features that are
2672 known to be not portable)
2673 @item extra-portability
2674 extra portability issues related to obscure tools.  One example of such
2675 a tool is the Microsoft @command{lib} archiver.
2676 @item syntax
2677 weird syntax, unused variables, typos
2678 @item unsupported
2679 unsupported or incomplete features
2680 @item all
2681 all the warnings
2682 @item none
2683 turn off all the warnings
2684 @item error
2685 treat warnings as errors
2686 @end table
2687
2688 A category can be turned off by prefixing its name with @samp{no-}.  For
2689 instance, @option{-Wno-syntax} will hide the warnings about unused
2690 variables.
2691
2692 The categories output by default are @samp{obsolete}, @samp{syntax} and
2693 @samp{unsupported}.  Additionally, @samp{gnu} and @samp{portability}
2694 are enabled in @option{--gnu} and @option{--gnits} strictness.
2695
2696 @c Checked by extra-portability.sh
2697 Turning off @samp{portability} will also turn off @samp{extra-portability},
2698 and similarly turning on @samp{extra-portability} will also turn on
2699 @samp{portability}.  However, turning on @samp{portability} or turning
2700 off @samp{extra-portability} will not affect the other category.
2701
2702 @vindex WARNINGS
2703 The environment variable @env{WARNINGS} can contain a comma separated
2704 list of categories to enable.  It will be taken into account before the
2705 command-line switches, this way @option{-Wnone} will also ignore any
2706 warning category enabled by @env{WARNINGS}.  This variable is also used
2707 by other tools like @command{autoconf}; unknown categories are ignored
2708 for this reason.
2709
2710 @end table
2711
2712 @vindex AUTOMAKE_JOBS
2713 If the environment variable @env{AUTOMAKE_JOBS} contains a positive
2714 number, it is taken as the maximum number of Perl threads to use in
2715 @command{automake} for generating multiple @file{Makefile.in} files
2716 concurrently.  This is an experimental feature.
2717
2718
2719 @node configure
2720 @chapter Scanning @file{configure.ac}, using @command{aclocal}
2721
2722 @cindex @file{configure.ac}, scanning
2723 @cindex Scanning @file{configure.ac}
2724 @cindex Using @command{aclocal}
2725 @cindex @command{aclocal}, using
2726
2727 Automake scans the package's @file{configure.ac} to determine certain
2728 information about the package.  Some @command{autoconf} macros are required
2729 and some variables must be defined in @file{configure.ac}.  Automake
2730 will also use information from @file{configure.ac} to further tailor its
2731 output.
2732
2733 Automake also supplies some Autoconf macros to make the maintenance
2734 easier.  These macros can automatically be put into your
2735 @file{aclocal.m4} using the @command{aclocal} program.
2736
2737 @menu
2738 * Requirements::                Configuration requirements
2739 * Optional::                    Other things Automake recognizes
2740 * aclocal Invocation::          Auto-generating aclocal.m4
2741 * Macros::                      Autoconf macros supplied with Automake
2742 @end menu
2743
2744
2745 @node Requirements
2746 @section Configuration requirements
2747
2748 @cindex Automake requirements
2749 @cindex Requirements of Automake
2750
2751 @acindex AM_INIT_AUTOMAKE
2752 The one real requirement of Automake is that your @file{configure.ac}
2753 call @code{AM_INIT_AUTOMAKE}.  This macro does several things that are
2754 required for proper Automake operation (@pxref{Macros}).
2755
2756 Here are the other macros that Automake requires but which are not run
2757 by @code{AM_INIT_AUTOMAKE}:
2758
2759 @table @code
2760 @item AC_CONFIG_FILES
2761 @itemx AC_OUTPUT
2762 @acindex AC_CONFIG_FILES
2763 @acindex AC_OUTPUT
2764 These two macros are usually invoked as follows near the end of
2765 @file{configure.ac}.
2766
2767 @example
2768 @dots{}
2769 AC_CONFIG_FILES([
2770   Makefile
2771   doc/Makefile
2772   src/Makefile
2773   src/lib/Makefile
2774   @dots{}
2775 ])
2776 AC_OUTPUT
2777 @end example
2778
2779 Automake uses these to determine which files to create (@pxref{Output, ,
2780 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
2781 is considered to be an Automake generated @file{Makefile} if there
2782 exists a file with the same name and the @file{.am} extension appended.
2783 Typically, @samp{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
2784 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
2785
2786 When using @code{AC_CONFIG_FILES} with multiple input files, as in
2787
2788 @example
2789 AC_CONFIG_FILES([Makefile:top.in:Makefile.in:bot.in])
2790 @end example
2791
2792 @noindent
2793 @command{automake} will generate the first @file{.in} input file for
2794 which a @file{.am} file exists.  If no such file exists the output
2795 file is not considered to be generated by Automake.
2796
2797 Files created by @code{AC_CONFIG_FILES}, be they Automake
2798 @file{Makefile}s or not, are all removed by @samp{make distclean}.
2799 Their inputs are automatically distributed, unless they
2800 are the output of prior @code{AC_CONFIG_FILES} commands.
2801 Finally, rebuild rules are generated in the Automake @file{Makefile}
2802 existing in the subdirectory of the output file, if there is one, or
2803 in the top-level @file{Makefile} otherwise.
2804
2805 The above machinery (cleaning, distributing, and rebuilding) works
2806 fine if the @code{AC_CONFIG_FILES} specifications contain only
2807 literals.  If part of the specification uses shell variables,
2808 @command{automake} will not be able to fulfill this setup, and you will
2809 have to complete the missing bits by hand.  For instance, on
2810
2811 @c Keep in sync with output11.sh
2812 @example
2813 file=input
2814 @dots{}
2815 AC_CONFIG_FILES([output:$file],, [file=$file])
2816 @end example
2817
2818 @noindent
2819 @command{automake} will output rules to clean @file{output}, and
2820 rebuild it.  However the rebuild rule will not depend on @file{input},
2821 and this file will not be distributed either.  (You must add
2822 @samp{EXTRA_DIST = input} to your @file{Makefile.am} if @file{input} is a
2823 source file.)
2824
2825 Similarly
2826
2827 @c Keep in sync with output11.sh
2828 @example
2829 file=output
2830 file2=out:in
2831 @dots{}
2832 AC_CONFIG_FILES([$file:input],, [file=$file])
2833 AC_CONFIG_FILES([$file2],, [file2=$file2])
2834 @end example
2835
2836 @noindent
2837 will only cause @file{input} to be distributed.  No file will be
2838 cleaned automatically (add @samp{DISTCLEANFILES = output out}
2839 yourself), and no rebuild rule will be output.
2840
2841 Obviously @command{automake} cannot guess what value @samp{$file} is
2842 going to hold later when @file{configure} is run, and it cannot use
2843 the shell variable @samp{$file} in a @file{Makefile}.  However, if you
2844 make reference to @samp{$file} as @samp{$@{file@}} (i.e., in a way
2845 that is compatible with @command{make}'s syntax) and furthermore use
2846 @code{AC_SUBST} to ensure that @samp{$@{file@}} is meaningful in a
2847 @file{Makefile}, then @command{automake} will be able to use
2848 @samp{$@{file@}} to generate all of these rules.  For instance, here is
2849 how the Automake package itself generates versioned scripts for its
2850 test suite:
2851
2852 @example
2853 AC_SUBST([APIVERSION], @dots{})
2854 @dots{}
2855 AC_CONFIG_FILES(
2856   [tests/aclocal-$@{APIVERSION@}:tests/aclocal.in],
2857   [chmod +x tests/aclocal-$@{APIVERSION@}],
2858   [APIVERSION=$APIVERSION])
2859 AC_CONFIG_FILES(
2860   [tests/automake-$@{APIVERSION@}:tests/automake.in],
2861   [chmod +x tests/automake-$@{APIVERSION@}])
2862 @end example
2863
2864 @noindent
2865 Here cleaning, distributing, and rebuilding are done automatically,
2866 because @samp{$@{APIVERSION@}} is known at @command{make}-time.
2867
2868 Note that you should not use shell variables to declare
2869 @file{Makefile} files for which @command{automake} must create
2870 @file{Makefile.in}.  Even @code{AC_SUBST} does not help here, because
2871 @command{automake} needs to know the file name when it runs in order
2872 to check whether @file{Makefile.am} exists.  (In the very hairy case
2873 that your setup requires such use of variables, you will have to tell
2874 Automake which @file{Makefile.in}s to generate on the command-line.)
2875
2876 It is possible to let @command{automake} emit conditional rules for
2877 @code{AC_CONFIG_FILES} with the help of @code{AM_COND_IF}
2878 (@pxref{Optional}).
2879
2880 To summarize:
2881 @itemize @bullet
2882 @item
2883 Use literals for @file{Makefile}s, and for other files whenever possible.
2884 @item
2885 Use @samp{$file} (or @samp{$@{file@}} without @samp{AC_SUBST([file])})
2886 for files that @command{automake} should ignore.
2887 @item
2888 Use @samp{$@{file@}} and @samp{AC_SUBST([file])} for files
2889 that @command{automake} should not ignore.
2890 @end itemize
2891
2892 @end table
2893
2894
2895 @node Optional
2896 @section Other things Automake recognizes
2897
2898 @cindex Macros Automake recognizes
2899 @cindex Recognized macros by Automake
2900
2901 Every time Automake is run it calls Autoconf to trace
2902 @file{configure.ac}.  This way it can recognize the use of certain
2903 macros and tailor the generated @file{Makefile.in} appropriately.
2904 Currently recognized macros and their effects are:
2905
2906 @ftable @code
2907 @item AC_CANONICAL_BUILD
2908 @itemx AC_CANONICAL_HOST
2909 @itemx AC_CANONICAL_TARGET
2910 @vindex build_triplet
2911 @vindex host_triplet
2912 @vindex target_triplet
2913 Automake will ensure that @file{config.guess} and @file{config.sub}
2914 exist.  Also, the @file{Makefile} variables @code{build_triplet},
2915 @code{host_triplet} and @code{target_triplet} are introduced.  See
2916 @ref{Canonicalizing, , Getting the Canonical System Type, autoconf,
2917 The Autoconf Manual}.
2918
2919 @item AC_CONFIG_AUX_DIR
2920 Automake will look for various helper scripts, such as
2921 @file{install-sh}, in the directory named in this macro invocation.
2922 @c This list is accurate relative to version 1.11
2923 (The full list of scripts is:
2924 @file{ar-lib},
2925 @file{config.guess},
2926 @file{config.sub},
2927 @file{depcomp},
2928 @file{compile},
2929 @file{install-sh},
2930 @file{ltmain.sh},
2931 @file{mdate-sh},
2932 @file{missing},
2933 @file{mkinstalldirs},
2934 @file{py-compile},
2935 @file{test-driver},
2936 @file{texinfo.tex},
2937 @file{ylwrap}.)
2938 Not all scripts are always searched for; some scripts
2939 will only be sought if the generated @file{Makefile.in} requires them.
2940
2941 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
2942 their standard locations.  For @file{mdate-sh},
2943 @file{texinfo.tex}, and @file{ylwrap}, the standard location is the
2944 source directory corresponding to the current @file{Makefile.am}.  For
2945 the rest, the standard location is the first one of @file{.}, @file{..},
2946 or @file{../..} (relative to the top source directory) that provides any
2947 one of the helper scripts.  @xref{Input, , Finding `configure' Input,
2948 autoconf, The Autoconf Manual}.
2949
2950 Required files from @code{AC_CONFIG_AUX_DIR} are automatically
2951 distributed, even if there is no @file{Makefile.am} in this directory.
2952
2953 @item AC_CONFIG_LIBOBJ_DIR
2954 Automake will require the sources file declared with
2955 @code{AC_LIBSOURCE} (see below) in the directory specified by this
2956 macro.
2957
2958 @item AC_CONFIG_HEADERS
2959 Automake will generate rules to rebuild these headers.  Older versions
2960 of Automake required the use of @code{AM_CONFIG_HEADER}; this is no
2961 longer the case, and that macro has indeed been removed.
2962
2963 As with @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2964 specification using shell variables will be ignored as far as
2965 cleaning, distributing, and rebuilding is concerned.
2966
2967 @item AC_CONFIG_LINKS
2968 Automake will generate rules to remove @file{configure} generated
2969 links on @samp{make distclean} and to distribute named source files as
2970 part of @samp{make dist}.
2971
2972 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2973 specification using shell variables will be ignored as far as cleaning
2974 and distributing is concerned.  (There are no rebuild rules for links.)
2975
2976 @item AC_LIBOBJ
2977 @itemx AC_LIBSOURCE
2978 @itemx AC_LIBSOURCES
2979 @vindex LIBOBJS
2980 Automake will automatically distribute any file listed in
2981 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
2982
2983 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}.  So if
2984 an Autoconf macro is documented to call @samp{AC_LIBOBJ([file])}, then
2985 @file{file.c} will be distributed automatically by Automake.  This
2986 encompasses many macros like @code{AC_FUNC_ALLOCA},
2987 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
2988
2989 By the way, direct assignments to @code{LIBOBJS} are no longer
2990 supported.  You should always use @code{AC_LIBOBJ} for this purpose.
2991 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
2992 autoconf, The Autoconf Manual}.
2993
2994 @item AC_PROG_RANLIB
2995 This is required if any libraries are built in the package.
2996 @xref{Particular Programs, , Particular Program Checks, autoconf, The
2997 Autoconf Manual}.
2998
2999 @item AC_PROG_CXX
3000 This is required if any C++ source is included.  @xref{Particular
3001 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3002
3003 @item AC_PROG_OBJC
3004 This is required if any Objective C source is included.  @xref{Particular
3005 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3006
3007 @item AC_PROG_OBJCXX
3008 This is required if any Objective C++ source is included.  @xref{Particular
3009 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3010
3011 @item AC_PROG_F77
3012 This is required if any Fortran 77 source is included.  @xref{Particular
3013 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3014
3015 @item AC_F77_LIBRARY_LDFLAGS
3016 This is required for programs and shared libraries that are a mixture of
3017 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
3018 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
3019
3020 @item AC_FC_SRCEXT
3021 Automake will add the flags computed by @code{AC_FC_SRCEXT} to compilation
3022 of files with the respective source extension (@pxref{Fortran Compiler, ,
3023 Fortran Compiler Characteristics, autoconf, The Autoconf Manual}).
3024
3025 @item AC_PROG_FC
3026 This is required if any Fortran 90/95 source is included.  This macro is
3027 distributed with Autoconf version 2.58 and later.  @xref{Particular
3028 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3029
3030 @item AC_PROG_LIBTOOL
3031 Automake will turn on processing for @command{libtool} (@pxref{Top, ,
3032 Introduction, libtool, The Libtool Manual}).
3033
3034 @item AC_PROG_YACC
3035 @vindex YACC
3036 If a Yacc source file is seen, then you must either use this macro or
3037 define the variable @code{YACC} in @file{configure.ac}.  The former is
3038 preferred (@pxref{Particular Programs, , Particular Program Checks,
3039 autoconf, The Autoconf Manual}).
3040
3041 @item AC_PROG_LEX
3042 If a Lex source file is seen, then this macro must be used.
3043 @xref{Particular Programs, , Particular Program Checks, autoconf, The
3044 Autoconf Manual}.
3045
3046 @item AC_REQUIRE_AUX_FILE
3047 For each @code{AC_REQUIRE_AUX_FILE([@var{file}])},
3048 @command{automake} will ensure that @file{@var{file}} exists in the
3049 aux directory, and will complain otherwise.  It
3050 will also automatically distribute the file.  This macro should be
3051 used by third-party Autoconf macros that require some supporting
3052 files in the aux directory specified with @code{AC_CONFIG_AUX_DIR}
3053 above.  @xref{Input, , Finding @command{configure} Input, autoconf,
3054 The Autoconf Manual}.
3055
3056 @item AC_SUBST
3057 The first argument is automatically defined as a variable in each
3058 generated @file{Makefile.in}, unless @code{AM_SUBST_NOTMAKE} is also
3059 used for this variable.  @xref{Setting Output Variables, , Setting
3060 Output Variables, autoconf, The Autoconf Manual}.
3061
3062 For every substituted variable @var{var}, @command{automake} will add
3063 a line @code{@var{var} = @var{value}} to each @file{Makefile.in} file.
3064 Many Autoconf macros invoke @code{AC_SUBST} to set output variables
3065 this way, e.g., @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and
3066 @code{X_LIBS}.  Thus, you can access these variables as
3067 @code{$(X_CFLAGS)} and @code{$(X_LIBS)} in any @file{Makefile.am}
3068 if @code{AC_PATH_XTRA} is called.
3069
3070 @item AM_CONDITIONAL
3071 This introduces an Automake conditional (@pxref{Conditionals}).
3072
3073 @item AM_COND_IF
3074 This macro allows @code{automake} to detect subsequent access within
3075 @file{configure.ac} to a conditional previously introduced with
3076 @code{AM_CONDITIONAL}, thus enabling conditional @code{AC_CONFIG_FILES}
3077 (@pxref{Usage of Conditionals}).
3078
3079 @item AM_GNU_GETTEXT
3080 This macro is required for packages that use GNU gettext
3081 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
3082 this macro it ensures that the package meets some of gettext's
3083 requirements.
3084
3085 @item AM_GNU_GETTEXT_INTL_SUBDIR
3086 This macro specifies that the @file{intl/} subdirectory is to be built,
3087 even if the @code{AM_GNU_GETTEXT} macro was invoked with a first argument
3088 of @samp{external}.
3089
3090 @item AM_MAINTAINER_MODE(@ovar{default-mode})
3091 @opindex --enable-maintainer-mode
3092 @opindex --disable-maintainer-mode
3093 This macro adds an @option{--enable-maintainer-mode} option to
3094 @command{configure}.  If this is used, @command{automake} will cause
3095 ``maintainer-only'' rules to be turned off by default in the
3096 generated @file{Makefile.in}s, unless @var{default-mode} is
3097 @samp{enable}.  This macro defines the @code{MAINTAINER_MODE}
3098 conditional, which you can use in your own @file{Makefile.am}.
3099 @xref{maintainer-mode}.
3100
3101 @item AM_SUBST_NOTMAKE(@var{var})
3102 Prevent Automake from defining a variable @var{var}, even if it is
3103 substituted by @command{config.status}.  Normally, Automake defines a
3104 @command{make} variable for each @command{configure} substitution,
3105 i.e., for each @code{AC_SUBST([@var{var}])}.  This macro prevents that
3106 definition from Automake.  If @code{AC_SUBST} has not been called
3107 for this variable, then @code{AM_SUBST_NOTMAKE} has no effects.
3108 Preventing variable definitions may be useful for substitution of
3109 multi-line values, where @code{@var{var} = @@@var{value}@@} might yield
3110 unintended results.
3111
3112 @item m4_include
3113 Files included by @file{configure.ac} using this macro will be
3114 detected by Automake and automatically distributed.  They will also
3115 appear as dependencies in @file{Makefile} rules.
3116
3117 @code{m4_include} is seldom used by @file{configure.ac} authors, but
3118 can appear in @file{aclocal.m4} when @command{aclocal} detects that
3119 some required macros come from files local to your package (as opposed to
3120 macros installed in a system-wide directory, @pxref{aclocal Invocation}).
3121
3122 @end ftable
3123
3124 @node aclocal Invocation
3125 @section Auto-generating aclocal.m4
3126 @c This node used to be named "Invoking automake".  This @anchor
3127 @c allows old links to still work.
3128 @anchor{Invoking aclocal}
3129
3130 @cindex Invocation of @command{aclocal}
3131 @cindex @command{aclocal}, Invocation
3132 @cindex Invoking @command{aclocal}
3133 @cindex @command{aclocal}, Invoking
3134
3135 Automake includes a number of Autoconf macros that can be used in
3136 your package (@pxref{Macros}); some of them are actually required by
3137 Automake in certain situations.  These macros must be defined in your
3138 @file{aclocal.m4}; otherwise they will not be seen by
3139 @command{autoconf}.
3140
3141 The @command{aclocal} program will automatically generate
3142 @file{aclocal.m4} files based on the contents of @file{configure.ac}.
3143 This provides a convenient way to get Automake-provided macros,
3144 without having to search around.  The @command{aclocal} mechanism
3145 allows other packages to supply their own macros (@pxref{Extending
3146 aclocal}).  You can also use it to maintain your own set of custom
3147 macros (@pxref{Local Macros}).
3148
3149 At startup, @command{aclocal} scans all the @file{.m4} files it can
3150 find, looking for macro definitions (@pxref{Macro Search Path}).  Then
3151 it scans @file{configure.ac}.  Any mention of one of the macros found
3152 in the first step causes that macro, and any macros it in turn
3153 requires, to be put into @file{aclocal.m4}.
3154
3155 @emph{Putting} the file that contains the macro definition into
3156 @file{aclocal.m4} is usually done by copying the entire text of this
3157 file, including unused macro definitions as well as both @samp{#} and
3158 @samp{dnl} comments.  If you want to make a comment that will be
3159 completely ignored by @command{aclocal}, use @samp{##} as the comment
3160 leader.
3161
3162 When a file selected by @command{aclocal} is located in a subdirectory
3163 specified as a relative search path with @command{aclocal}'s @option{-I}
3164 argument, @command{aclocal} assumes the file belongs to the package
3165 and uses @code{m4_include} instead of copying it into
3166 @file{aclocal.m4}.  This makes the package smaller, eases dependency
3167 tracking, and cause the file to be distributed automatically.
3168 (@xref{Local Macros}, for an example.)  Any macro that is found in a
3169 system-wide directory, or via an absolute search path will be copied.
3170 So use @samp{-I `pwd`/reldir} instead of @samp{-I reldir} whenever
3171 some relative directory should be considered outside the package.
3172
3173 The contents of @file{acinclude.m4}, if this file exists, are also
3174 automatically included in @file{aclocal.m4}.  We recommend against
3175 using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
3176
3177 @vindex AUTOM4TE
3178 @cindex autom4te
3179 While computing @file{aclocal.m4}, @command{aclocal} runs
3180 @command{autom4te} (@pxref{Using autom4te, , Using @command{Autom4te},
3181 autoconf, The Autoconf Manual}) in order to trace the macros that are
3182 really used, and omit from @file{aclocal.m4} all macros that are
3183 mentioned but otherwise unexpanded (this can happen when a macro is
3184 called conditionally).  @command{autom4te} is expected to be in the
3185 @env{PATH}, just as @command{autoconf}.  Its location can be
3186 overridden using the @env{AUTOM4TE} environment variable.
3187
3188 @menu
3189 * aclocal Options::             Options supported by aclocal
3190 * Macro Search Path::           How aclocal finds .m4 files
3191 * Extending aclocal::           Writing your own aclocal macros
3192 * Local Macros::                Organizing local macros
3193 * Serials::                     Serial lines in Autoconf macros
3194 * Future of aclocal::           aclocal's scheduled death
3195 @end menu
3196
3197 @node aclocal Options
3198 @subsection aclocal Options
3199
3200 @cindex @command{aclocal}, Options
3201 @cindex Options, @command{aclocal}
3202
3203 @command{aclocal} accepts the following options:
3204
3205 @table @code
3206 @item --automake-acdir=@var{dir}
3207 @opindex --automake-acdir
3208 Look for the automake-provided macro files in @var{dir} instead of
3209 in the installation directory.  This is typically used for debugging.
3210
3211 @item --system-acdir=@var{dir}
3212 @opindex --system-acdir
3213 Look for the system-wide third-party macro files (and the special
3214 @file{dirlist} file) in @var{dir} instead of in the installation
3215 directory.  This is typically used for debugging.
3216
3217 @item --diff[=@var{command}]
3218 @opindex --diff
3219 Run @var{command} on M4 file that would be installed or overwritten
3220 by @option{--install}.  The default @var{command} is @samp{diff -u}.
3221 This option implies @option{--install} and @option{--dry-run}.
3222
3223 @item --dry-run
3224 @opindex --dry-run
3225 Do not actually overwrite (or create) @file{aclocal.m4} and M4
3226 files installed by @option{--install}.
3227
3228 @item --help
3229 @opindex --help
3230 Print a summary of the command line options and exit.
3231
3232 @item -I @var{dir}
3233 @opindex -I
3234 Add the directory @var{dir} to the list of directories searched for
3235 @file{.m4} files.
3236
3237 @item --install
3238 @opindex --install
3239 Install system-wide third-party macros into the first directory
3240 specified with @samp{-I @var{dir}} instead of copying them in the
3241 output file.
3242 @c Keep in sync with aclocal-install-absdir.sh
3243 Note that this will happen also if @var{dir} is an absolute path.
3244
3245 @cindex serial number and @option{--install}
3246 When this option is used, and only when this option is used,
3247 @command{aclocal} will also honor @samp{#serial @var{number}} lines
3248 that appear in macros: an M4 file is ignored if there exists another
3249 M4 file with the same basename and a greater serial number in the
3250 search path (@pxref{Serials}).
3251
3252 @item --force
3253 @opindex --force
3254 Always overwrite the output file.  The default is to overwrite the output
3255 file only when really needed, i.e., when its contents changes or if one
3256 of its dependencies is younger.
3257
3258 This option forces the update of @file{aclocal.m4} (or the file
3259 specified with @file{--output} below) and only this file, it has
3260 absolutely no influence on files that may need to be installed by
3261 @option{--install}.
3262
3263 @item --output=@var{file}
3264 @opindex --output
3265 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
3266
3267 @item --print-ac-dir
3268 @opindex --print-ac-dir
3269 Prints the name of the directory that @command{aclocal} will search to
3270 find third-party @file{.m4} files.  When this option is given, normal
3271 processing is suppressed.  This option was used @emph{in the past} by
3272 third-party packages to determine where to install @file{.m4} macro
3273 files, but @emph{this usage is today discouraged}, since it causes
3274 @samp{$(prefix)} not to be thoroughly honoured (which violates the
3275 GNU Coding Standards), and a similar semantics can be better obtained
3276 with the @env{ACLOCAL_PATH} environment variable; @pxref{Extending aclocal}.
3277
3278 @item --verbose
3279 @opindex --verbose
3280 Print the names of the files it examines.
3281
3282 @item --version
3283 @opindex --version
3284 Print the version number of Automake and exit.
3285
3286 @item -W CATEGORY
3287 @item --warnings=@var{category}
3288 @opindex -W
3289 @opindex --warnings
3290 Output warnings falling in @var{category}.  @var{category} can be
3291 one of:
3292 @table @code
3293 @item syntax
3294 dubious syntactic constructs, underquoted macros, unused macros, etc.
3295 @item unsupported
3296 unknown macros
3297 @item all
3298 all the warnings, this is the default
3299 @item none
3300 turn off all the warnings
3301 @item error
3302 treat warnings as errors
3303 @end table
3304
3305 All warnings are output by default.
3306
3307 @vindex WARNINGS
3308 The environment variable @env{WARNINGS} is honored in the same
3309 way as it is for @command{automake} (@pxref{automake Invocation}).
3310
3311 @end table
3312
3313 @node Macro Search Path
3314 @subsection Macro Search Path
3315
3316 @cindex Macro search path
3317 @cindex @command{aclocal} search path
3318
3319 By default, @command{aclocal} searches for @file{.m4} files in the following
3320 directories, in this order:
3321
3322 @table @code
3323 @item @var{acdir-APIVERSION}
3324 This is where the @file{.m4} macros distributed with Automake itself
3325 are stored.  @var{APIVERSION} depends on the Automake release used;
3326 for example, for Automake 1.11.x, @var{APIVERSION} = @code{1.11}.
3327
3328 @item @var{acdir}
3329 This directory is intended for third party @file{.m4} files, and is
3330 configured when @command{automake} itself is built.  This is
3331 @file{@@datadir@@/aclocal/}, which typically
3332 expands to @file{$@{prefix@}/share/aclocal/}.  To find the compiled-in
3333 value of @var{acdir}, use the @option{--print-ac-dir} option
3334 (@pxref{aclocal Options}).
3335 @end table
3336
3337 As an example, suppose that @command{automake-1.11.2} was configured with
3338 @option{--prefix=@-/usr/local}.  Then, the search path would be:
3339
3340 @enumerate
3341 @item @file{/usr/local/share/aclocal-1.11.2/}
3342 @item @file{/usr/local/share/aclocal/}
3343 @end enumerate
3344
3345 The paths for the @var{acdir} and @var{acdir-APIVERSION} directories can
3346 be changed respectively through aclocal options @option{--system-acdir}
3347 and @option{--automake-acdir} (@pxref{aclocal Options}).  Note however
3348 that these options are only intended for use by the internal Automake
3349 test suite, or for debugging under highly unusual situations; they are
3350 not ordinarily needed by end-users.
3351
3352 As explained in (@pxref{aclocal Options}), there are several options that
3353 can be used to change or extend this search path.
3354
3355 @subsubheading Modifying the Macro Search Path: @samp{-I @var{dir}}
3356
3357 Any extra directories specified using @option{-I} options
3358 (@pxref{aclocal Options}) are @emph{prepended} to this search list.  Thus,
3359 @samp{aclocal -I /foo -I /bar} results in the following search path:
3360
3361 @enumerate
3362 @item @file{/foo}
3363 @item @file{/bar}
3364 @item @var{acdir}-@var{APIVERSION}
3365 @item @var{acdir}
3366 @end enumerate
3367
3368 @subsubheading Modifying the Macro Search Path: @file{dirlist}
3369 @cindex @file{dirlist}
3370
3371 There is a third mechanism for customizing the search path.  If a
3372 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
3373 contain a list of directory patterns, one per line.  @command{aclocal}
3374 expands these patterns to directory names, and adds them to the search
3375 list @emph{after} all other directories.  @file{dirlist} entries may
3376 use shell wildcards such as @samp{*}, @samp{?}, or @code{[...]}.
3377
3378 For example, suppose
3379 @file{@var{acdir}/dirlist} contains the following:
3380
3381 @example
3382 /test1
3383 /test2
3384 /test3*
3385 @end example
3386
3387 @noindent
3388 and that @command{aclocal} was called with the @samp{-I /foo -I /bar} options.
3389 Then, the search path would be
3390
3391 @c @code looks better than @file here
3392 @enumerate
3393 @item @code{/foo}
3394 @item @code{/bar}
3395 @item @var{acdir}-@var{APIVERSION}
3396 @item @var{acdir}
3397 @item @code{/test1}
3398 @item @code{/test2}
3399 @end enumerate
3400
3401 @noindent
3402 and all directories with path names starting with @code{/test3}.
3403
3404 If the @option{--system-acdir=@var{dir}} option is used, then
3405 @command{aclocal} will search for the @file{dirlist} file in
3406 @var{dir}; but remember the warnings  above against the use of
3407 @option{--system-acdir}.
3408
3409 @file{dirlist} is useful in the following situation: suppose that
3410 @command{automake} version @code{1.11.2} is installed with
3411 @samp{--prefix=/usr} by the system vendor.  Thus, the default search
3412 directories are
3413
3414 @c @code looks better than @file here
3415 @enumerate
3416 @item @code{/usr/share/aclocal-1.11/}
3417 @item @code{/usr/share/aclocal/}
3418 @end enumerate
3419
3420 However, suppose further that many packages have been manually
3421 installed on the system, with $prefix=/usr/local, as is typical.  In
3422 that case, many of these ``extra'' @file{.m4} files are in
3423 @file{/usr/local/share/aclocal}.  The only way to force
3424 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files is to
3425 always call @samp{aclocal -I /usr/local/share/aclocal}.  This is
3426 inconvenient.  With @file{dirlist}, one may create a file
3427 @file{/usr/share/aclocal/dirlist} containing only the single line
3428
3429 @example
3430 /usr/local/share/aclocal
3431 @end example
3432
3433 Now, the ``default'' search path on the affected system is
3434
3435 @c @code looks better than @file here
3436 @enumerate
3437 @item @code{/usr/share/aclocal-1.11/}
3438 @item @code{/usr/share/aclocal/}
3439 @item @code{/usr/local/share/aclocal/}
3440 @end enumerate
3441
3442 without the need for @option{-I} options; @option{-I} options can be reserved
3443 for project-specific needs (@file{my-source-dir/m4/}), rather than
3444 using it to work around local system-dependent tool installation
3445 directories.
3446
3447 Similarly, @file{dirlist} can be handy if you have installed a local
3448 copy of Automake in your account and want @command{aclocal} to look for
3449 macros installed at other places on the system.
3450
3451 @anchor{ACLOCAL_PATH}
3452 @subsubheading Modifying the Macro Search Path: @file{ACLOCAL_PATH}
3453 @cindex @env{ACLOCAL_PATH}
3454
3455 The fourth and last mechanism to customize the macro search path is
3456 also the simplest.  Any directory included in the colon-separated
3457 environment variable @env{ACLOCAL_PATH} is added to the search path
3458 @c Keep in sync with aclocal-path-precedence.sh
3459 and takes precedence over system directories (including those found via
3460 @file{dirlist}), with the exception of the versioned directory
3461 @var{acdir-APIVERSION} (@pxref{Macro Search Path}).  However, directories
3462 passed via @option{-I} will take precedence over directories in
3463 @env{ACLOCAL_PATH}.
3464
3465 @c Keep in sync with aclocal-path-installed.sh
3466 Also note that, if the @option{--install} option is used, any @file{.m4}
3467 file containing a required macro that is found in a directory listed in
3468 @env{ACLOCAL_PATH} will be installed locally.
3469 @c Keep in sync with aclocal-path-installed-serial.sh
3470 In this case, serial numbers in @file{.m4} are honoured too,
3471 @pxref{Serials}.
3472
3473 Conversely to @file{dirlist}, @env{ACLOCAL_PATH} is useful if you are
3474 using a global copy of Automake and want @command{aclocal} to look for
3475 macros somewhere under your home directory.
3476
3477 @subsubheading Planned future incompatibilities
3478
3479 The order in which the directories in the macro search path are currently
3480 looked up is confusing and/or suboptimal in various aspects, and is
3481 probably going to be changed in the future Automake release.  In
3482 particular, directories in @env{ACLOCAL_PATH} and @file{@var{acdir}}
3483 might end up taking precedence over @file{@var{acdir-APIVERSION}}, and
3484 directories in @file{@var{acdir}/dirlist} might end up taking precedence
3485 over @file{@var{acdir}}.  @emph{This is a possible future incompatibility!}
3486
3487 @node Extending aclocal
3488 @subsection Writing your own aclocal macros
3489
3490 @cindex @command{aclocal}, extending
3491 @cindex Extending @command{aclocal}
3492
3493 The @command{aclocal} program doesn't have any built-in knowledge of any
3494 macros, so it is easy to extend it with your own macros.
3495
3496 This can be used by libraries that want to supply their own Autoconf
3497 macros for use by other programs.  For instance, the @command{gettext}
3498 library supplies a macro @code{AM_GNU_GETTEXT} that should be used by
3499 any package using @command{gettext}.  When the library is installed, it
3500 installs this macro so that @command{aclocal} will find it.
3501
3502 A macro file's name should end in @file{.m4}.  Such files should be
3503 installed in @file{$(datadir)/aclocal}.  This is as simple as writing:
3504
3505 @c Keep in sync with primary-prefix-couples-documented-valid.sh
3506 @example
3507 aclocaldir = $(datadir)/aclocal
3508 aclocal_DATA = mymacro.m4 myothermacro.m4
3509 @end example
3510
3511 @noindent
3512 Please do use @file{$(datadir)/aclocal}, and not something based on
3513 the result of @samp{aclocal --print-ac-dir} (@pxref{Hard-Coded Install
3514 Paths}, for arguments).  It might also be helpful to suggest to
3515 the user to add the @file{$(datadir)/aclocal} directory to his
3516 @env{ACLOCAL_PATH} variable (@pxref{ACLOCAL_PATH}) so that
3517 @command{aclocal} will find the @file{.m4} files installed by your
3518 package automatically.
3519
3520 A file of macros should be a series of properly quoted
3521 @code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
3522 Autoconf Manual}).  The @command{aclocal} programs also understands
3523 @code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
3524 Autoconf Manual}), so it is safe to put each macro in a separate file.
3525 Each file should have no side effects but macro definitions.
3526 Especially, any call to @code{AC_PREREQ} should be done inside the
3527 defined macro, not at the beginning of the file.
3528
3529 @cindex underquoted @code{AC_DEFUN}
3530 @acindex AC_DEFUN
3531 @acindex AC_PREREQ
3532
3533 Starting with Automake 1.8, @command{aclocal} will warn about all
3534 underquoted calls to @code{AC_DEFUN}.  We realize this will annoy a
3535 lot of people, because @command{aclocal} was not so strict in the past
3536 and many third party macros are underquoted; and we have to apologize
3537 for this temporary inconvenience.  The reason we have to be stricter
3538 is that a future implementation of @command{aclocal} (@pxref{Future of
3539 aclocal}) will have to temporarily include all of these third party
3540 @file{.m4} files, maybe several times, including even files that are
3541 not actually needed.  Doing so should alleviate many problems of the
3542 current implementation, however it requires a stricter style from the
3543 macro authors.  Hopefully it is easy to revise the existing macros.
3544 For instance,
3545
3546 @example
3547 # bad style
3548 AC_PREREQ(2.68)
3549 AC_DEFUN(AX_FOOBAR,
3550 [AC_REQUIRE([AX_SOMETHING])dnl
3551 AX_FOO
3552 AX_BAR
3553 ])
3554 @end example
3555
3556 @noindent
3557 should be rewritten as
3558
3559 @example
3560 AC_DEFUN([AX_FOOBAR],
3561 [AC_PREREQ([2.68])dnl
3562 AC_REQUIRE([AX_SOMETHING])dnl
3563 AX_FOO
3564 AX_BAR
3565 ])
3566 @end example
3567
3568 Wrapping the @code{AC_PREREQ} call inside the macro ensures that
3569 Autoconf 2.68 will not be required if @code{AX_FOOBAR} is not actually
3570 used.  Most importantly, quoting the first argument of @code{AC_DEFUN}
3571 allows the macro to be redefined or included twice (otherwise this
3572 first argument would be expanded during the second definition).  For
3573 consistency we like to quote even arguments such as @code{2.68} that
3574 do not require it.
3575
3576 If you have been directed here by the @command{aclocal} diagnostic but
3577 are not the maintainer of the implicated macro, you will want to
3578 contact the maintainer of that macro.  Please make sure you have the
3579 latest version of the macro and that the problem hasn't already been
3580 reported before doing so: people tend to work faster when they aren't
3581 flooded by mails.
3582
3583 Another situation where @command{aclocal} is commonly used is to
3584 manage macros that are used locally by the package, @ref{Local
3585 Macros}.
3586
3587 @node Local Macros
3588 @subsection Handling Local Macros
3589
3590 Feature tests offered by Autoconf do not cover all needs.  People
3591 often have to supplement existing tests with their own macros, or
3592 with third-party macros.
3593
3594 There are two ways to organize custom macros in a package.
3595
3596 The first possibility (the historical practice) is to list all your
3597 macros in @file{acinclude.m4}.  This file will be included in
3598 @file{aclocal.m4} when you run @command{aclocal}, and its macro(s) will
3599 henceforth be visible to @command{autoconf}.  However if it contains
3600 numerous macros, it will rapidly become difficult to maintain, and it
3601 will be almost impossible to share macros between packages.
3602
3603 The second possibility, which we do recommend, is to write each macro
3604 in its own file and gather all these files in a directory.  This
3605 directory is usually called @file{m4/}.  Then it's enough to update
3606 @file{configure.ac} by adding a proper call to @code{AC_CONFIG_MACRO_DIR}:
3607
3608 @example
3609 AC_CONFIG_MACRO_DIR([m4])
3610 @end example
3611
3612 @command{aclocal} will then take care of automatically adding @file{m4/}
3613 to its search path for m4 files.
3614
3615 When @samp{aclocal} is run, it will build an @file{aclocal.m4}
3616 that @code{m4_include}s any file from @file{m4/} that defines a
3617 required macro.  Macros not found locally will still be searched in
3618 system-wide directories, as explained in @ref{Macro Search Path}.
3619
3620 Custom macros should be distributed for the same reason that
3621 @file{configure.ac} is: so that other people have all the sources of
3622 your package if they want to work on it.  Actually, this distribution
3623 happens automatically because all @code{m4_include}d files are
3624 distributed.
3625
3626 However there is no consensus on the distribution of third-party
3627 macros that your package may use.  Many libraries install their own
3628 macro in the system-wide @command{aclocal} directory (@pxref{Extending
3629 aclocal}).  For instance, Guile ships with a file called
3630 @file{guile.m4} that contains the macro @code{GUILE_FLAGS} that can
3631 be used to define setup compiler and linker flags appropriate for
3632 using Guile.  Using @code{GUILE_FLAGS} in @file{configure.ac} will
3633 cause @command{aclocal} to copy @file{guile.m4} into
3634 @file{aclocal.m4}, but as @file{guile.m4} is not part of the project,
3635 it will not be distributed.  Technically, that means a user who
3636 needs to rebuild @file{aclocal.m4} will have to install Guile first.
3637 This is probably OK, if Guile already is a requirement to build the
3638 package.  However, if Guile is only an optional feature, or if your
3639 package might run on architectures where Guile cannot be installed,
3640 this requirement will hinder development.  An easy solution is to copy
3641 such third-party macros in your local @file{m4/} directory so they get
3642 distributed.
3643
3644 Since Automake 1.10, @command{aclocal} offers the option @code{--install}
3645 to copy these system-wide third-party macros in your local macro directory,
3646 helping to solve the above problem.
3647
3648 With this setup, system-wide macros will be copied to @file{m4/}
3649 the first time you run @command{aclocal}.  Then the locally installed
3650 macros will have precedence over the system-wide installed macros
3651 each time @command{aclocal} is run again.
3652
3653 One reason why you should keep @option{--install} in the flags even
3654 after the first run is that when you later edit @file{configure.ac}
3655 and depend on a new macro, this macro will be installed in your
3656 @file{m4/} automatically.  Another one is that serial numbers
3657 (@pxref{Serials}) can be used to update the macros in your source tree
3658 automatically when new system-wide versions are installed.  A serial
3659 number should be a single line of the form
3660
3661 @example
3662 #serial @var{nnn}
3663 @end example
3664
3665 @noindent
3666 where @var{nnn} contains only digits and dots.  It should appear in
3667 the M4 file before any macro definition.  It is a good practice to
3668 maintain a serial number for each macro you distribute, even if you do
3669 not use the @option{--install} option of @command{aclocal}: this allows
3670 other people to use it.
3671
3672
3673 @node Serials
3674 @subsection Serial Numbers
3675 @cindex serial numbers in macros
3676 @cindex macro serial numbers
3677 @cindex @code{#serial} syntax
3678 @cindex @command{aclocal} and serial numbers
3679
3680 Because third-party macros defined in @file{*.m4} files are naturally
3681 shared between multiple projects, some people like to version them.
3682 This makes it easier to tell which of two M4 files is newer.  Since at
3683 least 1996, the tradition is to use a @samp{#serial} line for this.
3684
3685 A serial number should be a single line of the form
3686
3687 @example
3688 # serial @var{version}
3689 @end example
3690
3691 @noindent
3692 where @var{version} is a version number containing only digits and
3693 dots.  Usually people use a single integer, and they increment it each
3694 time they change the macro (hence the name of ``serial'').  Such a
3695 line should appear in the M4 file before any macro definition.
3696
3697 The @samp{#} must be the first character on the line,
3698 and it is OK to have extra words after the version, as in
3699
3700 @example
3701 #serial @var{version} @var{garbage}
3702 @end example
3703
3704 Normally these serial numbers are completely ignored by
3705 @command{aclocal} and @command{autoconf}, like any genuine comment.
3706 However when using @command{aclocal}'s @option{--install} feature, these
3707 serial numbers will modify the way @command{aclocal} selects the
3708 macros to install in the package: if two files with the same basename
3709 exist in your search path, and if at least one of them uses a
3710 @samp{#serial} line, @command{aclocal} will ignore the file that has
3711 the older @samp{#serial} line (or the file that has none).
3712
3713 Note that a serial number applies to a whole M4 file, not to any macro
3714 it contains.  A file can contains multiple macros, but only one
3715 serial.
3716
3717 Here is a use case that illustrates the use of @option{--install} and
3718 its interaction with serial numbers.  Let's assume we maintain a
3719 package called MyPackage, the @file{configure.ac} of which requires a
3720 third-party macro @code{AX_THIRD_PARTY} defined in
3721 @file{/usr/share/aclocal/thirdparty.m4} as follows:
3722
3723 @example
3724 # serial 1
3725 AC_DEFUN([AX_THIRD_PARTY], [...])
3726 @end example
3727
3728 MyPackage uses an @file{m4/} directory to store local macros as
3729 explained in @ref{Local Macros}, and has
3730
3731 @example
3732 AC_CONFIG_MACRO_DIR([m4])
3733 @end example
3734
3735 @noindent
3736 in its @file{configure.ac}.
3737
3738 Initially the @file{m4/} directory is empty.  The first time we run
3739 @command{aclocal --install}, it will notice that
3740
3741 @itemize @bullet
3742 @item
3743 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3744 @item
3745 No local macros define @code{AX_THIRD_PARTY}
3746 @item
3747 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3748 with serial 1.
3749 @end itemize
3750
3751 @noindent
3752 Because @file{/usr/share/aclocal/thirdparty.m4} is a system-wide macro
3753 and @command{aclocal} was given the @option{--install} option, it will
3754 copy this file in @file{m4/thirdparty.m4}, and output an
3755 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3756
3757 The next time @samp{aclocal --install} is run, something different
3758 happens.  @command{aclocal} notices that
3759
3760 @itemize @bullet
3761 @item
3762 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3763 @item
3764 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3765 with serial 1.
3766 @item
3767 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3768 with serial 1.
3769 @end itemize
3770
3771 @noindent
3772 Because both files have the same serial number, @command{aclocal} uses
3773 the first it found in its search path order (@pxref{Macro Search
3774 Path}).  @command{aclocal} therefore ignores
3775 @file{/usr/share/aclocal/thirdparty.m4} and outputs an
3776 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3777
3778 Local directories specified with @option{-I} are always searched before
3779 system-wide directories, so a local file will always be preferred to
3780 the system-wide file in case of equal serial numbers.
3781
3782 Now suppose the system-wide third-party macro is changed.  This can
3783 happen if the package installing this macro is updated.  Let's suppose
3784 the new macro has serial number 2.  The next time @samp{aclocal --install}
3785 is run the situation is the following:
3786
3787 @itemize @bullet
3788 @item
3789 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3790 @item
3791 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3792 with serial 1.
3793 @item
3794 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3795 with serial 2.
3796 @end itemize
3797
3798 @noindent
3799 When @command{aclocal} sees a greater serial number, it immediately
3800 forgets anything it knows from files that have the same basename and a
3801 smaller serial number.  So after it has found
3802 @file{/usr/share/aclocal/thirdparty.m4} with serial 2,
3803 @command{aclocal} will proceed as if it had never seen
3804 @file{m4/thirdparty.m4}.  This brings us back to a situation similar
3805 to that at the beginning of our example, where no local file defined
3806 the macro.  @command{aclocal} will install the new version of the
3807 macro in @file{m4/thirdparty.m4}, in this case overriding the old
3808 version.  MyPackage just had its macro updated as a side effect of
3809 running @command{aclocal}.
3810
3811 If you are leery of letting @command{aclocal} update your local
3812 macro, you can run @samp{aclocal --diff} to review the changes
3813 @samp{aclocal --install} would perform on these macros.
3814
3815 Finally, note that the @option{--force} option of @command{aclocal} has
3816 absolutely no effect on the files installed by @option{--install}.  For
3817 instance, if you have modified your local macros, do not expect
3818 @option{--install --force} to replace the local macros by their
3819 system-wide versions.  If you want to do so, simply erase the local
3820 macros you want to revert, and run @samp{aclocal --install}.
3821
3822
3823 @node Future of aclocal
3824 @subsection The Future of @command{aclocal}
3825 @cindex @command{aclocal}'s scheduled death
3826
3827 @command{aclocal} is expected to disappear.  This feature really
3828 should not be offered by Automake.  Automake should focus on
3829 generating @file{Makefile}s; dealing with M4 macros really is
3830 Autoconf's job.  The fact that some people install Automake just to use
3831 @command{aclocal}, but do not use @command{automake} otherwise is an
3832 indication of how that feature is misplaced.
3833
3834 The new implementation will probably be done slightly differently.
3835 For instance, it could enforce the @file{m4/}-style layout discussed in
3836 @ref{Local Macros}.
3837
3838 We have no idea when and how this will happen.  This has been
3839 discussed several times in the past, but someone still has to commit
3840 to that non-trivial task.
3841
3842 From the user point of view, @command{aclocal}'s removal might turn
3843 out to be painful.  There is a simple precaution that you may take to
3844 make that switch more seamless: never call @command{aclocal} yourself.
3845 Keep this guy under the exclusive control of @command{autoreconf} and
3846 Automake's rebuild rules.  Hopefully you won't need to worry about
3847 things breaking, when @command{aclocal} disappears, because everything
3848 will have been taken care of.  If otherwise you used to call
3849 @command{aclocal} directly yourself or from some script, you will
3850 quickly notice the change.
3851
3852 Many packages come with a script called @file{bootstrap.sh} or
3853 @file{autogen.sh}, that will just call @command{aclocal},
3854 @command{libtoolize}, @command{gettextize} or @command{autopoint},
3855 @command{autoconf}, @command{autoheader}, and @command{automake} in
3856 the right order.  Actually this is precisely what @command{autoreconf}
3857 can do for you.  If your package has such a @file{bootstrap.sh} or
3858 @file{autogen.sh} script, consider using @command{autoreconf}.  That
3859 should simplify its logic a lot (less things to maintain, yum!), it's
3860 even likely you will not need the script anymore, and more to the point
3861 you will not call @command{aclocal} directly anymore.
3862
3863 For the time being, third-party packages should continue to install
3864 public macros into @file{/usr/share/aclocal/}.  If @command{aclocal}
3865 is replaced by another tool it might make sense to rename the
3866 directory, but supporting @file{/usr/share/aclocal/} for backward
3867 compatibility should be really easy provided all macros are properly
3868 written (@pxref{Extending aclocal}).
3869
3870
3871
3872 @node Macros
3873 @section Autoconf macros supplied with Automake
3874
3875 Automake ships with several Autoconf macros that you can use from your
3876 @file{configure.ac}.  When you use one of them it will be included by
3877 @command{aclocal} in @file{aclocal.m4}.
3878
3879 @menu
3880 * Public Macros::               Macros that you can use.
3881 * Private Macros::              Macros that you should not use.
3882 @end menu
3883
3884 @c consider generating the following subsections automatically from m4 files.
3885
3886 @node Public Macros
3887 @subsection Public Macros
3888
3889 @table @code
3890
3891 @item AM_INIT_AUTOMAKE([OPTIONS])
3892 @acindex AM_INIT_AUTOMAKE
3893 Runs many macros required for proper operation of the generated Makefiles.
3894
3895 @vindex AUTOMAKE_OPTIONS
3896 @code{AM_INIT_AUTOMAKE} is called with a single argument: a space-separated
3897 list of Automake options that should be applied to every @file{Makefile.am}
3898 in the tree.  The effect is as if each option were listed in
3899 @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
3900
3901 @c FIXME: Remove this "modernization advice" in Automake 1.14 (and adjust
3902 @c FIXME: the error message in m4/init.m4:AM_INIT_AUTOMAKE accordingly).
3903
3904 @acindex AC_INIT
3905 This macro could once (before Automake 1.13) also be called in the
3906 @emph{now obsolete and completely unsupported} form
3907 @code{AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])}.  In this form,
3908 there were two required arguments: the package and the version number.
3909
3910 @anchor{Modernize AM_INIT_AUTOMAKE invocation}
3911 If your @file{configure.ac} has:
3912
3913 @example
3914 AC_INIT([src/foo.c])
3915 AM_INIT_AUTOMAKE([mumble], [1.5])
3916 @end example
3917
3918 @noindent
3919 you must modernize it as follows in order to make it work with Automake
3920 1.13 or later:
3921
3922 @example
3923 AC_INIT([mumble], [1.5])
3924 AC_CONFIG_SRCDIR([src/foo.c])
3925 AM_INIT_AUTOMAKE
3926 @end example
3927
3928 Note that if you're upgrading your @file{configure.ac} from an earlier
3929 version of Automake, it is not always correct to simply move the
3930 package and version arguments from @code{AM_INIT_AUTOMAKE} directly to
3931 @code{AC_INIT}, as in the example above.  The first argument to
3932 @code{AC_INIT} should be the name of your package (e.g., @samp{GNU
3933 Automake}), not the tarball name (e.g., @samp{automake}) that you used
3934 to pass to @code{AM_INIT_AUTOMAKE}.  Autoconf tries to derive a
3935 tarball name from the package name, which should work for most but not
3936 all package names.  (If it doesn't work for yours, you can use the
3937 four-argument form of @code{AC_INIT} to provide the tarball name
3938 explicitly).
3939
3940 @cindex @code{PACKAGE}, prevent definition
3941 @cindex @code{VERSION}, prevent definition
3942 @opindex no-define
3943 By default this macro @code{AC_DEFINE}'s @code{PACKAGE} and
3944 @code{VERSION}.  This can be avoided by passing the @option{no-define}
3945 option:
3946 @example
3947 AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
3948 @end example
3949
3950 @item AM_PATH_LISPDIR
3951 @acindex AM_PATH_LISPDIR
3952 @vindex EMACS
3953 @vindex lispdir
3954 Searches for the program @command{emacs}, and, if found, sets the
3955 output variable @code{lispdir} to the full path to Emacs' site-lisp
3956 directory.
3957
3958 Note that this test assumes the @command{emacs} found to be a version
3959 that supports Emacs Lisp (such as GNU Emacs or XEmacs).  Other
3960 emacsen can cause this test to hang (some, like old versions of
3961 MicroEmacs, start up in interactive mode, requiring @kbd{C-x C-c} to
3962 exit, which is hardly obvious for a non-emacs user).  In most cases,
3963 however, you should be able to use @kbd{C-c} to kill the test.  In
3964 order to avoid problems, you can set @env{EMACS} to ``no'' in the
3965 environment, or use the @option{--with-lispdir} option to
3966 @command{configure} to explicitly set the correct path (if you're sure
3967 you have an @command{emacs} that supports Emacs Lisp).
3968
3969 @item AM_PROG_AR(@ovar{act-if-fail})
3970 @acindex AM_PROG_AR
3971 @vindex AR
3972 You must use this macro when you use the archiver in your project, if
3973 you want support for unusual archivers such as Microsoft @command{lib}.
3974 The content of the optional argument is executed if the archiver
3975 interface is not recognized; the default action is to abort configure
3976 with an error message.
3977
3978 @item AM_PROG_AS
3979 @acindex AM_PROG_AS
3980 @vindex CCAS
3981 @vindex CCASFLAGS
3982 Use this macro when you have assembly code in your project.  This will
3983 choose the assembler for you (by default the C compiler) and set
3984 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
3985
3986 @item AM_PROG_CC_C_O
3987 @acindex AM_PROG_CC_C_O
3988 @acindex AC_PROG_CC_C_O
3989 This is like @code{AC_PROG_CC_C_O}, but it generates its results in
3990 the manner required by Automake.  You must use this instead of
3991 @code{AC_PROG_CC_C_O} when you need this functionality, that is, when
3992 using per-target flags or subdir-objects with C sources.
3993
3994 @item AM_PROG_LEX
3995 @acindex AM_PROG_LEX
3996 @acindex AC_PROG_LEX
3997 @cindex HP-UX 10, @command{lex} problems
3998 @cindex @command{lex} problems with HP-UX 10
3999 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
4000 Program Checks, autoconf, The Autoconf Manual}), but uses the
4001 @command{missing} script on systems that do not have @command{lex}.
4002 HP-UX 10 is one such system.
4003
4004 @item AM_PROG_GCJ
4005 @acindex AM_PROG_GCJ
4006 @vindex GCJ
4007 @vindex GCJFLAGS
4008 This macro finds the @command{gcj} program or causes an error.  It sets
4009 @code{GCJ} and @code{GCJFLAGS}.  @command{gcj} is the Java front-end to the
4010 GNU Compiler Collection.
4011
4012 @item AM_PROG_UPC([@var{compiler-search-list}])
4013 @acindex AM_PROG_UPC
4014 @vindex UPC
4015 Find a compiler for Unified Parallel C and define the @code{UPC}
4016 variable.  The default @var{compiler-search-list} is @samp{upcc upc}.
4017 This macro will abort @command{configure} if no Unified Parallel C
4018 compiler is found.
4019
4020 @item AM_MISSING_PROG(@var{name}, @var{program})
4021 @acindex AM_MISSING_PROG
4022 @vindex MISSING
4023 Find a maintainer tool @var{program} and define the @var{name}
4024 environment variable with its location.  If @var{program} is not
4025 detected, then @var{name} will instead invoke the @command{missing}
4026 script, in order to give useful advice to the user about the missing
4027 maintainer tool.  @xref{maintainer-mode}, for more information on when
4028 the @command{missing} script is appropriate.
4029
4030 @item AM_SILENT_RULES
4031 @acindex AM_SILENT_RULES
4032 Control the machinery for less verbose build output
4033 (@pxref{Automake Silent Rules}).
4034
4035 @item AM_WITH_DMALLOC
4036 @acindex AM_WITH_DMALLOC
4037 @cindex @command{dmalloc}, support for
4038 @vindex WITH_DMALLOC
4039 @opindex --with-dmalloc
4040 Add support for the @uref{http://dmalloc.com/, Dmalloc package}.  If
4041 the user runs @command{configure} with @option{--with-dmalloc}, then
4042 define @code{WITH_DMALLOC} and add @option{-ldmalloc} to @code{LIBS}.
4043
4044 @end table
4045
4046
4047 @node Private Macros
4048 @subsection Private Macros
4049
4050 The following macros are private macros you should not call directly.
4051 They are called by the other public macros when appropriate.  Do not
4052 rely on them, as they might be changed in a future version.  Consider
4053 them as implementation details; or better, do not consider them at all:
4054 skip this section!
4055
4056 @ftable @code
4057 @item _AM_DEPENDENCIES
4058 @itemx AM_SET_DEPDIR
4059 @itemx AM_DEP_TRACK
4060 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
4061 These macros are used to implement Automake's automatic dependency
4062 tracking scheme.  They are called automatically by Automake when
4063 required, and there should be no need to invoke them manually.
4064
4065 @item AM_MAKE_INCLUDE
4066 This macro is used to discover how the user's @command{make} handles
4067 @code{include} statements.  This macro is automatically invoked when
4068 needed; there should be no need to invoke it manually.
4069
4070 @item AM_PROG_INSTALL_STRIP
4071 This is used to find a version of @code{install} that can be used to
4072 strip a program at installation time.  This macro is automatically
4073 included when required.
4074
4075 @item AM_SANITY_CHECK
4076 This checks to make sure that a file created in the build directory is
4077 newer than a file in the source directory.  This can fail on systems
4078 where the clock is set incorrectly.  This macro is automatically run
4079 from @code{AM_INIT_AUTOMAKE}.
4080
4081 @end ftable
4082
4083
4084 @node Directories
4085 @chapter Directories
4086
4087 For simple projects that distribute all files in the same directory
4088 it is enough to have a single @file{Makefile.am} that builds
4089 everything in place.
4090
4091 In larger projects, it is common to organize files in different
4092 directories, in a tree.  For example, there could be a directory
4093 for the program's source, one for the testsuite, and one for the
4094 documentation; or, for very large projects, there could be one
4095 directory per program, per library or per module.
4096
4097 The traditional approach is to build these subdirectories recursively,
4098 employing @emph{make recursion}: each directory contains its
4099 own @file{Makefile}, and when @command{make} is run from the top-level
4100 directory, it enters each subdirectory in turn, and invokes there a
4101 new @command{make} instance to build the directory's contents.
4102
4103 Because this approach is very widespread, Automake offers built-in
4104 support for it.  However, it is worth nothing that the use of make
4105 recursion has its own serious issues and drawbacks, and that it's
4106 well possible to have packages with a multi directory layout that
4107 make little or no use of such recursion (examples of such packages
4108 are GNU Bison and GNU Automake itself); see also the @ref{Alternative}
4109 section below.
4110
4111 @menu
4112 * Subdirectories::              Building subdirectories recursively
4113 * Conditional Subdirectories::  Conditionally not building directories
4114 * Alternative::                 Subdirectories without recursion
4115 * Subpackages::                 Nesting packages
4116 @end menu
4117
4118 @node Subdirectories
4119 @section Recursing subdirectories
4120
4121 @cindex @code{SUBDIRS}, explained
4122
4123 In packages using make recursion, the top level @file{Makefile.am} must
4124 tell Automake which subdirectories are to be built.  This is done via
4125 the @code{SUBDIRS} variable.
4126 @vindex SUBDIRS
4127
4128 The @code{SUBDIRS} variable holds a list of subdirectories in which
4129 building of various sorts can occur.  The rules for many targets
4130 (e.g., @code{all}) in the generated @file{Makefile} will run commands
4131 both locally and in all specified subdirectories.  Note that the
4132 directories listed in @code{SUBDIRS} are not required to contain
4133 @file{Makefile.am}s; only @file{Makefile}s (after configuration).
4134 This allows inclusion of libraries from packages that do not use
4135 Automake (such as @code{gettext}; see also @ref{Third-Party
4136 Makefiles}).
4137
4138 In packages that use subdirectories, the top-level @file{Makefile.am} is
4139 often very short.  For instance, here is the @file{Makefile.am} from the
4140 GNU Hello distribution:
4141
4142 @example
4143 EXTRA_DIST = BUGS ChangeLog.O README-alpha
4144 SUBDIRS = doc intl po src tests
4145 @end example
4146
4147 When Automake invokes @command{make} in a subdirectory, it uses the value
4148 of the @code{MAKE} variable.  It passes the value of the variable
4149 @code{AM_MAKEFLAGS} to the @command{make} invocation; this can be set in
4150 @file{Makefile.am} if there are flags you must always pass to
4151 @command{make}.
4152 @vindex MAKE
4153 @vindex AM_MAKEFLAGS
4154
4155 The directories mentioned in @code{SUBDIRS} are usually direct
4156 children of the current directory, each subdirectory containing its
4157 own @file{Makefile.am} with a @code{SUBDIRS} pointing to deeper
4158 subdirectories.  Automake can be used to construct packages of
4159 arbitrary depth this way.
4160
4161 By default, Automake generates @file{Makefiles} that work depth-first
4162 in postfix order: the subdirectories are built before the current
4163 directory.  However, it is possible to change this ordering.  You can
4164 do this by putting @samp{.} into @code{SUBDIRS}.  For instance,
4165 putting @samp{.} first will cause a prefix ordering of
4166 directories.
4167
4168 Using
4169
4170 @example
4171 SUBDIRS = lib src . test
4172 @end example
4173
4174 @noindent
4175 will cause @file{lib/} to be built before @file{src/}, then the
4176 current directory will be built, finally the @file{test/} directory
4177 will be built.  It is customary to arrange test directories to be
4178 built after everything else since they are meant to test what has
4179 been constructed.
4180
4181 In addition to the built-in recursive targets defined by Automake
4182 (@code{all}, @code{check}, etc.), the developer can also define his
4183 own recursive targets.  That is done by passing the names of such
4184 targets as arguments to the m4 macro @code{AM_EXTRA_RECURSIVE_TARGETS}
4185 in @file{configure.ac}.  Automake generates rules to handle the
4186 recursion for such targets; and the developer can define real actions
4187 for them by defining corresponding @code{-local} targets.
4188
4189 @example
4190 % @kbd{cat configure.ac}
4191 AC_INIT([pkg-name], [1.0]
4192 AM_INIT_AUTOMAKE
4193 AM_EXTRA_RECURSIVE_TARGETS([foo])
4194 AC_CONFIG_FILES([Makefile sub/Makefile sub/src/Makefile])
4195 AC_OUTPUT
4196 % @kbd{cat Makefile.am}
4197 SUBDIRS = sub
4198 foo-local:
4199         @@echo This will be run by "make foo".
4200 % @kbd{cat sub/Makefile.am}
4201 SUBDIRS = src
4202 % @kbd{cat sub/src/Makefile.am}
4203 foo-local:
4204         @@echo This too will be run by a "make foo" issued either in
4205         @@echo the 'sub/src/' directory, the 'sub/' directory, or the
4206         @@echo top-level directory.
4207 @end example
4208
4209 @node Conditional Subdirectories
4210 @section Conditional Subdirectories
4211 @cindex Subdirectories, building conditionally
4212 @cindex Conditional subdirectories
4213 @cindex @code{SUBDIRS}, conditional
4214 @cindex Conditional @code{SUBDIRS}
4215
4216 It is possible to define the @code{SUBDIRS} variable conditionally if,
4217 like in the case of GNU Inetutils, you want to only build a subset of
4218 the entire package.
4219
4220 To illustrate how this works, let's assume we have two directories
4221 @file{src/} and @file{opt/}.  @file{src/} should always be built, but we
4222 want to decide in @command{configure} whether @file{opt/} will be built
4223 or not.  (For this example we will assume that @file{opt/} should be
4224 built when the variable @samp{$want_opt} was set to @samp{yes}.)
4225
4226 Running @command{make} should thus recurse into @file{src/} always, and
4227 then maybe in @file{opt/}.
4228
4229 However @samp{make dist} should always recurse into both @file{src/}
4230 and @file{opt/}.  Because @file{opt/} should be distributed even if it
4231 is not needed in the current configuration.  This means
4232 @file{opt/Makefile} should be created @emph{unconditionally}.
4233
4234 There are two ways to setup a project like this.  You can use Automake
4235 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
4236 variables (@pxref{Setting Output Variables, , Setting Output
4237 Variables, autoconf, The Autoconf Manual}).  Using Automake
4238 conditionals is the preferred solution.  Before we illustrate these
4239 two possibilities, let's introduce @code{DIST_SUBDIRS}.
4240
4241 @menu
4242 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
4243 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
4244 * Subdirectories with AC_SUBST::  Another way for conditional recursion
4245 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
4246 @end menu
4247
4248 @node SUBDIRS vs DIST_SUBDIRS
4249 @subsection @code{SUBDIRS} vs.@: @code{DIST_SUBDIRS}
4250 @cindex @code{DIST_SUBDIRS}, explained
4251
4252 Automake considers two sets of directories, defined by the variables
4253 @code{SUBDIRS} and @code{DIST_SUBDIRS}.
4254
4255 @code{SUBDIRS} contains the subdirectories of the current directory
4256 that must be built (@pxref{Subdirectories}).  It must be defined
4257 manually; Automake will never guess a directory is to be built.  As we
4258 will see in the next two sections, it is possible to define it
4259 conditionally so that some directory will be omitted from the build.
4260
4261 @code{DIST_SUBDIRS} is used in rules that need to recurse in all
4262 directories, even those that have been conditionally left out of the
4263 build.  Recall our example where we may not want to build subdirectory
4264 @file{opt/}, but yet we want to distribute it?  This is where
4265 @code{DIST_SUBDIRS} comes into play: @samp{opt} may not appear in
4266 @code{SUBDIRS}, but it must appear in @code{DIST_SUBDIRS}.
4267
4268 Precisely, @code{DIST_SUBDIRS} is used by @samp{make
4269 maintainer-clean}, @samp{make distclean} and @samp{make dist}.  All
4270 other recursive rules use @code{SUBDIRS}.
4271
4272 If @code{SUBDIRS} is defined conditionally using Automake
4273 conditionals, Automake will define @code{DIST_SUBDIRS} automatically
4274 from the possible values of @code{SUBDIRS} in all conditions.
4275
4276 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
4277 @code{DIST_SUBDIRS} will not be defined correctly because Automake
4278 does not know the possible values of these variables.  In this case
4279 @code{DIST_SUBDIRS} needs to be defined manually.
4280
4281 @node Subdirectories with AM_CONDITIONAL
4282 @subsection Subdirectories with @code{AM_CONDITIONAL}
4283 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
4284 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
4285
4286 @c Keep in sync with subdir-am-cond.sh
4287
4288 @file{configure} should output the @file{Makefile} for each directory
4289 and define a condition into which @file{opt/} should be built.
4290
4291 @example
4292 @dots{}
4293 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
4294 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4295 @dots{}
4296 @end example
4297
4298 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
4299 as follows.
4300
4301 @example
4302 if COND_OPT
4303   MAYBE_OPT = opt
4304 endif
4305 SUBDIRS = src $(MAYBE_OPT)
4306 @end example
4307
4308 As you can see, running @command{make} will rightly recurse into
4309 @file{src/} and maybe @file{opt/}.
4310
4311 @vindex DIST_SUBDIRS
4312 As you can't see, running @samp{make dist} will recurse into both
4313 @file{src/} and @file{opt/} directories because @samp{make dist}, unlike
4314 @samp{make all}, doesn't use the @code{SUBDIRS} variable.  It uses the
4315 @code{DIST_SUBDIRS} variable.
4316
4317 In this case Automake will define @samp{DIST_SUBDIRS = src opt}
4318 automatically because it knows that @code{MAYBE_OPT} can contain
4319 @samp{opt} in some condition.
4320
4321 @node Subdirectories with AC_SUBST
4322 @subsection Subdirectories with @code{AC_SUBST}
4323 @cindex @code{SUBDIRS} and @code{AC_SUBST}
4324 @cindex @code{AC_SUBST} and @code{SUBDIRS}
4325
4326 @c Keep in sync with subdir-ac-subst.sh
4327
4328 Another possibility is to define @code{MAYBE_OPT} from
4329 @file{./configure} using @code{AC_SUBST}:
4330
4331 @example
4332 @dots{}
4333 if test "$want_opt" = yes; then
4334   MAYBE_OPT=opt
4335 else
4336   MAYBE_OPT=
4337 fi
4338 AC_SUBST([MAYBE_OPT])
4339 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4340 @dots{}
4341 @end example
4342
4343 In this case the top-level @file{Makefile.am} should look as follows.
4344
4345 @example
4346 SUBDIRS = src $(MAYBE_OPT)
4347 DIST_SUBDIRS = src opt
4348 @end example
4349
4350 The drawback is that since Automake cannot guess what the possible
4351 values of @code{MAYBE_OPT} are, it is necessary to define
4352 @code{DIST_SUBDIRS}.
4353
4354 @node Unconfigured Subdirectories
4355 @subsection Unconfigured Subdirectories
4356 @cindex Subdirectories, configured conditionally
4357
4358 The semantics of @code{DIST_SUBDIRS} are often misunderstood by some
4359 users that try to @emph{configure and build} subdirectories
4360 conditionally.  Here by configuring we mean creating the
4361 @file{Makefile} (it might also involve running a nested
4362 @command{configure} script: this is a costly operation that explains
4363 why people want to do it conditionally, but only the @file{Makefile}
4364 is relevant to the discussion).
4365
4366 The above examples all assume that every @file{Makefile} is created,
4367 even in directories that are not going to be built.  The simple reason
4368 is that we want @samp{make dist} to distribute even the directories
4369 that are not being built (e.g., platform-dependent code), hence
4370 @file{make dist} must recurse into the subdirectory, hence this
4371 directory must be configured and appear in @code{DIST_SUBDIRS}.
4372
4373 Building packages that do not configure every subdirectory is a tricky
4374 business, and we do not recommend it to the novice as it is easy to
4375 produce an incomplete tarball by mistake.  We will not discuss this
4376 topic in depth here, yet for the adventurous here are a few rules to
4377 remember.
4378
4379 @cartouche
4380 @itemize
4381 @item @code{SUBDIRS} should always be a subset of @code{DIST_SUBDIRS}.
4382
4383 It makes little sense to have a directory in @code{SUBDIRS} that
4384 is not in @code{DIST_SUBDIRS}.  Think of the former as a way to tell
4385 which directories listed in the latter should be built.
4386 @item Any directory listed in @code{DIST_SUBDIRS} and @code{SUBDIRS}
4387 must be configured.
4388
4389 I.e., the @file{Makefile} must exists or the recursive @command{make}
4390 rules will not be able to process the directory.
4391 @item Any configured directory must be listed in @code{DIST_SUBDIRS}.
4392
4393 So that the cleaning rules remove the generated @file{Makefile}s.
4394 It would be correct to see @code{DIST_SUBDIRS} as a variable that
4395 lists all the directories that have been configured.
4396 @end itemize
4397 @end cartouche
4398
4399 In order to prevent recursion in some unconfigured directory you
4400 must therefore ensure that this directory does not appear in
4401 @code{DIST_SUBDIRS} (and @code{SUBDIRS}).  For instance, if you define
4402 @code{SUBDIRS} conditionally using @code{AC_SUBST} and do not define
4403 @code{DIST_SUBDIRS} explicitly, it will be default to
4404 @samp{$(SUBDIRS)}; another possibility is to force @code{DIST_SUBDIRS
4405 = $(SUBDIRS)}.
4406
4407 Of course, directories that are omitted from @code{DIST_SUBDIRS} will
4408 not be distributed unless you make other arrangements for this to
4409 happen (for instance, always running @samp{make dist} in a
4410 configuration where all directories are known to appear in
4411 @code{DIST_SUBDIRS}; or writing a @code{dist-hook} target to
4412 distribute these directories).
4413
4414 @cindex Subdirectories, not distributed
4415 In few packages, unconfigured directories are not even expected to
4416 be distributed.  Although these packages do not require the
4417 aforementioned extra arrangements, there is another pitfall.  If the
4418 name of a directory appears in @code{SUBDIRS} or @code{DIST_SUBDIRS},
4419 @command{automake} will make sure the directory exists.  Consequently
4420 @command{automake} cannot be run on such a distribution when one
4421 directory has been omitted.  One way to avoid this check is to use the
4422 @code{AC_SUBST} method to declare conditional directories; since
4423 @command{automake} does not know the values of @code{AC_SUBST}
4424 variables it cannot ensure the corresponding directory exists.
4425
4426 @node Alternative
4427 @section An Alternative Approach to Subdirectories
4428
4429 If you've ever read Peter Miller's excellent paper,
4430 @uref{http://miller.emu.id.au/pmiller/books/rmch/,
4431 Recursive Make Considered Harmful}, the preceding sections on the use of
4432 make recursion will probably come as unwelcome advice.  For those who
4433 haven't read the paper, Miller's main thesis is that recursive
4434 @command{make} invocations are both slow and error-prone.
4435
4436 Automake provides sufficient cross-directory support @footnote{We
4437 believe.  This work is new and there are probably warts.
4438 @xref{Introduction}, for information on reporting bugs.} to enable you
4439 to write a single @file{Makefile.am} for a complex multi-directory
4440 package.
4441
4442 By default an installable file specified in a subdirectory will have its
4443 directory name stripped before installation.  For instance, in this
4444 example, the header file will be installed as
4445 @file{$(includedir)/stdio.h}:
4446
4447 @example
4448 include_HEADERS = inc/stdio.h
4449 @end example
4450
4451 @vindex nobase_
4452 @cindex @code{nobase_} prefix
4453 @cindex Path stripping, avoiding
4454 @cindex Avoiding path stripping
4455
4456 However, the @samp{nobase_} prefix can be used to circumvent this path
4457 stripping.  In this example, the header file will be installed as
4458 @file{$(includedir)/sys/types.h}:
4459
4460 @example
4461 nobase_include_HEADERS = sys/types.h
4462 @end example
4463
4464 @cindex @code{nobase_} and @code{dist_} or @code{nodist_}
4465 @cindex @code{dist_} and @code{nobase_}
4466 @cindex @code{nodist_} and @code{nobase_}
4467 @vindex dist_
4468 @vindex nodist_
4469
4470 @samp{nobase_} should be specified first when used in conjunction with
4471 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
4472 Control}).  For instance:
4473
4474 @example
4475 nobase_dist_pkgdata_DATA = images/vortex.pgm sounds/whirl.ogg
4476 @end example
4477
4478 Finally, note that a variable using the @samp{nobase_} prefix can
4479 often be replaced by several variables, one for each destination
4480 directory (@pxref{Uniform}).  For instance, the last example could be
4481 rewritten as follows:
4482
4483 @c Keep in sync with primary-prefix-couples-documented-valid.sh
4484 @example
4485 imagesdir = $(pkgdatadir)/images
4486 soundsdir = $(pkgdatadir)/sounds
4487 dist_images_DATA = images/vortex.pgm
4488 dist_sounds_DATA = sounds/whirl.ogg
4489 @end example
4490
4491 @noindent
4492 This latter syntax makes it possible to change one destination
4493 directory without changing the layout of the source tree.
4494
4495 Currently, @samp{nobase_*_LTLIBRARIES} are the only exception to this
4496 rule, in that there is no particular installation order guarantee for
4497 an otherwise equivalent set of variables without @samp{nobase_} prefix.
4498
4499 @node Subpackages
4500 @section Nesting Packages
4501 @cindex Nesting packages
4502 @cindex Subpackages
4503 @acindex AC_CONFIG_SUBDIRS
4504 @acindex AC_CONFIG_AUX_DIR
4505
4506
4507 In the GNU Build System, packages can be nested to arbitrary depth.
4508 This means that a package can embed other packages with their own
4509 @file{configure}, @file{Makefile}s, etc.
4510
4511 These other packages should just appear as subdirectories of their
4512 parent package.  They must be listed in @code{SUBDIRS} like other
4513 ordinary directories.  However the subpackage's @file{Makefile}s
4514 should be output by its own @file{configure} script, not by the
4515 parent's @file{configure}.  This is achieved using the
4516 @code{AC_CONFIG_SUBDIRS} Autoconf macro (@pxref{Subdirectories,
4517 AC_CONFIG_SUBDIRS, Configuring Other Packages in Subdirectories,
4518 autoconf, The Autoconf Manual}).
4519
4520 Here is an example package for an @code{arm} program that links with
4521 a @code{hand} library that is a nested package in subdirectory
4522 @file{hand/}.
4523
4524 @code{arm}'s @file{configure.ac}:
4525
4526 @example
4527 AC_INIT([arm], [1.0])
4528 AC_CONFIG_AUX_DIR([.])
4529 AM_INIT_AUTOMAKE
4530 AC_PROG_CC
4531 AC_CONFIG_FILES([Makefile])
4532 # Call hand's ./configure script recursively.
4533 AC_CONFIG_SUBDIRS([hand])
4534 AC_OUTPUT
4535 @end example
4536
4537 @code{arm}'s @file{Makefile.am}:
4538
4539 @example
4540 # Build the library in the hand subdirectory first.
4541 SUBDIRS = hand
4542
4543 # Include hand's header when compiling this directory.
4544 AM_CPPFLAGS = -I$(srcdir)/hand
4545
4546 bin_PROGRAMS = arm
4547 arm_SOURCES = arm.c
4548 # link with the hand library.
4549 arm_LDADD = hand/libhand.a
4550 @end example
4551
4552 Now here is @code{hand}'s @file{hand/configure.ac}:
4553
4554 @example
4555 AC_INIT([hand], [1.2])
4556 AC_CONFIG_AUX_DIR([.])
4557 AM_INIT_AUTOMAKE
4558 AC_PROG_CC
4559 AM_PROG_AR
4560 AC_PROG_RANLIB
4561 AC_CONFIG_FILES([Makefile])
4562 AC_OUTPUT
4563 @end example
4564
4565 @noindent
4566 and its @file{hand/Makefile.am}:
4567
4568 @example
4569 lib_LIBRARIES = libhand.a
4570 libhand_a_SOURCES = hand.c
4571 @end example
4572
4573 When @samp{make dist} is run from the top-level directory it will
4574 create an archive @file{arm-1.0.tar.gz} that contains the @code{arm}
4575 code as well as the @file{hand} subdirectory.  This package can be
4576 built and installed like any ordinary package, with the usual
4577 @samp{./configure && make && make install} sequence (the @code{hand}
4578 subpackage will be built and installed by the process).
4579
4580 When @samp{make dist} is run from the hand directory, it will create a
4581 self-contained @file{hand-1.2.tar.gz} archive.  So although it appears
4582 to be embedded in another package, it can still be used separately.
4583
4584 The purpose of the @samp{AC_CONFIG_AUX_DIR([.])} instruction is to
4585 force Automake and Autoconf to search for auxiliary scripts in the
4586 current directory.  For instance, this means that there will be two
4587 copies of @file{install-sh}: one in the top-level of the @code{arm}
4588 package, and another one in the @file{hand/} subdirectory for the
4589 @code{hand} package.
4590
4591 The historical default is to search for these auxiliary scripts in
4592 the parent directory and the grandparent directory.  So if the
4593 @samp{AC_CONFIG_AUX_DIR([.])} line was removed from
4594 @file{hand/configure.ac}, that subpackage would share the auxiliary
4595 script of the @code{arm} package.  This may looks like a gain in size
4596 (a few kilobytes), but it is actually a loss of modularity as the
4597 @code{hand} subpackage is no longer self-contained (@samp{make dist}
4598 in the subdirectory will not work anymore).
4599
4600 Packages that do not use Automake need more work to be integrated this
4601 way.  @xref{Third-Party Makefiles}.
4602
4603 @node Programs
4604 @chapter Building Programs and Libraries
4605
4606 A large part of Automake's functionality is dedicated to making it easy
4607 to build programs and libraries.
4608
4609 @menu
4610 * A Program::                   Building a program
4611 * A Library::                   Building a library
4612 * A Shared Library::            Building a Libtool library
4613 * Program and Library Variables::  Variables controlling program and
4614                                 library builds
4615 * Default _SOURCES::            Default source files
4616 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
4617 * Program Variables::           Variables used when building a program
4618 * Yacc and Lex::                Yacc and Lex support
4619 * C++ Support::                 Compiling C++ sources
4620 * Objective C Support::         Compiling Objective C sources
4621 * Objective C++ Support::       Compiling Objective C++ sources
4622 * Unified Parallel C Support::  Compiling Unified Parallel C sources
4623 * Assembly Support::            Compiling assembly sources
4624 * Fortran 77 Support::          Compiling Fortran 77 sources
4625 * Fortran 9x Support::          Compiling Fortran 9x sources
4626 * Java Support with gcj::       Compiling Java sources using gcj
4627 * Vala Support::                Compiling Vala sources
4628 * Support for Other Languages::  Compiling other languages
4629 * Dependencies::                Automatic dependency tracking
4630 * EXEEXT::                      Support for executable extensions
4631 @end menu
4632
4633
4634 @node A Program
4635 @section Building a program
4636
4637 In order to build a program, you need to tell Automake which sources
4638 are part of it, and which libraries it should be linked with.
4639
4640 This section also covers conditional compilation of sources or
4641 programs.  Most of the comments about these also apply to libraries
4642 (@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
4643
4644 @menu
4645 * Program Sources::             Defining program sources
4646 * Linking::                     Linking with libraries or extra objects
4647 * Conditional Sources::         Handling conditional sources
4648 * Conditional Programs::        Building a program conditionally
4649 @end menu
4650
4651 @node Program Sources
4652 @subsection Defining program sources
4653
4654 @cindex @code{PROGRAMS}, @code{bindir}
4655 @vindex _PROGRAMS
4656 @vindex bin_PROGRAMS
4657 @vindex sbin_PROGRAMS
4658 @vindex libexec_PROGRAMS
4659 @vindex pkglibexec_PROGRAMS
4660 @vindex noinst_PROGRAMS
4661 @vindex check_PROGRAMS
4662
4663 In a directory containing source that gets built into a program (as
4664 opposed to a library or a script), the @code{PROGRAMS} primary is used.
4665 Programs can be installed in @code{bindir}, @code{sbindir},
4666 @code{libexecdir}, @code{pkglibexecdir}, or not at all
4667 (@code{noinst_}).  They can also be built only for @samp{make check}, in
4668 which case the prefix is @samp{check_}.
4669
4670 For instance:
4671
4672 @example
4673 bin_PROGRAMS = hello
4674 @end example
4675
4676 In this simple case, the resulting @file{Makefile.in} will contain code
4677 to generate a program named @code{hello}.
4678
4679 Associated with each program are several assisting variables that are
4680 named after the program.  These variables are all optional, and have
4681 reasonable defaults.  Each variable, its use, and default is spelled out
4682 below; we use the ``hello'' example throughout.
4683
4684 The variable @code{hello_SOURCES} is used to specify which source files
4685 get built into an executable:
4686
4687 @example
4688 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
4689 @end example
4690
4691 This causes each mentioned @file{.c} file to be compiled into the
4692 corresponding @file{.o}.  Then all are linked to produce @file{hello}.
4693
4694 @cindex @code{_SOURCES} primary, defined
4695 @cindex @code{SOURCES} primary, defined
4696 @cindex Primary variable, @code{SOURCES}
4697 @vindex _SOURCES
4698
4699 If @code{hello_SOURCES} is not specified, then it defaults to the single
4700 file @file{hello.c} (@pxref{Default _SOURCES}).
4701 @vindex _SOURCES
4702 @vindex SOURCES
4703
4704 Multiple programs can be built in a single directory.  Multiple programs
4705 can share a single source file, which must be listed in each
4706 @code{_SOURCES} definition.
4707
4708 @cindex Header files in @code{_SOURCES}
4709 @cindex @code{_SOURCES} and header files
4710
4711 Header files listed in a @code{_SOURCES} definition will be included in
4712 the distribution but otherwise ignored.  In case it isn't obvious, you
4713 should not include the header file generated by @file{configure} in a
4714 @code{_SOURCES} variable; this file should not be distributed.  Lex
4715 (@file{.l}) and Yacc (@file{.y}) files can also be listed; see @ref{Yacc
4716 and Lex}.
4717
4718
4719 @node Linking
4720 @subsection Linking the program
4721
4722 If you need to link against libraries that are not found by
4723 @command{configure}, you can use @code{LDADD} to do so.  This variable is
4724 used to specify additional objects or libraries to link with; it is
4725 inappropriate for specifying specific linker flags, you should use
4726 @code{AM_LDFLAGS} for this purpose.
4727 @vindex LDADD
4728 @vindex AM_LDFLAGS
4729
4730 @cindex @code{prog_LDADD}, defined
4731
4732 Sometimes, multiple programs are built in one directory but do not share
4733 the same link-time requirements.  In this case, you can use the
4734 @code{@var{prog}_LDADD} variable (where @var{prog} is the name of the
4735 program as it appears in some @code{_PROGRAMS} variable, and usually
4736 written in lowercase) to override @code{LDADD}.  If this variable exists
4737 for a given program, then that program is not linked using @code{LDADD}.
4738 @vindex maude_LDADD
4739
4740 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
4741 linked against the library @file{libcpio.a}.  However, @code{rmt} is
4742 built in the same directory, and has no such link requirement.  Also,
4743 @code{mt} and @code{rmt} are only built on certain architectures.  Here
4744 is what cpio's @file{src/Makefile.am} looks like (abridged):
4745
4746 @example
4747 bin_PROGRAMS = cpio pax $(MT)
4748 libexec_PROGRAMS = $(RMT)
4749 EXTRA_PROGRAMS = mt rmt
4750
4751 LDADD = ../lib/libcpio.a $(INTLLIBS)
4752 rmt_LDADD =
4753
4754 cpio_SOURCES = @dots{}
4755 pax_SOURCES = @dots{}
4756 mt_SOURCES = @dots{}
4757 rmt_SOURCES = @dots{}
4758 @end example
4759
4760 @cindex @code{_LDFLAGS}, defined
4761 @vindex maude_LDFLAGS
4762 @code{@var{prog}_LDADD} is inappropriate for passing program-specific
4763 linker flags (except for @option{-l}, @option{-L}, @option{-dlopen} and
4764 @option{-dlpreopen}).  So, use the @code{@var{prog}_LDFLAGS} variable for
4765 this purpose.
4766
4767 @cindex @code{_DEPENDENCIES}, defined
4768 @vindex maude_DEPENDENCIES
4769 @vindex EXTRA_maude_DEPENDENCIES
4770 It is also occasionally useful to have a program depend on some other
4771 target that is not actually part of that program.  This can be done
4772 using either the @code{@var{prog}_DEPENDENCIES} or the
4773 @code{EXTRA_@var{prog}_DEPENDENCIES} variable.  Each program depends on
4774 the contents both variables, but no further interpretation is done.
4775
4776 Since these dependencies are associated to the link rule used to
4777 create the programs they should normally list files used by the link
4778 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la}
4779 files.  In rare cases you may need to add other kinds of files such as
4780 linker scripts, but @emph{listing a source file in
4781 @code{_DEPENDENCIES} is wrong}.  If some source file needs to be built
4782 before all the components of a program are built, consider using the
4783 @code{BUILT_SOURCES} variable instead (@pxref{Sources}).
4784
4785 If @code{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
4786 Automake.  The automatically-assigned value is the contents of
4787 @code{@var{prog}_LDADD}, with most configure substitutions, @option{-l},
4788 @option{-L}, @option{-dlopen} and @option{-dlpreopen} options removed.  The
4789 configure substitutions that are left in are only @samp{$(LIBOBJS)} and
4790 @samp{$(ALLOCA)}; these are left because it is known that they will not
4791 cause an invalid value for @code{@var{prog}_DEPENDENCIES} to be
4792 generated.
4793
4794 @ref{Conditional Sources} shows a situation where @code{_DEPENDENCIES}
4795 may be used.
4796
4797 The @code{EXTRA_@var{prog}_DEPENDENCIES} may be useful for cases where
4798 you merely want to augment the @command{automake}-generated
4799 @code{@var{prog}_DEPENDENCIES} rather than replacing it.
4800
4801 @cindex @code{LDADD} and @option{-l}
4802 @cindex @option{-l} and @code{LDADD}
4803 We recommend that you avoid using @option{-l} options in @code{LDADD}
4804 or @code{@var{prog}_LDADD} when referring to libraries built by your
4805 package.  Instead, write the file name of the library explicitly as in
4806 the above @code{cpio} example.  Use @option{-l} only to list
4807 third-party libraries.  If you follow this rule, the default value of
4808 @code{@var{prog}_DEPENDENCIES} will list all your local libraries and
4809 omit the other ones.
4810
4811
4812 @node Conditional Sources
4813 @subsection Conditional compilation of sources
4814
4815 You can't put a configure substitution (e.g., @samp{@@FOO@@} or
4816 @samp{$(FOO)} where @code{FOO} is defined via @code{AC_SUBST}) into a
4817 @code{_SOURCES} variable.  The reason for this is a bit hard to
4818 explain, but suffice to say that it simply won't work.  Automake will
4819 give an error if you try to do this.
4820
4821 Fortunately there are two other ways to achieve the same result.  One is
4822 to use configure substitutions in @code{_LDADD} variables, the other is
4823 to use an Automake conditional.
4824
4825 @subsubheading Conditional Compilation using @code{_LDADD} Substitutions
4826
4827 @cindex @code{EXTRA_prog_SOURCES}, defined
4828
4829 Automake must know all the source files that could possibly go into a
4830 program, even if not all the files are built in every circumstance.  Any
4831 files that are only conditionally built should be listed in the
4832 appropriate @code{EXTRA_} variable.  For instance, if
4833 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
4834 in @code{hello}, the @file{Makefile.am} would contain:
4835
4836 @example
4837 bin_PROGRAMS = hello
4838 hello_SOURCES = hello-common.c
4839 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
4840 hello_LDADD = $(HELLO_SYSTEM)
4841 hello_DEPENDENCIES = $(HELLO_SYSTEM)
4842 @end example
4843
4844 @noindent
4845 You can then setup the @samp{$(HELLO_SYSTEM)} substitution from
4846 @file{configure.ac}:
4847
4848 @example
4849 @dots{}
4850 case $host in
4851   *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
4852   *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
4853 esac
4854 AC_SUBST([HELLO_SYSTEM])
4855 @dots{}
4856 @end example
4857
4858 In this case, the variable @code{HELLO_SYSTEM} should be replaced by
4859 either @file{hello-linux.o} or @file{hello-generic.o}, and added to
4860 both @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be
4861 built and linked in.
4862
4863 @subsubheading Conditional Compilation using Automake Conditionals
4864
4865 An often simpler way to compile source files conditionally is to use
4866 Automake conditionals.  For instance, you could use this
4867 @file{Makefile.am} construct to build the same @file{hello} example:
4868
4869 @example
4870 bin_PROGRAMS = hello
4871 if LINUX
4872 hello_SOURCES = hello-linux.c hello-common.c
4873 else
4874 hello_SOURCES = hello-generic.c hello-common.c
4875 endif
4876 @end example
4877
4878 In this case, @file{configure.ac} should setup the @code{LINUX}
4879 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
4880
4881 When using conditionals like this you don't need to use the
4882 @code{EXTRA_} variable, because Automake will examine the contents of
4883 each variable to construct the complete list of source files.
4884
4885 If your program uses a lot of files, you will probably prefer a
4886 conditional @samp{+=}.
4887
4888 @example
4889 bin_PROGRAMS = hello
4890 hello_SOURCES = hello-common.c
4891 if LINUX
4892 hello_SOURCES += hello-linux.c
4893 else
4894 hello_SOURCES += hello-generic.c
4895 endif
4896 @end example
4897
4898 @node Conditional Programs
4899 @subsection Conditional compilation of programs
4900 @cindex Conditional programs
4901 @cindex Programs, conditional
4902
4903 Sometimes it is useful to determine the programs that are to be built
4904 at configure time.  For instance, GNU @code{cpio} only builds
4905 @code{mt} and @code{rmt} under special circumstances.  The means to
4906 achieve conditional compilation of programs are the same you can use
4907 to compile source files conditionally: substitutions or conditionals.
4908
4909 @subsubheading Conditional Programs using @command{configure} Substitutions
4910
4911 @vindex EXTRA_PROGRAMS
4912 @cindex @code{EXTRA_PROGRAMS}, defined
4913 In this case, you must notify Automake of all the programs that can
4914 possibly be built, but at the same time cause the generated
4915 @file{Makefile.in} to use the programs specified by @command{configure}.
4916 This is done by having @command{configure} substitute values into each
4917 @code{_PROGRAMS} definition, while listing all optionally built programs
4918 in @code{EXTRA_PROGRAMS}.
4919
4920 @example
4921 bin_PROGRAMS = cpio pax $(MT)
4922 libexec_PROGRAMS = $(RMT)
4923 EXTRA_PROGRAMS = mt rmt
4924 @end example
4925
4926 As explained in @ref{EXEEXT}, Automake will rewrite
4927 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
4928 @code{EXTRA_PROGRAMS}, appending @samp{$(EXEEXT)} to each binary.
4929 Obviously it cannot rewrite values obtained at run-time through
4930 @command{configure} substitutions, therefore you should take care of
4931 appending @samp{$(EXEEXT)} yourself, as in @samp{AC_SUBST([MT],
4932 ['mt$@{EXEEXT@}'])}.
4933
4934 @subsubheading Conditional Programs using Automake Conditionals
4935
4936 You can also use Automake conditionals (@pxref{Conditionals}) to
4937 select programs to be built.  In this case you don't have to worry
4938 about @samp{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
4939
4940 @c Keep in sync with exeext.sh
4941 @example
4942 bin_PROGRAMS = cpio pax
4943 if WANT_MT
4944   bin_PROGRAMS += mt
4945 endif
4946 if WANT_RMT
4947   libexec_PROGRAMS = rmt
4948 endif
4949 @end example
4950
4951
4952 @node A Library
4953 @section Building a library
4954
4955 @cindex @code{_LIBRARIES} primary, defined
4956 @cindex @code{LIBRARIES} primary, defined
4957 @cindex Primary variable, @code{LIBRARIES}
4958 @vindex _LIBRARIES
4959
4960 @vindex lib_LIBRARIES
4961 @vindex pkglib_LIBRARIES
4962 @vindex noinst_LIBRARIES
4963
4964 Building a library is much like building a program.  In this case, the
4965 name of the primary is @code{LIBRARIES}.  Libraries can be installed in
4966 @code{libdir} or @code{pkglibdir}.
4967
4968 @xref{A Shared Library}, for information on how to build shared
4969 libraries using libtool and the @code{LTLIBRARIES} primary.
4970
4971 Each @code{_LIBRARIES} variable is a list of the libraries to be built.
4972 For instance, to create a library named @file{libcpio.a}, but not install
4973 it, you would write:
4974
4975 @example
4976 noinst_LIBRARIES = libcpio.a
4977 libcpio_a_SOURCES = @dots{}
4978 @end example
4979
4980 The sources that go into a library are determined exactly as they are
4981 for programs, via the @code{_SOURCES} variables.  Note that the library
4982 name is canonicalized (@pxref{Canonicalization}), so the @code{_SOURCES}
4983 variable corresponding to @file{libcpio.a} is @samp{libcpio_a_SOURCES},
4984 not @samp{libcpio.a_SOURCES}.
4985
4986 @vindex maude_LIBADD
4987 Extra objects can be added to a library using the
4988 @code{@var{library}_LIBADD} variable.  This should be used for objects
4989 determined by @command{configure}.  Again from @code{cpio}:
4990
4991 @c Keep in sync with pr401c.sh
4992 @example
4993 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
4994 @end example
4995
4996 In addition, sources for extra objects that will not exist until
4997 configure-time must be added to the @code{BUILT_SOURCES} variable
4998 (@pxref{Sources}).
4999
5000 Building a static library is done by compiling all object files, then
5001 by invoking @samp{$(AR) $(ARFLAGS)} followed by the name of the
5002 library and the list of objects, and finally by calling
5003 @samp{$(RANLIB)} on that library.  You should call
5004 @code{AC_PROG_RANLIB} from your @file{configure.ac} to define
5005 @code{RANLIB} (Automake will complain otherwise).  You should also
5006 call @code{AM_PROG_AR} to define @code{AR}, in order to support unusual
5007 archivers such as Microsoft lib.  @code{ARFLAGS} will default to
5008 @code{cru}; you can override this variable by setting it in your
5009 @file{Makefile.am} or by @code{AC_SUBST}ing it from your
5010 @file{configure.ac}.  You can override the @code{AR} variable by
5011 defining a per-library @code{maude_AR} variable (@pxref{Program and
5012 Library Variables}).
5013
5014 @cindex Empty libraries
5015 Be careful when selecting library components conditionally.  Because
5016 building an empty library is not portable, you should ensure that any
5017 library always contains at least one object.
5018
5019 To use a static library when building a program, add it to
5020 @code{LDADD} for this program.  In the following example, the program
5021 @file{cpio} is statically linked with the library @file{libcpio.a}.
5022
5023 @example
5024 noinst_LIBRARIES = libcpio.a
5025 libcpio_a_SOURCES = @dots{}
5026
5027 bin_PROGRAMS = cpio
5028 cpio_SOURCES = cpio.c @dots{}
5029 cpio_LDADD = libcpio.a
5030 @end example
5031
5032
5033 @node A Shared Library
5034 @section Building a Shared Library
5035
5036 @cindex Shared libraries, support for
5037
5038 Building shared libraries portably is a relatively complex matter.
5039 For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
5040 Libtool Manual}) was created to help build shared libraries in a
5041 platform-independent way.
5042
5043 @menu
5044 * Libtool Concept::             Introducing Libtool
5045 * Libtool Libraries::           Declaring Libtool Libraries
5046 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
5047 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
5048 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
5049 * Libtool Modules::             Building Libtool Modules
5050 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
5051 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
5052 * Libtool Issues::              Common Issues Related to Libtool's Use
5053 @end menu
5054
5055 @node Libtool Concept
5056 @subsection The Libtool Concept
5057
5058 @cindex @command{libtool}, introduction
5059 @cindex libtool library, definition
5060 @cindex suffix @file{.la}, defined
5061 @cindex @file{.la} suffix, defined
5062
5063 Libtool abstracts shared and static libraries into a unified concept
5064 henceforth called @dfn{libtool libraries}.  Libtool libraries are
5065 files using the @file{.la} suffix, and can designate a static library,
5066 a shared library, or maybe both.  Their exact nature cannot be
5067 determined until @file{./configure} is run: not all platforms support
5068 all kinds of libraries, and users can explicitly select which
5069 libraries should be built.  (However the package's maintainers can
5070 tune the default, @pxref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
5071 macro, libtool, The Libtool Manual}.)
5072
5073 @cindex suffix @file{.lo}, defined
5074 Because object files for shared and static libraries must be compiled
5075 differently, libtool is also used during compilation.  Object files
5076 built by libtool are called @dfn{libtool objects}: these are files
5077 using the @file{.lo} suffix.  Libtool libraries are built from these
5078 libtool objects.
5079
5080 You should not assume anything about the structure of @file{.la} or
5081 @file{.lo} files and how libtool constructs them: this is libtool's
5082 concern, and the last thing one wants is to learn about libtool's
5083 guts.  However the existence of these files matters, because they are
5084 used as targets and dependencies in @file{Makefile}s rules when
5085 building libtool libraries.  There are situations where you may have
5086 to refer to these, for instance when expressing dependencies for
5087 building source files conditionally (@pxref{Conditional Libtool
5088 Sources}).
5089
5090 @cindex @file{libltdl}, introduction
5091
5092 People considering writing a plug-in system, with dynamically loaded
5093 modules, should look into @file{libltdl}: libtool's dlopening library
5094 (@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
5095 This offers a portable dlopening facility to load libtool libraries
5096 dynamically, and can also achieve static linking where unavoidable.
5097
5098 Before we discuss how to use libtool with Automake in details, it
5099 should be noted that the libtool manual also has a section about how
5100 to use Automake with libtool (@pxref{Using Automake, , Using Automake
5101 with Libtool, libtool, The Libtool Manual}).
5102
5103 @node Libtool Libraries
5104 @subsection Building Libtool Libraries
5105
5106 @cindex @code{_LTLIBRARIES} primary, defined
5107 @cindex @code{LTLIBRARIES} primary, defined
5108 @cindex Primary variable, @code{LTLIBRARIES}
5109 @cindex Example of shared libraries
5110 @vindex lib_LTLIBRARIES
5111 @vindex pkglib_LTLIBRARIES
5112 @vindex _LTLIBRARIES
5113
5114 Automake uses libtool to build libraries declared with the
5115 @code{LTLIBRARIES} primary.  Each @code{_LTLIBRARIES} variable is a
5116 list of libtool libraries to build.  For instance, to create a libtool
5117 library named @file{libgettext.la}, and install it in @code{libdir},
5118 write:
5119
5120 @example
5121 lib_LTLIBRARIES = libgettext.la
5122 libgettext_la_SOURCES = gettext.c gettext.h @dots{}
5123 @end example
5124
5125 Automake predefines the variable @code{pkglibdir}, so you can use
5126 @code{pkglib_LTLIBRARIES} to install libraries in
5127 @samp{$(libdir)/@@PACKAGE@@/}.
5128
5129 If @file{gettext.h} is a public header file that needs to be installed
5130 in order for people to use the library, it should be declared using a
5131 @code{_HEADERS} variable, not in @code{libgettext_la_SOURCES}.
5132 Headers listed in the latter should be internal headers that are not
5133 part of the public interface.
5134
5135 @example
5136 lib_LTLIBRARIES = libgettext.la
5137 libgettext_la_SOURCES = gettext.c @dots{}
5138 include_HEADERS = gettext.h @dots{}
5139 @end example
5140
5141 A package can build and install such a library along with other
5142 programs that use it.  This dependency should be specified using
5143 @code{LDADD}.  The following example builds a program named
5144 @file{hello} that is linked with @file{libgettext.la}.
5145
5146 @example
5147 lib_LTLIBRARIES = libgettext.la
5148 libgettext_la_SOURCES = gettext.c @dots{}
5149
5150 bin_PROGRAMS = hello
5151 hello_SOURCES = hello.c @dots{}
5152 hello_LDADD = libgettext.la
5153 @end example
5154
5155 @noindent
5156 Whether @file{hello} is statically or dynamically linked with
5157 @file{libgettext.la} is not yet known: this will depend on the
5158 configuration of libtool and the capabilities of the host.
5159
5160
5161 @node Conditional Libtool Libraries
5162 @subsection Building Libtool Libraries Conditionally
5163 @cindex libtool libraries, conditional
5164 @cindex conditional libtool libraries
5165
5166 Like conditional programs (@pxref{Conditional Programs}), there are
5167 two main ways to build conditional libraries: using Automake
5168 conditionals or using Autoconf @code{AC_SUBST}itutions.
5169
5170 The important implementation detail you have to be aware of is that
5171 the place where a library will be installed matters to libtool: it
5172 needs to be indicated @emph{at link-time} using the @option{-rpath}
5173 option.
5174
5175 For libraries whose destination directory is known when Automake runs,
5176 Automake will automatically supply the appropriate @option{-rpath}
5177 option to libtool.  This is the case for libraries listed explicitly in
5178 some installable @code{_LTLIBRARIES} variables such as
5179 @code{lib_LTLIBRARIES}.
5180
5181 However, for libraries determined at configure time (and thus
5182 mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
5183 final installation directory.  For such libraries you must add the
5184 @option{-rpath} option to the appropriate @code{_LDFLAGS} variable by
5185 hand.
5186
5187 The examples below illustrate the differences between these two methods.
5188
5189 Here is an example where @code{WANTEDLIBS} is an @code{AC_SUBST}ed
5190 variable set at @file{./configure}-time to either @file{libfoo.la},
5191 @file{libbar.la}, both, or none.  Although @samp{$(WANTEDLIBS)}
5192 appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
5193 relates to @file{libfoo.la} or @file{libbar.la} at the time it creates
5194 the link rule for these two libraries.  Therefore the @option{-rpath}
5195 argument must be explicitly supplied.
5196
5197 @c Keep in sync with ltcond.sh
5198 @example
5199 EXTRA_LTLIBRARIES = libfoo.la libbar.la
5200 lib_LTLIBRARIES = $(WANTEDLIBS)
5201 libfoo_la_SOURCES = foo.c @dots{}
5202 libfoo_la_LDFLAGS = -rpath '$(libdir)'
5203 libbar_la_SOURCES = bar.c @dots{}
5204 libbar_la_LDFLAGS = -rpath '$(libdir)'
5205 @end example
5206
5207 Here is how the same @file{Makefile.am} would look using Automake
5208 conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}.  Now
5209 Automake is able to compute the @option{-rpath} setting itself, because
5210 it's clear that both libraries will end up in @samp{$(libdir)} if they
5211 are installed.
5212
5213 @c Keep in sync with ltcond.sh
5214 @example
5215 lib_LTLIBRARIES =
5216 if WANT_LIBFOO
5217 lib_LTLIBRARIES += libfoo.la
5218 endif
5219 if WANT_LIBBAR
5220 lib_LTLIBRARIES += libbar.la
5221 endif
5222 libfoo_la_SOURCES = foo.c @dots{}
5223 libbar_la_SOURCES = bar.c @dots{}
5224 @end example
5225
5226 @node Conditional Libtool Sources
5227 @subsection Libtool Libraries with Conditional Sources
5228
5229 Conditional compilation of sources in a library can be achieved in the
5230 same way as conditional compilation of sources in a program
5231 (@pxref{Conditional Sources}).  The only difference is that
5232 @code{_LIBADD} should be used instead of @code{_LDADD} and that it
5233 should mention libtool objects (@file{.lo} files).
5234
5235 So, to mimic the @file{hello} example from @ref{Conditional Sources},
5236 we could build a @file{libhello.la} library using either
5237 @file{hello-linux.c} or @file{hello-generic.c} with the following
5238 @file{Makefile.am}.
5239
5240 @c Keep in sync with ltcond2.sh
5241 @example
5242 lib_LTLIBRARIES = libhello.la
5243 libhello_la_SOURCES = hello-common.c
5244 EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
5245 libhello_la_LIBADD = $(HELLO_SYSTEM)
5246 libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
5247 @end example
5248
5249 @noindent
5250 And make sure @command{configure} defines @code{HELLO_SYSTEM} as
5251 either @file{hello-linux.lo} or @file{hello-@-generic.lo}.
5252
5253 Or we could simply use an Automake conditional as follows.
5254
5255 @c Keep in sync with ltcond2.sh
5256 @example
5257 lib_LTLIBRARIES = libhello.la
5258 libhello_la_SOURCES = hello-common.c
5259 if LINUX
5260 libhello_la_SOURCES += hello-linux.c
5261 else
5262 libhello_la_SOURCES += hello-generic.c
5263 endif
5264 @end example
5265
5266 @node Libtool Convenience Libraries
5267 @subsection Libtool Convenience Libraries
5268 @cindex convenience libraries, libtool
5269 @cindex libtool convenience libraries
5270 @vindex noinst_LTLIBRARIES
5271 @vindex check_LTLIBRARIES
5272
5273 Sometimes you want to build libtool libraries that should not be
5274 installed.  These are called @dfn{libtool convenience libraries} and
5275 are typically used to encapsulate many sublibraries, later gathered
5276 into one big installed library.
5277
5278 Libtool convenience libraries are declared by directory-less variables
5279 such as @code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
5280 @code{EXTRA_LTLIBRARIES}.  Unlike installed libtool libraries they do
5281 not need an @option{-rpath} flag at link time (actually this is the only
5282 difference).
5283
5284 Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
5285 built.  Those listed in @code{check_LTLIBRARIES} are built only upon
5286 @samp{make check}.  Finally, libraries listed in
5287 @code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
5288 rules to build them, but if the library does not appear as a Makefile
5289 dependency anywhere it won't be built (this is why
5290 @code{EXTRA_LTLIBRARIES} is used for conditional compilation).
5291
5292 Here is a sample setup merging libtool convenience libraries from
5293 subdirectories into one main @file{libtop.la} library.
5294
5295 @c Keep in sync with ltconv.sh
5296 @example
5297 # -- Top-level Makefile.am --
5298 SUBDIRS = sub1 sub2 @dots{}
5299 lib_LTLIBRARIES = libtop.la
5300 libtop_la_SOURCES =
5301 libtop_la_LIBADD = \
5302   sub1/libsub1.la \
5303   sub2/libsub2.la \
5304   @dots{}
5305
5306 # -- sub1/Makefile.am --
5307 noinst_LTLIBRARIES = libsub1.la
5308 libsub1_la_SOURCES = @dots{}
5309
5310 # -- sub2/Makefile.am --
5311 # showing nested convenience libraries
5312 SUBDIRS = sub2.1 sub2.2 @dots{}
5313 noinst_LTLIBRARIES = libsub2.la
5314 libsub2_la_SOURCES =
5315 libsub2_la_LIBADD = \
5316   sub21/libsub21.la \
5317   sub22/libsub22.la \
5318   @dots{}
5319 @end example
5320
5321 When using such setup, beware that @command{automake} will assume
5322 @file{libtop.la} is to be linked with the C linker.  This is because
5323 @code{libtop_la_SOURCES} is empty, so @command{automake} picks C as
5324 default language.  If @code{libtop_la_SOURCES} was not empty,
5325 @command{automake} would select the linker as explained in @ref{How
5326 the Linker is Chosen}.
5327
5328 If one of the sublibraries contains non-C source, it is important that
5329 the appropriate linker be chosen.  One way to achieve this is to
5330 pretend that there is such a non-C file among the sources of the
5331 library, thus forcing @command{automake} to select the appropriate
5332 linker.  Here is the top-level @file{Makefile} of our example updated
5333 to force C++ linking.
5334
5335 @example
5336 SUBDIRS = sub1 sub2 @dots{}
5337 lib_LTLIBRARIES = libtop.la
5338 libtop_la_SOURCES =
5339 # Dummy C++ source to cause C++ linking.
5340 nodist_EXTRA_libtop_la_SOURCES = dummy.cxx
5341 libtop_la_LIBADD = \
5342   sub1/libsub1.la \
5343   sub2/libsub2.la \
5344   @dots{}
5345 @end example
5346
5347 @samp{EXTRA_*_SOURCES} variables are used to keep track of source
5348 files that might be compiled (this is mostly useful when doing
5349 conditional compilation using @code{AC_SUBST}, @pxref{Conditional
5350 Libtool Sources}), and the @code{nodist_} prefix means the listed
5351 sources are not to be distributed (@pxref{Program and Library
5352 Variables}).  In effect the file @file{dummy.cxx} does not need to
5353 exist in the source tree.  Of course if you have some real source file
5354 to list in @code{libtop_la_SOURCES} there is no point in cheating with
5355 @code{nodist_EXTRA_libtop_la_SOURCES}.
5356
5357
5358 @node Libtool Modules
5359 @subsection Libtool Modules
5360 @cindex modules, libtool
5361 @cindex libtool modules
5362 @cindex @option{-module}, libtool
5363
5364 These are libtool libraries meant to be dlopened.  They are
5365 indicated to libtool by passing @option{-module} at link-time.
5366
5367 @example
5368 pkglib_LTLIBRARIES = mymodule.la
5369 mymodule_la_SOURCES = doit.c
5370 mymodule_la_LDFLAGS = -module
5371 @end example
5372
5373 Ordinarily, Automake requires that a library's name start with
5374 @code{lib}.  However, when building a dynamically loadable module you
5375 might wish to use a "nonstandard" name.  Automake will not complain
5376 about such nonstandard names if it knows the library being built is a
5377 libtool module, i.e., if @option{-module} explicitly appears in the
5378 library's @code{_LDFLAGS} variable (or in the common @code{AM_LDFLAGS}
5379 variable when no per-library @code{_LDFLAGS} variable is defined).
5380
5381 As always, @code{AC_SUBST} variables are black boxes to Automake since
5382 their values are not yet known when @command{automake} is run.
5383 Therefore if @option{-module} is set via such a variable, Automake
5384 cannot notice it and will proceed as if the library was an ordinary
5385 libtool library, with strict naming.
5386
5387 If @code{mymodule_la_SOURCES} is not specified, then it defaults to
5388 the single file @file{mymodule.c} (@pxref{Default _SOURCES}).
5389
5390 @node Libtool Flags
5391 @subsection @code{_LIBADD}, @code{_LDFLAGS}, and @code{_LIBTOOLFLAGS}
5392 @cindex @code{_LIBADD}, libtool
5393 @cindex @code{_LDFLAGS}, libtool
5394 @cindex @code{_LIBTOOLFLAGS}, libtool
5395 @vindex AM_LIBTOOLFLAGS
5396 @vindex LIBTOOLFLAGS
5397 @vindex maude_LIBTOOLFLAGS
5398
5399 As shown in previous sections, the @samp{@var{library}_LIBADD}
5400 variable should be used to list extra libtool objects (@file{.lo}
5401 files) or libtool libraries (@file{.la}) to add to @var{library}.
5402
5403 The @samp{@var{library}_LDFLAGS} variable is the place to list
5404 additional libtool linking flags, such as @option{-version-info},
5405 @option{-static}, and a lot more.  @xref{Link mode, , Link mode,
5406 libtool, The Libtool Manual}.
5407
5408 The @command{libtool} command has two kinds of options: mode-specific
5409 options and generic options.  Mode-specific options such as the
5410 aforementioned linking flags should be lumped with the other flags
5411 passed to the tool invoked by @command{libtool} (hence the use of
5412 @samp{@var{library}_LDFLAGS} for libtool linking flags).  Generic
5413 options include @option{--tag=@var{tag}} and @option{--silent}
5414 (@pxref{Invoking libtool, , Invoking @command{libtool}, libtool, The
5415 Libtool Manual} for more options) should appear before the mode
5416 selection on the command line; in @file{Makefile.am}s they should
5417 be listed in the @samp{@var{library}_LIBTOOLFLAGS} variable.
5418
5419 If @samp{@var{library}_LIBTOOLFLAGS} is not defined, then the variable
5420 @code{AM_LIBTOOLFLAGS} is used instead.
5421
5422 These flags are passed to libtool after the @option{--tag=@var{tag}}
5423 option computed by Automake (if any), so
5424 @samp{@var{library}_LIBTOOLFLAGS} (or @code{AM_LIBTOOLFLAGS}) is a
5425 good place to override or supplement the @option{--tag=@var{tag}}
5426 setting.
5427
5428 The libtool rules also use a @code{LIBTOOLFLAGS} variable that should
5429 not be set in @file{Makefile.am}: this is a user variable (@pxref{Flag
5430 Variables Ordering}.  It allows users to run @samp{make
5431 LIBTOOLFLAGS=--silent}, for instance.  Note that the verbosity of
5432 @command{libtool} can also be influenced by the Automake support
5433 for silent rules (@pxref{Automake Silent Rules}).
5434
5435 @node LTLIBOBJS, Libtool Issues, Libtool Flags, A Shared Library
5436 @subsection @code{LTLIBOBJS} and @code{LTALLOCA}
5437 @cindex @code{LTLIBOBJS}, special handling
5438 @cindex @code{LIBOBJS}, and Libtool
5439 @cindex @code{LTALLOCA}, special handling
5440 @cindex @code{ALLOCA}, and Libtool
5441 @vindex LTLIBOBJS
5442 @vindex LIBOBJS
5443 @vindex LTALLOCA
5444 @vindex ALLOCA
5445 @acindex AC_LIBOBJ
5446
5447 Where an ordinary library might include @samp{$(LIBOBJS)} or
5448 @samp{$(ALLOCA)} (@pxref{LIBOBJS}), a libtool library must use
5449 @samp{$(LTLIBOBJS)} or @samp{$(LTALLOCA)}.  This is required because
5450 the object files that libtool operates on do not necessarily end in
5451 @file{.o}.
5452
5453 Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
5454 performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
5455 @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual}).
5456
5457 @node Libtool Issues
5458 @subsection Common Issues Related to Libtool's Use
5459
5460 @menu
5461 * Error required file ltmain.sh not found::  The need to run libtoolize
5462 * Objects created both with libtool and without::  Avoid a specific build race
5463 @end menu
5464
5465 @node Error required file ltmain.sh not found
5466 @subsubsection Error: @samp{required file `./ltmain.sh' not found}
5467 @cindex @file{ltmain.sh} not found
5468 @cindex @command{libtoolize}, no longer run by @command{automake}
5469 @cindex @command{libtoolize} and @command{autoreconf}
5470 @cindex @command{autoreconf} and @command{libtoolize}
5471 @cindex @file{bootstrap.sh} and @command{autoreconf}
5472 @cindex @file{autogen.sh} and @command{autoreconf}
5473
5474 Libtool comes with a tool called @command{libtoolize} that will
5475 install libtool's supporting files into a package.  Running this
5476 command will install @file{ltmain.sh}.  You should execute it before
5477 @command{aclocal} and @command{automake}.
5478
5479 People upgrading old packages to newer autotools are likely to face
5480 this issue because older Automake versions used to call
5481 @command{libtoolize}.  Therefore old build scripts do not call
5482 @command{libtoolize}.
5483
5484 Since Automake 1.6, it has been decided that running
5485 @command{libtoolize} was none of Automake's business.  Instead, that
5486 functionality has been moved into the @command{autoreconf} command
5487 (@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
5488 The Autoconf Manual}).  If you do not want to remember what to run and
5489 when, just learn the @command{autoreconf} command.  Hopefully,
5490 replacing existing @file{bootstrap.sh} or @file{autogen.sh} scripts by
5491 a call to @command{autoreconf} should also free you from any similar
5492 incompatible change in the future.
5493
5494 @node Objects created both with libtool and without
5495 @subsubsection Objects @samp{created with both libtool and without}
5496
5497 Sometimes, the same source file is used both to build a libtool
5498 library and to build another non-libtool target (be it a program or
5499 another library).
5500
5501 Let's consider the following @file{Makefile.am}.
5502
5503 @example
5504 bin_PROGRAMS = prog
5505 prog_SOURCES = prog.c foo.c @dots{}
5506
5507 lib_LTLIBRARIES = libfoo.la
5508 libfoo_la_SOURCES = foo.c @dots{}
5509 @end example
5510
5511 @noindent
5512 (In this trivial case the issue could be avoided by linking
5513 @file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
5514 @code{prog_SOURCES}.  But let's assume we really want to keep
5515 @file{prog} and @file{libfoo.la} separate.)
5516
5517 Technically, it means that we should build @file{foo.$(OBJEXT)} for
5518 @file{prog}, and @file{foo.lo} for @file{libfoo.la}.  The problem is
5519 that in the course of creating @file{foo.lo}, libtool may erase (or
5520 replace) @file{foo.$(OBJEXT)}, and this cannot be avoided.
5521
5522 Therefore, when Automake detects this situation it will complain
5523 with a message such as
5524 @example
5525 object 'foo.$(OBJEXT)' created both with libtool and without
5526 @end example
5527
5528 A workaround for this issue is to ensure that these two objects get
5529 different basenames.  As explained in @ref{Renamed Objects}, this
5530 happens automatically when per-targets flags are used.
5531
5532 @example
5533 bin_PROGRAMS = prog
5534 prog_SOURCES = prog.c foo.c @dots{}
5535 prog_CFLAGS = $(AM_CFLAGS)
5536
5537 lib_LTLIBRARIES = libfoo.la
5538 libfoo_la_SOURCES = foo.c @dots{}
5539 @end example
5540
5541 @noindent
5542 Adding @samp{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
5543 when the @code{prog_CFLAGS} is defined, it is used instead of
5544 @code{AM_CFLAGS}.  However as a side effect it will cause
5545 @file{prog.c} and @file{foo.c} to be compiled as
5546 @file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)}, which solves
5547 the issue.
5548
5549 @node Program and Library Variables
5550 @section Program and Library Variables
5551
5552 Associated with each program is a collection of variables that can be
5553 used to modify how that program is built.  There is a similar list of
5554 such variables for each library.  The canonical name of the program (or
5555 library) is used as a base for naming these variables.
5556
5557 In the list below, we use the name ``maude'' to refer to the program or
5558 library.  In your @file{Makefile.am} you would replace this with the
5559 canonical name of your program.  This list also refers to ``maude'' as a
5560 program, but in general the same rules apply for both static and dynamic
5561 libraries; the documentation below notes situations where programs and
5562 libraries differ.
5563
5564 @vtable @code
5565 @item maude_SOURCES
5566 This variable, if it exists, lists all the source files that are
5567 compiled to build the program.  These files are added to the
5568 distribution by default.  When building the program, Automake will cause
5569 each source file to be compiled to a single @file{.o} file (or
5570 @file{.lo} when using libtool).  Normally these object files are named
5571 after the source file, but other factors can change this.  If a file in
5572 the @code{_SOURCES} variable has an unrecognized extension, Automake
5573 will do one of two things with it.  If a suffix rule exists for turning
5574 files with the unrecognized extension into @file{.o} files, then
5575 @command{automake} will treat this file as it will any other source file
5576 (@pxref{Support for Other Languages}).  Otherwise, the file will be
5577 ignored as though it were a header file.
5578
5579 The prefixes @code{dist_} and @code{nodist_} can be used to control
5580 whether files listed in a @code{_SOURCES} variable are distributed.
5581 @code{dist_} is redundant, as sources are distributed by default, but it
5582 can be specified for clarity if desired.
5583
5584 It is possible to have both @code{dist_} and @code{nodist_} variants of
5585 a given @code{_SOURCES} variable at once; this lets you easily
5586 distribute some files and not others, for instance:
5587
5588 @example
5589 nodist_maude_SOURCES = nodist.c
5590 dist_maude_SOURCES = dist-me.c
5591 @end example
5592
5593 By default the output file (on Unix systems, the @file{.o} file) will
5594 be put into the current build directory.  However, if the option
5595 @option{subdir-objects} is in effect in the current directory then the
5596 @file{.o} file will be put into the subdirectory named after the
5597 source file.  For instance, with @option{subdir-objects} enabled,
5598 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
5599 people prefer this mode of operation.  You can specify
5600 @option{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
5601 @cindex Subdirectory, objects in
5602 @cindex Objects in subdirectory
5603
5604
5605 @item EXTRA_maude_SOURCES
5606 Automake needs to know the list of files you intend to compile
5607 @emph{statically}.  For one thing, this is the only way Automake has of
5608 knowing what sort of language support a given @file{Makefile.in}
5609 requires.  @footnote{There are other, more obscure reasons for
5610 this limitation as well.}  This means that, for example, you can't put a
5611 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
5612 variable.  If you intend to conditionally compile source files and use
5613 @file{configure} to substitute the appropriate object names into, e.g.,
5614 @code{_LDADD} (see below), then you should list the corresponding source
5615 files in the @code{EXTRA_} variable.
5616
5617 This variable also supports @code{dist_} and @code{nodist_} prefixes.
5618 For instance, @code{nodist_EXTRA_maude_SOURCES} would list extra
5619 sources that may need to be built, but should not be distributed.
5620
5621 @item maude_AR
5622 A static library is created by default by invoking @samp{$(AR)
5623 $(ARFLAGS)} followed by the name of the library and then the objects
5624 being put into the library.  You can override this by setting the
5625 @code{_AR} variable.  This is usually used with C++; some C++
5626 compilers require a special invocation in order to instantiate all the
5627 templates that should go into a library.  For instance, the SGI C++
5628 compiler likes this variable set like so:
5629 @example
5630 libmaude_a_AR = $(CXX) -ar -o
5631 @end example
5632
5633 @item maude_LIBADD
5634 Extra objects can be added to a @emph{library} using the @code{_LIBADD}
5635 variable.  For instance, this should be used for objects determined by
5636 @command{configure} (@pxref{A Library}).
5637
5638 In the case of libtool libraries, @code{maude_LIBADD} can also refer
5639 to other libtool libraries.
5640
5641 @item maude_LDADD
5642 Extra objects (@file{*.$(OBJEXT)}) and libraries (@file{*.a},
5643 @file{*.la}) can be added to a @emph{program} by listing them in the
5644 @code{_LDADD} variable.  For instance, this should be used for objects
5645 determined by @command{configure} (@pxref{Linking}).
5646
5647 @code{_LDADD} and @code{_LIBADD} are inappropriate for passing
5648 program-specific linker flags (except for @option{-l}, @option{-L},
5649 @option{-dlopen} and @option{-dlpreopen}).  Use the @code{_LDFLAGS} variable
5650 for this purpose.
5651
5652 For instance, if your @file{configure.ac} uses @code{AC_PATH_XTRA}, you
5653 could link your program against the X libraries like so:
5654
5655 @example
5656 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
5657 @end example
5658
5659 We recommend that you use @option{-l} and @option{-L} only when
5660 referring to third-party libraries, and give the explicit file names
5661 of any library built by your package.  Doing so will ensure that
5662 @code{maude_DEPENDENCIES} (see below) is correctly defined by default.
5663
5664 @item maude_LDFLAGS
5665 This variable is used to pass extra flags to the link step of a program
5666 or a shared library.  It overrides the @code{AM_LDFLAGS} variable.
5667
5668 @item maude_LIBTOOLFLAGS
5669 This variable is used to pass extra options to @command{libtool}.
5670 It overrides the @code{AM_LIBTOOLFLAGS} variable.
5671 These options are output before @command{libtool}'s @option{--mode=@var{mode}}
5672 option, so they should not be mode-specific options (those belong to
5673 the compiler or linker flags).  @xref{Libtool Flags}.
5674
5675 @item maude_DEPENDENCIES
5676 @itemx EXTRA_maude_DEPENDENCIES
5677 It is also occasionally useful to have a target (program or library)
5678 depend on some other file that is not actually part of that target.
5679 This can be done using the @code{_DEPENDENCIES} variable.  Each
5680 target depends on the contents of such a variable, but no further
5681 interpretation is done.
5682
5683 Since these dependencies are associated to the link rule used to
5684 create the programs they should normally list files used by the link
5685 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la} files
5686 for programs; @file{*.lo} and @file{*.la} files for Libtool libraries;
5687 and @file{*.$(OBJEXT)} files for static libraries.  In rare cases you
5688 may need to add other kinds of files such as linker scripts, but
5689 @emph{listing a source file in @code{_DEPENDENCIES} is wrong}.  If
5690 some source file needs to be built before all the components of a
5691 program are built, consider using the @code{BUILT_SOURCES} variable
5692 (@pxref{Sources}).
5693
5694 If @code{_DEPENDENCIES} is not supplied, it is computed by Automake.
5695 The automatically-assigned value is the contents of @code{_LDADD} or
5696 @code{_LIBADD}, with most configure substitutions, @option{-l}, @option{-L},
5697 @option{-dlopen} and @option{-dlpreopen} options removed.  The configure
5698 substitutions that are left in are only @samp{$(LIBOBJS)} and
5699 @samp{$(ALLOCA)}; these are left because it is known that they will not
5700 cause an invalid value for @code{_DEPENDENCIES} to be generated.
5701
5702 @code{_DEPENDENCIES} is more likely used to perform conditional
5703 compilation using an @code{AC_SUBST} variable that contains a list of
5704 objects.  @xref{Conditional Sources}, and @ref{Conditional Libtool
5705 Sources}.
5706
5707 The @code{EXTRA_*_DEPENDENCIES} variable may be useful for cases where
5708 you merely want to augment the @command{automake}-generated
5709 @code{_DEPENDENCIES} variable rather than replacing it.
5710
5711 @item maude_LINK
5712 You can override the linker on a per-program basis.  By default the
5713 linker is chosen according to the languages used by the program.  For
5714 instance, a program that includes C++ source code would use the C++
5715 compiler to link.  The @code{_LINK} variable must hold the name of a
5716 command that can be passed all the @file{.o} file names and libraries
5717 to link against as arguments.  Note that the name of the underlying
5718 program is @emph{not} passed to @code{_LINK}; typically one uses
5719 @samp{$@@}:
5720
5721 @example
5722 maude_LINK = $(CCLD) -magic -o $@@
5723 @end example
5724
5725 If a @code{_LINK} variable is not supplied, it may still be generated
5726 and used by Automake due to the use of per-target link flags such as
5727 @code{_CFLAGS}, @code{_LDFLAGS} or @code{_LIBTOOLFLAGS}, in cases where
5728 they apply.
5729
5730 @item maude_CCASFLAGS
5731 @itemx maude_CFLAGS
5732 @itemx maude_CPPFLAGS
5733 @itemx maude_CXXFLAGS
5734 @itemx maude_FFLAGS
5735 @itemx maude_GCJFLAGS
5736 @itemx maude_LFLAGS
5737 @itemx maude_OBJCFLAGS
5738 @itemx maude_OBJCXXFLAGS
5739 @itemx maude_RFLAGS
5740 @itemx maude_UPCFLAGS
5741 @itemx maude_YFLAGS
5742 @cindex per-target compilation flags, defined
5743 Automake allows you to set compilation flags on a per-program (or
5744 per-library) basis.  A single source file can be included in several
5745 programs, and it will potentially be compiled with different flags for
5746 each program.  This works for any language directly supported by
5747 Automake.  These @dfn{per-target compilation flags} are
5748 @samp{_CCASFLAGS},
5749 @samp{_CFLAGS},
5750 @samp{_CPPFLAGS},
5751 @samp{_CXXFLAGS},
5752 @samp{_FFLAGS},
5753 @samp{_GCJFLAGS},
5754 @samp{_LFLAGS},
5755 @samp{_OBJCFLAGS},
5756 @samp{_OBJCXXFLAGS},
5757 @samp{_RFLAGS},
5758 @samp{_UPCFLAGS}, and
5759 @samp{_YFLAGS}.
5760
5761 When using a per-target compilation flag, Automake will choose a
5762 different name for the intermediate object files.  Ordinarily a file
5763 like @file{sample.c} will be compiled to produce @file{sample.o}.
5764 However, if the program's @code{_CFLAGS} variable is set, then the
5765 object file will be named, for instance, @file{maude-sample.o}.  (See
5766 also @ref{Renamed Objects}.)  The use of per-target compilation flags
5767 with C sources requires that the macro @code{AM_PROG_CC_C_O} be called
5768 from @file{configure.ac}.
5769
5770 In compilations with per-target flags, the ordinary @samp{AM_} form of
5771 the flags variable is @emph{not} automatically included in the
5772 compilation (however, the user form of the variable @emph{is} included).
5773 So for instance, if you want the hypothetical @file{maude} compilations
5774 to also use the value of @code{AM_CFLAGS}, you would need to write:
5775
5776 @example
5777 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
5778 @end example
5779
5780 @xref{Flag Variables Ordering}, for more discussion about the
5781 interaction between user variables, @samp{AM_} shadow variables, and
5782 per-target variables.
5783
5784 @item maude_SHORTNAME
5785 On some platforms the allowable file names are very short.  In order to
5786 support these systems and per-target compilation flags at the same
5787 time, Automake allows you to set a ``short name'' that will influence
5788 how intermediate object files are named.  For instance, in the following
5789 example,
5790
5791 @example
5792 bin_PROGRAMS = maude
5793 maude_CPPFLAGS = -DSOMEFLAG
5794 maude_SHORTNAME = m
5795 maude_SOURCES = sample.c @dots{}
5796 @end example
5797
5798 @noindent
5799 the object file would be named @file{m-sample.o} rather than
5800 @file{maude-sample.o}.
5801
5802 This facility is rarely needed in practice,
5803 and we recommend avoiding it until you find it is required.
5804 @end vtable
5805
5806 @node Default _SOURCES
5807 @section Default @code{_SOURCES}
5808
5809 @vindex _SOURCES
5810 @vindex SOURCES
5811 @cindex @code{_SOURCES}, default
5812 @cindex default @code{_SOURCES}
5813 @vindex AM_DEFAULT_SOURCE_EXT
5814
5815 @code{_SOURCES} variables are used to specify source files of programs
5816 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
5817 libraries (@pxref{A Shared Library}).
5818
5819 When no such variable is specified for a target, Automake will define
5820 one itself.  The default is to compile a single C file whose base name
5821 is the name of the target itself, with any extension replaced by
5822 @code{AM_DEFAULT_SOURCE_EXT}, which defaults to @file{.c}.
5823
5824 For example if you have the following somewhere in your
5825 @file{Makefile.am} with no corresponding @code{libfoo_a_SOURCES}:
5826
5827 @example
5828 lib_LIBRARIES = libfoo.a sub/libc++.a
5829 @end example
5830
5831 @noindent
5832 @file{libfoo.a} will be built using a default source file named
5833 @file{libfoo.c}, and @file{sub/libc++.a} will be built from
5834 @file{sub/libc++.c}.  (In older versions @file{sub/libc++.a}
5835 would be built from @file{sub_libc___a.c}, i.e., the default source
5836 was the canonized name of the target, with @file{.c} appended.
5837 We believe the new behavior is more sensible, but for backward
5838 compatibility @command{automake} will use the old name if a file or a rule
5839 with that name exists and @code{AM_DEFAULT_SOURCE_EXT} is not used.)
5840
5841 @cindex @code{check_PROGRAMS} example
5842 @vindex check_PROGRAMS
5843 Default sources are mainly useful in test suites, when building many
5844 test programs each from a single source.  For instance, in
5845
5846 @example
5847 check_PROGRAMS = test1 test2 test3
5848 AM_DEFAULT_SOURCE_EXT = .cpp
5849 @end example
5850
5851 @noindent
5852 @file{test1}, @file{test2}, and @file{test3} will be built
5853 from @file{test1.cpp}, @file{test2.cpp}, and @file{test3.cpp}.
5854 Without the last line, they will be built from @file{test1.c},
5855 @file{test2.c}, and @file{test3.c}.
5856
5857 @cindex Libtool modules, default source example
5858 @cindex default source, Libtool modules example
5859 Another case where this is convenient is building many Libtool modules
5860 (@file{module@var{n}.la}), each defined in its own file
5861 (@file{module@var{n}.c}).
5862
5863 @example
5864 AM_LDFLAGS = -module
5865 lib_LTLIBRARIES = module1.la module2.la module3.la
5866 @end example
5867
5868 @cindex empty @code{_SOURCES}
5869 @cindex @code{_SOURCES}, empty
5870 Finally, there is one situation where this default source computation
5871 needs to be avoided: when a target should not be built from sources.
5872 We already saw such an example in @ref{true}; this happens when all
5873 the constituents of a target have already been compiled and just need
5874 to be combined using a @code{_LDADD} variable.  Then it is necessary
5875 to define an empty @code{_SOURCES} variable, so that @command{automake}
5876 does not compute a default.
5877
5878 @example
5879 bin_PROGRAMS = target
5880 target_SOURCES =
5881 target_LDADD = libmain.a libmisc.a
5882 @end example
5883
5884 @node LIBOBJS
5885 @section Special handling for @code{LIBOBJS} and @code{ALLOCA}
5886
5887 @cindex @code{LIBOBJS}, example
5888 @cindex @code{ALLOCA}, example
5889 @cindex @code{LIBOBJS}, special handling
5890 @cindex @code{ALLOCA}, special handling
5891 @vindex LTLIBOBJS
5892 @vindex LIBOBJS
5893 @vindex LTALLOCA
5894 @vindex ALLOCA
5895
5896 The @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} variables list object
5897 files that should be compiled into the project to provide an
5898 implementation for functions that are missing or broken on the host
5899 system.  They are substituted by @file{configure}.
5900
5901 @acindex AC_LIBOBJ
5902
5903 These variables are defined by Autoconf macros such as
5904 @code{AC_LIBOBJ}, @code{AC_REPLACE_FUNCS} (@pxref{Generic Functions, ,
5905 Generic Function Checks, autoconf, The Autoconf Manual}), or
5906 @code{AC_FUNC_ALLOCA} (@pxref{Particular Functions, , Particular
5907 Function Checks, autoconf, The Autoconf Manual}).  Many other Autoconf
5908 macros call @code{AC_LIBOBJ} or @code{AC_REPLACE_FUNCS} to
5909 populate @samp{$(LIBOBJS)}.
5910
5911 @acindex AC_LIBSOURCE
5912
5913 Using these variables is very similar to doing conditional compilation
5914 using @code{AC_SUBST} variables, as described in @ref{Conditional
5915 Sources}.  That is, when building a program, @samp{$(LIBOBJS)} and
5916 @samp{$(ALLOCA)} should be added to the associated @samp{*_LDADD}
5917 variable, or to the @samp{*_LIBADD} variable when building a library.
5918 However there is no need to list the corresponding sources in
5919 @samp{EXTRA_*_SOURCES} nor to define @samp{*_DEPENDENCIES}.  Automake
5920 automatically adds @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} to the
5921 dependencies, and it will discover the list of corresponding source
5922 files automatically (by tracing the invocations of the
5923 @code{AC_LIBSOURCE} Autoconf macros).  If you have already defined
5924 @samp{*_DEPENDENCIES} explicitly for an unrelated reason, then you
5925 either need to add these variables manually, or use
5926 @samp{EXTRA_*_DEPENDENCIES} instead of @samp{*_DEPENDENCIES}.
5927
5928 These variables are usually used to build a portability library that
5929 is linked with all the programs of the project.  We now review a
5930 sample setup.  First, @file{configure.ac} contains some checks that
5931 affect either @code{LIBOBJS} or @code{ALLOCA}.
5932
5933 @example
5934 # configure.ac
5935 @dots{}
5936 AC_CONFIG_LIBOBJ_DIR([lib])
5937 @dots{}
5938 AC_FUNC_MALLOC             dnl May add malloc.$(OBJEXT) to LIBOBJS
5939 AC_FUNC_MEMCMP             dnl May add memcmp.$(OBJEXT) to LIBOBJS
5940 AC_REPLACE_FUNCS([strdup]) dnl May add strdup.$(OBJEXT) to LIBOBJS
5941 AC_FUNC_ALLOCA             dnl May add alloca.$(OBJEXT) to ALLOCA
5942 @dots{}
5943 AC_CONFIG_FILES([
5944   lib/Makefile
5945   src/Makefile
5946 ])
5947 AC_OUTPUT
5948 @end example
5949
5950 @acindex AC_CONFIG_LIBOBJ_DIR
5951
5952 The @code{AC_CONFIG_LIBOBJ_DIR} tells Autoconf that the source files
5953 of these object files are to be found in the @file{lib/} directory.
5954 Automake can also use this information, otherwise it expects the
5955 source files are to be in the directory where the @samp{$(LIBOBJS)}
5956 and @samp{$(ALLOCA)} variables are used.
5957
5958 The @file{lib/} directory should therefore contain @file{malloc.c},
5959 @file{memcmp.c}, @file{strdup.c}, @file{alloca.c}.  Here is its
5960 @file{Makefile.am}:
5961
5962 @example
5963 # lib/Makefile.am
5964
5965 noinst_LIBRARIES = libcompat.a
5966 libcompat_a_SOURCES =
5967 libcompat_a_LIBADD = $(LIBOBJS) $(ALLOCA)
5968 @end example
5969
5970 The library can have any name, of course, and anyway it is not going
5971 to be installed: it just holds the replacement versions of the missing
5972 or broken functions so we can later link them in.  Many projects
5973 also include extra functions, specific to the project, in that
5974 library: they are simply added on the @code{_SOURCES} line.
5975
5976 @cindex Empty libraries and @samp{$(LIBOBJS)}
5977 @cindex @samp{$(LIBOBJS)} and empty libraries
5978 There is a small trap here, though: @samp{$(LIBOBJS)} and
5979 @samp{$(ALLOCA)} might be empty, and building an empty library is not
5980 portable.  You should ensure that there is always something to put in
5981 @file{libcompat.a}.  Most projects will also add some utility
5982 functions in that directory, and list them in
5983 @code{libcompat_a_SOURCES}, so in practice @file{libcompat.a} cannot
5984 be empty.
5985
5986 Finally here is how this library could be used from the @file{src/}
5987 directory.
5988
5989 @example
5990 # src/Makefile.am
5991
5992 # Link all programs in this directory with libcompat.a
5993 LDADD = ../lib/libcompat.a
5994
5995 bin_PROGRAMS = tool1 tool2 @dots{}
5996 tool1_SOURCES = @dots{}
5997 tool2_SOURCES = @dots{}
5998 @end example
5999
6000 When option @option{subdir-objects} is not used, as in the above
6001 example, the variables @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} can only
6002 be used in the directory where their sources lie.  E.g., here it would
6003 be wrong to use @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} in
6004 @file{src/Makefile.am}.  However if both @option{subdir-objects} and
6005 @code{AC_CONFIG_LIBOBJ_DIR} are used, it is OK to use these variables
6006 in other directories.  For instance @file{src/Makefile.am} could be
6007 changed as follows.
6008
6009 @example
6010 # src/Makefile.am
6011
6012 AUTOMAKE_OPTIONS = subdir-objects
6013 LDADD = $(LIBOBJS) $(ALLOCA)
6014
6015 bin_PROGRAMS = tool1 tool2 @dots{}
6016 tool1_SOURCES = @dots{}
6017 tool2_SOURCES = @dots{}
6018 @end example
6019
6020 Because @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} contain object
6021 file names that end with @samp{.$(OBJEXT)}, they are not suitable for
6022 Libtool libraries (where the expected object extension is @file{.lo}):
6023 @code{LTLIBOBJS} and @code{LTALLOCA} should be used instead.
6024
6025 @code{LTLIBOBJS} is defined automatically by Autoconf and should not
6026 be defined by hand (as in the past), however at the time of writing
6027 @code{LTALLOCA} still needs to be defined from @code{ALLOCA} manually.
6028 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
6029 autoconf, The Autoconf Manual}.
6030
6031
6032 @node Program Variables
6033 @section Variables used when building a program
6034
6035 Occasionally it is useful to know which @file{Makefile} variables
6036 Automake uses for compilations, and in which order (@pxref{Flag
6037 Variables Ordering}); for instance, you might need to do your own
6038 compilation in some special cases.
6039
6040 Some variables are inherited from Autoconf; these are @code{CC},
6041 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
6042 @code{LIBS}.
6043 @vindex CC
6044 @vindex CFLAGS
6045 @vindex CPPFLAGS
6046 @vindex DEFS
6047 @vindex LDFLAGS
6048 @vindex LIBS
6049
6050 There are some additional variables that Automake defines on its own:
6051
6052 @vtable @code
6053 @item AM_CPPFLAGS
6054 The contents of this variable are passed to every compilation that invokes
6055 the C preprocessor; it is a list of arguments to the preprocessor.  For
6056 instance, @option{-I} and @option{-D} options should be listed here.
6057
6058 Automake already provides some @option{-I} options automatically, in a
6059 separate variable that is also passed to every compilation that invokes
6060 the C preprocessor.  In particular it generates @samp{-I.},
6061 @samp{-I$(srcdir)}, and a @option{-I} pointing to the directory holding
6062 @file{config.h} (if you've used @code{AC_CONFIG_HEADERS}).  You can
6063 disable the default @option{-I} options using the @option{nostdinc}
6064 option.
6065
6066 When a file to be included is generated during the build and not part
6067 of a distribution tarball, its location is under @code{$(builddir)},
6068 not under @code{$(srcdir)}.  This matters especially for packages that
6069 use header files placed in sub-directories and want to allow builds
6070 outside the source tree (@pxref{VPATH Builds}). In that case we
6071 recommend to use a pair of @option{-I} options, such as, e.g.,
6072 @samp{-Isome/subdir -I$(srcdir)/some/subdir} or
6073 @samp{-I$(top_builddir)/some/subdir -I$(top_srcdir)/some/subdir}.
6074 Note that the reference to the build tree should come before the
6075 reference to the source tree, so that accidentally leftover generated
6076 files in the source directory are ignored.
6077
6078 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
6079 per-library) @code{_CPPFLAGS} variable if it is defined.
6080
6081 @item INCLUDES
6082 This does the same job as @code{AM_CPPFLAGS} (or any per-target
6083 @code{_CPPFLAGS} variable if it is used).  It is an older name for the
6084 same functionality.  This variable is deprecated; we suggest using
6085 @code{AM_CPPFLAGS} and per-target @code{_CPPFLAGS} instead.
6086
6087 @item AM_CFLAGS
6088 This is the variable the @file{Makefile.am} author can use to pass
6089 in additional C compiler flags.  It is more fully documented elsewhere.
6090 In some situations, this is not used, in preference to the
6091 per-executable (or per-library) @code{_CFLAGS}.
6092
6093 @item COMPILE
6094 This is the command used to actually compile a C source file.  The
6095 file name is appended to form the complete command line.
6096
6097 @item AM_LDFLAGS
6098 This is the variable the @file{Makefile.am} author can use to pass
6099 in additional linker flags.  In some situations, this is not used, in
6100 preference to the per-executable (or per-library) @code{_LDFLAGS}.
6101
6102 @item LINK
6103 This is the command used to actually link a C program.  It already
6104 includes @samp{-o $@@} and the usual variable references (for instance,
6105 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
6106 and libraries to link in.  This variable is not used when the linker is
6107 overridden with a per-target @code{_LINK} variable or per-target flags
6108 cause Automake to define such a @code{_LINK} variable.
6109 @end vtable
6110
6111
6112 @node Yacc and Lex
6113 @section Yacc and Lex support
6114
6115 Automake has somewhat idiosyncratic support for Yacc and Lex.
6116
6117 Automake assumes that the @file{.c} file generated by @command{yacc}
6118 (or @command{lex}) should be named using the basename of the input
6119 file.  That is, for a yacc source file @file{foo.y}, Automake will
6120 cause the intermediate file to be named @file{foo.c} (as opposed to
6121 @file{y.tab.c}, which is more traditional).
6122
6123 The extension of a yacc source file is used to determine the extension
6124 of the resulting C or C++ source and header files.  Note that header
6125 files are generated only when the @option{-d} Yacc option is used; see
6126 below for more information about this flag, and how to specify it.
6127 Files with the extension @file{.y} will thus be turned into @file{.c}
6128 sources and @file{.h} headers; likewise, @file{.yy} will become
6129 @file{.cc} and @file{.hh}, @file{.y++} will become @file{c++} and
6130 @file{h++}, @file{.yxx} will become @file{.cxx} and @file{.hxx},
6131 and @file{.ypp} will become @file{.cpp} and @file{.hpp}.
6132
6133 Similarly, lex source files can be used to generate C or C++; the
6134 extensions @file{.l}, @file{.ll}, @file{.l++}, @file{.lxx}, and
6135 @file{.lpp} are recognized.
6136
6137 You should never explicitly mention the intermediate (C or C++) file
6138 in any @code{SOURCES} variable; only list the source file.
6139
6140 The intermediate files generated by @command{yacc} (or @command{lex})
6141 will be included in any distribution that is made.  That way the user
6142 doesn't need to have @command{yacc} or @command{lex}.
6143
6144 If a @command{yacc} source file is seen, then your @file{configure.ac} must
6145 define the variable @code{YACC}.  This is most easily done by invoking
6146 the macro @code{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
6147 Program Checks, autoconf, The Autoconf Manual}).
6148
6149 @vindex YFLAGS
6150 @vindex AM_YFLAGS
6151 When @code{yacc} is invoked, it is passed @code{AM_YFLAGS} and
6152 @code{YFLAGS}.  The latter is a user variable and the former is
6153 intended for the @file{Makefile.am} author.
6154
6155 @code{AM_YFLAGS} is usually used to pass the @option{-d} option to
6156 @command{yacc}.  Automake knows what this means and will automatically
6157 adjust its rules to update and distribute the header file built by
6158 @samp{yacc -d}@footnote{Please note that @command{automake} recognizes
6159 @option{-d} in @code{AM_YFLAGS} only if it is not clustered with other
6160 options; for example, it won't be recognized if @code{AM_YFLAGS} is
6161 @option{-dt}, but it will be if @code{AM_YFLAGS} is @option{-d -t} or
6162 @option{-t -d}.}.
6163 What Automake cannot guess, though, is where this
6164 header will be used: it is up to you to ensure the header gets built
6165 before it is first used.  Typically this is necessary in order for
6166 dependency tracking to work when the header is included by another
6167 file.  The common solution is listing the header file in
6168 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
6169
6170 @example
6171 BUILT_SOURCES = parser.h
6172 AM_YFLAGS = -d
6173 bin_PROGRAMS = foo
6174 foo_SOURCES = @dots{} parser.y @dots{}
6175 @end example
6176
6177 If a @command{lex} source file is seen, then your @file{configure.ac}
6178 must define the variable @code{LEX}.  You can use @code{AC_PROG_LEX}
6179 to do this (@pxref{Particular Programs, , Particular Program Checks,
6180 autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
6181 (@pxref{Macros}) is recommended.
6182
6183 @vindex LFLAGS
6184 @vindex AM_LFLAGS
6185 When @command{lex} is invoked, it is passed @code{AM_LFLAGS} and
6186 @code{LFLAGS}.  The latter is a user variable and the former is
6187 intended for the @file{Makefile.am} author.
6188
6189 When @code{AM_MAINTAINER_MODE} (@pxref{maintainer-mode}) is used, the
6190 rebuild rule for distributed Yacc and Lex sources are only used when
6191 @code{maintainer-mode} is enabled, or when the files have been erased.
6192
6193 @cindex @command{ylwrap}
6194 @cindex @command{yacc}, multiple parsers
6195 @cindex Multiple @command{yacc} parsers
6196 @cindex Multiple @command{lex} lexers
6197 @cindex @command{lex}, multiple lexers
6198
6199 When @command{lex} or @command{yacc} sources are used, @code{automake
6200 -i} automatically installs an auxiliary program called
6201 @command{ylwrap} in your package (@pxref{Auxiliary Programs}).  This
6202 program is used by the build rules to rename the output of these
6203 tools, and makes it possible to include multiple @command{yacc} (or
6204 @command{lex}) source files in a single directory.  (This is necessary
6205 because yacc's output file name is fixed, and a parallel make could
6206 conceivably invoke more than one instance of @command{yacc}
6207 simultaneously.)
6208
6209 For @command{yacc}, simply managing locking is insufficient.  The output of
6210 @command{yacc} always uses the same symbol names internally, so it isn't
6211 possible to link two @command{yacc} parsers into the same executable.
6212
6213 We recommend using the following renaming hack used in @command{gdb}:
6214 @example
6215 #define yymaxdepth c_maxdepth
6216 #define yyparse c_parse
6217 #define yylex   c_lex
6218 #define yyerror c_error
6219 #define yylval  c_lval
6220 #define yychar  c_char
6221 #define yydebug c_debug
6222 #define yypact  c_pact
6223 #define yyr1    c_r1
6224 #define yyr2    c_r2
6225 #define yydef   c_def
6226 #define yychk   c_chk
6227 #define yypgo   c_pgo
6228 #define yyact   c_act
6229 #define yyexca  c_exca
6230 #define yyerrflag c_errflag
6231 #define yynerrs c_nerrs
6232 #define yyps    c_ps
6233 #define yypv    c_pv
6234 #define yys     c_s
6235 #define yy_yys  c_yys
6236 #define yystate c_state
6237 #define yytmp   c_tmp
6238 #define yyv     c_v
6239 #define yy_yyv  c_yyv
6240 #define yyval   c_val
6241 #define yylloc  c_lloc
6242 #define yyreds  c_reds
6243 #define yytoks  c_toks
6244 #define yylhs   c_yylhs
6245 #define yylen   c_yylen
6246 #define yydefred c_yydefred
6247 #define yydgoto  c_yydgoto
6248 #define yysindex c_yysindex
6249 #define yyrindex c_yyrindex
6250 #define yygindex c_yygindex
6251 #define yytable  c_yytable
6252 #define yycheck  c_yycheck
6253 #define yyname   c_yyname
6254 #define yyrule   c_yyrule
6255 @end example
6256
6257 For each define, replace the @samp{c_} prefix with whatever you like.
6258 These defines work for @command{bison}, @command{byacc}, and
6259 traditional @code{yacc}s.  If you find a parser generator that uses a
6260 symbol not covered here, please report the new name so it can be added
6261 to the list.
6262
6263
6264 @node C++ Support
6265 @section C++ Support
6266
6267 @cindex C++ support
6268 @cindex Support for C++
6269
6270 Automake includes full support for C++.
6271
6272 Any package including C++ code must define the output variable
6273 @code{CXX} in @file{configure.ac}; the simplest way to do this is to use
6274 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
6275 Program Checks, autoconf, The Autoconf Manual}).
6276
6277 A few additional variables are defined when a C++ source file is seen:
6278
6279 @vtable @code
6280 @item CXX
6281 The name of the C++ compiler.
6282
6283 @item CXXFLAGS
6284 Any flags to pass to the C++ compiler.
6285
6286 @item AM_CXXFLAGS
6287 The maintainer's variant of @code{CXXFLAGS}.
6288
6289 @item CXXCOMPILE
6290 The command used to actually compile a C++ source file.  The file name
6291 is appended to form the complete command line.
6292
6293 @item CXXLINK
6294 The command used to actually link a C++ program.
6295 @end vtable
6296
6297
6298 @node Objective C Support
6299 @section Objective C Support
6300
6301 @cindex Objective C support
6302 @cindex Support for Objective C
6303
6304 Automake includes some support for Objective C.
6305
6306 Any package including Objective C code must define the output variable
6307 @code{OBJC} in @file{configure.ac}; the simplest way to do this is to use
6308 the @code{AC_PROG_OBJC} macro (@pxref{Particular Programs, , Particular
6309 Program Checks, autoconf, The Autoconf Manual}).
6310
6311 A few additional variables are defined when an Objective C source file
6312 is seen:
6313
6314 @vtable @code
6315 @item OBJC
6316 The name of the Objective C compiler.
6317
6318 @item OBJCFLAGS
6319 Any flags to pass to the Objective C compiler.
6320
6321 @item AM_OBJCFLAGS
6322 The maintainer's variant of @code{OBJCFLAGS}.
6323
6324 @item OBJCCOMPILE
6325 The command used to actually compile an Objective C source file.  The
6326 file name is appended to form the complete command line.
6327
6328 @item OBJCLINK
6329 The command used to actually link an Objective C program.
6330 @end vtable
6331
6332
6333 @node Objective C++ Support
6334 @section Objective C++ Support
6335
6336 @cindex Objective C++ support
6337 @cindex Support for Objective C++
6338
6339 Automake includes some support for Objective C++.
6340
6341 Any package including Objective C++ code must define the output variable
6342 @code{OBJCXX} in @file{configure.ac}; the simplest way to do this is to use
6343 the @code{AC_PROG_OBJCXX} macro (@pxref{Particular Programs, , Particular
6344 Program Checks, autoconf, The Autoconf Manual}).
6345
6346 A few additional variables are defined when an Objective C++ source file
6347 is seen:
6348
6349 @vtable @code
6350 @item OBJCXX
6351 The name of the Objective C++ compiler.
6352
6353 @item OBJCXXFLAGS
6354 Any flags to pass to the Objective C++ compiler.
6355
6356 @item AM_OBJCXXFLAGS
6357 The maintainer's variant of @code{OBJCXXFLAGS}.
6358
6359 @item OBJCXXCOMPILE
6360 The command used to actually compile an Objective C++ source file.  The
6361 file name is appended to form the complete command line.
6362
6363 @item OBJCXXLINK
6364 The command used to actually link an Objective C++ program.
6365 @end vtable
6366
6367
6368 @node Unified Parallel C Support
6369 @section Unified Parallel C Support
6370
6371 @cindex Unified Parallel C support
6372 @cindex Support for Unified Parallel C
6373
6374 Automake includes some support for Unified Parallel C.
6375
6376 Any package including Unified Parallel C code must define the output
6377 variable @code{UPC} in @file{configure.ac}; the simplest way to do
6378 this is to use the @code{AM_PROG_UPC} macro (@pxref{Public Macros}).
6379
6380 A few additional variables are defined when a Unified Parallel C
6381 source file is seen:
6382
6383 @vtable @code
6384 @item UPC
6385 The name of the Unified Parallel C compiler.
6386
6387 @item UPCFLAGS
6388 Any flags to pass to the Unified Parallel C compiler.
6389
6390 @item AM_UPCFLAGS
6391 The maintainer's variant of @code{UPCFLAGS}.
6392
6393 @item UPCCOMPILE
6394 The command used to actually compile a Unified Parallel C source file.
6395 The file name is appended to form the complete command line.
6396
6397 @item UPCLINK
6398 The command used to actually link a Unified Parallel C program.
6399 @end vtable
6400
6401
6402 @node Assembly Support
6403 @section Assembly Support
6404
6405 Automake includes some support for assembly code.  There are two forms
6406 of assembler files: normal (@file{*.s}) and preprocessed by @code{CPP}
6407 (@file{*.S} or @file{*.sx}).
6408
6409 @vindex CCAS
6410 @vindex CCASFLAGS
6411 @vindex CPPFLAGS
6412 @vindex AM_CCASFLAGS
6413 @vindex AM_CPPFLAGS
6414 The variable @code{CCAS} holds the name of the compiler used to build
6415 assembly code.  This compiler must work a bit like a C compiler; in
6416 particular it must accept @option{-c} and @option{-o}.  The values of
6417 @code{CCASFLAGS} and @code{AM_CCASFLAGS} (or its per-target
6418 definition) is passed to the compilation.  For preprocessed files,
6419 @code{DEFS}, @code{DEFAULT_INCLUDES}, @code{INCLUDES}, @code{CPPFLAGS}
6420 and @code{AM_CPPFLAGS} are also used.
6421
6422 The autoconf macro @code{AM_PROG_AS} will define @code{CCAS} and
6423 @code{CCASFLAGS} for you (unless they are already set, it simply sets
6424 @code{CCAS} to the C compiler and @code{CCASFLAGS} to the C compiler
6425 flags), but you are free to define these variables by other means.
6426
6427 Only the suffixes @file{.s}, @file{.S}, and @file{.sx} are recognized by
6428 @command{automake} as being files containing assembly code.
6429
6430
6431 @node Fortran 77 Support
6432 @comment  node-name,  next,  previous,  up
6433 @section Fortran 77 Support
6434
6435 @cindex Fortran 77 support
6436 @cindex Support for Fortran 77
6437
6438 Automake includes full support for Fortran 77.
6439
6440 Any package including Fortran 77 code must define the output variable
6441 @code{F77} in @file{configure.ac}; the simplest way to do this is to use
6442 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
6443 Program Checks, autoconf, The Autoconf Manual}).
6444
6445 A few additional variables are defined when a Fortran 77 source file is
6446 seen:
6447
6448 @vtable @code
6449
6450 @item F77
6451 The name of the Fortran 77 compiler.
6452
6453 @item FFLAGS
6454 Any flags to pass to the Fortran 77 compiler.
6455
6456 @item AM_FFLAGS
6457 The maintainer's variant of @code{FFLAGS}.
6458
6459 @item RFLAGS
6460 Any flags to pass to the Ratfor compiler.
6461
6462 @item AM_RFLAGS
6463 The maintainer's variant of @code{RFLAGS}.
6464
6465 @item F77COMPILE
6466 The command used to actually compile a Fortran 77 source file.  The file
6467 name is appended to form the complete command line.
6468
6469 @item FLINK
6470 The command used to actually link a pure Fortran 77 program or shared
6471 library.
6472
6473 @end vtable
6474
6475 Automake can handle preprocessing Fortran 77 and Ratfor source files in
6476 addition to compiling them@footnote{Much, if not most, of the
6477 information in the following sections pertaining to preprocessing
6478 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
6479 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
6480 also contains some support for creating programs and shared libraries
6481 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
6482 Fortran 77 With C and C++}).
6483
6484 These issues are covered in the following sections.
6485
6486 @menu
6487 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
6488 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
6489 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
6490 @end menu
6491
6492
6493 @node Preprocessing Fortran 77
6494 @comment  node-name,  next,  previous,  up
6495 @subsection Preprocessing Fortran 77
6496
6497 @cindex Preprocessing Fortran 77
6498 @cindex Fortran 77, Preprocessing
6499 @cindex Ratfor programs
6500
6501 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
6502 rule runs just the preprocessor to convert a preprocessable Fortran 77
6503 or Ratfor source file into a strict Fortran 77 source file.  The precise
6504 command used is as follows:
6505
6506 @table @file
6507
6508 @item .F
6509 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6510 $(AM_FFLAGS) $(FFLAGS)}
6511
6512 @item .r
6513 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6514
6515 @end table
6516
6517
6518 @node Compiling Fortran 77 Files
6519 @comment  node-name,  next,  previous,  up
6520 @subsection Compiling Fortran 77 Files
6521
6522 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
6523 @file{N.r} by running the Fortran 77 compiler.  The precise command used
6524 is as follows:
6525
6526 @table @file
6527
6528 @item .f
6529 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
6530
6531 @item .F
6532 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6533 $(AM_FFLAGS) $(FFLAGS)}
6534
6535 @item .r
6536 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6537
6538 @end table
6539
6540
6541 @node Mixing Fortran 77 With C and C++
6542 @comment  node-name,  next,  previous,  up
6543 @subsection Mixing Fortran 77 With C and C++
6544
6545 @cindex Fortran 77, mixing with C and C++
6546 @cindex Mixing Fortran 77 with C and C++
6547 @cindex Linking Fortran 77 with C and C++
6548 @cindex cfortran
6549 @cindex Mixing Fortran 77 with C and/or C++
6550
6551 Automake currently provides @emph{limited} support for creating programs
6552 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
6553 However, there are many other issues related to mixing Fortran 77 with
6554 other languages that are @emph{not} (currently) handled by Automake, but
6555 that are handled by other packages@footnote{For example,
6556 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
6557 addresses all of these inter-language issues, and runs under nearly all
6558 Fortran 77, C and C++ compilers on nearly all platforms.  However,
6559 @command{cfortran} is not yet Free Software, but it will be in the next
6560 major release.}.
6561
6562 Automake can help in two ways:
6563
6564 @enumerate
6565 @item
6566 Automatic selection of the linker depending on which combinations of
6567 source code.
6568
6569 @item
6570 Automatic selection of the appropriate linker flags (e.g., @option{-L} and
6571 @option{-l}) to pass to the automatically selected linker in order to link
6572 in the appropriate Fortran 77 intrinsic and run-time libraries.
6573
6574 @cindex @code{FLIBS}, defined
6575 @vindex FLIBS
6576 These extra Fortran 77 linker flags are supplied in the output variable
6577 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro.
6578 @xref{Fortran Compiler, , Fortran Compiler Characteristics, autoconf,
6579 The Autoconf Manual}.
6580 @end enumerate
6581
6582 If Automake detects that a program or shared library (as mentioned in
6583 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
6584 code that is a mixture of Fortran 77 and C and/or C++, then it requires
6585 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
6586 @file{configure.ac}, and that either @code{$(FLIBS)}
6587 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
6588 (for shared libraries) variables.  It is the responsibility of the
6589 person writing the @file{Makefile.am} to make sure that @samp{$(FLIBS)}
6590 appears in the appropriate @code{_LDADD} or
6591 @code{_LIBADD} variable.
6592
6593 @cindex Mixed language example
6594 @cindex Example, mixed language
6595
6596 For example, consider the following @file{Makefile.am}:
6597
6598 @example
6599 bin_PROGRAMS = foo
6600 foo_SOURCES  = main.cc foo.f
6601 foo_LDADD    = libfoo.la $(FLIBS)
6602
6603 pkglib_LTLIBRARIES = libfoo.la
6604 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
6605 libfoo_la_LIBADD   = $(FLIBS)
6606 @end example
6607
6608 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
6609 is mentioned in @file{configure.ac}.  Also, if @samp{$(FLIBS)} hadn't
6610 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
6611 Automake would have issued a warning.
6612
6613 @menu
6614 * How the Linker is Chosen::    Automatic linker selection
6615 @end menu
6616
6617 @node How the Linker is Chosen
6618 @comment  node-name,  next,  previous,  up
6619 @subsubsection How the Linker is Chosen
6620
6621 @cindex Automatic linker selection
6622 @cindex Selecting the linker automatically
6623
6624 When a program or library mixes several languages, Automake choose the
6625 linker according to the following priorities.  (The names in
6626 parentheses are the variables containing the link command.)
6627
6628 @enumerate
6629 @item
6630 @vindex GCJLINK
6631 Native Java (@code{GCJLINK})
6632 @item
6633 @vindex OBJCXXLINK
6634 Objective C++ (@code{OBJCXXLINK})
6635 @item
6636 @vindex CXXLINK
6637 C++ (@code{CXXLINK})
6638 @item
6639 @vindex F77LINK
6640 Fortran 77 (@code{F77LINK})
6641 @item
6642 @vindex FCLINK
6643 Fortran (@code{FCLINK})
6644 @item
6645 @vindex OBJCLINK
6646 Objective C (@code{OBJCLINK})
6647 @item
6648 @vindex UPCLINK
6649 Unified Parallel C (@code{UPCLINK})
6650 @item
6651 @vindex LINK
6652 C (@code{LINK})
6653 @end enumerate
6654
6655 For example, if Fortran 77, C and C++ source code is compiled
6656 into a program, then the C++ linker will be used.  In this case, if the
6657 C or Fortran 77 linkers required any special libraries that weren't
6658 included by the C++ linker, then they must be manually added to an
6659 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
6660 @file{Makefile.am}.
6661
6662 Automake only looks at the file names listed in @file{_SOURCES}
6663 variables to choose the linker, and defaults to the C linker.
6664 Sometimes this is inconvenient because you are linking against a
6665 library written in another language and would like to set the linker
6666 more appropriately.  @xref{Libtool Convenience Libraries}, for a
6667 trick with @code{nodist_EXTRA_@dots{}_SOURCES}.
6668
6669 A per-target @code{_LINK} variable will override the above selection.
6670 Per-target link flags will cause Automake to write a per-target
6671 @code{_LINK} variable according to the language chosen as above.
6672
6673
6674 @node Fortran 9x Support
6675 @comment  node-name,  next,  previous,  up
6676 @section Fortran 9x Support
6677
6678 @cindex Fortran 9x support
6679 @cindex Support for Fortran 9x
6680
6681 Automake includes support for Fortran 9x.
6682
6683 Any package including Fortran 9x code must define the output variable
6684 @code{FC} in @file{configure.ac}; the simplest way to do this is to use
6685 the @code{AC_PROG_FC} macro (@pxref{Particular Programs, , Particular
6686 Program Checks, autoconf, The Autoconf Manual}).
6687
6688 A few additional variables are defined when a Fortran 9x source file is
6689 seen:
6690
6691 @vtable @code
6692
6693 @item FC
6694 The name of the Fortran 9x compiler.
6695
6696 @item FCFLAGS
6697 Any flags to pass to the Fortran 9x compiler.
6698
6699 @item AM_FCFLAGS
6700 The maintainer's variant of @code{FCFLAGS}.
6701
6702 @item FCCOMPILE
6703 The command used to actually compile a Fortran 9x source file.  The file
6704 name is appended to form the complete command line.
6705
6706 @item FCLINK
6707 The command used to actually link a pure Fortran 9x program or shared
6708 library.
6709
6710 @end vtable
6711
6712 @menu
6713 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
6714 @end menu
6715
6716 @node Compiling Fortran 9x Files
6717 @comment  node-name,  next,  previous,  up
6718 @subsection Compiling Fortran 9x Files
6719
6720 @file{@var{file}.o} is made automatically from @file{@var{file}.f90},
6721 @file{@var{file}.f95}, @file{@var{file}.f03}, or @file{@var{file}.f08}
6722 by running the Fortran 9x compiler.  The precise command used
6723 is as follows:
6724
6725 @table @file
6726
6727 @item .f90
6728 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f90) $<}
6729
6730 @item .f95
6731 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f95) $<}
6732
6733 @item .f03
6734 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f03) $<}
6735
6736 @item .f08
6737 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f08) $<}
6738
6739 @end table
6740
6741 @node Java Support with gcj
6742 @comment  node-name,  next,  previous,  up
6743 @section Compiling Java sources using gcj
6744
6745 @cindex Java support with gcj
6746 @cindex Support for Java with gcj
6747 @cindex Java to native code, compilation
6748 @cindex Compilation of Java to native code
6749
6750 Automake includes support for natively compiled Java, using @command{gcj},
6751 the Java front end to the GNU Compiler Collection (rudimentary support
6752 for compiling Java to bytecode using the @command{javac} compiler is
6753 also present, @emph{albeit deprecated}; @pxref{Java}).
6754
6755 Any package including Java code to be compiled must define the output
6756 variable @code{GCJ} in @file{configure.ac}; the variable @code{GCJFLAGS}
6757 must also be defined somehow (either in @file{configure.ac} or
6758 @file{Makefile.am}).  The simplest way to do this is to use the
6759 @code{AM_PROG_GCJ} macro.
6760
6761 @vindex GCJFLAGS
6762
6763 By default, programs including Java source files are linked with
6764 @command{gcj}.
6765
6766 As always, the contents of @code{AM_GCJFLAGS} are passed to every
6767 compilation invoking @command{gcj} (in its role as an ahead-of-time
6768 compiler, when invoking it to create @file{.class} files,
6769 @code{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
6770 options to @command{gcj} from @file{Makefile.am}, this variable, and not
6771 the user variable @code{GCJFLAGS}, should be used.
6772
6773 @vindex AM_GCJFLAGS
6774
6775 @command{gcj} can be used to compile @file{.java}, @file{.class},
6776 @file{.zip}, or @file{.jar} files.
6777
6778 When linking, @command{gcj} requires that the main class be specified
6779 using the @option{--main=} option.  The easiest way to do this is to use
6780 the @code{_LDFLAGS} variable for the program.
6781
6782
6783 @node Vala Support
6784 @comment  node-name,  next,  previous,  up
6785 @section Vala Support
6786
6787 @cindex Vala Support
6788 @cindex Support for Vala
6789
6790 Automake provides initial support for Vala
6791 (@uref{http://www.vala-project.org/}).
6792 This requires valac version 0.7.0 or later, and currently requires
6793 the user to use GNU @command{make}.
6794
6795 @example
6796 foo_SOURCES = foo.vala bar.vala zardoc.c
6797 @end example
6798
6799 Any @file{.vala} file listed in a @code{_SOURCES} variable will be
6800 compiled into C code by the Vala compiler. The generated @file{.c} files are
6801 distributed. The end user does not need to have a Vala compiler installed.
6802
6803 Automake ships with an Autoconf macro called @code{AM_PROG_VALAC}
6804 that will locate the Vala compiler and optionally check its version
6805 number.
6806
6807 @defmac AM_PROG_VALAC (@ovar{minimum-version})
6808 Try to find a Vala compiler in @env{PATH}. If it is found, the variable
6809 @code{VALAC} is set. Optionally a minimum release number of the compiler
6810 can be requested:
6811
6812 @example
6813 AM_PROG_VALAC([0.7.0])
6814 @end example
6815 @end defmac
6816
6817 There are a few variables that are used when compiling Vala sources:
6818
6819 @vtable @code
6820 @item VALAC
6821 Path to the Vala compiler.
6822
6823 @item VALAFLAGS
6824 Additional arguments for the Vala compiler.
6825
6826 @item AM_VALAFLAGS
6827 The maintainer's variant of @code{VALAFLAGS}.
6828
6829 @example
6830 lib_LTLIBRARIES = libfoo.la
6831 libfoo_la_SOURCES = foo.vala
6832 @end example
6833 @end vtable
6834
6835 Note that currently, you cannot use per-target @code{*_VALAFLAGS}
6836 (@pxref{Renamed Objects}) to produce different C files from one Vala
6837 source file.
6838
6839
6840 @node Support for Other Languages
6841 @comment  node-name,  next,  previous,  up
6842 @section Support for Other Languages
6843
6844 Automake currently only includes full support for C, C++ (@pxref{C++
6845 Support}), Objective C (@pxref{Objective C Support}),
6846 Objective C++ (@pxref{Objective C++ Support}),
6847 Fortran 77
6848 (@pxref{Fortran 77 Support}), Fortran 9x (@pxref{Fortran 9x Support}),
6849 and Java (@pxref{Java Support with gcj}).  There is only rudimentary
6850 support for other languages, support for which will be improved based
6851 on user demand.
6852
6853 Some limited support for adding your own languages is available via the
6854 suffix rule handling (@pxref{Suffixes}).
6855
6856 @node Dependencies
6857 @section Automatic dependency tracking
6858
6859 As a developer it is often painful to continually update the
6860 @file{Makefile.am} whenever the include-file dependencies change in a
6861 project.  Automake supplies a way to automatically track dependency
6862 changes (@pxref{Dependency Tracking}).
6863
6864 @cindex Dependency tracking
6865 @cindex Automatic dependency tracking
6866
6867 Automake always uses complete dependencies for a compilation,
6868 including system headers.  Automake's model is that dependency
6869 computation should be a side effect of the build.  To this end,
6870 dependencies are computed by running all compilations through a
6871 special wrapper program called @command{depcomp}.  @command{depcomp}
6872 understands how to coax many different C and C++ compilers into
6873 generating dependency information in the format it requires.
6874 @samp{automake -a} will install @command{depcomp} into your source
6875 tree for you.  If @command{depcomp} can't figure out how to properly
6876 invoke your compiler, dependency tracking will simply be disabled for
6877 your build.
6878
6879 @cindex @command{depcomp}
6880
6881 Experience with earlier versions of Automake (@pxref{Dependency Tracking
6882 Evolution, , Dependency Tracking Evolution, automake-history, Brief History
6883 of Automake}) taught us that it is not reliable to generate dependencies
6884 only on the maintainer's system, as configurations vary too much.  So
6885 instead Automake implements dependency tracking at build time.
6886
6887 Automatic dependency tracking can be suppressed by putting
6888 @option{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
6889 passing @option{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
6890 (this should be the preferred way).  Or, you can invoke @command{automake}
6891 with the @option{-i} option.  Dependency tracking is enabled by default.
6892
6893 @vindex AUTOMAKE_OPTIONS
6894 @opindex no-dependencies
6895
6896 The person building your package also can choose to disable dependency
6897 tracking by configuring with @option{--disable-dependency-tracking}.
6898
6899 @cindex Disabling dependency tracking
6900 @cindex Dependency tracking, disabling
6901
6902
6903 @node EXEEXT
6904 @section Support for executable extensions
6905
6906 @cindex Executable extension
6907 @cindex Extension, executable
6908 @cindex Windows
6909
6910 On some platforms, such as Windows, executables are expected to have an
6911 extension such as @file{.exe}.  On these platforms, some compilers (GCC
6912 among them) will automatically generate @file{foo.exe} when asked to
6913 generate @file{foo}.
6914
6915 Automake provides mostly-transparent support for this.  Unfortunately
6916 @emph{mostly} doesn't yet mean @emph{fully}.  Until the English
6917 dictionary is revised, you will have to assist Automake if your package
6918 must support those platforms.
6919
6920 One thing you must be aware of is that, internally, Automake rewrites
6921 something like this:
6922
6923 @example
6924 bin_PROGRAMS = liver
6925 @end example
6926
6927 to this:
6928
6929 @example
6930 bin_PROGRAMS = liver$(EXEEXT)
6931 @end example
6932
6933 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
6934 extension.
6935
6936 The variables @code{TESTS} and @code{XFAIL_TESTS} (@pxref{Simple Tests})
6937 are also rewritten if they contain filenames that have been declared as
6938 programs in the same @file{Makefile}.  (This is mostly useful when some
6939 programs from @code{check_PROGRAMS} are listed in @code{TESTS}.)
6940
6941 However, Automake cannot apply this rewriting to @command{configure}
6942 substitutions.  This means that if you are conditionally building a
6943 program using such a substitution, then your @file{configure.ac} must
6944 take care to add @samp{$(EXEEXT)} when constructing the output variable.
6945
6946 Sometimes maintainers like to write an explicit link rule for their
6947 program.  Without executable extension support, this is easy---you
6948 simply write a rule whose target is the name of the program.  However,
6949 when executable extension support is enabled, you must instead add the
6950 @samp{$(EXEEXT)} suffix.
6951
6952 This might be a nuisance for maintainers who know their package will
6953 never run on a platform that has
6954 executable extensions.  For those maintainers, the @option{no-exeext}
6955 option (@pxref{Options}) will disable this feature.  This works in a
6956 fairly ugly way; if @option{no-exeext} is seen, then the presence of a
6957 rule for a target named @code{foo} in @file{Makefile.am} will override
6958 an @command{automake}-generated rule for @samp{foo$(EXEEXT)}.  Without
6959 the @option{no-exeext} option, this use will give a diagnostic.
6960
6961
6962 @node Other Objects
6963 @chapter Other Derived Objects
6964
6965 Automake can handle derived objects that are not C programs.  Sometimes
6966 the support for actually building such objects must be explicitly
6967 supplied, but Automake will still automatically handle installation and
6968 distribution.
6969
6970 @menu
6971 * Scripts::                     Executable scripts
6972 * Headers::                     Header files
6973 * Data::                        Architecture-independent data files
6974 * Sources::                     Derived sources
6975 @end menu
6976
6977
6978 @node Scripts
6979 @section Executable Scripts
6980
6981 @cindex @code{_SCRIPTS} primary, defined
6982 @cindex @code{SCRIPTS} primary, defined
6983 @cindex Primary variable, @code{SCRIPTS}
6984 @vindex _SCRIPTS
6985 @cindex Installing scripts
6986
6987 It is possible to define and install programs that are scripts.  Such
6988 programs are listed using the @code{SCRIPTS} primary name.  When the
6989 script is distributed in its final, installable form, the
6990 @file{Makefile} usually looks as follows:
6991 @vindex SCRIPTS
6992
6993 @example
6994 # Install my_script in $(bindir) and distribute it.
6995 dist_bin_SCRIPTS = my_script
6996 @end example
6997
6998 Scripts are not distributed by default; as we have just seen, those
6999 that should be distributed can be specified using a @code{dist_}
7000 prefix as with other primaries.
7001
7002 @cindex @code{SCRIPTS}, installation directories
7003 @vindex bin_SCRIPTS
7004 @vindex sbin_SCRIPTS
7005 @vindex libexec_SCRIPTS
7006 @vindex pkgdata_SCRIPTS
7007 @vindex pkglibexec_SCRIPTS
7008 @vindex noinst_SCRIPTS
7009 @vindex check_SCRIPTS
7010
7011 Scripts can be installed in @code{bindir}, @code{sbindir},
7012 @code{libexecdir}, @code{pkglibexecdir}, or @code{pkgdatadir}.
7013
7014 Scripts that need not be installed can be listed in
7015 @code{noinst_SCRIPTS}, and among them, those which are needed only by
7016 @samp{make check} should go in @code{check_SCRIPTS}.
7017
7018 When a script needs to be built, the @file{Makefile.am} should include
7019 the appropriate rules.  For instance the @command{automake} program
7020 itself is a Perl script that is generated from @file{automake.in}.
7021 Here is how this is handled:
7022
7023 @example
7024 bin_SCRIPTS = automake
7025 CLEANFILES = $(bin_SCRIPTS)
7026 EXTRA_DIST = automake.in
7027
7028 do_subst = sed -e 's,[@@]datadir[@@],$(datadir),g' \
7029             -e 's,[@@]PERL[@@],$(PERL),g' \
7030             -e 's,[@@]PACKAGE[@@],$(PACKAGE),g' \
7031             -e 's,[@@]VERSION[@@],$(VERSION),g' \
7032             @dots{}
7033
7034 automake: automake.in Makefile
7035         $(do_subst) < $(srcdir)/automake.in > automake
7036         chmod +x automake
7037 @end example
7038
7039 Such scripts for which a build rule has been supplied need to be
7040 deleted explicitly using @code{CLEANFILES} (@pxref{Clean}), and their
7041 sources have to be distributed, usually with @code{EXTRA_DIST}
7042 (@pxref{Basics of Distribution}).
7043
7044 Another common way to build scripts is to process them from
7045 @file{configure} with @code{AC_CONFIG_FILES}.  In this situation
7046 Automake knows which files should be cleaned and distributed, and what
7047 the rebuild rules should look like.
7048
7049 For instance if @file{configure.ac} contains
7050
7051 @example
7052 AC_CONFIG_FILES([src/my_script], [chmod +x src/my_script])
7053 @end example
7054
7055 @noindent
7056 to build @file{src/my_script} from @file{src/my_script.in}, then a
7057 @file{src/Makefile.am} to install this script in @code{$(bindir)} can
7058 be as simple as
7059
7060 @example
7061 bin_SCRIPTS = my_script
7062 CLEANFILES = $(bin_SCRIPTS)
7063 @end example
7064
7065 @noindent
7066 There is no need for @code{EXTRA_DIST} or any build rule: Automake
7067 infers them from @code{AC_CONFIG_FILES} (@pxref{Requirements}).
7068 @code{CLEANFILES} is still useful, because by default Automake will
7069 clean targets of @code{AC_CONFIG_FILES} in @code{distclean}, not
7070 @code{clean}.
7071
7072 Although this looks simpler, building scripts this way has one
7073 drawback: directory variables such as @code{$(datadir)} are not fully
7074 expanded and may refer to other directory variables.
7075
7076 @node Headers
7077 @section Header files
7078
7079 @cindex @code{_HEADERS} primary, defined
7080 @cindex @code{HEADERS} primary, defined
7081 @cindex Primary variable, @code{HEADERS}
7082 @vindex _HEADERS
7083 @vindex noinst_HEADERS
7084 @cindex @code{HEADERS}, installation directories
7085 @cindex Installing headers
7086 @vindex include_HEADERS
7087 @vindex oldinclude_HEADERS
7088 @vindex pkginclude_HEADERS
7089
7090
7091 Header files that must be installed are specified by the
7092 @code{HEADERS} family of variables.  Headers can be installed in
7093 @code{includedir}, @code{oldincludedir}, @code{pkgincludedir} or any
7094 other directory you may have defined (@pxref{Uniform}).  For instance,
7095
7096 @example
7097 include_HEADERS = foo.h bar/bar.h
7098 @end example
7099
7100 @noindent
7101 will install the two files as @file{$(includedir)/foo.h} and
7102 @file{$(includedir)/bar.h}.
7103
7104 The @code{nobase_} prefix is also supported,
7105
7106 @example
7107 nobase_include_HEADERS = foo.h bar/bar.h
7108 @end example
7109
7110 @noindent
7111 will install the two files as @file{$(includedir)/foo.h} and
7112 @file{$(includedir)/bar/bar.h} (@pxref{Alternative}).
7113
7114 @vindex noinst_HEADERS
7115 Usually, only header files that accompany installed libraries need to
7116 be installed.  Headers used by programs or convenience libraries are
7117 not installed.  The @code{noinst_HEADERS} variable can be used for
7118 such headers.  However when the header actually belongs to a single
7119 convenience library or program, we recommend listing it in the
7120 program's or library's @code{_SOURCES} variable (@pxref{Program
7121 Sources}) instead of in @code{noinst_HEADERS}.  This is clearer for
7122 the @file{Makefile.am} reader.  @code{noinst_HEADERS} would be the
7123 right variable to use in a directory containing only headers and no
7124 associated library or program.
7125
7126 All header files must be listed somewhere; in a @code{_SOURCES}
7127 variable or in a @code{_HEADERS} variable.  Missing ones will not
7128 appear in the distribution.
7129
7130 For header files that are built and must not be distributed, use the
7131 @code{nodist_} prefix as in @code{nodist_include_HEADERS} or
7132 @code{nodist_prog_SOURCES}.  If these generated headers are needed
7133 during the build, you must also ensure they exist before they are
7134 used (@pxref{Sources}).
7135
7136
7137 @node Data
7138 @section Architecture-independent data files
7139
7140 @cindex @code{_DATA} primary, defined
7141 @cindex @code{DATA} primary, defined
7142 @cindex Primary variable, @code{DATA}
7143 @vindex _DATA
7144
7145 Automake supports the installation of miscellaneous data files using the
7146 @code{DATA} family of variables.
7147 @vindex DATA
7148
7149 @vindex data_DATA
7150 @vindex sysconf_DATA
7151 @vindex sharedstate_DATA
7152 @vindex localstate_DATA
7153 @vindex pkgdata_DATA
7154
7155 Such data can be installed in the directories @code{datadir},
7156 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
7157 @code{pkgdatadir}.
7158
7159 By default, data files are @emph{not} included in a distribution.  Of
7160 course, you can use the @code{dist_} prefix to change this on a
7161 per-variable basis.
7162
7163 Here is how Automake declares its auxiliary data files:
7164
7165 @example
7166 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
7167 @end example
7168
7169
7170 @node Sources
7171 @section Built Sources
7172
7173 Because Automake's automatic dependency tracking works as a side-effect
7174 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
7175 target should not be compiled before its dependencies are made, but
7176 these dependencies are unknown until the target is first compiled.
7177
7178 Ordinarily this is not a problem, because dependencies are distributed
7179 sources: they preexist and do not need to be built.  Suppose that
7180 @file{foo.c} includes @file{foo.h}.  When it first compiles
7181 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
7182 @file{foo.c}.  As a side-effect of this compilation @command{depcomp}
7183 records the @file{foo.h} dependency so that following invocations of
7184 @command{make} will honor it.  In these conditions, it's clear there is
7185 no problem: either @file{foo.o} doesn't exist and has to be built
7186 (regardless of the dependencies), or accurate dependencies exist and
7187 they can be used to decide whether @file{foo.o} should be rebuilt.
7188
7189 It's a different story if @file{foo.h} doesn't exist by the first
7190 @command{make} run.  For instance, there might be a rule to build
7191 @file{foo.h}.  This time @file{file.o}'s build will fail because the
7192 compiler can't find @file{foo.h}.  @command{make} failed to trigger the
7193 rule to build @file{foo.h} first by lack of dependency information.
7194
7195 @vindex BUILT_SOURCES
7196 @cindex @code{BUILT_SOURCES}, defined
7197
7198 The @code{BUILT_SOURCES} variable is a workaround for this problem.  A
7199 source file listed in @code{BUILT_SOURCES} is made on @samp{make all}
7200 or @samp{make check} (or even @samp{make install}) before other
7201 targets are processed.  However, such a source file is not
7202 @emph{compiled} unless explicitly requested by mentioning it in some
7203 other @code{_SOURCES} variable.
7204
7205 So, to conclude our introductory example, we could use
7206 @samp{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
7207 any other target (including @file{foo.o}) during @samp{make all} or
7208 @samp{make check}.
7209
7210 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
7211 must be created early in the build process can be listed in this
7212 variable.  Moreover, all built sources do not necessarily have to be
7213 listed in @code{BUILT_SOURCES}.  For instance, a generated @file{.c} file
7214 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
7215 another source), because it's a known dependency of the associated
7216 object.
7217
7218 It might be important to emphasize that @code{BUILT_SOURCES} is
7219 honored only by @samp{make all}, @samp{make check} and @samp{make
7220 install}.  This means you cannot build a specific target (e.g.,
7221 @samp{make foo}) in a clean tree if it depends on a built source.
7222 However it will succeed if you have run @samp{make all} earlier,
7223 because accurate dependencies are already available.
7224
7225 The next section illustrates and discusses the handling of built sources
7226 on a toy example.
7227
7228 @menu
7229 * Built Sources Example::       Several ways to handle built sources.
7230 @end menu
7231
7232 @node Built Sources Example
7233 @subsection Built Sources Example
7234
7235 Suppose that @file{foo.c} includes @file{bindir.h}, which is
7236 installation-dependent and not distributed: it needs to be built.  Here
7237 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
7238 value of the @command{make} variable @code{bindir} (inherited from
7239 @file{configure}).
7240
7241 We suggest several implementations below.  It's not meant to be an
7242 exhaustive listing of all ways to handle built sources, but it will give
7243 you a few ideas if you encounter this issue.
7244
7245 @subsubheading First Try
7246
7247 This first implementation will illustrate the bootstrap issue mentioned
7248 in the previous section (@pxref{Sources}).
7249
7250 Here is a tentative @file{Makefile.am}.
7251
7252 @example
7253 # This won't work.
7254 bin_PROGRAMS = foo
7255 foo_SOURCES = foo.c
7256 nodist_foo_SOURCES = bindir.h
7257 CLEANFILES = bindir.h
7258 bindir.h: Makefile
7259         echo '#define bindir "$(bindir)"' >$@@
7260 @end example
7261
7262 This setup doesn't work, because Automake doesn't know that @file{foo.c}
7263 includes @file{bindir.h}.  Remember, automatic dependency tracking works
7264 as a side-effect of compilation, so the dependencies of @file{foo.o} will
7265 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
7266 The symptom is as follows.
7267
7268 @example
7269 % make
7270 source='foo.c' object='foo.o' libtool=no \
7271 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7272 depmode=gcc /bin/sh ./depcomp \
7273 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7274 foo.c:2: bindir.h: No such file or directory
7275 make: *** [foo.o] Error 1
7276 @end example
7277
7278 In this example @file{bindir.h} is not distributed nor installed, and
7279 it is not even being built on-time.  One may wonder if the
7280 @samp{nodist_foo_SOURCES = bindir.h} line has any use at all.  This
7281 line simply states that @file{bindir.h} is a source of @code{foo}, so
7282 for instance, it should be inspected while generating tags
7283 (@pxref{Tags}).  In other words, it does not help our present problem,
7284 and the build would fail identically without it.
7285
7286 @subsubheading Using @code{BUILT_SOURCES}
7287
7288 A solution is to require @file{bindir.h} to be built before anything
7289 else.  This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
7290
7291 @example
7292 bin_PROGRAMS = foo
7293 foo_SOURCES = foo.c
7294 nodist_foo_SOURCES = bindir.h
7295 BUILT_SOURCES = bindir.h
7296 CLEANFILES = bindir.h
7297 bindir.h: Makefile
7298         echo '#define bindir "$(bindir)"' >$@@
7299 @end example
7300
7301 See how @file{bindir.h} gets built first:
7302
7303 @example
7304 % make
7305 echo '#define bindir "/usr/local/bin"' >bindir.h
7306 make  all-am
7307 make[1]: Entering directory `/home/adl/tmp'
7308 source='foo.c' object='foo.o' libtool=no \
7309 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7310 depmode=gcc /bin/sh ./depcomp \
7311 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7312 gcc  -g -O2   -o foo  foo.o
7313 make[1]: Leaving directory `/home/adl/tmp'
7314 @end example
7315
7316 However, as said earlier, @code{BUILT_SOURCES} applies only to the
7317 @code{all}, @code{check}, and @code{install} targets.  It still fails
7318 if you try to run @samp{make foo} explicitly:
7319
7320 @example
7321 % make clean
7322 test -z "bindir.h" || rm -f bindir.h
7323 test -z "foo" || rm -f foo
7324 rm -f *.o
7325 % : > .deps/foo.Po # Suppress previously recorded dependencies
7326 % make foo
7327 source='foo.c' object='foo.o' libtool=no \
7328 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7329 depmode=gcc /bin/sh ./depcomp \
7330 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7331 foo.c:2: bindir.h: No such file or directory
7332 make: *** [foo.o] Error 1
7333 @end example
7334
7335 @subsubheading Recording Dependencies manually
7336
7337 Usually people are happy enough with @code{BUILT_SOURCES} because they
7338 never build targets such as @samp{make foo} before @samp{make all}, as
7339 in the previous example.  However if this matters to you, you can
7340 avoid @code{BUILT_SOURCES} and record such dependencies explicitly in
7341 the @file{Makefile.am}.
7342
7343 @example
7344 bin_PROGRAMS = foo
7345 foo_SOURCES = foo.c
7346 nodist_foo_SOURCES = bindir.h
7347 foo.$(OBJEXT): bindir.h
7348 CLEANFILES = bindir.h
7349 bindir.h: Makefile
7350         echo '#define bindir "$(bindir)"' >$@@
7351 @end example
7352
7353 You don't have to list @emph{all} the dependencies of @file{foo.o}
7354 explicitly, only those that might need to be built.  If a dependency
7355 already exists, it will not hinder the first compilation and will be
7356 recorded by the normal dependency tracking code.  (Note that after
7357 this first compilation the dependency tracking code will also have
7358 recorded the dependency between @file{foo.o} and
7359 @file{bindir.h}; so our explicit dependency is really useful to
7360 the first build only.)
7361
7362 Adding explicit dependencies like this can be a bit dangerous if you are
7363 not careful enough.  This is due to the way Automake tries not to
7364 overwrite your rules (it assumes you know better than it).
7365 @samp{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
7366 output to build @samp{foo.$(OBJEXT)}.  It happens to work in this case
7367 because Automake doesn't have to output any @samp{foo.$(OBJEXT):}
7368 target: it relies on a suffix rule instead (i.e., @samp{.c.$(OBJEXT):}).
7369 Always check the generated @file{Makefile.in} if you do this.
7370
7371 @subsubheading Build @file{bindir.h} from @file{configure}
7372
7373 It's possible to define this preprocessor macro from @file{configure},
7374 either in @file{config.h} (@pxref{Defining Directories, , Defining
7375 Directories, autoconf, The Autoconf Manual}), or by processing a
7376 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
7377 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
7378 Autoconf Manual}).
7379
7380 At this point it should be clear that building @file{bindir.h} from
7381 @file{configure} works well for this example.  @file{bindir.h} will exist
7382 before you build any target, hence will not cause any dependency issue.
7383
7384 The Makefile can be shrunk as follows.  We do not even have to mention
7385 @file{bindir.h}.
7386
7387 @example
7388 bin_PROGRAMS = foo
7389 foo_SOURCES = foo.c
7390 @end example
7391
7392 However, it's not always possible to build sources from
7393 @file{configure}, especially when these sources are generated by a tool
7394 that needs to be built first.
7395
7396 @subsubheading Build @file{bindir.c}, not @file{bindir.h}.
7397
7398 Another attractive idea is to define @code{bindir} as a variable or
7399 function exported from @file{bindir.o}, and build @file{bindir.c}
7400 instead of @file{bindir.h}.
7401
7402 @example
7403 noinst_PROGRAMS = foo
7404 foo_SOURCES = foo.c bindir.h
7405 nodist_foo_SOURCES = bindir.c
7406 CLEANFILES = bindir.c
7407 bindir.c: Makefile
7408         echo 'const char bindir[] = "$(bindir)";' >$@@
7409 @end example
7410
7411 @file{bindir.h} contains just the variable's declaration and doesn't
7412 need to be built, so it won't cause any trouble.  @file{bindir.o} is
7413 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
7414 first.
7415
7416 @subsubheading Which is best?
7417
7418 There is no panacea, of course.  Each solution has its merits and
7419 drawbacks.
7420
7421 You cannot use @code{BUILT_SOURCES} if the ability to run @samp{make
7422 foo} on a clean tree is important to you.
7423
7424 You won't add explicit dependencies if you are leery of overriding
7425 an Automake rule by mistake.
7426
7427 Building files from @file{./configure} is not always possible, neither
7428 is converting @file{.h} files into @file{.c} files.
7429
7430
7431 @node Other GNU Tools
7432 @chapter Other GNU Tools
7433
7434 Since Automake is primarily intended to generate @file{Makefile.in}s for
7435 use in GNU programs, it tries hard to interoperate with other GNU tools.
7436
7437 @menu
7438 * Emacs Lisp::                  Emacs Lisp
7439 * gettext::                     Gettext
7440 * Libtool::                     Libtool
7441 * Java::                        Java bytecode compilation (deprecated)
7442 * Python::                      Python
7443 @end menu
7444
7445
7446 @node Emacs Lisp
7447 @section Emacs Lisp
7448
7449 @cindex @code{_LISP} primary, defined
7450 @cindex @code{LISP} primary, defined
7451 @cindex Primary variable, @code{LISP}
7452
7453 @vindex _LISP
7454 @vindex lisp_LISP
7455 @vindex noinst_LISP
7456
7457 Automake provides some support for Emacs Lisp.  The @code{LISP} primary
7458 is used to hold a list of @file{.el} files.  Possible prefixes for this
7459 primary are @code{lisp_} and @code{noinst_}.  Note that if
7460 @code{lisp_LISP} is defined, then @file{configure.ac} must run
7461 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
7462
7463 @vindex dist_lisp_LISP
7464 @vindex dist_noinst_LISP
7465 Lisp sources are not distributed by default.  You can prefix the
7466 @code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
7467 @code{dist_noinst_LISP}, to indicate that these files should be
7468 distributed.
7469
7470 Automake will byte-compile all Emacs Lisp source files using the Emacs
7471 found by @code{AM_PATH_LISPDIR}, if any was found.  When performing such
7472 byte-compilation, the flags specified in the (developer-reserved)
7473 @code{AM_ELCFLAGS} and (user-reserved) @code{ELCFLAGS} make variables
7474 will be passed to the Emacs invocation.
7475
7476 Byte-compiled Emacs Lisp files are not portable among all versions of
7477 Emacs, so it makes sense to turn this off if you expect sites to have
7478 more than one version of Emacs installed.  Furthermore, many packages
7479 don't actually benefit from byte-compilation.  Still, we recommend
7480 that you byte-compile your Emacs Lisp sources.  It is probably better
7481 for sites with strange setups to cope for themselves than to make the
7482 installation less nice for everybody else.
7483
7484 There are two ways to avoid byte-compiling.  Historically, we have
7485 recommended the following construct.
7486
7487 @example
7488 lisp_LISP = file1.el file2.el
7489 ELCFILES =
7490 @end example
7491
7492 @noindent
7493 @code{ELCFILES} is an internal Automake variable that normally lists
7494 all @file{.elc} files that must be byte-compiled.  Automake defines
7495 @code{ELCFILES} automatically from @code{lisp_LISP}.  Emptying this
7496 variable explicitly prevents byte-compilation.
7497
7498 Since Automake 1.8, we now recommend using @code{lisp_DATA} instead:
7499
7500 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7501 @example
7502 lisp_DATA = file1.el file2.el
7503 @end example
7504
7505 Note that these two constructs are not equivalent.  @code{_LISP} will
7506 not install a file if Emacs is not installed, while @code{_DATA} will
7507 always install its files.
7508
7509 @node gettext
7510 @section Gettext
7511
7512 @cindex GNU Gettext support
7513 @cindex Gettext support
7514 @cindex Support for GNU Gettext
7515
7516 If @code{AM_GNU_GETTEXT} is seen in @file{configure.ac}, then Automake
7517 turns on support for GNU gettext, a message catalog system for
7518 internationalization
7519 (@pxref{Top, , Introduction, gettext, GNU gettext utilities}).
7520
7521 The @code{gettext} support in Automake requires the addition of one or
7522 two subdirectories to the package: @file{po} and possibly also @file{intl}.
7523 The latter is needed if @code{AM_GNU_GETTEXT} is not invoked with the
7524 @samp{external} argument, or if @code{AM_GNU_GETTEXT_INTL_SUBDIR} is used.
7525 Automake ensures that these directories exist and are mentioned in
7526 @code{SUBDIRS}.
7527
7528 @node Libtool
7529 @section Libtool
7530
7531 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
7532 libtool, The Libtool Manual}) with the @code{LTLIBRARIES} primary.
7533 @xref{A Shared Library}.
7534
7535
7536 @node Java
7537 @section Java bytecode compilation (deprecated)
7538
7539 @cindex @code{_JAVA} primary, defined
7540 @cindex @code{JAVA} primary, defined
7541 @cindex Primary variable, @code{JAVA}
7542 @cindex Java to bytecode, compilation
7543 @cindex Compilation of Java to bytecode
7544
7545 Automake provides some minimal support for Java bytecode compilation with
7546 the @code{JAVA} primary (in addition to the support for compiling Java to
7547 native machine code; @pxref{Java Support with gcj}).  Note however that
7548 @emph{the interface and most features described here are deprecated}; the
7549 next automake release will strive to provide a better and cleaner
7550 interface, which however @emph{won't be backward-compatible}; the present
7551 interface will probably be removed altogether in future automake releases
7552 (1.13 or later), so don't use it in new code.
7553
7554 Any @file{.java} files listed in a @code{_JAVA} variable will be
7555 compiled with @code{JAVAC} at build time.  By default, @file{.java}
7556 files are not included in the distribution, you should use the
7557 @code{dist_} prefix to distribute them.
7558
7559 Here is a typical setup for distributing @file{.java} files and
7560 installing the @file{.class} files resulting from their compilation.
7561
7562 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7563 @example
7564 javadir = $(datadir)/java
7565 dist_java_JAVA = a.java b.java @dots{}
7566 @end example
7567
7568 @cindex @code{JAVA} restrictions
7569 @cindex Restrictions for @code{JAVA}
7570
7571 Currently Automake enforces the restriction that only one @code{_JAVA}
7572 primary can be used in a given @file{Makefile.am}.  The reason for this
7573 restriction is that, in general, it isn't possible to know which
7574 @file{.class} files were generated from which @file{.java} files, so
7575 it would be impossible to know which files to install where.  For
7576 instance, a @file{.java} file can define multiple classes; the resulting
7577 @file{.class} file names cannot be predicted without parsing the
7578 @file{.java} file.
7579
7580 There are a few variables that are used when compiling Java sources:
7581
7582 @vtable @code
7583 @item JAVAC
7584 The name of the Java compiler.  This defaults to @samp{javac}.
7585
7586 @item JAVACFLAGS
7587 The flags to pass to the compiler.  This is considered to be a user
7588 variable (@pxref{User Variables}).
7589
7590 @item AM_JAVACFLAGS
7591 More flags to pass to the Java compiler.  This, and not
7592 @code{JAVACFLAGS}, should be used when it is necessary to put Java
7593 compiler flags into @file{Makefile.am}.
7594
7595 @item JAVAROOT
7596 The value of this variable is passed to the @option{-d} option to
7597 @code{javac}.  It defaults to @samp{$(top_builddir)}.
7598
7599 @item CLASSPATH_ENV
7600 This variable is a shell expression that is used to set the
7601 @env{CLASSPATH} environment variable on the @code{javac} command line.
7602 (In the future we will probably handle class path setting differently.)
7603 @end vtable
7604
7605
7606 @node Python
7607 @section Python
7608
7609 @cindex @code{_PYTHON} primary, defined
7610 @cindex @code{PYTHON} primary, defined
7611 @cindex Primary variable, @code{PYTHON}
7612 @vindex _PYTHON
7613
7614 Automake provides support for Python compilation with the
7615 @code{PYTHON} primary.  A typical setup is to call
7616 @code{AM_PATH_PYTHON} in @file{configure.ac} and use a line like the
7617 following in @file{Makefile.am}:
7618
7619 @example
7620 python_PYTHON = tree.py leave.py
7621 @end example
7622
7623 Any files listed in a @code{_PYTHON} variable will be byte-compiled
7624 with @command{py-compile} at install time.  @command{py-compile}
7625 actually creates both standard (@file{.pyc}) and optimized
7626 (@file{.pyo}) byte-compiled versions of the source files.  Note that
7627 because byte-compilation occurs at install time, any files listed in
7628 @code{noinst_PYTHON} will not be compiled.  Python source files are
7629 included in the distribution by default, prepend @code{nodist_} (as in
7630 @code{nodist_python_PYTHON}) to omit them.
7631
7632 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON}
7633 that will determine some Python-related directory variables (see
7634 below).  If you have called @code{AM_PATH_PYTHON} from
7635 @file{configure.ac}, then you may use the variables
7636 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7637 @code{python_PYTHON} or @code{pkgpython_PYTHON} to list Python source
7638 files in your @file{Makefile.am}, depending on where you want your files
7639 installed (see the definitions of @code{pythondir} and
7640 @code{pkgpythondir} below).
7641
7642 @defmac AM_PATH_PYTHON (@ovar{version}, @ovar{action-if-found},
7643   @ovar{action-if-not-found})
7644
7645 Search for a Python interpreter on the system.  This macro takes three
7646 optional arguments.  The first argument, if present, is the minimum
7647 version of Python required for this package: @code{AM_PATH_PYTHON}
7648 will skip any Python interpreter that is older than @var{version}.
7649 If an interpreter is found and satisfies @var{version}, then
7650 @var{action-if-found} is run.  Otherwise, @var{action-if-not-found} is
7651 run.
7652
7653 If @var{action-if-not-found} is not specified, as in the following
7654 example, the default is to abort @command{configure}.
7655
7656 @example
7657 AM_PATH_PYTHON([2.2])
7658 @end example
7659
7660 @noindent
7661 This is fine when Python is an absolute requirement for the package.
7662 If Python >= 2.5 was only @emph{optional} to the package,
7663 @code{AM_PATH_PYTHON} could be called as follows.
7664
7665 @example
7666 AM_PATH_PYTHON([2.5],, [:])
7667 @end example
7668
7669 If the @env{PYTHON} variable is set when @code{AM_PATH_PYTHON} is
7670 called, then that will be the only Python interpreter that is tried.
7671
7672 @code{AM_PATH_PYTHON} creates the following output variables based on
7673 the Python installation found during configuration.
7674 @end defmac
7675
7676 @vtable @code
7677 @item PYTHON
7678 The name of the Python executable, or @samp{:} if no suitable
7679 interpreter could be found.
7680
7681 Assuming @var{action-if-not-found} is used (otherwise @file{./configure}
7682 will abort if Python is absent), the value of @code{PYTHON} can be used
7683 to setup a conditional in order to disable the relevant part of a build
7684 as follows.
7685
7686 @example
7687 AM_PATH_PYTHON(,, [:])
7688 AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
7689 @end example
7690
7691 @item PYTHON_VERSION
7692 The Python version number, in the form @var{major}.@var{minor}
7693 (e.g., @samp{2.5}).  This is currently the value of
7694 @samp{sys.version[:3]}.
7695
7696 @item PYTHON_PREFIX
7697 The string @samp{$@{prefix@}}.  This term may be used in future work
7698 that needs the contents of Python's @samp{sys.prefix}, but general
7699 consensus is to always use the value from @command{configure}.
7700
7701 @item PYTHON_EXEC_PREFIX
7702 The string @samp{$@{exec_prefix@}}.  This term may be used in future work
7703 that needs the contents of Python's @samp{sys.exec_prefix}, but general
7704 consensus is to always use the value from @command{configure}.
7705
7706 @item PYTHON_PLATFORM
7707 The canonical name used by Python to describe the operating system, as
7708 given by @samp{sys.platform}.  This value is sometimes needed when
7709 building Python extensions.
7710
7711 @item pythondir
7712 The directory name for the @file{site-packages} subdirectory of the
7713 standard Python install tree.
7714
7715 @item pkgpythondir
7716 This is the directory under @code{pythondir} that is named after the
7717 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
7718 as a convenience.
7719
7720 @item pyexecdir
7721 This is the directory where Python extension modules (shared libraries)
7722 should be installed.  An extension module written in C could be declared
7723 as follows to Automake:
7724
7725 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7726 @example
7727 pyexec_LTLIBRARIES = quaternion.la
7728 quaternion_la_SOURCES = quaternion.c support.c support.h
7729 quaternion_la_LDFLAGS = -avoid-version -module
7730 @end example
7731
7732 @item pkgpyexecdir
7733 This is a convenience variable that is defined as
7734 @samp{$(pyexecdir)/$(PACKAGE)}.
7735 @end vtable
7736
7737 All of these directory variables have values that start with either
7738 @samp{$@{prefix@}} or @samp{$@{exec_prefix@}} unexpanded.  This works
7739 fine in @file{Makefiles}, but it makes these variables hard to use in
7740 @file{configure}.  This is mandated by the GNU coding standards, so
7741 that the user can run @samp{make prefix=/foo install}.  The Autoconf
7742 manual has a section with more details on this topic
7743 (@pxref{Installation Directory Variables, , Installation Directory
7744 Variables, autoconf, The Autoconf Manual}).  See also @ref{Hard-Coded
7745 Install Paths}.
7746
7747
7748 @node Documentation
7749 @chapter Building documentation
7750
7751 Currently Automake provides support for Texinfo and man pages.
7752
7753 @menu
7754 * Texinfo::                     Texinfo
7755 * Man Pages::                   Man pages
7756 @end menu
7757
7758
7759 @node Texinfo
7760 @section Texinfo
7761
7762 @cindex @code{_TEXINFOS} primary, defined
7763 @cindex @code{TEXINFOS} primary, defined
7764 @cindex Primary variable, @code{TEXINFOS}
7765 @cindex HTML output using Texinfo
7766 @cindex PDF output using Texinfo
7767 @cindex PS output using Texinfo
7768 @cindex DVI output using Texinfo
7769 @vindex _TEXINFOS
7770 @vindex info_TEXINFOS
7771
7772 If the current directory contains Texinfo source, you must declare it
7773 with the @code{TEXINFOS} primary.  Generally Texinfo files are converted
7774 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
7775 here.  Any Texinfo source file must end in the @file{.texi},
7776 @file{.txi}, or @file{.texinfo} extension.  We recommend @file{.texi}
7777 for new manuals.
7778
7779 Automake generates rules to build @file{.info}, @file{.dvi},
7780 @file{.ps}, @file{.pdf} and @file{.html} files from your Texinfo
7781 sources.  Following the GNU Coding Standards, only the @file{.info}
7782 files are built by @samp{make all} and installed by @samp{make
7783 install} (unless you use @option{no-installinfo}, see below).
7784 Furthermore, @file{.info} files are automatically distributed so that
7785 Texinfo is not a prerequisite for installing your package.
7786
7787 @trindex dvi
7788 @trindex html
7789 @trindex pdf
7790 @trindex ps
7791 @trindex install-dvi
7792 @trindex install-html
7793 @trindex install-pdf
7794 @trindex install-ps
7795 Other documentation formats can be built on request by @samp{make
7796 dvi}, @samp{make ps}, @samp{make pdf} and @samp{make html}, and they
7797 can be installed with @samp{make install-dvi}, @samp{make install-ps},
7798 @samp{make install-pdf} and @samp{make install-html} explicitly.
7799 @samp{make uninstall} will remove everything: the Texinfo
7800 documentation installed by default as well as all the above optional
7801 formats.
7802
7803 All of these targets can be extended using @samp{-local} rules
7804 (@pxref{Extending}).
7805
7806 @cindex Texinfo flag, @code{VERSION}
7807 @cindex Texinfo flag, @code{UPDATED}
7808 @cindex Texinfo flag, @code{EDITION}
7809 @cindex Texinfo flag, @code{UPDATED-MONTH}
7810
7811 @cindex @code{VERSION} Texinfo flag
7812 @cindex @code{UPDATED} Texinfo flag
7813 @cindex @code{EDITION} Texinfo flag
7814 @cindex @code{UPDATED-MONTH} Texinfo flag
7815
7816 @cindex @file{mdate-sh}
7817
7818 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
7819 that file will be automatically generated.  The file @file{version.texi}
7820 defines four Texinfo flag you can reference using
7821 @code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
7822 @code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
7823
7824 @table @code
7825 @item EDITION
7826 @itemx VERSION
7827 Both of these flags hold the version number of your program.  They are
7828 kept separate for clarity.
7829
7830 @item UPDATED
7831 This holds the date the primary @file{.texi} file was last modified.
7832
7833 @item UPDATED-MONTH
7834 This holds the name of the month in which the primary @file{.texi} file
7835 was last modified.
7836 @end table
7837
7838 The @file{version.texi} support requires the @command{mdate-sh}
7839 script; this script is supplied with Automake and automatically
7840 included when @command{automake} is invoked with the
7841 @option{--add-missing} option.
7842
7843 If you have multiple Texinfo files, and you want to use the
7844 @file{version.texi} feature, then you have to have a separate version
7845 file for each Texinfo file.  Automake will treat any include in a
7846 Texinfo file that matches @file{vers*.texi} just as an automatically
7847 generated version file.
7848
7849 Sometimes an info file actually depends on more than one @file{.texi}
7850 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
7851 @file{fdl.texi}.  You can tell Automake about these dependencies using
7852 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
7853 @vindex TEXINFOS
7854 @vindex _TEXINFOS
7855
7856 @example
7857 info_TEXINFOS = hello.texi
7858 hello_TEXINFOS = fdl.texi
7859 @end example
7860
7861 @cindex @file{texinfo.tex}
7862
7863 By default, Automake requires the file @file{texinfo.tex} to appear in
7864 the same directory as the @file{Makefile.am} file that lists the
7865 @file{.texi} files.  If you used @code{AC_CONFIG_AUX_DIR} in
7866 @file{configure.ac} (@pxref{Input, , Finding `configure' Input,
7867 autoconf, The Autoconf Manual}), then @file{texinfo.tex} is looked for
7868 there.  In both cases, @command{automake} then supplies @file{texinfo.tex} if
7869 @option{--add-missing} is given, and takes care of its distribution.
7870 However, if you set the @code{TEXINFO_TEX} variable (see below),
7871 it overrides the location of the file and turns off its installation
7872 into the source as well as its distribution.
7873
7874 The option @option{no-texinfo.tex} can be used to eliminate the
7875 requirement for the file @file{texinfo.tex}.  Use of the variable
7876 @code{TEXINFO_TEX} is preferable, however, because that allows the
7877 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
7878
7879 @cindex Option, @code{no-installinfo}
7880 @cindex Target, @code{install-info}
7881 @cindex @code{install-info} target
7882 @cindex @code{no-installinfo} option
7883
7884 @opindex no-installinfo
7885 @trindex install-info
7886
7887 Automake generates an @code{install-info} rule; some people apparently
7888 use this.  By default, info pages are installed by @samp{make
7889 install}, so running @code{make install-info} is pointless.  This can
7890 be prevented via the @code{no-installinfo} option.  In this case,
7891 @file{.info} files are not installed by default, and user must
7892 request this explicitly using @samp{make install-info}.
7893
7894 @vindex AM_UPDATE_INFO_DIR
7895 By default, @code{make install-info} and @code{make uninstall-info}
7896 will try to run the @command{install-info} program (if available) to
7897 update (or create/remove) the @file{@code{$@{infodir@}}/dir} index.
7898 If this is undesired, it can be prevented by exporting the
7899 @code{AM_UPDATE_INFO_DIR} variable to "@code{no}".
7900
7901 The following variables are used by the Texinfo build rules.
7902
7903 @vtable @code
7904 @item MAKEINFO
7905 The name of the program invoked to build @file{.info} files.  This
7906 variable is defined by Automake.  If the @command{makeinfo} program is
7907 found on the system then it will be used by default; otherwise
7908 @command{missing} will be used instead.
7909
7910 @item MAKEINFOHTML
7911 The command invoked to build @file{.html} files.  Automake
7912 defines this to @samp{$(MAKEINFO) --html}.
7913
7914 @item MAKEINFOFLAGS
7915 User flags passed to each invocation of @samp{$(MAKEINFO)} and
7916 @samp{$(MAKEINFOHTML)}.  This user variable (@pxref{User Variables}) is
7917 not expected to be defined in any @file{Makefile}; it can be used by
7918 users to pass extra flags to suit their needs.
7919
7920 @item AM_MAKEINFOFLAGS
7921 @itemx AM_MAKEINFOHTMLFLAGS
7922 Maintainer flags passed to each @command{makeinfo} invocation.  Unlike
7923 @code{MAKEINFOFLAGS}, these variables are meant to be defined by
7924 maintainers in @file{Makefile.am}.  @samp{$(AM_MAKEINFOFLAGS)} is
7925 passed to @code{makeinfo} when building @file{.info} files; and
7926 @samp{$(AM_MAKEINFOHTMLFLAGS)} is used when building @file{.html}
7927 files.
7928
7929 @c Keep in sync with txinfo21.sh
7930 For instance, the following setting can be used to obtain one single
7931 @file{.html} file per manual, without node separators.
7932 @example
7933 AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
7934 @end example
7935
7936 @code{AM_MAKEINFOHTMLFLAGS} defaults to @samp{$(AM_MAKEINFOFLAGS)}.
7937 This means that defining @code{AM_MAKEINFOFLAGS} without defining
7938 @code{AM_MAKEINFOHTMLFLAGS} will impact builds of both @file{.info}
7939 and @file{.html} files.
7940
7941 @item TEXI2DVI
7942 The name of the command that converts a @file{.texi} file into a
7943 @file{.dvi} file.  This defaults to @samp{texi2dvi}, a script that ships
7944 with the Texinfo package.
7945
7946 @item TEXI2PDF
7947 The name of the command that translates a @file{.texi} file into a
7948 @file{.pdf} file.  This defaults to @samp{$(TEXI2DVI) --pdf --batch}.
7949
7950 @item DVIPS
7951 The name of the command that builds a @file{.ps} file out of a
7952 @file{.dvi} file.  This defaults to @samp{dvips}.
7953
7954 @item TEXINFO_TEX
7955
7956 If your package has Texinfo files in many directories, you can use the
7957 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
7958 @file{texinfo.tex} for your package.  The value of this variable should
7959 be the relative path from the current @file{Makefile.am} to
7960 @file{texinfo.tex}:
7961
7962 @example
7963 TEXINFO_TEX = ../doc/texinfo.tex
7964 @end example
7965 @end vtable
7966
7967
7968 @node Man Pages
7969 @section Man Pages
7970
7971 @cindex @code{_MANS} primary, defined
7972 @cindex @code{MANS} primary, defined
7973 @cindex Primary variable, @code{MANS}
7974
7975 @vindex _MANS
7976 @vindex man_MANS
7977 A package can also include man pages (but see the GNU standards on this
7978 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
7979 pages are declared using the @code{MANS} primary.  Generally the
7980 @code{man_MANS} variable is used.  Man pages are automatically installed in
7981 the correct subdirectory of @code{mandir}, based on the file extension.
7982
7983 File extensions such as @file{.1c} are handled by looking for the valid
7984 part of the extension and using that to determine the correct
7985 subdirectory of @code{mandir}.  Valid section names are the digits
7986 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
7987
7988 Sometimes developers prefer to name a man page something like
7989 @file{foo.man} in the source, and then rename it to have the correct
7990 suffix, for example @file{foo.1}, when installing the file.  Automake
7991 also supports this mode.  For a valid section named @var{section},
7992 there is a corresponding directory named @samp{man@var{section}dir},
7993 and a corresponding @code{_MANS} variable.  Files listed in such a
7994 variable are installed in the indicated section.  If the file already
7995 has a valid suffix, then it is installed as-is; otherwise the file
7996 suffix is changed to match the section.
7997
7998 For instance, consider this example:
7999 @example
8000 man1_MANS = rename.man thesame.1 alsothesame.1c
8001 @end example
8002
8003 @noindent
8004 In this case, @file{rename.man} will be renamed to @file{rename.1} when
8005 installed, but the other files will keep their names.
8006
8007 @cindex Target, @code{install-man}
8008 @cindex Option, @option{no-installman}
8009 @cindex @code{install-man} target
8010 @cindex @option{no-installman} option
8011 @opindex no-installman
8012 @trindex install-man
8013
8014 By default, man pages are installed by @samp{make install}.  However,
8015 since the GNU project does not require man pages, many maintainers do
8016 not expend effort to keep the man pages up to date.  In these cases, the
8017 @option{no-installman} option will prevent the man pages from being
8018 installed by default.  The user can still explicitly install them via
8019 @samp{make install-man}.
8020
8021 For fast installation, with many files it is preferable to use
8022 @samp{man@var{section}_MANS} over @samp{man_MANS} as well as files that
8023 do not need to be renamed.
8024
8025 Man pages are not currently considered to be source, because it is not
8026 uncommon for man pages to be automatically generated.  Therefore they
8027 are not automatically included in the distribution.  However, this can
8028 be changed by use of the @code{dist_} prefix.  For instance here is
8029 how to distribute and install the two man pages of GNU @command{cpio}
8030 (which includes both Texinfo documentation and man pages):
8031
8032 @example
8033 dist_man_MANS = cpio.1 mt.1
8034 @end example
8035
8036 The @code{nobase_} prefix is meaningless for man pages and is
8037 disallowed.
8038
8039 @vindex notrans_
8040 @cindex @code{notrans_} prefix
8041 @cindex Man page renaming, avoiding
8042 @cindex Avoiding man page renaming
8043
8044 Executables and manpages may be renamed upon installation
8045 (@pxref{Renaming}).  For manpages this can be avoided by use of the
8046 @code{notrans_} prefix.  For instance, suppose an executable @samp{foo}
8047 allowing to access a library function @samp{foo} from the command line.
8048 The way to avoid renaming of the @file{foo.3} manpage is:
8049
8050 @example
8051 man_MANS = foo.1
8052 notrans_man_MANS = foo.3
8053 @end example
8054
8055 @cindex @code{notrans_} and @code{dist_} or @code{nodist_}
8056 @cindex @code{dist_} and @code{notrans_}
8057 @cindex @code{nodist_} and @code{notrans_}
8058
8059 @samp{notrans_} must be specified first when used in conjunction with
8060 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
8061 Control}).  For instance:
8062
8063 @example
8064 notrans_dist_man3_MANS = bar.3
8065 @end example
8066
8067 @node Install
8068 @chapter What Gets Installed
8069
8070 @cindex Installation support
8071 @cindex @samp{make install} support
8072
8073 Naturally, Automake handles the details of actually installing your
8074 program once it has been built.  All files named by the various
8075 primaries are automatically installed in the appropriate places when the
8076 user runs @samp{make install}.
8077
8078 @menu
8079 * Basics of Installation::      What gets installed where
8080 * The Two Parts of Install::    Installing data and programs separately
8081 * Extending Installation::      Adding your own rules for installation
8082 * Staged Installs::             Installation in a temporary location
8083 * Install Rules for the User::  Useful additional rules
8084 @end menu
8085
8086 @node Basics of Installation
8087 @section Basics of Installation
8088
8089 A file named in a primary is installed by copying the built file into
8090 the appropriate directory.  The base name of the file is used when
8091 installing.
8092
8093 @example
8094 bin_PROGRAMS = hello subdir/goodbye
8095 @end example
8096
8097 In this example, both @samp{hello} and @samp{goodbye} will be installed
8098 in @samp{$(bindir)}.
8099
8100 Sometimes it is useful to avoid the basename step at install time.  For
8101 instance, you might have a number of header files in subdirectories of
8102 the source tree that are laid out precisely how you want to install
8103 them.  In this situation you can use the @code{nobase_} prefix to
8104 suppress the base name step.  For example:
8105
8106 @example
8107 nobase_include_HEADERS = stdio.h sys/types.h
8108 @end example
8109
8110 @noindent
8111 will install @file{stdio.h} in @samp{$(includedir)} and @file{types.h}
8112 in @samp{$(includedir)/sys}.
8113
8114 For most file types, Automake will install multiple files at once, while
8115 avoiding command line length issues (@pxref{Length Limitations}).  Since
8116 some @command{install} programs will not install the same file twice in
8117 one invocation, you may need to ensure that file lists are unique within
8118 one variable such as @samp{nobase_include_HEADERS} above.
8119
8120 You should not rely on the order in which files listed in one variable
8121 are installed.  Likewise, to cater for parallel make, you should not
8122 rely on any particular file installation order even among different
8123 file types (library dependencies are an exception here).
8124
8125
8126 @node The Two Parts of Install
8127 @section The Two Parts of Install
8128
8129 Automake generates separate @code{install-data} and @code{install-exec}
8130 rules, in case the installer is installing on multiple machines that
8131 share directory structure---these targets allow the machine-independent
8132 parts to be installed only once.  @code{install-exec} installs
8133 platform-dependent files, and @code{install-data} installs
8134 platform-independent files.  The @code{install} target depends on both
8135 of these targets.  While Automake tries to automatically segregate
8136 objects into the correct category, the @file{Makefile.am} author is, in
8137 the end, responsible for making sure this is done correctly.
8138 @trindex install-data
8139 @trindex install-exec
8140 @trindex install
8141 @cindex Install, two parts of
8142
8143 Variables using the standard directory prefixes @samp{data},
8144 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
8145 @samp{pkgdata}, or @samp{pkginclude} are installed by
8146 @code{install-data}.
8147
8148 Variables using the standard directory prefixes @samp{bin},
8149 @samp{sbin}, @samp{libexec}, @samp{sysconf}, @samp{localstate},
8150 @samp{lib}, or @samp{pkglib} are installed by @code{install-exec}.
8151
8152 For instance, @code{data_DATA} files are installed by @code{install-data},
8153 while @code{bin_PROGRAMS} files are installed by @code{install-exec}.
8154
8155 Any variable using a user-defined directory prefix with
8156 @samp{exec} in the name (e.g.,
8157 @c Keep in sync with primary-prefix-couples-documented-valid.sh
8158 @code{myexecbin_PROGRAMS}) is installed by @code{install-exec}.  All
8159 other user-defined prefixes are installed by @code{install-data}.
8160
8161 @node Extending Installation
8162 @section Extending Installation
8163
8164 It is possible to extend this mechanism by defining an
8165 @code{install-exec-local} or @code{install-data-local} rule.  If these
8166 rules exist, they will be run at @samp{make install} time.  These
8167 rules can do almost anything; care is required.
8168 @trindex install-exec-local
8169 @trindex install-data-local
8170
8171 Automake also supports two install hooks, @code{install-exec-hook} and
8172 @code{install-data-hook}.  These hooks are run after all other install
8173 rules of the appropriate type, exec or data, have completed.  So, for
8174 instance, it is possible to perform post-installation modifications
8175 using an install hook.  @xref{Extending}, for some examples.
8176 @cindex Install hook
8177
8178 @node Staged Installs
8179 @section Staged Installs
8180
8181 @vindex DESTDIR
8182 Automake generates support for the @code{DESTDIR} variable in all
8183 install rules.  @code{DESTDIR} is used during the @samp{make install}
8184 step to relocate install objects into a staging area.  Each object and
8185 path is prefixed with the value of @code{DESTDIR} before being copied
8186 into the install area.  Here is an example of typical DESTDIR usage:
8187
8188 @example
8189 mkdir /tmp/staging &&
8190 make DESTDIR=/tmp/staging install
8191 @end example
8192
8193 The @command{mkdir} command avoids a security problem if the attacker
8194 creates a symbolic link from @file{/tmp/staging} to a victim area;
8195 then @command{make} places install objects in a directory tree built under
8196 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
8197 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
8198 would install @file{/tmp/staging/gnu/bin/foo} and
8199 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
8200
8201 This feature is commonly used to build install images and packages
8202 (@pxref{DESTDIR}).
8203
8204 Support for @code{DESTDIR} is implemented by coding it directly into
8205 the install rules.  If your @file{Makefile.am} uses a local install
8206 rule (e.g., @code{install-exec-local}) or an install hook, then you
8207 must write that code to respect @code{DESTDIR}.
8208
8209 @xref{Makefile Conventions, , , standards, The GNU Coding Standards},
8210 for another usage example.
8211
8212 @node Install Rules for the User
8213 @section Install Rules for the User
8214
8215 Automake also generates rules for targets @code{uninstall},
8216 @code{installdirs}, and @code{install-strip}.
8217 @trindex uninstall
8218 @trindex installdirs
8219 @trindex install-strip
8220
8221 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
8222 There is no notion of separate uninstalls for ``exec'' and ``data'', as
8223 these features would not provide additional functionality.
8224
8225 Note that @code{uninstall} is not meant as a replacement for a real
8226 packaging tool.
8227
8228
8229 @node Clean
8230 @chapter What Gets Cleaned
8231
8232 @cindex @samp{make clean} support
8233
8234 The GNU Makefile Standards specify a number of different clean rules.
8235 @xref{Standard Targets, , Standard Targets for Users, standards,
8236 The GNU Coding Standards}.
8237
8238 Generally the files that can be cleaned are determined automatically by
8239 Automake.  Of course, Automake also recognizes some variables that can
8240 be defined to specify additional files to clean.  These variables are
8241 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
8242 @code{MAINTAINERCLEANFILES}.
8243 @vindex MOSTLYCLEANFILES
8244 @vindex CLEANFILES
8245 @vindex DISTCLEANFILES
8246 @vindex MAINTAINERCLEANFILES
8247
8248 @trindex mostlyclean-local
8249 @trindex clean-local
8250 @trindex distclean-local
8251 @trindex maintainer-clean-local
8252 When cleaning involves more than deleting some hard-coded list of
8253 files, it is also possible to supplement the cleaning rules with your
8254 own commands.  Simply define a rule for any of the
8255 @code{mostlyclean-local}, @code{clean-local}, @code{distclean-local},
8256 or @code{maintainer-clean-local} targets (@pxref{Extending}).  A common
8257 case is deleting a directory, for instance, a directory created by the
8258 test suite:
8259
8260 @example
8261 clean-local:
8262         -rm -rf testSubDir
8263 @end example
8264
8265 Since @command{make} allows only one set of rules for a given target,
8266 a more extensible way of writing this is to use a separate target
8267 listed as a dependency:
8268
8269 @example
8270 clean-local: clean-local-check
8271 .PHONY: clean-local-check
8272 clean-local-check:
8273         -rm -rf testSubDir
8274 @end example
8275
8276 As the GNU Standards aren't always explicit as to which files should
8277 be removed by which rule, we've adopted a heuristic that we believe
8278 was first formulated by Fran@,{c}ois Pinard:
8279
8280 @itemize @bullet
8281 @item
8282 If @command{make} built it, and it is commonly something that one would
8283 want to rebuild (for instance, a @file{.o} file), then
8284 @code{mostlyclean} should delete it.
8285
8286 @item
8287 Otherwise, if @command{make} built it, then @code{clean} should delete it.
8288
8289 @item
8290 If @command{configure} built it, then @code{distclean} should delete it.
8291
8292 @item
8293 If the maintainer built it (for instance, a @file{.info} file), then
8294 @code{maintainer-clean} should delete it.  However
8295 @code{maintainer-clean} should not delete anything that needs to exist
8296 in order to run @samp{./configure && make}.
8297 @end itemize
8298
8299 We recommend that you follow this same set of heuristics in your
8300 @file{Makefile.am}.
8301
8302
8303 @node Dist
8304 @chapter What Goes in a Distribution
8305
8306 @menu
8307 * Basics of Distribution::      Files distributed by default
8308 * Fine-grained Distribution Control::  @code{dist_} and @code{nodist_} prefixes
8309 * The dist Hook::               A target for last-minute distribution changes
8310 * Checking the Distribution::   @samp{make distcheck} explained
8311 * The Types of Distributions::  A variety of formats and compression methods
8312 @end menu
8313
8314 @node Basics of Distribution
8315 @section Basics of Distribution
8316
8317 @cindex @samp{make dist}
8318
8319 @vindex PACKAGE
8320 @vindex VERSION
8321 @trindex dist
8322 The @code{dist} rule in the generated @file{Makefile.in} can be used
8323 to generate a gzipped @code{tar} file and other flavors of archive for
8324 distribution.  The file is named based on the @code{PACKAGE} and
8325 @code{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
8326 (@pxref{Macros}); more precisely the gzipped @code{tar} file is named
8327 @samp{@var{package}-@var{version}.tar.gz}.
8328 @vindex GZIP_ENV
8329 You can use the @command{make} variable @code{GZIP_ENV} to control how gzip
8330 is run.  The default setting is @option{--best}.
8331
8332 @cindex @code{m4_include}, distribution
8333 @cindex @code{include}, distribution
8334 @acindex m4_include
8335 @cmindex include
8336 For the most part, the files to distribute are automatically found by
8337 Automake: all source files are automatically included in a distribution,
8338 as are all @file{Makefile.am} and @file{Makefile.in} files.  Automake also
8339 has a built-in list of commonly used files that are automatically
8340 included if they are found in the current directory (either physically,
8341 or as the target of a @file{Makefile.am} rule); this list is printed by
8342 @samp{automake --help}.  Note that some files in this list are actually
8343 distributed only if other certain conditions hold (for example,
8344 @c Keep in sync with autodist-config-headers.sh
8345 the @file{config.h.top} and @file{config.h.bot} files are automatically
8346 distributed only if, e.g., @samp{AC_CONFIG_HEADERS([config.h])} is used
8347 in @file{configure.ac}).  Also, files that are read by @command{configure}
8348 (i.e.@: the source files corresponding to the files specified in various
8349 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
8350 automatically distributed.  Files included in a @file{Makefile.am} (using
8351 @code{include}) or in @file{configure.ac} (using @code{m4_include}), and
8352 helper scripts installed with @samp{automake --add-missing} are also
8353 distributed.
8354
8355 @vindex EXTRA_DIST
8356 Still, sometimes there are files that must be distributed, but which
8357 are not covered in the automatic rules.  These files should be listed in
8358 the @code{EXTRA_DIST} variable.  You can mention files from
8359 subdirectories in @code{EXTRA_DIST}.
8360
8361 You can also mention a directory in @code{EXTRA_DIST}; in this case the
8362 entire directory will be recursively copied into the distribution.
8363 Please note that this will also copy @emph{everything} in the directory,
8364 including, e.g., Subversion's @file{.svn} private directories or CVS/RCS
8365 version control files.  We recommend against using this feature.
8366
8367 @vindex SUBDIRS
8368 @vindex DIST_SUBDIRS
8369 If you define @code{SUBDIRS}, Automake will recursively include the
8370 subdirectories in the distribution.  If @code{SUBDIRS} is defined
8371 conditionally (@pxref{Conditionals}), Automake will normally include
8372 all directories that could possibly appear in @code{SUBDIRS} in the
8373 distribution.  If you need to specify the set of directories
8374 conditionally, you can set the variable @code{DIST_SUBDIRS} to the
8375 exact list of subdirectories to include in the distribution
8376 (@pxref{Conditional Subdirectories}).
8377
8378
8379 @node Fine-grained Distribution Control
8380 @section Fine-grained Distribution Control
8381
8382 @vindex dist_
8383 @vindex nodist_
8384 Sometimes you need tighter control over what does @emph{not} go into the
8385 distribution; for instance, you might have source files that are
8386 generated and that you do not want to distribute.  In this case
8387 Automake gives fine-grained control using the @code{dist} and
8388 @code{nodist} prefixes.  Any primary or @code{_SOURCES} variable can be
8389 prefixed with @code{dist_} to add the listed files to the distribution.
8390 Similarly, @code{nodist_} can be used to omit the files from the
8391 distribution.
8392
8393 As an example, here is how you would cause some data to be distributed
8394 while leaving some source code out of the distribution:
8395
8396 @example
8397 dist_data_DATA = distribute-this
8398 bin_PROGRAMS = foo
8399 nodist_foo_SOURCES = do-not-distribute.c
8400 @end example
8401
8402 @node The dist Hook
8403 @section The dist Hook
8404
8405 @trindex dist-hook
8406
8407 Occasionally it is useful to be able to change the distribution before
8408 it is packaged up.  If the @code{dist-hook} rule exists, it is run
8409 after the distribution directory is filled, but before the actual
8410 distribution archives are created.  One way to use this is for
8411 removing unnecessary files that get recursively included by specifying
8412 a directory in @code{EXTRA_DIST}:
8413
8414 @example
8415 EXTRA_DIST = doc
8416 dist-hook:
8417         rm -rf `find $(distdir)/doc -type d -name .svn`
8418 @end example
8419
8420 @c The caveates described here should be documented in 'disthook.sh'.
8421 @noindent
8422 Note that the @code{dist-hook} recipe shouldn't assume that the regular
8423 files in the distribution directory are writable; this might not be the
8424 case if one is packaging from a read-only source tree, or when a
8425 @code{make distcheck} is being done.  For similar reasons, the recipe
8426 shouldn't assume that the subdirectories put into the distribution
8427 directory as effect of having them listed in @code{EXTRA_DIST} are
8428 writable.  So, if the @code{dist-hook} recipe wants to modify the
8429 content of an existing file (or @code{EXTRA_DIST} subdirectory) in the
8430 distribution directory, it should explicitly to make it writable first:
8431
8432 @example
8433 EXTRA_DIST = README doc
8434 dist-hook:
8435         chmod u+w $(distdir)/README $(distdir)/doc
8436         echo "Distribution date: `date`" >> README
8437         rm -f $(distdir)/doc/HACKING
8438 @end example
8439
8440 @vindex distdir
8441 @vindex top_distdir
8442 Two variables that come handy when writing @code{dist-hook} rules are
8443 @samp{$(distdir)} and @samp{$(top_distdir)}.
8444
8445 @samp{$(distdir)} points to the directory where the @code{dist} rule
8446 will copy files from the current directory before creating the
8447 tarball.  If you are at the top-level directory, then @samp{distdir =
8448 $(PACKAGE)-$(VERSION)}.  When used from subdirectory named
8449 @file{foo/}, then @samp{distdir = ../$(PACKAGE)-$(VERSION)/foo}.
8450 @samp{$(distdir)} can be a relative or absolute path, do not assume
8451 any form.
8452
8453 @samp{$(top_distdir)} always points to the root directory of the
8454 distributed tree.  At the top-level it's equal to @samp{$(distdir)}.
8455 In the @file{foo/} subdirectory
8456 @samp{top_distdir = ../$(PACKAGE)-$(VERSION)}.
8457 @samp{$(top_distdir)} too can be a relative or absolute path.
8458
8459 Note that when packages are nested using @code{AC_CONFIG_SUBDIRS}
8460 (@pxref{Subpackages}), then @samp{$(distdir)} and
8461 @samp{$(top_distdir)} are relative to the package where @samp{make
8462 dist} was run, not to any sub-packages involved.
8463
8464 @node Checking the Distribution
8465 @section Checking the Distribution
8466
8467 @cindex @samp{make distcheck}
8468 @trindex distcheck
8469 Automake also generates a @code{distcheck} rule that can be of help
8470 to ensure that a given distribution will actually work.  Simplifying
8471 a bit, we can say this rule first makes a distribution, and then,
8472 @emph{operating from it}, takes the following steps:
8473 @itemize
8474 @item
8475 tries to do a @code{VPATH} build (@pxref{VPATH Builds}), with the
8476 @code{srcdir} and all its content made @emph{read-only};
8477 @item
8478 runs the test suite (with @command{make check}) on this fresh build;
8479 @item
8480 installs the package in a temporary directory (with @command{make
8481 install}), and tries runs the test suite on the resulting installation
8482 (with @command{make installcheck});
8483 @item
8484 checks that the package can be correctly uninstalled (by @command{make
8485 uninstall}) and cleaned (by @code{make distclean});
8486 @item
8487 finally, makes another tarball to ensure the distribution is
8488 self-contained.
8489 @end itemize
8490
8491 @vindex AM_DISTCHECK_CONFIGURE_FLAGS
8492 @vindex DISTCHECK_CONFIGURE_FLAGS
8493 @subheading DISTCHECK_CONFIGURE_FLAGS
8494 Building the package involves running @samp{./configure}.  If you need
8495 to supply additional flags to @command{configure}, define them in the
8496 @code{AM_DISTCHECK_CONFIGURE_FLAGS} variable in your top-level
8497 @file{Makefile.am}.  The user can still extend or override the flags
8498 provided there by defining the @code{DISTCHECK_CONFIGURE_FLAGS} variable,
8499 on the command line when invoking @command{make}.
8500
8501 Still, developers are encouraged to strive to make their code buildable
8502 without requiring any special configure option; thus, in general, you
8503 shouldn't define @code{AM_DISTCHECK_CONFIGURE_FLAGS}. However, there
8504 might be few scenarios in which the use of this variable is justified.
8505 GNU @command{m4} offers an example.  GNU @command{m4} configures by
8506 default with its experimental and seldom used "changeword" feature
8507 disabled; so in its case it is useful to have @command{make distcheck}
8508 run configure with the @option{--with-changeword} option, to ensure that
8509 the code for changeword support still compiles correctly.
8510 GNU @command{m4} also employs the @code{AM_DISTCHECK_CONFIGURE_FLAGS}
8511 variable to stress-test the use of @option{--program-prefix=g}, since at
8512 one point the @command{m4} build system had a bug where @command{make
8513 installcheck} was wrongly assuming it could blindly test "@command{m4}",
8514 rather than the just-installed "@command{gm4}".
8515
8516 @trindex distcheck-hook
8517 @subheading distcheck-hook
8518 If the @code{distcheck-hook} rule is defined in your top-level
8519 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
8520 the new distribution has been unpacked, but before the unpacked copy
8521 is configured and built.  Your @code{distcheck-hook} can do almost
8522 anything, though as always caution is advised.  Generally this hook is
8523 used to check for potential distribution errors not caught by the
8524 standard mechanism.  Note that @code{distcheck-hook} as well as
8525 @code{AM_DISTCHECK_CONFIGURE_FLAGS} and @code{DISTCHECK_CONFIGURE_FLAGS}
8526 are not honored in a subpackage @file{Makefile.am}, but the flags from
8527 @code{AM_DISTCHECK_CONFIGURE_FLAGS} and @code{DISTCHECK_CONFIGURE_FLAGS}
8528 are passed down to the @command{configure} script of the subpackage.
8529
8530 @cindex @samp{make distcleancheck}
8531 @trindex distcleancheck
8532 @vindex DISTCLEANFILES
8533 @vindex distcleancheck_listfiles
8534
8535 @subheading distcleancheck
8536 Speaking of potential distribution errors, @code{distcheck} also
8537 ensures that the @code{distclean} rule actually removes all built
8538 files.  This is done by running @samp{make distcleancheck} at the end of
8539 the @code{VPATH} build.  By default, @code{distcleancheck} will run
8540 @code{distclean} and then make sure the build tree has been emptied by
8541 running @samp{$(distcleancheck_listfiles)}.  Usually this check will
8542 find generated files that you forgot to add to the @code{DISTCLEANFILES}
8543 variable (@pxref{Clean}).
8544
8545 The @code{distcleancheck} behavior should be OK for most packages,
8546 otherwise you have the possibility to override the definition of
8547 either the @code{distcleancheck} rule, or the
8548 @samp{$(distcleancheck_listfiles)} variable.  For instance, to disable
8549 @code{distcleancheck} completely, add the following rule to your
8550 top-level @file{Makefile.am}:
8551
8552 @example
8553 distcleancheck:
8554         @@:
8555 @end example
8556
8557 If you want @code{distcleancheck} to ignore built files that have not
8558 been cleaned because they are also part of the distribution, add the
8559 following definition instead:
8560
8561 @c Keep in sync with distcleancheck.sh
8562 @example
8563 distcleancheck_listfiles = \
8564   find . -type f -exec sh -c 'test -f $(srcdir)/$$1 || echo $$1' \
8565        sh '@{@}' ';'
8566 @end example
8567
8568 The above definition is not the default because it's usually an error if
8569 your Makefiles cause some distributed files to be rebuilt when the user
8570 build the package.  (Think about the user missing the tool required to
8571 build the file; or if the required tool is built by your package,
8572 consider the cross-compilation case where it can't be run.)  There is
8573 an entry in the FAQ about this (@pxref{Errors with distclean}), make
8574 sure you read it before playing with @code{distcleancheck_listfiles}.
8575
8576 @cindex @samp{make distuninstallcheck}
8577 @trindex distuninstallcheck
8578 @vindex distuninstallcheck_listfiles
8579
8580 @subheading distuninstallcheck
8581 @code{distcheck} also checks that the @code{uninstall} rule works
8582 properly, both for ordinary and @code{DESTDIR} builds.  It does this
8583 by invoking @samp{make uninstall}, and then it checks the install tree
8584 to see if any files are left over.  This check will make sure that you
8585 correctly coded your @code{uninstall}-related rules.
8586
8587 By default, the checking is done by the @code{distuninstallcheck} rule,
8588 and the list of files in the install tree is generated by
8589 @samp{$(distuninstallcheck_listfiles)} (this is a variable whose value is
8590 a shell command to run that prints the list of files to stdout).
8591
8592 Either of these can be overridden to modify the behavior of
8593 @code{distcheck}.  For instance, to disable this check completely, you
8594 would write:
8595
8596 @example
8597 distuninstallcheck:
8598         @@:
8599 @end example
8600
8601 @node The Types of Distributions
8602 @section The Types of Distributions
8603
8604 Automake generates rules to provide archives of the project for
8605 distributions in various formats.  Their targets are:
8606
8607 @table @asis
8608 @vindex BZIP2
8609 @item @code{dist-bzip2}
8610 Generate a bzip2 tar archive of the distribution.  bzip2 archives are
8611 frequently smaller than gzipped archives.
8612 By default, this rule makes @samp{bzip2} use a compression option of @option{-9}.
8613 To make it use a different one, set the @env{BZIP2} environment variable.
8614 For example, @samp{make dist-bzip2 BZIP2=-7}.
8615 @trindex dist-bzip2
8616
8617 @item @code{dist-gzip}
8618 Generate a gzip tar archive of the distribution.
8619 @trindex dist-gzip
8620
8621 @item @code{dist-lzip}
8622 Generate an @samp{lzip} tar archive of the distribution.  @command{lzip}
8623 archives are frequently smaller than @command{bzip2}-compressed archives.
8624 @trindex dist-lzip
8625
8626 @item @code{dist-shar}
8627 Generate a shar archive of the distribution.
8628 @trindex dist-shar
8629
8630 @vindex XZ_OPT
8631 @item @code{dist-xz}
8632 Generate an @samp{xz} tar archive of the distribution.  @command{xz}
8633 archives are frequently smaller than @command{bzip2}-compressed archives.
8634 By default, this rule makes @samp{xz} use a compression option of
8635 @option{-e}.  To make it use a different one, set the @env{XZ_OPT}
8636 environment variable.  For example, run this command to use the
8637 default compression ratio, but with a progress indicator:
8638 @samp{make dist-xz XZ_OPT=-7e}.
8639 @trindex dist-xz
8640
8641 @item @code{dist-zip}
8642 Generate a zip archive of the distribution.
8643 @trindex dist-zip
8644
8645 @item @code{dist-tarZ}
8646 Generate a compressed tar archive of
8647 the distribution.
8648 @trindex dist-tarZ
8649 @end table
8650
8651 The rule @code{dist} (and its historical synonym @code{dist-all}) will
8652 create archives in all the enabled formats, @ref{Options}.  By
8653 default, only the @code{dist-gzip} target is hooked to @code{dist}.
8654
8655
8656 @node Tests
8657 @chapter Support for test suites
8658
8659 @cindex Test suites
8660 @cindex @code{make check}
8661 @trindex check
8662
8663 Automake can generate code to handle two kinds of test suites.  One is
8664 based on integration with the @command{dejagnu} framework.  The other
8665 (and most used) form is based on the use of generic test scripts, and
8666 its activation is triggered by the definition of the special @code{TESTS}
8667 variable.  This second form allows for various degrees of sophistication
8668 and customization; in particular, it allows for concurrent execution
8669 of test scripts, use of established test protocols such as TAP, and
8670 definition of custom test drivers and test runners.
8671
8672 @noindent
8673 In either case, the testsuite is invoked via @samp{make check}.
8674
8675 @menu
8676 * Generalities about Testing::  Concepts and terminology about testing
8677 * Simple Tests::                Listing test scripts in @code{TESTS}
8678 * Custom Test Drivers::         Writing and using custom test drivers
8679 * Using the TAP test protocol:: Integrating test scripts that use the TAP protocol
8680 * DejaGnu Tests::               Interfacing with the @command{dejagnu} testing framework
8681 * Install Tests::               Running tests on installed packages
8682 @end menu
8683
8684 @node Generalities about Testing
8685 @section Generalities about Testing
8686
8687 The purpose of testing is to determine whether a program or system behaves
8688 as expected (e.g., known inputs produce the expected outputs, error
8689 conditions are correctly handled or reported, and older bugs do not
8690 resurface).
8691
8692 @cindex test case
8693 The minimal unit of testing is usually called @emph{test case}, or simply
8694 @emph{test}.  How a test case is defined or delimited, and even what
8695 exactly @emph{constitutes} a test case, depends heavily on the testing
8696 paradigm and/or framework in use, so we won't attempt any more precise
8697 definition.  The set of the test cases for a given program or system
8698 constitutes its @emph{testsuite}.
8699
8700 @cindex test harness
8701 @cindex testsuite harness
8702 A @emph{test harness} (also @emph{testsuite harness}) is a program or
8703 software component that executes all (or part of) the defined test cases,
8704 analyzes their outcomes, and report or register these outcomes
8705 appropriately.  Again, the details of how this is accomplished (and how
8706 the developer and user can influence it or interface with it) varies
8707 wildly, and we'll attempt no precise definition.
8708
8709 @cindex test pass
8710 @cindex test failure
8711 A test is said to @emph{pass} when it can determine that the condition or
8712 behaviour it means to verify holds, and is said to @emph{fail} when it can
8713 determine that such condition of behaviour does @emph{not} hold.
8714
8715 @cindex test skip
8716 Sometimes, tests can rely on non-portable tools or prerequisites, or
8717 simply make no sense on a given system (for example, a test checking a
8718 Windows-specific feature makes no sense on a GNU/Linux system).  In this
8719 case, accordingly to the definition above, the tests can neither be
8720 considered passed nor failed; instead, they are @emph{skipped} -- i.e.,
8721 they are not run, or their result is anyway ignored for what concerns
8722 the count of failures an successes.  Skips are usually explicitly
8723 reported though, so that the user will be aware that not all of the
8724 testsuite has really run.
8725
8726 @cindex xfail
8727 @cindex expected failure
8728 @cindex expected test failure
8729 @cindex xpass
8730 @cindex unexpected pass
8731 @cindex unexpected test pass
8732 It's not uncommon, especially during early development stages, that some
8733 tests fail for known reasons, and that the developer doesn't want to
8734 tackle these failures immediately (this is especially true when the
8735 failing tests deal with corner cases).  In this situation, the better
8736 policy is to declare that each of those failures is an @emph{expected
8737 failure} (or @emph{xfail}).  In case a test that is expected to fail ends
8738 up passing instead, many testing environments will flag the result as a
8739 special kind of failure called @emph{unexpected pass} (or @emph{xpass}).
8740
8741 @cindex hard error
8742 @cindex Distinction between errors and failures in testsuites
8743 Many testing environments and frameworks distinguish between test failures
8744 and hard errors.  As we've seen, a test failure happens when some invariant
8745 or expected behaviour of the software under test is not met.  An @emph{hard
8746 error} happens when e.g., the set-up of a test case scenario fails, or when
8747 some other unexpected or highly undesirable condition is encountered (for
8748 example, the program under test experiences a segmentation fault).
8749
8750 @emph{TODO}: Links to other test harnesses (esp. those sharing our
8751 terminology)?
8752
8753 @node Simple Tests
8754 @section Simple Tests
8755
8756 @menu
8757 * Scripts-based Testsuites::    Automake-specific concepts and terminology
8758 * Serial Test Harness::         Older (and obsolescent) serial test harness
8759 * Parallel Test Harness::       Generic concurrent test harness
8760 @end menu
8761
8762 @node Scripts-based Testsuites
8763 @subsection Scripts-based Testsuites
8764
8765 If the special variable @code{TESTS} is defined, its value is taken to be
8766 a list of programs or scripts to run in order to do the testing.  Under
8767 the appropriate circumstances, it's possible for @code{TESTS} to list
8768 also data files to be passed to one or more test scripts defined by
8769 different means (the so-called ``log compilers'', @pxref{Parallel Test
8770 Harness}).
8771
8772 Test scripts can be executed serially or concurrently.  Automake supports
8773 both these kinds of test execution, with the parallel test harness being
8774 the default.  The concurrent test harness relies on the concurrence
8775 capabilities (if any) offered by the underlying @command{make}
8776 implementation, and can thus only be as good as those are.
8777
8778 By default, only the exit statuses of the test scripts are considered when
8779 determining the testsuite outcome.  But Automake allows also the use of
8780 more complex test protocols, either standard (@pxref{Using the TAP test
8781 protocol}) or custom (@pxref{Custom Test Drivers}).  Note that you can't
8782 enable such protocols when the serial harness is used, though.
8783 In the rest of this section we are going to concentrate mostly on
8784 protocol-less tests, since we cover test protocols in a later section
8785 (again, @pxref{Custom Test Drivers}).
8786
8787 @cindex Exit status 77, special interpretation
8788 @cindex Exit status 99, special interpretation
8789 When no test protocol is in use, an exit status of 0 from a test script will
8790 denote a success, an exit status of 77 a skipped test, an exit status of 99
8791 an hard error, and any other exit status will denote a failure.
8792
8793 @cindex Tests, expected failure
8794 @cindex Expected test failure
8795 @vindex XFAIL_TESTS
8796 @vindex DISABLE_HARD_ERRORS
8797 @cindex Disabling hard errors
8798 You may define the variable @code{XFAIL_TESTS} to a list of tests
8799 (usually a subset of @code{TESTS}) that are expected to fail; this will
8800 effectively reverse the result of those tests (with the provision that
8801 skips and hard errors remain untouched).  You may also instruct the
8802 testsuite harness to treat hard errors like simple failures, by defining
8803 the @code{DISABLE_HARD_ERRORS} make variable to a nonempty value.
8804
8805 Note however that, for tests based on more complex test protocols,
8806 the exact effects of @code{XFAIL_TESTS} and @code{DISABLE_HARD_ERRORS}
8807 might change, or they might even have no effect at all (for example,
8808 @c Keep this in sync with tap-no-disable-hard-errors.sh
8809 in tests using TAP, there is not way to disable hard errors, and the
8810 @code{DISABLE_HARD_ERRORS} variable has no effect on them).
8811
8812 @anchor{Testsuite progress on console}
8813 @cindex Testsuite progress on console
8814 The result of each test case run by the scripts in @code{TESTS} will be
8815 printed on standard output, along with the test name.  For test protocols
8816 that allow more test cases per test script (such as TAP), a number,
8817 identifier and/or brief description specific for the single test case is
8818 expected to be printed in addition to the name of the test script.  The
8819 possible results (whose meanings should be clear from the previous
8820 @ref{Generalities about Testing}) are @code{PASS}, @code{FAIL},
8821 @code{SKIP}, @code{XFAIL}, @code{XPASS} and @code{ERROR}.  Here is an
8822 example of output from an hypothetical testsuite that uses both plain
8823 and TAP tests:
8824 @c Keep in sync with tap-doc.sh
8825 @example
8826 PASS: foo.sh
8827 PASS: zardoz.tap 1 - Daemon started
8828 PASS: zardoz.tap 2 - Daemon responding
8829 SKIP: zardoz.tap 3 - Daemon uses /proc # SKIP /proc is not mounted
8830 PASS: zardoz.tap 4 - Daemon stopped
8831 SKIP: bar.sh
8832 PASS: mu.tap 1
8833 XFAIL: mu.tap 2 # TODO frobnication not yet implemented
8834 @end example
8835
8836 @noindent
8837 A testsuite summary (expected to report at least the number of run,
8838 skipped and failed tests) will be printed at the end of the testsuite
8839 run.
8840
8841 @anchor{Simple tests and color-tests}
8842 @vindex AM_COLOR_TESTS
8843 @cindex Colorized testsuite output
8844 If the standard output is connected to a capable terminal, then the test
8845 results and the summary are colored appropriately.  The developer and the
8846 user can disable colored output by setting the @command{make} variable
8847 @samp{AM_COLOR_TESTS=no}; the user can in addition force colored output
8848 even without a connecting terminal with @samp{AM_COLOR_TESTS=always}.  
8849 It's also worth noting that some @command{make} implementations,
8850 when used in parallel mode, have slightly different semantics
8851 (@pxref{Parallel make,,, autoconf, The Autoconf Manual}), which can
8852 break the automatic detection of a connection to a capable terminal.
8853 If this is the case, the user will have to resort to the use of
8854 @samp{AM_COLOR_TESTS=always} in order to have the testsuite output
8855 colorized.
8856
8857 Test programs that need data files should look for them in @code{srcdir}
8858 (which is both a make variable and an environment variable made available
8859 to the tests), so that they work when building in a separate directory
8860 (@pxref{Build Directories, , Build Directories , autoconf,
8861 The Autoconf Manual}), and in particular for the @code{distcheck} rule
8862 (@pxref{Checking the Distribution}).
8863
8864 @vindex TESTS
8865 @vindex TESTS_ENVIRONMENT
8866 @vindex AM_TESTS_ENVIRONMENT
8867 The @code{AM_TESTS_ENVIRONMENT} and @code{TESTS_ENVIRONMENT} variables can
8868 be used to run initialization code and set environment variables for the
8869 test scripts.  The former variable is developer-reserved, and can be
8870 defined in the @file{Makefile.am}, while the latter is reserved for the
8871 user, which can employ it to extend or override the settings in the
8872 former; for this to work portably, however, the contents of a non-empty
8873 @code{AM_TESTS_ENVIRONMENT} @emph{must} be terminated by a semicolon.
8874
8875 @vindex AM_TESTS_FD_REDIRECT
8876 The @code{AM_TESTS_FD_REDIRECT} variable can be used to define file
8877 descriptor redirections for the test scripts.  One might think that
8878 @code{AM_TESTS_ENVIRONMENT} could be used for this purpose, but experience
8879 has shown that doing so portably is practically impossible.  The main
8880 hurdle is constituted by Korn shells, which usually set the close-on-exec
8881 flag on file descriptors opened with the @command{exec} builtin, thus
8882 rendering an idiom like @code{AM_TESTS_ENVIRONMENT = exec 9>&2;}
8883 ineffectual.  This issue also affects some Bourne shells, such as the
8884 HP-UX's @command{/bin/sh},
8885 @c FIXME: should we offer a link to the relevant discussions on the
8886 @c bug-autoconf list?
8887
8888 @c Keep in sync with tests-environment-backcompat.sh
8889 @example
8890 AM_TESTS_ENVIRONMENT = \
8891 ## Some environment initializations are kept in a separate shell
8892 ## file 'tests-env.sh', which can make it easier to also run tests
8893 ## from the command line.
8894   . $(srcdir)/tests-env.sh; \
8895 ## On Solaris, prefer more POSIX-compliant versions of the standard
8896 ## tools by default.
8897   if test -d /usr/xpg4/bin; then \
8898     PATH=/usr/xpg4/bin:$$PATH; export PATH; \
8899   fi;
8900 @c $$ restore font-lock
8901 ## With this, the test scripts will be able to print diagnostic
8902 ## messages to the original standard error stream, even if the test
8903 ## driver redirects the stderr of the test scripts to a log file
8904 ## before executing them.
8905 AM_TESTS_FD_REDIRECT = 9>&2
8906 @end example
8907
8908 @noindent
8909 Note however that @code{AM_TESTS_ENVIRONMENT} is, for historical and
8910 implementation reasons, @emph{not} supported by the serial harness
8911 (@pxref{Serial Test Harness}).
8912
8913 Automake ensures that each file listed in @code{TESTS} is built before
8914 it is run; you can list both source and derived programs (or scripts)
8915 in @code{TESTS}; the generated rule will look both in @code{srcdir} and
8916 @file{.}.  For instance, you might want to run a C program as a test.
8917 To do this you would list its name in @code{TESTS} and also in
8918 @code{check_PROGRAMS}, and then specify it as you would any other
8919 program.
8920
8921 Programs listed in @code{check_PROGRAMS} (and @code{check_LIBRARIES},
8922 @code{check_LTLIBRARIES}...) are only built during @code{make check},
8923 not during @code{make all}.  You should list there any program needed
8924 by your tests that does not need to be built by @code{make all}.  Note
8925 that @code{check_PROGRAMS} are @emph{not} automatically added to
8926 @code{TESTS} because @code{check_PROGRAMS} usually lists programs used
8927 by the tests, not the tests themselves.  Of course you can set
8928 @code{TESTS = $(check_PROGRAMS)} if all your programs are test cases.
8929
8930 @node Serial Test Harness
8931 @subsection Older (and obsolescent) serial test harness
8932 @cindex @option{serial-tests}, Using
8933
8934 @emph{This harness is obsolescent}, and kept for backward-compatibility
8935 reasons only.  The user is strongly advised to just use the parallel test
8936 harness instead (@pxref{Parallel Test Harness}).
8937
8938 The serial test harness is enabled by the Automake option
8939 @option{serial-tests}. It operates by simply running the tests serially,
8940 one at the time, without any I/O redirection.  It's up to the user to
8941 implement logging of tests' output, if that's requited or desired.
8942 @c TODO: give an example of how this can be done.
8943
8944 For historical and implementation reasons, the @code{AM_TESTS_ENVIRONMENT}
8945 variable is @emph{not} supported by this harness (it will be silently
8946 ignored if defined); only @code{TESTS_ENVIRONMENT} is, and it is to be
8947 considered a developer-reserved variable.  This is done so that, when
8948 using the serial harness, @code{TESTS_ENVIRONMENT} can be defined to an
8949 invocation of an interpreter through which the tests are to be run.
8950 For instance, the following setup may be used to run tests with Perl:
8951
8952 @example
8953 TESTS_ENVIRONMENT = $(PERL) -Mstrict -w
8954 TESTS = foo.pl bar.pl baz.pl
8955 @end example
8956
8957 @noindent
8958 It's important to note that the use of @code{TESTS_ENVIRONMENT} endorsed
8959 here would be @emph{invalid} with the parallel harness.  That harness
8960 provides a more elegant way to achieve the same effect, with the further
8961 benefit of freeing the @code{TESTS_ENVIRONMENT} variable for the user
8962 (@pxref{Parallel Test Harness}).
8963
8964 Another, less serious limit of the serial harness is that it doesn't
8965 really distinguish between simple failures and hard errors; this is
8966 due to historical reasons only, and might be fixed in future Automake
8967 versions.
8968
8969 @node Parallel Test Harness
8970 @subsection Parallel Test Harness
8971
8972 By default, Automake generated a parallel (concurrent) test harness.  It
8973 features automatic collection of the test scripts output in @file{.log}
8974 files, concurrent execution of tests with @code{make -j}, specification
8975 of inter-test dependencies, lazy reruns of tests that have not completed
8976 in a prior run, and hard errors for exceptional failures.
8977
8978 This harness is still somewhat experimental and may undergo changes in
8979 order to satisfy additional portability requirements.
8980
8981 @anchor{Basics of test metadata}
8982 @vindex TEST_SUITE_LOG
8983 @vindex TESTS
8984 @cindex @file{.log} files
8985 @cindex @file{.trs} files
8986 @cindex test metadata
8987 The parallel test harness operates by defining a set of @command{make}
8988 rules that run the test scripts listed in @code{TESTS}, and, for each
8989 such script, save its output in a corresponding @file{.log} file and
8990 its results (and other ``metadata'', @pxref{API for Custom Test Drivers})
8991 in a corresponding @file{.trs} (as in @b{T}est @b{R}e@b{S}ults) file.
8992 @c We choose the '.trs' extension also because, at the time of writing,
8993 @c it isn't already used for other significant purposes; see e.g.:
8994 @c   - http://filext.com/file-extension/trs
8995 @c   - http://www.file-extensions.org/search/?searchstring=trs
8996 The @file{.log} file will contain all the output emitted by the test on
8997 its standard output and its standard error.  The @file{.trs} file will
8998 contain, among the other things, the results of the test cases run by
8999 the script.
9000
9001 The parallel test harness will also create a summary log file,
9002 @code{TEST_SUITE_LOG}, which defaults to @file{test-suite.log} and requires
9003 a @file{.log} suffix.  This file depends upon all the @file{.log} and
9004 @file{.trs} files created for the test scripts listed in @code{TESTS}.
9005
9006 @vindex VERBOSE
9007 As with the serial harness above, by default one status line is printed
9008 per completed test, and a short summary after the suite has completed.
9009 However, standard output and standard error of the test are redirected
9010 to a per-test log file, so that parallel execution does not produce
9011 intermingled output.  The output from failed tests is collected in the
9012 @file{test-suite.log} file.  If the variable @samp{VERBOSE} is set, this
9013 file is output after the summary.
9014 @c FIXME: we should be clearer about what we mean exactly here ...
9015 For best results, the tests should be verbose by default now.
9016
9017 @vindex TEST_EXTENSIONS
9018 @vindex TEST_LOGS
9019 Each couple of @file{.log} and @file{.trs} files is created when the
9020 corresponding test has completed.  The set of log files is listed in
9021 the read-only variable @code{TEST_LOGS}, and defaults to @code{TESTS},
9022 with the executable extension if any (@pxref{EXEEXT}), as well as any
9023 suffix listed in @code{TEST_EXTENSIONS} removed, and @file{.log} appended.
9024 Results are undefined if a test file name ends in several concatenated
9025 suffixes.  @code{TEST_EXTENSIONS} defaults to @file{.test}; it can be
9026 overridden by the user, in which case any extension listed in it must be
9027 constituted by a dot, followed by a non-digit alphabetic character,
9028 followed by any number of alphabetic characters.
9029 @c Keep in sync with test-extensions.sh
9030 For example, @samp{.sh}, @samp{.T} and @samp{.t1} are valid extensions,
9031 while @samp{.x-y}, @samp{.6c} and @samp{.t.1} are not.
9032
9033 @vindex _LOG_COMPILE
9034 @vindex _LOG_COMPILER
9035 @vindex _LOG_FLAGS
9036 @vindex LOG_COMPILE
9037 @vindex LOG_COMPILER
9038 @vindex LOG_FLAGS
9039 @vindex @var{ext}_LOG_COMPILE
9040 @vindex @var{ext}_LOG_COMPILER
9041 @vindex @var{ext}_LOG_FLAGS
9042 @vindex AM_@var{ext}_LOG_FLAGS
9043 @vindex AM_LOG_FLAGS
9044 For tests that match an extension @code{.@var{ext}} listed in
9045 @code{TEST_EXTENSIONS}, you can provide a custom ``test runner'' using
9046 the variable @code{@var{ext}_LOG_COMPILER} (note the upper-case
9047 extension) and pass options in @code{AM_@var{ext}_LOG_FLAGS} and allow
9048 the user to pass options in @code{@var{ext}_LOG_FLAGS}.  It will cause
9049 all tests with this extension to be called with this runner.  For all
9050 tests without a registered extension, the variables @code{LOG_COMPILER},
9051 @code{AM_LOG_FLAGS}, and @code{LOG_FLAGS} may be used.  For example,
9052
9053 @c Keep in sync with parallel-tests-log-compiler-example.sh
9054 @example
9055 TESTS = foo.pl bar.py baz
9056 TEST_EXTENSIONS = .pl .py
9057 PL_LOG_COMPILER = $(PERL)
9058 AM_PL_LOG_FLAGS = -w
9059 PY_LOG_COMPILER = $(PYTHON)
9060 AM_PY_LOG_FLAGS = -v
9061 LOG_COMPILER = ./wrapper-script
9062 AM_LOG_FLAGS = -d
9063 @end example
9064
9065 @noindent
9066 will invoke @samp{$(PERL) -w foo.pl}, @samp{$(PYTHON) -v bar.py},
9067 and @samp{./wrapper-script -d baz} to produce @file{foo.log},
9068 @file{bar.log}, and @file{baz.log}, respectively.  The @file{foo.trs},
9069 @file{bar.trs} and @file{baz.trs} files will be automatically produced
9070 as a side-effect.
9071
9072 It's important to note that, differently from what we've seen for the
9073 serial test harness (@pxref{Parallel Test Harness}), the
9074 @code{AM_TESTS_ENVIRONMENT} and @code{TESTS_ENVIRONMENT} variables
9075 @emph{cannot} be use to define a custom test runner; the
9076 @code{LOG_COMPILER} and @code{LOG_FLAGS} (or their extension-specific
9077 counterparts) should be used instead:
9078
9079 @example
9080 ## This is WRONG!
9081 AM_TESTS_ENVIRONMENT = PERL5LIB='$(srcdir)/lib' $(PERL) -Mstrict -w
9082 @end example
9083
9084 @example
9085 ## Do this instead.
9086 AM_TESTS_ENVIRONMENT = PERL5LIB='$(srcdir)/lib'; export PERL5LIB;
9087 LOG_COMPILER = $(PERL)
9088 AM_LOG_FLAGS = -Mstrict -w
9089 @end example
9090
9091 By default, the test suite harness will run all tests, but there are
9092 several ways to limit the set of tests that are run:
9093
9094 @itemize @bullet
9095 @item
9096 You can set the @code{TESTS} variable.  For example, you can use a
9097 command like this to run only a subset of the tests:
9098
9099 @example
9100 env TESTS="foo.test bar.test" make -e check
9101 @end example
9102
9103 Note however that the command above will unconditionally overwrite the
9104 @file{test-suite.log} file, thus clobbering the recorded results
9105 of any previous testsuite run.  This might be undesirable for packages
9106 whose testsuite takes long time to execute.  Luckily, this problem can
9107 easily be avoided by overriding also @code{TEST_SUITE_LOG} at runtime;
9108 for example,
9109
9110 @c Keep in sync with parallel-tests-log-override-2.sh
9111 @example
9112 env TEST_SUITE_LOG=partial.log TESTS="..." make -e check
9113 @end example
9114
9115 will write the result of the partial testsuite runs to the
9116 @file{partial.log}, without touching @file{test-suite.log}.
9117
9118 @item
9119 You can set the @code{TEST_LOGS} variable.  By default, this variable is
9120 computed at @command{make} run time from the value of @code{TESTS} as
9121 described above.  For example, you can use the following:
9122
9123 @example
9124 set x subset*.log; shift
9125 env TEST_LOGS="foo.log $*" make -e check
9126 @end example
9127
9128 The comments made above about @code{TEST_SUITE_LOG} overriding applies
9129 here too.
9130
9131 @item
9132 @vindex RECHECK_LOGS
9133 @cindex lazy test execution
9134 By default, the test harness removes all old per-test @file{.log} and
9135 @file{.trs} files before it starts running tests to regenerate them.  The
9136 variable @code{RECHECK_LOGS} contains the set of @file{.log} (and, by
9137 implication, @file{.trs}) files which are removed.  @code{RECHECK_LOGS}
9138 defaults to @code{TEST_LOGS}, which means all tests need to be rechecked.
9139 By overriding this variable, you can choose which tests need to be
9140 reconsidered.  For example, you can lazily rerun only those tests which
9141 are outdated, i.e., older than their prerequisite test files, by setting
9142 this variable to the empty value:
9143
9144 @example
9145 env RECHECK_LOGS= make -e check
9146 @end example
9147
9148 @item
9149 @trindex recheck
9150 You can ensure that all tests are rerun which have failed or passed
9151 unexpectedly, by running @code{make recheck} in the test directory.
9152 This convenience target will set @code{RECHECK_LOGS} appropriately
9153 before invoking the main test harness.
9154 @end itemize
9155
9156 @noindent
9157 In order to guarantee an ordering between tests even with @code{make
9158 -j@var{N}}, dependencies between the corresponding @file{.log} files
9159 may be specified through usual @command{make} dependencies.  For example,
9160 the following snippet lets the test named @file{foo-execute.test} depend
9161 upon completion of the test @file{foo-compile.test}:
9162
9163 @example
9164 TESTS = foo-compile.test foo-execute.test
9165 foo-execute.log: foo-compile.log
9166 @end example
9167
9168 @noindent
9169 Please note that this ordering ignores the @emph{results} of required
9170 tests, thus the test @file{foo-execute.test} is run even if the test
9171 @file{foo-compile.test} failed or was skipped beforehand.  Further,
9172 please note that specifying such dependencies currently works only for
9173 tests that end in one of the suffixes listed in @code{TEST_EXTENSIONS}.
9174
9175 Tests without such specified dependencies may be run concurrently with
9176 parallel @command{make -j@var{N}}, so be sure they are prepared for
9177 concurrent execution.
9178
9179 @cindex Unit tests
9180 @c Keep in sync with 'parallel-tests-extra-programs.sh'.
9181 The combination of lazy test execution and correct dependencies between
9182 tests and their sources may be exploited for efficient unit testing
9183 during development.  To further speed up the edit-compile-test cycle, it
9184 may even be useful to specify compiled programs in @code{EXTRA_PROGRAMS}
9185 instead of with @code{check_PROGRAMS}, as the former allows intertwined
9186 compilation and test execution (but note that @code{EXTRA_PROGRAMS} are
9187 not cleaned automatically, @pxref{Uniform}).
9188
9189 The variables @code{TESTS} and @code{XFAIL_TESTS} may contain
9190 conditional parts as well as configure substitutions.  In the latter
9191 case, however, certain restrictions apply: substituted test names
9192 must end with a nonempty test suffix like @file{.test}, so that one of
9193 the inference rules generated by @command{automake} can apply.  For
9194 literal test names, @command{automake} can generate per-target rules
9195 to avoid this limitation.
9196
9197 Please note that it is currently not possible to use @code{$(srcdir)/}
9198 or @code{$(top_srcdir)/} in the @code{TESTS} variable.  This technical
9199 limitation is necessary to avoid generating test logs in the source tree
9200 and has the unfortunate consequence that it is not possible to specify
9201 distributed tests that are themselves generated by means of explicit
9202 rules, in a way that is portable to all @command{make} implementations
9203 (@pxref{Make Target Lookup,,, autoconf, The Autoconf Manual}, the
9204 semantics of FreeBSD and OpenBSD @command{make} conflict with this).
9205 In case of doubt you may want to require to use GNU @command{make},
9206 or work around the issue with inference rules to generate the tests.
9207
9208 @node Custom Test Drivers
9209 @section Custom Test Drivers
9210
9211 @menu
9212 * Overview of Custom Test Drivers Support::
9213 * Declaring Custom Test Drivers::
9214 * API for Custom Test Drivers::
9215 @end menu
9216
9217 @node Overview of Custom Test Drivers Support
9218 @subsection Overview of Custom Test Drivers Support
9219
9220 Starting from Automake version 1.12, the parallel test harness allows
9221 the package authors to use third-party custom test drivers, in case the
9222 default ones are inadequate for their purposes, or do not support their
9223 testing protocol of choice.
9224
9225 A custom test driver is expected to properly run the test programs passed
9226 to it (including the command-line arguments passed to those programs, if
9227 any), to analyze their execution and outcome, to create the @file{.log}
9228 and @file{.trs} files associated to these test runs, and to display the test
9229 results on the console. It is responsibility of the author of the test
9230 driver to ensure that it implements all the above steps meaningfully and
9231 correctly; Automake isn't and can't be of any help here.  On the other
9232 hand, the Automake-provided code for testsuite summary generation offers
9233 support for test drivers allowing several test results per test script,
9234 if they take care to register such results properly (@pxref{Log files
9235 generation and test results recording}).
9236
9237 The exact details of how test scripts' results are to be determined and
9238 analyzed is left to the individual drivers.  Some drivers might only
9239 consider the test script exit status (this is done for example by the
9240 default test driver used by the parallel test harness, described
9241 in the previous section).  Other drivers might implement more complex and
9242 advanced test protocols, which might require them to parse and interpreter
9243 the output emitted by the test script they're running (examples of such
9244 protocols are TAP and SubUnit).
9245
9246 It's very important to note that, even when using custom test drivers,
9247 most of the infrastructure described in the previous section about the
9248 parallel harness remains in place; this includes:
9249
9250 @itemize
9251 @item
9252 list of test scripts defined in @code{TESTS}, and overridable at
9253 runtime through the redefinition of @code{TESTS} or @code{TEST_LOGS};
9254 @item
9255 concurrency through the use of @command{make}'s option @option{-j};
9256 @item
9257 per-test @file{.log} and @file{.trs} files, and generation of a summary
9258 @file{.log} file from them;
9259 @item
9260 @code{recheck} target, @code{RECHECK_LOGS} variable, and lazy reruns
9261 of tests;
9262 @item
9263 inter-test dependencies;
9264 @item
9265 support for @code{check_*} variables (@code{check_PROGRAMS},
9266 @code{check_LIBRARIES}, ...);
9267 @item
9268 use of @code{VERBOSE} environment variable to get verbose output on
9269 testsuite failures;
9270 @item
9271 definition and honoring of @code{TESTS_ENVIRONMENT},
9272 @code{AM_TESTS_ENVIRONMENT} and @code{AM_TESTS_FD_REDIRECT}
9273 variables;
9274 @item
9275 definition of generic and extension-specific @code{LOG_COMPILER} and
9276 @code{LOG_FLAGS} variables.
9277 @end itemize
9278
9279 @noindent
9280 On the other hand, the exact semantics of how (and if) testsuite output
9281 colorization, @code{XFAIL_TESTS}, and hard errors are supported and
9282 handled is left to the individual test drivers.
9283
9284 @c TODO: We should really add a working example in the doc/ directory,
9285 @c TODO: and reference if from here.
9286
9287 @node Declaring Custom Test Drivers
9288 @subsection Declaring Custom Test Drivers
9289
9290 @vindex _LOG_DRIVER
9291 @vindex _LOG_DRIVER_FLAGS
9292 @vindex LOG_DRIVER
9293 @vindex LOG_DRIVER_FLAGS
9294 @vindex @var{ext}_LOG_DRIVER
9295 @vindex @var{ext}_LOG_DRIVER_FLAGS
9296 @vindex AM_@var{ext}_LOG_DRIVER_FLAGS
9297 @vindex AM_LOG_DRIVER_FLAGS
9298 Custom testsuite drivers are declared by defining the make variables
9299 @code{LOG_DRIVER} or @code{@var{ext}_LOG_DRIVER} (where @var{ext} must
9300 be declared in @code{TEST_EXTENSIONS}).  They must be defined to
9301 programs or scripts that will be used to drive the execution, logging,
9302 and outcome report of the tests with corresponding extensions (or of
9303 those with no registered extension in the case of @code{LOG_DRIVER}).
9304 Clearly, multiple distinct test drivers can be declared in the same
9305 @file{Makefile.am}.  Note moreover that the @code{LOG_DRIVER} variables
9306 are @emph{not} a substitute for the @code{LOG_COMPILER} variables: the
9307 two sets of variables can, and often do, usefully and legitimately
9308 coexist.
9309
9310 @c TODO: We should really be able to point to a clarifying example here!
9311
9312 The developer-reserved variable @code{AM_LOG_DRIVER_FLAGS} and the
9313 user-reserved variable @code{LOG_DRIVER_FLAGS} can be used to define
9314 flags that will be passed to each invocation of @code{LOG_DRIVER},
9315 with the user-defined flags obviously taking precedence over the
9316 developer-reserved ones.  Similarly, for each extension @var{ext}
9317 declared in @code{TEST_EXTENSIONS}, flags listed in
9318 @code{AM_@var{ext}_LOG_DRIVER_FLAGS} and
9319 @code{@var{ext}_LOG_DRIVER_FLAGS} will be passed to
9320 invocations of @code{@var{ext}_LOG_DRIVER}.
9321
9322 @node API for Custom Test Drivers
9323 @subsection API for Custom Test Drivers
9324
9325 Note that @emph{the APIs described here are still highly experimental},
9326 and will very likely undergo tightenings and likely also extensive changes
9327 in the future, to accommodate for new features or to satisfy additional
9328 portability requirements.
9329
9330 The main characteristic of these APIs is that they are designed to share
9331 as much infrastructure, semantics, and implementation details as possible
9332 with the parallel test harness and its default driver.
9333
9334 @menu
9335 * Command-line arguments for test drivers::
9336 * Log files generation and test results recording::
9337 * Testsuite progress output::
9338 @end menu
9339
9340 @node Command-line arguments for test drivers
9341 @subsubsection Command-line arguments for test drivers
9342
9343 A custom driver can rely on various command-line options and arguments
9344 being passed to it automatically by the Automake-generated test harness.
9345 It is @emph{mandatory} that it understands all of them (even if the exact
9346 interpretation of the associated semantics can legitimately change
9347 between a test driver and another, and even be a no-op in some drivers).
9348
9349 @noindent
9350 Here is the list of options:
9351
9352 @table @option
9353 @item --test-name=@var{NAME}
9354 The name of the test, with VPATH prefix (if any) removed.  This can have a
9355 suffix and a directory component (as in e.g., @file{sub/foo.test}), and is
9356 mostly meant to be used in console reports about testsuite advancements and
9357 results (@pxref{Testsuite progress output}).
9358 @item --log-file=@file{@var{PATH}.log}
9359 The @file{.log} file the test driver must create (@pxref{Basics of
9360 test metadata}).  If it has a directory component (as in e.g.,
9361 @file{sub/foo.log}), the test harness will ensure that such directory
9362 exists @emph{before} the test driver is called.
9363 @item --trs-file=@file{@var{PATH}.trs}
9364 The @file{.trs} file the test driver must create (@pxref{Basics of
9365 test metadata}).  If it has a directory component (as in e.g.,
9366 @file{sub/foo.trs}), the test harness will ensure that such directory
9367 exists @emph{before} the test driver is called.
9368 @item --color-tests=@{yes|no@}
9369 Whether the console output should be colorized or not (@pxref{Simple
9370 tests and color-tests}, to learn when this option gets activated and
9371 when it doesn't).
9372 @item --expect-failure=@{yes|no@}
9373 Whether the tested program is expected to fail.
9374 @item --enable-hard-errors=@{yes|no@}
9375 Whether ``hard errors'' in the tested program should be treated differently
9376 from normal failures or not (the default should be @code{yes}).  The exact
9377 meaning of ``hard error'' is highly dependent from the test protocols or
9378 conventions in use.
9379 @item --
9380 Explicitly terminate the list of options.
9381 @end table
9382
9383 @noindent
9384 The first non-option argument passed to the test driver is the program to
9385 be run, and all the following ones are command-line options and arguments
9386 for this program.
9387
9388 Note that the exact semantics attached to the @option{--color-tests},
9389 @option{--expect-failure} and @option{--enable-hard-errors} options are
9390 left up to the individual test drivers.  Still, having a behaviour
9391 compatible or at least similar to that provided by the default driver
9392 is advised, as that would offer a better consistency and a more pleasant
9393 user experience.
9394
9395 @node Log files generation and test results recording
9396 @subsubsection Log files generation and test results recording
9397
9398 The test driver must correctly generate the files specified by the
9399 @option{--log-file} and @option{--trs-file} option (even when the tested
9400 program fails or crashes).
9401
9402 The @file{.log} file should ideally contain all the output produced by the
9403 tested program, plus optionally other information that might facilitate
9404 debugging or analysis of bug reports.  Apart from that, its format is
9405 basically free.
9406
9407 The @file{.trs} file is used to register some metadata through the use
9408 of custom reStructuredText fields.  This metadata is expected to be
9409 employed in various ways by the parallel test harness; for example, to
9410 count the test results when printing the testsuite summary, or to decide
9411 which tests to re-run upon @command{make reheck}.  Unrecognized metadata
9412 in a @file{.trs} file is currently ignored by the harness, but this might
9413 change in the future. The list of currently recognized metadata follows.
9414
9415 @table @code
9416
9417 @item :test-result:
9418 @cindex Register test result
9419 @cindex Register test case result
9420 @cindex Test result, registering
9421 @cindex Test case result, registering
9422 @cindex @code{:test-result:}
9423 @cindex reStructuredText field, @code{:test-result:}
9424 The test driver must use this field to register the results of @emph{each}
9425 test case run by a test script file.  Several @code{:test-result:} fields
9426 can be present in the same @file{.trs} file; this is done in order to
9427 support test protocols that allow a single test script to run more test
9428 cases.
9429
9430 @c Keep this in sync with lib/am/check-am:$(TEST_SUITE_LOG).
9431 The only recognized test results are currently @code{PASS}, @code{XFAIL},
9432 @code{SKIP}, @code{FAIL}, @code{XPASS} and @code{ERROR}.  These results,
9433 when declared with @code{:test-result:}, can be optionally followed by
9434 text holding the name and/or a brief description of the corresponding
9435 test; the harness will ignore such extra text when generating
9436 @file{test-suite.log} and preparing the testsuite summary.
9437
9438 @c Keep in sync with 'test-metadata-recheck.sh'.
9439 @item @code{:recheck:}
9440 @cindex :recheck:
9441 @cindex reStructuredText field, @code{:recheck:}
9442 If this field is present and defined to @code{no}, then the corresponding
9443 test script will @emph{not} be run upon a @command{make recheck}.  What
9444 happens when two or more @code{:recheck:} fields are present in the same
9445 @file{.trs} file is undefined behaviour.
9446
9447 @c Keep in sync with 'test-metadata-global-log.sh'.
9448 @item @code{:copy-in-global-log:}
9449 @cindex :copy-in-global-log:
9450 @cindex reStructuredText field, @code{:copy-in-global-log:}
9451 If this field is present and defined to @code{no}, then the content
9452 of the @file{.log} file will @emph{not} be copied into the global
9453 @file{test-suite.log}.  We allow to forsake such copying because, while
9454 it can be useful in debugging and analysis of bug report, it can also be
9455 just a waste of space in normal situations, e.g., when a test script is
9456 successful.  What happens when two or more @code{:copy-in-global-log:}
9457 fields are present in the same @file{.trs} file is undefined behaviour.
9458
9459 @c Keep in sync with 'test-metadata-global-result.sh'.
9460 @item @code{:test-global-result:}
9461 @cindex :test-global-result:
9462 @cindex reStructuredText field, @code{:test-global-result:}
9463 This is used to declare the "global result" of the script.  Currently,
9464 the value of this field is needed only to be reported (more or less
9465 verbatim) in the generated global log file @code{$(TEST_SUITE_LOG)},
9466 so it's quite free-form.  For example, a test script which run 10 test
9467 cases, 6 of which pass and 4 of which are skipped, could reasonably have
9468 a @code{PASS/SKIP} value for this field, while a test script which run
9469 19 successful tests and one failed test could have an @code{ALMOST
9470 PASSED} value.  What happens when two or more @code{:test-global-result:}
9471 fields are present in the same @file{.trs} file is undefined behaviour.
9472 @end table
9473
9474 @noindent
9475 Let's see a small example.  Assume a @file{.trs} file contains the
9476 following lines:
9477
9478 @example
9479 :test-result: PASS server starts
9480 :global-log-copy: no
9481 :test-result: PASS HTTP/1.1 request
9482 :test-result: FAIL HTTP/1.0 request
9483 :recheck: yes
9484 :test-result: SKIP HTTPS request (TLS library wasn't available)
9485 :test-result: PASS server stops
9486 @end example
9487
9488 @noindent
9489 Then the corresponding test script will be re-run by @command{make check},
9490 will contribute with @emph{five} test results to the testsuite summary
9491 (three of these tests being successful, one failed, and one skipped), and
9492 the content of the corresponding @file{.log} file will @emph{not} be
9493 copied in the global log file @file{test-suite.log}.
9494
9495 @node Testsuite progress output
9496 @subsubsection Testsuite progress output
9497
9498 A custom test driver also has the task of displaying, on the standard
9499 output, the test results as soon as they become available.  Depending on
9500 the protocol in use, it can also display the reasons for failures and
9501 skips, and, more generally, any useful diagnostic output (but remember
9502 that each line on the screen is precious, so that cluttering the screen
9503 with overly verbose information is bad idea).  The exact format of this
9504 progress output is left up to the test driver; in fact, a custom test
9505 driver might @emph{theoretically} even decide not to do any such report,
9506 leaving it all to the testsuite summary (that would be a very lousy idea,
9507 of course, and serves only to illustrate the flexibility that is
9508 granted here).
9509
9510 Remember that consistency is good; so, if possible, try to be consistent
9511 with the output of the built-in Automake test drivers, providing a similar
9512 ``look & feel''.  In particular, the testsuite progress output should be
9513 colorized when the @option{--color-tests} is passed to the driver.  On the
9514 other end, if you are using a known and widespread test protocol with
9515 well-established implementations, being consistent with those
9516 implementations' output might be a good idea too.
9517
9518 @c TODO: Give an example, maybe inspired to py.test-style output.
9519 @c TODO: That is a good idea because it shows a test driver that allows
9520 @c TODO: for different levels of verbosity in the progress output (could
9521 @c TODO: be implemented either using a driver cmdline flag, or an
9522 @c TODO: environment variable, or both).
9523
9524 @node Using the TAP test protocol
9525 @section Using the TAP test protocol
9526
9527 @menu
9528 * Introduction to TAP::
9529 * Use TAP with the Automake test harness::
9530 * Incompatibilities with other TAP parsers and drivers::
9531 * Links and external resources on TAP::
9532 @end menu
9533
9534 @node Introduction to TAP
9535 @subsection Introduction to TAP
9536
9537 TAP, the Test Anything Protocol, is a simple text-based interface between
9538 testing modules or programs and a test harness.  The tests (also called
9539 ``TAP producers'' in this context) write test results in a simple format
9540 on standard output; a test harness (also called ``TAP consumer'') will
9541 parse and interpret these results, and properly present them to the user,
9542 and/or register them for later analysis.  The exact details of how this
9543 is accomplished can vary among different test harnesses.  The Automake
9544 harness will present the results on the console in the usual
9545 fashion (@pxref{Testsuite progress on console}), and will use the
9546 @file{.trs} files (@pxref{Basics of test metadata}) to store the test
9547 results and related metadata.  Apart from that, it will try to remain
9548 as much compatible as possible with pre-existing and widespread utilities,
9549 such as the @uref{http://search.cpan.org/~andya/Test-Harness/bin/prove,
9550 @command{prove} utility}, at least for the simpler usages.
9551
9552 TAP started its life as part of the test harness for Perl, but today
9553 it has been (mostly) standardized, and has various independent
9554 implementations in different languages; among them, C, C++, Perl,
9555 Python, PHP, and Java.  For a semi-official specification of the
9556 TAP protocol, please refer to the documentation of
9557 @uref{http://search.cpan.org/~petdance/Test-Harness/lib/Test/Harness/TAP.pod,
9558       @samp{Test::Harness::TAP}}.
9559
9560 The most relevant real-world usages of TAP are obviously in the testsuites
9561 of @command{perl} and of many perl modules.  Still, also other important
9562 third-party packages, such as @uref{http://git-scm.com/, @command{git}},
9563 use TAP in their testsuite.
9564
9565 @node Use TAP with the Automake test harness
9566 @subsection Use TAP with the Automake test harness
9567
9568 Currently, the TAP driver that comes with Automake requires some by-hand
9569 steps on the developer's part (this situation should hopefully be improved
9570 in future Automake versions).  You'll have to grab the @file{tap-driver.sh}
9571 script from the Automake distribution by hand, copy it in your source tree,
9572 add a call to @code{AC_PROG_AWK} in @file{configure.ac} to search for a
9573 proper awk program, and use the Automake support for third-party test
9574 drivers to instruct the harness to use the @file{tap-driver.sh} script
9575 and that awk program to run your TAP-producing tests.  See the example
9576 below for clarification.
9577
9578 Apart from the options common to all the Automake test drivers
9579 (@pxref{Command-line arguments for test drivers}), the @file{tap-driver.sh}
9580 supports the following options, whose names are chosen for enhanced
9581 compatibility with the @command{prove} utility.
9582
9583 @table @option
9584 @c Keep in sync with 'tap-exit.sh' and 'tap-signal.tap'.
9585 @item --ignore-exit
9586 Causes the test driver to ignore the exit status of the test scripts;
9587 by default, the driver will report an error if the script exits with a
9588 non-zero status.  This option has effect also on non-zero exit statuses
9589 due to termination by a signal.
9590 @item --comments
9591 Instruct the test driver to display TAP diagnostic (i.e., lines beginning
9592 with the @samp{#} character) in the testsuite progress output too; by
9593 default, TAP diagnostic is only copied to the @file{.log} file.
9594 @item --no-comments
9595 Revert the effects of @option{--comments}.
9596 @item --merge
9597 Instruct the test driver to merge the test scripts' standard error into
9598 their standard output.  This is necessary if you want to ensure that
9599 diagnostics from the test scripts are displayed in the correct order
9600 relative to test results; this can be of great help in debugging
9601 (especially if your test scripts are shell scripts run with shell
9602 tracing active).  As a downside, this option might cause the test
9603 harness to get confused if anything that appears on standard error
9604 looks like a test result.
9605 @item --no-merge
9606 Revert the effects of @option{--merge}.
9607 @item --diagnostic-string=@var{STRING}
9608 Change the string that introduces TAP diagnostic from the default value
9609 of ``@code{#}'' to @code{@var{STRING}}.  This can be useful if your
9610 TAP-based test scripts produce verbose output on which they have limited
9611 control (because, say, the output comes from other tools invoked in the
9612 scripts), and it might contain text that gets spuriously interpreted as
9613 TAP diagnostic: such an issue can be solved by redefining the string that
9614 activates TAP diagnostic to a value you know won't appear by chance in
9615 the tests' output.  Note however that this feature is non-standard, as
9616 the ``official'' TAP protocol does not allow for such a customization; so
9617 don't use it if you can avoid it.
9618 @end table
9619
9620 @noindent
9621 Here is an example of how the TAP driver can be set up and used.
9622
9623 @c Keep in sync with tap-doc2.sh
9624 @example
9625 % @kbd{cat configure.ac}
9626 AC_INIT([GNU Try Tap], [1.0], [bug-automake@@gnu.org])
9627 AC_CONFIG_AUX_DIR([build-aux])
9628 AM_INIT_AUTOMAKE([foreign -Wall -Werror])
9629 AC_CONFIG_FILES([Makefile])
9630 AC_REQUIRE_AUX_FILE([tap-driver.sh])
9631 AC_PROG_AWK
9632 AC_OUTPUT
9633
9634 % @kbd{cat Makefile.am}
9635 TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
9636                   $(top_srcdir)/build-aux/tap-driver.sh
9637 TESTS = foo.test bar.test baz.test
9638 EXTRA_DIST = $(TESTS)
9639
9640 % @kbd{cat foo.test}
9641 #!/bin/sh
9642 echo 1..4 # Number of tests to be executed.
9643 echo 'ok 1 - Swallows fly'
9644 echo 'not ok 2 - Caterpillars fly # TODO metamorphosis in progress'
9645 echo 'ok 3 - Pigs fly # SKIP not enough acid'
9646 echo '# I just love word plays ...'
9647 echo 'ok 4 - Flies fly too :-)'
9648
9649 % @kbd{cat bar.test}
9650 #!/bin/sh
9651 echo 1..3
9652 echo 'not ok 1 - Bummer, this test has failed.'
9653 echo 'ok 2 - This passed though.'
9654 echo 'Bail out! Ennui kicking in, sorry...'
9655 echo 'ok 3 - This will not be seen.'
9656
9657 % @kbd{cat baz.test}
9658 #!/bin/sh
9659 echo 1..1
9660 echo ok 1
9661 # Exit with error, even if all the tests have been successful.
9662 exit 7
9663
9664 % @kbd{cp @var{PREFIX}/share/automake-@var{APIVERSION}/tap-driver.pl .}
9665 % @kbd{autoreconf -vi && ./configure && make check}
9666 ...
9667 PASS: foo.test 1 - Swallows fly
9668 XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
9669 SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
9670 PASS: foo.test 4 - Flies fly too :-)
9671 FAIL: bar.test 1 - Bummer, this test has failed.
9672 PASS: bar.test 2 - This passed though.
9673 ERROR: bar.test - Bail out! Ennui kicking in, sorry...
9674 PASS: baz.test 1
9675 ERROR: baz.test - exited with status 7
9676 ...
9677 Please report to bug-automake@@gnu.org
9678 ...
9679 % @kbd{echo exit status: $?}
9680 exit status: 1
9681
9682 @c Keep the "skewed" indentation below, it produces pretty PDF output.
9683 % @kbd{env TEST_LOG_DRIVER_FLAGS='--comments --ignore-exit' \
9684       TESTS='foo.test baz.test' make -e check}
9685 ...
9686 PASS: foo.test 1 - Swallows fly
9687 XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
9688 SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
9689 # foo.test: I just love word plays...
9690 PASS: foo.test 4 - Flies fly too :-)
9691 PASS: baz.test 1
9692 ...
9693 % @kbd{echo exit status: $?}
9694 exit status: 0
9695 @end example
9696
9697 @node Incompatibilities with other TAP parsers and drivers
9698 @subsection Incompatibilities with other TAP parsers and drivers
9699
9700 For implementation or historical reasons, the TAP driver and harness as
9701 implemented by Automake have some minors incompatibilities with the
9702 mainstream versions, which you should be aware of.
9703
9704 @itemize @bullet
9705 @item
9706 A @code{Bail out!} directive doesn't stop the whole testsuite, but only
9707 the test script it occurs in.  This doesn't follow TAP specifications,
9708 but on the other hand it maximizes compatibility (and code sharing) with
9709 the ``hard error'' concept of the default testsuite driver.
9710 @item
9711 The @code{version} and @code{pragma} directives are not supported.
9712 @item
9713 The @option{--diagnostic-string} option of our driver allows to modify
9714 the string that introduces TAP diagnostic from the default value
9715 of ``@code{#}''.  The standard TAP protocol has currently no way to
9716 allow this, so if you use it your diagnostic will be lost to more
9717 compliant tools like @command{prove} and @code{Test::Harness}
9718 @item
9719 And there are probably some other small and yet undiscovered
9720 incompatibilities, especially in corner cases or with rare usages.
9721 @end itemize
9722
9723 @node Links and external resources on TAP
9724 @subsection Links and external resources on TAP
9725
9726 @noindent
9727 Here are some links to more extensive official or third-party
9728 documentation and resources about the TAP protocol and related
9729 tools and libraries.
9730 @itemize @bullet
9731 @item
9732 @uref{http://search.cpan.org/~petdance/Test-Harness/lib/Test/Harness/TAP.pod,
9733       @samp{Test::Harness::TAP}},
9734 the (mostly) official documentation about the TAP format and protocol.
9735 @item
9736 @uref{http://search.cpan.org/~andya/Test-Harness/bin/prove,
9737       @command{prove}},
9738 the most famous command-line TAP test driver, included in the distribution
9739 of @command{perl} and
9740 @uref{http://search.cpan.org/~andya/Test-Harness/lib/Test/Harness.pm,
9741       @samp{Test::Harness}}.
9742 @item
9743 The @uref{http://testanything.org/wiki/index.php/Main_Page,TAP wiki}.
9744 @item
9745 A ``gentle introduction'' to testing for perl coders:
9746 @uref{http://search.cpan.org/dist/Test-Simple/lib/Test/Tutorial.pod,
9747       @samp{Test::Tutorial}}.
9748 @item
9749 @uref{http://search.cpan.org/~mschwern/Test-Simple/lib/Test/Simple.pm,
9750       @samp{Test::Simple}}
9751 and
9752 @uref{http://search.cpan.org/~mschwern/Test-Simple/lib/Test/More.pm,
9753       @samp{Test::More}},
9754 the standard perl testing libraries, which are based on TAP.
9755 @item
9756 @uref{http://www.eyrie.org/~eagle/software/c-tap-harness/,C TAP Harness},
9757 a C-based project implementing both a TAP producer and a TAP consumer.
9758 @item
9759 @uref{http://www.tap4j.org/,tap4j},
9760 a Java-based project implementing both a TAP producer and a TAP consumer.
9761 @end itemize
9762
9763 @node DejaGnu Tests
9764 @section DejaGnu Tests
9765
9766 If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @command{dejagnu}} appears in
9767 @code{AUTOMAKE_OPTIONS}, then a @command{dejagnu}-based test suite is
9768 assumed.  The variable @code{DEJATOOL} is a list of names that are
9769 passed, one at a time, as the @option{--tool} argument to
9770 @command{runtest} invocations; it defaults to the name of the package.
9771
9772 The variable @code{RUNTESTDEFAULTFLAGS} holds the @option{--tool} and
9773 @option{--srcdir} flags that are passed to dejagnu by default; this can be
9774 overridden if necessary.
9775 @vindex RUNTESTDEFAULTFLAGS
9776
9777 The variables @code{EXPECT} and @code{RUNTEST} can
9778 also be overridden to provide project-specific values.  For instance,
9779 you will need to do this if you are testing a compiler toolchain,
9780 because the default values do not take into account host and target
9781 names.
9782 @opindex dejagnu
9783 @vindex DEJATOOL
9784 @vindex EXPECT
9785 @vindex RUNTEST
9786
9787 The contents of the variable @code{RUNTESTFLAGS} are passed to the
9788 @code{runtest} invocation.  This is considered a ``user variable''
9789 (@pxref{User Variables}).  If you need to set @command{runtest} flags in
9790 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
9791 @vindex RUNTESTFLAGS
9792 @vindex AM_RUNTESTFLAGS
9793
9794 @cindex @file{site.exp}
9795 Automake will generate rules to create a local @file{site.exp} file,
9796 defining various variables detected by @command{configure}.  This file
9797 is automatically read by DejaGnu.  It is OK for the user of a package
9798 to edit this file in order to tune the test suite.  However this is
9799 not the place where the test suite author should define new variables:
9800 this should be done elsewhere in the real test suite code.
9801 Especially, @file{site.exp} should not be distributed.
9802
9803 Still, if the package author has legitimate reasons to extend
9804 @file{site.exp} at @command{make} time, he can do so by defining
9805 the variable @code{EXTRA_DEJAGNU_SITE_CONFIG}; the files listed
9806 there will be considered @file{site.exp} prerequisites, and their
9807 content will be appended to it (in the same order in which they
9808 appear in @code{EXTRA_DEJAGNU_SITE_CONFIG}).  Note that files are
9809 @emph{not} distributed by default.
9810
9811 For more information regarding DejaGnu test suites, see @ref{Top, , ,
9812 dejagnu, The DejaGnu Manual}.
9813
9814 @node Install Tests
9815 @section Install Tests
9816
9817 The @code{installcheck} target is available to the user as a way to
9818 run any tests after the package has been installed.  You can add tests
9819 to this by writing an @code{installcheck-local} rule.
9820
9821
9822 @node Rebuilding
9823 @chapter Rebuilding Makefiles
9824 @cindex rebuild rules
9825
9826 Automake generates rules to automatically rebuild @file{Makefile}s,
9827 @file{configure}, and other derived files like @file{Makefile.in}.
9828
9829 @acindex AM_MAINTAINER_MODE
9830 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.ac}, then
9831 these automatic rebuilding rules are only enabled in maintainer mode.
9832
9833 @vindex CONFIG_STATUS_DEPENDENCIES
9834 @vindex CONFIGURE_DEPENDENCIES
9835 @cindex @file{version.sh}, example
9836 @cindex @file{version.m4}, example
9837
9838 Sometimes it is convenient to supplement the rebuild rules for
9839 @file{configure} or @file{config.status} with additional dependencies.
9840 The variables @code{CONFIGURE_DEPENDENCIES} and
9841 @code{CONFIG_STATUS_DEPENDENCIES} can be used to list these extra
9842 dependencies.  These variables should be defined in all
9843 @file{Makefile}s of the tree (because these two rebuild rules are
9844 output in all them), so it is safer and easier to @code{AC_SUBST} them
9845 from @file{configure.ac}.  For instance, the following statement will
9846 cause @file{configure} to be rerun each time @file{version.sh} is
9847 changed.
9848
9849 @example
9850 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh'])
9851 @end example
9852
9853 @noindent
9854 Note the @samp{$(top_srcdir)/} in the file name.  Since this variable
9855 is to be used in all @file{Makefile}s, its value must be sensible at
9856 any level in the build hierarchy.
9857
9858 Beware not to mistake @code{CONFIGURE_DEPENDENCIES} for
9859 @code{CONFIG_STATUS_DEPENDENCIES}.
9860
9861 @code{CONFIGURE_DEPENDENCIES} adds dependencies to the
9862 @file{configure} rule, whose effect is to run @command{autoconf}.  This
9863 variable should be seldom used, because @command{automake} already tracks
9864 @code{m4_include}d files.  However it can be useful when playing
9865 tricky games with @code{m4_esyscmd} or similar non-recommendable
9866 macros with side effects.
9867
9868 @code{CONFIG_STATUS_DEPENDENCIES} adds dependencies to the
9869 @file{config.status} rule, whose effect is to run @file{configure}.
9870 This variable should therefore carry any non-standard source that may
9871 be read as a side effect of running @command{configure}, like @file{version.sh}
9872 in the example above.
9873
9874 Speaking of @file{version.sh} scripts, we recommend against them
9875 today.  We recommend that @file{version.sh} be replaced by an M4 file
9876 that is included by @file{configure.ac}:
9877
9878 @example
9879 m4_include([version.m4])
9880 AC_INIT([name], VERSION_NUMBER)
9881 AM_INIT_AUTOMAKE
9882 @dots{}
9883 @end example
9884
9885 @noindent
9886 Here @file{version.m4} could contain something like
9887 @samp{m4_define([VERSION_NUMBER], [1.2])}.  The advantage of this
9888 second form is that @command{automake} will take care of the
9889 dependencies when defining the rebuild rule, and will also distribute
9890 the file automatically.
9891
9892
9893 @node Options
9894 @chapter Changing Automake's Behavior
9895
9896 @menu
9897 * Options generalities::        Semantics of Automake option
9898 * List of Automake options::    A comprehensive list of Automake options
9899 @end menu
9900
9901 @node Options generalities
9902 @section Options generalities
9903
9904 Various features of Automake can be controlled by options.  Except where
9905 noted otherwise, options can be specified in one of several ways.  Most
9906 options can be applied on a per-@file{Makefile} basis when listed in a
9907 special @file{Makefile} variable named @code{AUTOMAKE_OPTIONS}.  Some
9908 of these options only make sense when specified in the toplevel
9909 @file{Makefile.am} file.  Options are applied globally to all processed
9910 @file{Makefile} files when listed in the first argument of
9911 @code{AM_INIT_AUTOMAKE} in @file{configure.ac}, and some options which
9912 require changes to the @command{configure} script can only be specified
9913 there.  These are annotated below.
9914
9915 As a general rule, options specified in @code{AUTOMAKE_OPTIONS} take
9916 precedence over those specified in @code{AM_INIT_AUTOMAKE}, which in
9917 turn take precedence over those specified on the command line.
9918
9919 Also, some care must be taken about the interactions among strictness
9920 level and warning categories.  As a general rule, strictness-implied
9921 warnings are overridden by those specified by explicit options.  For
9922 example, even if @samp{portability} warnings are disabled by default
9923 in @option{foreign} strictness, an usage like this will end up enabling
9924 them:
9925
9926 @example
9927 AUTOMAKE_OPTIONS = -Wportability foreign
9928 @end example
9929
9930 However, a strictness level specified in a higher-priority context
9931 will override all the explicit warnings specified in a lower-priority
9932 context.  For example, if @file{configure.ac} contains:
9933
9934 @example
9935 AM_INIT_AUTOMAKE([-Wportability])
9936 @end example
9937
9938 @noindent
9939 and @file{Makefile.am} contains:
9940
9941 @example
9942 AUTOMAKE_OPTIONS = foreign
9943 @end example
9944
9945 @noindent
9946 then @samp{portability} warnings will be @emph{disabled} in
9947 @file{Makefile.am}.
9948
9949 @node List of Automake options
9950 @section List of Automake options
9951
9952 @vindex AUTOMAKE_OPTIONS
9953
9954 @table @asis
9955 @item @option{gnits}
9956 @itemx @option{gnu}
9957 @itemx @option{foreign}
9958 @cindex Option, @option{gnits}
9959 @cindex Option, @option{gnu}
9960 @cindex Option, @option{foreign}
9961 @opindex gnits
9962 @opindex gnu
9963 @opindex foreign
9964
9965 Set the strictness as appropriate.  The @option{gnits} option also
9966 implies options @option{readme-alpha} and @option{check-news}.
9967
9968 @item @option{check-news}
9969 @cindex Option, @option{check-news}
9970 @opindex check-news
9971 Cause @samp{make dist} to fail unless the current version number appears
9972 in the first few lines of the @file{NEWS} file.
9973
9974 @item @option{dejagnu}
9975 @cindex Option, @option{dejagnu}
9976 @opindex dejagnu
9977 Cause @command{dejagnu}-specific rules to be generated.  @xref{DejaGnu Tests}.
9978
9979 @item @option{dist-bzip2}
9980 @cindex Option, @option{dist-bzip2}
9981 @opindex dist-bzip2
9982 Hook @code{dist-bzip2} to @code{dist}.
9983 @trindex dist-bzip2
9984
9985 @item @option{dist-lzip}
9986 @cindex Option, @option{dist-lzip}
9987 @opindex dist-lzip
9988 Hook @code{dist-lzip} to @code{dist}.
9989 @trindex dist-lzip
9990
9991 @item @option{dist-shar}
9992 @cindex Option, @option{dist-shar}
9993 @opindex dist-shar
9994 Hook @code{dist-shar} to @code{dist}.
9995 @trindex dist-shar
9996
9997 @item @option{dist-zip}
9998 @cindex Option, @option{dist-zip}
9999 @opindex dist-zip
10000 Hook @code{dist-zip} to @code{dist}.
10001 @trindex dist-zip
10002
10003 @item @option{dist-tarZ}
10004 @cindex Option, @option{dist-tarZ}
10005 @opindex dist-tarZ
10006 Hook @code{dist-tarZ} to @code{dist}.
10007 @trindex dist-tarZ
10008
10009 @item @option{filename-length-max=99}
10010 @cindex Option, @option{filename-length-max=99}
10011 @opindex filename-length-max=99
10012 Abort if file names longer than 99 characters are found during
10013 @samp{make dist}.  Such long file names are generally considered not to
10014 be portable in tarballs.  See the @option{tar-v7} and @option{tar-ustar}
10015 options below.  This option should be used in the top-level
10016 @file{Makefile.am} or as an argument of @code{AM_INIT_AUTOMAKE} in
10017 @file{configure.ac}, it will be ignored otherwise.  It will also be
10018 ignored in sub-packages of nested packages (@pxref{Subpackages}).
10019
10020 @item @option{no-define}
10021 @cindex Option, @option{no-define}
10022 @opindex no-define
10023 This option is meaningful only when passed as an argument to
10024 @code{AM_INIT_AUTOMAKE}.  It will prevent the @code{PACKAGE} and
10025 @code{VERSION} variables from being @code{AC_DEFINE}d.
10026
10027 @item @option{no-dependencies}
10028 @cindex Option, @option{no-dependencies}
10029 @opindex no-dependencies
10030 This is similar to using @option{--ignore-deps} on the command line,
10031 but is useful for those situations where you don't have the necessary
10032 bits to make automatic dependency tracking work
10033 (@pxref{Dependencies}).  In this case the effect is to effectively
10034 disable automatic dependency tracking.
10035
10036 @item @option{no-dist}
10037 @cindex Option, @option{no-dist}
10038 @opindex no-dist
10039 Don't emit any code related to @code{dist} target.  This is useful
10040 when a package has its own method for making distributions.
10041
10042 @item @option{no-dist-gzip}
10043 @cindex Option, @option{no-dist-gzip}
10044 @opindex no-dist-gzip
10045 Do not hook @code{dist-gzip} to @code{dist}.
10046 @trindex no-dist-gzip
10047
10048 @item @option{no-exeext}
10049 @cindex Option, @option{no-exeext}
10050 @opindex no-exeext
10051 If your @file{Makefile.am} defines a rule for target @code{foo}, it
10052 will override a rule for a target named @samp{foo$(EXEEXT)}.  This is
10053 necessary when @code{EXEEXT} is found to be empty.  However, by
10054 default @command{automake} will generate an error for this use.  The
10055 @option{no-exeext} option will disable this error.  This is intended for
10056 use only where it is known in advance that the package will not be
10057 ported to Windows, or any other operating system using extensions on
10058 executables.
10059
10060 @item @option{no-installinfo}
10061 @cindex Option, @option{no-installinfo}
10062 @opindex no-installinfo
10063 The generated @file{Makefile.in} will not cause info pages to be built
10064 or installed by default.  However, @code{info} and @code{install-info}
10065 targets will still be available.  This option is disallowed at
10066 @option{gnu} strictness and above.
10067 @trindex info
10068 @trindex install-info
10069
10070 @item @option{no-installman}
10071 @cindex Option, @option{no-installman}
10072 @opindex no-installman
10073 The generated @file{Makefile.in} will not cause man pages to be
10074 installed by default.  However, an @code{install-man} target will still
10075 be available for optional installation.  This option is disallowed at
10076 @option{gnu} strictness and above.
10077 @trindex install-man
10078
10079 @item @option{nostdinc}
10080 @cindex Option, @option{nostdinc}
10081 @opindex nostdinc
10082 This option can be used to disable the standard @option{-I} options that
10083 are ordinarily automatically provided by Automake.
10084
10085 @item @option{no-texinfo.tex}
10086 @cindex Option, @option{no-texinfo.tex}
10087 @opindex no-texinfo.tex
10088 Don't require @file{texinfo.tex}, even if there are texinfo files in
10089 this directory.
10090
10091 @item @option{serial-tests}
10092 @cindex Option, @option{serial-tests}
10093 @opindex serial-tests
10094 Enable the older serial test suite harness for @code{TESTS} (@pxref{Serial
10095 Test Harness}, for more information).
10096
10097 @item @option{parallel-tests}
10098 @cindex Option, @option{parallel-tests}
10099 @opindex parallel-tests
10100 Enable test suite harness for @code{TESTS} that can run tests in parallel
10101 (@pxref{Parallel Test Harness}, for more information).  This option is
10102 only kept for backward-compatibility, since the parallel test harness is
10103 the default now.
10104
10105 @item @option{readme-alpha}
10106 @cindex Option, @option{readme-alpha}
10107 @opindex readme-alpha
10108 If this release is an alpha release, and the file @file{README-alpha}
10109 exists, then it will be added to the distribution.  If this option is
10110 given, version numbers are expected to follow one of two forms.  The
10111 first form is @samp{@var{major}.@var{minor}.@var{alpha}}, where each
10112 element is a number; the final period and number should be left off for
10113 non-alpha releases.  The second form is
10114 @samp{@var{major}.@var{minor}@var{alpha}}, where @var{alpha} is a
10115 letter; it should be omitted for non-alpha releases.
10116
10117 @item @option{std-options}
10118 @cindex Options, @option{std-options}
10119 @cindex @samp{make installcheck}, testing @option{--help} and @option{--version}
10120 @cindex @option{--help} check
10121 @cindex @option{--version} check
10122 @opindex std-options
10123
10124 Make the @code{installcheck} rule check that installed scripts and
10125 programs support the @option{--help} and @option{--version} options.
10126 This also provides a basic check that the program's
10127 run-time dependencies are satisfied after installation.
10128
10129 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
10130 In a few situations, programs (or scripts) have to be exempted from this
10131 test.  For instance, @command{false} (from GNU coreutils) is never
10132 successful, even for @option{--help} or @option{--version}.  You can list
10133 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
10134 Programs (not scripts) listed in this variable should be suffixed by
10135 @samp{$(EXEEXT)} for the sake of Windows or OS/2.  For instance, suppose we
10136 build @file{false} as a program but @file{true.sh} as a script, and that
10137 neither of them support @option{--help} or @option{--version}:
10138
10139 @example
10140 AUTOMAKE_OPTIONS = std-options
10141 bin_PROGRAMS = false ...
10142 bin_SCRIPTS = true.sh ...
10143 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
10144 @end example
10145
10146 @item @option{subdir-objects}
10147 @cindex Options, @option{subdir-objects}
10148 @opindex subdir-objects
10149 If this option is specified, then objects are placed into the
10150 subdirectory of the build directory corresponding to the subdirectory of
10151 the source file.  For instance, if the source file is
10152 @file{subdir/file.cxx}, then the output file would be
10153 @file{subdir/file.o}.
10154
10155 In order to use this option with C sources, you should add
10156 @code{AM_PROG_CC_C_O} to @file{configure.ac}.
10157
10158 @anchor{tar-formats}
10159 @item @option{tar-v7}
10160 @itemx @option{tar-ustar}
10161 @itemx @option{tar-pax}
10162 @cindex Option, @option{tar-v7}
10163 @cindex Option, @option{tar-ustar}
10164 @cindex Option, @option{tar-pax}
10165 @cindex @command{tar} formats
10166 @cindex v7 @command{tar} format
10167 @cindex ustar format
10168 @cindex pax format
10169 @opindex tar-v7
10170 @opindex tar-ustar
10171 @opindex tar-pax
10172
10173 These three mutually exclusive options select the tar format to use
10174 when generating tarballs with @samp{make dist}.  (The tar file created
10175 is then compressed according to the set of @option{no-dist-gzip},
10176 @option{dist-bzip2}, @option{dist-lzip}, @option{dist-xz} and
10177 @option{dist-tarZ} options in use.)
10178
10179 These options must be passed as arguments to @code{AM_INIT_AUTOMAKE}
10180 (@pxref{Macros}) because they can require additional configure checks.
10181 Automake will complain if it sees such options in an
10182 @code{AUTOMAKE_OPTIONS} variable.
10183
10184 @option{tar-v7} selects the old V7 tar format.  This is the historical
10185 default.  This antiquated format is understood by all tar
10186 implementations and supports file names with up to 99 characters.  When
10187 given longer file names some tar implementations will diagnose the
10188 problem while other will generate broken tarballs or use non-portable
10189 extensions.  Furthermore, the V7 format cannot store empty
10190 directories.  When using this format, consider using the
10191 @option{filename-length-max=99} option to catch file names too long.
10192
10193 @option{tar-ustar} selects the ustar format defined by POSIX
10194 1003.1-1988.  This format is believed to be old enough to be portable.
10195 It fully supports empty directories.  It can store file names with up
10196 to 256 characters, provided that the file name can be split at
10197 directory separator in two parts, first of them being at most 155
10198 bytes long.  So, in most cases the maximum file name length will be
10199 shorter than 256 characters.  However you may run against broken tar
10200 implementations that incorrectly handle file names longer than 99
10201 characters (please report them to @email{@value{PACKAGE_BUGREPORT}} so we
10202 can document this accurately).
10203
10204 @option{tar-pax} selects the new pax interchange format defined by POSIX
10205 1003.1-2001.  It does not limit the length of file names.  However,
10206 this format is very young and should probably be restricted to
10207 packages that target only very modern platforms.  There are moves to
10208 change the pax format in an upward-compatible way, so this option may
10209 refer to a more recent version in the future.
10210
10211 @xref{Formats, , Controlling the Archive Format, tar, GNU Tar}, for
10212 further discussion about tar formats.
10213
10214 @command{configure} knows several ways to construct these formats.  It
10215 will not abort if it cannot find a tool up to the task (so that the
10216 package can still be built), but @samp{make dist} will fail.
10217
10218 @item @var{version}
10219 @cindex Option, @var{version}
10220 A version number (e.g., @samp{0.30}) can be specified.  If Automake is not
10221 newer than the version specified, creation of the @file{Makefile.in}
10222 will be suppressed.
10223
10224 @item @option{-W@var{category}} or @option{--warnings=@var{category}}
10225 @cindex Option, warnings
10226 @cindex Option, @option{-W@var{category}}
10227 @cindex Option, @option{--warnings=@var{category}}
10228 These options behave exactly like their command-line counterpart
10229 (@pxref{automake Invocation}).  This allows you to enable or disable some
10230 warning categories on a per-file basis.  You can also setup some warnings
10231 for your entire project; for instance, try @samp{AM_INIT_AUTOMAKE([-Wall])}
10232 in your @file{configure.ac}.
10233
10234 @end table
10235
10236 Unrecognized options are diagnosed by @command{automake}.
10237
10238 If you want an option to apply to all the files in the tree, you can use
10239 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.ac}.
10240 @xref{Macros}.
10241
10242
10243 @node Miscellaneous
10244 @chapter Miscellaneous Rules
10245
10246 There are a few rules and variables that didn't fit anywhere else.
10247
10248 @menu
10249 * Tags::                        Interfacing to cscope, etags and mkid
10250 * Suffixes::                    Handling new file extensions
10251 @end menu
10252
10253
10254 @node Tags
10255 @section Interfacing to @command{etags}
10256
10257 @cindex @file{TAGS} support
10258
10259 Automake will generate rules to generate @file{TAGS} files for use with
10260 GNU Emacs under some circumstances.
10261
10262 @trindex tags
10263 If any C, C++ or Fortran 77 source code or headers are present, then
10264 @code{tags} and @code{TAGS} rules will be generated for the directory.
10265 All files listed using the @code{_SOURCES}, @code{_HEADERS}, and
10266 @code{_LISP} primaries will be used to generate tags.  Note that
10267 generated source files that are not distributed must be declared in
10268 variables like @code{nodist_noinst_HEADERS} or
10269 @code{nodist_@var{prog}_SOURCES} or they will be ignored.
10270
10271 A @code{tags} rule will be output at the topmost directory of a
10272 multi-directory package.  When run from this topmost directory,
10273 @samp{make tags} will generate a @file{TAGS} file that includes by
10274 reference all @file{TAGS} files from subdirectories.
10275
10276 The @code{tags} rule will also be generated if the variable
10277 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
10278 directories that contain taggable source that @command{etags} does
10279 not understand.  The user can use the @code{ETAGSFLAGS} to pass
10280 additional flags to @command{etags}; @code{AM_ETAGSFLAGS} is also
10281 available for use in @file{Makefile.am}.
10282 @vindex ETAGS_ARGS
10283 @vindex ETAGSFLAGS
10284 @vindex AM_ETAGSFLAGS
10285
10286 Here is how Automake generates tags for its source, and for nodes in its
10287 Texinfo file:
10288
10289 @example
10290 ETAGS_ARGS = automake.in --lang=none \
10291  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
10292 @end example
10293
10294 If you add file names to @code{ETAGS_ARGS}, you will probably also
10295 want to define @code{TAGS_DEPENDENCIES}.  The contents of this variable
10296 are added directly to the dependencies for the @code{tags} rule.
10297 @vindex TAGS_DEPENDENCIES
10298
10299 Automake also generates a @code{ctags} rule that can be used to
10300 build @command{vi}-style @file{tags} files.  The variable @code{CTAGS}
10301 is the name of the program to invoke (by default @command{ctags});
10302 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
10303 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
10304
10305 @trindex id
10306 Automake will also generate an @code{ID} rule that will run
10307 @command{mkid} on the source.  This is only supported on a
10308 directory-by-directory basis.
10309
10310 Similarly, the @code{cscope} rule will create a list of all the source
10311 files in the tree and run @command{cscope} to build an inverted index
10312 database.  The variable @code{CSCOPE} is the name of the program to invoke
10313 (by default @command{cscope}); @code{CSCOPEFLAGS} and
10314 @code{CSCOPE_ARGS} can be used by the user to pass additional flags and
10315 file names respectively, while @code{AM_CSCOPEFLAGS} can be used by the
10316 @file{Makefile.am}.  Note that, currently, the Automake-provided
10317 @code{cscope} support, when used in a VPATH build, might not work well
10318 with non-GNU make implementations (especially with make implementations
10319 performing @ref{Automatic Rule Rewriting, , VPATH rewrites, autoconf,
10320 The Autoconf Manual}).
10321
10322 Finally, Automake also emits rules to support the
10323 @uref{http://www.gnu.org/software/global/, GNU Global Tags program}.
10324 The @code{GTAGS} rule runs Global Tags and puts the
10325 result in the top build directory.  The variable @code{GTAGS_ARGS}
10326 holds arguments that are passed to @command{gtags}.
10327 @vindex GTAGS_ARGS
10328
10329
10330 @node Suffixes
10331 @section Handling new file extensions
10332
10333 @cindex Adding new @code{SUFFIXES}
10334 @cindex @code{SUFFIXES}, adding
10335 @vindex SUFFIXES
10336
10337 It is sometimes useful to introduce a new implicit rule to handle a file
10338 type that Automake does not know about.
10339
10340 For instance, suppose you had a compiler that could compile @file{.foo}
10341 files to @file{.o} files.  You would simply define a suffix rule for
10342 your language:
10343
10344 @example
10345 .foo.o:
10346         foocc -c -o $@@ $<
10347 @end example
10348
10349 Then you could directly use a @file{.foo} file in a @code{_SOURCES}
10350 variable and expect the correct results:
10351
10352 @example
10353 bin_PROGRAMS = doit
10354 doit_SOURCES = doit.foo
10355 @end example
10356
10357 This was the simpler and more common case.  In other cases, you will
10358 have to help Automake to figure out which extensions you are defining your
10359 suffix rule for.  This usually happens when your extension does not
10360 start with a dot.  Then, all you have to do is to put a list of new
10361 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
10362 implicit rule.
10363
10364 For instance, the following definition prevents Automake from misinterpreting
10365 the @samp{.idlC.cpp:} rule as an attempt to transform @file{.idlC} files into
10366 @file{.cpp} files.
10367
10368 @c Keep in sync with suffix7.sh
10369 @example
10370 SUFFIXES = .idl C.cpp
10371 .idlC.cpp:
10372         # whatever
10373 @end example
10374
10375 As you may have noted, the @code{SUFFIXES} variable behaves like the
10376 @code{.SUFFIXES} special target of @command{make}.  You should not touch
10377 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
10378 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
10379 @code{SUFFIXES} go at the start of the generated suffixes list, followed
10380 by Automake generated suffixes not already in the list.
10381
10382 @node Include
10383 @chapter Include
10384
10385 @cmindex include
10386 @cindex Including @file{Makefile} fragment
10387 @cindex @file{Makefile} fragment, including
10388
10389 Automake supports an @code{include} directive that  can be used to
10390 include other @file{Makefile} fragments when @command{automake} is run.
10391 Note that these fragments are read and interpreted by @command{automake},
10392 not by @command{make}.  As with conditionals, @command{make} has no idea that
10393 @code{include} is in use.
10394
10395 There are two forms of @code{include}:
10396
10397 @table @code
10398 @item include $(srcdir)/file
10399 Include a fragment that is found relative to the current source
10400 directory.
10401
10402 @item include $(top_srcdir)/file
10403 Include a fragment that is found relative to the top source directory.
10404 @end table
10405
10406 Note that if a fragment is included inside a conditional, then the
10407 condition applies to the entire contents of that fragment.
10408
10409 Makefile fragments included this way are always distributed because
10410 they are needed to rebuild @file{Makefile.in}.
10411
10412 @node Conditionals
10413 @chapter Conditionals
10414
10415 @cindex Conditionals
10416
10417 Automake supports a simple type of conditionals.
10418
10419 These conditionals are not the same as conditionals in
10420 GNU Make.  Automake conditionals are checked at configure time by the
10421 @file{configure} script, and affect the translation from
10422 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
10423 to @file{configure} and on results that @file{configure} has discovered
10424 about the host system.  GNU Make conditionals are checked at @command{make}
10425 time, and are based on variables passed to the make program or defined
10426 in the @file{Makefile}.
10427
10428 Automake conditionals will work with any make program.
10429
10430 @menu
10431 * Usage of Conditionals::       Declaring conditional content
10432 * Limits of Conditionals::      Enclosing complete statements
10433 @end menu
10434
10435 @node Usage of Conditionals
10436 @section Usage of Conditionals
10437
10438 @acindex AM_CONDITIONAL
10439 Before using a conditional, you must define it by using
10440 @code{AM_CONDITIONAL} in the @file{configure.ac} file (@pxref{Macros}).
10441
10442 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
10443 The conditional name, @var{conditional}, should be a simple string
10444 starting with a letter and containing only letters, digits, and
10445 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
10446 that are reserved by Automake.
10447
10448 The shell @var{condition} (suitable for use in a shell @code{if}
10449 statement) is evaluated when @command{configure} is run.  Note that you
10450 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
10451 time @command{configure} is run.  If @code{AM_CONDITIONAL} is run
10452 conditionally (e.g., in a shell @code{if} statement), then the result
10453 will confuse @command{automake}.
10454 @end defmac
10455
10456 @cindex @option{--enable-debug}, example
10457 @cindex Example conditional @option{--enable-debug}
10458 @cindex Conditional example, @option{--enable-debug}
10459
10460 Conditionals typically depend upon options that the user provides to
10461 the @command{configure} script.  Here is an example of how to write a
10462 conditional that is true if the user uses the @option{--enable-debug}
10463 option.
10464
10465 @example
10466 AC_ARG_ENABLE([debug],
10467 [  --enable-debug    Turn on debugging],
10468 [case "$@{enableval@}" in
10469   yes) debug=true ;;
10470   no)  debug=false ;;
10471   *) AC_MSG_ERROR([bad value $@{enableval@} for --enable-debug]) ;;
10472 esac],[debug=false])
10473 AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
10474 @end example
10475
10476 Here is an example of how to use that conditional in @file{Makefile.am}:
10477
10478 @cmindex if
10479 @cmindex endif
10480 @cmindex else
10481
10482 @example
10483 if DEBUG
10484 DBG = debug
10485 else
10486 DBG =
10487 endif
10488 noinst_PROGRAMS = $(DBG)
10489 @end example
10490
10491 This trivial example could also be handled using @code{EXTRA_PROGRAMS}
10492 (@pxref{Conditional Programs}).
10493
10494 You may only test a single variable in an @code{if} statement, possibly
10495 negated using @samp{!}.  The @code{else} statement may be omitted.
10496 Conditionals may be nested to any depth.  You may specify an argument to
10497 @code{else} in which case it must be the negation of the condition used
10498 for the current @code{if}.  Similarly you may specify the condition
10499 that is closed on the @code{endif} line:
10500
10501 @example
10502 if DEBUG
10503 DBG = debug
10504 else !DEBUG
10505 DBG =
10506 endif !DEBUG
10507 @end example
10508
10509 @noindent
10510 Unbalanced conditions are errors.  The @code{if}, @code{else}, and
10511 @code{endif} statements should not be indented, i.e., start on column
10512 one.
10513
10514 The @code{else} branch of the above two examples could be omitted,
10515 since assigning the empty string to an otherwise undefined variable
10516 makes no difference.
10517
10518 @acindex AM_COND_IF
10519 In order to allow access to the condition registered by
10520 @code{AM_CONDITIONAL} inside @file{configure.ac}, and to allow
10521 conditional @code{AC_CONFIG_FILES}, @code{AM_COND_IF} may be used:
10522
10523 @defmac AM_COND_IF (@var{conditional}, @ovar{if-true}, @ovar{if-false})
10524 If @var{conditional} is fulfilled, execute @var{if-true}, otherwise
10525 execute @var{if-false}.  If either branch contains @code{AC_CONFIG_FILES},
10526 it will cause @command{automake} to output the rules for the respective
10527 files only for the given condition.
10528 @end defmac
10529
10530 @code{AM_COND_IF} macros may be nested when m4 quotation is used
10531 properly (@pxref{M4 Quotation, ,, autoconf, The Autoconf Manual}).
10532
10533 @cindex Example conditional @code{AC_CONFIG_FILES}
10534 @cindex @code{AC_CONFIG_FILES}, conditional
10535
10536 Here is an example of how to define a conditional config file:
10537
10538 @example
10539 AM_CONDITIONAL([SHELL_WRAPPER], [test "x$with_wrapper" = xtrue])
10540 AM_COND_IF([SHELL_WRAPPER],
10541            [AC_CONFIG_FILES([wrapper:wrapper.in])])
10542 @end example
10543
10544 @node Limits of Conditionals
10545 @section Limits of Conditionals
10546
10547 Conditionals should enclose complete statements like variables or
10548 rules definitions.  Automake cannot deal with conditionals used inside
10549 a variable definition, for instance, and is not even able to diagnose
10550 this situation.  The following example would not work:
10551
10552 @example
10553 # This syntax is not understood by Automake
10554 AM_CPPFLAGS = \
10555   -DFEATURE_A \
10556 if WANT_DEBUG
10557   -DDEBUG \
10558 endif
10559   -DFEATURE_B
10560 @end example
10561
10562 However the intended definition of @code{AM_CPPFLAGS} can be achieved
10563 with
10564
10565 @example
10566 if WANT_DEBUG
10567   DEBUGFLAGS = -DDEBUG
10568 endif
10569 AM_CPPFLAGS = -DFEATURE_A $(DEBUGFLAGS) -DFEATURE_B
10570 @end example
10571
10572 @noindent
10573 or
10574
10575 @example
10576 AM_CPPFLAGS = -DFEATURE_A
10577 if WANT_DEBUG
10578 AM_CPPFLAGS += -DDEBUG
10579 endif
10580 AM_CPPFLAGS += -DFEATURE_B
10581 @end example
10582
10583 More details and examples of conditionals are described alongside
10584 various Automake features in this manual (@pxref{Conditional
10585 Subdirectories}, @pxref{Conditional Sources}, @pxref{Conditional
10586 Programs}, @pxref{Conditional Libtool Libraries}, @pxref{Conditional
10587 Libtool Sources}).
10588
10589 @node Silencing Make
10590 @chapter Silencing @command{make}
10591
10592 @cindex Silent @command{make}
10593 @cindex Silencing @command{make}
10594 @cindex Silent rules
10595 @cindex Silent @command{make} rules
10596
10597 @menu
10598 * Make verbosity::              Make is verbose by default
10599 * Tricks For Silencing Make::   Standard and generic ways to silence make
10600 * Automake Silent Rules::       How Automake can help in silencing make
10601 @end menu
10602
10603 @node Make verbosity
10604 @section Make is verbose by default
10605
10606 Normally, when executing the set of rules associated with a target,
10607 @command{make} prints each rule before it is executed.  This behaviour,
10608 while having been in place for a long time, and being even mandated by
10609 the POSIX standard, starkly violates the ``silence is golden'' UNIX
10610 principle@footnote{See also
10611 @uref{http://catb.org/~esr/writings/taoup/html/ch11s09.html}.}:
10612
10613 @quotation
10614 When a program has nothing interesting or surprising to say, it should
10615 say nothing.  Well-behaved Unix programs do their jobs unobtrusively,
10616 with a minimum of fuss and bother.  Silence is golden.
10617 @end quotation
10618
10619 In fact, while such verbosity of @command{make} can theoretically be
10620 useful to track bugs and understand reasons of failures right away, it
10621 can also hide warning and error messages from @command{make}-invoked
10622 tools, drowning them in a flood of uninteresting and seldom useful
10623 messages, and thus allowing them to go easily undetected.
10624
10625 This problem can be very annoying, especially for developers, who usually
10626 know quite well what's going on behind the scenes, and for whom the
10627 verbose output from @command{make} ends up being mostly noise that hampers
10628 the easy detection of potentially important warning messages.
10629
10630 @node Tricks For Silencing Make
10631 @section Standard and generic ways to silence make
10632
10633 Here we describe some common idioms/tricks to obtain a quieter make
10634 output, with their relative advantages and drawbacks.  In the next
10635 section (@ref{Automake Silent Rules}) we'll see how Automake can help
10636 in this respect, providing more elaborate and flexible idioms.
10637
10638 @itemize @bullet
10639
10640 @item @command{make -s}
10641
10642 This simply causes @command{make} not to print @emph{any} rule before
10643 executing it.
10644
10645 The @option{-s} flag is mandated by POSIX, universally supported, and
10646 its purpose and function are easy to understand.
10647
10648 But it also has its serious limitations too.  First of all, it embodies
10649 an ``all or nothing'' strategy, i.e., either everything is silenced, or
10650 nothing is; this lack of granularity can sometimes be a fatal flaw.
10651 Moreover, when the @option{-s} flag is used, the @command{make} output
10652 might turn out to be too much terse; in case of errors, the user won't
10653 be able to easily see what rule or command have caused them, or even,
10654 in case of tools with poor error reporting, what the errors were!
10655
10656 @item @command{make >/dev/null || make}
10657
10658 Apparently, this perfectly obeys the ``silence is golden'' rule: warnings
10659 from stderr are passed through, output reporting is done only in case of
10660 error, and in that case it should provide a verbose-enough report to allow
10661 an easy determination of the error location and causes.
10662
10663 However, calling @command{make} two times in a row might hide errors
10664 (especially intermittent ones), or subtly change the expected semantic
10665 of the @command{make} calls --- things these which can clearly make
10666 debugging and error assessment very difficult.
10667
10668 @item @command{make --no-print-directory}
10669
10670 This is GNU @command{make} specific.  When called with the
10671 @option{--no-print-directory} option, GNU @command{make} will disable
10672 printing of the working directory by invoked sub-@command{make}s (the
10673 well-known ``@i{Entering/Leaving directory ...}'' messages).  This helps
10674 to decrease the verbosity of the output, but experience has shown that
10675 it can also often render debugging considerably harder in projects using
10676 deeply-nested @command{make} recursion.
10677
10678 As an aside, notice that the @option{--no-print-directory} option is
10679 automatically activated if the @option{-s} flag is used.
10680
10681 @c TODO: Other tricks?
10682 @c TODO: Maybe speak about the @code{.SILENT} target?
10683 @c TODO:  - Pros: More granularity on what to silence.
10684 @c TODO:  - Cons: No easy way to temporarily override.
10685
10686 @end itemize
10687
10688 @node Automake Silent Rules
10689 @section How Automake can help in silencing make
10690
10691 The tricks and idioms for silencing @command{make} described in the
10692 previous section can be useful from time to time, but we've seen that
10693 they all have their serious drawbacks and limitations.  That's why
10694 automake provides support for a more advanced and flexible way of
10695 obtaining quieter output from @command{make} (for most rules at least).
10696
10697 @c TODO: Maybe describe in brief the precedent set by the build system
10698 @c of the Linux Kernel, from which Automake took inspiration ... Links?
10699
10700 To give the gist of what Automake can do in this respect, here is a simple
10701 comparison between a typical @command{make} output (where silent rules
10702 are disabled) and one with silent rules enabled:
10703
10704 @example
10705 % @kbd{cat Makefile.am}
10706 bin_PROGRAMS = foo
10707 foo_SOURCES = main.c func.c
10708 % @kbd{cat main.c}
10709 int main (void) @{ return func (); @}  /* func used undeclared */
10710 % @kbd{cat func.c}
10711 int func (void) @{ int i; return i; @} /* i used uninitialized */
10712
10713 @i{The make output is by default very verbose.  This causes warnings
10714 from the compiler to be somewhat hidden, and not immediate to spot.}
10715 % @kbd{make CFLAGS=-Wall}
10716 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
10717 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
10718 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT main.o
10719 -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
10720 main.c: In function â€˜main’:
10721 main.c:3:3: warning: implicit declaration of function â€˜func’
10722 mv -f .deps/main.Tpo .deps/main.Po
10723 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
10724 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
10725 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT func.o
10726 -MD -MP -MF .deps/func.Tpo -c -o func.o func.c
10727 func.c: In function â€˜func’:
10728 func.c:4:3: warning: â€˜i’ used uninitialized in this function
10729 mv -f .deps/func.Tpo .deps/func.Po
10730 gcc -Wall -o foo main.o func.o
10731
10732 @i{Clean up, so that we we can rebuild everything from scratch.}
10733 % @kbd{make clean}
10734 test -z "foo" || rm -f foo
10735 rm -f *.o
10736
10737 @i{Silent rules enabled: the output is minimal but informative.  In
10738 particular, the warnings from the compiler stick out very clearly.}
10739 % @kbd{make V=0 CFLAGS=-Wall}
10740   CC     main.o
10741 main.c: In function â€˜main’:
10742 main.c:3:3: warning: implicit declaration of function â€˜func’
10743   CC     func.o
10744 func.c: In function â€˜func’:
10745 func.c:4:3: warning: â€˜i’ used uninitialized in this function
10746   CCLD   foo
10747 @end example
10748
10749 @cindex silent rules and libtool
10750 Also, in projects using @command{libtool}, the use of silent rules can
10751 automatically enable the @command{libtool}'s @option{--silent} option:
10752
10753 @example
10754 % @kbd{cat Makefile.am}
10755 lib_LTLIBRARIES = libx.la
10756
10757 % @kbd{make # Both make and libtool are verbose by default.}
10758 ...
10759 libtool: compile: gcc -DPACKAGE_NAME=\"foo\" ... -DLT_OBJDIR=\".libs/\"
10760   -I. -g -O2 -MT libx.lo -MD -MP -MF .deps/libx.Tpo -c libx.c -fPIC
10761   -DPIC -o .libs/libx.o
10762 mv -f .deps/libx.Tpo .deps/libx.Plo
10763 /bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -o libx.la -rpath
10764   /usr/local/lib libx.lo
10765 libtool: link: gcc -shared .libs/libx.o -Wl,-soname -Wl,libx.so.0
10766   -o .libs/libx.so.0.0.0
10767 libtool: link: cd .libs && rm -f libx.so && ln -s libx.so.0.0.0 libx.so
10768 ...
10769
10770 % @kbd{make V=0}
10771   CC     libx.lo
10772   CCLD   libx.la
10773 @end example
10774
10775 For Automake-generated @file{Makefile}s, the user may influence the
10776 verbosity at @command{configure} run time as well as at @command{make}
10777 run time:
10778
10779 @itemize @bullet
10780 @item
10781 @opindex --enable-silent-rules
10782 @opindex --disable-silent-rules
10783 Passing @option{--enable-silent-rules} to @command{configure} will cause
10784 build rules to be less verbose; the option @option{--disable-silent-rules}
10785 will cause normal verbose output.
10786 @item
10787 @vindex @code{V}
10788 At @command{make} run time, the default chosen at @command{configure}
10789 time may be overridden: @code{make V=1} will produce verbose output,
10790 @code{make V=0} less verbose output.
10791 @end itemize
10792
10793 @cindex default verbosity for silent rules
10794 Note that silent rules are @emph{disabled} by default; the user must
10795 enable them explicitly at either @command{configure} run time or at
10796 @command{make} run time.  We think that this is a good policy, since
10797 it provides the casual user with enough information to prepare a good
10798 bug report in case anything breaks.
10799
10800 Still, notwithstanding the rationales above, a developer who really
10801 wants to make silent rules enabled by default in his own package can
10802 do so by calling @code{AM_SILENT_RULES([yes])} in @file{configure.ac}.
10803
10804 @c Keep in sync with silent-configsite.sh
10805 Users who prefer to have silent rules enabled by default can edit their
10806 @file{config.site} file to make the variable @code{enable_silent_rules}
10807 default to @samp{yes}.  This should still allow disabling silent rules
10808 at @command{configure} time and at @command{make} time.
10809
10810 @c FIXME: there's really a need to specify this explicitly?
10811 For portability to different @command{make} implementations, package authors
10812 are advised to not set the variable @code{V} inside the @file{Makefile.am}
10813 file, to allow the user to override the value for subdirectories as well.
10814
10815 To work at its best, the current implementation of this feature normally
10816 uses nested variable expansion @samp{$(@var{var1}$(V))}, a @file{Makefile}
10817 feature that is not required by POSIX 2008 but is widely supported in
10818 practice.  On the rare @command{make} implementations that do not support
10819 nested variable expansion, whether rules are silent is always determined at
10820 configure time, and cannot be overridden at make time.  Future versions of
10821 POSIX are likely to require nested variable expansion, so this minor
10822 limitation should go away with time.
10823
10824 @vindex @code{AM_V_GEN}
10825 @vindex @code{AM_V_at}
10826 @vindex @code{AM_DEFAULT_VERBOSITY}
10827 @vindex @code{AM_V}
10828 @vindex @code{AM_DEFAULT_V}
10829 To extend the silent mode to your own rules, you have few choices:
10830
10831 @itemize @bullet
10832
10833 @item
10834 You can use the predefined variable @code{AM_V_GEN} as a prefix to
10835 commands that should output a status line in silent mode, and
10836 @code{AM_V_at} as a prefix to commands that should not output anything
10837 in silent mode.  When output is to be verbose, both of these variables
10838 will expand to the empty string.
10839
10840 @item
10841 You can silence a recipe unconditionally with @code{@@}, and then use
10842 the predefined variable @code{AM_V_P} to know whether make is being run
10843 in silent or verbose mode, adjust the verbose information your recipe
10844 displays accordingly:
10845
10846 @example
10847 generate-headers:
10848         @set -e; \
10849         ... [commands defining a shell variable '$headers'] ...; \
10850         if $(AM_V_P); then set -x; else echo " GEN   [headers]"; fi; \
10851         rm -f $$headers && generate-header --flags $$headers
10852 @end example
10853
10854 @item
10855 You can add your own variables, so strings of your own choice are shown.
10856 The following snippet shows how you would define your own equivalent of
10857 @code{AM_V_GEN}:
10858
10859 @example
10860 pkg_verbose = $(pkg_verbose_@@AM_V@@)
10861 pkg_verbose_ = $(pkg_verbose_@@AM_DEFAULT_V@@)
10862 pkg_verbose_0 = @@echo PKG-GEN $@@;
10863
10864 foo: foo.in
10865         $(pkg_verbose)cp $(srcdir)/foo.in $@@
10866 @end example
10867
10868 @end itemize
10869
10870 As a final note, observe that, even when silent rules are enabled,
10871 the @option{--no-print-directory} option is still required with GNU
10872 @command{make} if the ``@i{Entering/Leaving directory ...}'' messages
10873 are to be disabled.
10874
10875 @node Gnits
10876 @chapter The effect of @option{--gnu} and @option{--gnits}
10877
10878 @cindex @option{--gnu}, required files
10879 @cindex @option{--gnu}, complete description
10880
10881 The @option{--gnu} option (or @option{gnu} in the
10882 @code{AUTOMAKE_OPTIONS} variable) causes @command{automake} to check
10883 the following:
10884
10885 @itemize @bullet
10886 @item
10887 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
10888 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
10889 or @file{COPYING}, are required at the topmost directory of the package.
10890
10891 If the @option{--add-missing} option is given, @command{automake} will
10892 add a generic version of the @file{INSTALL} file as well as the
10893 @file{COPYING} file containing the text of the current version of the
10894 GNU General Public License existing at the time of this Automake release
10895 (version 3 as this is written, @uref{http://www.gnu.org/@/copyleft/@/gpl.html}).
10896 However, an existing @file{COPYING} file will never be overwritten by
10897 @command{automake}.
10898
10899 @item
10900 The options @option{no-installman} and @option{no-installinfo} are
10901 prohibited.
10902 @end itemize
10903
10904 Note that this option will be extended in the future to do even more
10905 checking; it is advisable to be familiar with the precise requirements
10906 of the GNU standards.  Also, @option{--gnu} can require certain
10907 non-standard GNU programs to exist for use by various maintainer-only
10908 rules; for instance, in the future @command{pathchk} might be required for
10909 @samp{make dist}.
10910
10911 @cindex @option{--gnits}, complete description
10912
10913 The @option{--gnits} option does everything that @option{--gnu} does, and
10914 checks the following as well:
10915
10916 @itemize @bullet
10917 @item
10918 @samp{make installcheck} will check to make sure that the @option{--help}
10919 and @option{--version} really print a usage message and a version string,
10920 respectively.  This is the @option{std-options} option (@pxref{Options}).
10921
10922 @item
10923 @samp{make dist} will check to make sure the @file{NEWS} file has been
10924 updated to the current version.
10925
10926 @item
10927 @code{VERSION} is checked to make sure its format complies with Gnits
10928 standards.
10929 @c FIXME xref when standards are finished
10930
10931 @item
10932 @cindex @file{README-alpha}
10933 If @code{VERSION} indicates that this is an alpha release, and the file
10934 @file{README-alpha} appears in the topmost directory of a package, then
10935 it is included in the distribution.  This is done in @option{--gnits}
10936 mode, and no other, because this mode is the only one where version
10937 number formats are constrained, and hence the only mode where Automake
10938 can automatically determine whether @file{README-alpha} should be
10939 included.
10940
10941 @item
10942 The file @file{THANKS} is required.
10943 @end itemize
10944
10945
10946 @node Not Enough
10947 @chapter When Automake Isn't Enough
10948
10949 In some situations, where Automake is not up to one task, one has to
10950 resort to handwritten rules or even handwritten @file{Makefile}s.
10951
10952 @menu
10953 * Extending::                   Adding new rules or overriding existing ones.
10954 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
10955 @end menu
10956
10957 @node Extending
10958 @section Extending Automake Rules
10959
10960 With some minor exceptions (for example @code{_PROGRAMS} variables,
10961 @code{TESTS}, or @code{XFAIL_TESTS}) being rewritten to append
10962 @samp{$(EXEEXT)}), the contents of a @file{Makefile.am} is copied to
10963 @file{Makefile.in} verbatim.
10964
10965 @cindex copying semantics
10966
10967 These copying semantics mean that many problems can be worked around
10968 by simply adding some @command{make} variables and rules to
10969 @file{Makefile.am}.  Automake will ignore these additions.
10970
10971 @cindex conflicting definitions
10972 @cindex rules, conflicting
10973 @cindex variables, conflicting
10974 @cindex definitions, conflicts
10975
10976 Since a @file{Makefile.in} is built from data gathered from three
10977 different places (@file{Makefile.am}, @file{configure.ac}, and
10978 @command{automake} itself), it is possible to have conflicting
10979 definitions of rules or variables.  When building @file{Makefile.in}
10980 the following priorities are respected by @command{automake} to ensure
10981 the user always has the last word:
10982
10983 @itemize
10984 @item
10985 User defined variables in @file{Makefile.am} have priority over
10986 variables @code{AC_SUBST}ed from @file{configure.ac}, and
10987 @code{AC_SUBST}ed variables have priority over
10988 @command{automake}-defined variables.
10989 @item
10990 As far as rules are concerned, a user-defined rule overrides any
10991 @command{automake}-defined rule for the same target.
10992 @end itemize
10993
10994 @cindex overriding rules
10995 @cindex overriding semantics
10996 @cindex rules, overriding
10997
10998 These overriding semantics make it possible to fine tune some default
10999 settings of Automake, or replace some of its rules.  Overriding
11000 Automake rules is often inadvisable, particularly in the topmost
11001 directory of a package with subdirectories.  The @option{-Woverride}
11002 option (@pxref{automake Invocation}) comes in handy to catch overridden
11003 definitions.
11004
11005 Note that Automake does not make any distinction between rules with
11006 commands and rules that only specify dependencies.  So it is not
11007 possible to append new dependencies to an @command{automake}-defined
11008 target without redefining the entire rule.
11009
11010 @cindex @option{-local} targets
11011 @cindex local targets
11012
11013 However, various useful targets have a @samp{-local} version you can
11014 specify in your @file{Makefile.am}.  Automake will supplement the
11015 standard target with these user-supplied targets.
11016
11017 @trindex  all
11018 @trindex  all-local
11019 @trindex  info
11020 @trindex  info-local
11021 @trindex  dvi
11022 @trindex  dvi-local
11023 @trindex  ps
11024 @trindex  ps-local
11025 @trindex  pdf
11026 @trindex  pdf-local
11027 @trindex  html
11028 @trindex  html-local
11029 @trindex  check
11030 @trindex  check-local
11031 @trindex  install
11032 @trindex  install-data
11033 @trindex  install-data-local
11034 @trindex  install-dvi
11035 @trindex  install-dvi-local
11036 @trindex  install-exec
11037 @trindex  install-exec-local
11038 @trindex  install-html
11039 @trindex  install-html-local
11040 @trindex  install-info
11041 @trindex  install-info-local
11042 @trindex  install-pdf
11043 @trindex  install-pdf-local
11044 @trindex  install-ps
11045 @trindex  install-ps-local
11046 @trindex  uninstall
11047 @trindex  uninstall-local
11048 @trindex  mostlyclean
11049 @trindex  mostlyclean-local
11050 @trindex  clean
11051 @trindex  clean-local
11052 @trindex  distclean
11053 @trindex  distclean-local
11054 @trindex  installdirs
11055 @trindex  installdirs-local
11056 @trindex  installcheck
11057 @trindex  installcheck-local
11058
11059 The targets that support a local version are @code{all}, @code{info},
11060 @code{dvi}, @code{ps}, @code{pdf}, @code{html}, @code{check},
11061 @code{install-data}, @code{install-dvi}, @code{install-exec},
11062 @code{install-html}, @code{install-info}, @code{install-pdf},
11063 @code{install-ps}, @code{uninstall}, @code{installdirs},
11064 @code{installcheck} and the various @code{clean} targets
11065 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
11066 @code{maintainer-clean}).
11067
11068 Note that there are no @code{uninstall-exec-local} or
11069 @code{uninstall-data-local} targets; just use @code{uninstall-local}.
11070 It doesn't make sense to uninstall just data or just executables.
11071
11072 For instance, here is one way to erase a subdirectory during
11073 @samp{make clean} (@pxref{Clean}).
11074
11075 @example
11076 clean-local:
11077         -rm -rf testSubDir
11078 @end example
11079
11080 You may be tempted to use @code{install-data-local} to install a file
11081 to some hard-coded location, but you should avoid this
11082 (@pxref{Hard-Coded Install Paths}).
11083
11084 With the @code{-local} targets, there is no particular guarantee of
11085 execution order; typically, they are run early, but with parallel
11086 make, there is no way to be sure of that.
11087
11088 @cindex @option{-hook} targets
11089 @cindex hook targets
11090 @trindex install-data-hook
11091 @trindex install-exec-hook
11092 @trindex uninstall-hook
11093 @trindex dist-hook
11094
11095 In contrast, some rules also have a way to run another rule, called a
11096 @dfn{hook}; hooks are always executed after the main rule's work is done.
11097 The hook is named after the principal target, with @samp{-hook} appended.
11098 The targets allowing hooks are @code{install-data},
11099 @code{install-exec}, @code{uninstall}, @code{dist}, and
11100 @code{distcheck}.
11101
11102 For instance, here is how to create a hard link to an installed program:
11103
11104 @example
11105 install-exec-hook:
11106         ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
11107            $(DESTDIR)$(bindir)/proglink$(EXEEXT)
11108 @end example
11109
11110 Although cheaper and more portable than symbolic links, hard links
11111 will not work everywhere (for instance, OS/2 does not have
11112 @command{ln}).  Ideally you should fall back to @samp{cp -p} when
11113 @command{ln} does not work.  An easy way, if symbolic links are
11114 acceptable to you, is to add @code{AC_PROG_LN_S} to
11115 @file{configure.ac} (@pxref{Particular Programs, , Particular Program
11116 Checks, autoconf, The Autoconf Manual}) and use @samp{$(LN_S)} in
11117 @file{Makefile.am}.
11118
11119 @cindex versioned binaries, installing
11120 @cindex installing versioned binaries
11121 @cindex @code{LN_S} example
11122 For instance, here is how you could install a versioned copy of a
11123 program using @samp{$(LN_S)}:
11124
11125 @c Keep in sync with insthook.sh
11126 @example
11127 install-exec-hook:
11128         cd $(DESTDIR)$(bindir) && \
11129           mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
11130           $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
11131 @end example
11132
11133 Note that we rename the program so that a new version will erase the
11134 symbolic link, not the real binary.  Also we @command{cd} into the
11135 destination directory in order to create relative links.
11136
11137 When writing @code{install-exec-hook} or @code{install-data-hook},
11138 please bear in mind that the exec/data distinction is based on the
11139 installation directory, not on the primary used (@pxref{The Two Parts of
11140 Install}).
11141 @c Keep in sync with primary-prefix-couples-documented-valid.sh
11142 So a @code{foo_SCRIPTS} will be installed by
11143 @code{install-data}, and a @code{barexec_SCRIPTS} will be installed by
11144 @code{install-exec}.  You should define your hooks consequently.
11145
11146 @c FIXME should include discussion of variables you can use in these
11147 @c rules
11148
11149 @node Third-Party Makefiles
11150 @section Third-Party @file{Makefile}s
11151
11152 @cindex Third-party packages, interfacing with
11153 @cindex Interfacing with third-party packages
11154
11155 In most projects all @file{Makefile}s are generated by Automake.  In
11156 some cases, however, projects need to embed subdirectories with
11157 handwritten @file{Makefile}s.  For instance, one subdirectory could be
11158 a third-party project with its own build system, not using Automake.
11159
11160 It is possible to list arbitrary directories in @code{SUBDIRS} or
11161 @code{DIST_SUBDIRS} provided each of these directories has a
11162 @file{Makefile} that recognizes all the following recursive targets.
11163
11164 @cindex recursive targets and third-party @file{Makefile}s
11165 When a user runs one of these targets, that target is run recursively
11166 in all subdirectories.  This is why it is important that even
11167 third-party @file{Makefile}s support them.
11168
11169 @table @code
11170 @item all
11171 Compile the entire package.  This is the default target in
11172 Automake-generated @file{Makefile}s, but it does not need to be the
11173 default in third-party @file{Makefile}s.
11174
11175 @item distdir
11176 @trindex distdir
11177 @vindex distdir
11178 @vindex top_distdir
11179 Copy files to distribute into @samp{$(distdir)}, before a tarball is
11180 constructed.  Of course this target is not required if the
11181 @option{no-dist} option (@pxref{Options}) is used.
11182
11183 The variables @samp{$(top_distdir)} and @samp{$(distdir)}
11184 (@pxref{The dist Hook}) will be passed from the outer package to the subpackage
11185 when the @code{distdir} target is invoked.  These two variables have
11186 been adjusted for the directory that is being recursed into, so they
11187 are ready to use.
11188
11189 @item install
11190 @itemx install-data
11191 @itemx install-exec
11192 @itemx uninstall
11193 Install or uninstall files (@pxref{Install}).
11194
11195 @item install-dvi
11196 @itemx install-html
11197 @itemx install-info
11198 @itemx install-ps
11199 @itemx install-pdf
11200 Install only some specific documentation format (@pxref{Texinfo}).
11201
11202 @item installdirs
11203 Create install directories, but do not install any files.
11204
11205 @item check
11206 @itemx installcheck
11207 Check the package (@pxref{Tests}).
11208
11209 @item mostlyclean
11210 @itemx clean
11211 @itemx distclean
11212 @itemx maintainer-clean
11213 Cleaning rules (@pxref{Clean}).
11214
11215 @item dvi
11216 @itemx pdf
11217 @itemx ps
11218 @itemx info
11219 @itemx html
11220 Build the documentation in various formats (@pxref{Texinfo}).
11221
11222 @item tags
11223 @itemx ctags
11224 Build @file{TAGS} and @file{CTAGS} (@pxref{Tags}).
11225 @end table
11226
11227 If you have ever used Gettext in a project, this is a good example of
11228 how third-party @file{Makefile}s can be used with Automake.  The
11229 @file{Makefile}s @command{gettextize} puts in the @file{po/} and
11230 @file{intl/} directories are handwritten @file{Makefile}s that
11231 implement all of these targets.  That way they can be added to
11232 @code{SUBDIRS} in Automake packages.
11233
11234 Directories that are only listed in @code{DIST_SUBDIRS} but not in
11235 @code{SUBDIRS} need only the @code{distclean},
11236 @code{maintainer-clean}, and @code{distdir} rules (@pxref{Conditional
11237 Subdirectories}).
11238
11239 Usually, many of these rules are irrelevant to the third-party
11240 subproject, but they are required for the whole package to work.  It's
11241 OK to have a rule that does nothing, so if you are integrating a
11242 third-party project with no documentation or tag support, you could
11243 simply augment its @file{Makefile} as follows:
11244
11245 @example
11246 EMPTY_AUTOMAKE_TARGETS = dvi pdf ps info html tags ctags
11247 .PHONY: $(EMPTY_AUTOMAKE_TARGETS)
11248 $(EMPTY_AUTOMAKE_TARGETS):
11249 @end example
11250
11251 Another aspect of integrating third-party build systems is whether
11252 they support VPATH builds (@pxref{VPATH Builds}).  Obviously if the
11253 subpackage does not support VPATH builds the whole package will not
11254 support VPATH builds.  This in turns means that @samp{make distcheck}
11255 will not work, because it relies on VPATH builds.  Some people can
11256 live without this (actually, many Automake users have never heard of
11257 @samp{make distcheck}).  Other people may prefer to revamp the
11258 existing @file{Makefile}s to support VPATH@.  Doing so does not
11259 necessarily require Automake, only Autoconf is needed (@pxref{Build
11260 Directories, , Build Directories, autoconf, The Autoconf Manual}).
11261 The necessary substitutions: @samp{@@srcdir@@}, @samp{@@top_srcdir@@},
11262 and @samp{@@top_builddir@@} are defined by @file{configure} when it
11263 processes a @file{Makefile} (@pxref{Preset Output Variables, , Preset
11264 Output Variables, autoconf, The Autoconf Manual}), they are not
11265 computed by the Makefile like the aforementioned @samp{$(distdir)} and
11266 @samp{$(top_distdir)} variables.
11267
11268 It is sometimes inconvenient to modify a third-party @file{Makefile}
11269 to introduce the above required targets.  For instance, one may want to
11270 keep the third-party sources untouched to ease upgrades to new
11271 versions.
11272
11273 @cindex @file{GNUmakefile} including @file{Makefile}
11274 Here are two other ideas.  If GNU make is assumed, one possibility is
11275 to add to that subdirectory a @file{GNUmakefile} that defines the
11276 required targets and includes the third-party @file{Makefile}.  For
11277 this to work in VPATH builds, @file{GNUmakefile} must lie in the build
11278 directory; the easiest way to do this is to write a
11279 @file{GNUmakefile.in} instead, and have it processed with
11280 @code{AC_CONFIG_FILES} from the outer package.  For example if we
11281 assume @file{Makefile} defines all targets except the documentation
11282 targets, and that the @code{check} target is actually called
11283 @code{test}, we could write @file{GNUmakefile} (or
11284 @file{GNUmakefile.in}) like this:
11285
11286 @example
11287 # First, include the real Makefile
11288 include Makefile
11289 # Then, define the other targets needed by Automake Makefiles.
11290 .PHONY: dvi pdf ps info html check
11291 dvi pdf ps info html:
11292 check: test
11293 @end example
11294
11295 @cindex Proxy @file{Makefile} for third-party packages
11296 A similar idea that does not use @code{include} is to write a proxy
11297 @file{Makefile} that dispatches rules to the real @file{Makefile},
11298 either with @samp{$(MAKE) -f Makefile.real $(AM_MAKEFLAGS) target} (if
11299 it's OK to rename the original @file{Makefile}) or with @samp{cd
11300 subdir && $(MAKE) $(AM_MAKEFLAGS) target} (if it's OK to store the
11301 subdirectory project one directory deeper).  The good news is that
11302 this proxy @file{Makefile} can be generated with Automake.  All we
11303 need are @option{-local} targets (@pxref{Extending}) that perform the
11304 dispatch.  Of course the other Automake features are available, so you
11305 could decide to let Automake perform distribution or installation.
11306 Here is a possible @file{Makefile.am}:
11307
11308 @example
11309 all-local:
11310         cd subdir && $(MAKE) $(AM_MAKEFLAGS) all
11311 check-local:
11312         cd subdir && $(MAKE) $(AM_MAKEFLAGS) test
11313 clean-local:
11314         cd subdir && $(MAKE) $(AM_MAKEFLAGS) clean
11315
11316 # Assuming the package knows how to install itself
11317 install-data-local:
11318         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-data
11319 install-exec-local:
11320         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-exec
11321 uninstall-local:
11322         cd subdir && $(MAKE) $(AM_MAKEFLAGS) uninstall
11323
11324 # Distribute files from here.
11325 EXTRA_DIST = subdir/Makefile subdir/program.c ...
11326 @end example
11327
11328 Pushing this idea to the extreme, it is also possible to ignore the
11329 subproject build system and build everything from this proxy
11330 @file{Makefile.am}.  This might sound very sensible if you need VPATH
11331 builds but the subproject does not support them.
11332
11333 @node Distributing
11334 @chapter Distributing @file{Makefile.in}s
11335
11336 Automake places no restrictions on the distribution of the resulting
11337 @file{Makefile.in}s.  We still encourage software authors to
11338 distribute their work under terms like those of the GPL, but doing so
11339 is not required to use Automake.
11340
11341 Some of the files that can be automatically installed via the
11342 @option{--add-missing} switch do fall under the GPL@.  However, these also
11343 have a special exception allowing you to distribute them with your
11344 package, regardless of the licensing you choose.
11345
11346
11347 @node API Versioning
11348 @chapter Automake API Versioning
11349
11350 New Automake releases usually include bug fixes and new features.
11351 Unfortunately they may also introduce new bugs and incompatibilities.
11352 This makes four reasons why a package may require a particular Automake
11353 version.
11354
11355 Things get worse when maintaining a large tree of packages, each one
11356 requiring a different version of Automake.  In the past, this meant that
11357 any developer (and sometimes users) had to install several versions of
11358 Automake in different places, and switch @samp{$PATH} appropriately for
11359 each package.
11360
11361 Starting with version 1.6, Automake installs versioned binaries.  This
11362 means you can install several versions of Automake in the same
11363 @samp{$prefix}, and can select an arbitrary Automake version by running
11364 @command{automake-1.6} or @command{automake-1.7} without juggling with
11365 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
11366 will use @command{automake-1.6} explicitly in their rebuild rules.
11367
11368 The number @samp{1.6} in @command{automake-1.6} is Automake's API version,
11369 not Automake's version.  If a bug fix release is made, for instance
11370 Automake 1.6.1, the API version will remain 1.6.  This means that a
11371 package that works with Automake 1.6 should also work with 1.6.1; after
11372 all, this is what people expect from bug fix releases.
11373
11374 If your package relies on a feature or a bug fix introduced in
11375 a release, you can pass this version as an option to Automake to ensure
11376 older releases will not be used.  For instance, use this in your
11377 @file{configure.ac}:
11378
11379 @example
11380   AM_INIT_AUTOMAKE([1.6.1])    dnl Require Automake 1.6.1 or better.
11381 @end example
11382
11383 @noindent
11384 or, in a particular @file{Makefile.am}:
11385
11386 @example
11387   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
11388 @end example
11389
11390 @noindent
11391 Automake will print an error message if its version is
11392 older than the requested version.
11393
11394
11395 @heading What is in the API
11396
11397 Automake's programming interface is not easy to define.  Basically it
11398 should include at least all @strong{documented} variables and targets
11399 that a @file{Makefile.am} author can use, any behavior associated with
11400 them (e.g., the places where @samp{-hook}'s are run), the command line
11401 interface of @command{automake} and @command{aclocal}, @dots{}
11402
11403 @heading What is not in the API
11404
11405 Every undocumented variable, target, or command line option, is not part
11406 of the API@.  You should avoid using them, as they could change from one
11407 version to the other (even in bug fix releases, if this helps to fix a
11408 bug).
11409
11410 If it turns out you need to use such an undocumented feature, contact
11411 @email{automake@@gnu.org} and try to get it documented and exercised by
11412 the test-suite.
11413
11414 @node Upgrading
11415 @chapter Upgrading a Package to a Newer Automake Version
11416
11417 Automake maintains three kind of files in a package.
11418
11419 @itemize
11420 @item @file{aclocal.m4}
11421 @item @file{Makefile.in}s
11422 @item auxiliary tools like @file{install-sh} or @file{py-compile}
11423 @end itemize
11424
11425 @file{aclocal.m4} is generated by @command{aclocal} and contains some
11426 Automake-supplied M4 macros.  Auxiliary tools are installed by
11427 @samp{automake --add-missing} when needed.  @file{Makefile.in}s are
11428 built from @file{Makefile.am} by @command{automake}, and rely on the
11429 definitions of the M4 macros put in @file{aclocal.m4} as well as the
11430 behavior of the auxiliary tools installed.
11431
11432 Because all of these files are closely related, it is important to
11433 regenerate all of them when upgrading to a newer Automake release.
11434 The usual way to do that is
11435
11436 @example
11437 aclocal # with any option needed (such a -I m4)
11438 autoconf
11439 automake --add-missing --force-missing
11440 @end example
11441
11442 @noindent
11443 or more conveniently:
11444
11445 @example
11446 autoreconf -vfi
11447 @end example
11448
11449 The use of @option{--force-missing} ensures that auxiliary tools will be
11450 overridden by new versions (@pxref{automake Invocation}).
11451
11452 It is important to regenerate all of these files each time Automake is
11453 upgraded, even between bug fixes releases.  For instance, it is not
11454 unusual for a bug fix to involve changes to both the rules generated
11455 in @file{Makefile.in} and the supporting M4 macros copied to
11456 @file{aclocal.m4}.
11457
11458 Presently @command{automake} is able to diagnose situations where
11459 @file{aclocal.m4} has been generated with another version of
11460 @command{aclocal}.  However it never checks whether auxiliary scripts
11461 are up-to-date.  In other words, @command{automake} will tell you when
11462 @command{aclocal} needs to be rerun, but it will never diagnose a
11463 missing @option{--force-missing}.
11464
11465 Before upgrading to a new major release, it is a good idea to read the
11466 file @file{NEWS}.  This file lists all changes between releases: new
11467 features, obsolete constructs, known incompatibilities, and
11468 workarounds.
11469
11470 @node FAQ
11471 @chapter Frequently Asked Questions about Automake
11472
11473 This chapter covers some questions that often come up on the mailing
11474 lists.
11475
11476 @menu
11477 * CVS::                         CVS and generated files
11478 * maintainer-mode::             missing and AM_MAINTAINER_MODE
11479 * Wildcards::                   Why doesn't Automake support wildcards?
11480 * Limitations on File Names::   Limitations on source and installed file names
11481 * Errors with distclean::       Files left in build directory after distclean
11482 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
11483 * Renamed Objects::             Why are object files sometimes renamed?
11484 * Per-Object Flags::            How to simulate per-object flags?
11485 * Multiple Outputs::            Writing rules for tools with many output files
11486 * Hard-Coded Install Paths::    Installing to hard-coded locations
11487 * Debugging Make Rules::        Strategies when things don't work as expected
11488 * Reporting Bugs::              Feedback on bugs and feature requests
11489 @end menu
11490
11491 @node CVS
11492 @section CVS and generated files
11493
11494 @subheading Background: distributed generated Files
11495 @cindex generated files, distributed
11496 @cindex rebuild rules
11497
11498 Packages made with Autoconf and Automake ship with some generated
11499 files like @file{configure} or @file{Makefile.in}.  These files were
11500 generated on the developer's machine and are distributed so that
11501 end-users do not have to install the maintainer tools required to
11502 rebuild them.  Other generated files like Lex scanners, Yacc parsers,
11503 or Info documentation, are usually distributed on similar grounds.
11504
11505 Automake output rules in @file{Makefile}s to rebuild these files.  For
11506 instance, @command{make} will run @command{autoconf} to rebuild
11507 @file{configure} whenever @file{configure.ac} is changed.  This makes
11508 development safer by ensuring a @file{configure} is never out-of-date
11509 with respect to @file{configure.ac}.
11510
11511 As generated files shipped in packages are up-to-date, and because
11512 @command{tar} preserves times-tamps, these rebuild rules are not
11513 triggered when a user unpacks and builds a package.
11514
11515 @subheading Background: CVS and Timestamps
11516 @cindex timestamps and CVS
11517 @cindex CVS and timestamps
11518
11519 Unless you use CVS keywords (in which case files must be updated at
11520 commit time), CVS preserves timestamp during @samp{cvs commit} and
11521 @samp{cvs import -d} operations.
11522
11523 When you check out a file using @samp{cvs checkout} its timestamp is
11524 set to that of the revision that is being checked out.
11525
11526 However, during @command{cvs update}, files will have the date of the
11527 update, not the original timestamp of this revision.  This is meant to
11528 make sure that @command{make} notices sources files have been updated.
11529
11530 This timestamp shift is troublesome when both sources and generated
11531 files are kept under CVS@.  Because CVS processes files in lexical
11532 order, @file{configure.ac} will appear newer than @file{configure}
11533 after a @command{cvs update} that updates both files, even if
11534 @file{configure} was newer than @file{configure.ac} when it was
11535 checked in.  Calling @command{make} will then trigger a spurious rebuild
11536 of @file{configure}.
11537
11538 @subheading Living with CVS in Autoconfiscated Projects
11539 @cindex CVS and generated files
11540 @cindex generated files and CVS
11541
11542 There are basically two clans amongst maintainers: those who keep all
11543 distributed files under CVS, including generated files, and those who
11544 keep generated files @emph{out} of CVS.
11545
11546 @subsubheading All Files in CVS
11547
11548 @itemize @bullet
11549 @item
11550 The CVS repository contains all distributed files so you know exactly
11551 what is distributed, and you can checkout any prior version entirely.
11552
11553 @item
11554 Maintainers can see how generated files evolve (for instance, you can
11555 see what happens to your @file{Makefile.in}s when you upgrade Automake
11556 and make sure they look OK).
11557
11558 @item
11559 Users do not need the autotools to build a checkout of the project, it
11560 works just like a released tarball.
11561
11562 @item
11563 If users use @command{cvs update} to update their copy, instead of
11564 @command{cvs checkout} to fetch a fresh one, timestamps will be
11565 inaccurate.  Some rebuild rules will be triggered and attempt to
11566 run developer tools such as @command{autoconf} or @command{automake}.
11567
11568 Calls to such tools are all wrapped into a call to the @command{missing}
11569 script discussed later (@pxref{maintainer-mode}), so that the user will
11570 see more descriptive warnings about missing or out-of-date tools, and
11571 possible suggestions about how to obtain them, rather than just some
11572 ``command not found'' error, or (worse) some obscure message from some
11573 older version of the required tool they happen to have installed.
11574
11575 Maintainers interested in keeping their package buildable from a CVS
11576 checkout even for those users that lack maintainer-specific tools might
11577 want to provide an helper script (or to enhance their existing bootstrap
11578 script) to fix the timestamps after a
11579 @command{cvs update} or a @command{git checkout}, to prevent spurious
11580 rebuilds.  In case of a project committing the Autotools-generated
11581 files, as well as the generated @file{.info} files, such script might
11582 look something like this:
11583
11584 @smallexample
11585 #!/bin/sh
11586 # fix-timestamp.sh: prevents useless rebuilds after "cvs update"
11587 sleep 1
11588 # aclocal-generated aclocal.m4 depends on locally-installed
11589 # '.m4' macro files, as well as on 'configure.ac'
11590 touch aclocal.m4
11591 sleep 1
11592 # autoconf-generated configure depends on aclocal.m4 and on
11593 # configure.ac
11594 configure config.h.in
11595 # so does autoheader-generated config.h.in
11596 configure config.h.in
11597 # and all the automake-generated Makefile.in files
11598 touch `find . -name Makefile.in -print`
11599 # finally, the makeinfo-generated '.info' files depend on the
11600 # corresponding '.texi' files
11601 touch doc/*.info
11602 @end smallexample
11603
11604 @item
11605 In distributed development, developers are likely to have different
11606 version of the maintainer tools installed.  In this case rebuilds
11607 triggered by timestamp lossage will lead to spurious changes
11608 to generated files.  There are several solutions to this:
11609
11610 @itemize
11611 @item
11612 All developers should use the same versions, so that the rebuilt files
11613 are identical to files in CVS@.  (This starts to be difficult when each
11614 project you work on uses different versions.)
11615 @item
11616 Or people use a script to fix the timestamp after a checkout (the GCC
11617 folks have such a script).
11618 @item
11619 Or @file{configure.ac} uses @code{AM_MAINTAINER_MODE}, which will
11620 disable all of these rebuild rules by default.  This is further discussed
11621 in @ref{maintainer-mode}.
11622 @end itemize
11623
11624 @item
11625 Although we focused on spurious rebuilds, the converse can also
11626 happen.  CVS's timestamp handling can also let you think an
11627 out-of-date file is up-to-date.
11628
11629 For instance, suppose a developer has modified @file{Makefile.am} and
11630 has rebuilt @file{Makefile.in}, and then decides to do a last-minute
11631 change to @file{Makefile.am} right before checking in both files
11632 (without rebuilding @file{Makefile.in} to account for the change).
11633
11634 This last change to @file{Makefile.am} makes the copy of
11635 @file{Makefile.in} out-of-date.  Since CVS processes files
11636 alphabetically, when another developer @samp{cvs update}s his or her
11637 tree, @file{Makefile.in} will happen to be newer than
11638 @file{Makefile.am}.  This other developer will not see that
11639 @file{Makefile.in} is out-of-date.
11640
11641 @end itemize
11642
11643 @subsubheading Generated Files out of CVS
11644
11645 One way to get CVS and @command{make} working peacefully is to never
11646 store generated files in CVS, i.e., do not CVS-control files that
11647 are @file{Makefile} targets (also called @emph{derived} files).
11648
11649 This way developers are not annoyed by changes to generated files.  It
11650 does not matter if they all have different versions (assuming they are
11651 compatible, of course).  And finally, timestamps are not lost, changes
11652 to sources files can't be missed as in the
11653 @file{Makefile.am}/@file{Makefile.in} example discussed earlier.
11654
11655 The drawback is that the CVS repository is not an exact copy of what
11656 is distributed and that users now need to install various development
11657 tools (maybe even specific versions) before they can build a checkout.
11658 But, after all, CVS's job is versioning, not distribution.
11659
11660 Allowing developers to use different versions of their tools can also
11661 hide bugs during distributed development.  Indeed, developers will be
11662 using (hence testing) their own generated files, instead of the
11663 generated files that will be released actually.  The developer who
11664 prepares the tarball might be using a version of the tool that
11665 produces bogus output (for instance a non-portable C file), something
11666 other developers could have noticed if they weren't using their own
11667 versions of this tool.
11668
11669 @subheading Third-party Files
11670 @cindex CVS and third-party files
11671 @cindex third-party files and CVS
11672
11673 Another class of files not discussed here (because they do not cause
11674 timestamp issues) are files that are shipped with a package, but
11675 maintained elsewhere.  For instance, tools like @command{gettextize}
11676 and @command{autopoint} (from Gettext) or @command{libtoolize} (from
11677 Libtool), will install or update files in your package.
11678
11679 These files, whether they are kept under CVS or not, raise similar
11680 concerns about version mismatch between developers' tools.  The
11681 Gettext manual has a section about this, see @ref{CVS Issues, CVS
11682 Issues, Integrating with CVS, gettext, GNU gettext tools}.
11683
11684 @node maintainer-mode
11685 @section @command{missing} and @code{AM_MAINTAINER_MODE}
11686
11687 @subheading @command{missing}
11688 @cindex @command{missing}, purpose
11689
11690 The @command{missing} script is a wrapper around several maintainer
11691 tools, designed to warn users if a maintainer tool is required but
11692 missing.  Typical maintainer tools are @command{autoconf},
11693 @command{automake}, @command{bison}, etc.  Because file generated by
11694 these tools are shipped with the other sources of a package, these
11695 tools shouldn't be required during a user build and they are not
11696 checked for in @file{configure}.
11697
11698 However, if for some reason a rebuild rule is triggered and involves a
11699 missing tool, @command{missing} will notice it and warn the user, even
11700 suggesting how to obtain such a tool (at least in case it is a well-known
11701 one, like @command{makeinfo} or @command{bison}).  This is more helpful
11702 and user-friendly than just having the rebuild rules spewing out a terse
11703 error message like @samp{sh: @var{tool}: command not found}.  Similarly,
11704 @command{missing} will warn the user if it detects that a maintainer
11705 tool it attempted to use seems too old (be warned that diagnosing this
11706 correctly is typically more difficult that detecting missing tools, and
11707 requires cooperation from the tool itself, so it won't always work).
11708
11709 If the required tool is installed, @command{missing} will run it and
11710 won't attempt to continue after failures.  This is correct during
11711 development: developers love fixing failures.  However, users with
11712 missing or too old maintainer tools may get an error when the rebuild
11713 rule is spuriously triggered, halting the build.  This failure to let
11714 the build continue is one of the arguments of the
11715 @code{AM_MAINTAINER_MODE} advocates.
11716
11717 @subheading @code{AM_MAINTAINER_MODE}
11718 @cindex @code{AM_MAINTAINER_MODE}, purpose
11719 @acindex AM_MAINTAINER_MODE
11720
11721 @code{AM_MAINTAINER_MODE} allows you to choose whether the so called
11722 "rebuild rules" should be enabled or disabled.  With
11723 @code{AM_MAINTAINER_MODE([enable])}, they are enabled by default,
11724 otherwise they are disabled by default.  In the latter case, if
11725 you have @code{AM_MAINTAINER_MODE} in @file{configure.ac}, and run
11726 @samp{./configure && make}, then @command{make} will *never* attempt to
11727 rebuild @file{configure}, @file{Makefile.in}s, Lex or Yacc outputs, etc.
11728 I.e., this disables build rules for files that are usually distributed
11729 and that users should normally not have to update.
11730
11731 The user can override the default setting by passing either
11732 @samp{--enable-maintainer-mode} or @samp{--disable-maintainer-mode}
11733 to @command{configure}.
11734
11735 People use @code{AM_MAINTAINER_MODE} either because they do not want their
11736 users (or themselves) annoyed by timestamps lossage (@pxref{CVS}), or
11737 because they simply can't stand the rebuild rules and prefer running
11738 maintainer tools explicitly.
11739
11740 @code{AM_MAINTAINER_MODE} also allows you to disable some custom build
11741 rules conditionally.  Some developers use this feature to disable
11742 rules that need exotic tools that users may not have available.
11743
11744 Several years ago Fran@,{c}ois Pinard pointed out several arguments
11745 against this @code{AM_MAINTAINER_MODE} macro.  Most of them relate to
11746 insecurity.  By removing dependencies you get non-dependable builds:
11747 changes to sources files can have no effect on generated files and this
11748 can be very confusing when unnoticed.  He adds that security shouldn't
11749 be reserved to maintainers (what @option{--enable-maintainer-mode}
11750 suggests), on the contrary.  If one user has to modify a
11751 @file{Makefile.am}, then either @file{Makefile.in} should be updated
11752 or a warning should be output (this is what Automake uses
11753 @command{missing} for) but the last thing you want is that nothing
11754 happens and the user doesn't notice it (this is what happens when
11755 rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
11756
11757 Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro was
11758 swayed by Fran@,{c}ois's arguments, and got rid of
11759 @code{AM_MAINTAINER_MODE} in all of his packages.
11760
11761 Still many people continue to use @code{AM_MAINTAINER_MODE}, because
11762 it helps them working on projects where all files are kept under version
11763 control, and because @command{missing} isn't enough if you have the
11764 wrong version of the tools.
11765
11766
11767 @node Wildcards
11768 @section Why doesn't Automake support wildcards?
11769 @cindex wildcards
11770
11771 Developers are lazy.  They would often like to use wildcards in
11772 @file{Makefile.am}s, so that they would not need to remember to
11773 update @file{Makefile.am}s every time they add, delete, or rename
11774 a file.
11775
11776 There are several objections to this:
11777 @itemize
11778 @item
11779 When using CVS (or similar) developers need to remember they have to
11780 run @samp{cvs add} or @samp{cvs rm} anyway.  Updating
11781 @file{Makefile.am} accordingly quickly becomes a reflex.
11782
11783 Conversely, if your application doesn't compile
11784 because you forgot to add a file in @file{Makefile.am}, it will help
11785 you remember to @samp{cvs add} it.
11786
11787 @item
11788 Using wildcards makes it easy to distribute files by mistake.  For
11789 instance, some code a developer is experimenting with (a test case,
11790 say) that should not be part of the distribution.
11791
11792 @item
11793 Using wildcards it's easy to omit some files by mistake.  For
11794 instance, one developer creates a new file, uses it in many places,
11795 but forgets to commit it.  Another developer then checks out the
11796 incomplete project and is able to run @samp{make dist} successfully,
11797 even though a file is missing. By listing files, @samp{make dist}
11798 @emph{will} complain.
11799
11800 @item
11801 Wildcards are not portable to some non-GNU @command{make} implementations,
11802 e.g., NetBSD @command{make} will not expand globs such as @samp{*} in
11803 prerequisites of a target.
11804
11805 @item
11806 Finally, it's really hard to @emph{forget} to add a file to
11807 @file{Makefile.am}: files that are not listed in @file{Makefile.am} are
11808 not compiled or installed, so you can't even test them.
11809 @end itemize
11810
11811 Still, these are philosophical objections, and as such you may disagree,
11812 or find enough value in wildcards to dismiss all of them.  Before you
11813 start writing a patch against Automake to teach it about wildcards,
11814 let's see the main technical issue: portability.
11815
11816 Although @samp{$(wildcard ...)} works with GNU @command{make}, it is
11817 not portable to other @command{make} implementations.
11818
11819 The only way Automake could support @command{$(wildcard ...)} is by
11820 expending @command{$(wildcard ...)} when @command{automake} is run.
11821 The resulting @file{Makefile.in}s would be portable since they would
11822 list all files and not use @samp{$(wildcard ...)}.  However that
11823 means developers would need to remember to run @command{automake} each
11824 time they add, delete, or rename files.
11825
11826 Compared to editing @file{Makefile.am}, this is a very small gain.  Sure,
11827 it's easier and faster to type @samp{automake; make} than to type
11828 @samp{emacs Makefile.am; make}.  But nobody bothered enough to write a
11829 patch to add support for this syntax.  Some people use scripts to
11830 generate file lists in @file{Makefile.am} or in separate
11831 @file{Makefile} fragments.
11832
11833 Even if you don't care about portability, and are tempted to use
11834 @samp{$(wildcard ...)} anyway because you target only GNU Make, you
11835 should know there are many places where Automake needs to know exactly
11836 which files should be processed.  As Automake doesn't know how to
11837 expand @samp{$(wildcard ...)}, you cannot use it in these places.
11838 @samp{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
11839 variables as far Automake is concerned.
11840
11841 You can get warnings about @samp{$(wildcard ...}) constructs using the
11842 @option{-Wportability} flag.
11843
11844 @node Limitations on File Names
11845 @section Limitations on File Names
11846 @cindex file names, limitations on
11847
11848 Automake attempts to support all kinds of file names, even those that
11849 contain unusual characters or are unusually long.  However, some
11850 limitations are imposed by the underlying operating system and tools.
11851
11852 Most operating systems prohibit the use of the null byte in file
11853 names, and reserve @samp{/} as a directory separator.  Also, they
11854 require that file names are properly encoded for the user's locale.
11855 Automake is subject to these limits.
11856
11857 Portable packages should limit themselves to POSIX file
11858 names.  These can contain ASCII letters and digits,
11859 @samp{_}, @samp{.}, and @samp{-}.  File names consist of components
11860 separated by @samp{/}.  File name components cannot begin with
11861 @samp{-}.
11862
11863 Portable POSIX file names cannot contain components that exceed a
11864 14-byte limit, but nowadays it's normally safe to assume the
11865 more-generous XOPEN limit of 255 bytes.  POSIX
11866 limits file names to 255 bytes (XOPEN allows 1023 bytes),
11867 but you may want to limit a source tarball to file names of 99 bytes
11868 to avoid interoperability problems with old versions of @command{tar}.
11869
11870 If you depart from these rules (e.g., by using non-ASCII
11871 characters in file names, or by using lengthy file names), your
11872 installers may have problems for reasons unrelated to Automake.
11873 However, if this does not concern you, you should know about the
11874 limitations imposed by Automake itself.  These limitations are
11875 undesirable, but some of them seem to be inherent to underlying tools
11876 like Autoconf, Make, M4, and the shell.  They fall into three
11877 categories: install directories, build directories, and file names.
11878
11879 The following characters:
11880
11881 @example
11882 @r{newline} " # $ ' `
11883 @end example
11884
11885 should not appear in the names of install directories.  For example,
11886 the operand of @command{configure}'s @option{--prefix} option should
11887 not contain these characters.
11888
11889 Build directories suffer the same limitations as install directories,
11890 and in addition should not contain the following characters:
11891
11892 @example
11893 & @@ \
11894 @end example
11895
11896 For example, the full name of the directory containing the source
11897 files should not contain these characters.
11898
11899 Source and installation file names like @file{main.c} are limited even
11900 further: they should conform to the POSIX/XOPEN
11901 rules described above.  In addition, if you plan to port to
11902 non-POSIX environments, you should avoid file names that
11903 differ only in case (e.g., @file{makefile} and @file{Makefile}).
11904 Nowadays it is no longer worth worrying about the 8.3 limits of
11905 DOS file systems.
11906
11907 @c FIXME This should probably be moved in the "Checking the Distribution"
11908 @c FIXME section...
11909 @node Errors with distclean
11910 @section Errors with distclean
11911 @cindex @code{distclean}, diagnostic
11912 @cindex @samp{make distclean}, diagnostic
11913 @cindex dependencies and distributed files
11914 @trindex distclean
11915
11916 This is a diagnostic you might encounter while running @samp{make
11917 distcheck}.
11918
11919 As explained in @ref{Checking the Distribution}, @samp{make distcheck}
11920 attempts to build and check your package for errors like this one.
11921
11922 @samp{make distcheck} will perform a @code{VPATH} build of your
11923 package (@pxref{VPATH Builds}), and then call @samp{make distclean}.
11924 Files left in the build directory after @samp{make distclean} has run
11925 are listed after this error.
11926
11927 This diagnostic really covers two kinds of errors:
11928
11929 @itemize @bullet
11930 @item
11931 files that are forgotten by distclean;
11932 @item
11933 distributed files that are erroneously rebuilt.
11934 @end itemize
11935
11936 The former left-over files are not distributed, so the fix is to mark
11937 them for cleaning (@pxref{Clean}), this is obvious and doesn't deserve
11938 more explanations.
11939
11940 The latter bug is not always easy to understand and fix, so let's
11941 proceed with an example.  Suppose our package contains a program for
11942 which we want to build a man page using @command{help2man}.  GNU
11943 @command{help2man} produces simple manual pages from the @option{--help}
11944 and @option{--version} output of other commands (@pxref{Top, , Overview,
11945 help2man, The Help2man Manual}).  Because we don't want to force our
11946 users to install @command{help2man}, we decide to distribute the
11947 generated man page using the following setup.
11948
11949 @example
11950 # This Makefile.am is bogus.
11951 bin_PROGRAMS = foo
11952 foo_SOURCES = foo.c
11953 dist_man_MANS = foo.1
11954
11955 foo.1: foo$(EXEEXT)
11956         help2man --output=foo.1 ./foo$(EXEEXT)
11957 @end example
11958
11959 This will effectively distribute the man page.  However,
11960 @samp{make distcheck} will fail with:
11961
11962 @example
11963 ERROR: files left in build directory after distclean:
11964 ./foo.1
11965 @end example
11966
11967 Why was @file{foo.1} rebuilt?  Because although distributed,
11968 @file{foo.1} depends on a non-distributed built file:
11969 @file{foo$(EXEEXT)}.  @file{foo$(EXEEXT)} is built by the user, so it
11970 will always appear to be newer than the distributed @file{foo.1}.
11971
11972 @samp{make distcheck} caught an inconsistency in our package.  Our
11973 intent was to distribute @file{foo.1} so users do not need to install
11974 @command{help2man}, however since this rule causes this file to be
11975 always rebuilt, users @emph{do} need @command{help2man}.  Either we
11976 should ensure that @file{foo.1} is not rebuilt by users, or there is
11977 no point in distributing @file{foo.1}.
11978
11979 More generally, the rule is that distributed files should never depend
11980 on non-distributed built files.  If you distribute something
11981 generated, distribute its sources.
11982
11983 One way to fix the above example, while still distributing
11984 @file{foo.1} is to not depend on @file{foo$(EXEEXT)}.  For instance,
11985 assuming @command{foo --version} and @command{foo --help} do not
11986 change unless @file{foo.c} or @file{configure.ac} change, we could
11987 write the following @file{Makefile.am}:
11988
11989 @example
11990 bin_PROGRAMS = foo
11991 foo_SOURCES = foo.c
11992 dist_man_MANS = foo.1
11993
11994 foo.1: foo.c $(top_srcdir)/configure.ac
11995         $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
11996         help2man --output=foo.1 ./foo$(EXEEXT)
11997 @end example
11998
11999 This way, @file{foo.1} will not get rebuilt every time
12000 @file{foo$(EXEEXT)} changes.  The @command{make} call makes sure
12001 @file{foo$(EXEEXT)} is up-to-date before @command{help2man}.  Another
12002 way to ensure this would be to use separate directories for binaries
12003 and man pages, and set @code{SUBDIRS} so that binaries are built
12004 before man pages.
12005
12006 We could also decide not to distribute @file{foo.1}.  In
12007 this case it's fine to have @file{foo.1} dependent upon
12008 @file{foo$(EXEEXT)}, since both will have to be rebuilt.
12009 However it would be impossible to build the package in a
12010 cross-compilation, because building @file{foo.1} involves
12011 an @emph{execution} of @file{foo$(EXEEXT)}.
12012
12013 Another context where such errors are common is when distributed files
12014 are built by tools that are built by the package.  The pattern is
12015 similar:
12016
12017 @example
12018 distributed-file: built-tools distributed-sources
12019         build-command
12020 @end example
12021
12022 @noindent
12023 should be changed to
12024
12025 @example
12026 distributed-file: distributed-sources
12027         $(MAKE) $(AM_MAKEFLAGS) built-tools
12028         build-command
12029 @end example
12030
12031 @noindent
12032 or you could choose not to distribute @file{distributed-file}, if
12033 cross-compilation does not matter.
12034
12035 The points made through these examples are worth a summary:
12036
12037 @cartouche
12038 @itemize
12039 @item
12040 Distributed files should never depend upon non-distributed built
12041 files.
12042 @item
12043 Distributed files should be distributed with all their dependencies.
12044 @item
12045 If a file is @emph{intended} to be rebuilt by users, then there is no point
12046 in distributing it.
12047 @end itemize
12048 @end cartouche
12049
12050 @vrindex distcleancheck_listfiles
12051 For desperate cases, it's always possible to disable this check by
12052 setting @code{distcleancheck_listfiles} as documented in @ref{Checking
12053 the Distribution}.
12054 Make sure you do understand the reason why @samp{make distcheck}
12055 complains before you do this.  @code{distcleancheck_listfiles} is a
12056 way to @emph{hide} errors, not to fix them.  You can always do better.
12057
12058 @node Flag Variables Ordering
12059 @section Flag Variables Ordering
12060 @cindex Ordering flag variables
12061 @cindex Flag variables, ordering
12062
12063 @display
12064 What is the difference between @code{AM_CFLAGS}, @code{CFLAGS}, and
12065 @code{mumble_CFLAGS}?
12066 @end display
12067
12068 @display
12069 Why does @command{automake} output @code{CPPFLAGS} after
12070 @code{AM_CPPFLAGS} on compile lines?  Shouldn't it be the converse?
12071 @end display
12072
12073 @display
12074 My @file{configure} adds some warning flags into @code{CXXFLAGS}.  In
12075 one @file{Makefile.am} I would like to append a new flag, however if I
12076 put the flag into @code{AM_CXXFLAGS} it is prepended to the other
12077 flags, not appended.
12078 @end display
12079
12080 @subheading Compile Flag Variables
12081 @cindex Flag Variables, Ordering
12082 @cindex Compile Flag Variables
12083 @cindex @code{AM_CCASFLAGS} and @code{CCASFLAGS}
12084 @cindex @code{AM_CFLAGS} and @code{CFLAGS}
12085 @cindex @code{AM_CPPFLAGS} and @code{CPPFLAGS}
12086 @cindex @code{AM_CXXFLAGS} and @code{CXXFLAGS}
12087 @cindex @code{AM_FCFLAGS} and @code{FCFLAGS}
12088 @cindex @code{AM_FFLAGS} and @code{FFLAGS}
12089 @cindex @code{AM_GCJFLAGS} and @code{GCJFLAGS}
12090 @cindex @code{AM_LDFLAGS} and @code{LDFLAGS}
12091 @cindex @code{AM_LFLAGS} and @code{LFLAGS}
12092 @cindex @code{AM_LIBTOOLFLAGS} and @code{LIBTOOLFLAGS}
12093 @cindex @code{AM_OBJCFLAGS} and @code{OBJCFLAGS}
12094 @cindex @code{AM_OBJCXXFLAGS} and @code{OBJXXCFLAGS}
12095 @cindex @code{AM_RFLAGS} and @code{RFLAGS}
12096 @cindex @code{AM_UPCFLAGS} and @code{UPCFLAGS}
12097 @cindex @code{AM_YFLAGS} and @code{YFLAGS}
12098 @cindex @code{CCASFLAGS} and @code{AM_CCASFLAGS}
12099 @cindex @code{CFLAGS} and @code{AM_CFLAGS}
12100 @cindex @code{CPPFLAGS} and @code{AM_CPPFLAGS}
12101 @cindex @code{CXXFLAGS} and @code{AM_CXXFLAGS}
12102 @cindex @code{FCFLAGS} and @code{AM_FCFLAGS}
12103 @cindex @code{FFLAGS} and @code{AM_FFLAGS}
12104 @cindex @code{GCJFLAGS} and @code{AM_GCJFLAGS}
12105 @cindex @code{LDFLAGS} and @code{AM_LDFLAGS}
12106 @cindex @code{LFLAGS} and @code{AM_LFLAGS}
12107 @cindex @code{LIBTOOLFLAGS} and @code{AM_LIBTOOLFLAGS}
12108 @cindex @code{OBJCFLAGS} and @code{AM_OBJCFLAGS}
12109 @cindex @code{OBJCXXFLAGS} and @code{AM_OBJCXXFLAGS}
12110 @cindex @code{RFLAGS} and @code{AM_RFLAGS}
12111 @cindex @code{UPCFLAGS} and @code{AM_UPCFLAGS}
12112 @cindex @code{YFLAGS} and @code{AM_YFLAGS}
12113
12114 This section attempts to answer all the above questions.  We will
12115 mostly discuss @code{CPPFLAGS} in our examples, but actually the
12116 answer holds for all the compile flags used in Automake:
12117 @code{CCASFLAGS}, @code{CFLAGS}, @code{CPPFLAGS}, @code{CXXFLAGS},
12118 @code{FCFLAGS}, @code{FFLAGS}, @code{GCJFLAGS}, @code{LDFLAGS},
12119 @code{LFLAGS}, @code{LIBTOOLFLAGS}, @code{OBJCFLAGS}, @code{OBJCXXFLAGS},
12120 @code{RFLAGS}, @code{UPCFLAGS}, and @code{YFLAGS}.
12121
12122 @code{CPPFLAGS}, @code{AM_CPPFLAGS}, and @code{mumble_CPPFLAGS} are
12123 three variables that can be used to pass flags to the C preprocessor
12124 (actually these variables are also used for other languages like C++
12125 or preprocessed Fortran).  @code{CPPFLAGS} is the user variable
12126 (@pxref{User Variables}), @code{AM_CPPFLAGS} is the Automake variable,
12127 and @code{mumble_CPPFLAGS} is the variable specific to the
12128 @code{mumble} target (we call this a per-target variable,
12129 @pxref{Program and Library Variables}).
12130
12131 Automake always uses two of these variables when compiling C sources
12132 files.  When compiling an object file for the @code{mumble} target,
12133 the first variable will be @code{mumble_CPPFLAGS} if it is defined, or
12134 @code{AM_CPPFLAGS} otherwise.  The second variable is always
12135 @code{CPPFLAGS}.
12136
12137 In the following example,
12138
12139 @example
12140 bin_PROGRAMS = foo bar
12141 foo_SOURCES = xyz.c
12142 bar_SOURCES = main.c
12143 foo_CPPFLAGS = -DFOO
12144 AM_CPPFLAGS = -DBAZ
12145 @end example
12146
12147 @noindent
12148 @file{xyz.o} will be compiled with @samp{$(foo_CPPFLAGS) $(CPPFLAGS)},
12149 (because @file{xyz.o} is part of the @code{foo} target), while
12150 @file{main.o} will be compiled with @samp{$(AM_CPPFLAGS) $(CPPFLAGS)}
12151 (because there is no per-target variable for target @code{bar}).
12152
12153 The difference between @code{mumble_CPPFLAGS} and @code{AM_CPPFLAGS}
12154 being clear enough, let's focus on @code{CPPFLAGS}.  @code{CPPFLAGS}
12155 is a user variable, i.e., a variable that users are entitled to modify
12156 in order to compile the package.  This variable, like many others,
12157 is documented at the end of the output of @samp{configure --help}.
12158
12159 For instance, someone who needs to add @file{/home/my/usr/include} to
12160 the C compiler's search path would configure a package with
12161
12162 @example
12163 ./configure CPPFLAGS='-I /home/my/usr/include'
12164 @end example
12165
12166 @noindent
12167 and this flag would be propagated to the compile rules of all
12168 @file{Makefile}s.
12169
12170 It is also not uncommon to override a user variable at
12171 @command{make}-time.  Many installers do this with @code{prefix}, but
12172 this can be useful with compiler flags too.  For instance, if, while
12173 debugging a C++ project, you need to disable optimization in one
12174 specific object file, you can run something like
12175
12176 @example
12177 rm file.o
12178 make CXXFLAGS=-O0 file.o
12179 make
12180 @end example
12181
12182 The reason @samp{$(CPPFLAGS)} appears after @samp{$(AM_CPPFLAGS)} or
12183 @samp{$(mumble_CPPFLAGS)} in the compile command is that users
12184 should always have the last say.  It probably makes more sense if you
12185 think about it while looking at the @samp{CXXFLAGS=-O0} above, which
12186 should supersede any other switch from @code{AM_CXXFLAGS} or
12187 @code{mumble_CXXFLAGS} (and this of course replaces the previous value
12188 of @code{CXXFLAGS}).
12189
12190 You should never redefine a user variable such as @code{CPPFLAGS} in
12191 @file{Makefile.am}.  Use @samp{automake -Woverride} to diagnose such
12192 mistakes.  Even something like
12193
12194 @example
12195 CPPFLAGS = -DDATADIR=\"$(datadir)\" @@CPPFLAGS@@
12196 @end example
12197
12198 @noindent
12199 is erroneous.  Although this preserves @file{configure}'s value of
12200 @code{CPPFLAGS}, the definition of @code{DATADIR} will disappear if a
12201 user attempts to override @code{CPPFLAGS} from the @command{make}
12202 command line.
12203
12204 @example
12205 AM_CPPFLAGS = -DDATADIR=\"$(datadir)\"
12206 @end example
12207
12208 @noindent
12209 is all that is needed here if no per-target flags are used.
12210
12211 You should not add options to these user variables within
12212 @file{configure} either, for the same reason.  Occasionally you need
12213 to modify these variables to perform a test, but you should reset
12214 their values afterwards.  In contrast, it is OK to modify the
12215 @samp{AM_} variables within @file{configure} if you @code{AC_SUBST}
12216 them, but it is rather rare that you need to do this, unless you
12217 really want to change the default definitions of the @samp{AM_}
12218 variables in all @file{Makefile}s.
12219
12220 What we recommend is that you define extra flags in separate
12221 variables.  For instance, you may write an Autoconf macro that computes
12222 a set of warning options for the C compiler, and @code{AC_SUBST} them
12223 in @code{WARNINGCFLAGS}; you may also have an Autoconf macro that
12224 determines which compiler and which linker flags should be used to
12225 link with library @file{libfoo}, and @code{AC_SUBST} these in
12226 @code{LIBFOOCFLAGS} and @code{LIBFOOLDFLAGS}.  Then, a
12227 @file{Makefile.am} could use these variables as follows:
12228
12229 @example
12230 AM_CFLAGS = $(WARNINGCFLAGS)
12231 bin_PROGRAMS = prog1 prog2
12232 prog1_SOURCES = @dots{}
12233 prog2_SOURCES = @dots{}
12234 prog2_CFLAGS = $(LIBFOOCFLAGS) $(AM_CFLAGS)
12235 prog2_LDFLAGS = $(LIBFOOLDFLAGS)
12236 @end example
12237
12238 In this example both programs will be compiled with the flags
12239 substituted into @samp{$(WARNINGCFLAGS)}, and @code{prog2} will
12240 additionally be compiled with the flags required to link with
12241 @file{libfoo}.
12242
12243 Note that listing @code{AM_CFLAGS} in a per-target @code{CFLAGS}
12244 variable is a common idiom to ensure that @code{AM_CFLAGS} applies to
12245 every target in a @file{Makefile.in}.
12246
12247 Using variables like this gives you full control over the ordering of
12248 the flags.  For instance, if there is a flag in $(WARNINGCFLAGS) that
12249 you want to negate for a particular target, you can use something like
12250 @samp{prog1_CFLAGS = $(AM_CFLAGS) -no-flag}.  If all of these flags had
12251 been forcefully appended to @code{CFLAGS}, there would be no way to
12252 disable one flag.  Yet another reason to leave user variables to
12253 users.
12254
12255 Finally, we have avoided naming the variable of the example
12256 @code{LIBFOO_LDFLAGS} (with an underscore) because that would cause
12257 Automake to think that this is actually a per-target variable (like
12258 @code{mumble_LDFLAGS}) for some non-declared @code{LIBFOO} target.
12259
12260 @subheading Other Variables
12261
12262 There are other variables in Automake that follow similar principles
12263 to allow user options.  For instance, Texinfo rules (@pxref{Texinfo})
12264 use @code{MAKEINFOFLAGS} and @code{AM_MAKEINFOFLAGS}.  Similarly,
12265 DejaGnu tests (@pxref{DejaGnu Tests}) use @code{RUNTESTDEFAULTFLAGS} and
12266 @code{AM_RUNTESTDEFAULTFLAGS}.  The tags and ctags rules
12267 (@pxref{Tags}) use @code{ETAGSFLAGS}, @code{AM_ETAGSFLAGS},
12268 @code{CTAGSFLAGS}, and @code{AM_CTAGSFLAGS}.  Java rules
12269 (@pxref{Java}) use @code{JAVACFLAGS} and @code{AM_JAVACFLAGS}.  None
12270 of these rules support per-target flags (yet).
12271
12272 To some extent, even @code{AM_MAKEFLAGS} (@pxref{Subdirectories})
12273 obeys this naming scheme.  The slight difference is that
12274 @code{MAKEFLAGS} is passed to sub-@command{make}s implicitly by
12275 @command{make} itself.
12276
12277 @code{ARFLAGS} (@pxref{A Library}) is usually defined by Automake and
12278 has neither @code{AM_} nor per-target cousin.
12279
12280 Finally you should not think that the existence of a per-target
12281 variable implies the existence of an @code{AM_} variable or of a user
12282 variable.  For instance, the @code{mumble_LDADD} per-target variable
12283 overrides the makefile-wide @code{LDADD} variable (which is not a user
12284 variable), and @code{mumble_LIBADD} exists only as a per-target
12285 variable.  @xref{Program and Library Variables}.
12286
12287
12288 @node Renamed Objects
12289 @section Why are object files sometimes renamed?
12290
12291 This happens when per-target compilation flags are used.  Object
12292 files need to be renamed just in case they would clash with object
12293 files compiled from the same sources, but with different flags.
12294 Consider the following example.
12295
12296 @example
12297 bin_PROGRAMS = true false
12298 true_SOURCES = generic.c
12299 true_CPPFLAGS = -DEXIT_CODE=0
12300 false_SOURCES = generic.c
12301 false_CPPFLAGS = -DEXIT_CODE=1
12302 @end example
12303
12304 @noindent
12305 Obviously the two programs are built from the same source, but it
12306 would be bad if they shared the same object, because @file{generic.o}
12307 cannot be built with both @samp{-DEXIT_CODE=0} @emph{and}
12308 @samp{-DEXIT_CODE=1}.  Therefore @command{automake} outputs rules to
12309 build two different objects: @file{true-generic.o} and
12310 @file{false-generic.o}.
12311
12312 @command{automake} doesn't actually look whether source files are
12313 shared to decide if it must rename objects.  It will just rename all
12314 objects of a target as soon as it sees per-target compilation flags
12315 used.
12316
12317 It's OK to share object files when per-target compilation flags are not
12318 used.  For instance, @file{true} and @file{false} will both use
12319 @file{version.o} in the following example.
12320
12321 @example
12322 AM_CPPFLAGS = -DVERSION=1.0
12323 bin_PROGRAMS = true false
12324 true_SOURCES = true.c version.c
12325 false_SOURCES = false.c version.c
12326 @end example
12327
12328 Note that the renaming of objects is also affected by the
12329 @code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
12330
12331
12332 @node Per-Object Flags
12333 @section Per-Object Flags Emulation
12334 @cindex Per-object flags, emulated
12335
12336 @display
12337 One of my source files needs to be compiled with different flags.  How
12338 do I do?
12339 @end display
12340
12341 Automake supports per-program and per-library compilation flags (see
12342 @ref{Program and Library Variables} and @ref{Flag Variables
12343 Ordering}).  With this you can define compilation flags that apply to
12344 all files compiled for a target.  For instance, in
12345
12346 @example
12347 bin_PROGRAMS = foo
12348 foo_SOURCES = foo.c foo.h bar.c bar.h main.c
12349 foo_CFLAGS = -some -flags
12350 @end example
12351
12352 @noindent
12353 @file{foo-foo.o}, @file{foo-bar.o}, and @file{foo-main.o} will all be
12354 compiled with @samp{-some -flags}.  (If you wonder about the names of
12355 these object files, see @ref{Renamed Objects}.)  Note that
12356 @code{foo_CFLAGS} gives the flags to use when compiling all the C
12357 sources of the @emph{program} @code{foo}, it has nothing to do with
12358 @file{foo.c} or @file{foo-foo.o} specifically.
12359
12360 What if @file{foo.c} needs to be compiled into @file{foo.o} using some
12361 specific flags, that none of the other files requires?  Obviously
12362 per-program flags are not directly applicable here.  Something like
12363 per-object flags are expected, i.e., flags that would be used only
12364 when creating @file{foo-foo.o}.  Automake does not support that,
12365 however this is easy to simulate using a library that contains only
12366 that object, and compiling this library with per-library flags.
12367
12368 @example
12369 bin_PROGRAMS = foo
12370 foo_SOURCES = bar.c bar.h main.c
12371 foo_CFLAGS = -some -flags
12372 foo_LDADD = libfoo.a
12373 noinst_LIBRARIES = libfoo.a
12374 libfoo_a_SOURCES = foo.c foo.h
12375 libfoo_a_CFLAGS = -some -other -flags
12376 @end example
12377
12378 Here @file{foo-bar.o} and @file{foo-main.o} will all be
12379 compiled with @samp{-some -flags}, while @file{libfoo_a-foo.o} will
12380 be compiled using @samp{-some -other -flags}.  Eventually, all
12381 three objects will be linked to form @file{foo}.
12382
12383 This trick can also be achieved using Libtool convenience libraries,
12384 for instance @samp{noinst_LTLIBRARIES = libfoo.la} (@pxref{Libtool
12385 Convenience Libraries}).
12386
12387 Another tempting idea to implement per-object flags is to override the
12388 compile rules @command{automake} would output for these files.
12389 Automake will not define a rule for a target you have defined, so you
12390 could think about defining the @samp{foo-foo.o: foo.c} rule yourself.
12391 We recommend against this, because this is error prone.  For instance,
12392 if you add such a rule to the first example, it will break the day you
12393 decide to remove @code{foo_CFLAGS} (because @file{foo.c} will then be
12394 compiled as @file{foo.o} instead of @file{foo-foo.o}, @pxref{Renamed
12395 Objects}).  Also in order to support dependency tracking, the two
12396 @file{.o}/@file{.obj} extensions, and all the other flags variables
12397 involved in a compilation, you will end up modifying a copy of the
12398 rule previously output by @command{automake} for this file.  If a new
12399 release of Automake generates a different rule, your copy will need to
12400 be updated by hand.
12401
12402 @node Multiple Outputs
12403 @section Handling Tools that Produce Many Outputs
12404 @cindex multiple outputs, rules with
12405 @cindex many outputs, rules with
12406 @cindex rules with multiple outputs
12407
12408 This section describes a @command{make} idiom that can be used when a
12409 tool produces multiple output files.  It is not specific to Automake
12410 and can be used in ordinary @file{Makefile}s.
12411
12412 Suppose we have a program called @command{foo} that will read one file
12413 called @file{data.foo} and produce two files named @file{data.c} and
12414 @file{data.h}.  We want to write a @file{Makefile} rule that captures
12415 this one-to-two dependency.
12416
12417 The naive rule is incorrect:
12418
12419 @example
12420 # This is incorrect.
12421 data.c data.h: data.foo
12422         foo data.foo
12423 @end example
12424
12425 @noindent
12426 What the above rule really says is that @file{data.c} and
12427 @file{data.h} each depend on @file{data.foo}, and can each be built by
12428 running @samp{foo data.foo}.  In other words it is equivalent to:
12429
12430 @example
12431 # We do not want this.
12432 data.c: data.foo
12433         foo data.foo
12434 data.h: data.foo
12435         foo data.foo
12436 @end example
12437
12438 @noindent
12439 which means that @command{foo} can be run twice.  Usually it will not
12440 be run twice, because @command{make} implementations are smart enough
12441 to check for the existence of the second file after the first one has
12442 been built; they will therefore detect that it already exists.
12443 However there are a few situations where it can run twice anyway:
12444
12445 @itemize
12446 @item
12447 The most worrying case is when running a parallel @command{make}.  If
12448 @file{data.c} and @file{data.h} are built in parallel, two @samp{foo
12449 data.foo} commands will run concurrently.  This is harmful.
12450 @item
12451 Another case is when the dependency (here @file{data.foo}) is
12452 (or depends upon) a phony target.
12453 @end itemize
12454
12455 A solution that works with parallel @command{make} but not with
12456 phony dependencies is the following:
12457
12458 @example
12459 data.c data.h: data.foo
12460         foo data.foo
12461 data.h: data.c
12462 @end example
12463
12464 @noindent
12465 The above rules are equivalent to
12466
12467 @example
12468 data.c: data.foo
12469         foo data.foo
12470 data.h: data.foo data.c
12471         foo data.foo
12472 @end example
12473
12474 @noindent
12475 therefore a parallel @command{make} will have to serialize the builds
12476 of @file{data.c} and @file{data.h}, and will detect that the second is
12477 no longer needed once the first is over.
12478
12479 Using this pattern is probably enough for most cases.  However it does
12480 not scale easily to more output files (in this scheme all output files
12481 must be totally ordered by the dependency relation), so we will
12482 explore a more complicated solution.
12483
12484 Another idea is to write the following:
12485
12486 @example
12487 # There is still a problem with this one.
12488 data.c: data.foo
12489         foo data.foo
12490 data.h: data.c
12491 @end example
12492
12493 @noindent
12494 The idea is that @samp{foo data.foo} is run only when @file{data.c}
12495 needs to be updated, but we further state that @file{data.h} depends
12496 upon @file{data.c}.  That way, if @file{data.h} is required and
12497 @file{data.foo} is out of date, the dependency on @file{data.c} will
12498 trigger the build.
12499
12500 This is almost perfect, but suppose we have built @file{data.h} and
12501 @file{data.c}, and then we erase @file{data.h}.  Then, running
12502 @samp{make data.h} will not rebuild @file{data.h}.  The above rules
12503 just state that @file{data.c} must be up-to-date with respect to
12504 @file{data.foo}, and this is already the case.
12505
12506 What we need is a rule that forces a rebuild when @file{data.h} is
12507 missing.  Here it is:
12508
12509 @example
12510 data.c: data.foo
12511         foo data.foo
12512 data.h: data.c
12513 ## Recover from the removal of $@@
12514         @@if test -f $@@; then :; else \
12515           rm -f data.c; \
12516           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12517         fi
12518 @end example
12519
12520 The above scheme can be extended to handle more outputs and more
12521 inputs.  One of the outputs is selected to serve as a witness to the
12522 successful completion of the command, it depends upon all inputs, and
12523 all other outputs depend upon it.  For instance, if @command{foo}
12524 should additionally read @file{data.bar} and also produce
12525 @file{data.w} and @file{data.x}, we would write:
12526
12527 @example
12528 data.c: data.foo data.bar
12529         foo data.foo data.bar
12530 data.h data.w data.x: data.c
12531 ## Recover from the removal of $@@
12532         @@if test -f $@@; then :; else \
12533           rm -f data.c; \
12534           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12535         fi
12536 @end example
12537
12538 However there are now three minor problems in this setup.  One is related
12539 to the timestamp ordering of @file{data.h}, @file{data.w},
12540 @file{data.x}, and @file{data.c}.  Another one is a race condition
12541 if a parallel @command{make} attempts to run multiple instances of the
12542 recover block at once.  Finally, the recursive rule breaks @samp{make -n}
12543 when run with GNU @command{make} (as well as some other @command{make}
12544 implementations), as it may remove @file{data.h} even when it should not
12545 (@pxref{MAKE Variable, , How the @code{MAKE} Variable Works, make,
12546 The GNU Make Manual}).
12547
12548 Let us deal with the first problem.  @command{foo} outputs four files,
12549 but we do not know in which order these files are created.  Suppose
12550 that @file{data.h} is created before @file{data.c}.  Then we have a
12551 weird situation.  The next time @command{make} is run, @file{data.h}
12552 will appear older than @file{data.c}, the second rule will be
12553 triggered, a shell will be started to execute the @samp{if@dots{}fi}
12554 command, but actually it will just execute the @code{then} branch,
12555 that is: nothing.  In other words, because the witness we selected is
12556 not the first file created by @command{foo}, @command{make} will start
12557 a shell to do nothing each time it is run.
12558
12559 A simple riposte is to fix the timestamps when this happens.
12560
12561 @example
12562 data.c: data.foo data.bar
12563         foo data.foo data.bar
12564 data.h data.w data.x: data.c
12565         @@if test -f $@@; then \
12566           touch $@@; \
12567         else \
12568 ## Recover from the removal of $@@
12569           rm -f data.c; \
12570           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12571         fi
12572 @end example
12573
12574 Another solution is to use a different and dedicated file as witness,
12575 rather than using any of @command{foo}'s outputs.
12576
12577 @example
12578 data.stamp: data.foo data.bar
12579         @@rm -f data.tmp
12580         @@touch data.tmp
12581         foo data.foo data.bar
12582         @@mv -f data.tmp $@@
12583 data.c data.h data.w data.x: data.stamp
12584 ## Recover from the removal of $@@
12585         @@if test -f $@@; then :; else \
12586           rm -f data.stamp; \
12587           $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
12588         fi
12589 @end example
12590
12591 @file{data.tmp} is created before @command{foo} is run, so it has a
12592 timestamp older than output files output by @command{foo}.  It is then
12593 renamed to @file{data.stamp} after @command{foo} has run, because we
12594 do not want to update @file{data.stamp} if @command{foo} fails.
12595
12596 This solution still suffers from the second problem: the race
12597 condition in the recover rule.  If, after a successful build, a user
12598 erases @file{data.c} and @file{data.h}, and runs @samp{make -j}, then
12599 @command{make} may start both recover rules in parallel.  If the two
12600 instances of the rule execute @samp{$(MAKE) $(AM_MAKEFLAGS)
12601 data.stamp} concurrently the build is likely to fail (for instance, the
12602 two rules will create @file{data.tmp}, but only one can rename it).
12603
12604 Admittedly, such a weird situation does not arise during ordinary
12605 builds.  It occurs only when the build tree is mutilated.  Here
12606 @file{data.c} and @file{data.h} have been explicitly removed without
12607 also removing @file{data.stamp} and the other output files.
12608 @code{make clean; make} will always recover from these situations even
12609 with parallel makes, so you may decide that the recover rule is solely
12610 to help non-parallel make users and leave things as-is.  Fixing this
12611 requires some locking mechanism to ensure only one instance of the
12612 recover rule rebuilds @file{data.stamp}.  One could imagine something
12613 along the following lines.
12614
12615 @example
12616 data.c data.h data.w data.x: data.stamp
12617 ## Recover from the removal of $@@
12618         @@if test -f $@@; then :; else \
12619           trap 'rm -rf data.lock data.stamp' 1 2 13 15; \
12620 ## mkdir is a portable test-and-set
12621           if mkdir data.lock 2>/dev/null; then \
12622 ## This code is being executed by the first process.
12623             rm -f data.stamp; \
12624             $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
12625             result=$$?; rm -rf data.lock; exit $$result; \
12626           else \
12627 ## This code is being executed by the follower processes.
12628 ## Wait until the first process is done.
12629             while test -d data.lock; do sleep 1; done; \
12630 ## Succeed if and only if the first process succeeded.
12631             test -f data.stamp; \
12632           fi; \
12633         fi
12634 @end example
12635
12636 Using a dedicated witness, like @file{data.stamp}, is very handy when
12637 the list of output files is not known beforehand.  As an illustration,
12638 consider the following rules to compile many @file{*.el} files into
12639 @file{*.elc} files in a single command.  It does not matter how
12640 @code{ELFILES} is defined (as long as it is not empty: empty targets
12641 are not accepted by POSIX).
12642
12643 @example
12644 ELFILES = one.el two.el three.el @dots{}
12645 ELCFILES = $(ELFILES:=c)
12646
12647 elc-stamp: $(ELFILES)
12648         @@rm -f elc-temp
12649         @@touch elc-temp
12650         $(elisp_comp) $(ELFILES)
12651         @@mv -f elc-temp $@@
12652
12653 $(ELCFILES): elc-stamp
12654         @@if test -f $@@; then :; else \
12655 ## Recover from the removal of $@@
12656           trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
12657           if mkdir elc-lock 2>/dev/null; then \
12658 ## This code is being executed by the first process.
12659             rm -f elc-stamp; \
12660             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
12661             rmdir elc-lock; \
12662           else \
12663 ## This code is being executed by the follower processes.
12664 ## Wait until the first process is done.
12665             while test -d elc-lock; do sleep 1; done; \
12666 ## Succeed if and only if the first process succeeded.
12667             test -f elc-stamp; exit $$?; \
12668 @c $$
12669           fi; \
12670         fi
12671 @end example
12672
12673 These solutions all still suffer from the third problem, namely that
12674 they break the promise that @samp{make -n} should not cause any actual
12675 changes to the tree.  For those solutions that do not create lock files,
12676 it is possible to split the recover rules into two separate recipe
12677 commands, one of which does all work but the recursion, and the
12678 other invokes the recursive @samp{$(MAKE)}.  The solutions involving
12679 locking could act upon the contents of the @samp{MAKEFLAGS} variable,
12680 but parsing that portably is not easy (@pxref{The Make Macro MAKEFLAGS,,,
12681 autoconf, The Autoconf Manual}).  Here is an example:
12682
12683 @example
12684 ELFILES = one.el two.el three.el @dots{}
12685 ELCFILES = $(ELFILES:=c)
12686
12687 elc-stamp: $(ELFILES)
12688         @@rm -f elc-temp
12689         @@touch elc-temp
12690         $(elisp_comp) $(ELFILES)
12691         @@mv -f elc-temp $@@
12692
12693 $(ELCFILES): elc-stamp
12694 ## Recover from the removal of $@@
12695         @@dry=; for f in x $$MAKEFLAGS; do \
12696           case $$f in \
12697             *=*|--*);; \
12698             *n*) dry=:;; \
12699           esac; \
12700         done; \
12701         if test -f $@@; then :; else \
12702           $$dry trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
12703           if $$dry mkdir elc-lock 2>/dev/null; then \
12704 ## This code is being executed by the first process.
12705             $$dry rm -f elc-stamp; \
12706             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
12707             $$dry rmdir elc-lock; \
12708           else \
12709 ## This code is being executed by the follower processes.
12710 ## Wait until the first process is done.
12711             while test -d elc-lock && test -z "$$dry"; do \
12712 @c $$
12713               sleep 1; \
12714             done; \
12715 ## Succeed if and only if the first process succeeded.
12716             $$dry test -f elc-stamp; exit $$?; \
12717           fi; \
12718         fi
12719 @end example
12720
12721 For completeness it should be noted that GNU @command{make} is able to
12722 express rules with multiple output files using pattern rules
12723 (@pxref{Pattern Examples, , Pattern Rule Examples, make, The GNU Make
12724 Manual}).  We do not discuss pattern rules here because they are not
12725 portable, but they can be convenient in packages that assume GNU
12726 @command{make}.
12727
12728
12729 @node Hard-Coded Install Paths
12730 @section Installing to Hard-Coded Locations
12731
12732 @display
12733 My package needs to install some configuration file.  I tried to use
12734 the following rule, but @samp{make distcheck} fails.  Why?
12735
12736 @example
12737 # Do not do this.
12738 install-data-local:
12739         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
12740 @end example
12741 @end display
12742
12743 @display
12744 My package needs to populate the installation directory of another
12745 package at install-time.  I can easily compute that installation
12746 directory in @file{configure}, but if I install files therein,
12747 @samp{make distcheck} fails.  How else should I do?
12748 @end display
12749
12750 These two setups share their symptoms: @samp{make distcheck} fails
12751 because they are installing files to hard-coded paths.  In the later
12752 case the path is not really hard-coded in the package, but we can
12753 consider it to be hard-coded in the system (or in whichever tool that
12754 supplies the path).  As long as the path does not use any of the
12755 standard directory variables (@samp{$(prefix)}, @samp{$(bindir)},
12756 @samp{$(datadir)}, etc.), the effect will be the same:
12757 user-installations are impossible.
12758
12759 As a (non-root) user who wants to install a package, you usually have no
12760 right to install anything in @file{/usr} or @file{/usr/local}.  So you
12761 do something like @samp{./configure --prefix ~/usr} to install a
12762 package in your own @file{~/usr} tree.
12763
12764 If a package attempts to install something to some hard-coded path
12765 (e.g., @file{/etc/afile}), regardless of this @option{--prefix} setting,
12766 then the installation will fail.  @samp{make distcheck} performs such
12767 a @option{--prefix} installation, hence it will fail too.
12768
12769 Now, there are some easy solutions.
12770
12771 The above @code{install-data-local} example for installing
12772 @file{/etc/afile} would be better replaced by
12773
12774 @example
12775 sysconf_DATA = afile
12776 @end example
12777
12778 @noindent
12779 by default @code{sysconfdir} will be @samp{$(prefix)/etc}, because
12780 this is what the GNU Standards require.  When such a package is
12781 installed on an FHS compliant system, the installer will have to set
12782 @samp{--sysconfdir=/etc}.  As the maintainer of the package you
12783 should not be concerned by such site policies: use the appropriate
12784 standard directory variable to install your files so that the installer
12785 can easily redefine these variables to match their site conventions.
12786
12787 Installing files that should be used by another package is slightly
12788 more involved.  Let's take an example and assume you want to install
12789 a shared library that is a Python extension module.  If you ask Python
12790 where to install the library, it will answer something like this:
12791
12792 @example
12793 % @kbd{python -c 'from distutils import sysconfig;
12794              print sysconfig.get_python_lib(1,0)'}
12795 /usr/lib/python2.5/site-packages
12796 @end example
12797
12798 If you indeed use this absolute path to install your shared library,
12799 non-root users will not be able to install the package, hence
12800 distcheck fails.
12801
12802 Let's do better.  The @samp{sysconfig.get_python_lib()} function
12803 actually accepts a third argument that will replace Python's
12804 installation prefix.
12805
12806 @example
12807 % @kbd{python -c 'from distutils import sysconfig;
12808              print sysconfig.get_python_lib(1,0,"$@{exec_prefix@}")'}
12809 $@{exec_prefix@}/lib/python2.5/site-packages
12810 @end example
12811
12812 You can also use this new path.  If you do
12813 @itemize @bullet
12814 @item
12815 root users can install your package with the same @option{--prefix}
12816 as Python (you get the behavior of the previous attempt)
12817
12818 @item
12819 non-root users can install your package too, they will have the
12820 extension module in a place that is not searched by Python but they
12821 can work around this using environment variables (and if you installed
12822 scripts that use this shared library, it's easy to tell Python were to
12823 look in the beginning of your script, so the script works in both
12824 cases).
12825 @end itemize
12826
12827 The @code{AM_PATH_PYTHON} macro uses similar commands to define
12828 @samp{$(pythondir)} and @samp{$(pyexecdir)} (@pxref{Python}).
12829
12830 Of course not all tools are as advanced as Python regarding that
12831 substitution of @var{prefix}.  So another strategy is to figure the
12832 part of the installation directory that must be preserved.  For
12833 instance, here is how @code{AM_PATH_LISPDIR} (@pxref{Emacs Lisp})
12834 computes @samp{$(lispdir)}:
12835
12836 @example
12837 $EMACS -batch -q -eval '(while load-path
12838   (princ (concat (car load-path) "\n"))
12839   (setq load-path (cdr load-path)))' >conftest.out
12840 lispdir=`sed -n
12841   -e 's,/$,,'
12842   -e '/.*\/lib\/x*emacs\/site-lisp$/@{
12843         s,.*/lib/\(x*emacs/site-lisp\)$,$@{libdir@}/\1,;p;q;
12844       @}'
12845   -e '/.*\/share\/x*emacs\/site-lisp$/@{
12846         s,.*/share/\(x*emacs/site-lisp\),$@{datarootdir@}/\1,;p;q;
12847       @}'
12848   conftest.out`
12849 @end example
12850
12851 I.e., it just picks the first directory that looks like
12852 @file{*/lib/*emacs/site-lisp} or @file{*/share/*emacs/site-lisp} in
12853 the search path of emacs, and then substitutes @samp{$@{libdir@}} or
12854 @samp{$@{datadir@}} appropriately.
12855
12856 The emacs case looks complicated because it processes a list and
12857 expects two possible layouts, otherwise it's easy, and the benefits for
12858 non-root users are really worth the extra @command{sed} invocation.
12859
12860
12861 @node Debugging Make Rules
12862 @section Debugging Make Rules
12863 @cindex debugging rules
12864 @cindex rules, debugging
12865
12866 The rules and dependency trees generated by @command{automake} can get
12867 rather complex, and leave the developer head-scratching when things
12868 don't work as expected.  Besides the debug options provided by the
12869 @command{make} command (@pxref{Options Summary,,, make, The GNU Make
12870 Manual}), here's a couple of further hints for debugging makefiles
12871 generated by @command{automake} effectively:
12872
12873 @itemize
12874 @item
12875 If less verbose output has been enabled in the package with the use
12876 of silent rules (@pxref{Automake Silent Rules}), you can use
12877 @code{make V=1} to see the commands being executed.
12878 @item
12879 @code{make -n} can help show what would be done without actually doing
12880 it.  Note however, that this will @emph{still execute} commands prefixed
12881 with @samp{+}, and, when using GNU @command{make}, commands that contain
12882 the strings @samp{$(MAKE)} or @samp{$@{MAKE@}} (@pxref{Instead of
12883 Execution,,, make, The GNU Make Manual}).
12884 Typically, this is helpful to show what recursive rules would do, but it
12885 means that, in your own rules, you should not mix such recursion with
12886 actions that change any files.@footnote{Automake's @samp{dist} and
12887 @samp{distcheck} rules had a bug in this regard in that they created
12888 directories even with @option{-n}, but this has been fixed in Automake
12889 1.11.}  Furthermore, note that GNU @command{make} will update
12890 prerequisites for the @file{Makefile} file itself even with @option{-n}
12891 (@pxref{Remaking Makefiles,,, make, The GNU Make Manual}).
12892 @item
12893 @code{make SHELL="/bin/bash -vx"} can help debug complex rules.
12894 @xref{The Make Macro SHELL,,, autoconf, The Autoconf Manual}, for some
12895 portability quirks associated with this construct.
12896 @item
12897 @code{echo 'print: ; @@echo "$(VAR)"' | make -f Makefile -f - print}
12898 can be handy to examine the expanded value of variables.  You may need
12899 to use a target other than @samp{print} if that is already used or a
12900 file with that name exists.
12901 @item
12902 @url{http://bashdb.sourceforge.net/@/remake/} provides a modified
12903 GNU @command{make} command called @command{remake} that copes with
12904 complex GNU @command{make}-specific Makefiles and allows to trace
12905 execution, examine variables, and call rules interactively, much like
12906 a debugger.
12907 @end itemize
12908
12909
12910 @node Reporting Bugs
12911 @section Reporting Bugs
12912
12913 Most nontrivial software has bugs.  Automake is no exception.  Although
12914 we cannot promise we can or will fix a bug, and we might not even agree
12915 that it is a bug, we want to hear about problems you encounter. Often we
12916 agree they are bugs and want to fix them.
12917
12918 To make it possible for us to fix a bug, please report it. In order to
12919 do so effectively, it helps to know when and how to do it.
12920
12921 Before reporting a bug, it is a good idea to see if it is already known.
12922 You can look at the @uref{http://debbugs.gnu.org/, GNU Bug Tracker}
12923 and the @uref{http://lists.gnu.org/@/archive/@/html/@/bug-automake/,
12924 bug-automake mailing list archives} for previous bug reports.  We
12925 previously used a
12926 @uref{http://sourceware.org/@/cgi-bin/@/gnatsweb.pl?database=automake,
12927 Gnats database} for bug tracking, so some bugs might have been reported
12928 there already.  Please do not use it for new bug reports, however.
12929
12930 If the bug is not already known, it should be reported.  It is very
12931 important to report bugs in a way that is useful and efficient.  For
12932 this, please familiarize yourself with
12933 @uref{http://www.chiark.greenend.org.uk/@/~sgtatham/@/bugs.html, How to
12934 Report Bugs Effectively} and
12935 @uref{http://catb.org/@/~esr/@/faqs/@/smart-questions.html, How to Ask
12936 Questions the Smart Way}.  This helps you and developers to save time
12937 which can then be spent on fixing more bugs and implementing more
12938 features.
12939
12940 For a bug report, a feature request or other suggestions, please send
12941 email to @email{@value{PACKAGE_BUGREPORT}}.  This will then open a new
12942 bug in the @uref{http://debbugs.gnu.org/@/automake, bug tracker}.  Be
12943 sure to include the versions of Autoconf and Automake that you use.
12944 Ideally, post a minimal @file{Makefile.am} and @file{configure.ac} that
12945 reproduces the problem you encounter.  If you have encountered test
12946 suite failures, please attach the @file{test-suite.log} file.
12947
12948 @c ========================================================== Appendices
12949
12950 @page
12951 @node Copying This Manual
12952 @appendix Copying This Manual
12953
12954 @menu
12955 * GNU Free Documentation License::  License for copying this manual
12956 @end menu
12957
12958 @node GNU Free Documentation License
12959 @appendixsec GNU Free Documentation License
12960 @include fdl.texi
12961
12962 @page
12963 @node Indices
12964 @appendix Indices
12965
12966 @menu
12967 * Macro Index::                 Index of Autoconf macros
12968 * Variable Index::              Index of Makefile variables
12969 * General Index::               General index
12970 @end menu
12971
12972 @node Macro Index
12973 @appendixsec Macro Index
12974
12975 @printindex fn
12976
12977 @node Variable Index
12978 @appendixsec Variable Index
12979
12980 @printindex vr
12981
12982 @node General Index
12983 @appendixsec General Index
12984
12985 @printindex cp
12986
12987
12988 @bye
12989
12990 @c  LocalWords:  texinfo setfilename settitle setchapternewpage texi direntry
12991 @c  LocalWords:  dircategory in's aclocal ifinfo titlepage Tromey vskip pt sp
12992 @c  LocalWords:  filll defcodeindex ov cv op tr syncodeindex fn cp vr ifnottex
12993 @c  LocalWords:  dir Automake's ac Dist Gnits gnits dfn Autoconf's pxref
12994 @c  LocalWords:  cindex Autoconf autoconf perl samp cvs dist trindex SUBST foo
12995 @c  LocalWords:  xs emph FIXME ref vindex pkglibdir pkgincludedir pkgdatadir mt
12996 @c  LocalWords:  pkg libdir cpio bindir sbindir rmt pax sbin zar zardir acindex
12997 @c  LocalWords:  HTML htmldir html noinst TEXINFOS nodist nobase strudel CFLAGS
12998 @c  LocalWords:  libmumble CC YFLAGS itemx de fication config url comp
12999 @c  LocalWords:  depcomp elisp sh mdate mkinstalldirs mkdir py tex dvi ps pdf
13000 @c  LocalWords:  ylwrap zardoz INIT gettext acinclude mv FUNCS LIBOBJS LDADD fr
13001 @c  LocalWords:  uref featureful dnl src LINGUAS es ko nl pl sl sv PROG ISC doc
13002 @c  LocalWords:  POSIX STDC fcntl FUNC ALLOCA blksize struct stat intl po chmod
13003 @c  LocalWords:  ChangeLog SUBDIRS gettextize gpl testdata getopt INTLLIBS cpp
13004 @c  LocalWords:  localedir datadir DLOCALEDIR DEXIT CPPFLAGS autoreconf opindex
13005 @c  LocalWords:  AUX var symlink deps Wno Wnone package's aclocal's distclean
13006 @c  LocalWords:  ltmain xref LIBSOURCE LIBSOURCES LIBOBJ MEMCMP vs RANLIB CXX
13007 @c  LocalWords:  LDFLAGS LIBTOOL libtool XTRA LIBS gettext's acdir APIVERSION
13008 @c  LocalWords:  dirlist noindent usr TIOCGWINSZ sc
13009 @c  LocalWords:  GWINSZ termios SRCDIR tarball bzip LISPDIR lispdir XEmacs CCAS
13010 @c  LocalWords:  emacsen MicroEmacs CCASFLAGS UX GCJ gcj GCJFLAGS posix DMALLOC
13011 @c  LocalWords:  dmalloc ldmalloc REGEX regex DEPDIR DEP DEFUN aclocaldir fi
13012 @c  LocalWords:  mymacro myothermacro AMFLAGS autopoint autogen libtoolize yum
13013 @c  LocalWords:  autoheader README MAKEFLAGS subdir Inetutils sync COND endif
13014 @c  LocalWords:  Miller's installable includedir inc pkgdata EXEEXT libexec bsd
13015 @c  LocalWords:  pkglib libexecdir prog libcpio cpio's dlopen dlpreopen linux
13016 @c  LocalWords:  subsubsection OBJEXT esac lib LTLIBRARIES liblob LIBADD AR ar
13017 @c  LocalWords:  ARFLAGS cru ing maude libgettext lo LTLIBOBJS rpath SGI PRE yy
13018 @c  LocalWords:  libmaude CCLD CXXFLAGS FFLAGS LFLAGS OBJCFLAGS RFLAGS DEFS cc
13019 @c  LocalWords:  OBJCXXFLAGS
13020 @c  LocalWords:  SHORTNAME vtable srcdir nostdinc basename yxx cxx ll lxx gdb
13021 @c  LocalWords:  lexers yymaxdepth maxdepth yyparse yylex yyerror yylval lval
13022 @c  LocalWords:  yychar yydebug yypact yyr yydef def yychk chk yypgo pgo yyact
13023 @c  LocalWords:  yyexca exca yyerrflag errflag yynerrs nerrs yyps yypv pv yys
13024 @c  LocalWords:  yystate yytmp tmp yyv yyval val yylloc lloc yyreds yytoks toks
13025 @c  LocalWords:  yylhs yylen yydefred yydgoto yysindex yyrindex yygindex yyname
13026 @c  LocalWords:  yytable yycheck yyrule byacc CXXCOMPILE CXXLINK FLINK cfortran
13027 @c  LocalWords:  Catalogue preprocessable FLIBS libfoo baz JAVACFLAGS java exe
13028 @c  LocalWords:  SunOS fying basenames exeext uninstalled oldinclude kr FSF's
13029 @c  LocalWords:  pkginclude oldincludedir sysconf sharedstate localstate gcc rm
13030 @c  LocalWords:  sysconfdir sharedstatedir localstatedir preexist CLEANFILES gz
13031 @c  LocalWords:  depfile tmpdepfile depmode const interoperate
13032 @c  LocalWords:  JAVAC javac JAVAROOT builddir CLASSPATH ENV pyc pyo pkgpython
13033 @c  LocalWords:  pyexecdir pkgpyexecdir Python's pythondir pkgpythondir txi ois
13034 @c  LocalWords:  installinfo vers MAKEINFO makeinfo MAKEINFOFLAGS noinstall rf
13035 @c  LocalWords:  mandir thesame alsothesame installman myexecbin DESTDIR Pinard
13036 @c  LocalWords:  uninstall installdirs uninstalls MOSTLYCLEANFILES mostlyclean
13037 @c  LocalWords:  DISTCLEANFILES MAINTAINERCLEANFILES GZIP gzip shar exp
13038 @c  LocalWords:  distdir distcheck distcleancheck listfiles distuninstallcheck
13039 @c  LocalWords:  VPATH tarfile stdout XFAIL DejaGnu dejagnu DEJATOOL runtest ln
13040 @c  LocalWords:  RUNTESTDEFAULTFLAGS toolchain RUNTESTFLAGS asis readme DVIPS
13041 @c  LocalWords:  installcheck gzipped tarZ std utils etags mkid cd
13042 @c  LocalWords:  ARGS taggable ETAGSFLAGS lang ctags CTAGSFLAGS GTAGS gtags idl
13043 @c  LocalWords:  foocc doit idlC multilibs ABIs cmindex defmac ARG enableval FC
13044 @c  LocalWords:  MSG xtrue DBG pathchk CYGWIN afile proglink versioned CVS's TE
13045 @c  LocalWords:  wildcards Autoconfiscated subsubheading autotools Meyering API
13046 @c  LocalWords:  ois's wildcard Wportability cartouche vrindex printindex Duret
13047 @c  LocalWords:  DSOMEFLAG DVERSION automake Lutz insertcopying versioning FAQ
13048 @c  LocalWords:  LTLIBOBJ Libtool's libtool's libltdl dlopening itutions libbar
13049 @c  LocalWords:  WANTEDLIBS libhello sublibraries libtop libsub dlopened Ratfor
13050 @c  LocalWords:  mymodule timestamps timestamp underquoted MAKEINFOHTMLFLAGS te
13051 @c  LocalWords:  GNUmakefile Subpackages subpackage's subpackages aux
13052 @c  LocalWords:  detailmenu Timeline pwd reldir AUTOM autom PREREQ FOOBAR libc
13053 @c  LocalWords:  libhand subpackage moduleN libmain libmisc FCFLAGS FCCOMPILE
13054 @c  LocalWords:  FCLINK subst sed ELCFILES elc MAKEINFOHTML dvips esyscmd ustar
13055 @c  LocalWords:  tarballs Woverride vfi ELFILES djm AutoMake honkin FSF
13056 @c  LocalWords:  fileutils precanned MacKenzie's reimplement termutils Tromey's
13057 @c  LocalWords:  cois gnitsians LIBPROGRAMS progs LIBLIBRARIES Textutils Ulrich
13058 @c  LocalWords:  Matzigkeit Drepper's Gord Matzigkeit's jm Dalley Debian org
13059 @c  LocalWords:  Administrivia ILU CORBA Sourceware Molenda sourceware Elliston
13060 @c  LocalWords:  dep Oliva Akim Demaille Aiieeee Demaillator Akim's sourcequake
13061 @c  LocalWords:  grep backported screenshots libgcj KB unnumberedsubsubsec pre
13062 @c  LocalWords:  precomputing hacky makedepend inline clearmake LD PRELOAD Rel
13063 @c  LocalWords:  syscalls perlhist acl pm multitable headitem fdl appendixsec
13064 @c  LocalWords:  LTALLOCA MALLOC malloc memcmp strdup alloca libcompat xyz DFOO
13065 @c  LocalWords:  unprefixed buildable preprocessed DBAZ DDATADIR WARNINGCFLAGS
13066 @c  LocalWords:  LIBFOOCFLAGS LIBFOOLDFLAGS ftable testSubDir obj LIBTOOLFLAGS
13067 @c  LocalWords:  barexec Pinard's automatize initialize lzip xz cscope