lint: recipes of syntax check require GNU grep; ensure it is used
[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-2013 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 @author Ralf Wildenhues
57 @author Stefano Lattarini
58 @page
59 @vskip 0pt plus 1filll
60 @insertcopying
61 @end titlepage
62
63 @contents
64
65 @c We use the following macros to define indices:
66 @c   @cindex   concepts, and anything that does not fit elsewhere
67 @c   @vindex   Makefile variables
68 @c   @trindex  targets
69 @c   @acindex  Autoconf/Automake/Libtool/M4/... macros
70 @c   @opindex  tool options
71
72 @c Define an index of configure macros.
73 @defcodeindex ac
74 @c Define an index of options.
75 @defcodeindex op
76 @c Define an index of targets.
77 @defcodeindex tr
78 @c Define an index of commands.
79 @defcodeindex cm
80
81 @c Put the macros in the function index.
82 @syncodeindex ac fn
83
84 @c Put everything else into one index (arbitrarily chosen to be the
85 @c concept index).
86 @syncodeindex op cp
87 @syncodeindex tr cp
88 @syncodeindex cm cp
89
90 @ifnottex
91 @node Top
92 @comment  node-name,  next,  previous,  up
93 @top GNU Automake
94
95 @insertcopying
96
97 @menu
98 * Introduction::                Automake's purpose
99 * Autotools Introduction::      An Introduction to the Autotools
100 * Generalities::                General ideas
101 * Examples::                    Some example packages
102 * automake Invocation::         Creating a Makefile.in
103 * configure::                   Scanning configure.ac, using aclocal
104 * Directories::                 Declaring subdirectories
105 * Programs::                    Building programs and libraries
106 * Other Objects::               Other derived objects
107 * Other GNU Tools::             Other GNU Tools
108 * Documentation::               Building documentation
109 * Install::                     What gets installed
110 * Clean::                       What gets cleaned
111 * Dist::                        What goes in a distribution
112 * Tests::                       Support for test suites
113 * Rebuilding::                  Automatic rebuilding of Makefile
114 * Options::                     Changing Automake's behavior
115 * Miscellaneous::               Miscellaneous rules
116 * Include::                     Including extra files in an Automake template
117 * Conditionals::                Conditionals
118 * Silencing Make::              Obtain less verbose output from @command{make}
119 * Gnits::                       The effect of @option{--gnu} and @option{--gnits}
120 * Not Enough::                  When Automake is not Enough
121 * Distributing::                Distributing the Makefile.in
122 * API Versioning::              About compatibility between Automake versions
123 * Upgrading::                   Upgrading to a Newer Automake Version
124 * FAQ::                         Frequently Asked Questions
125 * Copying This Manual::         How to make copies of this manual
126 * Indices::                     Indices of variables, macros, and concepts
127
128 @detailmenu
129  --- The Detailed Node Listing ---
130
131 An Introduction to the Autotools
132
133 * GNU Build System::            Introducing the GNU Build System
134 * Use Cases::                   Use Cases for the GNU Build System
135 * Why Autotools::               How Autotools Help
136 * Hello World::                 A Small Hello World Package
137
138 Use Cases for the GNU Build System
139
140 * Basic Installation::          Common installation procedure
141 * Standard Targets::            A list of standard Makefile targets
142 * Standard Directory Variables::  A list of standard directory variables
143 * Standard Configuration Variables::  Using configuration variables
144 * config.site::                 Using a config.site file
145 * VPATH Builds::                Parallel build trees
146 * Two-Part Install::            Installing data and programs separately
147 * Cross-Compilation::           Building for other architectures
148 * Renaming::                    Renaming programs at install time
149 * DESTDIR::                     Building binary packages with DESTDIR
150 * Preparing Distributions::     Rolling out tarballs
151 * Dependency Tracking::         Automatic dependency tracking
152 * Nested Packages::             The GNU Build Systems can be nested
153
154 A Small Hello World
155
156 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
157 * amhello's configure.ac Setup Explained::
158 * amhello's Makefile.am Setup Explained::
159
160 General ideas
161
162 * General Operation::           General operation of Automake
163 * Strictness::                  Standards conformance checking
164 * Uniform::                     The Uniform Naming Scheme
165 * Length Limitations::          Staying below the command line length limit
166 * Canonicalization::            How derived variables are named
167 * User Variables::              Variables reserved for the user
168 * Auxiliary Programs::          Programs automake might require
169
170 Some example packages
171
172 * Complete::                    A simple example, start to finish
173 * true::                        Building true and false
174
175 Scanning @file{configure.ac}, using @command{aclocal}
176
177 * Requirements::                Configuration requirements
178 * Optional::                    Other things Automake recognizes
179 * aclocal Invocation::          Auto-generating aclocal.m4
180 * Macros::                      Autoconf macros supplied with Automake
181
182 Auto-generating aclocal.m4
183
184 * aclocal Options::             Options supported by aclocal
185 * Macro Search Path::           How aclocal finds .m4 files
186 * Extending aclocal::           Writing your own aclocal macros
187 * Local Macros::                Organizing local macros
188 * Serials::                     Serial lines in Autoconf macros
189 * Future of aclocal::           aclocal's scheduled death
190
191 Autoconf macros supplied with Automake
192
193 * Public Macros::               Macros that you can use.
194 * Private Macros::              Macros that you should not use.
195
196 Directories
197
198 * Subdirectories::              Building subdirectories recursively
199 * Conditional Subdirectories::  Conditionally not building directories
200 * Alternative::                 Subdirectories without recursion
201 * Subpackages::                 Nesting packages
202
203 Conditional Subdirectories
204
205 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
206 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
207 * Subdirectories with AC_SUBST::  Another way for conditional recursion
208 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
209
210 Building Programs and Libraries
211
212 * A Program::                   Building a program
213 * A Library::                   Building a library
214 * A Shared Library::            Building a Libtool library
215 * Program and Library Variables::  Variables controlling program and
216                                 library builds
217 * Default _SOURCES::            Default source files
218 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
219 * Program Variables::           Variables used when building a program
220 * Yacc and Lex::                Yacc and Lex support
221 * C++ Support::                 Compiling C++ sources
222 * Objective C Support::         Compiling Objective C sources
223 * Objective C++ Support::       Compiling Objective C++ sources
224 * Unified Parallel C Support::  Compiling Unified Parallel C sources
225 * Assembly Support::            Compiling assembly sources
226 * Fortran 77 Support::          Compiling Fortran 77 sources
227 * Fortran 9x Support::          Compiling Fortran 9x sources
228 * Java Support with gcj::       Compiling Java sources using gcj
229 * Vala Support::                Compiling Vala sources
230 * Support for Other Languages::  Compiling other languages
231 * Dependencies::                Automatic dependency tracking
232 * EXEEXT::                      Support for executable extensions
233
234 Building a program
235
236 * Program Sources::             Defining program sources
237 * Linking::                     Linking with libraries or extra objects
238 * Conditional Sources::         Handling conditional sources
239 * Conditional Programs::        Building a program conditionally
240
241 Building a Shared Library
242
243 * Libtool Concept::             Introducing Libtool
244 * Libtool Libraries::           Declaring Libtool Libraries
245 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
246 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
247 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
248 * Libtool Modules::             Building Libtool Modules
249 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
250 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
251 * Libtool Issues::              Common Issues Related to Libtool's Use
252
253 Common Issues Related to Libtool's Use
254
255 * Error required file ltmain.sh not found::  The need to run libtoolize
256 * Objects created both with libtool and without::  Avoid a specific build race
257
258 Fortran 77 Support
259
260 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
261 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
262 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
263
264 Mixing Fortran 77 With C and C++
265
266 * How the Linker is Chosen::    Automatic linker selection
267
268 Fortran 9x Support
269
270 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
271
272 Other Derived Objects
273
274 * Scripts::                     Executable scripts
275 * Headers::                     Header files
276 * Data::                        Architecture-independent data files
277 * Sources::                     Derived sources
278
279 Built Sources
280
281 * Built Sources Example::       Several ways to handle built sources.
282
283 Other GNU Tools
284
285 * Emacs Lisp::                  Emacs Lisp
286 * gettext::                     Gettext
287 * Libtool::                     Libtool
288 * Java::                        Java bytecode compilation (deprecated)
289 * Python::                      Python
290
291 Building documentation
292
293 * Texinfo::                     Texinfo
294 * Man Pages::                   Man pages
295
296 What Gets Installed
297
298 * Basics of Installation::      What gets installed where
299 * The Two Parts of Install::    Installing data and programs separately
300 * Extending Installation::      Adding your own rules for installation
301 * Staged Installs::             Installation in a temporary location
302 * Install Rules for the User::  Useful additional rules
303
304 What Goes in a Distribution
305
306 * Basics of Distribution::      Files distributed by default
307 * Fine-grained Distribution Control::  @code{dist_} and @code{nodist_} prefixes
308 * The dist Hook::               A target for last-minute distribution changes
309 * Checking the Distribution::   @samp{make distcheck} explained
310 * The Types of Distributions::  A variety of formats and compression methods
311
312 Support for test suites
313
314 * Generalities about Testing::  Generic concepts and terminology about testing
315 * Simple Tests::                Listing test scripts in @code{TESTS}
316 * Custom Test Drivers::         Writing and using custom test drivers
317 * Using the TAP test protocol:: Integrating test scripts that use the TAP protocol
318 * DejaGnu Tests::               Interfacing with the @command{dejagnu} testing framework
319 * Install Tests::               Running tests on installed packages
320
321 Simple Tests
322
323 * Scripts-based Testsuites::    Automake-specific concepts and terminology
324 * Serial Test Harness::         Older (and discouraged) serial test harness
325 * Parallel Test Harness::       Generic concurrent test harness
326
327 Using the TAP test protocol
328
329 * Introduction to TAP::
330 * Use TAP with the Automake test harness::
331 * Incompatibilities with other TAP parsers and drivers::
332 * Links and external resources on TAP::
333
334 Custom Test Drivers
335
336 * Overview of Custom Test Drivers Support::
337 * Declaring Custom Test Drivers::
338 * API for Custom Test Drivers::
339
340 API for Custom Test Drivers
341
342 * Command-line arguments for test drivers::
343 * Log files generation and test results recording::
344 * Testsuite progress output::
345
346 Changing Automake's Behavior
347
348 * Options generalities::        Semantics of Automake option
349 * List of Automake options::    A comprehensive list of Automake options
350
351 Miscellaneous Rules
352
353 * Tags::                        Interfacing to cscope, etags and mkid
354 * Suffixes::                    Handling new file extensions
355
356 Conditionals
357
358 * Usage of Conditionals::       Declaring conditional content
359 * Limits of Conditionals::      Enclosing complete statements
360
361 Silencing Make
362
363 * Make verbosity::              Make is verbose by default
364 * Tricks For Silencing Make::   Standard and generic ways to silence make
365 * Automake Silent Rules::       How Automake can help in silencing make
366
367 When Automake Isn't Enough
368
369 * Extending::                   Adding new rules or overriding existing ones.
370 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
371
372 Frequently Asked Questions about Automake
373
374 * CVS::                         CVS and generated files
375 * maintainer-mode::             missing and AM_MAINTAINER_MODE
376 * Wildcards::                   Why doesn't Automake support wildcards?
377 * Limitations on File Names::   Limitations on source and installed file names
378 * Errors with distclean::       Files left in build directory after distclean
379 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
380 * Renamed Objects::             Why are object files sometimes renamed?
381 * Per-Object Flags::            How to simulate per-object flags?
382 * Multiple Outputs::            Writing rules for tools with many output files
383 * Hard-Coded Install Paths::    Installing to hard-coded locations
384 * Debugging Make Rules::        Strategies when things don't work as expected
385 * Reporting Bugs::              Feedback on bugs and feature requests
386
387 Copying This Manual
388
389 * GNU Free Documentation License::  License for copying this manual
390
391 Indices
392
393 * Macro Index::                 Index of Autoconf macros
394 * Variable Index::              Index of Makefile variables
395 * General Index::               General index
396
397 @end detailmenu
398 @end menu
399
400 @end ifnottex
401
402
403 @node Introduction
404 @chapter Introduction
405
406 Automake is a tool for automatically generating @file{Makefile.in}s
407 from files called @file{Makefile.am}.  Each @file{Makefile.am} is
408 basically a series of @command{make} variable
409 definitions@footnote{These variables are also called @dfn{make macros}
410 in Make terminology, however in this manual we reserve the term
411 @dfn{macro} for Autoconf's macros.}, with rules being thrown in
412 occasionally.  The generated @file{Makefile.in}s are compliant with
413 the GNU Makefile standards.
414
415 @cindex GNU Makefile standards
416
417 The GNU Makefile Standards Document
418 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
419 is long, complicated, and subject to change.  The goal of Automake is to
420 remove the burden of Makefile maintenance from the back of the
421 individual GNU maintainer (and put it on the back of the Automake
422 maintainers).
423
424 The typical Automake input file is simply a series of variable definitions.
425 Each such file is processed to create a @file{Makefile.in}.
426
427 @cindex Constraints of Automake
428 @cindex Automake constraints
429
430 Automake does constrain a project in certain ways; for instance, it
431 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
432 autoconf, The Autoconf Manual}), and enforces certain restrictions on
433 the @file{configure.ac} contents.
434
435 @cindex Automake requirements
436 @cindex Requirements, Automake
437
438 Automake requires @command{perl} in order to generate the
439 @file{Makefile.in}s.  However, the distributions created by Automake are
440 fully GNU standards-compliant, and do not require @command{perl} in order
441 to be built.
442
443 @cindex Bugs, reporting
444 @cindex Reporting bugs
445 @cindex E-mail, bug reports
446
447 For more information on bug reports, @xref{Reporting Bugs}.
448
449 @node Autotools Introduction
450 @chapter An Introduction to the Autotools
451
452 If you are new to Automake, maybe you know that it is part of a set of
453 tools called @emph{The Autotools}.  Maybe you've already delved into a
454 package full of files named @file{configure}, @file{configure.ac},
455 @file{Makefile.in}, @file{Makefile.am}, @file{aclocal.m4}, @dots{},
456 some of them claiming to be @emph{generated by} Autoconf or Automake.
457 But the exact purpose of these files and their relations is probably
458 fuzzy.  The goal of this chapter is to introduce you to this machinery,
459 to show you how it works and how powerful it is.  If you've never
460 installed or seen such a package, do not worry: this chapter will walk
461 you through it.
462
463 If you need some teaching material, more illustrations, or a less
464 @command{automake}-centered continuation, some slides for this
465 introduction are available in Alexandre Duret-Lutz's
466 @uref{http://www.lrde.epita.fr/@/~adl/@/autotools.html,
467 Autotools Tutorial}.
468 This chapter is the written version of the first part of his tutorial.
469
470 @menu
471 * GNU Build System::            Introducing the GNU Build System
472 * Use Cases::                   Use Cases for the GNU Build System
473 * Why Autotools::               How Autotools Help
474 * Hello World::                 A Small Hello World Package
475 @end menu
476
477 @node GNU Build System
478 @section Introducing the GNU Build System
479 @cindex GNU Build System, introduction
480
481 It is a truth universally acknowledged, that as a developer in
482 possession of a new package, you must be in want of a build system.
483
484 In the Unix world, such a build system is traditionally achieved using
485 the command @command{make} (@pxref{Top, , Overview, make, The GNU Make
486 Manual}).  You express the recipe to build your package in a
487 @file{Makefile}.  This file is a set of rules to build the files in
488 the package.  For instance the program @file{prog} may be built by
489 running the linker on the files @file{main.o}, @file{foo.o}, and
490 @file{bar.o}; the file @file{main.o} may be built by running the
491 compiler on @file{main.c}; etc.  Each time @command{make} is run, it
492 reads @file{Makefile}, checks the existence and modification time of
493 the files mentioned, decides what files need to be built (or rebuilt),
494 and runs the associated commands.
495
496 When a package needs to be built on a different platform than the one
497 it was developed on, its @file{Makefile} usually needs to be adjusted.
498 For instance the compiler may have another name or require more
499 options.  In 1991, David J. MacKenzie got tired of customizing
500 @file{Makefile} for the 20 platforms he had to deal with.  Instead, he
501 handcrafted a little shell script called @file{configure} to
502 automatically adjust the @file{Makefile} (@pxref{Genesis, , Genesis,
503 autoconf, The Autoconf Manual}).  Compiling his package was now
504 as simple as running @code{./configure && make}.
505
506 @cindex GNU Coding Standards
507
508 Today this process has been standardized in the GNU project.  The GNU
509 Coding Standards (@pxref{Managing Releases, The Release Process, ,
510 standards, The GNU Coding Standards}) explains how each package of the
511 GNU project should have a @file{configure} script, and the minimal
512 interface it should have.  The @file{Makefile} too should follow some
513 established conventions.  The result?  A unified build system that
514 makes all packages almost indistinguishable by the installer.  In its
515 simplest scenario, all the installer has to do is to unpack the
516 package, run @code{./configure && make && make install}, and repeat
517 with the next package to install.
518
519 We call this build system the @dfn{GNU Build System}, since it was
520 grown out of the GNU project.  However it is used by a vast number of
521 other packages: following any existing convention has its advantages.
522
523 @cindex Autotools, introduction
524
525 The Autotools are tools that will create a GNU Build System for your
526 package.  Autoconf mostly focuses on @file{configure} and Automake on
527 @file{Makefile}s.  It is entirely possible to create a GNU Build
528 System without the help of these tools.  However it is rather
529 burdensome and error-prone.  We will discuss this again after some
530 illustration of the GNU Build System in action.
531
532 @node Use Cases
533 @section Use Cases for the GNU Build System
534 @cindex GNU Build System, use cases
535 @cindex GNU Build System, features
536 @cindex Features of the GNU Build System
537 @cindex Use Cases for the GNU Build System
538 @cindex @file{amhello-1.0.tar.gz}, location
539 @cindex @file{amhello-1.0.tar.gz}, use cases
540
541 In this section we explore several use cases for the GNU Build System.
542 You can replay all of these examples on the @file{amhello-1.0.tar.gz}
543 package distributed with Automake.  If Automake is installed on your
544 system, you should find a copy of this file in
545 @file{@var{prefix}/share/doc/automake/amhello-1.0.tar.gz}, where
546 @var{prefix} is the installation prefix specified during configuration
547 (@var{prefix} defaults to @file{/usr/local}, however if Automake was
548 installed by some GNU/Linux distribution it most likely has been set
549 to @file{/usr}).  If you do not have a copy of Automake installed,
550 you can find a copy of this file inside the @file{doc/} directory of
551 the Automake package.
552
553 Some of the following use cases present features that are in fact
554 extensions to the GNU Build System.  Read: they are not specified by
555 the GNU Coding Standards, but they are nonetheless part of the build
556 system created by the Autotools.  To keep things simple, we do not
557 point out the difference.  Our objective is to show you many of the
558 features that the build system created by the Autotools will offer to
559 you.
560
561 @menu
562 * Basic Installation::          Common installation procedure
563 * Standard Targets::            A list of standard Makefile targets
564 * Standard Directory Variables::  A list of standard directory variables
565 * Standard Configuration Variables::  Using configuration variables
566 * config.site::                 Using a config.site file
567 * VPATH Builds::                Parallel build trees
568 * Two-Part Install::            Installing data and programs separately
569 * Cross-Compilation::           Building for other architectures
570 * Renaming::                    Renaming programs at install time
571 * DESTDIR::                     Building binary packages with DESTDIR
572 * Preparing Distributions::     Rolling out tarballs
573 * Dependency Tracking::         Automatic dependency tracking
574 * Nested Packages::             The GNU Build Systems can be nested
575 @end menu
576
577 @node Basic Installation
578 @subsection Basic Installation
579 @cindex Configuration, basics
580 @cindex Installation, basics
581 @cindex GNU Build System, basics
582
583 The most common installation procedure looks as follows.
584
585 @example
586 ~ % @kbd{tar zxf amhello-1.0.tar.gz}
587 ~ % @kbd{cd amhello-1.0}
588 ~/amhello-1.0 % @kbd{./configure}
589 @dots{}
590 config.status: creating Makefile
591 config.status: creating src/Makefile
592 @dots{}
593 ~/amhello-1.0 % @kbd{make}
594 @dots{}
595 ~/amhello-1.0 % @kbd{make check}
596 @dots{}
597 ~/amhello-1.0 % @kbd{su}
598 Password:
599 /home/adl/amhello-1.0 # @kbd{make install}
600 @dots{}
601 /home/adl/amhello-1.0 # @kbd{exit}
602 ~/amhello-1.0 % @kbd{make installcheck}
603 @dots{}
604 @end example
605
606 @cindex Unpacking
607
608 The user first unpacks the package.  Here, and in the following
609 examples, we will use the non-portable @code{tar zxf} command for
610 simplicity.  On a system without GNU @command{tar} installed, this
611 command should read @code{gunzip -c amhello-1.0.tar.gz | tar xf -}.
612
613 The user then enters the newly created directory to run the
614 @file{configure} script.  This script probes the system for various
615 features, and finally creates the @file{Makefile}s.  In this toy
616 example there are only two @file{Makefile}s, but in real-world projects,
617 there may be many more, usually one @file{Makefile} per directory.
618
619 It is now possible to run @code{make}.  This will construct all the
620 programs, libraries, and scripts that need to be constructed for the
621 package.  In our example, this compiles the @file{hello} program.
622 All files are constructed in place, in the source tree; we will see
623 later how this can be changed.
624
625 @code{make check} causes the package's tests to be run.  This step is
626 not mandatory, but it is often good to make sure the programs that
627 have been built behave as they should, before you decide to install
628 them.  Our example does not contain any tests, so running @code{make
629 check} is a no-op.
630
631 @cindex su, before @code{make install}
632 After everything has been built, and maybe tested, it is time to
633 install it on the system.  That means copying the programs,
634 libraries, header files, scripts, and other data files from the
635 source directory to their final destination on the system.  The
636 command @code{make install} will do that.  However, by default
637 everything will be installed in subdirectories of @file{/usr/local}:
638 binaries will go into @file{/usr/local/bin}, libraries will end up in
639 @file{/usr/local/lib}, etc.  This destination is usually not writable
640 by any user, so we assume that we have to become root before we can
641 run @code{make install}.  In our example, running @code{make install}
642 will copy the program @file{hello} into @file{/usr/local/bin}
643 and @file{README} into @file{/usr/local/share/doc/amhello}.
644
645 A last and optional step is to run @code{make installcheck}.  This
646 command may run tests on the installed files.  @code{make check} tests
647 the files in the source tree, while @code{make installcheck} tests
648 their installed copies.  The tests run by the latter can be different
649 from those run by the former.  For instance, there are tests that
650 cannot be run in the source tree.  Conversely, some packages are set
651 up so that @code{make installcheck} will run the very same tests as
652 @code{make check}, only on different files (non-installed
653 vs.@: installed).  It can make a difference, for instance when the
654 source tree's layout is different from that of the installation.
655 Furthermore it may help to diagnose an incomplete installation.
656
657 Presently most packages do not have any @code{installcheck} tests
658 because the existence of @code{installcheck} is little known, and its
659 usefulness is neglected.  Our little toy package is no better: @code{make
660 installcheck} does nothing.
661
662 @node Standard Targets
663 @subsection Standard @file{Makefile} Targets
664
665 So far we have come across four ways to run @command{make} in the GNU
666 Build System: @code{make}, @code{make check}, @code{make install}, and
667 @code{make installcheck}.  The words @code{check}, @code{install}, and
668 @code{installcheck}, passed as arguments to @command{make}, are called
669 @dfn{targets}.  @code{make} is a shorthand for @code{make all},
670 @code{all} being the default target in the GNU Build System.
671
672 Here is a list of the most useful targets that the GNU Coding Standards
673 specify.
674
675 @table @code
676 @item make all
677 @trindex all
678 Build programs, libraries, documentation, etc.@: (same as @code{make}).
679 @item make install
680 @trindex install
681 Install what needs to be installed, copying the files from the
682 package's tree to system-wide directories.
683 @item make install-strip
684 @trindex install-strip
685 Same as @code{make install}, then strip debugging symbols.  Some
686 users like to trade space for useful bug reports@enddots{}
687 @item make uninstall
688 @trindex uninstall
689 The opposite of @code{make install}: erase the installed files.
690 (This needs to be run from the same build tree that was installed.)
691 @item make clean
692 @trindex clean
693 Erase from the build tree the files built by @code{make all}.
694 @item make distclean
695 @trindex distclean
696 Additionally erase anything @code{./configure} created.
697 @item make check
698 @trindex check
699 Run the test suite, if any.
700 @item make installcheck
701 @trindex installcheck
702 Check the installed programs or libraries, if supported.
703 @item make dist
704 @trindex dist
705 Recreate @file{@var{package}-@var{version}.tar.gz} from all the source
706 files.
707 @end table
708
709 @node Standard Directory Variables
710 @subsection Standard Directory Variables
711 @cindex directory variables
712
713 The GNU Coding Standards also specify a hierarchy of variables to
714 denote installation directories.  Some of these are:
715
716 @multitable {Directory variable} {@code{$@{datarootdir@}/doc/$@{PACKAGE@}}}
717 @headitem Directory variable    @tab Default value
718 @item @code{prefix}              @tab @code{/usr/local}
719 @item @w{@ @ @code{exec_prefix}} @tab @code{$@{prefix@}}
720 @item @w{@ @ @ @ @code{bindir}}  @tab @code{$@{exec_prefix@}/bin}
721 @item @w{@ @ @ @ @code{libdir}}  @tab @code{$@{exec_prefix@}/lib}
722 @item @w{@ @ @ @ @dots{}}
723 @item @w{@ @ @code{includedir}}  @tab @code{$@{prefix@}/include}
724 @item @w{@ @ @code{datarootdir}} @tab @code{$@{prefix@}/share}
725 @item @w{@ @ @ @ @code{datadir}} @tab @code{$@{datarootdir@}}
726 @item @w{@ @ @ @ @code{mandir}}  @tab @code{$@{datarootdir@}/man}
727 @item @w{@ @ @ @ @code{infodir}} @tab @code{$@{datarootdir@}/info}
728 @item @w{@ @ @ @ @code{docdir}}  @tab @code{$@{datarootdir@}/doc/$@{PACKAGE@}}
729 @item @w{@ @ @dots{}}
730 @end multitable
731
732 @c We should provide a complete table somewhere, but not here.  The
733 @c complete list of directory variables it too confusing as-is.  It
734 @c requires some explanations that are too complicated for this
735 @c introduction.  Besides listing directories like localstatedir
736 @c would make the explanations in ``Two-Part Install'' harder.
737
738 Each of these directories has a role which is often obvious from its
739 name.  In a package, any installable file will be installed in one of
740 these directories.  For instance in @code{amhello-1.0}, the program
741 @file{hello} is to be installed in @var{bindir}, the directory for
742 binaries.  The default value for this directory is
743 @file{/usr/local/bin}, but the user can supply a different value when
744 calling @command{configure}.  Also the file @file{README} will be
745 installed into @var{docdir}, which defaults to
746 @file{/usr/local/share/doc/amhello}.
747
748 @opindex --prefix
749
750 As a user, if you wish to install a package on your own account, you
751 could proceed as follows:
752
753 @example
754 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
755 @dots{}
756 ~/amhello-1.0 % @kbd{make}
757 @dots{}
758 ~/amhello-1.0 % @kbd{make install}
759 @dots{}
760 @end example
761
762 This would install @file{~/usr/bin/hello} and
763 @file{~/usr/share/doc/amhello/README}.
764
765 The list of all such directory options is shown by
766 @code{./configure --help}.
767
768 @node Standard Configuration Variables
769 @subsection Standard Configuration Variables
770 @cindex configuration variables, overriding
771
772 The GNU Coding Standards also define a set of standard configuration
773 variables used during the build.  Here are some:
774
775 @table @asis
776 @item @code{CC}
777 C compiler command
778 @item @code{CFLAGS}
779 C compiler flags
780 @item @code{CXX}
781 C++ compiler command
782 @item @code{CXXFLAGS}
783 C++ compiler flags
784 @item @code{LDFLAGS}
785 linker flags
786 @item @code{CPPFLAGS}
787 C/C++ preprocessor flags
788 @item @dots{}
789 @end table
790
791 @command{configure} usually does a good job at setting appropriate
792 values for these variables, but there are cases where you may want to
793 override them.  For instance you may have several versions of a
794 compiler installed and would like to use another one, you may have
795 header files installed outside the default search path of the
796 compiler, or even libraries out of the way of the linker.
797
798 Here is how one would call @command{configure} to force it to use
799 @command{gcc-3} as C compiler, use header files from
800 @file{~/usr/include} when compiling, and libraries from
801 @file{~/usr/lib} when linking.
802
803 @example
804 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
805 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
806 @end example
807
808 Again, a full list of these variables appears in the output of
809 @code{./configure --help}.
810
811 @node config.site
812 @subsection Overriding Default Configuration Setting with @file{config.site}
813 @cindex @file{config.site} example
814
815 When installing several packages using the same setup, it can be
816 convenient to create a file to capture common settings.
817 If a file named @file{@var{prefix}/share/config.site} exists,
818 @command{configure} will source it at the beginning of its execution.
819
820 Recall the command from the previous section:
821
822 @example
823 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
824 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
825 @end example
826
827 Assuming we are installing many package in @file{~/usr}, and will
828 always want to use these definitions of @code{CC}, @code{CPPFLAGS}, and
829 @code{LDFLAGS}, we can automate this by creating the following
830 @file{~/usr/share/config.site} file:
831
832 @example
833 test -z "$CC" && CC=gcc-3
834 test -z "$CPPFLAGS" && CPPFLAGS=-I$HOME/usr/include
835 test -z "$LDFLAGS" && LDFLAGS=-L$HOME/usr/lib
836 @end example
837
838 Now, any time a @file{configure} script is using the @file{~/usr}
839 prefix, it will execute the above @file{config.site} and define
840 these three variables.
841
842 @example
843 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
844 configure: loading site script /home/adl/usr/share/config.site
845 @dots{}
846 @end example
847
848 @xref{Site Defaults, , Setting Site Defaults, autoconf, The Autoconf
849 Manual}, for more information about this feature.
850
851
852 @node VPATH Builds
853 @subsection Parallel Build Trees (a.k.a.@: VPATH Builds)
854 @cindex Parallel build trees
855 @cindex VPATH builds
856 @cindex source tree and build tree
857 @cindex build tree and source tree
858 @cindex trees, source vs.@: build
859
860 The GNU Build System distinguishes two trees: the source tree, and
861 the build tree.
862
863 The source tree is rooted in the directory containing
864 @file{configure}.  It contains all the sources files (those that are
865 distributed), and may be arranged using several subdirectories.
866
867 The build tree is rooted in the directory in which @file{configure}
868 was run, and is populated with all object files, programs, libraries,
869 and other derived files built from the sources (and hence not
870 distributed).  The build tree usually has the same subdirectory layout
871 as the source tree; its subdirectories are created automatically by
872 the build system.
873
874 If @file{configure} is executed in its own directory, the source and
875 build trees are combined: derived files are constructed in the same
876 directories as their sources.  This was the case in our first
877 installation example (@pxref{Basic Installation}).
878
879 A common request from users is that they want to confine all derived
880 files to a single directory, to keep their source directories
881 uncluttered.  Here is how we could run @file{configure} to build
882 everything in a subdirectory called @file{build/}.
883
884 @example
885 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
886 ~ % @kbd{cd amhello-1.0}
887 ~/amhello-1.0 % @kbd{mkdir build && cd build}
888 ~/amhello-1.0/build % @kbd{../configure}
889 @dots{}
890 ~/amhello-1.0/build % @kbd{make}
891 @dots{}
892 @end example
893
894 These setups, where source and build trees are different, are often
895 called @dfn{parallel builds} or @dfn{VPATH builds}.  The expression
896 @emph{parallel build} is misleading: the word @emph{parallel} is a
897 reference to the way the build tree shadows the source tree, it is not
898 about some concurrency in the way build commands are run.  For this
899 reason we refer to such setups using the name @emph{VPATH builds} in
900 the following.  @emph{VPATH} is the name of the @command{make} feature
901 used by the @file{Makefile}s to allow these builds (@pxref{General
902 Search, , @code{VPATH} Search Path for All Prerequisites, make, The
903 GNU Make Manual}).
904
905 @cindex multiple configurations, example
906 @cindex debug build, example
907 @cindex optimized build, example
908
909 VPATH builds have other interesting uses.  One is to build the same
910 sources with multiple configurations.  For instance:
911
912 @c Keep in sync with amhello-cflags.sh
913 @example
914 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
915 ~ % @kbd{cd amhello-1.0}
916 ~/amhello-1.0 % @kbd{mkdir debug optim && cd debug}
917 ~/amhello-1.0/debug % @kbd{../configure CFLAGS='-g -O0'}
918 @dots{}
919 ~/amhello-1.0/debug % @kbd{make}
920 @dots{}
921 ~/amhello-1.0/debug % cd ../optim
922 ~/amhello-1.0/optim % @kbd{../configure CFLAGS='-O3 -fomit-frame-pointer'}
923 @dots{}
924 ~/amhello-1.0/optim % @kbd{make}
925 @dots{}
926 @end example
927
928 With network file systems, a similar approach can be used to build the
929 same sources on different machines.  For instance, suppose that the
930 sources are installed on a directory shared by two hosts: @code{HOST1}
931 and @code{HOST2}, which may be different platforms.
932
933 @example
934 ~ % @kbd{cd /nfs/src}
935 /nfs/src % @kbd{tar zxf ~/amhello-1.0.tar.gz}
936 @end example
937
938 On the first host, you could create a local build directory:
939 @example
940 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
941 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
942 ...
943 [HOST1] /tmp/amh % @kbd{make && sudo make install}
944 ...
945 @end example
946
947 @noindent
948 (Here we assume that the installer has configured @command{sudo} so it
949 can execute @code{make install} with root privileges; it is more convenient
950 than using @command{su} like in @ref{Basic Installation}).
951
952 On the second host, you would do exactly the same, possibly at
953 the same time:
954 @example
955 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
956 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
957 ...
958 [HOST2] /tmp/amh % @kbd{make && sudo make install}
959 ...
960 @end example
961
962 @cindex read-only source tree
963 @cindex source tree, read-only
964
965 In this scenario, nothing forbids the @file{/nfs/src/amhello-1.0}
966 directory from being read-only.  In fact VPATH builds are also a means
967 of building packages from a read-only medium such as a CD-ROM.  (The
968 FSF used to sell CD-ROM with unpacked source code, before the GNU
969 project grew so big.)
970
971 @node Two-Part Install
972 @subsection Two-Part Installation
973
974 In our last example (@pxref{VPATH Builds}), a source tree was shared
975 by two hosts, but compilation and installation were done separately on
976 each host.
977
978 The GNU Build System also supports networked setups where part of the
979 installed files should be shared amongst multiple hosts.  It does so
980 by distinguishing architecture-dependent files from
981 architecture-independent files, and providing two @file{Makefile}
982 targets to install each of these classes of files.
983
984 @trindex install-exec
985 @trindex install-data
986
987 These targets are @code{install-exec} for architecture-dependent files
988 and @code{install-data} for architecture-independent files.
989 The command we used up to now, @code{make install}, can be thought of
990 as a shorthand for @code{make install-exec install-data}.
991
992 From the GNU Build System point of view, the distinction between
993 architecture-dependent files and architecture-independent files is
994 based exclusively on the directory variable used to specify their
995 installation destination.  In the list of directory variables we
996 provided earlier (@pxref{Standard Directory Variables}), all the
997 variables based on @var{exec-prefix} designate architecture-dependent
998 directories whose files will be installed by @code{make install-exec}.
999 The others designate architecture-independent directories and will
1000 serve files installed by @code{make install-data}.  @xref{The Two Parts
1001 of Install}, for more details.
1002
1003 Here is how we could revisit our two-host installation example,
1004 assuming that (1) we want to install the package directly in
1005 @file{/usr}, and (2) the directory @file{/usr/share} is shared by the
1006 two hosts.
1007
1008 On the first host we would run
1009 @example
1010 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1011 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1012 ...
1013 [HOST1] /tmp/amh % @kbd{make && sudo make install}
1014 ...
1015 @end example
1016
1017 On the second host, however, we need only install the
1018 architecture-specific files.
1019 @example
1020 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1021 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1022 ...
1023 [HOST2] /tmp/amh % @kbd{make && sudo make install-exec}
1024 ...
1025 @end example
1026
1027 In packages that have installation checks, it would make sense to run
1028 @code{make installcheck} (@pxref{Basic Installation}) to verify that
1029 the package works correctly despite the apparent partial installation.
1030
1031 @node Cross-Compilation
1032 @subsection Cross-Compilation
1033 @cindex cross-compilation
1034
1035 To @dfn{cross-compile} is to build on one platform a binary that will
1036 run on another platform.  When speaking of cross-compilation, it is
1037 important to distinguish between the @dfn{build platform} on which
1038 the compilation is performed, and the @dfn{host platform} on which the
1039 resulting executable is expected to run.  The following
1040 @command{configure} options are used to specify each of them:
1041
1042 @table @option
1043 @item --build=@var{build}
1044 @opindex --build=@var{build}
1045 The system on which the package is built.
1046 @item --host=@var{host}
1047 @opindex --host=@var{host}
1048 The system where built programs and libraries will run.
1049 @end table
1050
1051 When the @option{--host} is used, @command{configure} will search for
1052 the cross-compiling suite for this platform.  Cross-compilation tools
1053 commonly have their target architecture as prefix of their name.  For
1054 instance my cross-compiler for MinGW32 has its binaries called
1055 @code{i586-mingw32msvc-gcc}, @code{i586-mingw32msvc-ld},
1056 @code{i586-mingw32msvc-as}, etc.
1057
1058 @cindex MinGW cross-compilation example
1059 @cindex cross-compilation example
1060
1061 Here is how we could build @code{amhello-1.0} for
1062 @code{i586-mingw32msvc} on a GNU/Linux PC.
1063
1064 @c Keep in sync with amhello-cross-compile.sh
1065 @smallexample
1066 ~/amhello-1.0 % @kbd{./configure --build i686-pc-linux-gnu --host i586-mingw32msvc}
1067 checking for a BSD-compatible install... /usr/bin/install -c
1068 checking whether build environment is sane... yes
1069 checking for gawk... gawk
1070 checking whether make sets $(MAKE)... yes
1071 checking for i586-mingw32msvc-strip... i586-mingw32msvc-strip
1072 checking for i586-mingw32msvc-gcc... i586-mingw32msvc-gcc
1073 checking for C compiler default output file name... a.exe
1074 checking whether the C compiler works... yes
1075 checking whether we are cross compiling... yes
1076 checking for suffix of executables... .exe
1077 checking for suffix of object files... o
1078 checking whether we are using the GNU C compiler... yes
1079 checking whether i586-mingw32msvc-gcc accepts -g... yes
1080 checking for i586-mingw32msvc-gcc option to accept ANSI C...
1081 @dots{}
1082 ~/amhello-1.0 % @kbd{make}
1083 @dots{}
1084 ~/amhello-1.0 % @kbd{cd src; file hello.exe}
1085 hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable
1086 @end smallexample
1087
1088 The @option{--host} and @option{--build} options are usually all we
1089 need for cross-compiling.  The only exception is if the package being
1090 built is itself a cross-compiler: we need a third option to specify
1091 its target architecture.
1092
1093 @table @option
1094 @item --target=@var{target}
1095 @opindex --target=@var{target}
1096 When building compiler tools: the system for which the tools will
1097 create output.
1098 @end table
1099
1100 For instance when installing GCC, the GNU Compiler Collection, we can
1101 use @option{--target=@/@var{target}} to specify that we want to build
1102 GCC as a cross-compiler for @var{target}.  Mixing @option{--build} and
1103 @option{--target}, we can actually cross-compile a cross-compiler;
1104 such a three-way cross-compilation is known as a @dfn{Canadian cross}.
1105
1106 @xref{Specifying Names, , Specifying the System Type, autoconf, The
1107 Autoconf Manual}, for more information about these @command{configure}
1108 options.
1109
1110 @node Renaming
1111 @subsection Renaming Programs at Install Time
1112 @cindex Renaming programs
1113 @cindex Transforming program names
1114 @cindex Programs, renaming during installation
1115
1116 The GNU Build System provides means to automatically rename
1117 executables and manpages before they are installed (@pxref{Man Pages}).
1118 This is especially convenient
1119 when installing a GNU package on a system that already has a
1120 proprietary implementation you do not want to overwrite.  For instance,
1121 you may want to install GNU @command{tar} as @command{gtar} so you can
1122 distinguish it from your vendor's @command{tar}.
1123
1124 This can be done using one of these three @command{configure} options.
1125
1126 @table @option
1127 @item --program-prefix=@var{prefix}
1128 @opindex --program-prefix=@var{prefix}
1129 Prepend @var{prefix} to installed program names.
1130 @item --program-suffix=@var{suffix}
1131 @opindex --program-suffix=@var{suffix}
1132 Append @var{suffix} to installed program names.
1133 @item --program-transform-name=@var{program}
1134 @opindex --program-transform-name=@var{program}
1135 Run @code{sed @var{program}} on installed program names.
1136 @end table
1137
1138 The following commands would install @file{hello}
1139 as @file{/usr/local/bin/test-hello}, for instance.
1140
1141 @example
1142 ~/amhello-1.0 % @kbd{./configure --program-prefix test-}
1143 @dots{}
1144 ~/amhello-1.0 % @kbd{make}
1145 @dots{}
1146 ~/amhello-1.0 % @kbd{sudo make install}
1147 @dots{}
1148 @end example
1149
1150 @node DESTDIR
1151 @subsection Building Binary Packages Using DESTDIR
1152 @vindex DESTDIR
1153
1154 The GNU Build System's @code{make install} and @code{make uninstall}
1155 interface does not exactly fit the needs of a system administrator
1156 who has to deploy and upgrade packages on lots of hosts.  In other
1157 words, the GNU Build System does not replace a package manager.
1158
1159 Such package managers usually need to know which files have been
1160 installed by a package, so a mere @code{make install} is
1161 inappropriate.
1162
1163 @cindex Staged installation
1164
1165 The @code{DESTDIR} variable can be used to perform a staged
1166 installation.  The package should be configured as if it was going to
1167 be installed in its final location (e.g., @code{--prefix /usr}), but
1168 when running @code{make install}, the @code{DESTDIR} should be set to
1169 the absolute name of a directory into which the installation will be
1170 diverted.  From this directory it is easy to review which files are
1171 being installed where, and finally copy them to their final location
1172 by some means.
1173
1174 @cindex Binary package
1175
1176 For instance here is how we could create a binary package containing a
1177 snapshot of all the files to be installed.
1178
1179 @c Keep in sync with amhello-binpkg.sh
1180 @example
1181 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1182 @dots{}
1183 ~/amhello-1.0 % @kbd{make}
1184 @dots{}
1185 ~/amhello-1.0 % @kbd{make DESTDIR=$HOME/inst install}
1186 @dots{}
1187 ~/amhello-1.0 % @kbd{cd ~/inst}
1188 ~/inst % @kbd{find . -type f -print > ../files.lst}
1189 ~/inst % @kbd{tar zcvf ~/amhello-1.0-i686.tar.gz `cat ../files.lst`}
1190 ./usr/bin/hello
1191 ./usr/share/doc/amhello/README
1192 @end example
1193
1194 After this example, @code{amhello-1.0-i686.tar.gz} is ready to be
1195 uncompressed in @file{/} on many hosts.  (Using @code{`cat ../files.lst`}
1196 instead of @samp{.} as argument for @command{tar} avoids entries for
1197 each subdirectory in the archive: we would not like @command{tar} to
1198 restore the modification time of @file{/}, @file{/usr/}, etc.)
1199
1200 Note that when building packages for several architectures, it might
1201 be convenient to use @code{make install-data} and @code{make
1202 install-exec} (@pxref{Two-Part Install}) to gather
1203 architecture-independent files in a single package.
1204
1205 @xref{Install}, for more information.
1206
1207 @c We should document PRE_INSTALL/POST_INSTALL/NORMAL_INSTALL and their
1208 @c UNINSTALL counterparts.
1209
1210 @node Preparing Distributions
1211 @subsection Preparing Distributions
1212 @cindex Preparing distributions
1213 @cindex Packages, preparation
1214 @cindex Distributions, preparation
1215
1216 We have already mentioned @code{make dist}.  This target collects all
1217 your source files and the necessary parts of the build system to
1218 create a tarball named @file{@var{package}-@var{version}.tar.gz}.
1219
1220 @cindex @code{distcheck} better than @code{dist}
1221
1222 Another, more useful command is @code{make distcheck}.  The
1223 @code{distcheck} target constructs
1224 @file{@var{package}-@var{version}.tar.gz} just as well as @code{dist},
1225 but it additionally ensures most of the use cases presented so far
1226 work:
1227
1228 @itemize @bullet
1229 @item
1230 It attempts a full compilation of the package (@pxref{Basic
1231 Installation}), unpacking the newly constructed tarball, running
1232 @code{make}, @code{make check}, @code{make install}, as well as
1233 @code{make installcheck}, and even @code{make dist},
1234 @item
1235 it tests VPATH builds with read-only source tree (@pxref{VPATH Builds}),
1236 @item
1237 it makes sure @code{make clean}, @code{make distclean}, and @code{make
1238 uninstall} do not omit any file (@pxref{Standard Targets}),
1239 @item
1240 and it checks that @code{DESTDIR} installations work (@pxref{DESTDIR}).
1241 @end itemize
1242
1243 All of these actions are performed in a temporary subdirectory, so
1244 that no root privileges are required.
1245
1246 Releasing a package that fails @code{make distcheck} means that one of
1247 the scenarios we presented will not work and some users will be
1248 disappointed.  Therefore it is a good practice to release a package
1249 only after a successful @code{make distcheck}.  This of course does
1250 not imply that the package will be flawless, but at least it will
1251 prevent some of the embarrassing errors you may find in packages
1252 released by people who have never heard about @code{distcheck} (like
1253 @code{DESTDIR} not working because of a typo, or a distributed file
1254 being erased by @code{make clean}, or even @code{VPATH} builds not
1255 working).
1256
1257 @xref{Creating amhello}, to recreate @file{amhello-1.0.tar.gz} using
1258 @code{make distcheck}.  @xref{Checking the Distribution}, for more
1259 information about @code{distcheck}.
1260
1261 @node Dependency Tracking
1262 @subsection Automatic Dependency Tracking
1263 @cindex Dependency tracking
1264
1265 Dependency tracking is performed as a side-effect of compilation.
1266 Each time the build system compiles a source file, it computes its
1267 list of dependencies (in C these are the header files included by the
1268 source being compiled).  Later, any time @command{make} is run and a
1269 dependency appears to have changed, the dependent files will be
1270 rebuilt.
1271
1272 Automake generates code for automatic dependency tracking by default,
1273 unless the developer chooses to override it; for more information,
1274 @pxref{Dependencies}.
1275
1276 When @command{configure} is executed, you can see it probing each
1277 compiler for the dependency mechanism it supports (several mechanisms
1278 can be used):
1279
1280 @example
1281 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1282 @dots{}
1283 checking dependency style of gcc... gcc3
1284 @dots{}
1285 @end example
1286
1287 Because dependencies are only computed as a side-effect of the
1288 compilation, no dependency information exists the first time a package
1289 is built.  This is OK because all the files need to be built anyway:
1290 @code{make} does not have to decide which files need to be rebuilt.
1291 In fact, dependency tracking is completely useless for one-time builds
1292 and there is a @command{configure} option to disable this:
1293
1294 @table @option
1295 @item --disable-dependency-tracking
1296 @opindex --disable-dependency-tracking
1297 Speed up one-time builds.
1298 @end table
1299
1300 Some compilers do not offer any practical way to derive the list of
1301 dependencies as a side-effect of the compilation, requiring a separate
1302 run (maybe of another tool) to compute these dependencies.  The
1303 performance penalty implied by these methods is important enough to
1304 disable them by default.  The option @option{--enable-dependency-tracking}
1305 must be passed to @command{configure} to activate them.
1306
1307 @table @option
1308 @item --enable-dependency-tracking
1309 @opindex --enable-dependency-tracking
1310 Do not reject slow dependency extractors.
1311 @end table
1312
1313 @xref{Dependency Tracking Evolution, , Dependency Tracking Evolution,
1314 automake-history, Brief History of Automake}, for some discussion about
1315 the different dependency tracking schemes used by Automake over the years.
1316
1317 @node Nested Packages
1318 @subsection Nested Packages
1319 @cindex Nested packages
1320 @cindex Packages, nested
1321 @cindex Subpackages
1322
1323 Although nesting packages isn't something we would recommend to
1324 someone who is discovering the Autotools, it is a nice feature worthy
1325 of mention in this small advertising tour.
1326
1327 Autoconfiscated packages (that means packages whose build system have
1328 been created by Autoconf and friends) can be nested to arbitrary
1329 depth.
1330
1331 A typical setup is that package A will distribute one of the libraries
1332 it needs in a subdirectory.  This library B is a complete package with
1333 its own GNU Build System.  The @command{configure} script of A will
1334 run the @command{configure} script of B as part of its execution,
1335 building and installing A will also build and install B.  Generating a
1336 distribution for A will also include B.
1337
1338 It is possible to gather several packages like this.  GCC is a heavy
1339 user of this feature.  This gives installers a single package to
1340 configure, build and install, while it allows developers to work on
1341 subpackages independently.
1342
1343 When configuring nested packages, the @command{configure} options
1344 given to the top-level @command{configure} are passed recursively to
1345 nested @command{configure}s.  A package that does not understand an
1346 option will ignore it, assuming it is meaningful to some other
1347 package.
1348
1349 @opindex --help=recursive
1350
1351 The command @code{configure --help=recursive} can be used to display
1352 the options supported by all the included packages.
1353
1354 @xref{Subpackages}, for an example setup.
1355
1356 @node Why Autotools
1357 @section How Autotools Help
1358 @cindex Autotools, purpose
1359
1360 There are several reasons why you may not want to implement the GNU
1361 Build System yourself (read: write a @file{configure} script and
1362 @file{Makefile}s yourself).
1363
1364 @itemize @bullet
1365 @item
1366 As we have seen, the GNU Build System has a lot of
1367 features (@pxref{Use Cases}).
1368 Some users may expect features you have not implemented because
1369 you did not need them.
1370 @item
1371 Implementing these features portably is difficult and exhausting.
1372 Think of writing portable shell scripts, and portable
1373 @file{Makefile}s, for systems you may not have handy.  @xref{Portable
1374 Shell, , Portable Shell Programming, autoconf, The Autoconf Manual}, to
1375 convince yourself.
1376 @item
1377 You will have to upgrade your setup to follow changes to the GNU
1378 Coding Standards.
1379 @end itemize
1380
1381 The GNU Autotools take all this burden off your back and provide:
1382
1383 @itemize @bullet
1384 @item
1385 Tools to create a portable, complete, and self-contained GNU Build
1386 System, from simple instructions.
1387 @emph{Self-contained} meaning the resulting build system does not
1388 require the GNU Autotools.
1389 @item
1390 A central place where fixes and improvements are made:
1391 a bug-fix for a portability issue will benefit every package.
1392 @end itemize
1393
1394 Yet there also exist reasons why you may want NOT to use the
1395 Autotools@enddots{} For instance you may be already using (or used to)
1396 another incompatible build system.  Autotools will only be useful if
1397 you do accept the concepts of the GNU Build System.  People who have their
1398 own idea of how a build system should work will feel frustrated by the
1399 Autotools.
1400
1401 @node Hello World
1402 @section A Small Hello World
1403 @cindex Example Hello World
1404 @cindex Hello World example
1405 @cindex @file{amhello-1.0.tar.gz}, creation
1406
1407 In this section we recreate the @file{amhello-1.0} package from
1408 scratch.  The first subsection shows how to call the Autotools to
1409 instantiate the GNU Build System, while the second explains the
1410 meaning of the @file{configure.ac} and @file{Makefile.am} files read
1411 by the Autotools.
1412
1413 @anchor{amhello Explained}
1414 @menu
1415 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
1416 * amhello's configure.ac Setup Explained::
1417 * amhello's Makefile.am Setup Explained::
1418 @end menu
1419
1420 @node Creating amhello
1421 @subsection Creating @file{amhello-1.0.tar.gz}
1422
1423 Here is how we can recreate @file{amhello-1.0.tar.gz} from scratch.
1424 The package is simple enough so that we will only need to write 5
1425 files.  (You may copy them from the final @file{amhello-1.0.tar.gz}
1426 that is distributed with Automake if you do not want to write them.)
1427
1428 Create the following files in an empty directory.
1429
1430 @itemize @bullet
1431
1432 @item
1433 @file{src/main.c} is the source file for the @file{hello} program.  We
1434 store it in the @file{src/} subdirectory, because later, when the package
1435 evolves, it will ease the addition of a @file{man/} directory for man
1436 pages, a @file{data/} directory for data files, etc.
1437 @example
1438 ~/amhello % @kbd{cat src/main.c}
1439 #include <config.h>
1440 #include <stdio.h>
1441
1442 int
1443 main (void)
1444 @{
1445   puts ("Hello World!");
1446   puts ("This is " PACKAGE_STRING ".");
1447   return 0;
1448 @}
1449 @end example
1450
1451 @item
1452 @file{README} contains some very limited documentation for our little
1453 package.
1454 @example
1455 ~/amhello % @kbd{cat README}
1456 This is a demonstration package for GNU Automake.
1457 Type 'info Automake' to read the Automake manual.
1458 @end example
1459
1460 @item
1461 @file{Makefile.am} and @file{src/Makefile.am} contain Automake
1462 instructions for these two directories.
1463
1464 @example
1465 ~/amhello % @kbd{cat src/Makefile.am}
1466 bin_PROGRAMS = hello
1467 hello_SOURCES = main.c
1468 ~/amhello % @kbd{cat Makefile.am}
1469 SUBDIRS = src
1470 dist_doc_DATA = README
1471 @end example
1472
1473 @item
1474 Finally, @file{configure.ac} contains Autoconf instructions to
1475 create the @command{configure} script.
1476
1477 @example
1478 ~/amhello % @kbd{cat configure.ac}
1479 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1480 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1481 AC_PROG_CC
1482 AC_CONFIG_HEADERS([config.h])
1483 AC_CONFIG_FILES([
1484  Makefile
1485  src/Makefile
1486 ])
1487 AC_OUTPUT
1488 @end example
1489 @end itemize
1490
1491 @cindex @command{autoreconf}, example
1492
1493 Once you have these five files, it is time to run the Autotools to
1494 instantiate the build system.  Do this using the @command{autoreconf}
1495 command as follows:
1496
1497 @example
1498 ~/amhello % @kbd{autoreconf --install}
1499 configure.ac: installing './install-sh'
1500 configure.ac: installing './missing'
1501 src/Makefile.am: installing './depcomp'
1502 @end example
1503
1504 At this point the build system is complete.
1505
1506 In addition to the three scripts mentioned in its output, you can see
1507 that @command{autoreconf} created four other files: @file{configure},
1508 @file{config.h.in}, @file{Makefile.in}, and @file{src/Makefile.in}.
1509 The latter three files are templates that will be adapted to the
1510 system by @command{configure} under the names @file{config.h},
1511 @file{Makefile}, and @file{src/Makefile}.  Let's do this:
1512
1513 @example
1514 ~/amhello % @kbd{./configure}
1515 checking for a BSD-compatible install... /usr/bin/install -c
1516 checking whether build environment is sane... yes
1517 checking for gawk... no
1518 checking for mawk... mawk
1519 checking whether make sets $(MAKE)... yes
1520 checking for gcc... gcc
1521 checking for C compiler default output file name... a.out
1522 checking whether the C compiler works... yes
1523 checking whether we are cross compiling... no
1524 checking for suffix of executables...
1525 checking for suffix of object files... o
1526 checking whether we are using the GNU C compiler... yes
1527 checking whether gcc accepts -g... yes
1528 checking for gcc option to accept ISO C89... none needed
1529 checking for style of include used by make... GNU
1530 checking dependency style of gcc... gcc3
1531 configure: creating ./config.status
1532 config.status: creating Makefile
1533 config.status: creating src/Makefile
1534 config.status: creating config.h
1535 config.status: executing depfiles commands
1536 @end example
1537
1538 @trindex distcheck
1539 @cindex @code{distcheck} example
1540
1541 You can see @file{Makefile}, @file{src/Makefile}, and @file{config.h}
1542 being created at the end after @command{configure} has probed the
1543 system.  It is now possible to run all the targets we wish
1544 (@pxref{Standard Targets}).  For instance:
1545
1546 @example
1547 ~/amhello % @kbd{make}
1548 @dots{}
1549 ~/amhello % @kbd{src/hello}
1550 Hello World!
1551 This is amhello 1.0.
1552 ~/amhello % @kbd{make distcheck}
1553 @dots{}
1554 =============================================
1555 amhello-1.0 archives ready for distribution:
1556 amhello-1.0.tar.gz
1557 =============================================
1558 @end example
1559
1560 Note that running @command{autoreconf} is only needed initially when
1561 the GNU Build System does not exist.  When you later change some
1562 instructions in a @file{Makefile.am} or @file{configure.ac}, the
1563 relevant part of the build system will be regenerated automatically
1564 when you execute @command{make}.
1565
1566 @command{autoreconf} is a script that calls @command{autoconf},
1567 @command{automake}, and a bunch of other commands in the right order.
1568 If you are beginning with these tools, it is not important to figure
1569 out in which order all of these tools should be invoked and why.  However,
1570 because Autoconf and Automake have separate manuals, the important
1571 point to understand is that @command{autoconf} is in charge of
1572 creating @file{configure} from @file{configure.ac}, while
1573 @command{automake} is in charge of creating @file{Makefile.in}s from
1574 @file{Makefile.am}s and @file{configure.ac}.  This should at least
1575 direct you to the right manual when seeking answers.
1576
1577
1578 @node amhello's configure.ac Setup Explained
1579 @subsection @code{amhello}'s @file{configure.ac} Setup Explained
1580
1581 @cindex @file{configure.ac}, Hello World
1582
1583 Let us begin with the contents of @file{configure.ac}.
1584
1585 @example
1586 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1587 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1588 AC_PROG_CC
1589 AC_CONFIG_HEADERS([config.h])
1590 AC_CONFIG_FILES([
1591  Makefile
1592  src/Makefile
1593 ])
1594 AC_OUTPUT
1595 @end example
1596
1597 This file is read by both @command{autoconf} (to create
1598 @file{configure}) and @command{automake} (to create the various
1599 @file{Makefile.in}s).  It contains a series of M4 macros that will be
1600 expanded as shell code to finally form the @file{configure} script.
1601 We will not elaborate on the syntax of this file, because the Autoconf
1602 manual has a whole section about it (@pxref{Writing Autoconf Input, ,
1603 Writing @file{configure.ac}, autoconf, The Autoconf Manual}).
1604
1605 The macros prefixed with @code{AC_} are Autoconf macros, documented
1606 in the Autoconf manual (@pxref{Autoconf Macro Index, , Autoconf Macro
1607 Index, autoconf, The Autoconf Manual}).  The macros that start with
1608 @code{AM_} are Automake macros, documented later in this manual
1609 (@pxref{Macro Index}).
1610
1611 The first two lines of @file{configure.ac} initialize Autoconf and
1612 Automake.  @code{AC_INIT} takes in as parameters the name of the package,
1613 its version number, and a contact address for bug-reports about the
1614 package (this address is output at the end of @code{./configure
1615 --help}, for instance).  When adapting this setup to your own package,
1616 by all means please do not blindly copy Automake's address: use the
1617 mailing list of your package, or your own mail address.
1618
1619 @opindex -Wall
1620 @opindex -Werror
1621 @opindex foreign
1622
1623 The argument to @code{AM_INIT_AUTOMAKE} is a list of options for
1624 @command{automake} (@pxref{Options}).  @option{-Wall} and
1625 @option{-Werror} ask @command{automake} to turn on all warnings and
1626 report them as errors.  We are speaking of @strong{Automake} warnings
1627 here, such as dubious instructions in @file{Makefile.am}.  This has
1628 absolutely nothing to do with how the compiler will be called, even
1629 though it may support options with similar names.  Using @option{-Wall
1630 -Werror} is a safe setting when starting to work on a package: you do
1631 not want to miss any issues.  Later you may decide to relax things a
1632 bit.  The @option{foreign} option tells Automake that this package
1633 will not follow the GNU Standards.  GNU packages should always
1634 distribute additional files such as @file{ChangeLog}, @file{AUTHORS},
1635 etc.  We do not want @command{automake} to complain about these
1636 missing files in our small example.
1637
1638 The @code{AC_PROG_CC} line causes the @command{configure} script to
1639 search for a C compiler and define the variable @code{CC} with its
1640 name.  The @file{src/Makefile.in} file generated by Automake uses the
1641 variable @code{CC} to build @file{hello}, so when @command{configure}
1642 creates @file{src/Makefile} from @file{src/Makefile.in}, it will define
1643 @code{CC} with the value it has found.  If Automake is asked to create
1644 a @file{Makefile.in} that uses @code{CC} but @file{configure.ac} does
1645 not define it, it will suggest you add a call to @code{AC_PROG_CC}.
1646
1647 The @code{AC_CONFIG_HEADERS([config.h])} invocation causes the
1648 @command{configure} script to create a @file{config.h} file gathering
1649 @samp{#define}s defined by other macros in @file{configure.ac}.  In our
1650 case, the @code{AC_INIT} macro already defined a few of them.  Here
1651 is an excerpt of @file{config.h} after @command{configure} has run:
1652
1653 @smallexample
1654 @dots{}
1655 /* Define to the address where bug reports for this package should be sent. */
1656 #define PACKAGE_BUGREPORT "@value{PACKAGE_BUGREPORT}"
1657
1658 /* Define to the full name and version of this package. */
1659 #define PACKAGE_STRING "amhello 1.0"
1660 @dots{}
1661 @end smallexample
1662
1663 As you probably noticed, @file{src/main.c} includes @file{config.h} so
1664 it can use @code{PACKAGE_STRING}.  In a real-world project,
1665 @file{config.h} can grow really big, with one @samp{#define} per
1666 feature probed on the system.
1667
1668 The @code{AC_CONFIG_FILES} macro declares the list of files that
1669 @command{configure} should create from their @file{*.in} templates.
1670 Automake also scans this list to find the @file{Makefile.am} files it must
1671 process.  (This is important to remember: when adding a new directory
1672 to your project, you should add its @file{Makefile} to this list,
1673 otherwise Automake will never process the new @file{Makefile.am} you
1674 wrote in that directory.)
1675
1676 Finally, the @code{AC_OUTPUT} line is a closing command that actually
1677 produces the part of the script in charge of creating the files
1678 registered with @code{AC_CONFIG_HEADERS} and @code{AC_CONFIG_FILES}.
1679
1680 @cindex @command{autoscan}
1681
1682 When starting a new project, we suggest you start with such a simple
1683 @file{configure.ac}, and gradually add the other tests it requires.
1684 The command @command{autoscan} can also suggest a few of the tests
1685 your package may need (@pxref{autoscan Invocation, , Using
1686 @command{autoscan} to Create @file{configure.ac}, autoconf, The
1687 Autoconf Manual}).
1688
1689
1690 @node amhello's Makefile.am Setup Explained
1691 @subsection @code{amhello}'s @file{Makefile.am} Setup Explained
1692
1693 @cindex @file{Makefile.am}, Hello World
1694
1695 We now turn to @file{src/Makefile.am}.  This file contains
1696 Automake instructions to build and install @file{hello}.
1697
1698 @example
1699 bin_PROGRAMS = hello
1700 hello_SOURCES = main.c
1701 @end example
1702
1703 A @file{Makefile.am} has the same syntax as an ordinary
1704 @file{Makefile}.  When @command{automake} processes a
1705 @file{Makefile.am} it copies the entire file into the output
1706 @file{Makefile.in} (that will be later turned into @file{Makefile} by
1707 @command{configure}) but will react to certain variable definitions
1708 by generating some build rules and other variables.
1709 Often @file{Makefile.am}s contain only a list of variable definitions as
1710 above, but they can also contain other variable and rule definitions that
1711 @command{automake} will pass along without interpretation.
1712
1713 Variables that end with @code{_PROGRAMS} are special variables
1714 that list programs that the resulting @file{Makefile} should build.
1715 In Automake speak, this @code{_PROGRAMS} suffix is called a
1716 @dfn{primary}; Automake recognizes other primaries such as
1717 @code{_SCRIPTS}, @code{_DATA}, @code{_LIBRARIES}, etc.@: corresponding
1718 to different types of files.
1719
1720 The @samp{bin} part of the @code{bin_PROGRAMS} tells
1721 @command{automake} that the resulting programs should be installed in
1722 @var{bindir}.  Recall that the GNU Build System uses a set of variables
1723 to denote destination directories and allow users to customize these
1724 locations (@pxref{Standard Directory Variables}).  Any such directory
1725 variable can be put in front of a primary (omitting the @code{dir}
1726 suffix) to tell @command{automake} where to install the listed files.
1727
1728 Programs need to be built from source files, so for each program
1729 @code{@var{prog}} listed in a @code{@w{_PROGRAMS}} variable,
1730 @command{automake} will look for another variable named
1731 @code{@var{prog}_SOURCES} listing its source files.  There may be more
1732 than one source file: they will all be compiled and linked together.
1733
1734 Automake also knows that source files need to be distributed when
1735 creating a tarball (unlike built programs).  So a side-effect of this
1736 @code{hello_SOURCES} declaration is that @file{main.c} will be
1737 part of the tarball created by @code{make dist}.
1738
1739 Finally here are some explanations regarding the top-level
1740 @file{Makefile.am}.
1741
1742 @example
1743 SUBDIRS = src
1744 dist_doc_DATA = README
1745 @end example
1746
1747 @code{SUBDIRS} is a special variable listing all directories that
1748 @command{make} should recurse into before processing the current
1749 directory.  So this line is responsible for @command{make} building
1750 @file{src/hello} even though we run it from the top-level.  This line
1751 also causes @code{make install} to install @file{src/hello} before
1752 installing @file{README} (not that this order matters).
1753
1754 The line @code{dist_doc_DATA = README} causes @file{README} to be
1755 distributed and installed in @var{docdir}.  Files listed with the
1756 @code{_DATA} primary are not automatically part of the tarball built
1757 with @code{make dist}, so we add the @code{dist_} prefix so they get
1758 distributed.  However, for @file{README} it would not have been
1759 necessary: @command{automake} automatically distributes any
1760 @file{README} file it encounters (the list of other files
1761 automatically distributed is presented by @code{automake --help}).
1762 The only important effect of this second line is therefore to install
1763 @file{README} during @code{make install}.
1764
1765 One thing not covered in this example is accessing the installation
1766 directory values (@pxref{Standard Directory Variables}) from your
1767 program code, that is, converting them into defined macros.  For this,
1768 @pxref{Defining Directories,,, autoconf, The Autoconf Manual}.
1769
1770
1771 @node Generalities
1772 @chapter General ideas
1773
1774 The following sections cover a few basic ideas that will help you
1775 understand how Automake works.
1776
1777 @menu
1778 * General Operation::           General operation of Automake
1779 * Strictness::                  Standards conformance checking
1780 * Uniform::                     The Uniform Naming Scheme
1781 * Length Limitations::          Staying below the command line length limit
1782 * Canonicalization::            How derived variables are named
1783 * User Variables::              Variables reserved for the user
1784 * Auxiliary Programs::          Programs automake might require
1785 @end menu
1786
1787
1788 @node General Operation
1789 @section General Operation
1790
1791 Automake works by reading a @file{Makefile.am} and generating a
1792 @file{Makefile.in}.  Certain variables and rules defined in the
1793 @file{Makefile.am} instruct Automake to generate more specialized code;
1794 for instance, a @code{bin_PROGRAMS} variable definition will cause rules
1795 for compiling and linking programs to be generated.
1796
1797 @cindex Non-standard targets
1798 @cindex @code{git-dist}, non-standard example
1799 @trindex git-dist
1800
1801 The variable definitions and rules in the @file{Makefile.am} are
1802 copied mostly verbatim into the generated file, with all variable
1803 definitions preceding all rules.  This allows you to add almost
1804 arbitrary code into the generated @file{Makefile.in}.  For instance,
1805 the Automake distribution includes a non-standard rule for the
1806 @code{git-dist} target, which the Automake maintainer uses to make
1807 distributions from the source control system.
1808
1809 @cindex GNU make extensions
1810
1811 Note that most GNU make extensions are not recognized by Automake.  Using
1812 such extensions in a @file{Makefile.am} will lead to errors or confusing
1813 behavior.
1814
1815 @cindex Append operator
1816 @cmindex +=
1817 A special exception is that the GNU make append operator, @samp{+=}, is
1818 supported.  This operator appends its right hand argument to the variable
1819 specified on the left.  Automake will translate the operator into
1820 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
1821
1822 Automake tries to keep comments grouped with any adjoining rules or
1823 variable definitions.
1824
1825 @cindex Limitations of automake parser
1826 @cindex Automake parser, limitations of
1827 @cindex indentation in Makefile.am
1828 Generally, Automake is not particularly smart in the parsing of unusual
1829 Makefile constructs, so you're advised to avoid fancy constructs or
1830 ``creative'' use of whitespaces.
1831 @c Keep this in sync with doc-parsing-buglets-tabs.sh
1832 For example, @key{TAB} characters cannot be used between a target name
1833 and the following ``@code{:}'' character, and variable assignments
1834 shouldn't be indented with @key{TAB} characters.
1835 @c Keep this in sync with doc-parsing-buglets-colneq-subst.sh
1836 Also, using more complex macro in target names can cause trouble:
1837
1838 @example
1839 % @kbd{cat Makefile.am}
1840 $(FOO:=x): bar
1841 % @kbd{automake}
1842 Makefile.am:1: bad characters in variable name '$(FOO'
1843 Makefile.am:1: ':='-style assignments are not portable
1844 @end example
1845
1846 @cindex Make targets, overriding
1847 @cindex Make rules, overriding
1848 @cindex Overriding make rules
1849 @cindex Overriding make targets
1850
1851 A rule defined in @file{Makefile.am} generally overrides any such
1852 rule of a similar name that would be automatically generated by
1853 @command{automake}.  Although this is a supported feature, it is generally
1854 best to avoid making use of it, as sometimes the generated rules are
1855 very particular.
1856
1857 @cindex Variables, overriding
1858 @cindex Overriding make variables
1859
1860 Similarly, a variable defined in @file{Makefile.am} or
1861 @code{AC_SUBST}ed from @file{configure.ac} will override any
1862 definition of the variable that @command{automake} would ordinarily
1863 create.  This feature is more often useful than the ability to
1864 override a rule.  Be warned that many of the variables generated by
1865 @command{automake} are considered to be for internal use only, and their
1866 names might change in future releases.
1867
1868 @cindex Recursive operation of Automake
1869 @cindex Automake, recursive operation
1870 @cindex Example of recursive operation
1871
1872 When examining a variable definition, Automake will recursively examine
1873 variables referenced in the definition.  For example, if Automake is
1874 looking at the content of @code{foo_SOURCES} in this snippet
1875
1876 @c Keep in sync with interp.sh
1877 @example
1878 xs = a.c b.c
1879 foo_SOURCES = c.c $(xs)
1880 @end example
1881
1882 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
1883 contents of @code{foo_SOURCES}.
1884
1885 @cindex @code{##} (special Automake comment)
1886 @cindex Special Automake comment
1887 @cindex Comment, special to Automake
1888
1889 Automake also allows a form of comment that is @emph{not} copied into
1890 the output; all lines beginning with @samp{##} (leading spaces allowed)
1891 are completely ignored by Automake.
1892
1893 It is customary to make the first line of @file{Makefile.am} read:
1894
1895 @cindex Makefile.am, first line
1896 @cindex First line of Makefile.am
1897
1898 @example
1899 ## Process this file with automake to produce Makefile.in
1900 @end example
1901
1902 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
1903 @c I don't know quite what to say.
1904
1905 @c FIXME document customary ordering of Makefile.am here!
1906
1907
1908 @node Strictness
1909 @section Strictness
1910
1911 @cindex Non-GNU packages
1912
1913 While Automake is intended to be used by maintainers of GNU packages, it
1914 does make some effort to accommodate those who wish to use it, but do
1915 not want to use all the GNU conventions.
1916
1917 @cindex Strictness, defined
1918 @cindex Strictness, @option{foreign}
1919 @cindex @option{foreign} strictness
1920 @cindex Strictness, @option{gnu}
1921 @cindex @option{gnu} strictness
1922 @cindex Strictness, @option{gnits}
1923 @cindex @option{gnits} strictness
1924
1925 To this end, Automake supports three levels of @dfn{strictness}---the
1926 strictness indicating how stringently Automake should check standards
1927 conformance.
1928
1929 The valid strictness levels are:
1930
1931 @table @option
1932 @item foreign
1933 Automake will check for only those things that are absolutely
1934 required for proper operations.  For instance, whereas GNU standards
1935 dictate the existence of a @file{NEWS} file, it will not be required in
1936 this mode.  This strictness will also turn off some warnings by default
1937 (among them, portability warnings).
1938 The name comes from the fact that Automake is intended to be
1939 used for GNU programs; these relaxed rules are not the standard mode of
1940 operation.
1941
1942 @item gnu
1943 Automake will check---as much as possible---for compliance to the GNU
1944 standards for packages.  This is the default.
1945
1946 @item gnits
1947 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
1948 standards}.  These are based on the GNU standards, but are even more
1949 detailed.  Unless you are a Gnits standards contributor, it is
1950 recommended that you avoid this option until such time as the Gnits
1951 standard is actually published (which may never happen).
1952 @end table
1953
1954 @xref{Gnits}, for more information on the precise implications of the
1955 strictness level.
1956
1957
1958 @node Uniform
1959 @section The Uniform Naming Scheme
1960
1961 @cindex Uniform naming scheme
1962
1963 Automake variables generally follow a @dfn{uniform naming scheme} that
1964 makes it easy to decide how programs (and other derived objects) are
1965 built, and how they are installed.  This scheme also supports
1966 @command{configure} time determination of what should be built.
1967
1968 @cindex @code{_PROGRAMS} primary variable
1969 @cindex @code{PROGRAMS} primary variable
1970 @cindex Primary variable, @code{PROGRAMS}
1971 @cindex Primary variable, defined
1972 @vindex _PROGRAMS
1973
1974 At @command{make} time, certain variables are used to determine which
1975 objects are to be built.  The variable names are made of several pieces
1976 that are concatenated together.
1977
1978 The piece that tells @command{automake} what is being built is commonly called
1979 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
1980 list of programs that are to be compiled and linked.
1981 @vindex PROGRAMS
1982
1983 @cindex @code{pkgdatadir}, defined
1984 @cindex @code{pkgincludedir}, defined
1985 @cindex @code{pkglibdir}, defined
1986 @cindex @code{pkglibexecdir}, defined
1987
1988 @vindex pkgdatadir
1989 @vindex pkgincludedir
1990 @vindex pkglibdir
1991 @vindex pkglibexecdir
1992
1993 @cindex @code{PACKAGE}, directory
1994 A different set of names is used to decide where the built objects
1995 should be installed.  These names are prefixes to the primary, and they
1996 indicate which standard directory should be used as the installation
1997 directory.  The standard directory names are given in the GNU standards
1998 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
1999 Automake extends this list with @code{pkgdatadir}, @code{pkgincludedir},
2000 @code{pkglibdir}, and @code{pkglibexecdir}; these are the same as the
2001 non-@samp{pkg} versions, but with @samp{$(PACKAGE)} appended.  For instance,
2002 @code{pkglibdir} is defined as @samp{$(libdir)/$(PACKAGE)}.
2003
2004 @cindex @code{EXTRA_}, prepending
2005 For each primary, there is one additional variable named by prepending
2006 @samp{EXTRA_} to the primary name.  This variable is used to list
2007 objects that may or may not be built, depending on what
2008 @command{configure} decides.  This variable is required because Automake
2009 must statically know the entire list of objects that may be built in
2010 order to generate a @file{Makefile.in} that will work in all cases.
2011
2012 @cindex @code{EXTRA_PROGRAMS}, defined
2013 @cindex Example, @code{EXTRA_PROGRAMS}
2014 @cindex @command{cpio} example
2015
2016 For instance, @command{cpio} decides at configure time which programs
2017 should be built.  Some of the programs are installed in @code{bindir},
2018 and some are installed in @code{sbindir}:
2019
2020 @example
2021 EXTRA_PROGRAMS = mt rmt
2022 bin_PROGRAMS = cpio pax
2023 sbin_PROGRAMS = $(MORE_PROGRAMS)
2024 @end example
2025
2026 Defining a primary without a prefix as a variable, e.g.,
2027 @samp{PROGRAMS}, is an error.
2028
2029 Note that the common @samp{dir} suffix is left off when constructing the
2030 variable names; thus one writes @samp{bin_PROGRAMS} and not
2031 @samp{bindir_PROGRAMS}.
2032
2033 Not every sort of object can be installed in every directory.  Automake
2034 will flag those attempts it finds in error (but see below how to override
2035 the check if you really need to).
2036 Automake will also diagnose obvious misspellings in directory names.
2037
2038 @cindex Extending list of installation directories
2039 @cindex Installation directories, extending list
2040
2041 Sometimes the standard directories---even as augmented by
2042 Automake---are not enough.  In particular it is sometimes useful, for
2043 clarity, to install objects in a subdirectory of some predefined
2044 directory.  To this end, Automake allows you to extend the list of
2045 possible installation directories.  A given prefix (e.g., @samp{zar})
2046 is valid if a variable of the same name with @samp{dir} appended is
2047 defined (e.g., @samp{zardir}).
2048
2049 For instance, the following snippet will install @file{file.xml} into
2050 @samp{$(datadir)/xml}.
2051
2052 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2053 @example
2054 xmldir = $(datadir)/xml
2055 xml_DATA = file.xml
2056 @end example
2057
2058 This feature can also be used to override the sanity checks Automake
2059 performs to diagnose suspicious directory/primary couples (in the
2060 unlikely case these checks are undesirable, and you really know what
2061 you're doing).  For example, Automake would error out on this input:
2062
2063 @c Should be tested in primary-prefix-invalid-couples.sh
2064 @example
2065 # Forbidden directory combinations, automake will error out on this.
2066 pkglib_PROGRAMS = foo
2067 doc_LIBRARIES = libquux.a
2068 @end example
2069
2070 @noindent
2071 but it will succeed with this:
2072
2073 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2074 @example
2075 # Work around forbidden directory combinations.  Do not use this
2076 # without a very good reason!
2077 my_execbindir = $(pkglibdir)
2078 my_doclibdir = $(docdir)
2079 my_execbin_PROGRAMS = foo
2080 my_doclib_LIBRARIES = libquux.a
2081 @end example
2082
2083 The @samp{exec} substring of the @samp{my_execbindir} variable lets
2084 the files be installed at the right time (@pxref{The Two Parts of
2085 Install}).
2086
2087 @cindex @samp{noinst_} primary prefix, definition
2088 @vindex noinst_
2089
2090 The special prefix @samp{noinst_} indicates that the objects in question
2091 should be built but not installed at all.  This is usually used for
2092 objects required to build the rest of your package, for instance static
2093 libraries (@pxref{A Library}), or helper scripts.
2094
2095 @cindex @samp{check_} primary prefix, definition
2096 @vindex check_
2097
2098 The special prefix @samp{check_} indicates that the objects in question
2099 should not be built until the @samp{make check} command is run.  Those
2100 objects are not installed either.
2101
2102 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
2103 @samp{LTLIBRARIES}, @samp{LISP}, @samp{PYTHON}, @samp{JAVA},
2104 @samp{SCRIPTS}, @samp{DATA}, @samp{HEADERS}, @samp{MANS}, and
2105 @samp{TEXINFOS}.
2106 @vindex PROGRAMS
2107 @vindex LIBRARIES
2108 @vindex LTLIBRARIES
2109 @vindex LISP
2110 @vindex PYTHON
2111 @vindex JAVA
2112 @vindex SCRIPTS
2113 @vindex DATA
2114 @vindex HEADERS
2115 @vindex MANS
2116 @vindex TEXINFOS
2117
2118 Some primaries also allow additional prefixes that control other
2119 aspects of @command{automake}'s behavior.  The currently defined prefixes
2120 are @samp{dist_}, @samp{nodist_}, @samp{nobase_}, and @samp{notrans_}.
2121 These prefixes are explained later (@pxref{Program and Library Variables})
2122 (@pxref{Man Pages}).
2123
2124
2125 @node Length Limitations
2126 @section Staying below the command line length limit
2127
2128 @cindex command line length limit
2129 @cindex ARG_MAX
2130
2131 Traditionally, most unix-like systems have a length limitation for the
2132 command line arguments and environment contents when creating new
2133 processes (see for example
2134 @uref{http://www.in-ulm.de/@/~mascheck/@/various/@/argmax/} for an
2135 overview on this issue),
2136 which of course also applies to commands spawned by @command{make}.
2137 POSIX requires this limit to be at least 4096 bytes, and most modern
2138 systems have quite high limits (or are unlimited).
2139
2140 In order to create portable Makefiles that do not trip over these
2141 limits, it is necessary to keep the length of file lists bounded.
2142 Unfortunately, it is not possible to do so fully transparently within
2143 Automake, so your help may be needed.  Typically, you can split long
2144 file lists manually and use different installation directory names for
2145 each list.  For example,
2146
2147 @example
2148 data_DATA = file1 @dots{} file@var{N} file@var{N+1} @dots{} file@var{2N}
2149 @end example
2150
2151 @noindent
2152 may also be written as
2153
2154 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2155 @example
2156 data_DATA = file1 @dots{} file@var{N}
2157 data2dir = $(datadir)
2158 data2_DATA = file@var{N+1} @dots{} file@var{2N}
2159 @end example
2160
2161 @noindent
2162 and will cause Automake to treat the two lists separately during
2163 @code{make install}.  See @ref{The Two Parts of Install} for choosing
2164 directory names that will keep the ordering of the two parts of
2165 installation Note that @code{make dist} may still only work on a host
2166 with a higher length limit in this example.
2167
2168 Automake itself employs a couple of strategies to avoid long command
2169 lines.  For example, when @samp{$@{srcdir@}/} is prepended to file
2170 names, as can happen with above @code{$(data_DATA)} lists, it limits
2171 the amount of arguments passed to external commands.
2172
2173 Unfortunately, some system's @command{make} commands may prepend
2174 @code{VPATH} prefixes like @samp{$@{srcdir@}/} to file names from the
2175 source tree automatically (@pxref{Automatic Rule Rewriting, , Automatic
2176 Rule Rewriting, autoconf, The Autoconf Manual}).  In this case, the user
2177 may have to switch to use GNU Make, or refrain from using VPATH builds,
2178 in order to stay below the length limit.
2179
2180 For libraries and programs built from many sources, convenience archives
2181 may be used as intermediates in order to limit the object list length
2182 (@pxref{Libtool Convenience Libraries}).
2183
2184
2185 @node Canonicalization
2186 @section How derived variables are named
2187
2188 @cindex canonicalizing Automake variables
2189
2190 Sometimes a Makefile variable name is derived from some text the
2191 maintainer supplies.  For instance, a program name listed in
2192 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
2193 variable.  In cases like this, Automake canonicalizes the text, so that
2194 program names and the like do not have to follow Makefile variable naming
2195 rules.  All characters in the name except for letters, numbers, the
2196 strudel (@@), and the underscore are turned into underscores when making
2197 variable references.
2198
2199 For example, if your program is named @file{sniff-glue}, the derived
2200 variable name would be @samp{sniff_glue_SOURCES}, not
2201 @samp{sniff-glue_SOURCES}.  Similarly the sources for a library named
2202 @file{libmumble++.a} should be listed in the
2203 @samp{libmumble___a_SOURCES} variable.
2204
2205 The strudel is an addition, to make the use of Autoconf substitutions in
2206 variable names less obfuscating.
2207
2208
2209 @node User Variables
2210 @section Variables reserved for the user
2211
2212 @cindex variables, reserved for the user
2213 @cindex user variables
2214
2215 Some @file{Makefile} variables are reserved by the GNU Coding Standards
2216 for the use of the ``user''---the person building the package.  For
2217 instance, @code{CFLAGS} is one such variable.
2218
2219 Sometimes package developers are tempted to set user variables such as
2220 @code{CFLAGS} because it appears to make their job easier.  However,
2221 the package itself should never set a user variable, particularly not
2222 to include switches that are required for proper compilation of the
2223 package.  Since these variables are documented as being for the
2224 package builder, that person rightfully expects to be able to override
2225 any of these variables at build time.
2226
2227 To get around this problem, Automake introduces an automake-specific
2228 shadow variable for each user flag variable.  (Shadow variables are
2229 not introduced for variables like @code{CC}, where they would make no
2230 sense.)  The shadow variable is named by prepending @samp{AM_} to the
2231 user variable's name.  For instance, the shadow variable for
2232 @code{YFLAGS} is @code{AM_YFLAGS}.  The package maintainer---that is,
2233 the author(s) of the @file{Makefile.am} and @file{configure.ac}
2234 files---may adjust these shadow variables however necessary.
2235
2236 @xref{Flag Variables Ordering}, for more discussion about these
2237 variables and how they interact with per-target variables.
2238
2239 @node Auxiliary Programs
2240 @section Programs automake might require
2241
2242 @cindex Programs, auxiliary
2243 @cindex Auxiliary programs
2244
2245 Automake sometimes requires helper programs so that the generated
2246 @file{Makefile} can do its work properly.  There are a fairly large
2247 number of them, and we list them here.
2248
2249 Although all of these files are distributed and installed with
2250 Automake, a couple of them are maintained separately.  The Automake
2251 copies are updated before each release, but we mention the original
2252 source in case you need more recent versions.
2253
2254 @table @code
2255 @item ar-lib
2256 This is a wrapper primarily for the Microsoft lib archiver, to make
2257 it more POSIX-like.
2258
2259 @item compile
2260 This is a wrapper for compilers that do not accept options @option{-c}
2261 and @option{-o} at the same time.  It is only used when absolutely
2262 required.  Such compilers are rare, with the Microsoft C/C++ Compiler
2263 as the most notable exception. This wrapper also makes the following
2264 common options available for that compiler, while performing file name
2265 translation where needed: @option{-I}, @option{-L}, @option{-l},
2266 @option{-Wl,} and @option{-Xlinker}.
2267
2268 @item config.guess
2269 @itemx config.sub
2270 These two programs compute the canonical triplets for the given build,
2271 host, or target architecture.  These programs are updated regularly to
2272 support new architectures and fix probes broken by changes in new
2273 kernel versions.  Each new release of Automake comes with up-to-date
2274 copies of these programs.  If your copy of Automake is getting old,
2275 you are encouraged to fetch the latest versions of these files from
2276 @url{http://savannah.gnu.org/git/?group=config} before making a
2277 release.
2278
2279 @item depcomp
2280 This program understands how to run a compiler so that it will
2281 generate not only the desired output but also dependency information
2282 that is then used by the automatic dependency tracking feature
2283 (@pxref{Dependencies}).
2284
2285 @item install-sh
2286 This is a replacement for the @command{install} program that works on
2287 platforms where @command{install} is unavailable or unusable.
2288
2289 @item mdate-sh
2290 This script is used to generate a @file{version.texi} file.  It examines
2291 a file and prints some date information about it.
2292
2293 @item missing
2294 This wraps a number of programs that are typically only required by
2295 maintainers.  If the program in question doesn't exist, or seems to old,
2296 @command{missing} will print an informative warning before failing out,
2297 to provide the user with more context and information.
2298
2299 @item mkinstalldirs
2300 This script used to be a wrapper around @samp{mkdir -p}, which is not
2301 portable.  Now we prefer to use @samp{install-sh -d} when @command{configure}
2302 finds that @samp{mkdir -p} does not work, this makes one less script to
2303 distribute.
2304
2305 For backward compatibility @file{mkinstalldirs} is still used and
2306 distributed when @command{automake} finds it in a package.  But it is no
2307 longer installed automatically, and it should be safe to remove it.
2308
2309 @item py-compile
2310 This is used to byte-compile Python scripts.
2311
2312 @item test-driver
2313 This implements the default test driver offered by the parallel
2314 testsuite harness.
2315
2316 @item texinfo.tex
2317 Not a program, this file is required for @samp{make dvi}, @samp{make
2318 ps} and @samp{make pdf} to work when Texinfo sources are in the
2319 package.  The latest version can be downloaded from
2320 @url{http://www.gnu.org/software/texinfo/}.
2321
2322 @item ylwrap
2323 This program wraps @command{lex} and @command{yacc} to rename their
2324 output files.  It also ensures that, for instance, multiple
2325 @command{yacc} instances can be invoked in a single directory in
2326 parallel.
2327
2328 @end table
2329
2330
2331 @node Examples
2332 @chapter Some example packages
2333
2334 This section contains two small examples.
2335
2336 The first example (@pxref{Complete}) assumes you have an existing
2337 project already using Autoconf, with handcrafted @file{Makefile}s, and
2338 that you want to convert it to using Automake.  If you are discovering
2339 both tools, it is probably better that you look at the Hello World
2340 example presented earlier (@pxref{Hello World}).
2341
2342 The second example (@pxref{true}) shows how two programs can be built
2343 from the same file, using different compilation parameters.  It
2344 contains some technical digressions that are probably best skipped on
2345 first read.
2346
2347 @menu
2348 * Complete::                    A simple example, start to finish
2349 * true::                        Building true and false
2350 @end menu
2351
2352
2353 @node Complete
2354 @section A simple example, start to finish
2355
2356 @cindex Complete example
2357
2358 Let's suppose you just finished writing @code{zardoz}, a program to make
2359 your head float from vortex to vortex.  You've been using Autoconf to
2360 provide a portability framework, but your @file{Makefile.in}s have been
2361 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
2362
2363 @cindex @code{AM_INIT_AUTOMAKE}, example use
2364
2365 The first step is to update your @file{configure.ac} to include the
2366 commands that @command{automake} needs.  The way to do this is to add an
2367 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
2368
2369 @example
2370 AC_INIT([zardoz], [1.0])
2371 AM_INIT_AUTOMAKE
2372 @dots{}
2373 @end example
2374
2375 Since your program doesn't have any complicating factors (e.g., it
2376 doesn't use @code{gettext}, it doesn't want to build a shared library),
2377 you're done with this part.  That was easy!
2378
2379 @cindex @command{aclocal} program, introduction
2380 @cindex @file{aclocal.m4}, preexisting
2381 @cindex @file{acinclude.m4}, defined
2382
2383 Now you must regenerate @file{configure}.  But to do that, you'll need
2384 to tell @command{autoconf} how to find the new macro you've used.  The
2385 easiest way to do this is to use the @command{aclocal} program to
2386 generate your @file{aclocal.m4} for you.  But wait@dots{} maybe you
2387 already have an @file{aclocal.m4}, because you had to write some hairy
2388 macros for your program.  The @command{aclocal} program lets you put
2389 your own macros into @file{acinclude.m4}, so simply rename and then
2390 run:
2391
2392 @example
2393 mv aclocal.m4 acinclude.m4
2394 aclocal
2395 autoconf
2396 @end example
2397
2398 @cindex @command{zardoz} example
2399
2400 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
2401 Since @code{zardoz} is a user program, you want to install it where the
2402 rest of the user programs go: @code{bindir}.  Additionally,
2403 @code{zardoz} has some Texinfo documentation.  Your @file{configure.ac}
2404 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
2405 @samp{$(LIBOBJS)}.  So here's what you'd write:
2406
2407 @example
2408 bin_PROGRAMS = zardoz
2409 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
2410 zardoz_LDADD = $(LIBOBJS)
2411
2412 info_TEXINFOS = zardoz.texi
2413 @end example
2414
2415 Now you can run @samp{automake --add-missing} to generate your
2416 @file{Makefile.in} and grab any auxiliary files you might need, and
2417 you're done!
2418
2419
2420 @node true
2421 @section Building true and false
2422
2423 @cindex Example, @command{false} and @command{true}
2424 @cindex @command{false} Example
2425 @cindex @command{true} Example
2426
2427 Here is another, trickier example.  It shows how to generate two
2428 programs (@code{true} and @code{false}) from the same source file
2429 (@file{true.c}).  The difficult part is that each compilation of
2430 @file{true.c} requires different @code{cpp} flags.
2431
2432 @example
2433 bin_PROGRAMS = true false
2434 false_SOURCES =
2435 false_LDADD = false.o
2436
2437 true.o: true.c
2438         $(COMPILE) -DEXIT_CODE=0 -c true.c
2439
2440 false.o: true.c
2441         $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
2442 @end example
2443
2444 Note that there is no @code{true_SOURCES} definition.  Automake will
2445 implicitly assume that there is a source file named @file{true.c}
2446 (@pxref{Default _SOURCES}), and
2447 define rules to compile @file{true.o} and link @file{true}.  The
2448 @samp{true.o: true.c} rule supplied by the above @file{Makefile.am},
2449 will override the Automake generated rule to build @file{true.o}.
2450
2451 @code{false_SOURCES} is defined to be empty---that way no implicit value
2452 is substituted.  Because we have not listed the source of
2453 @file{false}, we have to tell Automake how to link the program.  This is
2454 the purpose of the @code{false_LDADD} line.  A @code{false_DEPENDENCIES}
2455 variable, holding the dependencies of the @file{false} target will be
2456 automatically generated by Automake from the content of
2457 @code{false_LDADD}.
2458
2459 The above rules won't work if your compiler doesn't accept both
2460 @option{-c} and @option{-o}.  The simplest fix for this is to introduce a
2461 bogus dependency (to avoid problems with a parallel @command{make}):
2462
2463 @example
2464 true.o: true.c false.o
2465         $(COMPILE) -DEXIT_CODE=0 -c true.c
2466
2467 false.o: true.c
2468         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
2469 @end example
2470
2471 As it turns out, there is also a much easier way to do this same task.
2472 Some of the above technique is useful enough that we've kept the
2473 example in the manual.  However if you were to build @code{true} and
2474 @code{false} in real life, you would probably use per-program
2475 compilation flags, like so:
2476
2477 @c Keep in sync with specflg7.sh and specflg8.sh
2478 @example
2479 bin_PROGRAMS = false true
2480
2481 false_SOURCES = true.c
2482 false_CPPFLAGS = -DEXIT_CODE=1
2483
2484 true_SOURCES = true.c
2485 true_CPPFLAGS = -DEXIT_CODE=0
2486 @end example
2487
2488 In this case Automake will cause @file{true.c} to be compiled twice,
2489 with different flags.  In this instance, the names of the object files
2490 would be chosen by automake; they would be @file{false-true.o} and
2491 @file{true-true.o}. (The name of the object files rarely matters.)
2492
2493 @node automake Invocation
2494 @chapter Creating a @file{Makefile.in}
2495 @c This node used to be named "Invoking automake".  This @anchor
2496 @c allows old links to still work.
2497 @anchor{Invoking automake}
2498
2499 @cindex Multiple @file{configure.ac} files
2500 @cindex Invoking @command{automake}
2501 @cindex @command{automake}, invoking
2502 @cindex Invocation of @command{automake}
2503 @cindex @command{automake}, invocation
2504
2505 To create all the @file{Makefile.in}s for a package, run the
2506 @command{automake} program in the top level directory, with no
2507 arguments.  @command{automake} will automatically find each
2508 appropriate @file{Makefile.am} (by scanning @file{configure.ac};
2509 @pxref{configure}) and generate the corresponding @file{Makefile.in}.
2510 Note that @command{automake} has a rather simplistic view of what
2511 constitutes a package; it assumes that a package has only one
2512 @file{configure.ac}, at the top.  If your package has multiple
2513 @file{configure.ac}s, then you must run @command{automake} in each
2514 directory holding a @file{configure.ac}.  (Alternatively, you may rely
2515 on Autoconf's @command{autoreconf}, which is able to recurse your
2516 package tree and run @command{automake} where appropriate.)
2517
2518 You can optionally give @command{automake} an argument; @file{.am} is
2519 appended to the argument and the result is used as the name of the
2520 input file.  This feature is generally only used to automatically
2521 rebuild an out-of-date @file{Makefile.in}.  Note that
2522 @command{automake} must always be run from the topmost directory of a
2523 project, even if being used to regenerate the @file{Makefile.in} in
2524 some subdirectory.  This is necessary because @command{automake} must
2525 scan @file{configure.ac}, and because @command{automake} uses the
2526 knowledge that a @file{Makefile.in} is in a subdirectory to change its
2527 behavior in some cases.
2528
2529 @vindex AUTOCONF
2530 Automake will run @command{autoconf} to scan @file{configure.ac} and
2531 its dependencies (i.e., @file{aclocal.m4} and any included file),
2532 therefore @command{autoconf} must be in your @env{PATH}.  If there is
2533 an @env{AUTOCONF} variable in your environment it will be used
2534 instead of @command{autoconf}, this allows you to select a particular
2535 version of Autoconf.  By the way, don't misunderstand this paragraph:
2536 @command{automake} runs @command{autoconf} to @strong{scan} your
2537 @file{configure.ac}, this won't build @file{configure} and you still
2538 have to run @command{autoconf} yourself for this purpose.
2539
2540 @cindex @command{automake} options
2541 @cindex Options, @command{automake}
2542 @cindex Strictness, command line
2543
2544 @command{automake} accepts the following options:
2545
2546 @cindex Extra files distributed with Automake
2547 @cindex Files distributed with Automake
2548 @cindex @file{config.guess}
2549
2550 @table @code
2551 @item -a
2552 @itemx --add-missing
2553 @opindex -a
2554 @opindex --add-missing
2555 Automake requires certain common files to exist in certain situations;
2556 for instance, @file{config.guess} is required if @file{configure.ac} invokes
2557 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
2558 files (@pxref{Auxiliary Programs}); this option will cause the missing
2559 ones to be automatically added to the package, whenever possible.  In
2560 general if Automake tells you a file is missing, try using this option.
2561 By default Automake tries to make a symbolic link pointing to its own
2562 copy of the missing file; this can be changed with @option{--copy}.
2563
2564 Many of the potentially-missing files are common scripts whose
2565 location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
2566 Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
2567 file is considered missing, and where the missing file is added
2568 (@pxref{Optional}).
2569
2570 In some strictness modes, additional files are installed, see @ref{Gnits}
2571 for more information.
2572
2573 @item --libdir=@var{dir}
2574 @opindex --libdir
2575 Look for Automake data files in directory @var{dir} instead of in the
2576 installation directory.  This is typically used for debugging.
2577
2578 @item --print-libdir
2579 @opindex --print-libdir
2580 Print the path of the installation directory containing Automake-provided
2581 scripts and data files (like e.g., @file{texinfo.texi} and
2582 @file{install-sh}).
2583
2584 @item -c
2585 @opindex -c
2586 @itemx --copy
2587 @opindex --copy
2588 When used with @option{--add-missing}, causes installed files to be
2589 copied.  The default is to make a symbolic link.
2590
2591 @item -f
2592 @opindex -f
2593 @itemx --force-missing
2594 @opindex --force-missing
2595 When used with @option{--add-missing}, causes standard files to be reinstalled
2596 even if they already exist in the source tree.  This involves removing
2597 the file from the source tree before creating the new symlink (or, with
2598 @option{--copy}, copying the new file).
2599
2600 @item --foreign
2601 @opindex --foreign
2602 Set the global strictness to @option{foreign}.  For more information, see
2603 @ref{Strictness}.
2604
2605 @item --gnits
2606 @opindex --gnits
2607 Set the global strictness to @option{gnits}.  For more information, see
2608 @ref{Gnits}.
2609
2610 @item --gnu
2611 @opindex --gnu
2612 Set the global strictness to @option{gnu}.  For more information, see
2613 @ref{Gnits}.  This is the default strictness.
2614
2615 @item --help
2616 @opindex --help
2617 Print a summary of the command line options and exit.
2618
2619 @item -i
2620 @itemx --ignore-deps
2621 @opindex -i
2622 This disables the dependency tracking feature in generated
2623 @file{Makefile}s; see @ref{Dependencies}.
2624
2625 @item --include-deps
2626 @opindex --include-deps
2627 This enables the dependency tracking feature.  This feature is enabled
2628 by default.  This option is provided for historical reasons only and
2629 probably should not be used.
2630
2631 @item --no-force
2632 @opindex --no-force
2633 Ordinarily @command{automake} creates all @file{Makefile.in}s mentioned in
2634 @file{configure.ac}.  This option causes it to only update those
2635 @file{Makefile.in}s that are out of date with respect to one of their
2636 dependents.
2637
2638 @item -o @var{dir}
2639 @itemx --output-dir=@var{dir}
2640 @opindex -o
2641 @opindex --output-dir
2642 Put the generated @file{Makefile.in} in the directory @var{dir}.
2643 Ordinarily each @file{Makefile.in} is created in the directory of the
2644 corresponding @file{Makefile.am}.  This option is deprecated and will be
2645 removed in a future release.
2646
2647 @item -v
2648 @itemx --verbose
2649 @opindex -v
2650 @opindex --verbose
2651 Cause Automake to print information about which files are being read or
2652 created.
2653
2654 @item --version
2655 @opindex --version
2656 Print the version number of Automake and exit.
2657
2658 @item -W CATEGORY
2659 @itemx --warnings=@var{category}
2660 @opindex -W
2661 @opindex --warnings
2662 Output warnings falling in @var{category}.  @var{category} can be
2663 one of:
2664 @table @code
2665 @item gnu
2666 warnings related to the GNU Coding Standards
2667 (@pxref{Top, , , standards, The GNU Coding Standards}).
2668 @item obsolete
2669 obsolete features or constructions
2670 @item override
2671 user redefinitions of Automake rules or variables
2672 @item portability
2673 portability issues (e.g., use of @command{make} features that are
2674 known to be not portable)
2675 @item extra-portability
2676 extra portability issues related to obscure tools.  One example of such
2677 a tool is the Microsoft @command{lib} archiver.
2678 @item syntax
2679 weird syntax, unused variables, typos
2680 @item unsupported
2681 unsupported or incomplete features
2682 @item all
2683 all the warnings
2684 @item none
2685 turn off all the warnings
2686 @item error
2687 treat warnings as errors
2688 @end table
2689
2690 A category can be turned off by prefixing its name with @samp{no-}.  For
2691 instance, @option{-Wno-syntax} will hide the warnings about unused
2692 variables.
2693
2694 The categories output by default are @samp{obsolete}, @samp{syntax} and
2695 @samp{unsupported}.  Additionally, @samp{gnu} and @samp{portability}
2696 are enabled in @option{--gnu} and @option{--gnits} strictness.
2697
2698 @c Checked by extra-portability.sh
2699 Turning off @samp{portability} will also turn off @samp{extra-portability},
2700 and similarly turning on @samp{extra-portability} will also turn on
2701 @samp{portability}.  However, turning on @samp{portability} or turning
2702 off @samp{extra-portability} will not affect the other category.
2703
2704 @vindex WARNINGS
2705 The environment variable @env{WARNINGS} can contain a comma separated
2706 list of categories to enable.  It will be taken into account before the
2707 command-line switches, this way @option{-Wnone} will also ignore any
2708 warning category enabled by @env{WARNINGS}.  This variable is also used
2709 by other tools like @command{autoconf}; unknown categories are ignored
2710 for this reason.
2711
2712 @end table
2713
2714 @vindex AUTOMAKE_JOBS
2715 If the environment variable @env{AUTOMAKE_JOBS} contains a positive
2716 number, it is taken as the maximum number of Perl threads to use in
2717 @command{automake} for generating multiple @file{Makefile.in} files
2718 concurrently.  This is an experimental feature.
2719
2720
2721 @node configure
2722 @chapter Scanning @file{configure.ac}, using @command{aclocal}
2723
2724 @cindex @file{configure.ac}, scanning
2725 @cindex Scanning @file{configure.ac}
2726 @cindex Using @command{aclocal}
2727 @cindex @command{aclocal}, using
2728
2729 Automake scans the package's @file{configure.ac} to determine certain
2730 information about the package.  Some @command{autoconf} macros are required
2731 and some variables must be defined in @file{configure.ac}.  Automake
2732 will also use information from @file{configure.ac} to further tailor its
2733 output.
2734
2735 Automake also supplies some Autoconf macros to make the maintenance
2736 easier.  These macros can automatically be put into your
2737 @file{aclocal.m4} using the @command{aclocal} program.
2738
2739 @menu
2740 * Requirements::                Configuration requirements
2741 * Optional::                    Other things Automake recognizes
2742 * aclocal Invocation::          Auto-generating aclocal.m4
2743 * Macros::                      Autoconf macros supplied with Automake
2744 @end menu
2745
2746
2747 @node Requirements
2748 @section Configuration requirements
2749
2750 @cindex Automake requirements
2751 @cindex Requirements of Automake
2752
2753 @acindex AM_INIT_AUTOMAKE
2754 The one real requirement of Automake is that your @file{configure.ac}
2755 call @code{AM_INIT_AUTOMAKE}.  This macro does several things that are
2756 required for proper Automake operation (@pxref{Macros}).
2757
2758 Here are the other macros that Automake requires but which are not run
2759 by @code{AM_INIT_AUTOMAKE}:
2760
2761 @table @code
2762 @item AC_CONFIG_FILES
2763 @itemx AC_OUTPUT
2764 @acindex AC_CONFIG_FILES
2765 @acindex AC_OUTPUT
2766 These two macros are usually invoked as follows near the end of
2767 @file{configure.ac}.
2768
2769 @example
2770 @dots{}
2771 AC_CONFIG_FILES([
2772   Makefile
2773   doc/Makefile
2774   src/Makefile
2775   src/lib/Makefile
2776   @dots{}
2777 ])
2778 AC_OUTPUT
2779 @end example
2780
2781 Automake uses these to determine which files to create (@pxref{Output, ,
2782 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
2783 is considered to be an Automake generated @file{Makefile} if there
2784 exists a file with the same name and the @file{.am} extension appended.
2785 Typically, @samp{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
2786 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
2787
2788 When using @code{AC_CONFIG_FILES} with multiple input files, as in
2789
2790 @example
2791 AC_CONFIG_FILES([Makefile:top.in:Makefile.in:bot.in])
2792 @end example
2793
2794 @noindent
2795 @command{automake} will generate the first @file{.in} input file for
2796 which a @file{.am} file exists.  If no such file exists the output
2797 file is not considered to be generated by Automake.
2798
2799 Files created by @code{AC_CONFIG_FILES}, be they Automake
2800 @file{Makefile}s or not, are all removed by @samp{make distclean}.
2801 Their inputs are automatically distributed, unless they
2802 are the output of prior @code{AC_CONFIG_FILES} commands.
2803 Finally, rebuild rules are generated in the Automake @file{Makefile}
2804 existing in the subdirectory of the output file, if there is one, or
2805 in the top-level @file{Makefile} otherwise.
2806
2807 The above machinery (cleaning, distributing, and rebuilding) works
2808 fine if the @code{AC_CONFIG_FILES} specifications contain only
2809 literals.  If part of the specification uses shell variables,
2810 @command{automake} will not be able to fulfill this setup, and you will
2811 have to complete the missing bits by hand.  For instance, on
2812
2813 @c Keep in sync with output11.sh
2814 @example
2815 file=input
2816 @dots{}
2817 AC_CONFIG_FILES([output:$file],, [file=$file])
2818 @end example
2819
2820 @noindent
2821 @command{automake} will output rules to clean @file{output}, and
2822 rebuild it.  However the rebuild rule will not depend on @file{input},
2823 and this file will not be distributed either.  (You must add
2824 @samp{EXTRA_DIST = input} to your @file{Makefile.am} if @file{input} is a
2825 source file.)
2826
2827 Similarly
2828
2829 @c Keep in sync with output11.sh
2830 @example
2831 file=output
2832 file2=out:in
2833 @dots{}
2834 AC_CONFIG_FILES([$file:input],, [file=$file])
2835 AC_CONFIG_FILES([$file2],, [file2=$file2])
2836 @end example
2837
2838 @noindent
2839 will only cause @file{input} to be distributed.  No file will be
2840 cleaned automatically (add @samp{DISTCLEANFILES = output out}
2841 yourself), and no rebuild rule will be output.
2842
2843 Obviously @command{automake} cannot guess what value @samp{$file} is
2844 going to hold later when @file{configure} is run, and it cannot use
2845 the shell variable @samp{$file} in a @file{Makefile}.  However, if you
2846 make reference to @samp{$file} as @samp{$@{file@}} (i.e., in a way
2847 that is compatible with @command{make}'s syntax) and furthermore use
2848 @code{AC_SUBST} to ensure that @samp{$@{file@}} is meaningful in a
2849 @file{Makefile}, then @command{automake} will be able to use
2850 @samp{$@{file@}} to generate all of these rules.  For instance, here is
2851 how the Automake package itself generates versioned scripts for its
2852 test suite:
2853
2854 @example
2855 AC_SUBST([APIVERSION], @dots{})
2856 @dots{}
2857 AC_CONFIG_FILES(
2858   [tests/aclocal-$@{APIVERSION@}:tests/aclocal.in],
2859   [chmod +x tests/aclocal-$@{APIVERSION@}],
2860   [APIVERSION=$APIVERSION])
2861 AC_CONFIG_FILES(
2862   [tests/automake-$@{APIVERSION@}:tests/automake.in],
2863   [chmod +x tests/automake-$@{APIVERSION@}])
2864 @end example
2865
2866 @noindent
2867 Here cleaning, distributing, and rebuilding are done automatically,
2868 because @samp{$@{APIVERSION@}} is known at @command{make}-time.
2869
2870 Note that you should not use shell variables to declare
2871 @file{Makefile} files for which @command{automake} must create
2872 @file{Makefile.in}.  Even @code{AC_SUBST} does not help here, because
2873 @command{automake} needs to know the file name when it runs in order
2874 to check whether @file{Makefile.am} exists.  (In the very hairy case
2875 that your setup requires such use of variables, you will have to tell
2876 Automake which @file{Makefile.in}s to generate on the command-line.)
2877
2878 It is possible to let @command{automake} emit conditional rules for
2879 @code{AC_CONFIG_FILES} with the help of @code{AM_COND_IF}
2880 (@pxref{Optional}).
2881
2882 To summarize:
2883 @itemize @bullet
2884 @item
2885 Use literals for @file{Makefile}s, and for other files whenever possible.
2886 @item
2887 Use @samp{$file} (or @samp{$@{file@}} without @samp{AC_SUBST([file])})
2888 for files that @command{automake} should ignore.
2889 @item
2890 Use @samp{$@{file@}} and @samp{AC_SUBST([file])} for files
2891 that @command{automake} should not ignore.
2892 @end itemize
2893
2894 @end table
2895
2896
2897 @node Optional
2898 @section Other things Automake recognizes
2899
2900 @cindex Macros Automake recognizes
2901 @cindex Recognized macros by Automake
2902
2903 Every time Automake is run it calls Autoconf to trace
2904 @file{configure.ac}.  This way it can recognize the use of certain
2905 macros and tailor the generated @file{Makefile.in} appropriately.
2906 Currently recognized macros and their effects are:
2907
2908 @ftable @code
2909 @item AC_CANONICAL_BUILD
2910 @itemx AC_CANONICAL_HOST
2911 @itemx AC_CANONICAL_TARGET
2912 @vindex build_triplet
2913 @vindex host_triplet
2914 @vindex target_triplet
2915 Automake will ensure that @file{config.guess} and @file{config.sub}
2916 exist.  Also, the @file{Makefile} variables @code{build_triplet},
2917 @code{host_triplet} and @code{target_triplet} are introduced.  See
2918 @ref{Canonicalizing, , Getting the Canonical System Type, autoconf,
2919 The Autoconf Manual}.
2920
2921 @item AC_CONFIG_AUX_DIR
2922 Automake will look for various helper scripts, such as
2923 @file{install-sh}, in the directory named in this macro invocation.
2924 @c This list is accurate relative to version 1.11
2925 (The full list of scripts is:
2926 @file{ar-lib},
2927 @file{config.guess},
2928 @file{config.sub},
2929 @file{depcomp},
2930 @file{compile},
2931 @file{install-sh},
2932 @file{ltmain.sh},
2933 @file{mdate-sh},
2934 @file{missing},
2935 @file{mkinstalldirs},
2936 @file{py-compile},
2937 @file{test-driver},
2938 @file{texinfo.tex},
2939 @file{ylwrap}.)
2940 Not all scripts are always searched for; some scripts
2941 will only be sought if the generated @file{Makefile.in} requires them.
2942
2943 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
2944 their standard locations.  For @file{mdate-sh},
2945 @file{texinfo.tex}, and @file{ylwrap}, the standard location is the
2946 source directory corresponding to the current @file{Makefile.am}.  For
2947 the rest, the standard location is the first one of @file{.}, @file{..},
2948 or @file{../..} (relative to the top source directory) that provides any
2949 one of the helper scripts.  @xref{Input, , Finding `configure' Input,
2950 autoconf, The Autoconf Manual}.
2951
2952 Required files from @code{AC_CONFIG_AUX_DIR} are automatically
2953 distributed, even if there is no @file{Makefile.am} in this directory.
2954
2955 @item AC_CONFIG_LIBOBJ_DIR
2956 Automake will require the sources file declared with
2957 @code{AC_LIBSOURCE} (see below) in the directory specified by this
2958 macro.
2959
2960 @item AC_CONFIG_HEADERS
2961 Automake will generate rules to rebuild these headers from the
2962 corresponding templates (usually, the template for a @file{foo.h}
2963 header being @file{foo.h.in}).  Older versions of Automake
2964 required the use of @code{AM_CONFIG_HEADER}; this is no longer
2965 the case, and that macro has indeed been removed.
2966
2967 As with @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2968 specification using shell variables will be ignored as far as
2969 cleaning, distributing, and rebuilding is concerned.
2970
2971 @item AC_CONFIG_LINKS
2972 Automake will generate rules to remove @file{configure} generated
2973 links on @samp{make distclean} and to distribute named source files as
2974 part of @samp{make dist}.
2975
2976 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2977 specification using shell variables will be ignored as far as cleaning
2978 and distributing is concerned.  (There are no rebuild rules for links.)
2979
2980 @item AC_LIBOBJ
2981 @itemx AC_LIBSOURCE
2982 @itemx AC_LIBSOURCES
2983 @vindex LIBOBJS
2984 Automake will automatically distribute any file listed in
2985 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
2986
2987 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}.  So if
2988 an Autoconf macro is documented to call @samp{AC_LIBOBJ([file])}, then
2989 @file{file.c} will be distributed automatically by Automake.  This
2990 encompasses many macros like @code{AC_FUNC_ALLOCA},
2991 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
2992
2993 By the way, direct assignments to @code{LIBOBJS} are no longer
2994 supported.  You should always use @code{AC_LIBOBJ} for this purpose.
2995 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
2996 autoconf, The Autoconf Manual}.
2997
2998 @item AC_PROG_RANLIB
2999 This is required if any libraries are built in the package.
3000 @xref{Particular Programs, , Particular Program Checks, autoconf, The
3001 Autoconf Manual}.
3002
3003 @item AC_PROG_CXX
3004 This is required if any C++ source is included.  @xref{Particular
3005 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3006
3007 @item AC_PROG_OBJC
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_OBJCXX
3012 This is required if any Objective C++ source is included.  @xref{Particular
3013 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3014
3015 @item AC_PROG_F77
3016 This is required if any Fortran 77 source is included.  @xref{Particular
3017 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3018
3019 @item AC_F77_LIBRARY_LDFLAGS
3020 This is required for programs and shared libraries that are a mixture of
3021 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
3022 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
3023
3024 @item AC_FC_SRCEXT
3025 Automake will add the flags computed by @code{AC_FC_SRCEXT} to compilation
3026 of files with the respective source extension (@pxref{Fortran Compiler, ,
3027 Fortran Compiler Characteristics, autoconf, The Autoconf Manual}).
3028
3029 @item AC_PROG_FC
3030 This is required if any Fortran 90/95 source is included.  This macro is
3031 distributed with Autoconf version 2.58 and later.  @xref{Particular
3032 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3033
3034 @item AC_PROG_LIBTOOL
3035 Automake will turn on processing for @command{libtool} (@pxref{Top, ,
3036 Introduction, libtool, The Libtool Manual}).
3037
3038 @item AC_PROG_YACC
3039 @vindex YACC
3040 If a Yacc source file is seen, then you must either use this macro or
3041 define the variable @code{YACC} in @file{configure.ac}.  The former is
3042 preferred (@pxref{Particular Programs, , Particular Program Checks,
3043 autoconf, The Autoconf Manual}).
3044
3045 @item AC_PROG_LEX
3046 If a Lex source file is seen, then this macro must be used.
3047 @xref{Particular Programs, , Particular Program Checks, autoconf, The
3048 Autoconf Manual}.
3049
3050 @item AC_REQUIRE_AUX_FILE
3051 For each @code{AC_REQUIRE_AUX_FILE([@var{file}])},
3052 @command{automake} will ensure that @file{@var{file}} exists in the
3053 aux directory, and will complain otherwise.  It
3054 will also automatically distribute the file.  This macro should be
3055 used by third-party Autoconf macros that require some supporting
3056 files in the aux directory specified with @code{AC_CONFIG_AUX_DIR}
3057 above.  @xref{Input, , Finding @command{configure} Input, autoconf,
3058 The Autoconf Manual}.
3059
3060 @item AC_SUBST
3061 The first argument is automatically defined as a variable in each
3062 generated @file{Makefile.in}, unless @code{AM_SUBST_NOTMAKE} is also
3063 used for this variable.  @xref{Setting Output Variables, , Setting
3064 Output Variables, autoconf, The Autoconf Manual}.
3065
3066 For every substituted variable @var{var}, @command{automake} will add
3067 a line @code{@var{var} = @var{value}} to each @file{Makefile.in} file.
3068 Many Autoconf macros invoke @code{AC_SUBST} to set output variables
3069 this way, e.g., @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and
3070 @code{X_LIBS}.  Thus, you can access these variables as
3071 @code{$(X_CFLAGS)} and @code{$(X_LIBS)} in any @file{Makefile.am}
3072 if @code{AC_PATH_XTRA} is called.
3073
3074 @item AM_CONDITIONAL
3075 This introduces an Automake conditional (@pxref{Conditionals}).
3076
3077 @item AM_COND_IF
3078 This macro allows @code{automake} to detect subsequent access within
3079 @file{configure.ac} to a conditional previously introduced with
3080 @code{AM_CONDITIONAL}, thus enabling conditional @code{AC_CONFIG_FILES}
3081 (@pxref{Usage of Conditionals}).
3082
3083 @item AM_GNU_GETTEXT
3084 This macro is required for packages that use GNU gettext
3085 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
3086 this macro it ensures that the package meets some of gettext's
3087 requirements.
3088
3089 @item AM_GNU_GETTEXT_INTL_SUBDIR
3090 This macro specifies that the @file{intl/} subdirectory is to be built,
3091 even if the @code{AM_GNU_GETTEXT} macro was invoked with a first argument
3092 of @samp{external}.
3093
3094 @item AM_MAINTAINER_MODE(@ovar{default-mode})
3095 @opindex --enable-maintainer-mode
3096 @opindex --disable-maintainer-mode
3097 This macro adds an @option{--enable-maintainer-mode} option to
3098 @command{configure}.  If this is used, @command{automake} will cause
3099 ``maintainer-only'' rules to be turned off by default in the
3100 generated @file{Makefile.in}s, unless @var{default-mode} is
3101 @samp{enable}.  This macro defines the @code{MAINTAINER_MODE}
3102 conditional, which you can use in your own @file{Makefile.am}.
3103 @xref{maintainer-mode}.
3104
3105 @item AM_SUBST_NOTMAKE(@var{var})
3106 Prevent Automake from defining a variable @var{var}, even if it is
3107 substituted by @command{config.status}.  Normally, Automake defines a
3108 @command{make} variable for each @command{configure} substitution,
3109 i.e., for each @code{AC_SUBST([@var{var}])}.  This macro prevents that
3110 definition from Automake.  If @code{AC_SUBST} has not been called
3111 for this variable, then @code{AM_SUBST_NOTMAKE} has no effects.
3112 Preventing variable definitions may be useful for substitution of
3113 multi-line values, where @code{@var{var} = @@@var{value}@@} might yield
3114 unintended results.
3115
3116 @item m4_include
3117 Files included by @file{configure.ac} using this macro will be
3118 detected by Automake and automatically distributed.  They will also
3119 appear as dependencies in @file{Makefile} rules.
3120
3121 @code{m4_include} is seldom used by @file{configure.ac} authors, but
3122 can appear in @file{aclocal.m4} when @command{aclocal} detects that
3123 some required macros come from files local to your package (as opposed to
3124 macros installed in a system-wide directory, @pxref{aclocal Invocation}).
3125
3126 @end ftable
3127
3128 @node aclocal Invocation
3129 @section Auto-generating aclocal.m4
3130 @c This node used to be named "Invoking automake".  This @anchor
3131 @c allows old links to still work.
3132 @anchor{Invoking aclocal}
3133
3134 @cindex Invocation of @command{aclocal}
3135 @cindex @command{aclocal}, Invocation
3136 @cindex Invoking @command{aclocal}
3137 @cindex @command{aclocal}, Invoking
3138
3139 Automake includes a number of Autoconf macros that can be used in
3140 your package (@pxref{Macros}); some of them are actually required by
3141 Automake in certain situations.  These macros must be defined in your
3142 @file{aclocal.m4}; otherwise they will not be seen by
3143 @command{autoconf}.
3144
3145 The @command{aclocal} program will automatically generate
3146 @file{aclocal.m4} files based on the contents of @file{configure.ac}.
3147 This provides a convenient way to get Automake-provided macros,
3148 without having to search around.  The @command{aclocal} mechanism
3149 allows other packages to supply their own macros (@pxref{Extending
3150 aclocal}).  You can also use it to maintain your own set of custom
3151 macros (@pxref{Local Macros}).
3152
3153 At startup, @command{aclocal} scans all the @file{.m4} files it can
3154 find, looking for macro definitions (@pxref{Macro Search Path}).  Then
3155 it scans @file{configure.ac}.  Any mention of one of the macros found
3156 in the first step causes that macro, and any macros it in turn
3157 requires, to be put into @file{aclocal.m4}.
3158
3159 @emph{Putting} the file that contains the macro definition into
3160 @file{aclocal.m4} is usually done by copying the entire text of this
3161 file, including unused macro definitions as well as both @samp{#} and
3162 @samp{dnl} comments.  If you want to make a comment that will be
3163 completely ignored by @command{aclocal}, use @samp{##} as the comment
3164 leader.
3165
3166 When a file selected by @command{aclocal} is located in a subdirectory
3167 specified as a relative search path with @command{aclocal}'s @option{-I}
3168 argument, @command{aclocal} assumes the file belongs to the package
3169 and uses @code{m4_include} instead of copying it into
3170 @file{aclocal.m4}.  This makes the package smaller, eases dependency
3171 tracking, and cause the file to be distributed automatically.
3172 (@xref{Local Macros}, for an example.)  Any macro that is found in a
3173 system-wide directory, or via an absolute search path will be copied.
3174 So use @samp{-I `pwd`/reldir} instead of @samp{-I reldir} whenever
3175 some relative directory should be considered outside the package.
3176
3177 The contents of @file{acinclude.m4}, if this file exists, are also
3178 automatically included in @file{aclocal.m4}.  We recommend against
3179 using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
3180
3181 @vindex AUTOM4TE
3182 @cindex autom4te
3183 While computing @file{aclocal.m4}, @command{aclocal} runs
3184 @command{autom4te} (@pxref{Using autom4te, , Using @command{Autom4te},
3185 autoconf, The Autoconf Manual}) in order to trace the macros that are
3186 really used, and omit from @file{aclocal.m4} all macros that are
3187 mentioned but otherwise unexpanded (this can happen when a macro is
3188 called conditionally).  @command{autom4te} is expected to be in the
3189 @env{PATH}, just as @command{autoconf}.  Its location can be
3190 overridden using the @env{AUTOM4TE} environment variable.
3191
3192 @menu
3193 * aclocal Options::             Options supported by aclocal
3194 * Macro Search Path::           How aclocal finds .m4 files
3195 * Extending aclocal::           Writing your own aclocal macros
3196 * Local Macros::                Organizing local macros
3197 * Serials::                     Serial lines in Autoconf macros
3198 * Future of aclocal::           aclocal's scheduled death
3199 @end menu
3200
3201 @node aclocal Options
3202 @subsection aclocal Options
3203
3204 @cindex @command{aclocal}, Options
3205 @cindex Options, @command{aclocal}
3206
3207 @command{aclocal} accepts the following options:
3208
3209 @table @code
3210 @item --automake-acdir=@var{dir}
3211 @opindex --automake-acdir
3212 Look for the automake-provided macro files in @var{dir} instead of
3213 in the installation directory.  This is typically used for debugging.
3214
3215 @item --system-acdir=@var{dir}
3216 @opindex --system-acdir
3217 Look for the system-wide third-party macro files (and the special
3218 @file{dirlist} file) in @var{dir} instead of in the installation
3219 directory.  This is typically used for debugging.
3220
3221 @item --diff[=@var{command}]
3222 @opindex --diff
3223 Run @var{command} on M4 file that would be installed or overwritten
3224 by @option{--install}.  The default @var{command} is @samp{diff -u}.
3225 This option implies @option{--install} and @option{--dry-run}.
3226
3227 @item --dry-run
3228 @opindex --dry-run
3229 Do not actually overwrite (or create) @file{aclocal.m4} and M4
3230 files installed by @option{--install}.
3231
3232 @item --help
3233 @opindex --help
3234 Print a summary of the command line options and exit.
3235
3236 @item -I @var{dir}
3237 @opindex -I
3238 Add the directory @var{dir} to the list of directories searched for
3239 @file{.m4} files.
3240
3241 @item --install
3242 @opindex --install
3243 Install system-wide third-party macros into the first directory
3244 specified with @samp{-I @var{dir}} instead of copying them in the
3245 output file.
3246 @c Keep in sync with aclocal-install-absdir.sh
3247 Note that this will happen also if @var{dir} is an absolute path.
3248
3249 @cindex serial number and @option{--install}
3250 When this option is used, and only when this option is used,
3251 @command{aclocal} will also honor @samp{#serial @var{number}} lines
3252 that appear in macros: an M4 file is ignored if there exists another
3253 M4 file with the same basename and a greater serial number in the
3254 search path (@pxref{Serials}).
3255
3256 @item --force
3257 @opindex --force
3258 Always overwrite the output file.  The default is to overwrite the output
3259 file only when really needed, i.e., when its contents changes or if one
3260 of its dependencies is younger.
3261
3262 This option forces the update of @file{aclocal.m4} (or the file
3263 specified with @file{--output} below) and only this file, it has
3264 absolutely no influence on files that may need to be installed by
3265 @option{--install}.
3266
3267 @item --output=@var{file}
3268 @opindex --output
3269 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
3270
3271 @item --print-ac-dir
3272 @opindex --print-ac-dir
3273 Prints the name of the directory that @command{aclocal} will search to
3274 find third-party @file{.m4} files.  When this option is given, normal
3275 processing is suppressed.  This option was used @emph{in the past} by
3276 third-party packages to determine where to install @file{.m4} macro
3277 files, but @emph{this usage is today discouraged}, since it causes
3278 @samp{$(prefix)} not to be thoroughly honoured (which violates the
3279 GNU Coding Standards), and a similar semantics can be better obtained
3280 with the @env{ACLOCAL_PATH} environment variable; @pxref{Extending aclocal}.
3281
3282 @item --verbose
3283 @opindex --verbose
3284 Print the names of the files it examines.
3285
3286 @item --version
3287 @opindex --version
3288 Print the version number of Automake and exit.
3289
3290 @item -W CATEGORY
3291 @item --warnings=@var{category}
3292 @opindex -W
3293 @opindex --warnings
3294 Output warnings falling in @var{category}.  @var{category} can be
3295 one of:
3296 @table @code
3297 @item syntax
3298 dubious syntactic constructs, underquoted macros, unused macros, etc.
3299 @item unsupported
3300 unknown macros
3301 @item all
3302 all the warnings, this is the default
3303 @item none
3304 turn off all the warnings
3305 @item error
3306 treat warnings as errors
3307 @end table
3308
3309 All warnings are output by default.
3310
3311 @vindex WARNINGS
3312 The environment variable @env{WARNINGS} is honored in the same
3313 way as it is for @command{automake} (@pxref{automake Invocation}).
3314
3315 @end table
3316
3317 @node Macro Search Path
3318 @subsection Macro Search Path
3319
3320 @cindex Macro search path
3321 @cindex @command{aclocal} search path
3322
3323 By default, @command{aclocal} searches for @file{.m4} files in the following
3324 directories, in this order:
3325
3326 @table @code
3327 @item @var{acdir-APIVERSION}
3328 This is where the @file{.m4} macros distributed with Automake itself
3329 are stored.  @var{APIVERSION} depends on the Automake release used;
3330 for example, for Automake 1.11.x, @var{APIVERSION} = @code{1.11}.
3331
3332 @item @var{acdir}
3333 This directory is intended for third party @file{.m4} files, and is
3334 configured when @command{automake} itself is built.  This is
3335 @file{@@datadir@@/aclocal/}, which typically
3336 expands to @file{$@{prefix@}/share/aclocal/}.  To find the compiled-in
3337 value of @var{acdir}, use the @option{--print-ac-dir} option
3338 (@pxref{aclocal Options}).
3339 @end table
3340
3341 As an example, suppose that @command{automake-1.11.2} was configured with
3342 @option{--prefix=@-/usr/local}.  Then, the search path would be:
3343
3344 @enumerate
3345 @item @file{/usr/local/share/aclocal-1.11.2/}
3346 @item @file{/usr/local/share/aclocal/}
3347 @end enumerate
3348
3349 The paths for the @var{acdir} and @var{acdir-APIVERSION} directories can
3350 be changed respectively through aclocal options @option{--system-acdir}
3351 and @option{--automake-acdir} (@pxref{aclocal Options}).  Note however
3352 that these options are only intended for use by the internal Automake
3353 test suite, or for debugging under highly unusual situations; they are
3354 not ordinarily needed by end-users.
3355
3356 As explained in (@pxref{aclocal Options}), there are several options that
3357 can be used to change or extend this search path.
3358
3359 @subsubheading Modifying the Macro Search Path: @samp{-I @var{dir}}
3360
3361 Any extra directories specified using @option{-I} options
3362 (@pxref{aclocal Options}) are @emph{prepended} to this search list.  Thus,
3363 @samp{aclocal -I /foo -I /bar} results in the following search path:
3364
3365 @enumerate
3366 @item @file{/foo}
3367 @item @file{/bar}
3368 @item @var{acdir}-@var{APIVERSION}
3369 @item @var{acdir}
3370 @end enumerate
3371
3372 @subsubheading Modifying the Macro Search Path: @file{dirlist}
3373 @cindex @file{dirlist}
3374
3375 There is a third mechanism for customizing the search path.  If a
3376 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
3377 contain a list of directory patterns, one per line.  @command{aclocal}
3378 expands these patterns to directory names, and adds them to the search
3379 list @emph{after} all other directories.  @file{dirlist} entries may
3380 use shell wildcards such as @samp{*}, @samp{?}, or @code{[...]}.
3381
3382 For example, suppose
3383 @file{@var{acdir}/dirlist} contains the following:
3384
3385 @example
3386 /test1
3387 /test2
3388 /test3*
3389 @end example
3390
3391 @noindent
3392 and that @command{aclocal} was called with the @samp{-I /foo -I /bar} options.
3393 Then, the search path would be
3394
3395 @c @code looks better than @file here
3396 @enumerate
3397 @item @code{/foo}
3398 @item @code{/bar}
3399 @item @var{acdir}-@var{APIVERSION}
3400 @item @var{acdir}
3401 @item @code{/test1}
3402 @item @code{/test2}
3403 @end enumerate
3404
3405 @noindent
3406 and all directories with path names starting with @code{/test3}.
3407
3408 If the @option{--system-acdir=@var{dir}} option is used, then
3409 @command{aclocal} will search for the @file{dirlist} file in
3410 @var{dir}; but remember the warnings  above against the use of
3411 @option{--system-acdir}.
3412
3413 @file{dirlist} is useful in the following situation: suppose that
3414 @command{automake} version @code{1.11.2} is installed with
3415 @samp{--prefix=/usr} by the system vendor.  Thus, the default search
3416 directories are
3417
3418 @c @code looks better than @file here
3419 @enumerate
3420 @item @code{/usr/share/aclocal-1.11/}
3421 @item @code{/usr/share/aclocal/}
3422 @end enumerate
3423
3424 However, suppose further that many packages have been manually
3425 installed on the system, with $prefix=/usr/local, as is typical.  In
3426 that case, many of these ``extra'' @file{.m4} files are in
3427 @file{/usr/local/share/aclocal}.  The only way to force
3428 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files is to
3429 always call @samp{aclocal -I /usr/local/share/aclocal}.  This is
3430 inconvenient.  With @file{dirlist}, one may create a file
3431 @file{/usr/share/aclocal/dirlist} containing only the single line
3432
3433 @example
3434 /usr/local/share/aclocal
3435 @end example
3436
3437 Now, the ``default'' search path on the affected system is
3438
3439 @c @code looks better than @file here
3440 @enumerate
3441 @item @code{/usr/share/aclocal-1.11/}
3442 @item @code{/usr/share/aclocal/}
3443 @item @code{/usr/local/share/aclocal/}
3444 @end enumerate
3445
3446 without the need for @option{-I} options; @option{-I} options can be reserved
3447 for project-specific needs (@file{my-source-dir/m4/}), rather than
3448 using it to work around local system-dependent tool installation
3449 directories.
3450
3451 Similarly, @file{dirlist} can be handy if you have installed a local
3452 copy of Automake in your account and want @command{aclocal} to look for
3453 macros installed at other places on the system.
3454
3455 @anchor{ACLOCAL_PATH}
3456 @subsubheading Modifying the Macro Search Path: @file{ACLOCAL_PATH}
3457 @cindex @env{ACLOCAL_PATH}
3458
3459 The fourth and last mechanism to customize the macro search path is
3460 also the simplest.  Any directory included in the colon-separated
3461 environment variable @env{ACLOCAL_PATH} is added to the search path
3462 @c Keep in sync with aclocal-path-precedence.sh
3463 and takes precedence over system directories (including those found via
3464 @file{dirlist}), with the exception of the versioned directory
3465 @var{acdir-APIVERSION} (@pxref{Macro Search Path}).  However, directories
3466 passed via @option{-I} will take precedence over directories in
3467 @env{ACLOCAL_PATH}.
3468
3469 @c Keep in sync with aclocal-path-installed.sh
3470 Also note that, if the @option{--install} option is used, any @file{.m4}
3471 file containing a required macro that is found in a directory listed in
3472 @env{ACLOCAL_PATH} will be installed locally.
3473 @c Keep in sync with aclocal-path-installed-serial.sh
3474 In this case, serial numbers in @file{.m4} are honoured too,
3475 @pxref{Serials}.
3476
3477 Conversely to @file{dirlist}, @env{ACLOCAL_PATH} is useful if you are
3478 using a global copy of Automake and want @command{aclocal} to look for
3479 macros somewhere under your home directory.
3480
3481 @subsubheading Planned future incompatibilities
3482
3483 The order in which the directories in the macro search path are currently
3484 looked up is confusing and/or suboptimal in various aspects, and is
3485 probably going to be changed in the future Automake release.  In
3486 particular, directories in @env{ACLOCAL_PATH} and @file{@var{acdir}}
3487 might end up taking precedence over @file{@var{acdir-APIVERSION}}, and
3488 directories in @file{@var{acdir}/dirlist} might end up taking precedence
3489 over @file{@var{acdir}}.  @emph{This is a possible future incompatibility!}
3490
3491 @node Extending aclocal
3492 @subsection Writing your own aclocal macros
3493
3494 @cindex @command{aclocal}, extending
3495 @cindex Extending @command{aclocal}
3496
3497 The @command{aclocal} program doesn't have any built-in knowledge of any
3498 macros, so it is easy to extend it with your own macros.
3499
3500 This can be used by libraries that want to supply their own Autoconf
3501 macros for use by other programs.  For instance, the @command{gettext}
3502 library supplies a macro @code{AM_GNU_GETTEXT} that should be used by
3503 any package using @command{gettext}.  When the library is installed, it
3504 installs this macro so that @command{aclocal} will find it.
3505
3506 A macro file's name should end in @file{.m4}.  Such files should be
3507 installed in @file{$(datadir)/aclocal}.  This is as simple as writing:
3508
3509 @c Keep in sync with primary-prefix-couples-documented-valid.sh
3510 @example
3511 aclocaldir = $(datadir)/aclocal
3512 aclocal_DATA = mymacro.m4 myothermacro.m4
3513 @end example
3514
3515 @noindent
3516 Please do use @file{$(datadir)/aclocal}, and not something based on
3517 the result of @samp{aclocal --print-ac-dir} (@pxref{Hard-Coded Install
3518 Paths}, for arguments).  It might also be helpful to suggest to
3519 the user to add the @file{$(datadir)/aclocal} directory to his
3520 @env{ACLOCAL_PATH} variable (@pxref{ACLOCAL_PATH}) so that
3521 @command{aclocal} will find the @file{.m4} files installed by your
3522 package automatically.
3523
3524 A file of macros should be a series of properly quoted
3525 @code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
3526 Autoconf Manual}).  The @command{aclocal} programs also understands
3527 @code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
3528 Autoconf Manual}), so it is safe to put each macro in a separate file.
3529 Each file should have no side effects but macro definitions.
3530 Especially, any call to @code{AC_PREREQ} should be done inside the
3531 defined macro, not at the beginning of the file.
3532
3533 @cindex underquoted @code{AC_DEFUN}
3534 @acindex AC_DEFUN
3535 @acindex AC_PREREQ
3536
3537 Starting with Automake 1.8, @command{aclocal} will warn about all
3538 underquoted calls to @code{AC_DEFUN}.  We realize this will annoy a
3539 lot of people, because @command{aclocal} was not so strict in the past
3540 and many third party macros are underquoted; and we have to apologize
3541 for this temporary inconvenience.  The reason we have to be stricter
3542 is that a future implementation of @command{aclocal} (@pxref{Future of
3543 aclocal}) will have to temporarily include all of these third party
3544 @file{.m4} files, maybe several times, including even files that are
3545 not actually needed.  Doing so should alleviate many problems of the
3546 current implementation, however it requires a stricter style from the
3547 macro authors.  Hopefully it is easy to revise the existing macros.
3548 For instance,
3549
3550 @example
3551 # bad style
3552 AC_PREREQ(2.68)
3553 AC_DEFUN(AX_FOOBAR,
3554 [AC_REQUIRE([AX_SOMETHING])dnl
3555 AX_FOO
3556 AX_BAR
3557 ])
3558 @end example
3559
3560 @noindent
3561 should be rewritten as
3562
3563 @example
3564 AC_DEFUN([AX_FOOBAR],
3565 [AC_PREREQ([2.68])dnl
3566 AC_REQUIRE([AX_SOMETHING])dnl
3567 AX_FOO
3568 AX_BAR
3569 ])
3570 @end example
3571
3572 Wrapping the @code{AC_PREREQ} call inside the macro ensures that
3573 Autoconf 2.68 will not be required if @code{AX_FOOBAR} is not actually
3574 used.  Most importantly, quoting the first argument of @code{AC_DEFUN}
3575 allows the macro to be redefined or included twice (otherwise this
3576 first argument would be expanded during the second definition).  For
3577 consistency we like to quote even arguments such as @code{2.68} that
3578 do not require it.
3579
3580 If you have been directed here by the @command{aclocal} diagnostic but
3581 are not the maintainer of the implicated macro, you will want to
3582 contact the maintainer of that macro.  Please make sure you have the
3583 latest version of the macro and that the problem hasn't already been
3584 reported before doing so: people tend to work faster when they aren't
3585 flooded by mails.
3586
3587 Another situation where @command{aclocal} is commonly used is to
3588 manage macros that are used locally by the package, @ref{Local
3589 Macros}.
3590
3591 @node Local Macros
3592 @subsection Handling Local Macros
3593
3594 Feature tests offered by Autoconf do not cover all needs.  People
3595 often have to supplement existing tests with their own macros, or
3596 with third-party macros.
3597
3598 There are two ways to organize custom macros in a package.
3599
3600 The first possibility (the historical practice) is to list all your
3601 macros in @file{acinclude.m4}.  This file will be included in
3602 @file{aclocal.m4} when you run @command{aclocal}, and its macro(s) will
3603 henceforth be visible to @command{autoconf}.  However if it contains
3604 numerous macros, it will rapidly become difficult to maintain, and it
3605 will be almost impossible to share macros between packages.
3606
3607 The second possibility, which we do recommend, is to write each macro
3608 in its own file and gather all these files in a directory.  This
3609 directory is usually called @file{m4/}.  Then it's enough to update
3610 @file{configure.ac} by adding a proper call to @code{AC_CONFIG_MACRO_DIRS}:
3611
3612 @example
3613 AC_CONFIG_MACRO_DIRS([m4])
3614 @end example
3615
3616 @command{aclocal} will then take care of automatically adding @file{m4/}
3617 to its search path for m4 files.
3618
3619 When @samp{aclocal} is run, it will build an @file{aclocal.m4}
3620 that @code{m4_include}s any file from @file{m4/} that defines a
3621 required macro.  Macros not found locally will still be searched in
3622 system-wide directories, as explained in @ref{Macro Search Path}.
3623
3624 Custom macros should be distributed for the same reason that
3625 @file{configure.ac} is: so that other people have all the sources of
3626 your package if they want to work on it.  Actually, this distribution
3627 happens automatically because all @code{m4_include}d files are
3628 distributed.
3629
3630 However there is no consensus on the distribution of third-party
3631 macros that your package may use.  Many libraries install their own
3632 macro in the system-wide @command{aclocal} directory (@pxref{Extending
3633 aclocal}).  For instance, Guile ships with a file called
3634 @file{guile.m4} that contains the macro @code{GUILE_FLAGS} that can
3635 be used to define setup compiler and linker flags appropriate for
3636 using Guile.  Using @code{GUILE_FLAGS} in @file{configure.ac} will
3637 cause @command{aclocal} to copy @file{guile.m4} into
3638 @file{aclocal.m4}, but as @file{guile.m4} is not part of the project,
3639 it will not be distributed.  Technically, that means a user who
3640 needs to rebuild @file{aclocal.m4} will have to install Guile first.
3641 This is probably OK, if Guile already is a requirement to build the
3642 package.  However, if Guile is only an optional feature, or if your
3643 package might run on architectures where Guile cannot be installed,
3644 this requirement will hinder development.  An easy solution is to copy
3645 such third-party macros in your local @file{m4/} directory so they get
3646 distributed.
3647
3648 Since Automake 1.10, @command{aclocal} offers the option @code{--install}
3649 to copy these system-wide third-party macros in your local macro directory,
3650 helping to solve the above problem.
3651
3652 With this setup, system-wide macros will be copied to @file{m4/}
3653 the first time you run @command{aclocal}.  Then the locally installed
3654 macros will have precedence over the system-wide installed macros
3655 each time @command{aclocal} is run again.
3656
3657 One reason why you should keep @option{--install} in the flags even
3658 after the first run is that when you later edit @file{configure.ac}
3659 and depend on a new macro, this macro will be installed in your
3660 @file{m4/} automatically.  Another one is that serial numbers
3661 (@pxref{Serials}) can be used to update the macros in your source tree
3662 automatically when new system-wide versions are installed.  A serial
3663 number should be a single line of the form
3664
3665 @example
3666 #serial @var{nnn}
3667 @end example
3668
3669 @noindent
3670 where @var{nnn} contains only digits and dots.  It should appear in
3671 the M4 file before any macro definition.  It is a good practice to
3672 maintain a serial number for each macro you distribute, even if you do
3673 not use the @option{--install} option of @command{aclocal}: this allows
3674 other people to use it.
3675
3676
3677 @node Serials
3678 @subsection Serial Numbers
3679 @cindex serial numbers in macros
3680 @cindex macro serial numbers
3681 @cindex @code{#serial} syntax
3682 @cindex @command{aclocal} and serial numbers
3683
3684 Because third-party macros defined in @file{*.m4} files are naturally
3685 shared between multiple projects, some people like to version them.
3686 This makes it easier to tell which of two M4 files is newer.  Since at
3687 least 1996, the tradition is to use a @samp{#serial} line for this.
3688
3689 A serial number should be a single line of the form
3690
3691 @example
3692 # serial @var{version}
3693 @end example
3694
3695 @noindent
3696 where @var{version} is a version number containing only digits and
3697 dots.  Usually people use a single integer, and they increment it each
3698 time they change the macro (hence the name of ``serial'').  Such a
3699 line should appear in the M4 file before any macro definition.
3700
3701 The @samp{#} must be the first character on the line,
3702 and it is OK to have extra words after the version, as in
3703
3704 @example
3705 #serial @var{version} @var{garbage}
3706 @end example
3707
3708 Normally these serial numbers are completely ignored by
3709 @command{aclocal} and @command{autoconf}, like any genuine comment.
3710 However when using @command{aclocal}'s @option{--install} feature, these
3711 serial numbers will modify the way @command{aclocal} selects the
3712 macros to install in the package: if two files with the same basename
3713 exist in your search path, and if at least one of them uses a
3714 @samp{#serial} line, @command{aclocal} will ignore the file that has
3715 the older @samp{#serial} line (or the file that has none).
3716
3717 Note that a serial number applies to a whole M4 file, not to any macro
3718 it contains.  A file can contains multiple macros, but only one
3719 serial.
3720
3721 Here is a use case that illustrates the use of @option{--install} and
3722 its interaction with serial numbers.  Let's assume we maintain a
3723 package called MyPackage, the @file{configure.ac} of which requires a
3724 third-party macro @code{AX_THIRD_PARTY} defined in
3725 @file{/usr/share/aclocal/thirdparty.m4} as follows:
3726
3727 @example
3728 # serial 1
3729 AC_DEFUN([AX_THIRD_PARTY], [...])
3730 @end example
3731
3732 MyPackage uses an @file{m4/} directory to store local macros as
3733 explained in @ref{Local Macros}, and has
3734
3735 @example
3736 AC_CONFIG_MACRO_DIRS([m4])
3737 @end example
3738
3739 @noindent
3740 in its @file{configure.ac}.
3741
3742 Initially the @file{m4/} directory is empty.  The first time we run
3743 @command{aclocal --install}, it will notice that
3744
3745 @itemize @bullet
3746 @item
3747 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3748 @item
3749 No local macros define @code{AX_THIRD_PARTY}
3750 @item
3751 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3752 with serial 1.
3753 @end itemize
3754
3755 @noindent
3756 Because @file{/usr/share/aclocal/thirdparty.m4} is a system-wide macro
3757 and @command{aclocal} was given the @option{--install} option, it will
3758 copy this file in @file{m4/thirdparty.m4}, and output an
3759 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3760
3761 The next time @samp{aclocal --install} is run, something different
3762 happens.  @command{aclocal} notices that
3763
3764 @itemize @bullet
3765 @item
3766 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3767 @item
3768 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3769 with serial 1.
3770 @item
3771 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3772 with serial 1.
3773 @end itemize
3774
3775 @noindent
3776 Because both files have the same serial number, @command{aclocal} uses
3777 the first it found in its search path order (@pxref{Macro Search
3778 Path}).  @command{aclocal} therefore ignores
3779 @file{/usr/share/aclocal/thirdparty.m4} and outputs an
3780 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3781
3782 Local directories specified with @option{-I} are always searched before
3783 system-wide directories, so a local file will always be preferred to
3784 the system-wide file in case of equal serial numbers.
3785
3786 Now suppose the system-wide third-party macro is changed.  This can
3787 happen if the package installing this macro is updated.  Let's suppose
3788 the new macro has serial number 2.  The next time @samp{aclocal --install}
3789 is run the situation is the following:
3790
3791 @itemize @bullet
3792 @item
3793 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3794 @item
3795 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3796 with serial 1.
3797 @item
3798 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3799 with serial 2.
3800 @end itemize
3801
3802 @noindent
3803 When @command{aclocal} sees a greater serial number, it immediately
3804 forgets anything it knows from files that have the same basename and a
3805 smaller serial number.  So after it has found
3806 @file{/usr/share/aclocal/thirdparty.m4} with serial 2,
3807 @command{aclocal} will proceed as if it had never seen
3808 @file{m4/thirdparty.m4}.  This brings us back to a situation similar
3809 to that at the beginning of our example, where no local file defined
3810 the macro.  @command{aclocal} will install the new version of the
3811 macro in @file{m4/thirdparty.m4}, in this case overriding the old
3812 version.  MyPackage just had its macro updated as a side effect of
3813 running @command{aclocal}.
3814
3815 If you are leery of letting @command{aclocal} update your local
3816 macro, you can run @samp{aclocal --diff} to review the changes
3817 @samp{aclocal --install} would perform on these macros.
3818
3819 Finally, note that the @option{--force} option of @command{aclocal} has
3820 absolutely no effect on the files installed by @option{--install}.  For
3821 instance, if you have modified your local macros, do not expect
3822 @option{--install --force} to replace the local macros by their
3823 system-wide versions.  If you want to do so, simply erase the local
3824 macros you want to revert, and run @samp{aclocal --install}.
3825
3826
3827 @node Future of aclocal
3828 @subsection The Future of @command{aclocal}
3829 @cindex @command{aclocal}'s scheduled death
3830
3831 @command{aclocal} is expected to disappear.  This feature really
3832 should not be offered by Automake.  Automake should focus on
3833 generating @file{Makefile}s; dealing with M4 macros really is
3834 Autoconf's job.  The fact that some people install Automake just to use
3835 @command{aclocal}, but do not use @command{automake} otherwise is an
3836 indication of how that feature is misplaced.
3837
3838 The new implementation will probably be done slightly differently.
3839 For instance, it could enforce the @file{m4/}-style layout discussed in
3840 @ref{Local Macros}.
3841
3842 We have no idea when and how this will happen.  This has been
3843 discussed several times in the past, but someone still has to commit
3844 to that non-trivial task.
3845
3846 From the user point of view, @command{aclocal}'s removal might turn
3847 out to be painful.  There is a simple precaution that you may take to
3848 make that switch more seamless: never call @command{aclocal} yourself.
3849 Keep this guy under the exclusive control of @command{autoreconf} and
3850 Automake's rebuild rules.  Hopefully you won't need to worry about
3851 things breaking, when @command{aclocal} disappears, because everything
3852 will have been taken care of.  If otherwise you used to call
3853 @command{aclocal} directly yourself or from some script, you will
3854 quickly notice the change.
3855
3856 Many packages come with a script called @file{bootstrap.sh} or
3857 @file{autogen.sh}, that will just call @command{aclocal},
3858 @command{libtoolize}, @command{gettextize} or @command{autopoint},
3859 @command{autoconf}, @command{autoheader}, and @command{automake} in
3860 the right order.  Actually this is precisely what @command{autoreconf}
3861 can do for you.  If your package has such a @file{bootstrap.sh} or
3862 @file{autogen.sh} script, consider using @command{autoreconf}.  That
3863 should simplify its logic a lot (less things to maintain, yum!), it's
3864 even likely you will not need the script anymore, and more to the point
3865 you will not call @command{aclocal} directly anymore.
3866
3867 For the time being, third-party packages should continue to install
3868 public macros into @file{/usr/share/aclocal/}.  If @command{aclocal}
3869 is replaced by another tool it might make sense to rename the
3870 directory, but supporting @file{/usr/share/aclocal/} for backward
3871 compatibility should be really easy provided all macros are properly
3872 written (@pxref{Extending aclocal}).
3873
3874
3875
3876 @node Macros
3877 @section Autoconf macros supplied with Automake
3878
3879 Automake ships with several Autoconf macros that you can use from your
3880 @file{configure.ac}.  When you use one of them it will be included by
3881 @command{aclocal} in @file{aclocal.m4}.
3882
3883 @menu
3884 * Public Macros::               Macros that you can use.
3885 * Obsolete Macros::             Macros that will soon be removed.
3886 * Private Macros::              Macros that you should not use.
3887 @end menu
3888
3889 @c consider generating the following subsections automatically from m4 files.
3890
3891 @node Public Macros
3892 @subsection Public Macros
3893
3894 @table @code
3895
3896 @item AM_INIT_AUTOMAKE([OPTIONS])
3897 @acindex AM_INIT_AUTOMAKE
3898 Runs many macros required for proper operation of the generated Makefiles.
3899
3900 @vindex AUTOMAKE_OPTIONS
3901 Today, @code{AM_INIT_AUTOMAKE} is called with a single argument: a
3902 space-separated list of Automake options that should be applied to
3903 every @file{Makefile.am} in the tree.  The effect is as if
3904 each option were listed in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
3905
3906 @acindex AC_INIT
3907 This macro can also be called in another, @emph{deprecated} form:
3908 @code{AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])}.  In this form,
3909 there are two required arguments: the package and the version number.
3910 This usage is mostly obsolete because the @var{package} and @var{version}
3911 can be obtained from Autoconf's @code{AC_INIT} macro.  However,
3912 differently from what happens for @code{AC_INIT} invocations, this
3913 @code{AM_INIT_AUTOMAKE} invocation supports shell variables' expansions
3914 in the @code{PACKAGE} and @code{VERSION} arguments, and this can be
3915 still be useful in some selected situations.  Our hope is that future
3916 Autoconf versions will improve their support for package versions
3917 defined dynamically at configure runtime; when (and if) this happens,
3918 support for the two-args @code{AM_INIT_AUTOMAKE} invocation will likely
3919 be removed from Automake.
3920
3921 @anchor{Modernize AM_INIT_AUTOMAKE invocation}
3922 If your @file{configure.ac} has:
3923
3924 @example
3925 AC_INIT([src/foo.c])
3926 AM_INIT_AUTOMAKE([mumble], [1.5])
3927 @end example
3928
3929 @noindent
3930 you should modernize it as follows:
3931
3932 @example
3933 AC_INIT([mumble], [1.5])
3934 AC_CONFIG_SRCDIR([src/foo.c])
3935 AM_INIT_AUTOMAKE
3936 @end example
3937
3938 Note that if you're upgrading your @file{configure.ac} from an earlier
3939 version of Automake, it is not always correct to simply move the
3940 package and version arguments from @code{AM_INIT_AUTOMAKE} directly to
3941 @code{AC_INIT}, as in the example above.  The first argument to
3942 @code{AC_INIT} should be the name of your package (e.g., @samp{GNU
3943 Automake}), not the tarball name (e.g., @samp{automake}) that you used
3944 to pass to @code{AM_INIT_AUTOMAKE}.  Autoconf tries to derive a
3945 tarball name from the package name, which should work for most but not
3946 all package names.  (If it doesn't work for yours, you can use the
3947 four-argument form of @code{AC_INIT} to provide the tarball name
3948 explicitly).
3949
3950 @cindex @code{PACKAGE}, prevent definition
3951 @cindex @code{VERSION}, prevent definition
3952 @opindex no-define
3953 By default this macro @code{AC_DEFINE}'s @code{PACKAGE} and
3954 @code{VERSION}.  This can be avoided by passing the @option{no-define}
3955 option (@pxref{List of Automake options}):
3956 @example
3957 AM_INIT_AUTOMAKE([no-define ...])
3958 @end example
3959
3960 @item AM_PATH_LISPDIR
3961 @acindex AM_PATH_LISPDIR
3962 @vindex EMACS
3963 @vindex lispdir
3964 Searches for the program @command{emacs}, and, if found, sets the
3965 output variable @code{lispdir} to the full path to Emacs' site-lisp
3966 directory.
3967
3968 Note that this test assumes the @command{emacs} found to be a version
3969 that supports Emacs Lisp (such as GNU Emacs or XEmacs).  Other
3970 emacsen can cause this test to hang (some, like old versions of
3971 MicroEmacs, start up in interactive mode, requiring @kbd{C-x C-c} to
3972 exit, which is hardly obvious for a non-emacs user).  In most cases,
3973 however, you should be able to use @kbd{C-c} to kill the test.  In
3974 order to avoid problems, you can set @env{EMACS} to ``no'' in the
3975 environment, or use the @option{--with-lispdir} option to
3976 @command{configure} to explicitly set the correct path (if you're sure
3977 you have an @command{emacs} that supports Emacs Lisp).
3978
3979 @item AM_PROG_AR(@ovar{act-if-fail})
3980 @acindex AM_PROG_AR
3981 @vindex AR
3982 You must use this macro when you use the archiver in your project, if
3983 you want support for unusual archivers such as Microsoft @command{lib}.
3984 The content of the optional argument is executed if the archiver
3985 interface is not recognized; the default action is to abort configure
3986 with an error message.
3987
3988 @item AM_PROG_AS
3989 @acindex AM_PROG_AS
3990 @vindex CCAS
3991 @vindex CCASFLAGS
3992 Use this macro when you have assembly code in your project.  This will
3993 choose the assembler for you (by default the C compiler) and set
3994 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
3995
3996 @item AM_PROG_CC_C_O
3997 @acindex AM_PROG_CC_C_O
3998 @acindex AC_PROG_CC_C_O
3999 This is like @code{AC_PROG_CC_C_O}, but it generates its results in
4000 the manner required by Automake.  You must use this instead of
4001 @code{AC_PROG_CC_C_O} when you need this functionality, that is, when
4002 using per-target flags or subdir-objects with C sources.
4003
4004 @item AM_PROG_LEX
4005 @acindex AM_PROG_LEX
4006 @acindex AC_PROG_LEX
4007 @cindex HP-UX 10, @command{lex} problems
4008 @cindex @command{lex} problems with HP-UX 10
4009 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
4010 Program Checks, autoconf, The Autoconf Manual}), but uses the
4011 @command{missing} script on systems that do not have @command{lex}.
4012 HP-UX 10 is one such system.
4013
4014 @item AM_PROG_GCJ
4015 @acindex AM_PROG_GCJ
4016 @vindex GCJ
4017 @vindex GCJFLAGS
4018 This macro finds the @command{gcj} program or causes an error.  It sets
4019 @code{GCJ} and @code{GCJFLAGS}.  @command{gcj} is the Java front-end to the
4020 GNU Compiler Collection.
4021
4022 @item AM_PROG_UPC([@var{compiler-search-list}])
4023 @acindex AM_PROG_UPC
4024 @vindex UPC
4025 Find a compiler for Unified Parallel C and define the @code{UPC}
4026 variable.  The default @var{compiler-search-list} is @samp{upcc upc}.
4027 This macro will abort @command{configure} if no Unified Parallel C
4028 compiler is found.
4029
4030 @item AM_MISSING_PROG(@var{name}, @var{program})
4031 @acindex AM_MISSING_PROG
4032 @vindex MISSING
4033 Find a maintainer tool @var{program} and define the @var{name}
4034 environment variable with its location.  If @var{program} is not
4035 detected, then @var{name} will instead invoke the @command{missing}
4036 script, in order to give useful advice to the user about the missing
4037 maintainer tool.  @xref{maintainer-mode}, for more information on when
4038 the @command{missing} script is appropriate.
4039
4040 @item AM_SILENT_RULES
4041 @acindex AM_SILENT_RULES
4042 Control the machinery for less verbose build output
4043 (@pxref{Automake Silent Rules}).
4044
4045 @item AM_WITH_DMALLOC
4046 @acindex AM_WITH_DMALLOC
4047 @cindex @command{dmalloc}, support for
4048 @vindex WITH_DMALLOC
4049 @opindex --with-dmalloc
4050 Add support for the @uref{http://dmalloc.com/, Dmalloc package}.  If
4051 the user runs @command{configure} with @option{--with-dmalloc}, then
4052 define @code{WITH_DMALLOC} and add @option{-ldmalloc} to @code{LIBS}.
4053
4054 @end table
4055
4056
4057 @node Obsolete Macros
4058 @subsection Obsolete Macros
4059 @cindex obsolete macros
4060 @cindex autoupdate
4061
4062 Although using some of the following macros was required in past
4063 releases, you should not use any of them in new code.  @emph{All
4064 these macros will be removed in the next major Automake version};
4065 if you are still using them, running @command{autoupdate} should
4066 adjust your @file{configure.ac} automatically (@pxref{autoupdate
4067 Invocation, , Using @command{autoupdate} to Modernize
4068 @file{configure.ac}, autoconf, The Autoconf Manual}).
4069 @emph{Do it NOW!}
4070
4071 @table @code
4072
4073 @item AM_PROG_MKDIR_P
4074 @acindex AM_PROG_MKDIR_P
4075 @cindex @code{mkdir -p}, macro check
4076 @vindex MKDIR_P
4077 @vindex mkdir_p
4078
4079 From Automake 1.8 to 1.9.6 this macro used to define the output
4080 variable @code{mkdir_p} to one of @code{mkdir -p}, @code{install-sh
4081 -d}, or @code{mkinstalldirs}.
4082
4083 Nowadays Autoconf provides a similar functionality with
4084 @code{AC_PROG_MKDIR_P} (@pxref{Particular Programs, , Particular
4085 Program Checks, autoconf, The Autoconf Manual}), however this defines
4086 the output variable @code{MKDIR_P} instead.  In case you are still
4087 using the @code{AM_PROG_MKDIR_P} macro in your @file{configure.ac},
4088 or its provided variable @code{$(mkdir_p)} in your @file{Makefile.am},
4089 you are advised to switch ASAP to the more modern Autoconf-provided
4090 interface instead; both the macro and the variable @emph{will be
4091 removed} in the next major Automake release.
4092
4093 @end table
4094
4095
4096 @node Private Macros
4097 @subsection Private Macros
4098
4099 The following macros are private macros you should not call directly.
4100 They are called by the other public macros when appropriate.  Do not
4101 rely on them, as they might be changed in a future version.  Consider
4102 them as implementation details; or better, do not consider them at all:
4103 skip this section!
4104
4105 @ftable @code
4106 @item _AM_DEPENDENCIES
4107 @itemx AM_SET_DEPDIR
4108 @itemx AM_DEP_TRACK
4109 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
4110 These macros are used to implement Automake's automatic dependency
4111 tracking scheme.  They are called automatically by Automake when
4112 required, and there should be no need to invoke them manually.
4113
4114 @item AM_MAKE_INCLUDE
4115 This macro is used to discover how the user's @command{make} handles
4116 @code{include} statements.  This macro is automatically invoked when
4117 needed; there should be no need to invoke it manually.
4118
4119 @item AM_PROG_INSTALL_STRIP
4120 This is used to find a version of @code{install} that can be used to
4121 strip a program at installation time.  This macro is automatically
4122 included when required.
4123
4124 @item AM_SANITY_CHECK
4125 This checks to make sure that a file created in the build directory is
4126 newer than a file in the source directory.  This can fail on systems
4127 where the clock is set incorrectly.  This macro is automatically run
4128 from @code{AM_INIT_AUTOMAKE}.
4129
4130 @end ftable
4131
4132
4133 @node Directories
4134 @chapter Directories
4135
4136 For simple projects that distribute all files in the same directory
4137 it is enough to have a single @file{Makefile.am} that builds
4138 everything in place.
4139
4140 In larger projects, it is common to organize files in different
4141 directories, in a tree.  For example, there could be a directory
4142 for the program's source, one for the testsuite, and one for the
4143 documentation; or, for very large projects, there could be one
4144 directory per program, per library or per module.
4145
4146 The traditional approach is to build these subdirectories recursively,
4147 employing @emph{make recursion}: each directory contains its
4148 own @file{Makefile}, and when @command{make} is run from the top-level
4149 directory, it enters each subdirectory in turn, and invokes there a
4150 new @command{make} instance to build the directory's contents.
4151
4152 Because this approach is very widespread, Automake offers built-in
4153 support for it.  However, it is worth nothing that the use of make
4154 recursion has its own serious issues and drawbacks, and that it's
4155 well possible to have packages with a multi directory layout that
4156 make little or no use of such recursion (examples of such packages
4157 are GNU Bison and GNU Automake itself); see also the @ref{Alternative}
4158 section below.
4159
4160 @menu
4161 * Subdirectories::              Building subdirectories recursively
4162 * Conditional Subdirectories::  Conditionally not building directories
4163 * Alternative::                 Subdirectories without recursion
4164 * Subpackages::                 Nesting packages
4165 @end menu
4166
4167 @node Subdirectories
4168 @section Recursing subdirectories
4169
4170 @cindex @code{SUBDIRS}, explained
4171
4172 In packages using make recursion, the top level @file{Makefile.am} must
4173 tell Automake which subdirectories are to be built.  This is done via
4174 the @code{SUBDIRS} variable.
4175 @vindex SUBDIRS
4176
4177 The @code{SUBDIRS} variable holds a list of subdirectories in which
4178 building of various sorts can occur.  The rules for many targets
4179 (e.g., @code{all}) in the generated @file{Makefile} will run commands
4180 both locally and in all specified subdirectories.  Note that the
4181 directories listed in @code{SUBDIRS} are not required to contain
4182 @file{Makefile.am}s; only @file{Makefile}s (after configuration).
4183 This allows inclusion of libraries from packages that do not use
4184 Automake (such as @code{gettext}; see also @ref{Third-Party
4185 Makefiles}).
4186
4187 In packages that use subdirectories, the top-level @file{Makefile.am} is
4188 often very short.  For instance, here is the @file{Makefile.am} from the
4189 GNU Hello distribution:
4190
4191 @example
4192 EXTRA_DIST = BUGS ChangeLog.O README-alpha
4193 SUBDIRS = doc intl po src tests
4194 @end example
4195
4196 When Automake invokes @command{make} in a subdirectory, it uses the value
4197 of the @code{MAKE} variable.  It passes the value of the variable
4198 @code{AM_MAKEFLAGS} to the @command{make} invocation; this can be set in
4199 @file{Makefile.am} if there are flags you must always pass to
4200 @command{make}.
4201 @vindex MAKE
4202 @vindex AM_MAKEFLAGS
4203
4204 The directories mentioned in @code{SUBDIRS} are usually direct
4205 children of the current directory, each subdirectory containing its
4206 own @file{Makefile.am} with a @code{SUBDIRS} pointing to deeper
4207 subdirectories.  Automake can be used to construct packages of
4208 arbitrary depth this way.
4209
4210 By default, Automake generates @file{Makefiles} that work depth-first
4211 in postfix order: the subdirectories are built before the current
4212 directory.  However, it is possible to change this ordering.  You can
4213 do this by putting @samp{.} into @code{SUBDIRS}.  For instance,
4214 putting @samp{.} first will cause a prefix ordering of
4215 directories.
4216
4217 Using
4218
4219 @example
4220 SUBDIRS = lib src . test
4221 @end example
4222
4223 @noindent
4224 will cause @file{lib/} to be built before @file{src/}, then the
4225 current directory will be built, finally the @file{test/} directory
4226 will be built.  It is customary to arrange test directories to be
4227 built after everything else since they are meant to test what has
4228 been constructed.
4229
4230 In addition to the built-in recursive targets defined by Automake
4231 (@code{all}, @code{check}, etc.), the developer can also define his
4232 own recursive targets.  That is done by passing the names of such
4233 targets as arguments to the m4 macro @code{AM_EXTRA_RECURSIVE_TARGETS}
4234 in @file{configure.ac}.  Automake generates rules to handle the
4235 recursion for such targets; and the developer can define real actions
4236 for them by defining corresponding @code{-local} targets.
4237
4238 @example
4239 % @kbd{cat configure.ac}
4240 AC_INIT([pkg-name], [1.0]
4241 AM_INIT_AUTOMAKE
4242 AM_EXTRA_RECURSIVE_TARGETS([foo])
4243 AC_CONFIG_FILES([Makefile sub/Makefile sub/src/Makefile])
4244 AC_OUTPUT
4245 % @kbd{cat Makefile.am}
4246 SUBDIRS = sub
4247 foo-local:
4248         @@echo This will be run by "make foo".
4249 % @kbd{cat sub/Makefile.am}
4250 SUBDIRS = src
4251 % @kbd{cat sub/src/Makefile.am}
4252 foo-local:
4253         @@echo This too will be run by a "make foo" issued either in
4254         @@echo the 'sub/src/' directory, the 'sub/' directory, or the
4255         @@echo top-level directory.
4256 @end example
4257
4258 @node Conditional Subdirectories
4259 @section Conditional Subdirectories
4260 @cindex Subdirectories, building conditionally
4261 @cindex Conditional subdirectories
4262 @cindex @code{SUBDIRS}, conditional
4263 @cindex Conditional @code{SUBDIRS}
4264
4265 It is possible to define the @code{SUBDIRS} variable conditionally if,
4266 like in the case of GNU Inetutils, you want to only build a subset of
4267 the entire package.
4268
4269 To illustrate how this works, let's assume we have two directories
4270 @file{src/} and @file{opt/}.  @file{src/} should always be built, but we
4271 want to decide in @command{configure} whether @file{opt/} will be built
4272 or not.  (For this example we will assume that @file{opt/} should be
4273 built when the variable @samp{$want_opt} was set to @samp{yes}.)
4274
4275 Running @command{make} should thus recurse into @file{src/} always, and
4276 then maybe in @file{opt/}.
4277
4278 However @samp{make dist} should always recurse into both @file{src/}
4279 and @file{opt/}.  Because @file{opt/} should be distributed even if it
4280 is not needed in the current configuration.  This means
4281 @file{opt/Makefile} should be created @emph{unconditionally}.
4282
4283 There are two ways to setup a project like this.  You can use Automake
4284 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
4285 variables (@pxref{Setting Output Variables, , Setting Output
4286 Variables, autoconf, The Autoconf Manual}).  Using Automake
4287 conditionals is the preferred solution.  Before we illustrate these
4288 two possibilities, let's introduce @code{DIST_SUBDIRS}.
4289
4290 @menu
4291 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
4292 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
4293 * Subdirectories with AC_SUBST::  Another way for conditional recursion
4294 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
4295 @end menu
4296
4297 @node SUBDIRS vs DIST_SUBDIRS
4298 @subsection @code{SUBDIRS} vs.@: @code{DIST_SUBDIRS}
4299 @cindex @code{DIST_SUBDIRS}, explained
4300
4301 Automake considers two sets of directories, defined by the variables
4302 @code{SUBDIRS} and @code{DIST_SUBDIRS}.
4303
4304 @code{SUBDIRS} contains the subdirectories of the current directory
4305 that must be built (@pxref{Subdirectories}).  It must be defined
4306 manually; Automake will never guess a directory is to be built.  As we
4307 will see in the next two sections, it is possible to define it
4308 conditionally so that some directory will be omitted from the build.
4309
4310 @code{DIST_SUBDIRS} is used in rules that need to recurse in all
4311 directories, even those that have been conditionally left out of the
4312 build.  Recall our example where we may not want to build subdirectory
4313 @file{opt/}, but yet we want to distribute it?  This is where
4314 @code{DIST_SUBDIRS} comes into play: @samp{opt} may not appear in
4315 @code{SUBDIRS}, but it must appear in @code{DIST_SUBDIRS}.
4316
4317 Precisely, @code{DIST_SUBDIRS} is used by @samp{make
4318 maintainer-clean}, @samp{make distclean} and @samp{make dist}.  All
4319 other recursive rules use @code{SUBDIRS}.
4320
4321 If @code{SUBDIRS} is defined conditionally using Automake
4322 conditionals, Automake will define @code{DIST_SUBDIRS} automatically
4323 from the possible values of @code{SUBDIRS} in all conditions.
4324
4325 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
4326 @code{DIST_SUBDIRS} will not be defined correctly because Automake
4327 does not know the possible values of these variables.  In this case
4328 @code{DIST_SUBDIRS} needs to be defined manually.
4329
4330 @node Subdirectories with AM_CONDITIONAL
4331 @subsection Subdirectories with @code{AM_CONDITIONAL}
4332 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
4333 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
4334
4335 @c Keep in sync with subdir-am-cond.sh
4336
4337 @file{configure} should output the @file{Makefile} for each directory
4338 and define a condition into which @file{opt/} should be built.
4339
4340 @example
4341 @dots{}
4342 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
4343 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4344 @dots{}
4345 @end example
4346
4347 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
4348 as follows.
4349
4350 @example
4351 if COND_OPT
4352   MAYBE_OPT = opt
4353 endif
4354 SUBDIRS = src $(MAYBE_OPT)
4355 @end example
4356
4357 As you can see, running @command{make} will rightly recurse into
4358 @file{src/} and maybe @file{opt/}.
4359
4360 @vindex DIST_SUBDIRS
4361 As you can't see, running @samp{make dist} will recurse into both
4362 @file{src/} and @file{opt/} directories because @samp{make dist}, unlike
4363 @samp{make all}, doesn't use the @code{SUBDIRS} variable.  It uses the
4364 @code{DIST_SUBDIRS} variable.
4365
4366 In this case Automake will define @samp{DIST_SUBDIRS = src opt}
4367 automatically because it knows that @code{MAYBE_OPT} can contain
4368 @samp{opt} in some condition.
4369
4370 @node Subdirectories with AC_SUBST
4371 @subsection Subdirectories with @code{AC_SUBST}
4372 @cindex @code{SUBDIRS} and @code{AC_SUBST}
4373 @cindex @code{AC_SUBST} and @code{SUBDIRS}
4374
4375 @c Keep in sync with subdir-ac-subst.sh
4376
4377 Another possibility is to define @code{MAYBE_OPT} from
4378 @file{./configure} using @code{AC_SUBST}:
4379
4380 @example
4381 @dots{}
4382 if test "$want_opt" = yes; then
4383   MAYBE_OPT=opt
4384 else
4385   MAYBE_OPT=
4386 fi
4387 AC_SUBST([MAYBE_OPT])
4388 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4389 @dots{}
4390 @end example
4391
4392 In this case the top-level @file{Makefile.am} should look as follows.
4393
4394 @example
4395 SUBDIRS = src $(MAYBE_OPT)
4396 DIST_SUBDIRS = src opt
4397 @end example
4398
4399 The drawback is that since Automake cannot guess what the possible
4400 values of @code{MAYBE_OPT} are, it is necessary to define
4401 @code{DIST_SUBDIRS}.
4402
4403 @node Unconfigured Subdirectories
4404 @subsection Unconfigured Subdirectories
4405 @cindex Subdirectories, configured conditionally
4406
4407 The semantics of @code{DIST_SUBDIRS} are often misunderstood by some
4408 users that try to @emph{configure and build} subdirectories
4409 conditionally.  Here by configuring we mean creating the
4410 @file{Makefile} (it might also involve running a nested
4411 @command{configure} script: this is a costly operation that explains
4412 why people want to do it conditionally, but only the @file{Makefile}
4413 is relevant to the discussion).
4414
4415 The above examples all assume that every @file{Makefile} is created,
4416 even in directories that are not going to be built.  The simple reason
4417 is that we want @samp{make dist} to distribute even the directories
4418 that are not being built (e.g., platform-dependent code), hence
4419 @file{make dist} must recurse into the subdirectory, hence this
4420 directory must be configured and appear in @code{DIST_SUBDIRS}.
4421
4422 Building packages that do not configure every subdirectory is a tricky
4423 business, and we do not recommend it to the novice as it is easy to
4424 produce an incomplete tarball by mistake.  We will not discuss this
4425 topic in depth here, yet for the adventurous here are a few rules to
4426 remember.
4427
4428 @cartouche
4429 @itemize
4430 @item @code{SUBDIRS} should always be a subset of @code{DIST_SUBDIRS}.
4431
4432 It makes little sense to have a directory in @code{SUBDIRS} that
4433 is not in @code{DIST_SUBDIRS}.  Think of the former as a way to tell
4434 which directories listed in the latter should be built.
4435 @item Any directory listed in @code{DIST_SUBDIRS} and @code{SUBDIRS}
4436 must be configured.
4437
4438 I.e., the @file{Makefile} must exists or the recursive @command{make}
4439 rules will not be able to process the directory.
4440 @item Any configured directory must be listed in @code{DIST_SUBDIRS}.
4441
4442 So that the cleaning rules remove the generated @file{Makefile}s.
4443 It would be correct to see @code{DIST_SUBDIRS} as a variable that
4444 lists all the directories that have been configured.
4445 @end itemize
4446 @end cartouche
4447
4448 In order to prevent recursion in some unconfigured directory you
4449 must therefore ensure that this directory does not appear in
4450 @code{DIST_SUBDIRS} (and @code{SUBDIRS}).  For instance, if you define
4451 @code{SUBDIRS} conditionally using @code{AC_SUBST} and do not define
4452 @code{DIST_SUBDIRS} explicitly, it will be default to
4453 @samp{$(SUBDIRS)}; another possibility is to force @code{DIST_SUBDIRS
4454 = $(SUBDIRS)}.
4455
4456 Of course, directories that are omitted from @code{DIST_SUBDIRS} will
4457 not be distributed unless you make other arrangements for this to
4458 happen (for instance, always running @samp{make dist} in a
4459 configuration where all directories are known to appear in
4460 @code{DIST_SUBDIRS}; or writing a @code{dist-hook} target to
4461 distribute these directories).
4462
4463 @cindex Subdirectories, not distributed
4464 In few packages, unconfigured directories are not even expected to
4465 be distributed.  Although these packages do not require the
4466 aforementioned extra arrangements, there is another pitfall.  If the
4467 name of a directory appears in @code{SUBDIRS} or @code{DIST_SUBDIRS},
4468 @command{automake} will make sure the directory exists.  Consequently
4469 @command{automake} cannot be run on such a distribution when one
4470 directory has been omitted.  One way to avoid this check is to use the
4471 @code{AC_SUBST} method to declare conditional directories; since
4472 @command{automake} does not know the values of @code{AC_SUBST}
4473 variables it cannot ensure the corresponding directory exists.
4474
4475 @node Alternative
4476 @section An Alternative Approach to Subdirectories
4477
4478 If you've ever read Peter Miller's excellent paper,
4479 @uref{http://miller.emu.id.au/pmiller/books/rmch/,
4480 Recursive Make Considered Harmful}, the preceding sections on the use of
4481 make recursion will probably come as unwelcome advice.  For those who
4482 haven't read the paper, Miller's main thesis is that recursive
4483 @command{make} invocations are both slow and error-prone.
4484
4485 Automake provides sufficient cross-directory support @footnote{We
4486 believe.  This work is new and there are probably warts.
4487 @xref{Introduction}, for information on reporting bugs.} to enable you
4488 to write a single @file{Makefile.am} for a complex multi-directory
4489 package.
4490
4491 By default an installable file specified in a subdirectory will have its
4492 directory name stripped before installation.  For instance, in this
4493 example, the header file will be installed as
4494 @file{$(includedir)/stdio.h}:
4495
4496 @example
4497 include_HEADERS = inc/stdio.h
4498 @end example
4499
4500 @vindex nobase_
4501 @cindex @code{nobase_} prefix
4502 @cindex Path stripping, avoiding
4503 @cindex Avoiding path stripping
4504
4505 However, the @samp{nobase_} prefix can be used to circumvent this path
4506 stripping.  In this example, the header file will be installed as
4507 @file{$(includedir)/sys/types.h}:
4508
4509 @example
4510 nobase_include_HEADERS = sys/types.h
4511 @end example
4512
4513 @cindex @code{nobase_} and @code{dist_} or @code{nodist_}
4514 @cindex @code{dist_} and @code{nobase_}
4515 @cindex @code{nodist_} and @code{nobase_}
4516 @vindex dist_
4517 @vindex nodist_
4518
4519 @samp{nobase_} should be specified first when used in conjunction with
4520 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
4521 Control}).  For instance:
4522
4523 @example
4524 nobase_dist_pkgdata_DATA = images/vortex.pgm sounds/whirl.ogg
4525 @end example
4526
4527 Finally, note that a variable using the @samp{nobase_} prefix can
4528 often be replaced by several variables, one for each destination
4529 directory (@pxref{Uniform}).  For instance, the last example could be
4530 rewritten as follows:
4531
4532 @c Keep in sync with primary-prefix-couples-documented-valid.sh
4533 @example
4534 imagesdir = $(pkgdatadir)/images
4535 soundsdir = $(pkgdatadir)/sounds
4536 dist_images_DATA = images/vortex.pgm
4537 dist_sounds_DATA = sounds/whirl.ogg
4538 @end example
4539
4540 @noindent
4541 This latter syntax makes it possible to change one destination
4542 directory without changing the layout of the source tree.
4543
4544 Currently, @samp{nobase_*_LTLIBRARIES} are the only exception to this
4545 rule, in that there is no particular installation order guarantee for
4546 an otherwise equivalent set of variables without @samp{nobase_} prefix.
4547
4548 @node Subpackages
4549 @section Nesting Packages
4550 @cindex Nesting packages
4551 @cindex Subpackages
4552 @acindex AC_CONFIG_SUBDIRS
4553 @acindex AC_CONFIG_AUX_DIR
4554
4555
4556 In the GNU Build System, packages can be nested to arbitrary depth.
4557 This means that a package can embed other packages with their own
4558 @file{configure}, @file{Makefile}s, etc.
4559
4560 These other packages should just appear as subdirectories of their
4561 parent package.  They must be listed in @code{SUBDIRS} like other
4562 ordinary directories.  However the subpackage's @file{Makefile}s
4563 should be output by its own @file{configure} script, not by the
4564 parent's @file{configure}.  This is achieved using the
4565 @code{AC_CONFIG_SUBDIRS} Autoconf macro (@pxref{Subdirectories,
4566 AC_CONFIG_SUBDIRS, Configuring Other Packages in Subdirectories,
4567 autoconf, The Autoconf Manual}).
4568
4569 Here is an example package for an @code{arm} program that links with
4570 a @code{hand} library that is a nested package in subdirectory
4571 @file{hand/}.
4572
4573 @code{arm}'s @file{configure.ac}:
4574
4575 @example
4576 AC_INIT([arm], [1.0])
4577 AC_CONFIG_AUX_DIR([.])
4578 AM_INIT_AUTOMAKE
4579 AC_PROG_CC
4580 AC_CONFIG_FILES([Makefile])
4581 # Call hand's ./configure script recursively.
4582 AC_CONFIG_SUBDIRS([hand])
4583 AC_OUTPUT
4584 @end example
4585
4586 @code{arm}'s @file{Makefile.am}:
4587
4588 @example
4589 # Build the library in the hand subdirectory first.
4590 SUBDIRS = hand
4591
4592 # Include hand's header when compiling this directory.
4593 AM_CPPFLAGS = -I$(srcdir)/hand
4594
4595 bin_PROGRAMS = arm
4596 arm_SOURCES = arm.c
4597 # link with the hand library.
4598 arm_LDADD = hand/libhand.a
4599 @end example
4600
4601 Now here is @code{hand}'s @file{hand/configure.ac}:
4602
4603 @example
4604 AC_INIT([hand], [1.2])
4605 AC_CONFIG_AUX_DIR([.])
4606 AM_INIT_AUTOMAKE
4607 AC_PROG_CC
4608 AM_PROG_AR
4609 AC_PROG_RANLIB
4610 AC_CONFIG_FILES([Makefile])
4611 AC_OUTPUT
4612 @end example
4613
4614 @noindent
4615 and its @file{hand/Makefile.am}:
4616
4617 @example
4618 lib_LIBRARIES = libhand.a
4619 libhand_a_SOURCES = hand.c
4620 @end example
4621
4622 When @samp{make dist} is run from the top-level directory it will
4623 create an archive @file{arm-1.0.tar.gz} that contains the @code{arm}
4624 code as well as the @file{hand} subdirectory.  This package can be
4625 built and installed like any ordinary package, with the usual
4626 @samp{./configure && make && make install} sequence (the @code{hand}
4627 subpackage will be built and installed by the process).
4628
4629 When @samp{make dist} is run from the hand directory, it will create a
4630 self-contained @file{hand-1.2.tar.gz} archive.  So although it appears
4631 to be embedded in another package, it can still be used separately.
4632
4633 The purpose of the @samp{AC_CONFIG_AUX_DIR([.])} instruction is to
4634 force Automake and Autoconf to search for auxiliary scripts in the
4635 current directory.  For instance, this means that there will be two
4636 copies of @file{install-sh}: one in the top-level of the @code{arm}
4637 package, and another one in the @file{hand/} subdirectory for the
4638 @code{hand} package.
4639
4640 The historical default is to search for these auxiliary scripts in
4641 the parent directory and the grandparent directory.  So if the
4642 @samp{AC_CONFIG_AUX_DIR([.])} line was removed from
4643 @file{hand/configure.ac}, that subpackage would share the auxiliary
4644 script of the @code{arm} package.  This may looks like a gain in size
4645 (a few kilobytes), but it is actually a loss of modularity as the
4646 @code{hand} subpackage is no longer self-contained (@samp{make dist}
4647 in the subdirectory will not work anymore).
4648
4649 Packages that do not use Automake need more work to be integrated this
4650 way.  @xref{Third-Party Makefiles}.
4651
4652 @node Programs
4653 @chapter Building Programs and Libraries
4654
4655 A large part of Automake's functionality is dedicated to making it easy
4656 to build programs and libraries.
4657
4658 @menu
4659 * A Program::                   Building a program
4660 * A Library::                   Building a library
4661 * A Shared Library::            Building a Libtool library
4662 * Program and Library Variables::  Variables controlling program and
4663                                 library builds
4664 * Default _SOURCES::            Default source files
4665 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
4666 * Program Variables::           Variables used when building a program
4667 * Yacc and Lex::                Yacc and Lex support
4668 * C++ Support::                 Compiling C++ sources
4669 * Objective C Support::         Compiling Objective C sources
4670 * Objective C++ Support::       Compiling Objective C++ sources
4671 * Unified Parallel C Support::  Compiling Unified Parallel C sources
4672 * Assembly Support::            Compiling assembly sources
4673 * Fortran 77 Support::          Compiling Fortran 77 sources
4674 * Fortran 9x Support::          Compiling Fortran 9x sources
4675 * Java Support with gcj::       Compiling Java sources using gcj
4676 * Vala Support::                Compiling Vala sources
4677 * Support for Other Languages::  Compiling other languages
4678 * Dependencies::                Automatic dependency tracking
4679 * EXEEXT::                      Support for executable extensions
4680 @end menu
4681
4682
4683 @node A Program
4684 @section Building a program
4685
4686 In order to build a program, you need to tell Automake which sources
4687 are part of it, and which libraries it should be linked with.
4688
4689 This section also covers conditional compilation of sources or
4690 programs.  Most of the comments about these also apply to libraries
4691 (@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
4692
4693 @menu
4694 * Program Sources::             Defining program sources
4695 * Linking::                     Linking with libraries or extra objects
4696 * Conditional Sources::         Handling conditional sources
4697 * Conditional Programs::        Building a program conditionally
4698 @end menu
4699
4700 @node Program Sources
4701 @subsection Defining program sources
4702
4703 @cindex @code{PROGRAMS}, @code{bindir}
4704 @vindex _PROGRAMS
4705 @vindex bin_PROGRAMS
4706 @vindex sbin_PROGRAMS
4707 @vindex libexec_PROGRAMS
4708 @vindex pkglibexec_PROGRAMS
4709 @vindex noinst_PROGRAMS
4710 @vindex check_PROGRAMS
4711
4712 In a directory containing source that gets built into a program (as
4713 opposed to a library or a script), the @code{PROGRAMS} primary is used.
4714 Programs can be installed in @code{bindir}, @code{sbindir},
4715 @code{libexecdir}, @code{pkglibexecdir}, or not at all
4716 (@code{noinst_}).  They can also be built only for @samp{make check}, in
4717 which case the prefix is @samp{check_}.
4718
4719 For instance:
4720
4721 @example
4722 bin_PROGRAMS = hello
4723 @end example
4724
4725 In this simple case, the resulting @file{Makefile.in} will contain code
4726 to generate a program named @code{hello}.
4727
4728 Associated with each program are several assisting variables that are
4729 named after the program.  These variables are all optional, and have
4730 reasonable defaults.  Each variable, its use, and default is spelled out
4731 below; we use the ``hello'' example throughout.
4732
4733 The variable @code{hello_SOURCES} is used to specify which source files
4734 get built into an executable:
4735
4736 @example
4737 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
4738 @end example
4739
4740 This causes each mentioned @file{.c} file to be compiled into the
4741 corresponding @file{.o}.  Then all are linked to produce @file{hello}.
4742
4743 @cindex @code{_SOURCES} primary, defined
4744 @cindex @code{SOURCES} primary, defined
4745 @cindex Primary variable, @code{SOURCES}
4746 @vindex _SOURCES
4747
4748 If @code{hello_SOURCES} is not specified, then it defaults to the single
4749 file @file{hello.c} (@pxref{Default _SOURCES}).
4750 @vindex _SOURCES
4751 @vindex SOURCES
4752
4753 Multiple programs can be built in a single directory.  Multiple programs
4754 can share a single source file, which must be listed in each
4755 @code{_SOURCES} definition.
4756
4757 @cindex Header files in @code{_SOURCES}
4758 @cindex @code{_SOURCES} and header files
4759
4760 Header files listed in a @code{_SOURCES} definition will be included in
4761 the distribution but otherwise ignored.  In case it isn't obvious, you
4762 should not include the header file generated by @file{configure} in a
4763 @code{_SOURCES} variable; this file should not be distributed.  Lex
4764 (@file{.l}) and Yacc (@file{.y}) files can also be listed; see @ref{Yacc
4765 and Lex}.
4766
4767
4768 @node Linking
4769 @subsection Linking the program
4770
4771 If you need to link against libraries that are not found by
4772 @command{configure}, you can use @code{LDADD} to do so.  This variable is
4773 used to specify additional objects or libraries to link with; it is
4774 inappropriate for specifying specific linker flags, you should use
4775 @code{AM_LDFLAGS} for this purpose.
4776 @vindex LDADD
4777 @vindex AM_LDFLAGS
4778
4779 @cindex @code{prog_LDADD}, defined
4780
4781 Sometimes, multiple programs are built in one directory but do not share
4782 the same link-time requirements.  In this case, you can use the
4783 @code{@var{prog}_LDADD} variable (where @var{prog} is the name of the
4784 program as it appears in some @code{_PROGRAMS} variable, and usually
4785 written in lowercase) to override @code{LDADD}.  If this variable exists
4786 for a given program, then that program is not linked using @code{LDADD}.
4787 @vindex maude_LDADD
4788
4789 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
4790 linked against the library @file{libcpio.a}.  However, @code{rmt} is
4791 built in the same directory, and has no such link requirement.  Also,
4792 @code{mt} and @code{rmt} are only built on certain architectures.  Here
4793 is what cpio's @file{src/Makefile.am} looks like (abridged):
4794
4795 @example
4796 bin_PROGRAMS = cpio pax $(MT)
4797 libexec_PROGRAMS = $(RMT)
4798 EXTRA_PROGRAMS = mt rmt
4799
4800 LDADD = ../lib/libcpio.a $(INTLLIBS)
4801 rmt_LDADD =
4802
4803 cpio_SOURCES = @dots{}
4804 pax_SOURCES = @dots{}
4805 mt_SOURCES = @dots{}
4806 rmt_SOURCES = @dots{}
4807 @end example
4808
4809 @cindex @code{_LDFLAGS}, defined
4810 @vindex maude_LDFLAGS
4811 @code{@var{prog}_LDADD} is inappropriate for passing program-specific
4812 linker flags (except for @option{-l}, @option{-L}, @option{-dlopen} and
4813 @option{-dlpreopen}).  So, use the @code{@var{prog}_LDFLAGS} variable for
4814 this purpose.
4815
4816 @cindex @code{_DEPENDENCIES}, defined
4817 @vindex maude_DEPENDENCIES
4818 @vindex EXTRA_maude_DEPENDENCIES
4819 It is also occasionally useful to have a program depend on some other
4820 target that is not actually part of that program.  This can be done
4821 using either the @code{@var{prog}_DEPENDENCIES} or the
4822 @code{EXTRA_@var{prog}_DEPENDENCIES} variable.  Each program depends on
4823 the contents both variables, but no further interpretation is done.
4824
4825 Since these dependencies are associated to the link rule used to
4826 create the programs they should normally list files used by the link
4827 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la}
4828 files.  In rare cases you may need to add other kinds of files such as
4829 linker scripts, but @emph{listing a source file in
4830 @code{_DEPENDENCIES} is wrong}.  If some source file needs to be built
4831 before all the components of a program are built, consider using the
4832 @code{BUILT_SOURCES} variable instead (@pxref{Sources}).
4833
4834 If @code{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
4835 Automake.  The automatically-assigned value is the contents of
4836 @code{@var{prog}_LDADD}, with most configure substitutions, @option{-l},
4837 @option{-L}, @option{-dlopen} and @option{-dlpreopen} options removed.  The
4838 configure substitutions that are left in are only @samp{$(LIBOBJS)} and
4839 @samp{$(ALLOCA)}; these are left because it is known that they will not
4840 cause an invalid value for @code{@var{prog}_DEPENDENCIES} to be
4841 generated.
4842
4843 @ref{Conditional Sources} shows a situation where @code{_DEPENDENCIES}
4844 may be used.
4845
4846 The @code{EXTRA_@var{prog}_DEPENDENCIES} may be useful for cases where
4847 you merely want to augment the @command{automake}-generated
4848 @code{@var{prog}_DEPENDENCIES} rather than replacing it.
4849
4850 @cindex @code{LDADD} and @option{-l}
4851 @cindex @option{-l} and @code{LDADD}
4852 We recommend that you avoid using @option{-l} options in @code{LDADD}
4853 or @code{@var{prog}_LDADD} when referring to libraries built by your
4854 package.  Instead, write the file name of the library explicitly as in
4855 the above @code{cpio} example.  Use @option{-l} only to list
4856 third-party libraries.  If you follow this rule, the default value of
4857 @code{@var{prog}_DEPENDENCIES} will list all your local libraries and
4858 omit the other ones.
4859
4860
4861 @node Conditional Sources
4862 @subsection Conditional compilation of sources
4863
4864 You can't put a configure substitution (e.g., @samp{@@FOO@@} or
4865 @samp{$(FOO)} where @code{FOO} is defined via @code{AC_SUBST}) into a
4866 @code{_SOURCES} variable.  The reason for this is a bit hard to
4867 explain, but suffice to say that it simply won't work.  Automake will
4868 give an error if you try to do this.
4869
4870 Fortunately there are two other ways to achieve the same result.  One is
4871 to use configure substitutions in @code{_LDADD} variables, the other is
4872 to use an Automake conditional.
4873
4874 @subsubheading Conditional Compilation using @code{_LDADD} Substitutions
4875
4876 @cindex @code{EXTRA_prog_SOURCES}, defined
4877
4878 Automake must know all the source files that could possibly go into a
4879 program, even if not all the files are built in every circumstance.  Any
4880 files that are only conditionally built should be listed in the
4881 appropriate @code{EXTRA_} variable.  For instance, if
4882 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
4883 in @code{hello}, the @file{Makefile.am} would contain:
4884
4885 @example
4886 bin_PROGRAMS = hello
4887 hello_SOURCES = hello-common.c
4888 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
4889 hello_LDADD = $(HELLO_SYSTEM)
4890 hello_DEPENDENCIES = $(HELLO_SYSTEM)
4891 @end example
4892
4893 @noindent
4894 You can then setup the @samp{$(HELLO_SYSTEM)} substitution from
4895 @file{configure.ac}:
4896
4897 @example
4898 @dots{}
4899 case $host in
4900   *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
4901   *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
4902 esac
4903 AC_SUBST([HELLO_SYSTEM])
4904 @dots{}
4905 @end example
4906
4907 In this case, the variable @code{HELLO_SYSTEM} should be replaced by
4908 either @file{hello-linux.o} or @file{hello-generic.o}, and added to
4909 both @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be
4910 built and linked in.
4911
4912 @subsubheading Conditional Compilation using Automake Conditionals
4913
4914 An often simpler way to compile source files conditionally is to use
4915 Automake conditionals.  For instance, you could use this
4916 @file{Makefile.am} construct to build the same @file{hello} example:
4917
4918 @example
4919 bin_PROGRAMS = hello
4920 if LINUX
4921 hello_SOURCES = hello-linux.c hello-common.c
4922 else
4923 hello_SOURCES = hello-generic.c hello-common.c
4924 endif
4925 @end example
4926
4927 In this case, @file{configure.ac} should setup the @code{LINUX}
4928 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
4929
4930 When using conditionals like this you don't need to use the
4931 @code{EXTRA_} variable, because Automake will examine the contents of
4932 each variable to construct the complete list of source files.
4933
4934 If your program uses a lot of files, you will probably prefer a
4935 conditional @samp{+=}.
4936
4937 @example
4938 bin_PROGRAMS = hello
4939 hello_SOURCES = hello-common.c
4940 if LINUX
4941 hello_SOURCES += hello-linux.c
4942 else
4943 hello_SOURCES += hello-generic.c
4944 endif
4945 @end example
4946
4947 @node Conditional Programs
4948 @subsection Conditional compilation of programs
4949 @cindex Conditional programs
4950 @cindex Programs, conditional
4951
4952 Sometimes it is useful to determine the programs that are to be built
4953 at configure time.  For instance, GNU @code{cpio} only builds
4954 @code{mt} and @code{rmt} under special circumstances.  The means to
4955 achieve conditional compilation of programs are the same you can use
4956 to compile source files conditionally: substitutions or conditionals.
4957
4958 @subsubheading Conditional Programs using @command{configure} Substitutions
4959
4960 @vindex EXTRA_PROGRAMS
4961 @cindex @code{EXTRA_PROGRAMS}, defined
4962 In this case, you must notify Automake of all the programs that can
4963 possibly be built, but at the same time cause the generated
4964 @file{Makefile.in} to use the programs specified by @command{configure}.
4965 This is done by having @command{configure} substitute values into each
4966 @code{_PROGRAMS} definition, while listing all optionally built programs
4967 in @code{EXTRA_PROGRAMS}.
4968
4969 @example
4970 bin_PROGRAMS = cpio pax $(MT)
4971 libexec_PROGRAMS = $(RMT)
4972 EXTRA_PROGRAMS = mt rmt
4973 @end example
4974
4975 As explained in @ref{EXEEXT}, Automake will rewrite
4976 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
4977 @code{EXTRA_PROGRAMS}, appending @samp{$(EXEEXT)} to each binary.
4978 Obviously it cannot rewrite values obtained at run-time through
4979 @command{configure} substitutions, therefore you should take care of
4980 appending @samp{$(EXEEXT)} yourself, as in @samp{AC_SUBST([MT],
4981 ['mt$@{EXEEXT@}'])}.
4982
4983 @subsubheading Conditional Programs using Automake Conditionals
4984
4985 You can also use Automake conditionals (@pxref{Conditionals}) to
4986 select programs to be built.  In this case you don't have to worry
4987 about @samp{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
4988
4989 @c Keep in sync with exeext.sh
4990 @example
4991 bin_PROGRAMS = cpio pax
4992 if WANT_MT
4993   bin_PROGRAMS += mt
4994 endif
4995 if WANT_RMT
4996   libexec_PROGRAMS = rmt
4997 endif
4998 @end example
4999
5000
5001 @node A Library
5002 @section Building a library
5003
5004 @cindex @code{_LIBRARIES} primary, defined
5005 @cindex @code{LIBRARIES} primary, defined
5006 @cindex Primary variable, @code{LIBRARIES}
5007 @vindex _LIBRARIES
5008
5009 @vindex lib_LIBRARIES
5010 @vindex pkglib_LIBRARIES
5011 @vindex noinst_LIBRARIES
5012
5013 Building a library is much like building a program.  In this case, the
5014 name of the primary is @code{LIBRARIES}.  Libraries can be installed in
5015 @code{libdir} or @code{pkglibdir}.
5016
5017 @xref{A Shared Library}, for information on how to build shared
5018 libraries using libtool and the @code{LTLIBRARIES} primary.
5019
5020 Each @code{_LIBRARIES} variable is a list of the libraries to be built.
5021 For instance, to create a library named @file{libcpio.a}, but not install
5022 it, you would write:
5023
5024 @example
5025 noinst_LIBRARIES = libcpio.a
5026 libcpio_a_SOURCES = @dots{}
5027 @end example
5028
5029 The sources that go into a library are determined exactly as they are
5030 for programs, via the @code{_SOURCES} variables.  Note that the library
5031 name is canonicalized (@pxref{Canonicalization}), so the @code{_SOURCES}
5032 variable corresponding to @file{libcpio.a} is @samp{libcpio_a_SOURCES},
5033 not @samp{libcpio.a_SOURCES}.
5034
5035 @vindex maude_LIBADD
5036 Extra objects can be added to a library using the
5037 @code{@var{library}_LIBADD} variable.  This should be used for objects
5038 determined by @command{configure}.  Again from @code{cpio}:
5039
5040 @c Keep in sync with pr401c.sh
5041 @example
5042 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
5043 @end example
5044
5045 In addition, sources for extra objects that will not exist until
5046 configure-time must be added to the @code{BUILT_SOURCES} variable
5047 (@pxref{Sources}).
5048
5049 Building a static library is done by compiling all object files, then
5050 by invoking @samp{$(AR) $(ARFLAGS)} followed by the name of the
5051 library and the list of objects, and finally by calling
5052 @samp{$(RANLIB)} on that library.  You should call
5053 @code{AC_PROG_RANLIB} from your @file{configure.ac} to define
5054 @code{RANLIB} (Automake will complain otherwise).  You should also
5055 call @code{AM_PROG_AR} to define @code{AR}, in order to support unusual
5056 archivers such as Microsoft lib.  @code{ARFLAGS} will default to
5057 @code{cru}; you can override this variable by setting it in your
5058 @file{Makefile.am} or by @code{AC_SUBST}ing it from your
5059 @file{configure.ac}.  You can override the @code{AR} variable by
5060 defining a per-library @code{maude_AR} variable (@pxref{Program and
5061 Library Variables}).
5062
5063 @cindex Empty libraries
5064 Be careful when selecting library components conditionally.  Because
5065 building an empty library is not portable, you should ensure that any
5066 library always contains at least one object.
5067
5068 To use a static library when building a program, add it to
5069 @code{LDADD} for this program.  In the following example, the program
5070 @file{cpio} is statically linked with the library @file{libcpio.a}.
5071
5072 @example
5073 noinst_LIBRARIES = libcpio.a
5074 libcpio_a_SOURCES = @dots{}
5075
5076 bin_PROGRAMS = cpio
5077 cpio_SOURCES = cpio.c @dots{}
5078 cpio_LDADD = libcpio.a
5079 @end example
5080
5081
5082 @node A Shared Library
5083 @section Building a Shared Library
5084
5085 @cindex Shared libraries, support for
5086
5087 Building shared libraries portably is a relatively complex matter.
5088 For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
5089 Libtool Manual}) was created to help build shared libraries in a
5090 platform-independent way.
5091
5092 @menu
5093 * Libtool Concept::             Introducing Libtool
5094 * Libtool Libraries::           Declaring Libtool Libraries
5095 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
5096 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
5097 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
5098 * Libtool Modules::             Building Libtool Modules
5099 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
5100 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
5101 * Libtool Issues::              Common Issues Related to Libtool's Use
5102 @end menu
5103
5104 @node Libtool Concept
5105 @subsection The Libtool Concept
5106
5107 @cindex @command{libtool}, introduction
5108 @cindex libtool library, definition
5109 @cindex suffix @file{.la}, defined
5110 @cindex @file{.la} suffix, defined
5111
5112 Libtool abstracts shared and static libraries into a unified concept
5113 henceforth called @dfn{libtool libraries}.  Libtool libraries are
5114 files using the @file{.la} suffix, and can designate a static library,
5115 a shared library, or maybe both.  Their exact nature cannot be
5116 determined until @file{./configure} is run: not all platforms support
5117 all kinds of libraries, and users can explicitly select which
5118 libraries should be built.  (However the package's maintainers can
5119 tune the default, @pxref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
5120 macro, libtool, The Libtool Manual}.)
5121
5122 @cindex suffix @file{.lo}, defined
5123 Because object files for shared and static libraries must be compiled
5124 differently, libtool is also used during compilation.  Object files
5125 built by libtool are called @dfn{libtool objects}: these are files
5126 using the @file{.lo} suffix.  Libtool libraries are built from these
5127 libtool objects.
5128
5129 You should not assume anything about the structure of @file{.la} or
5130 @file{.lo} files and how libtool constructs them: this is libtool's
5131 concern, and the last thing one wants is to learn about libtool's
5132 guts.  However the existence of these files matters, because they are
5133 used as targets and dependencies in @file{Makefile}s rules when
5134 building libtool libraries.  There are situations where you may have
5135 to refer to these, for instance when expressing dependencies for
5136 building source files conditionally (@pxref{Conditional Libtool
5137 Sources}).
5138
5139 @cindex @file{libltdl}, introduction
5140
5141 People considering writing a plug-in system, with dynamically loaded
5142 modules, should look into @file{libltdl}: libtool's dlopening library
5143 (@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
5144 This offers a portable dlopening facility to load libtool libraries
5145 dynamically, and can also achieve static linking where unavoidable.
5146
5147 Before we discuss how to use libtool with Automake in details, it
5148 should be noted that the libtool manual also has a section about how
5149 to use Automake with libtool (@pxref{Using Automake, , Using Automake
5150 with Libtool, libtool, The Libtool Manual}).
5151
5152 @node Libtool Libraries
5153 @subsection Building Libtool Libraries
5154
5155 @cindex @code{_LTLIBRARIES} primary, defined
5156 @cindex @code{LTLIBRARIES} primary, defined
5157 @cindex Primary variable, @code{LTLIBRARIES}
5158 @cindex Example of shared libraries
5159 @vindex lib_LTLIBRARIES
5160 @vindex pkglib_LTLIBRARIES
5161 @vindex _LTLIBRARIES
5162
5163 Automake uses libtool to build libraries declared with the
5164 @code{LTLIBRARIES} primary.  Each @code{_LTLIBRARIES} variable is a
5165 list of libtool libraries to build.  For instance, to create a libtool
5166 library named @file{libgettext.la}, and install it in @code{libdir},
5167 write:
5168
5169 @example
5170 lib_LTLIBRARIES = libgettext.la
5171 libgettext_la_SOURCES = gettext.c gettext.h @dots{}
5172 @end example
5173
5174 Automake predefines the variable @code{pkglibdir}, so you can use
5175 @code{pkglib_LTLIBRARIES} to install libraries in
5176 @samp{$(libdir)/@@PACKAGE@@/}.
5177
5178 If @file{gettext.h} is a public header file that needs to be installed
5179 in order for people to use the library, it should be declared using a
5180 @code{_HEADERS} variable, not in @code{libgettext_la_SOURCES}.
5181 Headers listed in the latter should be internal headers that are not
5182 part of the public interface.
5183
5184 @example
5185 lib_LTLIBRARIES = libgettext.la
5186 libgettext_la_SOURCES = gettext.c @dots{}
5187 include_HEADERS = gettext.h @dots{}
5188 @end example
5189
5190 A package can build and install such a library along with other
5191 programs that use it.  This dependency should be specified using
5192 @code{LDADD}.  The following example builds a program named
5193 @file{hello} that is linked with @file{libgettext.la}.
5194
5195 @example
5196 lib_LTLIBRARIES = libgettext.la
5197 libgettext_la_SOURCES = gettext.c @dots{}
5198
5199 bin_PROGRAMS = hello
5200 hello_SOURCES = hello.c @dots{}
5201 hello_LDADD = libgettext.la
5202 @end example
5203
5204 @noindent
5205 Whether @file{hello} is statically or dynamically linked with
5206 @file{libgettext.la} is not yet known: this will depend on the
5207 configuration of libtool and the capabilities of the host.
5208
5209
5210 @node Conditional Libtool Libraries
5211 @subsection Building Libtool Libraries Conditionally
5212 @cindex libtool libraries, conditional
5213 @cindex conditional libtool libraries
5214
5215 Like conditional programs (@pxref{Conditional Programs}), there are
5216 two main ways to build conditional libraries: using Automake
5217 conditionals or using Autoconf @code{AC_SUBST}itutions.
5218
5219 The important implementation detail you have to be aware of is that
5220 the place where a library will be installed matters to libtool: it
5221 needs to be indicated @emph{at link-time} using the @option{-rpath}
5222 option.
5223
5224 For libraries whose destination directory is known when Automake runs,
5225 Automake will automatically supply the appropriate @option{-rpath}
5226 option to libtool.  This is the case for libraries listed explicitly in
5227 some installable @code{_LTLIBRARIES} variables such as
5228 @code{lib_LTLIBRARIES}.
5229
5230 However, for libraries determined at configure time (and thus
5231 mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
5232 final installation directory.  For such libraries you must add the
5233 @option{-rpath} option to the appropriate @code{_LDFLAGS} variable by
5234 hand.
5235
5236 The examples below illustrate the differences between these two methods.
5237
5238 Here is an example where @code{WANTEDLIBS} is an @code{AC_SUBST}ed
5239 variable set at @file{./configure}-time to either @file{libfoo.la},
5240 @file{libbar.la}, both, or none.  Although @samp{$(WANTEDLIBS)}
5241 appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
5242 relates to @file{libfoo.la} or @file{libbar.la} at the time it creates
5243 the link rule for these two libraries.  Therefore the @option{-rpath}
5244 argument must be explicitly supplied.
5245
5246 @c Keep in sync with ltcond.sh
5247 @example
5248 EXTRA_LTLIBRARIES = libfoo.la libbar.la
5249 lib_LTLIBRARIES = $(WANTEDLIBS)
5250 libfoo_la_SOURCES = foo.c @dots{}
5251 libfoo_la_LDFLAGS = -rpath '$(libdir)'
5252 libbar_la_SOURCES = bar.c @dots{}
5253 libbar_la_LDFLAGS = -rpath '$(libdir)'
5254 @end example
5255
5256 Here is how the same @file{Makefile.am} would look using Automake
5257 conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}.  Now
5258 Automake is able to compute the @option{-rpath} setting itself, because
5259 it's clear that both libraries will end up in @samp{$(libdir)} if they
5260 are installed.
5261
5262 @c Keep in sync with ltcond.sh
5263 @example
5264 lib_LTLIBRARIES =
5265 if WANT_LIBFOO
5266 lib_LTLIBRARIES += libfoo.la
5267 endif
5268 if WANT_LIBBAR
5269 lib_LTLIBRARIES += libbar.la
5270 endif
5271 libfoo_la_SOURCES = foo.c @dots{}
5272 libbar_la_SOURCES = bar.c @dots{}
5273 @end example
5274
5275 @node Conditional Libtool Sources
5276 @subsection Libtool Libraries with Conditional Sources
5277
5278 Conditional compilation of sources in a library can be achieved in the
5279 same way as conditional compilation of sources in a program
5280 (@pxref{Conditional Sources}).  The only difference is that
5281 @code{_LIBADD} should be used instead of @code{_LDADD} and that it
5282 should mention libtool objects (@file{.lo} files).
5283
5284 So, to mimic the @file{hello} example from @ref{Conditional Sources},
5285 we could build a @file{libhello.la} library using either
5286 @file{hello-linux.c} or @file{hello-generic.c} with the following
5287 @file{Makefile.am}.
5288
5289 @c Keep in sync with ltcond2.sh
5290 @example
5291 lib_LTLIBRARIES = libhello.la
5292 libhello_la_SOURCES = hello-common.c
5293 EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
5294 libhello_la_LIBADD = $(HELLO_SYSTEM)
5295 libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
5296 @end example
5297
5298 @noindent
5299 And make sure @command{configure} defines @code{HELLO_SYSTEM} as
5300 either @file{hello-linux.lo} or @file{hello-@-generic.lo}.
5301
5302 Or we could simply use an Automake conditional as follows.
5303
5304 @c Keep in sync with ltcond2.sh
5305 @example
5306 lib_LTLIBRARIES = libhello.la
5307 libhello_la_SOURCES = hello-common.c
5308 if LINUX
5309 libhello_la_SOURCES += hello-linux.c
5310 else
5311 libhello_la_SOURCES += hello-generic.c
5312 endif
5313 @end example
5314
5315 @node Libtool Convenience Libraries
5316 @subsection Libtool Convenience Libraries
5317 @cindex convenience libraries, libtool
5318 @cindex libtool convenience libraries
5319 @vindex noinst_LTLIBRARIES
5320 @vindex check_LTLIBRARIES
5321
5322 Sometimes you want to build libtool libraries that should not be
5323 installed.  These are called @dfn{libtool convenience libraries} and
5324 are typically used to encapsulate many sublibraries, later gathered
5325 into one big installed library.
5326
5327 Libtool convenience libraries are declared by directory-less variables
5328 such as @code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
5329 @code{EXTRA_LTLIBRARIES}.  Unlike installed libtool libraries they do
5330 not need an @option{-rpath} flag at link time (actually this is the only
5331 difference).
5332
5333 Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
5334 built.  Those listed in @code{check_LTLIBRARIES} are built only upon
5335 @samp{make check}.  Finally, libraries listed in
5336 @code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
5337 rules to build them, but if the library does not appear as a Makefile
5338 dependency anywhere it won't be built (this is why
5339 @code{EXTRA_LTLIBRARIES} is used for conditional compilation).
5340
5341 Here is a sample setup merging libtool convenience libraries from
5342 subdirectories into one main @file{libtop.la} library.
5343
5344 @c Keep in sync with ltconv.sh
5345 @example
5346 # -- Top-level Makefile.am --
5347 SUBDIRS = sub1 sub2 @dots{}
5348 lib_LTLIBRARIES = libtop.la
5349 libtop_la_SOURCES =
5350 libtop_la_LIBADD = \
5351   sub1/libsub1.la \
5352   sub2/libsub2.la \
5353   @dots{}
5354
5355 # -- sub1/Makefile.am --
5356 noinst_LTLIBRARIES = libsub1.la
5357 libsub1_la_SOURCES = @dots{}
5358
5359 # -- sub2/Makefile.am --
5360 # showing nested convenience libraries
5361 SUBDIRS = sub2.1 sub2.2 @dots{}
5362 noinst_LTLIBRARIES = libsub2.la
5363 libsub2_la_SOURCES =
5364 libsub2_la_LIBADD = \
5365   sub21/libsub21.la \
5366   sub22/libsub22.la \
5367   @dots{}
5368 @end example
5369
5370 When using such setup, beware that @command{automake} will assume
5371 @file{libtop.la} is to be linked with the C linker.  This is because
5372 @code{libtop_la_SOURCES} is empty, so @command{automake} picks C as
5373 default language.  If @code{libtop_la_SOURCES} was not empty,
5374 @command{automake} would select the linker as explained in @ref{How
5375 the Linker is Chosen}.
5376
5377 If one of the sublibraries contains non-C source, it is important that
5378 the appropriate linker be chosen.  One way to achieve this is to
5379 pretend that there is such a non-C file among the sources of the
5380 library, thus forcing @command{automake} to select the appropriate
5381 linker.  Here is the top-level @file{Makefile} of our example updated
5382 to force C++ linking.
5383
5384 @example
5385 SUBDIRS = sub1 sub2 @dots{}
5386 lib_LTLIBRARIES = libtop.la
5387 libtop_la_SOURCES =
5388 # Dummy C++ source to cause C++ linking.
5389 nodist_EXTRA_libtop_la_SOURCES = dummy.cxx
5390 libtop_la_LIBADD = \
5391   sub1/libsub1.la \
5392   sub2/libsub2.la \
5393   @dots{}
5394 @end example
5395
5396 @samp{EXTRA_*_SOURCES} variables are used to keep track of source
5397 files that might be compiled (this is mostly useful when doing
5398 conditional compilation using @code{AC_SUBST}, @pxref{Conditional
5399 Libtool Sources}), and the @code{nodist_} prefix means the listed
5400 sources are not to be distributed (@pxref{Program and Library
5401 Variables}).  In effect the file @file{dummy.cxx} does not need to
5402 exist in the source tree.  Of course if you have some real source file
5403 to list in @code{libtop_la_SOURCES} there is no point in cheating with
5404 @code{nodist_EXTRA_libtop_la_SOURCES}.
5405
5406
5407 @node Libtool Modules
5408 @subsection Libtool Modules
5409 @cindex modules, libtool
5410 @cindex libtool modules
5411 @cindex @option{-module}, libtool
5412
5413 These are libtool libraries meant to be dlopened.  They are
5414 indicated to libtool by passing @option{-module} at link-time.
5415
5416 @example
5417 pkglib_LTLIBRARIES = mymodule.la
5418 mymodule_la_SOURCES = doit.c
5419 mymodule_la_LDFLAGS = -module
5420 @end example
5421
5422 Ordinarily, Automake requires that a library's name start with
5423 @code{lib}.  However, when building a dynamically loadable module you
5424 might wish to use a "nonstandard" name.  Automake will not complain
5425 about such nonstandard names if it knows the library being built is a
5426 libtool module, i.e., if @option{-module} explicitly appears in the
5427 library's @code{_LDFLAGS} variable (or in the common @code{AM_LDFLAGS}
5428 variable when no per-library @code{_LDFLAGS} variable is defined).
5429
5430 As always, @code{AC_SUBST} variables are black boxes to Automake since
5431 their values are not yet known when @command{automake} is run.
5432 Therefore if @option{-module} is set via such a variable, Automake
5433 cannot notice it and will proceed as if the library was an ordinary
5434 libtool library, with strict naming.
5435
5436 If @code{mymodule_la_SOURCES} is not specified, then it defaults to
5437 the single file @file{mymodule.c} (@pxref{Default _SOURCES}).
5438
5439 @node Libtool Flags
5440 @subsection @code{_LIBADD}, @code{_LDFLAGS}, and @code{_LIBTOOLFLAGS}
5441 @cindex @code{_LIBADD}, libtool
5442 @cindex @code{_LDFLAGS}, libtool
5443 @cindex @code{_LIBTOOLFLAGS}, libtool
5444 @vindex AM_LIBTOOLFLAGS
5445 @vindex LIBTOOLFLAGS
5446 @vindex maude_LIBTOOLFLAGS
5447
5448 As shown in previous sections, the @samp{@var{library}_LIBADD}
5449 variable should be used to list extra libtool objects (@file{.lo}
5450 files) or libtool libraries (@file{.la}) to add to @var{library}.
5451
5452 The @samp{@var{library}_LDFLAGS} variable is the place to list
5453 additional libtool linking flags, such as @option{-version-info},
5454 @option{-static}, and a lot more.  @xref{Link mode, , Link mode,
5455 libtool, The Libtool Manual}.
5456
5457 The @command{libtool} command has two kinds of options: mode-specific
5458 options and generic options.  Mode-specific options such as the
5459 aforementioned linking flags should be lumped with the other flags
5460 passed to the tool invoked by @command{libtool} (hence the use of
5461 @samp{@var{library}_LDFLAGS} for libtool linking flags).  Generic
5462 options include @option{--tag=@var{tag}} and @option{--silent}
5463 (@pxref{Invoking libtool, , Invoking @command{libtool}, libtool, The
5464 Libtool Manual} for more options) should appear before the mode
5465 selection on the command line; in @file{Makefile.am}s they should
5466 be listed in the @samp{@var{library}_LIBTOOLFLAGS} variable.
5467
5468 If @samp{@var{library}_LIBTOOLFLAGS} is not defined, then the variable
5469 @code{AM_LIBTOOLFLAGS} is used instead.
5470
5471 These flags are passed to libtool after the @option{--tag=@var{tag}}
5472 option computed by Automake (if any), so
5473 @samp{@var{library}_LIBTOOLFLAGS} (or @code{AM_LIBTOOLFLAGS}) is a
5474 good place to override or supplement the @option{--tag=@var{tag}}
5475 setting.
5476
5477 The libtool rules also use a @code{LIBTOOLFLAGS} variable that should
5478 not be set in @file{Makefile.am}: this is a user variable (@pxref{Flag
5479 Variables Ordering}.  It allows users to run @samp{make
5480 LIBTOOLFLAGS=--silent}, for instance.  Note that the verbosity of
5481 @command{libtool} can also be influenced by the Automake support
5482 for silent rules (@pxref{Automake Silent Rules}).
5483
5484 @node LTLIBOBJS, Libtool Issues, Libtool Flags, A Shared Library
5485 @subsection @code{LTLIBOBJS} and @code{LTALLOCA}
5486 @cindex @code{LTLIBOBJS}, special handling
5487 @cindex @code{LIBOBJS}, and Libtool
5488 @cindex @code{LTALLOCA}, special handling
5489 @cindex @code{ALLOCA}, and Libtool
5490 @vindex LTLIBOBJS
5491 @vindex LIBOBJS
5492 @vindex LTALLOCA
5493 @vindex ALLOCA
5494 @acindex AC_LIBOBJ
5495
5496 Where an ordinary library might include @samp{$(LIBOBJS)} or
5497 @samp{$(ALLOCA)} (@pxref{LIBOBJS}), a libtool library must use
5498 @samp{$(LTLIBOBJS)} or @samp{$(LTALLOCA)}.  This is required because
5499 the object files that libtool operates on do not necessarily end in
5500 @file{.o}.
5501
5502 Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
5503 performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
5504 @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual}).
5505
5506 @node Libtool Issues
5507 @subsection Common Issues Related to Libtool's Use
5508
5509 @menu
5510 * Error required file ltmain.sh not found::  The need to run libtoolize
5511 * Objects created both with libtool and without::  Avoid a specific build race
5512 @end menu
5513
5514 @node Error required file ltmain.sh not found
5515 @subsubsection Error: @samp{required file `./ltmain.sh' not found}
5516 @cindex @file{ltmain.sh} not found
5517 @cindex @command{libtoolize}, no longer run by @command{automake}
5518 @cindex @command{libtoolize} and @command{autoreconf}
5519 @cindex @command{autoreconf} and @command{libtoolize}
5520 @cindex @file{bootstrap.sh} and @command{autoreconf}
5521 @cindex @file{autogen.sh} and @command{autoreconf}
5522
5523 Libtool comes with a tool called @command{libtoolize} that will
5524 install libtool's supporting files into a package.  Running this
5525 command will install @file{ltmain.sh}.  You should execute it before
5526 @command{aclocal} and @command{automake}.
5527
5528 People upgrading old packages to newer autotools are likely to face
5529 this issue because older Automake versions used to call
5530 @command{libtoolize}.  Therefore old build scripts do not call
5531 @command{libtoolize}.
5532
5533 Since Automake 1.6, it has been decided that running
5534 @command{libtoolize} was none of Automake's business.  Instead, that
5535 functionality has been moved into the @command{autoreconf} command
5536 (@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
5537 The Autoconf Manual}).  If you do not want to remember what to run and
5538 when, just learn the @command{autoreconf} command.  Hopefully,
5539 replacing existing @file{bootstrap.sh} or @file{autogen.sh} scripts by
5540 a call to @command{autoreconf} should also free you from any similar
5541 incompatible change in the future.
5542
5543 @node Objects created both with libtool and without
5544 @subsubsection Objects @samp{created with both libtool and without}
5545
5546 Sometimes, the same source file is used both to build a libtool
5547 library and to build another non-libtool target (be it a program or
5548 another library).
5549
5550 Let's consider the following @file{Makefile.am}.
5551
5552 @example
5553 bin_PROGRAMS = prog
5554 prog_SOURCES = prog.c foo.c @dots{}
5555
5556 lib_LTLIBRARIES = libfoo.la
5557 libfoo_la_SOURCES = foo.c @dots{}
5558 @end example
5559
5560 @noindent
5561 (In this trivial case the issue could be avoided by linking
5562 @file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
5563 @code{prog_SOURCES}.  But let's assume we really want to keep
5564 @file{prog} and @file{libfoo.la} separate.)
5565
5566 Technically, it means that we should build @file{foo.$(OBJEXT)} for
5567 @file{prog}, and @file{foo.lo} for @file{libfoo.la}.  The problem is
5568 that in the course of creating @file{foo.lo}, libtool may erase (or
5569 replace) @file{foo.$(OBJEXT)}, and this cannot be avoided.
5570
5571 Therefore, when Automake detects this situation it will complain
5572 with a message such as
5573 @example
5574 object 'foo.$(OBJEXT)' created both with libtool and without
5575 @end example
5576
5577 A workaround for this issue is to ensure that these two objects get
5578 different basenames.  As explained in @ref{Renamed Objects}, this
5579 happens automatically when per-targets flags are used.
5580
5581 @example
5582 bin_PROGRAMS = prog
5583 prog_SOURCES = prog.c foo.c @dots{}
5584 prog_CFLAGS = $(AM_CFLAGS)
5585
5586 lib_LTLIBRARIES = libfoo.la
5587 libfoo_la_SOURCES = foo.c @dots{}
5588 @end example
5589
5590 @noindent
5591 Adding @samp{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
5592 when the @code{prog_CFLAGS} is defined, it is used instead of
5593 @code{AM_CFLAGS}.  However as a side effect it will cause
5594 @file{prog.c} and @file{foo.c} to be compiled as
5595 @file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)}, which solves
5596 the issue.
5597
5598 @node Program and Library Variables
5599 @section Program and Library Variables
5600
5601 Associated with each program is a collection of variables that can be
5602 used to modify how that program is built.  There is a similar list of
5603 such variables for each library.  The canonical name of the program (or
5604 library) is used as a base for naming these variables.
5605
5606 In the list below, we use the name ``maude'' to refer to the program or
5607 library.  In your @file{Makefile.am} you would replace this with the
5608 canonical name of your program.  This list also refers to ``maude'' as a
5609 program, but in general the same rules apply for both static and dynamic
5610 libraries; the documentation below notes situations where programs and
5611 libraries differ.
5612
5613 @vtable @code
5614 @item maude_SOURCES
5615 This variable, if it exists, lists all the source files that are
5616 compiled to build the program.  These files are added to the
5617 distribution by default.  When building the program, Automake will cause
5618 each source file to be compiled to a single @file{.o} file (or
5619 @file{.lo} when using libtool).  Normally these object files are named
5620 after the source file, but other factors can change this.  If a file in
5621 the @code{_SOURCES} variable has an unrecognized extension, Automake
5622 will do one of two things with it.  If a suffix rule exists for turning
5623 files with the unrecognized extension into @file{.o} files, then
5624 @command{automake} will treat this file as it will any other source file
5625 (@pxref{Support for Other Languages}).  Otherwise, the file will be
5626 ignored as though it were a header file.
5627
5628 The prefixes @code{dist_} and @code{nodist_} can be used to control
5629 whether files listed in a @code{_SOURCES} variable are distributed.
5630 @code{dist_} is redundant, as sources are distributed by default, but it
5631 can be specified for clarity if desired.
5632
5633 It is possible to have both @code{dist_} and @code{nodist_} variants of
5634 a given @code{_SOURCES} variable at once; this lets you easily
5635 distribute some files and not others, for instance:
5636
5637 @example
5638 nodist_maude_SOURCES = nodist.c
5639 dist_maude_SOURCES = dist-me.c
5640 @end example
5641
5642 By default the output file (on Unix systems, the @file{.o} file) will
5643 be put into the current build directory.  However, if the option
5644 @option{subdir-objects} is in effect in the current directory then the
5645 @file{.o} file will be put into the subdirectory named after the
5646 source file.  For instance, with @option{subdir-objects} enabled,
5647 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
5648 people prefer this mode of operation.  You can specify
5649 @option{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
5650 @cindex Subdirectory, objects in
5651 @cindex Objects in subdirectory
5652
5653
5654 @item EXTRA_maude_SOURCES
5655 Automake needs to know the list of files you intend to compile
5656 @emph{statically}.  For one thing, this is the only way Automake has of
5657 knowing what sort of language support a given @file{Makefile.in}
5658 requires.  @footnote{There are other, more obscure reasons for
5659 this limitation as well.}  This means that, for example, you can't put a
5660 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
5661 variable.  If you intend to conditionally compile source files and use
5662 @file{configure} to substitute the appropriate object names into, e.g.,
5663 @code{_LDADD} (see below), then you should list the corresponding source
5664 files in the @code{EXTRA_} variable.
5665
5666 This variable also supports @code{dist_} and @code{nodist_} prefixes.
5667 For instance, @code{nodist_EXTRA_maude_SOURCES} would list extra
5668 sources that may need to be built, but should not be distributed.
5669
5670 @item maude_AR
5671 A static library is created by default by invoking @samp{$(AR)
5672 $(ARFLAGS)} followed by the name of the library and then the objects
5673 being put into the library.  You can override this by setting the
5674 @code{_AR} variable.  This is usually used with C++; some C++
5675 compilers require a special invocation in order to instantiate all the
5676 templates that should go into a library.  For instance, the SGI C++
5677 compiler likes this variable set like so:
5678 @example
5679 libmaude_a_AR = $(CXX) -ar -o
5680 @end example
5681
5682 @item maude_LIBADD
5683 Extra objects can be added to a @emph{library} using the @code{_LIBADD}
5684 variable.  For instance, this should be used for objects determined by
5685 @command{configure} (@pxref{A Library}).
5686
5687 In the case of libtool libraries, @code{maude_LIBADD} can also refer
5688 to other libtool libraries.
5689
5690 @item maude_LDADD
5691 Extra objects (@file{*.$(OBJEXT)}) and libraries (@file{*.a},
5692 @file{*.la}) can be added to a @emph{program} by listing them in the
5693 @code{_LDADD} variable.  For instance, this should be used for objects
5694 determined by @command{configure} (@pxref{Linking}).
5695
5696 @code{_LDADD} and @code{_LIBADD} are inappropriate for passing
5697 program-specific linker flags (except for @option{-l}, @option{-L},
5698 @option{-dlopen} and @option{-dlpreopen}).  Use the @code{_LDFLAGS} variable
5699 for this purpose.
5700
5701 For instance, if your @file{configure.ac} uses @code{AC_PATH_XTRA}, you
5702 could link your program against the X libraries like so:
5703
5704 @example
5705 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
5706 @end example
5707
5708 We recommend that you use @option{-l} and @option{-L} only when
5709 referring to third-party libraries, and give the explicit file names
5710 of any library built by your package.  Doing so will ensure that
5711 @code{maude_DEPENDENCIES} (see below) is correctly defined by default.
5712
5713 @item maude_LDFLAGS
5714 This variable is used to pass extra flags to the link step of a program
5715 or a shared library.  It overrides the @code{AM_LDFLAGS} variable.
5716
5717 @item maude_LIBTOOLFLAGS
5718 This variable is used to pass extra options to @command{libtool}.
5719 It overrides the @code{AM_LIBTOOLFLAGS} variable.
5720 These options are output before @command{libtool}'s @option{--mode=@var{mode}}
5721 option, so they should not be mode-specific options (those belong to
5722 the compiler or linker flags).  @xref{Libtool Flags}.
5723
5724 @item maude_DEPENDENCIES
5725 @itemx EXTRA_maude_DEPENDENCIES
5726 It is also occasionally useful to have a target (program or library)
5727 depend on some other file that is not actually part of that target.
5728 This can be done using the @code{_DEPENDENCIES} variable.  Each
5729 target depends on the contents of such a variable, but no further
5730 interpretation is done.
5731
5732 Since these dependencies are associated to the link rule used to
5733 create the programs they should normally list files used by the link
5734 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la} files
5735 for programs; @file{*.lo} and @file{*.la} files for Libtool libraries;
5736 and @file{*.$(OBJEXT)} files for static libraries.  In rare cases you
5737 may need to add other kinds of files such as linker scripts, but
5738 @emph{listing a source file in @code{_DEPENDENCIES} is wrong}.  If
5739 some source file needs to be built before all the components of a
5740 program are built, consider using the @code{BUILT_SOURCES} variable
5741 (@pxref{Sources}).
5742
5743 If @code{_DEPENDENCIES} is not supplied, it is computed by Automake.
5744 The automatically-assigned value is the contents of @code{_LDADD} or
5745 @code{_LIBADD}, with most configure substitutions, @option{-l}, @option{-L},
5746 @option{-dlopen} and @option{-dlpreopen} options removed.  The configure
5747 substitutions that are left in are only @samp{$(LIBOBJS)} and
5748 @samp{$(ALLOCA)}; these are left because it is known that they will not
5749 cause an invalid value for @code{_DEPENDENCIES} to be generated.
5750
5751 @code{_DEPENDENCIES} is more likely used to perform conditional
5752 compilation using an @code{AC_SUBST} variable that contains a list of
5753 objects.  @xref{Conditional Sources}, and @ref{Conditional Libtool
5754 Sources}.
5755
5756 The @code{EXTRA_*_DEPENDENCIES} variable may be useful for cases where
5757 you merely want to augment the @command{automake}-generated
5758 @code{_DEPENDENCIES} variable rather than replacing it.
5759
5760 @item maude_LINK
5761 You can override the linker on a per-program basis.  By default the
5762 linker is chosen according to the languages used by the program.  For
5763 instance, a program that includes C++ source code would use the C++
5764 compiler to link.  The @code{_LINK} variable must hold the name of a
5765 command that can be passed all the @file{.o} file names and libraries
5766 to link against as arguments.  Note that the name of the underlying
5767 program is @emph{not} passed to @code{_LINK}; typically one uses
5768 @samp{$@@}:
5769
5770 @example
5771 maude_LINK = $(CCLD) -magic -o $@@
5772 @end example
5773
5774 If a @code{_LINK} variable is not supplied, it may still be generated
5775 and used by Automake due to the use of per-target link flags such as
5776 @code{_CFLAGS}, @code{_LDFLAGS} or @code{_LIBTOOLFLAGS}, in cases where
5777 they apply.
5778
5779 @item maude_CCASFLAGS
5780 @itemx maude_CFLAGS
5781 @itemx maude_CPPFLAGS
5782 @itemx maude_CXXFLAGS
5783 @itemx maude_FFLAGS
5784 @itemx maude_GCJFLAGS
5785 @itemx maude_LFLAGS
5786 @itemx maude_OBJCFLAGS
5787 @itemx maude_OBJCXXFLAGS
5788 @itemx maude_RFLAGS
5789 @itemx maude_UPCFLAGS
5790 @itemx maude_YFLAGS
5791 @cindex per-target compilation flags, defined
5792 Automake allows you to set compilation flags on a per-program (or
5793 per-library) basis.  A single source file can be included in several
5794 programs, and it will potentially be compiled with different flags for
5795 each program.  This works for any language directly supported by
5796 Automake.  These @dfn{per-target compilation flags} are
5797 @samp{_CCASFLAGS},
5798 @samp{_CFLAGS},
5799 @samp{_CPPFLAGS},
5800 @samp{_CXXFLAGS},
5801 @samp{_FFLAGS},
5802 @samp{_GCJFLAGS},
5803 @samp{_LFLAGS},
5804 @samp{_OBJCFLAGS},
5805 @samp{_OBJCXXFLAGS},
5806 @samp{_RFLAGS},
5807 @samp{_UPCFLAGS}, and
5808 @samp{_YFLAGS}.
5809
5810 When using a per-target compilation flag, Automake will choose a
5811 different name for the intermediate object files.  Ordinarily a file
5812 like @file{sample.c} will be compiled to produce @file{sample.o}.
5813 However, if the program's @code{_CFLAGS} variable is set, then the
5814 object file will be named, for instance, @file{maude-sample.o}.  (See
5815 also @ref{Renamed Objects}.)  The use of per-target compilation flags
5816 with C sources requires that the macro @code{AM_PROG_CC_C_O} be called
5817 from @file{configure.ac}.
5818
5819 In compilations with per-target flags, the ordinary @samp{AM_} form of
5820 the flags variable is @emph{not} automatically included in the
5821 compilation (however, the user form of the variable @emph{is} included).
5822 So for instance, if you want the hypothetical @file{maude} compilations
5823 to also use the value of @code{AM_CFLAGS}, you would need to write:
5824
5825 @example
5826 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
5827 @end example
5828
5829 @xref{Flag Variables Ordering}, for more discussion about the
5830 interaction between user variables, @samp{AM_} shadow variables, and
5831 per-target variables.
5832
5833 @item maude_SHORTNAME
5834 On some platforms the allowable file names are very short.  In order to
5835 support these systems and per-target compilation flags at the same
5836 time, Automake allows you to set a ``short name'' that will influence
5837 how intermediate object files are named.  For instance, in the following
5838 example,
5839
5840 @example
5841 bin_PROGRAMS = maude
5842 maude_CPPFLAGS = -DSOMEFLAG
5843 maude_SHORTNAME = m
5844 maude_SOURCES = sample.c @dots{}
5845 @end example
5846
5847 @noindent
5848 the object file would be named @file{m-sample.o} rather than
5849 @file{maude-sample.o}.
5850
5851 This facility is rarely needed in practice,
5852 and we recommend avoiding it until you find it is required.
5853 @end vtable
5854
5855 @node Default _SOURCES
5856 @section Default @code{_SOURCES}
5857
5858 @vindex _SOURCES
5859 @vindex SOURCES
5860 @cindex @code{_SOURCES}, default
5861 @cindex default @code{_SOURCES}
5862 @vindex AM_DEFAULT_SOURCE_EXT
5863
5864 @code{_SOURCES} variables are used to specify source files of programs
5865 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
5866 libraries (@pxref{A Shared Library}).
5867
5868 When no such variable is specified for a target, Automake will define
5869 one itself.  The default is to compile a single C file whose base name
5870 is the name of the target itself, with any extension replaced by
5871 @code{AM_DEFAULT_SOURCE_EXT}, which defaults to @file{.c}.
5872
5873 For example if you have the following somewhere in your
5874 @file{Makefile.am} with no corresponding @code{libfoo_a_SOURCES}:
5875
5876 @example
5877 lib_LIBRARIES = libfoo.a sub/libc++.a
5878 @end example
5879
5880 @noindent
5881 @file{libfoo.a} will be built using a default source file named
5882 @file{libfoo.c}, and @file{sub/libc++.a} will be built from
5883 @file{sub/libc++.c}.  (In older versions @file{sub/libc++.a}
5884 would be built from @file{sub_libc___a.c}, i.e., the default source
5885 was the canonized name of the target, with @file{.c} appended.
5886 We believe the new behavior is more sensible, but for backward
5887 compatibility @command{automake} will use the old name if a file or a rule
5888 with that name exists and @code{AM_DEFAULT_SOURCE_EXT} is not used.)
5889
5890 @cindex @code{check_PROGRAMS} example
5891 @vindex check_PROGRAMS
5892 Default sources are mainly useful in test suites, when building many
5893 test programs each from a single source.  For instance, in
5894
5895 @example
5896 check_PROGRAMS = test1 test2 test3
5897 AM_DEFAULT_SOURCE_EXT = .cpp
5898 @end example
5899
5900 @noindent
5901 @file{test1}, @file{test2}, and @file{test3} will be built
5902 from @file{test1.cpp}, @file{test2.cpp}, and @file{test3.cpp}.
5903 Without the last line, they will be built from @file{test1.c},
5904 @file{test2.c}, and @file{test3.c}.
5905
5906 @cindex Libtool modules, default source example
5907 @cindex default source, Libtool modules example
5908 Another case where this is convenient is building many Libtool modules
5909 (@file{module@var{n}.la}), each defined in its own file
5910 (@file{module@var{n}.c}).
5911
5912 @example
5913 AM_LDFLAGS = -module
5914 lib_LTLIBRARIES = module1.la module2.la module3.la
5915 @end example
5916
5917 @cindex empty @code{_SOURCES}
5918 @cindex @code{_SOURCES}, empty
5919 Finally, there is one situation where this default source computation
5920 needs to be avoided: when a target should not be built from sources.
5921 We already saw such an example in @ref{true}; this happens when all
5922 the constituents of a target have already been compiled and just need
5923 to be combined using a @code{_LDADD} variable.  Then it is necessary
5924 to define an empty @code{_SOURCES} variable, so that @command{automake}
5925 does not compute a default.
5926
5927 @example
5928 bin_PROGRAMS = target
5929 target_SOURCES =
5930 target_LDADD = libmain.a libmisc.a
5931 @end example
5932
5933 @node LIBOBJS
5934 @section Special handling for @code{LIBOBJS} and @code{ALLOCA}
5935
5936 @cindex @code{LIBOBJS}, example
5937 @cindex @code{ALLOCA}, example
5938 @cindex @code{LIBOBJS}, special handling
5939 @cindex @code{ALLOCA}, special handling
5940 @vindex LTLIBOBJS
5941 @vindex LIBOBJS
5942 @vindex LTALLOCA
5943 @vindex ALLOCA
5944
5945 The @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} variables list object
5946 files that should be compiled into the project to provide an
5947 implementation for functions that are missing or broken on the host
5948 system.  They are substituted by @file{configure}.
5949
5950 @acindex AC_LIBOBJ
5951
5952 These variables are defined by Autoconf macros such as
5953 @code{AC_LIBOBJ}, @code{AC_REPLACE_FUNCS} (@pxref{Generic Functions, ,
5954 Generic Function Checks, autoconf, The Autoconf Manual}), or
5955 @code{AC_FUNC_ALLOCA} (@pxref{Particular Functions, , Particular
5956 Function Checks, autoconf, The Autoconf Manual}).  Many other Autoconf
5957 macros call @code{AC_LIBOBJ} or @code{AC_REPLACE_FUNCS} to
5958 populate @samp{$(LIBOBJS)}.
5959
5960 @acindex AC_LIBSOURCE
5961
5962 Using these variables is very similar to doing conditional compilation
5963 using @code{AC_SUBST} variables, as described in @ref{Conditional
5964 Sources}.  That is, when building a program, @samp{$(LIBOBJS)} and
5965 @samp{$(ALLOCA)} should be added to the associated @samp{*_LDADD}
5966 variable, or to the @samp{*_LIBADD} variable when building a library.
5967 However there is no need to list the corresponding sources in
5968 @samp{EXTRA_*_SOURCES} nor to define @samp{*_DEPENDENCIES}.  Automake
5969 automatically adds @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} to the
5970 dependencies, and it will discover the list of corresponding source
5971 files automatically (by tracing the invocations of the
5972 @code{AC_LIBSOURCE} Autoconf macros).  If you have already defined
5973 @samp{*_DEPENDENCIES} explicitly for an unrelated reason, then you
5974 either need to add these variables manually, or use
5975 @samp{EXTRA_*_DEPENDENCIES} instead of @samp{*_DEPENDENCIES}.
5976
5977 These variables are usually used to build a portability library that
5978 is linked with all the programs of the project.  We now review a
5979 sample setup.  First, @file{configure.ac} contains some checks that
5980 affect either @code{LIBOBJS} or @code{ALLOCA}.
5981
5982 @example
5983 # configure.ac
5984 @dots{}
5985 AC_CONFIG_LIBOBJ_DIR([lib])
5986 @dots{}
5987 AC_FUNC_MALLOC             dnl May add malloc.$(OBJEXT) to LIBOBJS
5988 AC_FUNC_MEMCMP             dnl May add memcmp.$(OBJEXT) to LIBOBJS
5989 AC_REPLACE_FUNCS([strdup]) dnl May add strdup.$(OBJEXT) to LIBOBJS
5990 AC_FUNC_ALLOCA             dnl May add alloca.$(OBJEXT) to ALLOCA
5991 @dots{}
5992 AC_CONFIG_FILES([
5993   lib/Makefile
5994   src/Makefile
5995 ])
5996 AC_OUTPUT
5997 @end example
5998
5999 @acindex AC_CONFIG_LIBOBJ_DIR
6000
6001 The @code{AC_CONFIG_LIBOBJ_DIR} tells Autoconf that the source files
6002 of these object files are to be found in the @file{lib/} directory.
6003 Automake can also use this information, otherwise it expects the
6004 source files are to be in the directory where the @samp{$(LIBOBJS)}
6005 and @samp{$(ALLOCA)} variables are used.
6006
6007 The @file{lib/} directory should therefore contain @file{malloc.c},
6008 @file{memcmp.c}, @file{strdup.c}, @file{alloca.c}.  Here is its
6009 @file{Makefile.am}:
6010
6011 @example
6012 # lib/Makefile.am
6013
6014 noinst_LIBRARIES = libcompat.a
6015 libcompat_a_SOURCES =
6016 libcompat_a_LIBADD = $(LIBOBJS) $(ALLOCA)
6017 @end example
6018
6019 The library can have any name, of course, and anyway it is not going
6020 to be installed: it just holds the replacement versions of the missing
6021 or broken functions so we can later link them in.  Many projects
6022 also include extra functions, specific to the project, in that
6023 library: they are simply added on the @code{_SOURCES} line.
6024
6025 @cindex Empty libraries and @samp{$(LIBOBJS)}
6026 @cindex @samp{$(LIBOBJS)} and empty libraries
6027 There is a small trap here, though: @samp{$(LIBOBJS)} and
6028 @samp{$(ALLOCA)} might be empty, and building an empty library is not
6029 portable.  You should ensure that there is always something to put in
6030 @file{libcompat.a}.  Most projects will also add some utility
6031 functions in that directory, and list them in
6032 @code{libcompat_a_SOURCES}, so in practice @file{libcompat.a} cannot
6033 be empty.
6034
6035 Finally here is how this library could be used from the @file{src/}
6036 directory.
6037
6038 @example
6039 # src/Makefile.am
6040
6041 # Link all programs in this directory with libcompat.a
6042 LDADD = ../lib/libcompat.a
6043
6044 bin_PROGRAMS = tool1 tool2 @dots{}
6045 tool1_SOURCES = @dots{}
6046 tool2_SOURCES = @dots{}
6047 @end example
6048
6049 When option @option{subdir-objects} is not used, as in the above
6050 example, the variables @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} can only
6051 be used in the directory where their sources lie.  E.g., here it would
6052 be wrong to use @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} in
6053 @file{src/Makefile.am}.  However if both @option{subdir-objects} and
6054 @code{AC_CONFIG_LIBOBJ_DIR} are used, it is OK to use these variables
6055 in other directories.  For instance @file{src/Makefile.am} could be
6056 changed as follows.
6057
6058 @example
6059 # src/Makefile.am
6060
6061 AUTOMAKE_OPTIONS = subdir-objects
6062 LDADD = $(LIBOBJS) $(ALLOCA)
6063
6064 bin_PROGRAMS = tool1 tool2 @dots{}
6065 tool1_SOURCES = @dots{}
6066 tool2_SOURCES = @dots{}
6067 @end example
6068
6069 Because @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} contain object
6070 file names that end with @samp{.$(OBJEXT)}, they are not suitable for
6071 Libtool libraries (where the expected object extension is @file{.lo}):
6072 @code{LTLIBOBJS} and @code{LTALLOCA} should be used instead.
6073
6074 @code{LTLIBOBJS} is defined automatically by Autoconf and should not
6075 be defined by hand (as in the past), however at the time of writing
6076 @code{LTALLOCA} still needs to be defined from @code{ALLOCA} manually.
6077 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
6078 autoconf, The Autoconf Manual}.
6079
6080
6081 @node Program Variables
6082 @section Variables used when building a program
6083
6084 Occasionally it is useful to know which @file{Makefile} variables
6085 Automake uses for compilations, and in which order (@pxref{Flag
6086 Variables Ordering}); for instance, you might need to do your own
6087 compilation in some special cases.
6088
6089 Some variables are inherited from Autoconf; these are @code{CC},
6090 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
6091 @code{LIBS}.
6092 @vindex CC
6093 @vindex CFLAGS
6094 @vindex CPPFLAGS
6095 @vindex DEFS
6096 @vindex LDFLAGS
6097 @vindex LIBS
6098
6099 There are some additional variables that Automake defines on its own:
6100
6101 @vtable @code
6102 @item AM_CPPFLAGS
6103 The contents of this variable are passed to every compilation that invokes
6104 the C preprocessor; it is a list of arguments to the preprocessor.  For
6105 instance, @option{-I} and @option{-D} options should be listed here.
6106
6107 Automake already provides some @option{-I} options automatically, in a
6108 separate variable that is also passed to every compilation that invokes
6109 the C preprocessor.  In particular it generates @samp{-I.},
6110 @samp{-I$(srcdir)}, and a @option{-I} pointing to the directory holding
6111 @file{config.h} (if you've used @code{AC_CONFIG_HEADERS}).  You can
6112 disable the default @option{-I} options using the @option{nostdinc}
6113 option.
6114
6115 When a file to be included is generated during the build and not part
6116 of a distribution tarball, its location is under @code{$(builddir)},
6117 not under @code{$(srcdir)}.  This matters especially for packages that
6118 use header files placed in sub-directories and want to allow builds
6119 outside the source tree (@pxref{VPATH Builds}). In that case we
6120 recommend to use a pair of @option{-I} options, such as, e.g.,
6121 @samp{-Isome/subdir -I$(srcdir)/some/subdir} or
6122 @samp{-I$(top_builddir)/some/subdir -I$(top_srcdir)/some/subdir}.
6123 Note that the reference to the build tree should come before the
6124 reference to the source tree, so that accidentally leftover generated
6125 files in the source directory are ignored.
6126
6127 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
6128 per-library) @code{_CPPFLAGS} variable if it is defined.
6129
6130 @item INCLUDES
6131 This does the same job as @code{AM_CPPFLAGS} (or any per-target
6132 @code{_CPPFLAGS} variable if it is used).  It is an older name for the
6133 same functionality.  This variable is deprecated; we suggest using
6134 @code{AM_CPPFLAGS} and per-target @code{_CPPFLAGS} instead.
6135
6136 @item AM_CFLAGS
6137 This is the variable the @file{Makefile.am} author can use to pass
6138 in additional C compiler flags.  In some situations, this is
6139 not used, in preference to the per-executable (or per-library)
6140 @code{_CFLAGS}.
6141
6142 @item COMPILE
6143 This is the command used to actually compile a C source file.  The
6144 file name is appended to form the complete command line.
6145
6146 @item AM_LDFLAGS
6147 This is the variable the @file{Makefile.am} author can use to pass
6148 in additional linker flags.  In some situations, this is not used, in
6149 preference to the per-executable (or per-library) @code{_LDFLAGS}.
6150
6151 @item LINK
6152 This is the command used to actually link a C program.  It already
6153 includes @samp{-o $@@} and the usual variable references (for instance,
6154 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
6155 and libraries to link in.  This variable is not used when the linker is
6156 overridden with a per-target @code{_LINK} variable or per-target flags
6157 cause Automake to define such a @code{_LINK} variable.
6158 @end vtable
6159
6160
6161 @node Yacc and Lex
6162 @section Yacc and Lex support
6163
6164 Automake has somewhat idiosyncratic support for Yacc and Lex.
6165
6166 Automake assumes that the @file{.c} file generated by @command{yacc}
6167 (or @command{lex}) should be named using the basename of the input
6168 file.  That is, for a yacc source file @file{foo.y}, Automake will
6169 cause the intermediate file to be named @file{foo.c} (as opposed to
6170 @file{y.tab.c}, which is more traditional).
6171
6172 The extension of a yacc source file is used to determine the extension
6173 of the resulting C or C++ source and header files.  Note that header
6174 files are generated only when the @option{-d} Yacc option is used; see
6175 below for more information about this flag, and how to specify it.
6176 Files with the extension @file{.y} will thus be turned into @file{.c}
6177 sources and @file{.h} headers; likewise, @file{.yy} will become
6178 @file{.cc} and @file{.hh}, @file{.y++} will become @file{c++} and
6179 @file{h++}, @file{.yxx} will become @file{.cxx} and @file{.hxx},
6180 and @file{.ypp} will become @file{.cpp} and @file{.hpp}.
6181
6182 Similarly, lex source files can be used to generate C or C++; the
6183 extensions @file{.l}, @file{.ll}, @file{.l++}, @file{.lxx}, and
6184 @file{.lpp} are recognized.
6185
6186 You should never explicitly mention the intermediate (C or C++) file
6187 in any @code{SOURCES} variable; only list the source file.
6188
6189 The intermediate files generated by @command{yacc} (or @command{lex})
6190 will be included in any distribution that is made.  That way the user
6191 doesn't need to have @command{yacc} or @command{lex}.
6192
6193 If a @command{yacc} source file is seen, then your @file{configure.ac} must
6194 define the variable @code{YACC}.  This is most easily done by invoking
6195 the macro @code{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
6196 Program Checks, autoconf, The Autoconf Manual}).
6197
6198 @vindex YFLAGS
6199 @vindex AM_YFLAGS
6200 When @code{yacc} is invoked, it is passed @code{AM_YFLAGS} and
6201 @code{YFLAGS}.  The latter is a user variable and the former is
6202 intended for the @file{Makefile.am} author.
6203
6204 @code{AM_YFLAGS} is usually used to pass the @option{-d} option to
6205 @command{yacc}.  Automake knows what this means and will automatically
6206 adjust its rules to update and distribute the header file built by
6207 @samp{yacc -d}@footnote{Please note that @command{automake} recognizes
6208 @option{-d} in @code{AM_YFLAGS} only if it is not clustered with other
6209 options; for example, it won't be recognized if @code{AM_YFLAGS} is
6210 @option{-dt}, but it will be if @code{AM_YFLAGS} is @option{-d -t} or
6211 @option{-t -d}.}.
6212 What Automake cannot guess, though, is where this
6213 header will be used: it is up to you to ensure the header gets built
6214 before it is first used.  Typically this is necessary in order for
6215 dependency tracking to work when the header is included by another
6216 file.  The common solution is listing the header file in
6217 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
6218
6219 @example
6220 BUILT_SOURCES = parser.h
6221 AM_YFLAGS = -d
6222 bin_PROGRAMS = foo
6223 foo_SOURCES = @dots{} parser.y @dots{}
6224 @end example
6225
6226 If a @command{lex} source file is seen, then your @file{configure.ac}
6227 must define the variable @code{LEX}.  You can use @code{AC_PROG_LEX}
6228 to do this (@pxref{Particular Programs, , Particular Program Checks,
6229 autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
6230 (@pxref{Macros}) is recommended.
6231
6232 @vindex LFLAGS
6233 @vindex AM_LFLAGS
6234 When @command{lex} is invoked, it is passed @code{AM_LFLAGS} and
6235 @code{LFLAGS}.  The latter is a user variable and the former is
6236 intended for the @file{Makefile.am} author.
6237
6238 When @code{AM_MAINTAINER_MODE} (@pxref{maintainer-mode}) is used, the
6239 rebuild rule for distributed Yacc and Lex sources are only used when
6240 @code{maintainer-mode} is enabled, or when the files have been erased.
6241
6242 @cindex @command{ylwrap}
6243 @cindex @command{yacc}, multiple parsers
6244 @cindex Multiple @command{yacc} parsers
6245 @cindex Multiple @command{lex} lexers
6246 @cindex @command{lex}, multiple lexers
6247
6248 When @command{lex} or @command{yacc} sources are used, @code{automake
6249 -i} automatically installs an auxiliary program called
6250 @command{ylwrap} in your package (@pxref{Auxiliary Programs}).  This
6251 program is used by the build rules to rename the output of these
6252 tools, and makes it possible to include multiple @command{yacc} (or
6253 @command{lex}) source files in a single directory.  (This is necessary
6254 because yacc's output file name is fixed, and a parallel make could
6255 conceivably invoke more than one instance of @command{yacc}
6256 simultaneously.)
6257
6258 For @command{yacc}, simply managing locking is insufficient.  The output of
6259 @command{yacc} always uses the same symbol names internally, so it isn't
6260 possible to link two @command{yacc} parsers into the same executable.
6261
6262 We recommend using the following renaming hack used in @command{gdb}:
6263 @example
6264 #define yymaxdepth c_maxdepth
6265 #define yyparse c_parse
6266 #define yylex   c_lex
6267 #define yyerror c_error
6268 #define yylval  c_lval
6269 #define yychar  c_char
6270 #define yydebug c_debug
6271 #define yypact  c_pact
6272 #define yyr1    c_r1
6273 #define yyr2    c_r2
6274 #define yydef   c_def
6275 #define yychk   c_chk
6276 #define yypgo   c_pgo
6277 #define yyact   c_act
6278 #define yyexca  c_exca
6279 #define yyerrflag c_errflag
6280 #define yynerrs c_nerrs
6281 #define yyps    c_ps
6282 #define yypv    c_pv
6283 #define yys     c_s
6284 #define yy_yys  c_yys
6285 #define yystate c_state
6286 #define yytmp   c_tmp
6287 #define yyv     c_v
6288 #define yy_yyv  c_yyv
6289 #define yyval   c_val
6290 #define yylloc  c_lloc
6291 #define yyreds  c_reds
6292 #define yytoks  c_toks
6293 #define yylhs   c_yylhs
6294 #define yylen   c_yylen
6295 #define yydefred c_yydefred
6296 #define yydgoto  c_yydgoto
6297 #define yysindex c_yysindex
6298 #define yyrindex c_yyrindex
6299 #define yygindex c_yygindex
6300 #define yytable  c_yytable
6301 #define yycheck  c_yycheck
6302 #define yyname   c_yyname
6303 #define yyrule   c_yyrule
6304 @end example
6305
6306 For each define, replace the @samp{c_} prefix with whatever you like.
6307 These defines work for @command{bison}, @command{byacc}, and
6308 traditional @code{yacc}s.  If you find a parser generator that uses a
6309 symbol not covered here, please report the new name so it can be added
6310 to the list.
6311
6312
6313 @node C++ Support
6314 @section C++ Support
6315
6316 @cindex C++ support
6317 @cindex Support for C++
6318
6319 Automake includes full support for C++.
6320
6321 Any package including C++ code must define the output variable
6322 @code{CXX} in @file{configure.ac}; the simplest way to do this is to use
6323 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
6324 Program Checks, autoconf, The Autoconf Manual}).
6325
6326 A few additional variables are defined when a C++ source file is seen:
6327
6328 @vtable @code
6329 @item CXX
6330 The name of the C++ compiler.
6331
6332 @item CXXFLAGS
6333 Any flags to pass to the C++ compiler.
6334
6335 @item AM_CXXFLAGS
6336 The maintainer's variant of @code{CXXFLAGS}.
6337
6338 @item CXXCOMPILE
6339 The command used to actually compile a C++ source file.  The file name
6340 is appended to form the complete command line.
6341
6342 @item CXXLINK
6343 The command used to actually link a C++ program.
6344 @end vtable
6345
6346
6347 @node Objective C Support
6348 @section Objective C Support
6349
6350 @cindex Objective C support
6351 @cindex Support for Objective C
6352
6353 Automake includes some support for Objective C.
6354
6355 Any package including Objective C code must define the output variable
6356 @code{OBJC} in @file{configure.ac}; the simplest way to do this is to use
6357 the @code{AC_PROG_OBJC} macro (@pxref{Particular Programs, , Particular
6358 Program Checks, autoconf, The Autoconf Manual}).
6359
6360 A few additional variables are defined when an Objective C source file
6361 is seen:
6362
6363 @vtable @code
6364 @item OBJC
6365 The name of the Objective C compiler.
6366
6367 @item OBJCFLAGS
6368 Any flags to pass to the Objective C compiler.
6369
6370 @item AM_OBJCFLAGS
6371 The maintainer's variant of @code{OBJCFLAGS}.
6372
6373 @item OBJCCOMPILE
6374 The command used to actually compile an Objective C source file.  The
6375 file name is appended to form the complete command line.
6376
6377 @item OBJCLINK
6378 The command used to actually link an Objective C program.
6379 @end vtable
6380
6381
6382 @node Objective C++ Support
6383 @section Objective C++ Support
6384
6385 @cindex Objective C++ support
6386 @cindex Support for Objective C++
6387
6388 Automake includes some support for Objective C++.
6389
6390 Any package including Objective C++ code must define the output variable
6391 @code{OBJCXX} in @file{configure.ac}; the simplest way to do this is to use
6392 the @code{AC_PROG_OBJCXX} macro (@pxref{Particular Programs, , Particular
6393 Program Checks, autoconf, The Autoconf Manual}).
6394
6395 A few additional variables are defined when an Objective C++ source file
6396 is seen:
6397
6398 @vtable @code
6399 @item OBJCXX
6400 The name of the Objective C++ compiler.
6401
6402 @item OBJCXXFLAGS
6403 Any flags to pass to the Objective C++ compiler.
6404
6405 @item AM_OBJCXXFLAGS
6406 The maintainer's variant of @code{OBJCXXFLAGS}.
6407
6408 @item OBJCXXCOMPILE
6409 The command used to actually compile an Objective C++ source file.  The
6410 file name is appended to form the complete command line.
6411
6412 @item OBJCXXLINK
6413 The command used to actually link an Objective C++ program.
6414 @end vtable
6415
6416
6417 @node Unified Parallel C Support
6418 @section Unified Parallel C Support
6419
6420 @cindex Unified Parallel C support
6421 @cindex Support for Unified Parallel C
6422
6423 Automake includes some support for Unified Parallel C.
6424
6425 Any package including Unified Parallel C code must define the output
6426 variable @code{UPC} in @file{configure.ac}; the simplest way to do
6427 this is to use the @code{AM_PROG_UPC} macro (@pxref{Public Macros}).
6428
6429 A few additional variables are defined when a Unified Parallel C
6430 source file is seen:
6431
6432 @vtable @code
6433 @item UPC
6434 The name of the Unified Parallel C compiler.
6435
6436 @item UPCFLAGS
6437 Any flags to pass to the Unified Parallel C compiler.
6438
6439 @item AM_UPCFLAGS
6440 The maintainer's variant of @code{UPCFLAGS}.
6441
6442 @item UPCCOMPILE
6443 The command used to actually compile a Unified Parallel C source file.
6444 The file name is appended to form the complete command line.
6445
6446 @item UPCLINK
6447 The command used to actually link a Unified Parallel C program.
6448 @end vtable
6449
6450
6451 @node Assembly Support
6452 @section Assembly Support
6453
6454 Automake includes some support for assembly code.  There are two forms
6455 of assembler files: normal (@file{*.s}) and preprocessed by @code{CPP}
6456 (@file{*.S} or @file{*.sx}).
6457
6458 @vindex CCAS
6459 @vindex CCASFLAGS
6460 @vindex CPPFLAGS
6461 @vindex AM_CCASFLAGS
6462 @vindex AM_CPPFLAGS
6463 The variable @code{CCAS} holds the name of the compiler used to build
6464 assembly code.  This compiler must work a bit like a C compiler; in
6465 particular it must accept @option{-c} and @option{-o}.  The values of
6466 @code{CCASFLAGS} and @code{AM_CCASFLAGS} (or its per-target
6467 definition) is passed to the compilation.  For preprocessed files,
6468 @code{DEFS}, @code{DEFAULT_INCLUDES}, @code{INCLUDES}, @code{CPPFLAGS}
6469 and @code{AM_CPPFLAGS} are also used.
6470
6471 The autoconf macro @code{AM_PROG_AS} will define @code{CCAS} and
6472 @code{CCASFLAGS} for you (unless they are already set, it simply sets
6473 @code{CCAS} to the C compiler and @code{CCASFLAGS} to the C compiler
6474 flags), but you are free to define these variables by other means.
6475
6476 Only the suffixes @file{.s}, @file{.S}, and @file{.sx} are recognized by
6477 @command{automake} as being files containing assembly code.
6478
6479
6480 @node Fortran 77 Support
6481 @comment  node-name,  next,  previous,  up
6482 @section Fortran 77 Support
6483
6484 @cindex Fortran 77 support
6485 @cindex Support for Fortran 77
6486
6487 Automake includes full support for Fortran 77.
6488
6489 Any package including Fortran 77 code must define the output variable
6490 @code{F77} in @file{configure.ac}; the simplest way to do this is to use
6491 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
6492 Program Checks, autoconf, The Autoconf Manual}).
6493
6494 A few additional variables are defined when a Fortran 77 source file is
6495 seen:
6496
6497 @vtable @code
6498
6499 @item F77
6500 The name of the Fortran 77 compiler.
6501
6502 @item FFLAGS
6503 Any flags to pass to the Fortran 77 compiler.
6504
6505 @item AM_FFLAGS
6506 The maintainer's variant of @code{FFLAGS}.
6507
6508 @item RFLAGS
6509 Any flags to pass to the Ratfor compiler.
6510
6511 @item AM_RFLAGS
6512 The maintainer's variant of @code{RFLAGS}.
6513
6514 @item F77COMPILE
6515 The command used to actually compile a Fortran 77 source file.  The file
6516 name is appended to form the complete command line.
6517
6518 @item FLINK
6519 The command used to actually link a pure Fortran 77 program or shared
6520 library.
6521
6522 @end vtable
6523
6524 Automake can handle preprocessing Fortran 77 and Ratfor source files in
6525 addition to compiling them@footnote{Much, if not most, of the
6526 information in the following sections pertaining to preprocessing
6527 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
6528 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
6529 also contains some support for creating programs and shared libraries
6530 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
6531 Fortran 77 With C and C++}).
6532
6533 These issues are covered in the following sections.
6534
6535 @menu
6536 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
6537 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
6538 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
6539 @end menu
6540
6541
6542 @node Preprocessing Fortran 77
6543 @comment  node-name,  next,  previous,  up
6544 @subsection Preprocessing Fortran 77
6545
6546 @cindex Preprocessing Fortran 77
6547 @cindex Fortran 77, Preprocessing
6548 @cindex Ratfor programs
6549
6550 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
6551 rule runs just the preprocessor to convert a preprocessable Fortran 77
6552 or Ratfor source file into a strict Fortran 77 source file.  The precise
6553 command used is as follows:
6554
6555 @table @file
6556
6557 @item .F
6558 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6559 $(AM_FFLAGS) $(FFLAGS)}
6560
6561 @item .r
6562 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6563
6564 @end table
6565
6566
6567 @node Compiling Fortran 77 Files
6568 @comment  node-name,  next,  previous,  up
6569 @subsection Compiling Fortran 77 Files
6570
6571 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
6572 @file{N.r} by running the Fortran 77 compiler.  The precise command used
6573 is as follows:
6574
6575 @table @file
6576
6577 @item .f
6578 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
6579
6580 @item .F
6581 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6582 $(AM_FFLAGS) $(FFLAGS)}
6583
6584 @item .r
6585 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6586
6587 @end table
6588
6589
6590 @node Mixing Fortran 77 With C and C++
6591 @comment  node-name,  next,  previous,  up
6592 @subsection Mixing Fortran 77 With C and C++
6593
6594 @cindex Fortran 77, mixing with C and C++
6595 @cindex Mixing Fortran 77 with C and C++
6596 @cindex Linking Fortran 77 with C and C++
6597 @cindex cfortran
6598 @cindex Mixing Fortran 77 with C and/or C++
6599
6600 Automake currently provides @emph{limited} support for creating programs
6601 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
6602 However, there are many other issues related to mixing Fortran 77 with
6603 other languages that are @emph{not} (currently) handled by Automake, but
6604 that are handled by other packages@footnote{For example,
6605 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
6606 addresses all of these inter-language issues, and runs under nearly all
6607 Fortran 77, C and C++ compilers on nearly all platforms.  However,
6608 @command{cfortran} is not yet Free Software, but it will be in the next
6609 major release.}.
6610
6611 Automake can help in two ways:
6612
6613 @enumerate
6614 @item
6615 Automatic selection of the linker depending on which combinations of
6616 source code.
6617
6618 @item
6619 Automatic selection of the appropriate linker flags (e.g., @option{-L} and
6620 @option{-l}) to pass to the automatically selected linker in order to link
6621 in the appropriate Fortran 77 intrinsic and run-time libraries.
6622
6623 @cindex @code{FLIBS}, defined
6624 @vindex FLIBS
6625 These extra Fortran 77 linker flags are supplied in the output variable
6626 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro.
6627 @xref{Fortran Compiler, , Fortran Compiler Characteristics, autoconf,
6628 The Autoconf Manual}.
6629 @end enumerate
6630
6631 If Automake detects that a program or shared library (as mentioned in
6632 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
6633 code that is a mixture of Fortran 77 and C and/or C++, then it requires
6634 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
6635 @file{configure.ac}, and that either @code{$(FLIBS)}
6636 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
6637 (for shared libraries) variables.  It is the responsibility of the
6638 person writing the @file{Makefile.am} to make sure that @samp{$(FLIBS)}
6639 appears in the appropriate @code{_LDADD} or
6640 @code{_LIBADD} variable.
6641
6642 @cindex Mixed language example
6643 @cindex Example, mixed language
6644
6645 For example, consider the following @file{Makefile.am}:
6646
6647 @example
6648 bin_PROGRAMS = foo
6649 foo_SOURCES  = main.cc foo.f
6650 foo_LDADD    = libfoo.la $(FLIBS)
6651
6652 pkglib_LTLIBRARIES = libfoo.la
6653 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
6654 libfoo_la_LIBADD   = $(FLIBS)
6655 @end example
6656
6657 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
6658 is mentioned in @file{configure.ac}.  Also, if @samp{$(FLIBS)} hadn't
6659 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
6660 Automake would have issued a warning.
6661
6662 @menu
6663 * How the Linker is Chosen::    Automatic linker selection
6664 @end menu
6665
6666 @node How the Linker is Chosen
6667 @comment  node-name,  next,  previous,  up
6668 @subsubsection How the Linker is Chosen
6669
6670 @cindex Automatic linker selection
6671 @cindex Selecting the linker automatically
6672
6673 When a program or library mixes several languages, Automake choose the
6674 linker according to the following priorities.  (The names in
6675 parentheses are the variables containing the link command.)
6676
6677 @enumerate
6678 @item
6679 @vindex GCJLINK
6680 Native Java (@code{GCJLINK})
6681 @item
6682 @vindex OBJCXXLINK
6683 Objective C++ (@code{OBJCXXLINK})
6684 @item
6685 @vindex CXXLINK
6686 C++ (@code{CXXLINK})
6687 @item
6688 @vindex F77LINK
6689 Fortran 77 (@code{F77LINK})
6690 @item
6691 @vindex FCLINK
6692 Fortran (@code{FCLINK})
6693 @item
6694 @vindex OBJCLINK
6695 Objective C (@code{OBJCLINK})
6696 @item
6697 @vindex UPCLINK
6698 Unified Parallel C (@code{UPCLINK})
6699 @item
6700 @vindex LINK
6701 C (@code{LINK})
6702 @end enumerate
6703
6704 For example, if Fortran 77, C and C++ source code is compiled
6705 into a program, then the C++ linker will be used.  In this case, if the
6706 C or Fortran 77 linkers required any special libraries that weren't
6707 included by the C++ linker, then they must be manually added to an
6708 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
6709 @file{Makefile.am}.
6710
6711 Automake only looks at the file names listed in @file{_SOURCES}
6712 variables to choose the linker, and defaults to the C linker.
6713 Sometimes this is inconvenient because you are linking against a
6714 library written in another language and would like to set the linker
6715 more appropriately.  @xref{Libtool Convenience Libraries}, for a
6716 trick with @code{nodist_EXTRA_@dots{}_SOURCES}.
6717
6718 A per-target @code{_LINK} variable will override the above selection.
6719 Per-target link flags will cause Automake to write a per-target
6720 @code{_LINK} variable according to the language chosen as above.
6721
6722
6723 @node Fortran 9x Support
6724 @comment  node-name,  next,  previous,  up
6725 @section Fortran 9x Support
6726
6727 @cindex Fortran 9x support
6728 @cindex Support for Fortran 9x
6729
6730 Automake includes support for Fortran 9x.
6731
6732 Any package including Fortran 9x code must define the output variable
6733 @code{FC} in @file{configure.ac}; the simplest way to do this is to use
6734 the @code{AC_PROG_FC} macro (@pxref{Particular Programs, , Particular
6735 Program Checks, autoconf, The Autoconf Manual}).
6736
6737 A few additional variables are defined when a Fortran 9x source file is
6738 seen:
6739
6740 @vtable @code
6741
6742 @item FC
6743 The name of the Fortran 9x compiler.
6744
6745 @item FCFLAGS
6746 Any flags to pass to the Fortran 9x compiler.
6747
6748 @item AM_FCFLAGS
6749 The maintainer's variant of @code{FCFLAGS}.
6750
6751 @item FCCOMPILE
6752 The command used to actually compile a Fortran 9x source file.  The file
6753 name is appended to form the complete command line.
6754
6755 @item FCLINK
6756 The command used to actually link a pure Fortran 9x program or shared
6757 library.
6758
6759 @end vtable
6760
6761 @menu
6762 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
6763 @end menu
6764
6765 @node Compiling Fortran 9x Files
6766 @comment  node-name,  next,  previous,  up
6767 @subsection Compiling Fortran 9x Files
6768
6769 @file{@var{file}.o} is made automatically from @file{@var{file}.f90},
6770 @file{@var{file}.f95}, @file{@var{file}.f03}, or @file{@var{file}.f08}
6771 by running the Fortran 9x compiler.  The precise command used
6772 is as follows:
6773
6774 @table @file
6775
6776 @item .f90
6777 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f90) $<}
6778
6779 @item .f95
6780 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f95) $<}
6781
6782 @item .f03
6783 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f03) $<}
6784
6785 @item .f08
6786 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f08) $<}
6787
6788 @end table
6789
6790 @node Java Support with gcj
6791 @comment  node-name,  next,  previous,  up
6792 @section Compiling Java sources using gcj
6793
6794 @cindex Java support with gcj
6795 @cindex Support for Java with gcj
6796 @cindex Java to native code, compilation
6797 @cindex Compilation of Java to native code
6798
6799 Automake includes support for natively compiled Java, using @command{gcj},
6800 the Java front end to the GNU Compiler Collection (rudimentary support
6801 for compiling Java to bytecode using the @command{javac} compiler is
6802 also present, @emph{albeit deprecated}; @pxref{Java}).
6803
6804 Any package including Java code to be compiled must define the output
6805 variable @code{GCJ} in @file{configure.ac}; the variable @code{GCJFLAGS}
6806 must also be defined somehow (either in @file{configure.ac} or
6807 @file{Makefile.am}).  The simplest way to do this is to use the
6808 @code{AM_PROG_GCJ} macro.
6809
6810 @vindex GCJFLAGS
6811
6812 By default, programs including Java source files are linked with
6813 @command{gcj}.
6814
6815 As always, the contents of @code{AM_GCJFLAGS} are passed to every
6816 compilation invoking @command{gcj} (in its role as an ahead-of-time
6817 compiler, when invoking it to create @file{.class} files,
6818 @code{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
6819 options to @command{gcj} from @file{Makefile.am}, this variable, and not
6820 the user variable @code{GCJFLAGS}, should be used.
6821
6822 @vindex AM_GCJFLAGS
6823
6824 @command{gcj} can be used to compile @file{.java}, @file{.class},
6825 @file{.zip}, or @file{.jar} files.
6826
6827 When linking, @command{gcj} requires that the main class be specified
6828 using the @option{--main=} option.  The easiest way to do this is to use
6829 the @code{_LDFLAGS} variable for the program.
6830
6831
6832 @node Vala Support
6833 @comment  node-name,  next,  previous,  up
6834 @section Vala Support
6835
6836 @cindex Vala Support
6837 @cindex Support for Vala
6838
6839 Automake provides initial support for Vala
6840 (@uref{http://www.vala-project.org/}).
6841 This requires valac version 0.7.0 or later, and currently requires
6842 the user to use GNU @command{make}.
6843
6844 @example
6845 foo_SOURCES = foo.vala bar.vala zardoc.c
6846 @end example
6847
6848 Any @file{.vala} file listed in a @code{_SOURCES} variable will be
6849 compiled into C code by the Vala compiler. The generated @file{.c} files
6850 are distributed. The end user does not need to have a Vala compiler installed.
6851
6852 Automake ships with an Autoconf macro called @code{AM_PROG_VALAC}
6853 that will locate the Vala compiler and optionally check its version
6854 number.
6855
6856 @defmac AM_PROG_VALAC (@ovar{minimum-version}, @ovar{action-if-found},
6857   @ovar{action-if-not-found})
6858 Search for a Vala compiler in @env{PATH}.  If it is found, the variable
6859 @code{VALAC} is set to point to it (see below for more details).  This
6860 macro takes three optional arguments.  The first argument, if present,
6861 is the minimum version of the Vala compiler required to compile this
6862 package.  If a compiler is found and satisfies @var{minimum-version},
6863 then @var{action-if-found} is run (this defaults to do nothing).
6864 Otherwise, @var{action-if-not-found} is run.  If @var{action-if-not-found}
6865 is not specified, the default value is to print a warning in case no
6866 compiler is found, or if a too-old version of the compiler is found.
6867 @end defmac
6868
6869 There are a few variables that are used when compiling Vala sources:
6870
6871 @vtable @code
6872 @item VALAC
6873 Absolute path to the Vala compiler, or simply @samp{valac} if no
6874 suitable compiler Vala could be found at configure runtime.
6875
6876 @item VALAFLAGS
6877 Additional arguments for the Vala compiler.
6878
6879 @item AM_VALAFLAGS
6880 The maintainer's variant of @code{VALAFLAGS}.
6881
6882 @example
6883 lib_LTLIBRARIES = libfoo.la
6884 libfoo_la_SOURCES = foo.vala
6885 @end example
6886 @end vtable
6887
6888 Note that currently, you cannot use per-target @code{*_VALAFLAGS}
6889 (@pxref{Renamed Objects}) to produce different C files from one Vala
6890 source file.
6891
6892
6893 @node Support for Other Languages
6894 @comment  node-name,  next,  previous,  up
6895 @section Support for Other Languages
6896
6897 Automake currently only includes full support for C, C++ (@pxref{C++
6898 Support}), Objective C (@pxref{Objective C Support}),
6899 Objective C++ (@pxref{Objective C++ Support}),
6900 Fortran 77
6901 (@pxref{Fortran 77 Support}), Fortran 9x (@pxref{Fortran 9x Support}),
6902 and Java (@pxref{Java Support with gcj}).  There is only rudimentary
6903 support for other languages, support for which will be improved based
6904 on user demand.
6905
6906 Some limited support for adding your own languages is available via the
6907 suffix rule handling (@pxref{Suffixes}).
6908
6909 @node Dependencies
6910 @section Automatic dependency tracking
6911
6912 As a developer it is often painful to continually update the
6913 @file{Makefile.am} whenever the include-file dependencies change in a
6914 project.  Automake supplies a way to automatically track dependency
6915 changes (@pxref{Dependency Tracking}).
6916
6917 @cindex Dependency tracking
6918 @cindex Automatic dependency tracking
6919
6920 Automake always uses complete dependencies for a compilation,
6921 including system headers.  Automake's model is that dependency
6922 computation should be a side effect of the build.  To this end,
6923 dependencies are computed by running all compilations through a
6924 special wrapper program called @command{depcomp}.  @command{depcomp}
6925 understands how to coax many different C and C++ compilers into
6926 generating dependency information in the format it requires.
6927 @samp{automake -a} will install @command{depcomp} into your source
6928 tree for you.  If @command{depcomp} can't figure out how to properly
6929 invoke your compiler, dependency tracking will simply be disabled for
6930 your build.
6931
6932 @cindex @command{depcomp}
6933
6934 Experience with earlier versions of Automake (@pxref{Dependency Tracking
6935 Evolution, , Dependency Tracking Evolution, automake-history, Brief History
6936 of Automake}) taught us that it is not reliable to generate dependencies
6937 only on the maintainer's system, as configurations vary too much.  So
6938 instead Automake implements dependency tracking at build time.
6939
6940 Automatic dependency tracking can be suppressed by putting
6941 @option{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
6942 passing @option{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
6943 (this should be the preferred way).  Or, you can invoke @command{automake}
6944 with the @option{-i} option.  Dependency tracking is enabled by default.
6945
6946 @vindex AUTOMAKE_OPTIONS
6947 @opindex no-dependencies
6948
6949 The person building your package also can choose to disable dependency
6950 tracking by configuring with @option{--disable-dependency-tracking}.
6951
6952 @cindex Disabling dependency tracking
6953 @cindex Dependency tracking, disabling
6954
6955
6956 @node EXEEXT
6957 @section Support for executable extensions
6958
6959 @cindex Executable extension
6960 @cindex Extension, executable
6961 @cindex Windows
6962
6963 On some platforms, such as Windows, executables are expected to have an
6964 extension such as @file{.exe}.  On these platforms, some compilers (GCC
6965 among them) will automatically generate @file{foo.exe} when asked to
6966 generate @file{foo}.
6967
6968 Automake provides mostly-transparent support for this.  Unfortunately
6969 @emph{mostly} doesn't yet mean @emph{fully}.  Until the English
6970 dictionary is revised, you will have to assist Automake if your package
6971 must support those platforms.
6972
6973 One thing you must be aware of is that, internally, Automake rewrites
6974 something like this:
6975
6976 @example
6977 bin_PROGRAMS = liver
6978 @end example
6979
6980 to this:
6981
6982 @example
6983 bin_PROGRAMS = liver$(EXEEXT)
6984 @end example
6985
6986 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
6987 extension.
6988
6989 The variables @code{TESTS} and @code{XFAIL_TESTS} (@pxref{Simple Tests})
6990 are also rewritten if they contain filenames that have been declared as
6991 programs in the same @file{Makefile}.  (This is mostly useful when some
6992 programs from @code{check_PROGRAMS} are listed in @code{TESTS}.)
6993
6994 However, Automake cannot apply this rewriting to @command{configure}
6995 substitutions.  This means that if you are conditionally building a
6996 program using such a substitution, then your @file{configure.ac} must
6997 take care to add @samp{$(EXEEXT)} when constructing the output variable.
6998
6999 Sometimes maintainers like to write an explicit link rule for their
7000 program.  Without executable extension support, this is easy---you
7001 simply write a rule whose target is the name of the program.  However,
7002 when executable extension support is enabled, you must instead add the
7003 @samp{$(EXEEXT)} suffix.
7004
7005 This might be a nuisance for maintainers who know their package will
7006 never run on a platform that has
7007 executable extensions.  For those maintainers, the @option{no-exeext}
7008 option (@pxref{Options}) will disable this feature.  This works in a
7009 fairly ugly way; if @option{no-exeext} is seen, then the presence of a
7010 rule for a target named @code{foo} in @file{Makefile.am} will override
7011 an @command{automake}-generated rule for @samp{foo$(EXEEXT)}.  Without
7012 the @option{no-exeext} option, this use will give a diagnostic.
7013
7014
7015 @node Other Objects
7016 @chapter Other Derived Objects
7017
7018 Automake can handle derived objects that are not C programs.  Sometimes
7019 the support for actually building such objects must be explicitly
7020 supplied, but Automake will still automatically handle installation and
7021 distribution.
7022
7023 @menu
7024 * Scripts::                     Executable scripts
7025 * Headers::                     Header files
7026 * Data::                        Architecture-independent data files
7027 * Sources::                     Derived sources
7028 @end menu
7029
7030
7031 @node Scripts
7032 @section Executable Scripts
7033
7034 @cindex @code{_SCRIPTS} primary, defined
7035 @cindex @code{SCRIPTS} primary, defined
7036 @cindex Primary variable, @code{SCRIPTS}
7037 @vindex _SCRIPTS
7038 @cindex Installing scripts
7039
7040 It is possible to define and install programs that are scripts.  Such
7041 programs are listed using the @code{SCRIPTS} primary name.  When the
7042 script is distributed in its final, installable form, the
7043 @file{Makefile} usually looks as follows:
7044 @vindex SCRIPTS
7045
7046 @example
7047 # Install my_script in $(bindir) and distribute it.
7048 dist_bin_SCRIPTS = my_script
7049 @end example
7050
7051 Scripts are not distributed by default; as we have just seen, those
7052 that should be distributed can be specified using a @code{dist_}
7053 prefix as with other primaries.
7054
7055 @cindex @code{SCRIPTS}, installation directories
7056 @vindex bin_SCRIPTS
7057 @vindex sbin_SCRIPTS
7058 @vindex libexec_SCRIPTS
7059 @vindex pkgdata_SCRIPTS
7060 @vindex pkglibexec_SCRIPTS
7061 @vindex noinst_SCRIPTS
7062 @vindex check_SCRIPTS
7063
7064 Scripts can be installed in @code{bindir}, @code{sbindir},
7065 @code{libexecdir}, @code{pkglibexecdir}, or @code{pkgdatadir}.
7066
7067 Scripts that need not be installed can be listed in
7068 @code{noinst_SCRIPTS}, and among them, those which are needed only by
7069 @samp{make check} should go in @code{check_SCRIPTS}.
7070
7071 When a script needs to be built, the @file{Makefile.am} should include
7072 the appropriate rules.  For instance the @command{automake} program
7073 itself is a Perl script that is generated from @file{automake.in}.
7074 Here is how this is handled:
7075
7076 @example
7077 bin_SCRIPTS = automake
7078 CLEANFILES = $(bin_SCRIPTS)
7079 EXTRA_DIST = automake.in
7080
7081 do_subst = sed -e 's,[@@]datadir[@@],$(datadir),g' \
7082             -e 's,[@@]PERL[@@],$(PERL),g' \
7083             -e 's,[@@]PACKAGE[@@],$(PACKAGE),g' \
7084             -e 's,[@@]VERSION[@@],$(VERSION),g' \
7085             @dots{}
7086
7087 automake: automake.in Makefile
7088         $(do_subst) < $(srcdir)/automake.in > automake
7089         chmod +x automake
7090 @end example
7091
7092 Such scripts for which a build rule has been supplied need to be
7093 deleted explicitly using @code{CLEANFILES} (@pxref{Clean}), and their
7094 sources have to be distributed, usually with @code{EXTRA_DIST}
7095 (@pxref{Basics of Distribution}).
7096
7097 Another common way to build scripts is to process them from
7098 @file{configure} with @code{AC_CONFIG_FILES}.  In this situation
7099 Automake knows which files should be cleaned and distributed, and what
7100 the rebuild rules should look like.
7101
7102 For instance if @file{configure.ac} contains
7103
7104 @example
7105 AC_CONFIG_FILES([src/my_script], [chmod +x src/my_script])
7106 @end example
7107
7108 @noindent
7109 to build @file{src/my_script} from @file{src/my_script.in}, then a
7110 @file{src/Makefile.am} to install this script in @code{$(bindir)} can
7111 be as simple as
7112
7113 @example
7114 bin_SCRIPTS = my_script
7115 CLEANFILES = $(bin_SCRIPTS)
7116 @end example
7117
7118 @noindent
7119 There is no need for @code{EXTRA_DIST} or any build rule: Automake
7120 infers them from @code{AC_CONFIG_FILES} (@pxref{Requirements}).
7121 @code{CLEANFILES} is still useful, because by default Automake will
7122 clean targets of @code{AC_CONFIG_FILES} in @code{distclean}, not
7123 @code{clean}.
7124
7125 Although this looks simpler, building scripts this way has one
7126 drawback: directory variables such as @code{$(datadir)} are not fully
7127 expanded and may refer to other directory variables.
7128
7129 @node Headers
7130 @section Header files
7131
7132 @cindex @code{_HEADERS} primary, defined
7133 @cindex @code{HEADERS} primary, defined
7134 @cindex Primary variable, @code{HEADERS}
7135 @vindex _HEADERS
7136 @vindex noinst_HEADERS
7137 @cindex @code{HEADERS}, installation directories
7138 @cindex Installing headers
7139 @vindex include_HEADERS
7140 @vindex oldinclude_HEADERS
7141 @vindex pkginclude_HEADERS
7142
7143
7144 Header files that must be installed are specified by the
7145 @code{HEADERS} family of variables.  Headers can be installed in
7146 @code{includedir}, @code{oldincludedir}, @code{pkgincludedir} or any
7147 other directory you may have defined (@pxref{Uniform}).  For instance,
7148
7149 @example
7150 include_HEADERS = foo.h bar/bar.h
7151 @end example
7152
7153 @noindent
7154 will install the two files as @file{$(includedir)/foo.h} and
7155 @file{$(includedir)/bar.h}.
7156
7157 The @code{nobase_} prefix is also supported,
7158
7159 @example
7160 nobase_include_HEADERS = foo.h bar/bar.h
7161 @end example
7162
7163 @noindent
7164 will install the two files as @file{$(includedir)/foo.h} and
7165 @file{$(includedir)/bar/bar.h} (@pxref{Alternative}).
7166
7167 @vindex noinst_HEADERS
7168 Usually, only header files that accompany installed libraries need to
7169 be installed.  Headers used by programs or convenience libraries are
7170 not installed.  The @code{noinst_HEADERS} variable can be used for
7171 such headers.  However when the header actually belongs to a single
7172 convenience library or program, we recommend listing it in the
7173 program's or library's @code{_SOURCES} variable (@pxref{Program
7174 Sources}) instead of in @code{noinst_HEADERS}.  This is clearer for
7175 the @file{Makefile.am} reader.  @code{noinst_HEADERS} would be the
7176 right variable to use in a directory containing only headers and no
7177 associated library or program.
7178
7179 All header files must be listed somewhere; in a @code{_SOURCES}
7180 variable or in a @code{_HEADERS} variable.  Missing ones will not
7181 appear in the distribution.
7182
7183 For header files that are built and must not be distributed, use the
7184 @code{nodist_} prefix as in @code{nodist_include_HEADERS} or
7185 @code{nodist_prog_SOURCES}.  If these generated headers are needed
7186 during the build, you must also ensure they exist before they are
7187 used (@pxref{Sources}).
7188
7189
7190 @node Data
7191 @section Architecture-independent data files
7192
7193 @cindex @code{_DATA} primary, defined
7194 @cindex @code{DATA} primary, defined
7195 @cindex Primary variable, @code{DATA}
7196 @vindex _DATA
7197
7198 Automake supports the installation of miscellaneous data files using the
7199 @code{DATA} family of variables.
7200 @vindex DATA
7201
7202 @vindex data_DATA
7203 @vindex sysconf_DATA
7204 @vindex sharedstate_DATA
7205 @vindex localstate_DATA
7206 @vindex pkgdata_DATA
7207
7208 Such data can be installed in the directories @code{datadir},
7209 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
7210 @code{pkgdatadir}.
7211
7212 By default, data files are @emph{not} included in a distribution.  Of
7213 course, you can use the @code{dist_} prefix to change this on a
7214 per-variable basis.
7215
7216 Here is how Automake declares its auxiliary data files:
7217
7218 @example
7219 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
7220 @end example
7221
7222
7223 @node Sources
7224 @section Built Sources
7225
7226 Because Automake's automatic dependency tracking works as a side-effect
7227 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
7228 target should not be compiled before its dependencies are made, but
7229 these dependencies are unknown until the target is first compiled.
7230
7231 Ordinarily this is not a problem, because dependencies are distributed
7232 sources: they preexist and do not need to be built.  Suppose that
7233 @file{foo.c} includes @file{foo.h}.  When it first compiles
7234 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
7235 @file{foo.c}.  As a side-effect of this compilation @command{depcomp}
7236 records the @file{foo.h} dependency so that following invocations of
7237 @command{make} will honor it.  In these conditions, it's clear there is
7238 no problem: either @file{foo.o} doesn't exist and has to be built
7239 (regardless of the dependencies), or accurate dependencies exist and
7240 they can be used to decide whether @file{foo.o} should be rebuilt.
7241
7242 It's a different story if @file{foo.h} doesn't exist by the first
7243 @command{make} run.  For instance, there might be a rule to build
7244 @file{foo.h}.  This time @file{file.o}'s build will fail because the
7245 compiler can't find @file{foo.h}.  @command{make} failed to trigger the
7246 rule to build @file{foo.h} first by lack of dependency information.
7247
7248 @vindex BUILT_SOURCES
7249 @cindex @code{BUILT_SOURCES}, defined
7250
7251 The @code{BUILT_SOURCES} variable is a workaround for this problem.  A
7252 source file listed in @code{BUILT_SOURCES} is made on @samp{make all}
7253 or @samp{make check} (or even @samp{make install}) before other
7254 targets are processed.  However, such a source file is not
7255 @emph{compiled} unless explicitly requested by mentioning it in some
7256 other @code{_SOURCES} variable.
7257
7258 So, to conclude our introductory example, we could use
7259 @samp{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
7260 any other target (including @file{foo.o}) during @samp{make all} or
7261 @samp{make check}.
7262
7263 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
7264 must be created early in the build process can be listed in this
7265 variable.  Moreover, all built sources do not necessarily have to be
7266 listed in @code{BUILT_SOURCES}.  For instance, a generated @file{.c} file
7267 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
7268 another source), because it's a known dependency of the associated
7269 object.
7270
7271 It might be important to emphasize that @code{BUILT_SOURCES} is
7272 honored only by @samp{make all}, @samp{make check} and @samp{make
7273 install}.  This means you cannot build a specific target (e.g.,
7274 @samp{make foo}) in a clean tree if it depends on a built source.
7275 However it will succeed if you have run @samp{make all} earlier,
7276 because accurate dependencies are already available.
7277
7278 The next section illustrates and discusses the handling of built sources
7279 on a toy example.
7280
7281 @menu
7282 * Built Sources Example::       Several ways to handle built sources.
7283 @end menu
7284
7285 @node Built Sources Example
7286 @subsection Built Sources Example
7287
7288 Suppose that @file{foo.c} includes @file{bindir.h}, which is
7289 installation-dependent and not distributed: it needs to be built.  Here
7290 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
7291 value of the @command{make} variable @code{bindir} (inherited from
7292 @file{configure}).
7293
7294 We suggest several implementations below.  It's not meant to be an
7295 exhaustive listing of all ways to handle built sources, but it will give
7296 you a few ideas if you encounter this issue.
7297
7298 @subsubheading First Try
7299
7300 This first implementation will illustrate the bootstrap issue mentioned
7301 in the previous section (@pxref{Sources}).
7302
7303 Here is a tentative @file{Makefile.am}.
7304
7305 @example
7306 # This won't work.
7307 bin_PROGRAMS = foo
7308 foo_SOURCES = foo.c
7309 nodist_foo_SOURCES = bindir.h
7310 CLEANFILES = bindir.h
7311 bindir.h: Makefile
7312         echo '#define bindir "$(bindir)"' >$@@
7313 @end example
7314
7315 This setup doesn't work, because Automake doesn't know that @file{foo.c}
7316 includes @file{bindir.h}.  Remember, automatic dependency tracking works
7317 as a side-effect of compilation, so the dependencies of @file{foo.o} will
7318 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
7319 The symptom is as follows.
7320
7321 @example
7322 % make
7323 source='foo.c' object='foo.o' libtool=no \
7324 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7325 depmode=gcc /bin/sh ./depcomp \
7326 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7327 foo.c:2: bindir.h: No such file or directory
7328 make: *** [foo.o] Error 1
7329 @end example
7330
7331 In this example @file{bindir.h} is not distributed nor installed, and
7332 it is not even being built on-time.  One may wonder if the
7333 @samp{nodist_foo_SOURCES = bindir.h} line has any use at all.  This
7334 line simply states that @file{bindir.h} is a source of @code{foo}, so
7335 for instance, it should be inspected while generating tags
7336 (@pxref{Tags}).  In other words, it does not help our present problem,
7337 and the build would fail identically without it.
7338
7339 @subsubheading Using @code{BUILT_SOURCES}
7340
7341 A solution is to require @file{bindir.h} to be built before anything
7342 else.  This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
7343
7344 @example
7345 bin_PROGRAMS = foo
7346 foo_SOURCES = foo.c
7347 nodist_foo_SOURCES = bindir.h
7348 BUILT_SOURCES = bindir.h
7349 CLEANFILES = bindir.h
7350 bindir.h: Makefile
7351         echo '#define bindir "$(bindir)"' >$@@
7352 @end example
7353
7354 See how @file{bindir.h} gets built first:
7355
7356 @example
7357 % make
7358 echo '#define bindir "/usr/local/bin"' >bindir.h
7359 make  all-am
7360 make[1]: Entering directory `/home/adl/tmp'
7361 source='foo.c' object='foo.o' libtool=no \
7362 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7363 depmode=gcc /bin/sh ./depcomp \
7364 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7365 gcc  -g -O2   -o foo  foo.o
7366 make[1]: Leaving directory `/home/adl/tmp'
7367 @end example
7368
7369 However, as said earlier, @code{BUILT_SOURCES} applies only to the
7370 @code{all}, @code{check}, and @code{install} targets.  It still fails
7371 if you try to run @samp{make foo} explicitly:
7372
7373 @example
7374 % make clean
7375 test -z "bindir.h" || rm -f bindir.h
7376 test -z "foo" || rm -f foo
7377 rm -f *.o
7378 % : > .deps/foo.Po # Suppress previously recorded dependencies
7379 % make foo
7380 source='foo.c' object='foo.o' libtool=no \
7381 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7382 depmode=gcc /bin/sh ./depcomp \
7383 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7384 foo.c:2: bindir.h: No such file or directory
7385 make: *** [foo.o] Error 1
7386 @end example
7387
7388 @subsubheading Recording Dependencies manually
7389
7390 Usually people are happy enough with @code{BUILT_SOURCES} because they
7391 never build targets such as @samp{make foo} before @samp{make all}, as
7392 in the previous example.  However if this matters to you, you can
7393 avoid @code{BUILT_SOURCES} and record such dependencies explicitly in
7394 the @file{Makefile.am}.
7395
7396 @example
7397 bin_PROGRAMS = foo
7398 foo_SOURCES = foo.c
7399 nodist_foo_SOURCES = bindir.h
7400 foo.$(OBJEXT): bindir.h
7401 CLEANFILES = bindir.h
7402 bindir.h: Makefile
7403         echo '#define bindir "$(bindir)"' >$@@
7404 @end example
7405
7406 You don't have to list @emph{all} the dependencies of @file{foo.o}
7407 explicitly, only those that might need to be built.  If a dependency
7408 already exists, it will not hinder the first compilation and will be
7409 recorded by the normal dependency tracking code.  (Note that after
7410 this first compilation the dependency tracking code will also have
7411 recorded the dependency between @file{foo.o} and
7412 @file{bindir.h}; so our explicit dependency is really useful to
7413 the first build only.)
7414
7415 Adding explicit dependencies like this can be a bit dangerous if you are
7416 not careful enough.  This is due to the way Automake tries not to
7417 overwrite your rules (it assumes you know better than it).
7418 @samp{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
7419 output to build @samp{foo.$(OBJEXT)}.  It happens to work in this case
7420 because Automake doesn't have to output any @samp{foo.$(OBJEXT):}
7421 target: it relies on a suffix rule instead (i.e., @samp{.c.$(OBJEXT):}).
7422 Always check the generated @file{Makefile.in} if you do this.
7423
7424 @subsubheading Build @file{bindir.h} from @file{configure}
7425
7426 It's possible to define this preprocessor macro from @file{configure},
7427 either in @file{config.h} (@pxref{Defining Directories, , Defining
7428 Directories, autoconf, The Autoconf Manual}), or by processing a
7429 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
7430 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
7431 Autoconf Manual}).
7432
7433 At this point it should be clear that building @file{bindir.h} from
7434 @file{configure} works well for this example.  @file{bindir.h} will exist
7435 before you build any target, hence will not cause any dependency issue.
7436
7437 The Makefile can be shrunk as follows.  We do not even have to mention
7438 @file{bindir.h}.
7439
7440 @example
7441 bin_PROGRAMS = foo
7442 foo_SOURCES = foo.c
7443 @end example
7444
7445 However, it's not always possible to build sources from
7446 @file{configure}, especially when these sources are generated by a tool
7447 that needs to be built first.
7448
7449 @subsubheading Build @file{bindir.c}, not @file{bindir.h}.
7450
7451 Another attractive idea is to define @code{bindir} as a variable or
7452 function exported from @file{bindir.o}, and build @file{bindir.c}
7453 instead of @file{bindir.h}.
7454
7455 @example
7456 noinst_PROGRAMS = foo
7457 foo_SOURCES = foo.c bindir.h
7458 nodist_foo_SOURCES = bindir.c
7459 CLEANFILES = bindir.c
7460 bindir.c: Makefile
7461         echo 'const char bindir[] = "$(bindir)";' >$@@
7462 @end example
7463
7464 @file{bindir.h} contains just the variable's declaration and doesn't
7465 need to be built, so it won't cause any trouble.  @file{bindir.o} is
7466 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
7467 first.
7468
7469 @subsubheading Which is best?
7470
7471 There is no panacea, of course.  Each solution has its merits and
7472 drawbacks.
7473
7474 You cannot use @code{BUILT_SOURCES} if the ability to run @samp{make
7475 foo} on a clean tree is important to you.
7476
7477 You won't add explicit dependencies if you are leery of overriding
7478 an Automake rule by mistake.
7479
7480 Building files from @file{./configure} is not always possible, neither
7481 is converting @file{.h} files into @file{.c} files.
7482
7483
7484 @node Other GNU Tools
7485 @chapter Other GNU Tools
7486
7487 Since Automake is primarily intended to generate @file{Makefile.in}s for
7488 use in GNU programs, it tries hard to interoperate with other GNU tools.
7489
7490 @menu
7491 * Emacs Lisp::                  Emacs Lisp
7492 * gettext::                     Gettext
7493 * Libtool::                     Libtool
7494 * Java::                        Java bytecode compilation (deprecated)
7495 * Python::                      Python
7496 @end menu
7497
7498
7499 @node Emacs Lisp
7500 @section Emacs Lisp
7501
7502 @cindex @code{_LISP} primary, defined
7503 @cindex @code{LISP} primary, defined
7504 @cindex Primary variable, @code{LISP}
7505
7506 @vindex _LISP
7507 @vindex lisp_LISP
7508 @vindex noinst_LISP
7509
7510 Automake provides some support for Emacs Lisp.  The @code{LISP} primary
7511 is used to hold a list of @file{.el} files.  Possible prefixes for this
7512 primary are @code{lisp_} and @code{noinst_}.  Note that if
7513 @code{lisp_LISP} is defined, then @file{configure.ac} must run
7514 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
7515
7516 @vindex dist_lisp_LISP
7517 @vindex dist_noinst_LISP
7518 Lisp sources are not distributed by default.  You can prefix the
7519 @code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
7520 @code{dist_noinst_LISP}, to indicate that these files should be
7521 distributed.
7522
7523 Automake will byte-compile all Emacs Lisp source files using the Emacs
7524 found by @code{AM_PATH_LISPDIR}, if any was found.  When performing such
7525 byte-compilation, the flags specified in the (developer-reserved)
7526 @code{AM_ELCFLAGS} and (user-reserved) @code{ELCFLAGS} make variables
7527 will be passed to the Emacs invocation.
7528
7529 Byte-compiled Emacs Lisp files are not portable among all versions of
7530 Emacs, so it makes sense to turn this off if you expect sites to have
7531 more than one version of Emacs installed.  Furthermore, many packages
7532 don't actually benefit from byte-compilation.  Still, we recommend
7533 that you byte-compile your Emacs Lisp sources.  It is probably better
7534 for sites with strange setups to cope for themselves than to make the
7535 installation less nice for everybody else.
7536
7537 There are two ways to avoid byte-compiling.  Historically, we have
7538 recommended the following construct.
7539
7540 @example
7541 lisp_LISP = file1.el file2.el
7542 ELCFILES =
7543 @end example
7544
7545 @noindent
7546 @code{ELCFILES} is an internal Automake variable that normally lists
7547 all @file{.elc} files that must be byte-compiled.  Automake defines
7548 @code{ELCFILES} automatically from @code{lisp_LISP}.  Emptying this
7549 variable explicitly prevents byte-compilation.
7550
7551 Since Automake 1.8, we now recommend using @code{lisp_DATA} instead:
7552
7553 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7554 @example
7555 lisp_DATA = file1.el file2.el
7556 @end example
7557
7558 Note that these two constructs are not equivalent.  @code{_LISP} will
7559 not install a file if Emacs is not installed, while @code{_DATA} will
7560 always install its files.
7561
7562 @node gettext
7563 @section Gettext
7564
7565 @cindex GNU Gettext support
7566 @cindex Gettext support
7567 @cindex Support for GNU Gettext
7568
7569 If @code{AM_GNU_GETTEXT} is seen in @file{configure.ac}, then Automake
7570 turns on support for GNU gettext, a message catalog system for
7571 internationalization
7572 (@pxref{Top, , Introduction, gettext, GNU gettext utilities}).
7573
7574 The @code{gettext} support in Automake requires the addition of one or
7575 two subdirectories to the package: @file{po} and possibly also @file{intl}.
7576 The latter is needed if @code{AM_GNU_GETTEXT} is not invoked with the
7577 @samp{external} argument, or if @code{AM_GNU_GETTEXT_INTL_SUBDIR} is used.
7578 Automake ensures that these directories exist and are mentioned in
7579 @code{SUBDIRS}.
7580
7581 @node Libtool
7582 @section Libtool
7583
7584 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
7585 libtool, The Libtool Manual}) with the @code{LTLIBRARIES} primary.
7586 @xref{A Shared Library}.
7587
7588
7589 @node Java
7590 @section Java bytecode compilation (deprecated)
7591
7592 @cindex @code{_JAVA} primary, defined
7593 @cindex @code{JAVA} primary, defined
7594 @cindex Primary variable, @code{JAVA}
7595 @cindex Java to bytecode, compilation
7596 @cindex Compilation of Java to bytecode
7597
7598 Automake provides some minimal support for Java bytecode compilation with
7599 the @code{JAVA} primary (in addition to the support for compiling Java to
7600 native machine code; @pxref{Java Support with gcj}).  Note however that
7601 @emph{the interface and most features described here are deprecated}.
7602 Future Automake releases will strive to provide a better and cleaner
7603 interface, which however @emph{won't be backward-compatible}; the present
7604 interface will probably be removed altogether some time after the
7605 introduction of the new interface (if that ever materializes).
7606
7607 Any @file{.java} files listed in a @code{_JAVA} variable will be
7608 compiled with @code{JAVAC} at build time.  By default, @file{.java}
7609 files are not included in the distribution, you should use the
7610 @code{dist_} prefix to distribute them.
7611
7612 Here is a typical setup for distributing @file{.java} files and
7613 installing the @file{.class} files resulting from their compilation.
7614
7615 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7616 @example
7617 javadir = $(datadir)/java
7618 dist_java_JAVA = a.java b.java @dots{}
7619 @end example
7620
7621 @cindex @code{JAVA} restrictions
7622 @cindex Restrictions for @code{JAVA}
7623
7624 Currently Automake enforces the restriction that only one @code{_JAVA}
7625 primary can be used in a given @file{Makefile.am}.  The reason for this
7626 restriction is that, in general, it isn't possible to know which
7627 @file{.class} files were generated from which @file{.java} files, so
7628 it would be impossible to know which files to install where.  For
7629 instance, a @file{.java} file can define multiple classes; the resulting
7630 @file{.class} file names cannot be predicted without parsing the
7631 @file{.java} file.
7632
7633 There are a few variables that are used when compiling Java sources:
7634
7635 @vtable @code
7636 @item JAVAC
7637 The name of the Java compiler.  This defaults to @samp{javac}.
7638
7639 @item JAVACFLAGS
7640 The flags to pass to the compiler.  This is considered to be a user
7641 variable (@pxref{User Variables}).
7642
7643 @item AM_JAVACFLAGS
7644 More flags to pass to the Java compiler.  This, and not
7645 @code{JAVACFLAGS}, should be used when it is necessary to put Java
7646 compiler flags into @file{Makefile.am}.
7647
7648 @item JAVAROOT
7649 The value of this variable is passed to the @option{-d} option to
7650 @code{javac}.  It defaults to @samp{$(top_builddir)}.
7651
7652 @item CLASSPATH_ENV
7653 This variable is a shell expression that is used to set the
7654 @env{CLASSPATH} environment variable on the @code{javac} command line.
7655 (In the future we will probably handle class path setting differently.)
7656 @end vtable
7657
7658
7659 @node Python
7660 @section Python
7661
7662 @cindex @code{_PYTHON} primary, defined
7663 @cindex @code{PYTHON} primary, defined
7664 @cindex Primary variable, @code{PYTHON}
7665 @vindex _PYTHON
7666
7667 Automake provides support for Python compilation with the
7668 @code{PYTHON} primary.  A typical setup is to call
7669 @code{AM_PATH_PYTHON} in @file{configure.ac} and use a line like the
7670 following in @file{Makefile.am}:
7671
7672 @example
7673 python_PYTHON = tree.py leave.py
7674 @end example
7675
7676 Any files listed in a @code{_PYTHON} variable will be byte-compiled
7677 with @command{py-compile} at install time.  @command{py-compile}
7678 actually creates both standard (@file{.pyc}) and optimized
7679 (@file{.pyo}) byte-compiled versions of the source files.  Note that
7680 because byte-compilation occurs at install time, any files listed in
7681 @code{noinst_PYTHON} will not be compiled.  Python source files are
7682 included in the distribution by default, prepend @code{nodist_} (as in
7683 @code{nodist_python_PYTHON}) to omit them.
7684
7685 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON}
7686 that will determine some Python-related directory variables (see
7687 below).  If you have called @code{AM_PATH_PYTHON} from
7688 @file{configure.ac}, then you may use the variables
7689 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7690 @code{python_PYTHON} or @code{pkgpython_PYTHON} to list Python source
7691 files in your @file{Makefile.am}, depending on where you want your files
7692 installed (see the definitions of @code{pythondir} and
7693 @code{pkgpythondir} below).
7694
7695 @defmac AM_PATH_PYTHON (@ovar{version}, @ovar{action-if-found},
7696   @ovar{action-if-not-found})
7697
7698 Search for a Python interpreter on the system.  This macro takes three
7699 optional arguments.  The first argument, if present, is the minimum
7700 version of Python required for this package: @code{AM_PATH_PYTHON}
7701 will skip any Python interpreter that is older than @var{version}.
7702 If an interpreter is found and satisfies @var{version}, then
7703 @var{action-if-found} is run.  Otherwise, @var{action-if-not-found} is
7704 run.
7705
7706 If @var{action-if-not-found} is not specified, as in the following
7707 example, the default is to abort @command{configure}.
7708
7709 @example
7710 AM_PATH_PYTHON([2.2])
7711 @end example
7712
7713 @noindent
7714 This is fine when Python is an absolute requirement for the package.
7715 If Python >= 2.5 was only @emph{optional} to the package,
7716 @code{AM_PATH_PYTHON} could be called as follows.
7717
7718 @example
7719 AM_PATH_PYTHON([2.5],, [:])
7720 @end example
7721
7722 If the @env{PYTHON} variable is set when @code{AM_PATH_PYTHON} is
7723 called, then that will be the only Python interpreter that is tried.
7724
7725 @code{AM_PATH_PYTHON} creates the following output variables based on
7726 the Python installation found during configuration.
7727 @end defmac
7728
7729 @vtable @code
7730 @item PYTHON
7731 The name of the Python executable, or @samp{:} if no suitable
7732 interpreter could be found.
7733
7734 Assuming @var{action-if-not-found} is used (otherwise @file{./configure}
7735 will abort if Python is absent), the value of @code{PYTHON} can be used
7736 to setup a conditional in order to disable the relevant part of a build
7737 as follows.
7738
7739 @example
7740 AM_PATH_PYTHON(,, [:])
7741 AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
7742 @end example
7743
7744 @item PYTHON_VERSION
7745 The Python version number, in the form @var{major}.@var{minor}
7746 (e.g., @samp{2.5}).  This is currently the value of
7747 @samp{sys.version[:3]}.
7748
7749 @item PYTHON_PREFIX
7750 The string @samp{$@{prefix@}}.  This term may be used in future work
7751 that needs the contents of Python's @samp{sys.prefix}, but general
7752 consensus is to always use the value from @command{configure}.
7753
7754 @item PYTHON_EXEC_PREFIX
7755 The string @samp{$@{exec_prefix@}}.  This term may be used in future work
7756 that needs the contents of Python's @samp{sys.exec_prefix}, but general
7757 consensus is to always use the value from @command{configure}.
7758
7759 @item PYTHON_PLATFORM
7760 The canonical name used by Python to describe the operating system, as
7761 given by @samp{sys.platform}.  This value is sometimes needed when
7762 building Python extensions.
7763
7764 @item pythondir
7765 The directory name for the @file{site-packages} subdirectory of the
7766 standard Python install tree.
7767
7768 @item pkgpythondir
7769 This is the directory under @code{pythondir} that is named after the
7770 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
7771 as a convenience.
7772
7773 @item pyexecdir
7774 This is the directory where Python extension modules (shared libraries)
7775 should be installed.  An extension module written in C could be declared
7776 as follows to Automake:
7777
7778 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7779 @example
7780 pyexec_LTLIBRARIES = quaternion.la
7781 quaternion_la_SOURCES = quaternion.c support.c support.h
7782 quaternion_la_LDFLAGS = -avoid-version -module
7783 @end example
7784
7785 @item pkgpyexecdir
7786 This is a convenience variable that is defined as
7787 @samp{$(pyexecdir)/$(PACKAGE)}.
7788 @end vtable
7789
7790 All of these directory variables have values that start with either
7791 @samp{$@{prefix@}} or @samp{$@{exec_prefix@}} unexpanded.  This works
7792 fine in @file{Makefiles}, but it makes these variables hard to use in
7793 @file{configure}.  This is mandated by the GNU coding standards, so
7794 that the user can run @samp{make prefix=/foo install}.  The Autoconf
7795 manual has a section with more details on this topic
7796 (@pxref{Installation Directory Variables, , Installation Directory
7797 Variables, autoconf, The Autoconf Manual}).  See also @ref{Hard-Coded
7798 Install Paths}.
7799
7800
7801 @node Documentation
7802 @chapter Building documentation
7803
7804 Currently Automake provides support for Texinfo and man pages.
7805
7806 @menu
7807 * Texinfo::                     Texinfo
7808 * Man Pages::                   Man pages
7809 @end menu
7810
7811
7812 @node Texinfo
7813 @section Texinfo
7814
7815 @cindex @code{_TEXINFOS} primary, defined
7816 @cindex @code{TEXINFOS} primary, defined
7817 @cindex Primary variable, @code{TEXINFOS}
7818 @cindex HTML output using Texinfo
7819 @cindex PDF output using Texinfo
7820 @cindex PS output using Texinfo
7821 @cindex DVI output using Texinfo
7822 @vindex _TEXINFOS
7823 @vindex info_TEXINFOS
7824
7825 If the current directory contains Texinfo source, you must declare it
7826 with the @code{TEXINFOS} primary.  Generally Texinfo files are converted
7827 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
7828 here.  Any Texinfo source file should have the @file{.texi} extension.
7829 Automake also accepts @file{.txi} or @file{.texinfo} extensions, but their
7830 use is discouraged now, and will elicit runtime warnings.
7831
7832 Automake generates rules to build @file{.info}, @file{.dvi},
7833 @file{.ps}, @file{.pdf} and @file{.html} files from your Texinfo
7834 sources.  Following the GNU Coding Standards, only the @file{.info}
7835 files are built by @samp{make all} and installed by @samp{make
7836 install} (unless you use @option{no-installinfo}, see below).
7837 Furthermore, @file{.info} files are automatically distributed so that
7838 Texinfo is not a prerequisite for installing your package.
7839
7840 @trindex dvi
7841 @trindex html
7842 @trindex pdf
7843 @trindex ps
7844 @trindex install-dvi
7845 @trindex install-html
7846 @trindex install-pdf
7847 @trindex install-ps
7848 Other documentation formats can be built on request by @samp{make
7849 dvi}, @samp{make ps}, @samp{make pdf} and @samp{make html}, and they
7850 can be installed with @samp{make install-dvi}, @samp{make install-ps},
7851 @samp{make install-pdf} and @samp{make install-html} explicitly.
7852 @samp{make uninstall} will remove everything: the Texinfo
7853 documentation installed by default as well as all the above optional
7854 formats.
7855
7856 All of these targets can be extended using @samp{-local} rules
7857 (@pxref{Extending}).
7858
7859 @cindex Texinfo flag, @code{VERSION}
7860 @cindex Texinfo flag, @code{UPDATED}
7861 @cindex Texinfo flag, @code{EDITION}
7862 @cindex Texinfo flag, @code{UPDATED-MONTH}
7863
7864 @cindex @code{VERSION} Texinfo flag
7865 @cindex @code{UPDATED} Texinfo flag
7866 @cindex @code{EDITION} Texinfo flag
7867 @cindex @code{UPDATED-MONTH} Texinfo flag
7868
7869 @cindex @file{mdate-sh}
7870
7871 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
7872 that file will be automatically generated.  The file @file{version.texi}
7873 defines four Texinfo flag you can reference using
7874 @code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
7875 @code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
7876
7877 @table @code
7878 @item EDITION
7879 @itemx VERSION
7880 Both of these flags hold the version number of your program.  They are
7881 kept separate for clarity.
7882
7883 @item UPDATED
7884 This holds the date the primary @file{.texi} file was last modified.
7885
7886 @item UPDATED-MONTH
7887 This holds the name of the month in which the primary @file{.texi} file
7888 was last modified.
7889 @end table
7890
7891 The @file{version.texi} support requires the @command{mdate-sh}
7892 script; this script is supplied with Automake and automatically
7893 included when @command{automake} is invoked with the
7894 @option{--add-missing} option.
7895
7896 If you have multiple Texinfo files, and you want to use the
7897 @file{version.texi} feature, then you have to have a separate version
7898 file for each Texinfo file.  Automake will treat any include in a
7899 Texinfo file that matches @file{vers*.texi} just as an automatically
7900 generated version file.
7901
7902 Sometimes an info file actually depends on more than one @file{.texi}
7903 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
7904 @file{fdl.texi}.  You can tell Automake about these dependencies using
7905 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
7906 @vindex TEXINFOS
7907 @vindex _TEXINFOS
7908
7909 @example
7910 info_TEXINFOS = hello.texi
7911 hello_TEXINFOS = fdl.texi
7912 @end example
7913
7914 @cindex @file{texinfo.tex}
7915
7916 By default, Automake requires the file @file{texinfo.tex} to appear in
7917 the same directory as the @file{Makefile.am} file that lists the
7918 @file{.texi} files.  If you used @code{AC_CONFIG_AUX_DIR} in
7919 @file{configure.ac} (@pxref{Input, , Finding `configure' Input,
7920 autoconf, The Autoconf Manual}), then @file{texinfo.tex} is looked for
7921 there.  In both cases, @command{automake} then supplies @file{texinfo.tex} if
7922 @option{--add-missing} is given, and takes care of its distribution.
7923 However, if you set the @code{TEXINFO_TEX} variable (see below),
7924 it overrides the location of the file and turns off its installation
7925 into the source as well as its distribution.
7926
7927 The option @option{no-texinfo.tex} can be used to eliminate the
7928 requirement for the file @file{texinfo.tex}.  Use of the variable
7929 @code{TEXINFO_TEX} is preferable, however, because that allows the
7930 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
7931
7932 @cindex Option, @code{no-installinfo}
7933 @cindex Target, @code{install-info}
7934 @cindex @code{install-info} target
7935 @cindex @code{no-installinfo} option
7936
7937 @opindex no-installinfo
7938 @trindex install-info
7939
7940 Automake generates an @code{install-info} rule; some people apparently
7941 use this.  By default, info pages are installed by @samp{make
7942 install}, so running @code{make install-info} is pointless.  This can
7943 be prevented via the @code{no-installinfo} option.  In this case,
7944 @file{.info} files are not installed by default, and user must
7945 request this explicitly using @samp{make install-info}.
7946
7947 @vindex AM_UPDATE_INFO_DIR
7948 By default, @code{make install-info} and @code{make uninstall-info}
7949 will try to run the @command{install-info} program (if available) to
7950 update (or create/remove) the @file{@code{$@{infodir@}}/dir} index.
7951 If this is undesired, it can be prevented by exporting the
7952 @code{AM_UPDATE_INFO_DIR} variable to "@code{no}".
7953
7954 The following variables are used by the Texinfo build rules.
7955
7956 @vtable @code
7957 @item MAKEINFO
7958 The name of the program invoked to build @file{.info} files.  This
7959 variable is defined by Automake.  If the @command{makeinfo} program is
7960 found on the system then it will be used by default; otherwise
7961 @command{missing} will be used instead.
7962
7963 @item MAKEINFOHTML
7964 The command invoked to build @file{.html} files.  Automake
7965 defines this to @samp{$(MAKEINFO) --html}.
7966
7967 @item MAKEINFOFLAGS
7968 User flags passed to each invocation of @samp{$(MAKEINFO)} and
7969 @samp{$(MAKEINFOHTML)}.  This user variable (@pxref{User Variables}) is
7970 not expected to be defined in any @file{Makefile}; it can be used by
7971 users to pass extra flags to suit their needs.
7972
7973 @item AM_MAKEINFOFLAGS
7974 @itemx AM_MAKEINFOHTMLFLAGS
7975 Maintainer flags passed to each @command{makeinfo} invocation.  Unlike
7976 @code{MAKEINFOFLAGS}, these variables are meant to be defined by
7977 maintainers in @file{Makefile.am}.  @samp{$(AM_MAKEINFOFLAGS)} is
7978 passed to @code{makeinfo} when building @file{.info} files; and
7979 @samp{$(AM_MAKEINFOHTMLFLAGS)} is used when building @file{.html}
7980 files.
7981
7982 @c Keep in sync with txinfo-many-output-formats.sh
7983 For instance, the following setting can be used to obtain one single
7984 @file{.html} file per manual, without node separators.
7985 @example
7986 AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
7987 @end example
7988
7989 @code{AM_MAKEINFOHTMLFLAGS} defaults to @samp{$(AM_MAKEINFOFLAGS)}.
7990 This means that defining @code{AM_MAKEINFOFLAGS} without defining
7991 @code{AM_MAKEINFOHTMLFLAGS} will impact builds of both @file{.info}
7992 and @file{.html} files.
7993
7994 @item TEXI2DVI
7995 The name of the command that converts a @file{.texi} file into a
7996 @file{.dvi} file.  This defaults to @samp{texi2dvi}, a script that ships
7997 with the Texinfo package.
7998
7999 @item TEXI2PDF
8000 The name of the command that translates a @file{.texi} file into a
8001 @file{.pdf} file.  This defaults to @samp{$(TEXI2DVI) --pdf --batch}.
8002
8003 @item DVIPS
8004 The name of the command that builds a @file{.ps} file out of a
8005 @file{.dvi} file.  This defaults to @samp{dvips}.
8006
8007 @item TEXINFO_TEX
8008
8009 If your package has Texinfo files in many directories, you can use the
8010 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
8011 @file{texinfo.tex} for your package.  The value of this variable should
8012 be the relative path from the current @file{Makefile.am} to
8013 @file{texinfo.tex}:
8014
8015 @example
8016 TEXINFO_TEX = ../doc/texinfo.tex
8017 @end example
8018 @end vtable
8019
8020
8021 @node Man Pages
8022 @section Man Pages
8023
8024 @cindex @code{_MANS} primary, defined
8025 @cindex @code{MANS} primary, defined
8026 @cindex Primary variable, @code{MANS}
8027
8028 @vindex _MANS
8029 @vindex man_MANS
8030 A package can also include man pages (but see the GNU standards on this
8031 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
8032 pages are declared using the @code{MANS} primary.  Generally the
8033 @code{man_MANS} variable is used.  Man pages are automatically installed in
8034 the correct subdirectory of @code{mandir}, based on the file extension.
8035
8036 File extensions such as @file{.1c} are handled by looking for the valid
8037 part of the extension and using that to determine the correct
8038 subdirectory of @code{mandir}.  Valid section names are the digits
8039 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
8040
8041 Sometimes developers prefer to name a man page something like
8042 @file{foo.man} in the source, and then rename it to have the correct
8043 suffix, for example @file{foo.1}, when installing the file.  Automake
8044 also supports this mode.  For a valid section named @var{section},
8045 there is a corresponding directory named @samp{man@var{section}dir},
8046 and a corresponding @code{_MANS} variable.  Files listed in such a
8047 variable are installed in the indicated section.  If the file already
8048 has a valid suffix, then it is installed as-is; otherwise the file
8049 suffix is changed to match the section.
8050
8051 For instance, consider this example:
8052 @example
8053 man1_MANS = rename.man thesame.1 alsothesame.1c
8054 @end example
8055
8056 @noindent
8057 In this case, @file{rename.man} will be renamed to @file{rename.1} when
8058 installed, but the other files will keep their names.
8059
8060 @cindex Target, @code{install-man}
8061 @cindex Option, @option{no-installman}
8062 @cindex @code{install-man} target
8063 @cindex @option{no-installman} option
8064 @opindex no-installman
8065 @trindex install-man
8066
8067 By default, man pages are installed by @samp{make install}.  However,
8068 since the GNU project does not require man pages, many maintainers do
8069 not expend effort to keep the man pages up to date.  In these cases, the
8070 @option{no-installman} option will prevent the man pages from being
8071 installed by default.  The user can still explicitly install them via
8072 @samp{make install-man}.
8073
8074 For fast installation, with many files it is preferable to use
8075 @samp{man@var{section}_MANS} over @samp{man_MANS} as well as files that
8076 do not need to be renamed.
8077
8078 Man pages are not currently considered to be source, because it is not
8079 uncommon for man pages to be automatically generated.  Therefore they
8080 are not automatically included in the distribution.  However, this can
8081 be changed by use of the @code{dist_} prefix.  For instance here is
8082 how to distribute and install the two man pages of GNU @command{cpio}
8083 (which includes both Texinfo documentation and man pages):
8084
8085 @example
8086 dist_man_MANS = cpio.1 mt.1
8087 @end example
8088
8089 The @code{nobase_} prefix is meaningless for man pages and is
8090 disallowed.
8091
8092 @vindex notrans_
8093 @cindex @code{notrans_} prefix
8094 @cindex Man page renaming, avoiding
8095 @cindex Avoiding man page renaming
8096
8097 Executables and manpages may be renamed upon installation
8098 (@pxref{Renaming}).  For manpages this can be avoided by use of the
8099 @code{notrans_} prefix.  For instance, suppose an executable @samp{foo}
8100 allowing to access a library function @samp{foo} from the command line.
8101 The way to avoid renaming of the @file{foo.3} manpage is:
8102
8103 @example
8104 man_MANS = foo.1
8105 notrans_man_MANS = foo.3
8106 @end example
8107
8108 @cindex @code{notrans_} and @code{dist_} or @code{nodist_}
8109 @cindex @code{dist_} and @code{notrans_}
8110 @cindex @code{nodist_} and @code{notrans_}
8111
8112 @samp{notrans_} must be specified first when used in conjunction with
8113 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
8114 Control}).  For instance:
8115
8116 @example
8117 notrans_dist_man3_MANS = bar.3
8118 @end example
8119
8120 @node Install
8121 @chapter What Gets Installed
8122
8123 @cindex Installation support
8124 @cindex @samp{make install} support
8125
8126 Naturally, Automake handles the details of actually installing your
8127 program once it has been built.  All files named by the various
8128 primaries are automatically installed in the appropriate places when the
8129 user runs @samp{make install}.
8130
8131 @menu
8132 * Basics of Installation::      What gets installed where
8133 * The Two Parts of Install::    Installing data and programs separately
8134 * Extending Installation::      Adding your own rules for installation
8135 * Staged Installs::             Installation in a temporary location
8136 * Install Rules for the User::  Useful additional rules
8137 @end menu
8138
8139 @node Basics of Installation
8140 @section Basics of Installation
8141
8142 A file named in a primary is installed by copying the built file into
8143 the appropriate directory.  The base name of the file is used when
8144 installing.
8145
8146 @example
8147 bin_PROGRAMS = hello subdir/goodbye
8148 @end example
8149
8150 In this example, both @samp{hello} and @samp{goodbye} will be installed
8151 in @samp{$(bindir)}.
8152
8153 Sometimes it is useful to avoid the basename step at install time.  For
8154 instance, you might have a number of header files in subdirectories of
8155 the source tree that are laid out precisely how you want to install
8156 them.  In this situation you can use the @code{nobase_} prefix to
8157 suppress the base name step.  For example:
8158
8159 @example
8160 nobase_include_HEADERS = stdio.h sys/types.h
8161 @end example
8162
8163 @noindent
8164 will install @file{stdio.h} in @samp{$(includedir)} and @file{types.h}
8165 in @samp{$(includedir)/sys}.
8166
8167 For most file types, Automake will install multiple files at once, while
8168 avoiding command line length issues (@pxref{Length Limitations}).  Since
8169 some @command{install} programs will not install the same file twice in
8170 one invocation, you may need to ensure that file lists are unique within
8171 one variable such as @samp{nobase_include_HEADERS} above.
8172
8173 You should not rely on the order in which files listed in one variable
8174 are installed.  Likewise, to cater for parallel make, you should not
8175 rely on any particular file installation order even among different
8176 file types (library dependencies are an exception here).
8177
8178
8179 @node The Two Parts of Install
8180 @section The Two Parts of Install
8181
8182 Automake generates separate @code{install-data} and @code{install-exec}
8183 rules, in case the installer is installing on multiple machines that
8184 share directory structure---these targets allow the machine-independent
8185 parts to be installed only once.  @code{install-exec} installs
8186 platform-dependent files, and @code{install-data} installs
8187 platform-independent files.  The @code{install} target depends on both
8188 of these targets.  While Automake tries to automatically segregate
8189 objects into the correct category, the @file{Makefile.am} author is, in
8190 the end, responsible for making sure this is done correctly.
8191 @trindex install-data
8192 @trindex install-exec
8193 @trindex install
8194 @cindex Install, two parts of
8195
8196 Variables using the standard directory prefixes @samp{data},
8197 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
8198 @samp{pkgdata}, or @samp{pkginclude} are installed by
8199 @code{install-data}.
8200
8201 Variables using the standard directory prefixes @samp{bin},
8202 @samp{sbin}, @samp{libexec}, @samp{sysconf}, @samp{localstate},
8203 @samp{lib}, or @samp{pkglib} are installed by @code{install-exec}.
8204
8205 For instance, @code{data_DATA} files are installed by @code{install-data},
8206 while @code{bin_PROGRAMS} files are installed by @code{install-exec}.
8207
8208 Any variable using a user-defined directory prefix with
8209 @samp{exec} in the name (e.g.,
8210 @c Keep in sync with primary-prefix-couples-documented-valid.sh
8211 @code{myexecbin_PROGRAMS}) is installed by @code{install-exec}.  All
8212 other user-defined prefixes are installed by @code{install-data}.
8213
8214 @node Extending Installation
8215 @section Extending Installation
8216
8217 It is possible to extend this mechanism by defining an
8218 @code{install-exec-local} or @code{install-data-local} rule.  If these
8219 rules exist, they will be run at @samp{make install} time.  These
8220 rules can do almost anything; care is required.
8221 @trindex install-exec-local
8222 @trindex install-data-local
8223
8224 Automake also supports two install hooks, @code{install-exec-hook} and
8225 @code{install-data-hook}.  These hooks are run after all other install
8226 rules of the appropriate type, exec or data, have completed.  So, for
8227 instance, it is possible to perform post-installation modifications
8228 using an install hook.  @xref{Extending}, for some examples.
8229 @cindex Install hook
8230
8231 @node Staged Installs
8232 @section Staged Installs
8233
8234 @vindex DESTDIR
8235 Automake generates support for the @code{DESTDIR} variable in all
8236 install rules.  @code{DESTDIR} is used during the @samp{make install}
8237 step to relocate install objects into a staging area.  Each object and
8238 path is prefixed with the value of @code{DESTDIR} before being copied
8239 into the install area.  Here is an example of typical DESTDIR usage:
8240
8241 @example
8242 mkdir /tmp/staging &&
8243 make DESTDIR=/tmp/staging install
8244 @end example
8245
8246 The @command{mkdir} command avoids a security problem if the attacker
8247 creates a symbolic link from @file{/tmp/staging} to a victim area;
8248 then @command{make} places install objects in a directory tree built under
8249 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
8250 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
8251 would install @file{/tmp/staging/gnu/bin/foo} and
8252 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
8253
8254 This feature is commonly used to build install images and packages
8255 (@pxref{DESTDIR}).
8256
8257 Support for @code{DESTDIR} is implemented by coding it directly into
8258 the install rules.  If your @file{Makefile.am} uses a local install
8259 rule (e.g., @code{install-exec-local}) or an install hook, then you
8260 must write that code to respect @code{DESTDIR}.
8261
8262 @xref{Makefile Conventions, , , standards, The GNU Coding Standards},
8263 for another usage example.
8264
8265 @node Install Rules for the User
8266 @section Install Rules for the User
8267
8268 Automake also generates rules for targets @code{uninstall},
8269 @code{installdirs}, and @code{install-strip}.
8270 @trindex uninstall
8271 @trindex installdirs
8272 @trindex install-strip
8273
8274 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
8275 There is no notion of separate uninstalls for ``exec'' and ``data'', as
8276 these features would not provide additional functionality.
8277
8278 Note that @code{uninstall} is not meant as a replacement for a real
8279 packaging tool.
8280
8281
8282 @node Clean
8283 @chapter What Gets Cleaned
8284
8285 @cindex @samp{make clean} support
8286
8287 The GNU Makefile Standards specify a number of different clean rules.
8288 @xref{Standard Targets, , Standard Targets for Users, standards,
8289 The GNU Coding Standards}.
8290
8291 Generally the files that can be cleaned are determined automatically by
8292 Automake.  Of course, Automake also recognizes some variables that can
8293 be defined to specify additional files to clean.  These variables are
8294 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
8295 @code{MAINTAINERCLEANFILES}.
8296 @vindex MOSTLYCLEANFILES
8297 @vindex CLEANFILES
8298 @vindex DISTCLEANFILES
8299 @vindex MAINTAINERCLEANFILES
8300
8301 @trindex mostlyclean-local
8302 @trindex clean-local
8303 @trindex distclean-local
8304 @trindex maintainer-clean-local
8305 When cleaning involves more than deleting some hard-coded list of
8306 files, it is also possible to supplement the cleaning rules with your
8307 own commands.  Simply define a rule for any of the
8308 @code{mostlyclean-local}, @code{clean-local}, @code{distclean-local},
8309 or @code{maintainer-clean-local} targets (@pxref{Extending}).  A common
8310 case is deleting a directory, for instance, a directory created by the
8311 test suite:
8312
8313 @example
8314 clean-local:
8315         -rm -rf testSubDir
8316 @end example
8317
8318 Since @command{make} allows only one set of rules for a given target,
8319 a more extensible way of writing this is to use a separate target
8320 listed as a dependency:
8321
8322 @example
8323 clean-local: clean-local-check
8324 .PHONY: clean-local-check
8325 clean-local-check:
8326         -rm -rf testSubDir
8327 @end example
8328
8329 As the GNU Standards aren't always explicit as to which files should
8330 be removed by which rule, we've adopted a heuristic that we believe
8331 was first formulated by Fran@,{c}ois Pinard:
8332
8333 @itemize @bullet
8334 @item
8335 If @command{make} built it, and it is commonly something that one would
8336 want to rebuild (for instance, a @file{.o} file), then
8337 @code{mostlyclean} should delete it.
8338
8339 @item
8340 Otherwise, if @command{make} built it, then @code{clean} should delete it.
8341
8342 @item
8343 If @command{configure} built it, then @code{distclean} should delete it.
8344
8345 @item
8346 If the maintainer built it (for instance, a @file{.info} file), then
8347 @code{maintainer-clean} should delete it.  However
8348 @code{maintainer-clean} should not delete anything that needs to exist
8349 in order to run @samp{./configure && make}.
8350 @end itemize
8351
8352 We recommend that you follow this same set of heuristics in your
8353 @file{Makefile.am}.
8354
8355
8356 @node Dist
8357 @chapter What Goes in a Distribution
8358
8359 @menu
8360 * Basics of Distribution::      Files distributed by default
8361 * Fine-grained Distribution Control::  @code{dist_} and @code{nodist_} prefixes
8362 * The dist Hook::               A target for last-minute distribution changes
8363 * Checking the Distribution::   @samp{make distcheck} explained
8364 * The Types of Distributions::  A variety of formats and compression methods
8365 @end menu
8366
8367 @node Basics of Distribution
8368 @section Basics of Distribution
8369
8370 @cindex @samp{make dist}
8371
8372 @vindex PACKAGE
8373 @vindex VERSION
8374 @trindex dist
8375 The @code{dist} rule in the generated @file{Makefile.in} can be used
8376 to generate a gzipped @code{tar} file and other flavors of archive for
8377 distribution.  The file is named based on the @code{PACKAGE} and
8378 @code{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
8379 (@pxref{Macros}); more precisely the gzipped @code{tar} file is named
8380 @samp{@var{package}-@var{version}.tar.gz}.
8381 @vindex GZIP_ENV
8382 You can use the @command{make} variable @code{GZIP_ENV} to control how gzip
8383 is run.  The default setting is @option{--best}.
8384
8385 @cindex @code{m4_include}, distribution
8386 @cindex @code{include}, distribution
8387 @acindex m4_include
8388 @cmindex include
8389 For the most part, the files to distribute are automatically found by
8390 Automake: all source files are automatically included in a distribution,
8391 as are all @file{Makefile.am} and @file{Makefile.in} files.  Automake also
8392 has a built-in list of commonly used files that are automatically
8393 included if they are found in the current directory (either physically,
8394 or as the target of a @file{Makefile.am} rule); this list is printed by
8395 @samp{automake --help}.  Note that some files in this list are actually
8396 distributed only if other certain conditions hold (for example,
8397 @c Keep in sync with autodist-config-headers.sh
8398 the @file{config.h.top} and @file{config.h.bot} files are automatically
8399 distributed only if, e.g., @samp{AC_CONFIG_HEADERS([config.h])} is used
8400 in @file{configure.ac}).  Also, files that are read by @command{configure}
8401 (i.e.@: the source files corresponding to the files specified in various
8402 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
8403 automatically distributed.  Files included in a @file{Makefile.am} (using
8404 @code{include}) or in @file{configure.ac} (using @code{m4_include}), and
8405 helper scripts installed with @samp{automake --add-missing} are also
8406 distributed.
8407
8408 @vindex EXTRA_DIST
8409 Still, sometimes there are files that must be distributed, but which
8410 are not covered in the automatic rules.  These files should be listed in
8411 the @code{EXTRA_DIST} variable.  You can mention files from
8412 subdirectories in @code{EXTRA_DIST}.
8413
8414 You can also mention a directory in @code{EXTRA_DIST}; in this case the
8415 entire directory will be recursively copied into the distribution.
8416 Please note that this will also copy @emph{everything} in the directory,
8417 including, e.g., Subversion's @file{.svn} private directories or CVS/RCS
8418 version control files.  We recommend against using this feature.
8419
8420 @vindex SUBDIRS
8421 @vindex DIST_SUBDIRS
8422 If you define @code{SUBDIRS}, Automake will recursively include the
8423 subdirectories in the distribution.  If @code{SUBDIRS} is defined
8424 conditionally (@pxref{Conditionals}), Automake will normally include
8425 all directories that could possibly appear in @code{SUBDIRS} in the
8426 distribution.  If you need to specify the set of directories
8427 conditionally, you can set the variable @code{DIST_SUBDIRS} to the
8428 exact list of subdirectories to include in the distribution
8429 (@pxref{Conditional Subdirectories}).
8430
8431
8432 @node Fine-grained Distribution Control
8433 @section Fine-grained Distribution Control
8434
8435 @vindex dist_
8436 @vindex nodist_
8437 Sometimes you need tighter control over what does @emph{not} go into the
8438 distribution; for instance, you might have source files that are
8439 generated and that you do not want to distribute.  In this case
8440 Automake gives fine-grained control using the @code{dist} and
8441 @code{nodist} prefixes.  Any primary or @code{_SOURCES} variable can be
8442 prefixed with @code{dist_} to add the listed files to the distribution.
8443 Similarly, @code{nodist_} can be used to omit the files from the
8444 distribution.
8445
8446 As an example, here is how you would cause some data to be distributed
8447 while leaving some source code out of the distribution:
8448
8449 @example
8450 dist_data_DATA = distribute-this
8451 bin_PROGRAMS = foo
8452 nodist_foo_SOURCES = do-not-distribute.c
8453 @end example
8454
8455 @node The dist Hook
8456 @section The dist Hook
8457
8458 @trindex dist-hook
8459
8460 Occasionally it is useful to be able to change the distribution before
8461 it is packaged up.  If the @code{dist-hook} rule exists, it is run
8462 after the distribution directory is filled, but before the actual
8463 distribution archives are created.  One way to use this is for
8464 removing unnecessary files that get recursively included by specifying
8465 a directory in @code{EXTRA_DIST}:
8466
8467 @example
8468 EXTRA_DIST = doc
8469 dist-hook:
8470         rm -rf `find $(distdir)/doc -type d -name .svn`
8471 @end example
8472
8473 @c The caveates described here should be documented in 'disthook.sh'.
8474 @noindent
8475 Note that the @code{dist-hook} recipe shouldn't assume that the regular
8476 files in the distribution directory are writable; this might not be the
8477 case if one is packaging from a read-only source tree, or when a
8478 @code{make distcheck} is being done.  For similar reasons, the recipe
8479 shouldn't assume that the subdirectories put into the distribution
8480 directory as effect of having them listed in @code{EXTRA_DIST} are
8481 writable.  So, if the @code{dist-hook} recipe wants to modify the
8482 content of an existing file (or @code{EXTRA_DIST} subdirectory) in the
8483 distribution directory, it should explicitly to make it writable first:
8484
8485 @example
8486 EXTRA_DIST = README doc
8487 dist-hook:
8488         chmod u+w $(distdir)/README $(distdir)/doc
8489         echo "Distribution date: `date`" >> README
8490         rm -f $(distdir)/doc/HACKING
8491 @end example
8492
8493 @vindex distdir
8494 @vindex top_distdir
8495 Two variables that come handy when writing @code{dist-hook} rules are
8496 @samp{$(distdir)} and @samp{$(top_distdir)}.
8497
8498 @samp{$(distdir)} points to the directory where the @code{dist} rule
8499 will copy files from the current directory before creating the
8500 tarball.  If you are at the top-level directory, then @samp{distdir =
8501 $(PACKAGE)-$(VERSION)}.  When used from subdirectory named
8502 @file{foo/}, then @samp{distdir = ../$(PACKAGE)-$(VERSION)/foo}.
8503 @samp{$(distdir)} can be a relative or absolute path, do not assume
8504 any form.
8505
8506 @samp{$(top_distdir)} always points to the root directory of the
8507 distributed tree.  At the top-level it's equal to @samp{$(distdir)}.
8508 In the @file{foo/} subdirectory
8509 @samp{top_distdir = ../$(PACKAGE)-$(VERSION)}.
8510 @samp{$(top_distdir)} too can be a relative or absolute path.
8511
8512 Note that when packages are nested using @code{AC_CONFIG_SUBDIRS}
8513 (@pxref{Subpackages}), then @samp{$(distdir)} and
8514 @samp{$(top_distdir)} are relative to the package where @samp{make
8515 dist} was run, not to any sub-packages involved.
8516
8517 @node Checking the Distribution
8518 @section Checking the Distribution
8519
8520 @cindex @samp{make distcheck}
8521 @trindex distcheck
8522 Automake also generates a @code{distcheck} rule that can be of help
8523 to ensure that a given distribution will actually work.  Simplifying
8524 a bit, we can say this rule first makes a distribution, and then,
8525 @emph{operating from it}, takes the following steps:
8526 @itemize
8527 @item
8528 tries to do a @code{VPATH} build (@pxref{VPATH Builds}), with the
8529 @code{srcdir} and all its content made @emph{read-only};
8530 @item
8531 runs the test suite (with @command{make check}) on this fresh build;
8532 @item
8533 installs the package in a temporary directory (with @command{make
8534 install}), and tries runs the test suite on the resulting installation
8535 (with @command{make installcheck});
8536 @item
8537 checks that the package can be correctly uninstalled (by @command{make
8538 uninstall}) and cleaned (by @code{make distclean});
8539 @item
8540 finally, makes another tarball to ensure the distribution is
8541 self-contained.
8542 @end itemize
8543
8544 @vindex AM_DISTCHECK_CONFIGURE_FLAGS
8545 @vindex DISTCHECK_CONFIGURE_FLAGS
8546 @subheading DISTCHECK_CONFIGURE_FLAGS
8547 Building the package involves running @samp{./configure}.  If you need
8548 to supply additional flags to @command{configure}, define them in the
8549 @code{AM_DISTCHECK_CONFIGURE_FLAGS} variable in your top-level
8550 @file{Makefile.am}.  The user can still extend or override the flags
8551 provided there by defining the @code{DISTCHECK_CONFIGURE_FLAGS} variable,
8552 on the command line when invoking @command{make}.
8553
8554 Still, developers are encouraged to strive to make their code buildable
8555 without requiring any special configure option; thus, in general, you
8556 shouldn't define @code{AM_DISTCHECK_CONFIGURE_FLAGS}. However, there
8557 might be few scenarios in which the use of this variable is justified.
8558 GNU @command{m4} offers an example.  GNU @command{m4} configures by
8559 default with its experimental and seldom used "changeword" feature
8560 disabled; so in its case it is useful to have @command{make distcheck}
8561 run configure with the @option{--with-changeword} option, to ensure that
8562 the code for changeword support still compiles correctly.
8563 GNU @command{m4} also employs the @code{AM_DISTCHECK_CONFIGURE_FLAGS}
8564 variable to stress-test the use of @option{--program-prefix=g}, since at
8565 one point the @command{m4} build system had a bug where @command{make
8566 installcheck} was wrongly assuming it could blindly test "@command{m4}",
8567 rather than the just-installed "@command{gm4}".
8568
8569 @trindex distcheck-hook
8570 @subheading distcheck-hook
8571 If the @code{distcheck-hook} rule is defined in your top-level
8572 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
8573 the new distribution has been unpacked, but before the unpacked copy
8574 is configured and built.  Your @code{distcheck-hook} can do almost
8575 anything, though as always caution is advised.  Generally this hook is
8576 used to check for potential distribution errors not caught by the
8577 standard mechanism.  Note that @code{distcheck-hook} as well as
8578 @code{AM_DISTCHECK_CONFIGURE_FLAGS} and @code{DISTCHECK_CONFIGURE_FLAGS}
8579 are not honored in a subpackage @file{Makefile.am}, but the flags from
8580 @code{AM_DISTCHECK_CONFIGURE_FLAGS} and @code{DISTCHECK_CONFIGURE_FLAGS}
8581 are passed down to the @command{configure} script of the subpackage.
8582
8583 @cindex @samp{make distcleancheck}
8584 @trindex distcleancheck
8585 @vindex DISTCLEANFILES
8586 @vindex distcleancheck_listfiles
8587
8588 @subheading distcleancheck
8589 Speaking of potential distribution errors, @code{distcheck} also
8590 ensures that the @code{distclean} rule actually removes all built
8591 files.  This is done by running @samp{make distcleancheck} at the end of
8592 the @code{VPATH} build.  By default, @code{distcleancheck} will run
8593 @code{distclean} and then make sure the build tree has been emptied by
8594 running @samp{$(distcleancheck_listfiles)}.  Usually this check will
8595 find generated files that you forgot to add to the @code{DISTCLEANFILES}
8596 variable (@pxref{Clean}).
8597
8598 The @code{distcleancheck} behavior should be OK for most packages,
8599 otherwise you have the possibility to override the definition of
8600 either the @code{distcleancheck} rule, or the
8601 @samp{$(distcleancheck_listfiles)} variable.  For instance, to disable
8602 @code{distcleancheck} completely, add the following rule to your
8603 top-level @file{Makefile.am}:
8604
8605 @example
8606 distcleancheck:
8607         @@:
8608 @end example
8609
8610 If you want @code{distcleancheck} to ignore built files that have not
8611 been cleaned because they are also part of the distribution, add the
8612 following definition instead:
8613
8614 @c Keep in sync with distcleancheck.sh
8615 @example
8616 distcleancheck_listfiles = \
8617   find . -type f -exec sh -c 'test -f $(srcdir)/$$1 || echo $$1' \
8618        sh '@{@}' ';'
8619 @end example
8620
8621 The above definition is not the default because it's usually an error if
8622 your Makefiles cause some distributed files to be rebuilt when the user
8623 build the package.  (Think about the user missing the tool required to
8624 build the file; or if the required tool is built by your package,
8625 consider the cross-compilation case where it can't be run.)  There is
8626 an entry in the FAQ about this (@pxref{Errors with distclean}), make
8627 sure you read it before playing with @code{distcleancheck_listfiles}.
8628
8629 @cindex @samp{make distuninstallcheck}
8630 @trindex distuninstallcheck
8631 @vindex distuninstallcheck_listfiles
8632
8633 @subheading distuninstallcheck
8634 @code{distcheck} also checks that the @code{uninstall} rule works
8635 properly, both for ordinary and @code{DESTDIR} builds.  It does this
8636 by invoking @samp{make uninstall}, and then it checks the install tree
8637 to see if any files are left over.  This check will make sure that you
8638 correctly coded your @code{uninstall}-related rules.
8639
8640 By default, the checking is done by the @code{distuninstallcheck} rule,
8641 and the list of files in the install tree is generated by
8642 @samp{$(distuninstallcheck_listfiles)} (this is a variable whose value is
8643 a shell command to run that prints the list of files to stdout).
8644
8645 Either of these can be overridden to modify the behavior of
8646 @code{distcheck}.  For instance, to disable this check completely, you
8647 would write:
8648
8649 @example
8650 distuninstallcheck:
8651         @@:
8652 @end example
8653
8654 @node The Types of Distributions
8655 @section The Types of Distributions
8656
8657 Automake generates rules to provide archives of the project for
8658 distributions in various formats.  Their targets are:
8659
8660 @table @asis
8661 @item @code{dist-gzip}
8662 Generate a @samp{gzip} tar archive of the distribution.  This is the
8663 only format enabled by default.
8664 @trindex dist-gzip
8665
8666 @vindex BZIP2
8667 @item @code{dist-bzip2}
8668 Generate a @samp{bzip2} tar archive of the distribution.  bzip2 archives
8669 are frequently smaller than gzipped archives.
8670 By default, this rule makes @samp{bzip2} use a compression option of @option{-9}.
8671 To make it use a different one, set the @env{BZIP2} environment variable.
8672 For example, @samp{make dist-bzip2 BZIP2=-7}.
8673 @trindex dist-bzip2
8674
8675 @item @code{dist-lzip}
8676 Generate an @samp{lzip} tar archive of the distribution.  @command{lzip}
8677 archives are frequently smaller than @command{bzip2}-compressed archives.
8678 @trindex dist-lzip
8679
8680 @vindex XZ_OPT
8681 @item @code{dist-xz}
8682 Generate an @samp{xz} tar archive of the distribution.  @command{xz}
8683 archives are frequently smaller than @command{bzip2}-compressed archives.
8684 By default, this rule makes @samp{xz} use a compression option of
8685 @option{-e}.  To make it use a different one, set the @env{XZ_OPT}
8686 environment variable.  For example, run this command to use the
8687 default compression ratio, but with a progress indicator:
8688 @samp{make dist-xz XZ_OPT=-ve}.
8689 @trindex dist-xz
8690
8691 @item @code{dist-zip}
8692 Generate a @samp{zip} archive of the distribution.
8693 @trindex dist-zip
8694
8695 @item @code{dist-tarZ}
8696 Generate a tar archive of the distribution, compressed with the
8697 historical (obsolescent) program @command{compress}.  Use of this
8698 option is discouraged.
8699 @trindex dist-tarZ
8700
8701 @item @code{dist-shar}
8702 Generate a @samp{shar} archive of the distribution.  This format archive
8703 is obsolescent, and use of this option is discouraged.
8704 @trindex dist-shar
8705
8706 @end table
8707
8708 The rule @code{dist} (and its historical synonym @code{dist-all})
8709 will create archives in all the enabled formats (@pxref{List of
8710 Automake options} for how to change this list).  By default, only
8711 the @code{dist-gzip} target is hooked to @code{dist}.
8712
8713
8714 @node Tests
8715 @chapter Support for test suites
8716
8717 @cindex Test suites
8718 @cindex @code{make check}
8719 @trindex check
8720
8721 Automake can generate code to handle two kinds of test suites.  One is
8722 based on integration with the @command{dejagnu} framework.  The other
8723 (and most used) form is based on the use of generic test scripts, and
8724 its activation is triggered by the definition of the special @code{TESTS}
8725 variable.  This second form allows for various degrees of sophistication
8726 and customization; in particular, it allows for concurrent execution
8727 of test scripts, use of established test protocols such as TAP, and
8728 definition of custom test drivers and test runners.
8729
8730 @noindent
8731 In either case, the testsuite is invoked via @samp{make check}.
8732
8733 @menu
8734 * Generalities about Testing::  Concepts and terminology about testing
8735 * Simple Tests::                Listing test scripts in @code{TESTS}
8736 * Custom Test Drivers::         Writing and using custom test drivers
8737 * Using the TAP test protocol:: Integrating test scripts that use the TAP protocol
8738 * DejaGnu Tests::               Interfacing with the @command{dejagnu} testing framework
8739 * Install Tests::               Running tests on installed packages
8740 @end menu
8741
8742 @node Generalities about Testing
8743 @section Generalities about Testing
8744
8745 The purpose of testing is to determine whether a program or system behaves
8746 as expected (e.g., known inputs produce the expected outputs, error
8747 conditions are correctly handled or reported, and older bugs do not
8748 resurface).
8749
8750 @cindex test case
8751 The minimal unit of testing is usually called @emph{test case}, or simply
8752 @emph{test}.  How a test case is defined or delimited, and even what
8753 exactly @emph{constitutes} a test case, depends heavily on the testing
8754 paradigm and/or framework in use, so we won't attempt any more precise
8755 definition.  The set of the test cases for a given program or system
8756 constitutes its @emph{testsuite}.
8757
8758 @cindex test harness
8759 @cindex testsuite harness
8760 A @emph{test harness} (also @emph{testsuite harness}) is a program or
8761 software component that executes all (or part of) the defined test cases,
8762 analyzes their outcomes, and report or register these outcomes
8763 appropriately.  Again, the details of how this is accomplished (and how
8764 the developer and user can influence it or interface with it) varies
8765 wildly, and we'll attempt no precise definition.
8766
8767 @cindex test pass
8768 @cindex test failure
8769 A test is said to @emph{pass} when it can determine that the condition or
8770 behaviour it means to verify holds, and is said to @emph{fail} when it can
8771 determine that such condition of behaviour does @emph{not} hold.
8772
8773 @cindex test skip
8774 Sometimes, tests can rely on non-portable tools or prerequisites, or
8775 simply make no sense on a given system (for example, a test checking a
8776 Windows-specific feature makes no sense on a GNU/Linux system).  In this
8777 case, accordingly to the definition above, the tests can neither be
8778 considered passed nor failed; instead, they are @emph{skipped} -- i.e.,
8779 they are not run, or their result is anyway ignored for what concerns
8780 the count of failures an successes.  Skips are usually explicitly
8781 reported though, so that the user will be aware that not all of the
8782 testsuite has really run.
8783
8784 @cindex xfail
8785 @cindex expected failure
8786 @cindex expected test failure
8787 @cindex xpass
8788 @cindex unexpected pass
8789 @cindex unexpected test pass
8790 It's not uncommon, especially during early development stages, that some
8791 tests fail for known reasons, and that the developer doesn't want to
8792 tackle these failures immediately (this is especially true when the
8793 failing tests deal with corner cases).  In this situation, the better
8794 policy is to declare that each of those failures is an @emph{expected
8795 failure} (or @emph{xfail}).  In case a test that is expected to fail ends
8796 up passing instead, many testing environments will flag the result as a
8797 special kind of failure called @emph{unexpected pass} (or @emph{xpass}).
8798
8799 @cindex hard error
8800 @cindex Distinction between errors and failures in testsuites
8801 Many testing environments and frameworks distinguish between test failures
8802 and hard errors.  As we've seen, a test failure happens when some invariant
8803 or expected behaviour of the software under test is not met.  An @emph{hard
8804 error} happens when e.g., the set-up of a test case scenario fails, or when
8805 some other unexpected or highly undesirable condition is encountered (for
8806 example, the program under test experiences a segmentation fault).
8807
8808 @emph{TODO}: Links to other test harnesses (esp. those sharing our
8809 terminology)?
8810
8811 @node Simple Tests
8812 @section Simple Tests
8813
8814 @menu
8815 * Scripts-based Testsuites::    Automake-specific concepts and terminology
8816 * Serial Test Harness::         Older (and discouraged) serial test harness
8817 * Parallel Test Harness::       Generic concurrent test harness
8818 @end menu
8819
8820 @node Scripts-based Testsuites
8821 @subsection Scripts-based Testsuites
8822
8823 If the special variable @code{TESTS} is defined, its value is taken to be
8824 a list of programs or scripts to run in order to do the testing.  Under
8825 the appropriate circumstances, it's possible for @code{TESTS} to list
8826 also data files to be passed to one or more test scripts defined by
8827 different means (the so-called ``log compilers'', @pxref{Parallel Test
8828 Harness}).
8829
8830 Test scripts can be executed serially or concurrently.  Automake supports
8831 both these kinds of test execution, with the parallel test harness being
8832 the default.  The concurrent test harness relies on the concurrence
8833 capabilities (if any) offered by the underlying @command{make}
8834 implementation, and can thus only be as good as those are.
8835
8836 By default, only the exit statuses of the test scripts are considered when
8837 determining the testsuite outcome.  But Automake allows also the use of
8838 more complex test protocols, either standard (@pxref{Using the TAP test
8839 protocol}) or custom (@pxref{Custom Test Drivers}).  Note that you can't
8840 enable such protocols when the serial harness is used, though.
8841 In the rest of this section we are going to concentrate mostly on
8842 protocol-less tests, since we cover test protocols in a later section
8843 (again, @pxref{Custom Test Drivers}).
8844
8845 @cindex Exit status 77, special interpretation
8846 @cindex Exit status 99, special interpretation
8847 When no test protocol is in use, an exit status of 0 from a test script will
8848 denote a success, an exit status of 77 a skipped test, an exit status of 99
8849 an hard error, and any other exit status will denote a failure.
8850
8851 @cindex Tests, expected failure
8852 @cindex Expected test failure
8853 @vindex XFAIL_TESTS
8854 @vindex DISABLE_HARD_ERRORS
8855 @cindex Disabling hard errors
8856 You may define the variable @code{XFAIL_TESTS} to a list of tests
8857 (usually a subset of @code{TESTS}) that are expected to fail; this will
8858 effectively reverse the result of those tests (with the provision that
8859 skips and hard errors remain untouched).  You may also instruct the
8860 testsuite harness to treat hard errors like simple failures, by defining
8861 the @code{DISABLE_HARD_ERRORS} make variable to a nonempty value.
8862
8863 Note however that, for tests based on more complex test protocols,
8864 the exact effects of @code{XFAIL_TESTS} and @code{DISABLE_HARD_ERRORS}
8865 might change, or they might even have no effect at all (for example,
8866 @c Keep this in sync with tap-no-disable-hard-errors.sh
8867 in tests using TAP, there is not way to disable hard errors, and the
8868 @code{DISABLE_HARD_ERRORS} variable has no effect on them).
8869
8870 @anchor{Testsuite progress on console}
8871 @cindex Testsuite progress on console
8872 The result of each test case run by the scripts in @code{TESTS} will be
8873 printed on standard output, along with the test name.  For test protocols
8874 that allow more test cases per test script (such as TAP), a number,
8875 identifier and/or brief description specific for the single test case is
8876 expected to be printed in addition to the name of the test script.  The
8877 possible results (whose meanings should be clear from the previous
8878 @ref{Generalities about Testing}) are @code{PASS}, @code{FAIL},
8879 @code{SKIP}, @code{XFAIL}, @code{XPASS} and @code{ERROR}.  Here is an
8880 example of output from an hypothetical testsuite that uses both plain
8881 and TAP tests:
8882 @c Keep in sync with tap-doc.sh
8883 @example
8884 PASS: foo.sh
8885 PASS: zardoz.tap 1 - Daemon started
8886 PASS: zardoz.tap 2 - Daemon responding
8887 SKIP: zardoz.tap 3 - Daemon uses /proc # SKIP /proc is not mounted
8888 PASS: zardoz.tap 4 - Daemon stopped
8889 SKIP: bar.sh
8890 PASS: mu.tap 1
8891 XFAIL: mu.tap 2 # TODO frobnication not yet implemented
8892 @end example
8893
8894 @noindent
8895 A testsuite summary (expected to report at least the number of run,
8896 skipped and failed tests) will be printed at the end of the testsuite
8897 run.
8898
8899 @anchor{Simple tests and color-tests}
8900 @vindex AM_COLOR_TESTS
8901 @cindex Colorized testsuite output
8902 If the standard output is connected to a capable terminal, then the test
8903 results and the summary are colored appropriately.  The developer and the
8904 user can disable colored output by setting the @command{make} variable
8905 @samp{AM_COLOR_TESTS=no}; the user can in addition force colored output
8906 even without a connecting terminal with @samp{AM_COLOR_TESTS=always}.
8907 It's also worth noting that some @command{make} implementations,
8908 when used in parallel mode, have slightly different semantics
8909 (@pxref{Parallel make,,, autoconf, The Autoconf Manual}), which can
8910 break the automatic detection of a connection to a capable terminal.
8911 If this is the case, the user will have to resort to the use of
8912 @samp{AM_COLOR_TESTS=always} in order to have the testsuite output
8913 colorized.
8914
8915 Test programs that need data files should look for them in @code{srcdir}
8916 (which is both a make variable and an environment variable made available
8917 to the tests), so that they work when building in a separate directory
8918 (@pxref{Build Directories, , Build Directories , autoconf,
8919 The Autoconf Manual}), and in particular for the @code{distcheck} rule
8920 (@pxref{Checking the Distribution}).
8921
8922 @vindex TESTS
8923 @vindex TESTS_ENVIRONMENT
8924 @vindex AM_TESTS_ENVIRONMENT
8925 The @code{AM_TESTS_ENVIRONMENT} and @code{TESTS_ENVIRONMENT} variables can
8926 be used to run initialization code and set environment variables for the
8927 test scripts.  The former variable is developer-reserved, and can be
8928 defined in the @file{Makefile.am}, while the latter is reserved for the
8929 user, which can employ it to extend or override the settings in the
8930 former; for this to work portably, however, the contents of a non-empty
8931 @code{AM_TESTS_ENVIRONMENT} @emph{must} be terminated by a semicolon.
8932
8933 @vindex AM_TESTS_FD_REDIRECT
8934 The @code{AM_TESTS_FD_REDIRECT} variable can be used to define file
8935 descriptor redirections for the test scripts.  One might think that
8936 @code{AM_TESTS_ENVIRONMENT} could be used for this purpose, but experience
8937 has shown that doing so portably is practically impossible.  The main
8938 hurdle is constituted by Korn shells, which usually set the close-on-exec
8939 flag on file descriptors opened with the @command{exec} builtin, thus
8940 rendering an idiom like @code{AM_TESTS_ENVIRONMENT = exec 9>&2;}
8941 ineffectual.  This issue also affects some Bourne shells, such as the
8942 HP-UX's @command{/bin/sh},
8943 @c FIXME: should we offer a link to the relevant discussions on the
8944 @c bug-autoconf list?
8945
8946 @c Keep in sync with tests-environment-backcompat.sh
8947 @example
8948 AM_TESTS_ENVIRONMENT = \
8949 ## Some environment initializations are kept in a separate shell
8950 ## file 'tests-env.sh', which can make it easier to also run tests
8951 ## from the command line.
8952   . $(srcdir)/tests-env.sh; \
8953 ## On Solaris, prefer more POSIX-compliant versions of the standard
8954 ## tools by default.
8955   if test -d /usr/xpg4/bin; then \
8956     PATH=/usr/xpg4/bin:$$PATH; export PATH; \
8957   fi;
8958 @c $$ restore font-lock
8959 ## With this, the test scripts will be able to print diagnostic
8960 ## messages to the original standard error stream, even if the test
8961 ## driver redirects the stderr of the test scripts to a log file
8962 ## before executing them.
8963 AM_TESTS_FD_REDIRECT = 9>&2
8964 @end example
8965
8966 @noindent
8967 Note however that @code{AM_TESTS_ENVIRONMENT} is, for historical and
8968 implementation reasons, @emph{not} supported by the serial harness
8969 (@pxref{Serial Test Harness}).
8970
8971 Automake ensures that each file listed in @code{TESTS} is built before
8972 it is run; you can list both source and derived programs (or scripts)
8973 in @code{TESTS}; the generated rule will look both in @code{srcdir} and
8974 @file{.}.  For instance, you might want to run a C program as a test.
8975 To do this you would list its name in @code{TESTS} and also in
8976 @code{check_PROGRAMS}, and then specify it as you would any other
8977 program.
8978
8979 Programs listed in @code{check_PROGRAMS} (and @code{check_LIBRARIES},
8980 @code{check_LTLIBRARIES}...) are only built during @code{make check},
8981 not during @code{make all}.  You should list there any program needed
8982 by your tests that does not need to be built by @code{make all}.  Note
8983 that @code{check_PROGRAMS} are @emph{not} automatically added to
8984 @code{TESTS} because @code{check_PROGRAMS} usually lists programs used
8985 by the tests, not the tests themselves.  Of course you can set
8986 @code{TESTS = $(check_PROGRAMS)} if all your programs are test cases.
8987
8988 @node Serial Test Harness
8989 @subsection Older (and discouraged) serial test harness
8990 @cindex @option{serial-tests}, Using
8991
8992 First, note that today the use of this harness is strongly discouraged in
8993 favour of the parallel test harness (@pxref{Parallel Test Harness}).
8994 Still, there are @emph{few} situations when the advantages offered by
8995 the parallel harness are irrelevant, and when test concurrency can
8996 even cause tricky problems.  In those cases, it might make sense to
8997 still use the serial harness, for simplicity and reliability (we still
8998 suggest trying to give the parallel harness a shot though).
8999
9000 The serial test harness is enabled by the Automake option
9001 @option{serial-tests}. It operates by simply running the tests serially,
9002 one at the time, without any I/O redirection.  It's up to the user to
9003 implement logging of tests' output, if that's requited or desired.
9004 @c TODO: give an example of how this can be done.
9005
9006 For historical and implementation reasons, the @code{AM_TESTS_ENVIRONMENT}
9007 variable is @emph{not} supported by this harness (it will be silently
9008 ignored if defined); only @code{TESTS_ENVIRONMENT} is, and it is to be
9009 considered a developer-reserved variable.  This is done so that, when
9010 using the serial harness, @code{TESTS_ENVIRONMENT} can be defined to an
9011 invocation of an interpreter through which the tests are to be run.
9012 For instance, the following setup may be used to run tests with Perl:
9013
9014 @example
9015 TESTS_ENVIRONMENT = $(PERL) -Mstrict -w
9016 TESTS = foo.pl bar.pl baz.pl
9017 @end example
9018
9019 @noindent
9020 It's important to note that the use of @code{TESTS_ENVIRONMENT} endorsed
9021 here would be @emph{invalid} with the parallel harness.  That harness
9022 provides a more elegant way to achieve the same effect, with the further
9023 benefit of freeing the @code{TESTS_ENVIRONMENT} variable for the user
9024 (@pxref{Parallel Test Harness}).
9025
9026 Another, less serious limit of the serial harness is that it doesn't
9027 really distinguish between simple failures and hard errors; this is
9028 due to historical reasons only, and might be fixed in future Automake
9029 versions.
9030
9031 @node Parallel Test Harness
9032 @subsection Parallel Test Harness
9033
9034 By default, Automake generated a parallel (concurrent) test harness.  It
9035 features automatic collection of the test scripts output in @file{.log}
9036 files, concurrent execution of tests with @code{make -j}, specification
9037 of inter-test dependencies, lazy reruns of tests that have not completed
9038 in a prior run, and hard errors for exceptional failures.
9039
9040 @anchor{Basics of test metadata}
9041 @vindex TEST_SUITE_LOG
9042 @vindex TESTS
9043 @cindex @file{.log} files
9044 @cindex @file{.trs} files
9045 @cindex test metadata
9046 The parallel test harness operates by defining a set of @command{make}
9047 rules that run the test scripts listed in @code{TESTS}, and, for each
9048 such script, save its output in a corresponding @file{.log} file and
9049 its results (and other ``metadata'', @pxref{API for Custom Test Drivers})
9050 in a corresponding @file{.trs} (as in @b{T}est @b{R}e@b{S}ults) file.
9051 @c We choose the '.trs' extension also because, at the time of writing,
9052 @c it isn't already used for other significant purposes; see e.g.:
9053 @c   - http://filext.com/file-extension/trs
9054 @c   - http://www.file-extensions.org/search/?searchstring=trs
9055 The @file{.log} file will contain all the output emitted by the test on
9056 its standard output and its standard error.  The @file{.trs} file will
9057 contain, among the other things, the results of the test cases run by
9058 the script.
9059
9060 The parallel test harness will also create a summary log file,
9061 @code{TEST_SUITE_LOG}, which defaults to @file{test-suite.log} and requires
9062 a @file{.log} suffix.  This file depends upon all the @file{.log} and
9063 @file{.trs} files created for the test scripts listed in @code{TESTS}.
9064
9065 @vindex VERBOSE
9066 As with the serial harness above, by default one status line is printed
9067 per completed test, and a short summary after the suite has completed.
9068 However, standard output and standard error of the test are redirected
9069 to a per-test log file, so that parallel execution does not produce
9070 intermingled output.  The output from failed tests is collected in the
9071 @file{test-suite.log} file.  If the variable @samp{VERBOSE} is set, this
9072 file is output after the summary.
9073 @c FIXME: we should be clearer about what we mean exactly here ...
9074 For best results, the tests should be verbose by default now.
9075
9076 @vindex TEST_EXTENSIONS
9077 @vindex TEST_LOGS
9078 Each couple of @file{.log} and @file{.trs} files is created when the
9079 corresponding test has completed.  The set of log files is listed in
9080 the read-only variable @code{TEST_LOGS}, and defaults to @code{TESTS},
9081 with the executable extension if any (@pxref{EXEEXT}), as well as any
9082 suffix listed in @code{TEST_EXTENSIONS} removed, and @file{.log} appended.
9083 Results are undefined if a test file name ends in several concatenated
9084 suffixes.  @code{TEST_EXTENSIONS} defaults to @file{.test}; it can be
9085 overridden by the user, in which case any extension listed in it must be
9086 constituted by a dot, followed by a non-digit alphabetic character,
9087 followed by any number of alphabetic characters.
9088 @c Keep in sync with test-extensions.sh
9089 For example, @samp{.sh}, @samp{.T} and @samp{.t1} are valid extensions,
9090 while @samp{.x-y}, @samp{.6c} and @samp{.t.1} are not.
9091
9092 @cindex Configure substitutions in @code{TESTS}
9093 It is important to note that, due to current limitations (unlikely to be
9094 lifted), configure substitutions in the definition of @code{TESTS} can
9095 only work if they will expand to a list of tests that have a suffix listed
9096 in @code{TEST_EXTENSIONS}.
9097
9098 @vindex _LOG_COMPILE
9099 @vindex _LOG_COMPILER
9100 @vindex _LOG_FLAGS
9101 @vindex LOG_COMPILE
9102 @vindex LOG_COMPILER
9103 @vindex LOG_FLAGS
9104 @vindex @var{ext}_LOG_COMPILE
9105 @vindex @var{ext}_LOG_COMPILER
9106 @vindex @var{ext}_LOG_FLAGS
9107 @vindex AM_@var{ext}_LOG_FLAGS
9108 @vindex AM_LOG_FLAGS
9109 For tests that match an extension @code{.@var{ext}} listed in
9110 @code{TEST_EXTENSIONS}, you can provide a custom ``test runner'' using
9111 the variable @code{@var{ext}_LOG_COMPILER} (note the upper-case
9112 extension) and pass options in @code{AM_@var{ext}_LOG_FLAGS} and allow
9113 the user to pass options in @code{@var{ext}_LOG_FLAGS}.  It will cause
9114 all tests with this extension to be called with this runner.  For all
9115 tests without a registered extension, the variables @code{LOG_COMPILER},
9116 @code{AM_LOG_FLAGS}, and @code{LOG_FLAGS} may be used.  For example,
9117
9118 @c Keep in sync with parallel-tests-log-compiler-example.sh
9119 @example
9120 TESTS = foo.pl bar.py baz
9121 TEST_EXTENSIONS = .pl .py
9122 PL_LOG_COMPILER = $(PERL)
9123 AM_PL_LOG_FLAGS = -w
9124 PY_LOG_COMPILER = $(PYTHON)
9125 AM_PY_LOG_FLAGS = -v
9126 LOG_COMPILER = ./wrapper-script
9127 AM_LOG_FLAGS = -d
9128 @end example
9129
9130 @noindent
9131 will invoke @samp{$(PERL) -w foo.pl}, @samp{$(PYTHON) -v bar.py},
9132 and @samp{./wrapper-script -d baz} to produce @file{foo.log},
9133 @file{bar.log}, and @file{baz.log}, respectively.  The @file{foo.trs},
9134 @file{bar.trs} and @file{baz.trs} files will be automatically produced
9135 as a side-effect.
9136
9137 It's important to note that, differently from what we've seen for the
9138 serial test harness (@pxref{Parallel Test Harness}), the
9139 @code{AM_TESTS_ENVIRONMENT} and @code{TESTS_ENVIRONMENT} variables
9140 @emph{cannot} be use to define a custom test runner; the
9141 @code{LOG_COMPILER} and @code{LOG_FLAGS} (or their extension-specific
9142 counterparts) should be used instead:
9143
9144 @example
9145 ## This is WRONG!
9146 AM_TESTS_ENVIRONMENT = PERL5LIB='$(srcdir)/lib' $(PERL) -Mstrict -w
9147 @end example
9148
9149 @example
9150 ## Do this instead.
9151 AM_TESTS_ENVIRONMENT = PERL5LIB='$(srcdir)/lib'; export PERL5LIB;
9152 LOG_COMPILER = $(PERL)
9153 AM_LOG_FLAGS = -Mstrict -w
9154 @end example
9155
9156 By default, the test suite harness will run all tests, but there are
9157 several ways to limit the set of tests that are run:
9158
9159 @itemize @bullet
9160 @item
9161 You can set the @code{TESTS} variable.  For example, you can use a
9162 command like this to run only a subset of the tests:
9163
9164 @example
9165 env TESTS="foo.test bar.test" make -e check
9166 @end example
9167
9168 Note however that the command above will unconditionally overwrite the
9169 @file{test-suite.log} file, thus clobbering the recorded results
9170 of any previous testsuite run.  This might be undesirable for packages
9171 whose testsuite takes long time to execute.  Luckily, this problem can
9172 easily be avoided by overriding also @code{TEST_SUITE_LOG} at runtime;
9173 for example,
9174
9175 @c Keep in sync with parallel-tests-log-override-2.sh
9176 @example
9177 env TEST_SUITE_LOG=partial.log TESTS="..." make -e check
9178 @end example
9179
9180 will write the result of the partial testsuite runs to the
9181 @file{partial.log}, without touching @file{test-suite.log}.
9182
9183 @item
9184 You can set the @code{TEST_LOGS} variable.  By default, this variable is
9185 computed at @command{make} run time from the value of @code{TESTS} as
9186 described above.  For example, you can use the following:
9187
9188 @example
9189 set x subset*.log; shift
9190 env TEST_LOGS="foo.log $*" make -e check
9191 @end example
9192
9193 The comments made above about @code{TEST_SUITE_LOG} overriding applies
9194 here too.
9195
9196 @item
9197 @vindex RECHECK_LOGS
9198 @cindex lazy test execution
9199 By default, the test harness removes all old per-test @file{.log} and
9200 @file{.trs} files before it starts running tests to regenerate them.  The
9201 variable @code{RECHECK_LOGS} contains the set of @file{.log} (and, by
9202 implication, @file{.trs}) files which are removed.  @code{RECHECK_LOGS}
9203 defaults to @code{TEST_LOGS}, which means all tests need to be rechecked.
9204 By overriding this variable, you can choose which tests need to be
9205 reconsidered.  For example, you can lazily rerun only those tests which
9206 are outdated, i.e., older than their prerequisite test files, by setting
9207 this variable to the empty value:
9208
9209 @example
9210 env RECHECK_LOGS= make -e check
9211 @end example
9212
9213 @item
9214 @trindex recheck
9215 You can ensure that all tests are rerun which have failed or passed
9216 unexpectedly, by running @code{make recheck} in the test directory.
9217 This convenience target will set @code{RECHECK_LOGS} appropriately
9218 before invoking the main test harness.
9219 @end itemize
9220
9221 @noindent
9222 In order to guarantee an ordering between tests even with @code{make
9223 -j@var{N}}, dependencies between the corresponding @file{.log} files
9224 may be specified through usual @command{make} dependencies.  For example,
9225 the following snippet lets the test named @file{foo-execute.test} depend
9226 upon completion of the test @file{foo-compile.test}:
9227
9228 @example
9229 TESTS = foo-compile.test foo-execute.test
9230 foo-execute.log: foo-compile.log
9231 @end example
9232
9233 @noindent
9234 Please note that this ordering ignores the @emph{results} of required
9235 tests, thus the test @file{foo-execute.test} is run even if the test
9236 @file{foo-compile.test} failed or was skipped beforehand.  Further,
9237 please note that specifying such dependencies currently works only for
9238 tests that end in one of the suffixes listed in @code{TEST_EXTENSIONS}.
9239
9240 Tests without such specified dependencies may be run concurrently with
9241 parallel @command{make -j@var{N}}, so be sure they are prepared for
9242 concurrent execution.
9243
9244 @cindex Unit tests
9245 @c Keep in sync with 'parallel-tests-extra-programs.sh'.
9246 The combination of lazy test execution and correct dependencies between
9247 tests and their sources may be exploited for efficient unit testing
9248 during development.  To further speed up the edit-compile-test cycle, it
9249 may even be useful to specify compiled programs in @code{EXTRA_PROGRAMS}
9250 instead of with @code{check_PROGRAMS}, as the former allows intertwined
9251 compilation and test execution (but note that @code{EXTRA_PROGRAMS} are
9252 not cleaned automatically, @pxref{Uniform}).
9253
9254 The variables @code{TESTS} and @code{XFAIL_TESTS} may contain
9255 conditional parts as well as configure substitutions.  In the latter
9256 case, however, certain restrictions apply: substituted test names
9257 must end with a nonempty test suffix like @file{.test}, so that one of
9258 the inference rules generated by @command{automake} can apply.  For
9259 literal test names, @command{automake} can generate per-target rules
9260 to avoid this limitation.
9261
9262 Please note that it is currently not possible to use @code{$(srcdir)/}
9263 or @code{$(top_srcdir)/} in the @code{TESTS} variable.  This technical
9264 limitation is necessary to avoid generating test logs in the source tree
9265 and has the unfortunate consequence that it is not possible to specify
9266 distributed tests that are themselves generated by means of explicit
9267 rules, in a way that is portable to all @command{make} implementations
9268 (@pxref{Make Target Lookup,,, autoconf, The Autoconf Manual}, the
9269 semantics of FreeBSD and OpenBSD @command{make} conflict with this).
9270 In case of doubt you may want to require to use GNU @command{make},
9271 or work around the issue with inference rules to generate the tests.
9272
9273 @node Custom Test Drivers
9274 @section Custom Test Drivers
9275
9276 @menu
9277 * Overview of Custom Test Drivers Support::
9278 * Declaring Custom Test Drivers::
9279 * API for Custom Test Drivers::
9280 @end menu
9281
9282 @node Overview of Custom Test Drivers Support
9283 @subsection Overview of Custom Test Drivers Support
9284
9285 Starting from Automake version 1.12, the parallel test harness allows
9286 the package authors to use third-party custom test drivers, in case the
9287 default ones are inadequate for their purposes, or do not support their
9288 testing protocol of choice.
9289
9290 A custom test driver is expected to properly run the test programs passed
9291 to it (including the command-line arguments passed to those programs, if
9292 any), to analyze their execution and outcome, to create the @file{.log}
9293 and @file{.trs} files associated to these test runs, and to display the test
9294 results on the console. It is responsibility of the author of the test
9295 driver to ensure that it implements all the above steps meaningfully and
9296 correctly; Automake isn't and can't be of any help here.  On the other
9297 hand, the Automake-provided code for testsuite summary generation offers
9298 support for test drivers allowing several test results per test script,
9299 if they take care to register such results properly (@pxref{Log files
9300 generation and test results recording}).
9301
9302 The exact details of how test scripts' results are to be determined and
9303 analyzed is left to the individual drivers.  Some drivers might only
9304 consider the test script exit status (this is done for example by the
9305 default test driver used by the parallel test harness, described
9306 in the previous section).  Other drivers might implement more complex and
9307 advanced test protocols, which might require them to parse and interpreter
9308 the output emitted by the test script they're running (examples of such
9309 protocols are TAP and SubUnit).
9310
9311 It's very important to note that, even when using custom test drivers,
9312 most of the infrastructure described in the previous section about the
9313 parallel harness remains in place; this includes:
9314
9315 @itemize
9316 @item
9317 list of test scripts defined in @code{TESTS}, and overridable at
9318 runtime through the redefinition of @code{TESTS} or @code{TEST_LOGS};
9319 @item
9320 concurrency through the use of @command{make}'s option @option{-j};
9321 @item
9322 per-test @file{.log} and @file{.trs} files, and generation of a summary
9323 @file{.log} file from them;
9324 @item
9325 @code{recheck} target, @code{RECHECK_LOGS} variable, and lazy reruns
9326 of tests;
9327 @item
9328 inter-test dependencies;
9329 @item
9330 support for @code{check_*} variables (@code{check_PROGRAMS},
9331 @code{check_LIBRARIES}, ...);
9332 @item
9333 use of @code{VERBOSE} environment variable to get verbose output on
9334 testsuite failures;
9335 @item
9336 definition and honoring of @code{TESTS_ENVIRONMENT},
9337 @code{AM_TESTS_ENVIRONMENT} and @code{AM_TESTS_FD_REDIRECT}
9338 variables;
9339 @item
9340 definition of generic and extension-specific @code{LOG_COMPILER} and
9341 @code{LOG_FLAGS} variables.
9342 @end itemize
9343
9344 @noindent
9345 On the other hand, the exact semantics of how (and if) testsuite output
9346 colorization, @code{XFAIL_TESTS}, and hard errors are supported and
9347 handled is left to the individual test drivers.
9348
9349 @c TODO: We should really add a working example in the doc/ directory,
9350 @c TODO: and reference if from here.
9351
9352 @node Declaring Custom Test Drivers
9353 @subsection Declaring Custom Test Drivers
9354
9355 @vindex _LOG_DRIVER
9356 @vindex _LOG_DRIVER_FLAGS
9357 @vindex LOG_DRIVER
9358 @vindex LOG_DRIVER_FLAGS
9359 @vindex @var{ext}_LOG_DRIVER
9360 @vindex @var{ext}_LOG_DRIVER_FLAGS
9361 @vindex AM_@var{ext}_LOG_DRIVER_FLAGS
9362 @vindex AM_LOG_DRIVER_FLAGS
9363 Custom testsuite drivers are declared by defining the make variables
9364 @code{LOG_DRIVER} or @code{@var{ext}_LOG_DRIVER} (where @var{ext} must
9365 be declared in @code{TEST_EXTENSIONS}).  They must be defined to
9366 programs or scripts that will be used to drive the execution, logging,
9367 and outcome report of the tests with corresponding extensions (or of
9368 those with no registered extension in the case of @code{LOG_DRIVER}).
9369 Clearly, multiple distinct test drivers can be declared in the same
9370 @file{Makefile.am}.  Note moreover that the @code{LOG_DRIVER} variables
9371 are @emph{not} a substitute for the @code{LOG_COMPILER} variables: the
9372 two sets of variables can, and often do, usefully and legitimately
9373 coexist.
9374
9375 @c TODO: We should really be able to point to a clarifying example here!
9376
9377 The developer-reserved variable @code{AM_LOG_DRIVER_FLAGS} and the
9378 user-reserved variable @code{LOG_DRIVER_FLAGS} can be used to define
9379 flags that will be passed to each invocation of @code{LOG_DRIVER},
9380 with the user-defined flags obviously taking precedence over the
9381 developer-reserved ones.  Similarly, for each extension @var{ext}
9382 declared in @code{TEST_EXTENSIONS}, flags listed in
9383 @code{AM_@var{ext}_LOG_DRIVER_FLAGS} and
9384 @code{@var{ext}_LOG_DRIVER_FLAGS} will be passed to
9385 invocations of @code{@var{ext}_LOG_DRIVER}.
9386
9387 @node API for Custom Test Drivers
9388 @subsection API for Custom Test Drivers
9389
9390 Note that @emph{the APIs described here are still highly experimental},
9391 and will very likely undergo tightenings and likely also extensive changes
9392 in the future, to accommodate for new features or to satisfy additional
9393 portability requirements.
9394
9395 The main characteristic of these APIs is that they are designed to share
9396 as much infrastructure, semantics, and implementation details as possible
9397 with the parallel test harness and its default driver.
9398
9399 @menu
9400 * Command-line arguments for test drivers::
9401 * Log files generation and test results recording::
9402 * Testsuite progress output::
9403 @end menu
9404
9405 @node Command-line arguments for test drivers
9406 @subsubsection Command-line arguments for test drivers
9407
9408 A custom driver can rely on various command-line options and arguments
9409 being passed to it automatically by the Automake-generated test harness.
9410 It is @emph{mandatory} that it understands all of them (even if the exact
9411 interpretation of the associated semantics can legitimately change
9412 between a test driver and another, and even be a no-op in some drivers).
9413
9414 @noindent
9415 Here is the list of options:
9416
9417 @table @option
9418 @item --test-name=@var{NAME}
9419 The name of the test, with VPATH prefix (if any) removed.  This can have a
9420 suffix and a directory component (as in e.g., @file{sub/foo.test}), and is
9421 mostly meant to be used in console reports about testsuite advancements and
9422 results (@pxref{Testsuite progress output}).
9423 @item --log-file=@file{@var{PATH}.log}
9424 The @file{.log} file the test driver must create (@pxref{Basics of
9425 test metadata}).  If it has a directory component (as in e.g.,
9426 @file{sub/foo.log}), the test harness will ensure that such directory
9427 exists @emph{before} the test driver is called.
9428 @item --trs-file=@file{@var{PATH}.trs}
9429 The @file{.trs} file the test driver must create (@pxref{Basics of
9430 test metadata}).  If it has a directory component (as in e.g.,
9431 @file{sub/foo.trs}), the test harness will ensure that such directory
9432 exists @emph{before} the test driver is called.
9433 @item --color-tests=@{yes|no@}
9434 Whether the console output should be colorized or not (@pxref{Simple
9435 tests and color-tests}, to learn when this option gets activated and
9436 when it doesn't).
9437 @item --expect-failure=@{yes|no@}
9438 Whether the tested program is expected to fail.
9439 @item --enable-hard-errors=@{yes|no@}
9440 Whether ``hard errors'' in the tested program should be treated differently
9441 from normal failures or not (the default should be @code{yes}).  The exact
9442 meaning of ``hard error'' is highly dependent from the test protocols or
9443 conventions in use.
9444 @item --
9445 Explicitly terminate the list of options.
9446 @end table
9447
9448 @noindent
9449 The first non-option argument passed to the test driver is the program to
9450 be run, and all the following ones are command-line options and arguments
9451 for this program.
9452
9453 Note that the exact semantics attached to the @option{--color-tests},
9454 @option{--expect-failure} and @option{--enable-hard-errors} options are
9455 left up to the individual test drivers.  Still, having a behaviour
9456 compatible or at least similar to that provided by the default driver
9457 is advised, as that would offer a better consistency and a more pleasant
9458 user experience.
9459
9460 @node Log files generation and test results recording
9461 @subsubsection Log files generation and test results recording
9462
9463 The test driver must correctly generate the files specified by the
9464 @option{--log-file} and @option{--trs-file} option (even when the tested
9465 program fails or crashes).
9466
9467 The @file{.log} file should ideally contain all the output produced by the
9468 tested program, plus optionally other information that might facilitate
9469 debugging or analysis of bug reports.  Apart from that, its format is
9470 basically free.
9471
9472 The @file{.trs} file is used to register some metadata through the use
9473 of custom reStructuredText fields.  This metadata is expected to be
9474 employed in various ways by the parallel test harness; for example, to
9475 count the test results when printing the testsuite summary, or to decide
9476 which tests to re-run upon @command{make reheck}.  Unrecognized metadata
9477 in a @file{.trs} file is currently ignored by the harness, but this might
9478 change in the future. The list of currently recognized metadata follows.
9479
9480 @table @code
9481
9482 @item :test-result:
9483 @cindex Register test result
9484 @cindex Register test case result
9485 @cindex Test result, registering
9486 @cindex Test case result, registering
9487 @cindex @code{:test-result:}
9488 @cindex reStructuredText field, @code{:test-result:}
9489 The test driver must use this field to register the results of @emph{each}
9490 test case run by a test script file.  Several @code{:test-result:} fields
9491 can be present in the same @file{.trs} file; this is done in order to
9492 support test protocols that allow a single test script to run more test
9493 cases.
9494
9495 @c Keep this in sync with lib/am/check-am:$(TEST_SUITE_LOG).
9496 The only recognized test results are currently @code{PASS}, @code{XFAIL},
9497 @code{SKIP}, @code{FAIL}, @code{XPASS} and @code{ERROR}.  These results,
9498 when declared with @code{:test-result:}, can be optionally followed by
9499 text holding the name and/or a brief description of the corresponding
9500 test; the harness will ignore such extra text when generating
9501 @file{test-suite.log} and preparing the testsuite summary.
9502
9503 @c Keep in sync with 'test-metadata-recheck.sh'.
9504 @item @code{:recheck:}
9505 @cindex :recheck:
9506 @cindex reStructuredText field, @code{:recheck:}
9507 If this field is present and defined to @code{no}, then the corresponding
9508 test script will @emph{not} be run upon a @command{make recheck}.  What
9509 happens when two or more @code{:recheck:} fields are present in the same
9510 @file{.trs} file is undefined behaviour.
9511
9512 @c Keep in sync with 'test-metadata-global-log.sh'.
9513 @item @code{:copy-in-global-log:}
9514 @cindex :copy-in-global-log:
9515 @cindex reStructuredText field, @code{:copy-in-global-log:}
9516 If this field is present and defined to @code{no}, then the content
9517 of the @file{.log} file will @emph{not} be copied into the global
9518 @file{test-suite.log}.  We allow to forsake such copying because, while
9519 it can be useful in debugging and analysis of bug report, it can also be
9520 just a waste of space in normal situations, e.g., when a test script is
9521 successful.  What happens when two or more @code{:copy-in-global-log:}
9522 fields are present in the same @file{.trs} file is undefined behaviour.
9523
9524 @c Keep in sync with 'test-metadata-global-result.sh'.
9525 @item @code{:test-global-result:}
9526 @cindex :test-global-result:
9527 @cindex reStructuredText field, @code{:test-global-result:}
9528 This is used to declare the "global result" of the script.  Currently,
9529 the value of this field is needed only to be reported (more or less
9530 verbatim) in the generated global log file @code{$(TEST_SUITE_LOG)},
9531 so it's quite free-form.  For example, a test script which run 10 test
9532 cases, 6 of which pass and 4 of which are skipped, could reasonably have
9533 a @code{PASS/SKIP} value for this field, while a test script which run
9534 19 successful tests and one failed test could have an @code{ALMOST
9535 PASSED} value.  What happens when two or more @code{:test-global-result:}
9536 fields are present in the same @file{.trs} file is undefined behaviour.
9537 @end table
9538
9539 @noindent
9540 Let's see a small example.  Assume a @file{.trs} file contains the
9541 following lines:
9542
9543 @example
9544 :test-result: PASS server starts
9545 :global-log-copy: no
9546 :test-result: PASS HTTP/1.1 request
9547 :test-result: FAIL HTTP/1.0 request
9548 :recheck: yes
9549 :test-result: SKIP HTTPS request (TLS library wasn't available)
9550 :test-result: PASS server stops
9551 @end example
9552
9553 @noindent
9554 Then the corresponding test script will be re-run by @command{make check},
9555 will contribute with @emph{five} test results to the testsuite summary
9556 (three of these tests being successful, one failed, and one skipped), and
9557 the content of the corresponding @file{.log} file will @emph{not} be
9558 copied in the global log file @file{test-suite.log}.
9559
9560 @node Testsuite progress output
9561 @subsubsection Testsuite progress output
9562
9563 A custom test driver also has the task of displaying, on the standard
9564 output, the test results as soon as they become available.  Depending on
9565 the protocol in use, it can also display the reasons for failures and
9566 skips, and, more generally, any useful diagnostic output (but remember
9567 that each line on the screen is precious, so that cluttering the screen
9568 with overly verbose information is bad idea).  The exact format of this
9569 progress output is left up to the test driver; in fact, a custom test
9570 driver might @emph{theoretically} even decide not to do any such report,
9571 leaving it all to the testsuite summary (that would be a very lousy idea,
9572 of course, and serves only to illustrate the flexibility that is
9573 granted here).
9574
9575 Remember that consistency is good; so, if possible, try to be consistent
9576 with the output of the built-in Automake test drivers, providing a similar
9577 ``look & feel''.  In particular, the testsuite progress output should be
9578 colorized when the @option{--color-tests} is passed to the driver.  On the
9579 other end, if you are using a known and widespread test protocol with
9580 well-established implementations, being consistent with those
9581 implementations' output might be a good idea too.
9582
9583 @c TODO: Give an example, maybe inspired to py.test-style output.
9584 @c TODO: That is a good idea because it shows a test driver that allows
9585 @c TODO: for different levels of verbosity in the progress output (could
9586 @c TODO: be implemented either using a driver cmdline flag, or an
9587 @c TODO: environment variable, or both).
9588
9589 @node Using the TAP test protocol
9590 @section Using the TAP test protocol
9591
9592 @menu
9593 * Introduction to TAP::
9594 * Use TAP with the Automake test harness::
9595 * Incompatibilities with other TAP parsers and drivers::
9596 * Links and external resources on TAP::
9597 @end menu
9598
9599 @node Introduction to TAP
9600 @subsection Introduction to TAP
9601
9602 TAP, the Test Anything Protocol, is a simple text-based interface between
9603 testing modules or programs and a test harness.  The tests (also called
9604 ``TAP producers'' in this context) write test results in a simple format
9605 on standard output; a test harness (also called ``TAP consumer'') will
9606 parse and interpret these results, and properly present them to the user,
9607 and/or register them for later analysis.  The exact details of how this
9608 is accomplished can vary among different test harnesses.  The Automake
9609 harness will present the results on the console in the usual
9610 fashion (@pxref{Testsuite progress on console}), and will use the
9611 @file{.trs} files (@pxref{Basics of test metadata}) to store the test
9612 results and related metadata.  Apart from that, it will try to remain
9613 as much compatible as possible with pre-existing and widespread utilities,
9614 such as the @uref{http://search.cpan.org/~andya/Test-Harness/bin/prove,
9615 @command{prove} utility}, at least for the simpler usages.
9616
9617 TAP started its life as part of the test harness for Perl, but today
9618 it has been (mostly) standardized, and has various independent
9619 implementations in different languages; among them, C, C++, Perl,
9620 Python, PHP, and Java.  For a semi-official specification of the
9621 TAP protocol, please refer to the documentation of
9622 @uref{http://search.cpan.org/~petdance/Test-Harness/lib/Test/Harness/TAP.pod,
9623       @samp{Test::Harness::TAP}}.
9624
9625 The most relevant real-world usages of TAP are obviously in the testsuites
9626 of @command{perl} and of many perl modules.  Still, also other important
9627 third-party packages, such as @uref{http://git-scm.com/, @command{git}},
9628 use TAP in their testsuite.
9629
9630 @node Use TAP with the Automake test harness
9631 @subsection Use TAP with the Automake test harness
9632
9633 Currently, the TAP driver that comes with Automake requires some by-hand
9634 steps on the developer's part (this situation should hopefully be improved
9635 in future Automake versions).  You'll have to grab the @file{tap-driver.sh}
9636 script from the Automake distribution by hand, copy it in your source tree,
9637 add a call to @code{AC_PROG_AWK} in @file{configure.ac} to search for a
9638 proper awk program, and use the Automake support for third-party test
9639 drivers to instruct the harness to use the @file{tap-driver.sh} script
9640 and that awk program to run your TAP-producing tests.  See the example
9641 below for clarification.
9642
9643 Apart from the options common to all the Automake test drivers
9644 (@pxref{Command-line arguments for test drivers}), the @file{tap-driver.sh}
9645 supports the following options, whose names are chosen for enhanced
9646 compatibility with the @command{prove} utility.
9647
9648 @table @option
9649 @c Keep in sync with 'tap-exit.sh' and 'tap-signal.tap'.
9650 @item --ignore-exit
9651 Causes the test driver to ignore the exit status of the test scripts;
9652 by default, the driver will report an error if the script exits with a
9653 non-zero status.  This option has effect also on non-zero exit statuses
9654 due to termination by a signal.
9655 @item --comments
9656 Instruct the test driver to display TAP diagnostic (i.e., lines beginning
9657 with the @samp{#} character) in the testsuite progress output too; by
9658 default, TAP diagnostic is only copied to the @file{.log} file.
9659 @item --no-comments
9660 Revert the effects of @option{--comments}.
9661 @item --merge
9662 Instruct the test driver to merge the test scripts' standard error into
9663 their standard output.  This is necessary if you want to ensure that
9664 diagnostics from the test scripts are displayed in the correct order
9665 relative to test results; this can be of great help in debugging
9666 (especially if your test scripts are shell scripts run with shell
9667 tracing active).  As a downside, this option might cause the test
9668 harness to get confused if anything that appears on standard error
9669 looks like a test result.
9670 @item --no-merge
9671 Revert the effects of @option{--merge}.
9672 @item --diagnostic-string=@var{STRING}
9673 Change the string that introduces TAP diagnostic from the default value
9674 of ``@code{#}'' to @code{@var{STRING}}.  This can be useful if your
9675 TAP-based test scripts produce verbose output on which they have limited
9676 control (because, say, the output comes from other tools invoked in the
9677 scripts), and it might contain text that gets spuriously interpreted as
9678 TAP diagnostic: such an issue can be solved by redefining the string that
9679 activates TAP diagnostic to a value you know won't appear by chance in
9680 the tests' output.  Note however that this feature is non-standard, as
9681 the ``official'' TAP protocol does not allow for such a customization; so
9682 don't use it if you can avoid it.
9683 @end table
9684
9685 @noindent
9686 Here is an example of how the TAP driver can be set up and used.
9687
9688 @c Keep in sync with tap-doc2.sh
9689 @example
9690 % @kbd{cat configure.ac}
9691 AC_INIT([GNU Try Tap], [1.0], [bug-automake@@gnu.org])
9692 AC_CONFIG_AUX_DIR([build-aux])
9693 AM_INIT_AUTOMAKE([foreign -Wall -Werror])
9694 AC_CONFIG_FILES([Makefile])
9695 AC_REQUIRE_AUX_FILE([tap-driver.sh])
9696 AC_PROG_AWK
9697 AC_OUTPUT
9698
9699 % @kbd{cat Makefile.am}
9700 TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
9701                   $(top_srcdir)/build-aux/tap-driver.sh
9702 TESTS = foo.test bar.test baz.test
9703 EXTRA_DIST = $(TESTS)
9704
9705 % @kbd{cat foo.test}
9706 #!/bin/sh
9707 echo 1..4 # Number of tests to be executed.
9708 echo 'ok 1 - Swallows fly'
9709 echo 'not ok 2 - Caterpillars fly # TODO metamorphosis in progress'
9710 echo 'ok 3 - Pigs fly # SKIP not enough acid'
9711 echo '# I just love word plays ...'
9712 echo 'ok 4 - Flies fly too :-)'
9713
9714 % @kbd{cat bar.test}
9715 #!/bin/sh
9716 echo 1..3
9717 echo 'not ok 1 - Bummer, this test has failed.'
9718 echo 'ok 2 - This passed though.'
9719 echo 'Bail out! Ennui kicking in, sorry...'
9720 echo 'ok 3 - This will not be seen.'
9721
9722 % @kbd{cat baz.test}
9723 #!/bin/sh
9724 echo 1..1
9725 echo ok 1
9726 # Exit with error, even if all the tests have been successful.
9727 exit 7
9728
9729 % @kbd{cp @var{PREFIX}/share/automake-@var{APIVERSION}/tap-driver.pl .}
9730 % @kbd{autoreconf -vi && ./configure && make check}
9731 ...
9732 PASS: foo.test 1 - Swallows fly
9733 XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
9734 SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
9735 PASS: foo.test 4 - Flies fly too :-)
9736 FAIL: bar.test 1 - Bummer, this test has failed.
9737 PASS: bar.test 2 - This passed though.
9738 ERROR: bar.test - Bail out! Ennui kicking in, sorry...
9739 PASS: baz.test 1
9740 ERROR: baz.test - exited with status 7
9741 ...
9742 Please report to bug-automake@@gnu.org
9743 ...
9744 % @kbd{echo exit status: $?}
9745 exit status: 1
9746
9747 @c Keep the "skewed" indentation below, it produces pretty PDF output.
9748 % @kbd{env TEST_LOG_DRIVER_FLAGS='--comments --ignore-exit' \
9749       TESTS='foo.test baz.test' make -e check}
9750 ...
9751 PASS: foo.test 1 - Swallows fly
9752 XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
9753 SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
9754 # foo.test: I just love word plays...
9755 PASS: foo.test 4 - Flies fly too :-)
9756 PASS: baz.test 1
9757 ...
9758 % @kbd{echo exit status: $?}
9759 exit status: 0
9760 @end example
9761
9762 @node Incompatibilities with other TAP parsers and drivers
9763 @subsection Incompatibilities with other TAP parsers and drivers
9764
9765 For implementation or historical reasons, the TAP driver and harness as
9766 implemented by Automake have some minors incompatibilities with the
9767 mainstream versions, which you should be aware of.
9768
9769 @itemize @bullet
9770 @item
9771 A @code{Bail out!} directive doesn't stop the whole testsuite, but only
9772 the test script it occurs in.  This doesn't follow TAP specifications,
9773 but on the other hand it maximizes compatibility (and code sharing) with
9774 the ``hard error'' concept of the default testsuite driver.
9775 @item
9776 The @code{version} and @code{pragma} directives are not supported.
9777 @item
9778 The @option{--diagnostic-string} option of our driver allows to modify
9779 the string that introduces TAP diagnostic from the default value
9780 of ``@code{#}''.  The standard TAP protocol has currently no way to
9781 allow this, so if you use it your diagnostic will be lost to more
9782 compliant tools like @command{prove} and @code{Test::Harness}
9783 @item
9784 And there are probably some other small and yet undiscovered
9785 incompatibilities, especially in corner cases or with rare usages.
9786 @end itemize
9787
9788 @node Links and external resources on TAP
9789 @subsection Links and external resources on TAP
9790
9791 @noindent
9792 Here are some links to more extensive official or third-party
9793 documentation and resources about the TAP protocol and related
9794 tools and libraries.
9795 @itemize @bullet
9796 @item
9797 @uref{http://search.cpan.org/~petdance/Test-Harness/lib/Test/Harness/TAP.pod,
9798       @samp{Test::Harness::TAP}},
9799 the (mostly) official documentation about the TAP format and protocol.
9800 @item
9801 @uref{http://search.cpan.org/~andya/Test-Harness/bin/prove,
9802       @command{prove}},
9803 the most famous command-line TAP test driver, included in the distribution
9804 of @command{perl} and
9805 @uref{http://search.cpan.org/~andya/Test-Harness/lib/Test/Harness.pm,
9806       @samp{Test::Harness}}.
9807 @item
9808 The @uref{http://testanything.org/wiki/index.php/Main_Page,TAP wiki}.
9809 @item
9810 A ``gentle introduction'' to testing for perl coders:
9811 @uref{http://search.cpan.org/dist/Test-Simple/lib/Test/Tutorial.pod,
9812       @samp{Test::Tutorial}}.
9813 @item
9814 @uref{http://search.cpan.org/~mschwern/Test-Simple/lib/Test/Simple.pm,
9815       @samp{Test::Simple}}
9816 and
9817 @uref{http://search.cpan.org/~mschwern/Test-Simple/lib/Test/More.pm,
9818       @samp{Test::More}},
9819 the standard perl testing libraries, which are based on TAP.
9820 @item
9821 @uref{http://www.eyrie.org/~eagle/software/c-tap-harness/,C TAP Harness},
9822 a C-based project implementing both a TAP producer and a TAP consumer.
9823 @item
9824 @uref{http://www.tap4j.org/,tap4j},
9825 a Java-based project implementing both a TAP producer and a TAP consumer.
9826 @end itemize
9827
9828 @node DejaGnu Tests
9829 @section DejaGnu Tests
9830
9831 If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @command{dejagnu}} appears in
9832 @code{AUTOMAKE_OPTIONS}, then a @command{dejagnu}-based test suite is
9833 assumed.  The variable @code{DEJATOOL} is a list of names that are
9834 passed, one at a time, as the @option{--tool} argument to
9835 @command{runtest} invocations; it defaults to the name of the package.
9836
9837 The variable @code{RUNTESTDEFAULTFLAGS} holds the @option{--tool} and
9838 @option{--srcdir} flags that are passed to dejagnu by default; this can be
9839 overridden if necessary.
9840 @vindex RUNTESTDEFAULTFLAGS
9841
9842 The variables @code{EXPECT} and @code{RUNTEST} can
9843 also be overridden to provide project-specific values.  For instance,
9844 you will need to do this if you are testing a compiler toolchain,
9845 because the default values do not take into account host and target
9846 names.
9847 @opindex dejagnu
9848 @vindex DEJATOOL
9849 @vindex EXPECT
9850 @vindex RUNTEST
9851
9852 The contents of the variable @code{RUNTESTFLAGS} are passed to the
9853 @code{runtest} invocation.  This is considered a ``user variable''
9854 (@pxref{User Variables}).  If you need to set @command{runtest} flags in
9855 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
9856 @vindex RUNTESTFLAGS
9857 @vindex AM_RUNTESTFLAGS
9858
9859 @cindex @file{site.exp}
9860 Automake will generate rules to create a local @file{site.exp} file,
9861 defining various variables detected by @command{configure}.  This file
9862 is automatically read by DejaGnu.  It is OK for the user of a package
9863 to edit this file in order to tune the test suite.  However this is
9864 not the place where the test suite author should define new variables:
9865 this should be done elsewhere in the real test suite code.
9866 Especially, @file{site.exp} should not be distributed.
9867
9868 Still, if the package author has legitimate reasons to extend
9869 @file{site.exp} at @command{make} time, he can do so by defining
9870 the variable @code{EXTRA_DEJAGNU_SITE_CONFIG}; the files listed
9871 there will be considered @file{site.exp} prerequisites, and their
9872 content will be appended to it (in the same order in which they
9873 appear in @code{EXTRA_DEJAGNU_SITE_CONFIG}).  Note that files are
9874 @emph{not} distributed by default.
9875
9876 For more information regarding DejaGnu test suites, see @ref{Top, , ,
9877 dejagnu, The DejaGnu Manual}.
9878
9879 @node Install Tests
9880 @section Install Tests
9881
9882 The @code{installcheck} target is available to the user as a way to
9883 run any tests after the package has been installed.  You can add tests
9884 to this by writing an @code{installcheck-local} rule.
9885
9886
9887 @node Rebuilding
9888 @chapter Rebuilding Makefiles
9889 @cindex rebuild rules
9890
9891 Automake generates rules to automatically rebuild @file{Makefile}s,
9892 @file{configure}, and other derived files like @file{Makefile.in}.
9893
9894 @acindex AM_MAINTAINER_MODE
9895 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.ac}, then
9896 these automatic rebuilding rules are only enabled in maintainer mode.
9897
9898 @vindex CONFIG_STATUS_DEPENDENCIES
9899 @vindex CONFIGURE_DEPENDENCIES
9900 @cindex @file{version.sh}, example
9901 @cindex @file{version.m4}, example
9902
9903 Sometimes it is convenient to supplement the rebuild rules for
9904 @file{configure} or @file{config.status} with additional dependencies.
9905 The variables @code{CONFIGURE_DEPENDENCIES} and
9906 @code{CONFIG_STATUS_DEPENDENCIES} can be used to list these extra
9907 dependencies.  These variables should be defined in all
9908 @file{Makefile}s of the tree (because these two rebuild rules are
9909 output in all them), so it is safer and easier to @code{AC_SUBST} them
9910 from @file{configure.ac}.  For instance, the following statement will
9911 cause @file{configure} to be rerun each time @file{version.sh} is
9912 changed.
9913
9914 @c Keep in sync with remake-config-status-dependencies.sh
9915 @example
9916 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh'])
9917 @end example
9918
9919 @noindent
9920 Note the @samp{$(top_srcdir)/} in the file name.  Since this variable
9921 is to be used in all @file{Makefile}s, its value must be sensible at
9922 any level in the build hierarchy.
9923
9924 Beware not to mistake @code{CONFIGURE_DEPENDENCIES} for
9925 @code{CONFIG_STATUS_DEPENDENCIES}.
9926
9927 @c Keep in sync with remake-configure-dependencies.sh
9928 @code{CONFIGURE_DEPENDENCIES} adds dependencies to the
9929 @file{configure} rule, whose effect is to run @command{autoconf}.  This
9930 variable should be seldom used, because @command{automake} already tracks
9931 @code{m4_include}d files.  However it can be useful when playing
9932 tricky games with @code{m4_esyscmd} or similar non-recommendable
9933 macros with side effects.  Be also aware that interactions of this
9934 variable with the @ref{Autom4te Cache, , autom4te cache, autoconf,
9935 The Autoconf Manual} are quite problematic and can cause subtle
9936 breakage, so you might want to disable the cache if you want to use
9937 @code{CONFIGURE_DEPENDENCIES}.
9938
9939 @code{CONFIG_STATUS_DEPENDENCIES} adds dependencies to the
9940 @file{config.status} rule, whose effect is to run @file{configure}.
9941 This variable should therefore carry any non-standard source that may
9942 be read as a side effect of running @command{configure}, like @file{version.sh}
9943 in the example above.
9944
9945 Speaking of @file{version.sh} scripts, we recommend against them
9946 today.  They are mainly used when the version of a package is updated
9947 automatically by a script (e.g., in daily builds).  Here is what some
9948 old-style @file{configure.ac}s may look like:
9949
9950 @example
9951 AC_INIT
9952 . $srcdir/version.sh
9953 AM_INIT_AUTOMAKE([name], $VERSION_NUMBER)
9954 @dots{}
9955 @end example
9956
9957 @noindent
9958 Here, @file{version.sh} is a shell fragment that sets
9959 @code{VERSION_NUMBER}.  The problem with this example is that
9960 @command{automake} cannot track dependencies (listing @file{version.sh}
9961 in @command{CONFIG_STATUS_DEPENDENCIES}, and distributing this file is up
9962 to the user), and that it uses the obsolete form of @code{AC_INIT} and
9963 @code{AM_INIT_AUTOMAKE}.  Upgrading to the new syntax is not
9964 straightforward, because shell variables are not allowed in
9965 @code{AC_INIT}'s arguments.  We recommend that @file{version.sh} be
9966 replaced by an M4 file that is included by @file{configure.ac}:
9967
9968 @example
9969 m4_include([version.m4])
9970 AC_INIT([name], VERSION_NUMBER)
9971 AM_INIT_AUTOMAKE
9972 @dots{}
9973 @end example
9974
9975 @noindent
9976 Here @file{version.m4} could contain something like
9977 @samp{m4_define([VERSION_NUMBER], [1.2])}.  The advantage of this
9978 second form is that @command{automake} will take care of the
9979 dependencies when defining the rebuild rule, and will also distribute
9980 the file automatically.  An inconvenience is that @command{autoconf}
9981 will now be rerun each time the version number is bumped, when only
9982 @file{configure} had to be rerun in the previous setup.
9983
9984
9985 @node Options
9986 @chapter Changing Automake's Behavior
9987
9988 @menu
9989 * Options generalities::        Semantics of Automake option
9990 * List of Automake options::    A comprehensive list of Automake options
9991 @end menu
9992
9993 @node Options generalities
9994 @section Options generalities
9995
9996 Various features of Automake can be controlled by options.  Except where
9997 noted otherwise, options can be specified in one of several ways.  Most
9998 options can be applied on a per-@file{Makefile} basis when listed in a
9999 special @file{Makefile} variable named @code{AUTOMAKE_OPTIONS}.  Some
10000 of these options only make sense when specified in the toplevel
10001 @file{Makefile.am} file.  Options are applied globally to all processed
10002 @file{Makefile} files when listed in the first argument of
10003 @code{AM_INIT_AUTOMAKE} in @file{configure.ac}, and some options which
10004 require changes to the @command{configure} script can only be specified
10005 there.  These are annotated below.
10006
10007 As a general rule, options specified in @code{AUTOMAKE_OPTIONS} take
10008 precedence over those specified in @code{AM_INIT_AUTOMAKE}, which in
10009 turn take precedence over those specified on the command line.
10010
10011 Also, some care must be taken about the interactions among strictness
10012 level and warning categories.  As a general rule, strictness-implied
10013 warnings are overridden by those specified by explicit options.  For
10014 example, even if @samp{portability} warnings are disabled by default
10015 in @option{foreign} strictness, an usage like this will end up enabling
10016 them:
10017
10018 @example
10019 AUTOMAKE_OPTIONS = -Wportability foreign
10020 @end example
10021
10022 However, a strictness level specified in a higher-priority context
10023 will override all the explicit warnings specified in a lower-priority
10024 context.  For example, if @file{configure.ac} contains:
10025
10026 @example
10027 AM_INIT_AUTOMAKE([-Wportability])
10028 @end example
10029
10030 @noindent
10031 and @file{Makefile.am} contains:
10032
10033 @example
10034 AUTOMAKE_OPTIONS = foreign
10035 @end example
10036
10037 @noindent
10038 then @samp{portability} warnings will be @emph{disabled} in
10039 @file{Makefile.am}.
10040
10041 @node List of Automake options
10042 @section List of Automake options
10043
10044 @vindex AUTOMAKE_OPTIONS
10045
10046 @table @asis
10047 @item @option{gnits}
10048 @itemx @option{gnu}
10049 @itemx @option{foreign}
10050 @cindex Option, @option{gnits}
10051 @cindex Option, @option{gnu}
10052 @cindex Option, @option{foreign}
10053 @opindex gnits
10054 @opindex gnu
10055 @opindex foreign
10056
10057 Set the strictness as appropriate.  The @option{gnits} option also
10058 implies options @option{readme-alpha} and @option{check-news}.
10059
10060 @item @option{check-news}
10061 @cindex Option, @option{check-news}
10062 @opindex check-news
10063 Cause @samp{make dist} to fail unless the current version number appears
10064 in the first few lines of the @file{NEWS} file.
10065
10066 @item @option{dejagnu}
10067 @cindex Option, @option{dejagnu}
10068 @opindex dejagnu
10069 Cause @command{dejagnu}-specific rules to be generated.  @xref{DejaGnu Tests}.
10070
10071 @item @option{dist-bzip2}
10072 @cindex Option, @option{dist-bzip2}
10073 @opindex dist-bzip2
10074 Hook @code{dist-bzip2} to @code{dist}.
10075 @trindex dist-bzip2
10076
10077 @item @option{dist-lzip}
10078 @cindex Option, @option{dist-lzip}
10079 @opindex dist-lzip
10080 Hook @code{dist-lzip} to @code{dist}.
10081 @trindex dist-lzip
10082
10083 @item @option{dist-xz}
10084 @cindex Option, @option{dist-xz}
10085 @opindex dist-xz
10086 Hook @code{dist-xz} to @code{dist}.
10087 @trindex dist-xz
10088
10089 @item @option{dist-zip}
10090 @cindex Option, @option{dist-zip}
10091 @opindex dist-zip
10092 Hook @code{dist-zip} to @code{dist}.
10093 @trindex dist-zip
10094
10095 @item @option{dist-shar}
10096 @cindex Option, @option{dist-shar}
10097 @opindex dist-shar
10098 Hook @code{dist-shar} to @code{dist}.  Use of this option
10099 is discouraged, as the @samp{shar} format is obsolescent and
10100 problematic.
10101 @trindex dist-shar
10102
10103 @item @option{dist-tarZ}
10104 @cindex Option, @option{dist-tarZ}
10105 @opindex dist-tarZ
10106 Hook @code{dist-tarZ} to @code{dist}.  Use of this option
10107 is discouraged, as the @samp{compress} program is obsolete.
10108 @trindex dist-tarZ
10109
10110 @item @option{filename-length-max=99}
10111 @cindex Option, @option{filename-length-max=99}
10112 @opindex filename-length-max=99
10113 Abort if file names longer than 99 characters are found during
10114 @samp{make dist}.  Such long file names are generally considered not to
10115 be portable in tarballs.  See the @option{tar-v7} and @option{tar-ustar}
10116 options below.  This option should be used in the top-level
10117 @file{Makefile.am} or as an argument of @code{AM_INIT_AUTOMAKE} in
10118 @file{configure.ac}, it will be ignored otherwise.  It will also be
10119 ignored in sub-packages of nested packages (@pxref{Subpackages}).
10120
10121 @item @option{no-define}
10122 @cindex Option, @option{no-define}
10123 @opindex no-define
10124 This option is meaningful only when passed as an argument to
10125 @code{AM_INIT_AUTOMAKE}.  It will prevent the @code{PACKAGE} and
10126 @code{VERSION} variables from being @code{AC_DEFINE}d.
10127
10128 @item @option{no-dependencies}
10129 @cindex Option, @option{no-dependencies}
10130 @opindex no-dependencies
10131 This is similar to using @option{--ignore-deps} on the command line,
10132 but is useful for those situations where you don't have the necessary
10133 bits to make automatic dependency tracking work
10134 (@pxref{Dependencies}).  In this case the effect is to effectively
10135 disable automatic dependency tracking.
10136
10137 @item @option{no-dist}
10138 @cindex Option, @option{no-dist}
10139 @opindex no-dist
10140 Don't emit any code related to @code{dist} target.  This is useful
10141 when a package has its own method for making distributions.
10142
10143 @item @option{no-dist-gzip}
10144 @cindex Option, @option{no-dist-gzip}
10145 @opindex no-dist-gzip
10146 Do not hook @code{dist-gzip} to @code{dist}.
10147 @trindex no-dist-gzip
10148
10149 @item @option{no-exeext}
10150 @cindex Option, @option{no-exeext}
10151 @opindex no-exeext
10152 If your @file{Makefile.am} defines a rule for target @code{foo}, it
10153 will override a rule for a target named @samp{foo$(EXEEXT)}.  This is
10154 necessary when @code{EXEEXT} is found to be empty.  However, by
10155 default @command{automake} will generate an error for this use.  The
10156 @option{no-exeext} option will disable this error.  This is intended for
10157 use only where it is known in advance that the package will not be
10158 ported to Windows, or any other operating system using extensions on
10159 executables.
10160
10161 @item @option{no-installinfo}
10162 @cindex Option, @option{no-installinfo}
10163 @opindex no-installinfo
10164 The generated @file{Makefile.in} will not cause info pages to be built
10165 or installed by default.  However, @code{info} and @code{install-info}
10166 targets will still be available.  This option is disallowed at
10167 @option{gnu} strictness and above.
10168 @trindex info
10169 @trindex install-info
10170
10171 @item @option{no-installman}
10172 @cindex Option, @option{no-installman}
10173 @opindex no-installman
10174 The generated @file{Makefile.in} will not cause man pages to be
10175 installed by default.  However, an @code{install-man} target will still
10176 be available for optional installation.  This option is disallowed at
10177 @option{gnu} strictness and above.
10178 @trindex install-man
10179
10180 @item @option{nostdinc}
10181 @cindex Option, @option{nostdinc}
10182 @opindex nostdinc
10183 This option can be used to disable the standard @option{-I} options that
10184 are ordinarily automatically provided by Automake.
10185
10186 @item @option{no-texinfo.tex}
10187 @cindex Option, @option{no-texinfo.tex}
10188 @opindex no-texinfo.tex
10189 Don't require @file{texinfo.tex}, even if there are texinfo files in
10190 this directory.
10191
10192 @item @option{serial-tests}
10193 @cindex Option, @option{serial-tests}
10194 @opindex serial-tests
10195 Enable the older serial test suite harness for @code{TESTS} (@pxref{Serial
10196 Test Harness}, for more information).
10197
10198 @item @option{parallel-tests}
10199 @cindex Option, @option{parallel-tests}
10200 @opindex parallel-tests
10201 Enable test suite harness for @code{TESTS} that can run tests in parallel
10202 (@pxref{Parallel Test Harness}, for more information).  This option is
10203 only kept for backward-compatibility, since the parallel test harness is
10204 the default now.
10205
10206 @item @option{readme-alpha}
10207 @cindex Option, @option{readme-alpha}
10208 @opindex readme-alpha
10209 If this release is an alpha release, and the file @file{README-alpha}
10210 exists, then it will be added to the distribution.  If this option is
10211 given, version numbers are expected to follow one of two forms.  The
10212 first form is @samp{@var{major}.@var{minor}.@var{alpha}}, where each
10213 element is a number; the final period and number should be left off for
10214 non-alpha releases.  The second form is
10215 @samp{@var{major}.@var{minor}@var{alpha}}, where @var{alpha} is a
10216 letter; it should be omitted for non-alpha releases.
10217
10218 @item @option{std-options}
10219 @cindex Options, @option{std-options}
10220 @cindex @samp{make installcheck}, testing @option{--help} and @option{--version}
10221 @cindex @option{--help} check
10222 @cindex @option{--version} check
10223 @opindex std-options
10224
10225 Make the @code{installcheck} rule check that installed scripts and
10226 programs support the @option{--help} and @option{--version} options.
10227 This also provides a basic check that the program's
10228 run-time dependencies are satisfied after installation.
10229
10230 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
10231 In a few situations, programs (or scripts) have to be exempted from this
10232 test.  For instance, @command{false} (from GNU coreutils) is never
10233 successful, even for @option{--help} or @option{--version}.  You can list
10234 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
10235 Programs (not scripts) listed in this variable should be suffixed by
10236 @samp{$(EXEEXT)} for the sake of Windows or OS/2.  For instance, suppose we
10237 build @file{false} as a program but @file{true.sh} as a script, and that
10238 neither of them support @option{--help} or @option{--version}:
10239
10240 @example
10241 AUTOMAKE_OPTIONS = std-options
10242 bin_PROGRAMS = false ...
10243 bin_SCRIPTS = true.sh ...
10244 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
10245 @end example
10246
10247 @item @option{subdir-objects}
10248 @cindex Options, @option{subdir-objects}
10249 @opindex subdir-objects
10250 If this option is specified, then objects are placed into the
10251 subdirectory of the build directory corresponding to the subdirectory of
10252 the source file.  For instance, if the source file is
10253 @file{subdir/file.cxx}, then the output file would be
10254 @file{subdir/file.o}.
10255
10256 In order to use this option with C sources, you should add
10257 @code{AM_PROG_CC_C_O} to @file{configure.ac}.
10258
10259 @anchor{tar-formats}
10260 @item @option{tar-v7}
10261 @itemx @option{tar-ustar}
10262 @itemx @option{tar-pax}
10263 @cindex Option, @option{tar-v7}
10264 @cindex Option, @option{tar-ustar}
10265 @cindex Option, @option{tar-pax}
10266 @cindex @command{tar} formats
10267 @cindex v7 @command{tar} format
10268 @cindex ustar format
10269 @cindex pax format
10270 @opindex tar-v7
10271 @opindex tar-ustar
10272 @opindex tar-pax
10273
10274 These three mutually exclusive options select the tar format to use
10275 when generating tarballs with @samp{make dist}.  (The tar file created
10276 is then compressed according to the set of @option{no-dist-gzip},
10277 @option{dist-bzip2}, @option{dist-lzip}, @option{dist-xz} and
10278 @option{dist-tarZ} options in use.)
10279
10280 These options must be passed as arguments to @code{AM_INIT_AUTOMAKE}
10281 (@pxref{Macros}) because they can require additional configure checks.
10282 Automake will complain if it sees such options in an
10283 @code{AUTOMAKE_OPTIONS} variable.
10284
10285 @option{tar-v7} selects the old V7 tar format.  This is the historical
10286 default.  This antiquated format is understood by all tar
10287 implementations and supports file names with up to 99 characters.  When
10288 given longer file names some tar implementations will diagnose the
10289 problem while other will generate broken tarballs or use non-portable
10290 extensions.  Furthermore, the V7 format cannot store empty
10291 directories.  When using this format, consider using the
10292 @option{filename-length-max=99} option to catch file names too long.
10293
10294 @option{tar-ustar} selects the ustar format defined by POSIX
10295 1003.1-1988.  This format is believed to be old enough to be portable.
10296 It fully supports empty directories.  It can store file names with up
10297 to 256 characters, provided that the file name can be split at
10298 directory separator in two parts, first of them being at most 155
10299 bytes long.  So, in most cases the maximum file name length will be
10300 shorter than 256 characters.  However you may run against broken tar
10301 implementations that incorrectly handle file names longer than 99
10302 characters (please report them to @email{@value{PACKAGE_BUGREPORT}} so we
10303 can document this accurately).
10304
10305 @option{tar-pax} selects the new pax interchange format defined by POSIX
10306 1003.1-2001.  It does not limit the length of file names.  However,
10307 this format is very young and should probably be restricted to
10308 packages that target only very modern platforms.  There are moves to
10309 change the pax format in an upward-compatible way, so this option may
10310 refer to a more recent version in the future.
10311
10312 @xref{Formats, , Controlling the Archive Format, tar, GNU Tar}, for
10313 further discussion about tar formats.
10314
10315 @command{configure} knows several ways to construct these formats.  It
10316 will not abort if it cannot find a tool up to the task (so that the
10317 package can still be built), but @samp{make dist} will fail.
10318
10319 @item @var{version}
10320 @cindex Option, @var{version}
10321 A version number (e.g., @samp{0.30}) can be specified.  If Automake is not
10322 newer than the version specified, creation of the @file{Makefile.in}
10323 will be suppressed.
10324
10325 @item @option{-W@var{category}} or @option{--warnings=@var{category}}
10326 @cindex Option, warnings
10327 @cindex Option, @option{-W@var{category}}
10328 @cindex Option, @option{--warnings=@var{category}}
10329 These options behave exactly like their command-line counterpart
10330 (@pxref{automake Invocation}).  This allows you to enable or disable some
10331 warning categories on a per-file basis.  You can also setup some warnings
10332 for your entire project; for instance, try @samp{AM_INIT_AUTOMAKE([-Wall])}
10333 in your @file{configure.ac}.
10334
10335 @end table
10336
10337 Unrecognized options are diagnosed by @command{automake}.
10338
10339 If you want an option to apply to all the files in the tree, you can use
10340 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.ac}.
10341 @xref{Macros}.
10342
10343
10344 @node Miscellaneous
10345 @chapter Miscellaneous Rules
10346
10347 There are a few rules and variables that didn't fit anywhere else.
10348
10349 @menu
10350 * Tags::                        Interfacing to cscope, etags and mkid
10351 * Suffixes::                    Handling new file extensions
10352 @end menu
10353
10354
10355 @node Tags
10356 @section Interfacing to @command{etags}
10357
10358 @cindex @file{TAGS} support
10359
10360 Automake will generate rules to generate @file{TAGS} files for use with
10361 GNU Emacs under some circumstances.
10362
10363 @trindex tags
10364 If any C, C++ or Fortran 77 source code or headers are present, then
10365 @code{tags} and @code{TAGS} rules will be generated for the directory.
10366 All files listed using the @code{_SOURCES}, @code{_HEADERS}, and
10367 @code{_LISP} primaries will be used to generate tags.  Note that
10368 generated source files that are not distributed must be declared in
10369 variables like @code{nodist_noinst_HEADERS} or
10370 @code{nodist_@var{prog}_SOURCES} or they will be ignored.
10371
10372 A @code{tags} rule will be output at the topmost directory of a
10373 multi-directory package.  When run from this topmost directory,
10374 @samp{make tags} will generate a @file{TAGS} file that includes by
10375 reference all @file{TAGS} files from subdirectories.
10376
10377 The @code{tags} rule will also be generated if the variable
10378 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
10379 directories that contain taggable source that @command{etags} does
10380 not understand.  The user can use the @code{ETAGSFLAGS} to pass
10381 additional flags to @command{etags}; @code{AM_ETAGSFLAGS} is also
10382 available for use in @file{Makefile.am}.
10383 @vindex ETAGS_ARGS
10384 @vindex ETAGSFLAGS
10385 @vindex AM_ETAGSFLAGS
10386
10387 Here is how Automake generates tags for its source, and for nodes in its
10388 Texinfo file:
10389
10390 @example
10391 ETAGS_ARGS = automake.in --lang=none \
10392  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
10393 @end example
10394
10395 If you add file names to @code{ETAGS_ARGS}, you will probably also
10396 want to define @code{TAGS_DEPENDENCIES}.  The contents of this variable
10397 are added directly to the dependencies for the @code{tags} rule.
10398 @vindex TAGS_DEPENDENCIES
10399
10400 Automake also generates a @code{ctags} rule that can be used to
10401 build @command{vi}-style @file{tags} files.  The variable @code{CTAGS}
10402 is the name of the program to invoke (by default @command{ctags});
10403 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
10404 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
10405
10406 @trindex id
10407 Automake will also generate an @code{ID} rule that will run
10408 @command{mkid} on the source.  This is only supported on a
10409 directory-by-directory basis.
10410
10411 Similarly, the @code{cscope} rule will create a list of all the source
10412 files in the tree and run @command{cscope} to build an inverted index
10413 database.  The variable @code{CSCOPE} is the name of the program to invoke
10414 (by default @command{cscope}); @code{CSCOPEFLAGS} and
10415 @code{CSCOPE_ARGS} can be used by the user to pass additional flags and
10416 file names respectively, while @code{AM_CSCOPEFLAGS} can be used by the
10417 @file{Makefile.am}.  Note that, currently, the Automake-provided
10418 @code{cscope} support, when used in a VPATH build, might not work well
10419 with non-GNU make implementations (especially with make implementations
10420 performing @ref{Automatic Rule Rewriting, , VPATH rewrites, autoconf,
10421 The Autoconf Manual}).
10422
10423 Finally, Automake also emits rules to support the
10424 @uref{http://www.gnu.org/software/global/, GNU Global Tags program}.
10425 The @code{GTAGS} rule runs Global Tags and puts the
10426 result in the top build directory.  The variable @code{GTAGS_ARGS}
10427 holds arguments that are passed to @command{gtags}.
10428 @vindex GTAGS_ARGS
10429
10430
10431 @node Suffixes
10432 @section Handling new file extensions
10433
10434 @cindex Adding new @code{SUFFIXES}
10435 @cindex @code{SUFFIXES}, adding
10436 @vindex SUFFIXES
10437
10438 It is sometimes useful to introduce a new implicit rule to handle a file
10439 type that Automake does not know about.
10440
10441 For instance, suppose you had a compiler that could compile @file{.foo}
10442 files to @file{.o} files.  You would simply define a suffix rule for
10443 your language:
10444
10445 @example
10446 .foo.o:
10447         foocc -c -o $@@ $<
10448 @end example
10449
10450 Then you could directly use a @file{.foo} file in a @code{_SOURCES}
10451 variable and expect the correct results:
10452
10453 @example
10454 bin_PROGRAMS = doit
10455 doit_SOURCES = doit.foo
10456 @end example
10457
10458 This was the simpler and more common case.  In other cases, you will
10459 have to help Automake to figure out which extensions you are defining your
10460 suffix rule for.  This usually happens when your extension does not
10461 start with a dot.  Then, all you have to do is to put a list of new
10462 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
10463 implicit rule.
10464
10465 For instance, the following definition prevents Automake from misinterpreting
10466 the @samp{.idlC.cpp:} rule as an attempt to transform @file{.idlC} files into
10467 @file{.cpp} files.
10468
10469 @c Keep in sync with suffix7.sh
10470 @example
10471 SUFFIXES = .idl C.cpp
10472 .idlC.cpp:
10473         # whatever
10474 @end example
10475
10476 As you may have noted, the @code{SUFFIXES} variable behaves like the
10477 @code{.SUFFIXES} special target of @command{make}.  You should not touch
10478 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
10479 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
10480 @code{SUFFIXES} go at the start of the generated suffixes list, followed
10481 by Automake generated suffixes not already in the list.
10482
10483 @node Include
10484 @chapter Include
10485
10486 @cmindex include
10487 @cindex Including @file{Makefile} fragment
10488 @cindex @file{Makefile} fragment, including
10489
10490 Automake supports an @code{include} directive that  can be used to
10491 include other @file{Makefile} fragments when @command{automake} is run.
10492 Note that these fragments are read and interpreted by @command{automake},
10493 not by @command{make}.  As with conditionals, @command{make} has no idea that
10494 @code{include} is in use.
10495
10496 There are two forms of @code{include}:
10497
10498 @table @code
10499 @item include $(srcdir)/file
10500 Include a fragment that is found relative to the current source
10501 directory.
10502
10503 @item include $(top_srcdir)/file
10504 Include a fragment that is found relative to the top source directory.
10505 @end table
10506
10507 Note that if a fragment is included inside a conditional, then the
10508 condition applies to the entire contents of that fragment.
10509
10510 Makefile fragments included this way are always distributed because
10511 they are needed to rebuild @file{Makefile.in}.
10512
10513 @node Conditionals
10514 @chapter Conditionals
10515
10516 @cindex Conditionals
10517
10518 Automake supports a simple type of conditionals.
10519
10520 These conditionals are not the same as conditionals in
10521 GNU Make.  Automake conditionals are checked at configure time by the
10522 @file{configure} script, and affect the translation from
10523 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
10524 to @file{configure} and on results that @file{configure} has discovered
10525 about the host system.  GNU Make conditionals are checked at @command{make}
10526 time, and are based on variables passed to the make program or defined
10527 in the @file{Makefile}.
10528
10529 Automake conditionals will work with any make program.
10530
10531 @menu
10532 * Usage of Conditionals::       Declaring conditional content
10533 * Limits of Conditionals::      Enclosing complete statements
10534 @end menu
10535
10536 @node Usage of Conditionals
10537 @section Usage of Conditionals
10538
10539 @acindex AM_CONDITIONAL
10540 Before using a conditional, you must define it by using
10541 @code{AM_CONDITIONAL} in the @file{configure.ac} file (@pxref{Macros}).
10542
10543 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
10544 The conditional name, @var{conditional}, should be a simple string
10545 starting with a letter and containing only letters, digits, and
10546 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
10547 that are reserved by Automake.
10548
10549 The shell @var{condition} (suitable for use in a shell @code{if}
10550 statement) is evaluated when @command{configure} is run.  Note that you
10551 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
10552 time @command{configure} is run.  If @code{AM_CONDITIONAL} is run
10553 conditionally (e.g., in a shell @code{if} statement), then the result
10554 will confuse @command{automake}.
10555 @end defmac
10556
10557 @cindex @option{--enable-debug}, example
10558 @cindex Example conditional @option{--enable-debug}
10559 @cindex Conditional example, @option{--enable-debug}
10560
10561 Conditionals typically depend upon options that the user provides to
10562 the @command{configure} script.  Here is an example of how to write a
10563 conditional that is true if the user uses the @option{--enable-debug}
10564 option.
10565
10566 @example
10567 AC_ARG_ENABLE([debug],
10568 [  --enable-debug    Turn on debugging],
10569 [case "$@{enableval@}" in
10570   yes) debug=true ;;
10571   no)  debug=false ;;
10572   *) AC_MSG_ERROR([bad value $@{enableval@} for --enable-debug]) ;;
10573 esac],[debug=false])
10574 AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
10575 @end example
10576
10577 Here is an example of how to use that conditional in @file{Makefile.am}:
10578
10579 @cmindex if
10580 @cmindex endif
10581 @cmindex else
10582
10583 @example
10584 if DEBUG
10585 DBG = debug
10586 else
10587 DBG =
10588 endif
10589 noinst_PROGRAMS = $(DBG)
10590 @end example
10591
10592 This trivial example could also be handled using @code{EXTRA_PROGRAMS}
10593 (@pxref{Conditional Programs}).
10594
10595 You may only test a single variable in an @code{if} statement, possibly
10596 negated using @samp{!}.  The @code{else} statement may be omitted.
10597 Conditionals may be nested to any depth.  You may specify an argument to
10598 @code{else} in which case it must be the negation of the condition used
10599 for the current @code{if}.  Similarly you may specify the condition
10600 that is closed on the @code{endif} line:
10601
10602 @example
10603 if DEBUG
10604 DBG = debug
10605 else !DEBUG
10606 DBG =
10607 endif !DEBUG
10608 @end example
10609
10610 @noindent
10611 Unbalanced conditions are errors.  The @code{if}, @code{else}, and
10612 @code{endif} statements should not be indented, i.e., start on column
10613 one.
10614
10615 The @code{else} branch of the above two examples could be omitted,
10616 since assigning the empty string to an otherwise undefined variable
10617 makes no difference.
10618
10619 @acindex AM_COND_IF
10620 In order to allow access to the condition registered by
10621 @code{AM_CONDITIONAL} inside @file{configure.ac}, and to allow
10622 conditional @code{AC_CONFIG_FILES}, @code{AM_COND_IF} may be used:
10623
10624 @defmac AM_COND_IF (@var{conditional}, @ovar{if-true}, @ovar{if-false})
10625 If @var{conditional} is fulfilled, execute @var{if-true}, otherwise
10626 execute @var{if-false}.  If either branch contains @code{AC_CONFIG_FILES},
10627 it will cause @command{automake} to output the rules for the respective
10628 files only for the given condition.
10629 @end defmac
10630
10631 @code{AM_COND_IF} macros may be nested when m4 quotation is used
10632 properly (@pxref{M4 Quotation, ,, autoconf, The Autoconf Manual}).
10633
10634 @cindex Example conditional @code{AC_CONFIG_FILES}
10635 @cindex @code{AC_CONFIG_FILES}, conditional
10636
10637 Here is an example of how to define a conditional config file:
10638
10639 @example
10640 AM_CONDITIONAL([SHELL_WRAPPER], [test "x$with_wrapper" = xtrue])
10641 AM_COND_IF([SHELL_WRAPPER],
10642            [AC_CONFIG_FILES([wrapper:wrapper.in])])
10643 @end example
10644
10645 @node Limits of Conditionals
10646 @section Limits of Conditionals
10647
10648 Conditionals should enclose complete statements like variables or
10649 rules definitions.  Automake cannot deal with conditionals used inside
10650 a variable definition, for instance, and is not even able to diagnose
10651 this situation.  The following example would not work:
10652
10653 @example
10654 # This syntax is not understood by Automake
10655 AM_CPPFLAGS = \
10656   -DFEATURE_A \
10657 if WANT_DEBUG
10658   -DDEBUG \
10659 endif
10660   -DFEATURE_B
10661 @end example
10662
10663 However the intended definition of @code{AM_CPPFLAGS} can be achieved
10664 with
10665
10666 @example
10667 if WANT_DEBUG
10668   DEBUGFLAGS = -DDEBUG
10669 endif
10670 AM_CPPFLAGS = -DFEATURE_A $(DEBUGFLAGS) -DFEATURE_B
10671 @end example
10672
10673 @noindent
10674 or
10675
10676 @example
10677 AM_CPPFLAGS = -DFEATURE_A
10678 if WANT_DEBUG
10679 AM_CPPFLAGS += -DDEBUG
10680 endif
10681 AM_CPPFLAGS += -DFEATURE_B
10682 @end example
10683
10684 More details and examples of conditionals are described alongside
10685 various Automake features in this manual (@pxref{Conditional
10686 Subdirectories}, @pxref{Conditional Sources}, @pxref{Conditional
10687 Programs}, @pxref{Conditional Libtool Libraries}, @pxref{Conditional
10688 Libtool Sources}).
10689
10690 @node Silencing Make
10691 @chapter Silencing @command{make}
10692
10693 @cindex Silent @command{make}
10694 @cindex Silencing @command{make}
10695 @cindex Silent rules
10696 @cindex Silent @command{make} rules
10697
10698 @menu
10699 * Make verbosity::              Make is verbose by default
10700 * Tricks For Silencing Make::   Standard and generic ways to silence make
10701 * Automake Silent Rules::       How Automake can help in silencing make
10702 @end menu
10703
10704 @node Make verbosity
10705 @section Make is verbose by default
10706
10707 Normally, when executing the set of rules associated with a target,
10708 @command{make} prints each rule before it is executed.  This behaviour,
10709 while having been in place for a long time, and being even mandated by
10710 the POSIX standard, starkly violates the ``silence is golden'' UNIX
10711 principle@footnote{See also
10712 @uref{http://catb.org/~esr/writings/taoup/html/ch11s09.html}.}:
10713
10714 @quotation
10715 When a program has nothing interesting or surprising to say, it should
10716 say nothing.  Well-behaved Unix programs do their jobs unobtrusively,
10717 with a minimum of fuss and bother.  Silence is golden.
10718 @end quotation
10719
10720 In fact, while such verbosity of @command{make} can theoretically be
10721 useful to track bugs and understand reasons of failures right away, it
10722 can also hide warning and error messages from @command{make}-invoked
10723 tools, drowning them in a flood of uninteresting and seldom useful
10724 messages, and thus allowing them to go easily undetected.
10725
10726 This problem can be very annoying, especially for developers, who usually
10727 know quite well what's going on behind the scenes, and for whom the
10728 verbose output from @command{make} ends up being mostly noise that hampers
10729 the easy detection of potentially important warning messages.
10730
10731 @node Tricks For Silencing Make
10732 @section Standard and generic ways to silence make
10733
10734 Here we describe some common idioms/tricks to obtain a quieter make
10735 output, with their relative advantages and drawbacks.  In the next
10736 section (@ref{Automake Silent Rules}) we'll see how Automake can help
10737 in this respect, providing more elaborate and flexible idioms.
10738
10739 @itemize @bullet
10740
10741 @item @command{make -s}
10742
10743 This simply causes @command{make} not to print @emph{any} rule before
10744 executing it.
10745
10746 The @option{-s} flag is mandated by POSIX, universally supported, and
10747 its purpose and function are easy to understand.
10748
10749 But it also has its serious limitations too.  First of all, it embodies
10750 an ``all or nothing'' strategy, i.e., either everything is silenced, or
10751 nothing is; this lack of granularity can sometimes be a fatal flaw.
10752 Moreover, when the @option{-s} flag is used, the @command{make} output
10753 might turn out to be too much terse; in case of errors, the user won't
10754 be able to easily see what rule or command have caused them, or even,
10755 in case of tools with poor error reporting, what the errors were!
10756
10757 @item @command{make >/dev/null || make}
10758
10759 Apparently, this perfectly obeys the ``silence is golden'' rule: warnings
10760 from stderr are passed through, output reporting is done only in case of
10761 error, and in that case it should provide a verbose-enough report to allow
10762 an easy determination of the error location and causes.
10763
10764 However, calling @command{make} two times in a row might hide errors
10765 (especially intermittent ones), or subtly change the expected semantic
10766 of the @command{make} calls --- things these which can clearly make
10767 debugging and error assessment very difficult.
10768
10769 @item @command{make --no-print-directory}
10770
10771 This is GNU @command{make} specific.  When called with the
10772 @option{--no-print-directory} option, GNU @command{make} will disable
10773 printing of the working directory by invoked sub-@command{make}s (the
10774 well-known ``@i{Entering/Leaving directory ...}'' messages).  This helps
10775 to decrease the verbosity of the output, but experience has shown that
10776 it can also often render debugging considerably harder in projects using
10777 deeply-nested @command{make} recursion.
10778
10779 As an aside, notice that the @option{--no-print-directory} option is
10780 automatically activated if the @option{-s} flag is used.
10781
10782 @c TODO: Other tricks?
10783 @c TODO: Maybe speak about the @code{.SILENT} target?
10784 @c TODO:  - Pros: More granularity on what to silence.
10785 @c TODO:  - Cons: No easy way to temporarily override.
10786
10787 @end itemize
10788
10789 @node Automake Silent Rules
10790 @section How Automake can help in silencing make
10791
10792 The tricks and idioms for silencing @command{make} described in the
10793 previous section can be useful from time to time, but we've seen that
10794 they all have their serious drawbacks and limitations.  That's why
10795 automake provides support for a more advanced and flexible way of
10796 obtaining quieter output from @command{make} (for most rules at least).
10797
10798 @c TODO: Maybe describe in brief the precedent set by the build system
10799 @c of the Linux Kernel, from which Automake took inspiration ... Links?
10800
10801 To give the gist of what Automake can do in this respect, here is a simple
10802 comparison between a typical @command{make} output (where silent rules
10803 are disabled) and one with silent rules enabled:
10804
10805 @example
10806 % @kbd{cat Makefile.am}
10807 bin_PROGRAMS = foo
10808 foo_SOURCES = main.c func.c
10809 % @kbd{cat main.c}
10810 int main (void) @{ return func (); @}  /* func used undeclared */
10811 % @kbd{cat func.c}
10812 int func (void) @{ int i; return i; @} /* i used uninitialized */
10813
10814 @i{The make output is by default very verbose.  This causes warnings
10815 from the compiler to be somewhat hidden, and not immediate to spot.}
10816 % @kbd{make CFLAGS=-Wall}
10817 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
10818 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
10819 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT main.o
10820 -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
10821 main.c: In function â€˜main’:
10822 main.c:3:3: warning: implicit declaration of function â€˜func’
10823 mv -f .deps/main.Tpo .deps/main.Po
10824 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
10825 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
10826 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT func.o
10827 -MD -MP -MF .deps/func.Tpo -c -o func.o func.c
10828 func.c: In function â€˜func’:
10829 func.c:4:3: warning: â€˜i’ used uninitialized in this function
10830 mv -f .deps/func.Tpo .deps/func.Po
10831 gcc -Wall -o foo main.o func.o
10832
10833 @i{Clean up, so that we we can rebuild everything from scratch.}
10834 % @kbd{make clean}
10835 test -z "foo" || rm -f foo
10836 rm -f *.o
10837
10838 @i{Silent rules enabled: the output is minimal but informative.  In
10839 particular, the warnings from the compiler stick out very clearly.}
10840 % @kbd{make V=0 CFLAGS=-Wall}
10841   CC     main.o
10842 main.c: In function â€˜main’:
10843 main.c:3:3: warning: implicit declaration of function â€˜func’
10844   CC     func.o
10845 func.c: In function â€˜func’:
10846 func.c:4:3: warning: â€˜i’ used uninitialized in this function
10847   CCLD   foo
10848 @end example
10849
10850 @cindex silent rules and libtool
10851 Also, in projects using @command{libtool}, the use of silent rules can
10852 automatically enable the @command{libtool}'s @option{--silent} option:
10853
10854 @example
10855 % @kbd{cat Makefile.am}
10856 lib_LTLIBRARIES = libx.la
10857
10858 % @kbd{make # Both make and libtool are verbose by default.}
10859 ...
10860 libtool: compile: gcc -DPACKAGE_NAME=\"foo\" ... -DLT_OBJDIR=\".libs/\"
10861   -I. -g -O2 -MT libx.lo -MD -MP -MF .deps/libx.Tpo -c libx.c -fPIC
10862   -DPIC -o .libs/libx.o
10863 mv -f .deps/libx.Tpo .deps/libx.Plo
10864 /bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -o libx.la -rpath
10865   /usr/local/lib libx.lo
10866 libtool: link: gcc -shared .libs/libx.o -Wl,-soname -Wl,libx.so.0
10867   -o .libs/libx.so.0.0.0
10868 libtool: link: cd .libs && rm -f libx.so && ln -s libx.so.0.0.0 libx.so
10869 ...
10870
10871 % @kbd{make V=0}
10872   CC     libx.lo
10873   CCLD   libx.la
10874 @end example
10875
10876 For Automake-generated @file{Makefile}s, the user may influence the
10877 verbosity at @command{configure} run time as well as at @command{make}
10878 run time:
10879
10880 @itemize @bullet
10881 @item
10882 @opindex --enable-silent-rules
10883 @opindex --disable-silent-rules
10884 Passing @option{--enable-silent-rules} to @command{configure} will cause
10885 build rules to be less verbose; the option @option{--disable-silent-rules}
10886 will cause normal verbose output.
10887 @item
10888 @vindex @code{V}
10889 At @command{make} run time, the default chosen at @command{configure}
10890 time may be overridden: @code{make V=1} will produce verbose output,
10891 @code{make V=0} less verbose output.
10892 @end itemize
10893
10894 @cindex default verbosity for silent rules
10895 Note that silent rules are @emph{disabled} by default; the user must
10896 enable them explicitly at either @command{configure} run time or at
10897 @command{make} run time.  We think that this is a good policy, since
10898 it provides the casual user with enough information to prepare a good
10899 bug report in case anything breaks.
10900
10901 Still, notwithstanding the rationales above, a developer who really
10902 wants to make silent rules enabled by default in his own package can
10903 do so by calling @code{AM_SILENT_RULES([yes])} in @file{configure.ac}.
10904
10905 @c Keep in sync with silent-configsite.sh
10906 Users who prefer to have silent rules enabled by default can edit their
10907 @file{config.site} file to make the variable @code{enable_silent_rules}
10908 default to @samp{yes}.  This should still allow disabling silent rules
10909 at @command{configure} time and at @command{make} time.
10910
10911 @c FIXME: there's really a need to specify this explicitly?
10912 For portability to different @command{make} implementations, package authors
10913 are advised to not set the variable @code{V} inside the @file{Makefile.am}
10914 file, to allow the user to override the value for subdirectories as well.
10915
10916 To work at its best, the current implementation of this feature normally
10917 uses nested variable expansion @samp{$(@var{var1}$(V))}, a @file{Makefile}
10918 feature that is not required by POSIX 2008 but is widely supported in
10919 practice.  On the rare @command{make} implementations that do not support
10920 nested variable expansion, whether rules are silent is always determined at
10921 configure time, and cannot be overridden at make time.  Future versions of
10922 POSIX are likely to require nested variable expansion, so this minor
10923 limitation should go away with time.
10924
10925 @vindex @code{AM_V_GEN}
10926 @vindex @code{AM_V_at}
10927 @vindex @code{AM_DEFAULT_VERBOSITY}
10928 @vindex @code{AM_V}
10929 @vindex @code{AM_DEFAULT_V}
10930 To extend the silent mode to your own rules, you have few choices:
10931
10932 @itemize @bullet
10933
10934 @item
10935 You can use the predefined variable @code{AM_V_GEN} as a prefix to
10936 commands that should output a status line in silent mode, and
10937 @code{AM_V_at} as a prefix to commands that should not output anything
10938 in silent mode.  When output is to be verbose, both of these variables
10939 will expand to the empty string.
10940
10941 @item
10942 You can silence a recipe unconditionally with @code{@@}, and then use
10943 the predefined variable @code{AM_V_P} to know whether make is being run
10944 in silent or verbose mode, adjust the verbose information your recipe
10945 displays accordingly:
10946
10947 @example
10948 generate-headers:
10949         @set -e; \
10950         ... [commands defining a shell variable '$headers'] ...; \
10951         if $(AM_V_P); then set -x; else echo " GEN   [headers]"; fi; \
10952         rm -f $$headers && generate-header --flags $$headers
10953 @end example
10954
10955 @item
10956 You can add your own variables, so strings of your own choice are shown.
10957 The following snippet shows how you would define your own equivalent of
10958 @code{AM_V_GEN}:
10959
10960 @example
10961 pkg_verbose = $(pkg_verbose_@@AM_V@@)
10962 pkg_verbose_ = $(pkg_verbose_@@AM_DEFAULT_V@@)
10963 pkg_verbose_0 = @@echo PKG-GEN $@@;
10964
10965 foo: foo.in
10966         $(pkg_verbose)cp $(srcdir)/foo.in $@@
10967 @end example
10968
10969 @end itemize
10970
10971 As a final note, observe that, even when silent rules are enabled,
10972 the @option{--no-print-directory} option is still required with GNU
10973 @command{make} if the ``@i{Entering/Leaving directory ...}'' messages
10974 are to be disabled.
10975
10976 @node Gnits
10977 @chapter The effect of @option{--gnu} and @option{--gnits}
10978
10979 @cindex @option{--gnu}, required files
10980 @cindex @option{--gnu}, complete description
10981
10982 The @option{--gnu} option (or @option{gnu} in the
10983 @code{AUTOMAKE_OPTIONS} variable) causes @command{automake} to check
10984 the following:
10985
10986 @itemize @bullet
10987 @item
10988 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
10989 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
10990 or @file{COPYING}, are required at the topmost directory of the package.
10991
10992 If the @option{--add-missing} option is given, @command{automake} will
10993 add a generic version of the @file{INSTALL} file as well as the
10994 @file{COPYING} file containing the text of the current version of the
10995 GNU General Public License existing at the time of this Automake release
10996 (version 3 as this is written, @uref{http://www.gnu.org/@/copyleft/@/gpl.html}).
10997 However, an existing @file{COPYING} file will never be overwritten by
10998 @command{automake}.
10999
11000 @item
11001 The options @option{no-installman} and @option{no-installinfo} are
11002 prohibited.
11003 @end itemize
11004
11005 Note that this option will be extended in the future to do even more
11006 checking; it is advisable to be familiar with the precise requirements
11007 of the GNU standards.  Also, @option{--gnu} can require certain
11008 non-standard GNU programs to exist for use by various maintainer-only
11009 rules; for instance, in the future @command{pathchk} might be required for
11010 @samp{make dist}.
11011
11012 @cindex @option{--gnits}, complete description
11013
11014 The @option{--gnits} option does everything that @option{--gnu} does, and
11015 checks the following as well:
11016
11017 @itemize @bullet
11018 @item
11019 @samp{make installcheck} will check to make sure that the @option{--help}
11020 and @option{--version} really print a usage message and a version string,
11021 respectively.  This is the @option{std-options} option (@pxref{Options}).
11022
11023 @item
11024 @samp{make dist} will check to make sure the @file{NEWS} file has been
11025 updated to the current version.
11026
11027 @item
11028 @code{VERSION} is checked to make sure its format complies with Gnits
11029 standards.
11030 @c FIXME xref when standards are finished
11031
11032 @item
11033 @cindex @file{README-alpha}
11034 If @code{VERSION} indicates that this is an alpha release, and the file
11035 @file{README-alpha} appears in the topmost directory of a package, then
11036 it is included in the distribution.  This is done in @option{--gnits}
11037 mode, and no other, because this mode is the only one where version
11038 number formats are constrained, and hence the only mode where Automake
11039 can automatically determine whether @file{README-alpha} should be
11040 included.
11041
11042 @item
11043 The file @file{THANKS} is required.
11044 @end itemize
11045
11046
11047 @node Not Enough
11048 @chapter When Automake Isn't Enough
11049
11050 In some situations, where Automake is not up to one task, one has to
11051 resort to handwritten rules or even handwritten @file{Makefile}s.
11052
11053 @menu
11054 * Extending::                   Adding new rules or overriding existing ones.
11055 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
11056 @end menu
11057
11058 @node Extending
11059 @section Extending Automake Rules
11060
11061 With some minor exceptions (for example @code{_PROGRAMS} variables,
11062 @code{TESTS}, or @code{XFAIL_TESTS}) being rewritten to append
11063 @samp{$(EXEEXT)}), the contents of a @file{Makefile.am} is copied to
11064 @file{Makefile.in} verbatim.
11065
11066 @cindex copying semantics
11067
11068 These copying semantics mean that many problems can be worked around
11069 by simply adding some @command{make} variables and rules to
11070 @file{Makefile.am}.  Automake will ignore these additions.
11071
11072 @cindex conflicting definitions
11073 @cindex rules, conflicting
11074 @cindex variables, conflicting
11075 @cindex definitions, conflicts
11076
11077 Since a @file{Makefile.in} is built from data gathered from three
11078 different places (@file{Makefile.am}, @file{configure.ac}, and
11079 @command{automake} itself), it is possible to have conflicting
11080 definitions of rules or variables.  When building @file{Makefile.in}
11081 the following priorities are respected by @command{automake} to ensure
11082 the user always has the last word:
11083
11084 @itemize
11085 @item
11086 User defined variables in @file{Makefile.am} have priority over
11087 variables @code{AC_SUBST}ed from @file{configure.ac}, and
11088 @code{AC_SUBST}ed variables have priority over
11089 @command{automake}-defined variables.
11090 @item
11091 As far as rules are concerned, a user-defined rule overrides any
11092 @command{automake}-defined rule for the same target.
11093 @end itemize
11094
11095 @cindex overriding rules
11096 @cindex overriding semantics
11097 @cindex rules, overriding
11098
11099 These overriding semantics make it possible to fine tune some default
11100 settings of Automake, or replace some of its rules.  Overriding
11101 Automake rules is often inadvisable, particularly in the topmost
11102 directory of a package with subdirectories.  The @option{-Woverride}
11103 option (@pxref{automake Invocation}) comes in handy to catch overridden
11104 definitions.
11105
11106 Note that Automake does not make any distinction between rules with
11107 commands and rules that only specify dependencies.  So it is not
11108 possible to append new dependencies to an @command{automake}-defined
11109 target without redefining the entire rule.
11110
11111 @cindex @option{-local} targets
11112 @cindex local targets
11113
11114 However, various useful targets have a @samp{-local} version you can
11115 specify in your @file{Makefile.am}.  Automake will supplement the
11116 standard target with these user-supplied targets.
11117
11118 @trindex  all
11119 @trindex  all-local
11120 @trindex  info
11121 @trindex  info-local
11122 @trindex  dvi
11123 @trindex  dvi-local
11124 @trindex  ps
11125 @trindex  ps-local
11126 @trindex  pdf
11127 @trindex  pdf-local
11128 @trindex  html
11129 @trindex  html-local
11130 @trindex  check
11131 @trindex  check-local
11132 @trindex  install
11133 @trindex  install-data
11134 @trindex  install-data-local
11135 @trindex  install-dvi
11136 @trindex  install-dvi-local
11137 @trindex  install-exec
11138 @trindex  install-exec-local
11139 @trindex  install-html
11140 @trindex  install-html-local
11141 @trindex  install-info
11142 @trindex  install-info-local
11143 @trindex  install-pdf
11144 @trindex  install-pdf-local
11145 @trindex  install-ps
11146 @trindex  install-ps-local
11147 @trindex  uninstall
11148 @trindex  uninstall-local
11149 @trindex  mostlyclean
11150 @trindex  mostlyclean-local
11151 @trindex  clean
11152 @trindex  clean-local
11153 @trindex  distclean
11154 @trindex  distclean-local
11155 @trindex  installdirs
11156 @trindex  installdirs-local
11157 @trindex  installcheck
11158 @trindex  installcheck-local
11159
11160 The targets that support a local version are @code{all}, @code{info},
11161 @code{dvi}, @code{ps}, @code{pdf}, @code{html}, @code{check},
11162 @code{install-data}, @code{install-dvi}, @code{install-exec},
11163 @code{install-html}, @code{install-info}, @code{install-pdf},
11164 @code{install-ps}, @code{uninstall}, @code{installdirs},
11165 @code{installcheck} and the various @code{clean} targets
11166 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
11167 @code{maintainer-clean}).
11168
11169 Note that there are no @code{uninstall-exec-local} or
11170 @code{uninstall-data-local} targets; just use @code{uninstall-local}.
11171 It doesn't make sense to uninstall just data or just executables.
11172
11173 For instance, here is one way to erase a subdirectory during
11174 @samp{make clean} (@pxref{Clean}).
11175
11176 @example
11177 clean-local:
11178         -rm -rf testSubDir
11179 @end example
11180
11181 You may be tempted to use @code{install-data-local} to install a file
11182 to some hard-coded location, but you should avoid this
11183 (@pxref{Hard-Coded Install Paths}).
11184
11185 With the @code{-local} targets, there is no particular guarantee of
11186 execution order; typically, they are run early, but with parallel
11187 make, there is no way to be sure of that.
11188
11189 @cindex @option{-hook} targets
11190 @cindex hook targets
11191 @trindex install-data-hook
11192 @trindex install-exec-hook
11193 @trindex uninstall-hook
11194 @trindex dist-hook
11195
11196 In contrast, some rules also have a way to run another rule, called a
11197 @dfn{hook}; hooks are always executed after the main rule's work is done.
11198 The hook is named after the principal target, with @samp{-hook} appended.
11199 The targets allowing hooks are @code{install-data},
11200 @code{install-exec}, @code{uninstall}, @code{dist}, and
11201 @code{distcheck}.
11202
11203 For instance, here is how to create a hard link to an installed program:
11204
11205 @example
11206 install-exec-hook:
11207         ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
11208            $(DESTDIR)$(bindir)/proglink$(EXEEXT)
11209 @end example
11210
11211 Although cheaper and more portable than symbolic links, hard links
11212 will not work everywhere (for instance, OS/2 does not have
11213 @command{ln}).  Ideally you should fall back to @samp{cp -p} when
11214 @command{ln} does not work.  An easy way, if symbolic links are
11215 acceptable to you, is to add @code{AC_PROG_LN_S} to
11216 @file{configure.ac} (@pxref{Particular Programs, , Particular Program
11217 Checks, autoconf, The Autoconf Manual}) and use @samp{$(LN_S)} in
11218 @file{Makefile.am}.
11219
11220 @cindex versioned binaries, installing
11221 @cindex installing versioned binaries
11222 @cindex @code{LN_S} example
11223 For instance, here is how you could install a versioned copy of a
11224 program using @samp{$(LN_S)}:
11225
11226 @c Keep in sync with insthook.sh
11227 @example
11228 install-exec-hook:
11229         cd $(DESTDIR)$(bindir) && \
11230           mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
11231           $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
11232 @end example
11233
11234 Note that we rename the program so that a new version will erase the
11235 symbolic link, not the real binary.  Also we @command{cd} into the
11236 destination directory in order to create relative links.
11237
11238 When writing @code{install-exec-hook} or @code{install-data-hook},
11239 please bear in mind that the exec/data distinction is based on the
11240 installation directory, not on the primary used (@pxref{The Two Parts of
11241 Install}).
11242 @c Keep in sync with primary-prefix-couples-documented-valid.sh
11243 So a @code{foo_SCRIPTS} will be installed by
11244 @code{install-data}, and a @code{barexec_SCRIPTS} will be installed by
11245 @code{install-exec}.  You should define your hooks consequently.
11246
11247 @c FIXME should include discussion of variables you can use in these
11248 @c rules
11249
11250 @node Third-Party Makefiles
11251 @section Third-Party @file{Makefile}s
11252
11253 @cindex Third-party packages, interfacing with
11254 @cindex Interfacing with third-party packages
11255
11256 In most projects all @file{Makefile}s are generated by Automake.  In
11257 some cases, however, projects need to embed subdirectories with
11258 handwritten @file{Makefile}s.  For instance, one subdirectory could be
11259 a third-party project with its own build system, not using Automake.
11260
11261 It is possible to list arbitrary directories in @code{SUBDIRS} or
11262 @code{DIST_SUBDIRS} provided each of these directories has a
11263 @file{Makefile} that recognizes all the following recursive targets.
11264
11265 @cindex recursive targets and third-party @file{Makefile}s
11266 When a user runs one of these targets, that target is run recursively
11267 in all subdirectories.  This is why it is important that even
11268 third-party @file{Makefile}s support them.
11269
11270 @table @code
11271 @item all
11272 Compile the entire package.  This is the default target in
11273 Automake-generated @file{Makefile}s, but it does not need to be the
11274 default in third-party @file{Makefile}s.
11275
11276 @item distdir
11277 @trindex distdir
11278 @vindex distdir
11279 @vindex top_distdir
11280 Copy files to distribute into @samp{$(distdir)}, before a tarball is
11281 constructed.  Of course this target is not required if the
11282 @option{no-dist} option (@pxref{Options}) is used.
11283
11284 The variables @samp{$(top_distdir)} and @samp{$(distdir)}
11285 (@pxref{The dist Hook}) will be passed from the outer package to the subpackage
11286 when the @code{distdir} target is invoked.  These two variables have
11287 been adjusted for the directory that is being recursed into, so they
11288 are ready to use.
11289
11290 @item install
11291 @itemx install-data
11292 @itemx install-exec
11293 @itemx uninstall
11294 Install or uninstall files (@pxref{Install}).
11295
11296 @item install-dvi
11297 @itemx install-html
11298 @itemx install-info
11299 @itemx install-ps
11300 @itemx install-pdf
11301 Install only some specific documentation format (@pxref{Texinfo}).
11302
11303 @item installdirs
11304 Create install directories, but do not install any files.
11305
11306 @item check
11307 @itemx installcheck
11308 Check the package (@pxref{Tests}).
11309
11310 @item mostlyclean
11311 @itemx clean
11312 @itemx distclean
11313 @itemx maintainer-clean
11314 Cleaning rules (@pxref{Clean}).
11315
11316 @item dvi
11317 @itemx pdf
11318 @itemx ps
11319 @itemx info
11320 @itemx html
11321 Build the documentation in various formats (@pxref{Texinfo}).
11322
11323 @item tags
11324 @itemx ctags
11325 Build @file{TAGS} and @file{CTAGS} (@pxref{Tags}).
11326 @end table
11327
11328 If you have ever used Gettext in a project, this is a good example of
11329 how third-party @file{Makefile}s can be used with Automake.  The
11330 @file{Makefile}s @command{gettextize} puts in the @file{po/} and
11331 @file{intl/} directories are handwritten @file{Makefile}s that
11332 implement all of these targets.  That way they can be added to
11333 @code{SUBDIRS} in Automake packages.
11334
11335 Directories that are only listed in @code{DIST_SUBDIRS} but not in
11336 @code{SUBDIRS} need only the @code{distclean},
11337 @code{maintainer-clean}, and @code{distdir} rules (@pxref{Conditional
11338 Subdirectories}).
11339
11340 Usually, many of these rules are irrelevant to the third-party
11341 subproject, but they are required for the whole package to work.  It's
11342 OK to have a rule that does nothing, so if you are integrating a
11343 third-party project with no documentation or tag support, you could
11344 simply augment its @file{Makefile} as follows:
11345
11346 @example
11347 EMPTY_AUTOMAKE_TARGETS = dvi pdf ps info html tags ctags
11348 .PHONY: $(EMPTY_AUTOMAKE_TARGETS)
11349 $(EMPTY_AUTOMAKE_TARGETS):
11350 @end example
11351
11352 Another aspect of integrating third-party build systems is whether
11353 they support VPATH builds (@pxref{VPATH Builds}).  Obviously if the
11354 subpackage does not support VPATH builds the whole package will not
11355 support VPATH builds.  This in turns means that @samp{make distcheck}
11356 will not work, because it relies on VPATH builds.  Some people can
11357 live without this (actually, many Automake users have never heard of
11358 @samp{make distcheck}).  Other people may prefer to revamp the
11359 existing @file{Makefile}s to support VPATH@.  Doing so does not
11360 necessarily require Automake, only Autoconf is needed (@pxref{Build
11361 Directories, , Build Directories, autoconf, The Autoconf Manual}).
11362 The necessary substitutions: @samp{@@srcdir@@}, @samp{@@top_srcdir@@},
11363 and @samp{@@top_builddir@@} are defined by @file{configure} when it
11364 processes a @file{Makefile} (@pxref{Preset Output Variables, , Preset
11365 Output Variables, autoconf, The Autoconf Manual}), they are not
11366 computed by the Makefile like the aforementioned @samp{$(distdir)} and
11367 @samp{$(top_distdir)} variables.
11368
11369 It is sometimes inconvenient to modify a third-party @file{Makefile}
11370 to introduce the above required targets.  For instance, one may want to
11371 keep the third-party sources untouched to ease upgrades to new
11372 versions.
11373
11374 @cindex @file{GNUmakefile} including @file{Makefile}
11375 Here are two other ideas.  If GNU make is assumed, one possibility is
11376 to add to that subdirectory a @file{GNUmakefile} that defines the
11377 required targets and includes the third-party @file{Makefile}.  For
11378 this to work in VPATH builds, @file{GNUmakefile} must lie in the build
11379 directory; the easiest way to do this is to write a
11380 @file{GNUmakefile.in} instead, and have it processed with
11381 @code{AC_CONFIG_FILES} from the outer package.  For example if we
11382 assume @file{Makefile} defines all targets except the documentation
11383 targets, and that the @code{check} target is actually called
11384 @code{test}, we could write @file{GNUmakefile} (or
11385 @file{GNUmakefile.in}) like this:
11386
11387 @example
11388 # First, include the real Makefile
11389 include Makefile
11390 # Then, define the other targets needed by Automake Makefiles.
11391 .PHONY: dvi pdf ps info html check
11392 dvi pdf ps info html:
11393 check: test
11394 @end example
11395
11396 @cindex Proxy @file{Makefile} for third-party packages
11397 A similar idea that does not use @code{include} is to write a proxy
11398 @file{Makefile} that dispatches rules to the real @file{Makefile},
11399 either with @samp{$(MAKE) -f Makefile.real $(AM_MAKEFLAGS) target} (if
11400 it's OK to rename the original @file{Makefile}) or with @samp{cd
11401 subdir && $(MAKE) $(AM_MAKEFLAGS) target} (if it's OK to store the
11402 subdirectory project one directory deeper).  The good news is that
11403 this proxy @file{Makefile} can be generated with Automake.  All we
11404 need are @option{-local} targets (@pxref{Extending}) that perform the
11405 dispatch.  Of course the other Automake features are available, so you
11406 could decide to let Automake perform distribution or installation.
11407 Here is a possible @file{Makefile.am}:
11408
11409 @example
11410 all-local:
11411         cd subdir && $(MAKE) $(AM_MAKEFLAGS) all
11412 check-local:
11413         cd subdir && $(MAKE) $(AM_MAKEFLAGS) test
11414 clean-local:
11415         cd subdir && $(MAKE) $(AM_MAKEFLAGS) clean
11416
11417 # Assuming the package knows how to install itself
11418 install-data-local:
11419         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-data
11420 install-exec-local:
11421         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-exec
11422 uninstall-local:
11423         cd subdir && $(MAKE) $(AM_MAKEFLAGS) uninstall
11424
11425 # Distribute files from here.
11426 EXTRA_DIST = subdir/Makefile subdir/program.c ...
11427 @end example
11428
11429 Pushing this idea to the extreme, it is also possible to ignore the
11430 subproject build system and build everything from this proxy
11431 @file{Makefile.am}.  This might sound very sensible if you need VPATH
11432 builds but the subproject does not support them.
11433
11434 @node Distributing
11435 @chapter Distributing @file{Makefile.in}s
11436
11437 Automake places no restrictions on the distribution of the resulting
11438 @file{Makefile.in}s.  We still encourage software authors to
11439 distribute their work under terms like those of the GPL, but doing so
11440 is not required to use Automake.
11441
11442 Some of the files that can be automatically installed via the
11443 @option{--add-missing} switch do fall under the GPL@.  However, these also
11444 have a special exception allowing you to distribute them with your
11445 package, regardless of the licensing you choose.
11446
11447
11448 @node API Versioning
11449 @chapter Automake API Versioning
11450
11451 New Automake releases usually include bug fixes and new features.
11452 Unfortunately they may also introduce new bugs and incompatibilities.
11453 This makes four reasons why a package may require a particular Automake
11454 version.
11455
11456 Things get worse when maintaining a large tree of packages, each one
11457 requiring a different version of Automake.  In the past, this meant that
11458 any developer (and sometimes users) had to install several versions of
11459 Automake in different places, and switch @samp{$PATH} appropriately for
11460 each package.
11461
11462 Starting with version 1.6, Automake installs versioned binaries.  This
11463 means you can install several versions of Automake in the same
11464 @samp{$prefix}, and can select an arbitrary Automake version by running
11465 @command{automake-1.6} or @command{automake-1.7} without juggling with
11466 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
11467 will use @command{automake-1.6} explicitly in their rebuild rules.
11468
11469 The number @samp{1.6} in @command{automake-1.6} is Automake's API version,
11470 not Automake's version.  If a bug fix release is made, for instance
11471 Automake 1.6.1, the API version will remain 1.6.  This means that a
11472 package that works with Automake 1.6 should also work with 1.6.1; after
11473 all, this is what people expect from bug fix releases.
11474
11475 If your package relies on a feature or a bug fix introduced in
11476 a release, you can pass this version as an option to Automake to ensure
11477 older releases will not be used.  For instance, use this in your
11478 @file{configure.ac}:
11479
11480 @example
11481   AM_INIT_AUTOMAKE([1.6.1])    dnl Require Automake 1.6.1 or better.
11482 @end example
11483
11484 @noindent
11485 or, in a particular @file{Makefile.am}:
11486
11487 @example
11488   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
11489 @end example
11490
11491 @noindent
11492 Automake will print an error message if its version is
11493 older than the requested version.
11494
11495
11496 @heading What is in the API
11497
11498 Automake's programming interface is not easy to define.  Basically it
11499 should include at least all @strong{documented} variables and targets
11500 that a @file{Makefile.am} author can use, any behavior associated with
11501 them (e.g., the places where @samp{-hook}'s are run), the command line
11502 interface of @command{automake} and @command{aclocal}, @dots{}
11503
11504 @heading What is not in the API
11505
11506 Every undocumented variable, target, or command line option, is not part
11507 of the API@.  You should avoid using them, as they could change from one
11508 version to the other (even in bug fix releases, if this helps to fix a
11509 bug).
11510
11511 If it turns out you need to use such an undocumented feature, contact
11512 @email{automake@@gnu.org} and try to get it documented and exercised by
11513 the test-suite.
11514
11515 @node Upgrading
11516 @chapter Upgrading a Package to a Newer Automake Version
11517
11518 Automake maintains three kind of files in a package.
11519
11520 @itemize
11521 @item @file{aclocal.m4}
11522 @item @file{Makefile.in}s
11523 @item auxiliary tools like @file{install-sh} or @file{py-compile}
11524 @end itemize
11525
11526 @file{aclocal.m4} is generated by @command{aclocal} and contains some
11527 Automake-supplied M4 macros.  Auxiliary tools are installed by
11528 @samp{automake --add-missing} when needed.  @file{Makefile.in}s are
11529 built from @file{Makefile.am} by @command{automake}, and rely on the
11530 definitions of the M4 macros put in @file{aclocal.m4} as well as the
11531 behavior of the auxiliary tools installed.
11532
11533 Because all of these files are closely related, it is important to
11534 regenerate all of them when upgrading to a newer Automake release.
11535 The usual way to do that is
11536
11537 @example
11538 aclocal # with any option needed (such a -I m4)
11539 autoconf
11540 automake --add-missing --force-missing
11541 @end example
11542
11543 @noindent
11544 or more conveniently:
11545
11546 @example
11547 autoreconf -vfi
11548 @end example
11549
11550 The use of @option{--force-missing} ensures that auxiliary tools will be
11551 overridden by new versions (@pxref{automake Invocation}).
11552
11553 It is important to regenerate all of these files each time Automake is
11554 upgraded, even between bug fixes releases.  For instance, it is not
11555 unusual for a bug fix to involve changes to both the rules generated
11556 in @file{Makefile.in} and the supporting M4 macros copied to
11557 @file{aclocal.m4}.
11558
11559 Presently @command{automake} is able to diagnose situations where
11560 @file{aclocal.m4} has been generated with another version of
11561 @command{aclocal}.  However it never checks whether auxiliary scripts
11562 are up-to-date.  In other words, @command{automake} will tell you when
11563 @command{aclocal} needs to be rerun, but it will never diagnose a
11564 missing @option{--force-missing}.
11565
11566 Before upgrading to a new major release, it is a good idea to read the
11567 file @file{NEWS}.  This file lists all changes between releases: new
11568 features, obsolete constructs, known incompatibilities, and
11569 workarounds.
11570
11571 @node FAQ
11572 @chapter Frequently Asked Questions about Automake
11573
11574 This chapter covers some questions that often come up on the mailing
11575 lists.
11576
11577 @menu
11578 * CVS::                         CVS and generated files
11579 * maintainer-mode::             missing and AM_MAINTAINER_MODE
11580 * Wildcards::                   Why doesn't Automake support wildcards?
11581 * Limitations on File Names::   Limitations on source and installed file names
11582 * Errors with distclean::       Files left in build directory after distclean
11583 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
11584 * Renamed Objects::             Why are object files sometimes renamed?
11585 * Per-Object Flags::            How to simulate per-object flags?
11586 * Multiple Outputs::            Writing rules for tools with many output files
11587 * Hard-Coded Install Paths::    Installing to hard-coded locations
11588 * Debugging Make Rules::        Strategies when things don't work as expected
11589 * Reporting Bugs::              Feedback on bugs and feature requests
11590 @end menu
11591
11592 @node CVS
11593 @section CVS and generated files
11594
11595 @subheading Background: distributed generated Files
11596 @cindex generated files, distributed
11597 @cindex rebuild rules
11598
11599 Packages made with Autoconf and Automake ship with some generated
11600 files like @file{configure} or @file{Makefile.in}.  These files were
11601 generated on the developer's machine and are distributed so that
11602 end-users do not have to install the maintainer tools required to
11603 rebuild them.  Other generated files like Lex scanners, Yacc parsers,
11604 or Info documentation, are usually distributed on similar grounds.
11605
11606 Automake output rules in @file{Makefile}s to rebuild these files.  For
11607 instance, @command{make} will run @command{autoconf} to rebuild
11608 @file{configure} whenever @file{configure.ac} is changed.  This makes
11609 development safer by ensuring a @file{configure} is never out-of-date
11610 with respect to @file{configure.ac}.
11611
11612 As generated files shipped in packages are up-to-date, and because
11613 @command{tar} preserves times-tamps, these rebuild rules are not
11614 triggered when a user unpacks and builds a package.
11615
11616 @subheading Background: CVS and Timestamps
11617 @cindex timestamps and CVS
11618 @cindex CVS and timestamps
11619
11620 Unless you use CVS keywords (in which case files must be updated at
11621 commit time), CVS preserves timestamp during @samp{cvs commit} and
11622 @samp{cvs import -d} operations.
11623
11624 When you check out a file using @samp{cvs checkout} its timestamp is
11625 set to that of the revision that is being checked out.
11626
11627 However, during @command{cvs update}, files will have the date of the
11628 update, not the original timestamp of this revision.  This is meant to
11629 make sure that @command{make} notices sources files have been updated.
11630
11631 This timestamp shift is troublesome when both sources and generated
11632 files are kept under CVS@.  Because CVS processes files in lexical
11633 order, @file{configure.ac} will appear newer than @file{configure}
11634 after a @command{cvs update} that updates both files, even if
11635 @file{configure} was newer than @file{configure.ac} when it was
11636 checked in.  Calling @command{make} will then trigger a spurious rebuild
11637 of @file{configure}.
11638
11639 @subheading Living with CVS in Autoconfiscated Projects
11640 @cindex CVS and generated files
11641 @cindex generated files and CVS
11642
11643 There are basically two clans amongst maintainers: those who keep all
11644 distributed files under CVS, including generated files, and those who
11645 keep generated files @emph{out} of CVS.
11646
11647 @subsubheading All Files in CVS
11648
11649 @itemize @bullet
11650 @item
11651 The CVS repository contains all distributed files so you know exactly
11652 what is distributed, and you can checkout any prior version entirely.
11653
11654 @item
11655 Maintainers can see how generated files evolve (for instance, you can
11656 see what happens to your @file{Makefile.in}s when you upgrade Automake
11657 and make sure they look OK).
11658
11659 @item
11660 Users do not need the autotools to build a checkout of the project, it
11661 works just like a released tarball.
11662
11663 @item
11664 If users use @command{cvs update} to update their copy, instead of
11665 @command{cvs checkout} to fetch a fresh one, timestamps will be
11666 inaccurate.  Some rebuild rules will be triggered and attempt to
11667 run developer tools such as @command{autoconf} or @command{automake}.
11668
11669 Calls to such tools are all wrapped into a call to the @command{missing}
11670 script discussed later (@pxref{maintainer-mode}), so that the user will
11671 see more descriptive warnings about missing or out-of-date tools, and
11672 possible suggestions about how to obtain them, rather than just some
11673 ``command not found'' error, or (worse) some obscure message from some
11674 older version of the required tool they happen to have installed.
11675
11676 Maintainers interested in keeping their package buildable from a CVS
11677 checkout even for those users that lack maintainer-specific tools might
11678 want to provide an helper script (or to enhance their existing bootstrap
11679 script) to fix the timestamps after a
11680 @command{cvs update} or a @command{git checkout}, to prevent spurious
11681 rebuilds.  In case of a project committing the Autotools-generated
11682 files, as well as the generated @file{.info} files, such script might
11683 look something like this:
11684
11685 @smallexample
11686 #!/bin/sh
11687 # fix-timestamp.sh: prevents useless rebuilds after "cvs update"
11688 sleep 1
11689 # aclocal-generated aclocal.m4 depends on locally-installed
11690 # '.m4' macro files, as well as on 'configure.ac'
11691 touch aclocal.m4
11692 sleep 1
11693 # autoconf-generated configure depends on aclocal.m4 and on
11694 # configure.ac
11695 configure config.h.in
11696 # so does autoheader-generated config.h.in
11697 configure config.h.in
11698 # and all the automake-generated Makefile.in files
11699 touch `find . -name Makefile.in -print`
11700 # finally, the makeinfo-generated '.info' files depend on the
11701 # corresponding '.texi' files
11702 touch doc/*.info
11703 @end smallexample
11704
11705 @item
11706 In distributed development, developers are likely to have different
11707 version of the maintainer tools installed.  In this case rebuilds
11708 triggered by timestamp lossage will lead to spurious changes
11709 to generated files.  There are several solutions to this:
11710
11711 @itemize
11712 @item
11713 All developers should use the same versions, so that the rebuilt files
11714 are identical to files in CVS@.  (This starts to be difficult when each
11715 project you work on uses different versions.)
11716 @item
11717 Or people use a script to fix the timestamp after a checkout (the GCC
11718 folks have such a script).
11719 @item
11720 Or @file{configure.ac} uses @code{AM_MAINTAINER_MODE}, which will
11721 disable all of these rebuild rules by default.  This is further discussed
11722 in @ref{maintainer-mode}.
11723 @end itemize
11724
11725 @item
11726 Although we focused on spurious rebuilds, the converse can also
11727 happen.  CVS's timestamp handling can also let you think an
11728 out-of-date file is up-to-date.
11729
11730 For instance, suppose a developer has modified @file{Makefile.am} and
11731 has rebuilt @file{Makefile.in}, and then decides to do a last-minute
11732 change to @file{Makefile.am} right before checking in both files
11733 (without rebuilding @file{Makefile.in} to account for the change).
11734
11735 This last change to @file{Makefile.am} makes the copy of
11736 @file{Makefile.in} out-of-date.  Since CVS processes files
11737 alphabetically, when another developer @samp{cvs update}s his or her
11738 tree, @file{Makefile.in} will happen to be newer than
11739 @file{Makefile.am}.  This other developer will not see that
11740 @file{Makefile.in} is out-of-date.
11741
11742 @end itemize
11743
11744 @subsubheading Generated Files out of CVS
11745
11746 One way to get CVS and @command{make} working peacefully is to never
11747 store generated files in CVS, i.e., do not CVS-control files that
11748 are @file{Makefile} targets (also called @emph{derived} files).
11749
11750 This way developers are not annoyed by changes to generated files.  It
11751 does not matter if they all have different versions (assuming they are
11752 compatible, of course).  And finally, timestamps are not lost, changes
11753 to sources files can't be missed as in the
11754 @file{Makefile.am}/@file{Makefile.in} example discussed earlier.
11755
11756 The drawback is that the CVS repository is not an exact copy of what
11757 is distributed and that users now need to install various development
11758 tools (maybe even specific versions) before they can build a checkout.
11759 But, after all, CVS's job is versioning, not distribution.
11760
11761 Allowing developers to use different versions of their tools can also
11762 hide bugs during distributed development.  Indeed, developers will be
11763 using (hence testing) their own generated files, instead of the
11764 generated files that will be released actually.  The developer who
11765 prepares the tarball might be using a version of the tool that
11766 produces bogus output (for instance a non-portable C file), something
11767 other developers could have noticed if they weren't using their own
11768 versions of this tool.
11769
11770 @subheading Third-party Files
11771 @cindex CVS and third-party files
11772 @cindex third-party files and CVS
11773
11774 Another class of files not discussed here (because they do not cause
11775 timestamp issues) are files that are shipped with a package, but
11776 maintained elsewhere.  For instance, tools like @command{gettextize}
11777 and @command{autopoint} (from Gettext) or @command{libtoolize} (from
11778 Libtool), will install or update files in your package.
11779
11780 These files, whether they are kept under CVS or not, raise similar
11781 concerns about version mismatch between developers' tools.  The
11782 Gettext manual has a section about this, see @ref{CVS Issues, CVS
11783 Issues, Integrating with CVS, gettext, GNU gettext tools}.
11784
11785 @node maintainer-mode
11786 @section @command{missing} and @code{AM_MAINTAINER_MODE}
11787
11788 @subheading @command{missing}
11789 @cindex @command{missing}, purpose
11790
11791 The @command{missing} script is a wrapper around several maintainer
11792 tools, designed to warn users if a maintainer tool is required but
11793 missing.  Typical maintainer tools are @command{autoconf},
11794 @command{automake}, @command{bison}, etc.  Because file generated by
11795 these tools are shipped with the other sources of a package, these
11796 tools shouldn't be required during a user build and they are not
11797 checked for in @file{configure}.
11798
11799 However, if for some reason a rebuild rule is triggered and involves a
11800 missing tool, @command{missing} will notice it and warn the user, even
11801 suggesting how to obtain such a tool (at least in case it is a well-known
11802 one, like @command{makeinfo} or @command{bison}).  This is more helpful
11803 and user-friendly than just having the rebuild rules spewing out a terse
11804 error message like @samp{sh: @var{tool}: command not found}.  Similarly,
11805 @command{missing} will warn the user if it detects that a maintainer
11806 tool it attempted to use seems too old (be warned that diagnosing this
11807 correctly is typically more difficult that detecting missing tools, and
11808 requires cooperation from the tool itself, so it won't always work).
11809
11810 If the required tool is installed, @command{missing} will run it and
11811 won't attempt to continue after failures.  This is correct during
11812 development: developers love fixing failures.  However, users with
11813 missing or too old maintainer tools may get an error when the rebuild
11814 rule is spuriously triggered, halting the build.  This failure to let
11815 the build continue is one of the arguments of the
11816 @code{AM_MAINTAINER_MODE} advocates.
11817
11818 @subheading @code{AM_MAINTAINER_MODE}
11819 @cindex @code{AM_MAINTAINER_MODE}, purpose
11820 @acindex AM_MAINTAINER_MODE
11821
11822 @code{AM_MAINTAINER_MODE} allows you to choose whether the so called
11823 "rebuild rules" should be enabled or disabled.  With
11824 @code{AM_MAINTAINER_MODE([enable])}, they are enabled by default,
11825 otherwise they are disabled by default.  In the latter case, if
11826 you have @code{AM_MAINTAINER_MODE} in @file{configure.ac}, and run
11827 @samp{./configure && make}, then @command{make} will *never* attempt to
11828 rebuild @file{configure}, @file{Makefile.in}s, Lex or Yacc outputs, etc.
11829 I.e., this disables build rules for files that are usually distributed
11830 and that users should normally not have to update.
11831
11832 The user can override the default setting by passing either
11833 @samp{--enable-maintainer-mode} or @samp{--disable-maintainer-mode}
11834 to @command{configure}.
11835
11836 People use @code{AM_MAINTAINER_MODE} either because they do not want their
11837 users (or themselves) annoyed by timestamps lossage (@pxref{CVS}), or
11838 because they simply can't stand the rebuild rules and prefer running
11839 maintainer tools explicitly.
11840
11841 @code{AM_MAINTAINER_MODE} also allows you to disable some custom build
11842 rules conditionally.  Some developers use this feature to disable
11843 rules that need exotic tools that users may not have available.
11844
11845 Several years ago Fran@,{c}ois Pinard pointed out several arguments
11846 against this @code{AM_MAINTAINER_MODE} macro.  Most of them relate to
11847 insecurity.  By removing dependencies you get non-dependable builds:
11848 changes to sources files can have no effect on generated files and this
11849 can be very confusing when unnoticed.  He adds that security shouldn't
11850 be reserved to maintainers (what @option{--enable-maintainer-mode}
11851 suggests), on the contrary.  If one user has to modify a
11852 @file{Makefile.am}, then either @file{Makefile.in} should be updated
11853 or a warning should be output (this is what Automake uses
11854 @command{missing} for) but the last thing you want is that nothing
11855 happens and the user doesn't notice it (this is what happens when
11856 rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
11857
11858 Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro was
11859 swayed by Fran@,{c}ois's arguments, and got rid of
11860 @code{AM_MAINTAINER_MODE} in all of his packages.
11861
11862 Still many people continue to use @code{AM_MAINTAINER_MODE}, because
11863 it helps them working on projects where all files are kept under version
11864 control, and because @command{missing} isn't enough if you have the
11865 wrong version of the tools.
11866
11867
11868 @node Wildcards
11869 @section Why doesn't Automake support wildcards?
11870 @cindex wildcards
11871
11872 Developers are lazy.  They would often like to use wildcards in
11873 @file{Makefile.am}s, so that they would not need to remember to
11874 update @file{Makefile.am}s every time they add, delete, or rename
11875 a file.
11876
11877 There are several objections to this:
11878 @itemize
11879 @item
11880 When using CVS (or similar) developers need to remember they have to
11881 run @samp{cvs add} or @samp{cvs rm} anyway.  Updating
11882 @file{Makefile.am} accordingly quickly becomes a reflex.
11883
11884 Conversely, if your application doesn't compile
11885 because you forgot to add a file in @file{Makefile.am}, it will help
11886 you remember to @samp{cvs add} it.
11887
11888 @item
11889 Using wildcards makes it easy to distribute files by mistake.  For
11890 instance, some code a developer is experimenting with (a test case,
11891 say) that should not be part of the distribution.
11892
11893 @item
11894 Using wildcards it's easy to omit some files by mistake.  For
11895 instance, one developer creates a new file, uses it in many places,
11896 but forgets to commit it.  Another developer then checks out the
11897 incomplete project and is able to run @samp{make dist} successfully,
11898 even though a file is missing. By listing files, @samp{make dist}
11899 @emph{will} complain.
11900
11901 @item
11902 Wildcards are not portable to some non-GNU @command{make} implementations,
11903 e.g., NetBSD @command{make} will not expand globs such as @samp{*} in
11904 prerequisites of a target.
11905
11906 @item
11907 Finally, it's really hard to @emph{forget} to add a file to
11908 @file{Makefile.am}: files that are not listed in @file{Makefile.am} are
11909 not compiled or installed, so you can't even test them.
11910 @end itemize
11911
11912 Still, these are philosophical objections, and as such you may disagree,
11913 or find enough value in wildcards to dismiss all of them.  Before you
11914 start writing a patch against Automake to teach it about wildcards,
11915 let's see the main technical issue: portability.
11916
11917 Although @samp{$(wildcard ...)} works with GNU @command{make}, it is
11918 not portable to other @command{make} implementations.
11919
11920 The only way Automake could support @command{$(wildcard ...)} is by
11921 expanding @command{$(wildcard ...)} when @command{automake} is run.
11922 The resulting @file{Makefile.in}s would be portable since they would
11923 list all files and not use @samp{$(wildcard ...)}.  However that
11924 means developers would need to remember to run @command{automake} each
11925 time they add, delete, or rename files.
11926
11927 Compared to editing @file{Makefile.am}, this is a very small gain.  Sure,
11928 it's easier and faster to type @samp{automake; make} than to type
11929 @samp{emacs Makefile.am; make}.  But nobody bothered enough to write a
11930 patch to add support for this syntax.  Some people use scripts to
11931 generate file lists in @file{Makefile.am} or in separate
11932 @file{Makefile} fragments.
11933
11934 Even if you don't care about portability, and are tempted to use
11935 @samp{$(wildcard ...)} anyway because you target only GNU Make, you
11936 should know there are many places where Automake needs to know exactly
11937 which files should be processed.  As Automake doesn't know how to
11938 expand @samp{$(wildcard ...)}, you cannot use it in these places.
11939 @samp{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
11940 variables as far Automake is concerned.
11941
11942 You can get warnings about @samp{$(wildcard ...}) constructs using the
11943 @option{-Wportability} flag.
11944
11945 @node Limitations on File Names
11946 @section Limitations on File Names
11947 @cindex file names, limitations on
11948
11949 Automake attempts to support all kinds of file names, even those that
11950 contain unusual characters or are unusually long.  However, some
11951 limitations are imposed by the underlying operating system and tools.
11952
11953 Most operating systems prohibit the use of the null byte in file
11954 names, and reserve @samp{/} as a directory separator.  Also, they
11955 require that file names are properly encoded for the user's locale.
11956 Automake is subject to these limits.
11957
11958 Portable packages should limit themselves to POSIX file
11959 names.  These can contain ASCII letters and digits,
11960 @samp{_}, @samp{.}, and @samp{-}.  File names consist of components
11961 separated by @samp{/}.  File name components cannot begin with
11962 @samp{-}.
11963
11964 Portable POSIX file names cannot contain components that exceed a
11965 14-byte limit, but nowadays it's normally safe to assume the
11966 more-generous XOPEN limit of 255 bytes.  POSIX
11967 limits file names to 255 bytes (XOPEN allows 1023 bytes),
11968 but you may want to limit a source tarball to file names of 99 bytes
11969 to avoid interoperability problems with old versions of @command{tar}.
11970
11971 If you depart from these rules (e.g., by using non-ASCII
11972 characters in file names, or by using lengthy file names), your
11973 installers may have problems for reasons unrelated to Automake.
11974 However, if this does not concern you, you should know about the
11975 limitations imposed by Automake itself.  These limitations are
11976 undesirable, but some of them seem to be inherent to underlying tools
11977 like Autoconf, Make, M4, and the shell.  They fall into three
11978 categories: install directories, build directories, and file names.
11979
11980 The following characters:
11981
11982 @example
11983 @r{newline} " # $ ' `
11984 @end example
11985
11986 should not appear in the names of install directories.  For example,
11987 the operand of @command{configure}'s @option{--prefix} option should
11988 not contain these characters.
11989
11990 Build directories suffer the same limitations as install directories,
11991 and in addition should not contain the following characters:
11992
11993 @example
11994 & @@ \
11995 @end example
11996
11997 For example, the full name of the directory containing the source
11998 files should not contain these characters.
11999
12000 Source and installation file names like @file{main.c} are limited even
12001 further: they should conform to the POSIX/XOPEN
12002 rules described above.  In addition, if you plan to port to
12003 non-POSIX environments, you should avoid file names that
12004 differ only in case (e.g., @file{makefile} and @file{Makefile}).
12005 Nowadays it is no longer worth worrying about the 8.3 limits of
12006 DOS file systems.
12007
12008 @c FIXME This should probably be moved in the "Checking the Distribution"
12009 @c FIXME section...
12010 @node Errors with distclean
12011 @section Errors with distclean
12012 @cindex @code{distclean}, diagnostic
12013 @cindex @samp{make distclean}, diagnostic
12014 @cindex dependencies and distributed files
12015 @trindex distclean
12016
12017 This is a diagnostic you might encounter while running @samp{make
12018 distcheck}.
12019
12020 As explained in @ref{Checking the Distribution}, @samp{make distcheck}
12021 attempts to build and check your package for errors like this one.
12022
12023 @samp{make distcheck} will perform a @code{VPATH} build of your
12024 package (@pxref{VPATH Builds}), and then call @samp{make distclean}.
12025 Files left in the build directory after @samp{make distclean} has run
12026 are listed after this error.
12027
12028 This diagnostic really covers two kinds of errors:
12029
12030 @itemize @bullet
12031 @item
12032 files that are forgotten by distclean;
12033 @item
12034 distributed files that are erroneously rebuilt.
12035 @end itemize
12036
12037 The former left-over files are not distributed, so the fix is to mark
12038 them for cleaning (@pxref{Clean}), this is obvious and doesn't deserve
12039 more explanations.
12040
12041 The latter bug is not always easy to understand and fix, so let's
12042 proceed with an example.  Suppose our package contains a program for
12043 which we want to build a man page using @command{help2man}.  GNU
12044 @command{help2man} produces simple manual pages from the @option{--help}
12045 and @option{--version} output of other commands (@pxref{Top, , Overview,
12046 help2man, The Help2man Manual}).  Because we don't want to force our
12047 users to install @command{help2man}, we decide to distribute the
12048 generated man page using the following setup.
12049
12050 @example
12051 # This Makefile.am is bogus.
12052 bin_PROGRAMS = foo
12053 foo_SOURCES = foo.c
12054 dist_man_MANS = foo.1
12055
12056 foo.1: foo$(EXEEXT)
12057         help2man --output=foo.1 ./foo$(EXEEXT)
12058 @end example
12059
12060 This will effectively distribute the man page.  However,
12061 @samp{make distcheck} will fail with:
12062
12063 @example
12064 ERROR: files left in build directory after distclean:
12065 ./foo.1
12066 @end example
12067
12068 Why was @file{foo.1} rebuilt?  Because although distributed,
12069 @file{foo.1} depends on a non-distributed built file:
12070 @file{foo$(EXEEXT)}.  @file{foo$(EXEEXT)} is built by the user, so it
12071 will always appear to be newer than the distributed @file{foo.1}.
12072
12073 @samp{make distcheck} caught an inconsistency in our package.  Our
12074 intent was to distribute @file{foo.1} so users do not need to install
12075 @command{help2man}, however since this rule causes this file to be
12076 always rebuilt, users @emph{do} need @command{help2man}.  Either we
12077 should ensure that @file{foo.1} is not rebuilt by users, or there is
12078 no point in distributing @file{foo.1}.
12079
12080 More generally, the rule is that distributed files should never depend
12081 on non-distributed built files.  If you distribute something
12082 generated, distribute its sources.
12083
12084 One way to fix the above example, while still distributing
12085 @file{foo.1} is to not depend on @file{foo$(EXEEXT)}.  For instance,
12086 assuming @command{foo --version} and @command{foo --help} do not
12087 change unless @file{foo.c} or @file{configure.ac} change, we could
12088 write the following @file{Makefile.am}:
12089
12090 @example
12091 bin_PROGRAMS = foo
12092 foo_SOURCES = foo.c
12093 dist_man_MANS = foo.1
12094
12095 foo.1: foo.c $(top_srcdir)/configure.ac
12096         $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
12097         help2man --output=foo.1 ./foo$(EXEEXT)
12098 @end example
12099
12100 This way, @file{foo.1} will not get rebuilt every time
12101 @file{foo$(EXEEXT)} changes.  The @command{make} call makes sure
12102 @file{foo$(EXEEXT)} is up-to-date before @command{help2man}.  Another
12103 way to ensure this would be to use separate directories for binaries
12104 and man pages, and set @code{SUBDIRS} so that binaries are built
12105 before man pages.
12106
12107 We could also decide not to distribute @file{foo.1}.  In
12108 this case it's fine to have @file{foo.1} dependent upon
12109 @file{foo$(EXEEXT)}, since both will have to be rebuilt.
12110 However it would be impossible to build the package in a
12111 cross-compilation, because building @file{foo.1} involves
12112 an @emph{execution} of @file{foo$(EXEEXT)}.
12113
12114 Another context where such errors are common is when distributed files
12115 are built by tools that are built by the package.  The pattern is
12116 similar:
12117
12118 @example
12119 distributed-file: built-tools distributed-sources
12120         build-command
12121 @end example
12122
12123 @noindent
12124 should be changed to
12125
12126 @example
12127 distributed-file: distributed-sources
12128         $(MAKE) $(AM_MAKEFLAGS) built-tools
12129         build-command
12130 @end example
12131
12132 @noindent
12133 or you could choose not to distribute @file{distributed-file}, if
12134 cross-compilation does not matter.
12135
12136 The points made through these examples are worth a summary:
12137
12138 @cartouche
12139 @itemize
12140 @item
12141 Distributed files should never depend upon non-distributed built
12142 files.
12143 @item
12144 Distributed files should be distributed with all their dependencies.
12145 @item
12146 If a file is @emph{intended} to be rebuilt by users, then there is no point
12147 in distributing it.
12148 @end itemize
12149 @end cartouche
12150
12151 @vrindex distcleancheck_listfiles
12152 For desperate cases, it's always possible to disable this check by
12153 setting @code{distcleancheck_listfiles} as documented in @ref{Checking
12154 the Distribution}.
12155 Make sure you do understand the reason why @samp{make distcheck}
12156 complains before you do this.  @code{distcleancheck_listfiles} is a
12157 way to @emph{hide} errors, not to fix them.  You can always do better.
12158
12159 @node Flag Variables Ordering
12160 @section Flag Variables Ordering
12161 @cindex Ordering flag variables
12162 @cindex Flag variables, ordering
12163
12164 @display
12165 What is the difference between @code{AM_CFLAGS}, @code{CFLAGS}, and
12166 @code{mumble_CFLAGS}?
12167 @end display
12168
12169 @display
12170 Why does @command{automake} output @code{CPPFLAGS} after
12171 @code{AM_CPPFLAGS} on compile lines?  Shouldn't it be the converse?
12172 @end display
12173
12174 @display
12175 My @file{configure} adds some warning flags into @code{CXXFLAGS}.  In
12176 one @file{Makefile.am} I would like to append a new flag, however if I
12177 put the flag into @code{AM_CXXFLAGS} it is prepended to the other
12178 flags, not appended.
12179 @end display
12180
12181 @subheading Compile Flag Variables
12182 @cindex Flag Variables, Ordering
12183 @cindex Compile Flag Variables
12184 @cindex @code{AM_CCASFLAGS} and @code{CCASFLAGS}
12185 @cindex @code{AM_CFLAGS} and @code{CFLAGS}
12186 @cindex @code{AM_CPPFLAGS} and @code{CPPFLAGS}
12187 @cindex @code{AM_CXXFLAGS} and @code{CXXFLAGS}
12188 @cindex @code{AM_FCFLAGS} and @code{FCFLAGS}
12189 @cindex @code{AM_FFLAGS} and @code{FFLAGS}
12190 @cindex @code{AM_GCJFLAGS} and @code{GCJFLAGS}
12191 @cindex @code{AM_LDFLAGS} and @code{LDFLAGS}
12192 @cindex @code{AM_LFLAGS} and @code{LFLAGS}
12193 @cindex @code{AM_LIBTOOLFLAGS} and @code{LIBTOOLFLAGS}
12194 @cindex @code{AM_OBJCFLAGS} and @code{OBJCFLAGS}
12195 @cindex @code{AM_OBJCXXFLAGS} and @code{OBJXXCFLAGS}
12196 @cindex @code{AM_RFLAGS} and @code{RFLAGS}
12197 @cindex @code{AM_UPCFLAGS} and @code{UPCFLAGS}
12198 @cindex @code{AM_YFLAGS} and @code{YFLAGS}
12199 @cindex @code{CCASFLAGS} and @code{AM_CCASFLAGS}
12200 @cindex @code{CFLAGS} and @code{AM_CFLAGS}
12201 @cindex @code{CPPFLAGS} and @code{AM_CPPFLAGS}
12202 @cindex @code{CXXFLAGS} and @code{AM_CXXFLAGS}
12203 @cindex @code{FCFLAGS} and @code{AM_FCFLAGS}
12204 @cindex @code{FFLAGS} and @code{AM_FFLAGS}
12205 @cindex @code{GCJFLAGS} and @code{AM_GCJFLAGS}
12206 @cindex @code{LDFLAGS} and @code{AM_LDFLAGS}
12207 @cindex @code{LFLAGS} and @code{AM_LFLAGS}
12208 @cindex @code{LIBTOOLFLAGS} and @code{AM_LIBTOOLFLAGS}
12209 @cindex @code{OBJCFLAGS} and @code{AM_OBJCFLAGS}
12210 @cindex @code{OBJCXXFLAGS} and @code{AM_OBJCXXFLAGS}
12211 @cindex @code{RFLAGS} and @code{AM_RFLAGS}
12212 @cindex @code{UPCFLAGS} and @code{AM_UPCFLAGS}
12213 @cindex @code{YFLAGS} and @code{AM_YFLAGS}
12214
12215 This section attempts to answer all the above questions.  We will
12216 mostly discuss @code{CPPFLAGS} in our examples, but actually the
12217 answer holds for all the compile flags used in Automake:
12218 @code{CCASFLAGS}, @code{CFLAGS}, @code{CPPFLAGS}, @code{CXXFLAGS},
12219 @code{FCFLAGS}, @code{FFLAGS}, @code{GCJFLAGS}, @code{LDFLAGS},
12220 @code{LFLAGS}, @code{LIBTOOLFLAGS}, @code{OBJCFLAGS}, @code{OBJCXXFLAGS},
12221 @code{RFLAGS}, @code{UPCFLAGS}, and @code{YFLAGS}.
12222
12223 @code{CPPFLAGS}, @code{AM_CPPFLAGS}, and @code{mumble_CPPFLAGS} are
12224 three variables that can be used to pass flags to the C preprocessor
12225 (actually these variables are also used for other languages like C++
12226 or preprocessed Fortran).  @code{CPPFLAGS} is the user variable
12227 (@pxref{User Variables}), @code{AM_CPPFLAGS} is the Automake variable,
12228 and @code{mumble_CPPFLAGS} is the variable specific to the
12229 @code{mumble} target (we call this a per-target variable,
12230 @pxref{Program and Library Variables}).
12231
12232 Automake always uses two of these variables when compiling C sources
12233 files.  When compiling an object file for the @code{mumble} target,
12234 the first variable will be @code{mumble_CPPFLAGS} if it is defined, or
12235 @code{AM_CPPFLAGS} otherwise.  The second variable is always
12236 @code{CPPFLAGS}.
12237
12238 In the following example,
12239
12240 @example
12241 bin_PROGRAMS = foo bar
12242 foo_SOURCES = xyz.c
12243 bar_SOURCES = main.c
12244 foo_CPPFLAGS = -DFOO
12245 AM_CPPFLAGS = -DBAZ
12246 @end example
12247
12248 @noindent
12249 @file{xyz.o} will be compiled with @samp{$(foo_CPPFLAGS) $(CPPFLAGS)},
12250 (because @file{xyz.o} is part of the @code{foo} target), while
12251 @file{main.o} will be compiled with @samp{$(AM_CPPFLAGS) $(CPPFLAGS)}
12252 (because there is no per-target variable for target @code{bar}).
12253
12254 The difference between @code{mumble_CPPFLAGS} and @code{AM_CPPFLAGS}
12255 being clear enough, let's focus on @code{CPPFLAGS}.  @code{CPPFLAGS}
12256 is a user variable, i.e., a variable that users are entitled to modify
12257 in order to compile the package.  This variable, like many others,
12258 is documented at the end of the output of @samp{configure --help}.
12259
12260 For instance, someone who needs to add @file{/home/my/usr/include} to
12261 the C compiler's search path would configure a package with
12262
12263 @example
12264 ./configure CPPFLAGS='-I /home/my/usr/include'
12265 @end example
12266
12267 @noindent
12268 and this flag would be propagated to the compile rules of all
12269 @file{Makefile}s.
12270
12271 It is also not uncommon to override a user variable at
12272 @command{make}-time.  Many installers do this with @code{prefix}, but
12273 this can be useful with compiler flags too.  For instance, if, while
12274 debugging a C++ project, you need to disable optimization in one
12275 specific object file, you can run something like
12276
12277 @example
12278 rm file.o
12279 make CXXFLAGS=-O0 file.o
12280 make
12281 @end example
12282
12283 The reason @samp{$(CPPFLAGS)} appears after @samp{$(AM_CPPFLAGS)} or
12284 @samp{$(mumble_CPPFLAGS)} in the compile command is that users
12285 should always have the last say.  It probably makes more sense if you
12286 think about it while looking at the @samp{CXXFLAGS=-O0} above, which
12287 should supersede any other switch from @code{AM_CXXFLAGS} or
12288 @code{mumble_CXXFLAGS} (and this of course replaces the previous value
12289 of @code{CXXFLAGS}).
12290
12291 You should never redefine a user variable such as @code{CPPFLAGS} in
12292 @file{Makefile.am}.  Use @samp{automake -Woverride} to diagnose such
12293 mistakes.  Even something like
12294
12295 @example
12296 CPPFLAGS = -DDATADIR=\"$(datadir)\" @@CPPFLAGS@@
12297 @end example
12298
12299 @noindent
12300 is erroneous.  Although this preserves @file{configure}'s value of
12301 @code{CPPFLAGS}, the definition of @code{DATADIR} will disappear if a
12302 user attempts to override @code{CPPFLAGS} from the @command{make}
12303 command line.
12304
12305 @example
12306 AM_CPPFLAGS = -DDATADIR=\"$(datadir)\"
12307 @end example
12308
12309 @noindent
12310 is all that is needed here if no per-target flags are used.
12311
12312 You should not add options to these user variables within
12313 @file{configure} either, for the same reason.  Occasionally you need
12314 to modify these variables to perform a test, but you should reset
12315 their values afterwards.  In contrast, it is OK to modify the
12316 @samp{AM_} variables within @file{configure} if you @code{AC_SUBST}
12317 them, but it is rather rare that you need to do this, unless you
12318 really want to change the default definitions of the @samp{AM_}
12319 variables in all @file{Makefile}s.
12320
12321 What we recommend is that you define extra flags in separate
12322 variables.  For instance, you may write an Autoconf macro that computes
12323 a set of warning options for the C compiler, and @code{AC_SUBST} them
12324 in @code{WARNINGCFLAGS}; you may also have an Autoconf macro that
12325 determines which compiler and which linker flags should be used to
12326 link with library @file{libfoo}, and @code{AC_SUBST} these in
12327 @code{LIBFOOCFLAGS} and @code{LIBFOOLDFLAGS}.  Then, a
12328 @file{Makefile.am} could use these variables as follows:
12329
12330 @example
12331 AM_CFLAGS = $(WARNINGCFLAGS)
12332 bin_PROGRAMS = prog1 prog2
12333 prog1_SOURCES = @dots{}
12334 prog2_SOURCES = @dots{}
12335 prog2_CFLAGS = $(LIBFOOCFLAGS) $(AM_CFLAGS)
12336 prog2_LDFLAGS = $(LIBFOOLDFLAGS)
12337 @end example
12338
12339 In this example both programs will be compiled with the flags
12340 substituted into @samp{$(WARNINGCFLAGS)}, and @code{prog2} will
12341 additionally be compiled with the flags required to link with
12342 @file{libfoo}.
12343
12344 Note that listing @code{AM_CFLAGS} in a per-target @code{CFLAGS}
12345 variable is a common idiom to ensure that @code{AM_CFLAGS} applies to
12346 every target in a @file{Makefile.in}.
12347
12348 Using variables like this gives you full control over the ordering of
12349 the flags.  For instance, if there is a flag in $(WARNINGCFLAGS) that
12350 you want to negate for a particular target, you can use something like
12351 @samp{prog1_CFLAGS = $(AM_CFLAGS) -no-flag}.  If all of these flags had
12352 been forcefully appended to @code{CFLAGS}, there would be no way to
12353 disable one flag.  Yet another reason to leave user variables to
12354 users.
12355
12356 Finally, we have avoided naming the variable of the example
12357 @code{LIBFOO_LDFLAGS} (with an underscore) because that would cause
12358 Automake to think that this is actually a per-target variable (like
12359 @code{mumble_LDFLAGS}) for some non-declared @code{LIBFOO} target.
12360
12361 @subheading Other Variables
12362
12363 There are other variables in Automake that follow similar principles
12364 to allow user options.  For instance, Texinfo rules (@pxref{Texinfo})
12365 use @code{MAKEINFOFLAGS} and @code{AM_MAKEINFOFLAGS}.  Similarly,
12366 DejaGnu tests (@pxref{DejaGnu Tests}) use @code{RUNTESTDEFAULTFLAGS} and
12367 @code{AM_RUNTESTDEFAULTFLAGS}.  The tags and ctags rules
12368 (@pxref{Tags}) use @code{ETAGSFLAGS}, @code{AM_ETAGSFLAGS},
12369 @code{CTAGSFLAGS}, and @code{AM_CTAGSFLAGS}.  Java rules
12370 (@pxref{Java}) use @code{JAVACFLAGS} and @code{AM_JAVACFLAGS}.  None
12371 of these rules support per-target flags (yet).
12372
12373 To some extent, even @code{AM_MAKEFLAGS} (@pxref{Subdirectories})
12374 obeys this naming scheme.  The slight difference is that
12375 @code{MAKEFLAGS} is passed to sub-@command{make}s implicitly by
12376 @command{make} itself.
12377
12378 @code{ARFLAGS} (@pxref{A Library}) is usually defined by Automake and
12379 has neither @code{AM_} nor per-target cousin.
12380
12381 Finally you should not think that the existence of a per-target
12382 variable implies the existence of an @code{AM_} variable or of a user
12383 variable.  For instance, the @code{mumble_LDADD} per-target variable
12384 overrides the makefile-wide @code{LDADD} variable (which is not a user
12385 variable), and @code{mumble_LIBADD} exists only as a per-target
12386 variable.  @xref{Program and Library Variables}.
12387
12388
12389 @node Renamed Objects
12390 @section Why are object files sometimes renamed?
12391
12392 This happens when per-target compilation flags are used.  Object
12393 files need to be renamed just in case they would clash with object
12394 files compiled from the same sources, but with different flags.
12395 Consider the following example.
12396
12397 @example
12398 bin_PROGRAMS = true false
12399 true_SOURCES = generic.c
12400 true_CPPFLAGS = -DEXIT_CODE=0
12401 false_SOURCES = generic.c
12402 false_CPPFLAGS = -DEXIT_CODE=1
12403 @end example
12404
12405 @noindent
12406 Obviously the two programs are built from the same source, but it
12407 would be bad if they shared the same object, because @file{generic.o}
12408 cannot be built with both @samp{-DEXIT_CODE=0} @emph{and}
12409 @samp{-DEXIT_CODE=1}.  Therefore @command{automake} outputs rules to
12410 build two different objects: @file{true-generic.o} and
12411 @file{false-generic.o}.
12412
12413 @command{automake} doesn't actually look whether source files are
12414 shared to decide if it must rename objects.  It will just rename all
12415 objects of a target as soon as it sees per-target compilation flags
12416 used.
12417
12418 It's OK to share object files when per-target compilation flags are not
12419 used.  For instance, @file{true} and @file{false} will both use
12420 @file{version.o} in the following example.
12421
12422 @example
12423 AM_CPPFLAGS = -DVERSION=1.0
12424 bin_PROGRAMS = true false
12425 true_SOURCES = true.c version.c
12426 false_SOURCES = false.c version.c
12427 @end example
12428
12429 Note that the renaming of objects is also affected by the
12430 @code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
12431
12432
12433 @node Per-Object Flags
12434 @section Per-Object Flags Emulation
12435 @cindex Per-object flags, emulated
12436
12437 @display
12438 One of my source files needs to be compiled with different flags.  How
12439 do I do?
12440 @end display
12441
12442 Automake supports per-program and per-library compilation flags (see
12443 @ref{Program and Library Variables} and @ref{Flag Variables
12444 Ordering}).  With this you can define compilation flags that apply to
12445 all files compiled for a target.  For instance, in
12446
12447 @example
12448 bin_PROGRAMS = foo
12449 foo_SOURCES = foo.c foo.h bar.c bar.h main.c
12450 foo_CFLAGS = -some -flags
12451 @end example
12452
12453 @noindent
12454 @file{foo-foo.o}, @file{foo-bar.o}, and @file{foo-main.o} will all be
12455 compiled with @samp{-some -flags}.  (If you wonder about the names of
12456 these object files, see @ref{Renamed Objects}.)  Note that
12457 @code{foo_CFLAGS} gives the flags to use when compiling all the C
12458 sources of the @emph{program} @code{foo}, it has nothing to do with
12459 @file{foo.c} or @file{foo-foo.o} specifically.
12460
12461 What if @file{foo.c} needs to be compiled into @file{foo.o} using some
12462 specific flags, that none of the other files requires?  Obviously
12463 per-program flags are not directly applicable here.  Something like
12464 per-object flags are expected, i.e., flags that would be used only
12465 when creating @file{foo-foo.o}.  Automake does not support that,
12466 however this is easy to simulate using a library that contains only
12467 that object, and compiling this library with per-library flags.
12468
12469 @example
12470 bin_PROGRAMS = foo
12471 foo_SOURCES = bar.c bar.h main.c
12472 foo_CFLAGS = -some -flags
12473 foo_LDADD = libfoo.a
12474 noinst_LIBRARIES = libfoo.a
12475 libfoo_a_SOURCES = foo.c foo.h
12476 libfoo_a_CFLAGS = -some -other -flags
12477 @end example
12478
12479 Here @file{foo-bar.o} and @file{foo-main.o} will all be
12480 compiled with @samp{-some -flags}, while @file{libfoo_a-foo.o} will
12481 be compiled using @samp{-some -other -flags}.  Eventually, all
12482 three objects will be linked to form @file{foo}.
12483
12484 This trick can also be achieved using Libtool convenience libraries,
12485 for instance @samp{noinst_LTLIBRARIES = libfoo.la} (@pxref{Libtool
12486 Convenience Libraries}).
12487
12488 Another tempting idea to implement per-object flags is to override the
12489 compile rules @command{automake} would output for these files.
12490 Automake will not define a rule for a target you have defined, so you
12491 could think about defining the @samp{foo-foo.o: foo.c} rule yourself.
12492 We recommend against this, because this is error prone.  For instance,
12493 if you add such a rule to the first example, it will break the day you
12494 decide to remove @code{foo_CFLAGS} (because @file{foo.c} will then be
12495 compiled as @file{foo.o} instead of @file{foo-foo.o}, @pxref{Renamed
12496 Objects}).  Also in order to support dependency tracking, the two
12497 @file{.o}/@file{.obj} extensions, and all the other flags variables
12498 involved in a compilation, you will end up modifying a copy of the
12499 rule previously output by @command{automake} for this file.  If a new
12500 release of Automake generates a different rule, your copy will need to
12501 be updated by hand.
12502
12503 @node Multiple Outputs
12504 @section Handling Tools that Produce Many Outputs
12505 @cindex multiple outputs, rules with
12506 @cindex many outputs, rules with
12507 @cindex rules with multiple outputs
12508
12509 This section describes a @command{make} idiom that can be used when a
12510 tool produces multiple output files.  It is not specific to Automake
12511 and can be used in ordinary @file{Makefile}s.
12512
12513 Suppose we have a program called @command{foo} that will read one file
12514 called @file{data.foo} and produce two files named @file{data.c} and
12515 @file{data.h}.  We want to write a @file{Makefile} rule that captures
12516 this one-to-two dependency.
12517
12518 The naive rule is incorrect:
12519
12520 @example
12521 # This is incorrect.
12522 data.c data.h: data.foo
12523         foo data.foo
12524 @end example
12525
12526 @noindent
12527 What the above rule really says is that @file{data.c} and
12528 @file{data.h} each depend on @file{data.foo}, and can each be built by
12529 running @samp{foo data.foo}.  In other words it is equivalent to:
12530
12531 @example
12532 # We do not want this.
12533 data.c: data.foo
12534         foo data.foo
12535 data.h: data.foo
12536         foo data.foo
12537 @end example
12538
12539 @noindent
12540 which means that @command{foo} can be run twice.  Usually it will not
12541 be run twice, because @command{make} implementations are smart enough
12542 to check for the existence of the second file after the first one has
12543 been built; they will therefore detect that it already exists.
12544 However there are a few situations where it can run twice anyway:
12545
12546 @itemize
12547 @item
12548 The most worrying case is when running a parallel @command{make}.  If
12549 @file{data.c} and @file{data.h} are built in parallel, two @samp{foo
12550 data.foo} commands will run concurrently.  This is harmful.
12551 @item
12552 Another case is when the dependency (here @file{data.foo}) is
12553 (or depends upon) a phony target.
12554 @end itemize
12555
12556 A solution that works with parallel @command{make} but not with
12557 phony dependencies is the following:
12558
12559 @example
12560 data.c data.h: data.foo
12561         foo data.foo
12562 data.h: data.c
12563 @end example
12564
12565 @noindent
12566 The above rules are equivalent to
12567
12568 @example
12569 data.c: data.foo
12570         foo data.foo
12571 data.h: data.foo data.c
12572         foo data.foo
12573 @end example
12574
12575 @noindent
12576 therefore a parallel @command{make} will have to serialize the builds
12577 of @file{data.c} and @file{data.h}, and will detect that the second is
12578 no longer needed once the first is over.
12579
12580 Using this pattern is probably enough for most cases.  However it does
12581 not scale easily to more output files (in this scheme all output files
12582 must be totally ordered by the dependency relation), so we will
12583 explore a more complicated solution.
12584
12585 Another idea is to write the following:
12586
12587 @example
12588 # There is still a problem with this one.
12589 data.c: data.foo
12590         foo data.foo
12591 data.h: data.c
12592 @end example
12593
12594 @noindent
12595 The idea is that @samp{foo data.foo} is run only when @file{data.c}
12596 needs to be updated, but we further state that @file{data.h} depends
12597 upon @file{data.c}.  That way, if @file{data.h} is required and
12598 @file{data.foo} is out of date, the dependency on @file{data.c} will
12599 trigger the build.
12600
12601 This is almost perfect, but suppose we have built @file{data.h} and
12602 @file{data.c}, and then we erase @file{data.h}.  Then, running
12603 @samp{make data.h} will not rebuild @file{data.h}.  The above rules
12604 just state that @file{data.c} must be up-to-date with respect to
12605 @file{data.foo}, and this is already the case.
12606
12607 What we need is a rule that forces a rebuild when @file{data.h} is
12608 missing.  Here it is:
12609
12610 @example
12611 data.c: data.foo
12612         foo data.foo
12613 data.h: data.c
12614 ## Recover from the removal of $@@
12615         @@if test -f $@@; then :; else \
12616           rm -f data.c; \
12617           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12618         fi
12619 @end example
12620
12621 The above scheme can be extended to handle more outputs and more
12622 inputs.  One of the outputs is selected to serve as a witness to the
12623 successful completion of the command, it depends upon all inputs, and
12624 all other outputs depend upon it.  For instance, if @command{foo}
12625 should additionally read @file{data.bar} and also produce
12626 @file{data.w} and @file{data.x}, we would write:
12627
12628 @example
12629 data.c: data.foo data.bar
12630         foo data.foo data.bar
12631 data.h data.w data.x: data.c
12632 ## Recover from the removal of $@@
12633         @@if test -f $@@; then :; else \
12634           rm -f data.c; \
12635           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12636         fi
12637 @end example
12638
12639 However there are now three minor problems in this setup.  One is related
12640 to the timestamp ordering of @file{data.h}, @file{data.w},
12641 @file{data.x}, and @file{data.c}.  Another one is a race condition
12642 if a parallel @command{make} attempts to run multiple instances of the
12643 recover block at once.  Finally, the recursive rule breaks @samp{make -n}
12644 when run with GNU @command{make} (as well as some other @command{make}
12645 implementations), as it may remove @file{data.h} even when it should not
12646 (@pxref{MAKE Variable, , How the @code{MAKE} Variable Works, make,
12647 The GNU Make Manual}).
12648
12649 Let us deal with the first problem.  @command{foo} outputs four files,
12650 but we do not know in which order these files are created.  Suppose
12651 that @file{data.h} is created before @file{data.c}.  Then we have a
12652 weird situation.  The next time @command{make} is run, @file{data.h}
12653 will appear older than @file{data.c}, the second rule will be
12654 triggered, a shell will be started to execute the @samp{if@dots{}fi}
12655 command, but actually it will just execute the @code{then} branch,
12656 that is: nothing.  In other words, because the witness we selected is
12657 not the first file created by @command{foo}, @command{make} will start
12658 a shell to do nothing each time it is run.
12659
12660 A simple riposte is to fix the timestamps when this happens.
12661
12662 @example
12663 data.c: data.foo data.bar
12664         foo data.foo data.bar
12665 data.h data.w data.x: data.c
12666         @@if test -f $@@; then \
12667           touch $@@; \
12668         else \
12669 ## Recover from the removal of $@@
12670           rm -f data.c; \
12671           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12672         fi
12673 @end example
12674
12675 Another solution is to use a different and dedicated file as witness,
12676 rather than using any of @command{foo}'s outputs.
12677
12678 @example
12679 data.stamp: data.foo data.bar
12680         @@rm -f data.tmp
12681         @@touch data.tmp
12682         foo data.foo data.bar
12683         @@mv -f data.tmp $@@
12684 data.c data.h data.w data.x: data.stamp
12685 ## Recover from the removal of $@@
12686         @@if test -f $@@; then :; else \
12687           rm -f data.stamp; \
12688           $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
12689         fi
12690 @end example
12691
12692 @file{data.tmp} is created before @command{foo} is run, so it has a
12693 timestamp older than output files output by @command{foo}.  It is then
12694 renamed to @file{data.stamp} after @command{foo} has run, because we
12695 do not want to update @file{data.stamp} if @command{foo} fails.
12696
12697 This solution still suffers from the second problem: the race
12698 condition in the recover rule.  If, after a successful build, a user
12699 erases @file{data.c} and @file{data.h}, and runs @samp{make -j}, then
12700 @command{make} may start both recover rules in parallel.  If the two
12701 instances of the rule execute @samp{$(MAKE) $(AM_MAKEFLAGS)
12702 data.stamp} concurrently the build is likely to fail (for instance, the
12703 two rules will create @file{data.tmp}, but only one can rename it).
12704
12705 Admittedly, such a weird situation does not arise during ordinary
12706 builds.  It occurs only when the build tree is mutilated.  Here
12707 @file{data.c} and @file{data.h} have been explicitly removed without
12708 also removing @file{data.stamp} and the other output files.
12709 @code{make clean; make} will always recover from these situations even
12710 with parallel makes, so you may decide that the recover rule is solely
12711 to help non-parallel make users and leave things as-is.  Fixing this
12712 requires some locking mechanism to ensure only one instance of the
12713 recover rule rebuilds @file{data.stamp}.  One could imagine something
12714 along the following lines.
12715
12716 @example
12717 data.c data.h data.w data.x: data.stamp
12718 ## Recover from the removal of $@@
12719         @@if test -f $@@; then :; else \
12720           trap 'rm -rf data.lock data.stamp' 1 2 13 15; \
12721 ## mkdir is a portable test-and-set
12722           if mkdir data.lock 2>/dev/null; then \
12723 ## This code is being executed by the first process.
12724             rm -f data.stamp; \
12725             $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
12726             result=$$?; rm -rf data.lock; exit $$result; \
12727           else \
12728 ## This code is being executed by the follower processes.
12729 ## Wait until the first process is done.
12730             while test -d data.lock; do sleep 1; done; \
12731 ## Succeed if and only if the first process succeeded.
12732             test -f data.stamp; \
12733           fi; \
12734         fi
12735 @end example
12736
12737 Using a dedicated witness, like @file{data.stamp}, is very handy when
12738 the list of output files is not known beforehand.  As an illustration,
12739 consider the following rules to compile many @file{*.el} files into
12740 @file{*.elc} files in a single command.  It does not matter how
12741 @code{ELFILES} is defined (as long as it is not empty: empty targets
12742 are not accepted by POSIX).
12743
12744 @example
12745 ELFILES = one.el two.el three.el @dots{}
12746 ELCFILES = $(ELFILES:=c)
12747
12748 elc-stamp: $(ELFILES)
12749         @@rm -f elc-temp
12750         @@touch elc-temp
12751         $(elisp_comp) $(ELFILES)
12752         @@mv -f elc-temp $@@
12753
12754 $(ELCFILES): elc-stamp
12755         @@if test -f $@@; then :; else \
12756 ## Recover from the removal of $@@
12757           trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
12758           if mkdir elc-lock 2>/dev/null; then \
12759 ## This code is being executed by the first process.
12760             rm -f elc-stamp; \
12761             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
12762             rmdir elc-lock; \
12763           else \
12764 ## This code is being executed by the follower processes.
12765 ## Wait until the first process is done.
12766             while test -d elc-lock; do sleep 1; done; \
12767 ## Succeed if and only if the first process succeeded.
12768             test -f elc-stamp; exit $$?; \
12769 @c $$
12770           fi; \
12771         fi
12772 @end example
12773
12774 These solutions all still suffer from the third problem, namely that
12775 they break the promise that @samp{make -n} should not cause any actual
12776 changes to the tree.  For those solutions that do not create lock files,
12777 it is possible to split the recover rules into two separate recipe
12778 commands, one of which does all work but the recursion, and the
12779 other invokes the recursive @samp{$(MAKE)}.  The solutions involving
12780 locking could act upon the contents of the @samp{MAKEFLAGS} variable,
12781 but parsing that portably is not easy (@pxref{The Make Macro MAKEFLAGS,,,
12782 autoconf, The Autoconf Manual}).  Here is an example:
12783
12784 @example
12785 ELFILES = one.el two.el three.el @dots{}
12786 ELCFILES = $(ELFILES:=c)
12787
12788 elc-stamp: $(ELFILES)
12789         @@rm -f elc-temp
12790         @@touch elc-temp
12791         $(elisp_comp) $(ELFILES)
12792         @@mv -f elc-temp $@@
12793
12794 $(ELCFILES): elc-stamp
12795 ## Recover from the removal of $@@
12796         @@dry=; for f in x $$MAKEFLAGS; do \
12797           case $$f in \
12798             *=*|--*);; \
12799             *n*) dry=:;; \
12800           esac; \
12801         done; \
12802         if test -f $@@; then :; else \
12803           $$dry trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
12804           if $$dry mkdir elc-lock 2>/dev/null; then \
12805 ## This code is being executed by the first process.
12806             $$dry rm -f elc-stamp; \
12807             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
12808             $$dry rmdir elc-lock; \
12809           else \
12810 ## This code is being executed by the follower processes.
12811 ## Wait until the first process is done.
12812             while test -d elc-lock && test -z "$$dry"; do \
12813 @c $$
12814               sleep 1; \
12815             done; \
12816 ## Succeed if and only if the first process succeeded.
12817             $$dry test -f elc-stamp; exit $$?; \
12818           fi; \
12819         fi
12820 @end example
12821
12822 For completeness it should be noted that GNU @command{make} is able to
12823 express rules with multiple output files using pattern rules
12824 (@pxref{Pattern Examples, , Pattern Rule Examples, make, The GNU Make
12825 Manual}).  We do not discuss pattern rules here because they are not
12826 portable, but they can be convenient in packages that assume GNU
12827 @command{make}.
12828
12829
12830 @node Hard-Coded Install Paths
12831 @section Installing to Hard-Coded Locations
12832
12833 @display
12834 My package needs to install some configuration file.  I tried to use
12835 the following rule, but @samp{make distcheck} fails.  Why?
12836
12837 @example
12838 # Do not do this.
12839 install-data-local:
12840         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
12841 @end example
12842 @end display
12843
12844 @display
12845 My package needs to populate the installation directory of another
12846 package at install-time.  I can easily compute that installation
12847 directory in @file{configure}, but if I install files therein,
12848 @samp{make distcheck} fails.  How else should I do?
12849 @end display
12850
12851 These two setups share their symptoms: @samp{make distcheck} fails
12852 because they are installing files to hard-coded paths.  In the later
12853 case the path is not really hard-coded in the package, but we can
12854 consider it to be hard-coded in the system (or in whichever tool that
12855 supplies the path).  As long as the path does not use any of the
12856 standard directory variables (@samp{$(prefix)}, @samp{$(bindir)},
12857 @samp{$(datadir)}, etc.), the effect will be the same:
12858 user-installations are impossible.
12859
12860 As a (non-root) user who wants to install a package, you usually have no
12861 right to install anything in @file{/usr} or @file{/usr/local}.  So you
12862 do something like @samp{./configure --prefix ~/usr} to install a
12863 package in your own @file{~/usr} tree.
12864
12865 If a package attempts to install something to some hard-coded path
12866 (e.g., @file{/etc/afile}), regardless of this @option{--prefix} setting,
12867 then the installation will fail.  @samp{make distcheck} performs such
12868 a @option{--prefix} installation, hence it will fail too.
12869
12870 Now, there are some easy solutions.
12871
12872 The above @code{install-data-local} example for installing
12873 @file{/etc/afile} would be better replaced by
12874
12875 @example
12876 sysconf_DATA = afile
12877 @end example
12878
12879 @noindent
12880 by default @code{sysconfdir} will be @samp{$(prefix)/etc}, because
12881 this is what the GNU Standards require.  When such a package is
12882 installed on an FHS compliant system, the installer will have to set
12883 @samp{--sysconfdir=/etc}.  As the maintainer of the package you
12884 should not be concerned by such site policies: use the appropriate
12885 standard directory variable to install your files so that the installer
12886 can easily redefine these variables to match their site conventions.
12887
12888 Installing files that should be used by another package is slightly
12889 more involved.  Let's take an example and assume you want to install
12890 a shared library that is a Python extension module.  If you ask Python
12891 where to install the library, it will answer something like this:
12892
12893 @example
12894 % @kbd{python -c 'from distutils import sysconfig;
12895              print sysconfig.get_python_lib(1,0)'}
12896 /usr/lib/python2.5/site-packages
12897 @end example
12898
12899 If you indeed use this absolute path to install your shared library,
12900 non-root users will not be able to install the package, hence
12901 distcheck fails.
12902
12903 Let's do better.  The @samp{sysconfig.get_python_lib()} function
12904 actually accepts a third argument that will replace Python's
12905 installation prefix.
12906
12907 @example
12908 % @kbd{python -c 'from distutils import sysconfig;
12909              print sysconfig.get_python_lib(1,0,"$@{exec_prefix@}")'}
12910 $@{exec_prefix@}/lib/python2.5/site-packages
12911 @end example
12912
12913 You can also use this new path.  If you do
12914 @itemize @bullet
12915 @item
12916 root users can install your package with the same @option{--prefix}
12917 as Python (you get the behavior of the previous attempt)
12918
12919 @item
12920 non-root users can install your package too, they will have the
12921 extension module in a place that is not searched by Python but they
12922 can work around this using environment variables (and if you installed
12923 scripts that use this shared library, it's easy to tell Python were to
12924 look in the beginning of your script, so the script works in both
12925 cases).
12926 @end itemize
12927
12928 The @code{AM_PATH_PYTHON} macro uses similar commands to define
12929 @samp{$(pythondir)} and @samp{$(pyexecdir)} (@pxref{Python}).
12930
12931 Of course not all tools are as advanced as Python regarding that
12932 substitution of @var{prefix}.  So another strategy is to figure the
12933 part of the installation directory that must be preserved.  For
12934 instance, here is how @code{AM_PATH_LISPDIR} (@pxref{Emacs Lisp})
12935 computes @samp{$(lispdir)}:
12936
12937 @example
12938 $EMACS -batch -q -eval '(while load-path
12939   (princ (concat (car load-path) "\n"))
12940   (setq load-path (cdr load-path)))' >conftest.out
12941 lispdir=`sed -n
12942   -e 's,/$,,'
12943   -e '/.*\/lib\/x*emacs\/site-lisp$/@{
12944         s,.*/lib/\(x*emacs/site-lisp\)$,$@{libdir@}/\1,;p;q;
12945       @}'
12946   -e '/.*\/share\/x*emacs\/site-lisp$/@{
12947         s,.*/share/\(x*emacs/site-lisp\),$@{datarootdir@}/\1,;p;q;
12948       @}'
12949   conftest.out`
12950 @end example
12951
12952 I.e., it just picks the first directory that looks like
12953 @file{*/lib/*emacs/site-lisp} or @file{*/share/*emacs/site-lisp} in
12954 the search path of emacs, and then substitutes @samp{$@{libdir@}} or
12955 @samp{$@{datadir@}} appropriately.
12956
12957 The emacs case looks complicated because it processes a list and
12958 expects two possible layouts, otherwise it's easy, and the benefits for
12959 non-root users are really worth the extra @command{sed} invocation.
12960
12961
12962 @node Debugging Make Rules
12963 @section Debugging Make Rules
12964 @cindex debugging rules
12965 @cindex rules, debugging
12966
12967 The rules and dependency trees generated by @command{automake} can get
12968 rather complex, and leave the developer head-scratching when things
12969 don't work as expected.  Besides the debug options provided by the
12970 @command{make} command (@pxref{Options Summary,,, make, The GNU Make
12971 Manual}), here's a couple of further hints for debugging makefiles
12972 generated by @command{automake} effectively:
12973
12974 @itemize
12975 @item
12976 If less verbose output has been enabled in the package with the use
12977 of silent rules (@pxref{Automake Silent Rules}), you can use
12978 @code{make V=1} to see the commands being executed.
12979 @item
12980 @code{make -n} can help show what would be done without actually doing
12981 it.  Note however, that this will @emph{still execute} commands prefixed
12982 with @samp{+}, and, when using GNU @command{make}, commands that contain
12983 the strings @samp{$(MAKE)} or @samp{$@{MAKE@}} (@pxref{Instead of
12984 Execution,,, make, The GNU Make Manual}).
12985 Typically, this is helpful to show what recursive rules would do, but it
12986 means that, in your own rules, you should not mix such recursion with
12987 actions that change any files.@footnote{Automake's @samp{dist} and
12988 @samp{distcheck} rules had a bug in this regard in that they created
12989 directories even with @option{-n}, but this has been fixed in Automake
12990 1.11.}  Furthermore, note that GNU @command{make} will update
12991 prerequisites for the @file{Makefile} file itself even with @option{-n}
12992 (@pxref{Remaking Makefiles,,, make, The GNU Make Manual}).
12993 @item
12994 @code{make SHELL="/bin/bash -vx"} can help debug complex rules.
12995 @xref{The Make Macro SHELL,,, autoconf, The Autoconf Manual}, for some
12996 portability quirks associated with this construct.
12997 @item
12998 @code{echo 'print: ; @@echo "$(VAR)"' | make -f Makefile -f - print}
12999 can be handy to examine the expanded value of variables.  You may need
13000 to use a target other than @samp{print} if that is already used or a
13001 file with that name exists.
13002 @item
13003 @url{http://bashdb.sourceforge.net/@/remake/} provides a modified
13004 GNU @command{make} command called @command{remake} that copes with
13005 complex GNU @command{make}-specific Makefiles and allows to trace
13006 execution, examine variables, and call rules interactively, much like
13007 a debugger.
13008 @end itemize
13009
13010
13011 @node Reporting Bugs
13012 @section Reporting Bugs
13013
13014 Most nontrivial software has bugs.  Automake is no exception.  Although
13015 we cannot promise we can or will fix a bug, and we might not even agree
13016 that it is a bug, we want to hear about problems you encounter. Often we
13017 agree they are bugs and want to fix them.
13018
13019 To make it possible for us to fix a bug, please report it. In order to
13020 do so effectively, it helps to know when and how to do it.
13021
13022 Before reporting a bug, it is a good idea to see if it is already known.
13023 You can look at the @uref{http://debbugs.gnu.org/, GNU Bug Tracker}
13024 and the @uref{http://lists.gnu.org/@/archive/@/html/@/bug-automake/,
13025 bug-automake mailing list archives} for previous bug reports.  We
13026 previously used a
13027 @uref{http://sourceware.org/@/cgi-bin/@/gnatsweb.pl?database=automake,
13028 Gnats database} for bug tracking, so some bugs might have been reported
13029 there already.  Please do not use it for new bug reports, however.
13030
13031 If the bug is not already known, it should be reported.  It is very
13032 important to report bugs in a way that is useful and efficient.  For
13033 this, please familiarize yourself with
13034 @uref{http://www.chiark.greenend.org.uk/@/~sgtatham/@/bugs.html, How to
13035 Report Bugs Effectively} and
13036 @uref{http://catb.org/@/~esr/@/faqs/@/smart-questions.html, How to Ask
13037 Questions the Smart Way}.  This helps you and developers to save time
13038 which can then be spent on fixing more bugs and implementing more
13039 features.
13040
13041 For a bug report, a feature request or other suggestions, please send
13042 email to @email{@value{PACKAGE_BUGREPORT}}.  This will then open a new
13043 bug in the @uref{http://debbugs.gnu.org/@/automake, bug tracker}.  Be
13044 sure to include the versions of Autoconf and Automake that you use.
13045 Ideally, post a minimal @file{Makefile.am} and @file{configure.ac} that
13046 reproduces the problem you encounter.  If you have encountered test
13047 suite failures, please attach the @file{test-suite.log} file.
13048
13049 @c ========================================================== Appendices
13050
13051 @page
13052 @node Copying This Manual
13053 @appendix Copying This Manual
13054
13055 @menu
13056 * GNU Free Documentation License::  License for copying this manual
13057 @end menu
13058
13059 @node GNU Free Documentation License
13060 @appendixsec GNU Free Documentation License
13061 @include fdl.texi
13062
13063 @page
13064 @node Indices
13065 @appendix Indices
13066
13067 @menu
13068 * Macro Index::                 Index of Autoconf macros
13069 * Variable Index::              Index of Makefile variables
13070 * General Index::               General index
13071 @end menu
13072
13073 @node Macro Index
13074 @appendixsec Macro Index
13075
13076 @printindex fn
13077
13078 @node Variable Index
13079 @appendixsec Variable Index
13080
13081 @printindex vr
13082
13083 @node General Index
13084 @appendixsec General Index
13085
13086 @printindex cp
13087
13088
13089 @bye
13090
13091 @c  LocalWords:  texinfo setfilename settitle setchapternewpage texi direntry
13092 @c  LocalWords:  dircategory in's aclocal ifinfo titlepage Tromey vskip pt sp
13093 @c  LocalWords:  filll defcodeindex ov cv op tr syncodeindex fn cp vr ifnottex
13094 @c  LocalWords:  dir Automake's ac Dist Gnits gnits dfn Autoconf's pxref
13095 @c  LocalWords:  cindex Autoconf autoconf perl samp cvs dist trindex SUBST foo
13096 @c  LocalWords:  xs emph FIXME ref vindex pkglibdir pkgincludedir pkgdatadir mt
13097 @c  LocalWords:  pkg libdir cpio bindir sbindir rmt pax sbin zar zardir acindex
13098 @c  LocalWords:  HTML htmldir html noinst TEXINFOS nodist nobase strudel CFLAGS
13099 @c  LocalWords:  libmumble CC YFLAGS itemx de fication config url comp
13100 @c  LocalWords:  depcomp elisp sh mdate mkinstalldirs mkdir py tex dvi ps pdf
13101 @c  LocalWords:  ylwrap zardoz INIT gettext acinclude mv FUNCS LIBOBJS LDADD fr
13102 @c  LocalWords:  uref featureful dnl src LINGUAS es ko nl pl sl sv PROG ISC doc
13103 @c  LocalWords:  POSIX STDC fcntl FUNC ALLOCA blksize struct stat intl po chmod
13104 @c  LocalWords:  ChangeLog SUBDIRS gettextize gpl testdata getopt INTLLIBS cpp
13105 @c  LocalWords:  localedir datadir DLOCALEDIR DEXIT CPPFLAGS autoreconf opindex
13106 @c  LocalWords:  AUX var symlink deps Wno Wnone package's aclocal's distclean
13107 @c  LocalWords:  ltmain xref LIBSOURCE LIBSOURCES LIBOBJ MEMCMP vs RANLIB CXX
13108 @c  LocalWords:  LDFLAGS LIBTOOL libtool XTRA LIBS gettext's acdir APIVERSION
13109 @c  LocalWords:  dirlist noindent usr TIOCGWINSZ sc
13110 @c  LocalWords:  GWINSZ termios SRCDIR tarball bzip LISPDIR lispdir XEmacs CCAS
13111 @c  LocalWords:  emacsen MicroEmacs CCASFLAGS UX GCJ gcj GCJFLAGS posix DMALLOC
13112 @c  LocalWords:  dmalloc ldmalloc REGEX regex DEPDIR DEP DEFUN aclocaldir fi
13113 @c  LocalWords:  mymacro myothermacro AMFLAGS autopoint autogen libtoolize yum
13114 @c  LocalWords:  autoheader README MAKEFLAGS subdir Inetutils sync COND endif
13115 @c  LocalWords:  Miller's installable includedir inc pkgdata EXEEXT libexec bsd
13116 @c  LocalWords:  pkglib libexecdir prog libcpio cpio's dlopen dlpreopen linux
13117 @c  LocalWords:  subsubsection OBJEXT esac lib LTLIBRARIES liblob LIBADD AR ar
13118 @c  LocalWords:  ARFLAGS cru ing maude libgettext lo LTLIBOBJS rpath SGI PRE yy
13119 @c  LocalWords:  libmaude CCLD CXXFLAGS FFLAGS LFLAGS OBJCFLAGS RFLAGS DEFS cc
13120 @c  LocalWords:  OBJCXXFLAGS
13121 @c  LocalWords:  SHORTNAME vtable srcdir nostdinc basename yxx cxx ll lxx gdb
13122 @c  LocalWords:  lexers yymaxdepth maxdepth yyparse yylex yyerror yylval lval
13123 @c  LocalWords:  yychar yydebug yypact yyr yydef def yychk chk yypgo pgo yyact
13124 @c  LocalWords:  yyexca exca yyerrflag errflag yynerrs nerrs yyps yypv pv yys
13125 @c  LocalWords:  yystate yytmp tmp yyv yyval val yylloc lloc yyreds yytoks toks
13126 @c  LocalWords:  yylhs yylen yydefred yydgoto yysindex yyrindex yygindex yyname
13127 @c  LocalWords:  yytable yycheck yyrule byacc CXXCOMPILE CXXLINK FLINK cfortran
13128 @c  LocalWords:  Catalogue preprocessable FLIBS libfoo baz JAVACFLAGS java exe
13129 @c  LocalWords:  SunOS fying basenames exeext uninstalled oldinclude kr FSF's
13130 @c  LocalWords:  pkginclude oldincludedir sysconf sharedstate localstate gcc rm
13131 @c  LocalWords:  sysconfdir sharedstatedir localstatedir preexist CLEANFILES gz
13132 @c  LocalWords:  depfile tmpdepfile depmode const interoperate
13133 @c  LocalWords:  JAVAC javac JAVAROOT builddir CLASSPATH ENV pyc pyo pkgpython
13134 @c  LocalWords:  pyexecdir pkgpyexecdir Python's pythondir pkgpythondir txi ois
13135 @c  LocalWords:  installinfo vers MAKEINFO makeinfo MAKEINFOFLAGS noinstall rf
13136 @c  LocalWords:  mandir thesame alsothesame installman myexecbin DESTDIR Pinard
13137 @c  LocalWords:  uninstall installdirs uninstalls MOSTLYCLEANFILES mostlyclean
13138 @c  LocalWords:  DISTCLEANFILES MAINTAINERCLEANFILES GZIP gzip shar exp
13139 @c  LocalWords:  distdir distcheck distcleancheck listfiles distuninstallcheck
13140 @c  LocalWords:  VPATH tarfile stdout XFAIL DejaGnu dejagnu DEJATOOL runtest ln
13141 @c  LocalWords:  RUNTESTDEFAULTFLAGS toolchain RUNTESTFLAGS asis readme DVIPS
13142 @c  LocalWords:  installcheck gzipped tarZ std utils etags mkid cd
13143 @c  LocalWords:  ARGS taggable ETAGSFLAGS lang ctags CTAGSFLAGS GTAGS gtags idl
13144 @c  LocalWords:  foocc doit idlC multilibs ABIs cmindex defmac ARG enableval FC
13145 @c  LocalWords:  MSG xtrue DBG pathchk CYGWIN afile proglink versioned CVS's TE
13146 @c  LocalWords:  wildcards Autoconfiscated subsubheading autotools Meyering API
13147 @c  LocalWords:  ois's wildcard Wportability cartouche vrindex printindex Duret
13148 @c  LocalWords:  DSOMEFLAG DVERSION automake Lutz insertcopying versioning FAQ
13149 @c  LocalWords:  LTLIBOBJ Libtool's libtool's libltdl dlopening itutions libbar
13150 @c  LocalWords:  WANTEDLIBS libhello sublibraries libtop libsub dlopened Ratfor
13151 @c  LocalWords:  mymodule timestamps timestamp underquoted MAKEINFOHTMLFLAGS te
13152 @c  LocalWords:  GNUmakefile Subpackages subpackage's subpackages aux
13153 @c  LocalWords:  detailmenu Timeline pwd reldir AUTOM autom PREREQ FOOBAR libc
13154 @c  LocalWords:  libhand subpackage moduleN libmain libmisc FCFLAGS FCCOMPILE
13155 @c  LocalWords:  FCLINK subst sed ELCFILES elc MAKEINFOHTML dvips esyscmd ustar
13156 @c  LocalWords:  tarballs Woverride vfi ELFILES djm AutoMake honkin FSF
13157 @c  LocalWords:  fileutils precanned MacKenzie's reimplement termutils Tromey's
13158 @c  LocalWords:  cois gnitsians LIBPROGRAMS progs LIBLIBRARIES Textutils Ulrich
13159 @c  LocalWords:  Matzigkeit Drepper's Gord Matzigkeit's jm Dalley Debian org
13160 @c  LocalWords:  Administrivia ILU CORBA Sourceware Molenda sourceware Elliston
13161 @c  LocalWords:  dep Oliva Akim Demaille Aiieeee Demaillator Akim's sourcequake
13162 @c  LocalWords:  grep backported screenshots libgcj KB unnumberedsubsubsec pre
13163 @c  LocalWords:  precomputing hacky makedepend inline clearmake LD PRELOAD Rel
13164 @c  LocalWords:  syscalls perlhist acl pm multitable headitem fdl appendixsec
13165 @c  LocalWords:  LTALLOCA MALLOC malloc memcmp strdup alloca libcompat xyz DFOO
13166 @c  LocalWords:  unprefixed buildable preprocessed DBAZ DDATADIR WARNINGCFLAGS
13167 @c  LocalWords:  LIBFOOCFLAGS LIBFOOLDFLAGS ftable testSubDir obj LIBTOOLFLAGS
13168 @c  LocalWords:  barexec Pinard's automatize initialize lzip xz cscope