Merge branch 'msvc' into maint
[platform/upstream/automake.git] / doc / automake.texi
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename automake.info
4 @settitle automake
5 @setchapternewpage off
6 @c %**end of header
7
8 @include version.texi
9
10 @c @ovar(ARG, DEFAULT)
11 @c -------------------
12 @c The ARG is an optional argument.  To be used for macro arguments in
13 @c their documentation (@defmac).
14 @macro ovar{varname}
15 @r{[}@var{\varname\}@r{]}
16 @end macro
17
18 @set PACKAGE_BUGREPORT bug-automake@@gnu.org
19
20 @copying
21
22 This manual is for GNU Automake (version @value{VERSION},
23 @value{UPDATED}), a program that creates GNU standards-compliant
24 Makefiles from template files.
25
26 Copyright @copyright{} 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
27 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software
28 Foundation, Inc.
29
30 @quotation
31 Permission is granted to copy, distribute and/or modify this document
32 under the terms of the GNU Free Documentation License,
33 Version 1.3 or any later version published by the Free Software
34 Foundation; with no Invariant Sections, with no Front-Cover texts,
35 and with no Back-Cover Texts.  A copy of the license is included in the
36 section entitled ``GNU Free Documentation License.''
37
38 @end quotation
39 @end copying
40
41 @dircategory Software development
42 @direntry
43 * Automake: (automake).         Making GNU standards-compliant Makefiles.
44 @end direntry
45
46 @dircategory Individual utilities
47 @direntry
48 * aclocal-invocation: (automake)aclocal Invocation.   Generating aclocal.m4.
49 * automake-invocation: (automake)automake Invocation. Generating Makefile.in.
50 @end direntry
51
52 @titlepage
53 @title GNU Automake
54 @subtitle For version @value{VERSION}, @value{UPDATED}
55 @author David MacKenzie
56 @author Tom Tromey
57 @author Alexandre Duret-Lutz
58 @page
59 @vskip 0pt plus 1filll
60 @insertcopying
61 @end titlepage
62
63 @contents
64
65 @c We use the following macros to define indices:
66 @c   @cindex   concepts, and anything that does not fit elsewhere
67 @c   @vindex   Makefile variables
68 @c   @trindex  targets
69 @c   @acindex  Autoconf/Automake/Libtool/M4/... macros
70 @c   @opindex  tool options
71
72 @c Define an index of configure macros.
73 @defcodeindex ac
74 @c Define an index of options.
75 @defcodeindex op
76 @c Define an index of targets.
77 @defcodeindex tr
78 @c Define an index of commands.
79 @defcodeindex cm
80
81 @c Put the macros in the function index.
82 @syncodeindex ac fn
83
84 @c Put everything else into one index (arbitrarily chosen to be the
85 @c concept index).
86 @syncodeindex op cp
87 @syncodeindex tr cp
88 @syncodeindex cm cp
89
90 @ifnottex
91 @node Top
92 @comment  node-name,  next,  previous,  up
93 @top GNU Automake
94
95 @insertcopying
96
97 @menu
98 * Introduction::                Automake's purpose
99 * Autotools Introduction::      An Introduction to the Autotools
100 * Generalities::                General ideas
101 * Examples::                    Some example packages
102 * automake Invocation::         Creating a Makefile.in
103 * configure::                   Scanning configure.ac, using aclocal
104 * Directories::                 Declaring subdirectories
105 * Programs::                    Building programs and libraries
106 * Other Objects::               Other derived objects
107 * Other GNU Tools::             Other GNU Tools
108 * Documentation::               Building documentation
109 * Install::                     What gets installed
110 * Clean::                       What gets cleaned
111 * Dist::                        What goes in a distribution
112 * Tests::                       Support for test suites
113 * Rebuilding::                  Automatic rebuilding of Makefile
114 * Options::                     Changing Automake's behavior
115 * Miscellaneous::               Miscellaneous rules
116 * Include::                     Including extra files in an Automake template
117 * Conditionals::                Conditionals
118 * Silencing Make::              Obtain less verbose output from @command{make}
119 * Gnits::                       The effect of @option{--gnu} and @option{--gnits}
120 * Cygnus::                      The effect of @option{--cygnus}
121 * Not Enough::                  When Automake is not Enough
122 * Distributing::                Distributing the Makefile.in
123 * API Versioning::              About compatibility between Automake versions
124 * Upgrading::                   Upgrading to a Newer Automake Version
125 * FAQ::                         Frequently Asked Questions
126 * History::                     Notes about the history of Automake
127 * Copying This Manual::         How to make copies of this manual
128 * Indices::                     Indices of variables, macros, and concepts
129
130 @detailmenu
131  --- The Detailed Node Listing ---
132
133 An Introduction to the Autotools
134
135 * GNU Build System::            Introducing the GNU Build System
136 * Use Cases::                   Use Cases for the GNU Build System
137 * Why Autotools::               How Autotools Help
138 * Hello World::                 A Small Hello World Package
139
140 Use Cases for the GNU Build System
141
142 * Basic Installation::          Common installation procedure
143 * Standard Targets::            A list of standard Makefile targets
144 * Standard Directory Variables::  A list of standard directory variables
145 * Standard Configuration Variables::  Using configuration variables
146 * config.site::                 Using a config.site file
147 * VPATH Builds::                Parallel build trees
148 * Two-Part Install::            Installing data and programs separately
149 * Cross-Compilation::           Building for other architectures
150 * Renaming::                    Renaming programs at install time
151 * DESTDIR::                     Building binary packages with DESTDIR
152 * Preparing Distributions::     Rolling out tarballs
153 * Dependency Tracking::         Automatic dependency tracking
154 * Nested Packages::             The GNU Build Systems can be nested
155
156 A Small Hello World
157
158 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
159 * amhello's configure.ac Setup Explained::
160 * amhello's Makefile.am Setup Explained::
161
162 General ideas
163
164 * General Operation::           General operation of Automake
165 * Strictness::                  Standards conformance checking
166 * Uniform::                     The Uniform Naming Scheme
167 * Length Limitations::          Staying below the command line length limit
168 * Canonicalization::            How derived variables are named
169 * User Variables::              Variables reserved for the user
170 * Auxiliary Programs::          Programs automake might require
171
172 Some example packages
173
174 * Complete::                    A simple example, start to finish
175 * true::                        Building true and false
176
177 Scanning @file{configure.ac}, using @command{aclocal}
178
179 * Requirements::                Configuration requirements
180 * Optional::                    Other things Automake recognizes
181 * aclocal Invocation::          Auto-generating aclocal.m4
182 * Macros::                      Autoconf macros supplied with Automake
183
184 Auto-generating aclocal.m4
185
186 * aclocal Options::             Options supported by aclocal
187 * Macro Search Path::           How aclocal finds .m4 files
188 * Extending aclocal::           Writing your own aclocal macros
189 * Local Macros::                Organizing local macros
190 * Serials::                     Serial lines in Autoconf macros
191 * Future of aclocal::           aclocal's scheduled death
192
193 Autoconf macros supplied with Automake
194
195 * Public Macros::               Macros that you can use.
196 * Obsolete Macros::             Macros that you should stop using.
197 * Private Macros::              Macros that you should not use.
198
199 Directories
200
201 * Subdirectories::              Building subdirectories recursively
202 * Conditional Subdirectories::  Conditionally not building directories
203 * Alternative::                 Subdirectories without recursion
204 * Subpackages::                 Nesting packages
205
206 Conditional Subdirectories
207
208 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
209 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
210 * Subdirectories with AC_SUBST::  Another way for conditional recursion
211 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
212
213 Building Programs and Libraries
214
215 * A Program::                   Building a program
216 * A Library::                   Building a library
217 * A Shared Library::            Building a Libtool library
218 * Program and Library Variables::  Variables controlling program and
219                                 library builds
220 * Default _SOURCES::            Default source files
221 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
222 * Program Variables::           Variables used when building a program
223 * Yacc and Lex::                Yacc and Lex support
224 * C++ Support::                 Compiling C++ sources
225 * Objective C Support::         Compiling Objective C sources
226 * Unified Parallel C Support::  Compiling Unified Parallel C sources
227 * Assembly Support::            Compiling assembly sources
228 * Fortran 77 Support::          Compiling Fortran 77 sources
229 * Fortran 9x Support::          Compiling Fortran 9x sources
230 * Java Support with gcj::       Compiling Java sources using gcj
231 * Vala Support::                Compiling Vala sources
232 * Support for Other Languages::  Compiling other languages
233 * ANSI::                        Automatic de-ANSI-fication (deprecated, soon to be removed)
234 * Dependencies::                Automatic dependency tracking
235 * EXEEXT::                      Support for executable extensions
236
237 Building a program
238
239 * Program Sources::             Defining program sources
240 * Linking::                     Linking with libraries or extra objects
241 * Conditional Sources::         Handling conditional sources
242 * Conditional Programs::        Building a program conditionally
243
244 Building a Shared Library
245
246 * Libtool Concept::             Introducing Libtool
247 * Libtool Libraries::           Declaring Libtool Libraries
248 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
249 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
250 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
251 * Libtool Modules::             Building Libtool Modules
252 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
253 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
254 * Libtool Issues::              Common Issues Related to Libtool's Use
255
256 Common Issues Related to Libtool's Use
257
258 * Error required file ltmain.sh not found::  The need to run libtoolize
259 * Objects created both with libtool and without::  Avoid a specific build race
260
261 Fortran 77 Support
262
263 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
264 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
265 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
266
267 Mixing Fortran 77 With C and C++
268
269 * How the Linker is Chosen::    Automatic linker selection
270
271 Fortran 9x Support
272
273 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
274
275 Other Derived Objects
276
277 * Scripts::                     Executable scripts
278 * Headers::                     Header files
279 * Data::                        Architecture-independent data files
280 * Sources::                     Derived sources
281
282 Built Sources
283
284 * Built Sources Example::       Several ways to handle built sources.
285
286 Other GNU Tools
287
288 * Emacs Lisp::                  Emacs Lisp
289 * gettext::                     Gettext
290 * Libtool::                     Libtool
291 * Java::                        Java bytecode compilation (deprecated)
292 * Python::                      Python
293
294 Building documentation
295
296 * Texinfo::                     Texinfo
297 * Man Pages::                   Man pages
298
299 What Gets Installed
300
301 * Basics of Installation::      What gets installed where
302 * The Two Parts of Install::    Installing data and programs separately
303 * Extending Installation::      Adding your own rules for installation
304 * Staged Installs::             Installation in a temporary location
305 * Install Rules for the User::  Useful additional rules
306
307 What Goes in a Distribution
308
309 * Basics of Distribution::      Files distributed by default
310 * Fine-grained Distribution Control::  @code{dist_} and @code{nodist_} prefixes
311 * The dist Hook::               A target for last-minute distribution changes
312 * Checking the Distribution::   @samp{make distcheck} explained
313 * The Types of Distributions::  A variety of formats and compression methods
314
315 Support for test suites
316
317 * Simple Tests::                Listing programs and scripts in @code{TESTS}
318 * Simple Tests using parallel-tests::  More powerful test driver
319 * DejaGnu Tests::               Interfacing with the external testing framework
320 * Install Tests::               Running tests on installed packages
321
322 Miscellaneous Rules
323
324 * Tags::                        Interfacing to etags and mkid
325 * Suffixes::                    Handling new file extensions
326 * Multilibs::                   Support for multilibs (deprecated, soon to be removed).
327
328 Conditionals
329
330 * Usage of Conditionals::       Declaring conditional content
331 * Limits of Conditionals::      Enclosing complete statements
332
333 Silencing Make
334
335 * Make verbosity::               Make is verbose by default
336 * Tricks For Silencing Make::    Standard and generic ways to silence make
337 * Automake silent-rules Option:: How Automake can help in silencing make
338
339 When Automake Isn't Enough
340
341 * Extending::                   Adding new rules or overriding existing ones.
342 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
343
344 Frequently Asked Questions about Automake
345
346 * CVS::                         CVS and generated files
347 * maintainer-mode::             missing and AM_MAINTAINER_MODE
348 * Wildcards::                   Why doesn't Automake support wildcards?
349 * Limitations on File Names::   Limitations on source and installed file names
350 * distcleancheck::              Files left in build directory after distclean
351 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
352 * Renamed Objects::             Why are object files sometimes renamed?
353 * Per-Object Flags::            How to simulate per-object flags?
354 * Multiple Outputs::            Writing rules for tools with many output files
355 * Hard-Coded Install Paths::    Installing to hard-coded locations
356 * Debugging Make Rules::        Strategies when things don't work as expected
357 * Reporting Bugs::              Feedback on bugs and feature requests
358
359 History of Automake
360
361 * Timeline::                    The Automake story.
362 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
363 * Releases::                    Statistics about Automake Releases
364
365 Dependency Tracking in Automake
366
367 * First Take on Dependencies::  Precomputed dependency tracking
368 * Dependencies As Side Effects::  Update at developer compile time
369 * Dependencies for the User::   Update at user compile time
370 * Techniques for Dependencies::  Alternative approaches
371 * Recommendations for Tool Writers::  What tool writers can do to help
372 * Future Directions for Dependencies::  Languages Automake does not know
373
374 Copying This Manual
375
376 * GNU Free Documentation License::  License for copying this manual
377
378 Indices
379
380 * Macro Index::                 Index of Autoconf macros
381 * Variable Index::              Index of Makefile variables
382 * General Index::               General index
383
384 @end detailmenu
385 @end menu
386
387 @end ifnottex
388
389
390 @node Introduction
391 @chapter Introduction
392
393 Automake is a tool for automatically generating @file{Makefile.in}s
394 from files called @file{Makefile.am}.  Each @file{Makefile.am} is
395 basically a series of @command{make} variable
396 definitions@footnote{These variables are also called @dfn{make macros}
397 in Make terminology, however in this manual we reserve the term
398 @dfn{macro} for Autoconf's macros.}, with rules being thrown in
399 occasionally.  The generated @file{Makefile.in}s are compliant with
400 the GNU Makefile standards.
401
402 @cindex GNU Makefile standards
403
404 The GNU Makefile Standards Document
405 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
406 is long, complicated, and subject to change.  The goal of Automake is to
407 remove the burden of Makefile maintenance from the back of the
408 individual GNU maintainer (and put it on the back of the Automake
409 maintainers).
410
411 The typical Automake input file is simply a series of variable definitions.
412 Each such file is processed to create a @file{Makefile.in}.  There
413 should generally be one @file{Makefile.am} per directory of a project.
414
415 @cindex Constraints of Automake
416 @cindex Automake constraints
417
418 Automake does constrain a project in certain ways; for instance, it
419 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
420 autoconf, The Autoconf Manual}), and enforces certain restrictions on
421 the @file{configure.ac} contents@footnote{Older Autoconf versions used
422 @file{configure.in}.  Autoconf 2.50 and greater promotes
423 @file{configure.ac} over @file{configure.in}.  The rest of this
424 documentation will refer to @file{configure.ac}, but Automake also
425 supports @file{configure.in} for backward compatibility.}.
426
427 @cindex Automake requirements
428 @cindex Requirements, Automake
429
430 Automake requires @command{perl} in order to generate the
431 @file{Makefile.in}s.  However, the distributions created by Automake are
432 fully GNU standards-compliant, and do not require @command{perl} in order
433 to be built.
434
435 @cindex Bugs, reporting
436 @cindex Reporting bugs
437 @cindex E-mail, bug reports
438
439 For more information on bug reports, @xref{Reporting Bugs}.
440
441 @node Autotools Introduction
442 @chapter An Introduction to the Autotools
443
444 If you are new to Automake, maybe you know that it is part of a set of
445 tools called @emph{The Autotools}.  Maybe you've already delved into a
446 package full of files named @file{configure}, @file{configure.ac},
447 @file{Makefile.in}, @file{Makefile.am}, @file{aclocal.m4}, @dots{},
448 some of them claiming to be @emph{generated by} Autoconf or Automake.
449 But the exact purpose of these files and their relations is probably
450 fuzzy.  The goal of this chapter is to introduce you to this machinery,
451 to show you how it works and how powerful it is.  If you've never
452 installed or seen such a package, do not worry: this chapter will walk
453 you through it.
454
455 If you need some teaching material, more illustrations, or a less
456 @command{automake}-centered continuation, some slides for this
457 introduction are available in Alexandre Duret-Lutz's
458 @uref{http://www.lrde.epita.fr/@/~adl/@/autotools.html,
459 Autotools Tutorial}.
460 This chapter is the written version of the first part of his tutorial.
461
462 @menu
463 * GNU Build System::            Introducing the GNU Build System
464 * Use Cases::                   Use Cases for the GNU Build System
465 * Why Autotools::               How Autotools Help
466 * Hello World::                 A Small Hello World Package
467 @end menu
468
469 @node GNU Build System
470 @section Introducing the GNU Build System
471 @cindex GNU Build System, introduction
472
473 It is a truth universally acknowledged, that as a developer in
474 possession of a new package, you must be in want of a build system.
475
476 In the Unix world, such a build system is traditionally achieved using
477 the command @command{make} (@pxref{Top, , Overview, make, The GNU Make
478 Manual}).  You express the recipe to build your package in a
479 @file{Makefile}.  This file is a set of rules to build the files in
480 the package.  For instance the program @file{prog} may be built by
481 running the linker on the files @file{main.o}, @file{foo.o}, and
482 @file{bar.o}; the file @file{main.o} may be built by running the
483 compiler on @file{main.c}; etc.  Each time @command{make} is run, it
484 reads @file{Makefile}, checks the existence and modification time of
485 the files mentioned, decides what files need to be built (or rebuilt),
486 and runs the associated commands.
487
488 When a package needs to be built on a different platform than the one
489 it was developed on, its @file{Makefile} usually needs to be adjusted.
490 For instance the compiler may have another name or require more
491 options.  In 1991, David J. MacKenzie got tired of customizing
492 @file{Makefile} for the 20 platforms he had to deal with.  Instead, he
493 handcrafted a little shell script called @file{configure} to
494 automatically adjust the @file{Makefile} (@pxref{Genesis, , Genesis,
495 autoconf, The Autoconf Manual}).  Compiling his package was now
496 as simple as running @code{./configure && make}.
497
498 @cindex GNU Coding Standards
499
500 Today this process has been standardized in the GNU project.  The GNU
501 Coding Standards (@pxref{Managing Releases, The Release Process, ,
502 standards, The GNU Coding Standards}) explains how each package of the
503 GNU project should have a @file{configure} script, and the minimal
504 interface it should have.  The @file{Makefile} too should follow some
505 established conventions.  The result?  A unified build system that
506 makes all packages almost indistinguishable by the installer.  In its
507 simplest scenario, all the installer has to do is to unpack the
508 package, run @code{./configure && make && make install}, and repeat
509 with the next package to install.
510
511 We call this build system the @dfn{GNU Build System}, since it was
512 grown out of the GNU project.  However it is used by a vast number of
513 other packages: following any existing convention has its advantages.
514
515 @cindex Autotools, introduction
516
517 The Autotools are tools that will create a GNU Build System for your
518 package.  Autoconf mostly focuses on @file{configure} and Automake on
519 @file{Makefile}s.  It is entirely possible to create a GNU Build
520 System without the help of these tools.  However it is rather
521 burdensome and error-prone.  We will discuss this again after some
522 illustration of the GNU Build System in action.
523
524 @node Use Cases
525 @section Use Cases for the GNU Build System
526 @cindex GNU Build System, use cases
527 @cindex GNU Build System, features
528 @cindex Features of the GNU Build System
529 @cindex Use Cases for the GNU Build System
530 @cindex @file{amhello-1.0.tar.gz}, location
531 @cindex @file{amhello-1.0.tar.gz}, use cases
532
533 In this section we explore several use cases for the GNU Build System.
534 You can replay all these examples on the @file{amhello-1.0.tar.gz}
535 package distributed with Automake.  If Automake is installed on your
536 system, you should find a copy of this file in
537 @file{@var{prefix}/share/doc/automake/amhello-1.0.tar.gz}, where
538 @var{prefix} is the installation prefix specified during configuration
539 (@var{prefix} defaults to @file{/usr/local}, however if Automake was
540 installed by some GNU/Linux distribution it most likely has been set
541 to @file{/usr}).  If you do not have a copy of Automake installed,
542 you can find a copy of this file inside the @file{doc/} directory of
543 the Automake package.
544
545 Some of the following use cases present features that are in fact
546 extensions to the GNU Build System.  Read: they are not specified by
547 the GNU Coding Standards, but they are nonetheless part of the build
548 system created by the Autotools.  To keep things simple, we do not
549 point out the difference.  Our objective is to show you many of the
550 features that the build system created by the Autotools will offer to
551 you.
552
553 @menu
554 * Basic Installation::          Common installation procedure
555 * Standard Targets::            A list of standard Makefile targets
556 * Standard Directory Variables::  A list of standard directory variables
557 * Standard Configuration Variables::  Using configuration variables
558 * config.site::                 Using a config.site file
559 * VPATH Builds::                Parallel build trees
560 * Two-Part Install::            Installing data and programs separately
561 * Cross-Compilation::           Building for other architectures
562 * Renaming::                    Renaming programs at install time
563 * DESTDIR::                     Building binary packages with DESTDIR
564 * Preparing Distributions::     Rolling out tarballs
565 * Dependency Tracking::         Automatic dependency tracking
566 * Nested Packages::             The GNU Build Systems can be nested
567 @end menu
568
569 @node Basic Installation
570 @subsection Basic Installation
571 @cindex Configuration, basics
572 @cindex Installation, basics
573 @cindex GNU Build System, basics
574
575 The most common installation procedure looks as follows.
576
577 @example
578 ~ % @kbd{tar zxf amhello-1.0.tar.gz}
579 ~ % @kbd{cd amhello-1.0}
580 ~/amhello-1.0 % @kbd{./configure}
581 @dots{}
582 config.status: creating Makefile
583 config.status: creating src/Makefile
584 @dots{}
585 ~/amhello-1.0 % @kbd{make}
586 @dots{}
587 ~/amhello-1.0 % @kbd{make check}
588 @dots{}
589 ~/amhello-1.0 % @kbd{su}
590 Password:
591 /home/adl/amhello-1.0 # @kbd{make install}
592 @dots{}
593 /home/adl/amhello-1.0 # @kbd{exit}
594 ~/amhello-1.0 % @kbd{make installcheck}
595 @dots{}
596 @end example
597
598 @cindex Unpacking
599
600 The user first unpacks the package.  Here, and in the following
601 examples, we will use the non-portable @code{tar zxf} command for
602 simplicity.  On a system without GNU @command{tar} installed, this
603 command should read @code{gunzip -c amhello-1.0.tar.gz | tar xf -}.
604
605 The user then enters the newly created directory to run the
606 @file{configure} script.  This script probes the system for various
607 features, and finally creates the @file{Makefile}s.  In this toy
608 example there are only two @file{Makefile}s, but in real-world projects,
609 there may be many more, usually one @file{Makefile} per directory.
610
611 It is now possible to run @code{make}.  This will construct all the
612 programs, libraries, and scripts that need to be constructed for the
613 package.  In our example, this compiles the @file{hello} program.
614 All files are constructed in place, in the source tree; we will see
615 later how this can be changed.
616
617 @code{make check} causes the package's tests to be run.  This step is
618 not mandatory, but it is often good to make sure the programs that
619 have been built behave as they should, before you decide to install
620 them.  Our example does not contain any tests, so running @code{make
621 check} is a no-op.
622
623 @cindex su, before @code{make install}
624 After everything has been built, and maybe tested, it is time to
625 install it on the system.  That means copying the programs,
626 libraries, header files, scripts, and other data files from the
627 source directory to their final destination on the system.  The
628 command @code{make install} will do that.  However, by default
629 everything will be installed in subdirectories of @file{/usr/local}:
630 binaries will go into @file{/usr/local/bin}, libraries will end up in
631 @file{/usr/local/lib}, etc.  This destination is usually not writable
632 by any user, so we assume that we have to become root before we can
633 run @code{make install}.  In our example, running @code{make install}
634 will copy the program @file{hello} into @file{/usr/local/bin}
635 and @file{README} into @file{/usr/local/share/doc/amhello}.
636
637 A last and optional step is to run @code{make installcheck}.  This
638 command may run tests on the installed files.  @code{make check} tests
639 the files in the source tree, while @code{make installcheck} tests
640 their installed copies.  The tests run by the latter can be different
641 from those run by the former.  For instance, there are tests that
642 cannot be run in the source tree.  Conversely, some packages are set
643 up so that @code{make installcheck} will run the very same tests as
644 @code{make check}, only on different files (non-installed
645 vs.@: installed).  It can make a difference, for instance when the
646 source tree's layout is different from that of the installation.
647 Furthermore it may help to diagnose an incomplete installation.
648
649 Presently most packages do not have any @code{installcheck} tests
650 because the existence of @code{installcheck} is little known, and its
651 usefulness is neglected.  Our little toy package is no better: @code{make
652 installcheck} does nothing.
653
654 @node Standard Targets
655 @subsection Standard @file{Makefile} Targets
656
657 So far we have come across four ways to run @command{make} in the GNU
658 Build System: @code{make}, @code{make check}, @code{make install}, and
659 @code{make installcheck}.  The words @code{check}, @code{install}, and
660 @code{installcheck}, passed as arguments to @command{make}, are called
661 @dfn{targets}.  @code{make} is a shorthand for @code{make all},
662 @code{all} being the default target in the GNU Build System.
663
664 Here is a list of the most useful targets that the GNU Coding Standards
665 specify.
666
667 @table @code
668 @item make all
669 @trindex all
670 Build programs, libraries, documentation, etc.@: (same as @code{make}).
671 @item make install
672 @trindex install
673 Install what needs to be installed, copying the files from the
674 package's tree to system-wide directories.
675 @item make install-strip
676 @trindex install-strip
677 Same as @code{make install}, then strip debugging symbols.  Some
678 users like to trade space for useful bug reports@enddots{}
679 @item make uninstall
680 @trindex uninstall
681 The opposite of @code{make install}: erase the installed files.
682 (This needs to be run from the same build tree that was installed.)
683 @item make clean
684 @trindex clean
685 Erase from the build tree the files built by @code{make all}.
686 @item make distclean
687 @trindex distclean
688 Additionally erase anything @code{./configure} created.
689 @item make check
690 @trindex check
691 Run the test suite, if any.
692 @item make installcheck
693 @trindex installcheck
694 Check the installed programs or libraries, if supported.
695 @item make dist
696 @trindex dist
697 Recreate @file{@var{package}-@var{version}.tar.gz} from all the source
698 files.
699 @end table
700
701 @node Standard Directory Variables
702 @subsection Standard Directory Variables
703 @cindex directory variables
704
705 The GNU Coding Standards also specify a hierarchy of variables to
706 denote installation directories.  Some of these are:
707
708 @multitable {Directory variable} {@code{$@{datarootdir@}/doc/$@{PACKAGE@}}}
709 @headitem Directory variable    @tab Default value
710 @item @code{prefix}              @tab @code{/usr/local}
711 @item @w{@ @ @code{exec_prefix}} @tab @code{$@{prefix@}}
712 @item @w{@ @ @ @ @code{bindir}}  @tab @code{$@{exec_prefix@}/bin}
713 @item @w{@ @ @ @ @code{libdir}}  @tab @code{$@{exec_prefix@}/lib}
714 @item @w{@ @ @ @ @dots{}}
715 @item @w{@ @ @code{includedir}}  @tab @code{$@{prefix@}/include}
716 @item @w{@ @ @code{datarootdir}} @tab @code{$@{prefix@}/share}
717 @item @w{@ @ @ @ @code{datadir}} @tab @code{$@{datarootdir@}}
718 @item @w{@ @ @ @ @code{mandir}}  @tab @code{$@{datarootdir@}/man}
719 @item @w{@ @ @ @ @code{infodir}} @tab @code{$@{datarootdir@}/info}
720 @item @w{@ @ @ @ @code{docdir}}  @tab @code{$@{datarootdir@}/doc/$@{PACKAGE@}}
721 @item @w{@ @ @dots{}}
722 @end multitable
723
724 @c We should provide a complete table somewhere, but not here.  The
725 @c complete list of directory variables it too confusing as-is.  It
726 @c requires some explanations that are too complicated for this
727 @c introduction.  Besides listing directories like localstatedir
728 @c would make the explanations in ``Two-Part Install'' harder.
729
730 Each of these directories has a role which is often obvious from its
731 name.  In a package, any installable file will be installed in one of
732 these directories.  For instance in @code{amhello-1.0}, the program
733 @file{hello} is to be installed in @var{bindir}, the directory for
734 binaries.  The default value for this directory is
735 @file{/usr/local/bin}, but the user can supply a different value when
736 calling @command{configure}.  Also the file @file{README} will be
737 installed into @var{docdir}, which defaults to
738 @file{/usr/local/share/doc/amhello}.
739
740 @opindex --prefix
741
742 As a user, if you wish to install a package on your own account, you
743 could proceed as follows:
744
745 @example
746 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
747 @dots{}
748 ~/amhello-1.0 % @kbd{make}
749 @dots{}
750 ~/amhello-1.0 % @kbd{make install}
751 @dots{}
752 @end example
753
754 This would install @file{~/usr/bin/hello} and
755 @file{~/usr/share/doc/amhello/README}.
756
757 The list of all such directory options is shown by
758 @code{./configure --help}.
759
760 @node Standard Configuration Variables
761 @subsection Standard Configuration Variables
762 @cindex configuration variables, overriding
763
764 The GNU Coding Standards also define a set of standard configuration
765 variables used during the build.  Here are some:
766
767 @table @asis
768 @item @code{CC}
769 C compiler command
770 @item @code{CFLAGS}
771 C compiler flags
772 @item @code{CXX}
773 C++ compiler command
774 @item @code{CXXFLAGS}
775 C++ compiler flags
776 @item @code{LDFLAGS}
777 linker flags
778 @item @code{CPPFLAGS}
779 C/C++ preprocessor flags
780 @item @dots{}
781 @end table
782
783 @command{configure} usually does a good job at setting appropriate
784 values for these variables, but there are cases where you may want to
785 override them.  For instance you may have several versions of a
786 compiler installed and would like to use another one, you may have
787 header files installed outside the default search path of the
788 compiler, or even libraries out of the way of the linker.
789
790 Here is how one would call @command{configure} to force it to use
791 @command{gcc-3} as C compiler, use header files from
792 @file{~/usr/include} when compiling, and libraries from
793 @file{~/usr/lib} when linking.
794
795 @example
796 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
797 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
798 @end example
799
800 Again, a full list of these variables appears in the output of
801 @code{./configure --help}.
802
803 @node config.site
804 @subsection Overriding Default Configuration Setting with @file{config.site}
805 @cindex @file{config.site} example
806
807 When installing several packages using the same setup, it can be
808 convenient to create a file to capture common settings.
809 If a file named @file{@var{prefix}/share/config.site} exists,
810 @command{configure} will source it at the beginning of its execution.
811
812 Recall the command from the previous section:
813
814 @example
815 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
816 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
817 @end example
818
819 Assuming we are installing many package in @file{~/usr}, and will
820 always want to use these definitions of @code{CC}, @code{CPPFLAGS}, and
821 @code{LDFLAGS}, we can automate this by creating the following
822 @file{~/usr/share/config.site} file:
823
824 @example
825 test -z "$CC" && CC=gcc-3
826 test -z "$CPPFLAGS" && CPPFLAGS=-I$HOME/usr/include
827 test -z "$LDFLAGS" && LDFLAGS=-L$HOME/usr/lib
828 @end example
829
830 Now, any time a @file{configure} script is using the @file{~/usr}
831 prefix, it will execute the above @file{config.site} and define
832 these three variables.
833
834 @example
835 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
836 configure: loading site script /home/adl/usr/share/config.site
837 @dots{}
838 @end example
839
840 @xref{Site Defaults, , Setting Site Defaults, autoconf, The Autoconf
841 Manual}, for more information about this feature.
842
843
844 @node VPATH Builds
845 @subsection Parallel Build Trees (a.k.a.@: VPATH Builds)
846 @cindex Parallel build trees
847 @cindex VPATH builds
848 @cindex source tree and build tree
849 @cindex build tree and source tree
850 @cindex trees, source vs.@: build
851
852 The GNU Build System distinguishes two trees: the source tree, and
853 the build tree.
854
855 The source tree is rooted in the directory containing
856 @file{configure}.  It contains all the sources files (those that are
857 distributed), and may be arranged using several subdirectories.
858
859 The build tree is rooted in the directory in which @file{configure}
860 was run, and is populated with all object files, programs, libraries,
861 and other derived files built from the sources (and hence not
862 distributed).  The build tree usually has the same subdirectory layout
863 as the source tree; its subdirectories are created automatically by
864 the build system.
865
866 If @file{configure} is executed in its own directory, the source and
867 build trees are combined: derived files are constructed in the same
868 directories as their sources.  This was the case in our first
869 installation example (@pxref{Basic Installation}).
870
871 A common request from users is that they want to confine all derived
872 files to a single directory, to keep their source directories
873 uncluttered.  Here is how we could run @file{configure} to build
874 everything in a subdirectory called @file{build/}.
875
876 @example
877 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
878 ~ % @kbd{cd amhello-1.0}
879 ~/amhello-1.0 % @kbd{mkdir build && cd build}
880 ~/amhello-1.0/build % @kbd{../configure}
881 @dots{}
882 ~/amhello-1.0/build % @kbd{make}
883 @dots{}
884 @end example
885
886 These setups, where source and build trees are different, are often
887 called @dfn{parallel builds} or @dfn{VPATH builds}.  The expression
888 @emph{parallel build} is misleading: the word @emph{parallel} is a
889 reference to the way the build tree shadows the source tree, it is not
890 about some concurrency in the way build commands are run.  For this
891 reason we refer to such setups using the name @emph{VPATH builds} in
892 the following.  @emph{VPATH} is the name of the @command{make} feature
893 used by the @file{Makefile}s to allow these builds (@pxref{General
894 Search, , @code{VPATH} Search Path for All Prerequisites, make, The
895 GNU Make Manual}).
896
897 @cindex multiple configurations, example
898 @cindex debug build, example
899 @cindex optimized build, example
900
901 VPATH builds have other interesting uses.  One is to build the same
902 sources with multiple configurations.  For instance:
903
904 @c Keep in sync with amhello-cflags.test.
905 @example
906 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
907 ~ % @kbd{cd amhello-1.0}
908 ~/amhello-1.0 % @kbd{mkdir debug optim && cd debug}
909 ~/amhello-1.0/debug % @kbd{../configure CFLAGS='-g -O0'}
910 @dots{}
911 ~/amhello-1.0/debug % @kbd{make}
912 @dots{}
913 ~/amhello-1.0/debug % cd ../optim
914 ~/amhello-1.0/optim % @kbd{../configure CFLAGS='-O3 -fomit-frame-pointer'}
915 @dots{}
916 ~/amhello-1.0/optim % @kbd{make}
917 @dots{}
918 @end example
919
920 With network file systems, a similar approach can be used to build the
921 same sources on different machines.  For instance, suppose that the
922 sources are installed on a directory shared by two hosts: @code{HOST1}
923 and @code{HOST2}, which may be different platforms.
924
925 @example
926 ~ % @kbd{cd /nfs/src}
927 /nfs/src % @kbd{tar zxf ~/amhello-1.0.tar.gz}
928 @end example
929
930 On the first host, you could create a local build directory:
931 @example
932 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
933 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
934 ...
935 [HOST1] /tmp/amh % @kbd{make && sudo make install}
936 ...
937 @end example
938
939 @noindent
940 (Here we assume that the installer has configured @command{sudo} so it
941 can execute @code{make install} with root privileges; it is more convenient
942 than using @command{su} like in @ref{Basic Installation}).
943
944 On the second host, you would do exactly the same, possibly at
945 the same time:
946 @example
947 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
948 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
949 ...
950 [HOST2] /tmp/amh % @kbd{make && sudo make install}
951 ...
952 @end example
953
954 @cindex read-only source tree
955 @cindex source tree, read-only
956
957 In this scenario, nothing forbids the @file{/nfs/src/amhello-1.0}
958 directory from being read-only.  In fact VPATH builds are also a means
959 of building packages from a read-only medium such as a CD-ROM.  (The
960 FSF used to sell CD-ROM with unpacked source code, before the GNU
961 project grew so big.)
962
963 @node Two-Part Install
964 @subsection Two-Part Installation
965
966 In our last example (@pxref{VPATH Builds}), a source tree was shared
967 by two hosts, but compilation and installation were done separately on
968 each host.
969
970 The GNU Build System also supports networked setups where part of the
971 installed files should be shared amongst multiple hosts.  It does so
972 by distinguishing architecture-dependent files from
973 architecture-independent files, and providing two @file{Makefile}
974 targets to install each of these classes of files.
975
976 @trindex install-exec
977 @trindex install-data
978
979 These targets are @code{install-exec} for architecture-dependent files
980 and @code{install-data} for architecture-independent files.
981 The command we used up to now, @code{make install}, can be thought of
982 as a shorthand for @code{make install-exec install-data}.
983
984 From the GNU Build System point of view, the distinction between
985 architecture-dependent files and architecture-independent files is
986 based exclusively on the directory variable used to specify their
987 installation destination.  In the list of directory variables we
988 provided earlier (@pxref{Standard Directory Variables}), all the
989 variables based on @var{exec-prefix} designate architecture-dependent
990 directories whose files will be installed by @code{make install-exec}.
991 The others designate architecture-independent directories and will
992 serve files installed by @code{make install-data}.  @xref{The Two Parts
993 of Install}, for more details.
994
995 Here is how we could revisit our two-host installation example,
996 assuming that (1) we want to install the package directly in
997 @file{/usr}, and (2) the directory @file{/usr/share} is shared by the
998 two hosts.
999
1000 On the first host we would run
1001 @example
1002 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1003 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1004 ...
1005 [HOST1] /tmp/amh % @kbd{make && sudo make install}
1006 ...
1007 @end example
1008
1009 On the second host, however, we need only install the
1010 architecture-specific files.
1011 @example
1012 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1013 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1014 ...
1015 [HOST2] /tmp/amh % @kbd{make && sudo make install-exec}
1016 ...
1017 @end example
1018
1019 In packages that have installation checks, it would make sense to run
1020 @code{make installcheck} (@pxref{Basic Installation}) to verify that
1021 the package works correctly despite the apparent partial installation.
1022
1023 @node Cross-Compilation
1024 @subsection Cross-Compilation
1025 @cindex cross-compilation
1026
1027 To @dfn{cross-compile} is to build on one platform a binary that will
1028 run on another platform.  When speaking of cross-compilation, it is
1029 important to distinguish between the @dfn{build platform} on which
1030 the compilation is performed, and the @dfn{host platform} on which the
1031 resulting executable is expected to run.  The following
1032 @command{configure} options are used to specify each of them:
1033
1034 @table @option
1035 @item --build=@var{build}
1036 @opindex --build=@var{build}
1037 The system on which the package is built.
1038 @item --host=@var{host}
1039 @opindex --host=@var{host}
1040 The system where built programs and libraries will run.
1041 @end table
1042
1043 When the @option{--host} is used, @command{configure} will search for
1044 the cross-compiling suite for this platform.  Cross-compilation tools
1045 commonly have their target architecture as prefix of their name.  For
1046 instance my cross-compiler for MinGW32 has its binaries called
1047 @code{i586-mingw32msvc-gcc}, @code{i586-mingw32msvc-ld},
1048 @code{i586-mingw32msvc-as}, etc.
1049
1050 @cindex MinGW cross-compilation example
1051 @cindex cross-compilation example
1052
1053 Here is how we could build @code{amhello-1.0} for
1054 @code{i586-mingw32msvc} on a GNU/Linux PC.
1055
1056 @c Keep in sync with amhello-cross-compile.test.
1057 @smallexample
1058 ~/amhello-1.0 % @kbd{./configure --build i686-pc-linux-gnu --host i586-mingw32msvc}
1059 checking for a BSD-compatible install... /usr/bin/install -c
1060 checking whether build environment is sane... yes
1061 checking for gawk... gawk
1062 checking whether make sets $(MAKE)... yes
1063 checking for i586-mingw32msvc-strip... i586-mingw32msvc-strip
1064 checking for i586-mingw32msvc-gcc... i586-mingw32msvc-gcc
1065 checking for C compiler default output file name... a.exe
1066 checking whether the C compiler works... yes
1067 checking whether we are cross compiling... yes
1068 checking for suffix of executables... .exe
1069 checking for suffix of object files... o
1070 checking whether we are using the GNU C compiler... yes
1071 checking whether i586-mingw32msvc-gcc accepts -g... yes
1072 checking for i586-mingw32msvc-gcc option to accept ANSI C...
1073 @dots{}
1074 ~/amhello-1.0 % @kbd{make}
1075 @dots{}
1076 ~/amhello-1.0 % @kbd{cd src; file hello.exe}
1077 hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable
1078 @end smallexample
1079
1080 The @option{--host} and @option{--build} options are usually all we
1081 need for cross-compiling.  The only exception is if the package being
1082 built is itself a cross-compiler: we need a third option to specify
1083 its target architecture.
1084
1085 @table @option
1086 @item --target=@var{target}
1087 @opindex --target=@var{target}
1088 When building compiler tools: the system for which the tools will
1089 create output.
1090 @end table
1091
1092 For instance when installing GCC, the GNU Compiler Collection, we can
1093 use @option{--target=@/@var{target}} to specify that we want to build
1094 GCC as a cross-compiler for @var{target}.  Mixing @option{--build} and
1095 @option{--target}, we can actually cross-compile a cross-compiler;
1096 such a three-way cross-compilation is known as a @dfn{Canadian cross}.
1097
1098 @xref{Specifying Names, , Specifying the System Type, autoconf, The
1099 Autoconf Manual}, for more information about these @command{configure}
1100 options.
1101
1102 @node Renaming
1103 @subsection Renaming Programs at Install Time
1104 @cindex Renaming programs
1105 @cindex Transforming program names
1106 @cindex Programs, renaming during installation
1107
1108 The GNU Build System provides means to automatically rename
1109 executables and manpages before they are installed (@pxref{Man Pages}).
1110 This is especially convenient
1111 when installing a GNU package on a system that already has a
1112 proprietary implementation you do not want to overwrite.  For instance,
1113 you may want to install GNU @command{tar} as @command{gtar} so you can
1114 distinguish it from your vendor's @command{tar}.
1115
1116 This can be done using one of these three @command{configure} options.
1117
1118 @table @option
1119 @item --program-prefix=@var{prefix}
1120 @opindex --program-prefix=@var{prefix}
1121 Prepend @var{prefix} to installed program names.
1122 @item --program-suffix=@var{suffix}
1123 @opindex --program-suffix=@var{suffix}
1124 Append @var{suffix} to installed program names.
1125 @item --program-transform-name=@var{program}
1126 @opindex --program-transform-name=@var{program}
1127 Run @code{sed @var{program}} on installed program names.
1128 @end table
1129
1130 The following commands would install @file{hello}
1131 as @file{/usr/local/bin/test-hello}, for instance.
1132
1133 @example
1134 ~/amhello-1.0 % @kbd{./configure --program-prefix test-}
1135 @dots{}
1136 ~/amhello-1.0 % @kbd{make}
1137 @dots{}
1138 ~/amhello-1.0 % @kbd{sudo make install}
1139 @dots{}
1140 @end example
1141
1142 @node DESTDIR
1143 @subsection Building Binary Packages Using DESTDIR
1144 @vindex DESTDIR
1145
1146 The GNU Build System's @code{make install} and @code{make uninstall}
1147 interface does not exactly fit the needs of a system administrator
1148 who has to deploy and upgrade packages on lots of hosts.  In other
1149 words, the GNU Build System does not replace a package manager.
1150
1151 Such package managers usually need to know which files have been
1152 installed by a package, so a mere @code{make install} is
1153 inappropriate.
1154
1155 @cindex Staged installation
1156
1157 The @code{DESTDIR} variable can be used to perform a staged
1158 installation.  The package should be configured as if it was going to
1159 be installed in its final location (e.g., @code{--prefix /usr}), but
1160 when running @code{make install}, the @code{DESTDIR} should be set to
1161 the absolute name of a directory into which the installation will be
1162 diverted.  From this directory it is easy to review which files are
1163 being installed where, and finally copy them to their final location
1164 by some means.
1165
1166 @cindex Binary package
1167
1168 For instance here is how we could create a binary package containing a
1169 snapshot of all the files to be installed.
1170
1171 @c Keep in sync with amhello-binpkg.test.
1172 @example
1173 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1174 @dots{}
1175 ~/amhello-1.0 % @kbd{make}
1176 @dots{}
1177 ~/amhello-1.0 % @kbd{make DESTDIR=$HOME/inst install}
1178 @dots{}
1179 ~/amhello-1.0 % @kbd{cd ~/inst}
1180 ~/inst % @kbd{find . -type f -print > ../files.lst}
1181 ~/inst % @kbd{tar zcvf ~/amhello-1.0-i686.tar.gz `cat ../files.lst`}
1182 ./usr/bin/hello
1183 ./usr/share/doc/amhello/README
1184 @end example
1185
1186 After this example, @code{amhello-1.0-i686.tar.gz} is ready to be
1187 uncompressed in @file{/} on many hosts.  (Using @code{`cat ../files.lst`}
1188 instead of @samp{.} as argument for @command{tar} avoids entries for
1189 each subdirectory in the archive: we would not like @command{tar} to
1190 restore the modification time of @file{/}, @file{/usr/}, etc.)
1191
1192 Note that when building packages for several architectures, it might
1193 be convenient to use @code{make install-data} and @code{make
1194 install-exec} (@pxref{Two-Part Install}) to gather
1195 architecture-independent files in a single package.
1196
1197 @xref{Install}, for more information.
1198
1199 @c We should document PRE_INSTALL/POST_INSTALL/NORMAL_INSTALL and their
1200 @c UNINSTALL counterparts.
1201
1202 @node Preparing Distributions
1203 @subsection Preparing Distributions
1204 @cindex Preparing distributions
1205 @cindex Packages, preparation
1206 @cindex Distributions, preparation
1207
1208 We have already mentioned @code{make dist}.  This target collects all
1209 your source files and the necessary parts of the build system to
1210 create a tarball named @file{@var{package}-@var{version}.tar.gz}.
1211
1212 @cindex @code{distcheck} better than @code{dist}
1213
1214 Another, more useful command is @code{make distcheck}.  The
1215 @code{distcheck} target constructs
1216 @file{@var{package}-@var{version}.tar.gz} just as well as @code{dist},
1217 but it additionally ensures most of the use cases presented so far
1218 work:
1219
1220 @itemize @bullet
1221 @item
1222 It attempts a full compilation of the package (@pxref{Basic
1223 Installation}), unpacking the newly constructed tarball, running
1224 @code{make}, @code{make check}, @code{make install}, as well as
1225 @code{make installcheck}, and even @code{make dist},
1226 @item
1227 it tests VPATH builds with read-only source tree (@pxref{VPATH Builds}),
1228 @item
1229 it makes sure @code{make clean}, @code{make distclean}, and @code{make
1230 uninstall} do not omit any file (@pxref{Standard Targets}),
1231 @item
1232 and it checks that @code{DESTDIR} installations work (@pxref{DESTDIR}).
1233 @end itemize
1234
1235 All of these actions are performed in a temporary subdirectory, so
1236 that no root privileges are required.
1237
1238 Releasing a package that fails @code{make distcheck} means that one of
1239 the scenarios we presented will not work and some users will be
1240 disappointed.  Therefore it is a good practice to release a package
1241 only after a successful @code{make distcheck}.  This of course does
1242 not imply that the package will be flawless, but at least it will
1243 prevent some of the embarrassing errors you may find in packages
1244 released by people who have never heard about @code{distcheck} (like
1245 @code{DESTDIR} not working because of a typo, or a distributed file
1246 being erased by @code{make clean}, or even @code{VPATH} builds not
1247 working).
1248
1249 @xref{Creating amhello}, to recreate @file{amhello-1.0.tar.gz} using
1250 @code{make distcheck}.  @xref{Checking the Distribution}, for more
1251 information about @code{distcheck}.
1252
1253 @node Dependency Tracking
1254 @subsection Automatic Dependency Tracking
1255 @cindex Dependency tracking
1256
1257 Dependency tracking is performed as a side-effect of compilation.
1258 Each time the build system compiles a source file, it computes its
1259 list of dependencies (in C these are the header files included by the
1260 source being compiled).  Later, any time @command{make} is run and a
1261 dependency appears to have changed, the dependent files will be
1262 rebuilt.
1263
1264 Automake generates code for automatic dependency tracking by default,
1265 unless the developer chooses to override it; for more information,
1266 @pxref{Dependencies}.
1267
1268 When @command{configure} is executed, you can see it probing each
1269 compiler for the dependency mechanism it supports (several mechanisms
1270 can be used):
1271
1272 @example
1273 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1274 @dots{}
1275 checking dependency style of gcc... gcc3
1276 @dots{}
1277 @end example
1278
1279 Because dependencies are only computed as a side-effect of the
1280 compilation, no dependency information exists the first time a package
1281 is built.  This is OK because all the files need to be built anyway:
1282 @code{make} does not have to decide which files need to be rebuilt.
1283 In fact, dependency tracking is completely useless for one-time builds
1284 and there is a @command{configure} option to disable this:
1285
1286 @table @option
1287 @item --disable-dependency-tracking
1288 @opindex --disable-dependency-tracking
1289 Speed up one-time builds.
1290 @end table
1291
1292 Some compilers do not offer any practical way to derive the list of
1293 dependencies as a side-effect of the compilation, requiring a separate
1294 run (maybe of another tool) to compute these dependencies.  The
1295 performance penalty implied by these methods is important enough to
1296 disable them by default.  The option @option{--enable-dependency-tracking}
1297 must be passed to @command{configure} to activate them.
1298
1299 @table @option
1300 @item --enable-dependency-tracking
1301 @opindex --enable-dependency-tracking
1302 Do not reject slow dependency extractors.
1303 @end table
1304
1305 @xref{Dependency Tracking Evolution}, for some discussion about the
1306 different dependency tracking schemes used by Automake over the years.
1307
1308 @node Nested Packages
1309 @subsection Nested Packages
1310 @cindex Nested packages
1311 @cindex Packages, nested
1312 @cindex Subpackages
1313
1314 Although nesting packages isn't something we would recommend to
1315 someone who is discovering the Autotools, it is a nice feature worthy
1316 of mention in this small advertising tour.
1317
1318 Autoconfiscated packages (that means packages whose build system have
1319 been created by Autoconf and friends) can be nested to arbitrary
1320 depth.
1321
1322 A typical setup is that package A will distribute one of the libraries
1323 it needs in a subdirectory.  This library B is a complete package with
1324 its own GNU Build System.  The @command{configure} script of A will
1325 run the @command{configure} script of B as part of its execution,
1326 building and installing A will also build and install B.  Generating a
1327 distribution for A will also include B.
1328
1329 It is possible to gather several packages like this.  GCC is a heavy
1330 user of this feature.  This gives installers a single package to
1331 configure, build and install, while it allows developers to work on
1332 subpackages independently.
1333
1334 When configuring nested packages, the @command{configure} options
1335 given to the top-level @command{configure} are passed recursively to
1336 nested @command{configure}s.  A package that does not understand an
1337 option will ignore it, assuming it is meaningful to some other
1338 package.
1339
1340 @opindex --help=recursive
1341
1342 The command @code{configure --help=recursive} can be used to display
1343 the options supported by all the included packages.
1344
1345 @xref{Subpackages}, for an example setup.
1346
1347 @node Why Autotools
1348 @section How Autotools Help
1349 @cindex Autotools, purpose
1350
1351 There are several reasons why you may not want to implement the GNU
1352 Build System yourself (read: write a @file{configure} script and
1353 @file{Makefile}s yourself).
1354
1355 @itemize @bullet
1356 @item
1357 As we have seen, the GNU Build System has a lot of
1358 features (@pxref{Use Cases}).
1359 Some users may expect features you have not implemented because
1360 you did not need them.
1361 @item
1362 Implementing these features portably is difficult and exhausting.
1363 Think of writing portable shell scripts, and portable
1364 @file{Makefile}s, for systems you may not have handy.  @xref{Portable
1365 Shell, , Portable Shell Programming, autoconf, The Autoconf Manual}, to
1366 convince yourself.
1367 @item
1368 You will have to upgrade your setup to follow changes to the GNU
1369 Coding Standards.
1370 @end itemize
1371
1372 The GNU Autotools take all this burden off your back and provide:
1373
1374 @itemize @bullet
1375 @item
1376 Tools to create a portable, complete, and self-contained GNU Build
1377 System, from simple instructions.
1378 @emph{Self-contained} meaning the resulting build system does not
1379 require the GNU Autotools.
1380 @item
1381 A central place where fixes and improvements are made:
1382 a bug-fix for a portability issue will benefit every package.
1383 @end itemize
1384
1385 Yet there also exist reasons why you may want NOT to use the
1386 Autotools@enddots{} For instance you may be already using (or used to)
1387 another incompatible build system.  Autotools will only be useful if
1388 you do accept the concepts of the GNU Build System.  People who have their
1389 own idea of how a build system should work will feel frustrated by the
1390 Autotools.
1391
1392 @node Hello World
1393 @section A Small Hello World
1394 @cindex Example Hello World
1395 @cindex Hello World example
1396 @cindex @file{amhello-1.0.tar.gz}, creation
1397
1398 In this section we recreate the @file{amhello-1.0} package from
1399 scratch.  The first subsection shows how to call the Autotools to
1400 instantiate the GNU Build System, while the second explains the
1401 meaning of the @file{configure.ac} and @file{Makefile.am} files read
1402 by the Autotools.
1403
1404 @anchor{amhello Explained}
1405 @menu
1406 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
1407 * amhello's configure.ac Setup Explained::
1408 * amhello's Makefile.am Setup Explained::
1409 @end menu
1410
1411 @node Creating amhello
1412 @subsection Creating @file{amhello-1.0.tar.gz}
1413
1414 Here is how we can recreate @file{amhello-1.0.tar.gz} from scratch.
1415 The package is simple enough so that we will only need to write 5
1416 files.  (You may copy them from the final @file{amhello-1.0.tar.gz}
1417 that is distributed with Automake if you do not want to write them.)
1418
1419 Create the following files in an empty directory.
1420
1421 @itemize @bullet
1422
1423 @item
1424 @file{src/main.c} is the source file for the @file{hello} program.  We
1425 store it in the @file{src/} subdirectory, because later, when the package
1426 evolves, it will ease the addition of a @file{man/} directory for man
1427 pages, a @file{data/} directory for data files, etc.
1428 @example
1429 ~/amhello % @kbd{cat src/main.c}
1430 #include <config.h>
1431 #include <stdio.h>
1432
1433 int
1434 main (void)
1435 @{
1436   puts ("Hello World!");
1437   puts ("This is " PACKAGE_STRING ".");
1438   return 0;
1439 @}
1440 @end example
1441
1442 @item
1443 @file{README} contains some very limited documentation for our little
1444 package.
1445 @example
1446 ~/amhello % @kbd{cat README}
1447 This is a demonstration package for GNU Automake.
1448 Type `info Automake' to read the Automake manual.
1449 @end example
1450
1451 @item
1452 @file{Makefile.am} and @file{src/Makefile.am} contain Automake
1453 instructions for these two directories.
1454
1455 @example
1456 ~/amhello % @kbd{cat src/Makefile.am}
1457 bin_PROGRAMS = hello
1458 hello_SOURCES = main.c
1459 ~/amhello % @kbd{cat Makefile.am}
1460 SUBDIRS = src
1461 dist_doc_DATA = README
1462 @end example
1463
1464 @item
1465 Finally, @file{configure.ac} contains Autoconf instructions to
1466 create the @command{configure} script.
1467
1468 @example
1469 ~/amhello % @kbd{cat configure.ac}
1470 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1471 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1472 AC_PROG_CC
1473 AC_CONFIG_HEADERS([config.h])
1474 AC_CONFIG_FILES([
1475  Makefile
1476  src/Makefile
1477 ])
1478 AC_OUTPUT
1479 @end example
1480 @end itemize
1481
1482 @cindex @command{autoreconf}, example
1483
1484 Once you have these five files, it is time to run the Autotools to
1485 instantiate the build system.  Do this using the @command{autoreconf}
1486 command as follows:
1487
1488 @example
1489 ~/amhello % @kbd{autoreconf --install}
1490 configure.ac: installing `./install-sh'
1491 configure.ac: installing `./missing'
1492 src/Makefile.am: installing `./depcomp'
1493 @end example
1494
1495 At this point the build system is complete.
1496
1497 In addition to the three scripts mentioned in its output, you can see
1498 that @command{autoreconf} created four other files: @file{configure},
1499 @file{config.h.in}, @file{Makefile.in}, and @file{src/Makefile.in}.
1500 The latter three files are templates that will be adapted to the
1501 system by @command{configure} under the names @file{config.h},
1502 @file{Makefile}, and @file{src/Makefile}.  Let's do this:
1503
1504 @example
1505 ~/amhello % @kbd{./configure}
1506 checking for a BSD-compatible install... /usr/bin/install -c
1507 checking whether build environment is sane... yes
1508 checking for gawk... no
1509 checking for mawk... mawk
1510 checking whether make sets $(MAKE)... yes
1511 checking for gcc... gcc
1512 checking for C compiler default output file name... a.out
1513 checking whether the C compiler works... yes
1514 checking whether we are cross compiling... no
1515 checking for suffix of executables...
1516 checking for suffix of object files... o
1517 checking whether we are using the GNU C compiler... yes
1518 checking whether gcc accepts -g... yes
1519 checking for gcc option to accept ISO C89... none needed
1520 checking for style of include used by make... GNU
1521 checking dependency style of gcc... gcc3
1522 configure: creating ./config.status
1523 config.status: creating Makefile
1524 config.status: creating src/Makefile
1525 config.status: creating config.h
1526 config.status: executing depfiles commands
1527 @end example
1528
1529 @trindex distcheck
1530 @cindex @code{distcheck} example
1531
1532 You can see @file{Makefile}, @file{src/Makefile}, and @file{config.h}
1533 being created at the end after @command{configure} has probed the
1534 system.  It is now possible to run all the targets we wish
1535 (@pxref{Standard Targets}).  For instance:
1536
1537 @example
1538 ~/amhello % @kbd{make}
1539 @dots{}
1540 ~/amhello % @kbd{src/hello}
1541 Hello World!
1542 This is amhello 1.0.
1543 ~/amhello % @kbd{make distcheck}
1544 @dots{}
1545 =============================================
1546 amhello-1.0 archives ready for distribution:
1547 amhello-1.0.tar.gz
1548 =============================================
1549 @end example
1550
1551 Note that running @command{autoreconf} is only needed initially when
1552 the GNU Build System does not exist.  When you later change some
1553 instructions in a @file{Makefile.am} or @file{configure.ac}, the
1554 relevant part of the build system will be regenerated automatically
1555 when you execute @command{make}.
1556
1557 @command{autoreconf} is a script that calls @command{autoconf},
1558 @command{automake}, and a bunch of other commands in the right order.
1559 If you are beginning with these tools, it is not important to figure
1560 out in which order all these tools should be invoked and why.  However,
1561 because Autoconf and Automake have separate manuals, the important
1562 point to understand is that @command{autoconf} is in charge of
1563 creating @file{configure} from @file{configure.ac}, while
1564 @command{automake} is in charge of creating @file{Makefile.in}s from
1565 @file{Makefile.am}s and @file{configure.ac}.  This should at least
1566 direct you to the right manual when seeking answers.
1567
1568
1569 @node amhello's configure.ac Setup Explained
1570 @subsection @code{amhello}'s @file{configure.ac} Setup Explained
1571
1572 @cindex @file{configure.ac}, Hello World
1573
1574 Let us begin with the contents of @file{configure.ac}.
1575
1576 @example
1577 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1578 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1579 AC_PROG_CC
1580 AC_CONFIG_HEADERS([config.h])
1581 AC_CONFIG_FILES([
1582  Makefile
1583  src/Makefile
1584 ])
1585 AC_OUTPUT
1586 @end example
1587
1588 This file is read by both @command{autoconf} (to create
1589 @file{configure}) and @command{automake} (to create the various
1590 @file{Makefile.in}s).  It contains a series of M4 macros that will be
1591 expanded as shell code to finally form the @file{configure} script.
1592 We will not elaborate on the syntax of this file, because the Autoconf
1593 manual has a whole section about it (@pxref{Writing Autoconf Input, ,
1594 Writing @file{configure.ac}, autoconf, The Autoconf Manual}).
1595
1596 The macros prefixed with @code{AC_} are Autoconf macros, documented
1597 in the Autoconf manual (@pxref{Autoconf Macro Index, , Autoconf Macro
1598 Index, autoconf, The Autoconf Manual}).  The macros that start with
1599 @code{AM_} are Automake macros, documented later in this manual
1600 (@pxref{Macro Index}).
1601
1602 The first two lines of @file{configure.ac} initialize Autoconf and
1603 Automake.  @code{AC_INIT} takes in as parameters the name of the package,
1604 its version number, and a contact address for bug-reports about the
1605 package (this address is output at the end of @code{./configure
1606 --help}, for instance).  When adapting this setup to your own package,
1607 by all means please do not blindly copy Automake's address: use the
1608 mailing list of your package, or your own mail address.
1609
1610 @opindex -Wall
1611 @opindex -Werror
1612 @opindex foreign
1613
1614 The argument to @code{AM_INIT_AUTOMAKE} is a list of options for
1615 @command{automake} (@pxref{Options}).  @option{-Wall} and
1616 @option{-Werror} ask @command{automake} to turn on all warnings and
1617 report them as errors.  We are speaking of @strong{Automake} warnings
1618 here, such as dubious instructions in @file{Makefile.am}.  This has
1619 absolutely nothing to do with how the compiler will be called, even
1620 though it may support options with similar names.  Using @option{-Wall
1621 -Werror} is a safe setting when starting to work on a package: you do
1622 not want to miss any issues.  Later you may decide to relax things a
1623 bit.  The @option{foreign} option tells Automake that this package
1624 will not follow the GNU Standards.  GNU packages should always
1625 distribute additional files such as @file{ChangeLog}, @file{AUTHORS},
1626 etc.  We do not want @command{automake} to complain about these
1627 missing files in our small example.
1628
1629 The @code{AC_PROG_CC} line causes the @command{configure} script to
1630 search for a C compiler and define the variable @code{CC} with its
1631 name.  The @file{src/Makefile.in} file generated by Automake uses the
1632 variable @code{CC} to build @file{hello}, so when @command{configure}
1633 creates @file{src/Makefile} from @file{src/Makefile.in}, it will define
1634 @code{CC} with the value it has found.  If Automake is asked to create
1635 a @file{Makefile.in} that uses @code{CC} but @file{configure.ac} does
1636 not define it, it will suggest you add a call to @code{AC_PROG_CC}.
1637
1638 The @code{AC_CONFIG_HEADERS([config.h])} invocation causes the
1639 @command{configure} script to create a @file{config.h} file gathering
1640 @samp{#define}s defined by other macros in @file{configure.ac}.  In our
1641 case, the @code{AC_INIT} macro already defined a few of them.  Here
1642 is an excerpt of @file{config.h} after @command{configure} has run:
1643
1644 @smallexample
1645 @dots{}
1646 /* Define to the address where bug reports for this package should be sent. */
1647 #define PACKAGE_BUGREPORT "@value{PACKAGE_BUGREPORT}"
1648
1649 /* Define to the full name and version of this package. */
1650 #define PACKAGE_STRING "amhello 1.0"
1651 @dots{}
1652 @end smallexample
1653
1654 As you probably noticed, @file{src/main.c} includes @file{config.h} so
1655 it can use @code{PACKAGE_STRING}.  In a real-world project,
1656 @file{config.h} can grow really big, with one @samp{#define} per
1657 feature probed on the system.
1658
1659 The @code{AC_CONFIG_FILES} macro declares the list of files that
1660 @command{configure} should create from their @file{*.in} templates.
1661 Automake also scans this list to find the @file{Makefile.am} files it must
1662 process.  (This is important to remember: when adding a new directory
1663 to your project, you should add its @file{Makefile} to this list,
1664 otherwise Automake will never process the new @file{Makefile.am} you
1665 wrote in that directory.)
1666
1667 Finally, the @code{AC_OUTPUT} line is a closing command that actually
1668 produces the part of the script in charge of creating the files
1669 registered with @code{AC_CONFIG_HEADERS} and @code{AC_CONFIG_FILES}.
1670
1671 @cindex @command{autoscan}
1672
1673 When starting a new project, we suggest you start with such a simple
1674 @file{configure.ac}, and gradually add the other tests it requires.
1675 The command @command{autoscan} can also suggest a few of the tests
1676 your package may need (@pxref{autoscan Invocation, , Using
1677 @command{autoscan} to Create @file{configure.ac}, autoconf, The
1678 Autoconf Manual}).
1679
1680
1681 @node amhello's Makefile.am Setup Explained
1682 @subsection @code{amhello}'s @file{Makefile.am} Setup Explained
1683
1684 @cindex @file{Makefile.am}, Hello World
1685
1686 We now turn to @file{src/Makefile.am}.  This file contains
1687 Automake instructions to build and install @file{hello}.
1688
1689 @example
1690 bin_PROGRAMS = hello
1691 hello_SOURCES = main.c
1692 @end example
1693
1694 A @file{Makefile.am} has the same syntax as an ordinary
1695 @file{Makefile}.  When @command{automake} processes a
1696 @file{Makefile.am} it copies the entire file into the output
1697 @file{Makefile.in} (that will be later turned into @file{Makefile} by
1698 @command{configure}) but will react to certain variable definitions
1699 by generating some build rules and other variables.
1700 Often @file{Makefile.am}s contain only a list of variable definitions as
1701 above, but they can also contain other variable and rule definitions that
1702 @command{automake} will pass along without interpretation.
1703
1704 Variables that end with @code{_PROGRAMS} are special variables
1705 that list programs that the resulting @file{Makefile} should build.
1706 In Automake speak, this @code{_PROGRAMS} suffix is called a
1707 @dfn{primary}; Automake recognizes other primaries such as
1708 @code{_SCRIPTS}, @code{_DATA}, @code{_LIBRARIES}, etc.@: corresponding
1709 to different types of files.
1710
1711 The @samp{bin} part of the @code{bin_PROGRAMS} tells
1712 @command{automake} that the resulting programs should be installed in
1713 @var{bindir}.  Recall that the GNU Build System uses a set of variables
1714 to denote destination directories and allow users to customize these
1715 locations (@pxref{Standard Directory Variables}).  Any such directory
1716 variable can be put in front of a primary (omitting the @code{dir}
1717 suffix) to tell @command{automake} where to install the listed files.
1718
1719 Programs need to be built from source files, so for each program
1720 @code{@var{prog}} listed in a @code{@w{_PROGRAMS}} variable,
1721 @command{automake} will look for another variable named
1722 @code{@var{prog}_SOURCES} listing its source files.  There may be more
1723 than one source file: they will all be compiled and linked together.
1724
1725 Automake also knows that source files need to be distributed when
1726 creating a tarball (unlike built programs).  So a side-effect of this
1727 @code{hello_SOURCES} declaration is that @file{main.c} will be
1728 part of the tarball created by @code{make dist}.
1729
1730 Finally here are some explanations regarding the top-level
1731 @file{Makefile.am}.
1732
1733 @example
1734 SUBDIRS = src
1735 dist_doc_DATA = README
1736 @end example
1737
1738 @code{SUBDIRS} is a special variable listing all directories that
1739 @command{make} should recurse into before processing the current
1740 directory.  So this line is responsible for @command{make} building
1741 @file{src/hello} even though we run it from the top-level.  This line
1742 also causes @code{make install} to install @file{src/hello} before
1743 installing @file{README} (not that this order matters).
1744
1745 The line @code{dist_doc_DATA = README} causes @file{README} to be
1746 distributed and installed in @var{docdir}.  Files listed with the
1747 @code{_DATA} primary are not automatically part of the tarball built
1748 with @code{make dist}, so we add the @code{dist_} prefix so they get
1749 distributed.  However, for @file{README} it would not have been
1750 necessary: @command{automake} automatically distributes any
1751 @file{README} file it encounters (the list of other files
1752 automatically distributed is presented by @code{automake --help}).
1753 The only important effect of this second line is therefore to install
1754 @file{README} during @code{make install}.
1755
1756 One thing not covered in this example is accessing the installation
1757 directory values (@pxref{Standard Directory Variables}) from your
1758 program code, that is, converting them into defined macros.  For this,
1759 @pxref{Defining Directories,,, autoconf, The Autoconf Manual}.
1760
1761
1762 @node Generalities
1763 @chapter General ideas
1764
1765 The following sections cover a few basic ideas that will help you
1766 understand how Automake works.
1767
1768 @menu
1769 * General Operation::           General operation of Automake
1770 * Strictness::                  Standards conformance checking
1771 * Uniform::                     The Uniform Naming Scheme
1772 * Length Limitations::          Staying below the command line length limit
1773 * Canonicalization::            How derived variables are named
1774 * User Variables::              Variables reserved for the user
1775 * Auxiliary Programs::          Programs automake might require
1776 @end menu
1777
1778
1779 @node General Operation
1780 @section General Operation
1781
1782 Automake works by reading a @file{Makefile.am} and generating a
1783 @file{Makefile.in}.  Certain variables and rules defined in the
1784 @file{Makefile.am} instruct Automake to generate more specialized code;
1785 for instance, a @code{bin_PROGRAMS} variable definition will cause rules
1786 for compiling and linking programs to be generated.
1787
1788 @cindex Non-standard targets
1789 @cindex @code{git-dist}, non-standard example
1790 @trindex git-dist
1791
1792 The variable definitions and rules in the @file{Makefile.am} are
1793 copied mostly verbatim into the generated file, with all variable
1794 definitions preceding all rules.  This allows you to add almost
1795 arbitrary code into the generated @file{Makefile.in}.  For instance,
1796 the Automake distribution includes a non-standard rule for the
1797 @code{git-dist} target, which the Automake maintainer uses to make
1798 distributions from the source control system.
1799
1800 @cindex GNU make extensions
1801
1802 Note that most GNU make extensions are not recognized by Automake.  Using
1803 such extensions in a @file{Makefile.am} will lead to errors or confusing
1804 behavior.
1805
1806 @cindex Append operator
1807 @cmindex +=
1808 A special exception is that the GNU make append operator, @samp{+=}, is
1809 supported.  This operator appends its right hand argument to the variable
1810 specified on the left.  Automake will translate the operator into
1811 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
1812
1813 Automake tries to keep comments grouped with any adjoining rules or
1814 variable definitions.
1815
1816 @cindex Limitations of automake parser
1817 @cindex Automake parser, limitations of
1818 @cindex indentation in Makefile.am
1819 Generally, Automake is not particularly smart in the parsing of unusual
1820 Makefile constructs, so you're advised to avoid fancy constructs or
1821 ``creative'' use of whitespaces.
1822 @c Keep this in sync with doc-parsing-buglets-tabs.test.
1823 For example, @key{TAB} characters cannot be used between a target name
1824 and the following ``@code{:}'' character, and variable assignments
1825 shouldn't be indented with @key{TAB} characters.
1826 @c Keep this in sync with doc-parsing-buglets-colneq-subst.test.
1827 Also, using more complex macro in target names can cause trouble:
1828
1829 @example
1830 % @kbd{cat Makefile.am}
1831 $(FOO:=x): bar
1832 % @kbd{automake}
1833 Makefile.am:1: bad characters in variable name `$(FOO'
1834 Makefile.am:1: `:='-style assignments are not portable
1835 @end example
1836
1837 @cindex Make targets, overriding
1838 @cindex Make rules, overriding
1839 @cindex Overriding make rules
1840 @cindex Overriding make targets
1841
1842 A rule defined in @file{Makefile.am} generally overrides any such
1843 rule of a similar name that would be automatically generated by
1844 @command{automake}.  Although this is a supported feature, it is generally
1845 best to avoid making use of it, as sometimes the generated rules are
1846 very particular.
1847
1848 @cindex Variables, overriding
1849 @cindex Overriding make variables
1850
1851 Similarly, a variable defined in @file{Makefile.am} or
1852 @code{AC_SUBST}ed from @file{configure.ac} will override any
1853 definition of the variable that @command{automake} would ordinarily
1854 create.  This feature is more often useful than the ability to
1855 override a rule.  Be warned that many of the variables generated by
1856 @command{automake} are considered to be for internal use only, and their
1857 names might change in future releases.
1858
1859 @cindex Recursive operation of Automake
1860 @cindex Automake, recursive operation
1861 @cindex Example of recursive operation
1862
1863 When examining a variable definition, Automake will recursively examine
1864 variables referenced in the definition.  For example, if Automake is
1865 looking at the content of @code{foo_SOURCES} in this snippet
1866
1867 @c Keep in sync with interp.test.
1868 @example
1869 xs = a.c b.c
1870 foo_SOURCES = c.c $(xs)
1871 @end example
1872
1873 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
1874 contents of @code{foo_SOURCES}.
1875
1876 @cindex @code{##} (special Automake comment)
1877 @cindex Special Automake comment
1878 @cindex Comment, special to Automake
1879
1880 Automake also allows a form of comment that is @emph{not} copied into
1881 the output; all lines beginning with @samp{##} (leading spaces allowed)
1882 are completely ignored by Automake.
1883
1884 It is customary to make the first line of @file{Makefile.am} read:
1885
1886 @cindex Makefile.am, first line
1887 @cindex First line of Makefile.am
1888
1889 @example
1890 ## Process this file with automake to produce Makefile.in
1891 @end example
1892
1893 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
1894 @c I don't know quite what to say.
1895
1896 @c FIXME document customary ordering of Makefile.am here!
1897
1898
1899 @node Strictness
1900 @section Strictness
1901
1902 @cindex Non-GNU packages
1903
1904 While Automake is intended to be used by maintainers of GNU packages, it
1905 does make some effort to accommodate those who wish to use it, but do
1906 not want to use all the GNU conventions.
1907
1908 @cindex Strictness, defined
1909 @cindex Strictness, @option{foreign}
1910 @cindex @option{foreign} strictness
1911 @cindex Strictness, @option{gnu}
1912 @cindex @option{gnu} strictness
1913 @cindex Strictness, @option{gnits}
1914 @cindex @option{gnits} strictness
1915
1916 To this end, Automake supports three levels of @dfn{strictness}---the
1917 strictness indicating how stringently Automake should check standards
1918 conformance.
1919
1920 The valid strictness levels are:
1921
1922 @table @option
1923 @item foreign
1924 Automake will check for only those things that are absolutely
1925 required for proper operations.  For instance, whereas GNU standards
1926 dictate the existence of a @file{NEWS} file, it will not be required in
1927 this mode.  The name comes from the fact that Automake is intended to be
1928 used for GNU programs; these relaxed rules are not the standard mode of
1929 operation.
1930
1931 @item gnu
1932 Automake will check---as much as possible---for compliance to the GNU
1933 standards for packages.  This is the default.
1934
1935 @item gnits
1936 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
1937 standards}.  These are based on the GNU standards, but are even more
1938 detailed.  Unless you are a Gnits standards contributor, it is
1939 recommended that you avoid this option until such time as the Gnits
1940 standard is actually published (which may never happen).
1941 @end table
1942
1943 @xref{Gnits}, for more information on the precise implications of the
1944 strictness level.
1945
1946 Automake also has a special ``cygnus'' mode that is similar to
1947 strictness but handled differently.  This mode is useful for packages
1948 that are put into a ``Cygnus'' style tree (e.g., the GCC tree).
1949 @xref{Cygnus}, for more information on this mode.
1950
1951
1952 @node Uniform
1953 @section The Uniform Naming Scheme
1954
1955 @cindex Uniform naming scheme
1956
1957 Automake variables generally follow a @dfn{uniform naming scheme} that
1958 makes it easy to decide how programs (and other derived objects) are
1959 built, and how they are installed.  This scheme also supports
1960 @command{configure} time determination of what should be built.
1961
1962 @cindex @code{_PROGRAMS} primary variable
1963 @cindex @code{PROGRAMS} primary variable
1964 @cindex Primary variable, @code{PROGRAMS}
1965 @cindex Primary variable, defined
1966 @vindex _PROGRAMS
1967
1968 At @command{make} time, certain variables are used to determine which
1969 objects are to be built.  The variable names are made of several pieces
1970 that are concatenated together.
1971
1972 The piece that tells @command{automake} what is being built is commonly called
1973 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
1974 list of programs that are to be compiled and linked.
1975 @vindex PROGRAMS
1976
1977 @cindex @code{pkgdatadir}, defined
1978 @cindex @code{pkgincludedir}, defined
1979 @cindex @code{pkglibdir}, defined
1980 @cindex @code{pkglibexecdir}, defined
1981
1982 @vindex pkgdatadir
1983 @vindex pkgincludedir
1984 @vindex pkglibdir
1985 @vindex pkglibexecdir
1986
1987 @cindex @code{PACKAGE}, directory
1988 A different set of names is used to decide where the built objects
1989 should be installed.  These names are prefixes to the primary, and they
1990 indicate which standard directory should be used as the installation
1991 directory.  The standard directory names are given in the GNU standards
1992 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
1993 Automake extends this list with @code{pkgdatadir}, @code{pkgincludedir},
1994 @code{pkglibdir}, and @code{pkglibexecdir}; these are the same as the
1995 non-@samp{pkg} versions, but with @samp{$(PACKAGE)} appended.  For instance,
1996 @code{pkglibdir} is defined as @samp{$(libdir)/$(PACKAGE)}.
1997
1998 @cindex @code{EXTRA_}, prepending
1999 For each primary, there is one additional variable named by prepending
2000 @samp{EXTRA_} to the primary name.  This variable is used to list
2001 objects that may or may not be built, depending on what
2002 @command{configure} decides.  This variable is required because Automake
2003 must statically know the entire list of objects that may be built in
2004 order to generate a @file{Makefile.in} that will work in all cases.
2005
2006 @cindex @code{EXTRA_PROGRAMS}, defined
2007 @cindex Example, @code{EXTRA_PROGRAMS}
2008 @cindex @command{cpio} example
2009
2010 For instance, @command{cpio} decides at configure time which programs
2011 should be built.  Some of the programs are installed in @code{bindir},
2012 and some are installed in @code{sbindir}:
2013
2014 @example
2015 EXTRA_PROGRAMS = mt rmt
2016 bin_PROGRAMS = cpio pax
2017 sbin_PROGRAMS = $(MORE_PROGRAMS)
2018 @end example
2019
2020 Defining a primary without a prefix as a variable, e.g.,
2021 @samp{PROGRAMS}, is an error.
2022
2023 Note that the common @samp{dir} suffix is left off when constructing the
2024 variable names; thus one writes @samp{bin_PROGRAMS} and not
2025 @samp{bindir_PROGRAMS}.
2026
2027 Not every sort of object can be installed in every directory.  Automake
2028 will flag those attempts it finds in error (but see below how to override
2029 the check if you really need to).
2030 Automake will also diagnose obvious misspellings in directory names.
2031
2032 @cindex Extending list of installation directories
2033 @cindex Installation directories, extending list
2034
2035 Sometimes the standard directories---even as augmented by
2036 Automake---are not enough.  In particular it is sometimes useful, for
2037 clarity, to install objects in a subdirectory of some predefined
2038 directory.  To this end, Automake allows you to extend the list of
2039 possible installation directories.  A given prefix (e.g., @samp{zar})
2040 is valid if a variable of the same name with @samp{dir} appended is
2041 defined (e.g., @samp{zardir}).
2042
2043 For instance, the following snippet will install @file{file.xml} into
2044 @samp{$(datadir)/xml}.
2045
2046 @c Keep in sync with primary-prefix-couples-documented-valid.test.
2047 @example
2048 xmldir = $(datadir)/xml
2049 xml_DATA = file.xml
2050 @end example
2051
2052 This feature can also be used to override the sanity checks Automake
2053 performs to diagnose suspicious directory/primary couples (in the
2054 unlikely case these checks are undesirable, and you really know what
2055 you're doing).  For example, Automake would error out on this input:
2056
2057 @c Should be tested in primary-prefix-invalid-couples.test.
2058 @example
2059 # Forbidden directory combinations, automake will error out on this.
2060 pkglib_PROGRAMS = foo
2061 doc_LIBRARIES = libquux.a
2062 @end example
2063
2064 @noindent
2065 but it will succeed with this:
2066
2067 @c Keep in sync with primary-prefix-couples-documented-valid.test.
2068 @example
2069 # Work around forbidden directory combinations.  Do not use this
2070 # without a very good reason!
2071 my_execbindir = $(pkglibdir)
2072 my_doclibdir = $(docdir)
2073 my_execbin_PROGRAMS = foo
2074 my_doclib_LIBRARIES = libquux.a
2075 @end example
2076
2077 The @samp{exec} substring of the @samp{my_execbindir} variable lets
2078 the files be installed at the right time (@pxref{The Two Parts of
2079 Install}).
2080
2081 @cindex @samp{noinst_} primary prefix, definition
2082 @vindex noinst_
2083
2084 The special prefix @samp{noinst_} indicates that the objects in question
2085 should be built but not installed at all.  This is usually used for
2086 objects required to build the rest of your package, for instance static
2087 libraries (@pxref{A Library}), or helper scripts.
2088
2089 @cindex @samp{check_} primary prefix, definition
2090 @vindex check_
2091
2092 The special prefix @samp{check_} indicates that the objects in question
2093 should not be built until the @samp{make check} command is run.  Those
2094 objects are not installed either.
2095
2096 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
2097 @samp{LTLIBRARIES}, @samp{LISP}, @samp{PYTHON}, @samp{JAVA},
2098 @samp{SCRIPTS}, @samp{DATA}, @samp{HEADERS}, @samp{MANS}, and
2099 @samp{TEXINFOS}.
2100 @vindex PROGRAMS
2101 @vindex LIBRARIES
2102 @vindex LTLIBRARIES
2103 @vindex LISP
2104 @vindex PYTHON
2105 @vindex JAVA
2106 @vindex SCRIPTS
2107 @vindex DATA
2108 @vindex HEADERS
2109 @vindex MANS
2110 @vindex TEXINFOS
2111
2112 Some primaries also allow additional prefixes that control other
2113 aspects of @command{automake}'s behavior.  The currently defined prefixes
2114 are @samp{dist_}, @samp{nodist_}, @samp{nobase_}, and @samp{notrans_}.
2115 These prefixes are explained later (@pxref{Program and Library Variables})
2116 (@pxref{Man Pages}).
2117
2118
2119 @node Length Limitations
2120 @section Staying below the command line length limit
2121
2122 @cindex command line length limit
2123 @cindex ARG_MAX
2124
2125 Traditionally, most unix-like systems have a length limitation for the
2126 command line arguments and environment contents when creating new
2127 processes (see for example
2128 @uref{http://www.in-ulm.de/@/~mascheck/@/various/@/argmax/} for an
2129 overview on this issue),
2130 which of course also applies to commands spawned by @command{make}.
2131 POSIX requires this limit to be at least 4096 bytes, and most modern
2132 systems have quite high limits (or are unlimited).
2133
2134 In order to create portable Makefiles that do not trip over these
2135 limits, it is necessary to keep the length of file lists bounded.
2136 Unfortunately, it is not possible to do so fully transparently within
2137 Automake, so your help may be needed.  Typically, you can split long
2138 file lists manually and use different installation directory names for
2139 each list.  For example,
2140
2141 @example
2142 data_DATA = file1 @dots{} file@var{N} file@var{N+1} @dots{} file@var{2N}
2143 @end example
2144
2145 @noindent
2146 may also be written as
2147
2148 @c Keep in sync with primary-prefix-couples-documented-valid.test.
2149 @example
2150 data_DATA = file1 @dots{} file@var{N}
2151 data2dir = $(datadir)
2152 data2_DATA = file@var{N+1} @dots{} file@var{2N}
2153 @end example
2154
2155 @noindent
2156 and will cause Automake to treat the two lists separately during
2157 @code{make install}.  See @ref{The Two Parts of Install} for choosing
2158 directory names that will keep the ordering of the two parts of
2159 installation Note that @code{make dist} may still only work on a host
2160 with a higher length limit in this example.
2161
2162 Automake itself employs a couple of strategies to avoid long command
2163 lines.  For example, when @samp{$@{srcdir@}/} is prepended to file
2164 names, as can happen with above @code{$(data_DATA)} lists, it limits
2165 the amount of arguments passed to external commands.
2166
2167 Unfortunately, some system's @command{make} commands may prepend
2168 @code{VPATH} prefixes like @samp{$@{srcdir@}/} to file names from the
2169 source tree automatically (@pxref{Automatic Rule Rewriting, , Automatic
2170 Rule Rewriting, autoconf, The Autoconf Manual}).  In this case, the user
2171 may have to switch to use GNU Make, or refrain from using VPATH builds,
2172 in order to stay below the length limit.
2173
2174 For libraries and programs built from many sources, convenience archives
2175 may be used as intermediates in order to limit the object list length
2176 (@pxref{Libtool Convenience Libraries}).
2177
2178
2179 @node Canonicalization
2180 @section How derived variables are named
2181
2182 @cindex canonicalizing Automake variables
2183
2184 Sometimes a Makefile variable name is derived from some text the
2185 maintainer supplies.  For instance, a program name listed in
2186 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
2187 variable.  In cases like this, Automake canonicalizes the text, so that
2188 program names and the like do not have to follow Makefile variable naming
2189 rules.  All characters in the name except for letters, numbers, the
2190 strudel (@@), and the underscore are turned into underscores when making
2191 variable references.
2192
2193 For example, if your program is named @file{sniff-glue}, the derived
2194 variable name would be @samp{sniff_glue_SOURCES}, not
2195 @samp{sniff-glue_SOURCES}.  Similarly the sources for a library named
2196 @file{libmumble++.a} should be listed in the
2197 @samp{libmumble___a_SOURCES} variable.
2198
2199 The strudel is an addition, to make the use of Autoconf substitutions in
2200 variable names less obfuscating.
2201
2202
2203 @node User Variables
2204 @section Variables reserved for the user
2205
2206 @cindex variables, reserved for the user
2207 @cindex user variables
2208
2209 Some @file{Makefile} variables are reserved by the GNU Coding Standards
2210 for the use of the ``user''---the person building the package.  For
2211 instance, @code{CFLAGS} is one such variable.
2212
2213 Sometimes package developers are tempted to set user variables such as
2214 @code{CFLAGS} because it appears to make their job easier.  However,
2215 the package itself should never set a user variable, particularly not
2216 to include switches that are required for proper compilation of the
2217 package.  Since these variables are documented as being for the
2218 package builder, that person rightfully expects to be able to override
2219 any of these variables at build time.
2220
2221 To get around this problem, Automake introduces an automake-specific
2222 shadow variable for each user flag variable.  (Shadow variables are
2223 not introduced for variables like @code{CC}, where they would make no
2224 sense.)  The shadow variable is named by prepending @samp{AM_} to the
2225 user variable's name.  For instance, the shadow variable for
2226 @code{YFLAGS} is @code{AM_YFLAGS}.  The package maintainer---that is,
2227 the author(s) of the @file{Makefile.am} and @file{configure.ac}
2228 files---may adjust these shadow variables however necessary.
2229
2230 @xref{Flag Variables Ordering}, for more discussion about these
2231 variables and how they interact with per-target variables.
2232
2233 @node Auxiliary Programs
2234 @section Programs automake might require
2235
2236 @cindex Programs, auxiliary
2237 @cindex Auxiliary programs
2238
2239 Automake sometimes requires helper programs so that the generated
2240 @file{Makefile} can do its work properly.  There are a fairly large
2241 number of them, and we list them here.
2242
2243 Although all of these files are distributed and installed with
2244 Automake, a couple of them are maintained separately.  The Automake
2245 copies are updated before each release, but we mention the original
2246 source in case you need more recent versions.
2247
2248 @table @code
2249 @item ar-lib
2250 This is a wrapper primarily for the Microsoft lib archiver, to make
2251 it more POSIX-like.
2252
2253 @item ansi2knr.c
2254 @itemx ansi2knr.1
2255 These two files are used for de-ANSI-fication support (they are
2256 deprecated now, and @emph{will be removed} in the next major Automake
2257 release; @pxref{ANSI}).
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 config-ml.in
2280 This file is not a program, it is a @file{configure} fragment used for
2281 multilib support (@pxref{Multilibs}).  Since the Automake multilib
2282 support has been @emph{deprecated} and targeted for removal, this
2283 file is going to be @emph{removed from the Automake core} in the next
2284 major release.  The master copy of this file is maintained in the GCC
2285 tree at @url{http://gcc.gnu.org/svn.html}.
2286
2287 @item depcomp
2288 This program understands how to run a compiler so that it will
2289 generate not only the desired output but also dependency information
2290 that is then used by the automatic dependency tracking feature
2291 (@pxref{Dependencies}).
2292
2293 @item elisp-comp
2294 This program is used to byte-compile Emacs Lisp code.
2295
2296 @item install-sh
2297 This is a replacement for the @command{install} program that works on
2298 platforms where @command{install} is unavailable or unusable.
2299
2300 @item mdate-sh
2301 This script is used to generate a @file{version.texi} file.  It examines
2302 a file and prints some date information about it.
2303
2304 @item missing
2305 This wraps a number of programs that are typically only required by
2306 maintainers.  If the program in question doesn't exist,
2307 @command{missing} prints an informative warning and attempts to fix
2308 things so that the build can continue.
2309
2310 @item mkinstalldirs
2311 This script used to be a wrapper around @samp{mkdir -p}, which is not
2312 portable.  Now we prefer to use @samp{install-sh -d} when @command{configure}
2313 finds that @samp{mkdir -p} does not work, this makes one less script to
2314 distribute.
2315
2316 For backward compatibility @file{mkinstalldirs} is still used and
2317 distributed when @command{automake} finds it in a package.  But it is no
2318 longer installed automatically, and it should be safe to remove it.
2319
2320 @item py-compile
2321 This is used to byte-compile Python scripts.
2322
2323 @item symlink-tree
2324 This program duplicates a tree of directories, using symbolic links
2325 instead of copying files.  Such an operation is performed when building
2326 multilibs (@pxref{Multilibs}).  Since the Automake multilib support has
2327 been @emph{deprecated} and targeted for removal, this file is going to
2328 be @emph{removed from the Automake core} in the next major release.
2329 The master copy of this file is maintained in the GCC tree at
2330 @url{http://gcc.gnu.org/svn.html}.
2331
2332 @item texinfo.tex
2333 Not a program, this file is required for @samp{make dvi}, @samp{make
2334 ps} and @samp{make pdf} to work when Texinfo sources are in the
2335 package.  The latest version can be downloaded from
2336 @url{http://www.gnu.org/software/texinfo/}.
2337
2338 @item ylwrap
2339 This program wraps @command{lex} and @command{yacc} to rename their
2340 output files.  It also ensures that, for instance, multiple
2341 @command{yacc} instances can be invoked in a single directory in
2342 parallel.
2343
2344 @end table
2345
2346
2347 @node Examples
2348 @chapter Some example packages
2349
2350 This section contains two small examples.
2351
2352 The first example (@pxref{Complete}) assumes you have an existing
2353 project already using Autoconf, with handcrafted @file{Makefile}s, and
2354 that you want to convert it to using Automake.  If you are discovering
2355 both tools, it is probably better that you look at the Hello World
2356 example presented earlier (@pxref{Hello World}).
2357
2358 The second example (@pxref{true}) shows how two programs can be built
2359 from the same file, using different compilation parameters.  It
2360 contains some technical digressions that are probably best skipped on
2361 first read.
2362
2363 @menu
2364 * Complete::                    A simple example, start to finish
2365 * true::                        Building true and false
2366 @end menu
2367
2368
2369 @node Complete
2370 @section A simple example, start to finish
2371
2372 @cindex Complete example
2373
2374 Let's suppose you just finished writing @code{zardoz}, a program to make
2375 your head float from vortex to vortex.  You've been using Autoconf to
2376 provide a portability framework, but your @file{Makefile.in}s have been
2377 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
2378
2379 @cindex @code{AM_INIT_AUTOMAKE}, example use
2380
2381 The first step is to update your @file{configure.ac} to include the
2382 commands that @command{automake} needs.  The way to do this is to add an
2383 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
2384
2385 @example
2386 AC_INIT([zardoz], [1.0])
2387 AM_INIT_AUTOMAKE
2388 @dots{}
2389 @end example
2390
2391 Since your program doesn't have any complicating factors (e.g., it
2392 doesn't use @code{gettext}, it doesn't want to build a shared library),
2393 you're done with this part.  That was easy!
2394
2395 @cindex @command{aclocal} program, introduction
2396 @cindex @file{aclocal.m4}, preexisting
2397 @cindex @file{acinclude.m4}, defined
2398
2399 Now you must regenerate @file{configure}.  But to do that, you'll need
2400 to tell @command{autoconf} how to find the new macro you've used.  The
2401 easiest way to do this is to use the @command{aclocal} program to
2402 generate your @file{aclocal.m4} for you.  But wait@dots{} maybe you
2403 already have an @file{aclocal.m4}, because you had to write some hairy
2404 macros for your program.  The @command{aclocal} program lets you put
2405 your own macros into @file{acinclude.m4}, so simply rename and then
2406 run:
2407
2408 @example
2409 mv aclocal.m4 acinclude.m4
2410 aclocal
2411 autoconf
2412 @end example
2413
2414 @cindex @command{zardoz} example
2415
2416 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
2417 Since @code{zardoz} is a user program, you want to install it where the
2418 rest of the user programs go: @code{bindir}.  Additionally,
2419 @code{zardoz} has some Texinfo documentation.  Your @file{configure.ac}
2420 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
2421 @samp{$(LIBOBJS)}.  So here's what you'd write:
2422
2423 @example
2424 bin_PROGRAMS = zardoz
2425 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
2426 zardoz_LDADD = $(LIBOBJS)
2427
2428 info_TEXINFOS = zardoz.texi
2429 @end example
2430
2431 Now you can run @samp{automake --add-missing} to generate your
2432 @file{Makefile.in} and grab any auxiliary files you might need, and
2433 you're done!
2434
2435
2436 @node true
2437 @section Building true and false
2438
2439 @cindex Example, @command{false} and @command{true}
2440 @cindex @command{false} Example
2441 @cindex @command{true} Example
2442
2443 Here is another, trickier example.  It shows how to generate two
2444 programs (@code{true} and @code{false}) from the same source file
2445 (@file{true.c}).  The difficult part is that each compilation of
2446 @file{true.c} requires different @code{cpp} flags.
2447
2448 @example
2449 bin_PROGRAMS = true false
2450 false_SOURCES =
2451 false_LDADD = false.o
2452
2453 true.o: true.c
2454         $(COMPILE) -DEXIT_CODE=0 -c true.c
2455
2456 false.o: true.c
2457         $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
2458 @end example
2459
2460 Note that there is no @code{true_SOURCES} definition.  Automake will
2461 implicitly assume that there is a source file named @file{true.c}
2462 (@pxref{Default _SOURCES}), and
2463 define rules to compile @file{true.o} and link @file{true}.  The
2464 @samp{true.o: true.c} rule supplied by the above @file{Makefile.am},
2465 will override the Automake generated rule to build @file{true.o}.
2466
2467 @code{false_SOURCES} is defined to be empty---that way no implicit value
2468 is substituted.  Because we have not listed the source of
2469 @file{false}, we have to tell Automake how to link the program.  This is
2470 the purpose of the @code{false_LDADD} line.  A @code{false_DEPENDENCIES}
2471 variable, holding the dependencies of the @file{false} target will be
2472 automatically generated by Automake from the content of
2473 @code{false_LDADD}.
2474
2475 The above rules won't work if your compiler doesn't accept both
2476 @option{-c} and @option{-o}.  The simplest fix for this is to introduce a
2477 bogus dependency (to avoid problems with a parallel @command{make}):
2478
2479 @example
2480 true.o: true.c false.o
2481         $(COMPILE) -DEXIT_CODE=0 -c true.c
2482
2483 false.o: true.c
2484         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
2485 @end example
2486
2487 As it turns out, there is also a much easier way to do this same task.
2488 Some of the above technique is useful enough that we've kept the
2489 example in the manual.  However if you were to build @code{true} and
2490 @code{false} in real life, you would probably use per-program
2491 compilation flags, like so:
2492
2493 @c Keep in sync with specflg7.test and specflg8.test.
2494 @example
2495 bin_PROGRAMS = false true
2496
2497 false_SOURCES = true.c
2498 false_CPPFLAGS = -DEXIT_CODE=1
2499
2500 true_SOURCES = true.c
2501 true_CPPFLAGS = -DEXIT_CODE=0
2502 @end example
2503
2504 In this case Automake will cause @file{true.c} to be compiled twice,
2505 with different flags.  In this instance, the names of the object files
2506 would be chosen by automake; they would be @file{false-true.o} and
2507 @file{true-true.o}. (The name of the object files rarely matters.)
2508
2509 @node automake Invocation
2510 @chapter Creating a @file{Makefile.in}
2511 @c This node used to be named "Invoking automake".  This @anchor
2512 @c allows old links to still work.
2513 @anchor{Invoking automake}
2514
2515 @cindex Multiple @file{configure.ac} files
2516 @cindex Invoking @command{automake}
2517 @cindex @command{automake}, invoking
2518 @cindex Invocation of @command{automake}
2519 @cindex @command{automake}, invocation
2520
2521 To create all the @file{Makefile.in}s for a package, run the
2522 @command{automake} program in the top level directory, with no
2523 arguments.  @command{automake} will automatically find each
2524 appropriate @file{Makefile.am} (by scanning @file{configure.ac};
2525 @pxref{configure}) and generate the corresponding @file{Makefile.in}.
2526 Note that @command{automake} has a rather simplistic view of what
2527 constitutes a package; it assumes that a package has only one
2528 @file{configure.ac}, at the top.  If your package has multiple
2529 @file{configure.ac}s, then you must run @command{automake} in each
2530 directory holding a @file{configure.ac}.  (Alternatively, you may rely
2531 on Autoconf's @command{autoreconf}, which is able to recurse your
2532 package tree and run @command{automake} where appropriate.)
2533
2534 You can optionally give @command{automake} an argument; @file{.am} is
2535 appended to the argument and the result is used as the name of the
2536 input file.  This feature is generally only used to automatically
2537 rebuild an out-of-date @file{Makefile.in}.  Note that
2538 @command{automake} must always be run from the topmost directory of a
2539 project, even if being used to regenerate the @file{Makefile.in} in
2540 some subdirectory.  This is necessary because @command{automake} must
2541 scan @file{configure.ac}, and because @command{automake} uses the
2542 knowledge that a @file{Makefile.in} is in a subdirectory to change its
2543 behavior in some cases.
2544
2545 @vindex AUTOCONF
2546 Automake will run @command{autoconf} to scan @file{configure.ac} and
2547 its dependencies (i.e., @file{aclocal.m4} and any included file),
2548 therefore @command{autoconf} must be in your @env{PATH}.  If there is
2549 an @env{AUTOCONF} variable in your environment it will be used
2550 instead of @command{autoconf}, this allows you to select a particular
2551 version of Autoconf.  By the way, don't misunderstand this paragraph:
2552 @command{automake} runs @command{autoconf} to @strong{scan} your
2553 @file{configure.ac}, this won't build @file{configure} and you still
2554 have to run @command{autoconf} yourself for this purpose.
2555
2556 @cindex @command{automake} options
2557 @cindex Options, @command{automake}
2558 @cindex Strictness, command line
2559
2560 @command{automake} accepts the following options:
2561
2562 @cindex Extra files distributed with Automake
2563 @cindex Files distributed with Automake
2564 @cindex @file{config.guess}
2565
2566 @table @code
2567 @item -a
2568 @itemx --add-missing
2569 @opindex -a
2570 @opindex --add-missing
2571 Automake requires certain common files to exist in certain situations;
2572 for instance, @file{config.guess} is required if @file{configure.ac} invokes
2573 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
2574 files (@pxref{Auxiliary Programs}); this option will cause the missing
2575 ones to be automatically added to the package, whenever possible.  In
2576 general if Automake tells you a file is missing, try using this option.
2577 By default Automake tries to make a symbolic link pointing to its own
2578 copy of the missing file; this can be changed with @option{--copy}.
2579
2580 Many of the potentially-missing files are common scripts whose
2581 location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
2582 Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
2583 file is considered missing, and where the missing file is added
2584 (@pxref{Optional}).
2585
2586 In some strictness modes, additional files are installed, see @ref{Gnits}
2587 for more information.
2588
2589 @item --libdir=@var{dir}
2590 @opindex --libdir
2591 Look for Automake data files in directory @var{dir} instead of in the
2592 installation directory.  This is typically used for debugging.
2593
2594 @item -c
2595 @opindex -c
2596 @itemx --copy
2597 @opindex --copy
2598 When used with @option{--add-missing}, causes installed files to be
2599 copied.  The default is to make a symbolic link.
2600
2601 @item --cygnus
2602 @opindex --cygnus
2603 Causes the generated @file{Makefile.in}s to follow Cygnus rules, instead
2604 of GNU or Gnits rules.  For more information, see @ref{Cygnus}.
2605
2606 @item -f
2607 @opindex -f
2608 @itemx --force-missing
2609 @opindex --force-missing
2610 When used with @option{--add-missing}, causes standard files to be reinstalled
2611 even if they already exist in the source tree.  This involves removing
2612 the file from the source tree before creating the new symlink (or, with
2613 @option{--copy}, copying the new file).
2614
2615 @item --foreign
2616 @opindex --foreign
2617 Set the global strictness to @option{foreign}.  For more information, see
2618 @ref{Strictness}.
2619
2620 @item --gnits
2621 @opindex --gnits
2622 Set the global strictness to @option{gnits}.  For more information, see
2623 @ref{Gnits}.
2624
2625 @item --gnu
2626 @opindex --gnu
2627 Set the global strictness to @option{gnu}.  For more information, see
2628 @ref{Gnits}.  This is the default strictness.
2629
2630 @item --help
2631 @opindex --help
2632 Print a summary of the command line options and exit.
2633
2634 @item -i
2635 @itemx --ignore-deps
2636 @opindex -i
2637 This disables the dependency tracking feature in generated
2638 @file{Makefile}s; see @ref{Dependencies}.
2639
2640 @item --include-deps
2641 @opindex --include-deps
2642 This enables the dependency tracking feature.  This feature is enabled
2643 by default.  This option is provided for historical reasons only and
2644 probably should not be used.
2645
2646 @item --no-force
2647 @opindex --no-force
2648 Ordinarily @command{automake} creates all @file{Makefile.in}s mentioned in
2649 @file{configure.ac}.  This option causes it to only update those
2650 @file{Makefile.in}s that are out of date with respect to one of their
2651 dependents.
2652
2653 @item -o @var{dir}
2654 @itemx --output-dir=@var{dir}
2655 @opindex -o
2656 @opindex --output-dir
2657 Put the generated @file{Makefile.in} in the directory @var{dir}.
2658 Ordinarily each @file{Makefile.in} is created in the directory of the
2659 corresponding @file{Makefile.am}.  This option is deprecated and will be
2660 removed in a future release.
2661
2662 @item -v
2663 @itemx --verbose
2664 @opindex -v
2665 @opindex --verbose
2666 Cause Automake to print information about which files are being read or
2667 created.
2668
2669 @item --version
2670 @opindex --version
2671 Print the version number of Automake and exit.
2672
2673 @item -W CATEGORY
2674 @itemx --warnings=@var{category}
2675 @opindex -W
2676 @opindex --warnings
2677 Output warnings falling in @var{category}.  @var{category} can be
2678 one of:
2679 @table @code
2680 @item gnu
2681 warnings related to the GNU Coding Standards
2682 (@pxref{Top, , , standards, The GNU Coding Standards}).
2683 @item obsolete
2684 obsolete features or constructions
2685 @item override
2686 user redefinitions of Automake rules or variables
2687 @item portability
2688 portability issues (e.g., use of @command{make} features that are
2689 known to be not portable)
2690 @item extra-portability
2691 extra portability issues related to obscure tools.  One example of such
2692 a tool is the Microsoft @command{lib} archiver.
2693 @item syntax
2694 weird syntax, unused variables, typos
2695 @item unsupported
2696 unsupported or incomplete features
2697 @item all
2698 all the warnings
2699 @item none
2700 turn off all the warnings
2701 @item error
2702 treat warnings as errors
2703 @end table
2704
2705 A category can be turned off by prefixing its name with @samp{no-}.  For
2706 instance, @option{-Wno-syntax} will hide the warnings about unused
2707 variables.
2708
2709 The categories output by default are @samp{syntax} and
2710 @samp{unsupported}.  Additionally, @samp{gnu} and @samp{portability}
2711 are enabled in @option{--gnu} and @option{--gnits} strictness.
2712 On the other hand, the @option{silent-rules} options (@pxref{Options})
2713 turns off portability warnings about recursive variable expansions.
2714
2715 @c Checked by extra-portability.test
2716 Turning off @samp{portability} will also turn off @samp{extra-portability},
2717 and similarly turning on @samp{extra-portability} will also turn on
2718 @samp{portability}.  However, turning on @samp{portability} or turning
2719 off @samp{extra-portability} will not affect the other category.
2720
2721 @vindex WARNINGS
2722 The environment variable @env{WARNINGS} can contain a comma separated
2723 list of categories to enable.  It will be taken into account before the
2724 command-line switches, this way @option{-Wnone} will also ignore any
2725 warning category enabled by @env{WARNINGS}.  This variable is also used
2726 by other tools like @command{autoconf}; unknown categories are ignored
2727 for this reason.
2728
2729 @end table
2730
2731 @vindex AUTOMAKE_JOBS
2732 If the environment variable @env{AUTOMAKE_JOBS} contains a positive
2733 number, it is taken as the maximum number of Perl threads to use in
2734 @command{automake} for generating multiple @file{Makefile.in} files
2735 concurrently.  This is an experimental feature.
2736
2737
2738 @node configure
2739 @chapter Scanning @file{configure.ac}, using @command{aclocal}
2740
2741 @cindex @file{configure.ac}, scanning
2742 @cindex Scanning @file{configure.ac}
2743 @cindex Using @command{aclocal}
2744 @cindex @command{aclocal}, using
2745
2746 Automake scans the package's @file{configure.ac} to determine certain
2747 information about the package.  Some @command{autoconf} macros are required
2748 and some variables must be defined in @file{configure.ac}.  Automake
2749 will also use information from @file{configure.ac} to further tailor its
2750 output.
2751
2752 Automake also supplies some Autoconf macros to make the maintenance
2753 easier.  These macros can automatically be put into your
2754 @file{aclocal.m4} using the @command{aclocal} program.
2755
2756 @menu
2757 * Requirements::                Configuration requirements
2758 * Optional::                    Other things Automake recognizes
2759 * aclocal Invocation::          Auto-generating aclocal.m4
2760 * Macros::                      Autoconf macros supplied with Automake
2761 @end menu
2762
2763
2764 @node Requirements
2765 @section Configuration requirements
2766
2767 @cindex Automake requirements
2768 @cindex Requirements of Automake
2769
2770 @acindex AM_INIT_AUTOMAKE
2771 The one real requirement of Automake is that your @file{configure.ac}
2772 call @code{AM_INIT_AUTOMAKE}.  This macro does several things that are
2773 required for proper Automake operation (@pxref{Macros}).
2774
2775 Here are the other macros that Automake requires but which are not run
2776 by @code{AM_INIT_AUTOMAKE}:
2777
2778 @table @code
2779 @item AC_CONFIG_FILES
2780 @itemx AC_OUTPUT
2781 @acindex AC_CONFIG_FILES
2782 @acindex AC_OUTPUT
2783 These two macros are usually invoked as follows near the end of
2784 @file{configure.ac}.
2785
2786 @example
2787 @dots{}
2788 AC_CONFIG_FILES([
2789   Makefile
2790   doc/Makefile
2791   src/Makefile
2792   src/lib/Makefile
2793   @dots{}
2794 ])
2795 AC_OUTPUT
2796 @end example
2797
2798 Automake uses these to determine which files to create (@pxref{Output, ,
2799 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
2800 is considered to be an Automake generated @file{Makefile} if there
2801 exists a file with the same name and the @file{.am} extension appended.
2802 Typically, @samp{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
2803 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
2804
2805 When using @code{AC_CONFIG_FILES} with multiple input files, as in
2806
2807 @example
2808 AC_CONFIG_FILES([Makefile:top.in:Makefile.in:bot.in])
2809 @end example
2810
2811 @noindent
2812 @command{automake} will generate the first @file{.in} input file for
2813 which a @file{.am} file exists.  If no such file exists the output
2814 file is not considered to be generated by Automake.
2815
2816 Files created by @code{AC_CONFIG_FILES}, be they Automake
2817 @file{Makefile}s or not, are all removed by @samp{make distclean}.
2818 Their inputs are automatically distributed, unless they
2819 are the output of prior @code{AC_CONFIG_FILES} commands.
2820 Finally, rebuild rules are generated in the Automake @file{Makefile}
2821 existing in the subdirectory of the output file, if there is one, or
2822 in the top-level @file{Makefile} otherwise.
2823
2824 The above machinery (cleaning, distributing, and rebuilding) works
2825 fine if the @code{AC_CONFIG_FILES} specifications contain only
2826 literals.  If part of the specification uses shell variables,
2827 @command{automake} will not be able to fulfill this setup, and you will
2828 have to complete the missing bits by hand.  For instance, on
2829
2830 @c Keep in sync with output11.test.
2831 @example
2832 file=input
2833 @dots{}
2834 AC_CONFIG_FILES([output:$file],, [file=$file])
2835 @end example
2836
2837 @noindent
2838 @command{automake} will output rules to clean @file{output}, and
2839 rebuild it.  However the rebuild rule will not depend on @file{input},
2840 and this file will not be distributed either.  (You must add
2841 @samp{EXTRA_DIST = input} to your @file{Makefile.am} if @file{input} is a
2842 source file.)
2843
2844 Similarly
2845
2846 @c Keep in sync with output11.test.
2847 @example
2848 file=output
2849 file2=out:in
2850 @dots{}
2851 AC_CONFIG_FILES([$file:input],, [file=$file])
2852 AC_CONFIG_FILES([$file2],, [file2=$file2])
2853 @end example
2854
2855 @noindent
2856 will only cause @file{input} to be distributed.  No file will be
2857 cleaned automatically (add @samp{DISTCLEANFILES = output out}
2858 yourself), and no rebuild rule will be output.
2859
2860 Obviously @command{automake} cannot guess what value @samp{$file} is
2861 going to hold later when @file{configure} is run, and it cannot use
2862 the shell variable @samp{$file} in a @file{Makefile}.  However, if you
2863 make reference to @samp{$file} as @samp{$@{file@}} (i.e., in a way
2864 that is compatible with @command{make}'s syntax) and furthermore use
2865 @code{AC_SUBST} to ensure that @samp{$@{file@}} is meaningful in a
2866 @file{Makefile}, then @command{automake} will be able to use
2867 @samp{$@{file@}} to generate all these rules.  For instance, here is
2868 how the Automake package itself generates versioned scripts for its
2869 test suite:
2870
2871 @example
2872 AC_SUBST([APIVERSION], @dots{})
2873 @dots{}
2874 AC_CONFIG_FILES(
2875   [tests/aclocal-$@{APIVERSION@}:tests/aclocal.in],
2876   [chmod +x tests/aclocal-$@{APIVERSION@}],
2877   [APIVERSION=$APIVERSION])
2878 AC_CONFIG_FILES(
2879   [tests/automake-$@{APIVERSION@}:tests/automake.in],
2880   [chmod +x tests/automake-$@{APIVERSION@}])
2881 @end example
2882
2883 @noindent
2884 Here cleaning, distributing, and rebuilding are done automatically,
2885 because @samp{$@{APIVERSION@}} is known at @command{make}-time.
2886
2887 Note that you should not use shell variables to declare
2888 @file{Makefile} files for which @command{automake} must create
2889 @file{Makefile.in}.  Even @code{AC_SUBST} does not help here, because
2890 @command{automake} needs to know the file name when it runs in order
2891 to check whether @file{Makefile.am} exists.  (In the very hairy case
2892 that your setup requires such use of variables, you will have to tell
2893 Automake which @file{Makefile.in}s to generate on the command-line.)
2894
2895 It is possible to let @command{automake} emit conditional rules for
2896 @code{AC_CONFIG_FILES} with the help of @code{AM_COND_IF}
2897 (@pxref{Optional}).
2898
2899 To summarize:
2900 @itemize @bullet
2901 @item
2902 Use literals for @file{Makefile}s, and for other files whenever possible.
2903 @item
2904 Use @samp{$file} (or @samp{$@{file@}} without @samp{AC_SUBST([file])})
2905 for files that @command{automake} should ignore.
2906 @item
2907 Use @samp{$@{file@}} and @samp{AC_SUBST([file])} for files
2908 that @command{automake} should not ignore.
2909 @end itemize
2910
2911 @end table
2912
2913
2914 @node Optional
2915 @section Other things Automake recognizes
2916
2917 @cindex Macros Automake recognizes
2918 @cindex Recognized macros by Automake
2919
2920 Every time Automake is run it calls Autoconf to trace
2921 @file{configure.ac}.  This way it can recognize the use of certain
2922 macros and tailor the generated @file{Makefile.in} appropriately.
2923 Currently recognized macros and their effects are:
2924
2925 @ftable @code
2926 @item AC_CANONICAL_BUILD
2927 @itemx AC_CANONICAL_HOST
2928 @itemx AC_CANONICAL_TARGET
2929 @vindex build_triplet
2930 @vindex host_triplet
2931 @vindex target_triplet
2932 Automake will ensure that @file{config.guess} and @file{config.sub}
2933 exist.  Also, the @file{Makefile} variables @code{build_triplet},
2934 @code{host_triplet} and @code{target_triplet} are introduced.  See
2935 @ref{Canonicalizing, , Getting the Canonical System Type, autoconf,
2936 The Autoconf Manual}.
2937
2938 @item AC_CONFIG_AUX_DIR
2939 Automake will look for various helper scripts, such as
2940 @file{install-sh}, in the directory named in this macro invocation.
2941 @c This list is accurate relative to version 1.8
2942 (The full list of scripts is: @file{ar-lib}, @file{config.guess},
2943 @file{config.sub}, @file{depcomp}, @file{elisp-comp}, @file{compile},
2944 @file{install-sh}, @file{ltmain.sh}, @file{mdate-sh}, @file{missing},
2945 @file{mkinstalldirs}, @file{py-compile}, @file{texinfo.tex}, and
2946 @file{ylwrap}.)  Not all scripts are always searched for; some scripts
2947 will only be sought if the generated @file{Makefile.in} requires them.
2948
2949 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
2950 their standard locations.  For @file{mdate-sh},
2951 @file{texinfo.tex}, and @file{ylwrap}, the standard location is the
2952 source directory corresponding to the current @file{Makefile.am}.  For
2953 the rest, the standard location is the first one of @file{.}, @file{..},
2954 or @file{../..} (relative to the top source directory) that provides any
2955 one of the helper scripts.  @xref{Input, , Finding `configure' Input,
2956 autoconf, The Autoconf Manual}.
2957
2958 Required files from @code{AC_CONFIG_AUX_DIR} are automatically
2959 distributed, even if there is no @file{Makefile.am} in this directory.
2960
2961 @item AC_CONFIG_LIBOBJ_DIR
2962 Automake will require the sources file declared with
2963 @code{AC_LIBSOURCE} (see below) in the directory specified by this
2964 macro.
2965
2966 @item AC_CONFIG_HEADERS
2967 Automake will generate rules to rebuild these headers.  Older versions
2968 of Automake required the use of @code{AM_CONFIG_HEADER}
2969 (@pxref{Macros}); this is no longer the case.
2970
2971 As with @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2972 specification using shell variables will be ignored as far as
2973 cleaning, distributing, and rebuilding is concerned.
2974
2975 @item AC_CONFIG_LINKS
2976 Automake will generate rules to remove @file{configure} generated
2977 links on @samp{make distclean} and to distribute named source files as
2978 part of @samp{make dist}.
2979
2980 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2981 specification using shell variables will be ignored as far as cleaning
2982 and distributing is concerned.  (There are no rebuild rules for links.)
2983
2984 @item AC_LIBOBJ
2985 @itemx AC_LIBSOURCE
2986 @itemx AC_LIBSOURCES
2987 @vindex LIBOBJS
2988 Automake will automatically distribute any file listed in
2989 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
2990
2991 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}.  So if
2992 an Autoconf macro is documented to call @samp{AC_LIBOBJ([file])}, then
2993 @file{file.c} will be distributed automatically by Automake.  This
2994 encompasses many macros like @code{AC_FUNC_ALLOCA},
2995 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
2996
2997 By the way, direct assignments to @code{LIBOBJS} are no longer
2998 supported.  You should always use @code{AC_LIBOBJ} for this purpose.
2999 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
3000 autoconf, The Autoconf Manual}.
3001
3002 @item AC_PROG_RANLIB
3003 This is required if any libraries are built in the package.
3004 @xref{Particular Programs, , Particular Program Checks, autoconf, The
3005 Autoconf Manual}.
3006
3007 @item AC_PROG_CXX
3008 This is required if any C++ source is included.  @xref{Particular
3009 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3010
3011 @item AC_PROG_OBJC
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.  This macro is
3017 distributed with Autoconf version 2.13 and later.  @xref{Particular
3018 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3019
3020 @item AC_F77_LIBRARY_LDFLAGS
3021 This is required for programs and shared libraries that are a mixture of
3022 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
3023 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
3024
3025 @item AC_FC_SRCEXT
3026 Automake will add the flags computed by @code{AC_FC_SRCEXT} to compilation
3027 of files with the respective source extension (@pxref{Fortran Compiler, ,
3028 Fortran Compiler Characteristics, autoconf, The Autoconf Manual}).
3029
3030 @item AC_PROG_FC
3031 This is required if any Fortran 90/95 source is included.  This macro is
3032 distributed with Autoconf version 2.58 and later.  @xref{Particular
3033 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3034
3035 @item AC_PROG_LIBTOOL
3036 Automake will turn on processing for @command{libtool} (@pxref{Top, ,
3037 Introduction, libtool, The Libtool Manual}).
3038
3039 @item AC_PROG_YACC
3040 @vindex YACC
3041 If a Yacc source file is seen, then you must either use this macro or
3042 define the variable @code{YACC} in @file{configure.ac}.  The former is
3043 preferred (@pxref{Particular Programs, , Particular Program Checks,
3044 autoconf, The Autoconf Manual}).
3045
3046 @item AC_PROG_LEX
3047 If a Lex source file is seen, then this macro must be used.
3048 @xref{Particular Programs, , Particular Program Checks, autoconf, The
3049 Autoconf Manual}.
3050
3051 @item AC_REQUIRE_AUX_FILE
3052 For each @code{AC_REQUIRE_AUX_FILE([@var{file}])},
3053 @command{automake} will ensure that @file{@var{file}} exists in the
3054 aux directory, and will complain otherwise.  It
3055 will also automatically distribute the file.  This macro should be
3056 used by third-party Autoconf macros that require some supporting
3057 files in the aux directory specified with @code{AC_CONFIG_AUX_DIR}
3058 above.  @xref{Input, , Finding @command{configure} Input, autoconf,
3059 The Autoconf Manual}.
3060
3061 @item AC_SUBST
3062 The first argument is automatically defined as a variable in each
3063 generated @file{Makefile.in}, unless @code{AM_SUBST_NOTMAKE} is also
3064 used for this variable.  @xref{Setting Output Variables, , Setting
3065 Output Variables, autoconf, The Autoconf Manual}.
3066
3067 For every substituted variable @var{var}, @command{automake} will add
3068 a line @code{@var{var} = @var{value}} to each @file{Makefile.in} file.
3069 Many Autoconf macros invoke @code{AC_SUBST} to set output variables
3070 this way, e.g., @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and
3071 @code{X_LIBS}.  Thus, you can access these variables as
3072 @code{$(X_CFLAGS)} and @code{$(X_LIBS)} in any @file{Makefile.am}
3073 if @code{AC_PATH_XTRA} is called.
3074
3075 @item AM_C_PROTOTYPES
3076 This is required when using the deprecated de-ANSI-fication feature;
3077 @pxref{ANSI}.  @emph{It will be removed} in the next major Automake
3078 release.
3079
3080 @item AM_CONDITIONAL
3081 This introduces an Automake conditional (@pxref{Conditionals}).
3082
3083 @item AM_COND_IF
3084 This macro allows @code{automake} to detect subsequent access within
3085 @file{configure.ac} to a conditional previously introduced with
3086 @code{AM_CONDITIONAL}, thus enabling conditional @code{AC_CONFIG_FILES}
3087 (@pxref{Usage of Conditionals}).
3088
3089 @item AM_GNU_GETTEXT
3090 This macro is required for packages that use GNU gettext
3091 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
3092 this macro it ensures that the package meets some of gettext's
3093 requirements.
3094
3095 @item AM_GNU_GETTEXT_INTL_SUBDIR
3096 This macro specifies that the @file{intl/} subdirectory is to be built,
3097 even if the @code{AM_GNU_GETTEXT} macro was invoked with a first argument
3098 of @samp{external}.
3099
3100 @item AM_MAINTAINER_MODE(@ovar{default-mode})
3101 @opindex --enable-maintainer-mode
3102 @opindex --disable-maintainer-mode
3103 This macro adds an @option{--enable-maintainer-mode} option to
3104 @command{configure}.  If this is used, @command{automake} will cause
3105 ``maintainer-only'' rules to be turned off by default in the
3106 generated @file{Makefile.in}s, unless @var{default-mode} is
3107 @samp{enable}.  This macro defines the @code{MAINTAINER_MODE}
3108 conditional, which you can use in your own @file{Makefile.am}.
3109 @xref{maintainer-mode}.
3110
3111 @item AM_SUBST_NOTMAKE(@var{var})
3112 Prevent Automake from defining a variable @var{var}, even if it is
3113 substituted by @command{config.status}.  Normally, Automake defines a
3114 @command{make} variable for each @command{configure} substitution,
3115 i.e., for each @code{AC_SUBST([@var{var}])}.  This macro prevents that
3116 definition from Automake.  If @code{AC_SUBST} has not been called
3117 for this variable, then @code{AM_SUBST_NOTMAKE} has no effects.
3118 Preventing variable definitions may be useful for substitution of
3119 multi-line values, where @code{@var{var} = @@@var{value}@@} might yield
3120 unintended results.
3121
3122 @item m4_include
3123 Files included by @file{configure.ac} using this macro will be
3124 detected by Automake and automatically distributed.  They will also
3125 appear as dependencies in @file{Makefile} rules.
3126
3127 @code{m4_include} is seldom used by @file{configure.ac} authors, but
3128 can appear in @file{aclocal.m4} when @command{aclocal} detects that
3129 some required macros come from files local to your package (as opposed to
3130 macros installed in a system-wide directory, @pxref{aclocal Invocation}).
3131
3132 @end ftable
3133
3134 @node aclocal Invocation
3135 @section Auto-generating aclocal.m4
3136 @c This node used to be named "Invoking automake".  This @anchor
3137 @c allows old links to still work.
3138 @anchor{Invoking aclocal}
3139
3140 @cindex Invocation of @command{aclocal}
3141 @cindex @command{aclocal}, Invocation
3142 @cindex Invoking @command{aclocal}
3143 @cindex @command{aclocal}, Invoking
3144
3145 Automake includes a number of Autoconf macros that can be used in
3146 your package (@pxref{Macros}); some of them are actually required by
3147 Automake in certain situations.  These macros must be defined in your
3148 @file{aclocal.m4}; otherwise they will not be seen by
3149 @command{autoconf}.
3150
3151 The @command{aclocal} program will automatically generate
3152 @file{aclocal.m4} files based on the contents of @file{configure.ac}.
3153 This provides a convenient way to get Automake-provided macros,
3154 without having to search around.  The @command{aclocal} mechanism
3155 allows other packages to supply their own macros (@pxref{Extending
3156 aclocal}).  You can also use it to maintain your own set of custom
3157 macros (@pxref{Local Macros}).
3158
3159 At startup, @command{aclocal} scans all the @file{.m4} files it can
3160 find, looking for macro definitions (@pxref{Macro Search Path}).  Then
3161 it scans @file{configure.ac}.  Any mention of one of the macros found
3162 in the first step causes that macro, and any macros it in turn
3163 requires, to be put into @file{aclocal.m4}.
3164
3165 @emph{Putting} the file that contains the macro definition into
3166 @file{aclocal.m4} is usually done by copying the entire text of this
3167 file, including unused macro definitions as well as both @samp{#} and
3168 @samp{dnl} comments.  If you want to make a comment that will be
3169 completely ignored by @command{aclocal}, use @samp{##} as the comment
3170 leader.
3171
3172 When a file selected by @command{aclocal} is located in a subdirectory
3173 specified as a relative search path with @command{aclocal}'s @option{-I}
3174 argument, @command{aclocal} assumes the file belongs to the package
3175 and uses @code{m4_include} instead of copying it into
3176 @file{aclocal.m4}.  This makes the package smaller, eases dependency
3177 tracking, and cause the file to be distributed automatically.
3178 (@xref{Local Macros}, for an example.)  Any macro that is found in a
3179 system-wide directory, or via an absolute search path will be copied.
3180 So use @samp{-I `pwd`/reldir} instead of @samp{-I reldir} whenever
3181 some relative directory should be considered outside the package.
3182
3183 The contents of @file{acinclude.m4}, if this file exists, are also
3184 automatically included in @file{aclocal.m4}.  We recommend against
3185 using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
3186
3187 @vindex AUTOM4TE
3188 @cindex autom4te
3189 While computing @file{aclocal.m4}, @command{aclocal} runs
3190 @command{autom4te} (@pxref{Using autom4te, , Using @command{Autom4te},
3191 autoconf, The Autoconf Manual}) in order to trace the macros that are
3192 really used, and omit from @file{aclocal.m4} all macros that are
3193 mentioned but otherwise unexpanded (this can happen when a macro is
3194 called conditionally).  @command{autom4te} is expected to be in the
3195 @env{PATH}, just as @command{autoconf}.  Its location can be
3196 overridden using the @env{AUTOM4TE} environment variable.
3197
3198 @menu
3199 * aclocal Options::             Options supported by aclocal
3200 * Macro Search Path::           How aclocal finds .m4 files
3201 * Extending aclocal::           Writing your own aclocal macros
3202 * Local Macros::                Organizing local macros
3203 * Serials::                     Serial lines in Autoconf macros
3204 * Future of aclocal::           aclocal's scheduled death
3205 @end menu
3206
3207 @node aclocal Options
3208 @subsection aclocal Options
3209
3210 @cindex @command{aclocal}, Options
3211 @cindex Options, @command{aclocal}
3212
3213 @command{aclocal} accepts the following options:
3214
3215 @table @code
3216 @item --automake-acdir=@var{dir}
3217 @opindex --automake-acdir
3218 Look for the automake-provided macro files in @var{dir} instead of
3219 in the installation directory.  This is typically used for debugging.
3220
3221 @item --system-acdir=@var{dir}
3222 @opindex --system-acdir
3223 Look for the system-wide third-party macro files (and the special
3224 @file{dirlist} file) in @var{dir} instead of in the installation
3225 directory.  This is typically used for debugging.
3226
3227 @item --acdir=@var{dir}
3228 @opindex --acdir
3229 @emph{Deprecated} shorthand for ``@option{--automake-acdir=@var{dir}
3230 --system-acdir=@var{dir}}''.  Will be removed in future aclocal versions.
3231
3232 @item --diff[=@var{command}]
3233 @opindex --diff
3234 Run @var{command} on M4 file that would be installed or overwritten
3235 by @option{--install}.  The default @var{command} is @samp{diff -u}.
3236 This option implies @option{--install} and @option{--dry-run}.
3237
3238 @item --dry-run
3239 @opindex --dry-run
3240 Do not actually overwrite (or create) @file{aclocal.m4} and M4
3241 files installed by @option{--install}.
3242
3243 @item --help
3244 @opindex --help
3245 Print a summary of the command line options and exit.
3246
3247 @item -I @var{dir}
3248 @opindex -I
3249 Add the directory @var{dir} to the list of directories searched for
3250 @file{.m4} files.
3251
3252 @item --install
3253 @opindex --install
3254 Install system-wide third-party macros into the first directory
3255 specified with @samp{-I @var{dir}} instead of copying them in the
3256 output file.
3257 @c The following semantics is checked by `aclocal-install-absdir.test'.
3258 Note that this will happen also if @var{dir} is an absolute path.
3259
3260 @cindex serial number and @option{--install}
3261 When this option is used, and only when this option is used,
3262 @command{aclocal} will also honor @samp{#serial @var{number}} lines
3263 that appear in macros: an M4 file is ignored if there exists another
3264 M4 file with the same basename and a greater serial number in the
3265 search path (@pxref{Serials}).
3266
3267 @item --force
3268 @opindex --force
3269 Always overwrite the output file.  The default is to overwrite the output
3270 file only when really needed, i.e., when its contents changes or if one
3271 of its dependencies is younger.
3272
3273 This option forces the update of @file{aclocal.m4} (or the file
3274 specified with @file{--output} below) and only this file, it has
3275 absolutely no influence on files that may need to be installed by
3276 @option{--install}.
3277
3278 @item --output=@var{file}
3279 @opindex --output
3280 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
3281
3282 @item --print-ac-dir
3283 @opindex --print-ac-dir
3284 Prints the name of the directory that @command{aclocal} will search to
3285 find third-party @file{.m4} files.  When this option is given, normal
3286 processing is suppressed.  This option was used @emph{in the past} by
3287 third-party packages to determine where to install @file{.m4} macro
3288 files, but @emph{this usage is today discouraged}, since it causes
3289 @samp{$(prefix)} not to be thoroughly honoured (which violates the
3290 GNU Coding Standards), and a similar semantics can be better obtained
3291 with the @env{ACLOCAL_PATH} environment variable; @pxref{Extending aclocal}.
3292
3293 @item --verbose
3294 @opindex --verbose
3295 Print the names of the files it examines.
3296
3297 @item --version
3298 @opindex --version
3299 Print the version number of Automake and exit.
3300
3301 @item -W CATEGORY
3302 @item --warnings=@var{category}
3303 @opindex -W
3304 @opindex --warnings
3305 Output warnings falling in @var{category}.  @var{category} can be
3306 one of:
3307 @table @code
3308 @item syntax
3309 dubious syntactic constructs, underquoted macros, unused macros, etc.
3310 @item unsupported
3311 unknown macros
3312 @item all
3313 all the warnings, this is the default
3314 @item none
3315 turn off all the warnings
3316 @item error
3317 treat warnings as errors
3318 @end table
3319
3320 All warnings are output by default.
3321
3322 @vindex WARNINGS
3323 The environment variable @env{WARNINGS} is honored in the same
3324 way as it is for @command{automake} (@pxref{automake Invocation}).
3325
3326 @end table
3327
3328 @node Macro Search Path
3329 @subsection Macro Search Path
3330
3331 @cindex Macro search path
3332 @cindex @command{aclocal} search path
3333
3334 By default, @command{aclocal} searches for @file{.m4} files in the following
3335 directories, in this order:
3336
3337 @table @code
3338 @item @var{acdir-APIVERSION}
3339 This is where the @file{.m4} macros distributed with Automake itself
3340 are stored.  @var{APIVERSION} depends on the Automake release used;
3341 for example, for Automake 1.11.x, @var{APIVERSION} = @code{1.11}.
3342
3343 @item @var{acdir}
3344 This directory is intended for third party @file{.m4} files, and is
3345 configured when @command{automake} itself is built.  This is
3346 @file{@@datadir@@/aclocal/}, which typically
3347 expands to @file{$@{prefix@}/share/aclocal/}.  To find the compiled-in
3348 value of @var{acdir}, use the @option{--print-ac-dir} option
3349 (@pxref{aclocal Options}).
3350 @end table
3351
3352 As an example, suppose that @command{automake-1.11.2} was configured with
3353 @option{--prefix=@-/usr/local}.  Then, the search path would be:
3354
3355 @enumerate
3356 @item @file{/usr/local/share/aclocal-1.11.2/}
3357 @item @file{/usr/local/share/aclocal/}
3358 @end enumerate
3359
3360 The paths for the @var{acdir} and @var{acdir-APIVERSION} directories can
3361 be changed respectively through aclocal options @option{--system-acdir}
3362 and @option{--automake-acdir} (@pxref{aclocal Options}).  Note however
3363 that these options are only intended for use by the internal Automake
3364 test suite, or for debugging under highly unusual situations; they are
3365 not ordinarily needed by end-users.
3366
3367 As explained in (@pxref{aclocal Options}), there are several options that
3368 can be used to change or extend this search path.
3369
3370 @subsubheading Modifying the Macro Search Path: @samp{-I @var{dir}}
3371
3372 Any extra directories specified using @option{-I} options
3373 (@pxref{aclocal Options}) are @emph{prepended} to this search list.  Thus,
3374 @samp{aclocal -I /foo -I /bar} results in the following search path:
3375
3376 @enumerate
3377 @item @file{/foo}
3378 @item @file{/bar}
3379 @item @var{acdir}-@var{APIVERSION}
3380 @item @var{acdir}
3381 @end enumerate
3382
3383 @subsubheading Modifying the Macro Search Path: @file{dirlist}
3384 @cindex @file{dirlist}
3385
3386 There is a third mechanism for customizing the search path.  If a
3387 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
3388 contain a list of directory patterns, one per line.  @command{aclocal}
3389 expands these patterns to directory names, and adds them to the search
3390 list @emph{after} all other directories.  @file{dirlist} entries may
3391 use shell wildcards such as @samp{*}, @samp{?}, or @code{[...]}.
3392
3393 For example, suppose
3394 @file{@var{acdir}/dirlist} contains the following:
3395
3396 @example
3397 /test1
3398 /test2
3399 /test3*
3400 @end example
3401
3402 @noindent
3403 and that @command{aclocal} was called with the @samp{-I /foo -I /bar} options.
3404 Then, the search path would be
3405
3406 @c @code looks better than @file here
3407 @enumerate
3408 @item @code{/foo}
3409 @item @code{/bar}
3410 @item @var{acdir}-@var{APIVERSION}
3411 @item @var{acdir}
3412 @item @code{/test1}
3413 @item @code{/test2}
3414 @end enumerate
3415
3416 @noindent
3417 and all directories with path names starting with @code{/test3}.
3418
3419 If the @option{--system-acdir=@var{dir}} option is used, then
3420 @command{aclocal} will search for the @file{dirlist} file in
3421 @var{dir}; but remember the warnings  above against the use of
3422 @option{--system-acdir}.
3423
3424 @file{dirlist} is useful in the following situation: suppose that
3425 @command{automake} version @code{1.11.2} is installed with
3426 @samp{--prefix=/usr} by the system vendor.  Thus, the default search
3427 directories are
3428
3429 @c @code looks better than @file here
3430 @enumerate
3431 @item @code{/usr/share/aclocal-1.11/}
3432 @item @code{/usr/share/aclocal/}
3433 @end enumerate
3434
3435 However, suppose further that many packages have been manually
3436 installed on the system, with $prefix=/usr/local, as is typical.  In
3437 that case, many of these ``extra'' @file{.m4} files are in
3438 @file{/usr/local/share/aclocal}.  The only way to force
3439 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files is to
3440 always call @samp{aclocal -I /usr/local/share/aclocal}.  This is
3441 inconvenient.  With @file{dirlist}, one may create a file
3442 @file{/usr/share/aclocal/dirlist} containing only the single line
3443
3444 @example
3445 /usr/local/share/aclocal
3446 @end example
3447
3448 Now, the ``default'' search path on the affected system is
3449
3450 @c @code looks better than @file here
3451 @enumerate
3452 @item @code{/usr/share/aclocal-1.11/}
3453 @item @code{/usr/share/aclocal/}
3454 @item @code{/usr/local/share/aclocal/}
3455 @end enumerate
3456
3457 without the need for @option{-I} options; @option{-I} options can be reserved
3458 for project-specific needs (@file{my-source-dir/m4/}), rather than
3459 using it to work around local system-dependent tool installation
3460 directories.
3461
3462 Similarly, @file{dirlist} can be handy if you have installed a local
3463 copy of Automake in your account and want @command{aclocal} to look for
3464 macros installed at other places on the system.
3465
3466 @anchor{ACLOCAL_PATH}
3467 @subsubheading Modifying the Macro Search Path: @file{ACLOCAL_PATH}
3468 @cindex @env{ACLOCAL_PATH}
3469
3470 The fourth and last mechanism to customize the macro search path is
3471 also the simplest.  Any directory included in the colon-separated
3472 environment variable @env{ACLOCAL_PATH} is added to the search path
3473 @c Keep in sync with aclocal-path-precedence.test.
3474 and takes precedence over system directories (including those found via
3475 @file{dirlist}), with the exception of the versioned directory
3476 @var{acdir-APIVERSION} (@pxref{Macro Search Path}).  However, directories
3477 passed via @option{-I} will take precedence over directories in
3478 @env{ACLOCAL_PATH}.
3479
3480 @c Keep in sync with aclocal-path-installed.test.
3481 Also note that, if the @option{--install} option is used, any @file{.m4}
3482 file containing a required macro that is found in a directory listed in
3483 @env{ACLOCAL_PATH} will be installed locally.
3484 @c Keep in sync with aclocal-path-installed-serial.test.
3485 In this case, serial numbers in @file{.m4} are honoured too,
3486 @pxref{Serials}.
3487
3488 Conversely to @file{dirlist}, @env{ACLOCAL_PATH} is useful if you are
3489 using a global copy of Automake and want @command{aclocal} to look for
3490 macros somewhere under your home directory.
3491
3492 @subsubheading Planned future incompatibilities
3493
3494 The order in which the directories in the macro search path are currently
3495 looked up is confusing and/or suboptimal in various aspects, and is
3496 probably going to be changed in the future Automake release.  In
3497 particular, directories in @env{ACLOCAL_PATH} and @file{@var{acdir}}
3498 might end up taking precedence over @file{@var{acdir-APIVERSION}}, and
3499 directories in @file{@var{acdir}/dirlist} might end up taking precedence
3500 over @file{@var{acdir}}.  @emph{This is a possible future incompatibility!}
3501
3502 @node Extending aclocal
3503 @subsection Writing your own aclocal macros
3504
3505 @cindex @command{aclocal}, extending
3506 @cindex Extending @command{aclocal}
3507
3508 The @command{aclocal} program doesn't have any built-in knowledge of any
3509 macros, so it is easy to extend it with your own macros.
3510
3511 This can be used by libraries that want to supply their own Autoconf
3512 macros for use by other programs.  For instance, the @command{gettext}
3513 library supplies a macro @code{AM_GNU_GETTEXT} that should be used by
3514 any package using @command{gettext}.  When the library is installed, it
3515 installs this macro so that @command{aclocal} will find it.
3516
3517 A macro file's name should end in @file{.m4}.  Such files should be
3518 installed in @file{$(datadir)/aclocal}.  This is as simple as writing:
3519
3520 @c Keep in sync with primary-prefix-couples-documented-valid.test.
3521 @example
3522 aclocaldir = $(datadir)/aclocal
3523 aclocal_DATA = mymacro.m4 myothermacro.m4
3524 @end example
3525
3526 @noindent
3527 Please do use @file{$(datadir)/aclocal}, and not something based on
3528 the result of @samp{aclocal --print-ac-dir} (@pxref{Hard-Coded Install
3529 Paths}, for arguments).  It might also be helpful to suggest to
3530 the user to add the @file{$(datadir)/aclocal} directory to his
3531 @env{ACLOCAL_PATH} variable (@pxref{ACLOCAL_PATH}) so that
3532 @command{aclocal} will find the @file{.m4} files installed by your
3533 package automatically.
3534
3535 A file of macros should be a series of properly quoted
3536 @code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
3537 Autoconf Manual}).  The @command{aclocal} programs also understands
3538 @code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
3539 Autoconf Manual}), so it is safe to put each macro in a separate file.
3540 Each file should have no side effects but macro definitions.
3541 Especially, any call to @code{AC_PREREQ} should be done inside the
3542 defined macro, not at the beginning of the file.
3543
3544 @cindex underquoted @code{AC_DEFUN}
3545 @acindex AC_DEFUN
3546 @acindex AC_PREREQ
3547
3548 Starting with Automake 1.8, @command{aclocal} will warn about all
3549 underquoted calls to @code{AC_DEFUN}.  We realize this will annoy a
3550 lot of people, because @command{aclocal} was not so strict in the past
3551 and many third party macros are underquoted; and we have to apologize
3552 for this temporary inconvenience.  The reason we have to be stricter
3553 is that a future implementation of @command{aclocal} (@pxref{Future of
3554 aclocal}) will have to temporarily include all these third party
3555 @file{.m4} files, maybe several times, including even files that are
3556 not actually needed.  Doing so should alleviate many problems of the
3557 current implementation, however it requires a stricter style from the
3558 macro authors.  Hopefully it is easy to revise the existing macros.
3559 For instance,
3560
3561 @example
3562 # bad style
3563 AC_PREREQ(2.57)
3564 AC_DEFUN(AX_FOOBAR,
3565 [AC_REQUIRE([AX_SOMETHING])dnl
3566 AX_FOO
3567 AX_BAR
3568 ])
3569 @end example
3570
3571 @noindent
3572 should be rewritten as
3573
3574 @example
3575 AC_DEFUN([AX_FOOBAR],
3576 [AC_PREREQ([2.57])dnl
3577 AC_REQUIRE([AX_SOMETHING])dnl
3578 AX_FOO
3579 AX_BAR
3580 ])
3581 @end example
3582
3583 Wrapping the @code{AC_PREREQ} call inside the macro ensures that
3584 Autoconf 2.57 will not be required if @code{AX_FOOBAR} is not actually
3585 used.  Most importantly, quoting the first argument of @code{AC_DEFUN}
3586 allows the macro to be redefined or included twice (otherwise this
3587 first argument would be expanded during the second definition).  For
3588 consistency we like to quote even arguments such as @code{2.57} that
3589 do not require it.
3590
3591 If you have been directed here by the @command{aclocal} diagnostic but
3592 are not the maintainer of the implicated macro, you will want to
3593 contact the maintainer of that macro.  Please make sure you have the
3594 latest version of the macro and that the problem hasn't already been
3595 reported before doing so: people tend to work faster when they aren't
3596 flooded by mails.
3597
3598 Another situation where @command{aclocal} is commonly used is to
3599 manage macros that are used locally by the package, @ref{Local
3600 Macros}.
3601
3602 @node Local Macros
3603 @subsection Handling Local Macros
3604
3605 Feature tests offered by Autoconf do not cover all needs.  People
3606 often have to supplement existing tests with their own macros, or
3607 with third-party macros.
3608
3609 There are two ways to organize custom macros in a package.
3610
3611 The first possibility (the historical practice) is to list all your
3612 macros in @file{acinclude.m4}.  This file will be included in
3613 @file{aclocal.m4} when you run @command{aclocal}, and its macro(s) will
3614 henceforth be visible to @command{autoconf}.  However if it contains
3615 numerous macros, it will rapidly become difficult to maintain, and it
3616 will be almost impossible to share macros between packages.
3617
3618 @vindex ACLOCAL_AMFLAGS
3619 The second possibility, which we do recommend, is to write each macro
3620 in its own file and gather all these files in a directory.  This
3621 directory is usually called @file{m4/}.  To build @file{aclocal.m4},
3622 one should therefore instruct @command{aclocal} to scan @file{m4/}.
3623 From the command line, this is done with @samp{aclocal -I m4}.  The
3624 top-level @file{Makefile.am} should also be updated to define
3625
3626 @example
3627 ACLOCAL_AMFLAGS = -I m4
3628 @end example
3629
3630 @code{ACLOCAL_AMFLAGS} contains options to pass to @command{aclocal}
3631 when @file{aclocal.m4} is to be rebuilt by @command{make}.  This line is
3632 also used by @command{autoreconf} (@pxref{autoreconf Invocation, ,
3633 Using @command{autoreconf} to Update @file{configure} Scripts,
3634 autoconf, The Autoconf Manual}) to run @command{aclocal} with suitable
3635 options, or by @command{autopoint} (@pxref{autopoint Invocation, ,
3636 Invoking the @command{autopoint} Program, gettext, GNU gettext tools})
3637 and @command{gettextize} (@pxref{gettextize Invocation, , Invoking the
3638 @command{gettextize} Program, gettext, GNU gettext tools}) to locate
3639 the place where Gettext's macros should be installed.  So even if you
3640 do not really care about the rebuild rules, you should define
3641 @code{ACLOCAL_AMFLAGS}.
3642
3643 When @samp{aclocal -I m4} is run, it will build an @file{aclocal.m4}
3644 that @code{m4_include}s any file from @file{m4/} that defines a
3645 required macro.  Macros not found locally will still be searched in
3646 system-wide directories, as explained in @ref{Macro Search Path}.
3647
3648 Custom macros should be distributed for the same reason that
3649 @file{configure.ac} is: so that other people have all the sources of
3650 your package if they want to work on it.  Actually, this distribution
3651 happens automatically because all @code{m4_include}d files are
3652 distributed.
3653
3654 However there is no consensus on the distribution of third-party
3655 macros that your package may use.  Many libraries install their own
3656 macro in the system-wide @command{aclocal} directory (@pxref{Extending
3657 aclocal}).  For instance, Guile ships with a file called
3658 @file{guile.m4} that contains the macro @code{GUILE_FLAGS} that can
3659 be used to define setup compiler and linker flags appropriate for
3660 using Guile.  Using @code{GUILE_FLAGS} in @file{configure.ac} will
3661 cause @command{aclocal} to copy @file{guile.m4} into
3662 @file{aclocal.m4}, but as @file{guile.m4} is not part of the project,
3663 it will not be distributed.  Technically, that means a user who
3664 needs to rebuild @file{aclocal.m4} will have to install Guile first.
3665 This is probably OK, if Guile already is a requirement to build the
3666 package.  However, if Guile is only an optional feature, or if your
3667 package might run on architectures where Guile cannot be installed,
3668 this requirement will hinder development.  An easy solution is to copy
3669 such third-party macros in your local @file{m4/} directory so they get
3670 distributed.
3671
3672 Since Automake 1.10, @command{aclocal} offers an option to copy these
3673 system-wide third-party macros in your local macro directory, solving
3674 the above problem.  Simply use:
3675
3676 @example
3677 ACLOCAL_AMFLAGS = -I m4 --install
3678 @end example
3679
3680 @noindent
3681 With this setup, system-wide macros will be copied to @file{m4/}
3682 the first time you run @command{autoreconf}.  Then the locally
3683 installed macros will have precedence over the system-wide installed
3684 macros each time @command{aclocal} is run again.
3685
3686 One reason why you should keep @option{--install} in the flags even
3687 after the first run is that when you later edit @file{configure.ac}
3688 and depend on a new macro, this macro will be installed in your
3689 @file{m4/} automatically.  Another one is that serial numbers
3690 (@pxref{Serials}) can be used to update the macros in your source tree
3691 automatically when new system-wide versions are installed.  A serial
3692 number should be a single line of the form
3693
3694 @example
3695 #serial @var{nnn}
3696 @end example
3697
3698 @noindent
3699 where @var{nnn} contains only digits and dots.  It should appear in
3700 the M4 file before any macro definition.  It is a good practice to
3701 maintain a serial number for each macro you distribute, even if you do
3702 not use the @option{--install} option of @command{aclocal}: this allows
3703 other people to use it.
3704
3705
3706 @node Serials
3707 @subsection Serial Numbers
3708 @cindex serial numbers in macros
3709 @cindex macro serial numbers
3710 @cindex @code{#serial} syntax
3711 @cindex @command{aclocal} and serial numbers
3712
3713 Because third-party macros defined in @file{*.m4} files are naturally
3714 shared between multiple projects, some people like to version them.
3715 This makes it easier to tell which of two M4 files is newer.  Since at
3716 least 1996, the tradition is to use a @samp{#serial} line for this.
3717
3718 A serial number should be a single line of the form
3719
3720 @example
3721 # serial @var{version}
3722 @end example
3723
3724 @noindent
3725 where @var{version} is a version number containing only digits and
3726 dots.  Usually people use a single integer, and they increment it each
3727 time they change the macro (hence the name of ``serial'').  Such a
3728 line should appear in the M4 file before any macro definition.
3729
3730 The @samp{#} must be the first character on the line,
3731 and it is OK to have extra words after the version, as in
3732
3733 @example
3734 #serial @var{version} @var{garbage}
3735 @end example
3736
3737 Normally these serial numbers are completely ignored by
3738 @command{aclocal} and @command{autoconf}, like any genuine comment.
3739 However when using @command{aclocal}'s @option{--install} feature, these
3740 serial numbers will modify the way @command{aclocal} selects the
3741 macros to install in the package: if two files with the same basename
3742 exist in your search path, and if at least one of them uses a
3743 @samp{#serial} line, @command{aclocal} will ignore the file that has
3744 the older @samp{#serial} line (or the file that has none).
3745
3746 Note that a serial number applies to a whole M4 file, not to any macro
3747 it contains.  A file can contains multiple macros, but only one
3748 serial.
3749
3750 Here is a use case that illustrates the use of @option{--install} and
3751 its interaction with serial numbers.  Let's assume we maintain a
3752 package called MyPackage, the @file{configure.ac} of which requires a
3753 third-party macro @code{AX_THIRD_PARTY} defined in
3754 @file{/usr/share/aclocal/thirdparty.m4} as follows:
3755
3756 @example
3757 # serial 1
3758 AC_DEFUN([AX_THIRD_PARTY], [...])
3759 @end example
3760
3761 MyPackage uses an @file{m4/} directory to store local macros as
3762 explained in @ref{Local Macros}, and has
3763
3764 @example
3765 ACLOCAL_AMFLAGS = -I m4 --install
3766 @end example
3767
3768 @noindent
3769 in its top-level @file{Makefile.am}.
3770
3771 Initially the @file{m4/} directory is empty.  The first time we run
3772 @command{autoreconf}, it will fetch the options to pass to
3773 @command{aclocal} in @file{Makefile.am}, and run @samp{aclocal -I m4
3774 --install}.  @command{aclocal} will notice that
3775
3776 @itemize @bullet
3777 @item
3778 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3779 @item
3780 No local macros define @code{AX_THIRD_PARTY}
3781 @item
3782 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3783 with serial 1.
3784 @end itemize
3785
3786 @noindent
3787 Because @file{/usr/share/aclocal/thirdparty.m4} is a system-wide macro
3788 and @command{aclocal} was given the @option{--install} option, it will
3789 copy this file in @file{m4/thirdparty.m4}, and output an
3790 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3791
3792 The next time @samp{aclocal -I m4 --install} is run (either via
3793 @command{autoreconf}, by hand, or from the @file{Makefile} rebuild
3794 rules) something different happens.  @command{aclocal} notices that
3795
3796 @itemize @bullet
3797 @item
3798 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3799 @item
3800 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3801 with serial 1.
3802 @item
3803 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3804 with serial 1.
3805 @end itemize
3806
3807 @noindent
3808 Because both files have the same serial number, @command{aclocal} uses
3809 the first it found in its search path order (@pxref{Macro Search
3810 Path}).  @command{aclocal} therefore ignores
3811 @file{/usr/share/aclocal/thirdparty.m4} and outputs an
3812 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3813
3814 Local directories specified with @option{-I} are always searched before
3815 system-wide directories, so a local file will always be preferred to
3816 the system-wide file in case of equal serial numbers.
3817
3818 Now suppose the system-wide third-party macro is changed.  This can
3819 happen if the package installing this macro is updated.  Let's suppose
3820 the new macro has serial number 2.  The next time @samp{aclocal -I m4
3821 --install} is run the situation is the following:
3822
3823 @itemize @bullet
3824 @item
3825 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3826 @item
3827 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3828 with serial 1.
3829 @item
3830 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3831 with serial 2.
3832 @end itemize
3833
3834 @noindent
3835 When @command{aclocal} sees a greater serial number, it immediately
3836 forgets anything it knows from files that have the same basename and a
3837 smaller serial number.  So after it has found
3838 @file{/usr/share/aclocal/thirdparty.m4} with serial 2,
3839 @command{aclocal} will proceed as if it had never seen
3840 @file{m4/thirdparty.m4}.  This brings us back to a situation similar
3841 to that at the beginning of our example, where no local file defined
3842 the macro.  @command{aclocal} will install the new version of the
3843 macro in @file{m4/thirdparty.m4}, in this case overriding the old
3844 version.  MyPackage just had its macro updated as a side effect of
3845 running @command{aclocal}.
3846
3847 If you are leery of letting @command{aclocal} update your local macro,
3848 you can run @samp{aclocal -I m4 --diff} to review the changes
3849 @samp{aclocal -I m4 --install} would perform on these macros.
3850
3851 Finally, note that the @option{--force} option of @command{aclocal} has
3852 absolutely no effect on the files installed by @option{--install}.  For
3853 instance, if you have modified your local macros, do not expect
3854 @option{--install --force} to replace the local macros by their
3855 system-wide versions.  If you want to do so, simply erase the local
3856 macros you want to revert, and run @samp{aclocal -I m4 --install}.
3857
3858
3859 @node Future of aclocal
3860 @subsection The Future of @command{aclocal}
3861 @cindex @command{aclocal}'s scheduled death
3862
3863 @command{aclocal} is expected to disappear.  This feature really
3864 should not be offered by Automake.  Automake should focus on
3865 generating @file{Makefile}s; dealing with M4 macros really is
3866 Autoconf's job.  The fact that some people install Automake just to use
3867 @command{aclocal}, but do not use @command{automake} otherwise is an
3868 indication of how that feature is misplaced.
3869
3870 The new implementation will probably be done slightly differently.
3871 For instance, it could enforce the @file{m4/}-style layout discussed in
3872 @ref{Local Macros}.
3873
3874 We have no idea when and how this will happen.  This has been
3875 discussed several times in the past, but someone still has to commit
3876 to that non-trivial task.
3877
3878 From the user point of view, @command{aclocal}'s removal might turn
3879 out to be painful.  There is a simple precaution that you may take to
3880 make that switch more seamless: never call @command{aclocal} yourself.
3881 Keep this guy under the exclusive control of @command{autoreconf} and
3882 Automake's rebuild rules.  Hopefully you won't need to worry about
3883 things breaking, when @command{aclocal} disappears, because everything
3884 will have been taken care of.  If otherwise you used to call
3885 @command{aclocal} directly yourself or from some script, you will
3886 quickly notice the change.
3887
3888 Many packages come with a script called @file{bootstrap.sh} or
3889 @file{autogen.sh}, that will just call @command{aclocal},
3890 @command{libtoolize}, @command{gettextize} or @command{autopoint},
3891 @command{autoconf}, @command{autoheader}, and @command{automake} in
3892 the right order.  Actually this is precisely what @command{autoreconf}
3893 can do for you.  If your package has such a @file{bootstrap.sh} or
3894 @file{autogen.sh} script, consider using @command{autoreconf}.  That
3895 should simplify its logic a lot (less things to maintain, yum!), it's
3896 even likely you will not need the script anymore, and more to the point
3897 you will not call @command{aclocal} directly anymore.
3898
3899 For the time being, third-party packages should continue to install
3900 public macros into @file{/usr/share/aclocal/}.  If @command{aclocal}
3901 is replaced by another tool it might make sense to rename the
3902 directory, but supporting @file{/usr/share/aclocal/} for backward
3903 compatibility should be really easy provided all macros are properly
3904 written (@pxref{Extending aclocal}).
3905
3906
3907
3908 @node Macros
3909 @section Autoconf macros supplied with Automake
3910
3911 Automake ships with several Autoconf macros that you can use from your
3912 @file{configure.ac}.  When you use one of them it will be included by
3913 @command{aclocal} in @file{aclocal.m4}.
3914
3915 @menu
3916 * Public Macros::               Macros that you can use.
3917 * Obsolete Macros::             Macros that you should stop using.
3918 * Private Macros::              Macros that you should not use.
3919 @end menu
3920
3921 @c consider generating the following subsections automatically from m4 files.
3922
3923 @node Public Macros
3924 @subsection Public Macros
3925
3926 @table @code
3927
3928 @item AM_ENABLE_MULTILIB
3929 @acindex AM_ENABLE_MULTILIB
3930
3931 This is used when a ``multilib'' library is being built.  Please be
3932 aware that multilib support @emph{will be removed} from the Automake
3933 core in the next major release, and then @emph{this macro will go away
3934 as well} (even if a ``frozen'' version of will remain available in the
3935 @file{contrib/} directory of the Automake distribution).
3936
3937 The first optional argument is the name of the @file{Makefile} being
3938 generated; it defaults to @samp{Makefile}.  The second optional argument
3939 is used to find the top source directory; it defaults to the empty
3940 string (generally this should not be used unless you are familiar with
3941 the internals).  @xref{Multilibs}.
3942
3943 @item AM_INIT_AUTOMAKE([OPTIONS])
3944 @itemx AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
3945 @acindex AM_INIT_AUTOMAKE
3946 Runs many macros required for proper operation of the generated Makefiles.
3947
3948 @vindex AUTOMAKE_OPTIONS
3949 This macro has two forms, the first of which is preferred.
3950 In this form, @code{AM_INIT_AUTOMAKE} is called with a
3951 single argument: a space-separated list of Automake options that should
3952 be applied to every @file{Makefile.am} in the tree.  The effect is as if
3953 each option were listed in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
3954
3955 @acindex AC_INIT
3956 The second, deprecated, form of @code{AM_INIT_AUTOMAKE} has two required
3957 arguments: the package and the version number.  This form is
3958 obsolete because the @var{package} and @var{version} can be obtained
3959 from Autoconf's @code{AC_INIT} macro (which itself has an old and a new
3960 form).
3961
3962 If your @file{configure.ac} has:
3963
3964 @example
3965 AC_INIT([src/foo.c])
3966 AM_INIT_AUTOMAKE([mumble], [1.5])
3967 @end example
3968
3969 @noindent
3970 you can modernize it as follows:
3971
3972 @example
3973 AC_INIT([mumble], [1.5])
3974 AC_CONFIG_SRCDIR([src/foo.c])
3975 AM_INIT_AUTOMAKE
3976 @end example
3977
3978 Note that if you're upgrading your @file{configure.ac} from an earlier
3979 version of Automake, it is not always correct to simply move the
3980 package and version arguments from @code{AM_INIT_AUTOMAKE} directly to
3981 @code{AC_INIT}, as in the example above.  The first argument to
3982 @code{AC_INIT} should be the name of your package (e.g., @samp{GNU
3983 Automake}), not the tarball name (e.g., @samp{automake}) that you used
3984 to pass to @code{AM_INIT_AUTOMAKE}.  Autoconf tries to derive a
3985 tarball name from the package name, which should work for most but not
3986 all package names.  (If it doesn't work for yours, you can use the
3987 four-argument form of @code{AC_INIT} to provide the tarball name
3988 explicitly).
3989
3990 @cindex @code{PACKAGE}, prevent definition
3991 @cindex @code{VERSION}, prevent definition
3992 @opindex no-define
3993 By default this macro @code{AC_DEFINE}'s @code{PACKAGE} and
3994 @code{VERSION}.  This can be avoided by passing the @option{no-define}
3995 option, as in:
3996 @example
3997 AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
3998 @end example
3999 or by passing a third non-empty argument to the obsolete form.
4000
4001 @item AM_PATH_LISPDIR
4002 @acindex AM_PATH_LISPDIR
4003 @vindex EMACS
4004 @vindex lispdir
4005 Searches for the program @command{emacs}, and, if found, sets the
4006 output variable @code{lispdir} to the full path to Emacs' site-lisp
4007 directory.
4008
4009 Note that this test assumes the @command{emacs} found to be a version
4010 that supports Emacs Lisp (such as GNU Emacs or XEmacs).  Other
4011 emacsen can cause this test to hang (some, like old versions of
4012 MicroEmacs, start up in interactive mode, requiring @kbd{C-x C-c} to
4013 exit, which is hardly obvious for a non-emacs user).  In most cases,
4014 however, you should be able to use @kbd{C-c} to kill the test.  In
4015 order to avoid problems, you can set @env{EMACS} to ``no'' in the
4016 environment, or use the @option{--with-lispdir} option to
4017 @command{configure} to explicitly set the correct path (if you're sure
4018 you have an @command{emacs} that supports Emacs Lisp).
4019
4020 @item AM_PROG_AR(@ovar{act-if-fail})
4021 @acindex AM_PROG_AR
4022 @vindex AR
4023 You must use this macro when you use the archiver in your project, if
4024 you want support for unusual archivers such as Microsoft @command{lib}.
4025 The content of the optional argument is executed if the archiver
4026 interface is not recognized; the default action is to abort configure
4027 with an error message.
4028
4029 @item AM_PROG_AS
4030 @acindex AM_PROG_AS
4031 @vindex CCAS
4032 @vindex CCASFLAGS
4033 Use this macro when you have assembly code in your project.  This will
4034 choose the assembler for you (by default the C compiler) and set
4035 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
4036
4037 @item AM_PROG_CC_C_O
4038 @acindex AM_PROG_CC_C_O
4039 @acindex AC_PROG_CC_C_O
4040 This is like @code{AC_PROG_CC_C_O}, but it generates its results in
4041 the manner required by Automake.  You must use this instead of
4042 @code{AC_PROG_CC_C_O} when you need this functionality, that is, when
4043 using per-target flags or subdir-objects with C sources.
4044
4045 @item AM_PROG_LEX
4046 @acindex AM_PROG_LEX
4047 @acindex AC_PROG_LEX
4048 @cindex HP-UX 10, @command{lex} problems
4049 @cindex @command{lex} problems with HP-UX 10
4050 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
4051 Program Checks, autoconf, The Autoconf Manual}), but uses the
4052 @command{missing} script on systems that do not have @command{lex}.
4053 HP-UX 10 is one such system.
4054
4055 @item AM_PROG_GCJ
4056 @acindex AM_PROG_GCJ
4057 @vindex GCJ
4058 @vindex GCJFLAGS
4059 This macro finds the @command{gcj} program or causes an error.  It sets
4060 @code{GCJ} and @code{GCJFLAGS}.  @command{gcj} is the Java front-end to the
4061 GNU Compiler Collection.
4062
4063 @item AM_PROG_UPC([@var{compiler-search-list}])
4064 @acindex AM_PROG_UPC
4065 @vindex UPC
4066 Find a compiler for Unified Parallel C and define the @code{UPC}
4067 variable.  The default @var{compiler-search-list} is @samp{upcc upc}.
4068 This macro will abort @command{configure} if no Unified Parallel C
4069 compiler is found.
4070
4071 @item AM_SILENT_RULES
4072 @acindex AM_SILENT_RULES
4073 Enable the machinery for less verbose build output (@pxref{Options}).
4074
4075 @item AM_WITH_DMALLOC
4076 @acindex AM_WITH_DMALLOC
4077 @cindex @command{dmalloc}, support for
4078 @vindex WITH_DMALLOC
4079 @opindex --with-dmalloc
4080 Add support for the @uref{http://dmalloc.com/, Dmalloc package}.  If
4081 the user runs @command{configure} with @option{--with-dmalloc}, then
4082 define @code{WITH_DMALLOC} and add @option{-ldmalloc} to @code{LIBS}.
4083
4084 @end table
4085
4086
4087 @node Obsolete Macros
4088 @subsection Obsolete Macros
4089 @cindex obsolete macros
4090 @cindex autoupdate
4091
4092 Although using some of the following macros was required in past
4093 releases, you should not use any of them in new code.  Running
4094 @command{autoupdate} should adjust your @file{configure.ac}
4095 automatically (@pxref{autoupdate Invocation, , Using
4096 @command{autoupdate} to Modernize @file{configure.ac}, autoconf, The
4097 Autoconf Manual}).
4098
4099 @table @code
4100 @item AM_C_PROTOTYPES
4101 @acindex AM_C_PROTOTYPES
4102 @vindex ANSI2KNR
4103 @vindex U
4104 Check to see if function prototypes are understood by the compiler.  If
4105 so, define @samp{PROTOTYPES} and set the output variables @code{U} and
4106 @code{ANSI2KNR} to the empty string.  Otherwise, set @code{U} to
4107 @samp{_} and @code{ANSI2KNR} to @samp{./ansi2knr}.  Automake used these
4108 values to implement the deprecated de-ANSI-fication feature; however,
4109 support for @emph{that feature will be removed} in the next major Automake
4110 release, and then @emph{these macros and variables will go away as well}.
4111
4112 @item AM_CONFIG_HEADER
4113 @acindex AM_CONFIG_HEADER
4114 Automake will generate rules to automatically regenerate the config
4115 header.  This obsolete macro is a synonym of @code{AC_CONFIG_HEADERS}
4116 today (@pxref{Optional}).
4117
4118 @item AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
4119 @acindex AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
4120 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
4121 define @code{GWINSZ_IN_SYS_IOCTL}.  Otherwise @code{TIOCGWINSZ} can be
4122 found in @file{<termios.h>}.  This macro is obsolete, you should
4123 use Autoconf's @code{AC_HEADER_TIOCGWINSZ} instead.
4124
4125 @item AM_PROG_MKDIR_P
4126 @acindex AM_PROG_MKDIR_P
4127 @cindex @code{mkdir -p}, macro check
4128 @vindex MKDIR_P
4129 @vindex mkdir_p
4130
4131 From Automake 1.8 to 1.9.6 this macro used to define the output
4132 variable @code{mkdir_p} to one of @code{mkdir -p}, @code{install-sh
4133 -d}, or @code{mkinstalldirs}.
4134
4135 Nowadays Autoconf provides a similar functionality with
4136 @code{AC_PROG_MKDIR_P} (@pxref{Particular Programs, , Particular
4137 Program Checks, autoconf, The Autoconf Manual}), however this defines
4138 the output variable @code{MKDIR_P} instead.  Therefore
4139 @code{AM_PROG_MKDIR_P} has been rewritten as a thin wrapper around
4140 @code{AC_PROG_MKDIR_P} to define @code{mkdir_p} to the same value as
4141 @code{MKDIR_P} for backward compatibility.
4142
4143 If you are using Automake, there is normally no reason to call this
4144 macro, because @code{AM_INIT_AUTOMAKE} already does so.  However, make
4145 sure that the custom rules in your @file{Makefile}s use
4146 @code{$(MKDIR_P)} and not @code{$(mkdir_p)}.  Even if both variables
4147 still work, the latter should be considered obsolete.
4148
4149 If you are not using Automake, please call @code{AC_PROG_MKDIR_P}
4150 instead of @code{AM_PROG_MKDIR_P}.
4151
4152 @item AM_SYS_POSIX_TERMIOS
4153 @acindex AM_SYS_POSIX_TERMIOS
4154 @cindex POSIX termios headers
4155 @cindex termios POSIX headers
4156 Check to see if POSIX termios headers and functions are available on the
4157 system.  If so, set the shell variable @code{am_cv_sys_posix_termios} to
4158 @samp{yes}.  If not, set the variable to @samp{no}.  This macro is obsolete,
4159 you should use Autoconf's @code{AC_SYS_POSIX_TERMIOS} instead.
4160
4161 @item AM_WITH_REGEX
4162 @acindex AM_WITH_REGEX
4163 @vindex WITH_REGEX
4164 @opindex --with-regex
4165 @cindex regex package
4166 @cindex rx package
4167 Adds @option{--with-regex} to the @command{configure} command line.  If
4168 specified (the default), then the @samp{regex} regular expression
4169 library is used, @file{regex.o} is put into @code{LIBOBJS}, and
4170 @code{WITH_REGEX} is defined.  If @option{--without-regex} is given, then
4171 the @samp{rx} regular expression library is used, and @file{rx.o} is put
4172 into @code{LIBOBJS}.  This macro is obsolete now (since @samp{rx} doesn't
4173 seem to be maintained), and @emph{will be removed the next major version
4174 of Automake}.  Consider using gnulib if you need regex functionality.
4175
4176 @end table
4177
4178
4179 @node Private Macros
4180 @subsection Private Macros
4181
4182 The following macros are private macros you should not call directly.
4183 They are called by the other public macros when appropriate.  Do not
4184 rely on them, as they might be changed in a future version.  Consider
4185 them as implementation details; or better, do not consider them at all:
4186 skip this section!
4187
4188 @ftable @code
4189 @item _AM_DEPENDENCIES
4190 @itemx AM_SET_DEPDIR
4191 @itemx AM_DEP_TRACK
4192 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
4193 These macros are used to implement Automake's automatic dependency
4194 tracking scheme.  They are called automatically by Automake when
4195 required, and there should be no need to invoke them manually.
4196
4197 @item AM_MAKE_INCLUDE
4198 This macro is used to discover how the user's @command{make} handles
4199 @code{include} statements.  This macro is automatically invoked when
4200 needed; there should be no need to invoke it manually.
4201
4202 @item AM_PROG_INSTALL_STRIP
4203 This is used to find a version of @code{install} that can be used to
4204 strip a program at installation time.  This macro is automatically
4205 included when required.
4206
4207 @item AM_SANITY_CHECK
4208 This checks to make sure that a file created in the build directory is
4209 newer than a file in the source directory.  This can fail on systems
4210 where the clock is set incorrectly.  This macro is automatically run
4211 from @code{AM_INIT_AUTOMAKE}.
4212
4213 @end ftable
4214
4215
4216 @node Directories
4217 @chapter Directories
4218
4219 For simple projects that distribute all files in the same directory
4220 it is enough to have a single @file{Makefile.am} that builds
4221 everything in place.
4222
4223 In larger projects it is common to organize files in different
4224 directories, in a tree.  For instance one directory per program, per
4225 library or per module.  The traditional approach is to build these
4226 subdirectories recursively: each directory contains its @file{Makefile}
4227 (generated from @file{Makefile.am}), and when @command{make} is run
4228 from the top level directory it enters each subdirectory in turn to
4229 build its contents.
4230
4231 @menu
4232 * Subdirectories::              Building subdirectories recursively
4233 * Conditional Subdirectories::  Conditionally not building directories
4234 * Alternative::                 Subdirectories without recursion
4235 * Subpackages::                 Nesting packages
4236 @end menu
4237
4238 @node Subdirectories
4239 @section Recursing subdirectories
4240
4241 @cindex @code{SUBDIRS}, explained
4242
4243 In packages with subdirectories, the top level @file{Makefile.am} must
4244 tell Automake which subdirectories are to be built.  This is done via
4245 the @code{SUBDIRS} variable.
4246 @vindex SUBDIRS
4247
4248 The @code{SUBDIRS} variable holds a list of subdirectories in which
4249 building of various sorts can occur.  The rules for many targets
4250 (e.g., @code{all}) in the generated @file{Makefile} will run commands
4251 both locally and in all specified subdirectories.  Note that the
4252 directories listed in @code{SUBDIRS} are not required to contain
4253 @file{Makefile.am}s; only @file{Makefile}s (after configuration).
4254 This allows inclusion of libraries from packages that do not use
4255 Automake (such as @code{gettext}; see also @ref{Third-Party
4256 Makefiles}).
4257
4258 In packages that use subdirectories, the top-level @file{Makefile.am} is
4259 often very short.  For instance, here is the @file{Makefile.am} from the
4260 GNU Hello distribution:
4261
4262 @example
4263 EXTRA_DIST = BUGS ChangeLog.O README-alpha
4264 SUBDIRS = doc intl po src tests
4265 @end example
4266
4267 When Automake invokes @command{make} in a subdirectory, it uses the value
4268 of the @code{MAKE} variable.  It passes the value of the variable
4269 @code{AM_MAKEFLAGS} to the @command{make} invocation; this can be set in
4270 @file{Makefile.am} if there are flags you must always pass to
4271 @command{make}.
4272 @vindex MAKE
4273 @vindex AM_MAKEFLAGS
4274
4275 The directories mentioned in @code{SUBDIRS} are usually direct
4276 children of the current directory, each subdirectory containing its
4277 own @file{Makefile.am} with a @code{SUBDIRS} pointing to deeper
4278 subdirectories.  Automake can be used to construct packages of
4279 arbitrary depth this way.
4280
4281 By default, Automake generates @file{Makefiles} that work depth-first
4282 in postfix order: the subdirectories are built before the current
4283 directory.  However, it is possible to change this ordering.  You can
4284 do this by putting @samp{.} into @code{SUBDIRS}.  For instance,
4285 putting @samp{.} first will cause a prefix ordering of
4286 directories.
4287
4288 Using
4289
4290 @example
4291 SUBDIRS = lib src . test
4292 @end example
4293
4294 @noindent
4295 will cause @file{lib/} to be built before @file{src/}, then the
4296 current directory will be built, finally the @file{test/} directory
4297 will be built.  It is customary to arrange test directories to be
4298 built after everything else since they are meant to test what has
4299 been constructed.
4300
4301 All @code{clean} rules are run in reverse order of build rules.
4302
4303 @node Conditional Subdirectories
4304 @section Conditional Subdirectories
4305 @cindex Subdirectories, building conditionally
4306 @cindex Conditional subdirectories
4307 @cindex @code{SUBDIRS}, conditional
4308 @cindex Conditional @code{SUBDIRS}
4309
4310 It is possible to define the @code{SUBDIRS} variable conditionally if,
4311 like in the case of GNU Inetutils, you want to only build a subset of
4312 the entire package.
4313
4314 To illustrate how this works, let's assume we have two directories
4315 @file{src/} and @file{opt/}.  @file{src/} should always be built, but we
4316 want to decide in @command{configure} whether @file{opt/} will be built
4317 or not.  (For this example we will assume that @file{opt/} should be
4318 built when the variable @samp{$want_opt} was set to @samp{yes}.)
4319
4320 Running @command{make} should thus recurse into @file{src/} always, and
4321 then maybe in @file{opt/}.
4322
4323 However @samp{make dist} should always recurse into both @file{src/}
4324 and @file{opt/}.  Because @file{opt/} should be distributed even if it
4325 is not needed in the current configuration.  This means
4326 @file{opt/Makefile} should be created @emph{unconditionally}.
4327
4328 There are two ways to setup a project like this.  You can use Automake
4329 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
4330 variables (@pxref{Setting Output Variables, , Setting Output
4331 Variables, autoconf, The Autoconf Manual}).  Using Automake
4332 conditionals is the preferred solution.  Before we illustrate these
4333 two possibilities, let's introduce @code{DIST_SUBDIRS}.
4334
4335 @menu
4336 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
4337 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
4338 * Subdirectories with AC_SUBST::  Another way for conditional recursion
4339 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
4340 @end menu
4341
4342 @node SUBDIRS vs DIST_SUBDIRS
4343 @subsection @code{SUBDIRS} vs.@: @code{DIST_SUBDIRS}
4344 @cindex @code{DIST_SUBDIRS}, explained
4345
4346 Automake considers two sets of directories, defined by the variables
4347 @code{SUBDIRS} and @code{DIST_SUBDIRS}.
4348
4349 @code{SUBDIRS} contains the subdirectories of the current directory
4350 that must be built (@pxref{Subdirectories}).  It must be defined
4351 manually; Automake will never guess a directory is to be built.  As we
4352 will see in the next two sections, it is possible to define it
4353 conditionally so that some directory will be omitted from the build.
4354
4355 @code{DIST_SUBDIRS} is used in rules that need to recurse in all
4356 directories, even those that have been conditionally left out of the
4357 build.  Recall our example where we may not want to build subdirectory
4358 @file{opt/}, but yet we want to distribute it?  This is where
4359 @code{DIST_SUBDIRS} comes into play: @samp{opt} may not appear in
4360 @code{SUBDIRS}, but it must appear in @code{DIST_SUBDIRS}.
4361
4362 Precisely, @code{DIST_SUBDIRS} is used by @samp{make
4363 maintainer-clean}, @samp{make distclean} and @samp{make dist}.  All
4364 other recursive rules use @code{SUBDIRS}.
4365
4366 If @code{SUBDIRS} is defined conditionally using Automake
4367 conditionals, Automake will define @code{DIST_SUBDIRS} automatically
4368 from the possible values of @code{SUBDIRS} in all conditions.
4369
4370 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
4371 @code{DIST_SUBDIRS} will not be defined correctly because Automake
4372 does not know the possible values of these variables.  In this case
4373 @code{DIST_SUBDIRS} needs to be defined manually.
4374
4375 @node Subdirectories with AM_CONDITIONAL
4376 @subsection Subdirectories with @code{AM_CONDITIONAL}
4377 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
4378 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
4379
4380 @c Keep in sync with subcond2.test.
4381
4382 @file{configure} should output the @file{Makefile} for each directory
4383 and define a condition into which @file{opt/} should be built.
4384
4385 @example
4386 @dots{}
4387 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
4388 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4389 @dots{}
4390 @end example
4391
4392 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
4393 as follows.
4394
4395 @example
4396 if COND_OPT
4397   MAYBE_OPT = opt
4398 endif
4399 SUBDIRS = src $(MAYBE_OPT)
4400 @end example
4401
4402 As you can see, running @command{make} will rightly recurse into
4403 @file{src/} and maybe @file{opt/}.
4404
4405 @vindex DIST_SUBDIRS
4406 As you can't see, running @samp{make dist} will recurse into both
4407 @file{src/} and @file{opt/} directories because @samp{make dist}, unlike
4408 @samp{make all}, doesn't use the @code{SUBDIRS} variable.  It uses the
4409 @code{DIST_SUBDIRS} variable.
4410
4411 In this case Automake will define @samp{DIST_SUBDIRS = src opt}
4412 automatically because it knows that @code{MAYBE_OPT} can contain
4413 @samp{opt} in some condition.
4414
4415 @node Subdirectories with AC_SUBST
4416 @subsection Subdirectories with @code{AC_SUBST}
4417 @cindex @code{SUBDIRS} and @code{AC_SUBST}
4418 @cindex @code{AC_SUBST} and @code{SUBDIRS}
4419
4420 @c Keep in sync with subcond3.test.
4421
4422 Another possibility is to define @code{MAYBE_OPT} from
4423 @file{./configure} using @code{AC_SUBST}:
4424
4425 @example
4426 @dots{}
4427 if test "$want_opt" = yes; then
4428   MAYBE_OPT=opt
4429 else
4430   MAYBE_OPT=
4431 fi
4432 AC_SUBST([MAYBE_OPT])
4433 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4434 @dots{}
4435 @end example
4436
4437 In this case the top-level @file{Makefile.am} should look as follows.
4438
4439 @example
4440 SUBDIRS = src $(MAYBE_OPT)
4441 DIST_SUBDIRS = src opt
4442 @end example
4443
4444 The drawback is that since Automake cannot guess what the possible
4445 values of @code{MAYBE_OPT} are, it is necessary to define
4446 @code{DIST_SUBDIRS}.
4447
4448 @node Unconfigured Subdirectories
4449 @subsection Unconfigured Subdirectories
4450 @cindex Subdirectories, configured conditionally
4451
4452 The semantics of @code{DIST_SUBDIRS} are often misunderstood by some
4453 users that try to @emph{configure and build} subdirectories
4454 conditionally.  Here by configuring we mean creating the
4455 @file{Makefile} (it might also involve running a nested
4456 @command{configure} script: this is a costly operation that explains
4457 why people want to do it conditionally, but only the @file{Makefile}
4458 is relevant to the discussion).
4459
4460 The above examples all assume that every @file{Makefile} is created,
4461 even in directories that are not going to be built.  The simple reason
4462 is that we want @samp{make dist} to distribute even the directories
4463 that are not being built (e.g., platform-dependent code), hence
4464 @file{make dist} must recurse into the subdirectory, hence this
4465 directory must be configured and appear in @code{DIST_SUBDIRS}.
4466
4467 Building packages that do not configure every subdirectory is a tricky
4468 business, and we do not recommend it to the novice as it is easy to
4469 produce an incomplete tarball by mistake.  We will not discuss this
4470 topic in depth here, yet for the adventurous here are a few rules to
4471 remember.
4472
4473 @cartouche
4474 @itemize
4475 @item @code{SUBDIRS} should always be a subset of @code{DIST_SUBDIRS}.
4476
4477 It makes little sense to have a directory in @code{SUBDIRS} that
4478 is not in @code{DIST_SUBDIRS}.  Think of the former as a way to tell
4479 which directories listed in the latter should be built.
4480 @item Any directory listed in @code{DIST_SUBDIRS} and @code{SUBDIRS}
4481 must be configured.
4482
4483 I.e., the @file{Makefile} must exists or the recursive @command{make}
4484 rules will not be able to process the directory.
4485 @item Any configured directory must be listed in @code{DIST_SUBDIRS}.
4486
4487 So that the cleaning rules remove the generated @file{Makefile}s.
4488 It would be correct to see @code{DIST_SUBDIRS} as a variable that
4489 lists all the directories that have been configured.
4490 @end itemize
4491 @end cartouche
4492
4493 In order to prevent recursion in some unconfigured directory you
4494 must therefore ensure that this directory does not appear in
4495 @code{DIST_SUBDIRS} (and @code{SUBDIRS}).  For instance, if you define
4496 @code{SUBDIRS} conditionally using @code{AC_SUBST} and do not define
4497 @code{DIST_SUBDIRS} explicitly, it will be default to
4498 @samp{$(SUBDIRS)}; another possibility is to force @code{DIST_SUBDIRS
4499 = $(SUBDIRS)}.
4500
4501 Of course, directories that are omitted from @code{DIST_SUBDIRS} will
4502 not be distributed unless you make other arrangements for this to
4503 happen (for instance, always running @samp{make dist} in a
4504 configuration where all directories are known to appear in
4505 @code{DIST_SUBDIRS}; or writing a @code{dist-hook} target to
4506 distribute these directories).
4507
4508 @cindex Subdirectories, not distributed
4509 In few packages, unconfigured directories are not even expected to
4510 be distributed.  Although these packages do not require the
4511 aforementioned extra arrangements, there is another pitfall.  If the
4512 name of a directory appears in @code{SUBDIRS} or @code{DIST_SUBDIRS},
4513 @command{automake} will make sure the directory exists.  Consequently
4514 @command{automake} cannot be run on such a distribution when one
4515 directory has been omitted.  One way to avoid this check is to use the
4516 @code{AC_SUBST} method to declare conditional directories; since
4517 @command{automake} does not know the values of @code{AC_SUBST}
4518 variables it cannot ensure the corresponding directory exists.
4519
4520 @node Alternative
4521 @section An Alternative Approach to Subdirectories
4522
4523 If you've ever read Peter Miller's excellent paper,
4524 @uref{http://miller.emu.id.au/pmiller/books/rmch/,
4525 Recursive Make Considered Harmful}, the preceding sections on the use of
4526 subdirectories will probably come as unwelcome advice.  For those who
4527 haven't read the paper, Miller's main thesis is that recursive
4528 @command{make} invocations are both slow and error-prone.
4529
4530 Automake provides sufficient cross-directory support @footnote{We
4531 believe.  This work is new and there are probably warts.
4532 @xref{Introduction}, for information on reporting bugs.} to enable you
4533 to write a single @file{Makefile.am} for a complex multi-directory
4534 package.
4535
4536
4537 By default an installable file specified in a subdirectory will have its
4538 directory name stripped before installation.  For instance, in this
4539 example, the header file will be installed as
4540 @file{$(includedir)/stdio.h}:
4541
4542 @example
4543 include_HEADERS = inc/stdio.h
4544 @end example
4545
4546 @vindex nobase_
4547 @cindex @code{nobase_} prefix
4548 @cindex Path stripping, avoiding
4549 @cindex Avoiding path stripping
4550
4551 However, the @samp{nobase_} prefix can be used to circumvent this path
4552 stripping.  In this example, the header file will be installed as
4553 @file{$(includedir)/sys/types.h}:
4554
4555 @example
4556 nobase_include_HEADERS = sys/types.h
4557 @end example
4558
4559 @cindex @code{nobase_} and @code{dist_} or @code{nodist_}
4560 @cindex @code{dist_} and @code{nobase_}
4561 @cindex @code{nodist_} and @code{nobase_}
4562 @vindex dist_
4563 @vindex nodist_
4564
4565 @samp{nobase_} should be specified first when used in conjunction with
4566 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
4567 Control}).  For instance:
4568
4569 @example
4570 nobase_dist_pkgdata_DATA = images/vortex.pgm sounds/whirl.ogg
4571 @end example
4572
4573 Finally, note that a variable using the @samp{nobase_} prefix can
4574 often be replaced by several variables, one for each destination
4575 directory (@pxref{Uniform}).  For instance, the last example could be
4576 rewritten as follows:
4577
4578 @c Keep in sync with primary-prefix-couples-documented-valid.test.
4579 @example
4580 imagesdir = $(pkgdatadir)/images
4581 soundsdir = $(pkgdatadir)/sounds
4582 dist_images_DATA = images/vortex.pgm
4583 dist_sounds_DATA = sounds/whirl.ogg
4584 @end example
4585
4586 @noindent
4587 This latter syntax makes it possible to change one destination
4588 directory without changing the layout of the source tree.
4589
4590 Currently, @samp{nobase_*_LTLIBRARIES} are the only exception to this
4591 rule, in that there is no particular installation order guarantee for
4592 an otherwise equivalent set of variables without @samp{nobase_} prefix.
4593
4594 @node Subpackages
4595 @section Nesting Packages
4596 @cindex Nesting packages
4597 @cindex Subpackages
4598 @acindex AC_CONFIG_SUBDIRS
4599 @acindex AC_CONFIG_AUX_DIR
4600
4601
4602 In the GNU Build System, packages can be nested to arbitrary depth.
4603 This means that a package can embed other packages with their own
4604 @file{configure}, @file{Makefile}s, etc.
4605
4606 These other packages should just appear as subdirectories of their
4607 parent package.  They must be listed in @code{SUBDIRS} like other
4608 ordinary directories.  However the subpackage's @file{Makefile}s
4609 should be output by its own @file{configure} script, not by the
4610 parent's @file{configure}.  This is achieved using the
4611 @code{AC_CONFIG_SUBDIRS} Autoconf macro (@pxref{Subdirectories,
4612 AC_CONFIG_SUBDIRS, Configuring Other Packages in Subdirectories,
4613 autoconf, The Autoconf Manual}).
4614
4615 Here is an example package for an @code{arm} program that links with
4616 a @code{hand} library that is a nested package in subdirectory
4617 @file{hand/}.
4618
4619 @code{arm}'s @file{configure.ac}:
4620
4621 @example
4622 AC_INIT([arm], [1.0])
4623 AC_CONFIG_AUX_DIR([.])
4624 AM_INIT_AUTOMAKE
4625 AC_PROG_CC
4626 AC_CONFIG_FILES([Makefile])
4627 # Call hand's ./configure script recursively.
4628 AC_CONFIG_SUBDIRS([hand])
4629 AC_OUTPUT
4630 @end example
4631
4632 @code{arm}'s @file{Makefile.am}:
4633
4634 @example
4635 # Build the library in the hand subdirectory first.
4636 SUBDIRS = hand
4637
4638 # Include hand's header when compiling this directory.
4639 AM_CPPFLAGS = -I$(srcdir)/hand
4640
4641 bin_PROGRAMS = arm
4642 arm_SOURCES = arm.c
4643 # link with the hand library.
4644 arm_LDADD = hand/libhand.a
4645 @end example
4646
4647 Now here is @code{hand}'s @file{hand/configure.ac}:
4648
4649 @example
4650 AC_INIT([hand], [1.2])
4651 AC_CONFIG_AUX_DIR([.])
4652 AM_INIT_AUTOMAKE
4653 AC_PROG_CC
4654 AM_PROG_AR
4655 AC_PROG_RANLIB
4656 AC_CONFIG_FILES([Makefile])
4657 AC_OUTPUT
4658 @end example
4659
4660 @noindent
4661 and its @file{hand/Makefile.am}:
4662
4663 @example
4664 lib_LIBRARIES = libhand.a
4665 libhand_a_SOURCES = hand.c
4666 @end example
4667
4668 When @samp{make dist} is run from the top-level directory it will
4669 create an archive @file{arm-1.0.tar.gz} that contains the @code{arm}
4670 code as well as the @file{hand} subdirectory.  This package can be
4671 built and installed like any ordinary package, with the usual
4672 @samp{./configure && make && make install} sequence (the @code{hand}
4673 subpackage will be built and installed by the process).
4674
4675 When @samp{make dist} is run from the hand directory, it will create a
4676 self-contained @file{hand-1.2.tar.gz} archive.  So although it appears
4677 to be embedded in another package, it can still be used separately.
4678
4679 The purpose of the @samp{AC_CONFIG_AUX_DIR([.])} instruction is to
4680 force Automake and Autoconf to search for auxiliary scripts in the
4681 current directory.  For instance, this means that there will be two
4682 copies of @file{install-sh}: one in the top-level of the @code{arm}
4683 package, and another one in the @file{hand/} subdirectory for the
4684 @code{hand} package.
4685
4686 The historical default is to search for these auxiliary scripts in
4687 the parent directory and the grandparent directory.  So if the
4688 @samp{AC_CONFIG_AUX_DIR([.])} line was removed from
4689 @file{hand/configure.ac}, that subpackage would share the auxiliary
4690 script of the @code{arm} package.  This may looks like a gain in size
4691 (a few kilobytes), but it is actually a loss of modularity as the
4692 @code{hand} subpackage is no longer self-contained (@samp{make dist}
4693 in the subdirectory will not work anymore).
4694
4695 Packages that do not use Automake need more work to be integrated this
4696 way.  @xref{Third-Party Makefiles}.
4697
4698 @node Programs
4699 @chapter Building Programs and Libraries
4700
4701 A large part of Automake's functionality is dedicated to making it easy
4702 to build programs and libraries.
4703
4704 @menu
4705 * A Program::                   Building a program
4706 * A Library::                   Building a library
4707 * A Shared Library::            Building a Libtool library
4708 * Program and Library Variables::  Variables controlling program and
4709                                 library builds
4710 * Default _SOURCES::            Default source files
4711 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
4712 * Program Variables::           Variables used when building a program
4713 * Yacc and Lex::                Yacc and Lex support
4714 * C++ Support::                 Compiling C++ sources
4715 * Objective C Support::         Compiling Objective C sources
4716 * Unified Parallel C Support::  Compiling Unified Parallel C sources
4717 * Assembly Support::            Compiling assembly sources
4718 * Fortran 77 Support::          Compiling Fortran 77 sources
4719 * Fortran 9x Support::          Compiling Fortran 9x sources
4720 * Java Support with gcj::       Compiling Java sources using gcj
4721 * Vala Support::                Compiling Vala sources
4722 * Support for Other Languages::  Compiling other languages
4723 * ANSI::                        Automatic de-ANSI-fication (deprecated, soon to be removed)
4724 * Dependencies::                Automatic dependency tracking
4725 * EXEEXT::                      Support for executable extensions
4726 @end menu
4727
4728
4729 @node A Program
4730 @section Building a program
4731
4732 In order to build a program, you need to tell Automake which sources
4733 are part of it, and which libraries it should be linked with.
4734
4735 This section also covers conditional compilation of sources or
4736 programs.  Most of the comments about these also apply to libraries
4737 (@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
4738
4739 @menu
4740 * Program Sources::             Defining program sources
4741 * Linking::                     Linking with libraries or extra objects
4742 * Conditional Sources::         Handling conditional sources
4743 * Conditional Programs::        Building a program conditionally
4744 @end menu
4745
4746 @node Program Sources
4747 @subsection Defining program sources
4748
4749 @cindex @code{PROGRAMS}, @code{bindir}
4750 @vindex _PROGRAMS
4751 @vindex bin_PROGRAMS
4752 @vindex sbin_PROGRAMS
4753 @vindex libexec_PROGRAMS
4754 @vindex pkglibexec_PROGRAMS
4755 @vindex noinst_PROGRAMS
4756 @vindex check_PROGRAMS
4757
4758 In a directory containing source that gets built into a program (as
4759 opposed to a library or a script), the @code{PROGRAMS} primary is used.
4760 Programs can be installed in @code{bindir}, @code{sbindir},
4761 @code{libexecdir}, @code{pkglibexecdir}, or not at all
4762 (@code{noinst_}).  They can also be built only for @samp{make check}, in
4763 which case the prefix is @samp{check_}.
4764
4765 For instance:
4766
4767 @example
4768 bin_PROGRAMS = hello
4769 @end example
4770
4771 In this simple case, the resulting @file{Makefile.in} will contain code
4772 to generate a program named @code{hello}.
4773
4774 Associated with each program are several assisting variables that are
4775 named after the program.  These variables are all optional, and have
4776 reasonable defaults.  Each variable, its use, and default is spelled out
4777 below; we use the ``hello'' example throughout.
4778
4779 The variable @code{hello_SOURCES} is used to specify which source files
4780 get built into an executable:
4781
4782 @example
4783 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
4784 @end example
4785
4786 This causes each mentioned @file{.c} file to be compiled into the
4787 corresponding @file{.o}.  Then all are linked to produce @file{hello}.
4788
4789 @cindex @code{_SOURCES} primary, defined
4790 @cindex @code{SOURCES} primary, defined
4791 @cindex Primary variable, @code{SOURCES}
4792 @vindex _SOURCES
4793
4794 If @code{hello_SOURCES} is not specified, then it defaults to the single
4795 file @file{hello.c} (@pxref{Default _SOURCES}).
4796 @vindex _SOURCES
4797 @vindex SOURCES
4798
4799 Multiple programs can be built in a single directory.  Multiple programs
4800 can share a single source file, which must be listed in each
4801 @code{_SOURCES} definition.
4802
4803 @cindex Header files in @code{_SOURCES}
4804 @cindex @code{_SOURCES} and header files
4805
4806 Header files listed in a @code{_SOURCES} definition will be included in
4807 the distribution but otherwise ignored.  In case it isn't obvious, you
4808 should not include the header file generated by @file{configure} in a
4809 @code{_SOURCES} variable; this file should not be distributed.  Lex
4810 (@file{.l}) and Yacc (@file{.y}) files can also be listed; see @ref{Yacc
4811 and Lex}.
4812
4813
4814 @node Linking
4815 @subsection Linking the program
4816
4817 If you need to link against libraries that are not found by
4818 @command{configure}, you can use @code{LDADD} to do so.  This variable is
4819 used to specify additional objects or libraries to link with; it is
4820 inappropriate for specifying specific linker flags, you should use
4821 @code{AM_LDFLAGS} for this purpose.
4822 @vindex LDADD
4823 @vindex AM_LDFLAGS
4824
4825 @cindex @code{prog_LDADD}, defined
4826
4827 Sometimes, multiple programs are built in one directory but do not share
4828 the same link-time requirements.  In this case, you can use the
4829 @code{@var{prog}_LDADD} variable (where @var{prog} is the name of the
4830 program as it appears in some @code{_PROGRAMS} variable, and usually
4831 written in lowercase) to override @code{LDADD}.  If this variable exists
4832 for a given program, then that program is not linked using @code{LDADD}.
4833 @vindex maude_LDADD
4834
4835 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
4836 linked against the library @file{libcpio.a}.  However, @code{rmt} is
4837 built in the same directory, and has no such link requirement.  Also,
4838 @code{mt} and @code{rmt} are only built on certain architectures.  Here
4839 is what cpio's @file{src/Makefile.am} looks like (abridged):
4840
4841 @example
4842 bin_PROGRAMS = cpio pax $(MT)
4843 libexec_PROGRAMS = $(RMT)
4844 EXTRA_PROGRAMS = mt rmt
4845
4846 LDADD = ../lib/libcpio.a $(INTLLIBS)
4847 rmt_LDADD =
4848
4849 cpio_SOURCES = @dots{}
4850 pax_SOURCES = @dots{}
4851 mt_SOURCES = @dots{}
4852 rmt_SOURCES = @dots{}
4853 @end example
4854
4855 @cindex @code{_LDFLAGS}, defined
4856 @vindex maude_LDFLAGS
4857 @code{@var{prog}_LDADD} is inappropriate for passing program-specific
4858 linker flags (except for @option{-l}, @option{-L}, @option{-dlopen} and
4859 @option{-dlpreopen}).  So, use the @code{@var{prog}_LDFLAGS} variable for
4860 this purpose.
4861
4862 @cindex @code{_DEPENDENCIES}, defined
4863 @vindex maude_DEPENDENCIES
4864 @vindex EXTRA_maude_DEPENDENCIES
4865 It is also occasionally useful to have a program depend on some other
4866 target that is not actually part of that program.  This can be done
4867 using either the @code{@var{prog}_DEPENDENCIES} or the
4868 @code{EXTRA_@var{prog}_DEPENDENCIES} variable.  Each program depends on
4869 the contents both variables, but no further interpretation is done.
4870
4871 Since these dependencies are associated to the link rule used to
4872 create the programs they should normally list files used by the link
4873 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la}
4874 files.  In rare cases you may need to add other kinds of files such as
4875 linker scripts, but @emph{listing a source file in
4876 @code{_DEPENDENCIES} is wrong}.  If some source file needs to be built
4877 before all the components of a program are built, consider using the
4878 @code{BUILT_SOURCES} variable instead (@pxref{Sources}).
4879
4880 If @code{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
4881 Automake.  The automatically-assigned value is the contents of
4882 @code{@var{prog}_LDADD}, with most configure substitutions, @option{-l},
4883 @option{-L}, @option{-dlopen} and @option{-dlpreopen} options removed.  The
4884 configure substitutions that are left in are only @samp{$(LIBOBJS)} and
4885 @samp{$(ALLOCA)}; these are left because it is known that they will not
4886 cause an invalid value for @code{@var{prog}_DEPENDENCIES} to be
4887 generated.
4888
4889 @ref{Conditional Sources} shows a situation where @code{_DEPENDENCIES}
4890 may be used.
4891
4892 The @code{EXTRA_@var{prog}_DEPENDENCIES} may be useful for cases where
4893 you merely want to augment the @command{automake}-generated
4894 @code{@var{prog}_DEPENDENCIES} rather than replacing it.
4895
4896 @cindex @code{LDADD} and @option{-l}
4897 @cindex @option{-l} and @code{LDADD}
4898 We recommend that you avoid using @option{-l} options in @code{LDADD}
4899 or @code{@var{prog}_LDADD} when referring to libraries built by your
4900 package.  Instead, write the file name of the library explicitly as in
4901 the above @code{cpio} example.  Use @option{-l} only to list
4902 third-party libraries.  If you follow this rule, the default value of
4903 @code{@var{prog}_DEPENDENCIES} will list all your local libraries and
4904 omit the other ones.
4905
4906
4907 @node Conditional Sources
4908 @subsection Conditional compilation of sources
4909
4910 You can't put a configure substitution (e.g., @samp{@@FOO@@} or
4911 @samp{$(FOO)} where @code{FOO} is defined via @code{AC_SUBST}) into a
4912 @code{_SOURCES} variable.  The reason for this is a bit hard to
4913 explain, but suffice to say that it simply won't work.  Automake will
4914 give an error if you try to do this.
4915
4916 Fortunately there are two other ways to achieve the same result.  One is
4917 to use configure substitutions in @code{_LDADD} variables, the other is
4918 to use an Automake conditional.
4919
4920 @subsubheading Conditional Compilation using @code{_LDADD} Substitutions
4921
4922 @cindex @code{EXTRA_prog_SOURCES}, defined
4923
4924 Automake must know all the source files that could possibly go into a
4925 program, even if not all the files are built in every circumstance.  Any
4926 files that are only conditionally built should be listed in the
4927 appropriate @code{EXTRA_} variable.  For instance, if
4928 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
4929 in @code{hello}, the @file{Makefile.am} would contain:
4930
4931 @example
4932 bin_PROGRAMS = hello
4933 hello_SOURCES = hello-common.c
4934 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
4935 hello_LDADD = $(HELLO_SYSTEM)
4936 hello_DEPENDENCIES = $(HELLO_SYSTEM)
4937 @end example
4938
4939 @noindent
4940 You can then setup the @samp{$(HELLO_SYSTEM)} substitution from
4941 @file{configure.ac}:
4942
4943 @example
4944 @dots{}
4945 case $host in
4946   *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
4947   *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
4948 esac
4949 AC_SUBST([HELLO_SYSTEM])
4950 @dots{}
4951 @end example
4952
4953 In this case, the variable @code{HELLO_SYSTEM} should be replaced by
4954 either @file{hello-linux.o} or @file{hello-generic.o}, and added to
4955 both @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be
4956 built and linked in.
4957
4958 @subsubheading Conditional Compilation using Automake Conditionals
4959
4960 An often simpler way to compile source files conditionally is to use
4961 Automake conditionals.  For instance, you could use this
4962 @file{Makefile.am} construct to build the same @file{hello} example:
4963
4964 @example
4965 bin_PROGRAMS = hello
4966 if LINUX
4967 hello_SOURCES = hello-linux.c hello-common.c
4968 else
4969 hello_SOURCES = hello-generic.c hello-common.c
4970 endif
4971 @end example
4972
4973 In this case, @file{configure.ac} should setup the @code{LINUX}
4974 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
4975
4976 When using conditionals like this you don't need to use the
4977 @code{EXTRA_} variable, because Automake will examine the contents of
4978 each variable to construct the complete list of source files.
4979
4980 If your program uses a lot of files, you will probably prefer a
4981 conditional @samp{+=}.
4982
4983 @example
4984 bin_PROGRAMS = hello
4985 hello_SOURCES = hello-common.c
4986 if LINUX
4987 hello_SOURCES += hello-linux.c
4988 else
4989 hello_SOURCES += hello-generic.c
4990 endif
4991 @end example
4992
4993 @node Conditional Programs
4994 @subsection Conditional compilation of programs
4995 @cindex Conditional programs
4996 @cindex Programs, conditional
4997
4998 Sometimes it is useful to determine the programs that are to be built
4999 at configure time.  For instance, GNU @code{cpio} only builds
5000 @code{mt} and @code{rmt} under special circumstances.  The means to
5001 achieve conditional compilation of programs are the same you can use
5002 to compile source files conditionally: substitutions or conditionals.
5003
5004 @subsubheading Conditional Programs using @command{configure} Substitutions
5005
5006 @vindex EXTRA_PROGRAMS
5007 @cindex @code{EXTRA_PROGRAMS}, defined
5008 In this case, you must notify Automake of all the programs that can
5009 possibly be built, but at the same time cause the generated
5010 @file{Makefile.in} to use the programs specified by @command{configure}.
5011 This is done by having @command{configure} substitute values into each
5012 @code{_PROGRAMS} definition, while listing all optionally built programs
5013 in @code{EXTRA_PROGRAMS}.
5014
5015 @example
5016 bin_PROGRAMS = cpio pax $(MT)
5017 libexec_PROGRAMS = $(RMT)
5018 EXTRA_PROGRAMS = mt rmt
5019 @end example
5020
5021 As explained in @ref{EXEEXT}, Automake will rewrite
5022 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
5023 @code{EXTRA_PROGRAMS}, appending @samp{$(EXEEXT)} to each binary.
5024 Obviously it cannot rewrite values obtained at run-time through
5025 @command{configure} substitutions, therefore you should take care of
5026 appending @samp{$(EXEEXT)} yourself, as in @samp{AC_SUBST([MT],
5027 ['mt$@{EXEEXT@}'])}.
5028
5029 @subsubheading Conditional Programs using Automake Conditionals
5030
5031 You can also use Automake conditionals (@pxref{Conditionals}) to
5032 select programs to be built.  In this case you don't have to worry
5033 about @samp{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
5034
5035 @c Keep in sync with exeext.test.
5036 @example
5037 bin_PROGRAMS = cpio pax
5038 if WANT_MT
5039   bin_PROGRAMS += mt
5040 endif
5041 if WANT_RMT
5042   libexec_PROGRAMS = rmt
5043 endif
5044 @end example
5045
5046
5047 @node A Library
5048 @section Building a library
5049
5050 @cindex @code{_LIBRARIES} primary, defined
5051 @cindex @code{LIBRARIES} primary, defined
5052 @cindex Primary variable, @code{LIBRARIES}
5053 @vindex _LIBRARIES
5054
5055 @vindex lib_LIBRARIES
5056 @vindex pkglib_LIBRARIES
5057 @vindex noinst_LIBRARIES
5058
5059 Building a library is much like building a program.  In this case, the
5060 name of the primary is @code{LIBRARIES}.  Libraries can be installed in
5061 @code{libdir} or @code{pkglibdir}.
5062
5063 @xref{A Shared Library}, for information on how to build shared
5064 libraries using libtool and the @code{LTLIBRARIES} primary.
5065
5066 Each @code{_LIBRARIES} variable is a list of the libraries to be built.
5067 For instance, to create a library named @file{libcpio.a}, but not install
5068 it, you would write:
5069
5070 @example
5071 noinst_LIBRARIES = libcpio.a
5072 libcpio_a_SOURCES = @dots{}
5073 @end example
5074
5075 The sources that go into a library are determined exactly as they are
5076 for programs, via the @code{_SOURCES} variables.  Note that the library
5077 name is canonicalized (@pxref{Canonicalization}), so the @code{_SOURCES}
5078 variable corresponding to @file{libcpio.a} is @samp{libcpio_a_SOURCES},
5079 not @samp{libcpio.a_SOURCES}.
5080
5081 @vindex maude_LIBADD
5082 Extra objects can be added to a library using the
5083 @code{@var{library}_LIBADD} variable.  This should be used for objects
5084 determined by @command{configure}.  Again from @code{cpio}:
5085
5086 @c Keep in sync with pr401c.test.
5087 @example
5088 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
5089 @end example
5090
5091 In addition, sources for extra objects that will not exist until
5092 configure-time must be added to the @code{BUILT_SOURCES} variable
5093 (@pxref{Sources}).
5094
5095 Building a static library is done by compiling all object files, then
5096 by invoking @samp{$(AR) $(ARFLAGS)} followed by the name of the
5097 library and the list of objects, and finally by calling
5098 @samp{$(RANLIB)} on that library.  You should call
5099 @code{AC_PROG_RANLIB} from your @file{configure.ac} to define
5100 @code{RANLIB} (Automake will complain otherwise).  You should also
5101 call @code{AM_PROG_AR} to define @code{AR}, in order to support unusual
5102 archivers such as Microsoft lib.  @code{ARFLAGS} will default to
5103 @code{cru}; you can override this variable by setting it in your
5104 @file{Makefile.am} or by @code{AC_SUBST}ing it from your
5105 @file{configure.ac}.  You can override the @code{AR} variable by
5106 defining a per-library @code{maude_AR} variable (@pxref{Program and
5107 Library Variables}).
5108
5109 @cindex Empty libraries
5110 Be careful when selecting library components conditionally.  Because
5111 building an empty library is not portable, you should ensure that any
5112 library always contains at least one object.
5113
5114 To use a static library when building a program, add it to
5115 @code{LDADD} for this program.  In the following example, the program
5116 @file{cpio} is statically linked with the library @file{libcpio.a}.
5117
5118 @example
5119 noinst_LIBRARIES = libcpio.a
5120 libcpio_a_SOURCES = @dots{}
5121
5122 bin_PROGRAMS = cpio
5123 cpio_SOURCES = cpio.c @dots{}
5124 cpio_LDADD = libcpio.a
5125 @end example
5126
5127
5128 @node A Shared Library
5129 @section Building a Shared Library
5130
5131 @cindex Shared libraries, support for
5132
5133 Building shared libraries portably is a relatively complex matter.
5134 For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
5135 Libtool Manual}) was created to help build shared libraries in a
5136 platform-independent way.
5137
5138 @menu
5139 * Libtool Concept::             Introducing Libtool
5140 * Libtool Libraries::           Declaring Libtool Libraries
5141 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
5142 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
5143 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
5144 * Libtool Modules::             Building Libtool Modules
5145 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
5146 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
5147 * Libtool Issues::              Common Issues Related to Libtool's Use
5148 @end menu
5149
5150 @node Libtool Concept
5151 @subsection The Libtool Concept
5152
5153 @cindex @command{libtool}, introduction
5154 @cindex libtool library, definition
5155 @cindex suffix @file{.la}, defined
5156 @cindex @file{.la} suffix, defined
5157
5158 Libtool abstracts shared and static libraries into a unified concept
5159 henceforth called @dfn{libtool libraries}.  Libtool libraries are
5160 files using the @file{.la} suffix, and can designate a static library,
5161 a shared library, or maybe both.  Their exact nature cannot be
5162 determined until @file{./configure} is run: not all platforms support
5163 all kinds of libraries, and users can explicitly select which
5164 libraries should be built.  (However the package's maintainers can
5165 tune the default, @pxref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
5166 macro, libtool, The Libtool Manual}.)
5167
5168 @cindex suffix @file{.lo}, defined
5169 Because object files for shared and static libraries must be compiled
5170 differently, libtool is also used during compilation.  Object files
5171 built by libtool are called @dfn{libtool objects}: these are files
5172 using the @file{.lo} suffix.  Libtool libraries are built from these
5173 libtool objects.
5174
5175 You should not assume anything about the structure of @file{.la} or
5176 @file{.lo} files and how libtool constructs them: this is libtool's
5177 concern, and the last thing one wants is to learn about libtool's
5178 guts.  However the existence of these files matters, because they are
5179 used as targets and dependencies in @file{Makefile}s rules when
5180 building libtool libraries.  There are situations where you may have
5181 to refer to these, for instance when expressing dependencies for
5182 building source files conditionally (@pxref{Conditional Libtool
5183 Sources}).
5184
5185 @cindex @file{libltdl}, introduction
5186
5187 People considering writing a plug-in system, with dynamically loaded
5188 modules, should look into @file{libltdl}: libtool's dlopening library
5189 (@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
5190 This offers a portable dlopening facility to load libtool libraries
5191 dynamically, and can also achieve static linking where unavoidable.
5192
5193 Before we discuss how to use libtool with Automake in details, it
5194 should be noted that the libtool manual also has a section about how
5195 to use Automake with libtool (@pxref{Using Automake, , Using Automake
5196 with Libtool, libtool, The Libtool Manual}).
5197
5198 @node Libtool Libraries
5199 @subsection Building Libtool Libraries
5200
5201 @cindex @code{_LTLIBRARIES} primary, defined
5202 @cindex @code{LTLIBRARIES} primary, defined
5203 @cindex Primary variable, @code{LTLIBRARIES}
5204 @cindex Example of shared libraries
5205 @vindex lib_LTLIBRARIES
5206 @vindex pkglib_LTLIBRARIES
5207 @vindex _LTLIBRARIES
5208
5209 Automake uses libtool to build libraries declared with the
5210 @code{LTLIBRARIES} primary.  Each @code{_LTLIBRARIES} variable is a
5211 list of libtool libraries to build.  For instance, to create a libtool
5212 library named @file{libgettext.la}, and install it in @code{libdir},
5213 write:
5214
5215 @example
5216 lib_LTLIBRARIES = libgettext.la
5217 libgettext_la_SOURCES = gettext.c gettext.h @dots{}
5218 @end example
5219
5220 Automake predefines the variable @code{pkglibdir}, so you can use
5221 @code{pkglib_LTLIBRARIES} to install libraries in
5222 @samp{$(libdir)/@@PACKAGE@@/}.
5223
5224 If @file{gettext.h} is a public header file that needs to be installed
5225 in order for people to use the library, it should be declared using a
5226 @code{_HEADERS} variable, not in @code{libgettext_la_SOURCES}.
5227 Headers listed in the latter should be internal headers that are not
5228 part of the public interface.
5229
5230 @example
5231 lib_LTLIBRARIES = libgettext.la
5232 libgettext_la_SOURCES = gettext.c @dots{}
5233 include_HEADERS = gettext.h @dots{}
5234 @end example
5235
5236 A package can build and install such a library along with other
5237 programs that use it.  This dependency should be specified using
5238 @code{LDADD}.  The following example builds a program named
5239 @file{hello} that is linked with @file{libgettext.la}.
5240
5241 @example
5242 lib_LTLIBRARIES = libgettext.la
5243 libgettext_la_SOURCES = gettext.c @dots{}
5244
5245 bin_PROGRAMS = hello
5246 hello_SOURCES = hello.c @dots{}
5247 hello_LDADD = libgettext.la
5248 @end example
5249
5250 @noindent
5251 Whether @file{hello} is statically or dynamically linked with
5252 @file{libgettext.la} is not yet known: this will depend on the
5253 configuration of libtool and the capabilities of the host.
5254
5255
5256 @node Conditional Libtool Libraries
5257 @subsection Building Libtool Libraries Conditionally
5258 @cindex libtool libraries, conditional
5259 @cindex conditional libtool libraries
5260
5261 Like conditional programs (@pxref{Conditional Programs}), there are
5262 two main ways to build conditional libraries: using Automake
5263 conditionals or using Autoconf @code{AC_SUBST}itutions.
5264
5265 The important implementation detail you have to be aware of is that
5266 the place where a library will be installed matters to libtool: it
5267 needs to be indicated @emph{at link-time} using the @option{-rpath}
5268 option.
5269
5270 For libraries whose destination directory is known when Automake runs,
5271 Automake will automatically supply the appropriate @option{-rpath}
5272 option to libtool.  This is the case for libraries listed explicitly in
5273 some installable @code{_LTLIBRARIES} variables such as
5274 @code{lib_LTLIBRARIES}.
5275
5276 However, for libraries determined at configure time (and thus
5277 mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
5278 final installation directory.  For such libraries you must add the
5279 @option{-rpath} option to the appropriate @code{_LDFLAGS} variable by
5280 hand.
5281
5282 The examples below illustrate the differences between these two methods.
5283
5284 Here is an example where @code{WANTEDLIBS} is an @code{AC_SUBST}ed
5285 variable set at @file{./configure}-time to either @file{libfoo.la},
5286 @file{libbar.la}, both, or none.  Although @samp{$(WANTEDLIBS)}
5287 appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
5288 relates to @file{libfoo.la} or @file{libbar.la} at the time it creates
5289 the link rule for these two libraries.  Therefore the @option{-rpath}
5290 argument must be explicitly supplied.
5291
5292 @c Keep in sync with ltcond.test.
5293 @example
5294 EXTRA_LTLIBRARIES = libfoo.la libbar.la
5295 lib_LTLIBRARIES = $(WANTEDLIBS)
5296 libfoo_la_SOURCES = foo.c @dots{}
5297 libfoo_la_LDFLAGS = -rpath '$(libdir)'
5298 libbar_la_SOURCES = bar.c @dots{}
5299 libbar_la_LDFLAGS = -rpath '$(libdir)'
5300 @end example
5301
5302 Here is how the same @file{Makefile.am} would look using Automake
5303 conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}.  Now
5304 Automake is able to compute the @option{-rpath} setting itself, because
5305 it's clear that both libraries will end up in @samp{$(libdir)} if they
5306 are installed.
5307
5308 @c Keep in sync with ltcond.test.
5309 @example
5310 lib_LTLIBRARIES =
5311 if WANT_LIBFOO
5312 lib_LTLIBRARIES += libfoo.la
5313 endif
5314 if WANT_LIBBAR
5315 lib_LTLIBRARIES += libbar.la
5316 endif
5317 libfoo_la_SOURCES = foo.c @dots{}
5318 libbar_la_SOURCES = bar.c @dots{}
5319 @end example
5320
5321 @node Conditional Libtool Sources
5322 @subsection Libtool Libraries with Conditional Sources
5323
5324 Conditional compilation of sources in a library can be achieved in the
5325 same way as conditional compilation of sources in a program
5326 (@pxref{Conditional Sources}).  The only difference is that
5327 @code{_LIBADD} should be used instead of @code{_LDADD} and that it
5328 should mention libtool objects (@file{.lo} files).
5329
5330 So, to mimic the @file{hello} example from @ref{Conditional Sources},
5331 we could build a @file{libhello.la} library using either
5332 @file{hello-linux.c} or @file{hello-generic.c} with the following
5333 @file{Makefile.am}.
5334
5335 @c Keep in sync with ltcond2.test.
5336 @example
5337 lib_LTLIBRARIES = libhello.la
5338 libhello_la_SOURCES = hello-common.c
5339 EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
5340 libhello_la_LIBADD = $(HELLO_SYSTEM)
5341 libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
5342 @end example
5343
5344 @noindent
5345 And make sure @command{configure} defines @code{HELLO_SYSTEM} as
5346 either @file{hello-linux.lo} or @file{hello-@-generic.lo}.
5347
5348 Or we could simply use an Automake conditional as follows.
5349
5350 @c Keep in sync with ltcond2.test.
5351 @example
5352 lib_LTLIBRARIES = libhello.la
5353 libhello_la_SOURCES = hello-common.c
5354 if LINUX
5355 libhello_la_SOURCES += hello-linux.c
5356 else
5357 libhello_la_SOURCES += hello-generic.c
5358 endif
5359 @end example
5360
5361 @node Libtool Convenience Libraries
5362 @subsection Libtool Convenience Libraries
5363 @cindex convenience libraries, libtool
5364 @cindex libtool convenience libraries
5365 @vindex noinst_LTLIBRARIES
5366 @vindex check_LTLIBRARIES
5367
5368 Sometimes you want to build libtool libraries that should not be
5369 installed.  These are called @dfn{libtool convenience libraries} and
5370 are typically used to encapsulate many sublibraries, later gathered
5371 into one big installed library.
5372
5373 Libtool convenience libraries are declared by directory-less variables
5374 such as @code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
5375 @code{EXTRA_LTLIBRARIES}.  Unlike installed libtool libraries they do
5376 not need an @option{-rpath} flag at link time (actually this is the only
5377 difference).
5378
5379 Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
5380 built.  Those listed in @code{check_LTLIBRARIES} are built only upon
5381 @samp{make check}.  Finally, libraries listed in
5382 @code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
5383 rules to build them, but if the library does not appear as a Makefile
5384 dependency anywhere it won't be built (this is why
5385 @code{EXTRA_LTLIBRARIES} is used for conditional compilation).
5386
5387 Here is a sample setup merging libtool convenience libraries from
5388 subdirectories into one main @file{libtop.la} library.
5389
5390 @c Keep in sync with ltconv.test.
5391 @example
5392 # -- Top-level Makefile.am --
5393 SUBDIRS = sub1 sub2 @dots{}
5394 lib_LTLIBRARIES = libtop.la
5395 libtop_la_SOURCES =
5396 libtop_la_LIBADD = \
5397   sub1/libsub1.la \
5398   sub2/libsub2.la \
5399   @dots{}
5400
5401 # -- sub1/Makefile.am --
5402 noinst_LTLIBRARIES = libsub1.la
5403 libsub1_la_SOURCES = @dots{}
5404
5405 # -- sub2/Makefile.am --
5406 # showing nested convenience libraries
5407 SUBDIRS = sub2.1 sub2.2 @dots{}
5408 noinst_LTLIBRARIES = libsub2.la
5409 libsub2_la_SOURCES =
5410 libsub2_la_LIBADD = \
5411   sub21/libsub21.la \
5412   sub22/libsub22.la \
5413   @dots{}
5414 @end example
5415
5416 When using such setup, beware that @command{automake} will assume
5417 @file{libtop.la} is to be linked with the C linker.  This is because
5418 @code{libtop_la_SOURCES} is empty, so @command{automake} picks C as
5419 default language.  If @code{libtop_la_SOURCES} was not empty,
5420 @command{automake} would select the linker as explained in @ref{How
5421 the Linker is Chosen}.
5422
5423 If one of the sublibraries contains non-C source, it is important that
5424 the appropriate linker be chosen.  One way to achieve this is to
5425 pretend that there is such a non-C file among the sources of the
5426 library, thus forcing @command{automake} to select the appropriate
5427 linker.  Here is the top-level @file{Makefile} of our example updated
5428 to force C++ linking.
5429
5430 @example
5431 SUBDIRS = sub1 sub2 @dots{}
5432 lib_LTLIBRARIES = libtop.la
5433 libtop_la_SOURCES =
5434 # Dummy C++ source to cause C++ linking.
5435 nodist_EXTRA_libtop_la_SOURCES = dummy.cxx
5436 libtop_la_LIBADD = \
5437   sub1/libsub1.la \
5438   sub2/libsub2.la \
5439   @dots{}
5440 @end example
5441
5442 @samp{EXTRA_*_SOURCES} variables are used to keep track of source
5443 files that might be compiled (this is mostly useful when doing
5444 conditional compilation using @code{AC_SUBST}, @pxref{Conditional
5445 Libtool Sources}), and the @code{nodist_} prefix means the listed
5446 sources are not to be distributed (@pxref{Program and Library
5447 Variables}).  In effect the file @file{dummy.cxx} does not need to
5448 exist in the source tree.  Of course if you have some real source file
5449 to list in @code{libtop_la_SOURCES} there is no point in cheating with
5450 @code{nodist_EXTRA_libtop_la_SOURCES}.
5451
5452
5453 @node Libtool Modules
5454 @subsection Libtool Modules
5455 @cindex modules, libtool
5456 @cindex libtool modules
5457 @cindex @option{-module}, libtool
5458
5459 These are libtool libraries meant to be dlopened.  They are
5460 indicated to libtool by passing @option{-module} at link-time.
5461
5462 @example
5463 pkglib_LTLIBRARIES = mymodule.la
5464 mymodule_la_SOURCES = doit.c
5465 mymodule_la_LDFLAGS = -module
5466 @end example
5467
5468 Ordinarily, Automake requires that a library's name start with
5469 @code{lib}.  However, when building a dynamically loadable module you
5470 might wish to use a "nonstandard" name.  Automake will not complain
5471 about such nonstandard names if it knows the library being built is a
5472 libtool module, i.e., if @option{-module} explicitly appears in the
5473 library's @code{_LDFLAGS} variable (or in the common @code{AM_LDFLAGS}
5474 variable when no per-library @code{_LDFLAGS} variable is defined).
5475
5476 As always, @code{AC_SUBST} variables are black boxes to Automake since
5477 their values are not yet known when @command{automake} is run.
5478 Therefore if @option{-module} is set via such a variable, Automake
5479 cannot notice it and will proceed as if the library was an ordinary
5480 libtool library, with strict naming.
5481
5482 If @code{mymodule_la_SOURCES} is not specified, then it defaults to
5483 the single file @file{mymodule.c} (@pxref{Default _SOURCES}).
5484
5485 @node Libtool Flags
5486 @subsection @code{_LIBADD}, @code{_LDFLAGS}, and @code{_LIBTOOLFLAGS}
5487 @cindex @code{_LIBADD}, libtool
5488 @cindex @code{_LDFLAGS}, libtool
5489 @cindex @code{_LIBTOOLFLAGS}, libtool
5490 @vindex AM_LIBTOOLFLAGS
5491 @vindex LIBTOOLFLAGS
5492 @vindex maude_LIBTOOLFLAGS
5493
5494 As shown in previous sections, the @samp{@var{library}_LIBADD}
5495 variable should be used to list extra libtool objects (@file{.lo}
5496 files) or libtool libraries (@file{.la}) to add to @var{library}.
5497
5498 The @samp{@var{library}_LDFLAGS} variable is the place to list
5499 additional libtool linking flags, such as @option{-version-info},
5500 @option{-static}, and a lot more.  @xref{Link mode, , Link mode,
5501 libtool, The Libtool Manual}.
5502
5503 The @command{libtool} command has two kinds of options: mode-specific
5504 options and generic options.  Mode-specific options such as the
5505 aforementioned linking flags should be lumped with the other flags
5506 passed to the tool invoked by @command{libtool} (hence the use of
5507 @samp{@var{library}_LDFLAGS} for libtool linking flags).  Generic
5508 options include @option{--tag=@var{tag}} and @option{--silent}
5509 (@pxref{Invoking libtool, , Invoking @command{libtool}, libtool, The
5510 Libtool Manual} for more options) should appear before the mode
5511 selection on the command line; in @file{Makefile.am}s they should
5512 be listed in the @samp{@var{library}_LIBTOOLFLAGS} variable.
5513
5514 If @samp{@var{library}_LIBTOOLFLAGS} is not defined, then the variable
5515 @code{AM_LIBTOOLFLAGS} is used instead.
5516
5517 These flags are passed to libtool after the @option{--tag=@var{tag}}
5518 option computed by Automake (if any), so
5519 @samp{@var{library}_LIBTOOLFLAGS} (or @code{AM_LIBTOOLFLAGS}) is a
5520 good place to override or supplement the @option{--tag=@var{tag}}
5521 setting.
5522
5523 The libtool rules also use a @code{LIBTOOLFLAGS} variable that should
5524 not be set in @file{Makefile.am}: this is a user variable (@pxref{Flag
5525 Variables Ordering}.  It allows users to run @samp{make
5526 LIBTOOLFLAGS=--silent}, for instance.  Note that the verbosity of
5527 @command{libtool} can also be influenced with the Automake
5528 @option{silent-rules} option (@pxref{Options}).
5529
5530
5531 @node LTLIBOBJS, Libtool Issues, Libtool Flags, A Shared Library
5532 @subsection @code{LTLIBOBJS} and @code{LTALLOCA}
5533 @cindex @code{LTLIBOBJS}, special handling
5534 @cindex @code{LIBOBJS}, and Libtool
5535 @cindex @code{LTALLOCA}, special handling
5536 @cindex @code{ALLOCA}, and Libtool
5537 @vindex LTLIBOBJS
5538 @vindex LIBOBJS
5539 @vindex LTALLOCA
5540 @vindex ALLOCA
5541 @acindex AC_LIBOBJ
5542
5543 Where an ordinary library might include @samp{$(LIBOBJS)} or
5544 @samp{$(ALLOCA)} (@pxref{LIBOBJS}), a libtool library must use
5545 @samp{$(LTLIBOBJS)} or @samp{$(LTALLOCA)}.  This is required because
5546 the object files that libtool operates on do not necessarily end in
5547 @file{.o}.
5548
5549 Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
5550 performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
5551 @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual}).
5552
5553 @node Libtool Issues
5554 @subsection Common Issues Related to Libtool's Use
5555
5556 @menu
5557 * Error required file ltmain.sh not found::  The need to run libtoolize
5558 * Objects created both with libtool and without::  Avoid a specific build race
5559 @end menu
5560
5561 @node Error required file ltmain.sh not found
5562 @subsubsection Error: @samp{required file `./ltmain.sh' not found}
5563 @cindex @file{ltmain.sh} not found
5564 @cindex @command{libtoolize}, no longer run by @command{automake}
5565 @cindex @command{libtoolize} and @command{autoreconf}
5566 @cindex @command{autoreconf} and @command{libtoolize}
5567 @cindex @file{bootstrap.sh} and @command{autoreconf}
5568 @cindex @file{autogen.sh} and @command{autoreconf}
5569
5570 Libtool comes with a tool called @command{libtoolize} that will
5571 install libtool's supporting files into a package.  Running this
5572 command will install @file{ltmain.sh}.  You should execute it before
5573 @command{aclocal} and @command{automake}.
5574
5575 People upgrading old packages to newer autotools are likely to face
5576 this issue because older Automake versions used to call
5577 @command{libtoolize}.  Therefore old build scripts do not call
5578 @command{libtoolize}.
5579
5580 Since Automake 1.6, it has been decided that running
5581 @command{libtoolize} was none of Automake's business.  Instead, that
5582 functionality has been moved into the @command{autoreconf} command
5583 (@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
5584 The Autoconf Manual}).  If you do not want to remember what to run and
5585 when, just learn the @command{autoreconf} command.  Hopefully,
5586 replacing existing @file{bootstrap.sh} or @file{autogen.sh} scripts by
5587 a call to @command{autoreconf} should also free you from any similar
5588 incompatible change in the future.
5589
5590 @node Objects created both with libtool and without
5591 @subsubsection Objects @samp{created with both libtool and without}
5592
5593 Sometimes, the same source file is used both to build a libtool
5594 library and to build another non-libtool target (be it a program or
5595 another library).
5596
5597 Let's consider the following @file{Makefile.am}.
5598
5599 @example
5600 bin_PROGRAMS = prog
5601 prog_SOURCES = prog.c foo.c @dots{}
5602
5603 lib_LTLIBRARIES = libfoo.la
5604 libfoo_la_SOURCES = foo.c @dots{}
5605 @end example
5606
5607 @noindent
5608 (In this trivial case the issue could be avoided by linking
5609 @file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
5610 @code{prog_SOURCES}.  But let's assume we really want to keep
5611 @file{prog} and @file{libfoo.la} separate.)
5612
5613 Technically, it means that we should build @file{foo.$(OBJEXT)} for
5614 @file{prog}, and @file{foo.lo} for @file{libfoo.la}.  The problem is
5615 that in the course of creating @file{foo.lo}, libtool may erase (or
5616 replace) @file{foo.$(OBJEXT)}, and this cannot be avoided.
5617
5618 Therefore, when Automake detects this situation it will complain
5619 with a message such as
5620 @example
5621 object `foo.$(OBJEXT)' created both with libtool and without
5622 @end example
5623
5624 A workaround for this issue is to ensure that these two objects get
5625 different basenames.  As explained in @ref{Renamed Objects}, this
5626 happens automatically when per-targets flags are used.
5627
5628 @example
5629 bin_PROGRAMS = prog
5630 prog_SOURCES = prog.c foo.c @dots{}
5631 prog_CFLAGS = $(AM_CFLAGS)
5632
5633 lib_LTLIBRARIES = libfoo.la
5634 libfoo_la_SOURCES = foo.c @dots{}
5635 @end example
5636
5637 @noindent
5638 Adding @samp{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
5639 when the @code{prog_CFLAGS} is defined, it is used instead of
5640 @code{AM_CFLAGS}.  However as a side effect it will cause
5641 @file{prog.c} and @file{foo.c} to be compiled as
5642 @file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)}, which solves
5643 the issue.
5644
5645 @node Program and Library Variables
5646 @section Program and Library Variables
5647
5648 Associated with each program is a collection of variables that can be
5649 used to modify how that program is built.  There is a similar list of
5650 such variables for each library.  The canonical name of the program (or
5651 library) is used as a base for naming these variables.
5652
5653 In the list below, we use the name ``maude'' to refer to the program or
5654 library.  In your @file{Makefile.am} you would replace this with the
5655 canonical name of your program.  This list also refers to ``maude'' as a
5656 program, but in general the same rules apply for both static and dynamic
5657 libraries; the documentation below notes situations where programs and
5658 libraries differ.
5659
5660 @vtable @code
5661 @item maude_SOURCES
5662 This variable, if it exists, lists all the source files that are
5663 compiled to build the program.  These files are added to the
5664 distribution by default.  When building the program, Automake will cause
5665 each source file to be compiled to a single @file{.o} file (or
5666 @file{.lo} when using libtool).  Normally these object files are named
5667 after the source file, but other factors can change this.  If a file in
5668 the @code{_SOURCES} variable has an unrecognized extension, Automake
5669 will do one of two things with it.  If a suffix rule exists for turning
5670 files with the unrecognized extension into @file{.o} files, then
5671 @command{automake} will treat this file as it will any other source file
5672 (@pxref{Support for Other Languages}).  Otherwise, the file will be
5673 ignored as though it were a header file.
5674
5675 The prefixes @code{dist_} and @code{nodist_} can be used to control
5676 whether files listed in a @code{_SOURCES} variable are distributed.
5677 @code{dist_} is redundant, as sources are distributed by default, but it
5678 can be specified for clarity if desired.
5679
5680 It is possible to have both @code{dist_} and @code{nodist_} variants of
5681 a given @code{_SOURCES} variable at once; this lets you easily
5682 distribute some files and not others, for instance:
5683
5684 @example
5685 nodist_maude_SOURCES = nodist.c
5686 dist_maude_SOURCES = dist-me.c
5687 @end example
5688
5689 By default the output file (on Unix systems, the @file{.o} file) will
5690 be put into the current build directory.  However, if the option
5691 @option{subdir-objects} is in effect in the current directory then the
5692 @file{.o} file will be put into the subdirectory named after the
5693 source file.  For instance, with @option{subdir-objects} enabled,
5694 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
5695 people prefer this mode of operation.  You can specify
5696 @option{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
5697 @cindex Subdirectory, objects in
5698 @cindex Objects in subdirectory
5699
5700
5701 @item EXTRA_maude_SOURCES
5702 Automake needs to know the list of files you intend to compile
5703 @emph{statically}.  For one thing, this is the only way Automake has of
5704 knowing what sort of language support a given @file{Makefile.in}
5705 requires.  @footnote{There are other, more obscure reasons for
5706 this limitation as well.}  This means that, for example, you can't put a
5707 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
5708 variable.  If you intend to conditionally compile source files and use
5709 @file{configure} to substitute the appropriate object names into, e.g.,
5710 @code{_LDADD} (see below), then you should list the corresponding source
5711 files in the @code{EXTRA_} variable.
5712
5713 This variable also supports @code{dist_} and @code{nodist_} prefixes.
5714 For instance, @code{nodist_EXTRA_maude_SOURCES} would list extra
5715 sources that may need to be built, but should not be distributed.
5716
5717 @item maude_AR
5718 A static library is created by default by invoking @samp{$(AR)
5719 $(ARFLAGS)} followed by the name of the library and then the objects
5720 being put into the library.  You can override this by setting the
5721 @code{_AR} variable.  This is usually used with C++; some C++
5722 compilers require a special invocation in order to instantiate all the
5723 templates that should go into a library.  For instance, the SGI C++
5724 compiler likes this variable set like so:
5725 @example
5726 libmaude_a_AR = $(CXX) -ar -o
5727 @end example
5728
5729 @item maude_LIBADD
5730 Extra objects can be added to a @emph{library} using the @code{_LIBADD}
5731 variable.  For instance, this should be used for objects determined by
5732 @command{configure} (@pxref{A Library}).
5733
5734 In the case of libtool libraries, @code{maude_LIBADD} can also refer
5735 to other libtool libraries.
5736
5737 @item maude_LDADD
5738 Extra objects (@file{*.$(OBJEXT)}) and libraries (@file{*.a},
5739 @file{*.la}) can be added to a @emph{program} by listing them in the
5740 @code{_LDADD} variable.  For instance, this should be used for objects
5741 determined by @command{configure} (@pxref{Linking}).
5742
5743 @code{_LDADD} and @code{_LIBADD} are inappropriate for passing
5744 program-specific linker flags (except for @option{-l}, @option{-L},
5745 @option{-dlopen} and @option{-dlpreopen}).  Use the @code{_LDFLAGS} variable
5746 for this purpose.
5747
5748 For instance, if your @file{configure.ac} uses @code{AC_PATH_XTRA}, you
5749 could link your program against the X libraries like so:
5750
5751 @example
5752 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
5753 @end example
5754
5755 We recommend that you use @option{-l} and @option{-L} only when
5756 referring to third-party libraries, and give the explicit file names
5757 of any library built by your package.  Doing so will ensure that
5758 @code{maude_DEPENDENCIES} (see below) is correctly defined by default.
5759
5760 @item maude_LDFLAGS
5761 This variable is used to pass extra flags to the link step of a program
5762 or a shared library.  It overrides the @code{AM_LDFLAGS} variable.
5763
5764 @item maude_LIBTOOLFLAGS
5765 This variable is used to pass extra options to @command{libtool}.
5766 It overrides the @code{AM_LIBTOOLFLAGS} variable.
5767 These options are output before @command{libtool}'s @option{--mode=@var{mode}}
5768 option, so they should not be mode-specific options (those belong to
5769 the compiler or linker flags).  @xref{Libtool Flags}.
5770
5771 @item maude_DEPENDENCIES
5772 @itemx EXTRA_maude_DEPENDENCIES
5773 It is also occasionally useful to have a target (program or library)
5774 depend on some other file that is not actually part of that target.
5775 This can be done using the @code{_DEPENDENCIES} variable.  Each
5776 target depends on the contents of such a variable, but no further
5777 interpretation is done.
5778
5779 Since these dependencies are associated to the link rule used to
5780 create the programs they should normally list files used by the link
5781 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la} files
5782 for programs; @file{*.lo} and @file{*.la} files for Libtool libraries;
5783 and @file{*.$(OBJEXT)} files for static libraries.  In rare cases you
5784 may need to add other kinds of files such as linker scripts, but
5785 @emph{listing a source file in @code{_DEPENDENCIES} is wrong}.  If
5786 some source file needs to be built before all the components of a
5787 program are built, consider using the @code{BUILT_SOURCES} variable
5788 (@pxref{Sources}).
5789
5790 If @code{_DEPENDENCIES} is not supplied, it is computed by Automake.
5791 The automatically-assigned value is the contents of @code{_LDADD} or
5792 @code{_LIBADD}, with most configure substitutions, @option{-l}, @option{-L},
5793 @option{-dlopen} and @option{-dlpreopen} options removed.  The configure
5794 substitutions that are left in are only @samp{$(LIBOBJS)} and
5795 @samp{$(ALLOCA)}; these are left because it is known that they will not
5796 cause an invalid value for @code{_DEPENDENCIES} to be generated.
5797
5798 @code{_DEPENDENCIES} is more likely used to perform conditional
5799 compilation using an @code{AC_SUBST} variable that contains a list of
5800 objects.  @xref{Conditional Sources}, and @ref{Conditional Libtool
5801 Sources}.
5802
5803 The @code{EXTRA_*_DEPENDENCIES} variable may be useful for cases where
5804 you merely want to augment the @command{automake}-generated
5805 @code{_DEPENDENCIES} variable rather than replacing it.
5806
5807 @item maude_LINK
5808 You can override the linker on a per-program basis.  By default the
5809 linker is chosen according to the languages used by the program.  For
5810 instance, a program that includes C++ source code would use the C++
5811 compiler to link.  The @code{_LINK} variable must hold the name of a
5812 command that can be passed all the @file{.o} file names and libraries
5813 to link against as arguments.  Note that the name of the underlying
5814 program is @emph{not} passed to @code{_LINK}; typically one uses
5815 @samp{$@@}:
5816
5817 @example
5818 maude_LINK = $(CCLD) -magic -o $@@
5819 @end example
5820
5821 If a @code{_LINK} variable is not supplied, it may still be generated
5822 and used by Automake due to the use of per-target link flags such as
5823 @code{_CFLAGS}, @code{_LDFLAGS} or @code{_LIBTOOLFLAGS}, in cases where
5824 they apply.
5825
5826 @item maude_CCASFLAGS
5827 @itemx maude_CFLAGS
5828 @itemx maude_CPPFLAGS
5829 @itemx maude_CXXFLAGS
5830 @itemx maude_FFLAGS
5831 @itemx maude_GCJFLAGS
5832 @itemx maude_LFLAGS
5833 @itemx maude_OBJCFLAGS
5834 @itemx maude_RFLAGS
5835 @itemx maude_UPCFLAGS
5836 @itemx maude_YFLAGS
5837 @cindex per-target compilation flags, defined
5838 Automake allows you to set compilation flags on a per-program (or
5839 per-library) basis.  A single source file can be included in several
5840 programs, and it will potentially be compiled with different flags for
5841 each program.  This works for any language directly supported by
5842 Automake.  These @dfn{per-target compilation flags} are
5843 @samp{_CCASFLAGS},
5844 @samp{_CFLAGS},
5845 @samp{_CPPFLAGS},
5846 @samp{_CXXFLAGS},
5847 @samp{_FFLAGS},
5848 @samp{_GCJFLAGS},
5849 @samp{_LFLAGS},
5850 @samp{_OBJCFLAGS},
5851 @samp{_RFLAGS},
5852 @samp{_UPCFLAGS}, and
5853 @samp{_YFLAGS}.
5854
5855 When using a per-target compilation flag, Automake will choose a
5856 different name for the intermediate object files.  Ordinarily a file
5857 like @file{sample.c} will be compiled to produce @file{sample.o}.
5858 However, if the program's @code{_CFLAGS} variable is set, then the
5859 object file will be named, for instance, @file{maude-sample.o}.  (See
5860 also @ref{Renamed Objects}.)  The use of per-target compilation flags
5861 with C sources requires that the macro @code{AM_PROG_CC_C_O} be called
5862 from @file{configure.ac}.
5863
5864 In compilations with per-target flags, the ordinary @samp{AM_} form of
5865 the flags variable is @emph{not} automatically included in the
5866 compilation (however, the user form of the variable @emph{is} included).
5867 So for instance, if you want the hypothetical @file{maude} compilations
5868 to also use the value of @code{AM_CFLAGS}, you would need to write:
5869
5870 @example
5871 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
5872 @end example
5873
5874 @xref{Flag Variables Ordering}, for more discussion about the
5875 interaction between user variables, @samp{AM_} shadow variables, and
5876 per-target variables.
5877
5878 @item maude_SHORTNAME
5879 On some platforms the allowable file names are very short.  In order to
5880 support these systems and per-target compilation flags at the same
5881 time, Automake allows you to set a ``short name'' that will influence
5882 how intermediate object files are named.  For instance, in the following
5883 example,
5884
5885 @example
5886 bin_PROGRAMS = maude
5887 maude_CPPFLAGS = -DSOMEFLAG
5888 maude_SHORTNAME = m
5889 maude_SOURCES = sample.c @dots{}
5890 @end example
5891
5892 @noindent
5893 the object file would be named @file{m-sample.o} rather than
5894 @file{maude-sample.o}.
5895
5896 This facility is rarely needed in practice,
5897 and we recommend avoiding it until you find it is required.
5898 @end vtable
5899
5900 @node Default _SOURCES
5901 @section Default @code{_SOURCES}
5902
5903 @vindex _SOURCES
5904 @vindex SOURCES
5905 @cindex @code{_SOURCES}, default
5906 @cindex default @code{_SOURCES}
5907 @vindex AM_DEFAULT_SOURCE_EXT
5908
5909 @code{_SOURCES} variables are used to specify source files of programs
5910 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
5911 libraries (@pxref{A Shared Library}).
5912
5913 When no such variable is specified for a target, Automake will define
5914 one itself.  The default is to compile a single C file whose base name
5915 is the name of the target itself, with any extension replaced by
5916 @code{AM_DEFAULT_SOURCE_EXT}, which defaults to @file{.c}.
5917
5918 For example if you have the following somewhere in your
5919 @file{Makefile.am} with no corresponding @code{libfoo_a_SOURCES}:
5920
5921 @example
5922 lib_LIBRARIES = libfoo.a sub/libc++.a
5923 @end example
5924
5925 @noindent
5926 @file{libfoo.a} will be built using a default source file named
5927 @file{libfoo.c}, and @file{sub/libc++.a} will be built from
5928 @file{sub/libc++.c}.  (In older versions @file{sub/libc++.a}
5929 would be built from @file{sub_libc___a.c}, i.e., the default source
5930 was the canonized name of the target, with @file{.c} appended.
5931 We believe the new behavior is more sensible, but for backward
5932 compatibility @command{automake} will use the old name if a file or a rule
5933 with that name exists and @code{AM_DEFAULT_SOURCE_EXT} is not used.)
5934
5935 @cindex @code{check_PROGRAMS} example
5936 @vindex check_PROGRAMS
5937 Default sources are mainly useful in test suites, when building many
5938 test programs each from a single source.  For instance, in
5939
5940 @example
5941 check_PROGRAMS = test1 test2 test3
5942 AM_DEFAULT_SOURCE_EXT = .cpp
5943 @end example
5944
5945 @noindent
5946 @file{test1}, @file{test2}, and @file{test3} will be built
5947 from @file{test1.cpp}, @file{test2.cpp}, and @file{test3.cpp}.
5948 Without the last line, they will be built from @file{test1.c},
5949 @file{test2.c}, and @file{test3.c}.
5950
5951 @cindex Libtool modules, default source example
5952 @cindex default source, Libtool modules example
5953 Another case where this is convenient is building many Libtool modules
5954 (@file{module@var{n}.la}), each defined in its own file
5955 (@file{module@var{n}.c}).
5956
5957 @example
5958 AM_LDFLAGS = -module
5959 lib_LTLIBRARIES = module1.la module2.la module3.la
5960 @end example
5961
5962 @cindex empty @code{_SOURCES}
5963 @cindex @code{_SOURCES}, empty
5964 Finally, there is one situation where this default source computation
5965 needs to be avoided: when a target should not be built from sources.
5966 We already saw such an example in @ref{true}; this happens when all
5967 the constituents of a target have already been compiled and just need
5968 to be combined using a @code{_LDADD} variable.  Then it is necessary
5969 to define an empty @code{_SOURCES} variable, so that @command{automake}
5970 does not compute a default.
5971
5972 @example
5973 bin_PROGRAMS = target
5974 target_SOURCES =
5975 target_LDADD = libmain.a libmisc.a
5976 @end example
5977
5978 @node LIBOBJS
5979 @section Special handling for @code{LIBOBJS} and @code{ALLOCA}
5980
5981 @cindex @code{LIBOBJS}, example
5982 @cindex @code{ALLOCA}, example
5983 @cindex @code{LIBOBJS}, special handling
5984 @cindex @code{ALLOCA}, special handling
5985 @vindex LTLIBOBJS
5986 @vindex LIBOBJS
5987 @vindex LTALLOCA
5988 @vindex ALLOCA
5989
5990 The @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} variables list object
5991 files that should be compiled into the project to provide an
5992 implementation for functions that are missing or broken on the host
5993 system.  They are substituted by @file{configure}.
5994
5995 @acindex AC_LIBOBJ
5996
5997 These variables are defined by Autoconf macros such as
5998 @code{AC_LIBOBJ}, @code{AC_REPLACE_FUNCS} (@pxref{Generic Functions, ,
5999 Generic Function Checks, autoconf, The Autoconf Manual}), or
6000 @code{AC_FUNC_ALLOCA} (@pxref{Particular Functions, , Particular
6001 Function Checks, autoconf, The Autoconf Manual}).  Many other Autoconf
6002 macros call @code{AC_LIBOBJ} or @code{AC_REPLACE_FUNCS} to
6003 populate @samp{$(LIBOBJS)}.
6004
6005 @acindex AC_LIBSOURCE
6006
6007 Using these variables is very similar to doing conditional compilation
6008 using @code{AC_SUBST} variables, as described in @ref{Conditional
6009 Sources}.  That is, when building a program, @samp{$(LIBOBJS)} and
6010 @samp{$(ALLOCA)} should be added to the associated @samp{*_LDADD}
6011 variable, or to the @samp{*_LIBADD} variable when building a library.
6012 However there is no need to list the corresponding sources in
6013 @samp{EXTRA_*_SOURCES} nor to define @samp{*_DEPENDENCIES}.  Automake
6014 automatically adds @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} to the
6015 dependencies, and it will discover the list of corresponding source
6016 files automatically (by tracing the invocations of the
6017 @code{AC_LIBSOURCE} Autoconf macros).  If you have already defined
6018 @samp{*_DEPENDENCIES} explicitly for an unrelated reason, then you
6019 either need to add these variables manually, or use
6020 @samp{EXTRA_*_DEPENDENCIES} instead of @samp{*_DEPENDENCIES}.
6021
6022 These variables are usually used to build a portability library that
6023 is linked with all the programs of the project.  We now review a
6024 sample setup.  First, @file{configure.ac} contains some checks that
6025 affect either @code{LIBOBJS} or @code{ALLOCA}.
6026
6027 @example
6028 # configure.ac
6029 @dots{}
6030 AC_CONFIG_LIBOBJ_DIR([lib])
6031 @dots{}
6032 AC_FUNC_MALLOC             dnl May add malloc.$(OBJEXT) to LIBOBJS
6033 AC_FUNC_MEMCMP             dnl May add memcmp.$(OBJEXT) to LIBOBJS
6034 AC_REPLACE_FUNCS([strdup]) dnl May add strdup.$(OBJEXT) to LIBOBJS
6035 AC_FUNC_ALLOCA             dnl May add alloca.$(OBJEXT) to ALLOCA
6036 @dots{}
6037 AC_CONFIG_FILES([
6038   lib/Makefile
6039   src/Makefile
6040 ])
6041 AC_OUTPUT
6042 @end example
6043
6044 @acindex AC_CONFIG_LIBOBJ_DIR
6045
6046 The @code{AC_CONFIG_LIBOBJ_DIR} tells Autoconf that the source files
6047 of these object files are to be found in the @file{lib/} directory.
6048 Automake can also use this information, otherwise it expects the
6049 source files are to be in the directory where the @samp{$(LIBOBJS)}
6050 and @samp{$(ALLOCA)} variables are used.
6051
6052 The @file{lib/} directory should therefore contain @file{malloc.c},
6053 @file{memcmp.c}, @file{strdup.c}, @file{alloca.c}.  Here is its
6054 @file{Makefile.am}:
6055
6056 @example
6057 # lib/Makefile.am
6058
6059 noinst_LIBRARIES = libcompat.a
6060 libcompat_a_SOURCES =
6061 libcompat_a_LIBADD = $(LIBOBJS) $(ALLOCA)
6062 @end example
6063
6064 The library can have any name, of course, and anyway it is not going
6065 to be installed: it just holds the replacement versions of the missing
6066 or broken functions so we can later link them in.  Many projects
6067 also include extra functions, specific to the project, in that
6068 library: they are simply added on the @code{_SOURCES} line.
6069
6070 @cindex Empty libraries and @samp{$(LIBOBJS)}
6071 @cindex @samp{$(LIBOBJS)} and empty libraries
6072 There is a small trap here, though: @samp{$(LIBOBJS)} and
6073 @samp{$(ALLOCA)} might be empty, and building an empty library is not
6074 portable.  You should ensure that there is always something to put in
6075 @file{libcompat.a}.  Most projects will also add some utility
6076 functions in that directory, and list them in
6077 @code{libcompat_a_SOURCES}, so in practice @file{libcompat.a} cannot
6078 be empty.
6079
6080 Finally here is how this library could be used from the @file{src/}
6081 directory.
6082
6083 @example
6084 # src/Makefile.am
6085
6086 # Link all programs in this directory with libcompat.a
6087 LDADD = ../lib/libcompat.a
6088
6089 bin_PROGRAMS = tool1 tool2 @dots{}
6090 tool1_SOURCES = @dots{}
6091 tool2_SOURCES = @dots{}
6092 @end example
6093
6094 When option @option{subdir-objects} is not used, as in the above
6095 example, the variables @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} can only
6096 be used in the directory where their sources lie.  E.g., here it would
6097 be wrong to use @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} in
6098 @file{src/Makefile.am}.  However if both @option{subdir-objects} and
6099 @code{AC_CONFIG_LIBOBJ_DIR} are used, it is OK to use these variables
6100 in other directories.  For instance @file{src/Makefile.am} could be
6101 changed as follows.
6102
6103 @example
6104 # src/Makefile.am
6105
6106 AUTOMAKE_OPTIONS = subdir-objects
6107 LDADD = $(LIBOBJS) $(ALLOCA)
6108
6109 bin_PROGRAMS = tool1 tool2 @dots{}
6110 tool1_SOURCES = @dots{}
6111 tool2_SOURCES = @dots{}
6112 @end example
6113
6114 Because @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} contain object
6115 file names that end with @samp{.$(OBJEXT)}, they are not suitable for
6116 Libtool libraries (where the expected object extension is @file{.lo}):
6117 @code{LTLIBOBJS} and @code{LTALLOCA} should be used instead.
6118
6119 @code{LTLIBOBJS} is defined automatically by Autoconf and should not
6120 be defined by hand (as in the past), however at the time of writing
6121 @code{LTALLOCA} still needs to be defined from @code{ALLOCA} manually.
6122 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
6123 autoconf, The Autoconf Manual}.
6124
6125
6126 @node Program Variables
6127 @section Variables used when building a program
6128
6129 Occasionally it is useful to know which @file{Makefile} variables
6130 Automake uses for compilations, and in which order (@pxref{Flag
6131 Variables Ordering}); for instance, you might need to do your own
6132 compilation in some special cases.
6133
6134 Some variables are inherited from Autoconf; these are @code{CC},
6135 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
6136 @code{LIBS}.
6137 @vindex CC
6138 @vindex CFLAGS
6139 @vindex CPPFLAGS
6140 @vindex DEFS
6141 @vindex LDFLAGS
6142 @vindex LIBS
6143
6144 There are some additional variables that Automake defines on its own:
6145
6146 @vtable @code
6147 @item AM_CPPFLAGS
6148 The contents of this variable are passed to every compilation that invokes
6149 the C preprocessor; it is a list of arguments to the preprocessor.  For
6150 instance, @option{-I} and @option{-D} options should be listed here.
6151
6152 Automake already provides some @option{-I} options automatically, in a
6153 separate variable that is also passed to every compilation that invokes
6154 the C preprocessor.  In particular it generates @samp{-I.},
6155 @samp{-I$(srcdir)}, and a @option{-I} pointing to the directory holding
6156 @file{config.h} (if you've used @code{AC_CONFIG_HEADERS} or
6157 @code{AM_CONFIG_HEADER}).  You can disable the default @option{-I}
6158 options using the @option{nostdinc} option.
6159
6160 When a file to be included is generated during the build and not part
6161 of a distribution tarball, its location is under @code{$(builddir)},
6162 not under @code{$(srcdir)}.  This matters especially for packages that
6163 use header files placed in sub-directories and want to allow builds
6164 outside the source tree (@pxref{VPATH Builds}). In that case we
6165 recommend to use a pair of @option{-I} options, such as, e.g.,
6166 @samp{-Isome/subdir -I$(srcdir)/some/subdir} or
6167 @samp{-I$(top_builddir)/some/subdir -I$(top_srcdir)/some/subdir}.
6168 Note that the reference to the build tree should come before the
6169 reference to the source tree, so that accidentally leftover generated
6170 files in the source directory are ignored.
6171
6172 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
6173 per-library) @code{_CPPFLAGS} variable if it is defined.
6174
6175 @item INCLUDES
6176 This does the same job as @code{AM_CPPFLAGS} (or any per-target
6177 @code{_CPPFLAGS} variable if it is used).  It is an older name for the
6178 same functionality.  This variable is deprecated; we suggest using
6179 @code{AM_CPPFLAGS} and per-target @code{_CPPFLAGS} instead.
6180
6181 @item AM_CFLAGS
6182 This is the variable the @file{Makefile.am} author can use to pass
6183 in additional C compiler flags.  It is more fully documented elsewhere.
6184 In some situations, this is not used, in preference to the
6185 per-executable (or per-library) @code{_CFLAGS}.
6186
6187 @item COMPILE
6188 This is the command used to actually compile a C source file.  The
6189 file name is appended to form the complete command line.
6190
6191 @item AM_LDFLAGS
6192 This is the variable the @file{Makefile.am} author can use to pass
6193 in additional linker flags.  In some situations, this is not used, in
6194 preference to the per-executable (or per-library) @code{_LDFLAGS}.
6195
6196 @item LINK
6197 This is the command used to actually link a C program.  It already
6198 includes @samp{-o $@@} and the usual variable references (for instance,
6199 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
6200 and libraries to link in.  This variable is not used when the linker is
6201 overridden with a per-target @code{_LINK} variable or per-target flags
6202 cause Automake to define such a @code{_LINK} variable.
6203 @end vtable
6204
6205
6206 @node Yacc and Lex
6207 @section Yacc and Lex support
6208
6209 Automake has somewhat idiosyncratic support for Yacc and Lex.
6210
6211 Automake assumes that the @file{.c} file generated by @command{yacc}
6212 (or @command{lex}) should be named using the basename of the input
6213 file.  That is, for a yacc source file @file{foo.y}, Automake will
6214 cause the intermediate file to be named @file{foo.c} (as opposed to
6215 @file{y.tab.c}, which is more traditional).
6216
6217 The extension of a yacc source file is used to determine the extension
6218 of the resulting C or C++ file.  Files with the extension @file{.y}
6219 will be turned into @file{.c} files; likewise, @file{.yy} will become
6220 @file{.cc}; @file{.y++}, @file{c++}; @file{.yxx}, @file{.cxx}; and
6221 @file{.ypp}, @file{.cpp}.
6222
6223 Likewise, lex source files can be used to generate C or C++; the
6224 extensions @file{.l}, @file{.ll}, @file{.l++}, @file{.lxx}, and
6225 @file{.lpp} are recognized.
6226
6227 You should never explicitly mention the intermediate (C or C++) file
6228 in any @code{SOURCES} variable; only list the source file.
6229
6230 The intermediate files generated by @command{yacc} (or @command{lex})
6231 will be included in any distribution that is made.  That way the user
6232 doesn't need to have @command{yacc} or @command{lex}.
6233
6234 If a @command{yacc} source file is seen, then your @file{configure.ac} must
6235 define the variable @code{YACC}.  This is most easily done by invoking
6236 the macro @code{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
6237 Program Checks, autoconf, The Autoconf Manual}).
6238
6239 @vindex YFLAGS
6240 @vindex AM_YFLAGS
6241 When @code{yacc} is invoked, it is passed @code{AM_YFLAGS} and
6242 @code{YFLAGS}.  The latter is a user variable and the former is
6243 intended for the @file{Makefile.am} author.
6244
6245 @code{AM_YFLAGS} is usually used to pass the @option{-d} option to
6246 @command{yacc}.  Automake knows what this means and will automatically
6247 adjust its rules to update and distribute the header file built by
6248 @samp{yacc -d}@footnote{Please note that @command{automake} recognizes
6249 @option{-d} in @code{AM_YFLAGS} only if it is not clustered with other
6250 options; for example, it won't be recognized if @code{AM_YFLAGS} is
6251 @option{-dt}, but it will be if @code{AM_YFLAGS} is @option{-d -t} or
6252 @option{-d -t}}.
6253 What Automake cannot guess, though, is where this
6254 header will be used: it is up to you to ensure the header gets built
6255 before it is first used.  Typically this is necessary in order for
6256 dependency tracking to work when the header is included by another
6257 file.  The common solution is listing the header file in
6258 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
6259
6260 @example
6261 BUILT_SOURCES = parser.h
6262 AM_YFLAGS = -d
6263 bin_PROGRAMS = foo
6264 foo_SOURCES = @dots{} parser.y @dots{}
6265 @end example
6266
6267 If a @command{lex} source file is seen, then your @file{configure.ac}
6268 must define the variable @code{LEX}.  You can use @code{AC_PROG_LEX}
6269 to do this (@pxref{Particular Programs, , Particular Program Checks,
6270 autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
6271 (@pxref{Macros}) is recommended.
6272
6273 @vindex LFLAGS
6274 @vindex AM_LFLAGS
6275 When @command{lex} is invoked, it is passed @code{AM_LFLAGS} and
6276 @code{LFLAGS}.  The latter is a user variable and the former is
6277 intended for the @file{Makefile.am} author.
6278
6279 When @code{AM_MAINTAINER_MODE} (@pxref{maintainer-mode}) is used, the
6280 rebuild rule for distributed Yacc and Lex sources are only used when
6281 @code{maintainer-mode} is enabled, or when the files have been erased.
6282
6283 @cindex @command{ylwrap}
6284 @cindex @command{yacc}, multiple parsers
6285 @cindex Multiple @command{yacc} parsers
6286 @cindex Multiple @command{lex} lexers
6287 @cindex @command{lex}, multiple lexers
6288
6289 When @command{lex} or @command{yacc} sources are used, @code{automake
6290 -i} automatically installs an auxiliary program called
6291 @command{ylwrap} in your package (@pxref{Auxiliary Programs}).  This
6292 program is used by the build rules to rename the output of these
6293 tools, and makes it possible to include multiple @command{yacc} (or
6294 @command{lex}) source files in a single directory.  (This is necessary
6295 because yacc's output file name is fixed, and a parallel make could
6296 conceivably invoke more than one instance of @command{yacc}
6297 simultaneously.)
6298
6299 For @command{yacc}, simply managing locking is insufficient.  The output of
6300 @command{yacc} always uses the same symbol names internally, so it isn't
6301 possible to link two @command{yacc} parsers into the same executable.
6302
6303 We recommend using the following renaming hack used in @command{gdb}:
6304 @example
6305 #define yymaxdepth c_maxdepth
6306 #define yyparse c_parse
6307 #define yylex   c_lex
6308 #define yyerror c_error
6309 #define yylval  c_lval
6310 #define yychar  c_char
6311 #define yydebug c_debug
6312 #define yypact  c_pact
6313 #define yyr1    c_r1
6314 #define yyr2    c_r2
6315 #define yydef   c_def
6316 #define yychk   c_chk
6317 #define yypgo   c_pgo
6318 #define yyact   c_act
6319 #define yyexca  c_exca
6320 #define yyerrflag c_errflag
6321 #define yynerrs c_nerrs
6322 #define yyps    c_ps
6323 #define yypv    c_pv
6324 #define yys     c_s
6325 #define yy_yys  c_yys
6326 #define yystate c_state
6327 #define yytmp   c_tmp
6328 #define yyv     c_v
6329 #define yy_yyv  c_yyv
6330 #define yyval   c_val
6331 #define yylloc  c_lloc
6332 #define yyreds  c_reds
6333 #define yytoks  c_toks
6334 #define yylhs   c_yylhs
6335 #define yylen   c_yylen
6336 #define yydefred c_yydefred
6337 #define yydgoto  c_yydgoto
6338 #define yysindex c_yysindex
6339 #define yyrindex c_yyrindex
6340 #define yygindex c_yygindex
6341 #define yytable  c_yytable
6342 #define yycheck  c_yycheck
6343 #define yyname   c_yyname
6344 #define yyrule   c_yyrule
6345 @end example
6346
6347 For each define, replace the @samp{c_} prefix with whatever you like.
6348 These defines work for @command{bison}, @command{byacc}, and
6349 traditional @code{yacc}s.  If you find a parser generator that uses a
6350 symbol not covered here, please report the new name so it can be added
6351 to the list.
6352
6353
6354 @node C++ Support
6355 @section C++ Support
6356
6357 @cindex C++ support
6358 @cindex Support for C++
6359
6360 Automake includes full support for C++.
6361
6362 Any package including C++ code must define the output variable
6363 @code{CXX} in @file{configure.ac}; the simplest way to do this is to use
6364 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
6365 Program Checks, autoconf, The Autoconf Manual}).
6366
6367 A few additional variables are defined when a C++ source file is seen:
6368
6369 @vtable @code
6370 @item CXX
6371 The name of the C++ compiler.
6372
6373 @item CXXFLAGS
6374 Any flags to pass to the C++ compiler.
6375
6376 @item AM_CXXFLAGS
6377 The maintainer's variant of @code{CXXFLAGS}.
6378
6379 @item CXXCOMPILE
6380 The command used to actually compile a C++ source file.  The file name
6381 is appended to form the complete command line.
6382
6383 @item CXXLINK
6384 The command used to actually link a C++ program.
6385 @end vtable
6386
6387
6388 @node Objective C Support
6389 @section Objective C Support
6390
6391 @cindex Objective C support
6392 @cindex Support for Objective C
6393
6394 Automake includes some support for Objective C.
6395
6396 Any package including Objective C code must define the output variable
6397 @code{OBJC} in @file{configure.ac}; the simplest way to do this is to use
6398 the @code{AC_PROG_OBJC} macro (@pxref{Particular Programs, , Particular
6399 Program Checks, autoconf, The Autoconf Manual}).
6400
6401 A few additional variables are defined when an Objective C source file
6402 is seen:
6403
6404 @vtable @code
6405 @item OBJC
6406 The name of the Objective C compiler.
6407
6408 @item OBJCFLAGS
6409 Any flags to pass to the Objective C compiler.
6410
6411 @item AM_OBJCFLAGS
6412 The maintainer's variant of @code{OBJCFLAGS}.
6413
6414 @item OBJCCOMPILE
6415 The command used to actually compile an Objective C source file.  The
6416 file name is appended to form the complete command line.
6417
6418 @item OBJCLINK
6419 The command used to actually link an Objective C program.
6420 @end vtable
6421
6422
6423 @node Unified Parallel C Support
6424 @section Unified Parallel C Support
6425
6426 @cindex Unified Parallel C support
6427 @cindex Support for Unified Parallel C
6428
6429 Automake includes some support for Unified Parallel C.
6430
6431 Any package including Unified Parallel C code must define the output
6432 variable @code{UPC} in @file{configure.ac}; the simplest way to do
6433 this is to use the @code{AM_PROG_UPC} macro (@pxref{Public Macros}).
6434
6435 A few additional variables are defined when a Unified Parallel C
6436 source file is seen:
6437
6438 @vtable @code
6439 @item UPC
6440 The name of the Unified Parallel C compiler.
6441
6442 @item UPCFLAGS
6443 Any flags to pass to the Unified Parallel C compiler.
6444
6445 @item AM_UPCFLAGS
6446 The maintainer's variant of @code{UPCFLAGS}.
6447
6448 @item UPCCOMPILE
6449 The command used to actually compile a Unified Parallel C source file.
6450 The file name is appended to form the complete command line.
6451
6452 @item UPCLINK
6453 The command used to actually link a Unified Parallel C program.
6454 @end vtable
6455
6456
6457 @node Assembly Support
6458 @section Assembly Support
6459
6460 Automake includes some support for assembly code.  There are two forms
6461 of assembler files: normal (@file{*.s}) and preprocessed by @code{CPP}
6462 (@file{*.S} or @file{*.sx}).
6463
6464 @vindex CCAS
6465 @vindex CCASFLAGS
6466 @vindex CPPFLAGS
6467 @vindex AM_CCASFLAGS
6468 @vindex AM_CPPFLAGS
6469 The variable @code{CCAS} holds the name of the compiler used to build
6470 assembly code.  This compiler must work a bit like a C compiler; in
6471 particular it must accept @option{-c} and @option{-o}.  The values of
6472 @code{CCASFLAGS} and @code{AM_CCASFLAGS} (or its per-target
6473 definition) is passed to the compilation.  For preprocessed files,
6474 @code{DEFS}, @code{DEFAULT_INCLUDES}, @code{INCLUDES}, @code{CPPFLAGS}
6475 and @code{AM_CPPFLAGS} are also used.
6476
6477 The autoconf macro @code{AM_PROG_AS} will define @code{CCAS} and
6478 @code{CCASFLAGS} for you (unless they are already set, it simply sets
6479 @code{CCAS} to the C compiler and @code{CCASFLAGS} to the C compiler
6480 flags), but you are free to define these variables by other means.
6481
6482 Only the suffixes @file{.s}, @file{.S}, and @file{.sx} are recognized by
6483 @command{automake} as being files containing assembly code.
6484
6485
6486 @node Fortran 77 Support
6487 @comment  node-name,  next,  previous,  up
6488 @section Fortran 77 Support
6489
6490 @cindex Fortran 77 support
6491 @cindex Support for Fortran 77
6492
6493 Automake includes full support for Fortran 77.
6494
6495 Any package including Fortran 77 code must define the output variable
6496 @code{F77} in @file{configure.ac}; the simplest way to do this is to use
6497 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
6498 Program Checks, autoconf, The Autoconf Manual}).
6499
6500 A few additional variables are defined when a Fortran 77 source file is
6501 seen:
6502
6503 @vtable @code
6504
6505 @item F77
6506 The name of the Fortran 77 compiler.
6507
6508 @item FFLAGS
6509 Any flags to pass to the Fortran 77 compiler.
6510
6511 @item AM_FFLAGS
6512 The maintainer's variant of @code{FFLAGS}.
6513
6514 @item RFLAGS
6515 Any flags to pass to the Ratfor compiler.
6516
6517 @item AM_RFLAGS
6518 The maintainer's variant of @code{RFLAGS}.
6519
6520 @item F77COMPILE
6521 The command used to actually compile a Fortran 77 source file.  The file
6522 name is appended to form the complete command line.
6523
6524 @item FLINK
6525 The command used to actually link a pure Fortran 77 program or shared
6526 library.
6527
6528 @end vtable
6529
6530 Automake can handle preprocessing Fortran 77 and Ratfor source files in
6531 addition to compiling them@footnote{Much, if not most, of the
6532 information in the following sections pertaining to preprocessing
6533 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
6534 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
6535 also contains some support for creating programs and shared libraries
6536 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
6537 Fortran 77 With C and C++}).
6538
6539 These issues are covered in the following sections.
6540
6541 @menu
6542 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
6543 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
6544 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
6545 @end menu
6546
6547
6548 @node Preprocessing Fortran 77
6549 @comment  node-name,  next,  previous,  up
6550 @subsection Preprocessing Fortran 77
6551
6552 @cindex Preprocessing Fortran 77
6553 @cindex Fortran 77, Preprocessing
6554 @cindex Ratfor programs
6555
6556 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
6557 rule runs just the preprocessor to convert a preprocessable Fortran 77
6558 or Ratfor source file into a strict Fortran 77 source file.  The precise
6559 command used is as follows:
6560
6561 @table @file
6562
6563 @item .F
6564 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6565 $(AM_FFLAGS) $(FFLAGS)}
6566
6567 @item .r
6568 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6569
6570 @end table
6571
6572
6573 @node Compiling Fortran 77 Files
6574 @comment  node-name,  next,  previous,  up
6575 @subsection Compiling Fortran 77 Files
6576
6577 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
6578 @file{N.r} by running the Fortran 77 compiler.  The precise command used
6579 is as follows:
6580
6581 @table @file
6582
6583 @item .f
6584 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
6585
6586 @item .F
6587 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6588 $(AM_FFLAGS) $(FFLAGS)}
6589
6590 @item .r
6591 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6592
6593 @end table
6594
6595
6596 @node Mixing Fortran 77 With C and C++
6597 @comment  node-name,  next,  previous,  up
6598 @subsection Mixing Fortran 77 With C and C++
6599
6600 @cindex Fortran 77, mixing with C and C++
6601 @cindex Mixing Fortran 77 with C and C++
6602 @cindex Linking Fortran 77 with C and C++
6603 @cindex cfortran
6604 @cindex Mixing Fortran 77 with C and/or C++
6605
6606 Automake currently provides @emph{limited} support for creating programs
6607 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
6608 However, there are many other issues related to mixing Fortran 77 with
6609 other languages that are @emph{not} (currently) handled by Automake, but
6610 that are handled by other packages@footnote{For example,
6611 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
6612 addresses all of these inter-language issues, and runs under nearly all
6613 Fortran 77, C and C++ compilers on nearly all platforms.  However,
6614 @command{cfortran} is not yet Free Software, but it will be in the next
6615 major release.}.
6616
6617 Automake can help in two ways:
6618
6619 @enumerate
6620 @item
6621 Automatic selection of the linker depending on which combinations of
6622 source code.
6623
6624 @item
6625 Automatic selection of the appropriate linker flags (e.g., @option{-L} and
6626 @option{-l}) to pass to the automatically selected linker in order to link
6627 in the appropriate Fortran 77 intrinsic and run-time libraries.
6628
6629 @cindex @code{FLIBS}, defined
6630 @vindex FLIBS
6631 These extra Fortran 77 linker flags are supplied in the output variable
6632 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro
6633 supplied with newer versions of Autoconf (Autoconf version 2.13 and
6634 later).  @xref{Fortran Compiler, , Fortran Compiler Characteristics,
6635 autoconf, The Autoconf Manual}.
6636 @end enumerate
6637
6638 If Automake detects that a program or shared library (as mentioned in
6639 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
6640 code that is a mixture of Fortran 77 and C and/or C++, then it requires
6641 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
6642 @file{configure.ac}, and that either @code{$(FLIBS)}
6643 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
6644 (for shared libraries) variables.  It is the responsibility of the
6645 person writing the @file{Makefile.am} to make sure that @samp{$(FLIBS)}
6646 appears in the appropriate @code{_LDADD} or
6647 @code{_LIBADD} variable.
6648
6649 @cindex Mixed language example
6650 @cindex Example, mixed language
6651
6652 For example, consider the following @file{Makefile.am}:
6653
6654 @example
6655 bin_PROGRAMS = foo
6656 foo_SOURCES  = main.cc foo.f
6657 foo_LDADD    = libfoo.la $(FLIBS)
6658
6659 pkglib_LTLIBRARIES = libfoo.la
6660 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
6661 libfoo_la_LIBADD   = $(FLIBS)
6662 @end example
6663
6664 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
6665 is mentioned in @file{configure.ac}.  Also, if @samp{$(FLIBS)} hadn't
6666 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
6667 Automake would have issued a warning.
6668
6669 @menu
6670 * How the Linker is Chosen::    Automatic linker selection
6671 @end menu
6672
6673 @node How the Linker is Chosen
6674 @comment  node-name,  next,  previous,  up
6675 @subsubsection How the Linker is Chosen
6676
6677 @cindex Automatic linker selection
6678 @cindex Selecting the linker automatically
6679
6680 When a program or library mixes several languages, Automake choose the
6681 linker according to the following priorities.  (The names in
6682 parentheses are the variables containing the link command.)
6683
6684 @enumerate
6685 @item
6686 @vindex GCJLINK
6687 Native Java (@code{GCJLINK})
6688 @item
6689 @vindex CXXLINK
6690 C++ (@code{CXXLINK})
6691 @item
6692 @vindex F77LINK
6693 Fortran 77 (@code{F77LINK})
6694 @item
6695 @vindex FCLINK
6696 Fortran (@code{FCLINK})
6697 @item
6698 @vindex OBJCLINK
6699 Objective C (@code{OBJCLINK})
6700 @item
6701 @vindex UPCLINK
6702 Unified Parallel C (@code{UPCLINK})
6703 @item
6704 @vindex LINK
6705 C (@code{LINK})
6706 @end enumerate
6707
6708 For example, if Fortran 77, C and C++ source code is compiled
6709 into a program, then the C++ linker will be used.  In this case, if the
6710 C or Fortran 77 linkers required any special libraries that weren't
6711 included by the C++ linker, then they must be manually added to an
6712 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
6713 @file{Makefile.am}.
6714
6715 Automake only looks at the file names listed in @file{_SOURCES}
6716 variables to choose the linker, and defaults to the C linker.
6717 Sometimes this is inconvenient because you are linking against a
6718 library written in another language and would like to set the linker
6719 more appropriately.  @xref{Libtool Convenience Libraries}, for a
6720 trick with @code{nodist_EXTRA_@dots{}_SOURCES}.
6721
6722 A per-target @code{_LINK} variable will override the above selection.
6723 Per-target link flags will cause Automake to write a per-target
6724 @code{_LINK} variable according to the language chosen as above.
6725
6726
6727 @node Fortran 9x Support
6728 @comment  node-name,  next,  previous,  up
6729 @section Fortran 9x Support
6730
6731 @cindex Fortran 9x support
6732 @cindex Support for Fortran 9x
6733
6734 Automake includes support for Fortran 9x.
6735
6736 Any package including Fortran 9x code must define the output variable
6737 @code{FC} in @file{configure.ac}; the simplest way to do this is to use
6738 the @code{AC_PROG_FC} macro (@pxref{Particular Programs, , Particular
6739 Program Checks, autoconf, The Autoconf Manual}).
6740
6741 A few additional variables are defined when a Fortran 9x source file is
6742 seen:
6743
6744 @vtable @code
6745
6746 @item FC
6747 The name of the Fortran 9x compiler.
6748
6749 @item FCFLAGS
6750 Any flags to pass to the Fortran 9x compiler.
6751
6752 @item AM_FCFLAGS
6753 The maintainer's variant of @code{FCFLAGS}.
6754
6755 @item FCCOMPILE
6756 The command used to actually compile a Fortran 9x source file.  The file
6757 name is appended to form the complete command line.
6758
6759 @item FCLINK
6760 The command used to actually link a pure Fortran 9x program or shared
6761 library.
6762
6763 @end vtable
6764
6765 @menu
6766 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
6767 @end menu
6768
6769 @node Compiling Fortran 9x Files
6770 @comment  node-name,  next,  previous,  up
6771 @subsection Compiling Fortran 9x Files
6772
6773 @file{@var{file}.o} is made automatically from @file{@var{file}.f90},
6774 @file{@var{file}.f95}, @file{@var{file}.f03}, or @file{@var{file}.f08}
6775 by running the Fortran 9x compiler.  The precise command used
6776 is as follows:
6777
6778 @table @file
6779
6780 @item .f90
6781 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f90) $<}
6782
6783 @item .f95
6784 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f95) $<}
6785
6786 @item .f03
6787 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f03) $<}
6788
6789 @item .f08
6790 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f08) $<}
6791
6792 @end table
6793
6794 @node Java Support with gcj
6795 @comment  node-name,  next,  previous,  up
6796 @section Compiling Java sources using gcj
6797
6798 @cindex Java support with gcj
6799 @cindex Support for Java with gcj
6800 @cindex Java to native code, compilation
6801 @cindex Compilation of Java to native code
6802
6803 Automake includes support for natively compiled Java, using @command{gcj},
6804 the Java front end to the GNU Compiler Collection (rudimentary support
6805 for compiling Java to bytecode using the @command{javac} compiler is
6806 also present, @emph{albeit deprecated}; @pxref{Java}).
6807
6808 Any package including Java code to be compiled must define the output
6809 variable @code{GCJ} in @file{configure.ac}; the variable @code{GCJFLAGS}
6810 must also be defined somehow (either in @file{configure.ac} or
6811 @file{Makefile.am}).  The simplest way to do this is to use the
6812 @code{AM_PROG_GCJ} macro.
6813
6814 @vindex GCJFLAGS
6815
6816 By default, programs including Java source files are linked with
6817 @command{gcj}.
6818
6819 As always, the contents of @code{AM_GCJFLAGS} are passed to every
6820 compilation invoking @command{gcj} (in its role as an ahead-of-time
6821 compiler, when invoking it to create @file{.class} files,
6822 @code{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
6823 options to @command{gcj} from @file{Makefile.am}, this variable, and not
6824 the user variable @code{GCJFLAGS}, should be used.
6825
6826 @vindex AM_GCJFLAGS
6827
6828 @command{gcj} can be used to compile @file{.java}, @file{.class},
6829 @file{.zip}, or @file{.jar} files.
6830
6831 When linking, @command{gcj} requires that the main class be specified
6832 using the @option{--main=} option.  The easiest way to do this is to use
6833 the @code{_LDFLAGS} variable for the program.
6834
6835
6836 @node Vala Support
6837 @comment  node-name,  next,  previous,  up
6838 @section Vala Support
6839
6840 @cindex Vala Support
6841 @cindex Support for Vala
6842
6843 Automake provides initial support for Vala
6844 (@uref{http://www.vala-project.org/}).
6845 This requires valac version 0.7.0 or later, and currently requires
6846 the user to use GNU @command{make}.
6847
6848 @example
6849 foo_SOURCES = foo.vala bar.vala zardoc.c
6850 @end example
6851
6852 Any @file{.vala} file listed in a @code{_SOURCES} variable will be
6853 compiled into C code by the Vala compiler. The generated @file{.c} files are
6854 distributed. The end user does not need to have a Vala compiler installed.
6855
6856 Automake ships with an Autoconf macro called @code{AM_PROG_VALAC}
6857 that will locate the Vala compiler and optionally check its version
6858 number.
6859
6860 @defmac AM_PROG_VALAC (@ovar{minimum-version})
6861 Try to find a Vala compiler in @env{PATH}. If it is found, the variable
6862 @code{VALAC} is set. Optionally a minimum release number of the compiler
6863 can be requested:
6864
6865 @example
6866 AM_PROG_VALAC([0.7.0])
6867 @end example
6868 @end defmac
6869
6870 There are a few variables that are used when compiling Vala sources:
6871
6872 @vtable @code
6873 @item VALAC
6874 Path to the Vala compiler.
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}), Fortran 77
6899 (@pxref{Fortran 77 Support}), Fortran 9x (@pxref{Fortran 9x Support}),
6900 and Java (@pxref{Java Support with gcj}).  There is only rudimentary
6901 support for other languages, support for which will be improved based
6902 on user demand.
6903
6904 Some limited support for adding your own languages is available via the
6905 suffix rule handling (@pxref{Suffixes}).
6906
6907
6908 @node ANSI
6909 @section Automatic de-ANSI-fication (deprecated, soon to be removed)
6910
6911 @cindex de-ANSI-fication, defined
6912
6913 @emph{The features described in this section are deprecated; you must
6914 not use any of them in new code, and remove their use from older but
6915 still maintained code: they will be withdrawn in the next major
6916 Automake release.}
6917
6918 When the C language was standardized in 1989, there was a long
6919 transition period where package developers needed to worry about
6920 porting to older systems that did not support ANSI C by default.
6921 These older systems are no longer in practical use and are no longer
6922 supported by their original suppliers, so developers need not worry
6923 about this problem any more.
6924
6925 Automake allows you to write packages that are portable to K&R C by
6926 @dfn{de-ANSI-fying} each source file before the actual compilation takes
6927 place.
6928
6929 @vindex AUTOMAKE_OPTIONS
6930 @opindex ansi2knr
6931
6932 If the @file{Makefile.am} variable @code{AUTOMAKE_OPTIONS}
6933 (@pxref{Options}) contains the option @option{ansi2knr} then code to
6934 handle de-ANSI-fication is inserted into the generated
6935 @file{Makefile.in}.
6936
6937 This causes each C source file in the directory to be treated as ANSI C@.
6938 If an ANSI C compiler is available, it is used.  If no ANSI C compiler
6939 is available, the @command{ansi2knr} program is used to convert the source
6940 files into K&R C, which is then compiled.
6941
6942 The @command{ansi2knr} program is simple-minded.  It assumes the source
6943 code will be formatted in a particular way; see the @command{ansi2knr} man
6944 page for details.
6945
6946 @acindex AM_C_PROTOTYPES
6947 Support for the obsolete de-ANSI-fication feature
6948 requires the source files @file{ansi2knr.c}
6949 and @file{ansi2knr.1} to be in the same package as the ANSI C source;
6950 these files are distributed with Automake.  Also, the package
6951 @file{configure.ac} must call the macro @code{AM_C_PROTOTYPES}
6952 (@pxref{Macros}).
6953
6954 Automake also handles finding the @command{ansi2knr} support files in some
6955 other directory in the current package.  This is done by prepending the
6956 relative path to the appropriate directory to the @command{ansi2knr}
6957 option.  For instance, suppose the package has ANSI C code in the
6958 @file{src} and @file{lib} subdirectories.  The files @file{ansi2knr.c} and
6959 @file{ansi2knr.1} appear in @file{lib}.  Then this could appear in
6960 @file{src/Makefile.am}:
6961
6962 @example
6963 AUTOMAKE_OPTIONS = ../lib/ansi2knr
6964 @end example
6965
6966 If no directory prefix is given, the files are assumed to be in the
6967 current directory.
6968
6969 Note that automatic de-ANSI-fication will not work when the package is
6970 being built for a different host architecture.  That is because
6971 @command{automake} currently has no way to build @command{ansi2knr}
6972 for the build machine.
6973
6974 @c FIXME: this paragraph might be better moved to an `upgrading' section.
6975 @cindex @code{LTLIBOBJS} and @code{ansi2knr}
6976 @cindex @code{LIBOBJS} and @code{ansi2knr}
6977 @cindex @code{ansi2knr} and @code{LTLIBOBJS}
6978 @cindex @code{ansi2knr} and @code{LIBOBJS}
6979 Using @code{LIBOBJS} with source de-ANSI-fication used to require
6980 hand-crafted code in @file{configure} to append @samp{$U} to basenames
6981 in @code{LIBOBJS}.  This is no longer true today.  Starting with version
6982 2.54, Autoconf takes care of rewriting @code{LIBOBJS} and
6983 @code{LTLIBOBJS}.  (@pxref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ}
6984 vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual})
6985
6986 @node Dependencies
6987 @section Automatic dependency tracking
6988
6989 As a developer it is often painful to continually update the
6990 @file{Makefile.am} whenever the include-file dependencies change in a
6991 project.  Automake supplies a way to automatically track dependency
6992 changes (@pxref{Dependency Tracking}).
6993
6994 @cindex Dependency tracking
6995 @cindex Automatic dependency tracking
6996
6997 Automake always uses complete dependencies for a compilation,
6998 including system headers.  Automake's model is that dependency
6999 computation should be a side effect of the build.  To this end,
7000 dependencies are computed by running all compilations through a
7001 special wrapper program called @command{depcomp}.  @command{depcomp}
7002 understands how to coax many different C and C++ compilers into
7003 generating dependency information in the format it requires.
7004 @samp{automake -a} will install @command{depcomp} into your source
7005 tree for you.  If @command{depcomp} can't figure out how to properly
7006 invoke your compiler, dependency tracking will simply be disabled for
7007 your build.
7008
7009 @cindex @command{depcomp}
7010
7011 Experience with earlier versions of Automake (@pxref{Dependency
7012 Tracking Evolution}) taught us that it is not reliable to generate
7013 dependencies only on the maintainer's system, as configurations vary
7014 too much.  So instead Automake implements dependency tracking at build
7015 time.
7016
7017 Automatic dependency tracking can be suppressed by putting
7018 @option{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
7019 passing @option{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
7020 (this should be the preferred way).  Or, you can invoke @command{automake}
7021 with the @option{-i} option.  Dependency tracking is enabled by default.
7022
7023 @vindex AUTOMAKE_OPTIONS
7024 @opindex no-dependencies
7025
7026 The person building your package also can choose to disable dependency
7027 tracking by configuring with @option{--disable-dependency-tracking}.
7028
7029 @cindex Disabling dependency tracking
7030 @cindex Dependency tracking, disabling
7031
7032
7033 @node EXEEXT
7034 @section Support for executable extensions
7035
7036 @cindex Executable extension
7037 @cindex Extension, executable
7038 @cindex Windows
7039
7040 On some platforms, such as Windows, executables are expected to have an
7041 extension such as @file{.exe}.  On these platforms, some compilers (GCC
7042 among them) will automatically generate @file{foo.exe} when asked to
7043 generate @file{foo}.
7044
7045 Automake provides mostly-transparent support for this.  Unfortunately
7046 @emph{mostly} doesn't yet mean @emph{fully}.  Until the English
7047 dictionary is revised, you will have to assist Automake if your package
7048 must support those platforms.
7049
7050 One thing you must be aware of is that, internally, Automake rewrites
7051 something like this:
7052
7053 @example
7054 bin_PROGRAMS = liver
7055 @end example
7056
7057 to this:
7058
7059 @example
7060 bin_PROGRAMS = liver$(EXEEXT)
7061 @end example
7062
7063 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
7064 extension.
7065
7066 The variables @code{TESTS} and @code{XFAIL_TESTS} (@pxref{Simple Tests})
7067 are also rewritten if they contain filenames that have been declared as
7068 programs in the same @file{Makefile}.  (This is mostly useful when some
7069 programs from @code{check_PROGRAMS} are listed in @code{TESTS}.)
7070
7071 However, Automake cannot apply this rewriting to @command{configure}
7072 substitutions.  This means that if you are conditionally building a
7073 program using such a substitution, then your @file{configure.ac} must
7074 take care to add @samp{$(EXEEXT)} when constructing the output variable.
7075
7076 With Autoconf 2.13 and earlier, you must explicitly use @code{AC_EXEEXT}
7077 to get this support.  With Autoconf 2.50, @code{AC_EXEEXT} is run
7078 automatically if you configure a compiler (say, through
7079 @code{AC_PROG_CC}).
7080
7081 Sometimes maintainers like to write an explicit link rule for their
7082 program.  Without executable extension support, this is easy---you
7083 simply write a rule whose target is the name of the program.  However,
7084 when executable extension support is enabled, you must instead add the
7085 @samp{$(EXEEXT)} suffix.
7086
7087 Unfortunately, due to the change in Autoconf 2.50, this means you must
7088 always add this extension.  However, this is a problem for maintainers
7089 who know their package will never run on a platform that has
7090 executable extensions.  For those maintainers, the @option{no-exeext}
7091 option (@pxref{Options}) will disable this feature.  This works in a
7092 fairly ugly way; if @option{no-exeext} is seen, then the presence of a
7093 rule for a target named @code{foo} in @file{Makefile.am} will override
7094 an @command{automake}-generated rule for @samp{foo$(EXEEXT)}.  Without
7095 the @option{no-exeext} option, this use will give a diagnostic.
7096
7097
7098 @node Other Objects
7099 @chapter Other Derived Objects
7100
7101 Automake can handle derived objects that are not C programs.  Sometimes
7102 the support for actually building such objects must be explicitly
7103 supplied, but Automake will still automatically handle installation and
7104 distribution.
7105
7106 @menu
7107 * Scripts::                     Executable scripts
7108 * Headers::                     Header files
7109 * Data::                        Architecture-independent data files
7110 * Sources::                     Derived sources
7111 @end menu
7112
7113
7114 @node Scripts
7115 @section Executable Scripts
7116
7117 @cindex @code{_SCRIPTS} primary, defined
7118 @cindex @code{SCRIPTS} primary, defined
7119 @cindex Primary variable, @code{SCRIPTS}
7120 @vindex _SCRIPTS
7121 @cindex Installing scripts
7122
7123 It is possible to define and install programs that are scripts.  Such
7124 programs are listed using the @code{SCRIPTS} primary name.  When the
7125 script is distributed in its final, installable form, the
7126 @file{Makefile} usually looks as follows:
7127 @vindex SCRIPTS
7128
7129 @example
7130 # Install my_script in $(bindir) and distribute it.
7131 dist_bin_SCRIPTS = my_script
7132 @end example
7133
7134 Scripts are not distributed by default; as we have just seen, those
7135 that should be distributed can be specified using a @code{dist_}
7136 prefix as with other primaries.
7137
7138 @cindex @code{SCRIPTS}, installation directories
7139 @vindex bin_SCRIPTS
7140 @vindex sbin_SCRIPTS
7141 @vindex libexec_SCRIPTS
7142 @vindex pkgdata_SCRIPTS
7143 @vindex pkglibexec_SCRIPTS
7144 @vindex noinst_SCRIPTS
7145 @vindex check_SCRIPTS
7146
7147 Scripts can be installed in @code{bindir}, @code{sbindir},
7148 @code{libexecdir}, @code{pkglibexecdir}, or @code{pkgdatadir}.
7149
7150 Scripts that need not be installed can be listed in
7151 @code{noinst_SCRIPTS}, and among them, those which are needed only by
7152 @samp{make check} should go in @code{check_SCRIPTS}.
7153
7154 When a script needs to be built, the @file{Makefile.am} should include
7155 the appropriate rules.  For instance the @command{automake} program
7156 itself is a Perl script that is generated from @file{automake.in}.
7157 Here is how this is handled:
7158
7159 @example
7160 bin_SCRIPTS = automake
7161 CLEANFILES = $(bin_SCRIPTS)
7162 EXTRA_DIST = automake.in
7163
7164 do_subst = sed -e 's,[@@]datadir[@@],$(datadir),g' \
7165             -e 's,[@@]PERL[@@],$(PERL),g' \
7166             -e 's,[@@]PACKAGE[@@],$(PACKAGE),g' \
7167             -e 's,[@@]VERSION[@@],$(VERSION),g' \
7168             @dots{}
7169
7170 automake: automake.in Makefile
7171         $(do_subst) < $(srcdir)/automake.in > automake
7172         chmod +x automake
7173 @end example
7174
7175 Such scripts for which a build rule has been supplied need to be
7176 deleted explicitly using @code{CLEANFILES} (@pxref{Clean}), and their
7177 sources have to be distributed, usually with @code{EXTRA_DIST}
7178 (@pxref{Basics of Distribution}).
7179
7180 Another common way to build scripts is to process them from
7181 @file{configure} with @code{AC_CONFIG_FILES}.  In this situation
7182 Automake knows which files should be cleaned and distributed, and what
7183 the rebuild rules should look like.
7184
7185 For instance if @file{configure.ac} contains
7186
7187 @example
7188 AC_CONFIG_FILES([src/my_script], [chmod +x src/my_script])
7189 @end example
7190
7191 @noindent
7192 to build @file{src/my_script} from @file{src/my_script.in}, then a
7193 @file{src/Makefile.am} to install this script in @code{$(bindir)} can
7194 be as simple as
7195
7196 @example
7197 bin_SCRIPTS = my_script
7198 CLEANFILES = $(bin_SCRIPTS)
7199 @end example
7200
7201 @noindent
7202 There is no need for @code{EXTRA_DIST} or any build rule: Automake
7203 infers them from @code{AC_CONFIG_FILES} (@pxref{Requirements}).
7204 @code{CLEANFILES} is still useful, because by default Automake will
7205 clean targets of @code{AC_CONFIG_FILES} in @code{distclean}, not
7206 @code{clean}.
7207
7208 Although this looks simpler, building scripts this way has one
7209 drawback: directory variables such as @code{$(datadir)} are not fully
7210 expanded and may refer to other directory variables.
7211
7212 @node Headers
7213 @section Header files
7214
7215 @cindex @code{_HEADERS} primary, defined
7216 @cindex @code{HEADERS} primary, defined
7217 @cindex Primary variable, @code{HEADERS}
7218 @vindex _HEADERS
7219 @vindex noinst_HEADERS
7220 @cindex @code{HEADERS}, installation directories
7221 @cindex Installing headers
7222 @vindex include_HEADERS
7223 @vindex oldinclude_HEADERS
7224 @vindex pkginclude_HEADERS
7225
7226
7227 Header files that must be installed are specified by the
7228 @code{HEADERS} family of variables.  Headers can be installed in
7229 @code{includedir}, @code{oldincludedir}, @code{pkgincludedir} or any
7230 other directory you may have defined (@pxref{Uniform}).  For instance,
7231
7232 @example
7233 include_HEADERS = foo.h bar/bar.h
7234 @end example
7235
7236 @noindent
7237 will install the two files as @file{$(includedir)/foo.h} and
7238 @file{$(includedir)/bar.h}.
7239
7240 The @code{nobase_} prefix is also supported,
7241
7242 @example
7243 nobase_include_HEADERS = foo.h bar/bar.h
7244 @end example
7245
7246 @noindent
7247 will install the two files as @file{$(includedir)/foo.h} and
7248 @file{$(includedir)/bar/bar.h} (@pxref{Alternative}).
7249
7250 @vindex noinst_HEADERS
7251 Usually, only header files that accompany installed libraries need to
7252 be installed.  Headers used by programs or convenience libraries are
7253 not installed.  The @code{noinst_HEADERS} variable can be used for
7254 such headers.  However when the header actually belongs to a single
7255 convenience library or program, we recommend listing it in the
7256 program's or library's @code{_SOURCES} variable (@pxref{Program
7257 Sources}) instead of in @code{noinst_HEADERS}.  This is clearer for
7258 the @file{Makefile.am} reader.  @code{noinst_HEADERS} would be the
7259 right variable to use in a directory containing only headers and no
7260 associated library or program.
7261
7262 All header files must be listed somewhere; in a @code{_SOURCES}
7263 variable or in a @code{_HEADERS} variable.  Missing ones will not
7264 appear in the distribution.
7265
7266 For header files that are built and must not be distributed, use the
7267 @code{nodist_} prefix as in @code{nodist_include_HEADERS} or
7268 @code{nodist_prog_SOURCES}.  If these generated headers are needed
7269 during the build, you must also ensure they exist before they are
7270 used (@pxref{Sources}).
7271
7272
7273 @node Data
7274 @section Architecture-independent data files
7275
7276 @cindex @code{_DATA} primary, defined
7277 @cindex @code{DATA} primary, defined
7278 @cindex Primary variable, @code{DATA}
7279 @vindex _DATA
7280
7281 Automake supports the installation of miscellaneous data files using the
7282 @code{DATA} family of variables.
7283 @vindex DATA
7284
7285 @vindex data_DATA
7286 @vindex sysconf_DATA
7287 @vindex sharedstate_DATA
7288 @vindex localstate_DATA
7289 @vindex pkgdata_DATA
7290
7291 Such data can be installed in the directories @code{datadir},
7292 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
7293 @code{pkgdatadir}.
7294
7295 By default, data files are @emph{not} included in a distribution.  Of
7296 course, you can use the @code{dist_} prefix to change this on a
7297 per-variable basis.
7298
7299 Here is how Automake declares its auxiliary data files:
7300
7301 @example
7302 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
7303 @end example
7304
7305
7306 @node Sources
7307 @section Built Sources
7308
7309 Because Automake's automatic dependency tracking works as a side-effect
7310 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
7311 target should not be compiled before its dependencies are made, but
7312 these dependencies are unknown until the target is first compiled.
7313
7314 Ordinarily this is not a problem, because dependencies are distributed
7315 sources: they preexist and do not need to be built.  Suppose that
7316 @file{foo.c} includes @file{foo.h}.  When it first compiles
7317 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
7318 @file{foo.c}.  As a side-effect of this compilation @command{depcomp}
7319 records the @file{foo.h} dependency so that following invocations of
7320 @command{make} will honor it.  In these conditions, it's clear there is
7321 no problem: either @file{foo.o} doesn't exist and has to be built
7322 (regardless of the dependencies), or accurate dependencies exist and
7323 they can be used to decide whether @file{foo.o} should be rebuilt.
7324
7325 It's a different story if @file{foo.h} doesn't exist by the first
7326 @command{make} run.  For instance, there might be a rule to build
7327 @file{foo.h}.  This time @file{file.o}'s build will fail because the
7328 compiler can't find @file{foo.h}.  @command{make} failed to trigger the
7329 rule to build @file{foo.h} first by lack of dependency information.
7330
7331 @vindex BUILT_SOURCES
7332 @cindex @code{BUILT_SOURCES}, defined
7333
7334 The @code{BUILT_SOURCES} variable is a workaround for this problem.  A
7335 source file listed in @code{BUILT_SOURCES} is made on @samp{make all}
7336 or @samp{make check} (or even @samp{make install}) before other
7337 targets are processed.  However, such a source file is not
7338 @emph{compiled} unless explicitly requested by mentioning it in some
7339 other @code{_SOURCES} variable.
7340
7341 So, to conclude our introductory example, we could use
7342 @samp{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
7343 any other target (including @file{foo.o}) during @samp{make all} or
7344 @samp{make check}.
7345
7346 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
7347 must be created early in the build process can be listed in this
7348 variable.  Moreover, all built sources do not necessarily have to be
7349 listed in @code{BUILT_SOURCES}.  For instance, a generated @file{.c} file
7350 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
7351 another source), because it's a known dependency of the associated
7352 object.
7353
7354 It might be important to emphasize that @code{BUILT_SOURCES} is
7355 honored only by @samp{make all}, @samp{make check} and @samp{make
7356 install}.  This means you cannot build a specific target (e.g.,
7357 @samp{make foo}) in a clean tree if it depends on a built source.
7358 However it will succeed if you have run @samp{make all} earlier,
7359 because accurate dependencies are already available.
7360
7361 The next section illustrates and discusses the handling of built sources
7362 on a toy example.
7363
7364 @menu
7365 * Built Sources Example::       Several ways to handle built sources.
7366 @end menu
7367
7368 @node Built Sources Example
7369 @subsection Built Sources Example
7370
7371 Suppose that @file{foo.c} includes @file{bindir.h}, which is
7372 installation-dependent and not distributed: it needs to be built.  Here
7373 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
7374 value of the @command{make} variable @code{bindir} (inherited from
7375 @file{configure}).
7376
7377 We suggest several implementations below.  It's not meant to be an
7378 exhaustive listing of all ways to handle built sources, but it will give
7379 you a few ideas if you encounter this issue.
7380
7381 @subsubheading First Try
7382
7383 This first implementation will illustrate the bootstrap issue mentioned
7384 in the previous section (@pxref{Sources}).
7385
7386 Here is a tentative @file{Makefile.am}.
7387
7388 @example
7389 # This won't work.
7390 bin_PROGRAMS = foo
7391 foo_SOURCES = foo.c
7392 nodist_foo_SOURCES = bindir.h
7393 CLEANFILES = bindir.h
7394 bindir.h: Makefile
7395         echo '#define bindir "$(bindir)"' >$@@
7396 @end example
7397
7398 This setup doesn't work, because Automake doesn't know that @file{foo.c}
7399 includes @file{bindir.h}.  Remember, automatic dependency tracking works
7400 as a side-effect of compilation, so the dependencies of @file{foo.o} will
7401 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
7402 The symptom is as follows.
7403
7404 @example
7405 % make
7406 source='foo.c' object='foo.o' libtool=no \
7407 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7408 depmode=gcc /bin/sh ./depcomp \
7409 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7410 foo.c:2: bindir.h: No such file or directory
7411 make: *** [foo.o] Error 1
7412 @end example
7413
7414 In this example @file{bindir.h} is not distributed nor installed, and
7415 it is not even being built on-time.  One may wonder if the
7416 @samp{nodist_foo_SOURCES = bindir.h} line has any use at all.  This
7417 line simply states that @file{bindir.h} is a source of @code{foo}, so
7418 for instance, it should be inspected while generating tags
7419 (@pxref{Tags}).  In other words, it does not help our present problem,
7420 and the build would fail identically without it.
7421
7422 @subsubheading Using @code{BUILT_SOURCES}
7423
7424 A solution is to require @file{bindir.h} to be built before anything
7425 else.  This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
7426
7427 @example
7428 bin_PROGRAMS = foo
7429 foo_SOURCES = foo.c
7430 nodist_foo_SOURCES = bindir.h
7431 BUILT_SOURCES = bindir.h
7432 CLEANFILES = bindir.h
7433 bindir.h: Makefile
7434         echo '#define bindir "$(bindir)"' >$@@
7435 @end example
7436
7437 See how @file{bindir.h} gets built first:
7438
7439 @example
7440 % make
7441 echo '#define bindir "/usr/local/bin"' >bindir.h
7442 make  all-am
7443 make[1]: Entering directory `/home/adl/tmp'
7444 source='foo.c' object='foo.o' libtool=no \
7445 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7446 depmode=gcc /bin/sh ./depcomp \
7447 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7448 gcc  -g -O2   -o foo  foo.o
7449 make[1]: Leaving directory `/home/adl/tmp'
7450 @end example
7451
7452 However, as said earlier, @code{BUILT_SOURCES} applies only to the
7453 @code{all}, @code{check}, and @code{install} targets.  It still fails
7454 if you try to run @samp{make foo} explicitly:
7455
7456 @example
7457 % make clean
7458 test -z "bindir.h" || rm -f bindir.h
7459 test -z "foo" || rm -f foo
7460 rm -f *.o
7461 % : > .deps/foo.Po # Suppress previously recorded dependencies
7462 % make foo
7463 source='foo.c' object='foo.o' libtool=no \
7464 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7465 depmode=gcc /bin/sh ./depcomp \
7466 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7467 foo.c:2: bindir.h: No such file or directory
7468 make: *** [foo.o] Error 1
7469 @end example
7470
7471 @subsubheading Recording Dependencies manually
7472
7473 Usually people are happy enough with @code{BUILT_SOURCES} because they
7474 never build targets such as @samp{make foo} before @samp{make all}, as
7475 in the previous example.  However if this matters to you, you can
7476 avoid @code{BUILT_SOURCES} and record such dependencies explicitly in
7477 the @file{Makefile.am}.
7478
7479 @example
7480 bin_PROGRAMS = foo
7481 foo_SOURCES = foo.c
7482 nodist_foo_SOURCES = bindir.h
7483 foo.$(OBJEXT): bindir.h
7484 CLEANFILES = bindir.h
7485 bindir.h: Makefile
7486         echo '#define bindir "$(bindir)"' >$@@
7487 @end example
7488
7489 You don't have to list @emph{all} the dependencies of @file{foo.o}
7490 explicitly, only those that might need to be built.  If a dependency
7491 already exists, it will not hinder the first compilation and will be
7492 recorded by the normal dependency tracking code.  (Note that after
7493 this first compilation the dependency tracking code will also have
7494 recorded the dependency between @file{foo.o} and
7495 @file{bindir.h}; so our explicit dependency is really useful to
7496 the first build only.)
7497
7498 Adding explicit dependencies like this can be a bit dangerous if you are
7499 not careful enough.  This is due to the way Automake tries not to
7500 overwrite your rules (it assumes you know better than it).
7501 @samp{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
7502 output to build @samp{foo.$(OBJEXT)}.  It happens to work in this case
7503 because Automake doesn't have to output any @samp{foo.$(OBJEXT):}
7504 target: it relies on a suffix rule instead (i.e., @samp{.c.$(OBJEXT):}).
7505 Always check the generated @file{Makefile.in} if you do this.
7506
7507 @subsubheading Build @file{bindir.h} from @file{configure}
7508
7509 It's possible to define this preprocessor macro from @file{configure},
7510 either in @file{config.h} (@pxref{Defining Directories, , Defining
7511 Directories, autoconf, The Autoconf Manual}), or by processing a
7512 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
7513 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
7514 Autoconf Manual}).
7515
7516 At this point it should be clear that building @file{bindir.h} from
7517 @file{configure} works well for this example.  @file{bindir.h} will exist
7518 before you build any target, hence will not cause any dependency issue.
7519
7520 The Makefile can be shrunk as follows.  We do not even have to mention
7521 @file{bindir.h}.
7522
7523 @example
7524 bin_PROGRAMS = foo
7525 foo_SOURCES = foo.c
7526 @end example
7527
7528 However, it's not always possible to build sources from
7529 @file{configure}, especially when these sources are generated by a tool
7530 that needs to be built first.
7531
7532 @subsubheading Build @file{bindir.c}, not @file{bindir.h}.
7533
7534 Another attractive idea is to define @code{bindir} as a variable or
7535 function exported from @file{bindir.o}, and build @file{bindir.c}
7536 instead of @file{bindir.h}.
7537
7538 @example
7539 noinst_PROGRAMS = foo
7540 foo_SOURCES = foo.c bindir.h
7541 nodist_foo_SOURCES = bindir.c
7542 CLEANFILES = bindir.c
7543 bindir.c: Makefile
7544         echo 'const char bindir[] = "$(bindir)";' >$@@
7545 @end example
7546
7547 @file{bindir.h} contains just the variable's declaration and doesn't
7548 need to be built, so it won't cause any trouble.  @file{bindir.o} is
7549 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
7550 first.
7551
7552 @subsubheading Which is best?
7553
7554 There is no panacea, of course.  Each solution has its merits and
7555 drawbacks.
7556
7557 You cannot use @code{BUILT_SOURCES} if the ability to run @samp{make
7558 foo} on a clean tree is important to you.
7559
7560 You won't add explicit dependencies if you are leery of overriding
7561 an Automake rule by mistake.
7562
7563 Building files from @file{./configure} is not always possible, neither
7564 is converting @file{.h} files into @file{.c} files.
7565
7566
7567 @node Other GNU Tools
7568 @chapter Other GNU Tools
7569
7570 Since Automake is primarily intended to generate @file{Makefile.in}s for
7571 use in GNU programs, it tries hard to interoperate with other GNU tools.
7572
7573 @menu
7574 * Emacs Lisp::                  Emacs Lisp
7575 * gettext::                     Gettext
7576 * Libtool::                     Libtool
7577 * Java::                        Java bytecode compilation (deprecated)
7578 * Python::                      Python
7579 @end menu
7580
7581
7582 @node Emacs Lisp
7583 @section Emacs Lisp
7584
7585 @cindex @code{_LISP} primary, defined
7586 @cindex @code{LISP} primary, defined
7587 @cindex Primary variable, @code{LISP}
7588
7589 @vindex _LISP
7590 @vindex lisp_LISP
7591 @vindex noinst_LISP
7592
7593 Automake provides some support for Emacs Lisp.  The @code{LISP} primary
7594 is used to hold a list of @file{.el} files.  Possible prefixes for this
7595 primary are @code{lisp_} and @code{noinst_}.  Note that if
7596 @code{lisp_LISP} is defined, then @file{configure.ac} must run
7597 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
7598
7599 @vindex dist_lisp_LISP
7600 @vindex dist_noinst_LISP
7601 Lisp sources are not distributed by default.  You can prefix the
7602 @code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
7603 @code{dist_noinst_LISP}, to indicate that these files should be
7604 distributed.
7605
7606 Automake will byte-compile all Emacs Lisp source files using the Emacs
7607 found by @code{AM_PATH_LISPDIR}, if any was found.
7608
7609 Byte-compiled Emacs Lisp files are not portable among all versions of
7610 Emacs, so it makes sense to turn this off if you expect sites to have
7611 more than one version of Emacs installed.  Furthermore, many packages
7612 don't actually benefit from byte-compilation.  Still, we recommend
7613 that you byte-compile your Emacs Lisp sources.  It is probably better
7614 for sites with strange setups to cope for themselves than to make the
7615 installation less nice for everybody else.
7616
7617 There are two ways to avoid byte-compiling.  Historically, we have
7618 recommended the following construct.
7619
7620 @example
7621 lisp_LISP = file1.el file2.el
7622 ELCFILES =
7623 @end example
7624
7625 @noindent
7626 @code{ELCFILES} is an internal Automake variable that normally lists
7627 all @file{.elc} files that must be byte-compiled.  Automake defines
7628 @code{ELCFILES} automatically from @code{lisp_LISP}.  Emptying this
7629 variable explicitly prevents byte-compilation.
7630
7631 Since Automake 1.8, we now recommend using @code{lisp_DATA} instead:
7632
7633 @c Keep in sync with primary-prefix-couples-documented-valid.test.
7634 @example
7635 lisp_DATA = file1.el file2.el
7636 @end example
7637
7638 Note that these two constructs are not equivalent.  @code{_LISP} will
7639 not install a file if Emacs is not installed, while @code{_DATA} will
7640 always install its files.
7641
7642 @node gettext
7643 @section Gettext
7644
7645 @cindex GNU Gettext support
7646 @cindex Gettext support
7647 @cindex Support for GNU Gettext
7648
7649 If @code{AM_GNU_GETTEXT} is seen in @file{configure.ac}, then Automake
7650 turns on support for GNU gettext, a message catalog system for
7651 internationalization
7652 (@pxref{Top, , Introduction, gettext, GNU gettext utilities}).
7653
7654 The @code{gettext} support in Automake requires the addition of one or
7655 two subdirectories to the package: @file{po} and possibly also @file{intl}.
7656 The latter is needed if @code{AM_GNU_GETTEXT} is not invoked with the
7657 @samp{external} argument, or if @code{AM_GNU_GETTEXT_INTL_SUBDIR} is used.
7658 Automake ensures that these directories exist and are mentioned in
7659 @code{SUBDIRS}.
7660
7661 @node Libtool
7662 @section Libtool
7663
7664 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
7665 libtool, The Libtool Manual}) with the @code{LTLIBRARIES} primary.
7666 @xref{A Shared Library}.
7667
7668
7669 @node Java
7670 @section Java bytecode compilation (deprecated)
7671
7672 @cindex @code{_JAVA} primary, defined
7673 @cindex @code{JAVA} primary, defined
7674 @cindex Primary variable, @code{JAVA}
7675 @cindex Java to bytecode, compilation
7676 @cindex Compilation of Java to bytecode
7677
7678 Automake provides some minimal support for Java bytecode compilation with
7679 the @code{JAVA} primary (in addition to the support for compiling Java to
7680 native machine code; @pxref{Java Support with gcj}).  Note however that
7681 @emph{the interface and most features described here are deprecated}; the
7682 next automake release will strive to provide a better and cleaner
7683 interface, which however @emph{won't be backward-compatible}; the present
7684 interface will probably be removed altogether in future automake releases
7685 (1.13 or later), so don't use it in new code.
7686
7687 Any @file{.java} files listed in a @code{_JAVA} variable will be
7688 compiled with @code{JAVAC} at build time.  By default, @file{.java}
7689 files are not included in the distribution, you should use the
7690 @code{dist_} prefix to distribute them.
7691
7692 Here is a typical setup for distributing @file{.java} files and
7693 installing the @file{.class} files resulting from their compilation.
7694
7695 @c Keep in sync with primary-prefix-couples-documented-valid.test.
7696 @example
7697 javadir = $(datadir)/java
7698 dist_java_JAVA = a.java b.java @dots{}
7699 @end example
7700
7701 @cindex @code{JAVA} restrictions
7702 @cindex Restrictions for @code{JAVA}
7703
7704 Currently Automake enforces the restriction that only one @code{_JAVA}
7705 primary can be used in a given @file{Makefile.am}.  The reason for this
7706 restriction is that, in general, it isn't possible to know which
7707 @file{.class} files were generated from which @file{.java} files, so
7708 it would be impossible to know which files to install where.  For
7709 instance, a @file{.java} file can define multiple classes; the resulting
7710 @file{.class} file names cannot be predicted without parsing the
7711 @file{.java} file.
7712
7713 There are a few variables that are used when compiling Java sources:
7714
7715 @vtable @code
7716 @item JAVAC
7717 The name of the Java compiler.  This defaults to @samp{javac}.
7718
7719 @item JAVACFLAGS
7720 The flags to pass to the compiler.  This is considered to be a user
7721 variable (@pxref{User Variables}).
7722
7723 @item AM_JAVACFLAGS
7724 More flags to pass to the Java compiler.  This, and not
7725 @code{JAVACFLAGS}, should be used when it is necessary to put Java
7726 compiler flags into @file{Makefile.am}.
7727
7728 @item JAVAROOT
7729 The value of this variable is passed to the @option{-d} option to
7730 @code{javac}.  It defaults to @samp{$(top_builddir)}.
7731
7732 @item CLASSPATH_ENV
7733 This variable is a shell expression that is used to set the
7734 @env{CLASSPATH} environment variable on the @code{javac} command line.
7735 (In the future we will probably handle class path setting differently.)
7736 @end vtable
7737
7738
7739 @node Python
7740 @section Python
7741
7742 @cindex @code{_PYTHON} primary, defined
7743 @cindex @code{PYTHON} primary, defined
7744 @cindex Primary variable, @code{PYTHON}
7745 @vindex _PYTHON
7746
7747 Automake provides support for Python compilation with the
7748 @code{PYTHON} primary.  A typical setup is to call
7749 @code{AM_PATH_PYTHON} in @file{configure.ac} and use a line like the
7750 following in @file{Makefile.am}:
7751
7752 @example
7753 python_PYTHON = tree.py leave.py
7754 @end example
7755
7756 Any files listed in a @code{_PYTHON} variable will be byte-compiled
7757 with @command{py-compile} at install time.  @command{py-compile}
7758 actually creates both standard (@file{.pyc}) and optimized
7759 (@file{.pyo}) byte-compiled versions of the source files.  Note that
7760 because byte-compilation occurs at install time, any files listed in
7761 @code{noinst_PYTHON} will not be compiled.  Python source files are
7762 included in the distribution by default, prepend @code{nodist_} (as in
7763 @code{nodist_python_PYTHON}) to omit them.
7764
7765 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON}
7766 that will determine some Python-related directory variables (see
7767 below).  If you have called @code{AM_PATH_PYTHON} from
7768 @file{configure.ac}, then you may use the variables
7769 @c Keep in sync with primary-prefix-couples-documented-valid.test.
7770 @code{python_PYTHON} or @code{pkgpython_PYTHON} to list Python source
7771 files in your @file{Makefile.am}, depending on where you want your files
7772 installed (see the definitions of @code{pythondir} and
7773 @code{pkgpythondir} below).
7774
7775 @defmac AM_PATH_PYTHON (@ovar{version}, @ovar{action-if-found},
7776   @ovar{action-if-not-found})
7777
7778 Search for a Python interpreter on the system.  This macro takes three
7779 optional arguments.  The first argument, if present, is the minimum
7780 version of Python required for this package: @code{AM_PATH_PYTHON}
7781 will skip any Python interpreter that is older than @var{version}.
7782 If an interpreter is found and satisfies @var{version}, then
7783 @var{action-if-found} is run.  Otherwise, @var{action-if-not-found} is
7784 run.
7785
7786 If @var{action-if-not-found} is not specified, as in the following
7787 example, the default is to abort @command{configure}.
7788
7789 @example
7790 AM_PATH_PYTHON([2.2])
7791 @end example
7792
7793 @noindent
7794 This is fine when Python is an absolute requirement for the package.
7795 If Python >= 2.5 was only @emph{optional} to the package,
7796 @code{AM_PATH_PYTHON} could be called as follows.
7797
7798 @example
7799 AM_PATH_PYTHON([2.5],, [:])
7800 @end example
7801
7802 If the @env{PYTHON} variable is set when @code{AM_PATH_PYTHON} is
7803 called, then that will be the only Python interpreter that is tried.
7804
7805 @code{AM_PATH_PYTHON} creates the following output variables based on
7806 the Python installation found during configuration.
7807 @end defmac
7808
7809 @vtable @code
7810 @item PYTHON
7811 The name of the Python executable, or @samp{:} if no suitable
7812 interpreter could be found.
7813
7814 Assuming @var{action-if-not-found} is used (otherwise @file{./configure}
7815 will abort if Python is absent), the value of @code{PYTHON} can be used
7816 to setup a conditional in order to disable the relevant part of a build
7817 as follows.
7818
7819 @example
7820 AM_PATH_PYTHON(,, [:])
7821 AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
7822 @end example
7823
7824 @item PYTHON_VERSION
7825 The Python version number, in the form @var{major}.@var{minor}
7826 (e.g., @samp{2.5}).  This is currently the value of
7827 @samp{sys.version[:3]}.
7828
7829 @item PYTHON_PREFIX
7830 The string @samp{$@{prefix@}}.  This term may be used in future work
7831 that needs the contents of Python's @samp{sys.prefix}, but general
7832 consensus is to always use the value from @command{configure}.
7833
7834 @item PYTHON_EXEC_PREFIX
7835 The string @samp{$@{exec_prefix@}}.  This term may be used in future work
7836 that needs the contents of Python's @samp{sys.exec_prefix}, but general
7837 consensus is to always use the value from @command{configure}.
7838
7839 @item PYTHON_PLATFORM
7840 The canonical name used by Python to describe the operating system, as
7841 given by @samp{sys.platform}.  This value is sometimes needed when
7842 building Python extensions.
7843
7844 @item pythondir
7845 The directory name for the @file{site-packages} subdirectory of the
7846 standard Python install tree.
7847
7848 @item pkgpythondir
7849 This is the directory under @code{pythondir} that is named after the
7850 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
7851 as a convenience.
7852
7853 @item pyexecdir
7854 This is the directory where Python extension modules (shared libraries)
7855 should be installed.  An extension module written in C could be declared
7856 as follows to Automake:
7857
7858 @c Keep in sync with primary-prefix-couples-documented-valid.test.
7859 @example
7860 pyexec_LTLIBRARIES = quaternion.la
7861 quaternion_la_SOURCES = quaternion.c support.c support.h
7862 quaternion_la_LDFLAGS = -avoid-version -module
7863 @end example
7864
7865 @item pkgpyexecdir
7866 This is a convenience variable that is defined as
7867 @samp{$(pyexecdir)/$(PACKAGE)}.
7868 @end vtable
7869
7870 All these directory variables have values that start with either
7871 @samp{$@{prefix@}} or @samp{$@{exec_prefix@}} unexpanded.  This works
7872 fine in @file{Makefiles}, but it makes these variables hard to use in
7873 @file{configure}.  This is mandated by the GNU coding standards, so
7874 that the user can run @samp{make prefix=/foo install}.  The Autoconf
7875 manual has a section with more details on this topic
7876 (@pxref{Installation Directory Variables, , Installation Directory
7877 Variables, autoconf, The Autoconf Manual}).  See also @ref{Hard-Coded
7878 Install Paths}.
7879
7880
7881 @node Documentation
7882 @chapter Building documentation
7883
7884 Currently Automake provides support for Texinfo and man pages.
7885
7886 @menu
7887 * Texinfo::                     Texinfo
7888 * Man Pages::                   Man pages
7889 @end menu
7890
7891
7892 @node Texinfo
7893 @section Texinfo
7894
7895 @cindex @code{_TEXINFOS} primary, defined
7896 @cindex @code{TEXINFOS} primary, defined
7897 @cindex Primary variable, @code{TEXINFOS}
7898 @cindex HTML output using Texinfo
7899 @cindex PDF output using Texinfo
7900 @cindex PS output using Texinfo
7901 @cindex DVI output using Texinfo
7902 @vindex _TEXINFOS
7903 @vindex info_TEXINFOS
7904
7905 If the current directory contains Texinfo source, you must declare it
7906 with the @code{TEXINFOS} primary.  Generally Texinfo files are converted
7907 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
7908 here.  Any Texinfo source file must end in the @file{.texi},
7909 @file{.txi}, or @file{.texinfo} extension.  We recommend @file{.texi}
7910 for new manuals.
7911
7912 Automake generates rules to build @file{.info}, @file{.dvi},
7913 @file{.ps}, @file{.pdf} and @file{.html} files from your Texinfo
7914 sources.  Following the GNU Coding Standards, only the @file{.info}
7915 files are built by @samp{make all} and installed by @samp{make
7916 install} (unless you use @option{no-installinfo}, see below).
7917 Furthermore, @file{.info} files are automatically distributed so that
7918 Texinfo is not a prerequisite for installing your package.
7919
7920 @trindex dvi
7921 @trindex html
7922 @trindex pdf
7923 @trindex ps
7924 @trindex install-dvi
7925 @trindex install-html
7926 @trindex install-pdf
7927 @trindex install-ps
7928 Other documentation formats can be built on request by @samp{make
7929 dvi}, @samp{make ps}, @samp{make pdf} and @samp{make html}, and they
7930 can be installed with @samp{make install-dvi}, @samp{make install-ps},
7931 @samp{make install-pdf} and @samp{make install-html} explicitly.
7932 @samp{make uninstall} will remove everything: the Texinfo
7933 documentation installed by default as well as all the above optional
7934 formats.
7935
7936 All these targets can be extended using @samp{-local} rules
7937 (@pxref{Extending}).
7938
7939 @cindex Texinfo flag, @code{VERSION}
7940 @cindex Texinfo flag, @code{UPDATED}
7941 @cindex Texinfo flag, @code{EDITION}
7942 @cindex Texinfo flag, @code{UPDATED-MONTH}
7943
7944 @cindex @code{VERSION} Texinfo flag
7945 @cindex @code{UPDATED} Texinfo flag
7946 @cindex @code{EDITION} Texinfo flag
7947 @cindex @code{UPDATED-MONTH} Texinfo flag
7948
7949 @cindex @file{mdate-sh}
7950
7951 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
7952 that file will be automatically generated.  The file @file{version.texi}
7953 defines four Texinfo flag you can reference using
7954 @code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
7955 @code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
7956
7957 @table @code
7958 @item EDITION
7959 @itemx VERSION
7960 Both of these flags hold the version number of your program.  They are
7961 kept separate for clarity.
7962
7963 @item UPDATED
7964 This holds the date the primary @file{.texi} file was last modified.
7965
7966 @item UPDATED-MONTH
7967 This holds the name of the month in which the primary @file{.texi} file
7968 was last modified.
7969 @end table
7970
7971 The @file{version.texi} support requires the @command{mdate-sh}
7972 script; this script is supplied with Automake and automatically
7973 included when @command{automake} is invoked with the
7974 @option{--add-missing} option.
7975
7976 If you have multiple Texinfo files, and you want to use the
7977 @file{version.texi} feature, then you have to have a separate version
7978 file for each Texinfo file.  Automake will treat any include in a
7979 Texinfo file that matches @file{vers*.texi} just as an automatically
7980 generated version file.
7981
7982 Sometimes an info file actually depends on more than one @file{.texi}
7983 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
7984 @file{fdl.texi}.  You can tell Automake about these dependencies using
7985 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
7986 @vindex TEXINFOS
7987 @vindex _TEXINFOS
7988
7989 @example
7990 info_TEXINFOS = hello.texi
7991 hello_TEXINFOS = fdl.texi
7992 @end example
7993
7994 @cindex @file{texinfo.tex}
7995
7996 By default, Automake requires the file @file{texinfo.tex} to appear in
7997 the same directory as the @file{Makefile.am} file that lists the
7998 @file{.texi} files.  If you used @code{AC_CONFIG_AUX_DIR} in
7999 @file{configure.ac} (@pxref{Input, , Finding `configure' Input,
8000 autoconf, The Autoconf Manual}), then @file{texinfo.tex} is looked for
8001 there.  In both cases, @command{automake} then supplies @file{texinfo.tex} if
8002 @option{--add-missing} is given, and takes care of its distribution.
8003 However, if you set the @code{TEXINFO_TEX} variable (see below),
8004 it overrides the location of the file and turns off its installation
8005 into the source as well as its distribution.
8006
8007 The option @option{no-texinfo.tex} can be used to eliminate the
8008 requirement for the file @file{texinfo.tex}.  Use of the variable
8009 @code{TEXINFO_TEX} is preferable, however, because that allows the
8010 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
8011
8012 @cindex Option, @code{no-installinfo}
8013 @cindex Target, @code{install-info}
8014 @cindex @code{install-info} target
8015 @cindex @code{no-installinfo} option
8016
8017 @opindex no-installinfo
8018 @trindex install-info
8019
8020 Automake generates an @code{install-info} rule; some people apparently
8021 use this.  By default, info pages are installed by @samp{make
8022 install}, so running @code{make install-info} is pointless.  This can
8023 be prevented via the @code{no-installinfo} option.  In this case,
8024 @file{.info} files are not installed by default, and user must
8025 request this explicitly using @samp{make install-info}.
8026
8027 @vindex AM_UPDATE_INFO_DIR
8028 By default, @code{make install-info} will try to run the
8029 @command{install-info} program (if available) to update (or create)
8030 the @file{@code{$@{infodir@}}/dir} index.  If this is undesired, it
8031 can be prevented by exporting the @code{AM_UPDATE_INFO_DIR} variable
8032 to "@code{no}".
8033
8034 The following variables are used by the Texinfo build rules.
8035
8036 @vtable @code
8037 @item MAKEINFO
8038 The name of the program invoked to build @file{.info} files.  This
8039 variable is defined by Automake.  If the @command{makeinfo} program is
8040 found on the system then it will be used by default; otherwise
8041 @command{missing} will be used instead.
8042
8043 @item MAKEINFOHTML
8044 The command invoked to build @file{.html} files.  Automake
8045 defines this to @samp{$(MAKEINFO) --html}.
8046
8047 @item MAKEINFOFLAGS
8048 User flags passed to each invocation of @samp{$(MAKEINFO)} and
8049 @samp{$(MAKEINFOHTML)}.  This user variable (@pxref{User Variables}) is
8050 not expected to be defined in any @file{Makefile}; it can be used by
8051 users to pass extra flags to suit their needs.
8052
8053 @item AM_MAKEINFOFLAGS
8054 @itemx AM_MAKEINFOHTMLFLAGS
8055 Maintainer flags passed to each @command{makeinfo} invocation.  Unlike
8056 @code{MAKEINFOFLAGS}, these variables are meant to be defined by
8057 maintainers in @file{Makefile.am}.  @samp{$(AM_MAKEINFOFLAGS)} is
8058 passed to @code{makeinfo} when building @file{.info} files; and
8059 @samp{$(AM_MAKEINFOHTMLFLAGS)} is used when building @file{.html}
8060 files.
8061
8062 @c Keep in sync with txinfo21.test.
8063 For instance, the following setting can be used to obtain one single
8064 @file{.html} file per manual, without node separators.
8065 @example
8066 AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
8067 @end example
8068
8069 @code{AM_MAKEINFOHTMLFLAGS} defaults to @samp{$(AM_MAKEINFOFLAGS)}.
8070 This means that defining @code{AM_MAKEINFOFLAGS} without defining
8071 @code{AM_MAKEINFOHTMLFLAGS} will impact builds of both @file{.info}
8072 and @file{.html} files.
8073
8074 @item TEXI2DVI
8075 The name of the command that converts a @file{.texi} file into a
8076 @file{.dvi} file.  This defaults to @samp{texi2dvi}, a script that ships
8077 with the Texinfo package.
8078
8079 @item TEXI2PDF
8080 The name of the command that translates a @file{.texi} file into a
8081 @file{.pdf} file.  This defaults to @samp{$(TEXI2DVI) --pdf --batch}.
8082
8083 @item DVIPS
8084 The name of the command that builds a @file{.ps} file out of a
8085 @file{.dvi} file.  This defaults to @samp{dvips}.
8086
8087 @item TEXINFO_TEX
8088
8089 If your package has Texinfo files in many directories, you can use the
8090 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
8091 @file{texinfo.tex} for your package.  The value of this variable should
8092 be the relative path from the current @file{Makefile.am} to
8093 @file{texinfo.tex}:
8094
8095 @example
8096 TEXINFO_TEX = ../doc/texinfo.tex
8097 @end example
8098 @end vtable
8099
8100
8101 @node Man Pages
8102 @section Man Pages
8103
8104 @cindex @code{_MANS} primary, defined
8105 @cindex @code{MANS} primary, defined
8106 @cindex Primary variable, @code{MANS}
8107
8108 @vindex _MANS
8109 @vindex man_MANS
8110 A package can also include man pages (but see the GNU standards on this
8111 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
8112 pages are declared using the @code{MANS} primary.  Generally the
8113 @code{man_MANS} variable is used.  Man pages are automatically installed in
8114 the correct subdirectory of @code{mandir}, based on the file extension.
8115
8116 File extensions such as @file{.1c} are handled by looking for the valid
8117 part of the extension and using that to determine the correct
8118 subdirectory of @code{mandir}.  Valid section names are the digits
8119 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
8120
8121 Sometimes developers prefer to name a man page something like
8122 @file{foo.man} in the source, and then rename it to have the correct
8123 suffix, for example @file{foo.1}, when installing the file.  Automake
8124 also supports this mode.  For a valid section named @var{section},
8125 there is a corresponding directory named @samp{man@var{section}dir},
8126 and a corresponding @code{_MANS} variable.  Files listed in such a
8127 variable are installed in the indicated section.  If the file already
8128 has a valid suffix, then it is installed as-is; otherwise the file
8129 suffix is changed to match the section.
8130
8131 For instance, consider this example:
8132 @example
8133 man1_MANS = rename.man thesame.1 alsothesame.1c
8134 @end example
8135
8136 @noindent
8137 In this case, @file{rename.man} will be renamed to @file{rename.1} when
8138 installed, but the other files will keep their names.
8139
8140 @cindex Target, @code{install-man}
8141 @cindex Option, @option{no-installman}
8142 @cindex @code{install-man} target
8143 @cindex @option{no-installman} option
8144 @opindex no-installman
8145 @trindex install-man
8146
8147 By default, man pages are installed by @samp{make install}.  However,
8148 since the GNU project does not require man pages, many maintainers do
8149 not expend effort to keep the man pages up to date.  In these cases, the
8150 @option{no-installman} option will prevent the man pages from being
8151 installed by default.  The user can still explicitly install them via
8152 @samp{make install-man}.
8153
8154 For fast installation, with many files it is preferable to use
8155 @samp{man@var{section}_MANS} over @samp{man_MANS} as well as files that
8156 do not need to be renamed.
8157
8158 Man pages are not currently considered to be source, because it is not
8159 uncommon for man pages to be automatically generated.  Therefore they
8160 are not automatically included in the distribution.  However, this can
8161 be changed by use of the @code{dist_} prefix.  For instance here is
8162 how to distribute and install the two man pages of GNU @command{cpio}
8163 (which includes both Texinfo documentation and man pages):
8164
8165 @example
8166 dist_man_MANS = cpio.1 mt.1
8167 @end example
8168
8169 The @code{nobase_} prefix is meaningless for man pages and is
8170 disallowed.
8171
8172 @vindex notrans_
8173 @cindex @code{notrans_} prefix
8174 @cindex Man page renaming, avoiding
8175 @cindex Avoiding man page renaming
8176
8177 Executables and manpages may be renamed upon installation
8178 (@pxref{Renaming}).  For manpages this can be avoided by use of the
8179 @code{notrans_} prefix.  For instance, suppose an executable @samp{foo}
8180 allowing to access a library function @samp{foo} from the command line.
8181 The way to avoid renaming of the @file{foo.3} manpage is:
8182
8183 @example
8184 man_MANS = foo.1
8185 notrans_man_MANS = foo.3
8186 @end example
8187
8188 @cindex @code{notrans_} and @code{dist_} or @code{nodist_}
8189 @cindex @code{dist_} and @code{notrans_}
8190 @cindex @code{nodist_} and @code{notrans_}
8191
8192 @samp{notrans_} must be specified first when used in conjunction with
8193 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
8194 Control}).  For instance:
8195
8196 @example
8197 notrans_dist_man3_MANS = bar.3
8198 @end example
8199
8200 @node Install
8201 @chapter What Gets Installed
8202
8203 @cindex Installation support
8204 @cindex @samp{make install} support
8205
8206 Naturally, Automake handles the details of actually installing your
8207 program once it has been built.  All files named by the various
8208 primaries are automatically installed in the appropriate places when the
8209 user runs @samp{make install}.
8210
8211 @menu
8212 * Basics of Installation::      What gets installed where
8213 * The Two Parts of Install::    Installing data and programs separately
8214 * Extending Installation::      Adding your own rules for installation
8215 * Staged Installs::             Installation in a temporary location
8216 * Install Rules for the User::  Useful additional rules
8217 @end menu
8218
8219 @node Basics of Installation
8220 @section Basics of Installation
8221
8222 A file named in a primary is installed by copying the built file into
8223 the appropriate directory.  The base name of the file is used when
8224 installing.
8225
8226 @example
8227 bin_PROGRAMS = hello subdir/goodbye
8228 @end example
8229
8230 In this example, both @samp{hello} and @samp{goodbye} will be installed
8231 in @samp{$(bindir)}.
8232
8233 Sometimes it is useful to avoid the basename step at install time.  For
8234 instance, you might have a number of header files in subdirectories of
8235 the source tree that are laid out precisely how you want to install
8236 them.  In this situation you can use the @code{nobase_} prefix to
8237 suppress the base name step.  For example:
8238
8239 @example
8240 nobase_include_HEADERS = stdio.h sys/types.h
8241 @end example
8242
8243 @noindent
8244 will install @file{stdio.h} in @samp{$(includedir)} and @file{types.h}
8245 in @samp{$(includedir)/sys}.
8246
8247 For most file types, Automake will install multiple files at once, while
8248 avoiding command line length issues (@pxref{Length Limitations}).  Since
8249 some @command{install} programs will not install the same file twice in
8250 one invocation, you may need to ensure that file lists are unique within
8251 one variable such as @samp{nobase_include_HEADERS} above.
8252
8253 You should not rely on the order in which files listed in one variable
8254 are installed.  Likewise, to cater for parallel make, you should not
8255 rely on any particular file installation order even among different
8256 file types (library dependencies are an exception here).
8257
8258
8259 @node The Two Parts of Install
8260 @section The Two Parts of Install
8261
8262 Automake generates separate @code{install-data} and @code{install-exec}
8263 rules, in case the installer is installing on multiple machines that
8264 share directory structure---these targets allow the machine-independent
8265 parts to be installed only once.  @code{install-exec} installs
8266 platform-dependent files, and @code{install-data} installs
8267 platform-independent files.  The @code{install} target depends on both
8268 of these targets.  While Automake tries to automatically segregate
8269 objects into the correct category, the @file{Makefile.am} author is, in
8270 the end, responsible for making sure this is done correctly.
8271 @trindex install-data
8272 @trindex install-exec
8273 @trindex install
8274 @cindex Install, two parts of
8275
8276 Variables using the standard directory prefixes @samp{data},
8277 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
8278 @samp{pkgdata}, or @samp{pkginclude} are installed by
8279 @code{install-data}.
8280
8281 Variables using the standard directory prefixes @samp{bin},
8282 @samp{sbin}, @samp{libexec}, @samp{sysconf}, @samp{localstate},
8283 @samp{lib}, or @samp{pkglib} are installed by @code{install-exec}.
8284
8285 For instance, @code{data_DATA} files are installed by @code{install-data},
8286 while @code{bin_PROGRAMS} files are installed by @code{install-exec}.
8287
8288 Any variable using a user-defined directory prefix with
8289 @samp{exec} in the name (e.g.,
8290 @c Keep in sync with primary-prefix-couples-documented-valid.test.
8291 @code{myexecbin_PROGRAMS}) is installed by @code{install-exec}.  All
8292 other user-defined prefixes are installed by @code{install-data}.
8293
8294 @node Extending Installation
8295 @section Extending Installation
8296
8297 It is possible to extend this mechanism by defining an
8298 @code{install-exec-local} or @code{install-data-local} rule.  If these
8299 rules exist, they will be run at @samp{make install} time.  These
8300 rules can do almost anything; care is required.
8301 @trindex install-exec-local
8302 @trindex install-data-local
8303
8304 Automake also supports two install hooks, @code{install-exec-hook} and
8305 @code{install-data-hook}.  These hooks are run after all other install
8306 rules of the appropriate type, exec or data, have completed.  So, for
8307 instance, it is possible to perform post-installation modifications
8308 using an install hook.  @xref{Extending}, for some examples.
8309 @cindex Install hook
8310
8311 @node Staged Installs
8312 @section Staged Installs
8313
8314 @vindex DESTDIR
8315 Automake generates support for the @code{DESTDIR} variable in all
8316 install rules.  @code{DESTDIR} is used during the @samp{make install}
8317 step to relocate install objects into a staging area.  Each object and
8318 path is prefixed with the value of @code{DESTDIR} before being copied
8319 into the install area.  Here is an example of typical DESTDIR usage:
8320
8321 @example
8322 mkdir /tmp/staging &&
8323 make DESTDIR=/tmp/staging install
8324 @end example
8325
8326 The @command{mkdir} command avoids a security problem if the attacker
8327 creates a symbolic link from @file{/tmp/staging} to a victim area;
8328 then @command{make} places install objects in a directory tree built under
8329 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
8330 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
8331 would install @file{/tmp/staging/gnu/bin/foo} and
8332 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
8333
8334 This feature is commonly used to build install images and packages
8335 (@pxref{DESTDIR}).
8336
8337 Support for @code{DESTDIR} is implemented by coding it directly into
8338 the install rules.  If your @file{Makefile.am} uses a local install
8339 rule (e.g., @code{install-exec-local}) or an install hook, then you
8340 must write that code to respect @code{DESTDIR}.
8341
8342 @xref{Makefile Conventions, , , standards, The GNU Coding Standards},
8343 for another usage example.
8344
8345 @node Install Rules for the User
8346 @section Install Rules for the User
8347
8348 Automake also generates rules for targets @code{uninstall},
8349 @code{installdirs}, and @code{install-strip}.
8350 @trindex uninstall
8351 @trindex installdirs
8352 @trindex install-strip
8353
8354 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
8355 There is no notion of separate uninstalls for ``exec'' and ``data'', as
8356 these features would not provide additional functionality.
8357
8358 Note that @code{uninstall} is not meant as a replacement for a real
8359 packaging tool.
8360
8361
8362 @node Clean
8363 @chapter What Gets Cleaned
8364
8365 @cindex @samp{make clean} support
8366
8367 The GNU Makefile Standards specify a number of different clean rules.
8368 @xref{Standard Targets, , Standard Targets for Users, standards,
8369 The GNU Coding Standards}.
8370
8371 Generally the files that can be cleaned are determined automatically by
8372 Automake.  Of course, Automake also recognizes some variables that can
8373 be defined to specify additional files to clean.  These variables are
8374 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
8375 @code{MAINTAINERCLEANFILES}.
8376 @vindex MOSTLYCLEANFILES
8377 @vindex CLEANFILES
8378 @vindex DISTCLEANFILES
8379 @vindex MAINTAINERCLEANFILES
8380
8381 @trindex mostlyclean-local
8382 @trindex clean-local
8383 @trindex distclean-local
8384 @trindex maintainer-clean-local
8385 When cleaning involves more than deleting some hard-coded list of
8386 files, it is also possible to supplement the cleaning rules with your
8387 own commands.  Simply define a rule for any of the
8388 @code{mostlyclean-local}, @code{clean-local}, @code{distclean-local},
8389 or @code{maintainer-clean-local} targets (@pxref{Extending}).  A common
8390 case is deleting a directory, for instance, a directory created by the
8391 test suite:
8392
8393 @example
8394 clean-local:
8395         -rm -rf testSubDir
8396 @end example
8397
8398 Since @command{make} allows only one set of rules for a given target,
8399 a more extensible way of writing this is to use a separate target
8400 listed as a dependency:
8401
8402 @example
8403 clean-local: clean-local-check
8404 .PHONY: clean-local-check
8405 clean-local-check:
8406         -rm -rf testSubDir
8407 @end example
8408
8409 As the GNU Standards aren't always explicit as to which files should
8410 be removed by which rule, we've adopted a heuristic that we believe
8411 was first formulated by Fran@,{c}ois Pinard:
8412
8413 @itemize @bullet
8414 @item
8415 If @command{make} built it, and it is commonly something that one would
8416 want to rebuild (for instance, a @file{.o} file), then
8417 @code{mostlyclean} should delete it.
8418
8419 @item
8420 Otherwise, if @command{make} built it, then @code{clean} should delete it.
8421
8422 @item
8423 If @command{configure} built it, then @code{distclean} should delete it.
8424
8425 @item
8426 If the maintainer built it (for instance, a @file{.info} file), then
8427 @code{maintainer-clean} should delete it.  However
8428 @code{maintainer-clean} should not delete anything that needs to exist
8429 in order to run @samp{./configure && make}.
8430 @end itemize
8431
8432 We recommend that you follow this same set of heuristics in your
8433 @file{Makefile.am}.
8434
8435
8436 @node Dist
8437 @chapter What Goes in a Distribution
8438
8439 @menu
8440 * Basics of Distribution::      Files distributed by default
8441 * Fine-grained Distribution Control::  @code{dist_} and @code{nodist_} prefixes
8442 * The dist Hook::               A target for last-minute distribution changes
8443 * Checking the Distribution::   @samp{make distcheck} explained
8444 * The Types of Distributions::  A variety of formats and compression methods
8445 @end menu
8446
8447 @node Basics of Distribution
8448 @section Basics of Distribution
8449
8450 @cindex @samp{make dist}
8451
8452 @vindex PACKAGE
8453 @vindex VERSION
8454 @trindex dist
8455 The @code{dist} rule in the generated @file{Makefile.in} can be used
8456 to generate a gzipped @code{tar} file and other flavors of archive for
8457 distribution.  The file is named based on the @code{PACKAGE} and
8458 @code{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
8459 (@pxref{Macros}); more precisely the gzipped @code{tar} file is named
8460 @samp{@var{package}-@var{version}.tar.gz}.
8461 @vindex GZIP_ENV
8462 You can use the @command{make} variable @code{GZIP_ENV} to control how gzip
8463 is run.  The default setting is @option{--best}.
8464
8465 @cindex @code{m4_include}, distribution
8466 @cindex @code{include}, distribution
8467 @acindex m4_include
8468 @cmindex include
8469 For the most part, the files to distribute are automatically found by
8470 Automake: all source files are automatically included in a distribution,
8471 as are all @file{Makefile.am} and @file{Makefile.in} files.  Automake also
8472 has a built-in list of commonly used files that are automatically
8473 included if they are found in the current directory (either physically,
8474 or as the target of a @file{Makefile.am} rule); this list is printed by
8475 @samp{automake --help}.  Note that some files in this list are actually
8476 distributed only if other certain conditions hold (for example,
8477 @c Keep in sync with autodist-config-headers.test.
8478 the @file{config.h.top} and @file{config.h.bot} files are automatically
8479 distributed only if, e.g., @samp{AC_CONFIG_HEADERS([config.h])} is used
8480 in @file{configure.ac}).  Also, files that are read by @command{configure}
8481 (i.e.@: the source files corresponding to the files specified in various
8482 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
8483 automatically distributed.  Files included in a @file{Makefile.am} (using
8484 @code{include}) or in @file{configure.ac} (using @code{m4_include}), and
8485 helper scripts installed with @samp{automake --add-missing} are also
8486 distributed.
8487
8488 @vindex EXTRA_DIST
8489 Still, sometimes there are files that must be distributed, but which
8490 are not covered in the automatic rules.  These files should be listed in
8491 the @code{EXTRA_DIST} variable.  You can mention files from
8492 subdirectories in @code{EXTRA_DIST}.
8493
8494 You can also mention a directory in @code{EXTRA_DIST}; in this case the
8495 entire directory will be recursively copied into the distribution.
8496 Please note that this will also copy @emph{everything} in the directory,
8497 including, e.g., Subversion's @file{.svn} private directories or CVS/RCS
8498 version control files.  We recommend against using this feature.
8499
8500 @vindex SUBDIRS
8501 @vindex DIST_SUBDIRS
8502 If you define @code{SUBDIRS}, Automake will recursively include the
8503 subdirectories in the distribution.  If @code{SUBDIRS} is defined
8504 conditionally (@pxref{Conditionals}), Automake will normally include
8505 all directories that could possibly appear in @code{SUBDIRS} in the
8506 distribution.  If you need to specify the set of directories
8507 conditionally, you can set the variable @code{DIST_SUBDIRS} to the
8508 exact list of subdirectories to include in the distribution
8509 (@pxref{Conditional Subdirectories}).
8510
8511
8512 @node Fine-grained Distribution Control
8513 @section Fine-grained Distribution Control
8514
8515 @vindex dist_
8516 @vindex nodist_
8517 Sometimes you need tighter control over what does @emph{not} go into the
8518 distribution; for instance, you might have source files that are
8519 generated and that you do not want to distribute.  In this case
8520 Automake gives fine-grained control using the @code{dist} and
8521 @code{nodist} prefixes.  Any primary or @code{_SOURCES} variable can be
8522 prefixed with @code{dist_} to add the listed files to the distribution.
8523 Similarly, @code{nodist_} can be used to omit the files from the
8524 distribution.
8525
8526 As an example, here is how you would cause some data to be distributed
8527 while leaving some source code out of the distribution:
8528
8529 @example
8530 dist_data_DATA = distribute-this
8531 bin_PROGRAMS = foo
8532 nodist_foo_SOURCES = do-not-distribute.c
8533 @end example
8534
8535 @node The dist Hook
8536 @section The dist Hook
8537
8538 @trindex dist-hook
8539
8540 Occasionally it is useful to be able to change the distribution before
8541 it is packaged up.  If the @code{dist-hook} rule exists, it is run
8542 after the distribution directory is filled, but before the actual tar
8543 (or shar) file is created.  One way to use this is for distributing
8544 files in subdirectories for which a new @file{Makefile.am} is overkill:
8545
8546 @example
8547 dist-hook:
8548         mkdir $(distdir)/random
8549         cp -p $(srcdir)/random/a1 $(srcdir)/random/a2 $(distdir)/random
8550 @end example
8551
8552 Another way to use this is for removing unnecessary files that get
8553 recursively included by specifying a directory in EXTRA_DIST:
8554
8555 @example
8556 EXTRA_DIST = doc
8557
8558 dist-hook:
8559         rm -rf `find $(distdir)/doc -type d -name .svn`
8560 @end example
8561
8562 @vindex distdir
8563 @vindex top_distdir
8564 Two variables that come handy when writing @code{dist-hook} rules are
8565 @samp{$(distdir)} and @samp{$(top_distdir)}.
8566
8567 @samp{$(distdir)} points to the directory where the @code{dist} rule
8568 will copy files from the current directory before creating the
8569 tarball.  If you are at the top-level directory, then @samp{distdir =
8570 $(PACKAGE)-$(VERSION)}.  When used from subdirectory named
8571 @file{foo/}, then @samp{distdir = ../$(PACKAGE)-$(VERSION)/foo}.
8572 @samp{$(distdir)} can be a relative or absolute path, do not assume
8573 any form.
8574
8575 @samp{$(top_distdir)} always points to the root directory of the
8576 distributed tree.  At the top-level it's equal to @samp{$(distdir)}.
8577 In the @file{foo/} subdirectory
8578 @samp{top_distdir = ../$(PACKAGE)-$(VERSION)}.
8579 @samp{$(top_distdir)} too can be a relative or absolute path.
8580
8581 Note that when packages are nested using @code{AC_CONFIG_SUBDIRS}
8582 (@pxref{Subpackages}), then @samp{$(distdir)} and
8583 @samp{$(top_distdir)} are relative to the package where @samp{make
8584 dist} was run, not to any sub-packages involved.
8585
8586 @node Checking the Distribution
8587 @section Checking the Distribution
8588
8589 @cindex @samp{make distcheck}
8590 @cindex @samp{make distcleancheck}
8591 @vindex distcleancheck_listfiles
8592 @cindex @samp{make distuninstallcheck}
8593 @vindex distuninstallcheck_listfiles
8594
8595 @trindex distcheck
8596 Automake also generates a @code{distcheck} rule that can be of help to
8597 ensure that a given distribution will actually work.  @code{distcheck}
8598 makes a distribution, then tries to do a @code{VPATH} build
8599 (@pxref{VPATH Builds}), run the test suite, and finally make another
8600 tarball to ensure the distribution is self-contained.
8601
8602 @vindex AM_DISTCHECK_CONFIGURE_FLAGS
8603 @vindex DISTCHECK_CONFIGURE_FLAGS
8604 Building the package involves running @samp{./configure}.  If you need
8605 to supply additional flags to @command{configure}, define them in the
8606 @code{AM_DISTCHECK_CONFIGURE_FLAGS} variable in your top-level
8607 @file{Makefile.am}.  The user can still extend or override the flags
8608 provided there by defining the @code{DISTCHECK_CONFIGURE_FLAGS} variable,
8609 on the command line when invoking @command{make}.
8610
8611 Still, developers are encouraged to strive to make their code buildable
8612 without requiring any special configure option; thus, in general, you
8613 shouldn't define @code{AM_DISTCHECK_CONFIGURE_FLAGS}. However, there
8614 might be few scenarios in which the use of this variable is justified.
8615 GNU @command{m4} offers an example.  GNU @command{m4} configures by
8616 default with its experimental and seldom used "changeword" feature
8617 disabled; so in its case it is useful to have @command{make distcheck}
8618 run configure with the @option{--with-changeword} option, to ensure that
8619 the code for changeword support still compiles correctly.
8620 GNU @command{m4} also employs the @code{AM_DISTCHECK_CONFIGURE_FLAGS}
8621 variable to stress-test the use of @option{--program-prefix=g}, since at
8622 one point the @command{m4} build system had a bug where @command{make
8623 installcheck} was wrongly assuming it could blindly test "@command{m4}",
8624 rather than the just-installed "@command{gm4}".
8625
8626 @trindex distcheck-hook
8627 If the @code{distcheck-hook} rule is defined in your top-level
8628 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
8629 the new distribution has been unpacked, but before the unpacked copy
8630 is configured and built.  Your @code{distcheck-hook} can do almost
8631 anything, though as always caution is advised.  Generally this hook is
8632 used to check for potential distribution errors not caught by the
8633 standard mechanism.  Note that @code{distcheck-hook} as well as
8634 @code{AM_DISTCHECK_CONFIGURE_FLAGS} and @code{DISTCHECK_CONFIGURE_FLAGS}
8635 are not honored in a subpackage @file{Makefile.am}, but the flags from
8636 @code{AM_DISTCHECK_CONFIGURE_FLAGS} and @code{DISTCHECK_CONFIGURE_FLAGS}
8637 are passed down to the @command{configure} script of the subpackage.
8638
8639 @trindex distcleancheck
8640 @vindex DISTCLEANFILES
8641 @vindex distcleancheck_listfiles
8642 Speaking of potential distribution errors, @code{distcheck} also
8643 ensures that the @code{distclean} rule actually removes all built
8644 files.  This is done by running @samp{make distcleancheck} at the end of
8645 the @code{VPATH} build.  By default, @code{distcleancheck} will run
8646 @code{distclean} and then make sure the build tree has been emptied by
8647 running @samp{$(distcleancheck_listfiles)}.  Usually this check will
8648 find generated files that you forgot to add to the @code{DISTCLEANFILES}
8649 variable (@pxref{Clean}).
8650
8651 The @code{distcleancheck} behavior should be OK for most packages,
8652 otherwise you have the possibility to override the definition of
8653 either the @code{distcleancheck} rule, or the
8654 @samp{$(distcleancheck_listfiles)} variable.  For instance, to disable
8655 @code{distcleancheck} completely, add the following rule to your
8656 top-level @file{Makefile.am}:
8657
8658 @example
8659 distcleancheck:
8660         @@:
8661 @end example
8662
8663 If you want @code{distcleancheck} to ignore built files that have not
8664 been cleaned because they are also part of the distribution, add the
8665 following definition instead:
8666
8667 @c Keep in sync with distcleancheck.test.
8668 @example
8669 distcleancheck_listfiles = \
8670   find . -type f -exec sh -c 'test -f $(srcdir)/$$1 || echo $$1' \
8671        sh '@{@}' ';'
8672 @end example
8673
8674 The above definition is not the default because it's usually an error if
8675 your Makefiles cause some distributed files to be rebuilt when the user
8676 build the package.  (Think about the user missing the tool required to
8677 build the file; or if the required tool is built by your package,
8678 consider the cross-compilation case where it can't be run.)  There is
8679 an entry in the FAQ about this (@pxref{distcleancheck}), make sure you
8680 read it before playing with @code{distcleancheck_listfiles}.
8681
8682 @code{distcheck} also checks that the @code{uninstall} rule works
8683 properly, both for ordinary and @code{DESTDIR} builds.  It does this
8684 by invoking @samp{make uninstall}, and then it checks the install tree
8685 to see if any files are left over.  This check will make sure that you
8686 correctly coded your @code{uninstall}-related rules.
8687
8688 By default, the checking is done by the @code{distuninstallcheck} rule,
8689 and the list of files in the install tree is generated by
8690 @samp{$(distuninstallcheck_listfiles)} (this is a variable whose value is
8691 a shell command to run that prints the list of files to stdout).
8692
8693 Either of these can be overridden to modify the behavior of
8694 @code{distcheck}.  For instance, to disable this check completely, you
8695 would write:
8696
8697 @example
8698 distuninstallcheck:
8699         @@:
8700 @end example
8701
8702 @node The Types of Distributions
8703 @section The Types of Distributions
8704
8705 Automake generates rules to provide archives of the project for
8706 distributions in various formats.  Their targets are:
8707
8708 @table @asis
8709 @vindex BZIP2
8710 @item @code{dist-bzip2}
8711 Generate a bzip2 tar archive of the distribution.  bzip2 archives are
8712 frequently smaller than gzipped archives.
8713 By default, this rule makes @samp{bzip2} use a compression option of
8714 @option{-9}.  To make it use a different one, set the @env{BZIP2}
8715 environment variable.  For example, @samp{make dist-bzip2 BZIP2=-7}.
8716 @trindex dist-bzip2
8717
8718 @item @code{dist-gzip}
8719 Generate a gzip tar archive of the distribution.
8720 @trindex dist-gzip
8721
8722 @item @code{dist-lzip}
8723 Generate a @samp{lzip} tar archive of the distribution.  @command{lzip}
8724 archives are frequently smaller than @command{bzip2}-compressed archives.
8725 @trindex dist-lzip
8726
8727 @item @code{dist-lzma}
8728 Generate an @samp{lzma} tar archive of the distribution.
8729 The @samp{lzma} format is obsolete, you should use the @samp{xz} format
8730 instead. @emph{Support for @samp{lzma}-compressed archives will be
8731 removed in the next major Automake release.}
8732 @trindex dist-lzma
8733
8734 @item @code{dist-shar}
8735 Generate a shar archive of the distribution.
8736 @trindex dist-shar
8737
8738 @vindex XZ_OPT
8739 @item @code{dist-xz}
8740 Generate an @samp{xz} tar archive of the distribution.  @command{xz}
8741 archives are frequently smaller than @command{bzip2}-compressed archives.
8742 The @samp{xz} format displaces the obsolete @samp{lzma} format.
8743 By default, this rule makes @samp{xz} use a compression option of
8744 @option{-e}.  To make it use a different one, set the @env{XZ_OPT}
8745 environment variable.  For example, run this command to use the
8746 default compression ratio, but with a progress indicator:
8747 @samp{make dist-xz XZ_OPT=-7e}.
8748 @trindex dist-xz
8749
8750 @item @code{dist-zip}
8751 Generate a zip archive of the distribution.
8752 @trindex dist-zip
8753
8754 @item @code{dist-tarZ}
8755 Generate a compressed tar archive of
8756 the distribution.
8757 @trindex dist-tarZ
8758 @end table
8759
8760 The rule @code{dist} (and its historical synonym @code{dist-all}) will
8761 create archives in all the enabled formats, @ref{Options}.  By
8762 default, only the @code{dist-gzip} target is hooked to @code{dist}.
8763
8764
8765 @node Tests
8766 @chapter Support for test suites
8767
8768 @cindex Test suites
8769 @cindex @code{make check}
8770 @trindex check
8771
8772 Automake supports three forms of test suites, the first two of which
8773 are very similar.
8774
8775 @menu
8776 * Simple Tests::                Listing programs and scripts in @code{TESTS}
8777 * Simple Tests using parallel-tests::  More powerful test driver
8778 * DejaGnu Tests::               Interfacing with the external testing framework
8779 * Install Tests::               Running tests on installed packages
8780 @end menu
8781
8782 @node Simple Tests
8783 @section Simple Tests
8784
8785 If the variable @code{TESTS} is defined, its value is taken to be a
8786 list of programs or scripts to run in order to do the testing.
8787 Programs needing data files should look for them in @code{srcdir}
8788 (which is both an environment variable and a make variable) so they
8789 work when building in a separate directory (@pxref{Build Directories,
8790 , Build Directories , autoconf, The Autoconf Manual}), and in
8791 particular for the @code{distcheck} rule (@pxref{Checking the
8792 Distribution}).
8793
8794 For each of the @code{TESTS}, the result of execution is printed along
8795 with the test name, where @code{PASS} denotes a successful test,
8796 @code{FAIL} denotes a failed test, @code{XFAIL} an expected failure,
8797 @code{XPASS} an unexpected pass for a test that is supposed to fail,
8798 and @code{SKIP} denotes a skipped test.
8799
8800 @cindex Exit status 77, special interpretation
8801
8802 The number of failures will be printed at the end of the run.  If a
8803 given test program exits with a status of 77, then its result is ignored
8804 in the final count.  This feature allows non-portable tests to be
8805 ignored in environments where they don't make sense.
8806
8807 @vindex AM_COLOR_TESTS
8808 If the Automake option @code{color-tests} is used (@pxref{Options})
8809 and standard output is connected to a capable terminal, then the test
8810 results and the summary are colored appropriately.  The user can disable
8811 colored output by setting the @command{make} variable
8812 @samp{AM_COLOR_TESTS=no}, or force colored output even without a connecting
8813 terminal with @samp{AM_COLOR_TESTS=always}.
8814
8815 Note that the semantics of some @command{make} implementations when used
8816 in parallel mode (@pxref{Parallel make,,, autoconf, The Autoconf Manual})
8817 can cause the automatic detection of a connection to a capable terminal
8818 to fail.  In that case, you can still resort to the use of
8819 @samp{AM_COLOR_TESTS=always}.
8820
8821 @vindex TESTS
8822 @vindex TESTS_ENVIRONMENT
8823 The variable @code{TESTS_ENVIRONMENT} can be used to set environment
8824 variables for the test run; the environment variable @env{srcdir} is
8825 set in the rule.  If all your test programs are scripts, you can also
8826 set @code{TESTS_ENVIRONMENT} to an invocation of the shell (e.g.
8827 @samp{$(SHELL) -x} can be useful for debugging the tests), or any other
8828 interpreter.  For instance, the following setup may be used to run tests
8829 with Perl:
8830
8831 @c Keep in sync with tests-environment-backcompat.test.
8832 @example
8833 TESTS_ENVIRONMENT = $(PERL) -Mstrict -w
8834 TESTS = foo.pl bar.pl baz.pl
8835 @end example
8836
8837 Note that the @option{parallel-tests} driver provides a more elegant
8838 way to achieve the same effect, freeing the @code{TESTS_ENVIRONMENT}
8839 variable for the user to override (@pxref{Simple Tests using
8840 parallel-tests}).
8841
8842
8843 @cindex Tests, expected failure
8844 @cindex Expected test failure
8845
8846 @vindex XFAIL_TESTS
8847 You may define the variable @code{XFAIL_TESTS} to a list of tests
8848 (usually a subset of @code{TESTS}) that are expected to fail.  This will
8849 reverse the result of those tests.
8850
8851 Automake ensures that each file listed in @code{TESTS} is built before
8852 any tests are run; you can list both source and derived programs (or
8853 scripts) in @code{TESTS}; the generated rule will look both in
8854 @code{srcdir} and @file{.}.  For instance, you might want to run a C
8855 program as a test.  To do this you would list its name in @code{TESTS}
8856 and also in @code{check_PROGRAMS}, and then specify it as you would
8857 any other program.
8858
8859 Programs listed in @code{check_PROGRAMS} (and @code{check_LIBRARIES},
8860 @code{check_LTLIBRARIES}...) are only built during @code{make check},
8861 not during @code{make all}.  You should list there any program needed
8862 by your tests that does not need to be built by @code{make all}.  Note
8863 that @code{check_PROGRAMS} are @emph{not} automatically added to
8864 @code{TESTS} because @code{check_PROGRAMS} usually lists programs used
8865 by the tests, not the tests themselves.  Of course you can set
8866 @code{TESTS = $(check_PROGRAMS)} if all your programs are test cases.
8867
8868
8869 @node Simple Tests using parallel-tests
8870 @section Simple Tests using @samp{parallel-tests}
8871 @cindex @option{parallel-tests}, Using
8872
8873 The option @option{parallel-tests} (@pxref{Options}) enables a test suite
8874 driver that is mostly compatible to the simple test driver described in
8875 the previous section, but provides a few more features and slightly
8876 different semantics.  It features concurrent execution of tests with
8877 @code{make -j} and automatic collection of the test scripts output and
8878 summary thereof in @file{.log} files, and allows to specify inter-test
8879 dependencies, lazy reruns of tests that have not completed in a prior
8880 run, and hard errors for exceptional failures.  Similar to the simple
8881 test driver, @code{TESTS_ENVIRONMENT}, @code{AM_COLOR_TESTS},
8882 @code{XFAIL_TESTS}, and the @code{check_*} variables are honored,
8883 and the environment variable @env{srcdir} is set during test execution.
8884
8885 This test driver is still experimental and may undergo changes in order
8886 to satisfy additional portability requirements.
8887
8888 @vindex TEST_SUITE_LOG
8889 @vindex TESTS
8890 The driver operates by defining a set of @command{make} rules to create
8891 a summary log file, @code{TEST_SUITE_LOG}, which defaults to
8892 @file{test-suite.log} and requires a @file{.log} suffix.  This file
8893 depends upon log files created for each single test program listed in
8894 @code{TESTS}, which in turn contain all output produced by the
8895 corresponding tests.
8896
8897 @vindex TEST_EXTENSIONS
8898 @vindex TEST_LOGS
8899 Each log file is created when the corresponding test has completed.
8900 The set of log files is listed in the read-only variable
8901 @code{TEST_LOGS}, and defaults to @code{TESTS}, with the executable
8902 extension if any (@pxref{EXEEXT}), as well as any suffix listed in
8903 @code{TEST_EXTENSIONS} removed, and @file{.log} appended.  Results
8904 are undefined if a test file name ends in several concatenated suffixes.
8905 @code{TEST_EXTENSIONS} defaults to @file{.test}; it can be overridden by
8906 the user, in which case any extension listed in it must be constituted
8907 by a dot, followed by a non-digit alphabetic character, followed by any
8908 number of alphabetic characters.
8909 @c Keep in sync with test-extensions.test.
8910 For example, @samp{.sh}, @samp{.T} and @samp{.t1} are valid extensions,
8911 while @samp{.x-y}, @samp{.6c} and @samp{.t.1} are not.
8912
8913 @vindex _LOG_COMPILE
8914 @vindex _LOG_COMPILER
8915 @vindex _LOG_FLAGS
8916 @vindex LOG_COMPILE
8917 @vindex LOG_COMPILER
8918 @vindex LOG_FLAGS
8919 @vindex @var{ext}_LOG_COMPILE
8920 @vindex @var{ext}_LOG_COMPILER
8921 @vindex @var{ext}_LOG_FLAGS
8922 @vindex AM_@var{ext}_LOG_FLAGS
8923 @vindex AM_LOG_FLAGS
8924 For tests that match an extension @code{.@var{ext}} listed in
8925 @code{TEST_EXTENSIONS}, you can provide a test driver using the variable
8926 @code{@var{ext}_LOG_COMPILER} (note the upper-case extension) and pass
8927 options in @code{AM_@var{ext}_LOG_FLAGS} and allow the user to pass
8928 options in @code{@var{ext}_LOG_FLAGS}.  It will cause all tests with
8929 this extension to be called with this driver.  For all tests without a
8930 registered extension, the variables @code{LOG_COMPILER},
8931 @code{AM_LOG_FLAGS}, and @code{LOG_FLAGS} may be used.  For example,
8932
8933 @c Keep in sync with parallel-tests-log-compiler-example.test.
8934 @example
8935 TESTS = foo.pl bar.py baz
8936 TEST_EXTENSIONS = .pl .py
8937 PL_LOG_COMPILER = $(PERL)
8938 AM_PL_LOG_FLAGS = -w
8939 PY_LOG_COMPILER = $(PYTHON)
8940 AM_PY_LOG_FLAGS = -v
8941 LOG_COMPILER = ./wrapper-script
8942 AM_LOG_FLAGS = -d
8943 @end example
8944
8945 @noindent
8946 will invoke @samp{$(PERL) -w foo.pl}, @samp{$(PYTHON) -v bar.py},
8947 and @samp{./wrapper-script -d baz} to produce @file{foo.log},
8948 @file{bar.log}, and @file{baz.log}, respectively.  The
8949 @samp{TESTS_ENVIRONMENT} variable is still expanded before the driver,
8950 but should be reserved for the user.
8951
8952 @vindex VERBOSE
8953 As with the simple driver above, by default one status line is printed
8954 per completed test, and a short summary after the suite has completed.
8955 However, standard output and standard error of the test are redirected
8956 to a per-test log file, so that parallel execution does not produce
8957 intermingled output.  The output from failed tests is collected in the
8958 @file{test-suite.log} file.  If the variable @samp{VERBOSE} is set, this
8959 file is output after the summary.  For best results, the tests should be
8960 verbose by default now.
8961
8962 @trindex check-html
8963 @vindex RST2HTML
8964 @vindex TEST_SUITE_HTML
8965 Previous versions of automake used to provide a @code{check-html} target
8966 to convert the log files to HTML.  This feature is now deprecated, and
8967 @emph{will be removed} in the next major Automake release, so don't rely
8968 on it anymore.
8969
8970 @vindex DISABLE_HARD_ERRORS
8971 @cindex Exit status 99, special interpretation
8972 @cindex hard error
8973 Even in the presence of expected failures (see @code{XFAIL_TESTS}), there
8974 may be conditions under which a test outcome needs attention.  For
8975 example, with test-driven development, you may write tests for features
8976 that you have not implemented yet, and thus mark these tests as expected
8977 to fail.  However, you may still be interested in exceptional conditions,
8978 for example, tests that fail due to a segmentation violation or another
8979 error that is independent of the feature awaiting implementation.
8980 Tests can exit with an exit status of 99 to signal such a @emph{hard
8981 error}.  Unless the variable @code{DISABLE_HARD_ERRORS} is set to a
8982 nonempty value, such tests will be counted as failed.
8983
8984 By default, the test suite driver will run all tests, but there are
8985 several ways to limit the set of tests that are run:
8986
8987 @itemize @bullet
8988 @item
8989 You can set the @code{TESTS} variable, similarly to how you can with
8990 the simple test driver from the previous section.  For example, you can
8991 use a command like this to run only a subset of the tests:
8992
8993 @example
8994 env TESTS="foo.test bar.test" make -e check
8995 @end example
8996
8997 Note however that the command above will unconditionally overwrite the
8998 @file{test-suite.log} file, thus clobbering the recorded results
8999 of any previous testsuite run.  This might be undesirable for packages
9000 whose testsuite takes long time to execute.  Luckily, this problem can
9001 easily be avoided by overriding also @code{TEST_SUITE_LOG} at runtime;
9002 for example,
9003
9004 @c Keep in sync with parallel-tests-log-override-2.test.
9005 @example
9006 env TEST_SUITE_LOG=partial.log TESTS="..." make -e check
9007 @end example
9008
9009 will write the result of the partial testsuite runs to the
9010 @file{partial.log}, without touching @file{test-suite.log}.
9011
9012 @item
9013 You can set the @code{TEST_LOGS} variable.  By default, this variable is
9014 computed at @command{make} run time from the value of @code{TESTS} as
9015 described above.  For example, you can use the following:
9016
9017 @example
9018 set x subset*.log; shift
9019 env TEST_LOGS="foo.log $*" make -e check
9020 @end example
9021
9022 The comments made above about @code{TEST_SUITE_LOG} overriding applies
9023 here too.
9024
9025 @item
9026 @vindex RECHECK_LOGS
9027 @cindex lazy test execution
9028 By default, the test driver removes all old per-test log files before it
9029 starts running tests to regenerate them.  The variable
9030 @code{RECHECK_LOGS} contains the set of log files which are removed.
9031 @code{RECHECK_LOGS} defaults to @code{TEST_LOGS}, which means all tests
9032 need to be rechecked.  By overriding this variable, you can choose which
9033 tests need to be reconsidered.  For example, you can lazily rerun only
9034 those tests which are outdated, i.e., older than their prerequisite test
9035 files, by setting this variable to the empty value:
9036
9037 @example
9038 env RECHECK_LOGS= make -e check
9039 @end example
9040
9041 @item
9042 @trindex recheck
9043 You can ensure that all tests are rerun which have failed or passed
9044 unexpectedly, by running @code{make recheck} in the test directory.
9045 This convenience target will set @code{RECHECK_LOGS} appropriately
9046 before invoking the main test driver.
9047 @end itemize
9048
9049 In order to guarantee an ordering between tests even with @code{make
9050 -j@var{N}}, dependencies between the corresponding log files may be
9051 specified through usual @command{make} dependencies.  For example, the
9052 following snippet lets the test named @file{foo-execute.test} depend
9053 upon completion of the test @file{foo-compile.test}:
9054
9055 @example
9056 TESTS = foo-compile.test foo-execute.test
9057 foo-execute.log: foo-compile.log
9058 @end example
9059
9060 @noindent
9061 Please note that this ordering ignores the @emph{results} of required
9062 tests, thus the test @file{foo-execute.test} is run even if the test
9063 @file{foo-compile.test} failed or was skipped beforehand.  Further,
9064 please note that specifying such dependencies currently works only for
9065 tests that end in one of the suffixes listed in @code{TEST_EXTENSIONS}.
9066
9067 Tests without such specified dependencies may be run concurrently with
9068 parallel @command{make -j@var{N}}, so be sure they are prepared for
9069 concurrent execution.
9070
9071 @cindex Unit tests
9072 The combination of lazy test execution and correct dependencies between
9073 tests and their sources may be exploited for efficient unit testing
9074 during development.  To further speed up the edit-compile-test cycle, it
9075 may even be useful to specify compiled programs in @code{EXTRA_PROGRAMS}
9076 instead of with @code{check_PROGRAMS}, as the former allows intertwined
9077 compilation and test execution (but note that @code{EXTRA_PROGRAMS} are
9078 not cleaned automatically, @pxref{Uniform}).
9079
9080 The variables @code{TESTS} and @code{XFAIL_TESTS} may contain
9081 conditional parts as well as configure substitutions.  In the latter
9082 case, however, certain restrictions apply: substituted test names
9083 must end with a nonempty test suffix like @file{.test}, so that one of
9084 the inference rules generated by @command{automake} can apply.  For
9085 literal test names, @command{automake} can generate per-target rules
9086 to avoid this limitation.
9087
9088 Please note that it is currently not possible to use @code{$(srcdir)/}
9089 or @code{$(top_srcdir)/} in the @code{TESTS} variable.  This technical
9090 limitation is necessary to avoid generating test logs in the source tree
9091 and has the unfortunate consequence that it is not possible to specify
9092 distributed tests that are themselves generated by means of explicit
9093 rules, in a way that is portable to all @command{make} implementations
9094 (@pxref{Make Target Lookup,,, autoconf, The Autoconf Manual}, the
9095 semantics of FreeBSD and OpenBSD @command{make} conflict with this).
9096 In case of doubt you may want to require to use GNU @command{make},
9097 or work around the issue with inference rules to generate the tests.
9098
9099
9100 @node DejaGnu Tests
9101 @section DejaGnu Tests
9102
9103 If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @command{dejagnu}} appears in
9104 @code{AUTOMAKE_OPTIONS}, then a @command{dejagnu}-based test suite is
9105 assumed.  The variable @code{DEJATOOL} is a list of names that are
9106 passed, one at a time, as the @option{--tool} argument to
9107 @command{runtest} invocations; it defaults to the name of the package.
9108
9109 The variable @code{RUNTESTDEFAULTFLAGS} holds the @option{--tool} and
9110 @option{--srcdir} flags that are passed to dejagnu by default; this can be
9111 overridden if necessary.
9112 @vindex RUNTESTDEFAULTFLAGS
9113
9114 The variables @code{EXPECT} and @code{RUNTEST} can
9115 also be overridden to provide project-specific values.  For instance,
9116 you will need to do this if you are testing a compiler toolchain,
9117 because the default values do not take into account host and target
9118 names.
9119 @opindex dejagnu
9120 @vindex DEJATOOL
9121 @vindex EXPECT
9122 @vindex RUNTEST
9123
9124 The contents of the variable @code{RUNTESTFLAGS} are passed to the
9125 @code{runtest} invocation.  This is considered a ``user variable''
9126 (@pxref{User Variables}).  If you need to set @command{runtest} flags in
9127 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
9128 @vindex RUNTESTFLAGS
9129 @vindex AM_RUNTESTFLAGS
9130
9131 @cindex @file{site.exp}
9132 Automake will generate rules to create a local @file{site.exp} file,
9133 defining various variables detected by @command{configure}.  This file
9134 is automatically read by DejaGnu.  It is OK for the user of a package
9135 to edit this file in order to tune the test suite.  However this is
9136 not the place where the test suite author should define new variables:
9137 this should be done elsewhere in the real test suite code.
9138 Especially, @file{site.exp} should not be distributed.
9139
9140 Still, if the package author has legitimate reasons to extend
9141 @file{site.exp} at @command{make} time, he can do so by defining
9142 the variable @code{EXTRA_DEJAGNU_SITE_CONFIG}; the files listed
9143 there will be considered @file{site.exp} prerequisites, and their
9144 content will be appended to it (in the same order in which they
9145 appear in @code{EXTRA_DEJAGNU_SITE_CONFIG}).  Note that files are
9146 @emph{not} distributed by default.
9147
9148 For more information regarding DejaGnu test suites, see @ref{Top, , ,
9149 dejagnu, The DejaGnu Manual}.
9150
9151 In either case, the testing is done via @samp{make check}.
9152
9153 @node Install Tests
9154 @section Install Tests
9155
9156 The @code{installcheck} target is available to the user as a way to
9157 run any tests after the package has been installed.  You can add tests
9158 to this by writing an @code{installcheck-local} rule.
9159
9160
9161 @node Rebuilding
9162 @chapter Rebuilding Makefiles
9163 @cindex rebuild rules
9164
9165 Automake generates rules to automatically rebuild @file{Makefile}s,
9166 @file{configure}, and other derived files like @file{Makefile.in}.
9167
9168 @acindex AM_MAINTAINER_MODE
9169 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.ac}, then
9170 these automatic rebuilding rules are only enabled in maintainer mode.
9171
9172 @vindex ACLOCAL_AMFLAGS
9173 Sometimes you need to run @command{aclocal} with an argument like
9174 @option{-I} to tell it where to find @file{.m4} files.  Since
9175 sometimes @command{make} will automatically run @command{aclocal}, you
9176 need a way to specify these arguments.  You can do this by defining
9177 @code{ACLOCAL_AMFLAGS}; this holds arguments that are passed verbatim
9178 to @command{aclocal}.  This variable is only useful in the top-level
9179 @file{Makefile.am}.
9180
9181 @vindex CONFIG_STATUS_DEPENDENCIES
9182 @vindex CONFIGURE_DEPENDENCIES
9183 @cindex @file{version.sh}, example
9184 @cindex @file{version.m4}, example
9185
9186 Sometimes it is convenient to supplement the rebuild rules for
9187 @file{configure} or @file{config.status} with additional dependencies.
9188 The variables @code{CONFIGURE_DEPENDENCIES} and
9189 @code{CONFIG_STATUS_DEPENDENCIES} can be used to list these extra
9190 dependencies.  These variables should be defined in all
9191 @file{Makefile}s of the tree (because these two rebuild rules are
9192 output in all them), so it is safer and easier to @code{AC_SUBST} them
9193 from @file{configure.ac}.  For instance, the following statement will
9194 cause @file{configure} to be rerun each time @file{version.sh} is
9195 changed.
9196
9197 @example
9198 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh'])
9199 @end example
9200
9201 @noindent
9202 Note the @samp{$(top_srcdir)/} in the file name.  Since this variable
9203 is to be used in all @file{Makefile}s, its value must be sensible at
9204 any level in the build hierarchy.
9205
9206 Beware not to mistake @code{CONFIGURE_DEPENDENCIES} for
9207 @code{CONFIG_STATUS_DEPENDENCIES}.
9208
9209 @code{CONFIGURE_DEPENDENCIES} adds dependencies to the
9210 @file{configure} rule, whose effect is to run @command{autoconf}.  This
9211 variable should be seldom used, because @command{automake} already tracks
9212 @code{m4_include}d files.  However it can be useful when playing
9213 tricky games with @code{m4_esyscmd} or similar non-recommendable
9214 macros with side effects.
9215
9216 @code{CONFIG_STATUS_DEPENDENCIES} adds dependencies to the
9217 @file{config.status} rule, whose effect is to run @file{configure}.
9218 This variable should therefore carry any non-standard source that may
9219 be read as a side effect of running @command{configure}, like @file{version.sh}
9220 in the example above.
9221
9222 Speaking of @file{version.sh} scripts, we recommend against them
9223 today.  They are mainly used when the version of a package is updated
9224 automatically by a script (e.g., in daily builds).  Here is what some
9225 old-style @file{configure.ac}s may look like:
9226
9227 @example
9228 AC_INIT
9229 . $srcdir/version.sh
9230 AM_INIT_AUTOMAKE([name], $VERSION_NUMBER)
9231 @dots{}
9232 @end example
9233
9234 @noindent
9235 Here, @file{version.sh} is a shell fragment that sets
9236 @code{VERSION_NUMBER}.  The problem with this example is that
9237 @command{automake} cannot track dependencies (listing @file{version.sh}
9238 in @command{CONFIG_STATUS_DEPENDENCIES}, and distributing this file is up
9239 to the user), and that it uses the obsolete form of @code{AC_INIT} and
9240 @code{AM_INIT_AUTOMAKE}.  Upgrading to the new syntax is not
9241 straightforward, because shell variables are not allowed in
9242 @code{AC_INIT}'s arguments.  We recommend that @file{version.sh} be
9243 replaced by an M4 file that is included by @file{configure.ac}:
9244
9245 @example
9246 m4_include([version.m4])
9247 AC_INIT([name], VERSION_NUMBER)
9248 AM_INIT_AUTOMAKE
9249 @dots{}
9250 @end example
9251
9252 @noindent
9253 Here @file{version.m4} could contain something like
9254 @samp{m4_define([VERSION_NUMBER], [1.2])}.  The advantage of this
9255 second form is that @command{automake} will take care of the
9256 dependencies when defining the rebuild rule, and will also distribute
9257 the file automatically.  An inconvenience is that @command{autoconf}
9258 will now be rerun each time the version number is bumped, when only
9259 @file{configure} had to be rerun in the previous setup.
9260
9261
9262 @node Options
9263 @chapter Changing Automake's Behavior
9264
9265 Various features of Automake can be controlled by options.  Except where
9266 noted otherwise, options can be specified in one of several ways: Most
9267 options can be applied on a per-@file{Makefile} basis when listed in a
9268 special @file{Makefile} variable named @code{AUTOMAKE_OPTIONS}.  Some
9269 of these options only make sense when specified in the toplevel
9270 @file{Makefile.am} file.  Options are applied globally to all processed
9271 @file{Makefile} files when listed in the first argument of
9272 @code{AM_INIT_AUTOMAKE} in @file{configure.ac}, and some options which
9273 require changes to the @command{configure} script can only be specified
9274 there.  These are annotated below.
9275
9276 Currently understood options are:
9277 @vindex AUTOMAKE_OPTIONS
9278
9279 @table @asis
9280 @item @option{gnits}
9281 @itemx @option{gnu}
9282 @itemx @option{foreign}
9283 @itemx @option{cygnus}
9284 @cindex Option, @option{gnits}
9285 @cindex Option, @option{gnu}
9286 @cindex Option, @option{foreign}
9287 @cindex Option, @option{cygnus}
9288 @opindex gnits
9289 @opindex gnu
9290 @opindex foreign
9291 @opindex cygnus
9292
9293 Set the strictness as appropriate.  The @option{gnits} option also
9294 implies options @option{readme-alpha} and @option{check-news}.
9295
9296 @item @option{ansi2knr}
9297 @itemx @option{@var{path}/ansi2knr}
9298 @cindex Option, @option{ansi2knr}
9299 @opindex ansi2knr
9300 Turn on the deprecated de-ANSI-fication feature (@pxref{ANSI}).  Note
9301 that that feature and this option @emph{will be removed} in the next
9302 major Automake release.
9303
9304 If preceded by a
9305 path, the generated @file{Makefile.in} will look in the specified
9306 directory to find the @file{ansi2knr} program.  The path should be a
9307 relative path to another directory in the same distribution (Automake
9308 does not check this).
9309
9310 @item @option{check-news}
9311 @cindex Option, @option{check-news}
9312 @opindex check-news
9313 Cause @samp{make dist} to fail unless the current version number appears
9314 in the first few lines of the @file{NEWS} file.
9315
9316 @item @option{color-tests}
9317 @cindex Option, @option{color-tests}
9318 @opindex color-tests
9319 Cause output of the simple test suite (@pxref{Simple Tests}) to be
9320 colorized on capable terminals.
9321
9322 @item @option{dejagnu}
9323 @cindex Option, @option{dejagnu}
9324 @opindex dejagnu
9325 Cause @command{dejagnu}-specific rules to be generated.  @xref{DejaGnu Tests}.
9326
9327 @item @option{dist-bzip2}
9328 @cindex Option, @option{dist-bzip2}
9329 @opindex dist-bzip2
9330 Hook @code{dist-bzip2} to @code{dist}.
9331 @trindex dist-bzip2
9332
9333 @item @option{dist-lzip}
9334 @cindex Option, @option{dist-lzip}
9335 @opindex dist-lzip
9336 Hook @code{dist-lzip} to @code{dist}.
9337 @trindex dist-lzip
9338
9339 @item @option{dist-lzma}
9340 @cindex Option, @option{dist-lzma}
9341 @opindex dist-lzma
9342 Hook @code{dist-lzma} to @code{dist}.  Obsoleted by @code{dist-xz}.
9343 @trindex dist-lzma
9344
9345 @item @option{dist-shar}
9346 @cindex Option, @option{dist-shar}
9347 @opindex dist-shar
9348 Hook @code{dist-shar} to @code{dist}.
9349 @trindex dist-shar
9350
9351 @item @option{dist-zip}
9352 @cindex Option, @option{dist-zip}
9353 @opindex dist-zip
9354 Hook @code{dist-zip} to @code{dist}.
9355 @trindex dist-zip
9356
9357 @item @option{dist-tarZ}
9358 @cindex Option, @option{dist-tarZ}
9359 @opindex dist-tarZ
9360 Hook @code{dist-tarZ} to @code{dist}.
9361 @trindex dist-tarZ
9362
9363 @item @option{filename-length-max=99}
9364 @cindex Option, @option{filename-length-max=99}
9365 @opindex filename-length-max=99
9366 Abort if file names longer than 99 characters are found during
9367 @samp{make dist}.  Such long file names are generally considered not to
9368 be portable in tarballs.  See the @option{tar-v7} and @option{tar-ustar}
9369 options below.  This option should be used in the top-level
9370 @file{Makefile.am} or as an argument of @code{AM_INIT_AUTOMAKE} in
9371 @file{configure.ac}, it will be ignored otherwise.  It will also be
9372 ignored in sub-packages of nested packages (@pxref{Subpackages}).
9373
9374 @item @option{no-define}
9375 @cindex Option, @option{no-define}
9376 @opindex no-define
9377 This option is meaningful only when passed as an argument to
9378 @code{AM_INIT_AUTOMAKE}.  It will prevent the @code{PACKAGE} and
9379 @code{VERSION} variables from being @code{AC_DEFINE}d.
9380
9381 @item @option{no-dependencies}
9382 @cindex Option, @option{no-dependencies}
9383 @opindex no-dependencies
9384 This is similar to using @option{--ignore-deps} on the command line,
9385 but is useful for those situations where you don't have the necessary
9386 bits to make automatic dependency tracking work
9387 (@pxref{Dependencies}).  In this case the effect is to effectively
9388 disable automatic dependency tracking.
9389
9390 @item @option{no-dist}
9391 @cindex Option, @option{no-dist}
9392 @opindex no-dist
9393 Don't emit any code related to @code{dist} target.  This is useful
9394 when a package has its own method for making distributions.
9395
9396 @item @option{no-dist-gzip}
9397 @cindex Option, @option{no-dist-gzip}
9398 @opindex no-dist-gzip
9399 Do not hook @code{dist-gzip} to @code{dist}.
9400 @trindex no-dist-gzip
9401
9402 @item @option{no-exeext}
9403 @cindex Option, @option{no-exeext}
9404 @opindex no-exeext
9405 If your @file{Makefile.am} defines a rule for target @code{foo}, it
9406 will override a rule for a target named @samp{foo$(EXEEXT)}.  This is
9407 necessary when @code{EXEEXT} is found to be empty.  However, by
9408 default @command{automake} will generate an error for this use.  The
9409 @option{no-exeext} option will disable this error.  This is intended for
9410 use only where it is known in advance that the package will not be
9411 ported to Windows, or any other operating system using extensions on
9412 executables.
9413
9414 @item @option{no-installinfo}
9415 @cindex Option, @option{no-installinfo}
9416 @opindex no-installinfo
9417 The generated @file{Makefile.in} will not cause info pages to be built
9418 or installed by default.  However, @code{info} and @code{install-info}
9419 targets will still be available.  This option is disallowed at
9420 @option{gnu} strictness and above.
9421 @trindex info
9422 @trindex install-info
9423
9424 @item @option{no-installman}
9425 @cindex Option, @option{no-installman}
9426 @opindex no-installman
9427 The generated @file{Makefile.in} will not cause man pages to be
9428 installed by default.  However, an @code{install-man} target will still
9429 be available for optional installation.  This option is disallowed at
9430 @option{gnu} strictness and above.
9431 @trindex install-man
9432
9433 @item @option{nostdinc}
9434 @cindex Option, @option{nostdinc}
9435 @opindex nostdinc
9436 This option can be used to disable the standard @option{-I} options that
9437 are ordinarily automatically provided by Automake.
9438
9439 @item @option{no-texinfo.tex}
9440 @cindex Option, @option{no-texinfo.tex}
9441 @opindex no-texinfo.tex
9442 Don't require @file{texinfo.tex}, even if there are texinfo files in
9443 this directory.
9444
9445 @item @option{parallel-tests}
9446 @cindex Option, @option{parallel-tests}
9447 @opindex parallel-tests
9448 Enable test suite driver for @code{TESTS} that can run tests in parallel
9449 (@pxref{Simple Tests using parallel-tests}, for more information).
9450
9451 @item @option{readme-alpha}
9452 @cindex Option, @option{readme-alpha}
9453 @opindex readme-alpha
9454 If this release is an alpha release, and the file @file{README-alpha}
9455 exists, then it will be added to the distribution.  If this option is
9456 given, version numbers are expected to follow one of two forms.  The
9457 first form is @samp{@var{major}.@var{minor}.@var{alpha}}, where each
9458 element is a number; the final period and number should be left off for
9459 non-alpha releases.  The second form is
9460 @samp{@var{major}.@var{minor}@var{alpha}}, where @var{alpha} is a
9461 letter; it should be omitted for non-alpha releases.
9462
9463 @item @option{silent-rules}
9464 @cindex Option, @option{silent-rules}
9465 @opindex silent-rules
9466 Enable less verbose build rules.  This can be used to let build rules
9467 output status lines of the form:
9468 @example
9469 GEN @var{output-file}
9470  CC @var{object-file}
9471 @end example
9472 @noindent
9473 instead of printing the command that will be executed to update
9474 @var{output-file} or to compile @var{object-file}.  It can also
9475 silence @command{libtool} output.
9476
9477 For more information about how to use, enable, or disable silent
9478 rules, @pxref{Automake silent-rules Option}.
9479
9480 @item @option{std-options}
9481 @cindex Options, @option{std-options}
9482 @cindex @samp{make installcheck}, testing @option{--help} and @option{--version}
9483 @cindex @option{--help} check
9484 @cindex @option{--version} check
9485 @opindex std-options
9486
9487 Make the @code{installcheck} rule check that installed scripts and
9488 programs support the @option{--help} and @option{--version} options.
9489 This also provides a basic check that the program's
9490 run-time dependencies are satisfied after installation.
9491
9492 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
9493 In a few situations, programs (or scripts) have to be exempted from this
9494 test.  For instance, @command{false} (from GNU coreutils) is never
9495 successful, even for @option{--help} or @option{--version}.  You can list
9496 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
9497 Programs (not scripts) listed in this variable should be suffixed by
9498 @samp{$(EXEEXT)} for the sake of Win32 or OS/2.  For instance, suppose we
9499 build @file{false} as a program but @file{true.sh} as a script, and that
9500 neither of them support @option{--help} or @option{--version}:
9501
9502 @example
9503 AUTOMAKE_OPTIONS = std-options
9504 bin_PROGRAMS = false ...
9505 bin_SCRIPTS = true.sh ...
9506 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
9507 @end example
9508
9509 @item @option{subdir-objects}
9510 @cindex Options, @option{subdir-objects}
9511 @opindex subdir-objects
9512 If this option is specified, then objects are placed into the
9513 subdirectory of the build directory corresponding to the subdirectory of
9514 the source file.  For instance, if the source file is
9515 @file{subdir/file.cxx}, then the output file would be
9516 @file{subdir/file.o}.
9517
9518 In order to use this option with C sources, you should add
9519 @code{AM_PROG_CC_C_O} to @file{configure.ac}.
9520
9521 @anchor{tar-formats}
9522 @item @option{tar-v7}
9523 @itemx @option{tar-ustar}
9524 @itemx @option{tar-pax}
9525 @cindex Option, @option{tar-v7}
9526 @cindex Option, @option{tar-ustar}
9527 @cindex Option, @option{tar-pax}
9528 @cindex @command{tar} formats
9529 @cindex v7 @command{tar} format
9530 @cindex ustar format
9531 @cindex pax format
9532 @opindex tar-v7
9533 @opindex tar-ustar
9534 @opindex tar-pax
9535
9536 These three mutually exclusive options select the tar format to use
9537 when generating tarballs with @samp{make dist}.  (The tar file created
9538 is then compressed according to the set of @option{no-dist-gzip},
9539 @option{dist-bzip2}, @option{dist-lzip}, @option{dist-xz} and
9540 @option{dist-tarZ} options in use.)
9541
9542 These options must be passed as arguments to @code{AM_INIT_AUTOMAKE}
9543 (@pxref{Macros}) because they can require additional configure checks.
9544 Automake will complain if it sees such options in an
9545 @code{AUTOMAKE_OPTIONS} variable.
9546
9547 @option{tar-v7} selects the old V7 tar format.  This is the historical
9548 default.  This antiquated format is understood by all tar
9549 implementations and supports file names with up to 99 characters.  When
9550 given longer file names some tar implementations will diagnose the
9551 problem while other will generate broken tarballs or use non-portable
9552 extensions.  Furthermore, the V7 format cannot store empty
9553 directories.  When using this format, consider using the
9554 @option{filename-length-max=99} option to catch file names too long.
9555
9556 @option{tar-ustar} selects the ustar format defined by POSIX
9557 1003.1-1988.  This format is believed to be old enough to be portable.
9558 It fully supports empty directories.  It can store file names with up
9559 to 256 characters, provided that the file name can be split at
9560 directory separator in two parts, first of them being at most 155
9561 bytes long.  So, in most cases the maximum file name length will be
9562 shorter than 256 characters.  However you may run against broken tar
9563 implementations that incorrectly handle file names longer than 99
9564 characters (please report them to @email{@value{PACKAGE_BUGREPORT}} so we
9565 can document this accurately).
9566
9567 @option{tar-pax} selects the new pax interchange format defined by POSIX
9568 1003.1-2001.  It does not limit the length of file names.  However,
9569 this format is very young and should probably be restricted to
9570 packages that target only very modern platforms.  There are moves to
9571 change the pax format in an upward-compatible way, so this option may
9572 refer to a more recent version in the future.
9573
9574 @xref{Formats, , Controlling the Archive Format, tar, GNU Tar}, for
9575 further discussion about tar formats.
9576
9577 @command{configure} knows several ways to construct these formats.  It
9578 will not abort if it cannot find a tool up to the task (so that the
9579 package can still be built), but @samp{make dist} will fail.
9580
9581 @item @var{version}
9582 @cindex Option, @var{version}
9583 A version number (e.g., @samp{0.30}) can be specified.  If Automake is not
9584 newer than the version specified, creation of the @file{Makefile.in}
9585 will be suppressed.
9586
9587 @item @option{-W@var{category}} or @option{--warnings=@var{category}}
9588 @cindex Option, warnings
9589 @cindex Option, @option{-W@var{category}}
9590 @cindex Option, @option{--warnings=@var{category}}
9591 These options behave exactly like their command-line counterpart
9592 (@pxref{automake Invocation}).  This allows you to enable or disable some
9593 warning categories on a per-file basis.  You can also setup some warnings
9594 for your entire project; for instance, try @samp{AM_INIT_AUTOMAKE([-Wall])}
9595 in your @file{configure.ac}.
9596
9597 @end table
9598
9599 Unrecognized options are diagnosed by @command{automake}.
9600
9601 If you want an option to apply to all the files in the tree, you can use
9602 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.ac}.
9603 @xref{Macros}.
9604
9605
9606 @node Miscellaneous
9607 @chapter Miscellaneous Rules
9608
9609 There are a few rules and variables that didn't fit anywhere else.
9610
9611 @menu
9612 * Tags::        Interfacing to etags and mkid
9613 * Suffixes::    Handling new file extensions
9614 * Multilibs::   Support for multilibs (deprecated, soon to be removed).
9615 @end menu
9616
9617
9618 @node Tags
9619 @section Interfacing to @command{etags}
9620
9621 @cindex @file{TAGS} support
9622
9623 Automake will generate rules to generate @file{TAGS} files for use with
9624 GNU Emacs under some circumstances.
9625
9626 @trindex tags
9627 If any C, C++ or Fortran 77 source code or headers are present, then
9628 @code{tags} and @code{TAGS} rules will be generated for the directory.
9629 All files listed using the @code{_SOURCES}, @code{_HEADERS}, and
9630 @code{_LISP} primaries will be used to generate tags.  Note that
9631 generated source files that are not distributed must be declared in
9632 variables like @code{nodist_noinst_HEADERS} or
9633 @code{nodist_@var{prog}_SOURCES} or they will be ignored.
9634
9635 A @code{tags} rule will be output at the topmost directory of a
9636 multi-directory package.  When run from this topmost directory,
9637 @samp{make tags} will generate a @file{TAGS} file that includes by
9638 reference all @file{TAGS} files from subdirectories.
9639
9640 The @code{tags} rule will also be generated if the variable
9641 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
9642 directories that contain taggable source that @command{etags} does
9643 not understand.  The user can use the @code{ETAGSFLAGS} to pass
9644 additional flags to @command{etags}; @code{AM_ETAGSFLAGS} is also
9645 available for use in @file{Makefile.am}.
9646 @vindex ETAGS_ARGS
9647 @vindex ETAGSFLAGS
9648 @vindex AM_ETAGSFLAGS
9649
9650 Here is how Automake generates tags for its source, and for nodes in its
9651 Texinfo file:
9652
9653 @example
9654 ETAGS_ARGS = automake.in --lang=none \
9655  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
9656 @end example
9657
9658 If you add file names to @code{ETAGS_ARGS}, you will probably also
9659 want to define @code{TAGS_DEPENDENCIES}.  The contents of this variable
9660 are added directly to the dependencies for the @code{tags} rule.
9661 @vindex TAGS_DEPENDENCIES
9662
9663 Automake also generates a @code{ctags} rule that can be used to
9664 build @command{vi}-style @file{tags} files.  The variable @code{CTAGS}
9665 is the name of the program to invoke (by default @command{ctags});
9666 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
9667 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
9668
9669 Automake will also generate an @code{ID} rule that will run
9670 @command{mkid} on the source.  This is only supported on a
9671 directory-by-directory basis.
9672 @trindex id
9673
9674 Finally, Automake also emits rules to support the
9675 @uref{http://www.gnu.org/software/global/, GNU Global Tags program}.
9676 The @code{GTAGS} rule runs Global Tags and puts the
9677 result in the top build directory.  The variable @code{GTAGS_ARGS}
9678 holds arguments that are passed to @command{gtags}.
9679 @vindex GTAGS_ARGS
9680
9681
9682 @node Suffixes
9683 @section Handling new file extensions
9684
9685 @cindex Adding new @code{SUFFIXES}
9686 @cindex @code{SUFFIXES}, adding
9687 @vindex SUFFIXES
9688
9689 It is sometimes useful to introduce a new implicit rule to handle a file
9690 type that Automake does not know about.
9691
9692 For instance, suppose you had a compiler that could compile @file{.foo}
9693 files to @file{.o} files.  You would simply define a suffix rule for
9694 your language:
9695
9696 @example
9697 .foo.o:
9698         foocc -c -o $@@ $<
9699 @end example
9700
9701 Then you could directly use a @file{.foo} file in a @code{_SOURCES}
9702 variable and expect the correct results:
9703
9704 @example
9705 bin_PROGRAMS = doit
9706 doit_SOURCES = doit.foo
9707 @end example
9708
9709 This was the simpler and more common case.  In other cases, you will
9710 have to help Automake to figure out which extensions you are defining your
9711 suffix rule for.  This usually happens when your extension does not
9712 start with a dot.  Then, all you have to do is to put a list of new
9713 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
9714 implicit rule.
9715
9716 For instance, the following definition prevents Automake from misinterpreting
9717 the @samp{.idlC.cpp:} rule as an attempt to transform @file{.idlC} files into
9718 @file{.cpp} files.
9719
9720 @c Keep in sync with suffix7.test.
9721 @example
9722 SUFFIXES = .idl C.cpp
9723 .idlC.cpp:
9724         # whatever
9725 @end example
9726
9727 As you may have noted, the @code{SUFFIXES} variable behaves like the
9728 @code{.SUFFIXES} special target of @command{make}.  You should not touch
9729 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
9730 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
9731 @code{SUFFIXES} go at the start of the generated suffixes list, followed
9732 by Automake generated suffixes not already in the list.
9733
9734 @node Multilibs
9735 @section Support for Multilibs (deprecated, soon to be removed).
9736
9737 Automake used to support an obscure feature called multilibs.  @emph{This
9738 feature is now deprecated, and will be removed in the next major Automake
9739 version}.  Still, its implementation will remain available in the
9740 @file{contrib/} directory of the Automake distribution, so it should be
9741 very easy for motivated users to continue to use it in their projects,
9742 if they really need to.
9743
9744 A @dfn{multilib} is a library that is built for multiple different ABIs
9745 at a single time; each time the library is built with a different target
9746 flag combination.  This is only useful when the library is intended to
9747 be cross-compiled, and it is almost exclusively used for compiler
9748 support libraries.
9749
9750 @node Include
9751 @chapter Include
9752
9753 @cmindex include
9754 @cindex Including @file{Makefile} fragment
9755 @cindex @file{Makefile} fragment, including
9756
9757 Automake supports an @code{include} directive that  can be used to
9758 include other @file{Makefile} fragments when @command{automake} is run.
9759 Note that these fragments are read and interpreted by @command{automake},
9760 not by @command{make}.  As with conditionals, @command{make} has no idea that
9761 @code{include} is in use.
9762
9763 There are two forms of @code{include}:
9764
9765 @table @code
9766 @item include $(srcdir)/file
9767 Include a fragment that is found relative to the current source
9768 directory.
9769
9770 @item include $(top_srcdir)/file
9771 Include a fragment that is found relative to the top source directory.
9772 @end table
9773
9774 Note that if a fragment is included inside a conditional, then the
9775 condition applies to the entire contents of that fragment.
9776
9777 Makefile fragments included this way are always distributed because
9778 they are needed to rebuild @file{Makefile.in}.
9779
9780 @node Conditionals
9781 @chapter Conditionals
9782
9783 @cindex Conditionals
9784
9785 Automake supports a simple type of conditionals.
9786
9787 These conditionals are not the same as conditionals in
9788 GNU Make.  Automake conditionals are checked at configure time by the
9789 @file{configure} script, and affect the translation from
9790 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
9791 to @file{configure} and on results that @file{configure} has discovered
9792 about the host system.  GNU Make conditionals are checked at @command{make}
9793 time, and are based on variables passed to the make program or defined
9794 in the @file{Makefile}.
9795
9796 Automake conditionals will work with any make program.
9797
9798 @menu
9799 * Usage of Conditionals::       Declaring conditional content
9800 * Limits of Conditionals::      Enclosing complete statements
9801 @end menu
9802
9803 @node Usage of Conditionals
9804 @section Usage of Conditionals
9805
9806 @acindex AM_CONDITIONAL
9807 Before using a conditional, you must define it by using
9808 @code{AM_CONDITIONAL} in the @file{configure.ac} file (@pxref{Macros}).
9809
9810 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
9811 The conditional name, @var{conditional}, should be a simple string
9812 starting with a letter and containing only letters, digits, and
9813 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
9814 that are reserved by Automake.
9815
9816 The shell @var{condition} (suitable for use in a shell @code{if}
9817 statement) is evaluated when @command{configure} is run.  Note that you
9818 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
9819 time @command{configure} is run.  If @code{AM_CONDITIONAL} is run
9820 conditionally (e.g., in a shell @code{if} statement), then the result
9821 will confuse @command{automake}.
9822 @end defmac
9823
9824 @cindex @option{--enable-debug}, example
9825 @cindex Example conditional @option{--enable-debug}
9826 @cindex Conditional example, @option{--enable-debug}
9827
9828 Conditionals typically depend upon options that the user provides to
9829 the @command{configure} script.  Here is an example of how to write a
9830 conditional that is true if the user uses the @option{--enable-debug}
9831 option.
9832
9833 @example
9834 AC_ARG_ENABLE([debug],
9835 [  --enable-debug    Turn on debugging],
9836 [case "$@{enableval@}" in
9837   yes) debug=true ;;
9838   no)  debug=false ;;
9839   *) AC_MSG_ERROR([bad value $@{enableval@} for --enable-debug]) ;;
9840 esac],[debug=false])
9841 AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
9842 @end example
9843
9844 Here is an example of how to use that conditional in @file{Makefile.am}:
9845
9846 @cmindex if
9847 @cmindex endif
9848 @cmindex else
9849
9850 @example
9851 if DEBUG
9852 DBG = debug
9853 else
9854 DBG =
9855 endif
9856 noinst_PROGRAMS = $(DBG)
9857 @end example
9858
9859 This trivial example could also be handled using @code{EXTRA_PROGRAMS}
9860 (@pxref{Conditional Programs}).
9861
9862 You may only test a single variable in an @code{if} statement, possibly
9863 negated using @samp{!}.  The @code{else} statement may be omitted.
9864 Conditionals may be nested to any depth.  You may specify an argument to
9865 @code{else} in which case it must be the negation of the condition used
9866 for the current @code{if}.  Similarly you may specify the condition
9867 that is closed on the @code{endif} line:
9868
9869 @example
9870 if DEBUG
9871 DBG = debug
9872 else !DEBUG
9873 DBG =
9874 endif !DEBUG
9875 @end example
9876
9877 @noindent
9878 Unbalanced conditions are errors.  The @code{if}, @code{else}, and
9879 @code{endif} statements should not be indented, i.e., start on column
9880 one.
9881
9882 The @code{else} branch of the above two examples could be omitted,
9883 since assigning the empty string to an otherwise undefined variable
9884 makes no difference.
9885
9886 @acindex AM_COND_IF
9887 In order to allow access to the condition registered by
9888 @code{AM_CONDITIONAL} inside @file{configure.ac}, and to allow
9889 conditional @code{AC_CONFIG_FILES}, @code{AM_COND_IF} may be used:
9890
9891 @defmac AM_COND_IF (@var{conditional}, @ovar{if-true}, @ovar{if-false})
9892 If @var{conditional} is fulfilled, execute @var{if-true}, otherwise
9893 execute @var{if-false}.  If either branch contains @code{AC_CONFIG_FILES},
9894 it will cause @command{automake} to output the rules for the respective
9895 files only for the given condition.
9896 @end defmac
9897
9898 @code{AM_COND_IF} macros may be nested when m4 quotation is used
9899 properly (@pxref{M4 Quotation, ,, autoconf, The Autoconf Manual}).
9900
9901 @cindex Example conditional @code{AC_CONFIG_FILES}
9902 @cindex @code{AC_CONFIG_FILES}, conditional
9903
9904 Here is an example of how to define a conditional config file:
9905
9906 @example
9907 AM_CONDITIONAL([SHELL_WRAPPER], [test "x$with_wrapper" = xtrue])
9908 AM_COND_IF([SHELL_WRAPPER],
9909            [AC_CONFIG_FILES([wrapper:wrapper.in])])
9910 @end example
9911
9912 @node Limits of Conditionals
9913 @section Limits of Conditionals
9914
9915 Conditionals should enclose complete statements like variables or
9916 rules definitions.  Automake cannot deal with conditionals used inside
9917 a variable definition, for instance, and is not even able to diagnose
9918 this situation.  The following example would not work:
9919
9920 @example
9921 # This syntax is not understood by Automake
9922 AM_CPPFLAGS = \
9923   -DFEATURE_A \
9924 if WANT_DEBUG
9925   -DDEBUG \
9926 endif
9927   -DFEATURE_B
9928 @end example
9929
9930 However the intended definition of @code{AM_CPPFLAGS} can be achieved
9931 with
9932
9933 @example
9934 if WANT_DEBUG
9935   DEBUGFLAGS = -DDEBUG
9936 endif
9937 AM_CPPFLAGS = -DFEATURE_A $(DEBUGFLAGS) -DFEATURE_B
9938 @end example
9939
9940 @noindent
9941 or
9942
9943 @example
9944 AM_CPPFLAGS = -DFEATURE_A
9945 if WANT_DEBUG
9946 AM_CPPFLAGS += -DDEBUG
9947 endif
9948 AM_CPPFLAGS += -DFEATURE_B
9949 @end example
9950
9951 More details and examples of conditionals are described alongside
9952 various Automake features in this manual (@pxref{Conditional
9953 Subdirectories}, @pxref{Conditional Sources}, @pxref{Conditional
9954 Programs}, @pxref{Conditional Libtool Libraries}, @pxref{Conditional
9955 Libtool Sources}).
9956
9957 @node Silencing Make
9958 @chapter Silencing @command{make}
9959
9960 @cindex Silent @command{make}
9961 @cindex Silencing @command{make}
9962 @cindex Silent rules
9963 @cindex Silent @command{make} rules
9964
9965 @menu
9966 * Make verbosity::               Make is verbose by default
9967 * Tricks For Silencing Make::    Standard and generic ways to silence make
9968 * Automake silent-rules Option:: How Automake can help in silencing make
9969 @end menu
9970
9971 @node Make verbosity
9972 @section Make is verbose by default
9973
9974 Normally, when executing the set of rules associated with a target,
9975 @command{make} prints each rule before it is executed.  This behaviour,
9976 while having been in place for a long time, and being even mandated by
9977 the POSIX standard, starkly violates the ``silence is golden'' UNIX
9978 principle@footnote{See also
9979 @uref{http://catb.org/~esr/writings/taoup/html/ch11s09.html}.}:
9980
9981 @quotation
9982 When a program has nothing interesting or surprising to say, it should
9983 say nothing.  Well-behaved Unix programs do their jobs unobtrusively,
9984 with a minimum of fuss and bother.  Silence is golden.
9985 @end quotation
9986
9987 In fact, while such verbosity of @command{make} can theoretically be
9988 useful to track bugs and understand reasons of failures right away, it
9989 can also hide warning and error messages from @command{make}-invoked
9990 tools, drowning them in a flood of uninteresting and seldom useful
9991 messages, and thus allowing them to go easily undetected.
9992
9993 This problem can be very annoying, especially for developers, who usually
9994 know quite well what's going on behind the scenes, and for whom the
9995 verbose output from @command{make} ends up being mostly noise that hampers
9996 the easy detection of potentially important warning messages.
9997
9998 @node Tricks For Silencing Make
9999 @section Standard and generic ways to silence make
10000
10001 Here we describe some common idioms/tricks to obtain a quieter make
10002 output, with their relative advantages and drawbacks.  In the next
10003 section (@ref{Automake silent-rules Option}) we'll see how Automake
10004 can help in this respect.
10005
10006 @itemize @bullet
10007
10008 @item @command{make -s}
10009
10010 This simply causes @command{make} not to print @emph{any} rule before
10011 executing it.
10012
10013 The @option{-s} flag is mandated by POSIX, universally supported, and
10014 its purpose and function are easy to understand.
10015
10016 But it also has its serious limitations too.  First of all, it embodies
10017 an ``all or nothing'' strategy, i.e., either everything is silenced, or
10018 nothing is; this lack of granularity can sometimes be a fatal flaw.
10019 Moreover, when the @option{-s} flag is used, the @command{make} output
10020 might turn out to be too much terse; in case of errors, the user won't
10021 be able to easily see what rule or command have caused them, or even,
10022 in case of tools with poor error reporting, what the errors were!
10023
10024 @item @command{make >/dev/null || make}
10025
10026 Apparently, this perfectly obeys the ``silence is golden'' rule: warnings
10027 from stderr are passed through, output reporting is done only in case of
10028 error, and in that case it should provide a verbose-enough report to allow
10029 an easy determination of the error location and causes.
10030
10031 However, calling @command{make} two times in a row might hide errors
10032 (especially intermittent ones), or subtly change the expected semantic
10033 of the @command{make} calls --- things these which can clearly make
10034 debugging and error assessment very difficult.
10035
10036 @item @command{make --no-print-directory}
10037
10038 This is GNU @command{make} specific.  When called with the
10039 @option{--no-print-directory} option, GNU @command{make} will disable
10040 printing of the working directory by invoked sub-@command{make}s (the
10041 well-known ``@i{Entering/Leaving directory ...}'' messages).  This helps
10042 to decrease the verbosity of the output, but experience has shown that
10043 it can also often render debugging considerably harder in projects using
10044 deeply-nested @command{make} recursion.
10045
10046 As an aside, notice that the @option{--no-print-directory} option is
10047 automatically activated if the @option{-s} flag is used.
10048
10049 @c TODO: Other tricks?
10050 @c TODO: Maybe speak about the @code{.SILENT} target?
10051 @c TODO:  - Pros: More granularity on what to silence.
10052 @c TODO:  - Cons: No easy way to temporarily override.
10053
10054 @end itemize
10055
10056 @node Automake silent-rules Option
10057 @section How Automake can help in silencing make
10058
10059 The tricks and idioms for silencing @command{make} described in the
10060 previous section can be useful from time to time, but we've seen that
10061 they all have their serious drawbacks and limitations.  That's why
10062 automake provides support for a more advanced and flexible way of
10063 obtaining quieter output from @command{make}: the @option{silent-rules}
10064 mode.
10065
10066 @c TODO: Maybe describe in brief the precedent set by the build system
10067 @c of the Linux Kernel, from which Automake took inspiration ... Links?
10068
10069 To give the gist of what @option{silent-rules} can do, here is a simple
10070 comparison between a typical @command{make} output (where silent rules
10071 are disabled) and one with silent rules enabled:
10072
10073 @example
10074 % @kbd{cat Makefile.am}
10075 bin_PROGRAMS = foo
10076 foo_SOURCES = main.c func.c
10077 % @kbd{cat main.c}
10078 int main (void) @{ return func (); @}  /* func used undeclared */
10079 % @kbd{cat func.c}
10080 int func (void) @{ int i; return i; @} /* i used uninitialized */
10081
10082 @i{The make output is by default very verbose.  This causes warnings
10083 from the compiler to be somewhat hidden, and not immediate to spot.}
10084 % @kbd{make CFLAGS=-Wall}
10085 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
10086 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
10087 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT main.o
10088 -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
10089 main.c: In function â€˜main’:
10090 main.c:3:3: warning: implicit declaration of function â€˜func’
10091 mv -f .deps/main.Tpo .deps/main.Po
10092 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
10093 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
10094 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT func.o
10095 -MD -MP -MF .deps/func.Tpo -c -o func.o func.c
10096 func.c: In function â€˜func’:
10097 func.c:4:3: warning: â€˜i’ used uninitialized in this function
10098 mv -f .deps/func.Tpo .deps/func.Po
10099 gcc -Wall -o foo main.o func.o
10100
10101 @i{Clean up, so that we we can rebuild everything from scratch.}
10102 % @kbd{make clean}
10103 test -z "foo" || rm -f foo
10104 rm -f *.o
10105
10106 @i{Silent rules enabled: the output is minimal but informative.  In
10107 particular, the warnings from the compiler stick out very clearly.}
10108 % @kbd{make V=0 CFLAGS=-Wall}
10109   CC     main.o
10110 main.c: In function â€˜main’:
10111 main.c:3:3: warning: implicit declaration of function â€˜func’
10112   CC     func.o
10113 func.c: In function â€˜func’:
10114 func.c:4:3: warning: â€˜i’ used uninitialized in this function
10115   CCLD   foo
10116 @end example
10117
10118 @cindex silent-rules and libtool
10119 Also, in projects using @command{libtool}, the use of silent rules can
10120 automatically enable the @command{libtool}'s @option{--silent} option:
10121
10122 @example
10123 % @kbd{cat Makefile.am}
10124 lib_LTLIBRARIES = libx.la
10125
10126 % @kbd{make # Both make and libtool are verbose by default.}
10127 ...
10128 libtool: compile: gcc -DPACKAGE_NAME=\"foo\" ... -DLT_OBJDIR=\".libs/\"
10129   -I. -g -O2 -MT libx.lo -MD -MP -MF .deps/libx.Tpo -c libx.c -fPIC
10130   -DPIC -o .libs/libx.o
10131 mv -f .deps/libx.Tpo .deps/libx.Plo
10132 /bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -o libx.la -rpath
10133   /usr/local/lib libx.lo
10134 libtool: link: gcc -shared .libs/libx.o -Wl,-soname -Wl,libx.so.0
10135   -o .libs/libx.so.0.0.0
10136 libtool: link: cd .libs && rm -f libx.so && ln -s libx.so.0.0.0 libx.so
10137 ...
10138
10139 % @kbd{make V=0}
10140   CC     libx.lo
10141   CCLD   libx.la
10142 @end example
10143
10144 Let's now see how the @option{silent-rules} mode interfaces with the
10145 package developer and the package user.
10146
10147 To enable the use of @option{silent-rules} in his package, a developer
10148 needs to do either of the following:
10149
10150 @itemize @bullet
10151 @item
10152 Add the @option{silent-rules} option as argument to @code{AM_INIT_AUTOMAKE}.
10153 @item
10154 Call the @code{AM_SILENT_RULES} macro from within the @file{configure.ac}
10155 file.
10156 @end itemize
10157
10158 It is not possible to instead specify @option{silent-rules} in a
10159 @file{Makefile.am} file.
10160
10161 If the developer has done either of the above, then the user of the
10162 package may influence the verbosity at @command{configure} run time as
10163 well as at @command{make} run time:
10164
10165 @itemize @bullet
10166 @item
10167 @opindex --enable-silent-rules
10168 @opindex --disable-silent-rules
10169 Passing @option{--enable-silent-rules} to @command{configure} will cause
10170 build rules to be less verbose; the option @option{--disable-silent-rules}
10171 will cause normal verbose output.
10172 @item
10173 @vindex @code{V}
10174 At @command{make} run time, the default chosen at @command{configure}
10175 time may be overridden: @code{make V=1} will produce verbose output,
10176 @code{make V=0} less verbose output.
10177 @end itemize
10178
10179 @cindex default verbosity for silent-rules
10180 Note that silent rules are @emph{disabled} by default; the user must
10181 enable them explicitly at either @command{configure} run time or at
10182 @command{make} run time.  We think that this is a good policy, since
10183 it provides the casual user with enough information to prepare a good
10184 bug report in case anything breaks.
10185
10186 Still, notwithstanding the rationales above, a developer who wants to
10187 make silent rules enabled by default in his own package can do so by
10188 adding a @samp{yes} argument to the @code{AM_SILENT_RULES} call in
10189 @file{configure.ac}.  We advise against this approach, though.
10190
10191 @c Keep in sync with silent-configsite.test
10192 Users who prefer to have silent rules enabled by default can edit their
10193 @file{config.site} file to make the variable @code{enable_silent_rules}
10194 default to @samp{yes}.  This should still allow disabling silent rules
10195 at @command{configure} time and at @command{make} time.
10196
10197 @c FIXME: there's really a need to specify this explicitly?
10198 For portability to different @command{make} implementations, package authors
10199 are advised to not set the variable @code{V} inside the @file{Makefile.am}
10200 file, to allow the user to override the value for subdirectories as well.
10201
10202 The current implementation of this feature normally uses nested
10203 variable expansion @samp{$(@var{var1}$(V))}, a @file{Makefile} feature
10204 that is not required by POSIX 2008 but is widely supported in
10205 practice.  The @option{silent-rules} option thus turns off warnings
10206 about recursive variable expansion, which are in turn enabled by
10207 @option{-Wportability} (@pxref{automake Invocation}).  On the rare
10208 @command{make} implementations that do not support nested variable
10209 expansion, whether rules are silent is always determined at configure
10210 time, and cannot be overridden at make time.  Future versions of POSIX
10211 are likely to require nested variable expansion, so this minor
10212 limitation should go away with time.
10213
10214 @vindex @code{AM_V_GEN}
10215 @vindex @code{AM_V_at}
10216 @vindex @code{AM_DEFAULT_VERBOSITY}
10217 @vindex @code{AM_V}
10218 @vindex @code{AM_DEFAULT_V}
10219 To extend the silent mode to your own rules, you have two choices:
10220
10221 @itemize @bullet
10222 @item
10223 You can use the predefined variable @code{AM_V_GEN} as a prefix to
10224 commands that should output a status line in silent mode, and
10225 @code{AM_V_at} as a prefix to commands that should not output anything
10226 in silent mode.  When output is to be verbose, both of these variables
10227 will expand to the empty string.
10228 @item
10229 You can add your own variables, so strings of your own choice are shown.
10230 The following snippet shows how you would define your own equivalent of
10231 @code{AM_V_GEN}:
10232
10233 @example
10234 pkg_verbose = $(pkg_verbose_@@AM_V@@)
10235 pkg_verbose_ = $(pkg_verbose_@@AM_DEFAULT_V@@)
10236 pkg_verbose_0 = @@echo PKG-GEN $@@;
10237
10238 foo: foo.in
10239         $(pkg_verbose)cp $(srcdir)/foo.in $@@
10240 @end example
10241
10242 @end itemize
10243
10244 As a final note, observe that, even when silent rules are enabled,
10245 the @option{--no-print-directory} option is still required with GNU
10246 @command{make} if the ``@i{Entering/Leaving directory ...}'' messages
10247 are to be disabled.
10248
10249 @node Gnits
10250 @chapter The effect of @option{--gnu} and @option{--gnits}
10251
10252 @cindex @option{--gnu}, required files
10253 @cindex @option{--gnu}, complete description
10254
10255 The @option{--gnu} option (or @option{gnu} in the
10256 @code{AUTOMAKE_OPTIONS} variable) causes @command{automake} to check
10257 the following:
10258
10259 @itemize @bullet
10260 @item
10261 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
10262 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
10263 or @file{COPYING}, are required at the topmost directory of the package.
10264
10265 If the @option{--add-missing} option is given, @command{automake} will
10266 add a generic version of the @file{INSTALL} file as well as the
10267 @file{COPYING} file containing the text of the current version of the
10268 GNU General Public License existing at the time of this Automake release
10269 (version 3 as this is written, @uref{http://www.gnu.org/@/copyleft/@/gpl.html}).
10270 However, an existing @file{COPYING} file will never be overwritten by
10271 @command{automake}.
10272
10273 @item
10274 The options @option{no-installman} and @option{no-installinfo} are
10275 prohibited.
10276 @end itemize
10277
10278 Note that this option will be extended in the future to do even more
10279 checking; it is advisable to be familiar with the precise requirements
10280 of the GNU standards.  Also, @option{--gnu} can require certain
10281 non-standard GNU programs to exist for use by various maintainer-only
10282 rules; for instance, in the future @command{pathchk} might be required for
10283 @samp{make dist}.
10284
10285 @cindex @option{--gnits}, complete description
10286
10287 The @option{--gnits} option does everything that @option{--gnu} does, and
10288 checks the following as well:
10289
10290 @itemize @bullet
10291 @item
10292 @samp{make installcheck} will check to make sure that the @option{--help}
10293 and @option{--version} really print a usage message and a version string,
10294 respectively.  This is the @option{std-options} option (@pxref{Options}).
10295
10296 @item
10297 @samp{make dist} will check to make sure the @file{NEWS} file has been
10298 updated to the current version.
10299
10300 @item
10301 @code{VERSION} is checked to make sure its format complies with Gnits
10302 standards.
10303 @c FIXME xref when standards are finished
10304
10305 @item
10306 @cindex @file{README-alpha}
10307 If @code{VERSION} indicates that this is an alpha release, and the file
10308 @file{README-alpha} appears in the topmost directory of a package, then
10309 it is included in the distribution.  This is done in @option{--gnits}
10310 mode, and no other, because this mode is the only one where version
10311 number formats are constrained, and hence the only mode where Automake
10312 can automatically determine whether @file{README-alpha} should be
10313 included.
10314
10315 @item
10316 The file @file{THANKS} is required.
10317 @end itemize
10318
10319
10320 @node Cygnus
10321 @chapter The effect of @option{--cygnus}
10322
10323 @cindex @option{cygnus} strictness
10324
10325 Some packages, notably GNU GCC and GNU gdb, have a build environment
10326 originally written at Cygnus Support (subsequently renamed Cygnus
10327 Solutions, and then later purchased by Red Hat).  Packages with this
10328 ancestry are sometimes referred to as ``Cygnus'' trees.
10329
10330 A Cygnus tree has slightly different rules for how a
10331 @file{Makefile.in} is to be constructed.  Passing @option{--cygnus} to
10332 @command{automake} will cause any generated @file{Makefile.in} to
10333 comply with Cygnus rules.
10334
10335 Here are the precise effects of @option{--cygnus}:
10336
10337 @itemize @bullet
10338 @item
10339 Info files are always created in the build directory, and not in the
10340 source directory.
10341
10342 @item
10343 @file{texinfo.tex} is not required if a Texinfo source file is
10344 specified.  The assumption is that the file will be supplied, but in a
10345 place that Automake cannot find.  This assumption is an artifact of how
10346 Cygnus packages are typically bundled.
10347
10348 @item
10349 @samp{make dist} is not supported, and the rules for it are not
10350 generated.  Cygnus-style trees use their own distribution mechanism.
10351
10352 @item
10353 Certain tools will be searched for in the build tree as well as in the
10354 user's @env{PATH}.  These tools are @command{runtest}, @command{expect},
10355 @command{makeinfo} and @command{texi2dvi}.
10356
10357 @item
10358 @option{--foreign} is implied.
10359
10360 @item
10361 The options @option{no-installinfo} and @option{no-dependencies} are
10362 implied.
10363
10364 @item
10365 The macro @code{AM_MAINTAINER_MODE} is required.
10366
10367 @item
10368 The @code{check} target doesn't depend on @code{all}.
10369 @end itemize
10370
10371 GNU maintainers are advised to use @option{gnu} strictness in preference
10372 to the special Cygnus mode.  Some day, perhaps, the differences between
10373 Cygnus trees and GNU trees will disappear (for instance, as GCC is made
10374 more standards compliant).  At that time the special Cygnus mode will be
10375 removed.
10376
10377
10378 @node Not Enough
10379 @chapter When Automake Isn't Enough
10380
10381 In some situations, where Automake is not up to one task, one has to
10382 resort to handwritten rules or even handwritten @file{Makefile}s.
10383
10384 @menu
10385 * Extending::                   Adding new rules or overriding existing ones.
10386 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
10387 @end menu
10388
10389 @node Extending
10390 @section Extending Automake Rules
10391
10392 With some minor exceptions (for example @code{_PROGRAMS} variables,
10393 @code{TESTS}, or @code{XFAIL_TESTS}) being rewritten to append
10394 @samp{$(EXEEXT)}), the contents of a @file{Makefile.am} is copied to
10395 @file{Makefile.in} verbatim.
10396
10397 @cindex copying semantics
10398
10399 These copying semantics mean that many problems can be worked around
10400 by simply adding some @command{make} variables and rules to
10401 @file{Makefile.am}.  Automake will ignore these additions.
10402
10403 @cindex conflicting definitions
10404 @cindex rules, conflicting
10405 @cindex variables, conflicting
10406 @cindex definitions, conflicts
10407
10408 Since a @file{Makefile.in} is built from data gathered from three
10409 different places (@file{Makefile.am}, @file{configure.ac}, and
10410 @command{automake} itself), it is possible to have conflicting
10411 definitions of rules or variables.  When building @file{Makefile.in}
10412 the following priorities are respected by @command{automake} to ensure
10413 the user always has the last word:
10414
10415 @itemize
10416 @item
10417 User defined variables in @file{Makefile.am} have priority over
10418 variables @code{AC_SUBST}ed from @file{configure.ac}, and
10419 @code{AC_SUBST}ed variables have priority over
10420 @command{automake}-defined variables.
10421 @item
10422 As far as rules are concerned, a user-defined rule overrides any
10423 @command{automake}-defined rule for the same target.
10424 @end itemize
10425
10426 @cindex overriding rules
10427 @cindex overriding semantics
10428 @cindex rules, overriding
10429
10430 These overriding semantics make it possible to fine tune some default
10431 settings of Automake, or replace some of its rules.  Overriding
10432 Automake rules is often inadvisable, particularly in the topmost
10433 directory of a package with subdirectories.  The @option{-Woverride}
10434 option (@pxref{automake Invocation}) comes in handy to catch overridden
10435 definitions.
10436
10437 Note that Automake does not make any distinction between rules with
10438 commands and rules that only specify dependencies.  So it is not
10439 possible to append new dependencies to an @command{automake}-defined
10440 target without redefining the entire rule.
10441
10442 @cindex @option{-local} targets
10443 @cindex local targets
10444
10445 However, various useful targets have a @samp{-local} version you can
10446 specify in your @file{Makefile.am}.  Automake will supplement the
10447 standard target with these user-supplied targets.
10448
10449 @trindex  all
10450 @trindex  all-local
10451 @trindex  info
10452 @trindex  info-local
10453 @trindex  dvi
10454 @trindex  dvi-local
10455 @trindex  ps
10456 @trindex  ps-local
10457 @trindex  pdf
10458 @trindex  pdf-local
10459 @trindex  html
10460 @trindex  html-local
10461 @trindex  check
10462 @trindex  check-local
10463 @trindex  install
10464 @trindex  install-data
10465 @trindex  install-data-local
10466 @trindex  install-dvi
10467 @trindex  install-dvi-local
10468 @trindex  install-exec
10469 @trindex  install-exec-local
10470 @trindex  install-html
10471 @trindex  install-html-local
10472 @trindex  install-info
10473 @trindex  install-info-local
10474 @trindex  install-pdf
10475 @trindex  install-pdf-local
10476 @trindex  install-ps
10477 @trindex  install-ps-local
10478 @trindex  uninstall
10479 @trindex  uninstall-local
10480 @trindex  mostlyclean
10481 @trindex  mostlyclean-local
10482 @trindex  clean
10483 @trindex  clean-local
10484 @trindex  distclean
10485 @trindex  distclean-local
10486 @trindex  installdirs
10487 @trindex  installdirs-local
10488 @trindex  installcheck
10489 @trindex  installcheck-local
10490
10491 The targets that support a local version are @code{all}, @code{info},
10492 @code{dvi}, @code{ps}, @code{pdf}, @code{html}, @code{check},
10493 @code{install-data}, @code{install-dvi}, @code{install-exec},
10494 @code{install-html}, @code{install-info}, @code{install-pdf},
10495 @code{install-ps}, @code{uninstall}, @code{installdirs},
10496 @code{installcheck} and the various @code{clean} targets
10497 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
10498 @code{maintainer-clean}).
10499
10500 Note that there are no @code{uninstall-exec-local} or
10501 @code{uninstall-data-local} targets; just use @code{uninstall-local}.
10502 It doesn't make sense to uninstall just data or just executables.
10503
10504 For instance, here is one way to erase a subdirectory during
10505 @samp{make clean} (@pxref{Clean}).
10506
10507 @example
10508 clean-local:
10509         -rm -rf testSubDir
10510 @end example
10511
10512 You may be tempted to use @code{install-data-local} to install a file
10513 to some hard-coded location, but you should avoid this
10514 (@pxref{Hard-Coded Install Paths}).
10515
10516 With the @code{-local} targets, there is no particular guarantee of
10517 execution order; typically, they are run early, but with parallel
10518 make, there is no way to be sure of that.
10519
10520 @cindex @option{-hook} targets
10521 @cindex hook targets
10522 @trindex install-data-hook
10523 @trindex install-exec-hook
10524 @trindex uninstall-hook
10525 @trindex dist-hook
10526
10527 In contrast, some rules also have a way to run another rule, called a
10528 @dfn{hook}; hooks are always executed after the main rule's work is done.
10529 The hook is named after the principal target, with @samp{-hook} appended.
10530 The targets allowing hooks are @code{install-data},
10531 @code{install-exec}, @code{uninstall}, @code{dist}, and
10532 @code{distcheck}.
10533
10534 For instance, here is how to create a hard link to an installed program:
10535
10536 @example
10537 install-exec-hook:
10538         ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
10539            $(DESTDIR)$(bindir)/proglink$(EXEEXT)
10540 @end example
10541
10542 Although cheaper and more portable than symbolic links, hard links
10543 will not work everywhere (for instance, OS/2 does not have
10544 @command{ln}).  Ideally you should fall back to @samp{cp -p} when
10545 @command{ln} does not work.  An easy way, if symbolic links are
10546 acceptable to you, is to add @code{AC_PROG_LN_S} to
10547 @file{configure.ac} (@pxref{Particular Programs, , Particular Program
10548 Checks, autoconf, The Autoconf Manual}) and use @samp{$(LN_S)} in
10549 @file{Makefile.am}.
10550
10551 @cindex versioned binaries, installing
10552 @cindex installing versioned binaries
10553 @cindex @code{LN_S} example
10554 For instance, here is how you could install a versioned copy of a
10555 program using @samp{$(LN_S)}:
10556
10557 @c Keep in sync with insthook.test
10558 @example
10559 install-exec-hook:
10560         cd $(DESTDIR)$(bindir) && \
10561           mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
10562           $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
10563 @end example
10564
10565 Note that we rename the program so that a new version will erase the
10566 symbolic link, not the real binary.  Also we @command{cd} into the
10567 destination directory in order to create relative links.
10568
10569 When writing @code{install-exec-hook} or @code{install-data-hook},
10570 please bear in mind that the exec/data distinction is based on the
10571 installation directory, not on the primary used (@pxref{The Two Parts of
10572 Install}).
10573 @c Keep in sync with primary-prefix-couples-documented-valid.test.
10574 So a @code{foo_SCRIPTS} will be installed by
10575 @code{install-data}, and a @code{barexec_SCRIPTS} will be installed by
10576 @code{install-exec}.  You should define your hooks consequently.
10577
10578 @c FIXME should include discussion of variables you can use in these
10579 @c rules
10580
10581 @node Third-Party Makefiles
10582 @section Third-Party @file{Makefile}s
10583
10584 @cindex Third-party packages, interfacing with
10585 @cindex Interfacing with third-party packages
10586
10587 In most projects all @file{Makefile}s are generated by Automake.  In
10588 some cases, however, projects need to embed subdirectories with
10589 handwritten @file{Makefile}s.  For instance, one subdirectory could be
10590 a third-party project with its own build system, not using Automake.
10591
10592 It is possible to list arbitrary directories in @code{SUBDIRS} or
10593 @code{DIST_SUBDIRS} provided each of these directories has a
10594 @file{Makefile} that recognizes all the following recursive targets.
10595
10596 @cindex recursive targets and third-party @file{Makefile}s
10597 When a user runs one of these targets, that target is run recursively
10598 in all subdirectories.  This is why it is important that even
10599 third-party @file{Makefile}s support them.
10600
10601 @table @code
10602 @item all
10603 Compile the entire package.  This is the default target in
10604 Automake-generated @file{Makefile}s, but it does not need to be the
10605 default in third-party @file{Makefile}s.
10606
10607 @item distdir
10608 @trindex distdir
10609 @vindex distdir
10610 @vindex top_distdir
10611 Copy files to distribute into @samp{$(distdir)}, before a tarball is
10612 constructed.  Of course this target is not required if the
10613 @option{no-dist} option (@pxref{Options}) is used.
10614
10615 The variables @samp{$(top_distdir)} and @samp{$(distdir)}
10616 (@pxref{The dist Hook}) will be passed from the outer package to the subpackage
10617 when the @code{distdir} target is invoked.  These two variables have
10618 been adjusted for the directory that is being recursed into, so they
10619 are ready to use.
10620
10621 @item install
10622 @itemx install-data
10623 @itemx install-exec
10624 @itemx uninstall
10625 Install or uninstall files (@pxref{Install}).
10626
10627 @item install-dvi
10628 @itemx install-html
10629 @itemx install-info
10630 @itemx install-ps
10631 @itemx install-pdf
10632 Install only some specific documentation format (@pxref{Texinfo}).
10633
10634 @item installdirs
10635 Create install directories, but do not install any files.
10636
10637 @item check
10638 @itemx installcheck
10639 Check the package (@pxref{Tests}).
10640
10641 @item mostlyclean
10642 @itemx clean
10643 @itemx distclean
10644 @itemx maintainer-clean
10645 Cleaning rules (@pxref{Clean}).
10646
10647 @item dvi
10648 @itemx pdf
10649 @itemx ps
10650 @itemx info
10651 @itemx html
10652 Build the documentation in various formats (@pxref{Texinfo}).
10653
10654 @item tags
10655 @itemx ctags
10656 Build @file{TAGS} and @file{CTAGS} (@pxref{Tags}).
10657 @end table
10658
10659 If you have ever used Gettext in a project, this is a good example of
10660 how third-party @file{Makefile}s can be used with Automake.  The
10661 @file{Makefile}s @command{gettextize} puts in the @file{po/} and
10662 @file{intl/} directories are handwritten @file{Makefile}s that
10663 implement all these targets.  That way they can be added to
10664 @code{SUBDIRS} in Automake packages.
10665
10666 Directories that are only listed in @code{DIST_SUBDIRS} but not in
10667 @code{SUBDIRS} need only the @code{distclean},
10668 @code{maintainer-clean}, and @code{distdir} rules (@pxref{Conditional
10669 Subdirectories}).
10670
10671 Usually, many of these rules are irrelevant to the third-party
10672 subproject, but they are required for the whole package to work.  It's
10673 OK to have a rule that does nothing, so if you are integrating a
10674 third-party project with no documentation or tag support, you could
10675 simply augment its @file{Makefile} as follows:
10676
10677 @example
10678 EMPTY_AUTOMAKE_TARGETS = dvi pdf ps info html tags ctags
10679 .PHONY: $(EMPTY_AUTOMAKE_TARGETS)
10680 $(EMPTY_AUTOMAKE_TARGETS):
10681 @end example
10682
10683 Another aspect of integrating third-party build systems is whether
10684 they support VPATH builds (@pxref{VPATH Builds}).  Obviously if the
10685 subpackage does not support VPATH builds the whole package will not
10686 support VPATH builds.  This in turns means that @samp{make distcheck}
10687 will not work, because it relies on VPATH builds.  Some people can
10688 live without this (actually, many Automake users have never heard of
10689 @samp{make distcheck}).  Other people may prefer to revamp the
10690 existing @file{Makefile}s to support VPATH@.  Doing so does not
10691 necessarily require Automake, only Autoconf is needed (@pxref{Build
10692 Directories, , Build Directories, autoconf, The Autoconf Manual}).
10693 The necessary substitutions: @samp{@@srcdir@@}, @samp{@@top_srcdir@@},
10694 and @samp{@@top_builddir@@} are defined by @file{configure} when it
10695 processes a @file{Makefile} (@pxref{Preset Output Variables, , Preset
10696 Output Variables, autoconf, The Autoconf Manual}), they are not
10697 computed by the Makefile like the aforementioned @samp{$(distdir)} and
10698 @samp{$(top_distdir)} variables.
10699
10700 It is sometimes inconvenient to modify a third-party @file{Makefile}
10701 to introduce the above required targets.  For instance, one may want to
10702 keep the third-party sources untouched to ease upgrades to new
10703 versions.
10704
10705 @cindex @file{GNUmakefile} including @file{Makefile}
10706 Here are two other ideas.  If GNU make is assumed, one possibility is
10707 to add to that subdirectory a @file{GNUmakefile} that defines the
10708 required targets and includes the third-party @file{Makefile}.  For
10709 this to work in VPATH builds, @file{GNUmakefile} must lie in the build
10710 directory; the easiest way to do this is to write a
10711 @file{GNUmakefile.in} instead, and have it processed with
10712 @code{AC_CONFIG_FILES} from the outer package.  For example if we
10713 assume @file{Makefile} defines all targets except the documentation
10714 targets, and that the @code{check} target is actually called
10715 @code{test}, we could write @file{GNUmakefile} (or
10716 @file{GNUmakefile.in}) like this:
10717
10718 @example
10719 # First, include the real Makefile
10720 include Makefile
10721 # Then, define the other targets needed by Automake Makefiles.
10722 .PHONY: dvi pdf ps info html check
10723 dvi pdf ps info html:
10724 check: test
10725 @end example
10726
10727 @cindex Proxy @file{Makefile} for third-party packages
10728 A similar idea that does not use @code{include} is to write a proxy
10729 @file{Makefile} that dispatches rules to the real @file{Makefile},
10730 either with @samp{$(MAKE) -f Makefile.real $(AM_MAKEFLAGS) target} (if
10731 it's OK to rename the original @file{Makefile}) or with @samp{cd
10732 subdir && $(MAKE) $(AM_MAKEFLAGS) target} (if it's OK to store the
10733 subdirectory project one directory deeper).  The good news is that
10734 this proxy @file{Makefile} can be generated with Automake.  All we
10735 need are @option{-local} targets (@pxref{Extending}) that perform the
10736 dispatch.  Of course the other Automake features are available, so you
10737 could decide to let Automake perform distribution or installation.
10738 Here is a possible @file{Makefile.am}:
10739
10740 @example
10741 all-local:
10742         cd subdir && $(MAKE) $(AM_MAKEFLAGS) all
10743 check-local:
10744         cd subdir && $(MAKE) $(AM_MAKEFLAGS) test
10745 clean-local:
10746         cd subdir && $(MAKE) $(AM_MAKEFLAGS) clean
10747
10748 # Assuming the package knows how to install itself
10749 install-data-local:
10750         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-data
10751 install-exec-local:
10752         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-exec
10753 uninstall-local:
10754         cd subdir && $(MAKE) $(AM_MAKEFLAGS) uninstall
10755
10756 # Distribute files from here.
10757 EXTRA_DIST = subdir/Makefile subdir/program.c ...
10758 @end example
10759
10760 Pushing this idea to the extreme, it is also possible to ignore the
10761 subproject build system and build everything from this proxy
10762 @file{Makefile.am}.  This might sound very sensible if you need VPATH
10763 builds but the subproject does not support them.
10764
10765 @node Distributing
10766 @chapter Distributing @file{Makefile.in}s
10767
10768 Automake places no restrictions on the distribution of the resulting
10769 @file{Makefile.in}s.  We still encourage software authors to
10770 distribute their work under terms like those of the GPL, but doing so
10771 is not required to use Automake.
10772
10773 Some of the files that can be automatically installed via the
10774 @option{--add-missing} switch do fall under the GPL@.  However, these also
10775 have a special exception allowing you to distribute them with your
10776 package, regardless of the licensing you choose.
10777
10778
10779 @node API Versioning
10780 @chapter Automake API Versioning
10781
10782 New Automake releases usually include bug fixes and new features.
10783 Unfortunately they may also introduce new bugs and incompatibilities.
10784 This makes four reasons why a package may require a particular Automake
10785 version.
10786
10787 Things get worse when maintaining a large tree of packages, each one
10788 requiring a different version of Automake.  In the past, this meant that
10789 any developer (and sometimes users) had to install several versions of
10790 Automake in different places, and switch @samp{$PATH} appropriately for
10791 each package.
10792
10793 Starting with version 1.6, Automake installs versioned binaries.  This
10794 means you can install several versions of Automake in the same
10795 @samp{$prefix}, and can select an arbitrary Automake version by running
10796 @command{automake-1.6} or @command{automake-1.7} without juggling with
10797 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
10798 will use @command{automake-1.6} explicitly in their rebuild rules.
10799
10800 The number @samp{1.6} in @command{automake-1.6} is Automake's API version,
10801 not Automake's version.  If a bug fix release is made, for instance
10802 Automake 1.6.1, the API version will remain 1.6.  This means that a
10803 package that works with Automake 1.6 should also work with 1.6.1; after
10804 all, this is what people expect from bug fix releases.
10805
10806 If your package relies on a feature or a bug fix introduced in
10807 a release, you can pass this version as an option to Automake to ensure
10808 older releases will not be used.  For instance, use this in your
10809 @file{configure.ac}:
10810
10811 @example
10812   AM_INIT_AUTOMAKE([1.6.1])    dnl Require Automake 1.6.1 or better.
10813 @end example
10814
10815 @noindent
10816 or, in a particular @file{Makefile.am}:
10817
10818 @example
10819   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
10820 @end example
10821
10822 @noindent
10823 Automake will print an error message if its version is
10824 older than the requested version.
10825
10826
10827 @heading What is in the API
10828
10829 Automake's programming interface is not easy to define.  Basically it
10830 should include at least all @strong{documented} variables and targets
10831 that a @file{Makefile.am} author can use, any behavior associated with
10832 them (e.g., the places where @samp{-hook}'s are run), the command line
10833 interface of @command{automake} and @command{aclocal}, @dots{}
10834
10835 @heading What is not in the API
10836
10837 Every undocumented variable, target, or command line option, is not part
10838 of the API@.  You should avoid using them, as they could change from one
10839 version to the other (even in bug fix releases, if this helps to fix a
10840 bug).
10841
10842 If it turns out you need to use such an undocumented feature, contact
10843 @email{automake@@gnu.org} and try to get it documented and exercised by
10844 the test-suite.
10845
10846 @node Upgrading
10847 @chapter Upgrading a Package to a Newer Automake Version
10848
10849 Automake maintains three kind of files in a package.
10850
10851 @itemize
10852 @item @file{aclocal.m4}
10853 @item @file{Makefile.in}s
10854 @item auxiliary tools like @file{install-sh} or @file{py-compile}
10855 @end itemize
10856
10857 @file{aclocal.m4} is generated by @command{aclocal} and contains some
10858 Automake-supplied M4 macros.  Auxiliary tools are installed by
10859 @samp{automake --add-missing} when needed.  @file{Makefile.in}s are
10860 built from @file{Makefile.am} by @command{automake}, and rely on the
10861 definitions of the M4 macros put in @file{aclocal.m4} as well as the
10862 behavior of the auxiliary tools installed.
10863
10864 Because all these files are closely related, it is important to
10865 regenerate all of them when upgrading to a newer Automake release.
10866 The usual way to do that is
10867
10868 @example
10869 aclocal # with any option needed (such a -I m4)
10870 autoconf
10871 automake --add-missing --force-missing
10872 @end example
10873
10874 @noindent
10875 or more conveniently:
10876
10877 @example
10878 autoreconf -vfi
10879 @end example
10880
10881 The use of @option{--force-missing} ensures that auxiliary tools will be
10882 overridden by new versions (@pxref{automake Invocation}).
10883
10884 It is important to regenerate all these files each time Automake is
10885 upgraded, even between bug fixes releases.  For instance, it is not
10886 unusual for a bug fix to involve changes to both the rules generated
10887 in @file{Makefile.in} and the supporting M4 macros copied to
10888 @file{aclocal.m4}.
10889
10890 Presently @command{automake} is able to diagnose situations where
10891 @file{aclocal.m4} has been generated with another version of
10892 @command{aclocal}.  However it never checks whether auxiliary scripts
10893 are up-to-date.  In other words, @command{automake} will tell you when
10894 @command{aclocal} needs to be rerun, but it will never diagnose a
10895 missing @option{--force-missing}.
10896
10897 Before upgrading to a new major release, it is a good idea to read the
10898 file @file{NEWS}.  This file lists all changes between releases: new
10899 features, obsolete constructs, known incompatibilities, and
10900 workarounds.
10901
10902 @node FAQ
10903 @chapter Frequently Asked Questions about Automake
10904
10905 This chapter covers some questions that often come up on the mailing
10906 lists.
10907
10908 @menu
10909 * CVS::                         CVS and generated files
10910 * maintainer-mode::             missing and AM_MAINTAINER_MODE
10911 * Wildcards::                   Why doesn't Automake support wildcards?
10912 * Limitations on File Names::   Limitations on source and installed file names
10913 * distcleancheck::              Files left in build directory after distclean
10914 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
10915 * Renamed Objects::             Why are object files sometimes renamed?
10916 * Per-Object Flags::            How to simulate per-object flags?
10917 * Multiple Outputs::            Writing rules for tools with many output files
10918 * Hard-Coded Install Paths::    Installing to hard-coded locations
10919 * Debugging Make Rules::        Strategies when things don't work as expected
10920 * Reporting Bugs::              Feedback on bugs and feature requests
10921 @end menu
10922
10923 @node CVS
10924 @section CVS and generated files
10925
10926 @subheading Background: distributed generated Files
10927 @cindex generated files, distributed
10928 @cindex rebuild rules
10929
10930 Packages made with Autoconf and Automake ship with some generated
10931 files like @file{configure} or @file{Makefile.in}.  These files were
10932 generated on the developer's host and are distributed so that
10933 end-users do not have to install the maintainer tools required to
10934 rebuild them.  Other generated files like Lex scanners, Yacc parsers,
10935 or Info documentation, are usually distributed on similar grounds.
10936
10937 Automake outputs rules in @file{Makefile}s to rebuild these files.  For
10938 instance, @command{make} will run @command{autoconf} to rebuild
10939 @file{configure} whenever @file{configure.ac} is changed.  This makes
10940 development safer by ensuring a @file{configure} is never out-of-date
10941 with respect to @file{configure.ac}.
10942
10943 As generated files shipped in packages are up-to-date, and because
10944 @command{tar} preserves times-tamps, these rebuild rules are not
10945 triggered when a user unpacks and builds a package.
10946
10947 @subheading Background: CVS and Timestamps
10948 @cindex timestamps and CVS
10949 @cindex CVS and timestamps
10950
10951 Unless you use CVS keywords (in which case files must be updated at
10952 commit time), CVS preserves timestamp during @samp{cvs commit} and
10953 @samp{cvs import -d} operations.
10954
10955 When you check out a file using @samp{cvs checkout} its timestamp is
10956 set to that of the revision that is being checked out.
10957
10958 However, during @command{cvs update}, files will have the date of the
10959 update, not the original timestamp of this revision.  This is meant to
10960 make sure that @command{make} notices sources files have been updated.
10961
10962 This timestamp shift is troublesome when both sources and generated
10963 files are kept under CVS@.  Because CVS processes files in lexical
10964 order, @file{configure.ac} will appear newer than @file{configure}
10965 after a @command{cvs update} that updates both files, even if
10966 @file{configure} was newer than @file{configure.ac} when it was
10967 checked in.  Calling @command{make} will then trigger a spurious rebuild
10968 of @file{configure}.
10969
10970 @subheading Living with CVS in Autoconfiscated Projects
10971 @cindex CVS and generated files
10972 @cindex generated files and CVS
10973
10974 There are basically two clans amongst maintainers: those who keep all
10975 distributed files under CVS, including generated files, and those who
10976 keep generated files @emph{out} of CVS.
10977
10978 @subsubheading All Files in CVS
10979
10980 @itemize @bullet
10981 @item
10982 The CVS repository contains all distributed files so you know exactly
10983 what is distributed, and you can checkout any prior version entirely.
10984
10985 @item
10986 Maintainers can see how generated files evolve (for instance, you can
10987 see what happens to your @file{Makefile.in}s when you upgrade Automake
10988 and make sure they look OK).
10989
10990 @item
10991 Users do not need the autotools to build a checkout of the project, it
10992 works just like a released tarball.
10993
10994 @item
10995 If users use @command{cvs update} to update their copy, instead of
10996 @command{cvs checkout} to fetch a fresh one, timestamps will be
10997 inaccurate.  Some rebuild rules will be triggered and attempt to
10998 run developer tools such as @command{autoconf} or @command{automake}.
10999
11000 Actually, calls to such tools are all wrapped into a call to the
11001 @command{missing} script discussed later (@pxref{maintainer-mode}).
11002 @command{missing} will take care of fixing the timestamps when these
11003 tools are not installed, so that the build can continue.
11004
11005 @item
11006 In distributed development, developers are likely to have different
11007 version of the maintainer tools installed.  In this case rebuilds
11008 triggered by timestamp lossage will lead to spurious changes
11009 to generated files.  There are several solutions to this:
11010
11011 @itemize
11012 @item
11013 All developers should use the same versions, so that the rebuilt files
11014 are identical to files in CVS@.  (This starts to be difficult when each
11015 project you work on uses different versions.)
11016 @item
11017 Or people use a script to fix the timestamp after a checkout (the GCC
11018 folks have such a script).
11019 @item
11020 Or @file{configure.ac} uses @code{AM_MAINTAINER_MODE}, which will
11021 disable all these rebuild rules by default.  This is further discussed
11022 in @ref{maintainer-mode}.
11023 @end itemize
11024
11025 @item
11026 Although we focused on spurious rebuilds, the converse can also
11027 happen.  CVS's timestamp handling can also let you think an
11028 out-of-date file is up-to-date.
11029
11030 For instance, suppose a developer has modified @file{Makefile.am} and
11031 has rebuilt @file{Makefile.in}, and then decides to do a last-minute
11032 change to @file{Makefile.am} right before checking in both files
11033 (without rebuilding @file{Makefile.in} to account for the change).
11034
11035 This last change to @file{Makefile.am} makes the copy of
11036 @file{Makefile.in} out-of-date.  Since CVS processes files
11037 alphabetically, when another developer @samp{cvs update}s his or her
11038 tree, @file{Makefile.in} will happen to be newer than
11039 @file{Makefile.am}.  This other developer will not see that
11040 @file{Makefile.in} is out-of-date.
11041
11042 @end itemize
11043
11044 @subsubheading Generated Files out of CVS
11045
11046 One way to get CVS and @command{make} working peacefully is to never
11047 store generated files in CVS, i.e., do not CVS-control files that
11048 are @file{Makefile} targets (also called @emph{derived} files).
11049
11050 This way developers are not annoyed by changes to generated files.  It
11051 does not matter if they all have different versions (assuming they are
11052 compatible, of course).  And finally, timestamps are not lost, changes
11053 to sources files can't be missed as in the
11054 @file{Makefile.am}/@file{Makefile.in} example discussed earlier.
11055
11056 The drawback is that the CVS repository is not an exact copy of what
11057 is distributed and that users now need to install various development
11058 tools (maybe even specific versions) before they can build a checkout.
11059 But, after all, CVS's job is versioning, not distribution.
11060
11061 Allowing developers to use different versions of their tools can also
11062 hide bugs during distributed development.  Indeed, developers will be
11063 using (hence testing) their own generated files, instead of the
11064 generated files that will be released actually.  The developer who
11065 prepares the tarball might be using a version of the tool that
11066 produces bogus output (for instance a non-portable C file), something
11067 other developers could have noticed if they weren't using their own
11068 versions of this tool.
11069
11070 @subheading Third-party Files
11071 @cindex CVS and third-party files
11072 @cindex third-party files and CVS
11073
11074 Another class of files not discussed here (because they do not cause
11075 timestamp issues) are files that are shipped with a package, but
11076 maintained elsewhere.  For instance, tools like @command{gettextize}
11077 and @command{autopoint} (from Gettext) or @command{libtoolize} (from
11078 Libtool), will install or update files in your package.
11079
11080 These files, whether they are kept under CVS or not, raise similar
11081 concerns about version mismatch between developers' tools.  The
11082 Gettext manual has a section about this, see @ref{CVS Issues, CVS
11083 Issues, Integrating with CVS, gettext, GNU gettext tools}.
11084
11085 @node maintainer-mode
11086 @section @command{missing} and @code{AM_MAINTAINER_MODE}
11087
11088 @subheading @command{missing}
11089 @cindex @command{missing}, purpose
11090
11091 The @command{missing} script is a wrapper around several maintainer
11092 tools, designed to warn users if a maintainer tool is required but
11093 missing.  Typical maintainer tools are @command{autoconf},
11094 @command{automake}, @command{bison}, etc.  Because file generated by
11095 these tools are shipped with the other sources of a package, these
11096 tools shouldn't be required during a user build and they are not
11097 checked for in @file{configure}.
11098
11099 However, if for some reason a rebuild rule is triggered and involves a
11100 missing tool, @command{missing} will notice it and warn the user.
11101 Besides the warning, when a tool is missing, @command{missing} will
11102 attempt to fix timestamps in a way that allows the build to continue.
11103 For instance, @command{missing} will touch @file{configure} if
11104 @command{autoconf} is not installed.  When all distributed files are
11105 kept under version control, this feature of @command{missing} allows a
11106 user @emph{with no maintainer tools} to build a package off its version
11107 control repository, bypassing any timestamp inconsistency (implied by
11108 e.g.@: @samp{cvs update} or @samp{git clone}).
11109
11110 If the required tool is installed, @command{missing} will run it and
11111 won't attempt to continue after failures.  This is correct during
11112 development: developers love fixing failures.  However, users with
11113 wrong versions of maintainer tools may get an error when the rebuild
11114 rule is spuriously triggered, halting the build.  This failure to let
11115 the build continue is one of the arguments of the
11116 @code{AM_MAINTAINER_MODE} advocates.
11117
11118 @subheading @code{AM_MAINTAINER_MODE}
11119 @cindex @code{AM_MAINTAINER_MODE}, purpose
11120 @acindex AM_MAINTAINER_MODE
11121
11122 @code{AM_MAINTAINER_MODE} allows you to choose whether the so called
11123 "rebuild rules" should be enabled or disabled.  With
11124 @code{AM_MAINTAINER_MODE([enable])}, they are enabled by default,
11125 otherwise they are disabled by default.  In the latter case, if
11126 you have @code{AM_MAINTAINER_MODE} in @file{configure.ac}, and run
11127 @samp{./configure && make}, then @command{make} will *never* attempt to
11128 rebuild @file{configure}, @file{Makefile.in}s, Lex or Yacc outputs, etc.
11129 I.e., this disables build rules for files that are usually distributed
11130 and that users should normally not have to update.
11131
11132 The user can override the default setting by passing either
11133 @samp{--enable-maintainer-mode} or @samp{--disable-maintainer-mode}
11134 to @command{configure}.
11135
11136 People use @code{AM_MAINTAINER_MODE} either because they do not want their
11137 users (or themselves) annoyed by timestamps lossage (@pxref{CVS}), or
11138 because they simply can't stand the rebuild rules and prefer running
11139 maintainer tools explicitly.
11140
11141 @code{AM_MAINTAINER_MODE} also allows you to disable some custom build
11142 rules conditionally.  Some developers use this feature to disable
11143 rules that need exotic tools that users may not have available.
11144
11145 Several years ago Fran@,{c}ois Pinard pointed out several arguments
11146 against this @code{AM_MAINTAINER_MODE} macro.  Most of them relate to
11147 insecurity.  By removing dependencies you get non-dependable builds:
11148 changes to sources files can have no effect on generated files and this
11149 can be very confusing when unnoticed.  He adds that security shouldn't
11150 be reserved to maintainers (what @option{--enable-maintainer-mode}
11151 suggests), on the contrary.  If one user has to modify a
11152 @file{Makefile.am}, then either @file{Makefile.in} should be updated
11153 or a warning should be output (this is what Automake uses
11154 @command{missing} for) but the last thing you want is that nothing
11155 happens and the user doesn't notice it (this is what happens when
11156 rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
11157
11158 Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro was
11159 swayed by Fran@,{c}ois's arguments, and got rid of
11160 @code{AM_MAINTAINER_MODE} in all of his packages.
11161
11162 Still many people continue to use @code{AM_MAINTAINER_MODE}, because
11163 it helps them working on projects where all files are kept under version
11164 control, and because @command{missing} isn't enough if you have the
11165 wrong version of the tools.
11166
11167
11168 @node Wildcards
11169 @section Why doesn't Automake support wildcards?
11170 @cindex wildcards
11171
11172 Developers are lazy.  They would often like to use wildcards in
11173 @file{Makefile.am}s, so that they would not need to remember to
11174 update @file{Makefile.am}s every time they add, delete, or rename
11175 a file.
11176
11177 There are several objections to this:
11178 @itemize
11179 @item
11180 When using CVS (or similar) developers need to remember they have to
11181 run @samp{cvs add} or @samp{cvs rm} anyway.  Updating
11182 @file{Makefile.am} accordingly quickly becomes a reflex.
11183
11184 Conversely, if your application doesn't compile
11185 because you forgot to add a file in @file{Makefile.am}, it will help
11186 you remember to @samp{cvs add} it.
11187
11188 @item
11189 Using wildcards makes it easy to distribute files by mistake.  For
11190 instance, some code a developer is experimenting with (a test case,
11191 say) that should not be part of the distribution.
11192
11193 @item
11194 Using wildcards it's easy to omit some files by mistake.  For
11195 instance, one developer creates a new file, uses it in many places,
11196 but forgets to commit it.  Another developer then checks out the
11197 incomplete project and is able to run @samp{make dist} successfully,
11198 even though a file is missing. By listing files, @samp{make dist}
11199 @emph{will} complain.
11200
11201 @item
11202 Wildcards are not portable to some non-GNU @command{make} implementations,
11203 e.g., NetBSD @command{make} will not expand globs such as @samp{*} in
11204 prerequisites of a target.
11205
11206 @item
11207 Finally, it's really hard to @emph{forget} to add a file to
11208 @file{Makefile.am}: files that are not listed in @file{Makefile.am} are
11209 not compiled or installed, so you can't even test them.
11210 @end itemize
11211
11212 Still, these are philosophical objections, and as such you may disagree,
11213 or find enough value in wildcards to dismiss all of them.  Before you
11214 start writing a patch against Automake to teach it about wildcards,
11215 let's see the main technical issue: portability.
11216
11217 Although @samp{$(wildcard ...)} works with GNU @command{make}, it is
11218 not portable to other @command{make} implementations.
11219
11220 The only way Automake could support @command{$(wildcard ...)} is by
11221 expending @command{$(wildcard ...)} when @command{automake} is run.
11222 The resulting @file{Makefile.in}s would be portable since they would
11223 list all files and not use @samp{$(wildcard ...)}.  However that
11224 means developers would need to remember to run @command{automake} each
11225 time they add, delete, or rename files.
11226
11227 Compared to editing @file{Makefile.am}, this is a very small gain.  Sure,
11228 it's easier and faster to type @samp{automake; make} than to type
11229 @samp{emacs Makefile.am; make}.  But nobody bothered enough to write a
11230 patch to add support for this syntax.  Some people use scripts to
11231 generate file lists in @file{Makefile.am} or in separate
11232 @file{Makefile} fragments.
11233
11234 Even if you don't care about portability, and are tempted to use
11235 @samp{$(wildcard ...)} anyway because you target only GNU Make, you
11236 should know there are many places where Automake needs to know exactly
11237 which files should be processed.  As Automake doesn't know how to
11238 expand @samp{$(wildcard ...)}, you cannot use it in these places.
11239 @samp{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
11240 variables as far Automake is concerned.
11241
11242 You can get warnings about @samp{$(wildcard ...}) constructs using the
11243 @option{-Wportability} flag.
11244
11245 @node Limitations on File Names
11246 @section Limitations on File Names
11247 @cindex file names, limitations on
11248
11249 Automake attempts to support all kinds of file names, even those that
11250 contain unusual characters or are unusually long.  However, some
11251 limitations are imposed by the underlying operating system and tools.
11252
11253 Most operating systems prohibit the use of the null byte in file
11254 names, and reserve @samp{/} as a directory separator.  Also, they
11255 require that file names are properly encoded for the user's locale.
11256 Automake is subject to these limits.
11257
11258 Portable packages should limit themselves to POSIX file
11259 names.  These can contain ASCII letters and digits,
11260 @samp{_}, @samp{.}, and @samp{-}.  File names consist of components
11261 separated by @samp{/}.  File name components cannot begin with
11262 @samp{-}.
11263
11264 Portable POSIX file names cannot contain components that exceed a
11265 14-byte limit, but nowadays it's normally safe to assume the
11266 more-generous XOPEN limit of 255 bytes.  POSIX
11267 limits file names to 255 bytes (XOPEN allows 1023 bytes),
11268 but you may want to limit a source tarball to file names of 99 bytes
11269 to avoid interoperability problems with old versions of @command{tar}.
11270
11271 If you depart from these rules (e.g., by using non-ASCII
11272 characters in file names, or by using lengthy file names), your
11273 installers may have problems for reasons unrelated to Automake.
11274 However, if this does not concern you, you should know about the
11275 limitations imposed by Automake itself.  These limitations are
11276 undesirable, but some of them seem to be inherent to underlying tools
11277 like Autoconf, Make, M4, and the shell.  They fall into three
11278 categories: install directories, build directories, and file names.
11279
11280 The following characters:
11281
11282 @example
11283 @r{newline} " # $ ' `
11284 @end example
11285
11286 should not appear in the names of install directories.  For example,
11287 the operand of @command{configure}'s @option{--prefix} option should
11288 not contain these characters.
11289
11290 Build directories suffer the same limitations as install directories,
11291 and in addition should not contain the following characters:
11292
11293 @example
11294 & @@ \
11295 @end example
11296
11297 For example, the full name of the directory containing the source
11298 files should not contain these characters.
11299
11300 Source and installation file names like @file{main.c} are limited even
11301 further: they should conform to the POSIX/XOPEN
11302 rules described above.  In addition, if you plan to port to
11303 non-POSIX environments, you should avoid file names that
11304 differ only in case (e.g., @file{makefile} and @file{Makefile}).
11305 Nowadays it is no longer worth worrying about the 8.3 limits of
11306 DOS file systems.
11307
11308 @node distcleancheck
11309 @section Files left in build directory after distclean
11310 @cindex @code{distclean}, diagnostic
11311 @cindex @samp{make distclean}, diagnostic
11312 @cindex dependencies and distributed files
11313 @trindex distclean
11314 @trindex distcleancheck
11315
11316 This is a diagnostic you might encounter while running @samp{make
11317 distcheck}.
11318
11319 As explained in @ref{Checking the Distribution}, @samp{make distcheck}
11320 attempts to build and check your package for errors like this one.
11321
11322 @samp{make distcheck} will perform a @code{VPATH} build of your
11323 package (@pxref{VPATH Builds}), and then call @samp{make distclean}.
11324 Files left in the build directory after @samp{make distclean} has run
11325 are listed after this error.
11326
11327 This diagnostic really covers two kinds of errors:
11328
11329 @itemize @bullet
11330 @item
11331 files that are forgotten by distclean;
11332 @item
11333 distributed files that are erroneously rebuilt.
11334 @end itemize
11335
11336 The former left-over files are not distributed, so the fix is to mark
11337 them for cleaning (@pxref{Clean}), this is obvious and doesn't deserve
11338 more explanations.
11339
11340 The latter bug is not always easy to understand and fix, so let's
11341 proceed with an example.  Suppose our package contains a program for
11342 which we want to build a man page using @command{help2man}.  GNU
11343 @command{help2man} produces simple manual pages from the @option{--help}
11344 and @option{--version} output of other commands (@pxref{Top, , Overview,
11345 help2man, The Help2man Manual}).  Because we don't want to force our
11346 users to install @command{help2man}, we decide to distribute the
11347 generated man page using the following setup.
11348
11349 @example
11350 # This Makefile.am is bogus.
11351 bin_PROGRAMS = foo
11352 foo_SOURCES = foo.c
11353 dist_man_MANS = foo.1
11354
11355 foo.1: foo$(EXEEXT)
11356         help2man --output=foo.1 ./foo$(EXEEXT)
11357 @end example
11358
11359 This will effectively distribute the man page.  However,
11360 @samp{make distcheck} will fail with:
11361
11362 @example
11363 ERROR: files left in build directory after distclean:
11364 ./foo.1
11365 @end example
11366
11367 Why was @file{foo.1} rebuilt?  Because although distributed,
11368 @file{foo.1} depends on a non-distributed built file:
11369 @file{foo$(EXEEXT)}.  @file{foo$(EXEEXT)} is built by the user, so it
11370 will always appear to be newer than the distributed @file{foo.1}.
11371
11372 @samp{make distcheck} caught an inconsistency in our package.  Our
11373 intent was to distribute @file{foo.1} so users do not need to install
11374 @command{help2man}, however since this rule causes this file to be
11375 always rebuilt, users @emph{do} need @command{help2man}.  Either we
11376 should ensure that @file{foo.1} is not rebuilt by users, or there is
11377 no point in distributing @file{foo.1}.
11378
11379 More generally, the rule is that distributed files should never depend
11380 on non-distributed built files.  If you distribute something
11381 generated, distribute its sources.
11382
11383 One way to fix the above example, while still distributing
11384 @file{foo.1} is to not depend on @file{foo$(EXEEXT)}.  For instance,
11385 assuming @command{foo --version} and @command{foo --help} do not
11386 change unless @file{foo.c} or @file{configure.ac} change, we could
11387 write the following @file{Makefile.am}:
11388
11389 @example
11390 bin_PROGRAMS = foo
11391 foo_SOURCES = foo.c
11392 dist_man_MANS = foo.1
11393
11394 foo.1: foo.c $(top_srcdir)/configure.ac
11395         $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
11396         help2man --output=foo.1 ./foo$(EXEEXT)
11397 @end example
11398
11399 This way, @file{foo.1} will not get rebuilt every time
11400 @file{foo$(EXEEXT)} changes.  The @command{make} call makes sure
11401 @file{foo$(EXEEXT)} is up-to-date before @command{help2man}.  Another
11402 way to ensure this would be to use separate directories for binaries
11403 and man pages, and set @code{SUBDIRS} so that binaries are built
11404 before man pages.
11405
11406 We could also decide not to distribute @file{foo.1}.  In
11407 this case it's fine to have @file{foo.1} dependent upon
11408 @file{foo$(EXEEXT)}, since both will have to be rebuilt.
11409 However it would be impossible to build the package in a
11410 cross-compilation, because building @file{foo.1} involves
11411 an @emph{execution} of @file{foo$(EXEEXT)}.
11412
11413 Another context where such errors are common is when distributed files
11414 are built by tools that are built by the package.  The pattern is
11415 similar:
11416
11417 @example
11418 distributed-file: built-tools distributed-sources
11419         build-command
11420 @end example
11421
11422 @noindent
11423 should be changed to
11424
11425 @example
11426 distributed-file: distributed-sources
11427         $(MAKE) $(AM_MAKEFLAGS) built-tools
11428         build-command
11429 @end example
11430
11431 @noindent
11432 or you could choose not to distribute @file{distributed-file}, if
11433 cross-compilation does not matter.
11434
11435 The points made through these examples are worth a summary:
11436
11437 @cartouche
11438 @itemize
11439 @item
11440 Distributed files should never depend upon non-distributed built
11441 files.
11442 @item
11443 Distributed files should be distributed with all their dependencies.
11444 @item
11445 If a file is @emph{intended} to be rebuilt by users, then there is no point
11446 in distributing it.
11447 @end itemize
11448 @end cartouche
11449
11450 @vrindex distcleancheck_listfiles
11451 For desperate cases, it's always possible to disable this check by
11452 setting @code{distcleancheck_listfiles} as documented in @ref{Checking
11453 the Distribution}.
11454 Make sure you do understand the reason why @samp{make distcheck}
11455 complains before you do this.  @code{distcleancheck_listfiles} is a
11456 way to @emph{hide} errors, not to fix them.  You can always do better.
11457
11458 @node Flag Variables Ordering
11459 @section Flag Variables Ordering
11460 @cindex Ordering flag variables
11461 @cindex Flag variables, ordering
11462
11463 @display
11464 What is the difference between @code{AM_CFLAGS}, @code{CFLAGS}, and
11465 @code{mumble_CFLAGS}?
11466 @end display
11467
11468 @display
11469 Why does @command{automake} output @code{CPPFLAGS} after
11470 @code{AM_CPPFLAGS} on compile lines?  Shouldn't it be the converse?
11471 @end display
11472
11473 @display
11474 My @file{configure} adds some warning flags into @code{CXXFLAGS}.  In
11475 one @file{Makefile.am} I would like to append a new flag, however if I
11476 put the flag into @code{AM_CXXFLAGS} it is prepended to the other
11477 flags, not appended.
11478 @end display
11479
11480 @subheading Compile Flag Variables
11481 @cindex Flag Variables, Ordering
11482 @cindex Compile Flag Variables
11483 @cindex @code{AM_CCASFLAGS} and @code{CCASFLAGS}
11484 @cindex @code{AM_CFLAGS} and @code{CFLAGS}
11485 @cindex @code{AM_CPPFLAGS} and @code{CPPFLAGS}
11486 @cindex @code{AM_CXXFLAGS} and @code{CXXFLAGS}
11487 @cindex @code{AM_FCFLAGS} and @code{FCFLAGS}
11488 @cindex @code{AM_FFLAGS} and @code{FFLAGS}
11489 @cindex @code{AM_GCJFLAGS} and @code{GCJFLAGS}
11490 @cindex @code{AM_LDFLAGS} and @code{LDFLAGS}
11491 @cindex @code{AM_LFLAGS} and @code{LFLAGS}
11492 @cindex @code{AM_LIBTOOLFLAGS} and @code{LIBTOOLFLAGS}
11493 @cindex @code{AM_OBJCFLAGS} and @code{OBJCFLAGS}
11494 @cindex @code{AM_RFLAGS} and @code{RFLAGS}
11495 @cindex @code{AM_UPCFLAGS} and @code{UPCFLAGS}
11496 @cindex @code{AM_YFLAGS} and @code{YFLAGS}
11497 @cindex @code{CCASFLAGS} and @code{AM_CCASFLAGS}
11498 @cindex @code{CFLAGS} and @code{AM_CFLAGS}
11499 @cindex @code{CPPFLAGS} and @code{AM_CPPFLAGS}
11500 @cindex @code{CXXFLAGS} and @code{AM_CXXFLAGS}
11501 @cindex @code{FCFLAGS} and @code{AM_FCFLAGS}
11502 @cindex @code{FFLAGS} and @code{AM_FFLAGS}
11503 @cindex @code{GCJFLAGS} and @code{AM_GCJFLAGS}
11504 @cindex @code{LDFLAGS} and @code{AM_LDFLAGS}
11505 @cindex @code{LFLAGS} and @code{AM_LFLAGS}
11506 @cindex @code{LIBTOOLFLAGS} and @code{AM_LIBTOOLFLAGS}
11507 @cindex @code{OBJCFLAGS} and @code{AM_OBJCFLAGS}
11508 @cindex @code{RFLAGS} and @code{AM_RFLAGS}
11509 @cindex @code{UPCFLAGS} and @code{AM_UPCFLAGS}
11510 @cindex @code{YFLAGS} and @code{AM_YFLAGS}
11511
11512 This section attempts to answer all the above questions.  We will
11513 mostly discuss @code{CPPFLAGS} in our examples, but actually the
11514 answer holds for all the compile flags used in Automake:
11515 @code{CCASFLAGS}, @code{CFLAGS}, @code{CPPFLAGS}, @code{CXXFLAGS},
11516 @code{FCFLAGS}, @code{FFLAGS}, @code{GCJFLAGS}, @code{LDFLAGS},
11517 @code{LFLAGS}, @code{LIBTOOLFLAGS}, @code{OBJCFLAGS}, @code{RFLAGS},
11518 @code{UPCFLAGS}, and @code{YFLAGS}.
11519
11520 @code{CPPFLAGS}, @code{AM_CPPFLAGS}, and @code{mumble_CPPFLAGS} are
11521 three variables that can be used to pass flags to the C preprocessor
11522 (actually these variables are also used for other languages like C++
11523 or preprocessed Fortran).  @code{CPPFLAGS} is the user variable
11524 (@pxref{User Variables}), @code{AM_CPPFLAGS} is the Automake variable,
11525 and @code{mumble_CPPFLAGS} is the variable specific to the
11526 @code{mumble} target (we call this a per-target variable,
11527 @pxref{Program and Library Variables}).
11528
11529 Automake always uses two of these variables when compiling C sources
11530 files.  When compiling an object file for the @code{mumble} target,
11531 the first variable will be @code{mumble_CPPFLAGS} if it is defined, or
11532 @code{AM_CPPFLAGS} otherwise.  The second variable is always
11533 @code{CPPFLAGS}.
11534
11535 In the following example,
11536
11537 @example
11538 bin_PROGRAMS = foo bar
11539 foo_SOURCES = xyz.c
11540 bar_SOURCES = main.c
11541 foo_CPPFLAGS = -DFOO
11542 AM_CPPFLAGS = -DBAZ
11543 @end example
11544
11545 @noindent
11546 @file{xyz.o} will be compiled with @samp{$(foo_CPPFLAGS) $(CPPFLAGS)},
11547 (because @file{xyz.o} is part of the @code{foo} target), while
11548 @file{main.o} will be compiled with @samp{$(AM_CPPFLAGS) $(CPPFLAGS)}
11549 (because there is no per-target variable for target @code{bar}).
11550
11551 The difference between @code{mumble_CPPFLAGS} and @code{AM_CPPFLAGS}
11552 being clear enough, let's focus on @code{CPPFLAGS}.  @code{CPPFLAGS}
11553 is a user variable, i.e., a variable that users are entitled to modify
11554 in order to compile the package.  This variable, like many others,
11555 is documented at the end of the output of @samp{configure --help}.
11556
11557 For instance, someone who needs to add @file{/home/my/usr/include} to
11558 the C compiler's search path would configure a package with
11559
11560 @example
11561 ./configure CPPFLAGS='-I /home/my/usr/include'
11562 @end example
11563
11564 @noindent
11565 and this flag would be propagated to the compile rules of all
11566 @file{Makefile}s.
11567
11568 It is also not uncommon to override a user variable at
11569 @command{make}-time.  Many installers do this with @code{prefix}, but
11570 this can be useful with compiler flags too.  For instance, if, while
11571 debugging a C++ project, you need to disable optimization in one
11572 specific object file, you can run something like
11573
11574 @example
11575 rm file.o
11576 make CXXFLAGS=-O0 file.o
11577 make
11578 @end example
11579
11580 The reason @samp{$(CPPFLAGS)} appears after @samp{$(AM_CPPFLAGS)} or
11581 @samp{$(mumble_CPPFLAGS)} in the compile command is that users
11582 should always have the last say.  It probably makes more sense if you
11583 think about it while looking at the @samp{CXXFLAGS=-O0} above, which
11584 should supersede any other switch from @code{AM_CXXFLAGS} or
11585 @code{mumble_CXXFLAGS} (and this of course replaces the previous value
11586 of @code{CXXFLAGS}).
11587
11588 You should never redefine a user variable such as @code{CPPFLAGS} in
11589 @file{Makefile.am}.  Use @samp{automake -Woverride} to diagnose such
11590 mistakes.  Even something like
11591
11592 @example
11593 CPPFLAGS = -DDATADIR=\"$(datadir)\" @@CPPFLAGS@@
11594 @end example
11595
11596 @noindent
11597 is erroneous.  Although this preserves @file{configure}'s value of
11598 @code{CPPFLAGS}, the definition of @code{DATADIR} will disappear if a
11599 user attempts to override @code{CPPFLAGS} from the @command{make}
11600 command line.
11601
11602 @example
11603 AM_CPPFLAGS = -DDATADIR=\"$(datadir)\"
11604 @end example
11605
11606 @noindent
11607 is all that is needed here if no per-target flags are used.
11608
11609 You should not add options to these user variables within
11610 @file{configure} either, for the same reason.  Occasionally you need
11611 to modify these variables to perform a test, but you should reset
11612 their values afterwards.  In contrast, it is OK to modify the
11613 @samp{AM_} variables within @file{configure} if you @code{AC_SUBST}
11614 them, but it is rather rare that you need to do this, unless you
11615 really want to change the default definitions of the @samp{AM_}
11616 variables in all @file{Makefile}s.
11617
11618 What we recommend is that you define extra flags in separate
11619 variables.  For instance, you may write an Autoconf macro that computes
11620 a set of warning options for the C compiler, and @code{AC_SUBST} them
11621 in @code{WARNINGCFLAGS}; you may also have an Autoconf macro that
11622 determines which compiler and which linker flags should be used to
11623 link with library @file{libfoo}, and @code{AC_SUBST} these in
11624 @code{LIBFOOCFLAGS} and @code{LIBFOOLDFLAGS}.  Then, a
11625 @file{Makefile.am} could use these variables as follows:
11626
11627 @example
11628 AM_CFLAGS = $(WARNINGCFLAGS)
11629 bin_PROGRAMS = prog1 prog2
11630 prog1_SOURCES = @dots{}
11631 prog2_SOURCES = @dots{}
11632 prog2_CFLAGS = $(LIBFOOCFLAGS) $(AM_CFLAGS)
11633 prog2_LDFLAGS = $(LIBFOOLDFLAGS)
11634 @end example
11635
11636 In this example both programs will be compiled with the flags
11637 substituted into @samp{$(WARNINGCFLAGS)}, and @code{prog2} will
11638 additionally be compiled with the flags required to link with
11639 @file{libfoo}.
11640
11641 Note that listing @code{AM_CFLAGS} in a per-target @code{CFLAGS}
11642 variable is a common idiom to ensure that @code{AM_CFLAGS} applies to
11643 every target in a @file{Makefile.in}.
11644
11645 Using variables like this gives you full control over the ordering of
11646 the flags.  For instance, if there is a flag in $(WARNINGCFLAGS) that
11647 you want to negate for a particular target, you can use something like
11648 @samp{prog1_CFLAGS = $(AM_CFLAGS) -no-flag}.  If all these flags had
11649 been forcefully appended to @code{CFLAGS}, there would be no way to
11650 disable one flag.  Yet another reason to leave user variables to
11651 users.
11652
11653 Finally, we have avoided naming the variable of the example
11654 @code{LIBFOO_LDFLAGS} (with an underscore) because that would cause
11655 Automake to think that this is actually a per-target variable (like
11656 @code{mumble_LDFLAGS}) for some non-declared @code{LIBFOO} target.
11657
11658 @subheading Other Variables
11659
11660 There are other variables in Automake that follow similar principles
11661 to allow user options.  For instance, Texinfo rules (@pxref{Texinfo})
11662 use @code{MAKEINFOFLAGS} and @code{AM_MAKEINFOFLAGS}.  Similarly,
11663 DejaGnu tests (@pxref{DejaGnu Tests}) use @code{RUNTESTDEFAULTFLAGS} and
11664 @code{AM_RUNTESTDEFAULTFLAGS}.  The tags and ctags rules
11665 (@pxref{Tags}) use @code{ETAGSFLAGS}, @code{AM_ETAGSFLAGS},
11666 @code{CTAGSFLAGS}, and @code{AM_CTAGSFLAGS}.  Java rules
11667 (@pxref{Java}) use @code{JAVACFLAGS} and @code{AM_JAVACFLAGS}.  None
11668 of these rules support per-target flags (yet).
11669
11670 To some extent, even @code{AM_MAKEFLAGS} (@pxref{Subdirectories})
11671 obeys this naming scheme.  The slight difference is that
11672 @code{MAKEFLAGS} is passed to sub-@command{make}s implicitly by
11673 @command{make} itself.
11674
11675 However you should not think that all variables ending with
11676 @code{FLAGS} follow this convention.  For instance,
11677 @code{DISTCHECK_CONFIGURE_FLAGS} (@pxref{Checking the Distribution}) and
11678 @code{ACLOCAL_AMFLAGS} (see @ref{Rebuilding} and @ref{Local Macros}),
11679 are two variables that are only useful to the maintainer and have no
11680 user counterpart.
11681
11682 @code{ARFLAGS} (@pxref{A Library}) is usually defined by Automake and
11683 has neither @code{AM_} nor per-target cousin.
11684
11685 Finally you should not think that the existence of a per-target
11686 variable implies the existance of an @code{AM_} variable or of a user
11687 variable.  For instance, the @code{mumble_LDADD} per-target variable
11688 overrides the makefile-wide @code{LDADD} variable (which is not a user
11689 variable), and @code{mumble_LIBADD} exists only as a per-target
11690 variable.  @xref{Program and Library Variables}.
11691
11692
11693 @node Renamed Objects
11694 @section Why are object files sometimes renamed?
11695
11696 This happens when per-target compilation flags are used.  Object
11697 files need to be renamed just in case they would clash with object
11698 files compiled from the same sources, but with different flags.
11699 Consider the following example.
11700
11701 @example
11702 bin_PROGRAMS = true false
11703 true_SOURCES = generic.c
11704 true_CPPFLAGS = -DEXIT_CODE=0
11705 false_SOURCES = generic.c
11706 false_CPPFLAGS = -DEXIT_CODE=1
11707 @end example
11708
11709 @noindent
11710 Obviously the two programs are built from the same source, but it
11711 would be bad if they shared the same object, because @file{generic.o}
11712 cannot be built with both @samp{-DEXIT_CODE=0} @emph{and}
11713 @samp{-DEXIT_CODE=1}.  Therefore @command{automake} outputs rules to
11714 build two different objects: @file{true-generic.o} and
11715 @file{false-generic.o}.
11716
11717 @command{automake} doesn't actually look whether source files are
11718 shared to decide if it must rename objects.  It will just rename all
11719 objects of a target as soon as it sees per-target compilation flags
11720 used.
11721
11722 It's OK to share object files when per-target compilation flags are not
11723 used.  For instance, @file{true} and @file{false} will both use
11724 @file{version.o} in the following example.
11725
11726 @example
11727 AM_CPPFLAGS = -DVERSION=1.0
11728 bin_PROGRAMS = true false
11729 true_SOURCES = true.c version.c
11730 false_SOURCES = false.c version.c
11731 @end example
11732
11733 Note that the renaming of objects is also affected by the
11734 @code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
11735
11736
11737 @node Per-Object Flags
11738 @section Per-Object Flags Emulation
11739 @cindex Per-object flags, emulated
11740
11741 @display
11742 One of my source files needs to be compiled with different flags.  How
11743 do I do?
11744 @end display
11745
11746 Automake supports per-program and per-library compilation flags (see
11747 @ref{Program and Library Variables} and @ref{Flag Variables
11748 Ordering}).  With this you can define compilation flags that apply to
11749 all files compiled for a target.  For instance, in
11750
11751 @example
11752 bin_PROGRAMS = foo
11753 foo_SOURCES = foo.c foo.h bar.c bar.h main.c
11754 foo_CFLAGS = -some -flags
11755 @end example
11756
11757 @noindent
11758 @file{foo-foo.o}, @file{foo-bar.o}, and @file{foo-main.o} will all be
11759 compiled with @samp{-some -flags}.  (If you wonder about the names of
11760 these object files, see @ref{Renamed Objects}.)  Note that
11761 @code{foo_CFLAGS} gives the flags to use when compiling all the C
11762 sources of the @emph{program} @code{foo}, it has nothing to do with
11763 @file{foo.c} or @file{foo-foo.o} specifically.
11764
11765 What if @file{foo.c} needs to be compiled into @file{foo.o} using some
11766 specific flags, that none of the other files requires?  Obviously
11767 per-program flags are not directly applicable here.  Something like
11768 per-object flags are expected, i.e., flags that would be used only
11769 when creating @file{foo-foo.o}.  Automake does not support that,
11770 however this is easy to simulate using a library that contains only
11771 that object, and compiling this library with per-library flags.
11772
11773 @example
11774 bin_PROGRAMS = foo
11775 foo_SOURCES = bar.c bar.h main.c
11776 foo_CFLAGS = -some -flags
11777 foo_LDADD = libfoo.a
11778 noinst_LIBRARIES = libfoo.a
11779 libfoo_a_SOURCES = foo.c foo.h
11780 libfoo_a_CFLAGS = -some -other -flags
11781 @end example
11782
11783 Here @file{foo-bar.o} and @file{foo-main.o} will all be
11784 compiled with @samp{-some -flags}, while @file{libfoo_a-foo.o} will
11785 be compiled using @samp{-some -other -flags}.  Eventually, all
11786 three objects will be linked to form @file{foo}.
11787
11788 This trick can also be achieved using Libtool convenience libraries,
11789 for instance @samp{noinst_LTLIBRARIES = libfoo.la} (@pxref{Libtool
11790 Convenience Libraries}).
11791
11792 Another tempting idea to implement per-object flags is to override the
11793 compile rules @command{automake} would output for these files.
11794 Automake will not define a rule for a target you have defined, so you
11795 could think about defining the @samp{foo-foo.o: foo.c} rule yourself.
11796 We recommend against this, because this is error prone.  For instance,
11797 if you add such a rule to the first example, it will break the day you
11798 decide to remove @code{foo_CFLAGS} (because @file{foo.c} will then be
11799 compiled as @file{foo.o} instead of @file{foo-foo.o}, @pxref{Renamed
11800 Objects}).  Also in order to support dependency tracking, the two
11801 @file{.o}/@file{.obj} extensions, and all the other flags variables
11802 involved in a compilation, you will end up modifying a copy of the
11803 rule previously output by @command{automake} for this file.  If a new
11804 release of Automake generates a different rule, your copy will need to
11805 be updated by hand.
11806
11807 @node Multiple Outputs
11808 @section Handling Tools that Produce Many Outputs
11809 @cindex multiple outputs, rules with
11810 @cindex many outputs, rules with
11811 @cindex rules with multiple outputs
11812
11813 This section describes a @command{make} idiom that can be used when a
11814 tool produces multiple output files.  It is not specific to Automake
11815 and can be used in ordinary @file{Makefile}s.
11816
11817 Suppose we have a program called @command{foo} that will read one file
11818 called @file{data.foo} and produce two files named @file{data.c} and
11819 @file{data.h}.  We want to write a @file{Makefile} rule that captures
11820 this one-to-two dependency.
11821
11822 The naive rule is incorrect:
11823
11824 @example
11825 # This is incorrect.
11826 data.c data.h: data.foo
11827         foo data.foo
11828 @end example
11829
11830 @noindent
11831 What the above rule really says is that @file{data.c} and
11832 @file{data.h} each depend on @file{data.foo}, and can each be built by
11833 running @samp{foo data.foo}.  In other words it is equivalent to:
11834
11835 @example
11836 # We do not want this.
11837 data.c: data.foo
11838         foo data.foo
11839 data.h: data.foo
11840         foo data.foo
11841 @end example
11842
11843 @noindent
11844 which means that @command{foo} can be run twice.  Usually it will not
11845 be run twice, because @command{make} implementations are smart enough
11846 to check for the existence of the second file after the first one has
11847 been built; they will therefore detect that it already exists.
11848 However there are a few situations where it can run twice anyway:
11849
11850 @itemize
11851 @item
11852 The most worrying case is when running a parallel @command{make}.  If
11853 @file{data.c} and @file{data.h} are built in parallel, two @samp{foo
11854 data.foo} commands will run concurrently.  This is harmful.
11855 @item
11856 Another case is when the dependency (here @file{data.foo}) is
11857 (or depends upon) a phony target.
11858 @end itemize
11859
11860 A solution that works with parallel @command{make} but not with
11861 phony dependencies is the following:
11862
11863 @example
11864 data.c data.h: data.foo
11865         foo data.foo
11866 data.h: data.c
11867 @end example
11868
11869 @noindent
11870 The above rules are equivalent to
11871
11872 @example
11873 data.c: data.foo
11874         foo data.foo
11875 data.h: data.foo data.c
11876         foo data.foo
11877 @end example
11878
11879 @noindent
11880 therefore a parallel @command{make} will have to serialize the builds
11881 of @file{data.c} and @file{data.h}, and will detect that the second is
11882 no longer needed once the first is over.
11883
11884 Using this pattern is probably enough for most cases.  However it does
11885 not scale easily to more output files (in this scheme all output files
11886 must be totally ordered by the dependency relation), so we will
11887 explore a more complicated solution.
11888
11889 Another idea is to write the following:
11890
11891 @example
11892 # There is still a problem with this one.
11893 data.c: data.foo
11894         foo data.foo
11895 data.h: data.c
11896 @end example
11897
11898 @noindent
11899 The idea is that @samp{foo data.foo} is run only when @file{data.c}
11900 needs to be updated, but we further state that @file{data.h} depends
11901 upon @file{data.c}.  That way, if @file{data.h} is required and
11902 @file{data.foo} is out of date, the dependency on @file{data.c} will
11903 trigger the build.
11904
11905 This is almost perfect, but suppose we have built @file{data.h} and
11906 @file{data.c}, and then we erase @file{data.h}.  Then, running
11907 @samp{make data.h} will not rebuild @file{data.h}.  The above rules
11908 just state that @file{data.c} must be up-to-date with respect to
11909 @file{data.foo}, and this is already the case.
11910
11911 What we need is a rule that forces a rebuild when @file{data.h} is
11912 missing.  Here it is:
11913
11914 @example
11915 data.c: data.foo
11916         foo data.foo
11917 data.h: data.c
11918 ## Recover from the removal of $@@
11919         @@if test -f $@@; then :; else \
11920           rm -f data.c; \
11921           $(MAKE) $(AM_MAKEFLAGS) data.c; \
11922         fi
11923 @end example
11924
11925 The above scheme can be extended to handle more outputs and more
11926 inputs.  One of the outputs is selected to serve as a witness to the
11927 successful completion of the command, it depends upon all inputs, and
11928 all other outputs depend upon it.  For instance, if @command{foo}
11929 should additionally read @file{data.bar} and also produce
11930 @file{data.w} and @file{data.x}, we would write:
11931
11932 @example
11933 data.c: data.foo data.bar
11934         foo data.foo data.bar
11935 data.h data.w data.x: data.c
11936 ## Recover from the removal of $@@
11937         @@if test -f $@@; then :; else \
11938           rm -f data.c; \
11939           $(MAKE) $(AM_MAKEFLAGS) data.c; \
11940         fi
11941 @end example
11942
11943 However there are now three minor problems in this setup.  One is related
11944 to the timestamp ordering of @file{data.h}, @file{data.w},
11945 @file{data.x}, and @file{data.c}.  Another one is a race condition
11946 if a parallel @command{make} attempts to run multiple instances of the
11947 recover block at once.  Finally, the recursive rule breaks @samp{make -n}
11948 when run with GNU @command{make} (as well as some other @command{make}
11949 implementations), as it may remove @file{data.h} even when it should not
11950 (@pxref{MAKE Variable, , How the @code{MAKE} Variable Works, make,
11951 The GNU Make Manual}).
11952
11953 Let us deal with the first problem.  @command{foo} outputs four files,
11954 but we do not know in which order these files are created.  Suppose
11955 that @file{data.h} is created before @file{data.c}.  Then we have a
11956 weird situation.  The next time @command{make} is run, @file{data.h}
11957 will appear older than @file{data.c}, the second rule will be
11958 triggered, a shell will be started to execute the @samp{if@dots{}fi}
11959 command, but actually it will just execute the @code{then} branch,
11960 that is: nothing.  In other words, because the witness we selected is
11961 not the first file created by @command{foo}, @command{make} will start
11962 a shell to do nothing each time it is run.
11963
11964 A simple riposte is to fix the timestamps when this happens.
11965
11966 @example
11967 data.c: data.foo data.bar
11968         foo data.foo data.bar
11969 data.h data.w data.x: data.c
11970         @@if test -f $@@; then \
11971           touch $@@; \
11972         else \
11973 ## Recover from the removal of $@@
11974           rm -f data.c; \
11975           $(MAKE) $(AM_MAKEFLAGS) data.c; \
11976         fi
11977 @end example
11978
11979 Another solution is to use a different and dedicated file as witness,
11980 rather than using any of @command{foo}'s outputs.
11981
11982 @example
11983 data.stamp: data.foo data.bar
11984         @@rm -f data.tmp
11985         @@touch data.tmp
11986         foo data.foo data.bar
11987         @@mv -f data.tmp $@@
11988 data.c data.h data.w data.x: data.stamp
11989 ## Recover from the removal of $@@
11990         @@if test -f $@@; then :; else \
11991           rm -f data.stamp; \
11992           $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
11993         fi
11994 @end example
11995
11996 @file{data.tmp} is created before @command{foo} is run, so it has a
11997 timestamp older than output files output by @command{foo}.  It is then
11998 renamed to @file{data.stamp} after @command{foo} has run, because we
11999 do not want to update @file{data.stamp} if @command{foo} fails.
12000
12001 This solution still suffers from the second problem: the race
12002 condition in the recover rule.  If, after a successful build, a user
12003 erases @file{data.c} and @file{data.h}, and runs @samp{make -j}, then
12004 @command{make} may start both recover rules in parallel.  If the two
12005 instances of the rule execute @samp{$(MAKE) $(AM_MAKEFLAGS)
12006 data.stamp} concurrently the build is likely to fail (for instance, the
12007 two rules will create @file{data.tmp}, but only one can rename it).
12008
12009 Admittedly, such a weird situation does not arise during ordinary
12010 builds.  It occurs only when the build tree is mutilated.  Here
12011 @file{data.c} and @file{data.h} have been explicitly removed without
12012 also removing @file{data.stamp} and the other output files.
12013 @code{make clean; make} will always recover from these situations even
12014 with parallel makes, so you may decide that the recover rule is solely
12015 to help non-parallel make users and leave things as-is.  Fixing this
12016 requires some locking mechanism to ensure only one instance of the
12017 recover rule rebuilds @file{data.stamp}.  One could imagine something
12018 along the following lines.
12019
12020 @example
12021 data.c data.h data.w data.x: data.stamp
12022 ## Recover from the removal of $@@
12023         @@if test -f $@@; then :; else \
12024           trap 'rm -rf data.lock data.stamp' 1 2 13 15; \
12025 ## mkdir is a portable test-and-set
12026           if mkdir data.lock 2>/dev/null; then \
12027 ## This code is being executed by the first process.
12028             rm -f data.stamp; \
12029             $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
12030             result=$$?; rm -rf data.lock; exit $$result; \
12031           else \
12032 ## This code is being executed by the follower processes.
12033 ## Wait until the first process is done.
12034             while test -d data.lock; do sleep 1; done; \
12035 ## Succeed if and only if the first process succeeded.
12036             test -f data.stamp; \
12037           fi; \
12038         fi
12039 @end example
12040
12041 Using a dedicated witness, like @file{data.stamp}, is very handy when
12042 the list of output files is not known beforehand.  As an illustration,
12043 consider the following rules to compile many @file{*.el} files into
12044 @file{*.elc} files in a single command.  It does not matter how
12045 @code{ELFILES} is defined (as long as it is not empty: empty targets
12046 are not accepted by POSIX).
12047
12048 @example
12049 ELFILES = one.el two.el three.el @dots{}
12050 ELCFILES = $(ELFILES:=c)
12051
12052 elc-stamp: $(ELFILES)
12053         @@rm -f elc-temp
12054         @@touch elc-temp
12055         $(elisp_comp) $(ELFILES)
12056         @@mv -f elc-temp $@@
12057
12058 $(ELCFILES): elc-stamp
12059         @@if test -f $@@; then :; else \
12060 ## Recover from the removal of $@@
12061           trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
12062           if mkdir elc-lock 2>/dev/null; then \
12063 ## This code is being executed by the first process.
12064             rm -f elc-stamp; \
12065             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
12066             rmdir elc-lock; \
12067           else \
12068 ## This code is being executed by the follower processes.
12069 ## Wait until the first process is done.
12070             while test -d elc-lock; do sleep 1; done; \
12071 ## Succeed if and only if the first process succeeded.
12072             test -f elc-stamp; exit $$?; \
12073 @c $$
12074           fi; \
12075         fi
12076 @end example
12077
12078 These solutions all still suffer from the third problem, namely that
12079 they break the promise that @samp{make -n} should not cause any actual
12080 changes to the tree.  For those solutions that do not create lock files,
12081 it is possible to split the recover rules into two separate recipe
12082 commands, one of which does all work but the recursion, and the
12083 other invokes the recursive @samp{$(MAKE)}.  The solutions involving
12084 locking could act upon the contents of the @samp{MAKEFLAGS} variable,
12085 but parsing that portably is not easy (@pxref{The Make Macro MAKEFLAGS,,,
12086 autoconf, The Autoconf Manual}).  Here is an example:
12087
12088 @example
12089 ELFILES = one.el two.el three.el @dots{}
12090 ELCFILES = $(ELFILES:=c)
12091
12092 elc-stamp: $(ELFILES)
12093         @@rm -f elc-temp
12094         @@touch elc-temp
12095         $(elisp_comp) $(ELFILES)
12096         @@mv -f elc-temp $@@
12097
12098 $(ELCFILES): elc-stamp
12099 ## Recover from the removal of $@@
12100         @@dry=; for f in x $$MAKEFLAGS; do \
12101           case $$f in \
12102             *=*|--*);; \
12103             *n*) dry=:;; \
12104           esac; \
12105         done; \
12106         if test -f $@@; then :; else \
12107           $$dry trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
12108           if $$dry mkdir elc-lock 2>/dev/null; then \
12109 ## This code is being executed by the first process.
12110             $$dry rm -f elc-stamp; \
12111             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
12112             $$dry rmdir elc-lock; \
12113           else \
12114 ## This code is being executed by the follower processes.
12115 ## Wait until the first process is done.
12116             while test -d elc-lock && test -z "$$dry"; do \
12117 @c $$
12118               sleep 1; \
12119             done; \
12120 ## Succeed if and only if the first process succeeded.
12121             $$dry test -f elc-stamp; exit $$?; \
12122           fi; \
12123         fi
12124 @end example
12125
12126 For completeness it should be noted that GNU @command{make} is able to
12127 express rules with multiple output files using pattern rules
12128 (@pxref{Pattern Examples, , Pattern Rule Examples, make, The GNU Make
12129 Manual}).  We do not discuss pattern rules here because they are not
12130 portable, but they can be convenient in packages that assume GNU
12131 @command{make}.
12132
12133
12134 @node Hard-Coded Install Paths
12135 @section Installing to Hard-Coded Locations
12136
12137 @display
12138 My package needs to install some configuration file.  I tried to use
12139 the following rule, but @samp{make distcheck} fails.  Why?
12140
12141 @example
12142 # Do not do this.
12143 install-data-local:
12144         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
12145 @end example
12146 @end display
12147
12148 @display
12149 My package needs to populate the installation directory of another
12150 package at install-time.  I can easily compute that installation
12151 directory in @file{configure}, but if I install files therein,
12152 @samp{make distcheck} fails.  How else should I do?
12153 @end display
12154
12155 These two setups share their symptoms: @samp{make distcheck} fails
12156 because they are installing files to hard-coded paths.  In the later
12157 case the path is not really hard-coded in the package, but we can
12158 consider it to be hard-coded in the system (or in whichever tool that
12159 supplies the path).  As long as the path does not use any of the
12160 standard directory variables (@samp{$(prefix)}, @samp{$(bindir)},
12161 @samp{$(datadir)}, etc.), the effect will be the same:
12162 user-installations are impossible.
12163
12164 As a (non-root) user who wants to install a package, you usually have no
12165 right to install anything in @file{/usr} or @file{/usr/local}.  So you
12166 do something like @samp{./configure --prefix ~/usr} to install a
12167 package in your own @file{~/usr} tree.
12168
12169 If a package attempts to install something to some hard-coded path
12170 (e.g., @file{/etc/afile}), regardless of this @option{--prefix} setting,
12171 then the installation will fail.  @samp{make distcheck} performs such
12172 a @option{--prefix} installation, hence it will fail too.
12173
12174 Now, there are some easy solutions.
12175
12176 The above @code{install-data-local} example for installing
12177 @file{/etc/afile} would be better replaced by
12178
12179 @example
12180 sysconf_DATA = afile
12181 @end example
12182
12183 @noindent
12184 by default @code{sysconfdir} will be @samp{$(prefix)/etc}, because
12185 this is what the GNU Standards require.  When such a package is
12186 installed on an FHS compliant system, the installer will have to set
12187 @samp{--sysconfdir=/etc}.  As the maintainer of the package you
12188 should not be concerned by such site policies: use the appropriate
12189 standard directory variable to install your files so that the installer
12190 can easily redefine these variables to match their site conventions.
12191
12192 Installing files that should be used by another package is slightly
12193 more involved.  Let's take an example and assume you want to install
12194 a shared library that is a Python extension module.  If you ask Python
12195 where to install the library, it will answer something like this:
12196
12197 @example
12198 % @kbd{python -c 'from distutils import sysconfig;
12199              print sysconfig.get_python_lib(1,0)'}
12200 /usr/lib/python2.5/site-packages
12201 @end example
12202
12203 If you indeed use this absolute path to install your shared library,
12204 non-root users will not be able to install the package, hence
12205 distcheck fails.
12206
12207 Let's do better.  The @samp{sysconfig.get_python_lib()} function
12208 actually accepts a third argument that will replace Python's
12209 installation prefix.
12210
12211 @example
12212 % @kbd{python -c 'from distutils import sysconfig;
12213              print sysconfig.get_python_lib(1,0,"$@{exec_prefix@}")'}
12214 $@{exec_prefix@}/lib/python2.5/site-packages
12215 @end example
12216
12217 You can also use this new path.  If you do
12218 @itemize @bullet
12219 @item
12220 root users can install your package with the same @option{--prefix}
12221 as Python (you get the behavior of the previous attempt)
12222
12223 @item
12224 non-root users can install your package too, they will have the
12225 extension module in a place that is not searched by Python but they
12226 can work around this using environment variables (and if you installed
12227 scripts that use this shared library, it's easy to tell Python were to
12228 look in the beginning of your script, so the script works in both
12229 cases).
12230 @end itemize
12231
12232 The @code{AM_PATH_PYTHON} macro uses similar commands to define
12233 @samp{$(pythondir)} and @samp{$(pyexecdir)} (@pxref{Python}).
12234
12235 Of course not all tools are as advanced as Python regarding that
12236 substitution of @var{prefix}.  So another strategy is to figure the
12237 part of the installation directory that must be preserved.  For
12238 instance, here is how @code{AM_PATH_LISPDIR} (@pxref{Emacs Lisp})
12239 computes @samp{$(lispdir)}:
12240
12241 @example
12242 $EMACS -batch -q -eval '(while load-path
12243   (princ (concat (car load-path) "\n"))
12244   (setq load-path (cdr load-path)))' >conftest.out
12245 lispdir=`sed -n
12246   -e 's,/$,,'
12247   -e '/.*\/lib\/x*emacs\/site-lisp$/@{
12248         s,.*/lib/\(x*emacs/site-lisp\)$,$@{libdir@}/\1,;p;q;
12249       @}'
12250   -e '/.*\/share\/x*emacs\/site-lisp$/@{
12251         s,.*/share/\(x*emacs/site-lisp\),$@{datarootdir@}/\1,;p;q;
12252       @}'
12253   conftest.out`
12254 @end example
12255
12256 I.e., it just picks the first directory that looks like
12257 @file{*/lib/*emacs/site-lisp} or @file{*/share/*emacs/site-lisp} in
12258 the search path of emacs, and then substitutes @samp{$@{libdir@}} or
12259 @samp{$@{datadir@}} appropriately.
12260
12261 The emacs case looks complicated because it processes a list and
12262 expects two possible layouts, otherwise it's easy, and the benefits for
12263 non-root users are really worth the extra @command{sed} invocation.
12264
12265
12266 @node Debugging Make Rules
12267 @section Debugging Make Rules
12268 @cindex debugging rules
12269 @cindex rules, debugging
12270
12271 The rules and dependency trees generated by @command{automake} can get
12272 rather complex, and leave the developer head-scratching when things
12273 don't work as expected.  Besides the debug options provided by the
12274 @command{make} command (@pxref{Options Summary,,, make, The GNU Make
12275 Manual}), here's a couple of further hints for debugging makefiles
12276 generated by @command{automake} effectively:
12277
12278 @itemize
12279 @item
12280 If less verbose output has been enabled in the package with the
12281 @samp{silent-rules} option (@pxref{Options}), you can use
12282 @code{make V=1} to see the commands being executed.
12283 @item
12284 @code{make -n} can help show what would be done without actually doing
12285 it.  Note however, that this will @emph{still execute} commands prefixed
12286 with @samp{+}, and, when using GNU @command{make}, commands that contain
12287 the strings @samp{$(MAKE)} or @samp{$@{MAKE@}} (@pxref{Instead of
12288 Execution,,, make, The GNU Make Manual}).
12289 Typically, this is helpful to show what recursive rules would do, but it
12290 means that, in your own rules, you should not mix such recursion with
12291 actions that change any files.@footnote{Automake's @samp{dist} and
12292 @samp{distcheck} rules had a bug in this regard in that they created
12293 directories even with @option{-n}, but this has been fixed in Automake
12294 1.11.}  Furthermore, note that GNU @command{make} will update
12295 prerequisites for the @file{Makefile} file itself even with @option{-n}
12296 (@pxref{Remaking Makefiles,,, make, The GNU Make Manual}).
12297 @item
12298 @code{make SHELL="/bin/bash -vx"} can help debug complex rules.
12299 @xref{The Make Macro SHELL,,, autoconf, The Autoconf Manual}, for some
12300 portability quirks associated with this construct.
12301 @item
12302 @code{echo 'print: ; @@echo "$(VAR)"' | make -f Makefile -f - print}
12303 can be handy to examine the expanded value of variables.  You may need
12304 to use a target other than @samp{print} if that is already used or a
12305 file with that name exists.
12306 @item
12307 @url{http://bashdb.sourceforge.net/@/remake/} provides a modified
12308 GNU @command{make} command called @command{remake} that copes with
12309 complex GNU @command{make}-specific Makefiles and allows to trace
12310 execution, examine variables, and call rules interactively, much like
12311 a debugger.
12312 @end itemize
12313
12314
12315 @node Reporting Bugs
12316 @section Reporting Bugs
12317
12318 Most nontrivial software has bugs.  Automake is no exception.  Although
12319 we cannot promise we can or will fix a bug, and we might not even agree
12320 that it is a bug, we want to hear about problems you encounter. Often we
12321 agree they are bugs and want to fix them.
12322
12323 To make it possible for us to fix a bug, please report it. In order to
12324 do so effectively, it helps to know when and how to do it.
12325
12326 Before reporting a bug, it is a good idea to see if it is already known.
12327 You can look at the @uref{http://debbugs.gnu.org/, GNU Bug Tracker}
12328 and the @uref{http://lists.gnu.org/@/archive/@/html/@/bug-automake/,
12329 bug-automake mailing list archives} for previous bug reports.  We
12330 previously used a
12331 @uref{http://sourceware.org/@/cgi-bin/@/gnatsweb.pl?database=automake,
12332 Gnats database} for bug tracking, so some bugs might have been reported
12333 there already.  Please do not use it for new bug reports, however.
12334
12335 If the bug is not already known, it should be reported.  It is very
12336 important to report bugs in a way that is useful and efficient.  For
12337 this, please familiarize yourself with
12338 @uref{http://www.chiark.greenend.org.uk/@/~sgtatham/@/bugs.html, How to
12339 Report Bugs Effectively} and
12340 @uref{http://catb.org/@/~esr/@/faqs/@/smart-questions.html, How to Ask
12341 Questions the Smart Way}.  This helps you and developers to save time
12342 which can then be spent on fixing more bugs and implementing more
12343 features.
12344
12345 For a bug report, a feature request or other suggestions, please send
12346 email to @email{@value{PACKAGE_BUGREPORT}}.  This will then open a new
12347 bug in the @uref{http://debbugs.gnu.org/@/automake, bug tracker}.  Be
12348 sure to include the versions of Autoconf and Automake that you use.
12349 Ideally, post a minimal @file{Makefile.am} and @file{configure.ac} that
12350 reproduces the problem you encounter.  If you have encountered test
12351 suite failures, please attach the @file{tests/test-suite.log} file.
12352
12353
12354 @node History
12355 @chapter History of Automake
12356
12357 This chapter presents various aspects of the history of Automake.  The
12358 exhausted reader can safely skip it; this will be more of interest to
12359 nostalgic people, or to those curious to learn about the evolution of
12360 Automake.
12361
12362 @menu
12363 * Timeline::                    The Automake story.
12364 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
12365 * Releases::                    Statistics about Automake Releases
12366 @end menu
12367
12368 @node Timeline
12369 @section Timeline
12370
12371 @table @asis
12372 @item 1994-09-19 First CVS commit.
12373
12374 If we can trust the CVS repository, David J.@tie{}MacKenzie (djm) started
12375 working on Automake (or AutoMake, as it was spelt then) this Monday.
12376
12377 The first version of the @command{automake} script looks as follows.
12378
12379 @example
12380 #!/bin/sh
12381
12382 status=0
12383
12384 for makefile
12385 do
12386   if test ! -f $@{makefile@}.am; then
12387     echo "automake: $@{makefile@}.am: No such honkin' file"
12388     status=1
12389     continue
12390   fi
12391
12392   exec 4> $@{makefile@}.in
12393
12394 done
12395 @end example
12396
12397 From this you can already see that Automake will be about reading
12398 @file{*.am} file and producing @file{*.in} files.  You cannot see
12399 anything else, but if you also know that David is the one who created
12400 Autoconf two years before you can guess the rest.
12401
12402 Several commits follow, and by the end of the day Automake is
12403 reported to work for GNU fileutils and GNU m4.
12404
12405 The modus operandi is the one that is still used today: variable
12406 assignments in @file{Makefile.am} files trigger injections of
12407 precanned @file{Makefile} fragments into the generated
12408 @file{Makefile.in}.  The use of @file{Makefile} fragments was inspired
12409 by the 4.4BSD @command{make} and include files, however Automake aims
12410 to be portable and to conform to the GNU standards for @file{Makefile}
12411 variables and targets.
12412
12413 At this point, the most recent release of Autoconf is version 1.11,
12414 and David is preparing to release Autoconf 2.0 in late October.  As a
12415 matter of fact, he will barely touch Automake after September.
12416
12417 @item 1994-11-05 David MacKenzie's last commit.
12418
12419 At this point Automake is a 200 line portable shell script, plus 332
12420 lines of @file{Makefile} fragments.  In the @file{README}, David
12421 states his ambivalence between ``portable shell'' and ``more
12422 appropriate language'':
12423
12424 @quotation
12425 I wrote it keeping in mind the possibility of it becoming an Autoconf
12426 macro, so it would run at configure-time.  That would slow
12427 configuration down a bit, but allow users to modify the Makefile.am
12428 without needing to fetch the AutoMake package.  And, the Makefile.in
12429 files wouldn't need to be distributed.  But all of AutoMake would.  So
12430 I might reimplement AutoMake in Perl, m4, or some other more
12431 appropriate language.
12432 @end quotation
12433
12434 Automake is described as ``an experimental Makefile generator''.
12435 There is no documentation.  Adventurous users are referred to the
12436 examples and patches needed to use Automake with GNU m4 1.3, fileutils
12437 3.9, time 1.6, and development versions of find and indent.
12438
12439 These examples seem to have been lost.  However at the time of writing
12440 (10 years later in September, 2004) the FSF still distributes a
12441 package that uses this version of Automake: check out GNU termutils
12442 2.0.
12443
12444 @item 1995-11-12 Tom Tromey's first commit.
12445
12446 After one year of inactivity, Tom Tromey takes over the package.
12447 Tom was working on GNU cpio back then, and doing this just for fun,
12448 having trouble finding a project to contribute to.  So while hacking
12449 he wanted to bring the @file{Makefile.in} up to GNU standards.  This
12450 was hard, and one day he saw Automake on @url{ftp://alpha.gnu.org/},
12451 grabbed it and tried it out.
12452
12453 Tom didn't talk to djm about it until later, just to make sure he
12454 didn't mind if he made a release.  He did a bunch of early releases to
12455 the Gnits folks.
12456
12457 Gnits was (and still is) totally informal, just a few GNU friends who
12458 Fran@,cois Pinard knew, who were all interested in making a common
12459 infrastructure for GNU projects, and shared a similar outlook on how
12460 to do it.  So they were able to make some progress.  It came along
12461 with Autoconf and extensions thereof, and then Automake from David and
12462 Tom (who were both gnitsians).  One of their ideas was to write a
12463 document paralleling the GNU standards, that was more strict in some
12464 ways and more detailed.  They never finished the GNITS standards, but
12465 the ideas mostly made their way into Automake.
12466
12467 @item 1995-11-23 Automake 0.20
12468
12469 Besides introducing automatic dependency tracking (@pxref{Dependency
12470 Tracking Evolution}), this version also supplies a 9-page manual.
12471
12472 At this time @command{aclocal} and @code{AM_INIT_AUTOMAKE} did not
12473 exist, so many things had to be done by hand.  For instance, here is
12474 what a configure.in (this is the former name of the
12475 @file{configure.ac} we use today) must contain in order to use
12476 Automake 0.20:
12477
12478 @example
12479 PACKAGE=cpio
12480 VERSION=2.3.911
12481 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
12482 AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
12483 AC_SUBST(PACKAGE)
12484 AC_SUBST(VERSION)
12485 AC_ARG_PROGRAM
12486 AC_PROG_INSTALL
12487 @end example
12488
12489 (Today all of the above is achieved by @code{AC_INIT} and
12490 @code{AM_INIT_AUTOMAKE}.)
12491
12492 Here is how programs are specified in @file{Makefile.am}:
12493
12494 @example
12495 PROGRAMS = hello
12496 hello_SOURCES = hello.c
12497 @end example
12498
12499 This looks pretty much like what we do today, except the
12500 @code{PROGRAMS} variable has no directory prefix specifying where
12501 @file{hello} should be installed: all programs are installed in
12502 @samp{$(bindir)}.  @code{LIBPROGRAMS} can be used to specify programs
12503 that must be built but not installed (it is called
12504 @code{noinst_PROGRAMS} nowadays).
12505
12506 Programs can be built conditionally using @code{AC_SUBST}itutions:
12507
12508 @example
12509 PROGRAMS = @@progs@@
12510 AM_PROGRAMS = foo bar baz
12511 @end example
12512
12513 (@code{AM_PROGRAMS} has since then been renamed to
12514 @code{EXTRA_PROGRAMS}.)
12515
12516 Similarly scripts, static libraries, and data can be built and installed
12517 using the @code{LIBRARIES}, @code{SCRIPTS}, and @code{DATA} variables.
12518 However @code{LIBRARIES} were treated a bit specially in that Automake
12519 did automatically supply the @file{lib} and @file{.a} prefixes.
12520 Therefore to build @file{libcpio.a}, one had to write
12521
12522 @example
12523 LIBRARIES = cpio
12524 cpio_SOURCES = ...
12525 @end example
12526
12527 Extra files to distribute must be listed in @code{DIST_OTHER} (the
12528 ancestor of @code{EXTRA_DIST}).  Also extra directories that are to be
12529 distributed should appear in @code{DIST_SUBDIRS}, but the manual
12530 describes this as a temporary ugly hack (today extra directories should
12531 also be listed in @code{EXTRA_DIST}, and @code{DIST_SUBDIRS} is used
12532 for another purpose, @pxref{Conditional Subdirectories}).
12533
12534 @item 1995-11-26 Automake 0.21
12535
12536 In less time than it takes to cook a frozen pizza, Tom rewrites
12537 Automake using Perl.  At this time Perl 5 is only one year old, and
12538 Perl 4.036 is in use at many sites.  Supporting several Perl versions
12539 has been a source of problems through the whole history of Automake.
12540
12541 If you never used Perl 4, imagine Perl 5 without objects, without
12542 @samp{my} variables (only dynamically scoped @samp{local} variables),
12543 without function prototypes, with function calls that needs to be
12544 prefixed with @samp{&}, etc.  Traces of this old style can still be
12545 found in today's @command{automake}.
12546
12547 @item 1995-11-28 Automake 0.22
12548 @itemx 1995-11-29 Automake 0.23
12549
12550 Bug fixes.
12551
12552 @item 1995-12-08 Automake 0.24
12553 @itemx 1995-12-10 Automake 0.25
12554
12555 Releases are raining.  0.24 introduces the uniform naming scheme we
12556 use today, i.e., @code{bin_PROGRAMS} instead of @code{PROGRAMS},
12557 @code{noinst_LIBRARIES} instead of @code{LIBLIBRARIES}, etc.  (However
12558 @code{EXTRA_PROGRAMS} does not exist yet, @code{AM_PROGRAMS} is still
12559 in use; and @code{TEXINFOS} and @code{MANS} still have no directory
12560 prefixes.)  Adding support for prefixes like that was one of the major
12561 ideas in @command{automake}; it has lasted pretty well.
12562
12563 AutoMake is renamed to Automake (Tom seems to recall it was Fran@,cois
12564 Pinard's doing).
12565
12566 0.25 fixes a Perl 4 portability bug.
12567
12568 @item 1995-12-18 Jim Meyering starts using Automake in GNU Textutils.
12569 @item 1995-12-31 Fran@,cois Pinard starts using Automake in GNU tar.
12570
12571 @item 1996-01-03 Automake 0.26
12572 @itemx 1996-01-03 Automake 0.27
12573
12574 Of the many changes and suggestions sent by Fran@,cois Pinard and
12575 included in 0.26, perhaps the most important is the advice that to
12576 ease customization a user rule or variable definition should always
12577 override an Automake rule or definition.
12578
12579 Gordon Matzigkeit and Jim Meyering are two other early contributors
12580 that have been sending fixes.
12581
12582 0.27 fixes yet another Perl 4 portability bug.
12583
12584 @item 1996-01-13 Automake 0.28
12585
12586 Automake starts scanning @file{configure.in} for @code{LIBOBJS}
12587 support.  This is an important step because until this version
12588 Automake only knew about the @file{Makefile.am}s it processed.
12589 @file{configure.in} was Autoconf's world and the link between Autoconf
12590 and Automake had to be done by the @file{Makefile.am} author.  For
12591 instance, if @file{config.h} was generated by @file{configure}, it was the
12592 package maintainer's responsibility to define the @code{CONFIG_HEADER}
12593 variable in each @file{Makefile.am}.
12594
12595 Succeeding releases will rely more and more on scanning
12596 @file{configure.in} to better automate the Autoconf integration.
12597
12598 0.28 also introduces the @code{AUTOMAKE_OPTIONS} variable and the
12599 @option{--gnu} and @option{--gnits} options, the latter being stricter.
12600
12601 @item 1996-02-07 Automake 0.29
12602
12603 Thanks to @file{configure.in} scanning, @code{CONFIG_HEADER} is gone,
12604 and rebuild rules for @file{configure}-generated file are
12605 automatically output.
12606
12607 @code{TEXINFOS} and @code{MANS} converted to the uniform naming
12608 scheme.
12609
12610 @item 1996-02-24 Automake 0.30
12611
12612 The test suite is born.  It contains 9 tests.  From now on test cases
12613 will be added pretty regularly (@pxref{Releases}), and this proved to
12614 be really helpful later on.
12615
12616 @code{EXTRA_PROGRAMS} finally replaces @code{AM_PROGRAMS}.
12617
12618 All the third-party Autoconf macros, written mostly by Fran@,cois
12619 Pinard (and later Jim Meyering), are distributed in Automake's
12620 hand-written @file{aclocal.m4} file.  Package maintainers are expected
12621 to extract the necessary macros from this file.  (In previous versions
12622 you had to copy and paste them from the manual...)
12623
12624 @item 1996-03-11 Automake 0.31
12625
12626 The test suite in 0.30 was run via a long @code{check-local} rule.  Upon
12627 Ulrich Drepper's suggestion, 0.31 makes it an Automake rule output
12628 whenever the @code{TESTS} variable is defined.
12629
12630 @code{DIST_OTHER} is renamed to @code{EXTRA_DIST}, and the @code{check_}
12631 prefix is introduced.  The syntax is now the same as today.
12632
12633 @item 1996-03-15 Gordon Matzigkeit starts writing libtool.
12634
12635 @item 1996-04-27 Automake 0.32
12636
12637 @code{-hook} targets are introduced; an idea from Dieter Baron.
12638
12639 @file{*.info} files, which were output in the build directory are
12640 now built in the source directory, because they are distributed.  It
12641 seems these files like to move back and forth as that will happen
12642 again in future versions.
12643
12644 @item 1996-05-18 Automake 0.33
12645
12646 Gord Matzigkeit's main two contributions:
12647
12648 @itemize
12649 @item very preliminary libtool support
12650 @item the distcheck rule
12651 @end itemize
12652
12653 Although they were very basic at this point, these are probably
12654 among the top features for Automake today.
12655
12656 Jim Meyering also provides the infamous @code{jm_MAINTAINER_MODE},
12657 since then renamed to @code{AM_MAINTAINER_MODE} and abandoned by its
12658 author (@pxref{maintainer-mode}).
12659
12660 @item 1996-05-28 Automake 1.0
12661
12662 After only six months of heavy development, the @command{automake} script is
12663 3134 lines long, plus 973 lines of @file{Makefile} fragments.  The
12664 package has 30 pages of documentation, and 38 test cases.
12665 @file{aclocal.m4} contains 4 macros.
12666
12667 From now on and until version 1.4, new releases will occur at a rate
12668 of about one a year.  1.1 did not exist, actually 1.1b to 1.1p have
12669 been the name of beta releases for 1.2.  This is the first time
12670 Automake uses suffix letters to designate beta releases, a habit that
12671 lasts.
12672
12673 @item 1996-10-10 Kevin Dalley packages Automake 1.0 for Debian GNU/Linux.
12674
12675 @item 1996-11-26 David J.@tie{}MacKenzie releases Autoconf 2.12.
12676
12677 Between June and October, the Autoconf development is almost stalled.
12678 Roland McGrath has been working at the beginning of the year.  David
12679 comes back in November to release 2.12, but he won't touch Autoconf
12680 anymore after this year, and Autoconf then really stagnates.  The
12681 desolate Autoconf @file{ChangeLog} for 1997 lists only 7 commits.
12682
12683 @item 1997-02-28 @email{automake@@gnu.ai.mit.edu} list alive
12684
12685 The mailing list is announced as follows:
12686 @smallexample
12687 I've created the "automake" mailing list.  It is
12688 "automake@@gnu.ai.mit.edu".  Administrivia, as always, to
12689 automake-request@@gnu.ai.mit.edu.
12690
12691 The charter of this list is discussion of automake, autoconf, and
12692 other configuration/portability tools (e.g., libtool).  It is expected
12693 that discussion will range from pleas for help all the way up to
12694 patches.
12695
12696 This list is archived on the FSF machines.  Offhand I don't know if
12697 you can get the archive without an account there.
12698
12699 This list is open to anybody who wants to join.  Tell all your
12700 friends!
12701 -- Tom Tromey
12702 @end smallexample
12703
12704 Before that people were discussing Automake privately, on the Gnits
12705 mailing list (which is not public either), and less frequently on
12706 @code{gnu.misc.discuss}.
12707
12708 @code{gnu.ai.mit.edu} is now @code{gnu.org}, in case you never
12709 noticed.  The archives of the early years of the
12710 @code{automake@@gnu.org} list have been lost, so today it is almost
12711 impossible to find traces of discussions that occurred before 1999.
12712 This has been annoying more than once, as such discussions can be
12713 useful to understand the rationale behind a piece of uncommented code
12714 that was introduced back then.
12715
12716 @item 1997-06-22 Automake 1.2
12717
12718 Automake developments continues, and more and more new Autoconf macros
12719 are required.  Distributing them in @file{aclocal.m4} and requiring
12720 people to browse this file to extract the relevant macros becomes
12721 uncomfortable.  Ideally, some of them should be contributed to
12722 Autoconf so that they can be used directly, however Autoconf is
12723 currently inactive.  Automake 1.2 consequently introduces
12724 @command{aclocal} (@command{aclocal} was actually started on
12725 1996-07-28), a tool that automatically constructs an @file{aclocal.m4}
12726 file from a repository of third-party macros.  Because Autoconf has
12727 stalled, Automake also becomes a kind of repository for such
12728 third-party macros, even macros completely unrelated to Automake (for
12729 instance macros that fix broken Autoconf macros).
12730
12731 The 1.2 release contains 20 macros, including the
12732 @code{AM_INIT_AUTOMAKE} macro that simplifies the creation of
12733 @file{configure.in}.
12734
12735 Libtool is fully supported using @code{*_LTLIBRARIES}.
12736
12737 The missing script is introduced by Fran@,cois Pinard; it is meant to be
12738 a better solution than @code{AM_MAINTAINER_MODE}
12739 (@pxref{maintainer-mode}).
12740
12741 Conditionals support was implemented by Ian Lance Taylor.  At the
12742 time, Tom and Ian were working on an internal project at Cygnus.  They
12743 were using ILU, which is pretty similar to CORBA@.  They wanted to
12744 integrate ILU into their build, which was all @file{configure}-based,
12745 and Ian thought that adding conditionals to @command{automake} was
12746 simpler than doing all the work in @file{configure} (which was the
12747 standard at the time).  So this was actually funded by Cygnus.
12748
12749 This very useful but tricky feature will take a lot of time to
12750 stabilize.  (At the time this text is written, there are still
12751 primaries that have not been updated to support conditional
12752 definitions in Automake 1.9.)
12753
12754 The @command{automake} script has almost doubled: 6089 lines of Perl,
12755 plus 1294 lines of @file{Makefile} fragments.
12756
12757 @item 1997-07-08 Gordon Matzigkeit releases Libtool 1.0.
12758
12759 @item 1998-04-05 Automake 1.3
12760
12761 This is a small advance compared to 1.2.
12762 It adds support for assembly, and preliminary support for Java.
12763
12764 Perl 5.004_04 is out, but fixes to support Perl 4 are still
12765 regularly submitted whenever Automake breaks it.
12766
12767 @item 1998-09-06 @code{sourceware.cygnus.com} is on-line.
12768
12769 Sourceware was setup by Jason Molenda to host open source projects.
12770
12771 @item 1998-09-19  Automake CVS repository moved to @code{sourceware.cygnus.com}
12772 @itemx 1998-10-26  @code{sourceware.cygnus.com} announces it hosts Automake:
12773 Automake is now hosted on @code{sourceware.cygnus.com}.  It has a
12774 publicly accessible CVS repository.  This CVS repository is a copy of
12775 the one Tom was using on his machine, which in turn is based on
12776 a copy of the CVS repository of David MacKenzie.  This is why we still
12777 have to full source history.  (Automake was on Sourceware until 2007-10-29,
12778 when it moved to a git repository on @code{savannah.gnu.org},
12779 but the Sourceware host had been renamed to @code{sources.redhat.com}.)
12780
12781 The oldest file in the administrative directory of the CVS repository
12782 that was created on Sourceware is dated 1998-09-19, while the
12783 announcement that @command{automake} and @command{autoconf} had joined
12784 @command{sourceware} was made on 1998-10-26.  They were among the
12785 first projects to be hosted there.
12786
12787 The heedful reader will have noticed Automake was exactly 4 years old
12788 on 1998-09-19.
12789
12790 @item 1999-01-05 Ben Elliston releases Autoconf 2.13.
12791
12792 @item 1999-01-14 Automake 1.4
12793
12794 This release adds support for Fortran 77 and for the @code{include}
12795 statement.  Also, @samp{+=} assignments are introduced, but it is
12796 still quite easy to fool Automake when mixing this with conditionals.
12797
12798 These two releases, Automake 1.4 and Autoconf 2.13 make a duo that
12799 will be used together for years.
12800
12801 @command{automake} is 7228 lines, plus 1591 lines of Makefile
12802 fragment, 20 macros (some 1.3 macros were finally contributed back to
12803 Autoconf), 197 test cases, and 51 pages of documentation.
12804
12805 @item 1999-03-27 The @code{user-dep-branch} is created on the CVS repository.
12806
12807 This implements a new dependency tracking schemed that should be
12808 able to handle automatic dependency tracking using any compiler (not
12809 just gcc) and any make (not just GNU @command{make}).  In addition,
12810 the new scheme should be more reliable than the old one, as
12811 dependencies are generated on the end user's machine.  Alexandre Oliva
12812 creates depcomp for this purpose.
12813
12814 @xref{Dependency Tracking Evolution}, for more details about the
12815 evolution of automatic dependency tracking in Automake.
12816
12817 @item 1999-11-21 The @code{user-dep-branch} is merged into the main trunk.
12818
12819 This was a huge problem since we also had patches going in on the
12820 trunk.  The merge took a long time and was very painful.
12821
12822 @item 2000-05-10
12823
12824 Since September 1999 and until 2003, Akim Demaille will be zealously
12825 revamping Autoconf.
12826
12827 @quotation
12828 I think the next release should be called "3.0".@*
12829 Let's face it: you've basically rewritten autoconf.@*
12830 Every weekend there are 30 new patches.@*
12831 I don't see how we could call this "2.15" with a straight face.@*
12832 -- Tom Tromey on @email{autoconf@@gnu.org}
12833 @end quotation
12834
12835 Actually Akim works like a submarine: he will pile up patches while he
12836 works off-line during the weekend, and flush them in batch when he
12837 resurfaces on Monday.
12838
12839 @item 2001-01-24
12840
12841 On this Wednesday, Autoconf 2.49c, the last beta before Autoconf 2.50
12842 is out, and Akim has to find something to do during his week-end :)
12843
12844 @item 2001-01-28
12845
12846 Akim sends a batch of 14 patches to @email{automake@@gnu.org}.
12847
12848 @quotation
12849 Aiieeee!  I was dreading the day that the Demaillator turned his
12850 sights on automake@dots{} and now it has arrived! -- Tom Tromey
12851 @end quotation
12852
12853 It's only the beginning: in two months he will send 192 patches.  Then
12854 he would slow down so Tom can catch up and review all this.  Initially
12855 Tom actually read all these patches, then he probably trustingly
12856 answered OK to most of them, and finally gave up and let Akim apply
12857 whatever he wanted.  There was no way to keep up with that patch rate.
12858
12859 @quotation
12860 Anyway the patch below won't apply since it predates Akim's
12861 sourcequake; I have yet to figure where the relevant passage has
12862 been moved :) -- Alexandre Duret-Lutz
12863 @end quotation
12864
12865 All these patches were sent to and discussed on
12866 @email{automake@@gnu.org}, so subscribed users were literally drowning in
12867 technical mails.  Eventually, the @email{automake-patches@@gnu.org}
12868 mailing list was created in May.
12869
12870 Year after year, Automake had drifted away from its initial design:
12871 construct @file{Makefile.in} by assembling various @file{Makefile}
12872 fragments.  In 1.4, lots of @file{Makefile} rules are being emitted at
12873 various places in the @command{automake} script itself; this does not
12874 help ensuring a consistent treatment of these rules (for instance
12875 making sure that user-defined rules override Automake's own rules).
12876 One of Akim's goal was moving all these hard-coded rules to separate
12877 @file{Makefile} fragments, so the logic could be centralized in a
12878 @file{Makefile} fragment processor.
12879
12880 Another significant contribution of Akim is the interface with the
12881 ``trace'' feature of Autoconf.  The way to scan @file{configure.in} at
12882 this time was to read the file and grep the various macro of interest
12883 to Automake.  Doing so could break in many unexpected ways; @command{automake}
12884 could miss some definition (for instance @samp{AC_SUBST([$1], [$2])}
12885 where the arguments are known only when M4 is run), or conversely it
12886 could detect some macro that was not expanded (because it is called
12887 conditionally).  In the CVS version of Autoconf, Akim had implemented
12888 the @option{--trace} option, which provides accurate information about
12889 where macros are actually called and with what arguments.  Akim will
12890 equip Automake with a second @file{configure.in} scanner that uses
12891 this @option{--trace} interface.  Since it was not sensible to drop the
12892 Autoconf 2.13 compatibility yet, this experimental scanner was only
12893 used when an environment variable was set, the traditional
12894 grep-scanner being still the default.
12895
12896 @item 2001-04-25 Gary V.@tie{}Vaughan releases Libtool 1.4
12897
12898 It has been more than two years since Automake 1.4, CVS Automake has
12899 suffered lot's of heavy changes and still is not ready for release.
12900 Libtool 1.4 had to be distributed with a patch against Automake 1.4.
12901
12902 @item 2001-05-08 Automake 1.4-p1
12903 @itemx 2001-05-24 Automake 1.4-p2
12904
12905 Gary V.@tie{}Vaughan, the principal Libtool maintainer, makes a ``patch
12906 release'' of Automake:
12907
12908 @quotation
12909 The main purpose of this release is to have a stable automake
12910 which is compatible with the latest stable libtool.
12911 @end quotation
12912
12913 The release also contains obvious fixes for bugs in Automake 1.4,
12914 some of which were reported almost monthly.
12915
12916 @item 2001-05-21 Akim Demaille releases Autoconf 2.50
12917
12918 @item 2001-06-07 Automake 1.4-p3
12919 @itemx 2001-06-10 Automake 1.4-p4
12920 @itemx 2001-07-15 Automake 1.4-p5
12921
12922 Gary continues his patch-release series.  These also add support for
12923 some new Autoconf 2.50 idioms.  Essentially, Autoconf now advocates
12924 @file{configure.ac} over @file{configure.in}, and it introduces a new
12925 syntax for @code{AC_OUTPUT}ing files.
12926
12927 @item 2001-08-23 Automake 1.5
12928
12929 A major and long-awaited release, that comes more than two years after
12930 1.4.  It brings many changes, among which:
12931 @itemize
12932 @item The new dependency tracking scheme that uses @command{depcomp}.
12933 Aside from the improvement on the dependency tracking itself
12934 (@pxref{Dependency Tracking Evolution}), this also streamlines the use
12935 of @command{automake}-generated @file{Makefile.in}s as the @file{Makefile.in}s
12936 used during development are now the same as those used in
12937 distributions.  Before that the @file{Makefile.in}s generated for
12938 maintainers required GNU @command{make} and GCC, they were different
12939 from the portable @file{Makefile} generated for distribution; this was
12940 causing some confusion.
12941
12942 @item Support for per-target compilation flags.
12943
12944 @item Support for reference to files in subdirectories in most
12945 @file{Makefile.am} variables.
12946
12947 @item Introduction of the @code{dist_}, @code{nodist_}, and @code{nobase_}
12948 prefixes.
12949 @item Perl 4 support is finally dropped.
12950 @end itemize
12951
12952 1.5 did break several packages that worked with 1.4.  Enough so that
12953 Linux distributions could not easily install the new Automake version
12954 without breaking many of the packages for which they had to run
12955 @command{automake}.
12956
12957 Some of these breakages were effectively bugs that would eventually be
12958 fixed in the next release.  However, a lot of damage was caused by
12959 some changes made deliberately to render Automake stricter on some
12960 setup we did consider bogus.  For instance, @samp{make distcheck} was
12961 improved to check that @samp{make uninstall} did remove all the files
12962 @samp{make install} installed, that @samp{make distclean} did not omit
12963 some file, and that a VPATH build would work even if the source
12964 directory was read-only.  Similarly, Automake now rejects multiple
12965 definitions of the same variable (because that would mix very badly
12966 with conditionals), and @samp{+=} assignments with no previous
12967 definition.  Because these changes all occurred suddenly after 1.4 had
12968 been established for more than two years, it hurt users.
12969
12970 To make matter worse, meanwhile Autoconf (now at version 2.52) was
12971 facing similar troubles, for similar reasons.
12972
12973 @item 2002-03-05 Automake 1.6
12974
12975 This release introduced versioned installation (@pxref{API
12976 Versioning}).  This was mainly pushed by Havoc Pennington, taking the
12977 GNOME source tree as motive: due to incompatibilities between the
12978 autotools it's impossible for the GNOME packages to switch to Autoconf
12979 2.53 and Automake 1.5 all at once, so they are currently stuck with
12980 Autoconf 2.13 and Automake 1.4.
12981
12982 The idea was to call this version @file{automake-1.6}, call all its
12983 bug-fix versions identically, and switch to @file{automake-1.7} for
12984 the next release that adds new features or changes some rules.  This
12985 scheme implies maintaining a bug-fix branch in addition to the
12986 development trunk, which means more work from the maintainer, but
12987 providing regular bug-fix releases proved to be really worthwhile.
12988
12989 Like 1.5, 1.6 also introduced a bunch of incompatibilities, intentional or
12990 not.  Perhaps the more annoying was the dependence on the newly
12991 released Autoconf 2.53.  Autoconf seemed to have stabilized enough
12992 since its explosive 2.50 release and included changes required to fix
12993 some bugs in Automake.  In order to upgrade to Automake 1.6, people
12994 now had to upgrade Autoconf too; for some packages it was no picnic.
12995
12996 While versioned installation helped people to upgrade, it also
12997 unfortunately allowed people not to upgrade.  At the time of writing,
12998 some Linux distributions are shipping packages for Automake 1.4, 1.5,
12999 1.6, 1.7, 1.8, and 1.9.  Most of these still install 1.4 by default.
13000 Some distribution also call 1.4 the ``stable'' version, and present
13001 ``1.9'' as the development version; this does not really makes sense
13002 since 1.9 is way more solid than 1.4.  All this does not help the
13003 newcomer.
13004
13005 @item 2002-04-11 Automake 1.6.1
13006
13007 1.6, and the upcoming 1.4-p6 release were the last release by Tom.
13008 This one and those following will be handled by Alexandre
13009 Duret-Lutz.  Tom is still around, and will be there until about 1.7,
13010 but his interest into Automake is drifting away towards projects like
13011 @command{gcj}.
13012
13013 Alexandre has been using Automake since 2000, and started to
13014 contribute mostly on Akim's incitement (Akim and Alexandre have been
13015 working in the same room from 1999 to 2002).  In 2001 and 2002 he had
13016 a lot of free time to enjoy hacking Automake.
13017
13018 @item 2002-06-14 Automake 1.6.2
13019
13020 @item 2002-07-28 Automake 1.6.3
13021 @itemx 2002-07-28 Automake 1.4-p6
13022
13023 Two releases on the same day.  1.6.3 is a bug-fix release.
13024
13025 Tom Tromey backported the versioned installation mechanism on the 1.4
13026 branch, so that Automake 1.6.x and Automake 1.4-p6 could be installed
13027 side by side.  Another request from the GNOME folks.
13028
13029 @item 2002-09-25 Automake 1.7
13030
13031 This release switches to the new @file{configure.ac} scanner Akim
13032 was experimenting in 1.5.
13033
13034 @item 2002-10-16 Automake 1.7.1
13035 @itemx 2002-12-06 Automake 1.7.2
13036 @itemx 2003-02-20 Automake 1.7.3
13037 @itemx 2003-04-23 Automake 1.7.4
13038 @itemx 2003-05-18 Automake 1.7.5
13039 @itemx 2003-07-10 Automake 1.7.6
13040 @itemx 2003-09-07 Automake 1.7.7
13041 @itemx 2003-10-07 Automake 1.7.8
13042
13043 Many bug-fix releases.  1.7 lasted because the development version
13044 (upcoming 1.8) was suffering some major internal revamping.
13045
13046 @item 2003-10-26 Automake on screen
13047
13048 Episode 49, `Repercussions', in the third season of the `Alias' TV
13049 show is first aired.
13050
13051 Marshall, one of the characters, is working on a computer virus that he
13052 has to modify before it gets into the wrong hands or something like
13053 that.  The screenshots you see do not show any program code, they show
13054 a @file{Makefile.in} @code{generated by automake}...
13055
13056 @item 2003-11-09 Automake 1.7.9
13057
13058 @item 2003-12-10 Automake 1.8
13059
13060 The most striking update is probably that of @command{aclocal}.
13061
13062 @command{aclocal} now uses @code{m4_include} in the produced
13063 @file{aclocal.m4} when the included macros are already distributed
13064 with the package (an idiom used in many packages), which reduces code
13065 duplication.  Many people liked that, but in fact this change was
13066 really introduced to fix a bug in rebuild rules: @file{Makefile.in}
13067 must be rebuilt whenever a dependency of @file{configure} changes, but
13068 all the @file{m4} files included in @file{aclocal.m4} where unknown
13069 from @command{automake}.  Now @command{automake} can just trace the
13070 @code{m4_include}s to discover the dependencies.
13071
13072 @command{aclocal} also starts using the @option{--trace} Autoconf option
13073 in order to discover used macros more accurately.  This will turn out
13074 to be very tricky (later releases will improve this) as people had
13075 devised many ways to cope with the limitation of previous
13076 @command{aclocal} versions, notably using handwritten
13077 @code{m4_include}s: @command{aclocal} must make sure not to redefine a
13078 rule that is already included by such statement.
13079
13080 Automake also has seen its guts rewritten.  Although this rewriting
13081 took a lot of efforts, it is only apparent to the users in that some
13082 constructions previously disallowed by the implementation now work
13083 nicely.  Conditionals, Locations, Variable and Rule definitions,
13084 Options: these items on which Automake works have been rewritten as
13085 separate Perl modules, and documented.
13086
13087 @itemx 2004-01-11 Automake 1.8.1
13088 @itemx 2004-01-12 Automake 1.8.2
13089 @itemx 2004-03-07 Automake 1.8.3
13090 @itemx 2004-04-25 Automake 1.8.4
13091 @itemx 2004-05-16 Automake 1.8.5
13092
13093 @item 2004-07-28 Automake 1.9
13094
13095 This release tries to simplify the compilation rules it outputs to
13096 reduce the size of the Makefile.  The complaint initially come from
13097 the libgcj developers.  Their @file{Makefile.in} generated with
13098 Automake 1.4 and custom build rules (1.4 did not support compiled
13099 Java) is 250KB@.  The one generated by 1.8 was over 9MB@!  1.9 gets it
13100 down to 1.2MB@.
13101
13102 Aside from this it contains mainly minor changes and bug-fixes.
13103
13104 @itemx 2004-08-11 Automake 1.9.1
13105 @itemx 2004-09-19 Automake 1.9.2
13106
13107 Automake has ten years.  This chapter of the manual was initially
13108 written for this occasion.
13109
13110 @itemx 2007-10-29 Automake repository moves to @code{savannah.gnu.org} and uses
13111 git as primary repository.
13112
13113 @end table
13114
13115 @node Dependency Tracking Evolution
13116 @section Dependency Tracking in Automake
13117
13118 Over the years Automake has deployed three different dependency
13119 tracking methods.  Each method, including the current one, has had
13120 flaws of various sorts.  Here we lay out the different dependency
13121 tracking methods, their flaws, and their fixes.  We conclude with
13122 recommendations for tool writers, and by indicating future directions
13123 for dependency tracking work in Automake.
13124
13125 @menu
13126 * First Take on Dependencies::  Precomputed dependency tracking
13127 * Dependencies As Side Effects::  Update at developer compile time
13128 * Dependencies for the User::   Update at user compile time
13129 * Techniques for Dependencies::  Alternative approaches
13130 * Recommendations for Tool Writers::  What tool writers can do to help
13131 * Future Directions for Dependencies::  Languages Automake does not know
13132 @end menu
13133
13134 @node First Take on Dependencies
13135 @subsection First Take on Dependency Tracking
13136 @unnumberedsubsubsec Description
13137
13138 Our first attempt at automatic dependency tracking was based on the
13139 method recommended by GNU @command{make}.  (@pxref{Automatic
13140 Prerequisites, , Generating Prerequisites Automatically, make, The GNU
13141 make Manual})
13142
13143 This version worked by precomputing dependencies ahead of time.  For
13144 each source file, it had a special @file{.P} file that held the
13145 dependencies.  There was a rule to generate a @file{.P} file by
13146 invoking the compiler appropriately.  All such @file{.P} files were
13147 included by the @file{Makefile}, thus implicitly becoming dependencies
13148 of @file{Makefile}.
13149
13150 @unnumberedsubsubsec Bugs
13151
13152 This approach had several critical bugs.
13153
13154 @itemize
13155 @item
13156 The code to generate the @file{.P} file relied on @command{gcc}.
13157 (A limitation, not technically a bug.)
13158 @item
13159 The dependency tracking mechanism itself relied on GNU @command{make}.
13160 (A limitation, not technically a bug.)
13161 @item
13162 Because each @file{.P} file was a dependency of @file{Makefile}, this
13163 meant that dependency tracking was done eagerly by @command{make}.
13164 For instance, @samp{make clean} would cause all the dependency files
13165 to be updated, and then immediately removed.  This eagerness also
13166 caused problems with some configurations; if a certain source file
13167 could not be compiled on a given architecture for some reason,
13168 dependency tracking would fail, aborting the entire build.
13169 @item
13170 As dependency tracking was done as a pre-pass, compile times were
13171 doubled--the compiler had to be run twice per source file.
13172 @item
13173 @samp{make dist} re-ran @command{automake} to generate a
13174 @file{Makefile} that did not have automatic dependency tracking (and
13175 that was thus portable to any version of @command{make}).  In order to
13176 do this portably, Automake had to scan the dependency files and remove
13177 any reference that was to a source file not in the distribution.
13178 This process was error-prone.  Also, if @samp{make dist} was run in an
13179 environment where some object file had a dependency on a source file
13180 that was only conditionally created, Automake would generate a
13181 @file{Makefile} that referred to a file that might not appear in the
13182 end user's build.  A special, hacky mechanism was required to work
13183 around this.
13184 @end itemize
13185
13186 @unnumberedsubsubsec Historical Note
13187
13188 The code generated by Automake is often inspired by the
13189 @file{Makefile} style of a particular author.  In the case of the first
13190 implementation of dependency tracking, I believe the impetus and
13191 inspiration was Jim Meyering.  (I could be mistaken.  If you know
13192 otherwise feel free to correct me.)
13193
13194 @node Dependencies As Side Effects
13195 @subsection Dependencies As Side Effects
13196 @unnumberedsubsubsec Description
13197
13198 The next refinement of Automake's automatic dependency tracking scheme
13199 was to implement dependencies as side effects of the compilation.
13200 This was aimed at solving the most commonly reported problems with the
13201 first approach.  In particular we were most concerned with eliminating
13202 the weird rebuilding effect associated with make clean.
13203
13204 In this approach, the @file{.P} files were included using the
13205 @code{-include} command, which let us create these files lazily.  This
13206 avoided the @samp{make clean} problem.
13207
13208 We only computed dependencies when a file was actually compiled.  This
13209 avoided the performance penalty associated with scanning each file
13210 twice.  It also let us avoid the other problems associated with the
13211 first, eager, implementation.  For instance, dependencies would never
13212 be generated for a source file that was not compilable on a given
13213 architecture (because it in fact would never be compiled).
13214
13215 @unnumberedsubsubsec Bugs
13216
13217 @itemize
13218 @item
13219 This approach also relied on the existence of @command{gcc} and GNU
13220 @command{make}.  (A limitation, not technically a bug.)
13221 @item
13222 Dependency tracking was still done by the developer, so the problems
13223 from the first implementation relating to massaging of dependencies by
13224 @samp{make dist} were still in effect.
13225 @item
13226 This implementation suffered from the ``deleted header file'' problem.
13227 Suppose a lazily-created @file{.P} file includes a dependency on a
13228 given header file, like this:
13229
13230 @example
13231 maude.o: maude.c something.h
13232 @end example
13233
13234 Now suppose that you remove @file{something.h} and update @file{maude.c}
13235 so that this include is no longer needed.  If you run @command{make},
13236 you will get an error because there is no way to create
13237 @file{something.h}.
13238
13239 We fixed this problem in a later release by further massaging the
13240 output of @command{gcc} to include a dummy dependency for each header
13241 file.
13242 @end itemize
13243
13244 @node Dependencies for the User
13245 @subsection Dependencies for the User
13246 @unnumberedsubsubsec Description
13247
13248 The bugs associated with @samp{make dist}, over time, became a real
13249 problem.  Packages using Automake were being built on a large number
13250 of platforms, and were becoming increasingly complex.  Broken
13251 dependencies were distributed in ``portable'' @file{Makefile.in}s,
13252 leading to user complaints.  Also, the requirement for @command{gcc}
13253 and GNU @command{make} was a constant source of bug reports.  The next
13254 implementation of dependency tracking aimed to remove these problems.
13255
13256 We realized that the only truly reliable way to automatically track
13257 dependencies was to do it when the package itself was built.  This
13258 meant discovering a method portable to any version of make and any
13259 compiler.  Also, we wanted to preserve what we saw as the best point
13260 of the second implementation: dependency computation as a side effect
13261 of compilation.
13262
13263 In the end we found that most modern make implementations support some
13264 form of include directive.  Also, we wrote a wrapper script that let
13265 us abstract away differences between dependency tracking methods for
13266 compilers.  For instance, some compilers cannot generate dependencies
13267 as a side effect of compilation.  In this case we simply have the
13268 script run the compiler twice.  Currently our wrapper script
13269 (@command{depcomp}) knows about twelve different compilers (including
13270 a "compiler" that simply invokes @command{makedepend} and then the
13271 real compiler, which is assumed to be a standard Unix-like C compiler
13272 with no way to do dependency tracking).
13273
13274 @unnumberedsubsubsec Bugs
13275
13276 @itemize
13277 @item
13278 Running a wrapper script for each compilation slows down the build.
13279 @item
13280 Many users don't really care about precise dependencies.
13281 @item
13282 This implementation, like every other automatic dependency tracking
13283 scheme in common use today (indeed, every one we've ever heard of),
13284 suffers from the ``duplicated new header'' bug.
13285
13286 This bug occurs because dependency tracking tools, such as the
13287 compiler, only generate dependencies on the successful opening of a
13288 file, and not on every probe.
13289
13290 Suppose for instance that the compiler searches three directories for
13291 a given header, and that the header is found in the third directory.
13292 If the programmer erroneously adds a header file with the same name to
13293 the first directory, then a clean rebuild from scratch could fail
13294 (suppose the new header file is buggy), whereas an incremental rebuild
13295 will succeed.
13296
13297 What has happened here is that people have a misunderstanding of what
13298 a dependency is.  Tool writers think a dependency encodes information
13299 about which files were read by the compiler.  However, a dependency
13300 must actually encode information about what the compiler tried to do.
13301
13302 This problem is not serious in practice.  Programmers typically do not
13303 use the same name for a header file twice in a given project.  (At
13304 least, not in C or C++.  This problem may be more troublesome in
13305 Java.)  This problem is easy to fix, by modifying dependency
13306 generators to record every probe, instead of every successful open.
13307
13308 @item
13309 Since Automake generates dependencies as a side effect of compilation,
13310 there is a bootstrapping problem when header files are generated by
13311 running a program.  The problem is that, the first time the build is
13312 done, there is no way by default to know that the headers are
13313 required, so make might try to run a compilation for which the headers
13314 have not yet been built.
13315
13316 This was also a problem in the previous dependency tracking implementation.
13317
13318 The current fix is to use @code{BUILT_SOURCES} to list built headers
13319 (@pxref{Sources}).  This causes them to be built before any other
13320 build rules are run.  This is unsatisfactory as a general solution,
13321 however in practice it seems sufficient for most actual programs.
13322 @end itemize
13323
13324 This code is used since Automake 1.5.
13325
13326 In GCC 3.0, we managed to convince the maintainers to add special
13327 command-line options to help Automake more efficiently do its job.  We
13328 hoped this would let us avoid the use of a wrapper script when
13329 Automake's automatic dependency tracking was used with @command{gcc}.
13330
13331 Unfortunately, this code doesn't quite do what we want.  In
13332 particular, it removes the dependency file if the compilation fails;
13333 we'd prefer that it instead only touch the file in any way if the
13334 compilation succeeds.
13335
13336 Nevertheless, since Automake 1.7, when a recent @command{gcc} is
13337 detected at @command{configure} time, we inline the
13338 dependency-generation code and do not use the @command{depcomp}
13339 wrapper script.  This makes compilations faster for those using this
13340 compiler (probably our primary user base).  The counterpart is that
13341 because we have to encode two compilation rules in @file{Makefile}
13342 (with or without @command{depcomp}), the produced @file{Makefile}s are
13343 larger.
13344
13345 @node Techniques for Dependencies
13346 @subsection Techniques for Computing Dependencies
13347
13348 There are actually several ways for a build tool like Automake to
13349 cause tools to generate dependencies.
13350
13351 @table @asis
13352 @item @command{makedepend}
13353 This was a commonly-used method in the past.  The idea is to run a
13354 special program over the source and have it generate dependency
13355 information.  Traditional implementations of @command{makedepend} are
13356 not completely precise; ordinarily they were conservative and
13357 discovered too many dependencies.
13358 @item The tool
13359 An obvious way to generate dependencies is to simply write the tool so
13360 that it can generate the information needed by the build tool.  This is
13361 also the most portable method.  Many compilers have an option to
13362 generate dependencies.  Unfortunately, not all tools provide such an
13363 option.
13364 @item The file system
13365 It is possible to write a special file system that tracks opens,
13366 reads, writes, etc, and then feed this information back to the build
13367 tool.  @command{clearmake} does this.  This is a very powerful
13368 technique, as it doesn't require cooperation from the
13369 tool.  Unfortunately it is also very difficult to implement and also
13370 not practical in the general case.
13371 @item @code{LD_PRELOAD}
13372 Rather than use the file system, one could write a special library to
13373 intercept @code{open} and other syscalls.  This technique is also quite
13374 powerful, but unfortunately it is not portable enough for use in
13375 @command{automake}.
13376 @end table
13377
13378 @node Recommendations for Tool Writers
13379 @subsection Recommendations for Tool Writers
13380
13381 We think that every compilation tool ought to be able to generate
13382 dependencies as a side effect of compilation.  Furthermore, at least
13383 while @command{make}-based tools are nearly universally in use (at
13384 least in the free software community), the tool itself should generate
13385 dummy dependencies for header files, to avoid the deleted header file
13386 bug.  Finally, the tool should generate a dependency for each probe,
13387 instead of each successful file open, in order to avoid the duplicated
13388 new header bug.
13389
13390 @node Future Directions for Dependencies
13391 @subsection Future Directions for Dependencies
13392
13393 Currently, only languages and compilers understood by Automake can
13394 have dependency tracking enabled.  We would like to see if it is
13395 practical (and worthwhile) to let this support be extended by the user
13396 to languages unknown to Automake.
13397
13398 @node Releases
13399 @section Release Statistics
13400
13401 The following table (inspired by @samp{perlhist(1)}) quantifies the
13402 evolution of Automake using these metrics:
13403
13404 @table @asis
13405 @item Date, Rel
13406 The date and version of the release.
13407 @item am
13408 The number of lines of the @command{automake} script.
13409 @item acl
13410 The number of lines of the @command{aclocal} script.
13411 @item pm
13412 The number of lines of the @command{Perl} supporting modules.
13413 @item @file{*.am}
13414 The number of lines of the @file{Makefile} fragments.  The number in
13415 parentheses is the number of files.
13416 @item m4
13417 The number of lines (and files) of Autoconf macros.
13418 @item doc
13419 The number of pages of the documentation (the Postscript version).
13420 @item t
13421 The number of test cases in the test suite.  Of those, the number in
13422 parentheses is the number of generated test cases.
13423 @end table
13424
13425 @multitable {8888-88-88} {8.8-p8} {8888} {8888} {8888} {8888 (88)} {8888 (88)} {888} {888 (88)}
13426 @headitem Date   @tab Rel    @tab   am @tab acl @tab   pm @tab @file{*.am} @tab m4 @tab doc @tab t
13427 @item 1994-09-19 @tab CVS    @tab  141 @tab     @tab      @tab  299 (24) @tab           @tab     @tab
13428 @item 1994-11-05 @tab CVS    @tab  208 @tab     @tab      @tab  332 (28) @tab           @tab     @tab
13429 @item 1995-11-23 @tab 0.20   @tab  533 @tab     @tab      @tab  458 (35) @tab           @tab   9 @tab
13430 @item 1995-11-26 @tab 0.21   @tab  613 @tab     @tab      @tab  480 (36) @tab           @tab  11 @tab
13431 @item 1995-11-28 @tab 0.22   @tab 1116 @tab     @tab      @tab  539 (38) @tab           @tab  12 @tab
13432 @item 1995-11-29 @tab 0.23   @tab 1240 @tab     @tab      @tab  541 (38) @tab           @tab  12 @tab
13433 @item 1995-12-08 @tab 0.24   @tab 1462 @tab     @tab      @tab  504 (33) @tab           @tab  14 @tab
13434 @item 1995-12-10 @tab 0.25   @tab 1513 @tab     @tab      @tab  511 (37) @tab           @tab  15 @tab
13435 @item 1996-01-03 @tab 0.26   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
13436 @item 1996-01-03 @tab 0.27   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
13437 @item 1996-01-13 @tab 0.28   @tab 1964 @tab     @tab      @tab  934 (33) @tab           @tab  16 @tab
13438 @item 1996-02-07 @tab 0.29   @tab 2299 @tab     @tab      @tab  936 (33) @tab           @tab  17 @tab
13439 @item 1996-02-24 @tab 0.30   @tab 2544 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  20 @tab 9
13440 @item 1996-03-11 @tab 0.31   @tab 2877 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  29 @tab 17
13441 @item 1996-04-27 @tab 0.32   @tab 3058 @tab     @tab      @tab  921 (31) @tab   85 (1)  @tab  30 @tab 26
13442 @item 1996-05-18 @tab 0.33   @tab 3110 @tab     @tab      @tab  926 (31) @tab  105 (1)  @tab  30 @tab 35
13443 @item 1996-05-28 @tab 1.0    @tab 3134 @tab     @tab      @tab  973 (32) @tab  105 (1)  @tab  30 @tab 38
13444 @item 1997-06-22 @tab 1.2    @tab 6089 @tab 385 @tab      @tab 1294 (36) @tab  592 (20) @tab  37 @tab 126
13445 @item 1998-04-05 @tab 1.3    @tab 6415 @tab 422 @tab      @tab 1470 (39) @tab  741 (23) @tab  39 @tab 156
13446 @item 1999-01-14 @tab 1.4    @tab 7240 @tab 426 @tab      @tab 1591 (40) @tab  734 (20) @tab  51 @tab 197
13447 @item 2001-05-08 @tab 1.4-p1 @tab 7251 @tab 426 @tab      @tab 1591 (40) @tab  734 (20) @tab  51 @tab 197
13448 @item 2001-05-24 @tab 1.4-p2 @tab 7268 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 197
13449 @item 2001-06-07 @tab 1.4-p3 @tab 7312 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 197
13450 @item 2001-06-10 @tab 1.4-p4 @tab 7321 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 198
13451 @item 2001-07-15 @tab 1.4-p5 @tab 7228 @tab 426 @tab      @tab 1596 (40) @tab  734 (20) @tab  51 @tab 198
13452 @item 2001-08-23 @tab 1.5    @tab 8016 @tab 475 @tab  600 @tab 2654 (39) @tab 1166 (29) @tab  63 @tab 327
13453 @item 2002-03-05 @tab 1.6    @tab 8465 @tab 475 @tab 1136 @tab 2732 (39) @tab 1603 (27) @tab  66 @tab 365
13454 @item 2002-04-11 @tab 1.6.1  @tab 8544 @tab 475 @tab 1136 @tab 2741 (39) @tab 1603 (27) @tab  66 @tab 372
13455 @item 2002-06-14 @tab 1.6.2  @tab 8575 @tab 475 @tab 1136 @tab 2800 (39) @tab 1609 (27) @tab  67 @tab 386
13456 @item 2002-07-28 @tab 1.6.3  @tab 8600 @tab 475 @tab 1153 @tab 2809 (39) @tab 1609 (27) @tab  67 @tab 391
13457 @item 2002-07-28 @tab 1.4-p6 @tab 7332 @tab 455 @tab      @tab 1596 (40) @tab  735 (20) @tab  49 @tab 197
13458 @item 2002-09-25 @tab 1.7    @tab 9189 @tab 471 @tab 1790 @tab 2965 (39) @tab 1606 (28) @tab  73 @tab 430
13459 @item 2002-10-16 @tab 1.7.1  @tab 9229 @tab 475 @tab 1790 @tab 2977 (39) @tab 1606 (28) @tab  73 @tab 437
13460 @item 2002-12-06 @tab 1.7.2  @tab 9334 @tab 475 @tab 1790 @tab 2988 (39) @tab 1606 (28) @tab  77 @tab 445
13461 @item 2003-02-20 @tab 1.7.3  @tab 9389 @tab 475 @tab 1790 @tab 3023 (39) @tab 1651 (29) @tab  84 @tab 448
13462 @item 2003-04-23 @tab 1.7.4  @tab 9429 @tab 475 @tab 1790 @tab 3031 (39) @tab 1644 (29) @tab  85 @tab 458
13463 @item 2003-05-18 @tab 1.7.5  @tab 9429 @tab 475 @tab 1790 @tab 3033 (39) @tab 1645 (29) @tab  85 @tab 459
13464 @item 2003-07-10 @tab 1.7.6  @tab 9442 @tab 475 @tab 1790 @tab 3033 (39) @tab 1660 (29) @tab  85 @tab 461
13465 @item 2003-09-07 @tab 1.7.7  @tab 9443 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (29) @tab  90 @tab 467
13466 @item 2003-10-07 @tab 1.7.8  @tab 9444 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (29) @tab  90 @tab 468
13467 @item 2003-11-09 @tab 1.7.9  @tab 9444 @tab 475 @tab 1790 @tab 3048 (39) @tab 1660 (29) @tab  90 @tab 468
13468 @item 2003-12-10 @tab 1.8    @tab 7171 @tab 585 @tab 7730 @tab 3236 (39) @tab 1666 (31) @tab 104 @tab 521
13469 @item 2004-01-11 @tab 1.8.1  @tab 7217 @tab 663 @tab 7726 @tab 3287 (39) @tab 1686 (31) @tab 104 @tab 525
13470 @item 2004-01-12 @tab 1.8.2  @tab 7217 @tab 663 @tab 7726 @tab 3288 (39) @tab 1686 (31) @tab 104 @tab 526
13471 @item 2004-03-07 @tab 1.8.3  @tab 7214 @tab 686 @tab 7735 @tab 3303 (39) @tab 1695 (31) @tab 111 @tab 530
13472 @item 2004-04-25 @tab 1.8.4  @tab 7214 @tab 686 @tab 7736 @tab 3310 (39) @tab 1701 (31) @tab 112 @tab 531
13473 @item 2004-05-16 @tab 1.8.5  @tab 7240 @tab 686 @tab 7736 @tab 3299 (39) @tab 1701 (31) @tab 112 @tab 533
13474 @item 2004-07-28 @tab 1.9    @tab 7508 @tab 715 @tab 7794 @tab 3352 (40) @tab 1812 (32) @tab 115 @tab 551
13475 @item 2004-08-11 @tab 1.9.1  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (32) @tab 115 @tab 552
13476 @item 2004-09-19 @tab 1.9.2  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (32) @tab 132 @tab 554
13477 @item 2004-11-01 @tab 1.9.3  @tab 7507 @tab 718 @tab 7804 @tab 3354 (40) @tab 1812 (32) @tab 134 @tab 556
13478 @item 2004-12-18 @tab 1.9.4  @tab 7508 @tab 718 @tab 7856 @tab 3361 (40) @tab 1811 (32) @tab 140 @tab 560
13479 @item 2005-02-13 @tab 1.9.5  @tab 7523 @tab 719 @tab 7859 @tab 3373 (40) @tab 1453 (32) @tab 142 @tab 562
13480 @item 2005-07-10 @tab 1.9.6  @tab 7539 @tab 699 @tab 7867 @tab 3400 (40) @tab 1453 (32) @tab 144 @tab 570
13481 @item 2006-10-15 @tab 1.10   @tab 7859 @tab 1072 @tab 8024 @tab 3512 (40) @tab 1496 (34) @tab 172 @tab 604
13482 @item 2008-01-19 @tab 1.10.1 @tab 7870 @tab 1089 @tab 8025 @tab 3520 (40) @tab 1499 (34) @tab 173 @tab 617
13483 @item 2008-11-23 @tab 1.10.2 @tab 7882 @tab 1089 @tab 8027 @tab 3540 (40) @tab 1509 (34) @tab 176 @tab 628
13484 @item 2009-05-17 @tab 1.11   @tab 8721 @tab 1092 @tab 8289 @tab 4164 (42) @tab 1714 (37) @tab 181 @tab 732 (20)
13485 @end multitable
13486
13487
13488 @c ========================================================== Appendices
13489
13490 @page
13491 @node Copying This Manual
13492 @appendix Copying This Manual
13493
13494 @menu
13495 * GNU Free Documentation License::  License for copying this manual
13496 @end menu
13497
13498 @node GNU Free Documentation License
13499 @appendixsec GNU Free Documentation License
13500 @include fdl.texi
13501
13502 @page
13503 @node Indices
13504 @appendix Indices
13505
13506 @menu
13507 * Macro Index::                 Index of Autoconf macros
13508 * Variable Index::              Index of Makefile variables
13509 * General Index::               General index
13510 @end menu
13511
13512 @node Macro Index
13513 @appendixsec Macro Index
13514
13515 @printindex fn
13516
13517 @node Variable Index
13518 @appendixsec Variable Index
13519
13520 @printindex vr
13521
13522 @node General Index
13523 @appendixsec General Index
13524
13525 @printindex cp
13526
13527
13528 @bye
13529
13530 @c  LocalWords:  texinfo setfilename settitle setchapternewpage texi direntry
13531 @c  LocalWords:  dircategory in's aclocal ifinfo titlepage Tromey vskip pt sp
13532 @c  LocalWords:  filll defcodeindex ov cv op tr syncodeindex fn cp vr ifnottex
13533 @c  LocalWords:  dir Automake's ac Dist Gnits gnits cygnus dfn Autoconf's pxref
13534 @c  LocalWords:  cindex Autoconf autoconf perl samp cvs dist trindex SUBST foo
13535 @c  LocalWords:  xs emph FIXME ref vindex pkglibdir pkgincludedir pkgdatadir mt
13536 @c  LocalWords:  pkg libdir cpio bindir sbindir rmt pax sbin zar zardir acindex
13537 @c  LocalWords:  HTML htmldir html noinst TEXINFOS nodist nobase strudel CFLAGS
13538 @c  LocalWords:  libmumble CC YFLAGS ansi knr itemx de fication config url comp
13539 @c  LocalWords:  depcomp elisp sh mdate mkinstalldirs mkdir py tex dvi ps pdf
13540 @c  LocalWords:  ylwrap zardoz INIT gettext acinclude mv FUNCS LIBOBJS LDADD fr
13541 @c  LocalWords:  uref featureful dnl src LINGUAS es ko nl pl sl sv PROG ISC doc
13542 @c  LocalWords:  POSIX STDC fcntl FUNC ALLOCA blksize struct stat intl po chmod
13543 @c  LocalWords:  ChangeLog SUBDIRS gettextize gpl testdata getopt INTLLIBS cpp
13544 @c  LocalWords:  localedir datadir DLOCALEDIR DEXIT CPPFLAGS autoreconf opindex
13545 @c  LocalWords:  AUX var symlink deps Wno Wnone package's aclocal's distclean
13546 @c  LocalWords:  ltmain xref LIBSOURCE LIBSOURCES LIBOBJ MEMCMP vs RANLIB CXX
13547 @c  LocalWords:  LDFLAGS LIBTOOL libtool XTRA LIBS gettext's acdir APIVERSION
13548 @c  LocalWords:  dirlist noindent usr MULTILIB multilib Multilibs TIOCGWINSZ sc
13549 @c  LocalWords:  GWINSZ termios SRCDIR tarball bzip LISPDIR lispdir XEmacs CCAS
13550 @c  LocalWords:  emacsen MicroEmacs CCASFLAGS UX GCJ gcj GCJFLAGS posix DMALLOC
13551 @c  LocalWords:  dmalloc ldmalloc REGEX regex rx DEPDIR DEP DEFUN aclocaldir fi
13552 @c  LocalWords:  mymacro myothermacro AMFLAGS autopoint autogen libtoolize yum
13553 @c  LocalWords:  autoheader README MAKEFLAGS subdir Inetutils sync COND endif
13554 @c  LocalWords:  Miller's installable includedir inc pkgdata EXEEXT libexec bsd
13555 @c  LocalWords:  pkglib libexecdir prog libcpio cpio's dlopen dlpreopen linux
13556 @c  LocalWords:  subsubsection OBJEXT esac lib LTLIBRARIES liblob LIBADD AR ar
13557 @c  LocalWords:  ARFLAGS cru ing maude libgettext lo LTLIBOBJS rpath SGI PRE yy
13558 @c  LocalWords:  libmaude CCLD CXXFLAGS FFLAGS LFLAGS OBJCFLAGS RFLAGS DEFS cc
13559 @c  LocalWords:  SHORTNAME vtable srcdir nostdinc basename yxx cxx ll lxx gdb
13560 @c  LocalWords:  lexers yymaxdepth maxdepth yyparse yylex yyerror yylval lval
13561 @c  LocalWords:  yychar yydebug yypact yyr yydef def yychk chk yypgo pgo yyact
13562 @c  LocalWords:  yyexca exca yyerrflag errflag yynerrs nerrs yyps yypv pv yys
13563 @c  LocalWords:  yystate yytmp tmp yyv yyval val yylloc lloc yyreds yytoks toks
13564 @c  LocalWords:  yylhs yylen yydefred yydgoto yysindex yyrindex yygindex yyname
13565 @c  LocalWords:  yytable yycheck yyrule byacc CXXCOMPILE CXXLINK FLINK cfortran
13566 @c  LocalWords:  Catalogue preprocessable FLIBS libfoo baz JAVACFLAGS java exe
13567 @c  LocalWords:  SunOS fying basenames exeext uninstalled oldinclude kr FSF's
13568 @c  LocalWords:  pkginclude oldincludedir sysconf sharedstate localstate gcc rm
13569 @c  LocalWords:  sysconfdir sharedstatedir localstatedir preexist CLEANFILES gz
13570 @c  LocalWords:  depfile tmpdepfile depmode const interoperate
13571 @c  LocalWords:  JAVAC javac JAVAROOT builddir CLASSPATH ENV pyc pyo pkgpython
13572 @c  LocalWords:  pyexecdir pkgpyexecdir Python's pythondir pkgpythondir txi ois
13573 @c  LocalWords:  installinfo vers MAKEINFO makeinfo MAKEINFOFLAGS noinstall rf
13574 @c  LocalWords:  mandir thesame alsothesame installman myexecbin DESTDIR Pinard
13575 @c  LocalWords:  uninstall installdirs uninstalls MOSTLYCLEANFILES mostlyclean
13576 @c  LocalWords:  DISTCLEANFILES MAINTAINERCLEANFILES GZIP gzip shar exp
13577 @c  LocalWords:  distdir distcheck distcleancheck listfiles distuninstallcheck
13578 @c  LocalWords:  VPATH tarfile stdout XFAIL DejaGnu dejagnu DEJATOOL runtest ln
13579 @c  LocalWords:  RUNTESTDEFAULTFLAGS toolchain RUNTESTFLAGS asis readme DVIPS
13580 @c  LocalWords:  installcheck gzipped tarZ std utils etags mkid multilibbing cd
13581 @c  LocalWords:  ARGS taggable ETAGSFLAGS lang ctags CTAGSFLAGS GTAGS gtags idl
13582 @c  LocalWords:  foocc doit idlC multilibs ABIs cmindex defmac ARG enableval FC
13583 @c  LocalWords:  MSG xtrue DBG pathchk CYGWIN afile proglink versioned CVS's TE
13584 @c  LocalWords:  wildcards Autoconfiscated subsubheading autotools Meyering API
13585 @c  LocalWords:  ois's wildcard Wportability cartouche vrindex printindex Duret
13586 @c  LocalWords:  DSOMEFLAG DVERSION automake Lutz insertcopying versioning FAQ
13587 @c  LocalWords:  LTLIBOBJ Libtool's libtool's libltdl dlopening itutions libbar
13588 @c  LocalWords:  WANTEDLIBS libhello sublibraries libtop libsub dlopened Ratfor
13589 @c  LocalWords:  mymodule timestamps timestamp underquoted MAKEINFOHTMLFLAGS te
13590 @c  LocalWords:  GNUmakefile Subpackages subpackage's subpackages aux
13591 @c  LocalWords:  detailmenu Timeline pwd reldir AUTOM autom PREREQ FOOBAR libc
13592 @c  LocalWords:  libhand subpackage moduleN libmain libmisc FCFLAGS FCCOMPILE
13593 @c  LocalWords:  FCLINK subst sed ELCFILES elc MAKEINFOHTML dvips esyscmd ustar
13594 @c  LocalWords:  tarballs Woverride vfi ELFILES djm AutoMake honkin FSF
13595 @c  LocalWords:  fileutils precanned MacKenzie's reimplement termutils Tromey's
13596 @c  LocalWords:  cois gnitsians LIBPROGRAMS progs LIBLIBRARIES Textutils Ulrich
13597 @c  LocalWords:  Matzigkeit Drepper's Gord Matzigkeit's jm Dalley Debian org
13598 @c  LocalWords:  Administrivia ILU CORBA Sourceware Molenda sourceware Elliston
13599 @c  LocalWords:  dep Oliva Akim Demaille Aiieeee Demaillator Akim's sourcequake
13600 @c  LocalWords:  grep backported screenshots libgcj KB unnumberedsubsubsec pre
13601 @c  LocalWords:  precomputing hacky makedepend inline clearmake LD PRELOAD Rel
13602 @c  LocalWords:  syscalls perlhist acl pm multitable headitem fdl appendixsec
13603 @c  LocalWords:  LTALLOCA MALLOC malloc memcmp strdup alloca libcompat xyz DFOO
13604 @c  LocalWords:  unprefixed buildable preprocessed DBAZ DDATADIR WARNINGCFLAGS
13605 @c  LocalWords:  LIBFOOCFLAGS LIBFOOLDFLAGS ftable testSubDir obj LIBTOOLFLAGS
13606 @c  LocalWords:  barexec Pinard's automatize initialize lzip lzma xz