Merge branch 'maint' into yacc-work
[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 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 @c info Automake  points to the Automake package's documentation
42 @c info automake  points to the automake script's documentation
43 @c (Autoconf has a similar setup.)
44 @dircategory Software development
45 @direntry
46 * Automake: (automake).         Making GNU standards-compliant Makefiles.
47 @end direntry
48
49 @dircategory Individual utilities
50 @direntry
51 * aclocal: (automake)Invoking aclocal.          Generating aclocal.m4.
52 * automake: (automake)Invoking Automake.        Generating Makefile.in.
53 @end direntry
54
55 @titlepage
56 @title GNU Automake
57 @subtitle For version @value{VERSION}, @value{UPDATED}
58 @author David MacKenzie
59 @author Tom Tromey
60 @author Alexandre Duret-Lutz
61 @page
62 @vskip 0pt plus 1filll
63 @insertcopying
64 @end titlepage
65
66 @contents
67
68 @c We use the following macros to define indices:
69 @c   @cindex   concepts, and anything that does not fit elsewhere
70 @c   @vindex   Makefile variables
71 @c   @trindex  targets
72 @c   @acindex  Autoconf/Automake/Libtool/M4/... macros
73 @c   @opindex  tool options
74
75 @c Define an index of configure macros.
76 @defcodeindex ac
77 @c Define an index of options.
78 @defcodeindex op
79 @c Define an index of targets.
80 @defcodeindex tr
81 @c Define an index of commands.
82 @defcodeindex cm
83
84 @c Put the macros in the function index.
85 @syncodeindex ac fn
86
87 @c Put everything else into one index (arbitrarily chosen to be the
88 @c concept index).
89 @syncodeindex op cp
90 @syncodeindex tr cp
91 @syncodeindex cm cp
92
93 @ifnottex
94 @node Top
95 @comment  node-name,  next,  previous,  up
96 @top GNU Automake
97
98 @insertcopying
99
100 @menu
101 * Introduction::                Automake's purpose
102 * Autotools Introduction::      An Introduction to the Autotools
103 * Generalities::                General ideas
104 * Examples::                    Some example packages
105 * Invoking Automake::           Creating a Makefile.in
106 * configure::                   Scanning configure.ac, using aclocal
107 * Directories::                 Declaring subdirectories
108 * Programs::                    Building programs and libraries
109 * Other Objects::               Other derived objects
110 * Other GNU Tools::             Other GNU Tools
111 * Documentation::               Building documentation
112 * Install::                     What gets installed
113 * Clean::                       What gets cleaned
114 * Dist::                        What goes in a distribution
115 * Tests::                       Support for test suites
116 * Rebuilding::                  Automatic rebuilding of Makefile
117 * Options::                     Changing Automake's behavior
118 * Miscellaneous::               Miscellaneous rules
119 * Include::                     Including extra files in an Automake template
120 * Conditionals::                Conditionals
121 * Silencing Make::              Obtain less verbose output from @command{make}
122 * Gnits::                       The effect of @option{--gnu} and @option{--gnits}
123 * Cygnus::                      The effect of @option{--cygnus}
124 * Not Enough::                  When Automake is not Enough
125 * Distributing::                Distributing the Makefile.in
126 * API Versioning::              About compatibility between Automake versions
127 * Upgrading::                   Upgrading to a Newer Automake Version
128 * FAQ::                         Frequently Asked Questions
129 * History::                     Notes about the history of Automake
130 * Copying This Manual::         How to make copies of this manual
131 * Indices::                     Indices of variables, macros, and concepts
132
133 @detailmenu
134  --- The Detailed Node Listing ---
135
136 An Introduction to the Autotools
137
138 * GNU Build System::            Introducing the GNU Build System
139 * Use Cases::                   Use Cases for the GNU Build System
140 * Why Autotools::               How Autotools Help
141 * Hello World::                 A Small Hello World Package
142
143 Use Cases for the GNU Build System
144
145 * Basic Installation::          Common installation procedure
146 * Standard Targets::            A list of standard Makefile targets
147 * Standard Directory Variables::  A list of standard directory variables
148 * Standard Configuration Variables::  Using configuration variables
149 * config.site::                 Using a config.site file
150 * VPATH Builds::                Parallel build trees
151 * Two-Part Install::            Installing data and programs separately
152 * Cross-Compilation::           Building for other architectures
153 * Renaming::                    Renaming programs at install time
154 * DESTDIR::                     Building binary packages with DESTDIR
155 * Preparing Distributions::     Rolling out tarballs
156 * Dependency Tracking::         Automatic dependency tracking
157 * Nested Packages::             The GNU Build Systems can be nested
158
159 A Small Hello World
160
161 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
162 * amhello's configure.ac Setup Explained::
163 * amhello's Makefile.am Setup Explained::
164
165 General ideas
166
167 * General Operation::           General operation of Automake
168 * Strictness::                  Standards conformance checking
169 * Uniform::                     The Uniform Naming Scheme
170 * Length Limitations::          Staying below the command line length limit
171 * Canonicalization::            How derived variables are named
172 * User Variables::              Variables reserved for the user
173 * Auxiliary Programs::          Programs automake might require
174
175 Some example packages
176
177 * Complete::                    A simple example, start to finish
178 * true::                        Building true and false
179
180 Scanning @file{configure.ac}, using @command{aclocal}
181
182 * Requirements::                Configuration requirements
183 * Optional::                    Other things Automake recognizes
184 * Invoking aclocal::            Auto-generating aclocal.m4
185 * Macros::                      Autoconf macros supplied with Automake
186
187 Auto-generating aclocal.m4
188
189 * aclocal Options::             Options supported by aclocal
190 * Macro Search Path::           How aclocal finds .m4 files
191 * Extending aclocal::           Writing your own aclocal macros
192 * Local Macros::                Organizing local macros
193 * Serials::                     Serial lines in Autoconf macros
194 * Future of aclocal::           aclocal's scheduled death
195
196 Autoconf macros supplied with Automake
197
198 * Public Macros::               Macros that you can use.
199 * Obsolete Macros::             Macros that you should stop using.
200 * Private Macros::              Macros that you should not use.
201
202 Directories
203
204 * Subdirectories::              Building subdirectories recursively
205 * Conditional Subdirectories::  Conditionally not building directories
206 * Alternative::                 Subdirectories without recursion
207 * Subpackages::                 Nesting packages
208
209 Conditional Subdirectories
210
211 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
212 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
213 * Subdirectories with AC_SUBST::  Another way for conditional recursion
214 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
215
216 Building Programs and Libraries
217
218 * A Program::                   Building a program
219 * A Library::                   Building a library
220 * A Shared Library::            Building a Libtool library
221 * Program and Library Variables::  Variables controlling program and
222                                 library builds
223 * Default _SOURCES::            Default source files
224 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
225 * Program Variables::           Variables used when building a program
226 * Yacc and Lex::                Yacc and Lex support
227 * C++ Support::                 Compiling C++ sources
228 * Objective C Support::         Compiling Objective C sources
229 * Unified Parallel C Support::  Compiling Unified Parallel C sources
230 * Assembly Support::            Compiling assembly sources
231 * Fortran 77 Support::          Compiling Fortran 77 sources
232 * Fortran 9x Support::          Compiling Fortran 9x sources
233 * Java Support::                Compiling Java sources
234 * Vala Support::                Compiling Vala sources
235 * Support for Other Languages::  Compiling other languages
236 * ANSI::                        Automatic de-ANSI-fication (deprecated, soon to be removed)
237 * Dependencies::                Automatic dependency tracking
238 * EXEEXT::                      Support for executable extensions
239
240 Building a program
241
242 * Program Sources::             Defining program sources
243 * Linking::                     Linking with libraries or extra objects
244 * Conditional Sources::         Handling conditional sources
245 * Conditional Programs::        Building a program conditionally
246
247 Building a Shared Library
248
249 * Libtool Concept::             Introducing Libtool
250 * Libtool Libraries::           Declaring Libtool Libraries
251 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
252 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
253 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
254 * Libtool Modules::             Building Libtool Modules
255 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
256 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
257 * Libtool Issues::              Common Issues Related to Libtool's Use
258
259 Common Issues Related to Libtool's Use
260
261 * Error required file ltmain.sh not found::  The need to run libtoolize
262 * Objects created both with libtool and without::  Avoid a specific build race
263
264 Fortran 77 Support
265
266 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
267 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
268 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
269
270 Mixing Fortran 77 With C and C++
271
272 * How the Linker is Chosen::    Automatic linker selection
273
274 Fortran 9x Support
275
276 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
277
278 Other Derived Objects
279
280 * Scripts::                     Executable scripts
281 * Headers::                     Header files
282 * Data::                        Architecture-independent data files
283 * Sources::                     Derived sources
284
285 Built Sources
286
287 * Built Sources Example::       Several ways to handle built sources.
288
289 Other GNU Tools
290
291 * Emacs Lisp::                  Emacs Lisp
292 * gettext::                     Gettext
293 * Libtool::                     Libtool
294 * Java::                        Java
295 * Python::                      Python
296
297 Building documentation
298
299 * Texinfo::                     Texinfo
300 * Man Pages::                   Man pages
301
302 What Gets Installed
303
304 * Basics of Installation::      What gets installed where
305 * The Two Parts of Install::    Installing data and programs separately
306 * Extending Installation::      Adding your own rules for installation
307 * Staged Installs::             Installation in a temporary location
308 * Install Rules for the User::  Useful additional rules
309
310 What Goes in a Distribution
311
312 * Basics of Distribution::      Files distributed by default
313 * Fine-grained Distribution Control::  @code{dist_} and @code{nodist_} prefixes
314 * The dist Hook::               A target for last-minute distribution changes
315 * Checking the Distribution::   @samp{make distcheck} explained
316 * The Types of Distributions::  A variety of formats and compression methods
317
318 Support for test suites
319
320 * Simple Tests::                Listing programs and scripts in @code{TESTS}
321 * Simple Tests using parallel-tests::  More powerful test driver
322 * DejaGnu Tests::               Interfacing with the external testing framework
323 * Install Tests::               Running tests on installed packages
324
325 Miscellaneous Rules
326
327 * Tags::                        Interfacing to etags and mkid
328 * Suffixes::                    Handling new file extensions
329 * Multilibs::                   Support for multilibs.
330
331 Conditionals
332
333 * Usage of Conditionals::       Declaring conditional content
334 * Limits of Conditionals::      Enclosing complete statements
335
336 Silencing Make
337
338 * Make verbosity::               Make is verbose by default
339 * Tricks For Silencing Make::    Standard and generic ways to silence make
340 * Automake silent-rules Option:: How Automake can help in silencing make
341
342 When Automake Isn't Enough
343
344 * Extending::                   Adding new rules or overriding existing ones.
345 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
346
347 Frequently Asked Questions about Automake
348
349 * CVS::                         CVS and generated files
350 * maintainer-mode::             missing and AM_MAINTAINER_MODE
351 * Wildcards::                   Why doesn't Automake support wildcards?
352 * Limitations on File Names::   Limitations on source and installed file names
353 * distcleancheck::              Files left in build directory after distclean
354 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
355 * Renamed Objects::             Why are object files sometimes renamed?
356 * Per-Object Flags::            How to simulate per-object flags?
357 * Multiple Outputs::            Writing rules for tools with many output files
358 * Hard-Coded Install Paths::    Installing to hard-coded locations
359 * Debugging Make Rules::        Strategies when things don't work as expected
360 * Reporting Bugs::              Feedback on bugs and feature requests
361
362 History of Automake
363
364 * Timeline::                    The Automake story.
365 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
366 * Releases::                    Statistics about Automake Releases
367
368 Dependency Tracking in Automake
369
370 * First Take on Dependencies::  Precomputed dependency tracking
371 * Dependencies As Side Effects::  Update at developer compile time
372 * Dependencies for the User::   Update at user compile time
373 * Techniques for Dependencies::  Alternative approaches
374 * Recommendations for Tool Writers::  What tool writers can do to help
375 * Future Directions for Dependencies::  Languages Automake does not know
376
377 Copying This Manual
378
379 * GNU Free Documentation License::  License for copying this manual
380
381 Indices
382
383 * Macro Index::                 Index of Autoconf macros
384 * Variable Index::              Index of Makefile variables
385 * General Index::               General index
386
387 @end detailmenu
388 @end menu
389
390 @end ifnottex
391
392
393 @node Introduction
394 @chapter Introduction
395
396 Automake is a tool for automatically generating @file{Makefile.in}s
397 from files called @file{Makefile.am}.  Each @file{Makefile.am} is
398 basically a series of @command{make} variable
399 definitions@footnote{These variables are also called @dfn{make macros}
400 in Make terminology, however in this manual we reserve the term
401 @dfn{macro} for Autoconf's macros.}, with rules being thrown in
402 occasionally.  The generated @file{Makefile.in}s are compliant with
403 the GNU Makefile standards.
404
405 @cindex GNU Makefile standards
406
407 The GNU Makefile Standards Document
408 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
409 is long, complicated, and subject to change.  The goal of Automake is to
410 remove the burden of Makefile maintenance from the back of the
411 individual GNU maintainer (and put it on the back of the Automake
412 maintainers).
413
414 The typical Automake input file is simply a series of variable definitions.
415 Each such file is processed to create a @file{Makefile.in}.  There
416 should generally be one @file{Makefile.am} per directory of a project.
417
418 @cindex Constraints of Automake
419 @cindex Automake constraints
420
421 Automake does constrain a project in certain ways; for instance, it
422 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
423 autoconf, The Autoconf Manual}), and enforces certain restrictions on
424 the @file{configure.ac} contents@footnote{Older Autoconf versions used
425 @file{configure.in}.  Autoconf 2.50 and greater promotes
426 @file{configure.ac} over @file{configure.in}.  The rest of this
427 documentation will refer to @file{configure.ac}, but Automake also
428 supports @file{configure.in} for backward compatibility.}.
429
430 @cindex Automake requirements
431 @cindex Requirements, Automake
432
433 Automake requires @command{perl} in order to generate the
434 @file{Makefile.in}s.  However, the distributions created by Automake are
435 fully GNU standards-compliant, and do not require @command{perl} in order
436 to be built.
437
438 @cindex Bugs, reporting
439 @cindex Reporting bugs
440 @cindex E-mail, bug reports
441
442 For more information on bug reports, @xref{Reporting Bugs}.
443
444 @node Autotools Introduction
445 @chapter An Introduction to the Autotools
446
447 If you are new to Automake, maybe you know that it is part of a set of
448 tools called @emph{The Autotools}.  Maybe you've already delved into a
449 package full of files named @file{configure}, @file{configure.ac},
450 @file{Makefile.in}, @file{Makefile.am}, @file{aclocal.m4}, @dots{},
451 some of them claiming to be @emph{generated by} Autoconf or Automake.
452 But the exact purpose of these files and their relations is probably
453 fuzzy.  The goal of this chapter is to introduce you to this machinery,
454 to show you how it works and how powerful it is.  If you've never
455 installed or seen such a package, do not worry: this chapter will walk
456 you through it.
457
458 If you need some teaching material, more illustrations, or a less
459 @command{automake}-centered continuation, some slides for this
460 introduction are available in Alexandre Duret-Lutz's
461 @uref{http://www.lrde.epita.fr/@/~adl/@/autotools.html,
462 Autotools Tutorial}.
463 This chapter is the written version of the first part of his tutorial.
464
465 @menu
466 * GNU Build System::            Introducing the GNU Build System
467 * Use Cases::                   Use Cases for the GNU Build System
468 * Why Autotools::               How Autotools Help
469 * Hello World::                 A Small Hello World Package
470 @end menu
471
472 @node GNU Build System
473 @section Introducing the GNU Build System
474 @cindex GNU Build System, introduction
475
476 It is a truth universally acknowledged, that as a developer in
477 possession of a new package, you must be in want of a build system.
478
479 In the Unix world, such a build system is traditionally achieved using
480 the command @command{make} (@pxref{Top, , Overview, make, The GNU Make
481 Manual}).  You express the recipe to build your package in a
482 @file{Makefile}.  This file is a set of rules to build the files in
483 the package.  For instance the program @file{prog} may be built by
484 running the linker on the files @file{main.o}, @file{foo.o}, and
485 @file{bar.o}; the file @file{main.o} may be built by running the
486 compiler on @file{main.c}; etc.  Each time @command{make} is run, it
487 reads @file{Makefile}, checks the existence and modification time of
488 the files mentioned, decides what files need to be built (or rebuilt),
489 and runs the associated commands.
490
491 When a package needs to be built on a different platform than the one
492 it was developed on, its @file{Makefile} usually needs to be adjusted.
493 For instance the compiler may have another name or require more
494 options.  In 1991, David J. MacKenzie got tired of customizing
495 @file{Makefile} for the 20 platforms he had to deal with.  Instead, he
496 handcrafted a little shell script called @file{configure} to
497 automatically adjust the @file{Makefile} (@pxref{Genesis, , Genesis,
498 autoconf, The Autoconf Manual}).  Compiling his package was now
499 as simple as running @code{./configure && make}.
500
501 @cindex GNU Coding Standards
502
503 Today this process has been standardized in the GNU project.  The GNU
504 Coding Standards (@pxref{Managing Releases, The Release Process, ,
505 standards, The GNU Coding Standards}) explains how each package of the
506 GNU project should have a @file{configure} script, and the minimal
507 interface it should have.  The @file{Makefile} too should follow some
508 established conventions.  The result?  A unified build system that
509 makes all packages almost indistinguishable by the installer.  In its
510 simplest scenario, all the installer has to do is to unpack the
511 package, run @code{./configure && make && make install}, and repeat
512 with the next package to install.
513
514 We call this build system the @dfn{GNU Build System}, since it was
515 grown out of the GNU project.  However it is used by a vast number of
516 other packages: following any existing convention has its advantages.
517
518 @cindex Autotools, introduction
519
520 The Autotools are tools that will create a GNU Build System for your
521 package.  Autoconf mostly focuses on @file{configure} and Automake on
522 @file{Makefile}s.  It is entirely possible to create a GNU Build
523 System without the help of these tools.  However it is rather
524 burdensome and error-prone.  We will discuss this again after some
525 illustration of the GNU Build System in action.
526
527 @node Use Cases
528 @section Use Cases for the GNU Build System
529 @cindex GNU Build System, use cases
530 @cindex GNU Build System, features
531 @cindex Features of the GNU Build System
532 @cindex Use Cases for the GNU Build System
533 @cindex @file{amhello-1.0.tar.gz}, location
534 @cindex @file{amhello-1.0.tar.gz}, use cases
535
536 In this section we explore several use cases for the GNU Build System.
537 You can replay all these examples on the @file{amhello-1.0.tar.gz}
538 package distributed with Automake.  If Automake is installed on your
539 system, you should find a copy of this file in
540 @file{@var{prefix}/share/doc/automake/amhello-1.0.tar.gz}, where
541 @var{prefix} is the installation prefix specified during configuration
542 (@var{prefix} defaults to @file{/usr/local}, however if Automake was
543 installed by some GNU/Linux distribution it most likely has been set
544 to @file{/usr}).  If you do not have a copy of Automake installed,
545 you can find a copy of this file inside the @file{doc/} directory of
546 the Automake package.
547
548 Some of the following use cases present features that are in fact
549 extensions to the GNU Build System.  Read: they are not specified by
550 the GNU Coding Standards, but they are nonetheless part of the build
551 system created by the Autotools.  To keep things simple, we do not
552 point out the difference.  Our objective is to show you many of the
553 features that the build system created by the Autotools will offer to
554 you.
555
556 @menu
557 * Basic Installation::          Common installation procedure
558 * Standard Targets::            A list of standard Makefile targets
559 * Standard Directory Variables::  A list of standard directory variables
560 * Standard Configuration Variables::  Using configuration variables
561 * config.site::                 Using a config.site file
562 * VPATH Builds::                Parallel build trees
563 * Two-Part Install::            Installing data and programs separately
564 * Cross-Compilation::           Building for other architectures
565 * Renaming::                    Renaming programs at install time
566 * DESTDIR::                     Building binary packages with DESTDIR
567 * Preparing Distributions::     Rolling out tarballs
568 * Dependency Tracking::         Automatic dependency tracking
569 * Nested Packages::             The GNU Build Systems can be nested
570 @end menu
571
572 @node Basic Installation
573 @subsection Basic Installation
574 @cindex Configuration, basics
575 @cindex Installation, basics
576 @cindex GNU Build System, basics
577
578 The most common installation procedure looks as follows.
579
580 @example
581 ~ % @kbd{tar zxf amhello-1.0.tar.gz}
582 ~ % @kbd{cd amhello-1.0}
583 ~/amhello-1.0 % @kbd{./configure}
584 @dots{}
585 config.status: creating Makefile
586 config.status: creating src/Makefile
587 @dots{}
588 ~/amhello-1.0 % @kbd{make}
589 @dots{}
590 ~/amhello-1.0 % @kbd{make check}
591 @dots{}
592 ~/amhello-1.0 % @kbd{su}
593 Password:
594 /home/adl/amhello-1.0 # @kbd{make install}
595 @dots{}
596 /home/adl/amhello-1.0 # @kbd{exit}
597 ~/amhello-1.0 % @kbd{make installcheck}
598 @dots{}
599 @end example
600
601 @cindex Unpacking
602
603 The user first unpacks the package.  Here, and in the following
604 examples, we will use the non-portable @code{tar zxf} command for
605 simplicity.  On a system without GNU @command{tar} installed, this
606 command should read @code{gunzip -c amhello-1.0.tar.gz | tar xf -}.
607
608 The user then enters the newly created directory to run the
609 @file{configure} script.  This script probes the system for various
610 features, and finally creates the @file{Makefile}s.  In this toy
611 example there are only two @file{Makefile}s, but in real-world projects,
612 there may be many more, usually one @file{Makefile} per directory.
613
614 It is now possible to run @code{make}.  This will construct all the
615 programs, libraries, and scripts that need to be constructed for the
616 package.  In our example, this compiles the @file{hello} program.
617 All files are constructed in place, in the source tree; we will see
618 later how this can be changed.
619
620 @code{make check} causes the package's tests to be run.  This step is
621 not mandatory, but it is often good to make sure the programs that
622 have been built behave as they should, before you decide to install
623 them.  Our example does not contain any tests, so running @code{make
624 check} is a no-op.
625
626 @cindex su, before @code{make install}
627 After everything has been built, and maybe tested, it is time to
628 install it on the system.  That means copying the programs,
629 libraries, header files, scripts, and other data files from the
630 source directory to their final destination on the system.  The
631 command @code{make install} will do that.  However, by default
632 everything will be installed in subdirectories of @file{/usr/local}:
633 binaries will go into @file{/usr/local/bin}, libraries will end up in
634 @file{/usr/local/lib}, etc.  This destination is usually not writable
635 by any user, so we assume that we have to become root before we can
636 run @code{make install}.  In our example, running @code{make install}
637 will copy the program @file{hello} into @file{/usr/local/bin}
638 and @file{README} into @file{/usr/local/share/doc/amhello}.
639
640 A last and optional step is to run @code{make installcheck}.  This
641 command may run tests on the installed files.  @code{make check} tests
642 the files in the source tree, while @code{make installcheck} tests
643 their installed copies.  The tests run by the latter can be different
644 from those run by the former.  For instance, there are tests that
645 cannot be run in the source tree.  Conversely, some packages are set
646 up so that @code{make installcheck} will run the very same tests as
647 @code{make check}, only on different files (non-installed
648 vs.@: installed).  It can make a difference, for instance when the
649 source tree's layout is different from that of the installation.
650 Furthermore it may help to diagnose an incomplete installation.
651
652 Presently most packages do not have any @code{installcheck} tests
653 because the existence of @code{installcheck} is little known, and its
654 usefulness is neglected.  Our little toy package is no better: @code{make
655 installcheck} does nothing.
656
657 @node Standard Targets
658 @subsection Standard @file{Makefile} Targets
659
660 So far we have come across four ways to run @command{make} in the GNU
661 Build System: @code{make}, @code{make check}, @code{make install}, and
662 @code{make installcheck}.  The words @code{check}, @code{install}, and
663 @code{installcheck}, passed as arguments to @command{make}, are called
664 @dfn{targets}.  @code{make} is a shorthand for @code{make all},
665 @code{all} being the default target in the GNU Build System.
666
667 Here is a list of the most useful targets that the GNU Coding Standards
668 specify.
669
670 @table @code
671 @item make all
672 @trindex all
673 Build programs, libraries, documentation, etc.@: (same as @code{make}).
674 @item make install
675 @trindex install
676 Install what needs to be installed, copying the files from the
677 package's tree to system-wide directories.
678 @item make install-strip
679 @trindex install-strip
680 Same as @code{make install}, then strip debugging symbols.  Some
681 users like to trade space for useful bug reports@enddots{}
682 @item make uninstall
683 @trindex uninstall
684 The opposite of @code{make install}: erase the installed files.
685 (This needs to be run from the same build tree that was installed.)
686 @item make clean
687 @trindex clean
688 Erase from the build tree the files built by @code{make all}.
689 @item make distclean
690 @trindex distclean
691 Additionally erase anything @code{./configure} created.
692 @item make check
693 @trindex check
694 Run the test suite, if any.
695 @item make installcheck
696 @trindex installcheck
697 Check the installed programs or libraries, if supported.
698 @item make dist
699 @trindex dist
700 Recreate @file{@var{package}-@var{version}.tar.gz} from all the source
701 files.
702 @end table
703
704 @node Standard Directory Variables
705 @subsection Standard Directory Variables
706 @cindex directory variables
707
708 The GNU Coding Standards also specify a hierarchy of variables to
709 denote installation directories.  Some of these are:
710
711 @multitable {Directory variable} {@code{$@{datarootdir@}/doc/$@{PACKAGE@}}}
712 @headitem Directory variable    @tab Default value
713 @item @code{prefix}              @tab @code{/usr/local}
714 @item @w{@ @ @code{exec_prefix}} @tab @code{$@{prefix@}}
715 @item @w{@ @ @ @ @code{bindir}}  @tab @code{$@{exec_prefix@}/bin}
716 @item @w{@ @ @ @ @code{libdir}}  @tab @code{$@{exec_prefix@}/lib}
717 @item @w{@ @ @ @ @dots{}}
718 @item @w{@ @ @code{includedir}}  @tab @code{$@{prefix@}/include}
719 @item @w{@ @ @code{datarootdir}} @tab @code{$@{prefix@}/share}
720 @item @w{@ @ @ @ @code{datadir}} @tab @code{$@{datarootdir@}}
721 @item @w{@ @ @ @ @code{mandir}}  @tab @code{$@{datarootdir@}/man}
722 @item @w{@ @ @ @ @code{infodir}} @tab @code{$@{datarootdir@}/info}
723 @item @w{@ @ @ @ @code{docdir}}  @tab @code{$@{datarootdir@}/doc/$@{PACKAGE@}}
724 @item @w{@ @ @dots{}}
725 @end multitable
726
727 @c We should provide a complete table somewhere, but not here.  The
728 @c complete list of directory variables it too confusing as-is.  It
729 @c requires some explanations that are too complicated for this
730 @c introduction.  Besides listing directories like localstatedir
731 @c would make the explanations in ``Two-Part Install'' harder.
732
733 Each of these directories has a role which is often obvious from its
734 name.  In a package, any installable file will be installed in one of
735 these directories.  For instance in @code{amhello-1.0}, the program
736 @file{hello} is to be installed in @var{bindir}, the directory for
737 binaries.  The default value for this directory is
738 @file{/usr/local/bin}, but the user can supply a different value when
739 calling @command{configure}.  Also the file @file{README} will be
740 installed into @var{docdir}, which defaults to
741 @file{/usr/local/share/doc/amhello}.
742
743 @opindex --prefix
744
745 As a user, if you wish to install a package on your own account, you
746 could proceed as follows:
747
748 @example
749 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
750 @dots{}
751 ~/amhello-1.0 % @kbd{make}
752 @dots{}
753 ~/amhello-1.0 % @kbd{make install}
754 @dots{}
755 @end example
756
757 This would install @file{~/usr/bin/hello} and
758 @file{~/usr/share/doc/amhello/README}.
759
760 The list of all such directory options is shown by
761 @code{./configure --help}.
762
763 @node Standard Configuration Variables
764 @subsection Standard Configuration Variables
765 @cindex configuration variables, overriding
766
767 The GNU Coding Standards also define a set of standard configuration
768 variables used during the build.  Here are some:
769
770 @table @asis
771 @item @code{CC}
772 C compiler command
773 @item @code{CFLAGS}
774 C compiler flags
775 @item @code{CXX}
776 C++ compiler command
777 @item @code{CXXFLAGS}
778 C++ compiler flags
779 @item @code{LDFLAGS}
780 linker flags
781 @item @code{CPPFLAGS}
782 C/C++ preprocessor flags
783 @item @dots{}
784 @end table
785
786 @command{configure} usually does a good job at setting appropriate
787 values for these variables, but there are cases where you may want to
788 override them.  For instance you may have several versions of a
789 compiler installed and would like to use another one, you may have
790 header files installed outside the default search path of the
791 compiler, or even libraries out of the way of the linker.
792
793 Here is how one would call @command{configure} to force it to use
794 @command{gcc-3} as C compiler, use header files from
795 @file{~/usr/include} when compiling, and libraries from
796 @file{~/usr/lib} when linking.
797
798 @example
799 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
800 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
801 @end example
802
803 Again, a full list of these variables appears in the output of
804 @code{./configure --help}.
805
806 @node config.site
807 @subsection Overriding Default Configuration Setting with @file{config.site}
808 @cindex @file{config.site} example
809
810 When installing several packages using the same setup, it can be
811 convenient to create a file to capture common settings.
812 If a file named @file{@var{prefix}/share/config.site} exists,
813 @command{configure} will source it at the beginning of its execution.
814
815 Recall the command from the previous section:
816
817 @example
818 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
819 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
820 @end example
821
822 Assuming we are installing many package in @file{~/usr}, and will
823 always want to use these definitions of @code{CC}, @code{CPPFLAGS}, and
824 @code{LDFLAGS}, we can automate this by creating the following
825 @file{~/usr/share/config.site} file:
826
827 @example
828 test -z "$CC" && CC=gcc-3
829 test -z "$CPPFLAGS" && CPPFLAGS=-I$HOME/usr/include
830 test -z "$LDFLAGS" && LDFLAGS=-L$HOME/usr/lib
831 @end example
832
833 Now, any time a @file{configure} script is using the @file{~/usr}
834 prefix, it will execute the above @file{config.site} and define
835 these three variables.
836
837 @example
838 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
839 configure: loading site script /home/adl/usr/share/config.site
840 @dots{}
841 @end example
842
843 @xref{Site Defaults, , Setting Site Defaults, autoconf, The Autoconf
844 Manual}, for more information about this feature.
845
846
847 @node VPATH Builds
848 @subsection Parallel Build Trees (a.k.a.@: VPATH Builds)
849 @cindex Parallel build trees
850 @cindex VPATH builds
851 @cindex source tree and build tree
852 @cindex build tree and source tree
853 @cindex trees, source vs.@: build
854
855 The GNU Build System distinguishes two trees: the source tree, and
856 the build tree.
857
858 The source tree is rooted in the directory containing
859 @file{configure}.  It contains all the sources files (those that are
860 distributed), and may be arranged using several subdirectories.
861
862 The build tree is rooted in the directory in which @file{configure}
863 was run, and is populated with all object files, programs, libraries,
864 and other derived files built from the sources (and hence not
865 distributed).  The build tree usually has the same subdirectory layout
866 as the source tree; its subdirectories are created automatically by
867 the build system.
868
869 If @file{configure} is executed in its own directory, the source and
870 build trees are combined: derived files are constructed in the same
871 directories as their sources.  This was the case in our first
872 installation example (@pxref{Basic Installation}).
873
874 A common request from users is that they want to confine all derived
875 files to a single directory, to keep their source directories
876 uncluttered.  Here is how we could run @file{configure} to build
877 everything in a subdirectory called @file{build/}.
878
879 @example
880 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
881 ~ % @kbd{cd amhello-1.0}
882 ~/amhello-1.0 % @kbd{mkdir build && cd build}
883 ~/amhello-1.0/build % @kbd{../configure}
884 @dots{}
885 ~/amhello-1.0/build % @kbd{make}
886 @dots{}
887 @end example
888
889 These setups, where source and build trees are different, are often
890 called @dfn{parallel builds} or @dfn{VPATH builds}.  The expression
891 @emph{parallel build} is misleading: the word @emph{parallel} is a
892 reference to the way the build tree shadows the source tree, it is not
893 about some concurrency in the way build commands are run.  For this
894 reason we refer to such setups using the name @emph{VPATH builds} in
895 the following.  @emph{VPATH} is the name of the @command{make} feature
896 used by the @file{Makefile}s to allow these builds (@pxref{General
897 Search, , @code{VPATH}: Search Path for All Prerequisites, make, The
898 GNU Make Manual}).
899
900 @cindex multiple configurations, example
901 @cindex debug build, example
902 @cindex optimized build, example
903
904 VPATH builds have other interesting uses.  One is to build the same
905 sources with multiple configurations.  For instance:
906
907 @c Keep in sync with amhello-cflags.test.
908 @example
909 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
910 ~ % @kbd{cd amhello-1.0}
911 ~/amhello-1.0 % @kbd{mkdir debug optim && cd debug}
912 ~/amhello-1.0/debug % @kbd{../configure CFLAGS='-g -O0'}
913 @dots{}
914 ~/amhello-1.0/debug % @kbd{make}
915 @dots{}
916 ~/amhello-1.0/debug % cd ../optim
917 ~/amhello-1.0/optim % @kbd{../configure CFLAGS='-O3 -fomit-frame-pointer'}
918 @dots{}
919 ~/amhello-1.0/optim % @kbd{make}
920 @dots{}
921 @end example
922
923 With network file systems, a similar approach can be used to build the
924 same sources on different machines.  For instance, suppose that the
925 sources are installed on a directory shared by two hosts: @code{HOST1}
926 and @code{HOST2}, which may be different platforms.
927
928 @example
929 ~ % @kbd{cd /nfs/src}
930 /nfs/src % @kbd{tar zxf ~/amhello-1.0.tar.gz}
931 @end example
932
933 On the first host, you could create a local build directory:
934 @example
935 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
936 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
937 ...
938 [HOST1] /tmp/amh % @kbd{make && sudo make install}
939 ...
940 @end example
941
942 @noindent
943 (Here we assume that the installer has configured @command{sudo} so it
944 can execute @code{make install} with root privileges; it is more convenient
945 than using @command{su} like in @ref{Basic Installation}).
946
947 On the second host, you would do exactly the same, possibly at
948 the same time:
949 @example
950 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
951 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
952 ...
953 [HOST2] /tmp/amh % @kbd{make && sudo make install}
954 ...
955 @end example
956
957 @cindex read-only source tree
958 @cindex source tree, read-only
959
960 In this scenario, nothing forbids the @file{/nfs/src/amhello-1.0}
961 directory from being read-only.  In fact VPATH builds are also a means
962 of building packages from a read-only medium such as a CD-ROM.  (The
963 FSF used to sell CD-ROM with unpacked source code, before the GNU
964 project grew so big.)
965
966 @node Two-Part Install
967 @subsection Two-Part Installation
968
969 In our last example (@pxref{VPATH Builds}), a source tree was shared
970 by two hosts, but compilation and installation were done separately on
971 each host.
972
973 The GNU Build System also supports networked setups where part of the
974 installed files should be shared amongst multiple hosts.  It does so
975 by distinguishing architecture-dependent files from
976 architecture-independent files, and providing two @file{Makefile}
977 targets to install each of these classes of files.
978
979 @trindex install-exec
980 @trindex install-data
981
982 These targets are @code{install-exec} for architecture-dependent files
983 and @code{install-data} for architecture-independent files.
984 The command we used up to now, @code{make install}, can be thought of
985 as a shorthand for @code{make install-exec install-data}.
986
987 From the GNU Build System point of view, the distinction between
988 architecture-dependent files and architecture-independent files is
989 based exclusively on the directory variable used to specify their
990 installation destination.  In the list of directory variables we
991 provided earlier (@pxref{Standard Directory Variables}), all the
992 variables based on @var{exec-prefix} designate architecture-dependent
993 directories whose files will be installed by @code{make install-exec}.
994 The others designate architecture-independent directories and will
995 serve files installed by @code{make install-data}.  @xref{The Two Parts
996 of Install}, for more details.
997
998 Here is how we could revisit our two-host installation example,
999 assuming that (1) we want to install the package directly in
1000 @file{/usr}, and (2) the directory @file{/usr/share} is shared by the
1001 two hosts.
1002
1003 On the first host we would run
1004 @example
1005 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1006 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1007 ...
1008 [HOST1] /tmp/amh % @kbd{make && sudo make install}
1009 ...
1010 @end example
1011
1012 On the second host, however, we need only install the
1013 architecture-specific files.
1014 @example
1015 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1016 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1017 ...
1018 [HOST2] /tmp/amh % @kbd{make && sudo make install-exec}
1019 ...
1020 @end example
1021
1022 In packages that have installation checks, it would make sense to run
1023 @code{make installcheck} (@pxref{Basic Installation}) to verify that
1024 the package works correctly despite the apparent partial installation.
1025
1026 @node Cross-Compilation
1027 @subsection Cross-Compilation
1028 @cindex cross-compilation
1029
1030 To @dfn{cross-compile} is to build on one platform a binary that will
1031 run on another platform.  When speaking of cross-compilation, it is
1032 important to distinguish between the @dfn{build platform} on which
1033 the compilation is performed, and the @dfn{host platform} on which the
1034 resulting executable is expected to run.  The following
1035 @command{configure} options are used to specify each of them:
1036
1037 @table @option
1038 @item --build=@var{build}
1039 @opindex --build=@var{build}
1040 The system on which the package is built.
1041 @item --host=@var{host}
1042 @opindex --host=@var{host}
1043 The system where built programs and libraries will run.
1044 @end table
1045
1046 When the @option{--host} is used, @command{configure} will search for
1047 the cross-compiling suite for this platform.  Cross-compilation tools
1048 commonly have their target architecture as prefix of their name.  For
1049 instance my cross-compiler for MinGW32 has its binaries called
1050 @code{i586-mingw32msvc-gcc}, @code{i586-mingw32msvc-ld},
1051 @code{i586-mingw32msvc-as}, etc.
1052
1053 @cindex MinGW cross-compilation example
1054 @cindex cross-compilation example
1055
1056 Here is how we could build @code{amhello-1.0} for
1057 @code{i586-mingw32msvc} on a GNU/Linux PC.
1058
1059 @c Keep in sync with amhello-cross-compile.test.
1060 @smallexample
1061 ~/amhello-1.0 % @kbd{./configure --build i686-pc-linux-gnu --host i586-mingw32msvc}
1062 checking for a BSD-compatible install... /usr/bin/install -c
1063 checking whether build environment is sane... yes
1064 checking for gawk... gawk
1065 checking whether make sets $(MAKE)... yes
1066 checking for i586-mingw32msvc-strip... i586-mingw32msvc-strip
1067 checking for i586-mingw32msvc-gcc... i586-mingw32msvc-gcc
1068 checking for C compiler default output file name... a.exe
1069 checking whether the C compiler works... yes
1070 checking whether we are cross compiling... yes
1071 checking for suffix of executables... .exe
1072 checking for suffix of object files... o
1073 checking whether we are using the GNU C compiler... yes
1074 checking whether i586-mingw32msvc-gcc accepts -g... yes
1075 checking for i586-mingw32msvc-gcc option to accept ANSI C...
1076 @dots{}
1077 ~/amhello-1.0 % @kbd{make}
1078 @dots{}
1079 ~/amhello-1.0 % @kbd{cd src; file hello.exe}
1080 hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable
1081 @end smallexample
1082
1083 The @option{--host} and @option{--build} options are usually all we
1084 need for cross-compiling.  The only exception is if the package being
1085 built is itself a cross-compiler: we need a third option to specify
1086 its target architecture.
1087
1088 @table @option
1089 @item --target=@var{target}
1090 @opindex --target=@var{target}
1091 When building compiler tools: the system for which the tools will
1092 create output.
1093 @end table
1094
1095 For instance when installing GCC, the GNU Compiler Collection, we can
1096 use @option{--target=@/@var{target}} to specify that we want to build
1097 GCC as a cross-compiler for @var{target}.  Mixing @option{--build} and
1098 @option{--target}, we can actually cross-compile a cross-compiler;
1099 such a three-way cross-compilation is known as a @dfn{Canadian cross}.
1100
1101 @xref{Specifying Names, , Specifying the System Type, autoconf, The
1102 Autoconf Manual}, for more information about these @command{configure}
1103 options.
1104
1105 @node Renaming
1106 @subsection Renaming Programs at Install Time
1107 @cindex Renaming programs
1108 @cindex Transforming program names
1109 @cindex Programs, renaming during installation
1110
1111 The GNU Build System provides means to automatically rename
1112 executables and manpages before they are installed (@pxref{Man Pages}).
1113 This is especially convenient
1114 when installing a GNU package on a system that already has a
1115 proprietary implementation you do not want to overwrite.  For instance,
1116 you may want to install GNU @command{tar} as @command{gtar} so you can
1117 distinguish it from your vendor's @command{tar}.
1118
1119 This can be done using one of these three @command{configure} options.
1120
1121 @table @option
1122 @item --program-prefix=@var{prefix}
1123 @opindex --program-prefix=@var{prefix}
1124 Prepend @var{prefix} to installed program names.
1125 @item --program-suffix=@var{suffix}
1126 @opindex --program-suffix=@var{suffix}
1127 Append @var{suffix} to installed program names.
1128 @item --program-transform-name=@var{program}
1129 @opindex --program-transform-name=@var{program}
1130 Run @code{sed @var{program}} on installed program names.
1131 @end table
1132
1133 The following commands would install @file{hello}
1134 as @file{/usr/local/bin/test-hello}, for instance.
1135
1136 @example
1137 ~/amhello-1.0 % @kbd{./configure --program-prefix test-}
1138 @dots{}
1139 ~/amhello-1.0 % @kbd{make}
1140 @dots{}
1141 ~/amhello-1.0 % @kbd{sudo make install}
1142 @dots{}
1143 @end example
1144
1145 @node DESTDIR
1146 @subsection Building Binary Packages Using DESTDIR
1147 @vindex DESTDIR
1148
1149 The GNU Build System's @code{make install} and @code{make uninstall}
1150 interface does not exactly fit the needs of a system administrator
1151 who has to deploy and upgrade packages on lots of hosts.  In other
1152 words, the GNU Build System does not replace a package manager.
1153
1154 Such package managers usually need to know which files have been
1155 installed by a package, so a mere @code{make install} is
1156 inappropriate.
1157
1158 @cindex Staged installation
1159
1160 The @code{DESTDIR} variable can be used to perform a staged
1161 installation.  The package should be configured as if it was going to
1162 be installed in its final location (e.g., @code{--prefix /usr}), but
1163 when running @code{make install}, the @code{DESTDIR} should be set to
1164 the absolute name of a directory into which the installation will be
1165 diverted.  From this directory it is easy to review which files are
1166 being installed where, and finally copy them to their final location
1167 by some means.
1168
1169 @cindex Binary package
1170
1171 For instance here is how we could create a binary package containing a
1172 snapshot of all the files to be installed.
1173
1174 @c Keep in sync with amhello-binpkg.test.
1175 @example
1176 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1177 @dots{}
1178 ~/amhello-1.0 % @kbd{make}
1179 @dots{}
1180 ~/amhello-1.0 % @kbd{make DESTDIR=$HOME/inst install}
1181 @dots{}
1182 ~/amhello-1.0 % @kbd{cd ~/inst}
1183 ~/inst % @kbd{find . -type f -print > ../files.lst}
1184 ~/inst % @kbd{tar zcvf ~/amhello-1.0-i686.tar.gz `cat ../files.lst`}
1185 ./usr/bin/hello
1186 ./usr/share/doc/amhello/README
1187 @end example
1188
1189 After this example, @code{amhello-1.0-i686.tar.gz} is ready to be
1190 uncompressed in @file{/} on many hosts.  (Using @code{`cat ../files.lst`}
1191 instead of @samp{.} as argument for @command{tar} avoids entries for
1192 each subdirectory in the archive: we would not like @command{tar} to
1193 restore the modification time of @file{/}, @file{/usr/}, etc.)
1194
1195 Note that when building packages for several architectures, it might
1196 be convenient to use @code{make install-data} and @code{make
1197 install-exec} (@pxref{Two-Part Install}) to gather
1198 architecture-independent files in a single package.
1199
1200 @xref{Install}, for more information.
1201
1202 @c We should document PRE_INSTALL/POST_INSTALL/NORMAL_INSTALL and their
1203 @c UNINSTALL counterparts.
1204
1205 @node Preparing Distributions
1206 @subsection Preparing Distributions
1207 @cindex Preparing distributions
1208 @cindex Packages, preparation
1209 @cindex Distributions, preparation
1210
1211 We have already mentioned @code{make dist}.  This target collects all
1212 your source files and the necessary parts of the build system to
1213 create a tarball named @file{@var{package}-@var{version}.tar.gz}.
1214
1215 @cindex @code{distcheck} better than @code{dist}
1216
1217 Another, more useful command is @code{make distcheck}.  The
1218 @code{distcheck} target constructs
1219 @file{@var{package}-@var{version}.tar.gz} just as well as @code{dist},
1220 but it additionally ensures most of the use cases presented so far
1221 work:
1222
1223 @itemize @bullet
1224 @item
1225 It attempts a full compilation of the package (@pxref{Basic
1226 Installation}), unpacking the newly constructed tarball, running
1227 @code{make}, @code{make check}, @code{make install}, as well as
1228 @code{make installcheck}, and even @code{make dist},
1229 @item
1230 it tests VPATH builds with read-only source tree (@pxref{VPATH Builds}),
1231 @item
1232 it makes sure @code{make clean}, @code{make distclean}, and @code{make
1233 uninstall} do not omit any file (@pxref{Standard Targets}),
1234 @item
1235 and it checks that @code{DESTDIR} installations work (@pxref{DESTDIR}).
1236 @end itemize
1237
1238 All of these actions are performed in a temporary subdirectory, so
1239 that no root privileges are required.
1240
1241 Releasing a package that fails @code{make distcheck} means that one of
1242 the scenarios we presented will not work and some users will be
1243 disappointed.  Therefore it is a good practice to release a package
1244 only after a successful @code{make distcheck}.  This of course does
1245 not imply that the package will be flawless, but at least it will
1246 prevent some of the embarrassing errors you may find in packages
1247 released by people who have never heard about @code{distcheck} (like
1248 @code{DESTDIR} not working because of a typo, or a distributed file
1249 being erased by @code{make clean}, or even @code{VPATH} builds not
1250 working).
1251
1252 @xref{Creating amhello}, to recreate @file{amhello-1.0.tar.gz} using
1253 @code{make distcheck}.  @xref{Checking the Distribution}, for more
1254 information about @code{distcheck}.
1255
1256 @node Dependency Tracking
1257 @subsection Automatic Dependency Tracking
1258 @cindex Dependency tracking
1259
1260 Dependency tracking is performed as a side-effect of compilation.
1261 Each time the build system compiles a source file, it computes its
1262 list of dependencies (in C these are the header files included by the
1263 source being compiled).  Later, any time @command{make} is run and a
1264 dependency appears to have changed, the dependent files will be
1265 rebuilt.
1266
1267 Automake generates code for automatic dependency tracking by default,
1268 unless the developer chooses to override it; for more information,
1269 @pxref{Dependencies}.
1270
1271 When @command{configure} is executed, you can see it probing each
1272 compiler for the dependency mechanism it supports (several mechanisms
1273 can be used):
1274
1275 @example
1276 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1277 @dots{}
1278 checking dependency style of gcc... gcc3
1279 @dots{}
1280 @end example
1281
1282 Because dependencies are only computed as a side-effect of the
1283 compilation, no dependency information exists the first time a package
1284 is built.  This is OK because all the files need to be built anyway:
1285 @code{make} does not have to decide which files need to be rebuilt.
1286 In fact, dependency tracking is completely useless for one-time builds
1287 and there is a @command{configure} option to disable this:
1288
1289 @table @option
1290 @item --disable-dependency-tracking
1291 @opindex --disable-dependency-tracking
1292 Speed up one-time builds.
1293 @end table
1294
1295 Some compilers do not offer any practical way to derive the list of
1296 dependencies as a side-effect of the compilation, requiring a separate
1297 run (maybe of another tool) to compute these dependencies.  The
1298 performance penalty implied by these methods is important enough to
1299 disable them by default.  The option @option{--enable-dependency-tracking}
1300 must be passed to @command{configure} to activate them.
1301
1302 @table @option
1303 @item --enable-dependency-tracking
1304 @opindex --enable-dependency-tracking
1305 Do not reject slow dependency extractors.
1306 @end table
1307
1308 @xref{Dependency Tracking Evolution}, for some discussion about the
1309 different dependency tracking schemes used by Automake over the years.
1310
1311 @node Nested Packages
1312 @subsection Nested Packages
1313 @cindex Nested packages
1314 @cindex Packages, nested
1315 @cindex Subpackages
1316
1317 Although nesting packages isn't something we would recommend to
1318 someone who is discovering the Autotools, it is a nice feature worthy
1319 of mention in this small advertising tour.
1320
1321 Autoconfiscated packages (that means packages whose build system have
1322 been created by Autoconf and friends) can be nested to arbitrary
1323 depth.
1324
1325 A typical setup is that package A will distribute one of the libraries
1326 it needs in a subdirectory.  This library B is a complete package with
1327 its own GNU Build System.  The @command{configure} script of A will
1328 run the @command{configure} script of B as part of its execution,
1329 building and installing A will also build and install B.  Generating a
1330 distribution for A will also include B.
1331
1332 It is possible to gather several packages like this.  GCC is a heavy
1333 user of this feature.  This gives installers a single package to
1334 configure, build and install, while it allows developers to work on
1335 subpackages independently.
1336
1337 When configuring nested packages, the @command{configure} options
1338 given to the top-level @command{configure} are passed recursively to
1339 nested @command{configure}s.  A package that does not understand an
1340 option will ignore it, assuming it is meaningful to some other
1341 package.
1342
1343 @opindex --help=recursive
1344
1345 The command @code{configure --help=recursive} can be used to display
1346 the options supported by all the included packages.
1347
1348 @xref{Subpackages}, for an example setup.
1349
1350 @node Why Autotools
1351 @section How Autotools Help
1352 @cindex Autotools, purpose
1353
1354 There are several reasons why you may not want to implement the GNU
1355 Build System yourself (read: write a @file{configure} script and
1356 @file{Makefile}s yourself).
1357
1358 @itemize @bullet
1359 @item
1360 As we have seen, the GNU Build System has a lot of
1361 features (@pxref{Use Cases}).
1362 Some users may expect features you have not implemented because
1363 you did not need them.
1364 @item
1365 Implementing these features portably is difficult and exhausting.
1366 Think of writing portable shell scripts, and portable
1367 @file{Makefile}s, for systems you may not have handy.  @xref{Portable
1368 Shell, , Portable Shell Programming, autoconf, The Autoconf Manual}, to
1369 convince yourself.
1370 @item
1371 You will have to upgrade your setup to follow changes to the GNU
1372 Coding Standards.
1373 @end itemize
1374
1375 The GNU Autotools take all this burden off your back and provide:
1376
1377 @itemize @bullet
1378 @item
1379 Tools to create a portable, complete, and self-contained GNU Build
1380 System, from simple instructions.
1381 @emph{Self-contained} meaning the resulting build system does not
1382 require the GNU Autotools.
1383 @item
1384 A central place where fixes and improvements are made:
1385 a bug-fix for a portability issue will benefit every package.
1386 @end itemize
1387
1388 Yet there also exist reasons why you may want NOT to use the
1389 Autotools@enddots{} For instance you may be already using (or used to)
1390 another incompatible build system.  Autotools will only be useful if
1391 you do accept the concepts of the GNU Build System.  People who have their
1392 own idea of how a build system should work will feel frustrated by the
1393 Autotools.
1394
1395 @node Hello World
1396 @section A Small Hello World
1397 @cindex Example Hello World
1398 @cindex Hello World example
1399 @cindex @file{amhello-1.0.tar.gz}, creation
1400
1401 In this section we recreate the @file{amhello-1.0} package from
1402 scratch.  The first subsection shows how to call the Autotools to
1403 instantiate the GNU Build System, while the second explains the
1404 meaning of the @file{configure.ac} and @file{Makefile.am} files read
1405 by the Autotools.
1406
1407 @anchor{amhello Explained}
1408 @menu
1409 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
1410 * amhello's configure.ac Setup Explained::
1411 * amhello's Makefile.am Setup Explained::
1412 @end menu
1413
1414 @node Creating amhello
1415 @subsection Creating @file{amhello-1.0.tar.gz}
1416
1417 Here is how we can recreate @file{amhello-1.0.tar.gz} from scratch.
1418 The package is simple enough so that we will only need to write 5
1419 files.  (You may copy them from the final @file{amhello-1.0.tar.gz}
1420 that is distributed with Automake if you do not want to write them.)
1421
1422 Create the following files in an empty directory.
1423
1424 @itemize @bullet
1425
1426 @item
1427 @file{src/main.c} is the source file for the @file{hello} program.  We
1428 store it in the @file{src/} subdirectory, because later, when the package
1429 evolves, it will ease the addition of a @file{man/} directory for man
1430 pages, a @file{data/} directory for data files, etc.
1431 @example
1432 ~/amhello % @kbd{cat src/main.c}
1433 #include <config.h>
1434 #include <stdio.h>
1435
1436 int
1437 main (void)
1438 @{
1439   puts ("Hello World!");
1440   puts ("This is " PACKAGE_STRING ".");
1441   return 0;
1442 @}
1443 @end example
1444
1445 @item
1446 @file{README} contains some very limited documentation for our little
1447 package.
1448 @example
1449 ~/amhello % @kbd{cat README}
1450 This is a demonstration package for GNU Automake.
1451 Type `info Automake' to read the Automake manual.
1452 @end example
1453
1454 @item
1455 @file{Makefile.am} and @file{src/Makefile.am} contain Automake
1456 instructions for these two directories.
1457
1458 @example
1459 ~/amhello % @kbd{cat src/Makefile.am}
1460 bin_PROGRAMS = hello
1461 hello_SOURCES = main.c
1462 ~/amhello % @kbd{cat Makefile.am}
1463 SUBDIRS = src
1464 dist_doc_DATA = README
1465 @end example
1466
1467 @item
1468 Finally, @file{configure.ac} contains Autoconf instructions to
1469 create the @command{configure} script.
1470
1471 @example
1472 ~/amhello % @kbd{cat configure.ac}
1473 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1474 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1475 AC_PROG_CC
1476 AC_CONFIG_HEADERS([config.h])
1477 AC_CONFIG_FILES([
1478  Makefile
1479  src/Makefile
1480 ])
1481 AC_OUTPUT
1482 @end example
1483 @end itemize
1484
1485 @cindex @command{autoreconf}, example
1486
1487 Once you have these five files, it is time to run the Autotools to
1488 instantiate the build system.  Do this using the @command{autoreconf}
1489 command as follows:
1490
1491 @example
1492 ~/amhello % @kbd{autoreconf --install}
1493 configure.ac: installing `./install-sh'
1494 configure.ac: installing `./missing'
1495 src/Makefile.am: installing `./depcomp'
1496 @end example
1497
1498 At this point the build system is complete.
1499
1500 In addition to the three scripts mentioned in its output, you can see
1501 that @command{autoreconf} created four other files: @file{configure},
1502 @file{config.h.in}, @file{Makefile.in}, and @file{src/Makefile.in}.
1503 The latter three files are templates that will be adapted to the
1504 system by @command{configure} under the names @file{config.h},
1505 @file{Makefile}, and @file{src/Makefile}.  Let's do this:
1506
1507 @example
1508 ~/amhello % @kbd{./configure}
1509 checking for a BSD-compatible install... /usr/bin/install -c
1510 checking whether build environment is sane... yes
1511 checking for gawk... no
1512 checking for mawk... mawk
1513 checking whether make sets $(MAKE)... yes
1514 checking for gcc... gcc
1515 checking for C compiler default output file name... a.out
1516 checking whether the C compiler works... yes
1517 checking whether we are cross compiling... no
1518 checking for suffix of executables...
1519 checking for suffix of object files... o
1520 checking whether we are using the GNU C compiler... yes
1521 checking whether gcc accepts -g... yes
1522 checking for gcc option to accept ISO C89... none needed
1523 checking for style of include used by make... GNU
1524 checking dependency style of gcc... gcc3
1525 configure: creating ./config.status
1526 config.status: creating Makefile
1527 config.status: creating src/Makefile
1528 config.status: creating config.h
1529 config.status: executing depfiles commands
1530 @end example
1531
1532 @trindex distcheck
1533 @cindex @code{distcheck} example
1534
1535 You can see @file{Makefile}, @file{src/Makefile}, and @file{config.h}
1536 being created at the end after @command{configure} has probed the
1537 system.  It is now possible to run all the targets we wish
1538 (@pxref{Standard Targets}).  For instance:
1539
1540 @example
1541 ~/amhello % @kbd{make}
1542 @dots{}
1543 ~/amhello % @kbd{src/hello}
1544 Hello World!
1545 This is amhello 1.0.
1546 ~/amhello % @kbd{make distcheck}
1547 @dots{}
1548 =============================================
1549 amhello-1.0 archives ready for distribution:
1550 amhello-1.0.tar.gz
1551 =============================================
1552 @end example
1553
1554 Note that running @command{autoreconf} is only needed initially when
1555 the GNU Build System does not exist.  When you later change some
1556 instructions in a @file{Makefile.am} or @file{configure.ac}, the
1557 relevant part of the build system will be regenerated automatically
1558 when you execute @command{make}.
1559
1560 @command{autoreconf} is a script that calls @command{autoconf},
1561 @command{automake}, and a bunch of other commands in the right order.
1562 If you are beginning with these tools, it is not important to figure
1563 out in which order all these tools should be invoked and why.  However,
1564 because Autoconf and Automake have separate manuals, the important
1565 point to understand is that @command{autoconf} is in charge of
1566 creating @file{configure} from @file{configure.ac}, while
1567 @command{automake} is in charge of creating @file{Makefile.in}s from
1568 @file{Makefile.am}s and @file{configure.ac}.  This should at least
1569 direct you to the right manual when seeking answers.
1570
1571
1572 @node amhello's configure.ac Setup Explained
1573 @subsection @code{amhello}'s @file{configure.ac} Setup Explained
1574
1575 @cindex @file{configure.ac}, Hello World
1576
1577 Let us begin with the contents of @file{configure.ac}.
1578
1579 @example
1580 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1581 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1582 AC_PROG_CC
1583 AC_CONFIG_HEADERS([config.h])
1584 AC_CONFIG_FILES([
1585  Makefile
1586  src/Makefile
1587 ])
1588 AC_OUTPUT
1589 @end example
1590
1591 This file is read by both @command{autoconf} (to create
1592 @file{configure}) and @command{automake} (to create the various
1593 @file{Makefile.in}s).  It contains a series of M4 macros that will be
1594 expanded as shell code to finally form the @file{configure} script.
1595 We will not elaborate on the syntax of this file, because the Autoconf
1596 manual has a whole section about it (@pxref{Writing Autoconf Input, ,
1597 Writing @file{configure.ac}, autoconf, The Autoconf Manual}).
1598
1599 The macros prefixed with @code{AC_} are Autoconf macros, documented
1600 in the Autoconf manual (@pxref{Autoconf Macro Index, , Autoconf Macro
1601 Index, autoconf, The Autoconf Manual}).  The macros that start with
1602 @code{AM_} are Automake macros, documented later in this manual
1603 (@pxref{Macro Index}).
1604
1605 The first two lines of @file{configure.ac} initialize Autoconf and
1606 Automake.  @code{AC_INIT} takes in as parameters the name of the package,
1607 its version number, and a contact address for bug-reports about the
1608 package (this address is output at the end of @code{./configure
1609 --help}, for instance).  When adapting this setup to your own package,
1610 by all means please do not blindly copy Automake's address: use the
1611 mailing list of your package, or your own mail address.
1612
1613 @opindex -Wall
1614 @opindex -Werror
1615 @opindex foreign
1616
1617 The argument to @code{AM_INIT_AUTOMAKE} is a list of options for
1618 @command{automake} (@pxref{Options}).  @option{-Wall} and
1619 @option{-Werror} ask @command{automake} to turn on all warnings and
1620 report them as errors.  We are speaking of @strong{Automake} warnings
1621 here, such as dubious instructions in @file{Makefile.am}.  This has
1622 absolutely nothing to do with how the compiler will be called, even
1623 though it may support options with similar names.  Using @option{-Wall
1624 -Werror} is a safe setting when starting to work on a package: you do
1625 not want to miss any issues.  Later you may decide to relax things a
1626 bit.  The @option{foreign} option tells Automake that this package
1627 will not follow the GNU Standards.  GNU packages should always
1628 distribute additional files such as @file{ChangeLog}, @file{AUTHORS},
1629 etc.  We do not want @command{automake} to complain about these
1630 missing files in our small example.
1631
1632 The @code{AC_PROG_CC} line causes the @command{configure} script to
1633 search for a C compiler and define the variable @code{CC} with its
1634 name.  The @file{src/Makefile.in} file generated by Automake uses the
1635 variable @code{CC} to build @file{hello}, so when @command{configure}
1636 creates @file{src/Makefile} from @file{src/Makefile.in}, it will define
1637 @code{CC} with the value it has found.  If Automake is asked to create
1638 a @file{Makefile.in} that uses @code{CC} but @file{configure.ac} does
1639 not define it, it will suggest you add a call to @code{AC_PROG_CC}.
1640
1641 The @code{AC_CONFIG_HEADERS([config.h])} invocation causes the
1642 @command{configure} script to create a @file{config.h} file gathering
1643 @samp{#define}s defined by other macros in @file{configure.ac}.  In our
1644 case, the @code{AC_INIT} macro already defined a few of them.  Here
1645 is an excerpt of @file{config.h} after @command{configure} has run:
1646
1647 @smallexample
1648 @dots{}
1649 /* Define to the address where bug reports for this package should be sent. */
1650 #define PACKAGE_BUGREPORT "@value{PACKAGE_BUGREPORT}"
1651
1652 /* Define to the full name and version of this package. */
1653 #define PACKAGE_STRING "amhello 1.0"
1654 @dots{}
1655 @end smallexample
1656
1657 As you probably noticed, @file{src/main.c} includes @file{config.h} so
1658 it can use @code{PACKAGE_STRING}.  In a real-world project,
1659 @file{config.h} can grow really big, with one @samp{#define} per
1660 feature probed on the system.
1661
1662 The @code{AC_CONFIG_FILES} macro declares the list of files that
1663 @command{configure} should create from their @file{*.in} templates.
1664 Automake also scans this list to find the @file{Makefile.am} files it must
1665 process.  (This is important to remember: when adding a new directory
1666 to your project, you should add its @file{Makefile} to this list,
1667 otherwise Automake will never process the new @file{Makefile.am} you
1668 wrote in that directory.)
1669
1670 Finally, the @code{AC_OUTPUT} line is a closing command that actually
1671 produces the part of the script in charge of creating the files
1672 registered with @code{AC_CONFIG_HEADERS} and @code{AC_CONFIG_FILES}.
1673
1674 @cindex @command{autoscan}
1675
1676 When starting a new project, we suggest you start with such a simple
1677 @file{configure.ac}, and gradually add the other tests it requires.
1678 The command @command{autoscan} can also suggest a few of the tests
1679 your package may need (@pxref{autoscan Invocation, , Using
1680 @command{autoscan} to Create @file{configure.ac}, autoconf, The
1681 Autoconf Manual}).
1682
1683
1684 @node amhello's Makefile.am Setup Explained
1685 @subsection @code{amhello}'s @file{Makefile.am} Setup Explained
1686
1687 @cindex @file{Makefile.am}, Hello World
1688
1689 We now turn to @file{src/Makefile.am}.  This file contains
1690 Automake instructions to build and install @file{hello}.
1691
1692 @example
1693 bin_PROGRAMS = hello
1694 hello_SOURCES = main.c
1695 @end example
1696
1697 A @file{Makefile.am} has the same syntax as an ordinary
1698 @file{Makefile}.  When @command{automake} processes a
1699 @file{Makefile.am} it copies the entire file into the output
1700 @file{Makefile.in} (that will be later turned into @file{Makefile} by
1701 @command{configure}) but will react to certain variable definitions
1702 by generating some build rules and other variables.
1703 Often @file{Makefile.am}s contain only a list of variable definitions as
1704 above, but they can also contain other variable and rule definitions that
1705 @command{automake} will pass along without interpretation.
1706
1707 Variables that end with @code{_PROGRAMS} are special variables
1708 that list programs that the resulting @file{Makefile} should build.
1709 In Automake speak, this @code{_PROGRAMS} suffix is called a
1710 @dfn{primary}; Automake recognizes other primaries such as
1711 @code{_SCRIPTS}, @code{_DATA}, @code{_LIBRARIES}, etc.@: corresponding
1712 to different types of files.
1713
1714 The @samp{bin} part of the @code{bin_PROGRAMS} tells
1715 @command{automake} that the resulting programs should be installed in
1716 @var{bindir}.  Recall that the GNU Build System uses a set of variables
1717 to denote destination directories and allow users to customize these
1718 locations (@pxref{Standard Directory Variables}).  Any such directory
1719 variable can be put in front of a primary (omitting the @code{dir}
1720 suffix) to tell @command{automake} where to install the listed files.
1721
1722 Programs need to be built from source files, so for each program
1723 @code{@var{prog}} listed in a @code{@w{_PROGRAMS}} variable,
1724 @command{automake} will look for another variable named
1725 @code{@var{prog}_SOURCES} listing its source files.  There may be more
1726 than one source file: they will all be compiled and linked together.
1727
1728 Automake also knows that source files need to be distributed when
1729 creating a tarball (unlike built programs).  So a side-effect of this
1730 @code{hello_SOURCES} declaration is that @file{main.c} will be
1731 part of the tarball created by @code{make dist}.
1732
1733 Finally here are some explanations regarding the top-level
1734 @file{Makefile.am}.
1735
1736 @example
1737 SUBDIRS = src
1738 dist_doc_DATA = README
1739 @end example
1740
1741 @code{SUBDIRS} is a special variable listing all directories that
1742 @command{make} should recurse into before processing the current
1743 directory.  So this line is responsible for @command{make} building
1744 @file{src/hello} even though we run it from the top-level.  This line
1745 also causes @code{make install} to install @file{src/hello} before
1746 installing @file{README} (not that this order matters).
1747
1748 The line @code{dist_doc_DATA = README} causes @file{README} to be
1749 distributed and installed in @var{docdir}.  Files listed with the
1750 @code{_DATA} primary are not automatically part of the tarball built
1751 with @code{make dist}, so we add the @code{dist_} prefix so they get
1752 distributed.  However, for @file{README} it would not have been
1753 necessary: @command{automake} automatically distributes any
1754 @file{README} file it encounters (the list of other files
1755 automatically distributed is presented by @code{automake --help}).
1756 The only important effect of this second line is therefore to install
1757 @file{README} during @code{make install}.
1758
1759 One thing not covered in this example is accessing the installation
1760 directory values (@pxref{Standard Directory Variables}) from your
1761 program code, that is, converting them into defined macros.  For this,
1762 @pxref{Defining Directories,,, autoconf, The Autoconf Manual}.
1763
1764
1765 @node Generalities
1766 @chapter General ideas
1767
1768 The following sections cover a few basic ideas that will help you
1769 understand how Automake works.
1770
1771 @menu
1772 * General Operation::           General operation of Automake
1773 * Strictness::                  Standards conformance checking
1774 * Uniform::                     The Uniform Naming Scheme
1775 * Length Limitations::          Staying below the command line length limit
1776 * Canonicalization::            How derived variables are named
1777 * User Variables::              Variables reserved for the user
1778 * Auxiliary Programs::          Programs automake might require
1779 @end menu
1780
1781
1782 @node General Operation
1783 @section General Operation
1784
1785 Automake works by reading a @file{Makefile.am} and generating a
1786 @file{Makefile.in}.  Certain variables and rules defined in the
1787 @file{Makefile.am} instruct Automake to generate more specialized code;
1788 for instance, a @code{bin_PROGRAMS} variable definition will cause rules
1789 for compiling and linking programs to be generated.
1790
1791 @cindex Non-standard targets
1792 @cindex @code{git-dist}, non-standard example
1793 @trindex git-dist
1794
1795 The variable definitions and rules in the @file{Makefile.am} are
1796 copied mostly verbatim into the generated file, with all variable
1797 definitions preceding all rules.  This allows you to add almost
1798 arbitrary code into the generated @file{Makefile.in}.  For instance,
1799 the Automake distribution includes a non-standard rule for the
1800 @code{git-dist} target, which the Automake maintainer uses to make
1801 distributions from the source control system.
1802
1803 @cindex GNU make extensions
1804
1805 Note that most GNU make extensions are not recognized by Automake.  Using
1806 such extensions in a @file{Makefile.am} will lead to errors or confusing
1807 behavior.
1808
1809 @cindex Append operator
1810 @cmindex +=
1811 A special exception is that the GNU make append operator, @samp{+=}, is
1812 supported.  This operator appends its right hand argument to the variable
1813 specified on the left.  Automake will translate the operator into
1814 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
1815
1816 @cindex indentation
1817 Further note that variable assignments should not be indented with
1818 @key{TAB} characters, use spaces if necessary.  On the other hand,
1819 rule commands should be indented with a leading @key{TAB} character.
1820
1821 Automake tries to keep comments grouped with any adjoining rules or
1822 variable definitions.
1823
1824 @cindex Make targets, overriding
1825 @cindex Make rules, overriding
1826 @cindex Overriding make rules
1827 @cindex Overriding make targets
1828
1829 A rule defined in @file{Makefile.am} generally overrides any such
1830 rule of a similar name that would be automatically generated by
1831 @command{automake}.  Although this is a supported feature, it is generally
1832 best to avoid making use of it, as sometimes the generated rules are
1833 very particular.
1834
1835 @cindex Variables, overriding
1836 @cindex Overriding make variables
1837
1838 Similarly, a variable defined in @file{Makefile.am} or
1839 @code{AC_SUBST}ed from @file{configure.ac} will override any
1840 definition of the variable that @command{automake} would ordinarily
1841 create.  This feature is more often useful than the ability to
1842 override a rule.  Be warned that many of the variables generated by
1843 @command{automake} are considered to be for internal use only, and their
1844 names might change in future releases.
1845
1846 @cindex Recursive operation of Automake
1847 @cindex Automake, recursive operation
1848 @cindex Example of recursive operation
1849
1850 When examining a variable definition, Automake will recursively examine
1851 variables referenced in the definition.  For example, if Automake is
1852 looking at the content of @code{foo_SOURCES} in this snippet
1853
1854 @c Keep in sync with interp.test.
1855 @example
1856 xs = a.c b.c
1857 foo_SOURCES = c.c $(xs)
1858 @end example
1859
1860 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
1861 contents of @code{foo_SOURCES}.
1862
1863 @cindex @code{##} (special Automake comment)
1864 @cindex Special Automake comment
1865 @cindex Comment, special to Automake
1866
1867 Automake also allows a form of comment that is @emph{not} copied into
1868 the output; all lines beginning with @samp{##} (leading spaces allowed)
1869 are completely ignored by Automake.
1870
1871 It is customary to make the first line of @file{Makefile.am} read:
1872
1873 @cindex Makefile.am, first line
1874 @cindex First line of Makefile.am
1875
1876 @example
1877 ## Process this file with automake to produce Makefile.in
1878 @end example
1879
1880 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
1881 @c I don't know quite what to say.
1882
1883 @c FIXME document customary ordering of Makefile.am here!
1884
1885
1886 @node Strictness
1887 @section Strictness
1888
1889 @cindex Non-GNU packages
1890
1891 While Automake is intended to be used by maintainers of GNU packages, it
1892 does make some effort to accommodate those who wish to use it, but do
1893 not want to use all the GNU conventions.
1894
1895 @cindex Strictness, defined
1896 @cindex Strictness, @option{foreign}
1897 @cindex @option{foreign} strictness
1898 @cindex Strictness, @option{gnu}
1899 @cindex @option{gnu} strictness
1900 @cindex Strictness, @option{gnits}
1901 @cindex @option{gnits} strictness
1902
1903 To this end, Automake supports three levels of @dfn{strictness}---the
1904 strictness indicating how stringently Automake should check standards
1905 conformance.
1906
1907 The valid strictness levels are:
1908
1909 @table @option
1910 @item foreign
1911 Automake will check for only those things that are absolutely
1912 required for proper operations.  For instance, whereas GNU standards
1913 dictate the existence of a @file{NEWS} file, it will not be required in
1914 this mode.  The name comes from the fact that Automake is intended to be
1915 used for GNU programs; these relaxed rules are not the standard mode of
1916 operation.
1917
1918 @item gnu
1919 Automake will check---as much as possible---for compliance to the GNU
1920 standards for packages.  This is the default.
1921
1922 @item gnits
1923 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
1924 standards}.  These are based on the GNU standards, but are even more
1925 detailed.  Unless you are a Gnits standards contributor, it is
1926 recommended that you avoid this option until such time as the Gnits
1927 standard is actually published (which may never happen).
1928 @end table
1929
1930 @xref{Gnits}, for more information on the precise implications of the
1931 strictness level.
1932
1933 Automake also has a special ``cygnus'' mode that is similar to
1934 strictness but handled differently.  This mode is useful for packages
1935 that are put into a ``Cygnus'' style tree (e.g., the GCC tree).
1936 @xref{Cygnus}, for more information on this mode.
1937
1938
1939 @node Uniform
1940 @section The Uniform Naming Scheme
1941
1942 @cindex Uniform naming scheme
1943
1944 Automake variables generally follow a @dfn{uniform naming scheme} that
1945 makes it easy to decide how programs (and other derived objects) are
1946 built, and how they are installed.  This scheme also supports
1947 @command{configure} time determination of what should be built.
1948
1949 @cindex @code{_PROGRAMS} primary variable
1950 @cindex @code{PROGRAMS} primary variable
1951 @cindex Primary variable, @code{PROGRAMS}
1952 @cindex Primary variable, defined
1953 @vindex _PROGRAMS
1954
1955 At @command{make} time, certain variables are used to determine which
1956 objects are to be built.  The variable names are made of several pieces
1957 that are concatenated together.
1958
1959 The piece that tells @command{automake} what is being built is commonly called
1960 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
1961 list of programs that are to be compiled and linked.
1962 @vindex PROGRAMS
1963
1964 @cindex @code{pkgdatadir}, defined
1965 @cindex @code{pkgincludedir}, defined
1966 @cindex @code{pkglibdir}, defined
1967 @cindex @code{pkglibexecdir}, defined
1968
1969 @vindex pkgdatadir
1970 @vindex pkgincludedir
1971 @vindex pkglibdir
1972 @vindex pkglibexecdir
1973
1974 @cindex @code{PACKAGE}, directory
1975 A different set of names is used to decide where the built objects
1976 should be installed.  These names are prefixes to the primary, and they
1977 indicate which standard directory should be used as the installation
1978 directory.  The standard directory names are given in the GNU standards
1979 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
1980 Automake extends this list with @code{pkgdatadir}, @code{pkgincludedir},
1981 @code{pkglibdir}, and @code{pkglibexecdir}; these are the same as the
1982 non-@samp{pkg} versions, but with @samp{$(PACKAGE)} appended.  For instance,
1983 @code{pkglibdir} is defined as @samp{$(libdir)/$(PACKAGE)}.
1984
1985 @cindex @code{EXTRA_}, prepending
1986 For each primary, there is one additional variable named by prepending
1987 @samp{EXTRA_} to the primary name.  This variable is used to list
1988 objects that may or may not be built, depending on what
1989 @command{configure} decides.  This variable is required because Automake
1990 must statically know the entire list of objects that may be built in
1991 order to generate a @file{Makefile.in} that will work in all cases.
1992
1993 @cindex @code{EXTRA_PROGRAMS}, defined
1994 @cindex Example, @code{EXTRA_PROGRAMS}
1995 @cindex @command{cpio} example
1996
1997 For instance, @command{cpio} decides at configure time which programs
1998 should be built.  Some of the programs are installed in @code{bindir},
1999 and some are installed in @code{sbindir}:
2000
2001 @example
2002 EXTRA_PROGRAMS = mt rmt
2003 bin_PROGRAMS = cpio pax
2004 sbin_PROGRAMS = $(MORE_PROGRAMS)
2005 @end example
2006
2007 Defining a primary without a prefix as a variable, e.g.,
2008 @samp{PROGRAMS}, is an error.
2009
2010 Note that the common @samp{dir} suffix is left off when constructing the
2011 variable names; thus one writes @samp{bin_PROGRAMS} and not
2012 @samp{bindir_PROGRAMS}.
2013
2014 Not every sort of object can be installed in every directory.  Automake
2015 will flag those attempts it finds in error (but see below how to override
2016 the check if you really need to).
2017 Automake will also diagnose obvious misspellings in directory names.
2018
2019 @cindex Extending list of installation directories
2020 @cindex Installation directories, extending list
2021
2022 Sometimes the standard directories---even as augmented by
2023 Automake---are not enough.  In particular it is sometimes useful, for
2024 clarity, to install objects in a subdirectory of some predefined
2025 directory.  To this end, Automake allows you to extend the list of
2026 possible installation directories.  A given prefix (e.g., @samp{zar})
2027 is valid if a variable of the same name with @samp{dir} appended is
2028 defined (e.g., @samp{zardir}).
2029
2030 For instance, the following snippet will install @file{file.xml} into
2031 @samp{$(datadir)/xml}.
2032
2033 @c Keep in sync with primary-prefix-couples-documented-valid.test.
2034 @example
2035 xmldir = $(datadir)/xml
2036 xml_DATA = file.xml
2037 @end example
2038
2039 This feature can also be used to override the sanity checks Automake
2040 performs to diagnose suspicious directory/primary couples (in the
2041 unlikely case these checks are undesirable, and you really know what
2042 you're doing).  For example, Automake would error out on this input:
2043
2044 @c Should be tested in primary-prefix-invalid-couples.test.
2045 @example
2046 # Forbidden directory combinations, automake will error out on this.
2047 pkglib_PROGRAMS = foo
2048 doc_LIBRARIES = libquux.a
2049 @end example
2050
2051 @noindent
2052 but it will succeed with this:
2053
2054 @c Keep in sync with primary-prefix-couples-documented-valid.test.
2055 @example
2056 # Work around forbidden directory combinations.  Do not use this
2057 # without a very good reason!
2058 my_execbindir = $(pkglibdir)
2059 my_doclibdir = $(docdir)
2060 my_execbin_PROGRAMS = foo
2061 my_doclib_LIBRARIES = libquux.a
2062 @end example
2063
2064 The @samp{exec} substring of the @samp{my_execbindir} variable lets
2065 the files be installed at the right time (@pxref{The Two Parts of
2066 Install}).
2067
2068 @cindex @samp{noinst_} primary prefix, definition
2069 @vindex noinst_
2070
2071 The special prefix @samp{noinst_} indicates that the objects in question
2072 should be built but not installed at all.  This is usually used for
2073 objects required to build the rest of your package, for instance static
2074 libraries (@pxref{A Library}), or helper scripts.
2075
2076 @cindex @samp{check_} primary prefix, definition
2077 @vindex check_
2078
2079 The special prefix @samp{check_} indicates that the objects in question
2080 should not be built until the @samp{make check} command is run.  Those
2081 objects are not installed either.
2082
2083 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
2084 @samp{LTLIBRARIES}, @samp{LISP}, @samp{PYTHON}, @samp{JAVA},
2085 @samp{SCRIPTS}, @samp{DATA}, @samp{HEADERS}, @samp{MANS}, and
2086 @samp{TEXINFOS}.
2087 @vindex PROGRAMS
2088 @vindex LIBRARIES
2089 @vindex LTLIBRARIES
2090 @vindex LISP
2091 @vindex PYTHON
2092 @vindex JAVA
2093 @vindex SCRIPTS
2094 @vindex DATA
2095 @vindex HEADERS
2096 @vindex MANS
2097 @vindex TEXINFOS
2098
2099 Some primaries also allow additional prefixes that control other
2100 aspects of @command{automake}'s behavior.  The currently defined prefixes
2101 are @samp{dist_}, @samp{nodist_}, @samp{nobase_}, and @samp{notrans_}.
2102 These prefixes are explained later (@pxref{Program and Library Variables})
2103 (@pxref{Man Pages}).
2104
2105
2106 @node Length Limitations
2107 @section Staying below the command line length limit
2108
2109 @cindex command line length limit
2110 @cindex ARG_MAX
2111
2112 Traditionally, most unix-like systems have a length limitation for the
2113 command line arguments and environment contents when creating new
2114 processes (see for example
2115 @uref{http://www.in-ulm.de/@/~mascheck/@/various/@/argmax/} for an
2116 overview on this issue),
2117 which of course also applies to commands spawned by @command{make}.
2118 POSIX requires this limit to be at least 4096 bytes, and most modern
2119 systems have quite high limits (or are unlimited).
2120
2121 In order to create portable Makefiles that do not trip over these
2122 limits, it is necessary to keep the length of file lists bounded.
2123 Unfortunately, it is not possible to do so fully transparently within
2124 Automake, so your help may be needed.  Typically, you can split long
2125 file lists manually and use different installation directory names for
2126 each list.  For example,
2127
2128 @example
2129 data_DATA = file1 @dots{} file@var{N} file@var{N+1} @dots{} file@var{2N}
2130 @end example
2131
2132 @noindent
2133 may also be written as
2134
2135 @c Keep in sync with primary-prefix-couples-documented-valid.test.
2136 @example
2137 data_DATA = file1 @dots{} file@var{N}
2138 data2dir = $(datadir)
2139 data2_DATA = file@var{N+1} @dots{} file@var{2N}
2140 @end example
2141
2142 @noindent
2143 and will cause Automake to treat the two lists separately during
2144 @code{make install}.  See @ref{The Two Parts of Install} for choosing
2145 directory names that will keep the ordering of the two parts of
2146 installation Note that @code{make dist} may still only work on a host
2147 with a higher length limit in this example.
2148
2149 Automake itself employs a couple of strategies to avoid long command
2150 lines.  For example, when @samp{$@{srcdir@}/} is prepended to file
2151 names, as can happen with above @code{$(data_DATA)} lists, it limits
2152 the amount of arguments passed to external commands.
2153
2154 Unfortunately, some system's @command{make} commands may prepend
2155 @code{VPATH} prefixes like @samp{$@{srcdir@}/} to file names from the
2156 source tree automatically (@pxref{Automatic Rule Rewriting, , Automatic
2157 Rule Rewriting, autoconf, The Autoconf Manual}).  In this case, the user
2158 may have to switch to use GNU Make, or refrain from using VPATH builds,
2159 in order to stay below the length limit.
2160
2161 For libraries and programs built from many sources, convenience archives
2162 may be used as intermediates in order to limit the object list length
2163 (@pxref{Libtool Convenience Libraries}).
2164
2165
2166 @node Canonicalization
2167 @section How derived variables are named
2168
2169 @cindex canonicalizing Automake variables
2170
2171 Sometimes a Makefile variable name is derived from some text the
2172 maintainer supplies.  For instance, a program name listed in
2173 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
2174 variable.  In cases like this, Automake canonicalizes the text, so that
2175 program names and the like do not have to follow Makefile variable naming
2176 rules.  All characters in the name except for letters, numbers, the
2177 strudel (@@), and the underscore are turned into underscores when making
2178 variable references.
2179
2180 For example, if your program is named @file{sniff-glue}, the derived
2181 variable name would be @samp{sniff_glue_SOURCES}, not
2182 @samp{sniff-glue_SOURCES}.  Similarly the sources for a library named
2183 @file{libmumble++.a} should be listed in the
2184 @samp{libmumble___a_SOURCES} variable.
2185
2186 The strudel is an addition, to make the use of Autoconf substitutions in
2187 variable names less obfuscating.
2188
2189
2190 @node User Variables
2191 @section Variables reserved for the user
2192
2193 @cindex variables, reserved for the user
2194 @cindex user variables
2195
2196 Some @file{Makefile} variables are reserved by the GNU Coding Standards
2197 for the use of the ``user''---the person building the package.  For
2198 instance, @code{CFLAGS} is one such variable.
2199
2200 Sometimes package developers are tempted to set user variables such as
2201 @code{CFLAGS} because it appears to make their job easier.  However,
2202 the package itself should never set a user variable, particularly not
2203 to include switches that are required for proper compilation of the
2204 package.  Since these variables are documented as being for the
2205 package builder, that person rightfully expects to be able to override
2206 any of these variables at build time.
2207
2208 To get around this problem, Automake introduces an automake-specific
2209 shadow variable for each user flag variable.  (Shadow variables are
2210 not introduced for variables like @code{CC}, where they would make no
2211 sense.)  The shadow variable is named by prepending @samp{AM_} to the
2212 user variable's name.  For instance, the shadow variable for
2213 @code{YFLAGS} is @code{AM_YFLAGS}.  The package maintainer---that is,
2214 the author(s) of the @file{Makefile.am} and @file{configure.ac}
2215 files---may adjust these shadow variables however necessary.
2216
2217 @xref{Flag Variables Ordering}, for more discussion about these
2218 variables and how they interact with per-target variables.
2219
2220 @node Auxiliary Programs
2221 @section Programs automake might require
2222
2223 @cindex Programs, auxiliary
2224 @cindex Auxiliary programs
2225
2226 Automake sometimes requires helper programs so that the generated
2227 @file{Makefile} can do its work properly.  There are a fairly large
2228 number of them, and we list them here.
2229
2230 Although all of these files are distributed and installed with
2231 Automake, a couple of them are maintained separately.  The Automake
2232 copies are updated before each release, but we mention the original
2233 source in case you need more recent versions.
2234
2235 @table @code
2236 @item ansi2knr.c
2237 @itemx ansi2knr.1
2238 These two files are used for de-ANSI-fication support (they are
2239 deprecated now, and @emph{will be removed} in the next major Automake
2240 release; @pxref{ANSI}).
2241
2242 @item compile
2243 This is a wrapper for compilers that do not accept options @option{-c}
2244 and @option{-o} at the same time.  It is only used when absolutely
2245 required.  Such compilers are rare.
2246
2247 @item config.guess
2248 @itemx config.sub
2249 These two programs compute the canonical triplets for the given build,
2250 host, or target architecture.  These programs are updated regularly to
2251 support new architectures and fix probes broken by changes in new
2252 kernel versions.  Each new release of Automake comes with up-to-date
2253 copies of these programs.  If your copy of Automake is getting old,
2254 you are encouraged to fetch the latest versions of these files from
2255 @url{http://savannah.gnu.org/git/?group=config} before making a
2256 release.
2257
2258 @item config-ml.in
2259 This file is not a program, it is a @file{configure} fragment used for
2260 multilib support (@pxref{Multilibs}).  This file is maintained in the
2261 GCC tree at @url{http://gcc.gnu.org/svn.html}.
2262
2263 @item depcomp
2264 This program understands how to run a compiler so that it will
2265 generate not only the desired output but also dependency information
2266 that is then used by the automatic dependency tracking feature
2267 (@pxref{Dependencies}).
2268
2269 @item elisp-comp
2270 This program is used to byte-compile Emacs Lisp code.
2271
2272 @item install-sh
2273 This is a replacement for the @command{install} program that works on
2274 platforms where @command{install} is unavailable or unusable.
2275
2276 @item mdate-sh
2277 This script is used to generate a @file{version.texi} file.  It examines
2278 a file and prints some date information about it.
2279
2280 @item missing
2281 This wraps a number of programs that are typically only required by
2282 maintainers.  If the program in question doesn't exist,
2283 @command{missing} prints an informative warning and attempts to fix
2284 things so that the build can continue.
2285
2286 @item mkinstalldirs
2287 This script used to be a wrapper around @samp{mkdir -p}, which is not
2288 portable.  Now we prefer to use @samp{install-sh -d} when @command{configure}
2289 finds that @samp{mkdir -p} does not work, this makes one less script to
2290 distribute.
2291
2292 For backward compatibility @file{mkinstalldirs} is still used and
2293 distributed when @command{automake} finds it in a package.  But it is no
2294 longer installed automatically, and it should be safe to remove it.
2295
2296 @item py-compile
2297 This is used to byte-compile Python scripts.
2298
2299 @item symlink-tree
2300 This program duplicates a tree of directories, using symbolic links
2301 instead of copying files.  Such an operation is performed when building
2302 multilibs (@pxref{Multilibs}).  This file is maintained in the GCC
2303 tree at @url{http://gcc.gnu.org/svn.html}.
2304
2305 @item texinfo.tex
2306 Not a program, this file is required for @samp{make dvi}, @samp{make
2307 ps} and @samp{make pdf} to work when Texinfo sources are in the
2308 package.  The latest version can be downloaded from
2309 @url{http://www.gnu.org/software/texinfo/}.
2310
2311 @item ylwrap
2312 This program wraps @command{lex} and @command{yacc} to rename their
2313 output files.  It also ensures that, for instance, multiple
2314 @command{yacc} instances can be invoked in a single directory in
2315 parallel.
2316
2317 @end table
2318
2319
2320 @node Examples
2321 @chapter Some example packages
2322
2323 This section contains two small examples.
2324
2325 The first example (@pxref{Complete}) assumes you have an existing
2326 project already using Autoconf, with handcrafted @file{Makefile}s, and
2327 that you want to convert it to using Automake.  If you are discovering
2328 both tools, it is probably better that you look at the Hello World
2329 example presented earlier (@pxref{Hello World}).
2330
2331 The second example (@pxref{true}) shows how two programs can be built
2332 from the same file, using different compilation parameters.  It
2333 contains some technical digressions that are probably best skipped on
2334 first read.
2335
2336 @menu
2337 * Complete::                    A simple example, start to finish
2338 * true::                        Building true and false
2339 @end menu
2340
2341
2342 @node Complete
2343 @section A simple example, start to finish
2344
2345 @cindex Complete example
2346
2347 Let's suppose you just finished writing @code{zardoz}, a program to make
2348 your head float from vortex to vortex.  You've been using Autoconf to
2349 provide a portability framework, but your @file{Makefile.in}s have been
2350 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
2351
2352 @cindex @code{AM_INIT_AUTOMAKE}, example use
2353
2354 The first step is to update your @file{configure.ac} to include the
2355 commands that @command{automake} needs.  The way to do this is to add an
2356 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
2357
2358 @example
2359 AC_INIT([zardoz], [1.0])
2360 AM_INIT_AUTOMAKE
2361 @dots{}
2362 @end example
2363
2364 Since your program doesn't have any complicating factors (e.g., it
2365 doesn't use @code{gettext}, it doesn't want to build a shared library),
2366 you're done with this part.  That was easy!
2367
2368 @cindex @command{aclocal} program, introduction
2369 @cindex @file{aclocal.m4}, preexisting
2370 @cindex @file{acinclude.m4}, defined
2371
2372 Now you must regenerate @file{configure}.  But to do that, you'll need
2373 to tell @command{autoconf} how to find the new macro you've used.  The
2374 easiest way to do this is to use the @command{aclocal} program to
2375 generate your @file{aclocal.m4} for you.  But wait@dots{} maybe you
2376 already have an @file{aclocal.m4}, because you had to write some hairy
2377 macros for your program.  The @command{aclocal} program lets you put
2378 your own macros into @file{acinclude.m4}, so simply rename and then
2379 run:
2380
2381 @example
2382 mv aclocal.m4 acinclude.m4
2383 aclocal
2384 autoconf
2385 @end example
2386
2387 @cindex @command{zardoz} example
2388
2389 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
2390 Since @code{zardoz} is a user program, you want to install it where the
2391 rest of the user programs go: @code{bindir}.  Additionally,
2392 @code{zardoz} has some Texinfo documentation.  Your @file{configure.ac}
2393 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
2394 @samp{$(LIBOBJS)}.  So here's what you'd write:
2395
2396 @example
2397 bin_PROGRAMS = zardoz
2398 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
2399 zardoz_LDADD = $(LIBOBJS)
2400
2401 info_TEXINFOS = zardoz.texi
2402 @end example
2403
2404 Now you can run @samp{automake --add-missing} to generate your
2405 @file{Makefile.in} and grab any auxiliary files you might need, and
2406 you're done!
2407
2408
2409 @node true
2410 @section Building true and false
2411
2412 @cindex Example, @command{false} and @command{true}
2413 @cindex @command{false} Example
2414 @cindex @command{true} Example
2415
2416 Here is another, trickier example.  It shows how to generate two
2417 programs (@code{true} and @code{false}) from the same source file
2418 (@file{true.c}).  The difficult part is that each compilation of
2419 @file{true.c} requires different @code{cpp} flags.
2420
2421 @example
2422 bin_PROGRAMS = true false
2423 false_SOURCES =
2424 false_LDADD = false.o
2425
2426 true.o: true.c
2427         $(COMPILE) -DEXIT_CODE=0 -c true.c
2428
2429 false.o: true.c
2430         $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
2431 @end example
2432
2433 Note that there is no @code{true_SOURCES} definition.  Automake will
2434 implicitly assume that there is a source file named @file{true.c}
2435 (@pxref{Default _SOURCES}), and
2436 define rules to compile @file{true.o} and link @file{true}.  The
2437 @samp{true.o: true.c} rule supplied by the above @file{Makefile.am},
2438 will override the Automake generated rule to build @file{true.o}.
2439
2440 @code{false_SOURCES} is defined to be empty---that way no implicit value
2441 is substituted.  Because we have not listed the source of
2442 @file{false}, we have to tell Automake how to link the program.  This is
2443 the purpose of the @code{false_LDADD} line.  A @code{false_DEPENDENCIES}
2444 variable, holding the dependencies of the @file{false} target will be
2445 automatically generated by Automake from the content of
2446 @code{false_LDADD}.
2447
2448 The above rules won't work if your compiler doesn't accept both
2449 @option{-c} and @option{-o}.  The simplest fix for this is to introduce a
2450 bogus dependency (to avoid problems with a parallel @command{make}):
2451
2452 @example
2453 true.o: true.c false.o
2454         $(COMPILE) -DEXIT_CODE=0 -c true.c
2455
2456 false.o: true.c
2457         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
2458 @end example
2459
2460 As it turns out, there is also a much easier way to do this same task.
2461 Some of the above technique is useful enough that we've kept the
2462 example in the manual.  However if you were to build @code{true} and
2463 @code{false} in real life, you would probably use per-program
2464 compilation flags, like so:
2465
2466 @c Keep in sync with specflg7.test and specflg8.test.
2467 @example
2468 bin_PROGRAMS = false true
2469
2470 false_SOURCES = true.c
2471 false_CPPFLAGS = -DEXIT_CODE=1
2472
2473 true_SOURCES = true.c
2474 true_CPPFLAGS = -DEXIT_CODE=0
2475 @end example
2476
2477 In this case Automake will cause @file{true.c} to be compiled twice,
2478 with different flags.  In this instance, the names of the object files
2479 would be chosen by automake; they would be @file{false-true.o} and
2480 @file{true-true.o}. (The name of the object files rarely matters.)
2481
2482
2483 @node Invoking Automake
2484 @chapter Creating a @file{Makefile.in}
2485
2486 @cindex Multiple @file{configure.ac} files
2487 @cindex Invoking @command{automake}
2488 @cindex @command{automake}, invoking
2489
2490 To create all the @file{Makefile.in}s for a package, run the
2491 @command{automake} program in the top level directory, with no
2492 arguments.  @command{automake} will automatically find each
2493 appropriate @file{Makefile.am} (by scanning @file{configure.ac};
2494 @pxref{configure}) and generate the corresponding @file{Makefile.in}.
2495 Note that @command{automake} has a rather simplistic view of what
2496 constitutes a package; it assumes that a package has only one
2497 @file{configure.ac}, at the top.  If your package has multiple
2498 @file{configure.ac}s, then you must run @command{automake} in each
2499 directory holding a @file{configure.ac}.  (Alternatively, you may rely
2500 on Autoconf's @command{autoreconf}, which is able to recurse your
2501 package tree and run @command{automake} where appropriate.)
2502
2503 You can optionally give @command{automake} an argument; @file{.am} is
2504 appended to the argument and the result is used as the name of the
2505 input file.  This feature is generally only used to automatically
2506 rebuild an out-of-date @file{Makefile.in}.  Note that
2507 @command{automake} must always be run from the topmost directory of a
2508 project, even if being used to regenerate the @file{Makefile.in} in
2509 some subdirectory.  This is necessary because @command{automake} must
2510 scan @file{configure.ac}, and because @command{automake} uses the
2511 knowledge that a @file{Makefile.in} is in a subdirectory to change its
2512 behavior in some cases.
2513
2514 @vindex AUTOCONF
2515 Automake will run @command{autoconf} to scan @file{configure.ac} and
2516 its dependencies (i.e., @file{aclocal.m4} and any included file),
2517 therefore @command{autoconf} must be in your @env{PATH}.  If there is
2518 an @env{AUTOCONF} variable in your environment it will be used
2519 instead of @command{autoconf}, this allows you to select a particular
2520 version of Autoconf.  By the way, don't misunderstand this paragraph:
2521 @command{automake} runs @command{autoconf} to @strong{scan} your
2522 @file{configure.ac}, this won't build @file{configure} and you still
2523 have to run @command{autoconf} yourself for this purpose.
2524
2525 @cindex @command{automake} options
2526 @cindex Options, @command{automake}
2527 @cindex Strictness, command line
2528
2529 @command{automake} accepts the following options:
2530
2531 @cindex Extra files distributed with Automake
2532 @cindex Files distributed with Automake
2533 @cindex @file{config.guess}
2534
2535 @table @code
2536 @item -a
2537 @itemx --add-missing
2538 @opindex -a
2539 @opindex --add-missing
2540 Automake requires certain common files to exist in certain situations;
2541 for instance, @file{config.guess} is required if @file{configure.ac} invokes
2542 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
2543 files (@pxref{Auxiliary Programs}); this option will cause the missing
2544 ones to be automatically added to the package, whenever possible.  In
2545 general if Automake tells you a file is missing, try using this option.
2546 By default Automake tries to make a symbolic link pointing to its own
2547 copy of the missing file; this can be changed with @option{--copy}.
2548
2549 Many of the potentially-missing files are common scripts whose
2550 location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
2551 Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
2552 file is considered missing, and where the missing file is added
2553 (@pxref{Optional}).
2554
2555 In some strictness modes, additional files are installed, see @ref{Gnits}
2556 for more information.
2557
2558 @item --libdir=@var{dir}
2559 @opindex --libdir
2560 Look for Automake data files in directory @var{dir} instead of in the
2561 installation directory.  This is typically used for debugging.
2562
2563 @item -c
2564 @opindex -c
2565 @itemx --copy
2566 @opindex --copy
2567 When used with @option{--add-missing}, causes installed files to be
2568 copied.  The default is to make a symbolic link.
2569
2570 @item --cygnus
2571 @opindex --cygnus
2572 Causes the generated @file{Makefile.in}s to follow Cygnus rules, instead
2573 of GNU or Gnits rules.  For more information, see @ref{Cygnus}.
2574
2575 @item -f
2576 @opindex -f
2577 @itemx --force-missing
2578 @opindex --force-missing
2579 When used with @option{--add-missing}, causes standard files to be reinstalled
2580 even if they already exist in the source tree.  This involves removing
2581 the file from the source tree before creating the new symlink (or, with
2582 @option{--copy}, copying the new file).
2583
2584 @item --foreign
2585 @opindex --foreign
2586 Set the global strictness to @option{foreign}.  For more information, see
2587 @ref{Strictness}.
2588
2589 @item --gnits
2590 @opindex --gnits
2591 Set the global strictness to @option{gnits}.  For more information, see
2592 @ref{Gnits}.
2593
2594 @item --gnu
2595 @opindex --gnu
2596 Set the global strictness to @option{gnu}.  For more information, see
2597 @ref{Gnits}.  This is the default strictness.
2598
2599 @item --help
2600 @opindex --help
2601 Print a summary of the command line options and exit.
2602
2603 @item -i
2604 @itemx --ignore-deps
2605 @opindex -i
2606 This disables the dependency tracking feature in generated
2607 @file{Makefile}s; see @ref{Dependencies}.
2608
2609 @item --include-deps
2610 @opindex --include-deps
2611 This enables the dependency tracking feature.  This feature is enabled
2612 by default.  This option is provided for historical reasons only and
2613 probably should not be used.
2614
2615 @item --no-force
2616 @opindex --no-force
2617 Ordinarily @command{automake} creates all @file{Makefile.in}s mentioned in
2618 @file{configure.ac}.  This option causes it to only update those
2619 @file{Makefile.in}s that are out of date with respect to one of their
2620 dependents.
2621
2622 @item -o @var{dir}
2623 @itemx --output-dir=@var{dir}
2624 @opindex -o
2625 @opindex --output-dir
2626 Put the generated @file{Makefile.in} in the directory @var{dir}.
2627 Ordinarily each @file{Makefile.in} is created in the directory of the
2628 corresponding @file{Makefile.am}.  This option is deprecated and will be
2629 removed in a future release.
2630
2631 @item -v
2632 @itemx --verbose
2633 @opindex -v
2634 @opindex --verbose
2635 Cause Automake to print information about which files are being read or
2636 created.
2637
2638 @item --version
2639 @opindex --version
2640 Print the version number of Automake and exit.
2641
2642 @item -W CATEGORY
2643 @itemx --warnings=@var{category}
2644 @opindex -W
2645 @opindex --warnings
2646 Output warnings falling in @var{category}.  @var{category} can be
2647 one of:
2648 @table @code
2649 @item gnu
2650 warnings related to the GNU Coding Standards
2651 (@pxref{Top, , , standards, The GNU Coding Standards}).
2652 @item obsolete
2653 obsolete features or constructions
2654 @item override
2655 user redefinitions of Automake rules or variables
2656 @item portability
2657 portability issues (e.g., use of @command{make} features that are
2658 known to be not portable)
2659 @item syntax
2660 weird syntax, unused variables, typos
2661 @item unsupported
2662 unsupported or incomplete features
2663 @item all
2664 all the warnings
2665 @item none
2666 turn off all the warnings
2667 @item error
2668 treat warnings as errors
2669 @end table
2670
2671 A category can be turned off by prefixing its name with @samp{no-}.  For
2672 instance, @option{-Wno-syntax} will hide the warnings about unused
2673 variables.
2674
2675 The categories output by default are @samp{syntax} and
2676 @samp{unsupported}.  Additionally, @samp{gnu} and @samp{portability}
2677 are enabled in @option{--gnu} and @option{--gnits} strictness.
2678 On the other hand, the @option{silent-rules} options (@pxref{Options})
2679 turns off portability warnings about recursive variable expansions.
2680
2681 @vindex WARNINGS
2682 The environment variable @env{WARNINGS} can contain a comma separated
2683 list of categories to enable.  It will be taken into account before the
2684 command-line switches, this way @option{-Wnone} will also ignore any
2685 warning category enabled by @env{WARNINGS}.  This variable is also used
2686 by other tools like @command{autoconf}; unknown categories are ignored
2687 for this reason.
2688
2689 @end table
2690
2691 @vindex AUTOMAKE_JOBS
2692 If the environment variable @env{AUTOMAKE_JOBS} contains a positive
2693 number, it is taken as the maximum number of Perl threads to use in
2694 @command{automake} for generating multiple @file{Makefile.in} files
2695 concurrently.  This is an experimental feature.
2696
2697
2698 @node configure
2699 @chapter Scanning @file{configure.ac}, using @command{aclocal}
2700
2701 @cindex @file{configure.ac}, scanning
2702 @cindex Scanning @file{configure.ac}
2703 @cindex Using @command{aclocal}
2704 @cindex @command{aclocal}, using
2705
2706 Automake scans the package's @file{configure.ac} to determine certain
2707 information about the package.  Some @command{autoconf} macros are required
2708 and some variables must be defined in @file{configure.ac}.  Automake
2709 will also use information from @file{configure.ac} to further tailor its
2710 output.
2711
2712 Automake also supplies some Autoconf macros to make the maintenance
2713 easier.  These macros can automatically be put into your
2714 @file{aclocal.m4} using the @command{aclocal} program.
2715
2716 @menu
2717 * Requirements::                Configuration requirements
2718 * Optional::                    Other things Automake recognizes
2719 * Invoking aclocal::            Auto-generating aclocal.m4
2720 * Macros::                      Autoconf macros supplied with Automake
2721 @end menu
2722
2723
2724 @node Requirements
2725 @section Configuration requirements
2726
2727 @cindex Automake requirements
2728 @cindex Requirements of Automake
2729
2730 @acindex AM_INIT_AUTOMAKE
2731 The one real requirement of Automake is that your @file{configure.ac}
2732 call @code{AM_INIT_AUTOMAKE}.  This macro does several things that are
2733 required for proper Automake operation (@pxref{Macros}).
2734
2735 Here are the other macros that Automake requires but which are not run
2736 by @code{AM_INIT_AUTOMAKE}:
2737
2738 @table @code
2739 @item AC_CONFIG_FILES
2740 @itemx AC_OUTPUT
2741 @acindex AC_CONFIG_FILES
2742 @acindex AC_OUTPUT
2743 These two macros are usually invoked as follows near the end of
2744 @file{configure.ac}.
2745
2746 @example
2747 @dots{}
2748 AC_CONFIG_FILES([
2749   Makefile
2750   doc/Makefile
2751   src/Makefile
2752   src/lib/Makefile
2753   @dots{}
2754 ])
2755 AC_OUTPUT
2756 @end example
2757
2758 Automake uses these to determine which files to create (@pxref{Output, ,
2759 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
2760 is considered to be an Automake generated @file{Makefile} if there
2761 exists a file with the same name and the @file{.am} extension appended.
2762 Typically, @samp{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
2763 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
2764
2765 When using @code{AC_CONFIG_FILES} with multiple input files, as in
2766
2767 @example
2768 AC_CONFIG_FILES([Makefile:top.in:Makefile.in:bot.in])
2769 @end example
2770
2771 @noindent
2772 @command{automake} will generate the first @file{.in} input file for
2773 which a @file{.am} file exists.  If no such file exists the output
2774 file is not considered to be generated by Automake.
2775
2776 Files created by @code{AC_CONFIG_FILES}, be they Automake
2777 @file{Makefile}s or not, are all removed by @samp{make distclean}.
2778 Their inputs are automatically distributed, unless they
2779 are the output of prior @code{AC_CONFIG_FILES} commands.
2780 Finally, rebuild rules are generated in the Automake @file{Makefile}
2781 existing in the subdirectory of the output file, if there is one, or
2782 in the top-level @file{Makefile} otherwise.
2783
2784 The above machinery (cleaning, distributing, and rebuilding) works
2785 fine if the @code{AC_CONFIG_FILES} specifications contain only
2786 literals.  If part of the specification uses shell variables,
2787 @command{automake} will not be able to fulfill this setup, and you will
2788 have to complete the missing bits by hand.  For instance, on
2789
2790 @c Keep in sync with output11.test.
2791 @example
2792 file=input
2793 @dots{}
2794 AC_CONFIG_FILES([output:$file],, [file=$file])
2795 @end example
2796
2797 @noindent
2798 @command{automake} will output rules to clean @file{output}, and
2799 rebuild it.  However the rebuild rule will not depend on @file{input},
2800 and this file will not be distributed either.  (You must add
2801 @samp{EXTRA_DIST = input} to your @file{Makefile.am} if @file{input} is a
2802 source file.)
2803
2804 Similarly
2805
2806 @c Keep in sync with output11.test.
2807 @example
2808 file=output
2809 file2=out:in
2810 @dots{}
2811 AC_CONFIG_FILES([$file:input],, [file=$file])
2812 AC_CONFIG_FILES([$file2],, [file2=$file2])
2813 @end example
2814
2815 @noindent
2816 will only cause @file{input} to be distributed.  No file will be
2817 cleaned automatically (add @samp{DISTCLEANFILES = output out}
2818 yourself), and no rebuild rule will be output.
2819
2820 Obviously @command{automake} cannot guess what value @samp{$file} is
2821 going to hold later when @file{configure} is run, and it cannot use
2822 the shell variable @samp{$file} in a @file{Makefile}.  However, if you
2823 make reference to @samp{$file} as @samp{$@{file@}} (i.e., in a way
2824 that is compatible with @command{make}'s syntax) and furthermore use
2825 @code{AC_SUBST} to ensure that @samp{$@{file@}} is meaningful in a
2826 @file{Makefile}, then @command{automake} will be able to use
2827 @samp{$@{file@}} to generate all these rules.  For instance, here is
2828 how the Automake package itself generates versioned scripts for its
2829 test suite:
2830
2831 @example
2832 AC_SUBST([APIVERSION], @dots{})
2833 @dots{}
2834 AC_CONFIG_FILES(
2835   [tests/aclocal-$@{APIVERSION@}:tests/aclocal.in],
2836   [chmod +x tests/aclocal-$@{APIVERSION@}],
2837   [APIVERSION=$APIVERSION])
2838 AC_CONFIG_FILES(
2839   [tests/automake-$@{APIVERSION@}:tests/automake.in],
2840   [chmod +x tests/automake-$@{APIVERSION@}])
2841 @end example
2842
2843 @noindent
2844 Here cleaning, distributing, and rebuilding are done automatically,
2845 because @samp{$@{APIVERSION@}} is known at @command{make}-time.
2846
2847 Note that you should not use shell variables to declare
2848 @file{Makefile} files for which @command{automake} must create
2849 @file{Makefile.in}.  Even @code{AC_SUBST} does not help here, because
2850 @command{automake} needs to know the file name when it runs in order
2851 to check whether @file{Makefile.am} exists.  (In the very hairy case
2852 that your setup requires such use of variables, you will have to tell
2853 Automake which @file{Makefile.in}s to generate on the command-line.)
2854
2855 It is possible to let @command{automake} emit conditional rules for
2856 @code{AC_CONFIG_FILES} with the help of @code{AM_COND_IF}
2857 (@pxref{Optional}).
2858
2859 To summarize:
2860 @itemize @bullet
2861 @item
2862 Use literals for @file{Makefile}s, and for other files whenever possible.
2863 @item
2864 Use @samp{$file} (or @samp{$@{file@}} without @samp{AC_SUBST([file])})
2865 for files that @command{automake} should ignore.
2866 @item
2867 Use @samp{$@{file@}} and @samp{AC_SUBST([file])} for files
2868 that @command{automake} should not ignore.
2869 @end itemize
2870
2871 @end table
2872
2873
2874 @node Optional
2875 @section Other things Automake recognizes
2876
2877 @cindex Macros Automake recognizes
2878 @cindex Recognized macros by Automake
2879
2880 Every time Automake is run it calls Autoconf to trace
2881 @file{configure.ac}.  This way it can recognize the use of certain
2882 macros and tailor the generated @file{Makefile.in} appropriately.
2883 Currently recognized macros and their effects are:
2884
2885 @ftable @code
2886 @item AC_CANONICAL_BUILD
2887 @itemx AC_CANONICAL_HOST
2888 @itemx AC_CANONICAL_TARGET
2889 @vindex build_triplet
2890 @vindex host_triplet
2891 @vindex target_triplet
2892 Automake will ensure that @file{config.guess} and @file{config.sub}
2893 exist.  Also, the @file{Makefile} variables @code{build_triplet},
2894 @code{host_triplet} and @code{target_triplet} are introduced.  See
2895 @ref{Canonicalizing, , Getting the Canonical System Type, autoconf,
2896 The Autoconf Manual}.
2897
2898 @item AC_CONFIG_AUX_DIR
2899 Automake will look for various helper scripts, such as
2900 @file{install-sh}, in the directory named in this macro invocation.
2901 @c This list is accurate relative to version 1.8
2902 (The full list of scripts is: @file{config.guess}, @file{config.sub},
2903 @file{depcomp}, @file{elisp-comp}, @file{compile}, @file{install-sh},
2904 @file{ltmain.sh}, @file{mdate-sh}, @file{missing}, @file{mkinstalldirs},
2905 @file{py-compile}, @file{texinfo.tex}, and @file{ylwrap}.)  Not all
2906 scripts are always searched for; some scripts will only be sought if the
2907 generated @file{Makefile.in} requires them.
2908
2909 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
2910 their standard locations.  For @file{mdate-sh},
2911 @file{texinfo.tex}, and @file{ylwrap}, the standard location is the
2912 source directory corresponding to the current @file{Makefile.am}.  For
2913 the rest, the standard location is the first one of @file{.}, @file{..},
2914 or @file{../..} (relative to the top source directory) that provides any
2915 one of the helper scripts.  @xref{Input, , Finding `configure' Input,
2916 autoconf, The Autoconf Manual}.
2917
2918 Required files from @code{AC_CONFIG_AUX_DIR} are automatically
2919 distributed, even if there is no @file{Makefile.am} in this directory.
2920
2921 @item AC_CONFIG_LIBOBJ_DIR
2922 Automake will require the sources file declared with
2923 @code{AC_LIBSOURCE} (see below) in the directory specified by this
2924 macro.
2925
2926 @item AC_CONFIG_HEADERS
2927 Automake will generate rules to rebuild these headers.  Older versions
2928 of Automake required the use of @code{AM_CONFIG_HEADER}
2929 (@pxref{Macros}); this is no longer the case.
2930
2931 As with @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2932 specification using shell variables will be ignored as far as
2933 cleaning, distributing, and rebuilding is concerned.
2934
2935 @item AC_CONFIG_LINKS
2936 Automake will generate rules to remove @file{configure} generated
2937 links on @samp{make distclean} and to distribute named source files as
2938 part of @samp{make dist}.
2939
2940 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2941 specification using shell variables will be ignored as far as cleaning
2942 and distributing is concerned.  (There are no rebuild rules for links.)
2943
2944 @item AC_LIBOBJ
2945 @itemx AC_LIBSOURCE
2946 @itemx AC_LIBSOURCES
2947 @vindex LIBOBJS
2948 Automake will automatically distribute any file listed in
2949 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
2950
2951 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}.  So if
2952 an Autoconf macro is documented to call @samp{AC_LIBOBJ([file])}, then
2953 @file{file.c} will be distributed automatically by Automake.  This
2954 encompasses many macros like @code{AC_FUNC_ALLOCA},
2955 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
2956
2957 By the way, direct assignments to @code{LIBOBJS} are no longer
2958 supported.  You should always use @code{AC_LIBOBJ} for this purpose.
2959 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
2960 autoconf, The Autoconf Manual}.
2961
2962 @item AC_PROG_RANLIB
2963 This is required if any libraries are built in the package.
2964 @xref{Particular Programs, , Particular Program Checks, autoconf, The
2965 Autoconf Manual}.
2966
2967 @item AC_PROG_CXX
2968 This is required if any C++ source is included.  @xref{Particular
2969 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2970
2971 @item AC_PROG_OBJC
2972 This is required if any Objective C source is included.  @xref{Particular
2973 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2974
2975 @item AC_PROG_F77
2976 This is required if any Fortran 77 source is included.  This macro is
2977 distributed with Autoconf version 2.13 and later.  @xref{Particular
2978 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2979
2980 @item AC_F77_LIBRARY_LDFLAGS
2981 This is required for programs and shared libraries that are a mixture of
2982 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
2983 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
2984
2985 @item AC_FC_SRCEXT
2986 Automake will add the flags computed by @code{AC_FC_SRCEXT} to compilation
2987 of files with the respective source extension (@pxref{Fortran Compiler, ,
2988 Fortran Compiler Characteristics, autoconf, The Autoconf Manual}).
2989
2990 @item AC_PROG_FC
2991 This is required if any Fortran 90/95 source is included.  This macro is
2992 distributed with Autoconf version 2.58 and later.  @xref{Particular
2993 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2994
2995 @item AC_PROG_LIBTOOL
2996 Automake will turn on processing for @command{libtool} (@pxref{Top, ,
2997 Introduction, libtool, The Libtool Manual}).
2998
2999 @item AC_PROG_YACC
3000 @vindex YACC
3001 If a Yacc source file is seen, then you must either use this macro or
3002 define the variable @code{YACC} in @file{configure.ac}.  The former is
3003 preferred (@pxref{Particular Programs, , Particular Program Checks,
3004 autoconf, The Autoconf Manual}).
3005
3006 @item AC_PROG_LEX
3007 If a Lex source file is seen, then this macro must be used.
3008 @xref{Particular Programs, , Particular Program Checks, autoconf, The
3009 Autoconf Manual}.
3010
3011 @item AC_REQUIRE_AUX_FILE
3012 For each @code{AC_REQUIRE_AUX_FILE([@var{file}])},
3013 @command{automake} will ensure that @file{@var{file}} exists in the
3014 aux directory, and will complain otherwise.  It
3015 will also automatically distribute the file.  This macro should be
3016 used by third-party Autoconf macros that require some supporting
3017 files in the aux directory specified with @code{AC_CONFIG_AUX_DIR}
3018 above.  @xref{Input, , Finding @command{configure} Input, autoconf,
3019 The Autoconf Manual}.
3020
3021 @item AC_SUBST
3022 The first argument is automatically defined as a variable in each
3023 generated @file{Makefile.in}, unless @code{AM_SUBST_NOTMAKE} is also
3024 used for this variable.  @xref{Setting Output Variables, , Setting
3025 Output Variables, autoconf, The Autoconf Manual}.
3026
3027 For every substituted variable @var{var}, @command{automake} will add
3028 a line @code{@var{var} = @var{value}} to each @file{Makefile.in} file.
3029 Many Autoconf macros invoke @code{AC_SUBST} to set output variables
3030 this way, e.g., @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and
3031 @code{X_LIBS}.  Thus, you can access these variables as
3032 @code{$(X_CFLAGS)} and @code{$(X_LIBS)} in any @file{Makefile.am}
3033 if @code{AC_PATH_XTRA} is called.
3034
3035 @item AM_C_PROTOTYPES
3036 This is required when using the deprecated de-ANSI-fication feature;
3037 @pxref{ANSI}.  @emph{It will be removed} in the next major Automake
3038 release.
3039
3040 @item AM_CONDITIONAL
3041 This introduces an Automake conditional (@pxref{Conditionals}).
3042
3043 @item AM_COND_IF
3044 This macro allows @code{automake} to detect subsequent access within
3045 @file{configure.ac} to a conditional previously introduced with
3046 @code{AM_CONDITIONAL}, thus enabling conditional @code{AC_CONFIG_FILES}
3047 (@pxref{Usage of Conditionals}).
3048
3049 @item AM_GNU_GETTEXT
3050 This macro is required for packages that use GNU gettext
3051 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
3052 this macro it ensures that the package meets some of gettext's
3053 requirements.
3054
3055 @item AM_GNU_GETTEXT_INTL_SUBDIR
3056 This macro specifies that the @file{intl/} subdirectory is to be built,
3057 even if the @code{AM_GNU_GETTEXT} macro was invoked with a first argument
3058 of @samp{external}.
3059
3060 @item AM_MAINTAINER_MODE(@ovar{default-mode})
3061 @opindex --enable-maintainer-mode
3062 @opindex --disable-maintainer-mode
3063 This macro adds an @option{--enable-maintainer-mode} option to
3064 @command{configure}.  If this is used, @command{automake} will cause
3065 ``maintainer-only'' rules to be turned off by default in the
3066 generated @file{Makefile.in}s, unless @var{default-mode} is
3067 @samp{enable}.  This macro defines the @code{MAINTAINER_MODE}
3068 conditional, which you can use in your own @file{Makefile.am}.
3069 @xref{maintainer-mode}.
3070
3071 @item AM_SUBST_NOTMAKE(@var{var})
3072 Prevent Automake from defining a variable @var{var}, even if it is
3073 substituted by @command{config.status}.  Normally, Automake defines a
3074 @command{make} variable for each @command{configure} substitution,
3075 i.e., for each @code{AC_SUBST([@var{var}])}.  This macro prevents that
3076 definition from Automake.  If @code{AC_SUBST} has not been called
3077 for this variable, then @code{AM_SUBST_NOTMAKE} has no effects.
3078 Preventing variable definitions may be useful for substitution of
3079 multi-line values, where @code{@var{var} = @@@var{value}@@} might yield
3080 unintended results.
3081
3082 @item m4_include
3083 Files included by @file{configure.ac} using this macro will be
3084 detected by Automake and automatically distributed.  They will also
3085 appear as dependencies in @file{Makefile} rules.
3086
3087 @code{m4_include} is seldom used by @file{configure.ac} authors, but
3088 can appear in @file{aclocal.m4} when @command{aclocal} detects that
3089 some required macros come from files local to your package (as opposed
3090 to macros installed in a system-wide directory, @pxref{Invoking
3091 aclocal}).
3092
3093 @end ftable
3094
3095
3096 @node Invoking aclocal
3097 @section Auto-generating aclocal.m4
3098
3099 @cindex Invoking @command{aclocal}
3100 @cindex @command{aclocal}, Invoking
3101
3102 Automake includes a number of Autoconf macros that can be used in
3103 your package (@pxref{Macros}); some of them are actually required by
3104 Automake in certain situations.  These macros must be defined in your
3105 @file{aclocal.m4}; otherwise they will not be seen by
3106 @command{autoconf}.
3107
3108 The @command{aclocal} program will automatically generate
3109 @file{aclocal.m4} files based on the contents of @file{configure.ac}.
3110 This provides a convenient way to get Automake-provided macros,
3111 without having to search around.  The @command{aclocal} mechanism
3112 allows other packages to supply their own macros (@pxref{Extending
3113 aclocal}).  You can also use it to maintain your own set of custom
3114 macros (@pxref{Local Macros}).
3115
3116 At startup, @command{aclocal} scans all the @file{.m4} files it can
3117 find, looking for macro definitions (@pxref{Macro Search Path}).  Then
3118 it scans @file{configure.ac}.  Any mention of one of the macros found
3119 in the first step causes that macro, and any macros it in turn
3120 requires, to be put into @file{aclocal.m4}.
3121
3122 @emph{Putting} the file that contains the macro definition into
3123 @file{aclocal.m4} is usually done by copying the entire text of this
3124 file, including unused macro definitions as well as both @samp{#} and
3125 @samp{dnl} comments.  If you want to make a comment that will be
3126 completely ignored by @command{aclocal}, use @samp{##} as the comment
3127 leader.
3128
3129 When a file selected by @command{aclocal} is located in a subdirectory
3130 specified as a relative search path with @command{aclocal}'s @option{-I}
3131 argument, @command{aclocal} assumes the file belongs to the package
3132 and uses @code{m4_include} instead of copying it into
3133 @file{aclocal.m4}.  This makes the package smaller, eases dependency
3134 tracking, and cause the file to be distributed automatically.
3135 (@xref{Local Macros}, for an example.)  Any macro that is found in a
3136 system-wide directory, or via an absolute search path will be copied.
3137 So use @samp{-I `pwd`/reldir} instead of @samp{-I reldir} whenever
3138 some relative directory should be considered outside the package.
3139
3140 The contents of @file{acinclude.m4}, if this file exists, are also
3141 automatically included in @file{aclocal.m4}.  We recommend against
3142 using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
3143
3144 @vindex AUTOM4TE
3145 @cindex autom4te
3146 While computing @file{aclocal.m4}, @command{aclocal} runs
3147 @command{autom4te} (@pxref{Using autom4te, , Using @command{Autom4te},
3148 autoconf, The Autoconf Manual}) in order to trace the macros that are
3149 really used, and omit from @file{aclocal.m4} all macros that are
3150 mentioned but otherwise unexpanded (this can happen when a macro is
3151 called conditionally).  @command{autom4te} is expected to be in the
3152 @env{PATH}, just as @command{autoconf}.  Its location can be
3153 overridden using the @env{AUTOM4TE} environment variable.
3154
3155 @menu
3156 * aclocal Options::             Options supported by aclocal
3157 * Macro Search Path::           How aclocal finds .m4 files
3158 * Extending aclocal::           Writing your own aclocal macros
3159 * Local Macros::                Organizing local macros
3160 * Serials::                     Serial lines in Autoconf macros
3161 * Future of aclocal::           aclocal's scheduled death
3162 @end menu
3163
3164 @node aclocal Options
3165 @subsection aclocal Options
3166
3167 @cindex @command{aclocal}, Options
3168 @cindex Options, @command{aclocal}
3169
3170 @command{aclocal} accepts the following options:
3171
3172 @table @code
3173 @item --acdir=@var{dir}
3174 @opindex --acdir
3175 Look for the macro files in @var{dir} instead of the installation
3176 directory.  This is typically used for debugging.
3177
3178 @item --diff[=@var{command}]
3179 @opindex --diff
3180 Run @var{command} on M4 file that would be installed or overwritten
3181 by @option{--install}.  The default @var{command} is @samp{diff -u}.
3182 This option implies @option{--install} and @option{--dry-run}.
3183
3184 @item --dry-run
3185 @opindex --dry-run
3186 Do not actually overwrite (or create) @file{aclocal.m4} and M4
3187 files installed by @option{--install}.
3188
3189 @item --help
3190 @opindex --help
3191 Print a summary of the command line options and exit.
3192
3193 @item -I @var{dir}
3194 @opindex -I
3195 Add the directory @var{dir} to the list of directories searched for
3196 @file{.m4} files.
3197
3198 @item --install
3199 @opindex --install
3200 Install system-wide third-party macros into the first directory
3201 specified with @samp{-I @var{dir}} instead of copying them in the
3202 output file.
3203
3204 @cindex serial number and @option{--install}
3205 When this option is used, and only when this option is used,
3206 @command{aclocal} will also honor @samp{#serial @var{number}} lines
3207 that appear in macros: an M4 file is ignored if there exists another
3208 M4 file with the same basename and a greater serial number in the
3209 search path (@pxref{Serials}).
3210
3211 @item --force
3212 @opindex --force
3213 Always overwrite the output file.  The default is to overwrite the output
3214 file only when really needed, i.e., when its contents changes or if one
3215 of its dependencies is younger.
3216
3217 This option forces the update of @file{aclocal.m4} (or the file
3218 specified with @file{--output} below) and only this file, it has
3219 absolutely no influence on files that may need to be installed by
3220 @option{--install}.
3221
3222 @item --output=@var{file}
3223 @opindex --output
3224 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
3225
3226 @item --print-ac-dir
3227 @opindex --print-ac-dir
3228 Prints the name of the directory that @command{aclocal} will search to
3229 find third-party @file{.m4} files.  When this option is given, normal
3230 processing is suppressed.  This option can be used by a package to
3231 determine where to install a macro file.
3232
3233 @item --verbose
3234 @opindex --verbose
3235 Print the names of the files it examines.
3236
3237 @item --version
3238 @opindex --version
3239 Print the version number of Automake and exit.
3240
3241 @item -W CATEGORY
3242 @item --warnings=@var{category}
3243 @opindex -W
3244 @opindex --warnings
3245 Output warnings falling in @var{category}.  @var{category} can be
3246 one of:
3247 @table @code
3248 @item syntax
3249 dubious syntactic constructs, underquoted macros, unused macros, etc.
3250 @item unsupported
3251 unknown macros
3252 @item all
3253 all the warnings, this is the default
3254 @item none
3255 turn off all the warnings
3256 @item error
3257 treat warnings as errors
3258 @end table
3259
3260 All warnings are output by default.
3261
3262 @vindex WARNINGS
3263 The environment variable @env{WARNINGS} is honored in the same
3264 way as it is for @command{automake} (@pxref{Invoking Automake}).
3265
3266 @end table
3267
3268 @node Macro Search Path
3269 @subsection Macro Search Path
3270
3271 @cindex Macro search path
3272 @cindex @command{aclocal} search path
3273
3274 By default, @command{aclocal} searches for @file{.m4} files in the following
3275 directories, in this order:
3276
3277 @table @code
3278 @item @var{acdir-APIVERSION}
3279 This is where the @file{.m4} macros distributed with Automake itself
3280 are stored.  @var{APIVERSION} depends on the Automake release used;
3281 for Automake 1.6.x, @var{APIVERSION} = @code{1.6}.
3282
3283 @item @var{acdir}
3284 This directory is intended for third party @file{.m4} files, and is
3285 configured when @command{automake} itself is built.  This is
3286 @file{@@datadir@@/aclocal/}, which typically
3287 expands to @file{$@{prefix@}/share/aclocal/}.  To find the compiled-in
3288 value of @var{acdir}, use the @option{--print-ac-dir} option
3289 (@pxref{aclocal Options}).
3290 @end table
3291
3292 As an example, suppose that @command{automake-1.6.2} was configured with
3293 @option{--prefix=@-/usr/local}.  Then, the search path would be:
3294
3295 @enumerate
3296 @item @file{/usr/local/share/aclocal-1.6/}
3297 @item @file{/usr/local/share/aclocal/}
3298 @end enumerate
3299
3300 As explained in (@pxref{aclocal Options}), there are several options that
3301 can be used to change or extend this search path.
3302
3303 @subsubheading Modifying the Macro Search Path: @option{--acdir}
3304
3305 The most erroneous option to modify the search path is
3306 @option{--acdir=@var{dir}}, which changes default directory and
3307 drops the @var{APIVERSION} directory.  For example, if one specifies
3308 @samp{--acdir=/opt/private/}, then the search path becomes:
3309
3310 @enumerate
3311 @item @file{/opt/private/}
3312 @end enumerate
3313
3314 This option, @option{--acdir}, is intended for use by the internal
3315 Automake test suite only; it is not ordinarily needed by end-users.
3316
3317 @subsubheading Modifying the Macro Search Path: @samp{-I @var{dir}}
3318
3319 Any extra directories specified using @option{-I} options
3320 (@pxref{aclocal Options}) are @emph{prepended} to this search list.  Thus,
3321 @samp{aclocal -I /foo -I /bar} results in the following search path:
3322
3323 @enumerate
3324 @item @file{/foo}
3325 @item @file{/bar}
3326 @item @var{acdir}-@var{APIVERSION}
3327 @item @var{acdir}
3328 @end enumerate
3329
3330 @subsubheading Modifying the Macro Search Path: @file{dirlist}
3331 @cindex @file{dirlist}
3332
3333 There is a third mechanism for customizing the search path.  If a
3334 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
3335 contain a list of directory patterns, one per line.  @command{aclocal}
3336 expands these patterns to directory names, and adds them to the search
3337 list @emph{after} all other directories.  @file{dirlist} entries may
3338 use shell wildcards such as @samp{*}, @samp{?}, or @code{[...]}.
3339
3340 For example, suppose
3341 @file{@var{acdir}/dirlist} contains the following:
3342
3343 @example
3344 /test1
3345 /test2
3346 /test3*
3347 @end example
3348
3349 @noindent
3350 and that @command{aclocal} was called with the @samp{-I /foo -I /bar} options.
3351 Then, the search path would be
3352
3353 @c @code looks better than @file here
3354 @enumerate
3355 @item @code{/foo}
3356 @item @code{/bar}
3357 @item @var{acdir}-@var{APIVERSION}
3358 @item @var{acdir}
3359 @item @code{/test1}
3360 @item @code{/test2}
3361 @end enumerate
3362
3363 @noindent
3364 and all directories with path names starting with @code{/test3}.
3365
3366 If the @option{--acdir=@var{dir}} option is used, then @command{aclocal}
3367 will search for the @file{dirlist} file in @var{dir}.  In the
3368 @samp{--acdir=/opt/private/} example above, @command{aclocal} would look
3369 for @file{/opt/private/dirlist}.  Again, however, the @option{--acdir}
3370 option is intended for use by the internal Automake test suite only;
3371 @option{--acdir} is not ordinarily needed by end-users.
3372
3373 @file{dirlist} is useful in the following situation: suppose that
3374 @command{automake} version @code{1.6.2} is installed with
3375 @samp{--prefix=/usr} by the system vendor.  Thus, the default search
3376 directories are
3377
3378 @c @code looks better than @file here
3379 @enumerate
3380 @item @code{/usr/share/aclocal-1.6/}
3381 @item @code{/usr/share/aclocal/}
3382 @end enumerate
3383
3384 However, suppose further that many packages have been manually
3385 installed on the system, with $prefix=/usr/local, as is typical.  In
3386 that case, many of these ``extra'' @file{.m4} files are in
3387 @file{/usr/local/share/aclocal}.  The only way to force
3388 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files is to
3389 always call @samp{aclocal -I /usr/local/share/aclocal}.  This is
3390 inconvenient.  With @file{dirlist}, one may create a file
3391 @file{/usr/share/aclocal/dirlist} containing only the single line
3392
3393 @example
3394 /usr/local/share/aclocal
3395 @end example
3396
3397 Now, the ``default'' search path on the affected system is
3398
3399 @c @code looks better than @file here
3400 @enumerate
3401 @item @code{/usr/share/aclocal-1.6/}
3402 @item @code{/usr/share/aclocal/}
3403 @item @code{/usr/local/share/aclocal/}
3404 @end enumerate
3405
3406 without the need for @option{-I} options; @option{-I} options can be reserved
3407 for project-specific needs (@file{my-source-dir/m4/}), rather than
3408 using it to work around local system-dependent tool installation
3409 directories.
3410
3411 Similarly, @file{dirlist} can be handy if you have installed a local
3412 copy of Automake in your account and want @command{aclocal} to look for
3413 macros installed at other places on the system.
3414
3415
3416 @node Extending aclocal
3417 @subsection Writing your own aclocal macros
3418
3419 @cindex @command{aclocal}, extending
3420 @cindex Extending @command{aclocal}
3421
3422 The @command{aclocal} program doesn't have any built-in knowledge of any
3423 macros, so it is easy to extend it with your own macros.
3424
3425 This can be used by libraries that want to supply their own Autoconf
3426 macros for use by other programs.  For instance, the @command{gettext}
3427 library supplies a macro @code{AM_GNU_GETTEXT} that should be used by
3428 any package using @command{gettext}.  When the library is installed, it
3429 installs this macro so that @command{aclocal} will find it.
3430
3431 A macro file's name should end in @file{.m4}.  Such files should be
3432 installed in @file{$(datadir)/aclocal}.  This is as simple as writing:
3433
3434 @c Keep in sync with primary-prefix-couples-documented-valid.test.
3435 @example
3436 aclocaldir = $(datadir)/aclocal
3437 aclocal_DATA = mymacro.m4 myothermacro.m4
3438 @end example
3439
3440 @noindent
3441 Please do use @file{$(datadir)/aclocal}, and not something based on
3442 the result of @samp{aclocal --print-ac-dir}.  @xref{Hard-Coded Install
3443 Paths}, for arguments.
3444
3445 A file of macros should be a series of properly quoted
3446 @code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
3447 Autoconf Manual}).  The @command{aclocal} programs also understands
3448 @code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
3449 Autoconf Manual}), so it is safe to put each macro in a separate file.
3450 Each file should have no side effects but macro definitions.
3451 Especially, any call to @code{AC_PREREQ} should be done inside the
3452 defined macro, not at the beginning of the file.
3453
3454 @cindex underquoted @code{AC_DEFUN}
3455 @acindex AC_DEFUN
3456 @acindex AC_PREREQ
3457
3458 Starting with Automake 1.8, @command{aclocal} will warn about all
3459 underquoted calls to @code{AC_DEFUN}.  We realize this will annoy a
3460 lot of people, because @command{aclocal} was not so strict in the past
3461 and many third party macros are underquoted; and we have to apologize
3462 for this temporary inconvenience.  The reason we have to be stricter
3463 is that a future implementation of @command{aclocal} (@pxref{Future of
3464 aclocal}) will have to temporarily include all these third party
3465 @file{.m4} files, maybe several times, including even files that are
3466 not actually needed.  Doing so should alleviate many problems of the
3467 current implementation, however it requires a stricter style from the
3468 macro authors.  Hopefully it is easy to revise the existing macros.
3469 For instance,
3470
3471 @example
3472 # bad style
3473 AC_PREREQ(2.57)
3474 AC_DEFUN(AX_FOOBAR,
3475 [AC_REQUIRE([AX_SOMETHING])dnl
3476 AX_FOO
3477 AX_BAR
3478 ])
3479 @end example
3480
3481 @noindent
3482 should be rewritten as
3483
3484 @example
3485 AC_DEFUN([AX_FOOBAR],
3486 [AC_PREREQ([2.57])dnl
3487 AC_REQUIRE([AX_SOMETHING])dnl
3488 AX_FOO
3489 AX_BAR
3490 ])
3491 @end example
3492
3493 Wrapping the @code{AC_PREREQ} call inside the macro ensures that
3494 Autoconf 2.57 will not be required if @code{AX_FOOBAR} is not actually
3495 used.  Most importantly, quoting the first argument of @code{AC_DEFUN}
3496 allows the macro to be redefined or included twice (otherwise this
3497 first argument would be expanded during the second definition).  For
3498 consistency we like to quote even arguments such as @code{2.57} that
3499 do not require it.
3500
3501 If you have been directed here by the @command{aclocal} diagnostic but
3502 are not the maintainer of the implicated macro, you will want to
3503 contact the maintainer of that macro.  Please make sure you have the
3504 latest version of the macro and that the problem hasn't already been
3505 reported before doing so: people tend to work faster when they aren't
3506 flooded by mails.
3507
3508 Another situation where @command{aclocal} is commonly used is to
3509 manage macros that are used locally by the package, @ref{Local
3510 Macros}.
3511
3512 @node Local Macros
3513 @subsection Handling Local Macros
3514
3515 Feature tests offered by Autoconf do not cover all needs.  People
3516 often have to supplement existing tests with their own macros, or
3517 with third-party macros.
3518
3519 There are two ways to organize custom macros in a package.
3520
3521 The first possibility (the historical practice) is to list all your
3522 macros in @file{acinclude.m4}.  This file will be included in
3523 @file{aclocal.m4} when you run @command{aclocal}, and its macro(s) will
3524 henceforth be visible to @command{autoconf}.  However if it contains
3525 numerous macros, it will rapidly become difficult to maintain, and it
3526 will be almost impossible to share macros between packages.
3527
3528 @vindex ACLOCAL_AMFLAGS
3529 The second possibility, which we do recommend, is to write each macro
3530 in its own file and gather all these files in a directory.  This
3531 directory is usually called @file{m4/}.  To build @file{aclocal.m4},
3532 one should therefore instruct @command{aclocal} to scan @file{m4/}.
3533 From the command line, this is done with @samp{aclocal -I m4}.  The
3534 top-level @file{Makefile.am} should also be updated to define
3535
3536 @example
3537 ACLOCAL_AMFLAGS = -I m4
3538 @end example
3539
3540 @code{ACLOCAL_AMFLAGS} contains options to pass to @command{aclocal}
3541 when @file{aclocal.m4} is to be rebuilt by @command{make}.  This line is
3542 also used by @command{autoreconf} (@pxref{autoreconf Invocation, ,
3543 Using @command{autoreconf} to Update @file{configure} Scripts,
3544 autoconf, The Autoconf Manual}) to run @command{aclocal} with suitable
3545 options, or by @command{autopoint} (@pxref{autopoint Invocation, ,
3546 Invoking the @command{autopoint} Program, gettext, GNU gettext tools})
3547 and @command{gettextize} (@pxref{gettextize Invocation, , Invoking the
3548 @command{gettextize} Program, gettext, GNU gettext tools}) to locate
3549 the place where Gettext's macros should be installed.  So even if you
3550 do not really care about the rebuild rules, you should define
3551 @code{ACLOCAL_AMFLAGS}.
3552
3553 When @samp{aclocal -I m4} is run, it will build an @file{aclocal.m4}
3554 that @code{m4_include}s any file from @file{m4/} that defines a
3555 required macro.  Macros not found locally will still be searched in
3556 system-wide directories, as explained in @ref{Macro Search Path}.
3557
3558 Custom macros should be distributed for the same reason that
3559 @file{configure.ac} is: so that other people have all the sources of
3560 your package if they want to work on it.  Actually, this distribution
3561 happens automatically because all @code{m4_include}d files are
3562 distributed.
3563
3564 However there is no consensus on the distribution of third-party
3565 macros that your package may use.  Many libraries install their own
3566 macro in the system-wide @command{aclocal} directory (@pxref{Extending
3567 aclocal}).  For instance, Guile ships with a file called
3568 @file{guile.m4} that contains the macro @code{GUILE_FLAGS} that can
3569 be used to define setup compiler and linker flags appropriate for
3570 using Guile.  Using @code{GUILE_FLAGS} in @file{configure.ac} will
3571 cause @command{aclocal} to copy @file{guile.m4} into
3572 @file{aclocal.m4}, but as @file{guile.m4} is not part of the project,
3573 it will not be distributed.  Technically, that means a user who
3574 needs to rebuild @file{aclocal.m4} will have to install Guile first.
3575 This is probably OK, if Guile already is a requirement to build the
3576 package.  However, if Guile is only an optional feature, or if your
3577 package might run on architectures where Guile cannot be installed,
3578 this requirement will hinder development.  An easy solution is to copy
3579 such third-party macros in your local @file{m4/} directory so they get
3580 distributed.
3581
3582 Since Automake 1.10, @command{aclocal} offers an option to copy these
3583 system-wide third-party macros in your local macro directory, solving
3584 the above problem.  Simply use:
3585
3586 @example
3587 ACLOCAL_AMFLAGS = -I m4 --install
3588 @end example
3589
3590 @noindent
3591 With this setup, system-wide macros will be copied to @file{m4/}
3592 the first time you run @command{autoreconf}.  Then the locally
3593 installed macros will have precedence over the system-wide installed
3594 macros each time @command{aclocal} is run again.
3595
3596 One reason why you should keep @option{--install} in the flags even
3597 after the first run is that when you later edit @file{configure.ac}
3598 and depend on a new macro, this macro will be installed in your
3599 @file{m4/} automatically.  Another one is that serial numbers
3600 (@pxref{Serials}) can be used to update the macros in your source tree
3601 automatically when new system-wide versions are installed.  A serial
3602 number should be a single line of the form
3603
3604 @example
3605 #serial @var{nnn}
3606 @end example
3607
3608 @noindent
3609 where @var{nnn} contains only digits and dots.  It should appear in
3610 the M4 file before any macro definition.  It is a good practice to
3611 maintain a serial number for each macro you distribute, even if you do
3612 not use the @option{--install} option of @command{aclocal}: this allows
3613 other people to use it.
3614
3615
3616 @node Serials
3617 @subsection Serial Numbers
3618 @cindex serial numbers in macros
3619 @cindex macro serial numbers
3620 @cindex @code{#serial} syntax
3621 @cindex @command{aclocal} and serial numbers
3622
3623 Because third-party macros defined in @file{*.m4} files are naturally
3624 shared between multiple projects, some people like to version them.
3625 This makes it easier to tell which of two M4 files is newer.  Since at
3626 least 1996, the tradition is to use a @samp{#serial} line for this.
3627
3628 A serial number should be a single line of the form
3629
3630 @example
3631 # serial @var{version}
3632 @end example
3633
3634 @noindent
3635 where @var{version} is a version number containing only digits and
3636 dots.  Usually people use a single integer, and they increment it each
3637 time they change the macro (hence the name of ``serial'').  Such a
3638 line should appear in the M4 file before any macro definition.
3639
3640 The @samp{#} must be the first character on the line,
3641 and it is OK to have extra words after the version, as in
3642
3643 @example
3644 #serial @var{version} @var{garbage}
3645 @end example
3646
3647 Normally these serial numbers are completely ignored by
3648 @command{aclocal} and @command{autoconf}, like any genuine comment.
3649 However when using @command{aclocal}'s @option{--install} feature, these
3650 serial numbers will modify the way @command{aclocal} selects the
3651 macros to install in the package: if two files with the same basename
3652 exist in your search path, and if at least one of them uses a
3653 @samp{#serial} line, @command{aclocal} will ignore the file that has
3654 the older @samp{#serial} line (or the file that has none).
3655
3656 Note that a serial number applies to a whole M4 file, not to any macro
3657 it contains.  A file can contains multiple macros, but only one
3658 serial.
3659
3660 Here is a use case that illustrates the use of @option{--install} and
3661 its interaction with serial numbers.  Let's assume we maintain a
3662 package called MyPackage, the @file{configure.ac} of which requires a
3663 third-party macro @code{AX_THIRD_PARTY} defined in
3664 @file{/usr/share/aclocal/thirdparty.m4} as follows:
3665
3666 @example
3667 # serial 1
3668 AC_DEFUN([AX_THIRD_PARTY], [...])
3669 @end example
3670
3671 MyPackage uses an @file{m4/} directory to store local macros as
3672 explained in @ref{Local Macros}, and has
3673
3674 @example
3675 ACLOCAL_AMFLAGS = -I m4 --install
3676 @end example
3677
3678 @noindent
3679 in its top-level @file{Makefile.am}.
3680
3681 Initially the @file{m4/} directory is empty.  The first time we run
3682 @command{autoreconf}, it will fetch the options to pass to
3683 @command{aclocal} in @file{Makefile.am}, and run @samp{aclocal -I m4
3684 --install}.  @command{aclocal} will notice that
3685
3686 @itemize @bullet
3687 @item
3688 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3689 @item
3690 No local macros define @code{AX_THIRD_PARTY}
3691 @item
3692 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3693 with serial 1.
3694 @end itemize
3695
3696 @noindent
3697 Because @file{/usr/share/aclocal/thirdparty.m4} is a system-wide macro
3698 and @command{aclocal} was given the @option{--install} option, it will
3699 copy this file in @file{m4/thirdparty.m4}, and output an
3700 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3701
3702 The next time @samp{aclocal -I m4 --install} is run (either via
3703 @command{autoreconf}, by hand, or from the @file{Makefile} rebuild
3704 rules) something different happens.  @command{aclocal} notices that
3705
3706 @itemize @bullet
3707 @item
3708 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3709 @item
3710 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3711 with serial 1.
3712 @item
3713 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3714 with serial 1.
3715 @end itemize
3716
3717 @noindent
3718 Because both files have the same serial number, @command{aclocal} uses
3719 the first it found in its search path order (@pxref{Macro Search
3720 Path}).  @command{aclocal} therefore ignores
3721 @file{/usr/share/aclocal/thirdparty.m4} and outputs an
3722 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3723
3724 Local directories specified with @option{-I} are always searched before
3725 system-wide directories, so a local file will always be preferred to
3726 the system-wide file in case of equal serial numbers.
3727
3728 Now suppose the system-wide third-party macro is changed.  This can
3729 happen if the package installing this macro is updated.  Let's suppose
3730 the new macro has serial number 2.  The next time @samp{aclocal -I m4
3731 --install} is run the situation is the following:
3732
3733 @itemize @bullet
3734 @item
3735 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3736 @item
3737 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3738 with serial 1.
3739 @item
3740 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3741 with serial 2.
3742 @end itemize
3743
3744 @noindent
3745 When @command{aclocal} sees a greater serial number, it immediately
3746 forgets anything it knows from files that have the same basename and a
3747 smaller serial number.  So after it has found
3748 @file{/usr/share/aclocal/thirdparty.m4} with serial 2,
3749 @command{aclocal} will proceed as if it had never seen
3750 @file{m4/thirdparty.m4}.  This brings us back to a situation similar
3751 to that at the beginning of our example, where no local file defined
3752 the macro.  @command{aclocal} will install the new version of the
3753 macro in @file{m4/thirdparty.m4}, in this case overriding the old
3754 version.  MyPackage just had its macro updated as a side effect of
3755 running @command{aclocal}.
3756
3757 If you are leery of letting @command{aclocal} update your local macro,
3758 you can run @samp{aclocal -I m4 --diff} to review the changes
3759 @samp{aclocal -I m4 --install} would perform on these macros.
3760
3761 Finally, note that the @option{--force} option of @command{aclocal} has
3762 absolutely no effect on the files installed by @option{--install}.  For
3763 instance, if you have modified your local macros, do not expect
3764 @option{--install --force} to replace the local macros by their
3765 system-wide versions.  If you want to do so, simply erase the local
3766 macros you want to revert, and run @samp{aclocal -I m4 --install}.
3767
3768
3769 @node Future of aclocal
3770 @subsection The Future of @command{aclocal}
3771 @cindex @command{aclocal}'s scheduled death
3772
3773 @command{aclocal} is expected to disappear.  This feature really
3774 should not be offered by Automake.  Automake should focus on
3775 generating @file{Makefile}s; dealing with M4 macros really is
3776 Autoconf's job.  The fact that some people install Automake just to use
3777 @command{aclocal}, but do not use @command{automake} otherwise is an
3778 indication of how that feature is misplaced.
3779
3780 The new implementation will probably be done slightly differently.
3781 For instance, it could enforce the @file{m4/}-style layout discussed in
3782 @ref{Local Macros}.
3783
3784 We have no idea when and how this will happen.  This has been
3785 discussed several times in the past, but someone still has to commit
3786 to that non-trivial task.
3787
3788 From the user point of view, @command{aclocal}'s removal might turn
3789 out to be painful.  There is a simple precaution that you may take to
3790 make that switch more seamless: never call @command{aclocal} yourself.
3791 Keep this guy under the exclusive control of @command{autoreconf} and
3792 Automake's rebuild rules.  Hopefully you won't need to worry about
3793 things breaking, when @command{aclocal} disappears, because everything
3794 will have been taken care of.  If otherwise you used to call
3795 @command{aclocal} directly yourself or from some script, you will
3796 quickly notice the change.
3797
3798 Many packages come with a script called @file{bootstrap.sh} or
3799 @file{autogen.sh}, that will just call @command{aclocal},
3800 @command{libtoolize}, @command{gettextize} or @command{autopoint},
3801 @command{autoconf}, @command{autoheader}, and @command{automake} in
3802 the right order.  Actually this is precisely what @command{autoreconf}
3803 can do for you.  If your package has such a @file{bootstrap.sh} or
3804 @file{autogen.sh} script, consider using @command{autoreconf}.  That
3805 should simplify its logic a lot (less things to maintain, yum!), it's
3806 even likely you will not need the script anymore, and more to the point
3807 you will not call @command{aclocal} directly anymore.
3808
3809 For the time being, third-party packages should continue to install
3810 public macros into @file{/usr/share/aclocal/}.  If @command{aclocal}
3811 is replaced by another tool it might make sense to rename the
3812 directory, but supporting @file{/usr/share/aclocal/} for backward
3813 compatibility should be really easy provided all macros are properly
3814 written (@pxref{Extending aclocal}).
3815
3816
3817
3818 @node Macros
3819 @section Autoconf macros supplied with Automake
3820
3821 Automake ships with several Autoconf macros that you can use from your
3822 @file{configure.ac}.  When you use one of them it will be included by
3823 @command{aclocal} in @file{aclocal.m4}.
3824
3825 @menu
3826 * Public Macros::               Macros that you can use.
3827 * Obsolete Macros::             Macros that you should stop using.
3828 * Private Macros::              Macros that you should not use.
3829 @end menu
3830
3831 @c consider generating the following subsections automatically from m4 files.
3832
3833 @node Public Macros
3834 @subsection Public Macros
3835
3836 @table @code
3837
3838 @item AM_ENABLE_MULTILIB
3839 @acindex AM_ENABLE_MULTILIB
3840 This is used when a ``multilib'' library is being built.  The first
3841 optional argument is the name of the @file{Makefile} being generated; it
3842 defaults to @samp{Makefile}.  The second optional argument is used to find
3843 the top source directory; it defaults to the empty string (generally
3844 this should not be used unless you are familiar with the internals).
3845 @xref{Multilibs}.
3846
3847 @item AM_INIT_AUTOMAKE([OPTIONS])
3848 @itemx AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
3849 @acindex AM_INIT_AUTOMAKE
3850 Runs many macros required for proper operation of the generated Makefiles.
3851
3852 @vindex AUTOMAKE_OPTIONS
3853 This macro has two forms, the first of which is preferred.
3854 In this form, @code{AM_INIT_AUTOMAKE} is called with a
3855 single argument: a space-separated list of Automake options that should
3856 be applied to every @file{Makefile.am} in the tree.  The effect is as if
3857 each option were listed in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
3858
3859 @acindex AC_INIT
3860 The second, deprecated, form of @code{AM_INIT_AUTOMAKE} has two required
3861 arguments: the package and the version number.  This form is
3862 obsolete because the @var{package} and @var{version} can be obtained
3863 from Autoconf's @code{AC_INIT} macro (which itself has an old and a new
3864 form).
3865
3866 If your @file{configure.ac} has:
3867
3868 @example
3869 AC_INIT([src/foo.c])
3870 AM_INIT_AUTOMAKE([mumble], [1.5])
3871 @end example
3872
3873 @noindent
3874 you can modernize it as follows:
3875
3876 @example
3877 AC_INIT([mumble], [1.5])
3878 AC_CONFIG_SRCDIR([src/foo.c])
3879 AM_INIT_AUTOMAKE
3880 @end example
3881
3882 Note that if you're upgrading your @file{configure.ac} from an earlier
3883 version of Automake, it is not always correct to simply move the
3884 package and version arguments from @code{AM_INIT_AUTOMAKE} directly to
3885 @code{AC_INIT}, as in the example above.  The first argument to
3886 @code{AC_INIT} should be the name of your package (e.g., @samp{GNU
3887 Automake}), not the tarball name (e.g., @samp{automake}) that you used
3888 to pass to @code{AM_INIT_AUTOMAKE}.  Autoconf tries to derive a
3889 tarball name from the package name, which should work for most but not
3890 all package names.  (If it doesn't work for yours, you can use the
3891 four-argument form of @code{AC_INIT} to provide the tarball name
3892 explicitly).
3893
3894 @cindex @code{PACKAGE}, prevent definition
3895 @cindex @code{VERSION}, prevent definition
3896 @opindex no-define
3897 By default this macro @code{AC_DEFINE}'s @code{PACKAGE} and
3898 @code{VERSION}.  This can be avoided by passing the @option{no-define}
3899 option, as in:
3900 @example
3901 AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
3902 @end example
3903 or by passing a third non-empty argument to the obsolete form.
3904
3905 @item AM_PATH_LISPDIR
3906 @acindex AM_PATH_LISPDIR
3907 @vindex EMACS
3908 @vindex lispdir
3909 Searches for the program @command{emacs}, and, if found, sets the
3910 output variable @code{lispdir} to the full path to Emacs' site-lisp
3911 directory.
3912
3913 Note that this test assumes the @command{emacs} found to be a version
3914 that supports Emacs Lisp (such as GNU Emacs or XEmacs).  Other
3915 emacsen can cause this test to hang (some, like old versions of
3916 MicroEmacs, start up in interactive mode, requiring @kbd{C-x C-c} to
3917 exit, which is hardly obvious for a non-emacs user).  In most cases,
3918 however, you should be able to use @kbd{C-c} to kill the test.  In
3919 order to avoid problems, you can set @env{EMACS} to ``no'' in the
3920 environment, or use the @option{--with-lispdir} option to
3921 @command{configure} to explicitly set the correct path (if you're sure
3922 you have an @command{emacs} that supports Emacs Lisp).
3923
3924 @item AM_PROG_AS
3925 @acindex AM_PROG_AS
3926 @vindex CCAS
3927 @vindex CCASFLAGS
3928 Use this macro when you have assembly code in your project.  This will
3929 choose the assembler for you (by default the C compiler) and set
3930 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
3931
3932 @item AM_PROG_CC_C_O
3933 @acindex AM_PROG_CC_C_O
3934 @acindex AC_PROG_CC_C_O
3935 This is like @code{AC_PROG_CC_C_O}, but it generates its results in
3936 the manner required by Automake.  You must use this instead of
3937 @code{AC_PROG_CC_C_O} when you need this functionality, that is, when
3938 using per-target flags or subdir-objects with C sources.
3939
3940 @item AM_PROG_LEX
3941 @acindex AM_PROG_LEX
3942 @acindex AC_PROG_LEX
3943 @cindex HP-UX 10, @command{lex} problems
3944 @cindex @command{lex} problems with HP-UX 10
3945 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
3946 Program Checks, autoconf, The Autoconf Manual}), but uses the
3947 @command{missing} script on systems that do not have @command{lex}.
3948 HP-UX 10 is one such system.
3949
3950 @item AM_PROG_GCJ
3951 @acindex AM_PROG_GCJ
3952 @vindex GCJ
3953 @vindex GCJFLAGS
3954 This macro finds the @command{gcj} program or causes an error.  It sets
3955 @code{GCJ} and @code{GCJFLAGS}.  @command{gcj} is the Java front-end to the
3956 GNU Compiler Collection.
3957
3958 @item AM_PROG_UPC([@var{compiler-search-list}])
3959 @acindex AM_PROG_UPC
3960 @vindex UPC
3961 Find a compiler for Unified Parallel C and define the @code{UPC}
3962 variable.  The default @var{compiler-search-list} is @samp{upcc upc}.
3963 This macro will abort @command{configure} if no Unified Parallel C
3964 compiler is found.
3965
3966 @item AM_SILENT_RULES
3967 @acindex AM_SILENT_RULES
3968 Enable the machinery for less verbose build output (@pxref{Options}).
3969
3970 @item AM_WITH_DMALLOC
3971 @acindex AM_WITH_DMALLOC
3972 @cindex @command{dmalloc}, support for
3973 @vindex WITH_DMALLOC
3974 @opindex --with-dmalloc
3975 Add support for the @uref{http://dmalloc.com/, Dmalloc package}.  If
3976 the user runs @command{configure} with @option{--with-dmalloc}, then
3977 define @code{WITH_DMALLOC} and add @option{-ldmalloc} to @code{LIBS}.
3978
3979 @item AM_WITH_REGEX
3980 @acindex AM_WITH_REGEX
3981 @vindex WITH_REGEX
3982 @opindex --with-regex
3983 @cindex regex package
3984 @cindex rx package
3985 Adds @option{--with-regex} to the @command{configure} command line.  If
3986 specified (the default), then the @samp{regex} regular expression
3987 library is used, @file{regex.o} is put into @code{LIBOBJS}, and
3988 @code{WITH_REGEX} is defined.  If @option{--without-regex} is given, then
3989 the @code{rx} regular expression library is used, and @file{rx.o} is put
3990 into @code{LIBOBJS}.
3991
3992 @end table
3993
3994
3995 @node Obsolete Macros
3996 @subsection Obsolete Macros
3997 @cindex obsolete macros
3998 @cindex autoupdate
3999
4000 Although using some of the following macros was required in past
4001 releases, you should not use any of them in new code.  Running
4002 @command{autoupdate} should adjust your @file{configure.ac}
4003 automatically (@pxref{autoupdate Invocation, , Using
4004 @command{autoupdate} to Modernize @file{configure.ac}, autoconf, The
4005 Autoconf Manual}).
4006
4007 @table @code
4008 @item AM_C_PROTOTYPES
4009 @acindex AM_C_PROTOTYPES
4010 @vindex ANSI2KNR
4011 @vindex U
4012 Check to see if function prototypes are understood by the compiler.  If
4013 so, define @samp{PROTOTYPES} and set the output variables @code{U} and
4014 @code{ANSI2KNR} to the empty string.  Otherwise, set @code{U} to
4015 @samp{_} and @code{ANSI2KNR} to @samp{./ansi2knr}.  Automake used these
4016 values to implement the deprecated de-ANSI-fication feature; however,
4017 support for @emph{that feature will be removed} in the next major Automake
4018 release, and then @emph{these macros and variables will go away as well}.
4019
4020 @item AM_CONFIG_HEADER
4021 @acindex AM_CONFIG_HEADER
4022 Automake will generate rules to automatically regenerate the config
4023 header.  This obsolete macro is a synonym of @code{AC_CONFIG_HEADERS}
4024 today (@pxref{Optional}).
4025
4026 @item AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
4027 @acindex AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
4028 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
4029 define @code{GWINSZ_IN_SYS_IOCTL}.  Otherwise @code{TIOCGWINSZ} can be
4030 found in @file{<termios.h>}.  This macro is obsolete, you should
4031 use Autoconf's @code{AC_HEADER_TIOCGWINSZ} instead.
4032
4033 @item AM_PROG_MKDIR_P
4034 @acindex AM_PROG_MKDIR_P
4035 @cindex @code{mkdir -p}, macro check
4036 @vindex MKDIR_P
4037 @vindex mkdir_p
4038
4039 From Automake 1.8 to 1.9.6 this macro used to define the output
4040 variable @code{mkdir_p} to one of @code{mkdir -p}, @code{install-sh
4041 -d}, or @code{mkinstalldirs}.
4042
4043 Nowadays Autoconf provides a similar functionality with
4044 @code{AC_PROG_MKDIR_P} (@pxref{Particular Programs, , Particular
4045 Program Checks, autoconf, The Autoconf Manual}), however this defines
4046 the output variable @code{MKDIR_P} instead.  Therefore
4047 @code{AM_PROG_MKDIR_P} has been rewritten as a thin wrapper around
4048 @code{AC_PROG_MKDIR_P} to define @code{mkdir_p} to the same value as
4049 @code{MKDIR_P} for backward compatibility.
4050
4051 If you are using Automake, there is normally no reason to call this
4052 macro, because @code{AM_INIT_AUTOMAKE} already does so.  However, make
4053 sure that the custom rules in your @file{Makefile}s use
4054 @code{$(MKDIR_P)} and not @code{$(mkdir_p)}.  Even if both variables
4055 still work, the latter should be considered obsolete.
4056
4057 If you are not using Automake, please call @code{AC_PROG_MKDIR_P}
4058 instead of @code{AM_PROG_MKDIR_P}.
4059
4060 @item AM_SYS_POSIX_TERMIOS
4061 @acindex AM_SYS_POSIX_TERMIOS
4062 @cindex POSIX termios headers
4063 @cindex termios POSIX headers
4064 Check to see if POSIX termios headers and functions are available on the
4065 system.  If so, set the shell variable @code{am_cv_sys_posix_termios} to
4066 @samp{yes}.  If not, set the variable to @samp{no}.  This macro is obsolete,
4067 you should use Autoconf's @code{AC_SYS_POSIX_TERMIOS} instead.
4068
4069 @end table
4070
4071
4072 @node Private Macros
4073 @subsection Private Macros
4074
4075 The following macros are private macros you should not call directly.
4076 They are called by the other public macros when appropriate.  Do not
4077 rely on them, as they might be changed in a future version.  Consider
4078 them as implementation details; or better, do not consider them at all:
4079 skip this section!
4080
4081 @ftable @code
4082 @item _AM_DEPENDENCIES
4083 @itemx AM_SET_DEPDIR
4084 @itemx AM_DEP_TRACK
4085 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
4086 These macros are used to implement Automake's automatic dependency
4087 tracking scheme.  They are called automatically by Automake when
4088 required, and there should be no need to invoke them manually.
4089
4090 @item AM_MAKE_INCLUDE
4091 This macro is used to discover how the user's @command{make} handles
4092 @code{include} statements.  This macro is automatically invoked when
4093 needed; there should be no need to invoke it manually.
4094
4095 @item AM_PROG_INSTALL_STRIP
4096 This is used to find a version of @code{install} that can be used to
4097 strip a program at installation time.  This macro is automatically
4098 included when required.
4099
4100 @item AM_SANITY_CHECK
4101 This checks to make sure that a file created in the build directory is
4102 newer than a file in the source directory.  This can fail on systems
4103 where the clock is set incorrectly.  This macro is automatically run
4104 from @code{AM_INIT_AUTOMAKE}.
4105
4106 @end ftable
4107
4108
4109 @node Directories
4110 @chapter Directories
4111
4112 For simple projects that distribute all files in the same directory
4113 it is enough to have a single @file{Makefile.am} that builds
4114 everything in place.
4115
4116 In larger projects it is common to organize files in different
4117 directories, in a tree.  For instance one directory per program, per
4118 library or per module.  The traditional approach is to build these
4119 subdirectories recursively: each directory contains its @file{Makefile}
4120 (generated from @file{Makefile.am}), and when @command{make} is run
4121 from the top level directory it enters each subdirectory in turn to
4122 build its contents.
4123
4124 @menu
4125 * Subdirectories::              Building subdirectories recursively
4126 * Conditional Subdirectories::  Conditionally not building directories
4127 * Alternative::                 Subdirectories without recursion
4128 * Subpackages::                 Nesting packages
4129 @end menu
4130
4131 @node Subdirectories
4132 @section Recursing subdirectories
4133
4134 @cindex @code{SUBDIRS}, explained
4135
4136 In packages with subdirectories, the top level @file{Makefile.am} must
4137 tell Automake which subdirectories are to be built.  This is done via
4138 the @code{SUBDIRS} variable.
4139 @vindex SUBDIRS
4140
4141 The @code{SUBDIRS} variable holds a list of subdirectories in which
4142 building of various sorts can occur.  The rules for many targets
4143 (e.g., @code{all}) in the generated @file{Makefile} will run commands
4144 both locally and in all specified subdirectories.  Note that the
4145 directories listed in @code{SUBDIRS} are not required to contain
4146 @file{Makefile.am}s; only @file{Makefile}s (after configuration).
4147 This allows inclusion of libraries from packages that do not use
4148 Automake (such as @code{gettext}; see also @ref{Third-Party
4149 Makefiles}).
4150
4151 In packages that use subdirectories, the top-level @file{Makefile.am} is
4152 often very short.  For instance, here is the @file{Makefile.am} from the
4153 GNU Hello distribution:
4154
4155 @example
4156 EXTRA_DIST = BUGS ChangeLog.O README-alpha
4157 SUBDIRS = doc intl po src tests
4158 @end example
4159
4160 When Automake invokes @command{make} in a subdirectory, it uses the value
4161 of the @code{MAKE} variable.  It passes the value of the variable
4162 @code{AM_MAKEFLAGS} to the @command{make} invocation; this can be set in
4163 @file{Makefile.am} if there are flags you must always pass to
4164 @command{make}.
4165 @vindex MAKE
4166 @vindex AM_MAKEFLAGS
4167
4168 The directories mentioned in @code{SUBDIRS} are usually direct
4169 children of the current directory, each subdirectory containing its
4170 own @file{Makefile.am} with a @code{SUBDIRS} pointing to deeper
4171 subdirectories.  Automake can be used to construct packages of
4172 arbitrary depth this way.
4173
4174 By default, Automake generates @file{Makefiles} that work depth-first
4175 in postfix order: the subdirectories are built before the current
4176 directory.  However, it is possible to change this ordering.  You can
4177 do this by putting @samp{.} into @code{SUBDIRS}.  For instance,
4178 putting @samp{.} first will cause a prefix ordering of
4179 directories.
4180
4181 Using
4182
4183 @example
4184 SUBDIRS = lib src . test
4185 @end example
4186
4187 @noindent
4188 will cause @file{lib/} to be built before @file{src/}, then the
4189 current directory will be built, finally the @file{test/} directory
4190 will be built.  It is customary to arrange test directories to be
4191 built after everything else since they are meant to test what has
4192 been constructed.
4193
4194 All @code{clean} rules are run in reverse order of build rules.
4195
4196 @node Conditional Subdirectories
4197 @section Conditional Subdirectories
4198 @cindex Subdirectories, building conditionally
4199 @cindex Conditional subdirectories
4200 @cindex @code{SUBDIRS}, conditional
4201 @cindex Conditional @code{SUBDIRS}
4202
4203 It is possible to define the @code{SUBDIRS} variable conditionally if,
4204 like in the case of GNU Inetutils, you want to only build a subset of
4205 the entire package.
4206
4207 To illustrate how this works, let's assume we have two directories
4208 @file{src/} and @file{opt/}.  @file{src/} should always be built, but we
4209 want to decide in @command{configure} whether @file{opt/} will be built
4210 or not.  (For this example we will assume that @file{opt/} should be
4211 built when the variable @samp{$want_opt} was set to @samp{yes}.)
4212
4213 Running @command{make} should thus recurse into @file{src/} always, and
4214 then maybe in @file{opt/}.
4215
4216 However @samp{make dist} should always recurse into both @file{src/}
4217 and @file{opt/}.  Because @file{opt/} should be distributed even if it
4218 is not needed in the current configuration.  This means
4219 @file{opt/Makefile} should be created @emph{unconditionally}.
4220
4221 There are two ways to setup a project like this.  You can use Automake
4222 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
4223 variables (@pxref{Setting Output Variables, , Setting Output
4224 Variables, autoconf, The Autoconf Manual}).  Using Automake
4225 conditionals is the preferred solution.  Before we illustrate these
4226 two possibilities, let's introduce @code{DIST_SUBDIRS}.
4227
4228 @menu
4229 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
4230 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
4231 * Subdirectories with AC_SUBST::  Another way for conditional recursion
4232 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
4233 @end menu
4234
4235 @node SUBDIRS vs DIST_SUBDIRS
4236 @subsection @code{SUBDIRS} vs.@: @code{DIST_SUBDIRS}
4237 @cindex @code{DIST_SUBDIRS}, explained
4238
4239 Automake considers two sets of directories, defined by the variables
4240 @code{SUBDIRS} and @code{DIST_SUBDIRS}.
4241
4242 @code{SUBDIRS} contains the subdirectories of the current directory
4243 that must be built (@pxref{Subdirectories}).  It must be defined
4244 manually; Automake will never guess a directory is to be built.  As we
4245 will see in the next two sections, it is possible to define it
4246 conditionally so that some directory will be omitted from the build.
4247
4248 @code{DIST_SUBDIRS} is used in rules that need to recurse in all
4249 directories, even those that have been conditionally left out of the
4250 build.  Recall our example where we may not want to build subdirectory
4251 @file{opt/}, but yet we want to distribute it?  This is where
4252 @code{DIST_SUBDIRS} comes into play: @samp{opt} may not appear in
4253 @code{SUBDIRS}, but it must appear in @code{DIST_SUBDIRS}.
4254
4255 Precisely, @code{DIST_SUBDIRS} is used by @samp{make
4256 maintainer-clean}, @samp{make distclean} and @samp{make dist}.  All
4257 other recursive rules use @code{SUBDIRS}.
4258
4259 If @code{SUBDIRS} is defined conditionally using Automake
4260 conditionals, Automake will define @code{DIST_SUBDIRS} automatically
4261 from the possible values of @code{SUBDIRS} in all conditions.
4262
4263 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
4264 @code{DIST_SUBDIRS} will not be defined correctly because Automake
4265 does not know the possible values of these variables.  In this case
4266 @code{DIST_SUBDIRS} needs to be defined manually.
4267
4268 @node Subdirectories with AM_CONDITIONAL
4269 @subsection Subdirectories with @code{AM_CONDITIONAL}
4270 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
4271 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
4272
4273 @c Keep in sync with subcond2.test.
4274
4275 @file{configure} should output the @file{Makefile} for each directory
4276 and define a condition into which @file{opt/} should be built.
4277
4278 @example
4279 @dots{}
4280 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
4281 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4282 @dots{}
4283 @end example
4284
4285 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
4286 as follows.
4287
4288 @example
4289 if COND_OPT
4290   MAYBE_OPT = opt
4291 endif
4292 SUBDIRS = src $(MAYBE_OPT)
4293 @end example
4294
4295 As you can see, running @command{make} will rightly recurse into
4296 @file{src/} and maybe @file{opt/}.
4297
4298 @vindex DIST_SUBDIRS
4299 As you can't see, running @samp{make dist} will recurse into both
4300 @file{src/} and @file{opt/} directories because @samp{make dist}, unlike
4301 @samp{make all}, doesn't use the @code{SUBDIRS} variable.  It uses the
4302 @code{DIST_SUBDIRS} variable.
4303
4304 In this case Automake will define @samp{DIST_SUBDIRS = src opt}
4305 automatically because it knows that @code{MAYBE_OPT} can contain
4306 @samp{opt} in some condition.
4307
4308 @node Subdirectories with AC_SUBST
4309 @subsection Subdirectories with @code{AC_SUBST}
4310 @cindex @code{SUBDIRS} and @code{AC_SUBST}
4311 @cindex @code{AC_SUBST} and @code{SUBDIRS}
4312
4313 @c Keep in sync with subcond3.test.
4314
4315 Another possibility is to define @code{MAYBE_OPT} from
4316 @file{./configure} using @code{AC_SUBST}:
4317
4318 @example
4319 @dots{}
4320 if test "$want_opt" = yes; then
4321   MAYBE_OPT=opt
4322 else
4323   MAYBE_OPT=
4324 fi
4325 AC_SUBST([MAYBE_OPT])
4326 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4327 @dots{}
4328 @end example
4329
4330 In this case the top-level @file{Makefile.am} should look as follows.
4331
4332 @example
4333 SUBDIRS = src $(MAYBE_OPT)
4334 DIST_SUBDIRS = src opt
4335 @end example
4336
4337 The drawback is that since Automake cannot guess what the possible
4338 values of @code{MAYBE_OPT} are, it is necessary to define
4339 @code{DIST_SUBDIRS}.
4340
4341 @node Unconfigured Subdirectories
4342 @subsection Unconfigured Subdirectories
4343 @cindex Subdirectories, configured conditionally
4344
4345 The semantics of @code{DIST_SUBDIRS} are often misunderstood by some
4346 users that try to @emph{configure and build} subdirectories
4347 conditionally.  Here by configuring we mean creating the
4348 @file{Makefile} (it might also involve running a nested
4349 @command{configure} script: this is a costly operation that explains
4350 why people want to do it conditionally, but only the @file{Makefile}
4351 is relevant to the discussion).
4352
4353 The above examples all assume that every @file{Makefile} is created,
4354 even in directories that are not going to be built.  The simple reason
4355 is that we want @samp{make dist} to distribute even the directories
4356 that are not being built (e.g., platform-dependent code), hence
4357 @file{make dist} must recurse into the subdirectory, hence this
4358 directory must be configured and appear in @code{DIST_SUBDIRS}.
4359
4360 Building packages that do not configure every subdirectory is a tricky
4361 business, and we do not recommend it to the novice as it is easy to
4362 produce an incomplete tarball by mistake.  We will not discuss this
4363 topic in depth here, yet for the adventurous here are a few rules to
4364 remember.
4365
4366 @cartouche
4367 @itemize
4368 @item @code{SUBDIRS} should always be a subset of @code{DIST_SUBDIRS}.
4369
4370 It makes little sense to have a directory in @code{SUBDIRS} that
4371 is not in @code{DIST_SUBDIRS}.  Think of the former as a way to tell
4372 which directories listed in the latter should be built.
4373 @item Any directory listed in @code{DIST_SUBDIRS} and @code{SUBDIRS}
4374 must be configured.
4375
4376 I.e., the @file{Makefile} must exists or the recursive @command{make}
4377 rules will not be able to process the directory.
4378 @item Any configured directory must be listed in @code{DIST_SUBDIRS}.
4379
4380 So that the cleaning rules remove the generated @file{Makefile}s.
4381 It would be correct to see @code{DIST_SUBDIRS} as a variable that
4382 lists all the directories that have been configured.
4383 @end itemize
4384 @end cartouche
4385
4386 In order to prevent recursion in some unconfigured directory you
4387 must therefore ensure that this directory does not appear in
4388 @code{DIST_SUBDIRS} (and @code{SUBDIRS}).  For instance, if you define
4389 @code{SUBDIRS} conditionally using @code{AC_SUBST} and do not define
4390 @code{DIST_SUBDIRS} explicitly, it will be default to
4391 @samp{$(SUBDIRS)}; another possibility is to force @code{DIST_SUBDIRS
4392 = $(SUBDIRS)}.
4393
4394 Of course, directories that are omitted from @code{DIST_SUBDIRS} will
4395 not be distributed unless you make other arrangements for this to
4396 happen (for instance, always running @samp{make dist} in a
4397 configuration where all directories are known to appear in
4398 @code{DIST_SUBDIRS}; or writing a @code{dist-hook} target to
4399 distribute these directories).
4400
4401 @cindex Subdirectories, not distributed
4402 In few packages, unconfigured directories are not even expected to
4403 be distributed.  Although these packages do not require the
4404 aforementioned extra arrangements, there is another pitfall.  If the
4405 name of a directory appears in @code{SUBDIRS} or @code{DIST_SUBDIRS},
4406 @command{automake} will make sure the directory exists.  Consequently
4407 @command{automake} cannot be run on such a distribution when one
4408 directory has been omitted.  One way to avoid this check is to use the
4409 @code{AC_SUBST} method to declare conditional directories; since
4410 @command{automake} does not know the values of @code{AC_SUBST}
4411 variables it cannot ensure the corresponding directory exists.
4412
4413 @node Alternative
4414 @section An Alternative Approach to Subdirectories
4415
4416 If you've ever read Peter Miller's excellent paper,
4417 @uref{http://miller.emu.id.au/pmiller/books/rmch/,
4418 Recursive Make Considered Harmful}, the preceding sections on the use of
4419 subdirectories will probably come as unwelcome advice.  For those who
4420 haven't read the paper, Miller's main thesis is that recursive
4421 @command{make} invocations are both slow and error-prone.
4422
4423 Automake provides sufficient cross-directory support @footnote{We
4424 believe.  This work is new and there are probably warts.
4425 @xref{Introduction}, for information on reporting bugs.} to enable you
4426 to write a single @file{Makefile.am} for a complex multi-directory
4427 package.
4428
4429
4430 By default an installable file specified in a subdirectory will have its
4431 directory name stripped before installation.  For instance, in this
4432 example, the header file will be installed as
4433 @file{$(includedir)/stdio.h}:
4434
4435 @example
4436 include_HEADERS = inc/stdio.h
4437 @end example
4438
4439 @vindex nobase_
4440 @cindex @code{nobase_} prefix
4441 @cindex Path stripping, avoiding
4442 @cindex Avoiding path stripping
4443
4444 However, the @samp{nobase_} prefix can be used to circumvent this path
4445 stripping.  In this example, the header file will be installed as
4446 @file{$(includedir)/sys/types.h}:
4447
4448 @example
4449 nobase_include_HEADERS = sys/types.h
4450 @end example
4451
4452 @cindex @code{nobase_} and @code{dist_} or @code{nodist_}
4453 @cindex @code{dist_} and @code{nobase_}
4454 @cindex @code{nodist_} and @code{nobase_}
4455 @vindex dist_
4456 @vindex nodist_
4457
4458 @samp{nobase_} should be specified first when used in conjunction with
4459 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
4460 Control}).  For instance:
4461
4462 @example
4463 nobase_dist_pkgdata_DATA = images/vortex.pgm sounds/whirl.ogg
4464 @end example
4465
4466 Finally, note that a variable using the @samp{nobase_} prefix can
4467 often be replaced by several variables, one for each destination
4468 directory (@pxref{Uniform}).  For instance, the last example could be
4469 rewritten as follows:
4470
4471 @c Keep in sync with primary-prefix-couples-documented-valid.test.
4472 @example
4473 imagesdir = $(pkgdatadir)/images
4474 soundsdir = $(pkgdatadir)/sounds
4475 dist_images_DATA = images/vortex.pgm
4476 dist_sounds_DATA = sounds/whirl.ogg
4477 @end example
4478
4479 @noindent
4480 This latter syntax makes it possible to change one destination
4481 directory without changing the layout of the source tree.
4482
4483 Currently, @samp{nobase_*_LTLIBRARIES} are the only exception to this
4484 rule, in that there is no particular installation order guarantee for
4485 an otherwise equivalent set of variables without @samp{nobase_} prefix.
4486
4487 @node Subpackages
4488 @section Nesting Packages
4489 @cindex Nesting packages
4490 @cindex Subpackages
4491 @acindex AC_CONFIG_SUBDIRS
4492 @acindex AC_CONFIG_AUX_DIR
4493
4494
4495 In the GNU Build System, packages can be nested to arbitrary depth.
4496 This means that a package can embed other packages with their own
4497 @file{configure}, @file{Makefile}s, etc.
4498
4499 These other packages should just appear as subdirectories of their
4500 parent package.  They must be listed in @code{SUBDIRS} like other
4501 ordinary directories.  However the subpackage's @file{Makefile}s
4502 should be output by its own @file{configure} script, not by the
4503 parent's @file{configure}.  This is achieved using the
4504 @code{AC_CONFIG_SUBDIRS} Autoconf macro (@pxref{Subdirectories,
4505 AC_CONFIG_SUBDIRS, Configuring Other Packages in Subdirectories,
4506 autoconf, The Autoconf Manual}).
4507
4508 Here is an example package for an @code{arm} program that links with
4509 a @code{hand} library that is a nested package in subdirectory
4510 @file{hand/}.
4511
4512 @code{arm}'s @file{configure.ac}:
4513
4514 @example
4515 AC_INIT([arm], [1.0])
4516 AC_CONFIG_AUX_DIR([.])
4517 AM_INIT_AUTOMAKE
4518 AC_PROG_CC
4519 AC_CONFIG_FILES([Makefile])
4520 # Call hand's ./configure script recursively.
4521 AC_CONFIG_SUBDIRS([hand])
4522 AC_OUTPUT
4523 @end example
4524
4525 @code{arm}'s @file{Makefile.am}:
4526
4527 @example
4528 # Build the library in the hand subdirectory first.
4529 SUBDIRS = hand
4530
4531 # Include hand's header when compiling this directory.
4532 AM_CPPFLAGS = -I$(srcdir)/hand
4533
4534 bin_PROGRAMS = arm
4535 arm_SOURCES = arm.c
4536 # link with the hand library.
4537 arm_LDADD = hand/libhand.a
4538 @end example
4539
4540 Now here is @code{hand}'s @file{hand/configure.ac}:
4541
4542 @example
4543 AC_INIT([hand], [1.2])
4544 AC_CONFIG_AUX_DIR([.])
4545 AM_INIT_AUTOMAKE
4546 AC_PROG_CC
4547 AC_PROG_RANLIB
4548 AC_CONFIG_FILES([Makefile])
4549 AC_OUTPUT
4550 @end example
4551
4552 @noindent
4553 and its @file{hand/Makefile.am}:
4554
4555 @example
4556 lib_LIBRARIES = libhand.a
4557 libhand_a_SOURCES = hand.c
4558 @end example
4559
4560 When @samp{make dist} is run from the top-level directory it will
4561 create an archive @file{arm-1.0.tar.gz} that contains the @code{arm}
4562 code as well as the @file{hand} subdirectory.  This package can be
4563 built and installed like any ordinary package, with the usual
4564 @samp{./configure && make && make install} sequence (the @code{hand}
4565 subpackage will be built and installed by the process).
4566
4567 When @samp{make dist} is run from the hand directory, it will create a
4568 self-contained @file{hand-1.2.tar.gz} archive.  So although it appears
4569 to be embedded in another package, it can still be used separately.
4570
4571 The purpose of the @samp{AC_CONFIG_AUX_DIR([.])} instruction is to
4572 force Automake and Autoconf to search for auxiliary scripts in the
4573 current directory.  For instance, this means that there will be two
4574 copies of @file{install-sh}: one in the top-level of the @code{arm}
4575 package, and another one in the @file{hand/} subdirectory for the
4576 @code{hand} package.
4577
4578 The historical default is to search for these auxiliary scripts in
4579 the parent directory and the grandparent directory.  So if the
4580 @samp{AC_CONFIG_AUX_DIR([.])} line was removed from
4581 @file{hand/configure.ac}, that subpackage would share the auxiliary
4582 script of the @code{arm} package.  This may looks like a gain in size
4583 (a few kilobytes), but it is actually a loss of modularity as the
4584 @code{hand} subpackage is no longer self-contained (@samp{make dist}
4585 in the subdirectory will not work anymore).
4586
4587 Packages that do not use Automake need more work to be integrated this
4588 way.  @xref{Third-Party Makefiles}.
4589
4590 @node Programs
4591 @chapter Building Programs and Libraries
4592
4593 A large part of Automake's functionality is dedicated to making it easy
4594 to build programs and libraries.
4595
4596 @menu
4597 * A Program::                   Building a program
4598 * A Library::                   Building a library
4599 * A Shared Library::            Building a Libtool library
4600 * Program and Library Variables::  Variables controlling program and
4601                                 library builds
4602 * Default _SOURCES::            Default source files
4603 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
4604 * Program Variables::           Variables used when building a program
4605 * Yacc and Lex::                Yacc and Lex support
4606 * C++ Support::                 Compiling C++ sources
4607 * Objective C Support::         Compiling Objective C sources
4608 * Unified Parallel C Support::  Compiling Unified Parallel C sources
4609 * Assembly Support::            Compiling assembly sources
4610 * Fortran 77 Support::          Compiling Fortran 77 sources
4611 * Fortran 9x Support::          Compiling Fortran 9x sources
4612 * Java Support::                Compiling Java sources
4613 * Vala Support::                Compiling Vala sources
4614 * Support for Other Languages::  Compiling other languages
4615 * ANSI::                        Automatic de-ANSI-fication (deprecated, soon to be removed)
4616 * Dependencies::                Automatic dependency tracking
4617 * EXEEXT::                      Support for executable extensions
4618 @end menu
4619
4620
4621 @node A Program
4622 @section Building a program
4623
4624 In order to build a program, you need to tell Automake which sources
4625 are part of it, and which libraries it should be linked with.
4626
4627 This section also covers conditional compilation of sources or
4628 programs.  Most of the comments about these also apply to libraries
4629 (@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
4630
4631 @menu
4632 * Program Sources::             Defining program sources
4633 * Linking::                     Linking with libraries or extra objects
4634 * Conditional Sources::         Handling conditional sources
4635 * Conditional Programs::        Building a program conditionally
4636 @end menu
4637
4638 @node Program Sources
4639 @subsection Defining program sources
4640
4641 @cindex @code{PROGRAMS}, @code{bindir}
4642 @vindex _PROGRAMS
4643 @vindex bin_PROGRAMS
4644 @vindex sbin_PROGRAMS
4645 @vindex libexec_PROGRAMS
4646 @vindex pkglibexec_PROGRAMS
4647 @vindex noinst_PROGRAMS
4648 @vindex check_PROGRAMS
4649
4650 In a directory containing source that gets built into a program (as
4651 opposed to a library or a script), the @code{PROGRAMS} primary is used.
4652 Programs can be installed in @code{bindir}, @code{sbindir},
4653 @code{libexecdir}, @code{pkglibexecdir}, or not at all
4654 (@code{noinst_}).  They can also be built only for @samp{make check}, in
4655 which case the prefix is @samp{check_}.
4656
4657 For instance:
4658
4659 @example
4660 bin_PROGRAMS = hello
4661 @end example
4662
4663 In this simple case, the resulting @file{Makefile.in} will contain code
4664 to generate a program named @code{hello}.
4665
4666 Associated with each program are several assisting variables that are
4667 named after the program.  These variables are all optional, and have
4668 reasonable defaults.  Each variable, its use, and default is spelled out
4669 below; we use the ``hello'' example throughout.
4670
4671 The variable @code{hello_SOURCES} is used to specify which source files
4672 get built into an executable:
4673
4674 @example
4675 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
4676 @end example
4677
4678 This causes each mentioned @file{.c} file to be compiled into the
4679 corresponding @file{.o}.  Then all are linked to produce @file{hello}.
4680
4681 @cindex @code{_SOURCES} primary, defined
4682 @cindex @code{SOURCES} primary, defined
4683 @cindex Primary variable, @code{SOURCES}
4684 @vindex _SOURCES
4685
4686 If @code{hello_SOURCES} is not specified, then it defaults to the single
4687 file @file{hello.c} (@pxref{Default _SOURCES}).
4688 @vindex _SOURCES
4689 @vindex SOURCES
4690
4691 Multiple programs can be built in a single directory.  Multiple programs
4692 can share a single source file, which must be listed in each
4693 @code{_SOURCES} definition.
4694
4695 @cindex Header files in @code{_SOURCES}
4696 @cindex @code{_SOURCES} and header files
4697
4698 Header files listed in a @code{_SOURCES} definition will be included in
4699 the distribution but otherwise ignored.  In case it isn't obvious, you
4700 should not include the header file generated by @file{configure} in a
4701 @code{_SOURCES} variable; this file should not be distributed.  Lex
4702 (@file{.l}) and Yacc (@file{.y}) files can also be listed; see @ref{Yacc
4703 and Lex}.
4704
4705
4706 @node Linking
4707 @subsection Linking the program
4708
4709 If you need to link against libraries that are not found by
4710 @command{configure}, you can use @code{LDADD} to do so.  This variable is
4711 used to specify additional objects or libraries to link with; it is
4712 inappropriate for specifying specific linker flags, you should use
4713 @code{AM_LDFLAGS} for this purpose.
4714 @vindex LDADD
4715 @vindex AM_LDFLAGS
4716
4717 @cindex @code{prog_LDADD}, defined
4718
4719 Sometimes, multiple programs are built in one directory but do not share
4720 the same link-time requirements.  In this case, you can use the
4721 @code{@var{prog}_LDADD} variable (where @var{prog} is the name of the
4722 program as it appears in some @code{_PROGRAMS} variable, and usually
4723 written in lowercase) to override @code{LDADD}.  If this variable exists
4724 for a given program, then that program is not linked using @code{LDADD}.
4725 @vindex maude_LDADD
4726
4727 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
4728 linked against the library @file{libcpio.a}.  However, @code{rmt} is
4729 built in the same directory, and has no such link requirement.  Also,
4730 @code{mt} and @code{rmt} are only built on certain architectures.  Here
4731 is what cpio's @file{src/Makefile.am} looks like (abridged):
4732
4733 @example
4734 bin_PROGRAMS = cpio pax $(MT)
4735 libexec_PROGRAMS = $(RMT)
4736 EXTRA_PROGRAMS = mt rmt
4737
4738 LDADD = ../lib/libcpio.a $(INTLLIBS)
4739 rmt_LDADD =
4740
4741 cpio_SOURCES = @dots{}
4742 pax_SOURCES = @dots{}
4743 mt_SOURCES = @dots{}
4744 rmt_SOURCES = @dots{}
4745 @end example
4746
4747 @cindex @code{_LDFLAGS}, defined
4748 @vindex maude_LDFLAGS
4749 @code{@var{prog}_LDADD} is inappropriate for passing program-specific
4750 linker flags (except for @option{-l}, @option{-L}, @option{-dlopen} and
4751 @option{-dlpreopen}).  So, use the @code{@var{prog}_LDFLAGS} variable for
4752 this purpose.
4753
4754 @cindex @code{_DEPENDENCIES}, defined
4755 @vindex maude_DEPENDENCIES
4756 It is also occasionally useful to have a program depend on some other
4757 target that is not actually part of that program.  This can be done
4758 using the @code{@var{prog}_DEPENDENCIES} variable.  Each program
4759 depends on the contents of such a variable, but no further
4760 interpretation is done.
4761
4762 Since these dependencies are associated to the link rule used to
4763 create the programs they should normally list files used by the link
4764 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la}
4765 files.  In rare cases you may need to add other kinds of files such as
4766 linker scripts, but @emph{listing a source file in
4767 @code{_DEPENDENCIES} is wrong}.  If some source file needs to be built
4768 before all the components of a program are built, consider using the
4769 @code{BUILT_SOURCES} variable instead (@pxref{Sources}).
4770
4771 If @code{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
4772 Automake.  The automatically-assigned value is the contents of
4773 @code{@var{prog}_LDADD}, with most configure substitutions, @option{-l},
4774 @option{-L}, @option{-dlopen} and @option{-dlpreopen} options removed.  The
4775 configure substitutions that are left in are only @samp{$(LIBOBJS)} and
4776 @samp{$(ALLOCA)}; these are left because it is known that they will not
4777 cause an invalid value for @code{@var{prog}_DEPENDENCIES} to be
4778 generated.
4779
4780 @ref{Conditional Sources} shows a situation where @code{_DEPENDENCIES}
4781 may be used.
4782
4783 @cindex @code{LDADD} and @option{-l}
4784 @cindex @option{-l} and @code{LDADD}
4785 We recommend that you avoid using @option{-l} options in @code{LDADD}
4786 or @code{@var{prog}_LDADD} when referring to libraries built by your
4787 package.  Instead, write the file name of the library explicitly as in
4788 the above @code{cpio} example.  Use @option{-l} only to list
4789 third-party libraries.  If you follow this rule, the default value of
4790 @code{@var{prog}_DEPENDENCIES} will list all your local libraries and
4791 omit the other ones.
4792
4793
4794 @node Conditional Sources
4795 @subsection Conditional compilation of sources
4796
4797 You can't put a configure substitution (e.g., @samp{@@FOO@@} or
4798 @samp{$(FOO)} where @code{FOO} is defined via @code{AC_SUBST}) into a
4799 @code{_SOURCES} variable.  The reason for this is a bit hard to
4800 explain, but suffice to say that it simply won't work.  Automake will
4801 give an error if you try to do this.
4802
4803 Fortunately there are two other ways to achieve the same result.  One is
4804 to use configure substitutions in @code{_LDADD} variables, the other is
4805 to use an Automake conditional.
4806
4807 @subsubheading Conditional Compilation using @code{_LDADD} Substitutions
4808
4809 @cindex @code{EXTRA_prog_SOURCES}, defined
4810
4811 Automake must know all the source files that could possibly go into a
4812 program, even if not all the files are built in every circumstance.  Any
4813 files that are only conditionally built should be listed in the
4814 appropriate @code{EXTRA_} variable.  For instance, if
4815 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
4816 in @code{hello}, the @file{Makefile.am} would contain:
4817
4818 @example
4819 bin_PROGRAMS = hello
4820 hello_SOURCES = hello-common.c
4821 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
4822 hello_LDADD = $(HELLO_SYSTEM)
4823 hello_DEPENDENCIES = $(HELLO_SYSTEM)
4824 @end example
4825
4826 @noindent
4827 You can then setup the @samp{$(HELLO_SYSTEM)} substitution from
4828 @file{configure.ac}:
4829
4830 @example
4831 @dots{}
4832 case $host in
4833   *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
4834   *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
4835 esac
4836 AC_SUBST([HELLO_SYSTEM])
4837 @dots{}
4838 @end example
4839
4840 In this case, the variable @code{HELLO_SYSTEM} should be replaced by
4841 either @file{hello-linux.o} or @file{hello-generic.o}, and added to
4842 both @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be
4843 built and linked in.
4844
4845 @subsubheading Conditional Compilation using Automake Conditionals
4846
4847 An often simpler way to compile source files conditionally is to use
4848 Automake conditionals.  For instance, you could use this
4849 @file{Makefile.am} construct to build the same @file{hello} example:
4850
4851 @example
4852 bin_PROGRAMS = hello
4853 if LINUX
4854 hello_SOURCES = hello-linux.c hello-common.c
4855 else
4856 hello_SOURCES = hello-generic.c hello-common.c
4857 endif
4858 @end example
4859
4860 In this case, @file{configure.ac} should setup the @code{LINUX}
4861 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
4862
4863 When using conditionals like this you don't need to use the
4864 @code{EXTRA_} variable, because Automake will examine the contents of
4865 each variable to construct the complete list of source files.
4866
4867 If your program uses a lot of files, you will probably prefer a
4868 conditional @samp{+=}.
4869
4870 @example
4871 bin_PROGRAMS = hello
4872 hello_SOURCES = hello-common.c
4873 if LINUX
4874 hello_SOURCES += hello-linux.c
4875 else
4876 hello_SOURCES += hello-generic.c
4877 endif
4878 @end example
4879
4880 @node Conditional Programs
4881 @subsection Conditional compilation of programs
4882 @cindex Conditional programs
4883 @cindex Programs, conditional
4884
4885 Sometimes it is useful to determine the programs that are to be built
4886 at configure time.  For instance, GNU @code{cpio} only builds
4887 @code{mt} and @code{rmt} under special circumstances.  The means to
4888 achieve conditional compilation of programs are the same you can use
4889 to compile source files conditionally: substitutions or conditionals.
4890
4891 @subsubheading Conditional Programs using @command{configure} Substitutions
4892
4893 @vindex EXTRA_PROGRAMS
4894 @cindex @code{EXTRA_PROGRAMS}, defined
4895 In this case, you must notify Automake of all the programs that can
4896 possibly be built, but at the same time cause the generated
4897 @file{Makefile.in} to use the programs specified by @command{configure}.
4898 This is done by having @command{configure} substitute values into each
4899 @code{_PROGRAMS} definition, while listing all optionally built programs
4900 in @code{EXTRA_PROGRAMS}.
4901
4902 @example
4903 bin_PROGRAMS = cpio pax $(MT)
4904 libexec_PROGRAMS = $(RMT)
4905 EXTRA_PROGRAMS = mt rmt
4906 @end example
4907
4908 As explained in @ref{EXEEXT}, Automake will rewrite
4909 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
4910 @code{EXTRA_PROGRAMS}, appending @samp{$(EXEEXT)} to each binary.
4911 Obviously it cannot rewrite values obtained at run-time through
4912 @command{configure} substitutions, therefore you should take care of
4913 appending @samp{$(EXEEXT)} yourself, as in @samp{AC_SUBST([MT],
4914 ['mt$@{EXEEXT@}'])}.
4915
4916 @subsubheading Conditional Programs using Automake Conditionals
4917
4918 You can also use Automake conditionals (@pxref{Conditionals}) to
4919 select programs to be built.  In this case you don't have to worry
4920 about @samp{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
4921
4922 @c Keep in sync with exeext.test.
4923 @example
4924 bin_PROGRAMS = cpio pax
4925 if WANT_MT
4926   bin_PROGRAMS += mt
4927 endif
4928 if WANT_RMT
4929   libexec_PROGRAMS = rmt
4930 endif
4931 @end example
4932
4933
4934 @node A Library
4935 @section Building a library
4936
4937 @cindex @code{_LIBRARIES} primary, defined
4938 @cindex @code{LIBRARIES} primary, defined
4939 @cindex Primary variable, @code{LIBRARIES}
4940 @vindex _LIBRARIES
4941
4942 @vindex lib_LIBRARIES
4943 @vindex pkglib_LIBRARIES
4944 @vindex noinst_LIBRARIES
4945
4946 Building a library is much like building a program.  In this case, the
4947 name of the primary is @code{LIBRARIES}.  Libraries can be installed in
4948 @code{libdir} or @code{pkglibdir}.
4949
4950 @xref{A Shared Library}, for information on how to build shared
4951 libraries using libtool and the @code{LTLIBRARIES} primary.
4952
4953 Each @code{_LIBRARIES} variable is a list of the libraries to be built.
4954 For instance, to create a library named @file{libcpio.a}, but not install
4955 it, you would write:
4956
4957 @example
4958 noinst_LIBRARIES = libcpio.a
4959 libcpio_a_SOURCES = @dots{}
4960 @end example
4961
4962 The sources that go into a library are determined exactly as they are
4963 for programs, via the @code{_SOURCES} variables.  Note that the library
4964 name is canonicalized (@pxref{Canonicalization}), so the @code{_SOURCES}
4965 variable corresponding to @file{libcpio.a} is @samp{libcpio_a_SOURCES},
4966 not @samp{libcpio.a_SOURCES}.
4967
4968 @vindex maude_LIBADD
4969 Extra objects can be added to a library using the
4970 @code{@var{library}_LIBADD} variable.  This should be used for objects
4971 determined by @command{configure}.  Again from @code{cpio}:
4972
4973 @c Keep in sync with pr401c.test.
4974 @example
4975 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
4976 @end example
4977
4978 In addition, sources for extra objects that will not exist until
4979 configure-time must be added to the @code{BUILT_SOURCES} variable
4980 (@pxref{Sources}).
4981
4982 Building a static library is done by compiling all object files, then
4983 by invoking @samp{$(AR) $(ARFLAGS)} followed by the name of the
4984 library and the list of objects, and finally by calling
4985 @samp{$(RANLIB)} on that library.  You should call
4986 @code{AC_PROG_RANLIB} from your @file{configure.ac} to define
4987 @code{RANLIB} (Automake will complain otherwise).  @code{AR} and
4988 @code{ARFLAGS} default to @code{ar} and @code{cru} respectively; you
4989 can override these two variables my setting them in your
4990 @file{Makefile.am}, by @code{AC_SUBST}ing them from your
4991 @file{configure.ac}, or by defining a per-library @code{maude_AR}
4992 variable (@pxref{Program and Library Variables}).
4993
4994 @cindex Empty libraries
4995 Be careful when selecting library components conditionally.  Because
4996 building an empty library is not portable, you should ensure that any
4997 library always contains at least one object.
4998
4999 To use a static library when building a program, add it to
5000 @code{LDADD} for this program.  In the following example, the program
5001 @file{cpio} is statically linked with the library @file{libcpio.a}.
5002
5003 @example
5004 noinst_LIBRARIES = libcpio.a
5005 libcpio_a_SOURCES = @dots{}
5006
5007 bin_PROGRAMS = cpio
5008 cpio_SOURCES = cpio.c @dots{}
5009 cpio_LDADD = libcpio.a
5010 @end example
5011
5012
5013 @node A Shared Library
5014 @section Building a Shared Library
5015
5016 @cindex Shared libraries, support for
5017
5018 Building shared libraries portably is a relatively complex matter.
5019 For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
5020 Libtool Manual}) was created to help build shared libraries in a
5021 platform-independent way.
5022
5023 @menu
5024 * Libtool Concept::             Introducing Libtool
5025 * Libtool Libraries::           Declaring Libtool Libraries
5026 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
5027 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
5028 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
5029 * Libtool Modules::             Building Libtool Modules
5030 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
5031 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
5032 * Libtool Issues::              Common Issues Related to Libtool's Use
5033 @end menu
5034
5035 @node Libtool Concept
5036 @subsection The Libtool Concept
5037
5038 @cindex @command{libtool}, introduction
5039 @cindex libtool library, definition
5040 @cindex suffix @file{.la}, defined
5041 @cindex @file{.la} suffix, defined
5042
5043 Libtool abstracts shared and static libraries into a unified concept
5044 henceforth called @dfn{libtool libraries}.  Libtool libraries are
5045 files using the @file{.la} suffix, and can designate a static library,
5046 a shared library, or maybe both.  Their exact nature cannot be
5047 determined until @file{./configure} is run: not all platforms support
5048 all kinds of libraries, and users can explicitly select which
5049 libraries should be built.  (However the package's maintainers can
5050 tune the default, @pxref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
5051 macro, libtool, The Libtool Manual}.)
5052
5053 @cindex suffix @file{.lo}, defined
5054 Because object files for shared and static libraries must be compiled
5055 differently, libtool is also used during compilation.  Object files
5056 built by libtool are called @dfn{libtool objects}: these are files
5057 using the @file{.lo} suffix.  Libtool libraries are built from these
5058 libtool objects.
5059
5060 You should not assume anything about the structure of @file{.la} or
5061 @file{.lo} files and how libtool constructs them: this is libtool's
5062 concern, and the last thing one wants is to learn about libtool's
5063 guts.  However the existence of these files matters, because they are
5064 used as targets and dependencies in @file{Makefile}s rules when
5065 building libtool libraries.  There are situations where you may have
5066 to refer to these, for instance when expressing dependencies for
5067 building source files conditionally (@pxref{Conditional Libtool
5068 Sources}).
5069
5070 @cindex @file{libltdl}, introduction
5071
5072 People considering writing a plug-in system, with dynamically loaded
5073 modules, should look into @file{libltdl}: libtool's dlopening library
5074 (@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
5075 This offers a portable dlopening facility to load libtool libraries
5076 dynamically, and can also achieve static linking where unavoidable.
5077
5078 Before we discuss how to use libtool with Automake in details, it
5079 should be noted that the libtool manual also has a section about how
5080 to use Automake with libtool (@pxref{Using Automake, , Using Automake
5081 with Libtool, libtool, The Libtool Manual}).
5082
5083 @node Libtool Libraries
5084 @subsection Building Libtool Libraries
5085
5086 @cindex @code{_LTLIBRARIES} primary, defined
5087 @cindex @code{LTLIBRARIES} primary, defined
5088 @cindex Primary variable, @code{LTLIBRARIES}
5089 @cindex Example of shared libraries
5090 @vindex lib_LTLIBRARIES
5091 @vindex pkglib_LTLIBRARIES
5092 @vindex _LTLIBRARIES
5093
5094 Automake uses libtool to build libraries declared with the
5095 @code{LTLIBRARIES} primary.  Each @code{_LTLIBRARIES} variable is a
5096 list of libtool libraries to build.  For instance, to create a libtool
5097 library named @file{libgettext.la}, and install it in @code{libdir},
5098 write:
5099
5100 @example
5101 lib_LTLIBRARIES = libgettext.la
5102 libgettext_la_SOURCES = gettext.c gettext.h @dots{}
5103 @end example
5104
5105 Automake predefines the variable @code{pkglibdir}, so you can use
5106 @code{pkglib_LTLIBRARIES} to install libraries in
5107 @samp{$(libdir)/@@PACKAGE@@/}.
5108
5109 If @file{gettext.h} is a public header file that needs to be installed
5110 in order for people to use the library, it should be declared using a
5111 @code{_HEADERS} variable, not in @code{libgettext_la_SOURCES}.
5112 Headers listed in the latter should be internal headers that are not
5113 part of the public interface.
5114
5115 @example
5116 lib_LTLIBRARIES = libgettext.la
5117 libgettext_la_SOURCES = gettext.c @dots{}
5118 include_HEADERS = gettext.h @dots{}
5119 @end example
5120
5121 A package can build and install such a library along with other
5122 programs that use it.  This dependency should be specified using
5123 @code{LDADD}.  The following example builds a program named
5124 @file{hello} that is linked with @file{libgettext.la}.
5125
5126 @example
5127 lib_LTLIBRARIES = libgettext.la
5128 libgettext_la_SOURCES = gettext.c @dots{}
5129
5130 bin_PROGRAMS = hello
5131 hello_SOURCES = hello.c @dots{}
5132 hello_LDADD = libgettext.la
5133 @end example
5134
5135 @noindent
5136 Whether @file{hello} is statically or dynamically linked with
5137 @file{libgettext.la} is not yet known: this will depend on the
5138 configuration of libtool and the capabilities of the host.
5139
5140
5141 @node Conditional Libtool Libraries
5142 @subsection Building Libtool Libraries Conditionally
5143 @cindex libtool libraries, conditional
5144 @cindex conditional libtool libraries
5145
5146 Like conditional programs (@pxref{Conditional Programs}), there are
5147 two main ways to build conditional libraries: using Automake
5148 conditionals or using Autoconf @code{AC_SUBST}itutions.
5149
5150 The important implementation detail you have to be aware of is that
5151 the place where a library will be installed matters to libtool: it
5152 needs to be indicated @emph{at link-time} using the @option{-rpath}
5153 option.
5154
5155 For libraries whose destination directory is known when Automake runs,
5156 Automake will automatically supply the appropriate @option{-rpath}
5157 option to libtool.  This is the case for libraries listed explicitly in
5158 some installable @code{_LTLIBRARIES} variables such as
5159 @code{lib_LTLIBRARIES}.
5160
5161 However, for libraries determined at configure time (and thus
5162 mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
5163 final installation directory.  For such libraries you must add the
5164 @option{-rpath} option to the appropriate @code{_LDFLAGS} variable by
5165 hand.
5166
5167 The examples below illustrate the differences between these two methods.
5168
5169 Here is an example where @code{WANTEDLIBS} is an @code{AC_SUBST}ed
5170 variable set at @file{./configure}-time to either @file{libfoo.la},
5171 @file{libbar.la}, both, or none.  Although @samp{$(WANTEDLIBS)}
5172 appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
5173 relates to @file{libfoo.la} or @file{libbar.la} at the time it creates
5174 the link rule for these two libraries.  Therefore the @option{-rpath}
5175 argument must be explicitly supplied.
5176
5177 @c Keep in sync with ltcond.test.
5178 @example
5179 EXTRA_LTLIBRARIES = libfoo.la libbar.la
5180 lib_LTLIBRARIES = $(WANTEDLIBS)
5181 libfoo_la_SOURCES = foo.c @dots{}
5182 libfoo_la_LDFLAGS = -rpath '$(libdir)'
5183 libbar_la_SOURCES = bar.c @dots{}
5184 libbar_la_LDFLAGS = -rpath '$(libdir)'
5185 @end example
5186
5187 Here is how the same @file{Makefile.am} would look using Automake
5188 conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}.  Now
5189 Automake is able to compute the @option{-rpath} setting itself, because
5190 it's clear that both libraries will end up in @samp{$(libdir)} if they
5191 are installed.
5192
5193 @c Keep in sync with ltcond.test.
5194 @example
5195 lib_LTLIBRARIES =
5196 if WANT_LIBFOO
5197 lib_LTLIBRARIES += libfoo.la
5198 endif
5199 if WANT_LIBBAR
5200 lib_LTLIBRARIES += libbar.la
5201 endif
5202 libfoo_la_SOURCES = foo.c @dots{}
5203 libbar_la_SOURCES = bar.c @dots{}
5204 @end example
5205
5206 @node Conditional Libtool Sources
5207 @subsection Libtool Libraries with Conditional Sources
5208
5209 Conditional compilation of sources in a library can be achieved in the
5210 same way as conditional compilation of sources in a program
5211 (@pxref{Conditional Sources}).  The only difference is that
5212 @code{_LIBADD} should be used instead of @code{_LDADD} and that it
5213 should mention libtool objects (@file{.lo} files).
5214
5215 So, to mimic the @file{hello} example from @ref{Conditional Sources},
5216 we could build a @file{libhello.la} library using either
5217 @file{hello-linux.c} or @file{hello-generic.c} with the following
5218 @file{Makefile.am}.
5219
5220 @c Keep in sync with ltcond2.test.
5221 @example
5222 lib_LTLIBRARIES = libhello.la
5223 libhello_la_SOURCES = hello-common.c
5224 EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
5225 libhello_la_LIBADD = $(HELLO_SYSTEM)
5226 libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
5227 @end example
5228
5229 @noindent
5230 And make sure @command{configure} defines @code{HELLO_SYSTEM} as
5231 either @file{hello-linux.lo} or @file{hello-@-generic.lo}.
5232
5233 Or we could simply use an Automake conditional as follows.
5234
5235 @c Keep in sync with ltcond2.test.
5236 @example
5237 lib_LTLIBRARIES = libhello.la
5238 libhello_la_SOURCES = hello-common.c
5239 if LINUX
5240 libhello_la_SOURCES += hello-linux.c
5241 else
5242 libhello_la_SOURCES += hello-generic.c
5243 endif
5244 @end example
5245
5246 @node Libtool Convenience Libraries
5247 @subsection Libtool Convenience Libraries
5248 @cindex convenience libraries, libtool
5249 @cindex libtool convenience libraries
5250 @vindex noinst_LTLIBRARIES
5251 @vindex check_LTLIBRARIES
5252
5253 Sometimes you want to build libtool libraries that should not be
5254 installed.  These are called @dfn{libtool convenience libraries} and
5255 are typically used to encapsulate many sublibraries, later gathered
5256 into one big installed library.
5257
5258 Libtool convenience libraries are declared by directory-less variables
5259 such as @code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
5260 @code{EXTRA_LTLIBRARIES}.  Unlike installed libtool libraries they do
5261 not need an @option{-rpath} flag at link time (actually this is the only
5262 difference).
5263
5264 Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
5265 built.  Those listed in @code{check_LTLIBRARIES} are built only upon
5266 @samp{make check}.  Finally, libraries listed in
5267 @code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
5268 rules to build them, but if the library does not appear as a Makefile
5269 dependency anywhere it won't be built (this is why
5270 @code{EXTRA_LTLIBRARIES} is used for conditional compilation).
5271
5272 Here is a sample setup merging libtool convenience libraries from
5273 subdirectories into one main @file{libtop.la} library.
5274
5275 @c Keep in sync with ltconv.test.
5276 @example
5277 # -- Top-level Makefile.am --
5278 SUBDIRS = sub1 sub2 @dots{}
5279 lib_LTLIBRARIES = libtop.la
5280 libtop_la_SOURCES =
5281 libtop_la_LIBADD = \
5282   sub1/libsub1.la \
5283   sub2/libsub2.la \
5284   @dots{}
5285
5286 # -- sub1/Makefile.am --
5287 noinst_LTLIBRARIES = libsub1.la
5288 libsub1_la_SOURCES = @dots{}
5289
5290 # -- sub2/Makefile.am --
5291 # showing nested convenience libraries
5292 SUBDIRS = sub2.1 sub2.2 @dots{}
5293 noinst_LTLIBRARIES = libsub2.la
5294 libsub2_la_SOURCES =
5295 libsub2_la_LIBADD = \
5296   sub21/libsub21.la \
5297   sub22/libsub22.la \
5298   @dots{}
5299 @end example
5300
5301 When using such setup, beware that @command{automake} will assume
5302 @file{libtop.la} is to be linked with the C linker.  This is because
5303 @code{libtop_la_SOURCES} is empty, so @command{automake} picks C as
5304 default language.  If @code{libtop_la_SOURCES} was not empty,
5305 @command{automake} would select the linker as explained in @ref{How
5306 the Linker is Chosen}.
5307
5308 If one of the sublibraries contains non-C source, it is important that
5309 the appropriate linker be chosen.  One way to achieve this is to
5310 pretend that there is such a non-C file among the sources of the
5311 library, thus forcing @command{automake} to select the appropriate
5312 linker.  Here is the top-level @file{Makefile} of our example updated
5313 to force C++ linking.
5314
5315 @example
5316 SUBDIRS = sub1 sub2 @dots{}
5317 lib_LTLIBRARIES = libtop.la
5318 libtop_la_SOURCES =
5319 # Dummy C++ source to cause C++ linking.
5320 nodist_EXTRA_libtop_la_SOURCES = dummy.cxx
5321 libtop_la_LIBADD = \
5322   sub1/libsub1.la \
5323   sub2/libsub2.la \
5324   @dots{}
5325 @end example
5326
5327 @samp{EXTRA_*_SOURCES} variables are used to keep track of source
5328 files that might be compiled (this is mostly useful when doing
5329 conditional compilation using @code{AC_SUBST}, @pxref{Conditional
5330 Libtool Sources}), and the @code{nodist_} prefix means the listed
5331 sources are not to be distributed (@pxref{Program and Library
5332 Variables}).  In effect the file @file{dummy.cxx} does not need to
5333 exist in the source tree.  Of course if you have some real source file
5334 to list in @code{libtop_la_SOURCES} there is no point in cheating with
5335 @code{nodist_EXTRA_libtop_la_SOURCES}.
5336
5337
5338 @node Libtool Modules
5339 @subsection Libtool Modules
5340 @cindex modules, libtool
5341 @cindex libtool modules
5342 @cindex @option{-module}, libtool
5343
5344 These are libtool libraries meant to be dlopened.  They are
5345 indicated to libtool by passing @option{-module} at link-time.
5346
5347 @example
5348 pkglib_LTLIBRARIES = mymodule.la
5349 mymodule_la_SOURCES = doit.c
5350 mymodule_la_LDFLAGS = -module
5351 @end example
5352
5353 Ordinarily, Automake requires that a library's name start with
5354 @code{lib}.  However, when building a dynamically loadable module you
5355 might wish to use a "nonstandard" name.  Automake will not complain
5356 about such nonstandard names if it knows the library being built is a
5357 libtool module, i.e., if @option{-module} explicitly appears in the
5358 library's @code{_LDFLAGS} variable (or in the common @code{AM_LDFLAGS}
5359 variable when no per-library @code{_LDFLAGS} variable is defined).
5360
5361 As always, @code{AC_SUBST} variables are black boxes to Automake since
5362 their values are not yet known when @command{automake} is run.
5363 Therefore if @option{-module} is set via such a variable, Automake
5364 cannot notice it and will proceed as if the library was an ordinary
5365 libtool library, with strict naming.
5366
5367 If @code{mymodule_la_SOURCES} is not specified, then it defaults to
5368 the single file @file{mymodule.c} (@pxref{Default _SOURCES}).
5369
5370 @node Libtool Flags
5371 @subsection @code{_LIBADD}, @code{_LDFLAGS}, and @code{_LIBTOOLFLAGS}
5372 @cindex @code{_LIBADD}, libtool
5373 @cindex @code{_LDFLAGS}, libtool
5374 @cindex @code{_LIBTOOLFLAGS}, libtool
5375 @vindex AM_LIBTOOLFLAGS
5376 @vindex LIBTOOLFLAGS
5377 @vindex maude_LIBTOOLFLAGS
5378
5379 As shown in previous sections, the @samp{@var{library}_LIBADD}
5380 variable should be used to list extra libtool objects (@file{.lo}
5381 files) or libtool libraries (@file{.la}) to add to @var{library}.
5382
5383 The @samp{@var{library}_LDFLAGS} variable is the place to list
5384 additional libtool linking flags, such as @option{-version-info},
5385 @option{-static}, and a lot more.  @xref{Link mode, , Link mode,
5386 libtool, The Libtool Manual}.
5387
5388 The @command{libtool} command has two kinds of options: mode-specific
5389 options and generic options.  Mode-specific options such as the
5390 aforementioned linking flags should be lumped with the other flags
5391 passed to the tool invoked by @command{libtool} (hence the use of
5392 @samp{@var{library}_LDFLAGS} for libtool linking flags).  Generic
5393 options include @option{--tag=@var{tag}} and @option{--silent}
5394 (@pxref{Invoking libtool, , Invoking @command{libtool}, libtool, The
5395 Libtool Manual} for more options) should appear before the mode
5396 selection on the command line; in @file{Makefile.am}s they should
5397 be listed in the @samp{@var{library}_LIBTOOLFLAGS} variable.
5398
5399 If @samp{@var{library}_LIBTOOLFLAGS} is not defined, then the variable
5400 @code{AM_LIBTOOLFLAGS} is used instead.
5401
5402 These flags are passed to libtool after the @option{--tag=@var{tag}}
5403 option computed by Automake (if any), so
5404 @samp{@var{library}_LIBTOOLFLAGS} (or @code{AM_LIBTOOLFLAGS}) is a
5405 good place to override or supplement the @option{--tag=@var{tag}}
5406 setting.
5407
5408 The libtool rules also use a @code{LIBTOOLFLAGS} variable that should
5409 not be set in @file{Makefile.am}: this is a user variable (@pxref{Flag
5410 Variables Ordering}.  It allows users to run @samp{make
5411 LIBTOOLFLAGS=--silent}, for instance.  Note that the verbosity of
5412 @command{libtool} can also be influenced with the Automake
5413 @option{silent-rules} option (@pxref{Options}).
5414
5415
5416 @node LTLIBOBJS, Libtool Issues, Libtool Flags, A Shared Library
5417 @subsection @code{LTLIBOBJS} and @code{LTALLOCA}
5418 @cindex @code{LTLIBOBJS}, special handling
5419 @cindex @code{LIBOBJS}, and Libtool
5420 @cindex @code{LTALLOCA}, special handling
5421 @cindex @code{ALLOCA}, and Libtool
5422 @vindex LTLIBOBJS
5423 @vindex LIBOBJS
5424 @vindex LTALLOCA
5425 @vindex ALLOCA
5426 @acindex AC_LIBOBJ
5427
5428 Where an ordinary library might include @samp{$(LIBOBJS)} or
5429 @samp{$(ALLOCA)} (@pxref{LIBOBJS}), a libtool library must use
5430 @samp{$(LTLIBOBJS)} or @samp{$(LTALLOCA)}.  This is required because
5431 the object files that libtool operates on do not necessarily end in
5432 @file{.o}.
5433
5434 Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
5435 performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
5436 @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual}).
5437
5438 @node Libtool Issues
5439 @subsection Common Issues Related to Libtool's Use
5440
5441 @menu
5442 * Error required file ltmain.sh not found::  The need to run libtoolize
5443 * Objects created both with libtool and without::  Avoid a specific build race
5444 @end menu
5445
5446 @node Error required file ltmain.sh not found
5447 @subsubsection Error: @samp{required file `./ltmain.sh' not found}
5448 @cindex @file{ltmain.sh} not found
5449 @cindex @command{libtoolize}, no longer run by @command{automake}
5450 @cindex @command{libtoolize} and @command{autoreconf}
5451 @cindex @command{autoreconf} and @command{libtoolize}
5452 @cindex @file{bootstrap.sh} and @command{autoreconf}
5453 @cindex @file{autogen.sh} and @command{autoreconf}
5454
5455 Libtool comes with a tool called @command{libtoolize} that will
5456 install libtool's supporting files into a package.  Running this
5457 command will install @file{ltmain.sh}.  You should execute it before
5458 @command{aclocal} and @command{automake}.
5459
5460 People upgrading old packages to newer autotools are likely to face
5461 this issue because older Automake versions used to call
5462 @command{libtoolize}.  Therefore old build scripts do not call
5463 @command{libtoolize}.
5464
5465 Since Automake 1.6, it has been decided that running
5466 @command{libtoolize} was none of Automake's business.  Instead, that
5467 functionality has been moved into the @command{autoreconf} command
5468 (@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
5469 The Autoconf Manual}).  If you do not want to remember what to run and
5470 when, just learn the @command{autoreconf} command.  Hopefully,
5471 replacing existing @file{bootstrap.sh} or @file{autogen.sh} scripts by
5472 a call to @command{autoreconf} should also free you from any similar
5473 incompatible change in the future.
5474
5475 @node Objects created both with libtool and without
5476 @subsubsection Objects @samp{created with both libtool and without}
5477
5478 Sometimes, the same source file is used both to build a libtool
5479 library and to build another non-libtool target (be it a program or
5480 another library).
5481
5482 Let's consider the following @file{Makefile.am}.
5483
5484 @example
5485 bin_PROGRAMS = prog
5486 prog_SOURCES = prog.c foo.c @dots{}
5487
5488 lib_LTLIBRARIES = libfoo.la
5489 libfoo_la_SOURCES = foo.c @dots{}
5490 @end example
5491
5492 @noindent
5493 (In this trivial case the issue could be avoided by linking
5494 @file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
5495 @code{prog_SOURCES}.  But let's assume we really want to keep
5496 @file{prog} and @file{libfoo.la} separate.)
5497
5498 Technically, it means that we should build @file{foo.$(OBJEXT)} for
5499 @file{prog}, and @file{foo.lo} for @file{libfoo.la}.  The problem is
5500 that in the course of creating @file{foo.lo}, libtool may erase (or
5501 replace) @file{foo.$(OBJEXT)}, and this cannot be avoided.
5502
5503 Therefore, when Automake detects this situation it will complain
5504 with a message such as
5505 @example
5506 object `foo.$(OBJEXT)' created both with libtool and without
5507 @end example
5508
5509 A workaround for this issue is to ensure that these two objects get
5510 different basenames.  As explained in @ref{Renamed Objects}, this
5511 happens automatically when per-targets flags are used.
5512
5513 @example
5514 bin_PROGRAMS = prog
5515 prog_SOURCES = prog.c foo.c @dots{}
5516 prog_CFLAGS = $(AM_CFLAGS)
5517
5518 lib_LTLIBRARIES = libfoo.la
5519 libfoo_la_SOURCES = foo.c @dots{}
5520 @end example
5521
5522 @noindent
5523 Adding @samp{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
5524 when the @code{prog_CFLAGS} is defined, it is used instead of
5525 @code{AM_CFLAGS}.  However as a side effect it will cause
5526 @file{prog.c} and @file{foo.c} to be compiled as
5527 @file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)}, which solves
5528 the issue.
5529
5530 @node Program and Library Variables
5531 @section Program and Library Variables
5532
5533 Associated with each program is a collection of variables that can be
5534 used to modify how that program is built.  There is a similar list of
5535 such variables for each library.  The canonical name of the program (or
5536 library) is used as a base for naming these variables.
5537
5538 In the list below, we use the name ``maude'' to refer to the program or
5539 library.  In your @file{Makefile.am} you would replace this with the
5540 canonical name of your program.  This list also refers to ``maude'' as a
5541 program, but in general the same rules apply for both static and dynamic
5542 libraries; the documentation below notes situations where programs and
5543 libraries differ.
5544
5545 @vtable @code
5546 @item maude_SOURCES
5547 This variable, if it exists, lists all the source files that are
5548 compiled to build the program.  These files are added to the
5549 distribution by default.  When building the program, Automake will cause
5550 each source file to be compiled to a single @file{.o} file (or
5551 @file{.lo} when using libtool).  Normally these object files are named
5552 after the source file, but other factors can change this.  If a file in
5553 the @code{_SOURCES} variable has an unrecognized extension, Automake
5554 will do one of two things with it.  If a suffix rule exists for turning
5555 files with the unrecognized extension into @file{.o} files, then
5556 @command{automake} will treat this file as it will any other source file
5557 (@pxref{Support for Other Languages}).  Otherwise, the file will be
5558 ignored as though it were a header file.
5559
5560 The prefixes @code{dist_} and @code{nodist_} can be used to control
5561 whether files listed in a @code{_SOURCES} variable are distributed.
5562 @code{dist_} is redundant, as sources are distributed by default, but it
5563 can be specified for clarity if desired.
5564
5565 It is possible to have both @code{dist_} and @code{nodist_} variants of
5566 a given @code{_SOURCES} variable at once; this lets you easily
5567 distribute some files and not others, for instance:
5568
5569 @example
5570 nodist_maude_SOURCES = nodist.c
5571 dist_maude_SOURCES = dist-me.c
5572 @end example
5573
5574 By default the output file (on Unix systems, the @file{.o} file) will
5575 be put into the current build directory.  However, if the option
5576 @option{subdir-objects} is in effect in the current directory then the
5577 @file{.o} file will be put into the subdirectory named after the
5578 source file.  For instance, with @option{subdir-objects} enabled,
5579 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
5580 people prefer this mode of operation.  You can specify
5581 @option{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
5582 @cindex Subdirectory, objects in
5583 @cindex Objects in subdirectory
5584
5585
5586 @item EXTRA_maude_SOURCES
5587 Automake needs to know the list of files you intend to compile
5588 @emph{statically}.  For one thing, this is the only way Automake has of
5589 knowing what sort of language support a given @file{Makefile.in}
5590 requires.  @footnote{There are other, more obscure reasons for
5591 this limitation as well.}  This means that, for example, you can't put a
5592 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
5593 variable.  If you intend to conditionally compile source files and use
5594 @file{configure} to substitute the appropriate object names into, e.g.,
5595 @code{_LDADD} (see below), then you should list the corresponding source
5596 files in the @code{EXTRA_} variable.
5597
5598 This variable also supports @code{dist_} and @code{nodist_} prefixes.
5599 For instance, @code{nodist_EXTRA_maude_SOURCES} would list extra
5600 sources that may need to be built, but should not be distributed.
5601
5602 @item maude_AR
5603 A static library is created by default by invoking @samp{$(AR)
5604 $(ARFLAGS)} followed by the name of the library and then the objects
5605 being put into the library.  You can override this by setting the
5606 @code{_AR} variable.  This is usually used with C++; some C++
5607 compilers require a special invocation in order to instantiate all the
5608 templates that should go into a library.  For instance, the SGI C++
5609 compiler likes this variable set like so:
5610 @example
5611 libmaude_a_AR = $(CXX) -ar -o
5612 @end example
5613
5614 @item maude_LIBADD
5615 Extra objects can be added to a @emph{library} using the @code{_LIBADD}
5616 variable.  For instance, this should be used for objects determined by
5617 @command{configure} (@pxref{A Library}).
5618
5619 In the case of libtool libraries, @code{maude_LIBADD} can also refer
5620 to other libtool libraries.
5621
5622 @item maude_LDADD
5623 Extra objects (@file{*.$(OBJEXT)}) and libraries (@file{*.a},
5624 @file{*.la}) can be added to a @emph{program} by listing them in the
5625 @code{_LDADD} variable.  For instance, this should be used for objects
5626 determined by @command{configure} (@pxref{Linking}).
5627
5628 @code{_LDADD} and @code{_LIBADD} are inappropriate for passing
5629 program-specific linker flags (except for @option{-l}, @option{-L},
5630 @option{-dlopen} and @option{-dlpreopen}).  Use the @code{_LDFLAGS} variable
5631 for this purpose.
5632
5633 For instance, if your @file{configure.ac} uses @code{AC_PATH_XTRA}, you
5634 could link your program against the X libraries like so:
5635
5636 @example
5637 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
5638 @end example
5639
5640 We recommend that you use @option{-l} and @option{-L} only when
5641 referring to third-party libraries, and give the explicit file names
5642 of any library built by your package.  Doing so will ensure that
5643 @code{maude_DEPENDENCIES} (see below) is correctly defined by default.
5644
5645 @item maude_LDFLAGS
5646 This variable is used to pass extra flags to the link step of a program
5647 or a shared library.  It overrides the @code{AM_LDFLAGS} variable.
5648
5649 @item maude_LIBTOOLFLAGS
5650 This variable is used to pass extra options to @command{libtool}.
5651 It overrides the @code{AM_LIBTOOLFLAGS} variable.
5652 These options are output before @command{libtool}'s @option{--mode=@var{mode}}
5653 option, so they should not be mode-specific options (those belong to
5654 the compiler or linker flags).  @xref{Libtool Flags}.
5655
5656 @item maude_DEPENDENCIES
5657 It is also occasionally useful to have a target (program or library)
5658 depend on some other file that is not actually part of that target.
5659 This can be done using the @code{_DEPENDENCIES} variable.  Each
5660 target depends on the contents of such a variable, but no further
5661 interpretation is done.
5662
5663 Since these dependencies are associated to the link rule used to
5664 create the programs they should normally list files used by the link
5665 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la} files
5666 for programs; @file{*.lo} and @file{*.la} files for Libtool libraries;
5667 and @file{*.$(OBJEXT)} files for static libraries.  In rare cases you
5668 may need to add other kinds of files such as linker scripts, but
5669 @emph{listing a source file in @code{_DEPENDENCIES} is wrong}.  If
5670 some source file needs to be built before all the components of a
5671 program are built, consider using the @code{BUILT_SOURCES} variable
5672 (@pxref{Sources}).
5673
5674 If @code{_DEPENDENCIES} is not supplied, it is computed by Automake.
5675 The automatically-assigned value is the contents of @code{_LDADD} or
5676 @code{_LIBADD}, with most configure substitutions, @option{-l}, @option{-L},
5677 @option{-dlopen} and @option{-dlpreopen} options removed.  The configure
5678 substitutions that are left in are only @samp{$(LIBOBJS)} and
5679 @samp{$(ALLOCA)}; these are left because it is known that they will not
5680 cause an invalid value for @code{_DEPENDENCIES} to be generated.
5681
5682 @code{_DEPENDENCIES} is more likely used to perform conditional
5683 compilation using an @code{AC_SUBST} variable that contains a list of
5684 objects.  @xref{Conditional Sources}, and @ref{Conditional Libtool
5685 Sources}.
5686
5687 @item maude_LINK
5688 You can override the linker on a per-program basis.  By default the
5689 linker is chosen according to the languages used by the program.  For
5690 instance, a program that includes C++ source code would use the C++
5691 compiler to link.  The @code{_LINK} variable must hold the name of a
5692 command that can be passed all the @file{.o} file names and libraries
5693 to link against as arguments.  Note that the name of the underlying
5694 program is @emph{not} passed to @code{_LINK}; typically one uses
5695 @samp{$@@}:
5696
5697 @example
5698 maude_LINK = $(CCLD) -magic -o $@@
5699 @end example
5700
5701 If a @code{_LINK} variable is not supplied, it may still be generated
5702 and used by Automake due to the use of per-target link flags such as
5703 @code{_CFLAGS}, @code{_LDFLAGS} or @code{_LIBTOOLFLAGS}, in cases where
5704 they apply.
5705
5706 @item maude_CCASFLAGS
5707 @itemx maude_CFLAGS
5708 @itemx maude_CPPFLAGS
5709 @itemx maude_CXXFLAGS
5710 @itemx maude_FFLAGS
5711 @itemx maude_GCJFLAGS
5712 @itemx maude_LFLAGS
5713 @itemx maude_OBJCFLAGS
5714 @itemx maude_RFLAGS
5715 @itemx maude_UPCFLAGS
5716 @itemx maude_YFLAGS
5717 @cindex per-target compilation flags, defined
5718 Automake allows you to set compilation flags on a per-program (or
5719 per-library) basis.  A single source file can be included in several
5720 programs, and it will potentially be compiled with different flags for
5721 each program.  This works for any language directly supported by
5722 Automake.  These @dfn{per-target compilation flags} are
5723 @samp{_CCASFLAGS},
5724 @samp{_CFLAGS},
5725 @samp{_CPPFLAGS},
5726 @samp{_CXXFLAGS},
5727 @samp{_FFLAGS},
5728 @samp{_GCJFLAGS},
5729 @samp{_LFLAGS},
5730 @samp{_OBJCFLAGS},
5731 @samp{_RFLAGS},
5732 @samp{_UPCFLAGS}, and
5733 @samp{_YFLAGS}.
5734
5735 When using a per-target compilation flag, Automake will choose a
5736 different name for the intermediate object files.  Ordinarily a file
5737 like @file{sample.c} will be compiled to produce @file{sample.o}.
5738 However, if the program's @code{_CFLAGS} variable is set, then the
5739 object file will be named, for instance, @file{maude-sample.o}.  (See
5740 also @ref{Renamed Objects}.)  The use of per-target compilation flags
5741 with C sources requires that the macro @code{AM_PROG_CC_C_O} be called
5742 from @file{configure.ac}.
5743
5744 In compilations with per-target flags, the ordinary @samp{AM_} form of
5745 the flags variable is @emph{not} automatically included in the
5746 compilation (however, the user form of the variable @emph{is} included).
5747 So for instance, if you want the hypothetical @file{maude} compilations
5748 to also use the value of @code{AM_CFLAGS}, you would need to write:
5749
5750 @example
5751 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
5752 @end example
5753
5754 @xref{Flag Variables Ordering}, for more discussion about the
5755 interaction between user variables, @samp{AM_} shadow variables, and
5756 per-target variables.
5757
5758 @item maude_SHORTNAME
5759 On some platforms the allowable file names are very short.  In order to
5760 support these systems and per-target compilation flags at the same
5761 time, Automake allows you to set a ``short name'' that will influence
5762 how intermediate object files are named.  For instance, in the following
5763 example,
5764
5765 @example
5766 bin_PROGRAMS = maude
5767 maude_CPPFLAGS = -DSOMEFLAG
5768 maude_SHORTNAME = m
5769 maude_SOURCES = sample.c @dots{}
5770 @end example
5771
5772 @noindent
5773 the object file would be named @file{m-sample.o} rather than
5774 @file{maude-sample.o}.
5775
5776 This facility is rarely needed in practice,
5777 and we recommend avoiding it until you find it is required.
5778 @end vtable
5779
5780 @node Default _SOURCES
5781 @section Default @code{_SOURCES}
5782
5783 @vindex _SOURCES
5784 @vindex SOURCES
5785 @cindex @code{_SOURCES}, default
5786 @cindex default @code{_SOURCES}
5787 @vindex AM_DEFAULT_SOURCE_EXT
5788
5789 @code{_SOURCES} variables are used to specify source files of programs
5790 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
5791 libraries (@pxref{A Shared Library}).
5792
5793 When no such variable is specified for a target, Automake will define
5794 one itself.  The default is to compile a single C file whose base name
5795 is the name of the target itself, with any extension replaced by
5796 @code{AM_DEFAULT_SOURCE_EXT}, which defaults to @file{.c}.
5797
5798 For example if you have the following somewhere in your
5799 @file{Makefile.am} with no corresponding @code{libfoo_a_SOURCES}:
5800
5801 @example
5802 lib_LIBRARIES = libfoo.a sub/libc++.a
5803 @end example
5804
5805 @noindent
5806 @file{libfoo.a} will be built using a default source file named
5807 @file{libfoo.c}, and @file{sub/libc++.a} will be built from
5808 @file{sub/libc++.c}.  (In older versions @file{sub/libc++.a}
5809 would be built from @file{sub_libc___a.c}, i.e., the default source
5810 was the canonized name of the target, with @file{.c} appended.
5811 We believe the new behavior is more sensible, but for backward
5812 compatibility @command{automake} will use the old name if a file or a rule
5813 with that name exists and @code{AM_DEFAULT_SOURCE_EXT} is not used.)
5814
5815 @cindex @code{check_PROGRAMS} example
5816 @vindex check_PROGRAMS
5817 Default sources are mainly useful in test suites, when building many
5818 test programs each from a single source.  For instance, in
5819
5820 @example
5821 check_PROGRAMS = test1 test2 test3
5822 AM_DEFAULT_SOURCE_EXT = .cpp
5823 @end example
5824
5825 @noindent
5826 @file{test1}, @file{test2}, and @file{test3} will be built
5827 from @file{test1.cpp}, @file{test2.cpp}, and @file{test3.cpp}.
5828 Without the last line, they will be built from @file{test1.c},
5829 @file{test2.c}, and @file{test3.c}.
5830
5831 @cindex Libtool modules, default source example
5832 @cindex default source, Libtool modules example
5833 Another case where this is convenient is building many Libtool modules
5834 (@file{module@var{n}.la}), each defined in its own file
5835 (@file{module@var{n}.c}).
5836
5837 @example
5838 AM_LDFLAGS = -module
5839 lib_LTLIBRARIES = module1.la module2.la module3.la
5840 @end example
5841
5842 @cindex empty @code{_SOURCES}
5843 @cindex @code{_SOURCES}, empty
5844 Finally, there is one situation where this default source computation
5845 needs to be avoided: when a target should not be built from sources.
5846 We already saw such an example in @ref{true}; this happens when all
5847 the constituents of a target have already been compiled and just need
5848 to be combined using a @code{_LDADD} variable.  Then it is necessary
5849 to define an empty @code{_SOURCES} variable, so that @command{automake}
5850 does not compute a default.
5851
5852 @example
5853 bin_PROGRAMS = target
5854 target_SOURCES =
5855 target_LDADD = libmain.a libmisc.a
5856 @end example
5857
5858 @node LIBOBJS
5859 @section Special handling for @code{LIBOBJS} and @code{ALLOCA}
5860
5861 @cindex @code{LIBOBJS}, example
5862 @cindex @code{ALLOCA}, example
5863 @cindex @code{LIBOBJS}, special handling
5864 @cindex @code{ALLOCA}, special handling
5865 @vindex LTLIBOBJS
5866 @vindex LIBOBJS
5867 @vindex LTALLOCA
5868 @vindex ALLOCA
5869
5870 The @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} variables list object
5871 files that should be compiled into the project to provide an
5872 implementation for functions that are missing or broken on the host
5873 system.  They are substituted by @file{configure}.
5874
5875 @acindex AC_LIBOBJ
5876
5877 These variables are defined by Autoconf macros such as
5878 @code{AC_LIBOBJ}, @code{AC_REPLACE_FUNCS} (@pxref{Generic Functions, ,
5879 Generic Function Checks, autoconf, The Autoconf Manual}), or
5880 @code{AC_FUNC_ALLOCA} (@pxref{Particular Functions, , Particular
5881 Function Checks, autoconf, The Autoconf Manual}).  Many other Autoconf
5882 macros call @code{AC_LIBOBJ} or @code{AC_REPLACE_FUNCS} to
5883 populate @samp{$(LIBOBJS)}.
5884
5885 @acindex AC_LIBSOURCE
5886
5887 Using these variables is very similar to doing conditional compilation
5888 using @code{AC_SUBST} variables, as described in @ref{Conditional
5889 Sources}.  That is, when building a program, @samp{$(LIBOBJS)} and
5890 @samp{$(ALLOCA)} should be added to the associated @samp{*_LDADD}
5891 variable, or to the @samp{*_LIBADD} variable when building a library.
5892 However there is no need to list the corresponding sources in
5893 @samp{EXTRA_*_SOURCES} nor to define @samp{*_DEPENDENCIES}.  Automake
5894 automatically adds @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} to the
5895 dependencies, and it will discover the list of corresponding source
5896 files automatically (by tracing the invocations of the
5897 @code{AC_LIBSOURCE} Autoconf macros).  However, if you have already
5898 defined @samp{*_DEPENDENCIES} explicitly for an unrelated reason, then
5899 you have to add these variables manually.
5900
5901 These variables are usually used to build a portability library that
5902 is linked with all the programs of the project.  We now review a
5903 sample setup.  First, @file{configure.ac} contains some checks that
5904 affect either @code{LIBOBJS} or @code{ALLOCA}.
5905
5906 @example
5907 # configure.ac
5908 @dots{}
5909 AC_CONFIG_LIBOBJ_DIR([lib])
5910 @dots{}
5911 AC_FUNC_MALLOC             dnl May add malloc.$(OBJEXT) to LIBOBJS
5912 AC_FUNC_MEMCMP             dnl May add memcmp.$(OBJEXT) to LIBOBJS
5913 AC_REPLACE_FUNCS([strdup]) dnl May add strdup.$(OBJEXT) to LIBOBJS
5914 AC_FUNC_ALLOCA             dnl May add alloca.$(OBJEXT) to ALLOCA
5915 @dots{}
5916 AC_CONFIG_FILES([
5917   lib/Makefile
5918   src/Makefile
5919 ])
5920 AC_OUTPUT
5921 @end example
5922
5923 @acindex AC_CONFIG_LIBOBJ_DIR
5924
5925 The @code{AC_CONFIG_LIBOBJ_DIR} tells Autoconf that the source files
5926 of these object files are to be found in the @file{lib/} directory.
5927 Automake can also use this information, otherwise it expects the
5928 source files are to be in the directory where the @samp{$(LIBOBJS)}
5929 and @samp{$(ALLOCA)} variables are used.
5930
5931 The @file{lib/} directory should therefore contain @file{malloc.c},
5932 @file{memcmp.c}, @file{strdup.c}, @file{alloca.c}.  Here is its
5933 @file{Makefile.am}:
5934
5935 @example
5936 # lib/Makefile.am
5937
5938 noinst_LIBRARIES = libcompat.a
5939 libcompat_a_SOURCES =
5940 libcompat_a_LIBADD = $(LIBOBJS) $(ALLOCA)
5941 @end example
5942
5943 The library can have any name, of course, and anyway it is not going
5944 to be installed: it just holds the replacement versions of the missing
5945 or broken functions so we can later link them in.  Many projects
5946 also include extra functions, specific to the project, in that
5947 library: they are simply added on the @code{_SOURCES} line.
5948
5949 @cindex Empty libraries and @samp{$(LIBOBJS)}
5950 @cindex @samp{$(LIBOBJS)} and empty libraries
5951 There is a small trap here, though: @samp{$(LIBOBJS)} and
5952 @samp{$(ALLOCA)} might be empty, and building an empty library is not
5953 portable.  You should ensure that there is always something to put in
5954 @file{libcompat.a}.  Most projects will also add some utility
5955 functions in that directory, and list them in
5956 @code{libcompat_a_SOURCES}, so in practice @file{libcompat.a} cannot
5957 be empty.
5958
5959 Finally here is how this library could be used from the @file{src/}
5960 directory.
5961
5962 @example
5963 # src/Makefile.am
5964
5965 # Link all programs in this directory with libcompat.a
5966 LDADD = ../lib/libcompat.a
5967
5968 bin_PROGRAMS = tool1 tool2 @dots{}
5969 tool1_SOURCES = @dots{}
5970 tool2_SOURCES = @dots{}
5971 @end example
5972
5973 When option @option{subdir-objects} is not used, as in the above
5974 example, the variables @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} can only
5975 be used in the directory where their sources lie.  E.g., here it would
5976 be wrong to use @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} in
5977 @file{src/Makefile.am}.  However if both @option{subdir-objects} and
5978 @code{AC_CONFIG_LIBOBJ_DIR} are used, it is OK to use these variables
5979 in other directories.  For instance @file{src/Makefile.am} could be
5980 changed as follows.
5981
5982 @example
5983 # src/Makefile.am
5984
5985 AUTOMAKE_OPTIONS = subdir-objects
5986 LDADD = $(LIBOBJS) $(ALLOCA)
5987
5988 bin_PROGRAMS = tool1 tool2 @dots{}
5989 tool1_SOURCES = @dots{}
5990 tool2_SOURCES = @dots{}
5991 @end example
5992
5993 Because @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} contain object
5994 file names that end with @samp{.$(OBJEXT)}, they are not suitable for
5995 Libtool libraries (where the expected object extension is @file{.lo}):
5996 @code{LTLIBOBJS} and @code{LTALLOCA} should be used instead.
5997
5998 @code{LTLIBOBJS} is defined automatically by Autoconf and should not
5999 be defined by hand (as in the past), however at the time of writing
6000 @code{LTALLOCA} still needs to be defined from @code{ALLOCA} manually.
6001 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
6002 autoconf, The Autoconf Manual}.
6003
6004
6005 @node Program Variables
6006 @section Variables used when building a program
6007
6008 Occasionally it is useful to know which @file{Makefile} variables
6009 Automake uses for compilations, and in which order (@pxref{Flag
6010 Variables Ordering}); for instance, you might need to do your own
6011 compilation in some special cases.
6012
6013 Some variables are inherited from Autoconf; these are @code{CC},
6014 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
6015 @code{LIBS}.
6016 @vindex CC
6017 @vindex CFLAGS
6018 @vindex CPPFLAGS
6019 @vindex DEFS
6020 @vindex LDFLAGS
6021 @vindex LIBS
6022
6023 There are some additional variables that Automake defines on its own:
6024
6025 @vtable @code
6026 @item AM_CPPFLAGS
6027 The contents of this variable are passed to every compilation that invokes
6028 the C preprocessor; it is a list of arguments to the preprocessor.  For
6029 instance, @option{-I} and @option{-D} options should be listed here.
6030
6031 Automake already provides some @option{-I} options automatically, in a
6032 separate variable that is also passed to every compilation that invokes
6033 the C preprocessor.  In particular it generates @samp{-I.},
6034 @samp{-I$(srcdir)}, and a @option{-I} pointing to the directory holding
6035 @file{config.h} (if you've used @code{AC_CONFIG_HEADERS} or
6036 @code{AM_CONFIG_HEADER}).  You can disable the default @option{-I}
6037 options using the @option{nostdinc} option.
6038
6039 When a file to be included is generated during the build and not part
6040 of a distribution tarball, its location is under @code{$(builddir)},
6041 not under @code{$(srcdir)}.  This matters especially for packages that
6042 use header files placed in sub-directories and want to allow builds
6043 outside the source tree (@pxref{VPATH Builds}). In that case we
6044 recommend to use a pair of @option{-I} options, such as, e.g.,
6045 @samp{-Isome/subdir -I$(srcdir)/some/subdir} or
6046 @samp{-I$(top_builddir)/some/subdir -I$(top_srcdir)/some/subdir}.
6047 Note that the reference to the build tree should come before the
6048 reference to the source tree, so that accidentally leftover generated
6049 files in the source directory are ignored.
6050
6051 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
6052 per-library) @code{_CPPFLAGS} variable if it is defined.
6053
6054 @item INCLUDES
6055 This does the same job as @code{AM_CPPFLAGS} (or any per-target
6056 @code{_CPPFLAGS} variable if it is used).  It is an older name for the
6057 same functionality.  This variable is deprecated; we suggest using
6058 @code{AM_CPPFLAGS} and per-target @code{_CPPFLAGS} instead.
6059
6060 @item AM_CFLAGS
6061 This is the variable the @file{Makefile.am} author can use to pass
6062 in additional C compiler flags.  It is more fully documented elsewhere.
6063 In some situations, this is not used, in preference to the
6064 per-executable (or per-library) @code{_CFLAGS}.
6065
6066 @item COMPILE
6067 This is the command used to actually compile a C source file.  The
6068 file name is appended to form the complete command line.
6069
6070 @item AM_LDFLAGS
6071 This is the variable the @file{Makefile.am} author can use to pass
6072 in additional linker flags.  In some situations, this is not used, in
6073 preference to the per-executable (or per-library) @code{_LDFLAGS}.
6074
6075 @item LINK
6076 This is the command used to actually link a C program.  It already
6077 includes @samp{-o $@@} and the usual variable references (for instance,
6078 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
6079 and libraries to link in.  This variable is not used when the linker is
6080 overridden with a per-target @code{_LINK} variable or per-target flags
6081 cause Automake to define such a @code{_LINK} variable.
6082 @end vtable
6083
6084
6085 @node Yacc and Lex
6086 @section Yacc and Lex support
6087
6088 Automake has somewhat idiosyncratic support for Yacc and Lex.
6089
6090 Automake assumes that the @file{.c} file generated by @command{yacc}
6091 (or @command{lex}) should be named using the basename of the input
6092 file.  That is, for a yacc source file @file{foo.y}, Automake will
6093 cause the intermediate file to be named @file{foo.c} (as opposed to
6094 @file{y.tab.c}, which is more traditional).
6095
6096 The extension of a yacc source file is used to determine the extension
6097 of the resulting C or C++ source and header files.  Note that header
6098 files are generated only when the @option{-d} Yacc option is used; see
6099 below for more information about this flag, and how to specify it.
6100 Files with the extension @file{.y} will thus be turned into @file{.c}
6101 sources and @file{.h} headers; likewise, @file{.yy} will become
6102 @file{.cc} and @file{.hh}, @file{.y++} will become @file{c++} and
6103 @file{h++}, @file{.yxx} will become @file{.cxx} and @file{.hxx},
6104 and @file{.ypp} will become @file{.cpp} and @file{.hpp}.
6105
6106 Similarly, lex source files can be used to generate C or C++; the
6107 extensions @file{.l}, @file{.ll}, @file{.l++}, @file{.lxx}, and
6108 @file{.lpp} are recognized.
6109
6110 You should never explicitly mention the intermediate (C or C++) file
6111 in any @code{SOURCES} variable; only list the source file.
6112
6113 The intermediate files generated by @command{yacc} (or @command{lex})
6114 will be included in any distribution that is made.  That way the user
6115 doesn't need to have @command{yacc} or @command{lex}.
6116
6117 If a @command{yacc} source file is seen, then your @file{configure.ac} must
6118 define the variable @code{YACC}.  This is most easily done by invoking
6119 the macro @code{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
6120 Program Checks, autoconf, The Autoconf Manual}).
6121
6122 @vindex YFLAGS
6123 @vindex AM_YFLAGS
6124 When @code{yacc} is invoked, it is passed @code{AM_YFLAGS} and
6125 @code{YFLAGS}.  The latter is a user variable and the former is
6126 intended for the @file{Makefile.am} author.
6127
6128 @code{AM_YFLAGS} is usually used to pass the @option{-d} option to
6129 @command{yacc}.  Automake knows what this means and will automatically
6130 adjust its rules to update and distribute the header file built by
6131 @samp{yacc -d}@footnote{Please note that @command{automake} recognizes
6132 @option{-d} in @code{AM_YFLAGS} only if it is not clustered with other
6133 options; for example, it won't be recognized if @code{AM_YFLAGS} is
6134 @option{-dt}, but it will be if @code{AM_YFLAGS} is @option{-d -t} or
6135 @option{-d -t}}.
6136 What Automake cannot guess, though, is where this
6137 header will be used: it is up to you to ensure the header gets built
6138 before it is first used.  Typically this is necessary in order for
6139 dependency tracking to work when the header is included by another
6140 file.  The common solution is listing the header file in
6141 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
6142
6143 @example
6144 BUILT_SOURCES = parser.h
6145 AM_YFLAGS = -d
6146 bin_PROGRAMS = foo
6147 foo_SOURCES = @dots{} parser.y @dots{}
6148 @end example
6149
6150 If a @command{lex} source file is seen, then your @file{configure.ac}
6151 must define the variable @code{LEX}.  You can use @code{AC_PROG_LEX}
6152 to do this (@pxref{Particular Programs, , Particular Program Checks,
6153 autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
6154 (@pxref{Macros}) is recommended.
6155
6156 @vindex LFLAGS
6157 @vindex AM_LFLAGS
6158 When @command{lex} is invoked, it is passed @code{AM_LFLAGS} and
6159 @code{LFLAGS}.  The latter is a user variable and the former is
6160 intended for the @file{Makefile.am} author.
6161
6162 When @code{AM_MAINTAINER_MODE} (@pxref{maintainer-mode}) is used, the
6163 rebuild rule for distributed Yacc and Lex sources are only used when
6164 @code{maintainer-mode} is enabled, or when the files have been erased.
6165
6166 @cindex @command{ylwrap}
6167 @cindex @command{yacc}, multiple parsers
6168 @cindex Multiple @command{yacc} parsers
6169 @cindex Multiple @command{lex} lexers
6170 @cindex @command{lex}, multiple lexers
6171
6172 When @command{lex} or @command{yacc} sources are used, @code{automake
6173 -i} automatically installs an auxiliary program called
6174 @command{ylwrap} in your package (@pxref{Auxiliary Programs}).  This
6175 program is used by the build rules to rename the output of these
6176 tools, and makes it possible to include multiple @command{yacc} (or
6177 @command{lex}) source files in a single directory.  (This is necessary
6178 because yacc's output file name is fixed, and a parallel make could
6179 conceivably invoke more than one instance of @command{yacc}
6180 simultaneously.)
6181
6182 For @command{yacc}, simply managing locking is insufficient.  The output of
6183 @command{yacc} always uses the same symbol names internally, so it isn't
6184 possible to link two @command{yacc} parsers into the same executable.
6185
6186 We recommend using the following renaming hack used in @command{gdb}:
6187 @example
6188 #define yymaxdepth c_maxdepth
6189 #define yyparse c_parse
6190 #define yylex   c_lex
6191 #define yyerror c_error
6192 #define yylval  c_lval
6193 #define yychar  c_char
6194 #define yydebug c_debug
6195 #define yypact  c_pact
6196 #define yyr1    c_r1
6197 #define yyr2    c_r2
6198 #define yydef   c_def
6199 #define yychk   c_chk
6200 #define yypgo   c_pgo
6201 #define yyact   c_act
6202 #define yyexca  c_exca
6203 #define yyerrflag c_errflag
6204 #define yynerrs c_nerrs
6205 #define yyps    c_ps
6206 #define yypv    c_pv
6207 #define yys     c_s
6208 #define yy_yys  c_yys
6209 #define yystate c_state
6210 #define yytmp   c_tmp
6211 #define yyv     c_v
6212 #define yy_yyv  c_yyv
6213 #define yyval   c_val
6214 #define yylloc  c_lloc
6215 #define yyreds  c_reds
6216 #define yytoks  c_toks
6217 #define yylhs   c_yylhs
6218 #define yylen   c_yylen
6219 #define yydefred c_yydefred
6220 #define yydgoto  c_yydgoto
6221 #define yysindex c_yysindex
6222 #define yyrindex c_yyrindex
6223 #define yygindex c_yygindex
6224 #define yytable  c_yytable
6225 #define yycheck  c_yycheck
6226 #define yyname   c_yyname
6227 #define yyrule   c_yyrule
6228 @end example
6229
6230 For each define, replace the @samp{c_} prefix with whatever you like.
6231 These defines work for @command{bison}, @command{byacc}, and
6232 traditional @code{yacc}s.  If you find a parser generator that uses a
6233 symbol not covered here, please report the new name so it can be added
6234 to the list.
6235
6236
6237 @node C++ Support
6238 @section C++ Support
6239
6240 @cindex C++ support
6241 @cindex Support for C++
6242
6243 Automake includes full support for C++.
6244
6245 Any package including C++ code must define the output variable
6246 @code{CXX} in @file{configure.ac}; the simplest way to do this is to use
6247 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
6248 Program Checks, autoconf, The Autoconf Manual}).
6249
6250 A few additional variables are defined when a C++ source file is seen:
6251
6252 @vtable @code
6253 @item CXX
6254 The name of the C++ compiler.
6255
6256 @item CXXFLAGS
6257 Any flags to pass to the C++ compiler.
6258
6259 @item AM_CXXFLAGS
6260 The maintainer's variant of @code{CXXFLAGS}.
6261
6262 @item CXXCOMPILE
6263 The command used to actually compile a C++ source file.  The file name
6264 is appended to form the complete command line.
6265
6266 @item CXXLINK
6267 The command used to actually link a C++ program.
6268 @end vtable
6269
6270
6271 @node Objective C Support
6272 @section Objective C Support
6273
6274 @cindex Objective C support
6275 @cindex Support for Objective C
6276
6277 Automake includes some support for Objective C.
6278
6279 Any package including Objective C code must define the output variable
6280 @code{OBJC} in @file{configure.ac}; the simplest way to do this is to use
6281 the @code{AC_PROG_OBJC} macro (@pxref{Particular Programs, , Particular
6282 Program Checks, autoconf, The Autoconf Manual}).
6283
6284 A few additional variables are defined when an Objective C source file
6285 is seen:
6286
6287 @vtable @code
6288 @item OBJC
6289 The name of the Objective C compiler.
6290
6291 @item OBJCFLAGS
6292 Any flags to pass to the Objective C compiler.
6293
6294 @item AM_OBJCFLAGS
6295 The maintainer's variant of @code{OBJCFLAGS}.
6296
6297 @item OBJCCOMPILE
6298 The command used to actually compile an Objective C source file.  The
6299 file name is appended to form the complete command line.
6300
6301 @item OBJCLINK
6302 The command used to actually link an Objective C program.
6303 @end vtable
6304
6305
6306 @node Unified Parallel C Support
6307 @section Unified Parallel C Support
6308
6309 @cindex Unified Parallel C support
6310 @cindex Support for Unified Parallel C
6311
6312 Automake includes some support for Unified Parallel C.
6313
6314 Any package including Unified Parallel C code must define the output
6315 variable @code{UPC} in @file{configure.ac}; the simplest way to do
6316 this is to use the @code{AM_PROG_UPC} macro (@pxref{Public Macros}).
6317
6318 A few additional variables are defined when a Unified Parallel C
6319 source file is seen:
6320
6321 @vtable @code
6322 @item UPC
6323 The name of the Unified Parallel C compiler.
6324
6325 @item UPCFLAGS
6326 Any flags to pass to the Unified Parallel C compiler.
6327
6328 @item AM_UPCFLAGS
6329 The maintainer's variant of @code{UPCFLAGS}.
6330
6331 @item UPCCOMPILE
6332 The command used to actually compile a Unified Parallel C source file.
6333 The file name is appended to form the complete command line.
6334
6335 @item UPCLINK
6336 The command used to actually link a Unified Parallel C program.
6337 @end vtable
6338
6339
6340 @node Assembly Support
6341 @section Assembly Support
6342
6343 Automake includes some support for assembly code.  There are two forms
6344 of assembler files: normal (@file{*.s}) and preprocessed by @code{CPP}
6345 (@file{*.S} or @file{*.sx}).
6346
6347 @vindex CCAS
6348 @vindex CCASFLAGS
6349 @vindex CPPFLAGS
6350 @vindex AM_CCASFLAGS
6351 @vindex AM_CPPFLAGS
6352 The variable @code{CCAS} holds the name of the compiler used to build
6353 assembly code.  This compiler must work a bit like a C compiler; in
6354 particular it must accept @option{-c} and @option{-o}.  The values of
6355 @code{CCASFLAGS} and @code{AM_CCASFLAGS} (or its per-target
6356 definition) is passed to the compilation.  For preprocessed files,
6357 @code{DEFS}, @code{DEFAULT_INCLUDES}, @code{INCLUDES}, @code{CPPFLAGS}
6358 and @code{AM_CPPFLAGS} are also used.
6359
6360 The autoconf macro @code{AM_PROG_AS} will define @code{CCAS} and
6361 @code{CCASFLAGS} for you (unless they are already set, it simply sets
6362 @code{CCAS} to the C compiler and @code{CCASFLAGS} to the C compiler
6363 flags), but you are free to define these variables by other means.
6364
6365 Only the suffixes @file{.s}, @file{.S}, and @file{.sx} are recognized by
6366 @command{automake} as being files containing assembly code.
6367
6368
6369 @node Fortran 77 Support
6370 @comment  node-name,  next,  previous,  up
6371 @section Fortran 77 Support
6372
6373 @cindex Fortran 77 support
6374 @cindex Support for Fortran 77
6375
6376 Automake includes full support for Fortran 77.
6377
6378 Any package including Fortran 77 code must define the output variable
6379 @code{F77} in @file{configure.ac}; the simplest way to do this is to use
6380 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
6381 Program Checks, autoconf, The Autoconf Manual}).
6382
6383 A few additional variables are defined when a Fortran 77 source file is
6384 seen:
6385
6386 @vtable @code
6387
6388 @item F77
6389 The name of the Fortran 77 compiler.
6390
6391 @item FFLAGS
6392 Any flags to pass to the Fortran 77 compiler.
6393
6394 @item AM_FFLAGS
6395 The maintainer's variant of @code{FFLAGS}.
6396
6397 @item RFLAGS
6398 Any flags to pass to the Ratfor compiler.
6399
6400 @item AM_RFLAGS
6401 The maintainer's variant of @code{RFLAGS}.
6402
6403 @item F77COMPILE
6404 The command used to actually compile a Fortran 77 source file.  The file
6405 name is appended to form the complete command line.
6406
6407 @item FLINK
6408 The command used to actually link a pure Fortran 77 program or shared
6409 library.
6410
6411 @end vtable
6412
6413 Automake can handle preprocessing Fortran 77 and Ratfor source files in
6414 addition to compiling them@footnote{Much, if not most, of the
6415 information in the following sections pertaining to preprocessing
6416 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
6417 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
6418 also contains some support for creating programs and shared libraries
6419 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
6420 Fortran 77 With C and C++}).
6421
6422 These issues are covered in the following sections.
6423
6424 @menu
6425 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
6426 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
6427 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
6428 @end menu
6429
6430
6431 @node Preprocessing Fortran 77
6432 @comment  node-name,  next,  previous,  up
6433 @subsection Preprocessing Fortran 77
6434
6435 @cindex Preprocessing Fortran 77
6436 @cindex Fortran 77, Preprocessing
6437 @cindex Ratfor programs
6438
6439 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
6440 rule runs just the preprocessor to convert a preprocessable Fortran 77
6441 or Ratfor source file into a strict Fortran 77 source file.  The precise
6442 command used is as follows:
6443
6444 @table @file
6445
6446 @item .F
6447 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6448 $(AM_FFLAGS) $(FFLAGS)}
6449
6450 @item .r
6451 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6452
6453 @end table
6454
6455
6456 @node Compiling Fortran 77 Files
6457 @comment  node-name,  next,  previous,  up
6458 @subsection Compiling Fortran 77 Files
6459
6460 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
6461 @file{N.r} by running the Fortran 77 compiler.  The precise command used
6462 is as follows:
6463
6464 @table @file
6465
6466 @item .f
6467 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
6468
6469 @item .F
6470 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6471 $(AM_FFLAGS) $(FFLAGS)}
6472
6473 @item .r
6474 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6475
6476 @end table
6477
6478
6479 @node Mixing Fortran 77 With C and C++
6480 @comment  node-name,  next,  previous,  up
6481 @subsection Mixing Fortran 77 With C and C++
6482
6483 @cindex Fortran 77, mixing with C and C++
6484 @cindex Mixing Fortran 77 with C and C++
6485 @cindex Linking Fortran 77 with C and C++
6486 @cindex cfortran
6487 @cindex Mixing Fortran 77 with C and/or C++
6488
6489 Automake currently provides @emph{limited} support for creating programs
6490 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
6491 However, there are many other issues related to mixing Fortran 77 with
6492 other languages that are @emph{not} (currently) handled by Automake, but
6493 that are handled by other packages@footnote{For example,
6494 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
6495 addresses all of these inter-language issues, and runs under nearly all
6496 Fortran 77, C and C++ compilers on nearly all platforms.  However,
6497 @command{cfortran} is not yet Free Software, but it will be in the next
6498 major release.}.
6499
6500 Automake can help in two ways:
6501
6502 @enumerate
6503 @item
6504 Automatic selection of the linker depending on which combinations of
6505 source code.
6506
6507 @item
6508 Automatic selection of the appropriate linker flags (e.g., @option{-L} and
6509 @option{-l}) to pass to the automatically selected linker in order to link
6510 in the appropriate Fortran 77 intrinsic and run-time libraries.
6511
6512 @cindex @code{FLIBS}, defined
6513 @vindex FLIBS
6514 These extra Fortran 77 linker flags are supplied in the output variable
6515 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro
6516 supplied with newer versions of Autoconf (Autoconf version 2.13 and
6517 later).  @xref{Fortran Compiler, , Fortran Compiler Characteristics,
6518 autoconf, The Autoconf Manual}.
6519 @end enumerate
6520
6521 If Automake detects that a program or shared library (as mentioned in
6522 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
6523 code that is a mixture of Fortran 77 and C and/or C++, then it requires
6524 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
6525 @file{configure.ac}, and that either @code{$(FLIBS)}
6526 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
6527 (for shared libraries) variables.  It is the responsibility of the
6528 person writing the @file{Makefile.am} to make sure that @samp{$(FLIBS)}
6529 appears in the appropriate @code{_LDADD} or
6530 @code{_LIBADD} variable.
6531
6532 @cindex Mixed language example
6533 @cindex Example, mixed language
6534
6535 For example, consider the following @file{Makefile.am}:
6536
6537 @example
6538 bin_PROGRAMS = foo
6539 foo_SOURCES  = main.cc foo.f
6540 foo_LDADD    = libfoo.la $(FLIBS)
6541
6542 pkglib_LTLIBRARIES = libfoo.la
6543 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
6544 libfoo_la_LIBADD   = $(FLIBS)
6545 @end example
6546
6547 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
6548 is mentioned in @file{configure.ac}.  Also, if @samp{$(FLIBS)} hadn't
6549 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
6550 Automake would have issued a warning.
6551
6552 @menu
6553 * How the Linker is Chosen::    Automatic linker selection
6554 @end menu
6555
6556 @node How the Linker is Chosen
6557 @comment  node-name,  next,  previous,  up
6558 @subsubsection How the Linker is Chosen
6559
6560 @cindex Automatic linker selection
6561 @cindex Selecting the linker automatically
6562
6563 When a program or library mixes several languages, Automake choose the
6564 linker according to the following priorities.  (The names in
6565 parentheses are the variables containing the link command.)
6566
6567 @enumerate
6568 @item
6569 @vindex GCJLINK
6570 Native Java (@code{GCJLINK})
6571 @item
6572 @vindex CXXLINK
6573 C++ (@code{CXXLINK})
6574 @item
6575 @vindex F77LINK
6576 Fortran 77 (@code{F77LINK})
6577 @item
6578 @vindex FCLINK
6579 Fortran (@code{FCLINK})
6580 @item
6581 @vindex OBJCLINK
6582 Objective C (@code{OBJCLINK})
6583 @item
6584 @vindex UPCLINK
6585 Unified Parallel C (@code{UPCLINK})
6586 @item
6587 @vindex LINK
6588 C (@code{LINK})
6589 @end enumerate
6590
6591 For example, if Fortran 77, C and C++ source code is compiled
6592 into a program, then the C++ linker will be used.  In this case, if the
6593 C or Fortran 77 linkers required any special libraries that weren't
6594 included by the C++ linker, then they must be manually added to an
6595 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
6596 @file{Makefile.am}.
6597
6598 Automake only looks at the file names listed in @file{_SOURCES}
6599 variables to choose the linker, and defaults to the C linker.
6600 Sometimes this is inconvenient because you are linking against a
6601 library written in another language and would like to set the linker
6602 more appropriately.  @xref{Libtool Convenience Libraries}, for a
6603 trick with @code{nodist_EXTRA_@dots{}_SOURCES}.
6604
6605 A per-target @code{_LINK} variable will override the above selection.
6606 Per-target link flags will cause Automake to write a per-target
6607 @code{_LINK} variable according to the language chosen as above.
6608
6609
6610 @node Fortran 9x Support
6611 @comment  node-name,  next,  previous,  up
6612 @section Fortran 9x Support
6613
6614 @cindex Fortran 9x support
6615 @cindex Support for Fortran 9x
6616
6617 Automake includes support for Fortran 9x.
6618
6619 Any package including Fortran 9x code must define the output variable
6620 @code{FC} in @file{configure.ac}; the simplest way to do this is to use
6621 the @code{AC_PROG_FC} macro (@pxref{Particular Programs, , Particular
6622 Program Checks, autoconf, The Autoconf Manual}).
6623
6624 A few additional variables are defined when a Fortran 9x source file is
6625 seen:
6626
6627 @vtable @code
6628
6629 @item FC
6630 The name of the Fortran 9x compiler.
6631
6632 @item FCFLAGS
6633 Any flags to pass to the Fortran 9x compiler.
6634
6635 @item AM_FCFLAGS
6636 The maintainer's variant of @code{FCFLAGS}.
6637
6638 @item FCCOMPILE
6639 The command used to actually compile a Fortran 9x source file.  The file
6640 name is appended to form the complete command line.
6641
6642 @item FCLINK
6643 The command used to actually link a pure Fortran 9x program or shared
6644 library.
6645
6646 @end vtable
6647
6648 @menu
6649 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
6650 @end menu
6651
6652 @node Compiling Fortran 9x Files
6653 @comment  node-name,  next,  previous,  up
6654 @subsection Compiling Fortran 9x Files
6655
6656 @file{@var{file}.o} is made automatically from @file{@var{file}.f90},
6657 @file{@var{file}.f95}, @file{@var{file}.f03}, or @file{@var{file}.f08}
6658 by running the Fortran 9x compiler.  The precise command used
6659 is as follows:
6660
6661 @table @file
6662
6663 @item .f90
6664 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f90) $<}
6665
6666 @item .f95
6667 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f95) $<}
6668
6669 @item .f03
6670 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f03) $<}
6671
6672 @item .f08
6673 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f08) $<}
6674
6675 @end table
6676
6677 @node Java Support
6678 @comment  node-name,  next,  previous,  up
6679 @section Java Support
6680
6681 @cindex Java support
6682 @cindex Support for Java
6683
6684 Automake includes support for natively compiled Java, using @command{gcj},
6685 the Java front end to the GNU Compiler Collection (preliminary support
6686 for compiling Java to bytecode using the @command{javac} compiler is
6687 also present; @pxref{Java}).
6688
6689 Any package including Java code to be compiled must define the output
6690 variable @code{GCJ} in @file{configure.ac}; the variable @code{GCJFLAGS}
6691 must also be defined somehow (either in @file{configure.ac} or
6692 @file{Makefile.am}).  The simplest way to do this is to use the
6693 @code{AM_PROG_GCJ} macro.
6694
6695 @vindex GCJFLAGS
6696
6697 By default, programs including Java source files are linked with
6698 @command{gcj}.
6699
6700 As always, the contents of @code{AM_GCJFLAGS} are passed to every
6701 compilation invoking @command{gcj} (in its role as an ahead-of-time
6702 compiler, when invoking it to create @file{.class} files,
6703 @code{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
6704 options to @command{gcj} from @file{Makefile.am}, this variable, and not
6705 the user variable @code{GCJFLAGS}, should be used.
6706
6707 @vindex AM_GCJFLAGS
6708
6709 @command{gcj} can be used to compile @file{.java}, @file{.class},
6710 @file{.zip}, or @file{.jar} files.
6711
6712 When linking, @command{gcj} requires that the main class be specified
6713 using the @option{--main=} option.  The easiest way to do this is to use
6714 the @code{_LDFLAGS} variable for the program.
6715
6716
6717 @node Vala Support
6718 @comment  node-name,  next,  previous,  up
6719 @section Vala Support
6720
6721 @cindex Vala Support
6722 @cindex Support for Vala
6723
6724 Automake provides initial support for Vala
6725 (@uref{http://www.vala-project.org/}).
6726 This requires valac version 0.7.0 or later, and currently requires
6727 the user to use GNU @command{make}.
6728
6729 @example
6730 foo_SOURCES = foo.vala bar.vala zardoc.c
6731 @end example
6732
6733 Any @file{.vala} file listed in a @code{_SOURCES} variable will be
6734 compiled into C code by the Vala compiler. The generated @file{.c} files are
6735 distributed. The end user does not need to have a Vala compiler installed.
6736
6737 Automake ships with an Autoconf macro called @code{AM_PROG_VALAC}
6738 that will locate the Vala compiler and optionally check its version
6739 number.
6740
6741 @defmac AM_PROG_VALAC (@ovar{minimum-version})
6742 Try to find a Vala compiler in @env{PATH}. If it is found, the variable
6743 @code{VALAC} is set. Optionally a minimum release number of the compiler
6744 can be requested:
6745
6746 @example
6747 AM_PROG_VALAC([0.7.0])
6748 @end example
6749 @end defmac
6750
6751 There are a few variables that are used when compiling Vala sources:
6752
6753 @vtable @code
6754 @item VALAC
6755 Path to the Vala compiler.
6756
6757 @item VALAFLAGS
6758 Additional arguments for the Vala compiler.
6759
6760 @item AM_VALAFLAGS
6761 The maintainer's variant of @code{VALAFLAGS}.
6762
6763 @example
6764 lib_LTLIBRARIES = libfoo.la
6765 libfoo_la_SOURCES = foo.vala
6766 @end example
6767 @end vtable
6768
6769 Note that currently, you cannot use per-target @code{*_VALAFLAGS}
6770 (@pxref{Renamed Objects}) to produce different C files from one Vala
6771 source file.
6772
6773
6774 @node Support for Other Languages
6775 @comment  node-name,  next,  previous,  up
6776 @section Support for Other Languages
6777
6778 Automake currently only includes full support for C, C++ (@pxref{C++
6779 Support}), Objective C (@pxref{Objective C Support}), Fortran 77
6780 (@pxref{Fortran 77 Support}), Fortran 9x (@pxref{Fortran 9x Support}),
6781 and Java (@pxref{Java Support}).  There is only rudimentary support for other
6782 languages, support for which will be improved based on user demand.
6783
6784 Some limited support for adding your own languages is available via the
6785 suffix rule handling (@pxref{Suffixes}).
6786
6787
6788 @node ANSI
6789 @section Automatic de-ANSI-fication (deprecated, soon to be removed)
6790
6791 @cindex de-ANSI-fication, defined
6792
6793 @emph{The features described in this section are deprecated; you must
6794 not use any of them in new code, and remove their use from older but
6795 still maintained code: they will be withdrawn in the next major
6796 Automake release.}
6797
6798 When the C language was standardized in 1989, there was a long
6799 transition period where package developers needed to worry about
6800 porting to older systems that did not support ANSI C by default.
6801 These older systems are no longer in practical use and are no longer
6802 supported by their original suppliers, so developers need not worry
6803 about this problem any more.
6804
6805 Automake allows you to write packages that are portable to K&R C by
6806 @dfn{de-ANSI-fying} each source file before the actual compilation takes
6807 place.
6808
6809 @vindex AUTOMAKE_OPTIONS
6810 @opindex ansi2knr
6811
6812 If the @file{Makefile.am} variable @code{AUTOMAKE_OPTIONS}
6813 (@pxref{Options}) contains the option @option{ansi2knr} then code to
6814 handle de-ANSI-fication is inserted into the generated
6815 @file{Makefile.in}.
6816
6817 This causes each C source file in the directory to be treated as ANSI C@.
6818 If an ANSI C compiler is available, it is used.  If no ANSI C compiler
6819 is available, the @command{ansi2knr} program is used to convert the source
6820 files into K&R C, which is then compiled.
6821
6822 The @command{ansi2knr} program is simple-minded.  It assumes the source
6823 code will be formatted in a particular way; see the @command{ansi2knr} man
6824 page for details.
6825
6826 @acindex AM_C_PROTOTYPES
6827 Support for the obsolete de-ANSI-fication feature
6828 requires the source files @file{ansi2knr.c}
6829 and @file{ansi2knr.1} to be in the same package as the ANSI C source;
6830 these files are distributed with Automake.  Also, the package
6831 @file{configure.ac} must call the macro @code{AM_C_PROTOTYPES}
6832 (@pxref{Macros}).
6833
6834 Automake also handles finding the @command{ansi2knr} support files in some
6835 other directory in the current package.  This is done by prepending the
6836 relative path to the appropriate directory to the @command{ansi2knr}
6837 option.  For instance, suppose the package has ANSI C code in the
6838 @file{src} and @file{lib} subdirectories.  The files @file{ansi2knr.c} and
6839 @file{ansi2knr.1} appear in @file{lib}.  Then this could appear in
6840 @file{src/Makefile.am}:
6841
6842 @example
6843 AUTOMAKE_OPTIONS = ../lib/ansi2knr
6844 @end example
6845
6846 If no directory prefix is given, the files are assumed to be in the
6847 current directory.
6848
6849 Note that automatic de-ANSI-fication will not work when the package is
6850 being built for a different host architecture.  That is because
6851 @command{automake} currently has no way to build @command{ansi2knr}
6852 for the build machine.
6853
6854 @c FIXME: this paragraph might be better moved to an `upgrading' section.
6855 @cindex @code{LTLIBOBJS} and @code{ansi2knr}
6856 @cindex @code{LIBOBJS} and @code{ansi2knr}
6857 @cindex @code{ansi2knr} and @code{LTLIBOBJS}
6858 @cindex @code{ansi2knr} and @code{LIBOBJS}
6859 Using @code{LIBOBJS} with source de-ANSI-fication used to require
6860 hand-crafted code in @file{configure} to append @samp{$U} to basenames
6861 in @code{LIBOBJS}.  This is no longer true today.  Starting with version
6862 2.54, Autoconf takes care of rewriting @code{LIBOBJS} and
6863 @code{LTLIBOBJS}.  (@pxref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ}
6864 vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual})
6865
6866 @node Dependencies
6867 @section Automatic dependency tracking
6868
6869 As a developer it is often painful to continually update the
6870 @file{Makefile.am} whenever the include-file dependencies change in a
6871 project.  Automake supplies a way to automatically track dependency
6872 changes (@pxref{Dependency Tracking}).
6873
6874 @cindex Dependency tracking
6875 @cindex Automatic dependency tracking
6876
6877 Automake always uses complete dependencies for a compilation,
6878 including system headers.  Automake's model is that dependency
6879 computation should be a side effect of the build.  To this end,
6880 dependencies are computed by running all compilations through a
6881 special wrapper program called @command{depcomp}.  @command{depcomp}
6882 understands how to coax many different C and C++ compilers into
6883 generating dependency information in the format it requires.
6884 @samp{automake -a} will install @command{depcomp} into your source
6885 tree for you.  If @command{depcomp} can't figure out how to properly
6886 invoke your compiler, dependency tracking will simply be disabled for
6887 your build.
6888
6889 @cindex @command{depcomp}
6890
6891 Experience with earlier versions of Automake (@pxref{Dependency
6892 Tracking Evolution}) taught us that it is not reliable to generate
6893 dependencies only on the maintainer's system, as configurations vary
6894 too much.  So instead Automake implements dependency tracking at build
6895 time.
6896
6897 Automatic dependency tracking can be suppressed by putting
6898 @option{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
6899 passing @option{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
6900 (this should be the preferred way).  Or, you can invoke @command{automake}
6901 with the @option{-i} option.  Dependency tracking is enabled by default.
6902
6903 @vindex AUTOMAKE_OPTIONS
6904 @opindex no-dependencies
6905
6906 The person building your package also can choose to disable dependency
6907 tracking by configuring with @option{--disable-dependency-tracking}.
6908
6909 @cindex Disabling dependency tracking
6910 @cindex Dependency tracking, disabling
6911
6912
6913 @node EXEEXT
6914 @section Support for executable extensions
6915
6916 @cindex Executable extension
6917 @cindex Extension, executable
6918 @cindex Windows
6919
6920 On some platforms, such as Windows, executables are expected to have an
6921 extension such as @file{.exe}.  On these platforms, some compilers (GCC
6922 among them) will automatically generate @file{foo.exe} when asked to
6923 generate @file{foo}.
6924
6925 Automake provides mostly-transparent support for this.  Unfortunately
6926 @emph{mostly} doesn't yet mean @emph{fully}.  Until the English
6927 dictionary is revised, you will have to assist Automake if your package
6928 must support those platforms.
6929
6930 One thing you must be aware of is that, internally, Automake rewrites
6931 something like this:
6932
6933 @example
6934 bin_PROGRAMS = liver
6935 @end example
6936
6937 to this:
6938
6939 @example
6940 bin_PROGRAMS = liver$(EXEEXT)
6941 @end example
6942
6943 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
6944 extension.
6945
6946 The variables @code{TESTS} and @code{XFAIL_TESTS} (@pxref{Simple Tests})
6947 are also rewritten if they contain filenames that have been declared as
6948 programs in the same @file{Makefile}.  (This is mostly useful when some
6949 programs from @code{check_PROGRAMS} are listed in @code{TESTS}.)
6950
6951 However, Automake cannot apply this rewriting to @command{configure}
6952 substitutions.  This means that if you are conditionally building a
6953 program using such a substitution, then your @file{configure.ac} must
6954 take care to add @samp{$(EXEEXT)} when constructing the output variable.
6955
6956 With Autoconf 2.13 and earlier, you must explicitly use @code{AC_EXEEXT}
6957 to get this support.  With Autoconf 2.50, @code{AC_EXEEXT} is run
6958 automatically if you configure a compiler (say, through
6959 @code{AC_PROG_CC}).
6960
6961 Sometimes maintainers like to write an explicit link rule for their
6962 program.  Without executable extension support, this is easy---you
6963 simply write a rule whose target is the name of the program.  However,
6964 when executable extension support is enabled, you must instead add the
6965 @samp{$(EXEEXT)} suffix.
6966
6967 Unfortunately, due to the change in Autoconf 2.50, this means you must
6968 always add this extension.  However, this is a problem for maintainers
6969 who know their package will never run on a platform that has
6970 executable extensions.  For those maintainers, the @option{no-exeext}
6971 option (@pxref{Options}) will disable this feature.  This works in a
6972 fairly ugly way; if @option{no-exeext} is seen, then the presence of a
6973 rule for a target named @code{foo} in @file{Makefile.am} will override
6974 an @command{automake}-generated rule for @samp{foo$(EXEEXT)}.  Without
6975 the @option{no-exeext} option, this use will give a diagnostic.
6976
6977
6978 @node Other Objects
6979 @chapter Other Derived Objects
6980
6981 Automake can handle derived objects that are not C programs.  Sometimes
6982 the support for actually building such objects must be explicitly
6983 supplied, but Automake will still automatically handle installation and
6984 distribution.
6985
6986 @menu
6987 * Scripts::                     Executable scripts
6988 * Headers::                     Header files
6989 * Data::                        Architecture-independent data files
6990 * Sources::                     Derived sources
6991 @end menu
6992
6993
6994 @node Scripts
6995 @section Executable Scripts
6996
6997 @cindex @code{_SCRIPTS} primary, defined
6998 @cindex @code{SCRIPTS} primary, defined
6999 @cindex Primary variable, @code{SCRIPTS}
7000 @vindex _SCRIPTS
7001 @cindex Installing scripts
7002
7003 It is possible to define and install programs that are scripts.  Such
7004 programs are listed using the @code{SCRIPTS} primary name.  When the
7005 script is distributed in its final, installable form, the
7006 @file{Makefile} usually looks as follows:
7007 @vindex SCRIPTS
7008
7009 @example
7010 # Install my_script in $(bindir) and distribute it.
7011 dist_bin_SCRIPTS = my_script
7012 @end example
7013
7014 Scripts are not distributed by default; as we have just seen, those
7015 that should be distributed can be specified using a @code{dist_}
7016 prefix as with other primaries.
7017
7018 @cindex @code{SCRIPTS}, installation directories
7019 @vindex bin_SCRIPTS
7020 @vindex sbin_SCRIPTS
7021 @vindex libexec_SCRIPTS
7022 @vindex pkgdata_SCRIPTS
7023 @vindex noinst_SCRIPTS
7024 @vindex check_SCRIPTS
7025
7026 Scripts can be installed in @code{bindir}, @code{sbindir},
7027 @code{libexecdir}, or @code{pkgdatadir}.
7028
7029 Scripts that need not be installed can be listed in
7030 @code{noinst_SCRIPTS}, and among them, those which are needed only by
7031 @samp{make check} should go in @code{check_SCRIPTS}.
7032
7033 When a script needs to be built, the @file{Makefile.am} should include
7034 the appropriate rules.  For instance the @command{automake} program
7035 itself is a Perl script that is generated from @file{automake.in}.
7036 Here is how this is handled:
7037
7038 @example
7039 bin_SCRIPTS = automake
7040 CLEANFILES = $(bin_SCRIPTS)
7041 EXTRA_DIST = automake.in
7042
7043 do_subst = sed -e 's,[@@]datadir[@@],$(datadir),g' \
7044             -e 's,[@@]PERL[@@],$(PERL),g' \
7045             -e 's,[@@]PACKAGE[@@],$(PACKAGE),g' \
7046             -e 's,[@@]VERSION[@@],$(VERSION),g' \
7047             @dots{}
7048
7049 automake: automake.in Makefile
7050         $(do_subst) < $(srcdir)/automake.in > automake
7051         chmod +x automake
7052 @end example
7053
7054 Such scripts for which a build rule has been supplied need to be
7055 deleted explicitly using @code{CLEANFILES} (@pxref{Clean}), and their
7056 sources have to be distributed, usually with @code{EXTRA_DIST}
7057 (@pxref{Basics of Distribution}).
7058
7059 Another common way to build scripts is to process them from
7060 @file{configure} with @code{AC_CONFIG_FILES}.  In this situation
7061 Automake knows which files should be cleaned and distributed, and what
7062 the rebuild rules should look like.
7063
7064 For instance if @file{configure.ac} contains
7065
7066 @example
7067 AC_CONFIG_FILES([src/my_script], [chmod +x src/my_script])
7068 @end example
7069
7070 @noindent
7071 to build @file{src/my_script} from @file{src/my_script.in}, then a
7072 @file{src/Makefile.am} to install this script in @code{$(bindir)} can
7073 be as simple as
7074
7075 @example
7076 bin_SCRIPTS = my_script
7077 CLEANFILES = $(bin_SCRIPTS)
7078 @end example
7079
7080 @noindent
7081 There is no need for @code{EXTRA_DIST} or any build rule: Automake
7082 infers them from @code{AC_CONFIG_FILES} (@pxref{Requirements}).
7083 @code{CLEANFILES} is still useful, because by default Automake will
7084 clean targets of @code{AC_CONFIG_FILES} in @code{distclean}, not
7085 @code{clean}.
7086
7087 Although this looks simpler, building scripts this way has one
7088 drawback: directory variables such as @code{$(datadir)} are not fully
7089 expanded and may refer to other directory variables.
7090
7091 @node Headers
7092 @section Header files
7093
7094 @cindex @code{_HEADERS} primary, defined
7095 @cindex @code{HEADERS} primary, defined
7096 @cindex Primary variable, @code{HEADERS}
7097 @vindex _HEADERS
7098 @vindex noinst_HEADERS
7099 @cindex @code{HEADERS}, installation directories
7100 @cindex Installing headers
7101 @vindex include_HEADERS
7102 @vindex oldinclude_HEADERS
7103 @vindex pkginclude_HEADERS
7104
7105
7106 Header files that must be installed are specified by the
7107 @code{HEADERS} family of variables.  Headers can be installed in
7108 @code{includedir}, @code{oldincludedir}, @code{pkgincludedir} or any
7109 other directory you may have defined (@pxref{Uniform}).  For instance,
7110
7111 @example
7112 include_HEADERS = foo.h bar/bar.h
7113 @end example
7114
7115 @noindent
7116 will install the two files as @file{$(includedir)/foo.h} and
7117 @file{$(includedir)/bar.h}.
7118
7119 The @code{nobase_} prefix is also supported,
7120
7121 @example
7122 nobase_include_HEADERS = foo.h bar/bar.h
7123 @end example
7124
7125 @noindent
7126 will install the two files as @file{$(includedir)/foo.h} and
7127 @file{$(includedir)/bar/bar.h} (@pxref{Alternative}).
7128
7129 @vindex noinst_HEADERS
7130 Usually, only header files that accompany installed libraries need to
7131 be installed.  Headers used by programs or convenience libraries are
7132 not installed.  The @code{noinst_HEADERS} variable can be used for
7133 such headers.  However when the header actually belongs to a single
7134 convenience library or program, we recommend listing it in the
7135 program's or library's @code{_SOURCES} variable (@pxref{Program
7136 Sources}) instead of in @code{noinst_HEADERS}.  This is clearer for
7137 the @file{Makefile.am} reader.  @code{noinst_HEADERS} would be the
7138 right variable to use in a directory containing only headers and no
7139 associated library or program.
7140
7141 All header files must be listed somewhere; in a @code{_SOURCES}
7142 variable or in a @code{_HEADERS} variable.  Missing ones will not
7143 appear in the distribution.
7144
7145 For header files that are built and must not be distributed, use the
7146 @code{nodist_} prefix as in @code{nodist_include_HEADERS} or
7147 @code{nodist_prog_SOURCES}.  If these generated headers are needed
7148 during the build, you must also ensure they exist before they are
7149 used (@pxref{Sources}).
7150
7151
7152 @node Data
7153 @section Architecture-independent data files
7154
7155 @cindex @code{_DATA} primary, defined
7156 @cindex @code{DATA} primary, defined
7157 @cindex Primary variable, @code{DATA}
7158 @vindex _DATA
7159
7160 Automake supports the installation of miscellaneous data files using the
7161 @code{DATA} family of variables.
7162 @vindex DATA
7163
7164 @vindex data_DATA
7165 @vindex sysconf_DATA
7166 @vindex sharedstate_DATA
7167 @vindex localstate_DATA
7168 @vindex pkgdata_DATA
7169
7170 Such data can be installed in the directories @code{datadir},
7171 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
7172 @code{pkgdatadir}.
7173
7174 By default, data files are @emph{not} included in a distribution.  Of
7175 course, you can use the @code{dist_} prefix to change this on a
7176 per-variable basis.
7177
7178 Here is how Automake declares its auxiliary data files:
7179
7180 @example
7181 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
7182 @end example
7183
7184
7185 @node Sources
7186 @section Built Sources
7187
7188 Because Automake's automatic dependency tracking works as a side-effect
7189 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
7190 target should not be compiled before its dependencies are made, but
7191 these dependencies are unknown until the target is first compiled.
7192
7193 Ordinarily this is not a problem, because dependencies are distributed
7194 sources: they preexist and do not need to be built.  Suppose that
7195 @file{foo.c} includes @file{foo.h}.  When it first compiles
7196 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
7197 @file{foo.c}.  As a side-effect of this compilation @command{depcomp}
7198 records the @file{foo.h} dependency so that following invocations of
7199 @command{make} will honor it.  In these conditions, it's clear there is
7200 no problem: either @file{foo.o} doesn't exist and has to be built
7201 (regardless of the dependencies), or accurate dependencies exist and
7202 they can be used to decide whether @file{foo.o} should be rebuilt.
7203
7204 It's a different story if @file{foo.h} doesn't exist by the first
7205 @command{make} run.  For instance, there might be a rule to build
7206 @file{foo.h}.  This time @file{file.o}'s build will fail because the
7207 compiler can't find @file{foo.h}.  @command{make} failed to trigger the
7208 rule to build @file{foo.h} first by lack of dependency information.
7209
7210 @vindex BUILT_SOURCES
7211 @cindex @code{BUILT_SOURCES}, defined
7212
7213 The @code{BUILT_SOURCES} variable is a workaround for this problem.  A
7214 source file listed in @code{BUILT_SOURCES} is made on @samp{make all}
7215 or @samp{make check} (or even @samp{make install}) before other
7216 targets are processed.  However, such a source file is not
7217 @emph{compiled} unless explicitly requested by mentioning it in some
7218 other @code{_SOURCES} variable.
7219
7220 So, to conclude our introductory example, we could use
7221 @samp{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
7222 any other target (including @file{foo.o}) during @samp{make all} or
7223 @samp{make check}.
7224
7225 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
7226 must be created early in the build process can be listed in this
7227 variable.  Moreover, all built sources do not necessarily have to be
7228 listed in @code{BUILT_SOURCES}.  For instance, a generated @file{.c} file
7229 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
7230 another source), because it's a known dependency of the associated
7231 object.
7232
7233 It might be important to emphasize that @code{BUILT_SOURCES} is
7234 honored only by @samp{make all}, @samp{make check} and @samp{make
7235 install}.  This means you cannot build a specific target (e.g.,
7236 @samp{make foo}) in a clean tree if it depends on a built source.
7237 However it will succeed if you have run @samp{make all} earlier,
7238 because accurate dependencies are already available.
7239
7240 The next section illustrates and discusses the handling of built sources
7241 on a toy example.
7242
7243 @menu
7244 * Built Sources Example::       Several ways to handle built sources.
7245 @end menu
7246
7247 @node Built Sources Example
7248 @subsection Built Sources Example
7249
7250 Suppose that @file{foo.c} includes @file{bindir.h}, which is
7251 installation-dependent and not distributed: it needs to be built.  Here
7252 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
7253 value of the @command{make} variable @code{bindir} (inherited from
7254 @file{configure}).
7255
7256 We suggest several implementations below.  It's not meant to be an
7257 exhaustive listing of all ways to handle built sources, but it will give
7258 you a few ideas if you encounter this issue.
7259
7260 @subsubheading First Try
7261
7262 This first implementation will illustrate the bootstrap issue mentioned
7263 in the previous section (@pxref{Sources}).
7264
7265 Here is a tentative @file{Makefile.am}.
7266
7267 @example
7268 # This won't work.
7269 bin_PROGRAMS = foo
7270 foo_SOURCES = foo.c
7271 nodist_foo_SOURCES = bindir.h
7272 CLEANFILES = bindir.h
7273 bindir.h: Makefile
7274         echo '#define bindir "$(bindir)"' >$@@
7275 @end example
7276
7277 This setup doesn't work, because Automake doesn't know that @file{foo.c}
7278 includes @file{bindir.h}.  Remember, automatic dependency tracking works
7279 as a side-effect of compilation, so the dependencies of @file{foo.o} will
7280 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
7281 The symptom is as follows.
7282
7283 @example
7284 % make
7285 source='foo.c' object='foo.o' libtool=no \
7286 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7287 depmode=gcc /bin/sh ./depcomp \
7288 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7289 foo.c:2: bindir.h: No such file or directory
7290 make: *** [foo.o] Error 1
7291 @end example
7292
7293 In this example @file{bindir.h} is not distributed nor installed, and
7294 it is not even being built on-time.  One may wonder if the
7295 @samp{nodist_foo_SOURCES = bindir.h} line has any use at all.  This
7296 line simply states that @file{bindir.h} is a source of @code{foo}, so
7297 for instance, it should be inspected while generating tags
7298 (@pxref{Tags}).  In other words, it does not help our present problem,
7299 and the build would fail identically without it.
7300
7301 @subsubheading Using @code{BUILT_SOURCES}
7302
7303 A solution is to require @file{bindir.h} to be built before anything
7304 else.  This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
7305
7306 @example
7307 bin_PROGRAMS = foo
7308 foo_SOURCES = foo.c
7309 nodist_foo_SOURCES = bindir.h
7310 BUILT_SOURCES = bindir.h
7311 CLEANFILES = bindir.h
7312 bindir.h: Makefile
7313         echo '#define bindir "$(bindir)"' >$@@
7314 @end example
7315
7316 See how @file{bindir.h} gets built first:
7317
7318 @example
7319 % make
7320 echo '#define bindir "/usr/local/bin"' >bindir.h
7321 make  all-am
7322 make[1]: Entering directory `/home/adl/tmp'
7323 source='foo.c' object='foo.o' libtool=no \
7324 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7325 depmode=gcc /bin/sh ./depcomp \
7326 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7327 gcc  -g -O2   -o foo  foo.o
7328 make[1]: Leaving directory `/home/adl/tmp'
7329 @end example
7330
7331 However, as said earlier, @code{BUILT_SOURCES} applies only to the
7332 @code{all}, @code{check}, and @code{install} targets.  It still fails
7333 if you try to run @samp{make foo} explicitly:
7334
7335 @example
7336 % make clean
7337 test -z "bindir.h" || rm -f bindir.h
7338 test -z "foo" || rm -f foo
7339 rm -f *.o
7340 % : > .deps/foo.Po # Suppress previously recorded dependencies
7341 % make foo
7342 source='foo.c' object='foo.o' libtool=no \
7343 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7344 depmode=gcc /bin/sh ./depcomp \
7345 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7346 foo.c:2: bindir.h: No such file or directory
7347 make: *** [foo.o] Error 1
7348 @end example
7349
7350 @subsubheading Recording Dependencies manually
7351
7352 Usually people are happy enough with @code{BUILT_SOURCES} because they
7353 never build targets such as @samp{make foo} before @samp{make all}, as
7354 in the previous example.  However if this matters to you, you can
7355 avoid @code{BUILT_SOURCES} and record such dependencies explicitly in
7356 the @file{Makefile.am}.
7357
7358 @example
7359 bin_PROGRAMS = foo
7360 foo_SOURCES = foo.c
7361 nodist_foo_SOURCES = bindir.h
7362 foo.$(OBJEXT): bindir.h
7363 CLEANFILES = bindir.h
7364 bindir.h: Makefile
7365         echo '#define bindir "$(bindir)"' >$@@
7366 @end example
7367
7368 You don't have to list @emph{all} the dependencies of @file{foo.o}
7369 explicitly, only those that might need to be built.  If a dependency
7370 already exists, it will not hinder the first compilation and will be
7371 recorded by the normal dependency tracking code.  (Note that after
7372 this first compilation the dependency tracking code will also have
7373 recorded the dependency between @file{foo.o} and
7374 @file{bindir.h}; so our explicit dependency is really useful to
7375 the first build only.)
7376
7377 Adding explicit dependencies like this can be a bit dangerous if you are
7378 not careful enough.  This is due to the way Automake tries not to
7379 overwrite your rules (it assumes you know better than it).
7380 @samp{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
7381 output to build @samp{foo.$(OBJEXT)}.  It happens to work in this case
7382 because Automake doesn't have to output any @samp{foo.$(OBJEXT):}
7383 target: it relies on a suffix rule instead (i.e., @samp{.c.$(OBJEXT):}).
7384 Always check the generated @file{Makefile.in} if you do this.
7385
7386 @subsubheading Build @file{bindir.h} from @file{configure}
7387
7388 It's possible to define this preprocessor macro from @file{configure},
7389 either in @file{config.h} (@pxref{Defining Directories, , Defining
7390 Directories, autoconf, The Autoconf Manual}), or by processing a
7391 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
7392 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
7393 Autoconf Manual}).
7394
7395 At this point it should be clear that building @file{bindir.h} from
7396 @file{configure} works well for this example.  @file{bindir.h} will exist
7397 before you build any target, hence will not cause any dependency issue.
7398
7399 The Makefile can be shrunk as follows.  We do not even have to mention
7400 @file{bindir.h}.
7401
7402 @example
7403 bin_PROGRAMS = foo
7404 foo_SOURCES = foo.c
7405 @end example
7406
7407 However, it's not always possible to build sources from
7408 @file{configure}, especially when these sources are generated by a tool
7409 that needs to be built first.
7410
7411 @subsubheading Build @file{bindir.c}, not @file{bindir.h}.
7412
7413 Another attractive idea is to define @code{bindir} as a variable or
7414 function exported from @file{bindir.o}, and build @file{bindir.c}
7415 instead of @file{bindir.h}.
7416
7417 @example
7418 noinst_PROGRAMS = foo
7419 foo_SOURCES = foo.c bindir.h
7420 nodist_foo_SOURCES = bindir.c
7421 CLEANFILES = bindir.c
7422 bindir.c: Makefile
7423         echo 'const char bindir[] = "$(bindir)";' >$@@
7424 @end example
7425
7426 @file{bindir.h} contains just the variable's declaration and doesn't
7427 need to be built, so it won't cause any trouble.  @file{bindir.o} is
7428 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
7429 first.
7430
7431 @subsubheading Which is best?
7432
7433 There is no panacea, of course.  Each solution has its merits and
7434 drawbacks.
7435
7436 You cannot use @code{BUILT_SOURCES} if the ability to run @samp{make
7437 foo} on a clean tree is important to you.
7438
7439 You won't add explicit dependencies if you are leery of overriding
7440 an Automake rule by mistake.
7441
7442 Building files from @file{./configure} is not always possible, neither
7443 is converting @file{.h} files into @file{.c} files.
7444
7445
7446 @node Other GNU Tools
7447 @chapter Other GNU Tools
7448
7449 Since Automake is primarily intended to generate @file{Makefile.in}s for
7450 use in GNU programs, it tries hard to interoperate with other GNU tools.
7451
7452 @menu
7453 * Emacs Lisp::                  Emacs Lisp
7454 * gettext::                     Gettext
7455 * Libtool::                     Libtool
7456 * Java::                        Java
7457 * Python::                      Python
7458 @end menu
7459
7460
7461 @node Emacs Lisp
7462 @section Emacs Lisp
7463
7464 @cindex @code{_LISP} primary, defined
7465 @cindex @code{LISP} primary, defined
7466 @cindex Primary variable, @code{LISP}
7467
7468 @vindex _LISP
7469 @vindex lisp_LISP
7470 @vindex noinst_LISP
7471
7472 Automake provides some support for Emacs Lisp.  The @code{LISP} primary
7473 is used to hold a list of @file{.el} files.  Possible prefixes for this
7474 primary are @code{lisp_} and @code{noinst_}.  Note that if
7475 @code{lisp_LISP} is defined, then @file{configure.ac} must run
7476 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
7477
7478 @vindex dist_lisp_LISP
7479 @vindex dist_noinst_LISP
7480 Lisp sources are not distributed by default.  You can prefix the
7481 @code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
7482 @code{dist_noinst_LISP}, to indicate that these files should be
7483 distributed.
7484
7485 Automake will byte-compile all Emacs Lisp source files using the Emacs
7486 found by @code{AM_PATH_LISPDIR}, if any was found.
7487
7488 Byte-compiled Emacs Lisp files are not portable among all versions of
7489 Emacs, so it makes sense to turn this off if you expect sites to have
7490 more than one version of Emacs installed.  Furthermore, many packages
7491 don't actually benefit from byte-compilation.  Still, we recommend
7492 that you byte-compile your Emacs Lisp sources.  It is probably better
7493 for sites with strange setups to cope for themselves than to make the
7494 installation less nice for everybody else.
7495
7496 There are two ways to avoid byte-compiling.  Historically, we have
7497 recommended the following construct.
7498
7499 @example
7500 lisp_LISP = file1.el file2.el
7501 ELCFILES =
7502 @end example
7503
7504 @noindent
7505 @code{ELCFILES} is an internal Automake variable that normally lists
7506 all @file{.elc} files that must be byte-compiled.  Automake defines
7507 @code{ELCFILES} automatically from @code{lisp_LISP}.  Emptying this
7508 variable explicitly prevents byte-compilation.
7509
7510 Since Automake 1.8, we now recommend using @code{lisp_DATA} instead:
7511
7512 @c Keep in sync with primary-prefix-couples-documented-valid.test.
7513 @example
7514 lisp_DATA = file1.el file2.el
7515 @end example
7516
7517 Note that these two constructs are not equivalent.  @code{_LISP} will
7518 not install a file if Emacs is not installed, while @code{_DATA} will
7519 always install its files.
7520
7521 @node gettext
7522 @section Gettext
7523
7524 @cindex GNU Gettext support
7525 @cindex Gettext support
7526 @cindex Support for GNU Gettext
7527
7528 If @code{AM_GNU_GETTEXT} is seen in @file{configure.ac}, then Automake
7529 turns on support for GNU gettext, a message catalog system for
7530 internationalization
7531 (@pxref{Top, , Introduction, gettext, GNU gettext utilities}).
7532
7533 The @code{gettext} support in Automake requires the addition of one or
7534 two subdirectories to the package: @file{po} and possibly also @file{intl}.
7535 The latter is needed if @code{AM_GNU_GETTEXT} is not invoked with the
7536 @samp{external} argument, or if @code{AM_GNU_GETTEXT_INTL_SUBDIR} is used.
7537 Automake ensures that these directories exist and are mentioned in
7538 @code{SUBDIRS}.
7539
7540 @node Libtool
7541 @section Libtool
7542
7543 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
7544 libtool, The Libtool Manual}) with the @code{LTLIBRARIES} primary.
7545 @xref{A Shared Library}.
7546
7547
7548 @node Java
7549 @section Java
7550
7551 @cindex @code{_JAVA} primary, defined
7552 @cindex @code{JAVA} primary, defined
7553 @cindex Primary variable, @code{JAVA}
7554
7555 Automake provides some minimal support for Java bytecode compilation with
7556 the @code{JAVA} primary (in addition to the support for compiling Java to
7557 native machine code; @pxref{Java Support}).
7558
7559 Any @file{.java} files listed in a @code{_JAVA} variable will be
7560 compiled with @code{JAVAC} at build time.  By default, @file{.java}
7561 files are not included in the distribution, you should use the
7562 @code{dist_} prefix to distribute them.
7563
7564 Here is a typical setup for distributing @file{.java} files and
7565 installing the @file{.class} files resulting from their compilation.
7566
7567 @c Keep in sync with primary-prefix-couples-documented-valid.test.
7568 @example
7569 javadir = $(datadir)/java
7570 dist_java_JAVA = a.java b.java @dots{}
7571 @end example
7572
7573 @cindex @code{JAVA} restrictions
7574 @cindex Restrictions for @code{JAVA}
7575
7576 Currently Automake enforces the restriction that only one @code{_JAVA}
7577 primary can be used in a given @file{Makefile.am}.  The reason for this
7578 restriction is that, in general, it isn't possible to know which
7579 @file{.class} files were generated from which @file{.java} files, so
7580 it would be impossible to know which files to install where.  For
7581 instance, a @file{.java} file can define multiple classes; the resulting
7582 @file{.class} file names cannot be predicted without parsing the
7583 @file{.java} file.
7584
7585 There are a few variables that are used when compiling Java sources:
7586
7587 @vtable @code
7588 @item JAVAC
7589 The name of the Java compiler.  This defaults to @samp{javac}.
7590
7591 @item JAVACFLAGS
7592 The flags to pass to the compiler.  This is considered to be a user
7593 variable (@pxref{User Variables}).
7594
7595 @item AM_JAVACFLAGS
7596 More flags to pass to the Java compiler.  This, and not
7597 @code{JAVACFLAGS}, should be used when it is necessary to put Java
7598 compiler flags into @file{Makefile.am}.
7599
7600 @item JAVAROOT
7601 The value of this variable is passed to the @option{-d} option to
7602 @code{javac}.  It defaults to @samp{$(top_builddir)}.
7603
7604 @item CLASSPATH_ENV
7605 This variable is a shell expression that is used to set the
7606 @env{CLASSPATH} environment variable on the @code{javac} command line.
7607 (In the future we will probably handle class path setting differently.)
7608 @end vtable
7609
7610
7611 @node Python
7612 @section Python
7613
7614 @cindex @code{_PYTHON} primary, defined
7615 @cindex @code{PYTHON} primary, defined
7616 @cindex Primary variable, @code{PYTHON}
7617 @vindex _PYTHON
7618
7619 Automake provides support for Python compilation with the
7620 @code{PYTHON} primary.  A typical setup is to call
7621 @code{AM_PATH_PYTHON} in @file{configure.ac} and use a line like the
7622 following in @file{Makefile.am}:
7623
7624 @example
7625 python_PYTHON = tree.py leave.py
7626 @end example
7627
7628 Any files listed in a @code{_PYTHON} variable will be byte-compiled
7629 with @command{py-compile} at install time.  @command{py-compile}
7630 actually creates both standard (@file{.pyc}) and optimized
7631 (@file{.pyo}) byte-compiled versions of the source files.  Note that
7632 because byte-compilation occurs at install time, any files listed in
7633 @code{noinst_PYTHON} will not be compiled.  Python source files are
7634 included in the distribution by default, prepend @code{nodist_} (as in
7635 @code{nodist_python_PYTHON}) to omit them.
7636
7637 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON}
7638 that will determine some Python-related directory variables (see
7639 below).  If you have called @code{AM_PATH_PYTHON} from
7640 @file{configure.ac}, then you may use the variables
7641 @c Keep in sync with primary-prefix-couples-documented-valid.test.
7642 @code{python_PYTHON} or @code{pkgpython_PYTHON} to list Python source
7643 files in your @file{Makefile.am}, depending on where you want your files
7644 installed (see the definitions of @code{pythondir} and
7645 @code{pkgpythondir} below).
7646
7647 @defmac AM_PATH_PYTHON (@ovar{version}, @ovar{action-if-found},
7648   @ovar{action-if-not-found})
7649
7650 Search for a Python interpreter on the system.  This macro takes three
7651 optional arguments.  The first argument, if present, is the minimum
7652 version of Python required for this package: @code{AM_PATH_PYTHON}
7653 will skip any Python interpreter that is older than @var{version}.
7654 If an interpreter is found and satisfies @var{version}, then
7655 @var{action-if-found} is run.  Otherwise, @var{action-if-not-found} is
7656 run.
7657
7658 If @var{action-if-not-found} is not specified, as in the following
7659 example, the default is to abort @command{configure}.
7660
7661 @example
7662 AM_PATH_PYTHON([2.2])
7663 @end example
7664
7665 @noindent
7666 This is fine when Python is an absolute requirement for the package.
7667 If Python >= 2.5 was only @emph{optional} to the package,
7668 @code{AM_PATH_PYTHON} could be called as follows.
7669
7670 @example
7671 AM_PATH_PYTHON([2.5],, [:])
7672 @end example
7673
7674 If the @env{PYTHON} variable is set when @code{AM_PATH_PYTHON} is
7675 called, then that will be the only Python interpreter that is tried.
7676
7677 @code{AM_PATH_PYTHON} creates the following output variables based on
7678 the Python installation found during configuration.
7679 @end defmac
7680
7681 @vtable @code
7682 @item PYTHON
7683 The name of the Python executable, or @samp{:} if no suitable
7684 interpreter could be found.
7685
7686 Assuming @var{action-if-not-found} is used (otherwise @file{./configure}
7687 will abort if Python is absent), the value of @code{PYTHON} can be used
7688 to setup a conditional in order to disable the relevant part of a build
7689 as follows.
7690
7691 @example
7692 AM_PATH_PYTHON(,, [:])
7693 AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
7694 @end example
7695
7696 @item PYTHON_VERSION
7697 The Python version number, in the form @var{major}.@var{minor}
7698 (e.g., @samp{2.5}).  This is currently the value of
7699 @samp{sys.version[:3]}.
7700
7701 @item PYTHON_PREFIX
7702 The string @samp{$@{prefix@}}.  This term may be used in future work
7703 that needs the contents of Python's @samp{sys.prefix}, but general
7704 consensus is to always use the value from @command{configure}.
7705
7706 @item PYTHON_EXEC_PREFIX
7707 The string @samp{$@{exec_prefix@}}.  This term may be used in future work
7708 that needs the contents of Python's @samp{sys.exec_prefix}, but general
7709 consensus is to always use the value from @command{configure}.
7710
7711 @item PYTHON_PLATFORM
7712 The canonical name used by Python to describe the operating system, as
7713 given by @samp{sys.platform}.  This value is sometimes needed when
7714 building Python extensions.
7715
7716 @item pythondir
7717 The directory name for the @file{site-packages} subdirectory of the
7718 standard Python install tree.
7719
7720 @item pkgpythondir
7721 This is the directory under @code{pythondir} that is named after the
7722 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
7723 as a convenience.
7724
7725 @item pyexecdir
7726 This is the directory where Python extension modules (shared libraries)
7727 should be installed.  An extension module written in C could be declared
7728 as follows to Automake:
7729
7730 @c Keep in sync with primary-prefix-couples-documented-valid.test.
7731 @example
7732 pyexec_LTLIBRARIES = quaternion.la
7733 quaternion_la_SOURCES = quaternion.c support.c support.h
7734 quaternion_la_LDFLAGS = -avoid-version -module
7735 @end example
7736
7737 @item pkgpyexecdir
7738 This is a convenience variable that is defined as
7739 @samp{$(pyexecdir)/$(PACKAGE)}.
7740 @end vtable
7741
7742 All these directory variables have values that start with either
7743 @samp{$@{prefix@}} or @samp{$@{exec_prefix@}} unexpanded.  This works
7744 fine in @file{Makefiles}, but it makes these variables hard to use in
7745 @file{configure}.  This is mandated by the GNU coding standards, so
7746 that the user can run @samp{make prefix=/foo install}.  The Autoconf
7747 manual has a section with more details on this topic
7748 (@pxref{Installation Directory Variables, , Installation Directory
7749 Variables, autoconf, The Autoconf Manual}).  See also @ref{Hard-Coded
7750 Install Paths}.
7751
7752
7753 @node Documentation
7754 @chapter Building documentation
7755
7756 Currently Automake provides support for Texinfo and man pages.
7757
7758 @menu
7759 * Texinfo::                     Texinfo
7760 * Man Pages::                   Man pages
7761 @end menu
7762
7763
7764 @node Texinfo
7765 @section Texinfo
7766
7767 @cindex @code{_TEXINFOS} primary, defined
7768 @cindex @code{TEXINFOS} primary, defined
7769 @cindex Primary variable, @code{TEXINFOS}
7770 @cindex HTML output using Texinfo
7771 @cindex PDF output using Texinfo
7772 @cindex PS output using Texinfo
7773 @cindex DVI output using Texinfo
7774 @vindex _TEXINFOS
7775 @vindex info_TEXINFOS
7776
7777 If the current directory contains Texinfo source, you must declare it
7778 with the @code{TEXINFOS} primary.  Generally Texinfo files are converted
7779 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
7780 here.  Any Texinfo source file must end in the @file{.texi},
7781 @file{.txi}, or @file{.texinfo} extension.  We recommend @file{.texi}
7782 for new manuals.
7783
7784 Automake generates rules to build @file{.info}, @file{.dvi},
7785 @file{.ps}, @file{.pdf} and @file{.html} files from your Texinfo
7786 sources.  Following the GNU Coding Standards, only the @file{.info}
7787 files are built by @samp{make all} and installed by @samp{make
7788 install} (unless you use @option{no-installinfo}, see below).
7789 Furthermore, @file{.info} files are automatically distributed so that
7790 Texinfo is not a prerequisite for installing your package.
7791
7792 @trindex dvi
7793 @trindex html
7794 @trindex pdf
7795 @trindex ps
7796 @trindex install-dvi
7797 @trindex install-html
7798 @trindex install-pdf
7799 @trindex install-ps
7800 Other documentation formats can be built on request by @samp{make
7801 dvi}, @samp{make ps}, @samp{make pdf} and @samp{make html}, and they
7802 can be installed with @samp{make install-dvi}, @samp{make install-ps},
7803 @samp{make install-pdf} and @samp{make install-html} explicitly.
7804 @samp{make uninstall} will remove everything: the Texinfo
7805 documentation installed by default as well as all the above optional
7806 formats.
7807
7808 All these targets can be extended using @samp{-local} rules
7809 (@pxref{Extending}).
7810
7811 @cindex Texinfo flag, @code{VERSION}
7812 @cindex Texinfo flag, @code{UPDATED}
7813 @cindex Texinfo flag, @code{EDITION}
7814 @cindex Texinfo flag, @code{UPDATED-MONTH}
7815
7816 @cindex @code{VERSION} Texinfo flag
7817 @cindex @code{UPDATED} Texinfo flag
7818 @cindex @code{EDITION} Texinfo flag
7819 @cindex @code{UPDATED-MONTH} Texinfo flag
7820
7821 @cindex @file{mdate-sh}
7822
7823 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
7824 that file will be automatically generated.  The file @file{version.texi}
7825 defines four Texinfo flag you can reference using
7826 @code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
7827 @code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
7828
7829 @table @code
7830 @item EDITION
7831 @itemx VERSION
7832 Both of these flags hold the version number of your program.  They are
7833 kept separate for clarity.
7834
7835 @item UPDATED
7836 This holds the date the primary @file{.texi} file was last modified.
7837
7838 @item UPDATED-MONTH
7839 This holds the name of the month in which the primary @file{.texi} file
7840 was last modified.
7841 @end table
7842
7843 The @file{version.texi} support requires the @command{mdate-sh}
7844 script; this script is supplied with Automake and automatically
7845 included when @command{automake} is invoked with the
7846 @option{--add-missing} option.
7847
7848 If you have multiple Texinfo files, and you want to use the
7849 @file{version.texi} feature, then you have to have a separate version
7850 file for each Texinfo file.  Automake will treat any include in a
7851 Texinfo file that matches @file{vers*.texi} just as an automatically
7852 generated version file.
7853
7854 Sometimes an info file actually depends on more than one @file{.texi}
7855 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
7856 @file{fdl.texi}.  You can tell Automake about these dependencies using
7857 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
7858 @vindex TEXINFOS
7859 @vindex _TEXINFOS
7860
7861 @example
7862 info_TEXINFOS = hello.texi
7863 hello_TEXINFOS = fdl.texi
7864 @end example
7865
7866 @cindex @file{texinfo.tex}
7867
7868 By default, Automake requires the file @file{texinfo.tex} to appear in
7869 the same directory as the @file{Makefile.am} file that lists the
7870 @file{.texi} files.  If you used @code{AC_CONFIG_AUX_DIR} in
7871 @file{configure.ac} (@pxref{Input, , Finding `configure' Input,
7872 autoconf, The Autoconf Manual}), then @file{texinfo.tex} is looked for
7873 there.  In both cases, @command{automake} then supplies @file{texinfo.tex} if
7874 @option{--add-missing} is given, and takes care of its distribution.
7875 However, if you set the @code{TEXINFO_TEX} variable (see below),
7876 it overrides the location of the file and turns off its installation
7877 into the source as well as its distribution.
7878
7879 The option @option{no-texinfo.tex} can be used to eliminate the
7880 requirement for the file @file{texinfo.tex}.  Use of the variable
7881 @code{TEXINFO_TEX} is preferable, however, because that allows the
7882 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
7883
7884 @cindex Option, @code{no-installinfo}
7885 @cindex Target, @code{install-info}
7886 @cindex @code{install-info} target
7887 @cindex @code{no-installinfo} option
7888
7889 @opindex no-installinfo
7890 @trindex install-info
7891
7892 Automake generates an @code{install-info} rule; some people apparently
7893 use this.  By default, info pages are installed by @samp{make
7894 install}, so running @code{make install-info} is pointless.  This can
7895 be prevented via the @code{no-installinfo} option.  In this case,
7896 @file{.info} files are not installed by default, and user must
7897 request this explicitly using @samp{make install-info}.
7898
7899 The following variables are used by the Texinfo build rules.
7900
7901 @vtable @code
7902 @item MAKEINFO
7903 The name of the program invoked to build @file{.info} files.  This
7904 variable is defined by Automake.  If the @command{makeinfo} program is
7905 found on the system then it will be used by default; otherwise
7906 @command{missing} will be used instead.
7907
7908 @item MAKEINFOHTML
7909 The command invoked to build @file{.html} files.  Automake
7910 defines this to @samp{$(MAKEINFO) --html}.
7911
7912 @item MAKEINFOFLAGS
7913 User flags passed to each invocation of @samp{$(MAKEINFO)} and
7914 @samp{$(MAKEINFOHTML)}.  This user variable (@pxref{User Variables}) is
7915 not expected to be defined in any @file{Makefile}; it can be used by
7916 users to pass extra flags to suit their needs.
7917
7918 @item AM_MAKEINFOFLAGS
7919 @itemx AM_MAKEINFOHTMLFLAGS
7920 Maintainer flags passed to each @command{makeinfo} invocation.  Unlike
7921 @code{MAKEINFOFLAGS}, these variables are meant to be defined by
7922 maintainers in @file{Makefile.am}.  @samp{$(AM_MAKEINFOFLAGS)} is
7923 passed to @code{makeinfo} when building @file{.info} files; and
7924 @samp{$(AM_MAKEINFOHTMLFLAGS)} is used when building @file{.html}
7925 files.
7926
7927 @c Keep in sync with txinfo21.test.
7928 For instance, the following setting can be used to obtain one single
7929 @file{.html} file per manual, without node separators.
7930 @example
7931 AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
7932 @end example
7933
7934 @code{AM_MAKEINFOHTMLFLAGS} defaults to @samp{$(AM_MAKEINFOFLAGS)}.
7935 This means that defining @code{AM_MAKEINFOFLAGS} without defining
7936 @code{AM_MAKEINFOHTMLFLAGS} will impact builds of both @file{.info}
7937 and @file{.html} files.
7938
7939 @item TEXI2DVI
7940 The name of the command that converts a @file{.texi} file into a
7941 @file{.dvi} file.  This defaults to @samp{texi2dvi}, a script that ships
7942 with the Texinfo package.
7943
7944 @item TEXI2PDF
7945 The name of the command that translates a @file{.texi} file into a
7946 @file{.pdf} file.  This defaults to @samp{$(TEXI2DVI) --pdf --batch}.
7947
7948 @item DVIPS
7949 The name of the command that builds a @file{.ps} file out of a
7950 @file{.dvi} file.  This defaults to @samp{dvips}.
7951
7952 @item TEXINFO_TEX
7953
7954 If your package has Texinfo files in many directories, you can use the
7955 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
7956 @file{texinfo.tex} for your package.  The value of this variable should
7957 be the relative path from the current @file{Makefile.am} to
7958 @file{texinfo.tex}:
7959
7960 @example
7961 TEXINFO_TEX = ../doc/texinfo.tex
7962 @end example
7963 @end vtable
7964
7965
7966 @node Man Pages
7967 @section Man Pages
7968
7969 @cindex @code{_MANS} primary, defined
7970 @cindex @code{MANS} primary, defined
7971 @cindex Primary variable, @code{MANS}
7972
7973 @vindex _MANS
7974 @vindex man_MANS
7975 A package can also include man pages (but see the GNU standards on this
7976 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
7977 pages are declared using the @code{MANS} primary.  Generally the
7978 @code{man_MANS} variable is used.  Man pages are automatically installed in
7979 the correct subdirectory of @code{mandir}, based on the file extension.
7980
7981 File extensions such as @file{.1c} are handled by looking for the valid
7982 part of the extension and using that to determine the correct
7983 subdirectory of @code{mandir}.  Valid section names are the digits
7984 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
7985
7986 Sometimes developers prefer to name a man page something like
7987 @file{foo.man} in the source, and then rename it to have the correct
7988 suffix, for example @file{foo.1}, when installing the file.  Automake
7989 also supports this mode.  For a valid section named @var{section},
7990 there is a corresponding directory named @samp{man@var{section}dir},
7991 and a corresponding @code{_MANS} variable.  Files listed in such a
7992 variable are installed in the indicated section.  If the file already
7993 has a valid suffix, then it is installed as-is; otherwise the file
7994 suffix is changed to match the section.
7995
7996 For instance, consider this example:
7997 @example
7998 man1_MANS = rename.man thesame.1 alsothesame.1c
7999 @end example
8000
8001 @noindent
8002 In this case, @file{rename.man} will be renamed to @file{rename.1} when
8003 installed, but the other files will keep their names.
8004
8005 @cindex Target, @code{install-man}
8006 @cindex Option, @option{no-installman}
8007 @cindex @code{install-man} target
8008 @cindex @option{no-installman} option
8009 @opindex no-installman
8010 @trindex install-man
8011
8012 By default, man pages are installed by @samp{make install}.  However,
8013 since the GNU project does not require man pages, many maintainers do
8014 not expend effort to keep the man pages up to date.  In these cases, the
8015 @option{no-installman} option will prevent the man pages from being
8016 installed by default.  The user can still explicitly install them via
8017 @samp{make install-man}.
8018
8019 For fast installation, with many files it is preferable to use
8020 @samp{man@var{section}_MANS} over @samp{man_MANS} as well as files that
8021 do not need to be renamed.
8022
8023 Man pages are not currently considered to be source, because it is not
8024 uncommon for man pages to be automatically generated.  Therefore they
8025 are not automatically included in the distribution.  However, this can
8026 be changed by use of the @code{dist_} prefix.  For instance here is
8027 how to distribute and install the two man pages of GNU @command{cpio}
8028 (which includes both Texinfo documentation and man pages):
8029
8030 @example
8031 dist_man_MANS = cpio.1 mt.1
8032 @end example
8033
8034 The @code{nobase_} prefix is meaningless for man pages and is
8035 disallowed.
8036
8037 @vindex notrans_
8038 @cindex @code{notrans_} prefix
8039 @cindex Man page renaming, avoiding
8040 @cindex Avoiding man page renaming
8041
8042 Executables and manpages may be renamed upon installation
8043 (@pxref{Renaming}).  For manpages this can be avoided by use of the
8044 @code{notrans_} prefix.  For instance, suppose an executable @samp{foo}
8045 allowing to access a library function @samp{foo} from the command line.
8046 The way to avoid renaming of the @file{foo.3} manpage is:
8047
8048 @example
8049 man_MANS = foo.1
8050 notrans_man_MANS = foo.3
8051 @end example
8052
8053 @cindex @code{notrans_} and @code{dist_} or @code{nodist_}
8054 @cindex @code{dist_} and @code{notrans_}
8055 @cindex @code{nodist_} and @code{notrans_}
8056
8057 @samp{notrans_} must be specified first when used in conjunction with
8058 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
8059 Control}).  For instance:
8060
8061 @example
8062 notrans_dist_man3_MANS = bar.3
8063 @end example
8064
8065 @node Install
8066 @chapter What Gets Installed
8067
8068 @cindex Installation support
8069 @cindex @samp{make install} support
8070
8071 Naturally, Automake handles the details of actually installing your
8072 program once it has been built.  All files named by the various
8073 primaries are automatically installed in the appropriate places when the
8074 user runs @samp{make install}.
8075
8076 @menu
8077 * Basics of Installation::      What gets installed where
8078 * The Two Parts of Install::    Installing data and programs separately
8079 * Extending Installation::      Adding your own rules for installation
8080 * Staged Installs::             Installation in a temporary location
8081 * Install Rules for the User::  Useful additional rules
8082 @end menu
8083
8084 @node Basics of Installation
8085 @section Basics of Installation
8086
8087 A file named in a primary is installed by copying the built file into
8088 the appropriate directory.  The base name of the file is used when
8089 installing.
8090
8091 @example
8092 bin_PROGRAMS = hello subdir/goodbye
8093 @end example
8094
8095 In this example, both @samp{hello} and @samp{goodbye} will be installed
8096 in @samp{$(bindir)}.
8097
8098 Sometimes it is useful to avoid the basename step at install time.  For
8099 instance, you might have a number of header files in subdirectories of
8100 the source tree that are laid out precisely how you want to install
8101 them.  In this situation you can use the @code{nobase_} prefix to
8102 suppress the base name step.  For example:
8103
8104 @example
8105 nobase_include_HEADERS = stdio.h sys/types.h
8106 @end example
8107
8108 @noindent
8109 will install @file{stdio.h} in @samp{$(includedir)} and @file{types.h}
8110 in @samp{$(includedir)/sys}.
8111
8112 For most file types, Automake will install multiple files at once, while
8113 avoiding command line length issues (@pxref{Length Limitations}).  Since
8114 some @command{install} programs will not install the same file twice in
8115 one invocation, you may need to ensure that file lists are unique within
8116 one variable such as @samp{nobase_include_HEADERS} above.
8117
8118 You should not rely on the order in which files listed in one variable
8119 are installed.  Likewise, to cater for parallel make, you should not
8120 rely on any particular file installation order even among different
8121 file types (library dependencies are an exception here).
8122
8123
8124 @node The Two Parts of Install
8125 @section The Two Parts of Install
8126
8127 Automake generates separate @code{install-data} and @code{install-exec}
8128 rules, in case the installer is installing on multiple machines that
8129 share directory structure---these targets allow the machine-independent
8130 parts to be installed only once.  @code{install-exec} installs
8131 platform-dependent files, and @code{install-data} installs
8132 platform-independent files.  The @code{install} target depends on both
8133 of these targets.  While Automake tries to automatically segregate
8134 objects into the correct category, the @file{Makefile.am} author is, in
8135 the end, responsible for making sure this is done correctly.
8136 @trindex install-data
8137 @trindex install-exec
8138 @trindex install
8139 @cindex Install, two parts of
8140
8141 Variables using the standard directory prefixes @samp{data},
8142 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
8143 @samp{pkgdata}, or @samp{pkginclude} are installed by
8144 @code{install-data}.
8145
8146 Variables using the standard directory prefixes @samp{bin},
8147 @samp{sbin}, @samp{libexec}, @samp{sysconf}, @samp{localstate},
8148 @samp{lib}, or @samp{pkglib} are installed by @code{install-exec}.
8149
8150 For instance, @code{data_DATA} files are installed by @code{install-data},
8151 while @code{bin_PROGRAMS} files are installed by @code{install-exec}.
8152
8153 Any variable using a user-defined directory prefix with
8154 @samp{exec} in the name (e.g.,
8155 @c Keep in sync with primary-prefix-couples-documented-valid.test.
8156 @code{myexecbin_PROGRAMS}) is installed by @code{install-exec}.  All
8157 other user-defined prefixes are installed by @code{install-data}.
8158
8159 @node Extending Installation
8160 @section Extending Installation
8161
8162 It is possible to extend this mechanism by defining an
8163 @code{install-exec-local} or @code{install-data-local} rule.  If these
8164 rules exist, they will be run at @samp{make install} time.  These
8165 rules can do almost anything; care is required.
8166 @trindex install-exec-local
8167 @trindex install-data-local
8168
8169 Automake also supports two install hooks, @code{install-exec-hook} and
8170 @code{install-data-hook}.  These hooks are run after all other install
8171 rules of the appropriate type, exec or data, have completed.  So, for
8172 instance, it is possible to perform post-installation modifications
8173 using an install hook.  @xref{Extending}, for some examples.
8174 @cindex Install hook
8175
8176 @node Staged Installs
8177 @section Staged Installs
8178
8179 @vindex DESTDIR
8180 Automake generates support for the @code{DESTDIR} variable in all
8181 install rules.  @code{DESTDIR} is used during the @samp{make install}
8182 step to relocate install objects into a staging area.  Each object and
8183 path is prefixed with the value of @code{DESTDIR} before being copied
8184 into the install area.  Here is an example of typical DESTDIR usage:
8185
8186 @example
8187 mkdir /tmp/staging &&
8188 make DESTDIR=/tmp/staging install
8189 @end example
8190
8191 The @command{mkdir} command avoids a security problem if the attacker
8192 creates a symbolic link from @file{/tmp/staging} to a victim area;
8193 then @command{make} places install objects in a directory tree built under
8194 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
8195 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
8196 would install @file{/tmp/staging/gnu/bin/foo} and
8197 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
8198
8199 This feature is commonly used to build install images and packages
8200 (@pxref{DESTDIR}).
8201
8202 Support for @code{DESTDIR} is implemented by coding it directly into
8203 the install rules.  If your @file{Makefile.am} uses a local install
8204 rule (e.g., @code{install-exec-local}) or an install hook, then you
8205 must write that code to respect @code{DESTDIR}.
8206
8207 @xref{Makefile Conventions, , , standards, The GNU Coding Standards},
8208 for another usage example.
8209
8210 @node Install Rules for the User
8211 @section Install Rules for the User
8212
8213 Automake also generates rules for targets @code{uninstall},
8214 @code{installdirs}, and @code{install-strip}.
8215 @trindex uninstall
8216 @trindex installdirs
8217 @trindex install-strip
8218
8219 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
8220 There is no notion of separate uninstalls for ``exec'' and ``data'', as
8221 these features would not provide additional functionality.
8222
8223 Note that @code{uninstall} is not meant as a replacement for a real
8224 packaging tool.
8225
8226
8227 @node Clean
8228 @chapter What Gets Cleaned
8229
8230 @cindex @samp{make clean} support
8231
8232 The GNU Makefile Standards specify a number of different clean rules.
8233 @xref{Standard Targets, , Standard Targets for Users, standards,
8234 The GNU Coding Standards}.
8235
8236 Generally the files that can be cleaned are determined automatically by
8237 Automake.  Of course, Automake also recognizes some variables that can
8238 be defined to specify additional files to clean.  These variables are
8239 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
8240 @code{MAINTAINERCLEANFILES}.
8241 @vindex MOSTLYCLEANFILES
8242 @vindex CLEANFILES
8243 @vindex DISTCLEANFILES
8244 @vindex MAINTAINERCLEANFILES
8245
8246 @trindex mostlyclean-local
8247 @trindex clean-local
8248 @trindex distclean-local
8249 @trindex maintainer-clean-local
8250 When cleaning involves more than deleting some hard-coded list of
8251 files, it is also possible to supplement the cleaning rules with your
8252 own commands.  Simply define a rule for any of the
8253 @code{mostlyclean-local}, @code{clean-local}, @code{distclean-local},
8254 or @code{maintainer-clean-local} targets (@pxref{Extending}).  A common
8255 case is deleting a directory, for instance, a directory created by the
8256 test suite:
8257
8258 @example
8259 clean-local:
8260         -rm -rf testSubDir
8261 @end example
8262
8263 Since @command{make} allows only one set of rules for a given target,
8264 a more extensible way of writing this is to use a separate target
8265 listed as a dependency:
8266
8267 @example
8268 clean-local: clean-local-check
8269 .PHONY: clean-local-check
8270 clean-local-check:
8271         -rm -rf testSubDir
8272 @end example
8273
8274 As the GNU Standards aren't always explicit as to which files should
8275 be removed by which rule, we've adopted a heuristic that we believe
8276 was first formulated by Fran@,{c}ois Pinard:
8277
8278 @itemize @bullet
8279 @item
8280 If @command{make} built it, and it is commonly something that one would
8281 want to rebuild (for instance, a @file{.o} file), then
8282 @code{mostlyclean} should delete it.
8283
8284 @item
8285 Otherwise, if @command{make} built it, then @code{clean} should delete it.
8286
8287 @item
8288 If @command{configure} built it, then @code{distclean} should delete it.
8289
8290 @item
8291 If the maintainer built it (for instance, a @file{.info} file), then
8292 @code{maintainer-clean} should delete it.  However
8293 @code{maintainer-clean} should not delete anything that needs to exist
8294 in order to run @samp{./configure && make}.
8295 @end itemize
8296
8297 We recommend that you follow this same set of heuristics in your
8298 @file{Makefile.am}.
8299
8300
8301 @node Dist
8302 @chapter What Goes in a Distribution
8303
8304 @menu
8305 * Basics of Distribution::      Files distributed by default
8306 * Fine-grained Distribution Control::  @code{dist_} and @code{nodist_} prefixes
8307 * The dist Hook::               A target for last-minute distribution changes
8308 * Checking the Distribution::   @samp{make distcheck} explained
8309 * The Types of Distributions::  A variety of formats and compression methods
8310 @end menu
8311
8312 @node Basics of Distribution
8313 @section Basics of Distribution
8314
8315 @cindex @samp{make dist}
8316
8317 @vindex PACKAGE
8318 @vindex VERSION
8319 @trindex dist
8320 The @code{dist} rule in the generated @file{Makefile.in} can be used
8321 to generate a gzipped @code{tar} file and other flavors of archive for
8322 distribution.  The file is named based on the @code{PACKAGE} and
8323 @code{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
8324 (@pxref{Macros}); more precisely the gzipped @code{tar} file is named
8325 @samp{@var{package}-@var{version}.tar.gz}.
8326 @vindex GZIP_ENV
8327 You can use the @command{make} variable @code{GZIP_ENV} to control how gzip
8328 is run.  The default setting is @option{--best}.
8329
8330 @cindex @code{m4_include}, distribution
8331 @cindex @code{include}, distribution
8332 @acindex m4_include
8333 @cmindex include
8334 For the most part, the files to distribute are automatically found by
8335 Automake: all source files are automatically included in a distribution,
8336 as are all @file{Makefile.am} and @file{Makefile.in} files.  Automake also
8337 has a built-in list of commonly used files that are automatically
8338 included if they are found in the current directory (either physically,
8339 or as the target of a @file{Makefile.am} rule); this list is printed by
8340 @samp{automake --help}.  Note that some files in this list are actually
8341 distributed only if other certain conditions hold (for example,
8342 @c Keep in sync with autodist-config-headers.test.
8343 the @file{config.h.top} and @file{config.h.bot} files are automatically
8344 distributed only if, e.g., @samp{AC_CONFIG_HEADERS([config.h])} is used
8345 in @file{configure.ac}).  Also, files that are read by @command{configure}
8346 (i.e.@: the source files corresponding to the files specified in various
8347 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
8348 automatically distributed.  Files included in a @file{Makefile.am} (using
8349 @code{include}) or in @file{configure.ac} (using @code{m4_include}), and
8350 helper scripts installed with @samp{automake --add-missing} are also
8351 distributed.
8352
8353 @vindex EXTRA_DIST
8354 Still, sometimes there are files that must be distributed, but which
8355 are not covered in the automatic rules.  These files should be listed in
8356 the @code{EXTRA_DIST} variable.  You can mention files from
8357 subdirectories in @code{EXTRA_DIST}.
8358
8359 You can also mention a directory in @code{EXTRA_DIST}; in this case the
8360 entire directory will be recursively copied into the distribution.
8361 Please note that this will also copy @emph{everything} in the directory,
8362 including, e.g., Subversion's @file{.svn} private directories or CVS/RCS
8363 version control files.  We recommend against using this feature.
8364
8365 @vindex SUBDIRS
8366 @vindex DIST_SUBDIRS
8367 If you define @code{SUBDIRS}, Automake will recursively include the
8368 subdirectories in the distribution.  If @code{SUBDIRS} is defined
8369 conditionally (@pxref{Conditionals}), Automake will normally include
8370 all directories that could possibly appear in @code{SUBDIRS} in the
8371 distribution.  If you need to specify the set of directories
8372 conditionally, you can set the variable @code{DIST_SUBDIRS} to the
8373 exact list of subdirectories to include in the distribution
8374 (@pxref{Conditional Subdirectories}).
8375
8376
8377 @node Fine-grained Distribution Control
8378 @section Fine-grained Distribution Control
8379
8380 @vindex dist_
8381 @vindex nodist_
8382 Sometimes you need tighter control over what does @emph{not} go into the
8383 distribution; for instance, you might have source files that are
8384 generated and that you do not want to distribute.  In this case
8385 Automake gives fine-grained control using the @code{dist} and
8386 @code{nodist} prefixes.  Any primary or @code{_SOURCES} variable can be
8387 prefixed with @code{dist_} to add the listed files to the distribution.
8388 Similarly, @code{nodist_} can be used to omit the files from the
8389 distribution.
8390
8391 As an example, here is how you would cause some data to be distributed
8392 while leaving some source code out of the distribution:
8393
8394 @example
8395 dist_data_DATA = distribute-this
8396 bin_PROGRAMS = foo
8397 nodist_foo_SOURCES = do-not-distribute.c
8398 @end example
8399
8400 @node The dist Hook
8401 @section The dist Hook
8402
8403 @trindex dist-hook
8404
8405 Occasionally it is useful to be able to change the distribution before
8406 it is packaged up.  If the @code{dist-hook} rule exists, it is run
8407 after the distribution directory is filled, but before the actual tar
8408 (or shar) file is created.  One way to use this is for distributing
8409 files in subdirectories for which a new @file{Makefile.am} is overkill:
8410
8411 @example
8412 dist-hook:
8413         mkdir $(distdir)/random
8414         cp -p $(srcdir)/random/a1 $(srcdir)/random/a2 $(distdir)/random
8415 @end example
8416
8417 Another way to use this is for removing unnecessary files that get
8418 recursively included by specifying a directory in EXTRA_DIST:
8419
8420 @example
8421 EXTRA_DIST = doc
8422
8423 dist-hook:
8424         rm -rf `find $(distdir)/doc -type d -name .svn`
8425 @end example
8426
8427 @vindex distdir
8428 @vindex top_distdir
8429 Two variables that come handy when writing @code{dist-hook} rules are
8430 @samp{$(distdir)} and @samp{$(top_distdir)}.
8431
8432 @samp{$(distdir)} points to the directory where the @code{dist} rule
8433 will copy files from the current directory before creating the
8434 tarball.  If you are at the top-level directory, then @samp{distdir =
8435 $(PACKAGE)-$(VERSION)}.  When used from subdirectory named
8436 @file{foo/}, then @samp{distdir = ../$(PACKAGE)-$(VERSION)/foo}.
8437 @samp{$(distdir)} can be a relative or absolute path, do not assume
8438 any form.
8439
8440 @samp{$(top_distdir)} always points to the root directory of the
8441 distributed tree.  At the top-level it's equal to @samp{$(distdir)}.
8442 In the @file{foo/} subdirectory
8443 @samp{top_distdir = ../$(PACKAGE)-$(VERSION)}.
8444 @samp{$(top_distdir)} too can be a relative or absolute path.
8445
8446 Note that when packages are nested using @code{AC_CONFIG_SUBDIRS}
8447 (@pxref{Subpackages}), then @samp{$(distdir)} and
8448 @samp{$(top_distdir)} are relative to the package where @samp{make
8449 dist} was run, not to any sub-packages involved.
8450
8451 @node Checking the Distribution
8452 @section Checking the Distribution
8453
8454 @cindex @samp{make distcheck}
8455 @cindex @samp{make distcleancheck}
8456 @vindex distcleancheck_listfiles
8457 @cindex @samp{make distuninstallcheck}
8458 @vindex distuninstallcheck_listfiles
8459
8460 @trindex distcheck
8461 Automake also generates a @code{distcheck} rule that can be of help to
8462 ensure that a given distribution will actually work.  @code{distcheck}
8463 makes a distribution, then tries to do a @code{VPATH} build
8464 (@pxref{VPATH Builds}), run the test suite, and finally make another
8465 tarball to ensure the distribution is self-contained.
8466
8467 @vindex AM_DISTCHECK_CONFIGURE_FLAGS
8468 @vindex DISTCHECK_CONFIGURE_FLAGS
8469 Building the package involves running @samp{./configure}.  If you need
8470 to supply additional flags to @command{configure}, define them in the
8471 @code{AM_DISTCHECK_CONFIGURE_FLAGS} variable in your top-level
8472 @file{Makefile.am}.  The user can still extend or override the flags
8473 provided there by defining the @code{DISTCHECK_CONFIGURE_FLAGS} variable,
8474 on the command line when invoking @command{make}.
8475
8476 Still, developers are encouraged to strive to make their code buildable
8477 without requiring any special configure option; thus, in general, you
8478 shouldn't define @code{AM_DISTCHECK_CONFIGURE_FLAGS}. However, there
8479 might be few scenarios in which the use of this variable is justified.
8480 GNU @command{m4} offers an example.  GNU @command{m4} configures by
8481 default with its experimental and seldom used "changeword" feature
8482 disabled; so in its case it is useful to have @command{make distcheck}
8483 run configure with the @option{--with-changeword} option, to ensure that
8484 the code for changeword support still compiles correctly.
8485 GNU @command{m4} also employs the @code{AM_DISTCHECK_CONFIGURE_FLAGS}
8486 variable to stress-test the use of @option{--program-prefix=g}, since at
8487 one point the @command{m4} build system had a bug where @command{make
8488 installcheck} was wrongly assuming it could blindly test "@command{m4}",
8489 rather than the just-installed "@command{gm4}".
8490
8491 @trindex distcheck-hook
8492 If the @code{distcheck-hook} rule is defined in your top-level
8493 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
8494 the new distribution has been unpacked, but before the unpacked copy
8495 is configured and built.  Your @code{distcheck-hook} can do almost
8496 anything, though as always caution is advised.  Generally this hook is
8497 used to check for potential distribution errors not caught by the
8498 standard mechanism.  Note that @code{distcheck-hook} as well as
8499 @code{AM_DISTCHECK_CONFIGURE_FLAGS} and @code{DISTCHECK_CONFIGURE_FLAGS}
8500 are not honored in a subpackage @file{Makefile.am}, but the flags from
8501 @code{AM_DISTCHECK_CONFIGURE_FLAGS} and @code{DISTCHECK_CONFIGURE_FLAGS}
8502 are passed down to the @command{configure} script of the subpackage.
8503
8504 @trindex distcleancheck
8505 @vindex DISTCLEANFILES
8506 @vindex distcleancheck_listfiles
8507 Speaking of potential distribution errors, @code{distcheck} also
8508 ensures that the @code{distclean} rule actually removes all built
8509 files.  This is done by running @samp{make distcleancheck} at the end of
8510 the @code{VPATH} build.  By default, @code{distcleancheck} will run
8511 @code{distclean} and then make sure the build tree has been emptied by
8512 running @samp{$(distcleancheck_listfiles)}.  Usually this check will
8513 find generated files that you forgot to add to the @code{DISTCLEANFILES}
8514 variable (@pxref{Clean}).
8515
8516 The @code{distcleancheck} behavior should be OK for most packages,
8517 otherwise you have the possibility to override the definition of
8518 either the @code{distcleancheck} rule, or the
8519 @samp{$(distcleancheck_listfiles)} variable.  For instance, to disable
8520 @code{distcleancheck} completely, add the following rule to your
8521 top-level @file{Makefile.am}:
8522
8523 @example
8524 distcleancheck:
8525         @@:
8526 @end example
8527
8528 If you want @code{distcleancheck} to ignore built files that have not
8529 been cleaned because they are also part of the distribution, add the
8530 following definition instead:
8531
8532 @c Keep in sync with distcleancheck.test.
8533 @example
8534 distcleancheck_listfiles = \
8535   find . -type f -exec sh -c 'test -f $(srcdir)/$$1 || echo $$1' \
8536        sh '@{@}' ';'
8537 @end example
8538
8539 The above definition is not the default because it's usually an error if
8540 your Makefiles cause some distributed files to be rebuilt when the user
8541 build the package.  (Think about the user missing the tool required to
8542 build the file; or if the required tool is built by your package,
8543 consider the cross-compilation case where it can't be run.)  There is
8544 an entry in the FAQ about this (@pxref{distcleancheck}), make sure you
8545 read it before playing with @code{distcleancheck_listfiles}.
8546
8547 @code{distcheck} also checks that the @code{uninstall} rule works
8548 properly, both for ordinary and @code{DESTDIR} builds.  It does this
8549 by invoking @samp{make uninstall}, and then it checks the install tree
8550 to see if any files are left over.  This check will make sure that you
8551 correctly coded your @code{uninstall}-related rules.
8552
8553 By default, the checking is done by the @code{distuninstallcheck} rule,
8554 and the list of files in the install tree is generated by
8555 @samp{$(distuninstallcheck_listfiles)} (this is a variable whose value is
8556 a shell command to run that prints the list of files to stdout).
8557
8558 Either of these can be overridden to modify the behavior of
8559 @code{distcheck}.  For instance, to disable this check completely, you
8560 would write:
8561
8562 @example
8563 distuninstallcheck:
8564         @@:
8565 @end example
8566
8567 @node The Types of Distributions
8568 @section The Types of Distributions
8569
8570 Automake generates rules to provide archives of the project for
8571 distributions in various formats.  Their targets are:
8572
8573 @table @asis
8574 @item @code{dist-bzip2}
8575 Generate a bzip2 tar archive of the distribution.  bzip2 archives are
8576 frequently smaller than gzipped archives.
8577 @trindex dist-bzip2
8578
8579 @item @code{dist-gzip}
8580 Generate a gzip tar archive of the distribution.
8581 @trindex dist-gzip
8582
8583 @item @code{dist-lzma}
8584 Generate an @samp{lzma} tar archive of the distribution.  @command{lzma}
8585 archives are frequently smaller than @command{bzip2}-compressed archives.
8586 The @samp{lzma} format is obsolete, you should use the @samp{xz} format
8587 instead.
8588 @trindex dist-lzma
8589
8590 @item @code{dist-shar}
8591 Generate a shar archive of the distribution.
8592 @trindex dist-shar
8593
8594 @item @code{dist-xz}
8595 Generate an @samp{xz} tar archive of the distribution.  @command{xz}
8596 archives are frequently smaller than @command{bzip2}-compressed archives.
8597 The @samp{xz} format displaces the obsolete @samp{lzma} format.
8598 @trindex dist-xz
8599
8600 @item @code{dist-zip}
8601 Generate a zip archive of the distribution.
8602 @trindex dist-zip
8603
8604 @item @code{dist-tarZ}
8605 Generate a compressed tar archive of
8606 the distribution.
8607 @trindex dist-tarZ
8608 @end table
8609
8610 The rule @code{dist} (and its historical synonym @code{dist-all}) will
8611 create archives in all the enabled formats, @ref{Options}.  By
8612 default, only the @code{dist-gzip} target is hooked to @code{dist}.
8613
8614
8615 @node Tests
8616 @chapter Support for test suites
8617
8618 @cindex Test suites
8619 @cindex @code{make check}
8620 @trindex check
8621
8622 Automake supports three forms of test suites, the first two of which
8623 are very similar.
8624
8625 @menu
8626 * Simple Tests::                Listing programs and scripts in @code{TESTS}
8627 * Simple Tests using parallel-tests::  More powerful test driver
8628 * DejaGnu Tests::               Interfacing with the external testing framework
8629 * Install Tests::               Running tests on installed packages
8630 @end menu
8631
8632 @node Simple Tests
8633 @section Simple Tests
8634
8635 If the variable @code{TESTS} is defined, its value is taken to be a
8636 list of programs or scripts to run in order to do the testing.
8637 Programs needing data files should look for them in @code{srcdir}
8638 (which is both an environment variable and a make variable) so they
8639 work when building in a separate directory (@pxref{Build Directories,
8640 , Build Directories , autoconf, The Autoconf Manual}), and in
8641 particular for the @code{distcheck} rule (@pxref{Checking the
8642 Distribution}).
8643
8644 For each of the @code{TESTS}, the result of execution is printed along
8645 with the test name, where @code{PASS} denotes a successful test,
8646 @code{FAIL} denotes a failed test, @code{XFAIL} an expected failure,
8647 @code{XPASS} an unexpected pass for a test that is supposed to fail,
8648 and @code{SKIP} denotes a skipped test.
8649
8650 @cindex Exit status 77, special interpretation
8651
8652 The number of failures will be printed at the end of the run.  If a
8653 given test program exits with a status of 77, then its result is ignored
8654 in the final count.  This feature allows non-portable tests to be
8655 ignored in environments where they don't make sense.
8656
8657 @vindex AM_COLOR_TESTS
8658 If the Automake option @code{color-tests} is used (@pxref{Options})
8659 and standard output is connected to a capable terminal, then the test
8660 results and the summary are colored appropriately.  The user can disable
8661 colored output by setting the @command{make} variable
8662 @samp{AM_COLOR_TESTS=no}, or force colored output even without a connecting
8663 terminal with @samp{AM_COLOR_TESTS=always}.
8664
8665 Note that the semantics of some @command{make} implementations when used
8666 in parallel mode (@pxref{Parallel make,,, autoconf, The Autoconf Manual})
8667 can cause the automatic detection of a connection to a capable terminal
8668 to fail.  In that case, you can still resort to the use of
8669 @samp{AM_COLOR_TESTS=always}.
8670
8671 @vindex TESTS
8672 @vindex TESTS_ENVIRONMENT
8673 The variable @code{TESTS_ENVIRONMENT} can be used to set environment
8674 variables for the test run; the environment variable @env{srcdir} is
8675 set in the rule.  If all your test programs are scripts, you can also
8676 set @code{TESTS_ENVIRONMENT} to an invocation of the shell (e.g.
8677 @samp{$(SHELL) -x} can be useful for debugging the tests), or any other
8678 interpreter.  For instance, the following setup may be used to run tests
8679 with Perl:
8680
8681 @c Keep in sync with tests-environment-backcompat.test.
8682 @example
8683 TESTS_ENVIRONMENT = $(PERL) -Mstrict -w
8684 TESTS = foo.pl bar.pl baz.pl
8685 @end example
8686
8687 Note that the @option{parallel-tests} driver provides a more elegant
8688 way to achieve the same effect, freeing the @code{TESTS_ENVIRONMENT}
8689 variable for the user to override (@pxref{Simple Tests using
8690 parallel-tests}).
8691
8692
8693 @cindex Tests, expected failure
8694 @cindex Expected test failure
8695
8696 @vindex XFAIL_TESTS
8697 You may define the variable @code{XFAIL_TESTS} to a list of tests
8698 (usually a subset of @code{TESTS}) that are expected to fail.  This will
8699 reverse the result of those tests.
8700
8701 Automake ensures that each file listed in @code{TESTS} is built before
8702 any tests are run; you can list both source and derived programs (or
8703 scripts) in @code{TESTS}; the generated rule will look both in
8704 @code{srcdir} and @file{.}.  For instance, you might want to run a C
8705 program as a test.  To do this you would list its name in @code{TESTS}
8706 and also in @code{check_PROGRAMS}, and then specify it as you would
8707 any other program.
8708
8709 Programs listed in @code{check_PROGRAMS} (and @code{check_LIBRARIES},
8710 @code{check_LTLIBRARIES}...) are only built during @code{make check},
8711 not during @code{make all}.  You should list there any program needed
8712 by your tests that does not need to be built by @code{make all}.  Note
8713 that @code{check_PROGRAMS} are @emph{not} automatically added to
8714 @code{TESTS} because @code{check_PROGRAMS} usually lists programs used
8715 by the tests, not the tests themselves.  Of course you can set
8716 @code{TESTS = $(check_PROGRAMS)} if all your programs are test cases.
8717
8718
8719 @node Simple Tests using parallel-tests
8720 @section Simple Tests using @samp{parallel-tests}
8721 @cindex @option{parallel-tests}, Using
8722
8723 The option @option{parallel-tests} (@pxref{Options}) enables a test
8724 suite driver that is mostly compatible to the simple test driver described
8725 in the previous section, but provides a few more features and slightly different
8726 semantics.  It features concurrent execution of tests with @code{make -j},
8727 allows to specify inter-test dependencies, lazy reruns of tests that
8728 have not completed in a prior run, summary and verbose output in
8729 @samp{RST} (reStructuredText) and @samp{HTML} format, and hard errors
8730 for exceptional failures.  Similar to the simple test driver,
8731 @code{TESTS_ENVIRONMENT}, @code{AM_COLOR_TESTS}, @code{XFAIL_TESTS}, and
8732 the @code{check_*} variables are honored, and the environment variable
8733 @env{srcdir} is set during test execution.
8734
8735 This test driver is still experimental and may undergo changes in order
8736 to satisfy additional portability requirements.
8737
8738 @vindex TEST_SUITE_LOG
8739 @vindex TESTS
8740 The driver operates by defining a set of @command{make} rules to create
8741 a summary log file, @code{TEST_SUITE_LOG}, which defaults to
8742 @file{test-suite.log} and requires a @file{.log} suffix.  This file
8743 depends upon log files created for each single test program listed in
8744 @code{TESTS}, which in turn contain all output produced by the
8745 corresponding tests.
8746
8747 @vindex TEST_EXTENSIONS
8748 @vindex TEST_LOGS
8749 Each log file is created when the corresponding test has completed.
8750 The set of log files is listed in the read-only variable
8751 @code{TEST_LOGS}, and defaults to @code{TESTS}, with the executable
8752 extension if any (@pxref{EXEEXT}), as well as any suffix listed in
8753 @code{TEST_EXTENSIONS} removed, and @file{.log} appended.
8754 @code{TEST_EXTENSIONS} defaults to @file{.test}.  Results are undefined
8755 if a test file name ends in several concatenated suffixes.
8756
8757 @vindex _LOG_COMPILE
8758 @vindex _LOG_COMPILER
8759 @vindex _LOG_FLAGS
8760 @vindex LOG_COMPILE
8761 @vindex LOG_COMPILER
8762 @vindex LOG_FLAGS
8763 @vindex @var{ext}_LOG_COMPILE
8764 @vindex @var{ext}_LOG_COMPILER
8765 @vindex @var{ext}_LOG_FLAGS
8766 @vindex AM_@var{ext}_LOG_FLAGS
8767 @vindex AM_LOG_FLAGS
8768 For tests that match an extension @code{.@var{ext}} listed in
8769 @code{TEST_EXTENSIONS}, you can provide a test driver using the variable
8770 @code{@var{ext}_LOG_COMPILER} (note the upper-case extension) and pass
8771 options in @code{AM_@var{ext}_LOG_FLAGS} and allow the user to pass
8772 options in @code{@var{ext}_LOG_FLAGS}.  It will cause all tests with
8773 this extension to be called with this driver.  For all tests without a
8774 registered extension, the variables @code{LOG_COMPILER},
8775 @code{AM_LOG_FLAGS}, and @code{LOG_FLAGS} may be used.  For example,
8776
8777 @c Keep in sync with parallel-tests-log-compiler-example.test.
8778 @example
8779 TESTS = foo.pl bar.py baz
8780 TEST_EXTENSIONS = .pl .py
8781 PL_LOG_COMPILER = $(PERL)
8782 AM_PL_LOG_FLAGS = -w
8783 PY_LOG_COMPILER = $(PYTHON)
8784 AM_PY_LOG_FLAGS = -v
8785 LOG_COMPILER = ./wrapper-script
8786 AM_LOG_FLAGS = -d
8787 @end example
8788
8789 @noindent
8790 will invoke @samp{$(PERL) -w foo.pl}, @samp{$(PYTHON) -v bar.py},
8791 and @samp{./wrapper-script -d baz} to produce @file{foo.log},
8792 @file{bar.log}, and @file{baz.log}, respectively.  The
8793 @samp{TESTS_ENVIRONMENT} variable is still expanded before the driver,
8794 but should be reserved for the user.
8795
8796 @vindex VERBOSE
8797 As with the simple driver above, by default one status line is printed
8798 per completed test, and a short summary after the suite has completed.
8799 However, standard output and standard error of the test are redirected
8800 to a per-test log file, so that parallel execution does not produce
8801 intermingled output.  The output from failed tests is collected in the
8802 @file{test-suite.log} file.  If the variable @samp{VERBOSE} is set, this
8803 file is output after the summary.  For best results, the tests should be
8804 verbose by default now.
8805
8806 @trindex mostlyclean
8807 @trindex check-html
8808 @vindex RST2HTML
8809 @vindex TEST_SUITE_HTML
8810 With @code{make check-html}, the log files may be converted from RST
8811 (reStructuredText, see @uref{http://docutils.sourceforge.net/@/rst.html})
8812 to HTML using @samp{RST2HTML}, which defaults to @command{rst2html} or
8813 @command{rst2html.py}.  The variable @samp{TEST_SUITE_HTML} contains the
8814 set of converted log files.  The log and HTML files are removed upon
8815 @code{make mostlyclean}.
8816
8817 @vindex DISABLE_HARD_ERRORS
8818 @cindex Exit status 99, special interpretation
8819 @cindex hard error
8820 Even in the presence of expected failures (see @code{XFAIL_TESTS}), there
8821 may be conditions under which a test outcome needs attention.  For
8822 example, with test-driven development, you may write tests for features
8823 that you have not implemented yet, and thus mark these tests as expected
8824 to fail.  However, you may still be interested in exceptional conditions,
8825 for example, tests that fail due to a segmentation violation or another
8826 error that is independent of the feature awaiting implementation.
8827 Tests can exit with an exit status of 99 to signal such a @emph{hard
8828 error}.  Unless the variable @code{DISABLE_HARD_ERRORS} is set to a
8829 nonempty value, such tests will be counted as failed.
8830
8831 By default, the test suite driver will run all tests, but there are
8832 several ways to limit the set of tests that are run:
8833
8834 @itemize @bullet
8835 @item
8836 You can set the @code{TESTS} variable, similarly to how you can with
8837 the simple test driver from the previous section.  For example, you can
8838 use a command like this to run only a subset of the tests:
8839
8840 @example
8841 env TESTS="foo.test bar.test" make -e check
8842 @end example
8843
8844 Note however that the command above will unconditionally overwrite the
8845 @file{test-suite.log} file, thus clobbering the recorded results
8846 of any previous testsuite run.  This might be undesirable for packages
8847 whose testsuite takes long time to execute.  Luckily, this problem can
8848 easily be avoided by overriding also @code{TEST_SUITE_LOG} at runtime;
8849 for example,
8850
8851 @c Keep in sync with parallel-tests-log-override-2.test.
8852 @example
8853 env TEST_SUITE_LOG=partial.log TESTS="..." make -e check
8854 @end example
8855
8856 will write the result of the partial testsuite runs to the
8857 @file{partial.log}, without touching @file{test-suite.log}.
8858
8859 @item
8860 You can set the @code{TEST_LOGS} variable.  By default, this variable is
8861 computed at @command{make} run time from the value of @code{TESTS} as
8862 described above.  For example, you can use the following:
8863
8864 @example
8865 set x subset*.log; shift
8866 env TEST_LOGS="foo.log $*" make -e check
8867 @end example
8868
8869 The comments made above about @code{TEST_SUITE_LOG} overriding applies
8870 here too.
8871
8872 @item
8873 @vindex RECHECK_LOGS
8874 @cindex lazy test execution
8875 By default, the test driver removes all old per-test log files before it
8876 starts running tests to regenerate them.  The variable
8877 @code{RECHECK_LOGS} contains the set of log files which are removed.
8878 @code{RECHECK_LOGS} defaults to @code{TEST_LOGS}, which means all tests
8879 need to be rechecked.  By overriding this variable, you can choose which
8880 tests need to be reconsidered.  For example, you can lazily rerun only
8881 those tests which are outdated, i.e., older than their prerequisite test
8882 files, by setting this variable to the empty value:
8883
8884 @example
8885 env RECHECK_LOGS= make -e check
8886 @end example
8887
8888 @item
8889 @trindex recheck
8890 @trindex recheck-html
8891 You can ensure that all tests are rerun which have failed or passed
8892 unexpectedly, by running @code{make recheck} in the test directory.
8893 This convenience target will set @code{RECHECK_LOGS} appropriately
8894 before invoking the main test driver.  The @code{recheck-html} target
8895 does the same as @code{recheck} but again converts the resulting log
8896 file in HTML format, like the @code{check-html} target.
8897 @end itemize
8898
8899 In order to guarantee an ordering between tests even with @code{make
8900 -j@var{N}}, dependencies between the corresponding log files may be
8901 specified through usual @command{make} dependencies.  For example, the
8902 following snippet lets the test named @file{foo-execute.test} depend
8903 upon completion of the test @file{foo-compile.test}:
8904
8905 @example
8906 TESTS = foo-compile.test foo-execute.test
8907 foo-execute.log: foo-compile.log
8908 @end example
8909
8910 @noindent
8911 Please note that this ordering ignores the @emph{results} of required
8912 tests, thus the test @file{foo-execute.test} is run even if the test
8913 @file{foo-compile.test} failed or was skipped beforehand.  Further,
8914 please note that specifying such dependencies currently works only for
8915 tests that end in one of the suffixes listed in @code{TEST_EXTENSIONS}.
8916
8917 Tests without such specified dependencies may be run concurrently with
8918 parallel @command{make -j@var{N}}, so be sure they are prepared for
8919 concurrent execution.
8920
8921 @cindex Unit tests
8922 The combination of lazy test execution and correct dependencies between
8923 tests and their sources may be exploited for efficient unit testing
8924 during development.  To further speed up the edit-compile-test cycle, it
8925 may even be useful to specify compiled programs in @code{EXTRA_PROGRAMS}
8926 instead of with @code{check_PROGRAMS}, as the former allows intertwined
8927 compilation and test execution (but note that @code{EXTRA_PROGRAMS} are
8928 not cleaned automatically, @pxref{Uniform}).
8929
8930 The variables @code{TESTS} and @code{XFAIL_TESTS} may contain
8931 conditional parts as well as configure substitutions.  In the latter
8932 case, however, certain restrictions apply: substituted test names
8933 must end with a nonempty test suffix like @file{.test}, so that one of
8934 the inference rules generated by @command{automake} can apply.  For
8935 literal test names, @command{automake} can generate per-target rules
8936 to avoid this limitation.
8937
8938 Please note that it is currently not possible to use @code{$(srcdir)/}
8939 or @code{$(top_srcdir)/} in the @code{TESTS} variable.  This technical
8940 limitation is necessary to avoid generating test logs in the source tree
8941 and has the unfortunate consequence that it is not possible to specify
8942 distributed tests that are themselves generated by means of explicit
8943 rules, in a way that is portable to all @command{make} implementations
8944 (@pxref{Make Target Lookup,,, autoconf, The Autoconf Manual}, the
8945 semantics of FreeBSD and OpenBSD @command{make} conflict with this).
8946 In case of doubt you may want to require to use GNU @command{make},
8947 or work around the issue with inference rules to generate the tests.
8948
8949
8950 @node DejaGnu Tests
8951 @section DejaGnu Tests
8952
8953 If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @command{dejagnu}} appears in
8954 @code{AUTOMAKE_OPTIONS}, then a @command{dejagnu}-based test suite is
8955 assumed.  The variable @code{DEJATOOL} is a list of names that are
8956 passed, one at a time, as the @option{--tool} argument to
8957 @command{runtest} invocations; it defaults to the name of the package.
8958
8959 The variable @code{RUNTESTDEFAULTFLAGS} holds the @option{--tool} and
8960 @option{--srcdir} flags that are passed to dejagnu by default; this can be
8961 overridden if necessary.
8962 @vindex RUNTESTDEFAULTFLAGS
8963
8964 The variables @code{EXPECT} and @code{RUNTEST} can
8965 also be overridden to provide project-specific values.  For instance,
8966 you will need to do this if you are testing a compiler toolchain,
8967 because the default values do not take into account host and target
8968 names.
8969 @opindex dejagnu
8970 @vindex DEJATOOL
8971 @vindex EXPECT
8972 @vindex RUNTEST
8973
8974 The contents of the variable @code{RUNTESTFLAGS} are passed to the
8975 @code{runtest} invocation.  This is considered a ``user variable''
8976 (@pxref{User Variables}).  If you need to set @command{runtest} flags in
8977 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
8978 @vindex RUNTESTFLAGS
8979 @vindex AM_RUNTESTFLAGS
8980
8981 @cindex @file{site.exp}
8982 Automake will generate rules to create a local @file{site.exp} file,
8983 defining various variables detected by @command{configure}.  This file
8984 is automatically read by DejaGnu.  It is OK for the user of a package
8985 to edit this file in order to tune the test suite.  However this is
8986 not the place where the test suite author should define new variables:
8987 this should be done elsewhere in the real test suite code.
8988 Especially, @file{site.exp} should not be distributed.
8989
8990 For more information regarding DejaGnu test suites, see @ref{Top, , ,
8991 dejagnu, The DejaGnu Manual}.
8992
8993 In either case, the testing is done via @samp{make check}.
8994
8995 @node Install Tests
8996 @section Install Tests
8997
8998 The @code{installcheck} target is available to the user as a way to
8999 run any tests after the package has been installed.  You can add tests
9000 to this by writing an @code{installcheck-local} rule.
9001
9002
9003 @node Rebuilding
9004 @chapter Rebuilding Makefiles
9005 @cindex rebuild rules
9006
9007 Automake generates rules to automatically rebuild @file{Makefile}s,
9008 @file{configure}, and other derived files like @file{Makefile.in}.
9009
9010 @acindex AM_MAINTAINER_MODE
9011 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.ac}, then
9012 these automatic rebuilding rules are only enabled in maintainer mode.
9013
9014 @vindex ACLOCAL_AMFLAGS
9015 Sometimes you need to run @command{aclocal} with an argument like
9016 @option{-I} to tell it where to find @file{.m4} files.  Since
9017 sometimes @command{make} will automatically run @command{aclocal}, you
9018 need a way to specify these arguments.  You can do this by defining
9019 @code{ACLOCAL_AMFLAGS}; this holds arguments that are passed verbatim
9020 to @command{aclocal}.  This variable is only useful in the top-level
9021 @file{Makefile.am}.
9022
9023 @vindex CONFIG_STATUS_DEPENDENCIES
9024 @vindex CONFIGURE_DEPENDENCIES
9025 @cindex @file{version.sh}, example
9026 @cindex @file{version.m4}, example
9027
9028 Sometimes it is convenient to supplement the rebuild rules for
9029 @file{configure} or @file{config.status} with additional dependencies.
9030 The variables @code{CONFIGURE_DEPENDENCIES} and
9031 @code{CONFIG_STATUS_DEPENDENCIES} can be used to list these extra
9032 dependencies.  These variables should be defined in all
9033 @file{Makefile}s of the tree (because these two rebuild rules are
9034 output in all them), so it is safer and easier to @code{AC_SUBST} them
9035 from @file{configure.ac}.  For instance, the following statement will
9036 cause @file{configure} to be rerun each time @file{version.sh} is
9037 changed.
9038
9039 @example
9040 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh'])
9041 @end example
9042
9043 @noindent
9044 Note the @samp{$(top_srcdir)/} in the file name.  Since this variable
9045 is to be used in all @file{Makefile}s, its value must be sensible at
9046 any level in the build hierarchy.
9047
9048 Beware not to mistake @code{CONFIGURE_DEPENDENCIES} for
9049 @code{CONFIG_STATUS_DEPENDENCIES}.
9050
9051 @code{CONFIGURE_DEPENDENCIES} adds dependencies to the
9052 @file{configure} rule, whose effect is to run @command{autoconf}.  This
9053 variable should be seldom used, because @command{automake} already tracks
9054 @code{m4_include}d files.  However it can be useful when playing
9055 tricky games with @code{m4_esyscmd} or similar non-recommendable
9056 macros with side effects.
9057
9058 @code{CONFIG_STATUS_DEPENDENCIES} adds dependencies to the
9059 @file{config.status} rule, whose effect is to run @file{configure}.
9060 This variable should therefore carry any non-standard source that may
9061 be read as a side effect of running @command{configure}, like @file{version.sh}
9062 in the example above.
9063
9064 Speaking of @file{version.sh} scripts, we recommend against them
9065 today.  They are mainly used when the version of a package is updated
9066 automatically by a script (e.g., in daily builds).  Here is what some
9067 old-style @file{configure.ac}s may look like:
9068
9069 @example
9070 AC_INIT
9071 . $srcdir/version.sh
9072 AM_INIT_AUTOMAKE([name], $VERSION_NUMBER)
9073 @dots{}
9074 @end example
9075
9076 @noindent
9077 Here, @file{version.sh} is a shell fragment that sets
9078 @code{VERSION_NUMBER}.  The problem with this example is that
9079 @command{automake} cannot track dependencies (listing @file{version.sh}
9080 in @command{CONFIG_STATUS_DEPENDENCIES}, and distributing this file is up
9081 to the user), and that it uses the obsolete form of @code{AC_INIT} and
9082 @code{AM_INIT_AUTOMAKE}.  Upgrading to the new syntax is not
9083 straightforward, because shell variables are not allowed in
9084 @code{AC_INIT}'s arguments.  We recommend that @file{version.sh} be
9085 replaced by an M4 file that is included by @file{configure.ac}:
9086
9087 @example
9088 m4_include([version.m4])
9089 AC_INIT([name], VERSION_NUMBER)
9090 AM_INIT_AUTOMAKE
9091 @dots{}
9092 @end example
9093
9094 @noindent
9095 Here @file{version.m4} could contain something like
9096 @samp{m4_define([VERSION_NUMBER], [1.2])}.  The advantage of this
9097 second form is that @command{automake} will take care of the
9098 dependencies when defining the rebuild rule, and will also distribute
9099 the file automatically.  An inconvenience is that @command{autoconf}
9100 will now be rerun each time the version number is bumped, when only
9101 @file{configure} had to be rerun in the previous setup.
9102
9103
9104 @node Options
9105 @chapter Changing Automake's Behavior
9106
9107 Various features of Automake can be controlled by options.  Except where
9108 noted otherwise, options can be specified in one of several ways: Most
9109 options can be applied on a per-@file{Makefile} basis when listed in a
9110 special @file{Makefile} variable named @code{AUTOMAKE_OPTIONS}.  Some
9111 of these options only make sense when specified in the toplevel
9112 @file{Makefile.am} file.  Options are applied globally to all processed
9113 @file{Makefile} files when listed in the first argument of
9114 @code{AM_INIT_AUTOMAKE} in @file{configure.ac}, and some options which
9115 require changes to the @command{configure} script can only be specified
9116 there.  These are annotated below.
9117
9118 Currently understood options are:
9119 @vindex AUTOMAKE_OPTIONS
9120
9121 @table @asis
9122 @item @option{gnits}
9123 @itemx @option{gnu}
9124 @itemx @option{foreign}
9125 @itemx @option{cygnus}
9126 @cindex Option, @option{gnits}
9127 @cindex Option, @option{gnu}
9128 @cindex Option, @option{foreign}
9129 @cindex Option, @option{cygnus}
9130 @opindex gnits
9131 @opindex gnu
9132 @opindex foreign
9133 @opindex cygnus
9134
9135 Set the strictness as appropriate.  The @option{gnits} option also
9136 implies options @option{readme-alpha} and @option{check-news}.
9137
9138 @item @option{ansi2knr}
9139 @itemx @option{@var{path}/ansi2knr}
9140 @cindex Option, @option{ansi2knr}
9141 @opindex ansi2knr
9142 Turn on the deprecated de-ANSI-fication feature (@pxref{ANSI}).  Note
9143 that that feature and this option @emph{will be removed} in the next
9144 major Automake release.
9145
9146 If preceded by a
9147 path, the generated @file{Makefile.in} will look in the specified
9148 directory to find the @file{ansi2knr} program.  The path should be a
9149 relative path to another directory in the same distribution (Automake
9150 does not check this).
9151
9152 @item @option{check-news}
9153 @cindex Option, @option{check-news}
9154 @opindex check-news
9155 Cause @samp{make dist} to fail unless the current version number appears
9156 in the first few lines of the @file{NEWS} file.
9157
9158 @item @option{color-tests}
9159 @cindex Option, @option{color-tests}
9160 @opindex color-tests
9161 Cause output of the simple test suite (@pxref{Simple Tests}) to be
9162 colorized on capable terminals.
9163
9164 @item @option{dejagnu}
9165 @cindex Option, @option{dejagnu}
9166 @opindex dejagnu
9167 Cause @command{dejagnu}-specific rules to be generated.  @xref{DejaGnu Tests}.
9168
9169 @item @option{dist-bzip2}
9170 @cindex Option, @option{dist-bzip2}
9171 @opindex dist-bzip2
9172 Hook @code{dist-bzip2} to @code{dist}.
9173 @trindex dist-bzip2
9174
9175 @item @option{dist-lzma}
9176 @cindex Option, @option{dist-lzma}
9177 @opindex dist-lzma
9178 Hook @code{dist-lzma} to @code{dist}.  Obsoleted by @code{dist-xz}.
9179 @trindex dist-lzma
9180
9181 @item @option{dist-shar}
9182 @cindex Option, @option{dist-shar}
9183 @opindex dist-shar
9184 Hook @code{dist-shar} to @code{dist}.
9185 @trindex dist-shar
9186
9187 @item @option{dist-zip}
9188 @cindex Option, @option{dist-zip}
9189 @opindex dist-zip
9190 Hook @code{dist-zip} to @code{dist}.
9191 @trindex dist-zip
9192
9193 @item @option{dist-tarZ}
9194 @cindex Option, @option{dist-tarZ}
9195 @opindex dist-tarZ
9196 Hook @code{dist-tarZ} to @code{dist}.
9197 @trindex dist-tarZ
9198
9199 @item @option{filename-length-max=99}
9200 @cindex Option, @option{filename-length-max=99}
9201 @opindex filename-length-max=99
9202 Abort if file names longer than 99 characters are found during
9203 @samp{make dist}.  Such long file names are generally considered not to
9204 be portable in tarballs.  See the @option{tar-v7} and @option{tar-ustar}
9205 options below.  This option should be used in the top-level
9206 @file{Makefile.am} or as an argument of @code{AM_INIT_AUTOMAKE} in
9207 @file{configure.ac}, it will be ignored otherwise.  It will also be
9208 ignored in sub-packages of nested packages (@pxref{Subpackages}).
9209
9210 @item @option{no-define}
9211 @cindex Option, @option{no-define}
9212 @opindex no-define
9213 This option is meaningful only when passed as an argument to
9214 @code{AM_INIT_AUTOMAKE}.  It will prevent the @code{PACKAGE} and
9215 @code{VERSION} variables from being @code{AC_DEFINE}d.
9216
9217 @item @option{no-dependencies}
9218 @cindex Option, @option{no-dependencies}
9219 @opindex no-dependencies
9220 This is similar to using @option{--ignore-deps} on the command line,
9221 but is useful for those situations where you don't have the necessary
9222 bits to make automatic dependency tracking work
9223 (@pxref{Dependencies}).  In this case the effect is to effectively
9224 disable automatic dependency tracking.
9225
9226 @item @option{no-dist}
9227 @cindex Option, @option{no-dist}
9228 @opindex no-dist
9229 Don't emit any code related to @code{dist} target.  This is useful
9230 when a package has its own method for making distributions.
9231
9232 @item @option{no-dist-gzip}
9233 @cindex Option, @option{no-dist-gzip}
9234 @opindex no-dist-gzip
9235 Do not hook @code{dist-gzip} to @code{dist}.
9236 @trindex no-dist-gzip
9237
9238 @item @option{no-exeext}
9239 @cindex Option, @option{no-exeext}
9240 @opindex no-exeext
9241 If your @file{Makefile.am} defines a rule for target @code{foo}, it
9242 will override a rule for a target named @samp{foo$(EXEEXT)}.  This is
9243 necessary when @code{EXEEXT} is found to be empty.  However, by
9244 default @command{automake} will generate an error for this use.  The
9245 @option{no-exeext} option will disable this error.  This is intended for
9246 use only where it is known in advance that the package will not be
9247 ported to Windows, or any other operating system using extensions on
9248 executables.
9249
9250 @item @option{no-installinfo}
9251 @cindex Option, @option{no-installinfo}
9252 @opindex no-installinfo
9253 The generated @file{Makefile.in} will not cause info pages to be built
9254 or installed by default.  However, @code{info} and @code{install-info}
9255 targets will still be available.  This option is disallowed at
9256 @option{gnu} strictness and above.
9257 @trindex info
9258 @trindex install-info
9259
9260 @item @option{no-installman}
9261 @cindex Option, @option{no-installman}
9262 @opindex no-installman
9263 The generated @file{Makefile.in} will not cause man pages to be
9264 installed by default.  However, an @code{install-man} target will still
9265 be available for optional installation.  This option is disallowed at
9266 @option{gnu} strictness and above.
9267 @trindex install-man
9268
9269 @item @option{nostdinc}
9270 @cindex Option, @option{nostdinc}
9271 @opindex nostdinc
9272 This option can be used to disable the standard @option{-I} options that
9273 are ordinarily automatically provided by Automake.
9274
9275 @item @option{no-texinfo.tex}
9276 @cindex Option, @option{no-texinfo.tex}
9277 @opindex no-texinfo.tex
9278 Don't require @file{texinfo.tex}, even if there are texinfo files in
9279 this directory.
9280
9281 @item @option{parallel-tests}
9282 @cindex Option, @option{parallel-tests}
9283 @opindex parallel-tests
9284 Enable test suite driver for @code{TESTS} that can run tests in parallel
9285 (@pxref{Simple Tests using parallel-tests}, for more information).
9286
9287 @item @option{readme-alpha}
9288 @cindex Option, @option{readme-alpha}
9289 @opindex readme-alpha
9290 If this release is an alpha release, and the file @file{README-alpha}
9291 exists, then it will be added to the distribution.  If this option is
9292 given, version numbers are expected to follow one of two forms.  The
9293 first form is @samp{@var{major}.@var{minor}.@var{alpha}}, where each
9294 element is a number; the final period and number should be left off for
9295 non-alpha releases.  The second form is
9296 @samp{@var{major}.@var{minor}@var{alpha}}, where @var{alpha} is a
9297 letter; it should be omitted for non-alpha releases.
9298
9299 @item @option{silent-rules}
9300 @cindex Option, @option{silent-rules}
9301 @opindex silent-rules
9302 Enable less verbose build rules.  This can be used to let build rules
9303 output status lines of the form:
9304 @example
9305 GEN @var{output-file}
9306  CC @var{object-file}
9307 @end example
9308 @noindent
9309 instead of printing the command that will be executed to update
9310 @var{output-file} or to compile @var{object-file}.  It can also
9311 silence @command{libtool} output.
9312
9313 For more information about how to use, enable, or disable silent
9314 rules, @pxref{Automake silent-rules Option}.
9315
9316 @item @option{std-options}
9317 @cindex Options, @option{std-options}
9318 @cindex @samp{make installcheck}, testing @option{--help} and @option{--version}
9319 @cindex @option{--help} check
9320 @cindex @option{--version} check
9321 @opindex std-options
9322
9323 Make the @code{installcheck} rule check that installed scripts and
9324 programs support the @option{--help} and @option{--version} options.
9325 This also provides a basic check that the program's
9326 run-time dependencies are satisfied after installation.
9327
9328 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
9329 In a few situations, programs (or scripts) have to be exempted from this
9330 test.  For instance, @command{false} (from GNU coreutils) is never
9331 successful, even for @option{--help} or @option{--version}.  You can list
9332 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
9333 Programs (not scripts) listed in this variable should be suffixed by
9334 @samp{$(EXEEXT)} for the sake of Win32 or OS/2.  For instance, suppose we
9335 build @file{false} as a program but @file{true.sh} as a script, and that
9336 neither of them support @option{--help} or @option{--version}:
9337
9338 @example
9339 AUTOMAKE_OPTIONS = std-options
9340 bin_PROGRAMS = false ...
9341 bin_SCRIPTS = true.sh ...
9342 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
9343 @end example
9344
9345 @item @option{subdir-objects}
9346 @cindex Options, @option{subdir-objects}
9347 @opindex subdir-objects
9348 If this option is specified, then objects are placed into the
9349 subdirectory of the build directory corresponding to the subdirectory of
9350 the source file.  For instance, if the source file is
9351 @file{subdir/file.cxx}, then the output file would be
9352 @file{subdir/file.o}.
9353
9354 In order to use this option with C sources, you should add
9355 @code{AM_PROG_CC_C_O} to @file{configure.ac}.
9356
9357 @anchor{tar-formats}
9358 @item @option{tar-v7}
9359 @itemx @option{tar-ustar}
9360 @itemx @option{tar-pax}
9361 @cindex Option, @option{tar-v7}
9362 @cindex Option, @option{tar-ustar}
9363 @cindex Option, @option{tar-pax}
9364 @cindex @command{tar} formats
9365 @cindex v7 @command{tar} format
9366 @cindex ustar format
9367 @cindex pax format
9368 @opindex tar-v7
9369 @opindex tar-ustar
9370 @opindex tar-pax
9371
9372 These three mutually exclusive options select the tar format to use
9373 when generating tarballs with @samp{make dist}.  (The tar file created
9374 is then compressed according to the set of @option{no-dist-gzip},
9375 @option{dist-bzip2}, @option{dist-xz} and @option{dist-tarZ} options in use.)
9376
9377 These options must be passed as arguments to @code{AM_INIT_AUTOMAKE}
9378 (@pxref{Macros}) because they can require additional configure checks.
9379 Automake will complain if it sees such options in an
9380 @code{AUTOMAKE_OPTIONS} variable.
9381
9382 @option{tar-v7} selects the old V7 tar format.  This is the historical
9383 default.  This antiquated format is understood by all tar
9384 implementations and supports file names with up to 99 characters.  When
9385 given longer file names some tar implementations will diagnose the
9386 problem while other will generate broken tarballs or use non-portable
9387 extensions.  Furthermore, the V7 format cannot store empty
9388 directories.  When using this format, consider using the
9389 @option{filename-length-max=99} option to catch file names too long.
9390
9391 @option{tar-ustar} selects the ustar format defined by POSIX
9392 1003.1-1988.  This format is believed to be old enough to be portable.
9393 It fully supports empty directories.  It can store file names with up
9394 to 256 characters, provided that the file name can be split at
9395 directory separator in two parts, first of them being at most 155
9396 bytes long.  So, in most cases the maximum file name length will be
9397 shorter than 256 characters.  However you may run against broken tar
9398 implementations that incorrectly handle file names longer than 99
9399 characters (please report them to @email{@value{PACKAGE_BUGREPORT}} so we
9400 can document this accurately).
9401
9402 @option{tar-pax} selects the new pax interchange format defined by POSIX
9403 1003.1-2001.  It does not limit the length of file names.  However,
9404 this format is very young and should probably be restricted to
9405 packages that target only very modern platforms.  There are moves to
9406 change the pax format in an upward-compatible way, so this option may
9407 refer to a more recent version in the future.
9408
9409 @xref{Formats, , Controlling the Archive Format, tar, GNU Tar}, for
9410 further discussion about tar formats.
9411
9412 @command{configure} knows several ways to construct these formats.  It
9413 will not abort if it cannot find a tool up to the task (so that the
9414 package can still be built), but @samp{make dist} will fail.
9415
9416 @item @var{version}
9417 @cindex Option, @var{version}
9418 A version number (e.g., @samp{0.30}) can be specified.  If Automake is not
9419 newer than the version specified, creation of the @file{Makefile.in}
9420 will be suppressed.
9421
9422 @item @option{-W@var{category}} or @option{--warnings=@var{category}}
9423 @cindex Option, warnings
9424 @cindex Option, @option{-W@var{category}}
9425 @cindex Option, @option{--warnings=@var{category}}
9426 These options behave exactly like their command-line counterpart
9427 (@pxref{Invoking Automake}).  This allows you to enable or disable some
9428 warning categories on a per-file basis.  You can also setup some warnings
9429 for your entire project; for instance, try @samp{AM_INIT_AUTOMAKE([-Wall])}
9430 in your @file{configure.ac}.
9431
9432 @end table
9433
9434 Unrecognized options are diagnosed by @command{automake}.
9435
9436 If you want an option to apply to all the files in the tree, you can use
9437 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.ac}.
9438 @xref{Macros}.
9439
9440
9441 @node Miscellaneous
9442 @chapter Miscellaneous Rules
9443
9444 There are a few rules and variables that didn't fit anywhere else.
9445
9446 @menu
9447 * Tags::                        Interfacing to etags and mkid
9448 * Suffixes::                    Handling new file extensions
9449 * Multilibs::                   Support for multilibs.
9450 @end menu
9451
9452
9453 @node Tags
9454 @section Interfacing to @command{etags}
9455
9456 @cindex @file{TAGS} support
9457
9458 Automake will generate rules to generate @file{TAGS} files for use with
9459 GNU Emacs under some circumstances.
9460
9461 @trindex tags
9462 If any C, C++ or Fortran 77 source code or headers are present, then
9463 @code{tags} and @code{TAGS} rules will be generated for the directory.
9464 All files listed using the @code{_SOURCES}, @code{_HEADERS}, and
9465 @code{_LISP} primaries will be used to generate tags.  Note that
9466 generated source files that are not distributed must be declared in
9467 variables like @code{nodist_noinst_HEADERS} or
9468 @code{nodist_@var{prog}_SOURCES} or they will be ignored.
9469
9470 A @code{tags} rule will be output at the topmost directory of a
9471 multi-directory package.  When run from this topmost directory,
9472 @samp{make tags} will generate a @file{TAGS} file that includes by
9473 reference all @file{TAGS} files from subdirectories.
9474
9475 The @code{tags} rule will also be generated if the variable
9476 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
9477 directories that contain taggable source that @command{etags} does
9478 not understand.  The user can use the @code{ETAGSFLAGS} to pass
9479 additional flags to @command{etags}; @code{AM_ETAGSFLAGS} is also
9480 available for use in @file{Makefile.am}.
9481 @vindex ETAGS_ARGS
9482 @vindex ETAGSFLAGS
9483 @vindex AM_ETAGSFLAGS
9484
9485 Here is how Automake generates tags for its source, and for nodes in its
9486 Texinfo file:
9487
9488 @example
9489 ETAGS_ARGS = automake.in --lang=none \
9490  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
9491 @end example
9492
9493 If you add file names to @code{ETAGS_ARGS}, you will probably also
9494 want to define @code{TAGS_DEPENDENCIES}.  The contents of this variable
9495 are added directly to the dependencies for the @code{tags} rule.
9496 @vindex TAGS_DEPENDENCIES
9497
9498 Automake also generates a @code{ctags} rule that can be used to
9499 build @command{vi}-style @file{tags} files.  The variable @code{CTAGS}
9500 is the name of the program to invoke (by default @command{ctags});
9501 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
9502 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
9503
9504 Automake will also generate an @code{ID} rule that will run
9505 @command{mkid} on the source.  This is only supported on a
9506 directory-by-directory basis.
9507 @trindex id
9508
9509 Finally, Automake also emits rules to support the
9510 @uref{http://www.gnu.org/software/global/, GNU Global Tags program}.
9511 The @code{GTAGS} rule runs Global Tags and puts the
9512 result in the top build directory.  The variable @code{GTAGS_ARGS}
9513 holds arguments that are passed to @command{gtags}.
9514 @vindex GTAGS_ARGS
9515
9516
9517 @node Suffixes
9518 @section Handling new file extensions
9519
9520 @cindex Adding new @code{SUFFIXES}
9521 @cindex @code{SUFFIXES}, adding
9522 @vindex SUFFIXES
9523
9524 It is sometimes useful to introduce a new implicit rule to handle a file
9525 type that Automake does not know about.
9526
9527 For instance, suppose you had a compiler that could compile @file{.foo}
9528 files to @file{.o} files.  You would simply define a suffix rule for
9529 your language:
9530
9531 @example
9532 .foo.o:
9533         foocc -c -o $@@ $<
9534 @end example
9535
9536 Then you could directly use a @file{.foo} file in a @code{_SOURCES}
9537 variable and expect the correct results:
9538
9539 @example
9540 bin_PROGRAMS = doit
9541 doit_SOURCES = doit.foo
9542 @end example
9543
9544 This was the simpler and more common case.  In other cases, you will
9545 have to help Automake to figure out which extensions you are defining your
9546 suffix rule for.  This usually happens when your extension does not
9547 start with a dot.  Then, all you have to do is to put a list of new
9548 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
9549 implicit rule.
9550
9551 For instance, the following definition prevents Automake from misinterpreting
9552 the @samp{.idlC.cpp:} rule as an attempt to transform @file{.idlC} files into
9553 @file{.cpp} files.
9554
9555 @c Keep in sync with suffix7.test.
9556 @example
9557 SUFFIXES = .idl C.cpp
9558 .idlC.cpp:
9559         # whatever
9560 @end example
9561
9562 As you may have noted, the @code{SUFFIXES} variable behaves like the
9563 @code{.SUFFIXES} special target of @command{make}.  You should not touch
9564 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
9565 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
9566 @code{SUFFIXES} go at the start of the generated suffixes list, followed
9567 by Automake generated suffixes not already in the list.
9568
9569 @node Multilibs
9570 @section Support for Multilibs
9571
9572 Automake has support for an obscure feature called multilibs.  A
9573 @dfn{multilib} is a library that is built for multiple different ABIs
9574 at a single time; each time the library is built with a different target
9575 flag combination.  This is only useful when the library is intended to
9576 be cross-compiled, and it is almost exclusively used for compiler
9577 support libraries.
9578
9579 The multilib support is still experimental.  Only use it if you are
9580 familiar with multilibs and can debug problems you might encounter.
9581
9582
9583 @node Include
9584 @chapter Include
9585
9586 @cmindex include
9587 @cindex Including @file{Makefile} fragment
9588 @cindex @file{Makefile} fragment, including
9589
9590 Automake supports an @code{include} directive that  can be used to
9591 include other @file{Makefile} fragments when @command{automake} is run.
9592 Note that these fragments are read and interpreted by @command{automake},
9593 not by @command{make}.  As with conditionals, @command{make} has no idea that
9594 @code{include} is in use.
9595
9596 There are two forms of @code{include}:
9597
9598 @table @code
9599 @item include $(srcdir)/file
9600 Include a fragment that is found relative to the current source
9601 directory.
9602
9603 @item include $(top_srcdir)/file
9604 Include a fragment that is found relative to the top source directory.
9605 @end table
9606
9607 Note that if a fragment is included inside a conditional, then the
9608 condition applies to the entire contents of that fragment.
9609
9610 Makefile fragments included this way are always distributed because
9611 they are needed to rebuild @file{Makefile.in}.
9612
9613 @node Conditionals
9614 @chapter Conditionals
9615
9616 @cindex Conditionals
9617
9618 Automake supports a simple type of conditionals.
9619
9620 These conditionals are not the same as conditionals in
9621 GNU Make.  Automake conditionals are checked at configure time by the
9622 @file{configure} script, and affect the translation from
9623 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
9624 to @file{configure} and on results that @file{configure} has discovered
9625 about the host system.  GNU Make conditionals are checked at @command{make}
9626 time, and are based on variables passed to the make program or defined
9627 in the @file{Makefile}.
9628
9629 Automake conditionals will work with any make program.
9630
9631 @menu
9632 * Usage of Conditionals::       Declaring conditional content
9633 * Limits of Conditionals::      Enclosing complete statements
9634 @end menu
9635
9636 @node Usage of Conditionals
9637 @section Usage of Conditionals
9638
9639 @acindex AM_CONDITIONAL
9640 Before using a conditional, you must define it by using
9641 @code{AM_CONDITIONAL} in the @file{configure.ac} file (@pxref{Macros}).
9642
9643 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
9644 The conditional name, @var{conditional}, should be a simple string
9645 starting with a letter and containing only letters, digits, and
9646 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
9647 that are reserved by Automake.
9648
9649 The shell @var{condition} (suitable for use in a shell @code{if}
9650 statement) is evaluated when @command{configure} is run.  Note that you
9651 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
9652 time @command{configure} is run.  If @code{AM_CONDITIONAL} is run
9653 conditionally (e.g., in a shell @code{if} statement), then the result
9654 will confuse @command{automake}.
9655 @end defmac
9656
9657 @cindex @option{--enable-debug}, example
9658 @cindex Example conditional @option{--enable-debug}
9659 @cindex Conditional example, @option{--enable-debug}
9660
9661 Conditionals typically depend upon options that the user provides to
9662 the @command{configure} script.  Here is an example of how to write a
9663 conditional that is true if the user uses the @option{--enable-debug}
9664 option.
9665
9666 @example
9667 AC_ARG_ENABLE([debug],
9668 [  --enable-debug    Turn on debugging],
9669 [case "$@{enableval@}" in
9670   yes) debug=true ;;
9671   no)  debug=false ;;
9672   *) AC_MSG_ERROR([bad value $@{enableval@} for --enable-debug]) ;;
9673 esac],[debug=false])
9674 AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
9675 @end example
9676
9677 Here is an example of how to use that conditional in @file{Makefile.am}:
9678
9679 @cmindex if
9680 @cmindex endif
9681 @cmindex else
9682
9683 @example
9684 if DEBUG
9685 DBG = debug
9686 else
9687 DBG =
9688 endif
9689 noinst_PROGRAMS = $(DBG)
9690 @end example
9691
9692 This trivial example could also be handled using @code{EXTRA_PROGRAMS}
9693 (@pxref{Conditional Programs}).
9694
9695 You may only test a single variable in an @code{if} statement, possibly
9696 negated using @samp{!}.  The @code{else} statement may be omitted.
9697 Conditionals may be nested to any depth.  You may specify an argument to
9698 @code{else} in which case it must be the negation of the condition used
9699 for the current @code{if}.  Similarly you may specify the condition
9700 that is closed on the @code{endif} line:
9701
9702 @example
9703 if DEBUG
9704 DBG = debug
9705 else !DEBUG
9706 DBG =
9707 endif !DEBUG
9708 @end example
9709
9710 @noindent
9711 Unbalanced conditions are errors.  The @code{if}, @code{else}, and
9712 @code{endif} statements should not be indented, i.e., start on column
9713 one.
9714
9715 The @code{else} branch of the above two examples could be omitted,
9716 since assigning the empty string to an otherwise undefined variable
9717 makes no difference.
9718
9719 @acindex AM_COND_IF
9720 In order to allow access to the condition registered by
9721 @code{AM_CONDITIONAL} inside @file{configure.ac}, and to allow
9722 conditional @code{AC_CONFIG_FILES}, @code{AM_COND_IF} may be used:
9723
9724 @defmac AM_COND_IF (@var{conditional}, @ovar{if-true}, @ovar{if-false})
9725 If @var{conditional} is fulfilled, execute @var{if-true}, otherwise
9726 execute @var{if-false}.  If either branch contains @code{AC_CONFIG_FILES},
9727 it will cause @command{automake} to output the rules for the respective
9728 files only for the given condition.
9729 @end defmac
9730
9731 @code{AM_COND_IF} macros may be nested when m4 quotation is used
9732 properly (@pxref{M4 Quotation, ,, autoconf, The Autoconf Manual}).
9733
9734 @cindex Example conditional @code{AC_CONFIG_FILES}
9735 @cindex @code{AC_CONFIG_FILES}, conditional
9736
9737 Here is an example of how to define a conditional config file:
9738
9739 @example
9740 AM_CONDITIONAL([SHELL_WRAPPER], [test "x$with_wrapper" = xtrue])
9741 AM_COND_IF([SHELL_WRAPPER],
9742            [AC_CONFIG_FILES([wrapper:wrapper.in])])
9743 @end example
9744
9745 @node Limits of Conditionals
9746 @section Limits of Conditionals
9747
9748 Conditionals should enclose complete statements like variables or
9749 rules definitions.  Automake cannot deal with conditionals used inside
9750 a variable definition, for instance, and is not even able to diagnose
9751 this situation.  The following example would not work:
9752
9753 @example
9754 # This syntax is not understood by Automake
9755 AM_CPPFLAGS = \
9756   -DFEATURE_A \
9757 if WANT_DEBUG
9758   -DDEBUG \
9759 endif
9760   -DFEATURE_B
9761 @end example
9762
9763 However the intended definition of @code{AM_CPPFLAGS} can be achieved
9764 with
9765
9766 @example
9767 if WANT_DEBUG
9768   DEBUGFLAGS = -DDEBUG
9769 endif
9770 AM_CPPFLAGS = -DFEATURE_A $(DEBUGFLAGS) -DFEATURE_B
9771 @end example
9772
9773 @noindent
9774 or
9775
9776 @example
9777 AM_CPPFLAGS = -DFEATURE_A
9778 if WANT_DEBUG
9779 AM_CPPFLAGS += -DDEBUG
9780 endif
9781 AM_CPPFLAGS += -DFEATURE_B
9782 @end example
9783
9784 More details and examples of conditionals are described alongside
9785 various Automake features in this manual (@pxref{Conditional
9786 Subdirectories}, @pxref{Conditional Sources}, @pxref{Conditional
9787 Programs}, @pxref{Conditional Libtool Libraries}, @pxref{Conditional
9788 Libtool Sources}).
9789
9790 @node Silencing Make
9791 @chapter Silencing @command{make}
9792
9793 @cindex Silent @command{make}
9794 @cindex Silencing @command{make}
9795 @cindex Silent rules
9796 @cindex Silent @command{make} rules
9797
9798 @menu
9799 * Make verbosity::               Make is verbose by default
9800 * Tricks For Silencing Make::    Standard and generic ways to silence make
9801 * Automake silent-rules Option:: How Automake can help in silencing make
9802 @end menu
9803
9804 @node Make verbosity
9805 @section Make is verbose by default
9806
9807 Normally, when executing the set of rules associated with a target,
9808 @command{make} prints each rule before it is executed.  This behaviour,
9809 while having been in place for a long time, and being even mandated by
9810 the POSIX standard, starkly violates the ``silence is golden'' UNIX
9811 principle@footnote{See also
9812 @uref{http://catb.org/~esr/writings/taoup/html/ch11s09.html}.}:
9813
9814 @quotation
9815 When a program has nothing interesting or surprising to say, it should
9816 say nothing.  Well-behaved Unix programs do their jobs unobtrusively,
9817 with a minimum of fuss and bother.  Silence is golden.
9818 @end quotation
9819
9820 In fact, while such verbosity of @command{make} can theoretically be
9821 useful to track bugs and understand reasons of failures right away, it
9822 can also hide warning and error messages from @command{make}-invoked
9823 tools, drowning them in a flood of uninteresting and seldom useful
9824 messages, and thus allowing them to go easily undetected.
9825
9826 This problem can be very annoying, especially for developers, who usually
9827 know quite well what's going on behind the scenes, and for whom the
9828 verbose output from @command{make} ends up being mostly noise that hampers
9829 the easy detection of potentially important warning messages.
9830
9831 @node Tricks For Silencing Make
9832 @section Standard and generic ways to silence make
9833
9834 Here we describe some common idioms/tricks to obtain a quieter make
9835 output, with their relative advantages and drawbacks.  In the next
9836 section (@ref{Automake silent-rules Option}) we'll see how Automake
9837 can help in this respect.
9838
9839 @itemize @bullet
9840
9841 @item @command{make -s}
9842
9843 This simply causes @command{make} not to print @emph{any} rule before
9844 executing it.
9845
9846 The @option{-s} flag is mandated by POSIX, universally supported, and
9847 its purpose and function are easy to understand.
9848
9849 But it also has its serious limitations too.  First of all, it embodies
9850 an ``all or nothing'' strategy, i.e., either everything is silenced, or
9851 nothing is; this lack of granularity can sometimes be a fatal flaw.
9852 Moreover, when the @option{-s} flag is used, the @command{make} output
9853 might turn out to be too much terse; in case of errors, the user won't
9854 be able to easily see what rule or command have caused them, or even,
9855 in case of tools with poor error reporting, what the errors were!
9856
9857 @item @command{make >/dev/null || make}
9858
9859 Apparently, this perfectly obeys the ``silence is golden'' rule: warnings
9860 from stderr are passed through, output reporting is done only in case of
9861 error, and in that case it should provide a verbose-enough report to allow
9862 an easy determination of the error location and causes.
9863
9864 However, calling @command{make} two times in a row might hide errors
9865 (especially intermittent ones), or subtly change the expected semantic
9866 of the @command{make} calls --- things these which can clearly make
9867 debugging and error assessment very difficult.
9868
9869 @item @command{make --no-print-directory}
9870
9871 This is GNU @command{make} specific.  When called with the
9872 @option{--no-print-directory} option, GNU @command{make} will disable
9873 printing of the working directory by invoked sub-@command{make}s (the
9874 well-known ``@i{Entering/Leaving directory ...}'' messages).  This helps
9875 to decrease the verbosity of the output, but experience has shown that
9876 it can also often render debugging considerably harder in projects using
9877 deeply-nested @command{make} recursion.
9878
9879 As an aside, notice that the @option{--no-print-directory} option is
9880 automatically activated if the @option{-s} flag is used.
9881
9882 @c TODO: Other tricks?
9883 @c TODO: Maybe speak about the @code{.SILENT} target?
9884 @c TODO:  - Pros: More granularity on what to silence.
9885 @c TODO:  - Cons: No easy way to temporarily override.
9886
9887 @end itemize
9888
9889 @node Automake silent-rules Option
9890 @section How Automake can help in silencing make
9891
9892 The tricks and idioms for silencing @command{make} described in the
9893 previous section can be useful from time to time, but we've seen that
9894 they all have their serious drawbacks and limitations.  That's why
9895 automake provides support for a more advanced and flexible way of
9896 obtaining quieter output from @command{make}: the @option{silent-rules}
9897 mode.
9898
9899 @c TODO: Maybe describe in brief the precedent set by the build system
9900 @c of the Linux Kernel, from which Automake took inspiration ... Links?
9901
9902 To give the gist of what @option{silent-rules} can do, here is a simple
9903 comparison between a typical @command{make} output (where silent rules
9904 are disabled) and one with silent rules enabled:
9905
9906 @example
9907 % @kbd{cat Makefile.am}
9908 bin_PROGRAMS = foo
9909 foo_SOURCES = main.c func.c
9910 % @kbd{cat main.c}
9911 int main (void) @{ return func (); @}  /* func used undeclared */
9912 % @kbd{cat func.c}
9913 int func (void) @{ int i; return i; @} /* i used uninitialized */
9914
9915 @i{The make output is by default very verbose.  This causes warnings
9916 from the compiler to be somewhat hidden, and not immediate to spot.}
9917 % @kbd{make CFLAGS=-Wall}
9918 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
9919 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
9920 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT main.o
9921 -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
9922 main.c: In function â€˜main’:
9923 main.c:3:3: warning: implicit declaration of function â€˜func’
9924 mv -f .deps/main.Tpo .deps/main.Po
9925 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
9926 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
9927 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT func.o
9928 -MD -MP -MF .deps/func.Tpo -c -o func.o func.c
9929 func.c: In function â€˜func’:
9930 func.c:4:3: warning: â€˜i’ used uninitialized in this function
9931 mv -f .deps/func.Tpo .deps/func.Po
9932 gcc -Wall -o foo main.o func.o
9933
9934 @i{Clean up, so that we we can rebuild everything from scratch.}
9935 % @kbd{make clean}
9936 test -z "foo" || rm -f foo
9937 rm -f *.o
9938
9939 @i{Silent rules enabled: the output is minimal but informative.  In
9940 particular, the warnings from the compiler stick out very clearly.}
9941 % @kbd{make V=0 CFLAGS=-Wall}
9942   CC     main.o
9943 main.c: In function â€˜main’:
9944 main.c:3:3: warning: implicit declaration of function â€˜func’
9945   CC     func.o
9946 func.c: In function â€˜func’:
9947 func.c:4:3: warning: â€˜i’ used uninitialized in this function
9948   CCLD   foo
9949 @end example
9950
9951 @cindex silent-rules and libtool
9952 Also, in projects using @command{libtool}, the use of silent rules can
9953 automatically enable the @command{libtool}'s @option{--silent} option:
9954
9955 @example
9956 % @kbd{cat Makefile.am}
9957 lib_LTLIBRARIES = libx.la
9958
9959 % @kbd{make # Both make and libtool are verbose by default.}
9960 ...
9961 libtool: compile: gcc -DPACKAGE_NAME=\"foo\" ... -DLT_OBJDIR=\".libs/\"
9962   -I. -g -O2 -MT libx.lo -MD -MP -MF .deps/libx.Tpo -c libx.c -fPIC
9963   -DPIC -o .libs/libx.o
9964 mv -f .deps/libx.Tpo .deps/libx.Plo
9965 /bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -o libx.la -rpath
9966   /usr/local/lib libx.lo
9967 libtool: link: gcc -shared .libs/libx.o -Wl,-soname -Wl,libx.so.0
9968   -o .libs/libx.so.0.0.0
9969 libtool: link: cd .libs && rm -f libx.so && ln -s libx.so.0.0.0 libx.so
9970 ...
9971
9972 % @kbd{make V=0}
9973   CC     libx.lo
9974   CCLD   libx.la
9975 @end example
9976
9977 Let's now see how the @option{silent-rules} mode interfaces with the
9978 package developer and the package user.
9979
9980 To enable the use of @option{silent-rules} in his package, a developer
9981 needs to do either of the following:
9982
9983 @itemize @bullet
9984 @item
9985 Add the @option{silent-rules} option as argument to @code{AM_INIT_AUTOMAKE}.
9986 @item
9987 Call the @code{AM_SILENT_RULES} macro from within the @file{configure.ac}
9988 file.
9989 @end itemize
9990
9991 It is not possible to instead specify @option{silent-rules} in a
9992 @file{Makefile.am} file.
9993
9994 If the developer has done either of the above, then the user of the
9995 package may influence the verbosity at @command{configure} run time as
9996 well as at @command{make} run time:
9997
9998 @itemize @bullet
9999 @item
10000 @opindex --enable-silent-rules
10001 @opindex --disable-silent-rules
10002 Passing @option{--enable-silent-rules} to @command{configure} will cause
10003 build rules to be less verbose; the option @option{--disable-silent-rules}
10004 will cause normal verbose output.
10005 @item
10006 @vindex @code{V}
10007 At @command{make} run time, the default chosen at @command{configure}
10008 time may be overridden: @code{make V=1} will produce verbose output,
10009 @code{make V=0} less verbose output.
10010 @end itemize
10011
10012 @cindex default verbosity for silent-rules
10013 Note that silent rules are @emph{disabled} by default; the user must
10014 enable them explicitly at either @command{configure} run time or at
10015 @command{make} run time.  We think that this is a good policy, since
10016 it provides the casual user with enough information to prepare a good
10017 bug report in case anything breaks.
10018
10019 Still, notwithstanding the rationales above, a developer who wants to
10020 make silent rules enabled by default in his own package can do so by
10021 adding a @samp{yes} argument to the @code{AM_SILENT_RULES} call in
10022 @file{configure.ac}.  We advise against this approach, though.
10023
10024 @c Keep in sync with silent-configsite.test
10025 Users who prefer to have silent rules enabled by default can edit their
10026 @file{config.site} file to make the variable @code{enable_silent_rules}
10027 default to @samp{yes}.  This should still allow disabling silent rules
10028 at @command{configure} time and at @command{make} time.
10029
10030 @c FIXME: there's really a need to specify this explicitly?
10031 For portability to different @command{make} implementations, package authors
10032 are advised to not set the variable @code{V} inside the @file{Makefile.am}
10033 file, to allow the user to override the value for subdirectories as well.
10034
10035 The current implementation of this feature relies on a non-POSIX, but in
10036 practice rather widely supported @file{Makefile} construct of nested
10037 variable expansion @samp{$(@var{var1}$(V))}.  Do not use the
10038 @option{silent-rules} option if your package needs to build with
10039 @command{make} implementations that do not support it.  The
10040 @option{silent-rules} option turns off warnings about recursive variable
10041 expansion, which are in turn enabled by @option{-Wportability}
10042 (@pxref{Invoking Automake}).
10043
10044 @vindex @code{AM_V_GEN}
10045 @vindex @code{AM_V_at}
10046 @vindex @code{AM_DEFAULT_VERBOSITY}
10047 To extend the silent mode to your own rules, you have two choices:
10048
10049 @itemize @bullet
10050 @item
10051 You can use the predefined variable @code{AM_V_GEN} as a prefix to
10052 commands that should output a status line in silent mode, and
10053 @code{AM_V_at} as a prefix to commands that should not output anything
10054 in silent mode.  When output is to be verbose, both of these variables
10055 will expand to the empty string.
10056 @item
10057 You can add your own variables, so strings of your own choice are shown.
10058 The following snippet shows how you would define your own equivalent of
10059 @code{AM_V_GEN}:
10060
10061 @example
10062 pkg_verbose = $(pkg_verbose_$(V))
10063 pkg_verbose_ = $(pkg_verbose_$(AM_DEFAULT_VERBOSITY))
10064 pkg_verbose_0 = @@echo PKG-GEN $@@;
10065
10066 foo: foo.in
10067         $(pkg_verbose)cp $(srcdir)/foo.in $@@
10068 @end example
10069
10070 @end itemize
10071
10072 As a final note, observe that, even when silent rules are enabled,
10073 the @option{--no-print-directory} option is still required with GNU
10074 @command{make} if the ``@i{Entering/Leaving directory ...}'' messages
10075 are to be disabled.
10076
10077 @node Gnits
10078 @chapter The effect of @option{--gnu} and @option{--gnits}
10079
10080 @cindex @option{--gnu}, required files
10081 @cindex @option{--gnu}, complete description
10082
10083 The @option{--gnu} option (or @option{gnu} in the
10084 @code{AUTOMAKE_OPTIONS} variable) causes @command{automake} to check
10085 the following:
10086
10087 @itemize @bullet
10088 @item
10089 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
10090 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
10091 or @file{COPYING}, are required at the topmost directory of the package.
10092
10093 If the @option{--add-missing} option is given, @command{automake} will
10094 add a generic version of the @file{INSTALL} file as well as the
10095 @file{COPYING} file containing the text of the current version of the
10096 GNU General Public License existing at the time of this Automake release
10097 (version 3 as this is written, @uref{http://www.gnu.org/@/copyleft/@/gpl.html}).
10098 However, an existing @file{COPYING} file will never be overwritten by
10099 @command{automake}.
10100
10101 @item
10102 The options @option{no-installman} and @option{no-installinfo} are
10103 prohibited.
10104 @end itemize
10105
10106 Note that this option will be extended in the future to do even more
10107 checking; it is advisable to be familiar with the precise requirements
10108 of the GNU standards.  Also, @option{--gnu} can require certain
10109 non-standard GNU programs to exist for use by various maintainer-only
10110 rules; for instance, in the future @command{pathchk} might be required for
10111 @samp{make dist}.
10112
10113 @cindex @option{--gnits}, complete description
10114
10115 The @option{--gnits} option does everything that @option{--gnu} does, and
10116 checks the following as well:
10117
10118 @itemize @bullet
10119 @item
10120 @samp{make installcheck} will check to make sure that the @option{--help}
10121 and @option{--version} really print a usage message and a version string,
10122 respectively.  This is the @option{std-options} option (@pxref{Options}).
10123
10124 @item
10125 @samp{make dist} will check to make sure the @file{NEWS} file has been
10126 updated to the current version.
10127
10128 @item
10129 @code{VERSION} is checked to make sure its format complies with Gnits
10130 standards.
10131 @c FIXME xref when standards are finished
10132
10133 @item
10134 @cindex @file{README-alpha}
10135 If @code{VERSION} indicates that this is an alpha release, and the file
10136 @file{README-alpha} appears in the topmost directory of a package, then
10137 it is included in the distribution.  This is done in @option{--gnits}
10138 mode, and no other, because this mode is the only one where version
10139 number formats are constrained, and hence the only mode where Automake
10140 can automatically determine whether @file{README-alpha} should be
10141 included.
10142
10143 @item
10144 The file @file{THANKS} is required.
10145 @end itemize
10146
10147
10148 @node Cygnus
10149 @chapter The effect of @option{--cygnus}
10150
10151 @cindex @option{cygnus} strictness
10152
10153 Some packages, notably GNU GCC and GNU gdb, have a build environment
10154 originally written at Cygnus Support (subsequently renamed Cygnus
10155 Solutions, and then later purchased by Red Hat).  Packages with this
10156 ancestry are sometimes referred to as ``Cygnus'' trees.
10157
10158 A Cygnus tree has slightly different rules for how a
10159 @file{Makefile.in} is to be constructed.  Passing @option{--cygnus} to
10160 @command{automake} will cause any generated @file{Makefile.in} to
10161 comply with Cygnus rules.
10162
10163 Here are the precise effects of @option{--cygnus}:
10164
10165 @itemize @bullet
10166 @item
10167 Info files are always created in the build directory, and not in the
10168 source directory.
10169
10170 @item
10171 @file{texinfo.tex} is not required if a Texinfo source file is
10172 specified.  The assumption is that the file will be supplied, but in a
10173 place that Automake cannot find.  This assumption is an artifact of how
10174 Cygnus packages are typically bundled.
10175
10176 @item
10177 @samp{make dist} is not supported, and the rules for it are not
10178 generated.  Cygnus-style trees use their own distribution mechanism.
10179
10180 @item
10181 Certain tools will be searched for in the build tree as well as in the
10182 user's @env{PATH}.  These tools are @command{runtest}, @command{expect},
10183 @command{makeinfo} and @command{texi2dvi}.
10184
10185 @item
10186 @option{--foreign} is implied.
10187
10188 @item
10189 The options @option{no-installinfo} and @option{no-dependencies} are
10190 implied.
10191
10192 @item
10193 The macro @code{AM_MAINTAINER_MODE} is required.
10194
10195 @item
10196 The @code{check} target doesn't depend on @code{all}.
10197 @end itemize
10198
10199 GNU maintainers are advised to use @option{gnu} strictness in preference
10200 to the special Cygnus mode.  Some day, perhaps, the differences between
10201 Cygnus trees and GNU trees will disappear (for instance, as GCC is made
10202 more standards compliant).  At that time the special Cygnus mode will be
10203 removed.
10204
10205
10206 @node Not Enough
10207 @chapter When Automake Isn't Enough
10208
10209 In some situations, where Automake is not up to one task, one has to
10210 resort to handwritten rules or even handwritten @file{Makefile}s.
10211
10212 @menu
10213 * Extending::                   Adding new rules or overriding existing ones.
10214 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
10215 @end menu
10216
10217 @node Extending
10218 @section Extending Automake Rules
10219
10220 With some minor exceptions (for example @code{_PROGRAMS} variables,
10221 @code{TESTS}, or @code{XFAIL_TESTS}) being rewritten to append
10222 @samp{$(EXEEXT)}), the contents of a @file{Makefile.am} is copied to
10223 @file{Makefile.in} verbatim.
10224
10225 @cindex copying semantics
10226
10227 These copying semantics mean that many problems can be worked around
10228 by simply adding some @command{make} variables and rules to
10229 @file{Makefile.am}.  Automake will ignore these additions.
10230
10231 @cindex conflicting definitions
10232 @cindex rules, conflicting
10233 @cindex variables, conflicting
10234 @cindex definitions, conflicts
10235
10236 Since a @file{Makefile.in} is built from data gathered from three
10237 different places (@file{Makefile.am}, @file{configure.ac}, and
10238 @command{automake} itself), it is possible to have conflicting
10239 definitions of rules or variables.  When building @file{Makefile.in}
10240 the following priorities are respected by @command{automake} to ensure
10241 the user always has the last word:
10242
10243 @itemize
10244 @item
10245 User defined variables in @file{Makefile.am} have priority over
10246 variables @code{AC_SUBST}ed from @file{configure.ac}, and
10247 @code{AC_SUBST}ed variables have priority over
10248 @command{automake}-defined variables.
10249 @item
10250 As far as rules are concerned, a user-defined rule overrides any
10251 @command{automake}-defined rule for the same target.
10252 @end itemize
10253
10254 @cindex overriding rules
10255 @cindex overriding semantics
10256 @cindex rules, overriding
10257
10258 These overriding semantics make it possible to fine tune some default
10259 settings of Automake, or replace some of its rules.  Overriding
10260 Automake rules is often inadvisable, particularly in the topmost
10261 directory of a package with subdirectories.  The @option{-Woverride}
10262 option (@pxref{Invoking Automake}) comes in handy to catch overridden
10263 definitions.
10264
10265 Note that Automake does not make any distinction between rules with
10266 commands and rules that only specify dependencies.  So it is not
10267 possible to append new dependencies to an @command{automake}-defined
10268 target without redefining the entire rule.
10269
10270 @cindex @option{-local} targets
10271 @cindex local targets
10272
10273 However, various useful targets have a @samp{-local} version you can
10274 specify in your @file{Makefile.am}.  Automake will supplement the
10275 standard target with these user-supplied targets.
10276
10277 @trindex  all
10278 @trindex  all-local
10279 @trindex  info
10280 @trindex  info-local
10281 @trindex  dvi
10282 @trindex  dvi-local
10283 @trindex  ps
10284 @trindex  ps-local
10285 @trindex  pdf
10286 @trindex  pdf-local
10287 @trindex  html
10288 @trindex  html-local
10289 @trindex  check
10290 @trindex  check-local
10291 @trindex  install
10292 @trindex  install-data
10293 @trindex  install-data-local
10294 @trindex  install-dvi
10295 @trindex  install-dvi-local
10296 @trindex  install-exec
10297 @trindex  install-exec-local
10298 @trindex  install-html
10299 @trindex  install-html-local
10300 @trindex  install-info
10301 @trindex  install-info-local
10302 @trindex  install-pdf
10303 @trindex  install-pdf-local
10304 @trindex  install-ps
10305 @trindex  install-ps-local
10306 @trindex  uninstall
10307 @trindex  uninstall-local
10308 @trindex  mostlyclean
10309 @trindex  mostlyclean-local
10310 @trindex  clean
10311 @trindex  clean-local
10312 @trindex  distclean
10313 @trindex  distclean-local
10314 @trindex  installdirs
10315 @trindex  installdirs-local
10316 @trindex  installcheck
10317 @trindex  installcheck-local
10318
10319 The targets that support a local version are @code{all}, @code{info},
10320 @code{dvi}, @code{ps}, @code{pdf}, @code{html}, @code{check},
10321 @code{install-data}, @code{install-dvi}, @code{install-exec},
10322 @code{install-html}, @code{install-info}, @code{install-pdf},
10323 @code{install-ps}, @code{uninstall}, @code{installdirs},
10324 @code{installcheck} and the various @code{clean} targets
10325 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
10326 @code{maintainer-clean}).
10327
10328 Note that there are no @code{uninstall-exec-local} or
10329 @code{uninstall-data-local} targets; just use @code{uninstall-local}.
10330 It doesn't make sense to uninstall just data or just executables.
10331
10332 For instance, here is one way to erase a subdirectory during
10333 @samp{make clean} (@pxref{Clean}).
10334
10335 @example
10336 clean-local:
10337         -rm -rf testSubDir
10338 @end example
10339
10340 You may be tempted to use @code{install-data-local} to install a file
10341 to some hard-coded location, but you should avoid this
10342 (@pxref{Hard-Coded Install Paths}).
10343
10344 With the @code{-local} targets, there is no particular guarantee of
10345 execution order; typically, they are run early, but with parallel
10346 make, there is no way to be sure of that.
10347
10348 @cindex @option{-hook} targets
10349 @cindex hook targets
10350 @trindex install-data-hook
10351 @trindex install-exec-hook
10352 @trindex uninstall-hook
10353 @trindex dist-hook
10354
10355 In contrast, some rules also have a way to run another rule, called a
10356 @dfn{hook}; hooks are always executed after the main rule's work is done.
10357 The hook is named after the principal target, with @samp{-hook} appended.
10358 The targets allowing hooks are @code{install-data},
10359 @code{install-exec}, @code{uninstall}, @code{dist}, and
10360 @code{distcheck}.
10361
10362 For instance, here is how to create a hard link to an installed program:
10363
10364 @example
10365 install-exec-hook:
10366         ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
10367            $(DESTDIR)$(bindir)/proglink$(EXEEXT)
10368 @end example
10369
10370 Although cheaper and more portable than symbolic links, hard links
10371 will not work everywhere (for instance, OS/2 does not have
10372 @command{ln}).  Ideally you should fall back to @samp{cp -p} when
10373 @command{ln} does not work.  An easy way, if symbolic links are
10374 acceptable to you, is to add @code{AC_PROG_LN_S} to
10375 @file{configure.ac} (@pxref{Particular Programs, , Particular Program
10376 Checks, autoconf, The Autoconf Manual}) and use @samp{$(LN_S)} in
10377 @file{Makefile.am}.
10378
10379 @cindex versioned binaries, installing
10380 @cindex installing versioned binaries
10381 @cindex @code{LN_S} example
10382 For instance, here is how you could install a versioned copy of a
10383 program using @samp{$(LN_S)}:
10384
10385 @c Keep in sync with insthook.test
10386 @example
10387 install-exec-hook:
10388         cd $(DESTDIR)$(bindir) && \
10389           mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
10390           $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
10391 @end example
10392
10393 Note that we rename the program so that a new version will erase the
10394 symbolic link, not the real binary.  Also we @command{cd} into the
10395 destination directory in order to create relative links.
10396
10397 When writing @code{install-exec-hook} or @code{install-data-hook},
10398 please bear in mind that the exec/data distinction is based on the
10399 installation directory, not on the primary used (@pxref{The Two Parts of
10400 Install}).
10401 @c Keep in sync with primary-prefix-couples-documented-valid.test.
10402 So a @code{foo_SCRIPTS} will be installed by
10403 @code{install-data}, and a @code{barexec_SCRIPTS} will be installed by
10404 @code{install-exec}.  You should define your hooks consequently.
10405
10406 @c FIXME should include discussion of variables you can use in these
10407 @c rules
10408
10409 @node Third-Party Makefiles
10410 @section Third-Party @file{Makefile}s
10411
10412 @cindex Third-party packages, interfacing with
10413 @cindex Interfacing with third-party packages
10414
10415 In most projects all @file{Makefile}s are generated by Automake.  In
10416 some cases, however, projects need to embed subdirectories with
10417 handwritten @file{Makefile}s.  For instance, one subdirectory could be
10418 a third-party project with its own build system, not using Automake.
10419
10420 It is possible to list arbitrary directories in @code{SUBDIRS} or
10421 @code{DIST_SUBDIRS} provided each of these directories has a
10422 @file{Makefile} that recognizes all the following recursive targets.
10423
10424 @cindex recursive targets and third-party @file{Makefile}s
10425 When a user runs one of these targets, that target is run recursively
10426 in all subdirectories.  This is why it is important that even
10427 third-party @file{Makefile}s support them.
10428
10429 @table @code
10430 @item all
10431 Compile the entire package.  This is the default target in
10432 Automake-generated @file{Makefile}s, but it does not need to be the
10433 default in third-party @file{Makefile}s.
10434
10435 @item distdir
10436 @trindex distdir
10437 @vindex distdir
10438 @vindex top_distdir
10439 Copy files to distribute into @samp{$(distdir)}, before a tarball is
10440 constructed.  Of course this target is not required if the
10441 @option{no-dist} option (@pxref{Options}) is used.
10442
10443 The variables @samp{$(top_distdir)} and @samp{$(distdir)}
10444 (@pxref{The dist Hook}) will be passed from the outer package to the subpackage
10445 when the @code{distdir} target is invoked.  These two variables have
10446 been adjusted for the directory that is being recursed into, so they
10447 are ready to use.
10448
10449 @item install
10450 @itemx install-data
10451 @itemx install-exec
10452 @itemx uninstall
10453 Install or uninstall files (@pxref{Install}).
10454
10455 @item install-dvi
10456 @itemx install-html
10457 @itemx install-info
10458 @itemx install-ps
10459 @itemx install-pdf
10460 Install only some specific documentation format (@pxref{Texinfo}).
10461
10462 @item installdirs
10463 Create install directories, but do not install any files.
10464
10465 @item check
10466 @itemx installcheck
10467 Check the package (@pxref{Tests}).
10468
10469 @item mostlyclean
10470 @itemx clean
10471 @itemx distclean
10472 @itemx maintainer-clean
10473 Cleaning rules (@pxref{Clean}).
10474
10475 @item dvi
10476 @itemx pdf
10477 @itemx ps
10478 @itemx info
10479 @itemx html
10480 Build the documentation in various formats (@pxref{Texinfo}).
10481
10482 @item tags
10483 @itemx ctags
10484 Build @file{TAGS} and @file{CTAGS} (@pxref{Tags}).
10485 @end table
10486
10487 If you have ever used Gettext in a project, this is a good example of
10488 how third-party @file{Makefile}s can be used with Automake.  The
10489 @file{Makefile}s @command{gettextize} puts in the @file{po/} and
10490 @file{intl/} directories are handwritten @file{Makefile}s that
10491 implement all these targets.  That way they can be added to
10492 @code{SUBDIRS} in Automake packages.
10493
10494 Directories that are only listed in @code{DIST_SUBDIRS} but not in
10495 @code{SUBDIRS} need only the @code{distclean},
10496 @code{maintainer-clean}, and @code{distdir} rules (@pxref{Conditional
10497 Subdirectories}).
10498
10499 Usually, many of these rules are irrelevant to the third-party
10500 subproject, but they are required for the whole package to work.  It's
10501 OK to have a rule that does nothing, so if you are integrating a
10502 third-party project with no documentation or tag support, you could
10503 simply augment its @file{Makefile} as follows:
10504
10505 @example
10506 EMPTY_AUTOMAKE_TARGETS = dvi pdf ps info html tags ctags
10507 .PHONY: $(EMPTY_AUTOMAKE_TARGETS)
10508 $(EMPTY_AUTOMAKE_TARGETS):
10509 @end example
10510
10511 Another aspect of integrating third-party build systems is whether
10512 they support VPATH builds (@pxref{VPATH Builds}).  Obviously if the
10513 subpackage does not support VPATH builds the whole package will not
10514 support VPATH builds.  This in turns means that @samp{make distcheck}
10515 will not work, because it relies on VPATH builds.  Some people can
10516 live without this (actually, many Automake users have never heard of
10517 @samp{make distcheck}).  Other people may prefer to revamp the
10518 existing @file{Makefile}s to support VPATH@.  Doing so does not
10519 necessarily require Automake, only Autoconf is needed (@pxref{Build
10520 Directories, , Build Directories, autoconf, The Autoconf Manual}).
10521 The necessary substitutions: @samp{@@srcdir@@}, @samp{@@top_srcdir@@},
10522 and @samp{@@top_builddir@@} are defined by @file{configure} when it
10523 processes a @file{Makefile} (@pxref{Preset Output Variables, , Preset
10524 Output Variables, autoconf, The Autoconf Manual}), they are not
10525 computed by the Makefile like the aforementioned @samp{$(distdir)} and
10526 @samp{$(top_distdir)} variables.
10527
10528 It is sometimes inconvenient to modify a third-party @file{Makefile}
10529 to introduce the above required targets.  For instance, one may want to
10530 keep the third-party sources untouched to ease upgrades to new
10531 versions.
10532
10533 @cindex @file{GNUmakefile} including @file{Makefile}
10534 Here are two other ideas.  If GNU make is assumed, one possibility is
10535 to add to that subdirectory a @file{GNUmakefile} that defines the
10536 required targets and includes the third-party @file{Makefile}.  For
10537 this to work in VPATH builds, @file{GNUmakefile} must lie in the build
10538 directory; the easiest way to do this is to write a
10539 @file{GNUmakefile.in} instead, and have it processed with
10540 @code{AC_CONFIG_FILES} from the outer package.  For example if we
10541 assume @file{Makefile} defines all targets except the documentation
10542 targets, and that the @code{check} target is actually called
10543 @code{test}, we could write @file{GNUmakefile} (or
10544 @file{GNUmakefile.in}) like this:
10545
10546 @example
10547 # First, include the real Makefile
10548 include Makefile
10549 # Then, define the other targets needed by Automake Makefiles.
10550 .PHONY: dvi pdf ps info html check
10551 dvi pdf ps info html:
10552 check: test
10553 @end example
10554
10555 @cindex Proxy @file{Makefile} for third-party packages
10556 A similar idea that does not use @code{include} is to write a proxy
10557 @file{Makefile} that dispatches rules to the real @file{Makefile},
10558 either with @samp{$(MAKE) -f Makefile.real $(AM_MAKEFLAGS) target} (if
10559 it's OK to rename the original @file{Makefile}) or with @samp{cd
10560 subdir && $(MAKE) $(AM_MAKEFLAGS) target} (if it's OK to store the
10561 subdirectory project one directory deeper).  The good news is that
10562 this proxy @file{Makefile} can be generated with Automake.  All we
10563 need are @option{-local} targets (@pxref{Extending}) that perform the
10564 dispatch.  Of course the other Automake features are available, so you
10565 could decide to let Automake perform distribution or installation.
10566 Here is a possible @file{Makefile.am}:
10567
10568 @example
10569 all-local:
10570         cd subdir && $(MAKE) $(AM_MAKEFLAGS) all
10571 check-local:
10572         cd subdir && $(MAKE) $(AM_MAKEFLAGS) test
10573 clean-local:
10574         cd subdir && $(MAKE) $(AM_MAKEFLAGS) clean
10575
10576 # Assuming the package knows how to install itself
10577 install-data-local:
10578         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-data
10579 install-exec-local:
10580         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-exec
10581 uninstall-local:
10582         cd subdir && $(MAKE) $(AM_MAKEFLAGS) uninstall
10583
10584 # Distribute files from here.
10585 EXTRA_DIST = subdir/Makefile subdir/program.c ...
10586 @end example
10587
10588 Pushing this idea to the extreme, it is also possible to ignore the
10589 subproject build system and build everything from this proxy
10590 @file{Makefile.am}.  This might sound very sensible if you need VPATH
10591 builds but the subproject does not support them.
10592
10593 @node Distributing
10594 @chapter Distributing @file{Makefile.in}s
10595
10596 Automake places no restrictions on the distribution of the resulting
10597 @file{Makefile.in}s.  We still encourage software authors to
10598 distribute their work under terms like those of the GPL, but doing so
10599 is not required to use Automake.
10600
10601 Some of the files that can be automatically installed via the
10602 @option{--add-missing} switch do fall under the GPL@.  However, these also
10603 have a special exception allowing you to distribute them with your
10604 package, regardless of the licensing you choose.
10605
10606
10607 @node API Versioning
10608 @chapter Automake API Versioning
10609
10610 New Automake releases usually include bug fixes and new features.
10611 Unfortunately they may also introduce new bugs and incompatibilities.
10612 This makes four reasons why a package may require a particular Automake
10613 version.
10614
10615 Things get worse when maintaining a large tree of packages, each one
10616 requiring a different version of Automake.  In the past, this meant that
10617 any developer (and sometimes users) had to install several versions of
10618 Automake in different places, and switch @samp{$PATH} appropriately for
10619 each package.
10620
10621 Starting with version 1.6, Automake installs versioned binaries.  This
10622 means you can install several versions of Automake in the same
10623 @samp{$prefix}, and can select an arbitrary Automake version by running
10624 @command{automake-1.6} or @command{automake-1.7} without juggling with
10625 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
10626 will use @command{automake-1.6} explicitly in their rebuild rules.
10627
10628 The number @samp{1.6} in @command{automake-1.6} is Automake's API version,
10629 not Automake's version.  If a bug fix release is made, for instance
10630 Automake 1.6.1, the API version will remain 1.6.  This means that a
10631 package that works with Automake 1.6 should also work with 1.6.1; after
10632 all, this is what people expect from bug fix releases.
10633
10634 If your package relies on a feature or a bug fix introduced in
10635 a release, you can pass this version as an option to Automake to ensure
10636 older releases will not be used.  For instance, use this in your
10637 @file{configure.ac}:
10638
10639 @example
10640   AM_INIT_AUTOMAKE([1.6.1])    dnl Require Automake 1.6.1 or better.
10641 @end example
10642
10643 @noindent
10644 or, in a particular @file{Makefile.am}:
10645
10646 @example
10647   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
10648 @end example
10649
10650 @noindent
10651 Automake will print an error message if its version is
10652 older than the requested version.
10653
10654
10655 @heading What is in the API
10656
10657 Automake's programming interface is not easy to define.  Basically it
10658 should include at least all @strong{documented} variables and targets
10659 that a @file{Makefile.am} author can use, any behavior associated with
10660 them (e.g., the places where @samp{-hook}'s are run), the command line
10661 interface of @command{automake} and @command{aclocal}, @dots{}
10662
10663 @heading What is not in the API
10664
10665 Every undocumented variable, target, or command line option, is not part
10666 of the API@.  You should avoid using them, as they could change from one
10667 version to the other (even in bug fix releases, if this helps to fix a
10668 bug).
10669
10670 If it turns out you need to use such an undocumented feature, contact
10671 @email{automake@@gnu.org} and try to get it documented and exercised by
10672 the test-suite.
10673
10674 @node Upgrading
10675 @chapter Upgrading a Package to a Newer Automake Version
10676
10677 Automake maintains three kind of files in a package.
10678
10679 @itemize
10680 @item @file{aclocal.m4}
10681 @item @file{Makefile.in}s
10682 @item auxiliary tools like @file{install-sh} or @file{py-compile}
10683 @end itemize
10684
10685 @file{aclocal.m4} is generated by @command{aclocal} and contains some
10686 Automake-supplied M4 macros.  Auxiliary tools are installed by
10687 @samp{automake --add-missing} when needed.  @file{Makefile.in}s are
10688 built from @file{Makefile.am} by @command{automake}, and rely on the
10689 definitions of the M4 macros put in @file{aclocal.m4} as well as the
10690 behavior of the auxiliary tools installed.
10691
10692 Because all these files are closely related, it is important to
10693 regenerate all of them when upgrading to a newer Automake release.
10694 The usual way to do that is
10695
10696 @example
10697 aclocal # with any option needed (such a -I m4)
10698 autoconf
10699 automake --add-missing --force-missing
10700 @end example
10701
10702 @noindent
10703 or more conveniently:
10704
10705 @example
10706 autoreconf -vfi
10707 @end example
10708
10709 The use of @option{--force-missing} ensures that auxiliary tools will be
10710 overridden by new versions (@pxref{Invoking Automake}).
10711
10712 It is important to regenerate all these files each time Automake is
10713 upgraded, even between bug fixes releases.  For instance, it is not
10714 unusual for a bug fix to involve changes to both the rules generated
10715 in @file{Makefile.in} and the supporting M4 macros copied to
10716 @file{aclocal.m4}.
10717
10718 Presently @command{automake} is able to diagnose situations where
10719 @file{aclocal.m4} has been generated with another version of
10720 @command{aclocal}.  However it never checks whether auxiliary scripts
10721 are up-to-date.  In other words, @command{automake} will tell you when
10722 @command{aclocal} needs to be rerun, but it will never diagnose a
10723 missing @option{--force-missing}.
10724
10725 Before upgrading to a new major release, it is a good idea to read the
10726 file @file{NEWS}.  This file lists all changes between releases: new
10727 features, obsolete constructs, known incompatibilities, and
10728 workarounds.
10729
10730 @node FAQ
10731 @chapter Frequently Asked Questions about Automake
10732
10733 This chapter covers some questions that often come up on the mailing
10734 lists.
10735
10736 @menu
10737 * CVS::                         CVS and generated files
10738 * maintainer-mode::             missing and AM_MAINTAINER_MODE
10739 * Wildcards::                   Why doesn't Automake support wildcards?
10740 * Limitations on File Names::   Limitations on source and installed file names
10741 * distcleancheck::              Files left in build directory after distclean
10742 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
10743 * Renamed Objects::             Why are object files sometimes renamed?
10744 * Per-Object Flags::            How to simulate per-object flags?
10745 * Multiple Outputs::            Writing rules for tools with many output files
10746 * Hard-Coded Install Paths::    Installing to hard-coded locations
10747 * Debugging Make Rules::        Strategies when things don't work as expected
10748 * Reporting Bugs::              Feedback on bugs and feature requests
10749 @end menu
10750
10751 @node CVS
10752 @section CVS and generated files
10753
10754 @subheading Background: distributed generated Files
10755 @cindex generated files, distributed
10756 @cindex rebuild rules
10757
10758 Packages made with Autoconf and Automake ship with some generated
10759 files like @file{configure} or @file{Makefile.in}.  These files were
10760 generated on the developer's host and are distributed so that
10761 end-users do not have to install the maintainer tools required to
10762 rebuild them.  Other generated files like Lex scanners, Yacc parsers,
10763 or Info documentation, are usually distributed on similar grounds.
10764
10765 Automake outputs rules in @file{Makefile}s to rebuild these files.  For
10766 instance, @command{make} will run @command{autoconf} to rebuild
10767 @file{configure} whenever @file{configure.ac} is changed.  This makes
10768 development safer by ensuring a @file{configure} is never out-of-date
10769 with respect to @file{configure.ac}.
10770
10771 As generated files shipped in packages are up-to-date, and because
10772 @command{tar} preserves times-tamps, these rebuild rules are not
10773 triggered when a user unpacks and builds a package.
10774
10775 @subheading Background: CVS and Timestamps
10776 @cindex timestamps and CVS
10777 @cindex CVS and timestamps
10778
10779 Unless you use CVS keywords (in which case files must be updated at
10780 commit time), CVS preserves timestamp during @samp{cvs commit} and
10781 @samp{cvs import -d} operations.
10782
10783 When you check out a file using @samp{cvs checkout} its timestamp is
10784 set to that of the revision that is being checked out.
10785
10786 However, during @command{cvs update}, files will have the date of the
10787 update, not the original timestamp of this revision.  This is meant to
10788 make sure that @command{make} notices sources files have been updated.
10789
10790 This timestamp shift is troublesome when both sources and generated
10791 files are kept under CVS@.  Because CVS processes files in lexical
10792 order, @file{configure.ac} will appear newer than @file{configure}
10793 after a @command{cvs update} that updates both files, even if
10794 @file{configure} was newer than @file{configure.ac} when it was
10795 checked in.  Calling @command{make} will then trigger a spurious rebuild
10796 of @file{configure}.
10797
10798 @subheading Living with CVS in Autoconfiscated Projects
10799 @cindex CVS and generated files
10800 @cindex generated files and CVS
10801
10802 There are basically two clans amongst maintainers: those who keep all
10803 distributed files under CVS, including generated files, and those who
10804 keep generated files @emph{out} of CVS.
10805
10806 @subsubheading All Files in CVS
10807
10808 @itemize @bullet
10809 @item
10810 The CVS repository contains all distributed files so you know exactly
10811 what is distributed, and you can checkout any prior version entirely.
10812
10813 @item
10814 Maintainers can see how generated files evolve (for instance, you can
10815 see what happens to your @file{Makefile.in}s when you upgrade Automake
10816 and make sure they look OK).
10817
10818 @item
10819 Users do not need the autotools to build a checkout of the project, it
10820 works just like a released tarball.
10821
10822 @item
10823 If users use @command{cvs update} to update their copy, instead of
10824 @command{cvs checkout} to fetch a fresh one, timestamps will be
10825 inaccurate.  Some rebuild rules will be triggered and attempt to
10826 run developer tools such as @command{autoconf} or @command{automake}.
10827
10828 Actually, calls to such tools are all wrapped into a call to the
10829 @command{missing} script discussed later (@pxref{maintainer-mode}).
10830 @command{missing} will take care of fixing the timestamps when these
10831 tools are not installed, so that the build can continue.
10832
10833 @item
10834 In distributed development, developers are likely to have different
10835 version of the maintainer tools installed.  In this case rebuilds
10836 triggered by timestamp lossage will lead to spurious changes
10837 to generated files.  There are several solutions to this:
10838
10839 @itemize
10840 @item
10841 All developers should use the same versions, so that the rebuilt files
10842 are identical to files in CVS@.  (This starts to be difficult when each
10843 project you work on uses different versions.)
10844 @item
10845 Or people use a script to fix the timestamp after a checkout (the GCC
10846 folks have such a script).
10847 @item
10848 Or @file{configure.ac} uses @code{AM_MAINTAINER_MODE}, which will
10849 disable all these rebuild rules by default.  This is further discussed
10850 in @ref{maintainer-mode}.
10851 @end itemize
10852
10853 @item
10854 Although we focused on spurious rebuilds, the converse can also
10855 happen.  CVS's timestamp handling can also let you think an
10856 out-of-date file is up-to-date.
10857
10858 For instance, suppose a developer has modified @file{Makefile.am} and
10859 has rebuilt @file{Makefile.in}, and then decides to do a last-minute
10860 change to @file{Makefile.am} right before checking in both files
10861 (without rebuilding @file{Makefile.in} to account for the change).
10862
10863 This last change to @file{Makefile.am} makes the copy of
10864 @file{Makefile.in} out-of-date.  Since CVS processes files
10865 alphabetically, when another developer @samp{cvs update}s his or her
10866 tree, @file{Makefile.in} will happen to be newer than
10867 @file{Makefile.am}.  This other developer will not see that
10868 @file{Makefile.in} is out-of-date.
10869
10870 @end itemize
10871
10872 @subsubheading Generated Files out of CVS
10873
10874 One way to get CVS and @command{make} working peacefully is to never
10875 store generated files in CVS, i.e., do not CVS-control files that
10876 are @file{Makefile} targets (also called @emph{derived} files).
10877
10878 This way developers are not annoyed by changes to generated files.  It
10879 does not matter if they all have different versions (assuming they are
10880 compatible, of course).  And finally, timestamps are not lost, changes
10881 to sources files can't be missed as in the
10882 @file{Makefile.am}/@file{Makefile.in} example discussed earlier.
10883
10884 The drawback is that the CVS repository is not an exact copy of what
10885 is distributed and that users now need to install various development
10886 tools (maybe even specific versions) before they can build a checkout.
10887 But, after all, CVS's job is versioning, not distribution.
10888
10889 Allowing developers to use different versions of their tools can also
10890 hide bugs during distributed development.  Indeed, developers will be
10891 using (hence testing) their own generated files, instead of the
10892 generated files that will be released actually.  The developer who
10893 prepares the tarball might be using a version of the tool that
10894 produces bogus output (for instance a non-portable C file), something
10895 other developers could have noticed if they weren't using their own
10896 versions of this tool.
10897
10898 @subheading Third-party Files
10899 @cindex CVS and third-party files
10900 @cindex third-party files and CVS
10901
10902 Another class of files not discussed here (because they do not cause
10903 timestamp issues) are files that are shipped with a package, but
10904 maintained elsewhere.  For instance, tools like @command{gettextize}
10905 and @command{autopoint} (from Gettext) or @command{libtoolize} (from
10906 Libtool), will install or update files in your package.
10907
10908 These files, whether they are kept under CVS or not, raise similar
10909 concerns about version mismatch between developers' tools.  The
10910 Gettext manual has a section about this, see @ref{CVS Issues, CVS
10911 Issues, Integrating with CVS, gettext, GNU gettext tools}.
10912
10913 @node maintainer-mode
10914 @section @command{missing} and @code{AM_MAINTAINER_MODE}
10915
10916 @subheading @command{missing}
10917 @cindex @command{missing}, purpose
10918
10919 The @command{missing} script is a wrapper around several maintainer
10920 tools, designed to warn users if a maintainer tool is required but
10921 missing.  Typical maintainer tools are @command{autoconf},
10922 @command{automake}, @command{bison}, etc.  Because file generated by
10923 these tools are shipped with the other sources of a package, these
10924 tools shouldn't be required during a user build and they are not
10925 checked for in @file{configure}.
10926
10927 However, if for some reason a rebuild rule is triggered and involves a
10928 missing tool, @command{missing} will notice it and warn the user.
10929 Besides the warning, when a tool is missing, @command{missing} will
10930 attempt to fix timestamps in a way that allows the build to continue.
10931 For instance, @command{missing} will touch @file{configure} if
10932 @command{autoconf} is not installed.  When all distributed files are
10933 kept under version control, this feature of @command{missing} allows a
10934 user @emph{with no maintainer tools} to build a package off its version
10935 control repository, bypassing any timestamp inconsistency (implied by
10936 e.g.@: @samp{cvs update} or @samp{git clone}).
10937
10938 If the required tool is installed, @command{missing} will run it and
10939 won't attempt to continue after failures.  This is correct during
10940 development: developers love fixing failures.  However, users with
10941 wrong versions of maintainer tools may get an error when the rebuild
10942 rule is spuriously triggered, halting the build.  This failure to let
10943 the build continue is one of the arguments of the
10944 @code{AM_MAINTAINER_MODE} advocates.
10945
10946 @subheading @code{AM_MAINTAINER_MODE}
10947 @cindex @code{AM_MAINTAINER_MODE}, purpose
10948 @acindex AM_MAINTAINER_MODE
10949
10950 @code{AM_MAINTAINER_MODE} allows you to choose whether the so called
10951 "rebuild rules" should be enabled or disabled.  With
10952 @code{AM_MAINTAINER_MODE([enable])}, they are enabled by default,
10953 otherwise they are disabled by default.  In the latter case, if
10954 you have @code{AM_MAINTAINER_MODE} in @file{configure.ac}, and run
10955 @samp{./configure && make}, then @command{make} will *never* attempt to
10956 rebuild @file{configure}, @file{Makefile.in}s, Lex or Yacc outputs, etc.
10957 I.e., this disables build rules for files that are usually distributed
10958 and that users should normally not have to update.
10959
10960 The user can override the default setting by passing either
10961 @samp{--enable-maintainer-mode} or @samp{--disable-maintainer-mode}
10962 to @command{configure}.
10963
10964 People use @code{AM_MAINTAINER_MODE} either because they do not want their
10965 users (or themselves) annoyed by timestamps lossage (@pxref{CVS}), or
10966 because they simply can't stand the rebuild rules and prefer running
10967 maintainer tools explicitly.
10968
10969 @code{AM_MAINTAINER_MODE} also allows you to disable some custom build
10970 rules conditionally.  Some developers use this feature to disable
10971 rules that need exotic tools that users may not have available.
10972
10973 Several years ago Fran@,{c}ois Pinard pointed out several arguments
10974 against this @code{AM_MAINTAINER_MODE} macro.  Most of them relate to
10975 insecurity.  By removing dependencies you get non-dependable builds:
10976 changes to sources files can have no effect on generated files and this
10977 can be very confusing when unnoticed.  He adds that security shouldn't
10978 be reserved to maintainers (what @option{--enable-maintainer-mode}
10979 suggests), on the contrary.  If one user has to modify a
10980 @file{Makefile.am}, then either @file{Makefile.in} should be updated
10981 or a warning should be output (this is what Automake uses
10982 @command{missing} for) but the last thing you want is that nothing
10983 happens and the user doesn't notice it (this is what happens when
10984 rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
10985
10986 Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro was
10987 swayed by Fran@,{c}ois's arguments, and got rid of
10988 @code{AM_MAINTAINER_MODE} in all of his packages.
10989
10990 Still many people continue to use @code{AM_MAINTAINER_MODE}, because
10991 it helps them working on projects where all files are kept under version
10992 control, and because @command{missing} isn't enough if you have the
10993 wrong version of the tools.
10994
10995
10996 @node Wildcards
10997 @section Why doesn't Automake support wildcards?
10998 @cindex wildcards
10999
11000 Developers are lazy.  They would often like to use wildcards in
11001 @file{Makefile.am}s, so that they would not need to remember to
11002 update @file{Makefile.am}s every time they add, delete, or rename
11003 a file.
11004
11005 There are several objections to this:
11006 @itemize
11007 @item
11008 When using CVS (or similar) developers need to remember they have to
11009 run @samp{cvs add} or @samp{cvs rm} anyway.  Updating
11010 @file{Makefile.am} accordingly quickly becomes a reflex.
11011
11012 Conversely, if your application doesn't compile
11013 because you forgot to add a file in @file{Makefile.am}, it will help
11014 you remember to @samp{cvs add} it.
11015
11016 @item
11017 Using wildcards makes it easy to distribute files by mistake.  For
11018 instance, some code a developer is experimenting with (a test case,
11019 say) that should not be part of the distribution.
11020
11021 @item
11022 Using wildcards it's easy to omit some files by mistake.  For
11023 instance, one developer creates a new file, uses it in many places,
11024 but forgets to commit it.  Another developer then checks out the
11025 incomplete project and is able to run @samp{make dist} successfully,
11026 even though a file is missing. By listing files, @samp{make dist}
11027 @emph{will} complain.
11028
11029 @item
11030 Wildcards are not portable to some non-GNU @command{make} implementations,
11031 e.g., NetBSD @command{make} will not expand globs such as @samp{*} in
11032 prerequisites of a target.
11033
11034 @item
11035 Finally, it's really hard to @emph{forget} to add a file to
11036 @file{Makefile.am}: files that are not listed in @file{Makefile.am} are
11037 not compiled or installed, so you can't even test them.
11038 @end itemize
11039
11040 Still, these are philosophical objections, and as such you may disagree,
11041 or find enough value in wildcards to dismiss all of them.  Before you
11042 start writing a patch against Automake to teach it about wildcards,
11043 let's see the main technical issue: portability.
11044
11045 Although @samp{$(wildcard ...)} works with GNU @command{make}, it is
11046 not portable to other @command{make} implementations.
11047
11048 The only way Automake could support @command{$(wildcard ...)} is by
11049 expending @command{$(wildcard ...)} when @command{automake} is run.
11050 The resulting @file{Makefile.in}s would be portable since they would
11051 list all files and not use @samp{$(wildcard ...)}.  However that
11052 means developers would need to remember to run @command{automake} each
11053 time they add, delete, or rename files.
11054
11055 Compared to editing @file{Makefile.am}, this is a very small gain.  Sure,
11056 it's easier and faster to type @samp{automake; make} than to type
11057 @samp{emacs Makefile.am; make}.  But nobody bothered enough to write a
11058 patch to add support for this syntax.  Some people use scripts to
11059 generate file lists in @file{Makefile.am} or in separate
11060 @file{Makefile} fragments.
11061
11062 Even if you don't care about portability, and are tempted to use
11063 @samp{$(wildcard ...)} anyway because you target only GNU Make, you
11064 should know there are many places where Automake needs to know exactly
11065 which files should be processed.  As Automake doesn't know how to
11066 expand @samp{$(wildcard ...)}, you cannot use it in these places.
11067 @samp{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
11068 variables as far Automake is concerned.
11069
11070 You can get warnings about @samp{$(wildcard ...}) constructs using the
11071 @option{-Wportability} flag.
11072
11073 @node Limitations on File Names
11074 @section Limitations on File Names
11075 @cindex file names, limitations on
11076
11077 Automake attempts to support all kinds of file names, even those that
11078 contain unusual characters or are unusually long.  However, some
11079 limitations are imposed by the underlying operating system and tools.
11080
11081 Most operating systems prohibit the use of the null byte in file
11082 names, and reserve @samp{/} as a directory separator.  Also, they
11083 require that file names are properly encoded for the user's locale.
11084 Automake is subject to these limits.
11085
11086 Portable packages should limit themselves to POSIX file
11087 names.  These can contain ASCII letters and digits,
11088 @samp{_}, @samp{.}, and @samp{-}.  File names consist of components
11089 separated by @samp{/}.  File name components cannot begin with
11090 @samp{-}.
11091
11092 Portable POSIX file names cannot contain components that exceed a
11093 14-byte limit, but nowadays it's normally safe to assume the
11094 more-generous XOPEN limit of 255 bytes.  POSIX
11095 limits file names to 255 bytes (XOPEN allows 1023 bytes),
11096 but you may want to limit a source tarball to file names of 99 bytes
11097 to avoid interoperability problems with old versions of @command{tar}.
11098
11099 If you depart from these rules (e.g., by using non-ASCII
11100 characters in file names, or by using lengthy file names), your
11101 installers may have problems for reasons unrelated to Automake.
11102 However, if this does not concern you, you should know about the
11103 limitations imposed by Automake itself.  These limitations are
11104 undesirable, but some of them seem to be inherent to underlying tools
11105 like Autoconf, Make, M4, and the shell.  They fall into three
11106 categories: install directories, build directories, and file names.
11107
11108 The following characters:
11109
11110 @example
11111 @r{newline} " # $ ' `
11112 @end example
11113
11114 should not appear in the names of install directories.  For example,
11115 the operand of @command{configure}'s @option{--prefix} option should
11116 not contain these characters.
11117
11118 Build directories suffer the same limitations as install directories,
11119 and in addition should not contain the following characters:
11120
11121 @example
11122 & @@ \
11123 @end example
11124
11125 For example, the full name of the directory containing the source
11126 files should not contain these characters.
11127
11128 Source and installation file names like @file{main.c} are limited even
11129 further: they should conform to the POSIX/XOPEN
11130 rules described above.  In addition, if you plan to port to
11131 non-POSIX environments, you should avoid file names that
11132 differ only in case (e.g., @file{makefile} and @file{Makefile}).
11133 Nowadays it is no longer worth worrying about the 8.3 limits of
11134 DOS file systems.
11135
11136 @node distcleancheck
11137 @section Files left in build directory after distclean
11138 @cindex @code{distclean}, diagnostic
11139 @cindex @samp{make distclean}, diagnostic
11140 @cindex dependencies and distributed files
11141 @trindex distclean
11142 @trindex distcleancheck
11143
11144 This is a diagnostic you might encounter while running @samp{make
11145 distcheck}.
11146
11147 As explained in @ref{Checking the Distribution}, @samp{make distcheck}
11148 attempts to build and check your package for errors like this one.
11149
11150 @samp{make distcheck} will perform a @code{VPATH} build of your
11151 package (@pxref{VPATH Builds}), and then call @samp{make distclean}.
11152 Files left in the build directory after @samp{make distclean} has run
11153 are listed after this error.
11154
11155 This diagnostic really covers two kinds of errors:
11156
11157 @itemize @bullet
11158 @item
11159 files that are forgotten by distclean;
11160 @item
11161 distributed files that are erroneously rebuilt.
11162 @end itemize
11163
11164 The former left-over files are not distributed, so the fix is to mark
11165 them for cleaning (@pxref{Clean}), this is obvious and doesn't deserve
11166 more explanations.
11167
11168 The latter bug is not always easy to understand and fix, so let's
11169 proceed with an example.  Suppose our package contains a program for
11170 which we want to build a man page using @command{help2man}.  GNU
11171 @command{help2man} produces simple manual pages from the @option{--help}
11172 and @option{--version} output of other commands (@pxref{Top, , Overview,
11173 help2man, The Help2man Manual}).  Because we don't want to force our
11174 users to install @command{help2man}, we decide to distribute the
11175 generated man page using the following setup.
11176
11177 @example
11178 # This Makefile.am is bogus.
11179 bin_PROGRAMS = foo
11180 foo_SOURCES = foo.c
11181 dist_man_MANS = foo.1
11182
11183 foo.1: foo$(EXEEXT)
11184         help2man --output=foo.1 ./foo$(EXEEXT)
11185 @end example
11186
11187 This will effectively distribute the man page.  However,
11188 @samp{make distcheck} will fail with:
11189
11190 @example
11191 ERROR: files left in build directory after distclean:
11192 ./foo.1
11193 @end example
11194
11195 Why was @file{foo.1} rebuilt?  Because although distributed,
11196 @file{foo.1} depends on a non-distributed built file:
11197 @file{foo$(EXEEXT)}.  @file{foo$(EXEEXT)} is built by the user, so it
11198 will always appear to be newer than the distributed @file{foo.1}.
11199
11200 @samp{make distcheck} caught an inconsistency in our package.  Our
11201 intent was to distribute @file{foo.1} so users do not need to install
11202 @command{help2man}, however since this rule causes this file to be
11203 always rebuilt, users @emph{do} need @command{help2man}.  Either we
11204 should ensure that @file{foo.1} is not rebuilt by users, or there is
11205 no point in distributing @file{foo.1}.
11206
11207 More generally, the rule is that distributed files should never depend
11208 on non-distributed built files.  If you distribute something
11209 generated, distribute its sources.
11210
11211 One way to fix the above example, while still distributing
11212 @file{foo.1} is to not depend on @file{foo$(EXEEXT)}.  For instance,
11213 assuming @command{foo --version} and @command{foo --help} do not
11214 change unless @file{foo.c} or @file{configure.ac} change, we could
11215 write the following @file{Makefile.am}:
11216
11217 @example
11218 bin_PROGRAMS = foo
11219 foo_SOURCES = foo.c
11220 dist_man_MANS = foo.1
11221
11222 foo.1: foo.c $(top_srcdir)/configure.ac
11223         $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
11224         help2man --output=foo.1 ./foo$(EXEEXT)
11225 @end example
11226
11227 This way, @file{foo.1} will not get rebuilt every time
11228 @file{foo$(EXEEXT)} changes.  The @command{make} call makes sure
11229 @file{foo$(EXEEXT)} is up-to-date before @command{help2man}.  Another
11230 way to ensure this would be to use separate directories for binaries
11231 and man pages, and set @code{SUBDIRS} so that binaries are built
11232 before man pages.
11233
11234 We could also decide not to distribute @file{foo.1}.  In
11235 this case it's fine to have @file{foo.1} dependent upon
11236 @file{foo$(EXEEXT)}, since both will have to be rebuilt.
11237 However it would be impossible to build the package in a
11238 cross-compilation, because building @file{foo.1} involves
11239 an @emph{execution} of @file{foo$(EXEEXT)}.
11240
11241 Another context where such errors are common is when distributed files
11242 are built by tools that are built by the package.  The pattern is
11243 similar:
11244
11245 @example
11246 distributed-file: built-tools distributed-sources
11247         build-command
11248 @end example
11249
11250 @noindent
11251 should be changed to
11252
11253 @example
11254 distributed-file: distributed-sources
11255         $(MAKE) $(AM_MAKEFLAGS) built-tools
11256         build-command
11257 @end example
11258
11259 @noindent
11260 or you could choose not to distribute @file{distributed-file}, if
11261 cross-compilation does not matter.
11262
11263 The points made through these examples are worth a summary:
11264
11265 @cartouche
11266 @itemize
11267 @item
11268 Distributed files should never depend upon non-distributed built
11269 files.
11270 @item
11271 Distributed files should be distributed with all their dependencies.
11272 @item
11273 If a file is @emph{intended} to be rebuilt by users, then there is no point
11274 in distributing it.
11275 @end itemize
11276 @end cartouche
11277
11278 @vrindex distcleancheck_listfiles
11279 For desperate cases, it's always possible to disable this check by
11280 setting @code{distcleancheck_listfiles} as documented in @ref{Checking
11281 the Distribution}.
11282 Make sure you do understand the reason why @samp{make distcheck}
11283 complains before you do this.  @code{distcleancheck_listfiles} is a
11284 way to @emph{hide} errors, not to fix them.  You can always do better.
11285
11286 @node Flag Variables Ordering
11287 @section Flag Variables Ordering
11288 @cindex Ordering flag variables
11289 @cindex Flag variables, ordering
11290
11291 @display
11292 What is the difference between @code{AM_CFLAGS}, @code{CFLAGS}, and
11293 @code{mumble_CFLAGS}?
11294 @end display
11295
11296 @display
11297 Why does @command{automake} output @code{CPPFLAGS} after
11298 @code{AM_CPPFLAGS} on compile lines?  Shouldn't it be the converse?
11299 @end display
11300
11301 @display
11302 My @file{configure} adds some warning flags into @code{CXXFLAGS}.  In
11303 one @file{Makefile.am} I would like to append a new flag, however if I
11304 put the flag into @code{AM_CXXFLAGS} it is prepended to the other
11305 flags, not appended.
11306 @end display
11307
11308 @subheading Compile Flag Variables
11309 @cindex Flag Variables, Ordering
11310 @cindex Compile Flag Variables
11311 @cindex @code{AM_CCASFLAGS} and @code{CCASFLAGS}
11312 @cindex @code{AM_CFLAGS} and @code{CFLAGS}
11313 @cindex @code{AM_CPPFLAGS} and @code{CPPFLAGS}
11314 @cindex @code{AM_CXXFLAGS} and @code{CXXFLAGS}
11315 @cindex @code{AM_FCFLAGS} and @code{FCFLAGS}
11316 @cindex @code{AM_FFLAGS} and @code{FFLAGS}
11317 @cindex @code{AM_GCJFLAGS} and @code{GCJFLAGS}
11318 @cindex @code{AM_LDFLAGS} and @code{LDFLAGS}
11319 @cindex @code{AM_LFLAGS} and @code{LFLAGS}
11320 @cindex @code{AM_LIBTOOLFLAGS} and @code{LIBTOOLFLAGS}
11321 @cindex @code{AM_OBJCFLAGS} and @code{OBJCFLAGS}
11322 @cindex @code{AM_RFLAGS} and @code{RFLAGS}
11323 @cindex @code{AM_UPCFLAGS} and @code{UPCFLAGS}
11324 @cindex @code{AM_YFLAGS} and @code{YFLAGS}
11325 @cindex @code{CCASFLAGS} and @code{AM_CCASFLAGS}
11326 @cindex @code{CFLAGS} and @code{AM_CFLAGS}
11327 @cindex @code{CPPFLAGS} and @code{AM_CPPFLAGS}
11328 @cindex @code{CXXFLAGS} and @code{AM_CXXFLAGS}
11329 @cindex @code{FCFLAGS} and @code{AM_FCFLAGS}
11330 @cindex @code{FFLAGS} and @code{AM_FFLAGS}
11331 @cindex @code{GCJFLAGS} and @code{AM_GCJFLAGS}
11332 @cindex @code{LDFLAGS} and @code{AM_LDFLAGS}
11333 @cindex @code{LFLAGS} and @code{AM_LFLAGS}
11334 @cindex @code{LIBTOOLFLAGS} and @code{AM_LIBTOOLFLAGS}
11335 @cindex @code{OBJCFLAGS} and @code{AM_OBJCFLAGS}
11336 @cindex @code{RFLAGS} and @code{AM_RFLAGS}
11337 @cindex @code{UPCFLAGS} and @code{AM_UPCFLAGS}
11338 @cindex @code{YFLAGS} and @code{AM_YFLAGS}
11339
11340 This section attempts to answer all the above questions.  We will
11341 mostly discuss @code{CPPFLAGS} in our examples, but actually the
11342 answer holds for all the compile flags used in Automake:
11343 @code{CCASFLAGS}, @code{CFLAGS}, @code{CPPFLAGS}, @code{CXXFLAGS},
11344 @code{FCFLAGS}, @code{FFLAGS}, @code{GCJFLAGS}, @code{LDFLAGS},
11345 @code{LFLAGS}, @code{LIBTOOLFLAGS}, @code{OBJCFLAGS}, @code{RFLAGS},
11346 @code{UPCFLAGS}, and @code{YFLAGS}.
11347
11348 @code{CPPFLAGS}, @code{AM_CPPFLAGS}, and @code{mumble_CPPFLAGS} are
11349 three variables that can be used to pass flags to the C preprocessor
11350 (actually these variables are also used for other languages like C++
11351 or preprocessed Fortran).  @code{CPPFLAGS} is the user variable
11352 (@pxref{User Variables}), @code{AM_CPPFLAGS} is the Automake variable,
11353 and @code{mumble_CPPFLAGS} is the variable specific to the
11354 @code{mumble} target (we call this a per-target variable,
11355 @pxref{Program and Library Variables}).
11356
11357 Automake always uses two of these variables when compiling C sources
11358 files.  When compiling an object file for the @code{mumble} target,
11359 the first variable will be @code{mumble_CPPFLAGS} if it is defined, or
11360 @code{AM_CPPFLAGS} otherwise.  The second variable is always
11361 @code{CPPFLAGS}.
11362
11363 In the following example,
11364
11365 @example
11366 bin_PROGRAMS = foo bar
11367 foo_SOURCES = xyz.c
11368 bar_SOURCES = main.c
11369 foo_CPPFLAGS = -DFOO
11370 AM_CPPFLAGS = -DBAZ
11371 @end example
11372
11373 @noindent
11374 @file{xyz.o} will be compiled with @samp{$(foo_CPPFLAGS) $(CPPFLAGS)},
11375 (because @file{xyz.o} is part of the @code{foo} target), while
11376 @file{main.o} will be compiled with @samp{$(AM_CPPFLAGS) $(CPPFLAGS)}
11377 (because there is no per-target variable for target @code{bar}).
11378
11379 The difference between @code{mumble_CPPFLAGS} and @code{AM_CPPFLAGS}
11380 being clear enough, let's focus on @code{CPPFLAGS}.  @code{CPPFLAGS}
11381 is a user variable, i.e., a variable that users are entitled to modify
11382 in order to compile the package.  This variable, like many others,
11383 is documented at the end of the output of @samp{configure --help}.
11384
11385 For instance, someone who needs to add @file{/home/my/usr/include} to
11386 the C compiler's search path would configure a package with
11387
11388 @example
11389 ./configure CPPFLAGS='-I /home/my/usr/include'
11390 @end example
11391
11392 @noindent
11393 and this flag would be propagated to the compile rules of all
11394 @file{Makefile}s.
11395
11396 It is also not uncommon to override a user variable at
11397 @command{make}-time.  Many installers do this with @code{prefix}, but
11398 this can be useful with compiler flags too.  For instance, if, while
11399 debugging a C++ project, you need to disable optimization in one
11400 specific object file, you can run something like
11401
11402 @example
11403 rm file.o
11404 make CXXFLAGS=-O0 file.o
11405 make
11406 @end example
11407
11408 The reason @samp{$(CPPFLAGS)} appears after @samp{$(AM_CPPFLAGS)} or
11409 @samp{$(mumble_CPPFLAGS)} in the compile command is that users
11410 should always have the last say.  It probably makes more sense if you
11411 think about it while looking at the @samp{CXXFLAGS=-O0} above, which
11412 should supersede any other switch from @code{AM_CXXFLAGS} or
11413 @code{mumble_CXXFLAGS} (and this of course replaces the previous value
11414 of @code{CXXFLAGS}).
11415
11416 You should never redefine a user variable such as @code{CPPFLAGS} in
11417 @file{Makefile.am}.  Use @samp{automake -Woverride} to diagnose such
11418 mistakes.  Even something like
11419
11420 @example
11421 CPPFLAGS = -DDATADIR=\"$(datadir)\" @@CPPFLAGS@@
11422 @end example
11423
11424 @noindent
11425 is erroneous.  Although this preserves @file{configure}'s value of
11426 @code{CPPFLAGS}, the definition of @code{DATADIR} will disappear if a
11427 user attempts to override @code{CPPFLAGS} from the @command{make}
11428 command line.
11429
11430 @example
11431 AM_CPPFLAGS = -DDATADIR=\"$(datadir)\"
11432 @end example
11433
11434 @noindent
11435 is all that is needed here if no per-target flags are used.
11436
11437 You should not add options to these user variables within
11438 @file{configure} either, for the same reason.  Occasionally you need
11439 to modify these variables to perform a test, but you should reset
11440 their values afterwards.  In contrast, it is OK to modify the
11441 @samp{AM_} variables within @file{configure} if you @code{AC_SUBST}
11442 them, but it is rather rare that you need to do this, unless you
11443 really want to change the default definitions of the @samp{AM_}
11444 variables in all @file{Makefile}s.
11445
11446 What we recommend is that you define extra flags in separate
11447 variables.  For instance, you may write an Autoconf macro that computes
11448 a set of warning options for the C compiler, and @code{AC_SUBST} them
11449 in @code{WARNINGCFLAGS}; you may also have an Autoconf macro that
11450 determines which compiler and which linker flags should be used to
11451 link with library @file{libfoo}, and @code{AC_SUBST} these in
11452 @code{LIBFOOCFLAGS} and @code{LIBFOOLDFLAGS}.  Then, a
11453 @file{Makefile.am} could use these variables as follows:
11454
11455 @example
11456 AM_CFLAGS = $(WARNINGCFLAGS)
11457 bin_PROGRAMS = prog1 prog2
11458 prog1_SOURCES = @dots{}
11459 prog2_SOURCES = @dots{}
11460 prog2_CFLAGS = $(LIBFOOCFLAGS) $(AM_CFLAGS)
11461 prog2_LDFLAGS = $(LIBFOOLDFLAGS)
11462 @end example
11463
11464 In this example both programs will be compiled with the flags
11465 substituted into @samp{$(WARNINGCFLAGS)}, and @code{prog2} will
11466 additionally be compiled with the flags required to link with
11467 @file{libfoo}.
11468
11469 Note that listing @code{AM_CFLAGS} in a per-target @code{CFLAGS}
11470 variable is a common idiom to ensure that @code{AM_CFLAGS} applies to
11471 every target in a @file{Makefile.in}.
11472
11473 Using variables like this gives you full control over the ordering of
11474 the flags.  For instance, if there is a flag in $(WARNINGCFLAGS) that
11475 you want to negate for a particular target, you can use something like
11476 @samp{prog1_CFLAGS = $(AM_CFLAGS) -no-flag}.  If all these flags had
11477 been forcefully appended to @code{CFLAGS}, there would be no way to
11478 disable one flag.  Yet another reason to leave user variables to
11479 users.
11480
11481 Finally, we have avoided naming the variable of the example
11482 @code{LIBFOO_LDFLAGS} (with an underscore) because that would cause
11483 Automake to think that this is actually a per-target variable (like
11484 @code{mumble_LDFLAGS}) for some non-declared @code{LIBFOO} target.
11485
11486 @subheading Other Variables
11487
11488 There are other variables in Automake that follow similar principles
11489 to allow user options.  For instance, Texinfo rules (@pxref{Texinfo})
11490 use @code{MAKEINFOFLAGS} and @code{AM_MAKEINFOFLAGS}.  Similarly,
11491 DejaGnu tests (@pxref{DejaGnu Tests}) use @code{RUNTESTDEFAULTFLAGS} and
11492 @code{AM_RUNTESTDEFAULTFLAGS}.  The tags and ctags rules
11493 (@pxref{Tags}) use @code{ETAGSFLAGS}, @code{AM_ETAGSFLAGS},
11494 @code{CTAGSFLAGS}, and @code{AM_CTAGSFLAGS}.  Java rules
11495 (@pxref{Java}) use @code{JAVACFLAGS} and @code{AM_JAVACFLAGS}.  None
11496 of these rules support per-target flags (yet).
11497
11498 To some extent, even @code{AM_MAKEFLAGS} (@pxref{Subdirectories})
11499 obeys this naming scheme.  The slight difference is that
11500 @code{MAKEFLAGS} is passed to sub-@command{make}s implicitly by
11501 @command{make} itself.
11502
11503 However you should not think that all variables ending with
11504 @code{FLAGS} follow this convention.  For instance,
11505 @code{DISTCHECK_CONFIGURE_FLAGS} (@pxref{Checking the Distribution}) and
11506 @code{ACLOCAL_AMFLAGS} (see @ref{Rebuilding} and @ref{Local Macros}),
11507 are two variables that are only useful to the maintainer and have no
11508 user counterpart.
11509
11510 @code{ARFLAGS} (@pxref{A Library}) is usually defined by Automake and
11511 has neither @code{AM_} nor per-target cousin.
11512
11513 Finally you should not think that the existence of a per-target
11514 variable implies the existance of an @code{AM_} variable or of a user
11515 variable.  For instance, the @code{mumble_LDADD} per-target variable
11516 overrides the makefile-wide @code{LDADD} variable (which is not a user
11517 variable), and @code{mumble_LIBADD} exists only as a per-target
11518 variable.  @xref{Program and Library Variables}.
11519
11520
11521 @node Renamed Objects
11522 @section Why are object files sometimes renamed?
11523
11524 This happens when per-target compilation flags are used.  Object
11525 files need to be renamed just in case they would clash with object
11526 files compiled from the same sources, but with different flags.
11527 Consider the following example.
11528
11529 @example
11530 bin_PROGRAMS = true false
11531 true_SOURCES = generic.c
11532 true_CPPFLAGS = -DEXIT_CODE=0
11533 false_SOURCES = generic.c
11534 false_CPPFLAGS = -DEXIT_CODE=1
11535 @end example
11536
11537 @noindent
11538 Obviously the two programs are built from the same source, but it
11539 would be bad if they shared the same object, because @file{generic.o}
11540 cannot be built with both @samp{-DEXIT_CODE=0} @emph{and}
11541 @samp{-DEXIT_CODE=1}.  Therefore @command{automake} outputs rules to
11542 build two different objects: @file{true-generic.o} and
11543 @file{false-generic.o}.
11544
11545 @command{automake} doesn't actually look whether source files are
11546 shared to decide if it must rename objects.  It will just rename all
11547 objects of a target as soon as it sees per-target compilation flags
11548 used.
11549
11550 It's OK to share object files when per-target compilation flags are not
11551 used.  For instance, @file{true} and @file{false} will both use
11552 @file{version.o} in the following example.
11553
11554 @example
11555 AM_CPPFLAGS = -DVERSION=1.0
11556 bin_PROGRAMS = true false
11557 true_SOURCES = true.c version.c
11558 false_SOURCES = false.c version.c
11559 @end example
11560
11561 Note that the renaming of objects is also affected by the
11562 @code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
11563
11564
11565 @node Per-Object Flags
11566 @section Per-Object Flags Emulation
11567 @cindex Per-object flags, emulated
11568
11569 @display
11570 One of my source files needs to be compiled with different flags.  How
11571 do I do?
11572 @end display
11573
11574 Automake supports per-program and per-library compilation flags (see
11575 @ref{Program and Library Variables} and @ref{Flag Variables
11576 Ordering}).  With this you can define compilation flags that apply to
11577 all files compiled for a target.  For instance, in
11578
11579 @example
11580 bin_PROGRAMS = foo
11581 foo_SOURCES = foo.c foo.h bar.c bar.h main.c
11582 foo_CFLAGS = -some -flags
11583 @end example
11584
11585 @noindent
11586 @file{foo-foo.o}, @file{foo-bar.o}, and @file{foo-main.o} will all be
11587 compiled with @samp{-some -flags}.  (If you wonder about the names of
11588 these object files, see @ref{Renamed Objects}.)  Note that
11589 @code{foo_CFLAGS} gives the flags to use when compiling all the C
11590 sources of the @emph{program} @code{foo}, it has nothing to do with
11591 @file{foo.c} or @file{foo-foo.o} specifically.
11592
11593 What if @file{foo.c} needs to be compiled into @file{foo.o} using some
11594 specific flags, that none of the other files requires?  Obviously
11595 per-program flags are not directly applicable here.  Something like
11596 per-object flags are expected, i.e., flags that would be used only
11597 when creating @file{foo-foo.o}.  Automake does not support that,
11598 however this is easy to simulate using a library that contains only
11599 that object, and compiling this library with per-library flags.
11600
11601 @example
11602 bin_PROGRAMS = foo
11603 foo_SOURCES = bar.c bar.h main.c
11604 foo_CFLAGS = -some -flags
11605 foo_LDADD = libfoo.a
11606 noinst_LIBRARIES = libfoo.a
11607 libfoo_a_SOURCES = foo.c foo.h
11608 libfoo_a_CFLAGS = -some -other -flags
11609 @end example
11610
11611 Here @file{foo-bar.o} and @file{foo-main.o} will all be
11612 compiled with @samp{-some -flags}, while @file{libfoo_a-foo.o} will
11613 be compiled using @samp{-some -other -flags}.  Eventually, all
11614 three objects will be linked to form @file{foo}.
11615
11616 This trick can also be achieved using Libtool convenience libraries,
11617 for instance @samp{noinst_LTLIBRARIES = libfoo.la} (@pxref{Libtool
11618 Convenience Libraries}).
11619
11620 Another tempting idea to implement per-object flags is to override the
11621 compile rules @command{automake} would output for these files.
11622 Automake will not define a rule for a target you have defined, so you
11623 could think about defining the @samp{foo-foo.o: foo.c} rule yourself.
11624 We recommend against this, because this is error prone.  For instance,
11625 if you add such a rule to the first example, it will break the day you
11626 decide to remove @code{foo_CFLAGS} (because @file{foo.c} will then be
11627 compiled as @file{foo.o} instead of @file{foo-foo.o}, @pxref{Renamed
11628 Objects}).  Also in order to support dependency tracking, the two
11629 @file{.o}/@file{.obj} extensions, and all the other flags variables
11630 involved in a compilation, you will end up modifying a copy of the
11631 rule previously output by @command{automake} for this file.  If a new
11632 release of Automake generates a different rule, your copy will need to
11633 be updated by hand.
11634
11635 @node Multiple Outputs
11636 @section Handling Tools that Produce Many Outputs
11637 @cindex multiple outputs, rules with
11638 @cindex many outputs, rules with
11639 @cindex rules with multiple outputs
11640
11641 This section describes a @command{make} idiom that can be used when a
11642 tool produces multiple output files.  It is not specific to Automake
11643 and can be used in ordinary @file{Makefile}s.
11644
11645 Suppose we have a program called @command{foo} that will read one file
11646 called @file{data.foo} and produce two files named @file{data.c} and
11647 @file{data.h}.  We want to write a @file{Makefile} rule that captures
11648 this one-to-two dependency.
11649
11650 The naive rule is incorrect:
11651
11652 @example
11653 # This is incorrect.
11654 data.c data.h: data.foo
11655         foo data.foo
11656 @end example
11657
11658 @noindent
11659 What the above rule really says is that @file{data.c} and
11660 @file{data.h} each depend on @file{data.foo}, and can each be built by
11661 running @samp{foo data.foo}.  In other words it is equivalent to:
11662
11663 @example
11664 # We do not want this.
11665 data.c: data.foo
11666         foo data.foo
11667 data.h: data.foo
11668         foo data.foo
11669 @end example
11670
11671 @noindent
11672 which means that @command{foo} can be run twice.  Usually it will not
11673 be run twice, because @command{make} implementations are smart enough
11674 to check for the existence of the second file after the first one has
11675 been built; they will therefore detect that it already exists.
11676 However there are a few situations where it can run twice anyway:
11677
11678 @itemize
11679 @item
11680 The most worrying case is when running a parallel @command{make}.  If
11681 @file{data.c} and @file{data.h} are built in parallel, two @samp{foo
11682 data.foo} commands will run concurrently.  This is harmful.
11683 @item
11684 Another case is when the dependency (here @file{data.foo}) is
11685 (or depends upon) a phony target.
11686 @end itemize
11687
11688 A solution that works with parallel @command{make} but not with
11689 phony dependencies is the following:
11690
11691 @example
11692 data.c data.h: data.foo
11693         foo data.foo
11694 data.h: data.c
11695 @end example
11696
11697 @noindent
11698 The above rules are equivalent to
11699
11700 @example
11701 data.c: data.foo
11702         foo data.foo
11703 data.h: data.foo data.c
11704         foo data.foo
11705 @end example
11706
11707 @noindent
11708 therefore a parallel @command{make} will have to serialize the builds
11709 of @file{data.c} and @file{data.h}, and will detect that the second is
11710 no longer needed once the first is over.
11711
11712 Using this pattern is probably enough for most cases.  However it does
11713 not scale easily to more output files (in this scheme all output files
11714 must be totally ordered by the dependency relation), so we will
11715 explore a more complicated solution.
11716
11717 Another idea is to write the following:
11718
11719 @example
11720 # There is still a problem with this one.
11721 data.c: data.foo
11722         foo data.foo
11723 data.h: data.c
11724 @end example
11725
11726 @noindent
11727 The idea is that @samp{foo data.foo} is run only when @file{data.c}
11728 needs to be updated, but we further state that @file{data.h} depends
11729 upon @file{data.c}.  That way, if @file{data.h} is required and
11730 @file{data.foo} is out of date, the dependency on @file{data.c} will
11731 trigger the build.
11732
11733 This is almost perfect, but suppose we have built @file{data.h} and
11734 @file{data.c}, and then we erase @file{data.h}.  Then, running
11735 @samp{make data.h} will not rebuild @file{data.h}.  The above rules
11736 just state that @file{data.c} must be up-to-date with respect to
11737 @file{data.foo}, and this is already the case.
11738
11739 What we need is a rule that forces a rebuild when @file{data.h} is
11740 missing.  Here it is:
11741
11742 @example
11743 data.c: data.foo
11744         foo data.foo
11745 data.h: data.c
11746 ## Recover from the removal of $@@
11747         @@if test -f $@@; then :; else \
11748           rm -f data.c; \
11749           $(MAKE) $(AM_MAKEFLAGS) data.c; \
11750         fi
11751 @end example
11752
11753 The above scheme can be extended to handle more outputs and more
11754 inputs.  One of the outputs is selected to serve as a witness to the
11755 successful completion of the command, it depends upon all inputs, and
11756 all other outputs depend upon it.  For instance, if @command{foo}
11757 should additionally read @file{data.bar} and also produce
11758 @file{data.w} and @file{data.x}, we would write:
11759
11760 @example
11761 data.c: data.foo data.bar
11762         foo data.foo data.bar
11763 data.h data.w data.x: data.c
11764 ## Recover from the removal of $@@
11765         @@if test -f $@@; then :; else \
11766           rm -f data.c; \
11767           $(MAKE) $(AM_MAKEFLAGS) data.c; \
11768         fi
11769 @end example
11770
11771 However there are now three minor problems in this setup.  One is related
11772 to the timestamp ordering of @file{data.h}, @file{data.w},
11773 @file{data.x}, and @file{data.c}.  Another one is a race condition
11774 if a parallel @command{make} attempts to run multiple instances of the
11775 recover block at once.  Finally, the recursive rule breaks @samp{make -n}
11776 when run with GNU @command{make} (as well as some other @command{make}
11777 implementations), as it may remove @file{data.h} even when it should not
11778 (@pxref{MAKE Variable, , How the @code{MAKE} Variable Works, make,
11779 The GNU Make Manual}).
11780
11781 Let us deal with the first problem.  @command{foo} outputs four files,
11782 but we do not know in which order these files are created.  Suppose
11783 that @file{data.h} is created before @file{data.c}.  Then we have a
11784 weird situation.  The next time @command{make} is run, @file{data.h}
11785 will appear older than @file{data.c}, the second rule will be
11786 triggered, a shell will be started to execute the @samp{if@dots{}fi}
11787 command, but actually it will just execute the @code{then} branch,
11788 that is: nothing.  In other words, because the witness we selected is
11789 not the first file created by @command{foo}, @command{make} will start
11790 a shell to do nothing each time it is run.
11791
11792 A simple riposte is to fix the timestamps when this happens.
11793
11794 @example
11795 data.c: data.foo data.bar
11796         foo data.foo data.bar
11797 data.h data.w data.x: data.c
11798         @@if test -f $@@; then \
11799           touch $@@; \
11800         else \
11801 ## Recover from the removal of $@@
11802           rm -f data.c; \
11803           $(MAKE) $(AM_MAKEFLAGS) data.c; \
11804         fi
11805 @end example
11806
11807 Another solution is to use a different and dedicated file as witness,
11808 rather than using any of @command{foo}'s outputs.
11809
11810 @example
11811 data.stamp: data.foo data.bar
11812         @@rm -f data.tmp
11813         @@touch data.tmp
11814         foo data.foo data.bar
11815         @@mv -f data.tmp $@@
11816 data.c data.h data.w data.x: data.stamp
11817 ## Recover from the removal of $@@
11818         @@if test -f $@@; then :; else \
11819           rm -f data.stamp; \
11820           $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
11821         fi
11822 @end example
11823
11824 @file{data.tmp} is created before @command{foo} is run, so it has a
11825 timestamp older than output files output by @command{foo}.  It is then
11826 renamed to @file{data.stamp} after @command{foo} has run, because we
11827 do not want to update @file{data.stamp} if @command{foo} fails.
11828
11829 This solution still suffers from the second problem: the race
11830 condition in the recover rule.  If, after a successful build, a user
11831 erases @file{data.c} and @file{data.h}, and runs @samp{make -j}, then
11832 @command{make} may start both recover rules in parallel.  If the two
11833 instances of the rule execute @samp{$(MAKE) $(AM_MAKEFLAGS)
11834 data.stamp} concurrently the build is likely to fail (for instance, the
11835 two rules will create @file{data.tmp}, but only one can rename it).
11836
11837 Admittedly, such a weird situation does not arise during ordinary
11838 builds.  It occurs only when the build tree is mutilated.  Here
11839 @file{data.c} and @file{data.h} have been explicitly removed without
11840 also removing @file{data.stamp} and the other output files.
11841 @code{make clean; make} will always recover from these situations even
11842 with parallel makes, so you may decide that the recover rule is solely
11843 to help non-parallel make users and leave things as-is.  Fixing this
11844 requires some locking mechanism to ensure only one instance of the
11845 recover rule rebuilds @file{data.stamp}.  One could imagine something
11846 along the following lines.
11847
11848 @example
11849 data.c data.h data.w data.x: data.stamp
11850 ## Recover from the removal of $@@
11851         @@if test -f $@@; then :; else \
11852           trap 'rm -rf data.lock data.stamp' 1 2 13 15; \
11853 ## mkdir is a portable test-and-set
11854           if mkdir data.lock 2>/dev/null; then \
11855 ## This code is being executed by the first process.
11856             rm -f data.stamp; \
11857             $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
11858             result=$$?; rm -rf data.lock; exit $$result; \
11859           else \
11860 ## This code is being executed by the follower processes.
11861 ## Wait until the first process is done.
11862             while test -d data.lock; do sleep 1; done; \
11863 ## Succeed if and only if the first process succeeded.
11864             test -f data.stamp; \
11865           fi; \
11866         fi
11867 @end example
11868
11869 Using a dedicated witness, like @file{data.stamp}, is very handy when
11870 the list of output files is not known beforehand.  As an illustration,
11871 consider the following rules to compile many @file{*.el} files into
11872 @file{*.elc} files in a single command.  It does not matter how
11873 @code{ELFILES} is defined (as long as it is not empty: empty targets
11874 are not accepted by POSIX).
11875
11876 @example
11877 ELFILES = one.el two.el three.el @dots{}
11878 ELCFILES = $(ELFILES:=c)
11879
11880 elc-stamp: $(ELFILES)
11881         @@rm -f elc-temp
11882         @@touch elc-temp
11883         $(elisp_comp) $(ELFILES)
11884         @@mv -f elc-temp $@@
11885
11886 $(ELCFILES): elc-stamp
11887         @@if test -f $@@; then :; else \
11888 ## Recover from the removal of $@@
11889           trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
11890           if mkdir elc-lock 2>/dev/null; then \
11891 ## This code is being executed by the first process.
11892             rm -f elc-stamp; \
11893             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
11894             rmdir elc-lock; \
11895           else \
11896 ## This code is being executed by the follower processes.
11897 ## Wait until the first process is done.
11898             while test -d elc-lock; do sleep 1; done; \
11899 ## Succeed if and only if the first process succeeded.
11900             test -f elc-stamp; exit $$?; \
11901 @c $$
11902           fi; \
11903         fi
11904 @end example
11905
11906 These solutions all still suffer from the third problem, namely that
11907 they break the promise that @samp{make -n} should not cause any actual
11908 changes to the tree.  For those solutions that do not create lock files,
11909 it is possible to split the recover rules into two separate recipe
11910 commands, one of which does all work but the recursion, and the
11911 other invokes the recursive @samp{$(MAKE)}.  The solutions involving
11912 locking could act upon the contents of the @samp{MAKEFLAGS} variable,
11913 but parsing that portably is not easy (@pxref{The Make Macro MAKEFLAGS,,,
11914 autoconf, The Autoconf Manual}).  Here is an example:
11915
11916 @example
11917 ELFILES = one.el two.el three.el @dots{}
11918 ELCFILES = $(ELFILES:=c)
11919
11920 elc-stamp: $(ELFILES)
11921         @@rm -f elc-temp
11922         @@touch elc-temp
11923         $(elisp_comp) $(ELFILES)
11924         @@mv -f elc-temp $@@
11925
11926 $(ELCFILES): elc-stamp
11927 ## Recover from the removal of $@@
11928         @@dry=; for f in x $$MAKEFLAGS; do \
11929           case $$f in \
11930             *=*|--*);; \
11931             *n*) dry=:;; \
11932           esac; \
11933         done; \
11934         if test -f $@@; then :; else \
11935           $$dry trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
11936           if $$dry mkdir elc-lock 2>/dev/null; then \
11937 ## This code is being executed by the first process.
11938             $$dry rm -f elc-stamp; \
11939             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
11940             $$dry rmdir elc-lock; \
11941           else \
11942 ## This code is being executed by the follower processes.
11943 ## Wait until the first process is done.
11944             while test -d elc-lock && test -z "$$dry"; do \
11945 @c $$
11946               sleep 1; \
11947             done; \
11948 ## Succeed if and only if the first process succeeded.
11949             $$dry test -f elc-stamp; exit $$?; \
11950           fi; \
11951         fi
11952 @end example
11953
11954 For completeness it should be noted that GNU @command{make} is able to
11955 express rules with multiple output files using pattern rules
11956 (@pxref{Pattern Examples, , Pattern Rule Examples, make, The GNU Make
11957 Manual}).  We do not discuss pattern rules here because they are not
11958 portable, but they can be convenient in packages that assume GNU
11959 @command{make}.
11960
11961
11962 @node Hard-Coded Install Paths
11963 @section Installing to Hard-Coded Locations
11964
11965 @display
11966 My package needs to install some configuration file.  I tried to use
11967 the following rule, but @samp{make distcheck} fails.  Why?
11968
11969 @example
11970 # Do not do this.
11971 install-data-local:
11972         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
11973 @end example
11974 @end display
11975
11976 @display
11977 My package needs to populate the installation directory of another
11978 package at install-time.  I can easily compute that installation
11979 directory in @file{configure}, but if I install files therein,
11980 @samp{make distcheck} fails.  How else should I do?
11981 @end display
11982
11983 These two setups share their symptoms: @samp{make distcheck} fails
11984 because they are installing files to hard-coded paths.  In the later
11985 case the path is not really hard-coded in the package, but we can
11986 consider it to be hard-coded in the system (or in whichever tool that
11987 supplies the path).  As long as the path does not use any of the
11988 standard directory variables (@samp{$(prefix)}, @samp{$(bindir)},
11989 @samp{$(datadir)}, etc.), the effect will be the same:
11990 user-installations are impossible.
11991
11992 As a (non-root) user who wants to install a package, you usually have no
11993 right to install anything in @file{/usr} or @file{/usr/local}.  So you
11994 do something like @samp{./configure --prefix ~/usr} to install a
11995 package in your own @file{~/usr} tree.
11996
11997 If a package attempts to install something to some hard-coded path
11998 (e.g., @file{/etc/afile}), regardless of this @option{--prefix} setting,
11999 then the installation will fail.  @samp{make distcheck} performs such
12000 a @option{--prefix} installation, hence it will fail too.
12001
12002 Now, there are some easy solutions.
12003
12004 The above @code{install-data-local} example for installing
12005 @file{/etc/afile} would be better replaced by
12006
12007 @example
12008 sysconf_DATA = afile
12009 @end example
12010
12011 @noindent
12012 by default @code{sysconfdir} will be @samp{$(prefix)/etc}, because
12013 this is what the GNU Standards require.  When such a package is
12014 installed on an FHS compliant system, the installer will have to set
12015 @samp{--sysconfdir=/etc}.  As the maintainer of the package you
12016 should not be concerned by such site policies: use the appropriate
12017 standard directory variable to install your files so that the installer
12018 can easily redefine these variables to match their site conventions.
12019
12020 Installing files that should be used by another package is slightly
12021 more involved.  Let's take an example and assume you want to install
12022 a shared library that is a Python extension module.  If you ask Python
12023 where to install the library, it will answer something like this:
12024
12025 @example
12026 % @kbd{python -c 'from distutils import sysconfig;
12027              print sysconfig.get_python_lib(1,0)'}
12028 /usr/lib/python2.5/site-packages
12029 @end example
12030
12031 If you indeed use this absolute path to install your shared library,
12032 non-root users will not be able to install the package, hence
12033 distcheck fails.
12034
12035 Let's do better.  The @samp{sysconfig.get_python_lib()} function
12036 actually accepts a third argument that will replace Python's
12037 installation prefix.
12038
12039 @example
12040 % @kbd{python -c 'from distutils import sysconfig;
12041              print sysconfig.get_python_lib(1,0,"$@{exec_prefix@}")'}
12042 $@{exec_prefix@}/lib/python2.5/site-packages
12043 @end example
12044
12045 You can also use this new path.  If you do
12046 @itemize @bullet
12047 @item
12048 root users can install your package with the same @option{--prefix}
12049 as Python (you get the behavior of the previous attempt)
12050
12051 @item
12052 non-root users can install your package too, they will have the
12053 extension module in a place that is not searched by Python but they
12054 can work around this using environment variables (and if you installed
12055 scripts that use this shared library, it's easy to tell Python were to
12056 look in the beginning of your script, so the script works in both
12057 cases).
12058 @end itemize
12059
12060 The @code{AM_PATH_PYTHON} macro uses similar commands to define
12061 @samp{$(pythondir)} and @samp{$(pyexecdir)} (@pxref{Python}).
12062
12063 Of course not all tools are as advanced as Python regarding that
12064 substitution of @var{prefix}.  So another strategy is to figure the
12065 part of the installation directory that must be preserved.  For
12066 instance, here is how @code{AM_PATH_LISPDIR} (@pxref{Emacs Lisp})
12067 computes @samp{$(lispdir)}:
12068
12069 @example
12070 $EMACS -batch -q -eval '(while load-path
12071   (princ (concat (car load-path) "\n"))
12072   (setq load-path (cdr load-path)))' >conftest.out
12073 lispdir=`sed -n
12074   -e 's,/$,,'
12075   -e '/.*\/lib\/x*emacs\/site-lisp$/@{
12076         s,.*/lib/\(x*emacs/site-lisp\)$,$@{libdir@}/\1,;p;q;
12077       @}'
12078   -e '/.*\/share\/x*emacs\/site-lisp$/@{
12079         s,.*/share/\(x*emacs/site-lisp\),$@{datarootdir@}/\1,;p;q;
12080       @}'
12081   conftest.out`
12082 @end example
12083
12084 I.e., it just picks the first directory that looks like
12085 @file{*/lib/*emacs/site-lisp} or @file{*/share/*emacs/site-lisp} in
12086 the search path of emacs, and then substitutes @samp{$@{libdir@}} or
12087 @samp{$@{datadir@}} appropriately.
12088
12089 The emacs case looks complicated because it processes a list and
12090 expects two possible layouts, otherwise it's easy, and the benefits for
12091 non-root users are really worth the extra @command{sed} invocation.
12092
12093
12094 @node Debugging Make Rules
12095 @section Debugging Make Rules
12096 @cindex debugging rules
12097 @cindex rules, debugging
12098
12099 The rules and dependency trees generated by @command{automake} can get
12100 rather complex, and leave the developer head-scratching when things
12101 don't work as expected.  Besides the debug options provided by the
12102 @command{make} command (@pxref{Options Summary,,, make, The GNU Make
12103 Manual}), here's a couple of further hints for debugging makefiles
12104 generated by @command{automake} effectively:
12105
12106 @itemize
12107 @item
12108 If less verbose output has been enabled in the package with the
12109 @samp{silent-rules} option (@pxref{Options}), you can use
12110 @code{make V=1} to see the commands being executed.
12111 @item
12112 @code{make -n} can help show what would be done without actually doing
12113 it.  Note however, that this will @emph{still execute} commands prefixed
12114 with @samp{+}, and, when using GNU @command{make}, commands that contain
12115 the strings @samp{$(MAKE)} or @samp{$@{MAKE@}} (@pxref{Instead of
12116 Execution,,, make, The GNU Make Manual}).
12117 Typically, this is helpful to show what recursive rules would do, but it
12118 means that, in your own rules, you should not mix such recursion with
12119 actions that change any files.@footnote{Automake's @samp{dist} and
12120 @samp{distcheck} rules had a bug in this regard in that they created
12121 directories even with @option{-n}, but this has been fixed in Automake
12122 1.11.}  Furthermore, note that GNU @command{make} will update
12123 prerequisites for the @file{Makefile} file itself even with @option{-n}
12124 (@pxref{Remaking Makefiles,,, make, The GNU Make Manual}).
12125 @item
12126 @code{make SHELL="/bin/bash -vx"} can help debug complex rules.
12127 @xref{The Make Macro SHELL,,, autoconf, The Autoconf Manual}, for some
12128 portability quirks associated with this construct.
12129 @item
12130 @code{echo 'print: ; @@echo "$(VAR)"' | make -f Makefile -f - print}
12131 can be handy to examine the expanded value of variables.  You may need
12132 to use a target other than @samp{print} if that is already used or a
12133 file with that name exists.
12134 @item
12135 @url{http://bashdb.sourceforge.net/@/remake/} provides a modified
12136 GNU @command{make} command called @command{remake} that copes with
12137 complex GNU @command{make}-specific Makefiles and allows to trace
12138 execution, examine variables, and call rules interactively, much like
12139 a debugger.
12140 @end itemize
12141
12142
12143 @node Reporting Bugs
12144 @section Reporting Bugs
12145
12146 Most nontrivial software has bugs.  Automake is no exception.  Although
12147 we cannot promise we can or will fix a bug, and we might not even agree
12148 that it is a bug, we want to hear about problems you encounter. Often we
12149 agree they are bugs and want to fix them.
12150
12151 To make it possible for us to fix a bug, please report it. In order to
12152 do so effectively, it helps to know when and how to do it.
12153
12154 Before reporting a bug, it is a good idea to see if it is already known.
12155 You can look at the @uref{http://debbugs.gnu.org/, GNU Bug Tracker}
12156 and the @uref{http://lists.gnu.org/@/archive/@/html/@/bug-automake/,
12157 bug-automake mailing list archives} for previous bug reports.  We
12158 previously used a
12159 @uref{http://sourceware.org/@/cgi-bin/@/gnatsweb.pl?database=automake,
12160 Gnats database} for bug tracking, so some bugs might have been reported
12161 there already.  Please do not use it for new bug reports, however.
12162
12163 If the bug is not already known, it should be reported.  It is very
12164 important to report bugs in a way that is useful and efficient.  For
12165 this, please familiarize yourself with
12166 @uref{http://www.chiark.greenend.org.uk/@/~sgtatham/@/bugs.html, How to
12167 Report Bugs Effectively} and
12168 @uref{http://catb.org/@/~esr/@/faqs/@/smart-questions.html, How to Ask
12169 Questions the Smart Way}.  This helps you and developers to save time
12170 which can then be spent on fixing more bugs and implementing more
12171 features.
12172
12173 For a bug report, a feature request or other suggestions, please send
12174 email to @email{@value{PACKAGE_BUGREPORT}}.  This will then open a new
12175 bug in the @uref{http://debbugs.gnu.org/@/automake, bug tracker}.  Be
12176 sure to include the versions of Autoconf and Automake that you use.
12177 Ideally, post a minimal @file{Makefile.am} and @file{configure.ac} that
12178 reproduces the problem you encounter.  If you have encountered test
12179 suite failures, please attach the @file{tests/test-suite.log} file.
12180
12181
12182 @node History
12183 @chapter History of Automake
12184
12185 This chapter presents various aspects of the history of Automake.  The
12186 exhausted reader can safely skip it; this will be more of interest to
12187 nostalgic people, or to those curious to learn about the evolution of
12188 Automake.
12189
12190 @menu
12191 * Timeline::                    The Automake story.
12192 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
12193 * Releases::                    Statistics about Automake Releases
12194 @end menu
12195
12196 @node Timeline
12197 @section Timeline
12198
12199 @table @asis
12200 @item 1994-09-19 First CVS commit.
12201
12202 If we can trust the CVS repository, David J.@tie{}MacKenzie (djm) started
12203 working on Automake (or AutoMake, as it was spelt then) this Monday.
12204
12205 The first version of the @command{automake} script looks as follows.
12206
12207 @example
12208 #!/bin/sh
12209
12210 status=0
12211
12212 for makefile
12213 do
12214   if test ! -f $@{makefile@}.am; then
12215     echo "automake: $@{makefile@}.am: No such honkin' file"
12216     status=1
12217     continue
12218   fi
12219
12220   exec 4> $@{makefile@}.in
12221
12222 done
12223 @end example
12224
12225 From this you can already see that Automake will be about reading
12226 @file{*.am} file and producing @file{*.in} files.  You cannot see
12227 anything else, but if you also know that David is the one who created
12228 Autoconf two years before you can guess the rest.
12229
12230 Several commits follow, and by the end of the day Automake is
12231 reported to work for GNU fileutils and GNU m4.
12232
12233 The modus operandi is the one that is still used today: variable
12234 assignments in @file{Makefile.am} files trigger injections of
12235 precanned @file{Makefile} fragments into the generated
12236 @file{Makefile.in}.  The use of @file{Makefile} fragments was inspired
12237 by the 4.4BSD @command{make} and include files, however Automake aims
12238 to be portable and to conform to the GNU standards for @file{Makefile}
12239 variables and targets.
12240
12241 At this point, the most recent release of Autoconf is version 1.11,
12242 and David is preparing to release Autoconf 2.0 in late October.  As a
12243 matter of fact, he will barely touch Automake after September.
12244
12245 @item 1994-11-05 David MacKenzie's last commit.
12246
12247 At this point Automake is a 200 line portable shell script, plus 332
12248 lines of @file{Makefile} fragments.  In the @file{README}, David
12249 states his ambivalence between ``portable shell'' and ``more
12250 appropriate language'':
12251
12252 @quotation
12253 I wrote it keeping in mind the possibility of it becoming an Autoconf
12254 macro, so it would run at configure-time.  That would slow
12255 configuration down a bit, but allow users to modify the Makefile.am
12256 without needing to fetch the AutoMake package.  And, the Makefile.in
12257 files wouldn't need to be distributed.  But all of AutoMake would.  So
12258 I might reimplement AutoMake in Perl, m4, or some other more
12259 appropriate language.
12260 @end quotation
12261
12262 Automake is described as ``an experimental Makefile generator''.
12263 There is no documentation.  Adventurous users are referred to the
12264 examples and patches needed to use Automake with GNU m4 1.3, fileutils
12265 3.9, time 1.6, and development versions of find and indent.
12266
12267 These examples seem to have been lost.  However at the time of writing
12268 (10 years later in September, 2004) the FSF still distributes a
12269 package that uses this version of Automake: check out GNU termutils
12270 2.0.
12271
12272 @item 1995-11-12 Tom Tromey's first commit.
12273
12274 After one year of inactivity, Tom Tromey takes over the package.
12275 Tom was working on GNU cpio back then, and doing this just for fun,
12276 having trouble finding a project to contribute to.  So while hacking
12277 he wanted to bring the @file{Makefile.in} up to GNU standards.  This
12278 was hard, and one day he saw Automake on @url{ftp://alpha.gnu.org/},
12279 grabbed it and tried it out.
12280
12281 Tom didn't talk to djm about it until later, just to make sure he
12282 didn't mind if he made a release.  He did a bunch of early releases to
12283 the Gnits folks.
12284
12285 Gnits was (and still is) totally informal, just a few GNU friends who
12286 Fran@,cois Pinard knew, who were all interested in making a common
12287 infrastructure for GNU projects, and shared a similar outlook on how
12288 to do it.  So they were able to make some progress.  It came along
12289 with Autoconf and extensions thereof, and then Automake from David and
12290 Tom (who were both gnitsians).  One of their ideas was to write a
12291 document paralleling the GNU standards, that was more strict in some
12292 ways and more detailed.  They never finished the GNITS standards, but
12293 the ideas mostly made their way into Automake.
12294
12295 @item 1995-11-23 Automake 0.20
12296
12297 Besides introducing automatic dependency tracking (@pxref{Dependency
12298 Tracking Evolution}), this version also supplies a 9-page manual.
12299
12300 At this time @command{aclocal} and @code{AM_INIT_AUTOMAKE} did not
12301 exist, so many things had to be done by hand.  For instance, here is
12302 what a configure.in (this is the former name of the
12303 @file{configure.ac} we use today) must contain in order to use
12304 Automake 0.20:
12305
12306 @example
12307 PACKAGE=cpio
12308 VERSION=2.3.911
12309 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
12310 AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
12311 AC_SUBST(PACKAGE)
12312 AC_SUBST(VERSION)
12313 AC_ARG_PROGRAM
12314 AC_PROG_INSTALL
12315 @end example
12316
12317 (Today all of the above is achieved by @code{AC_INIT} and
12318 @code{AM_INIT_AUTOMAKE}.)
12319
12320 Here is how programs are specified in @file{Makefile.am}:
12321
12322 @example
12323 PROGRAMS = hello
12324 hello_SOURCES = hello.c
12325 @end example
12326
12327 This looks pretty much like what we do today, except the
12328 @code{PROGRAMS} variable has no directory prefix specifying where
12329 @file{hello} should be installed: all programs are installed in
12330 @samp{$(bindir)}.  @code{LIBPROGRAMS} can be used to specify programs
12331 that must be built but not installed (it is called
12332 @code{noinst_PROGRAMS} nowadays).
12333
12334 Programs can be built conditionally using @code{AC_SUBST}itutions:
12335
12336 @example
12337 PROGRAMS = @@progs@@
12338 AM_PROGRAMS = foo bar baz
12339 @end example
12340
12341 (@code{AM_PROGRAMS} has since then been renamed to
12342 @code{EXTRA_PROGRAMS}.)
12343
12344 Similarly scripts, static libraries, and data can be built and installed
12345 using the @code{LIBRARIES}, @code{SCRIPTS}, and @code{DATA} variables.
12346 However @code{LIBRARIES} were treated a bit specially in that Automake
12347 did automatically supply the @file{lib} and @file{.a} prefixes.
12348 Therefore to build @file{libcpio.a}, one had to write
12349
12350 @example
12351 LIBRARIES = cpio
12352 cpio_SOURCES = ...
12353 @end example
12354
12355 Extra files to distribute must be listed in @code{DIST_OTHER} (the
12356 ancestor of @code{EXTRA_DIST}).  Also extra directories that are to be
12357 distributed should appear in @code{DIST_SUBDIRS}, but the manual
12358 describes this as a temporary ugly hack (today extra directories should
12359 also be listed in @code{EXTRA_DIST}, and @code{DIST_SUBDIRS} is used
12360 for another purpose, @pxref{Conditional Subdirectories}).
12361
12362 @item 1995-11-26 Automake 0.21
12363
12364 In less time than it takes to cook a frozen pizza, Tom rewrites
12365 Automake using Perl.  At this time Perl 5 is only one year old, and
12366 Perl 4.036 is in use at many sites.  Supporting several Perl versions
12367 has been a source of problems through the whole history of Automake.
12368
12369 If you never used Perl 4, imagine Perl 5 without objects, without
12370 @samp{my} variables (only dynamically scoped @samp{local} variables),
12371 without function prototypes, with function calls that needs to be
12372 prefixed with @samp{&}, etc.  Traces of this old style can still be
12373 found in today's @command{automake}.
12374
12375 @item 1995-11-28 Automake 0.22
12376 @itemx 1995-11-29 Automake 0.23
12377
12378 Bug fixes.
12379
12380 @item 1995-12-08 Automake 0.24
12381 @itemx 1995-12-10 Automake 0.25
12382
12383 Releases are raining.  0.24 introduces the uniform naming scheme we
12384 use today, i.e., @code{bin_PROGRAMS} instead of @code{PROGRAMS},
12385 @code{noinst_LIBRARIES} instead of @code{LIBLIBRARIES}, etc.  (However
12386 @code{EXTRA_PROGRAMS} does not exist yet, @code{AM_PROGRAMS} is still
12387 in use; and @code{TEXINFOS} and @code{MANS} still have no directory
12388 prefixes.)  Adding support for prefixes like that was one of the major
12389 ideas in @command{automake}; it has lasted pretty well.
12390
12391 AutoMake is renamed to Automake (Tom seems to recall it was Fran@,cois
12392 Pinard's doing).
12393
12394 0.25 fixes a Perl 4 portability bug.
12395
12396 @item 1995-12-18 Jim Meyering starts using Automake in GNU Textutils.
12397 @item 1995-12-31 Fran@,cois Pinard starts using Automake in GNU tar.
12398
12399 @item 1996-01-03 Automake 0.26
12400 @itemx 1996-01-03 Automake 0.27
12401
12402 Of the many changes and suggestions sent by Fran@,cois Pinard and
12403 included in 0.26, perhaps the most important is the advice that to
12404 ease customization a user rule or variable definition should always
12405 override an Automake rule or definition.
12406
12407 Gordon Matzigkeit and Jim Meyering are two other early contributors
12408 that have been sending fixes.
12409
12410 0.27 fixes yet another Perl 4 portability bug.
12411
12412 @item 1996-01-13 Automake 0.28
12413
12414 Automake starts scanning @file{configure.in} for @code{LIBOBJS}
12415 support.  This is an important step because until this version
12416 Automake only knew about the @file{Makefile.am}s it processed.
12417 @file{configure.in} was Autoconf's world and the link between Autoconf
12418 and Automake had to be done by the @file{Makefile.am} author.  For
12419 instance, if @file{config.h} was generated by @file{configure}, it was the
12420 package maintainer's responsibility to define the @code{CONFIG_HEADER}
12421 variable in each @file{Makefile.am}.
12422
12423 Succeeding releases will rely more and more on scanning
12424 @file{configure.in} to better automate the Autoconf integration.
12425
12426 0.28 also introduces the @code{AUTOMAKE_OPTIONS} variable and the
12427 @option{--gnu} and @option{--gnits} options, the latter being stricter.
12428
12429 @item 1996-02-07 Automake 0.29
12430
12431 Thanks to @file{configure.in} scanning, @code{CONFIG_HEADER} is gone,
12432 and rebuild rules for @file{configure}-generated file are
12433 automatically output.
12434
12435 @code{TEXINFOS} and @code{MANS} converted to the uniform naming
12436 scheme.
12437
12438 @item 1996-02-24 Automake 0.30
12439
12440 The test suite is born.  It contains 9 tests.  From now on test cases
12441 will be added pretty regularly (@pxref{Releases}), and this proved to
12442 be really helpful later on.
12443
12444 @code{EXTRA_PROGRAMS} finally replaces @code{AM_PROGRAMS}.
12445
12446 All the third-party Autoconf macros, written mostly by Fran@,cois
12447 Pinard (and later Jim Meyering), are distributed in Automake's
12448 hand-written @file{aclocal.m4} file.  Package maintainers are expected
12449 to extract the necessary macros from this file.  (In previous versions
12450 you had to copy and paste them from the manual...)
12451
12452 @item 1996-03-11 Automake 0.31
12453
12454 The test suite in 0.30 was run via a long @code{check-local} rule.  Upon
12455 Ulrich Drepper's suggestion, 0.31 makes it an Automake rule output
12456 whenever the @code{TESTS} variable is defined.
12457
12458 @code{DIST_OTHER} is renamed to @code{EXTRA_DIST}, and the @code{check_}
12459 prefix is introduced.  The syntax is now the same as today.
12460
12461 @item 1996-03-15 Gordon Matzigkeit starts writing libtool.
12462
12463 @item 1996-04-27 Automake 0.32
12464
12465 @code{-hook} targets are introduced; an idea from Dieter Baron.
12466
12467 @file{*.info} files, which were output in the build directory are
12468 now built in the source directory, because they are distributed.  It
12469 seems these files like to move back and forth as that will happen
12470 again in future versions.
12471
12472 @item 1996-05-18 Automake 0.33
12473
12474 Gord Matzigkeit's main two contributions:
12475
12476 @itemize
12477 @item very preliminary libtool support
12478 @item the distcheck rule
12479 @end itemize
12480
12481 Although they were very basic at this point, these are probably
12482 among the top features for Automake today.
12483
12484 Jim Meyering also provides the infamous @code{jm_MAINTAINER_MODE},
12485 since then renamed to @code{AM_MAINTAINER_MODE} and abandoned by its
12486 author (@pxref{maintainer-mode}).
12487
12488 @item 1996-05-28 Automake 1.0
12489
12490 After only six months of heavy development, the @command{automake} script is
12491 3134 lines long, plus 973 lines of @file{Makefile} fragments.  The
12492 package has 30 pages of documentation, and 38 test cases.
12493 @file{aclocal.m4} contains 4 macros.
12494
12495 From now on and until version 1.4, new releases will occur at a rate
12496 of about one a year.  1.1 did not exist, actually 1.1b to 1.1p have
12497 been the name of beta releases for 1.2.  This is the first time
12498 Automake uses suffix letters to designate beta releases, a habit that
12499 lasts.
12500
12501 @item 1996-10-10 Kevin Dalley packages Automake 1.0 for Debian GNU/Linux.
12502
12503 @item 1996-11-26 David J.@tie{}MacKenzie releases Autoconf 2.12.
12504
12505 Between June and October, the Autoconf development is almost stalled.
12506 Roland McGrath has been working at the beginning of the year.  David
12507 comes back in November to release 2.12, but he won't touch Autoconf
12508 anymore after this year, and Autoconf then really stagnates.  The
12509 desolate Autoconf @file{ChangeLog} for 1997 lists only 7 commits.
12510
12511 @item 1997-02-28 @email{automake@@gnu.ai.mit.edu} list alive
12512
12513 The mailing list is announced as follows:
12514 @smallexample
12515 I've created the "automake" mailing list.  It is
12516 "automake@@gnu.ai.mit.edu".  Administrivia, as always, to
12517 automake-request@@gnu.ai.mit.edu.
12518
12519 The charter of this list is discussion of automake, autoconf, and
12520 other configuration/portability tools (e.g., libtool).  It is expected
12521 that discussion will range from pleas for help all the way up to
12522 patches.
12523
12524 This list is archived on the FSF machines.  Offhand I don't know if
12525 you can get the archive without an account there.
12526
12527 This list is open to anybody who wants to join.  Tell all your
12528 friends!
12529 -- Tom Tromey
12530 @end smallexample
12531
12532 Before that people were discussing Automake privately, on the Gnits
12533 mailing list (which is not public either), and less frequently on
12534 @code{gnu.misc.discuss}.
12535
12536 @code{gnu.ai.mit.edu} is now @code{gnu.org}, in case you never
12537 noticed.  The archives of the early years of the
12538 @code{automake@@gnu.org} list have been lost, so today it is almost
12539 impossible to find traces of discussions that occurred before 1999.
12540 This has been annoying more than once, as such discussions can be
12541 useful to understand the rationale behind a piece of uncommented code
12542 that was introduced back then.
12543
12544 @item 1997-06-22 Automake 1.2
12545
12546 Automake developments continues, and more and more new Autoconf macros
12547 are required.  Distributing them in @file{aclocal.m4} and requiring
12548 people to browse this file to extract the relevant macros becomes
12549 uncomfortable.  Ideally, some of them should be contributed to
12550 Autoconf so that they can be used directly, however Autoconf is
12551 currently inactive.  Automake 1.2 consequently introduces
12552 @command{aclocal} (@command{aclocal} was actually started on
12553 1996-07-28), a tool that automatically constructs an @file{aclocal.m4}
12554 file from a repository of third-party macros.  Because Autoconf has
12555 stalled, Automake also becomes a kind of repository for such
12556 third-party macros, even macros completely unrelated to Automake (for
12557 instance macros that fix broken Autoconf macros).
12558
12559 The 1.2 release contains 20 macros, including the
12560 @code{AM_INIT_AUTOMAKE} macro that simplifies the creation of
12561 @file{configure.in}.
12562
12563 Libtool is fully supported using @code{*_LTLIBRARIES}.
12564
12565 The missing script is introduced by Fran@,cois Pinard; it is meant to be
12566 a better solution than @code{AM_MAINTAINER_MODE}
12567 (@pxref{maintainer-mode}).
12568
12569 Conditionals support was implemented by Ian Lance Taylor.  At the
12570 time, Tom and Ian were working on an internal project at Cygnus.  They
12571 were using ILU, which is pretty similar to CORBA@.  They wanted to
12572 integrate ILU into their build, which was all @file{configure}-based,
12573 and Ian thought that adding conditionals to @command{automake} was
12574 simpler than doing all the work in @file{configure} (which was the
12575 standard at the time).  So this was actually funded by Cygnus.
12576
12577 This very useful but tricky feature will take a lot of time to
12578 stabilize.  (At the time this text is written, there are still
12579 primaries that have not been updated to support conditional
12580 definitions in Automake 1.9.)
12581
12582 The @command{automake} script has almost doubled: 6089 lines of Perl,
12583 plus 1294 lines of @file{Makefile} fragments.
12584
12585 @item 1997-07-08 Gordon Matzigkeit releases Libtool 1.0.
12586
12587 @item 1998-04-05 Automake 1.3
12588
12589 This is a small advance compared to 1.2.
12590 It adds support for assembly, and preliminary support for Java.
12591
12592 Perl 5.004_04 is out, but fixes to support Perl 4 are still
12593 regularly submitted whenever Automake breaks it.
12594
12595 @item 1998-09-06 @code{sourceware.cygnus.com} is on-line.
12596
12597 Sourceware was setup by Jason Molenda to host open source projects.
12598
12599 @item 1998-09-19  Automake CVS repository moved to @code{sourceware.cygnus.com}
12600 @itemx 1998-10-26  @code{sourceware.cygnus.com} announces it hosts Automake:
12601 Automake is now hosted on @code{sourceware.cygnus.com}.  It has a
12602 publicly accessible CVS repository.  This CVS repository is a copy of
12603 the one Tom was using on his machine, which in turn is based on
12604 a copy of the CVS repository of David MacKenzie.  This is why we still
12605 have to full source history.  (Automake was on Sourceware until 2007-10-29,
12606 when it moved to a git repository on @code{savannah.gnu.org},
12607 but the Sourceware host had been renamed to @code{sources.redhat.com}.)
12608
12609 The oldest file in the administrative directory of the CVS repository
12610 that was created on Sourceware is dated 1998-09-19, while the
12611 announcement that @command{automake} and @command{autoconf} had joined
12612 @command{sourceware} was made on 1998-10-26.  They were among the
12613 first projects to be hosted there.
12614
12615 The heedful reader will have noticed Automake was exactly 4 years old
12616 on 1998-09-19.
12617
12618 @item 1999-01-05 Ben Elliston releases Autoconf 2.13.
12619
12620 @item 1999-01-14 Automake 1.4
12621
12622 This release adds support for Fortran 77 and for the @code{include}
12623 statement.  Also, @samp{+=} assignments are introduced, but it is
12624 still quite easy to fool Automake when mixing this with conditionals.
12625
12626 These two releases, Automake 1.4 and Autoconf 2.13 make a duo that
12627 will be used together for years.
12628
12629 @command{automake} is 7228 lines, plus 1591 lines of Makefile
12630 fragment, 20 macros (some 1.3 macros were finally contributed back to
12631 Autoconf), 197 test cases, and 51 pages of documentation.
12632
12633 @item 1999-03-27 The @code{user-dep-branch} is created on the CVS repository.
12634
12635 This implements a new dependency tracking schemed that should be
12636 able to handle automatic dependency tracking using any compiler (not
12637 just gcc) and any make (not just GNU @command{make}).  In addition,
12638 the new scheme should be more reliable than the old one, as
12639 dependencies are generated on the end user's machine.  Alexandre Oliva
12640 creates depcomp for this purpose.
12641
12642 @xref{Dependency Tracking Evolution}, for more details about the
12643 evolution of automatic dependency tracking in Automake.
12644
12645 @item 1999-11-21 The @code{user-dep-branch} is merged into the main trunk.
12646
12647 This was a huge problem since we also had patches going in on the
12648 trunk.  The merge took a long time and was very painful.
12649
12650 @item 2000-05-10
12651
12652 Since September 1999 and until 2003, Akim Demaille will be zealously
12653 revamping Autoconf.
12654
12655 @quotation
12656 I think the next release should be called "3.0".@*
12657 Let's face it: you've basically rewritten autoconf.@*
12658 Every weekend there are 30 new patches.@*
12659 I don't see how we could call this "2.15" with a straight face.@*
12660 -- Tom Tromey on @email{autoconf@@gnu.org}
12661 @end quotation
12662
12663 Actually Akim works like a submarine: he will pile up patches while he
12664 works off-line during the weekend, and flush them in batch when he
12665 resurfaces on Monday.
12666
12667 @item 2001-01-24
12668
12669 On this Wednesday, Autoconf 2.49c, the last beta before Autoconf 2.50
12670 is out, and Akim has to find something to do during his week-end :)
12671
12672 @item 2001-01-28
12673
12674 Akim sends a batch of 14 patches to @email{automake@@gnu.org}.
12675
12676 @quotation
12677 Aiieeee!  I was dreading the day that the Demaillator turned his
12678 sights on automake@dots{} and now it has arrived! -- Tom Tromey
12679 @end quotation
12680
12681 It's only the beginning: in two months he will send 192 patches.  Then
12682 he would slow down so Tom can catch up and review all this.  Initially
12683 Tom actually read all these patches, then he probably trustingly
12684 answered OK to most of them, and finally gave up and let Akim apply
12685 whatever he wanted.  There was no way to keep up with that patch rate.
12686
12687 @quotation
12688 Anyway the patch below won't apply since it predates Akim's
12689 sourcequake; I have yet to figure where the relevant passage has
12690 been moved :) -- Alexandre Duret-Lutz
12691 @end quotation
12692
12693 All these patches were sent to and discussed on
12694 @email{automake@@gnu.org}, so subscribed users were literally drowning in
12695 technical mails.  Eventually, the @email{automake-patches@@gnu.org}
12696 mailing list was created in May.
12697
12698 Year after year, Automake had drifted away from its initial design:
12699 construct @file{Makefile.in} by assembling various @file{Makefile}
12700 fragments.  In 1.4, lots of @file{Makefile} rules are being emitted at
12701 various places in the @command{automake} script itself; this does not
12702 help ensuring a consistent treatment of these rules (for instance
12703 making sure that user-defined rules override Automake's own rules).
12704 One of Akim's goal was moving all these hard-coded rules to separate
12705 @file{Makefile} fragments, so the logic could be centralized in a
12706 @file{Makefile} fragment processor.
12707
12708 Another significant contribution of Akim is the interface with the
12709 ``trace'' feature of Autoconf.  The way to scan @file{configure.in} at
12710 this time was to read the file and grep the various macro of interest
12711 to Automake.  Doing so could break in many unexpected ways; @command{automake}
12712 could miss some definition (for instance @samp{AC_SUBST([$1], [$2])}
12713 where the arguments are known only when M4 is run), or conversely it
12714 could detect some macro that was not expanded (because it is called
12715 conditionally).  In the CVS version of Autoconf, Akim had implemented
12716 the @option{--trace} option, which provides accurate information about
12717 where macros are actually called and with what arguments.  Akim will
12718 equip Automake with a second @file{configure.in} scanner that uses
12719 this @option{--trace} interface.  Since it was not sensible to drop the
12720 Autoconf 2.13 compatibility yet, this experimental scanner was only
12721 used when an environment variable was set, the traditional
12722 grep-scanner being still the default.
12723
12724 @item 2001-04-25 Gary V.@tie{}Vaughan releases Libtool 1.4
12725
12726 It has been more than two years since Automake 1.4, CVS Automake has
12727 suffered lot's of heavy changes and still is not ready for release.
12728 Libtool 1.4 had to be distributed with a patch against Automake 1.4.
12729
12730 @item 2001-05-08 Automake 1.4-p1
12731 @itemx 2001-05-24 Automake 1.4-p2
12732
12733 Gary V.@tie{}Vaughan, the principal Libtool maintainer, makes a ``patch
12734 release'' of Automake:
12735
12736 @quotation
12737 The main purpose of this release is to have a stable automake
12738 which is compatible with the latest stable libtool.
12739 @end quotation
12740
12741 The release also contains obvious fixes for bugs in Automake 1.4,
12742 some of which were reported almost monthly.
12743
12744 @item 2001-05-21 Akim Demaille releases Autoconf 2.50
12745
12746 @item 2001-06-07 Automake 1.4-p3
12747 @itemx 2001-06-10 Automake 1.4-p4
12748 @itemx 2001-07-15 Automake 1.4-p5
12749
12750 Gary continues his patch-release series.  These also add support for
12751 some new Autoconf 2.50 idioms.  Essentially, Autoconf now advocates
12752 @file{configure.ac} over @file{configure.in}, and it introduces a new
12753 syntax for @code{AC_OUTPUT}ing files.
12754
12755 @item 2001-08-23 Automake 1.5
12756
12757 A major and long-awaited release, that comes more than two years after
12758 1.4.  It brings many changes, among which:
12759 @itemize
12760 @item The new dependency tracking scheme that uses @command{depcomp}.
12761 Aside from the improvement on the dependency tracking itself
12762 (@pxref{Dependency Tracking Evolution}), this also streamlines the use
12763 of @command{automake}-generated @file{Makefile.in}s as the @file{Makefile.in}s
12764 used during development are now the same as those used in
12765 distributions.  Before that the @file{Makefile.in}s generated for
12766 maintainers required GNU @command{make} and GCC, they were different
12767 from the portable @file{Makefile} generated for distribution; this was
12768 causing some confusion.
12769
12770 @item Support for per-target compilation flags.
12771
12772 @item Support for reference to files in subdirectories in most
12773 @file{Makefile.am} variables.
12774
12775 @item Introduction of the @code{dist_}, @code{nodist_}, and @code{nobase_}
12776 prefixes.
12777 @item Perl 4 support is finally dropped.
12778 @end itemize
12779
12780 1.5 did break several packages that worked with 1.4.  Enough so that
12781 Linux distributions could not easily install the new Automake version
12782 without breaking many of the packages for which they had to run
12783 @command{automake}.
12784
12785 Some of these breakages were effectively bugs that would eventually be
12786 fixed in the next release.  However, a lot of damage was caused by
12787 some changes made deliberately to render Automake stricter on some
12788 setup we did consider bogus.  For instance, @samp{make distcheck} was
12789 improved to check that @samp{make uninstall} did remove all the files
12790 @samp{make install} installed, that @samp{make distclean} did not omit
12791 some file, and that a VPATH build would work even if the source
12792 directory was read-only.  Similarly, Automake now rejects multiple
12793 definitions of the same variable (because that would mix very badly
12794 with conditionals), and @samp{+=} assignments with no previous
12795 definition.  Because these changes all occurred suddenly after 1.4 had
12796 been established for more than two years, it hurt users.
12797
12798 To make matter worse, meanwhile Autoconf (now at version 2.52) was
12799 facing similar troubles, for similar reasons.
12800
12801 @item 2002-03-05 Automake 1.6
12802
12803 This release introduced versioned installation (@pxref{API
12804 Versioning}).  This was mainly pushed by Havoc Pennington, taking the
12805 GNOME source tree as motive: due to incompatibilities between the
12806 autotools it's impossible for the GNOME packages to switch to Autoconf
12807 2.53 and Automake 1.5 all at once, so they are currently stuck with
12808 Autoconf 2.13 and Automake 1.4.
12809
12810 The idea was to call this version @file{automake-1.6}, call all its
12811 bug-fix versions identically, and switch to @file{automake-1.7} for
12812 the next release that adds new features or changes some rules.  This
12813 scheme implies maintaining a bug-fix branch in addition to the
12814 development trunk, which means more work from the maintainer, but
12815 providing regular bug-fix releases proved to be really worthwhile.
12816
12817 Like 1.5, 1.6 also introduced a bunch of incompatibilities, intentional or
12818 not.  Perhaps the more annoying was the dependence on the newly
12819 released Autoconf 2.53.  Autoconf seemed to have stabilized enough
12820 since its explosive 2.50 release and included changes required to fix
12821 some bugs in Automake.  In order to upgrade to Automake 1.6, people
12822 now had to upgrade Autoconf too; for some packages it was no picnic.
12823
12824 While versioned installation helped people to upgrade, it also
12825 unfortunately allowed people not to upgrade.  At the time of writing,
12826 some Linux distributions are shipping packages for Automake 1.4, 1.5,
12827 1.6, 1.7, 1.8, and 1.9.  Most of these still install 1.4 by default.
12828 Some distribution also call 1.4 the ``stable'' version, and present
12829 ``1.9'' as the development version; this does not really makes sense
12830 since 1.9 is way more solid than 1.4.  All this does not help the
12831 newcomer.
12832
12833 @item 2002-04-11 Automake 1.6.1
12834
12835 1.6, and the upcoming 1.4-p6 release were the last release by Tom.
12836 This one and those following will be handled by Alexandre
12837 Duret-Lutz.  Tom is still around, and will be there until about 1.7,
12838 but his interest into Automake is drifting away towards projects like
12839 @command{gcj}.
12840
12841 Alexandre has been using Automake since 2000, and started to
12842 contribute mostly on Akim's incitement (Akim and Alexandre have been
12843 working in the same room from 1999 to 2002).  In 2001 and 2002 he had
12844 a lot of free time to enjoy hacking Automake.
12845
12846 @item 2002-06-14 Automake 1.6.2
12847
12848 @item 2002-07-28 Automake 1.6.3
12849 @itemx 2002-07-28 Automake 1.4-p6
12850
12851 Two releases on the same day.  1.6.3 is a bug-fix release.
12852
12853 Tom Tromey backported the versioned installation mechanism on the 1.4
12854 branch, so that Automake 1.6.x and Automake 1.4-p6 could be installed
12855 side by side.  Another request from the GNOME folks.
12856
12857 @item 2002-09-25 Automake 1.7
12858
12859 This release switches to the new @file{configure.ac} scanner Akim
12860 was experimenting in 1.5.
12861
12862 @item 2002-10-16 Automake 1.7.1
12863 @itemx 2002-12-06 Automake 1.7.2
12864 @itemx 2003-02-20 Automake 1.7.3
12865 @itemx 2003-04-23 Automake 1.7.4
12866 @itemx 2003-05-18 Automake 1.7.5
12867 @itemx 2003-07-10 Automake 1.7.6
12868 @itemx 2003-09-07 Automake 1.7.7
12869 @itemx 2003-10-07 Automake 1.7.8
12870
12871 Many bug-fix releases.  1.7 lasted because the development version
12872 (upcoming 1.8) was suffering some major internal revamping.
12873
12874 @item 2003-10-26 Automake on screen
12875
12876 Episode 49, `Repercussions', in the third season of the `Alias' TV
12877 show is first aired.
12878
12879 Marshall, one of the characters, is working on a computer virus that he
12880 has to modify before it gets into the wrong hands or something like
12881 that.  The screenshots you see do not show any program code, they show
12882 a @file{Makefile.in} @code{generated by automake}...
12883
12884 @item 2003-11-09 Automake 1.7.9
12885
12886 @item 2003-12-10 Automake 1.8
12887
12888 The most striking update is probably that of @command{aclocal}.
12889
12890 @command{aclocal} now uses @code{m4_include} in the produced
12891 @file{aclocal.m4} when the included macros are already distributed
12892 with the package (an idiom used in many packages), which reduces code
12893 duplication.  Many people liked that, but in fact this change was
12894 really introduced to fix a bug in rebuild rules: @file{Makefile.in}
12895 must be rebuilt whenever a dependency of @file{configure} changes, but
12896 all the @file{m4} files included in @file{aclocal.m4} where unknown
12897 from @command{automake}.  Now @command{automake} can just trace the
12898 @code{m4_include}s to discover the dependencies.
12899
12900 @command{aclocal} also starts using the @option{--trace} Autoconf option
12901 in order to discover used macros more accurately.  This will turn out
12902 to be very tricky (later releases will improve this) as people had
12903 devised many ways to cope with the limitation of previous
12904 @command{aclocal} versions, notably using handwritten
12905 @code{m4_include}s: @command{aclocal} must make sure not to redefine a
12906 rule that is already included by such statement.
12907
12908 Automake also has seen its guts rewritten.  Although this rewriting
12909 took a lot of efforts, it is only apparent to the users in that some
12910 constructions previously disallowed by the implementation now work
12911 nicely.  Conditionals, Locations, Variable and Rule definitions,
12912 Options: these items on which Automake works have been rewritten as
12913 separate Perl modules, and documented.
12914
12915 @itemx 2004-01-11 Automake 1.8.1
12916 @itemx 2004-01-12 Automake 1.8.2
12917 @itemx 2004-03-07 Automake 1.8.3
12918 @itemx 2004-04-25 Automake 1.8.4
12919 @itemx 2004-05-16 Automake 1.8.5
12920
12921 @item 2004-07-28 Automake 1.9
12922
12923 This release tries to simplify the compilation rules it outputs to
12924 reduce the size of the Makefile.  The complaint initially come from
12925 the libgcj developers.  Their @file{Makefile.in} generated with
12926 Automake 1.4 and custom build rules (1.4 did not support compiled
12927 Java) is 250KB@.  The one generated by 1.8 was over 9MB@!  1.9 gets it
12928 down to 1.2MB@.
12929
12930 Aside from this it contains mainly minor changes and bug-fixes.
12931
12932 @itemx 2004-08-11 Automake 1.9.1
12933 @itemx 2004-09-19 Automake 1.9.2
12934
12935 Automake has ten years.  This chapter of the manual was initially
12936 written for this occasion.
12937
12938 @itemx 2007-10-29 Automake repository moves to @code{savannah.gnu.org} and uses
12939 git as primary repository.
12940
12941 @end table
12942
12943 @node Dependency Tracking Evolution
12944 @section Dependency Tracking in Automake
12945
12946 Over the years Automake has deployed three different dependency
12947 tracking methods.  Each method, including the current one, has had
12948 flaws of various sorts.  Here we lay out the different dependency
12949 tracking methods, their flaws, and their fixes.  We conclude with
12950 recommendations for tool writers, and by indicating future directions
12951 for dependency tracking work in Automake.
12952
12953 @menu
12954 * First Take on Dependencies::  Precomputed dependency tracking
12955 * Dependencies As Side Effects::  Update at developer compile time
12956 * Dependencies for the User::   Update at user compile time
12957 * Techniques for Dependencies::  Alternative approaches
12958 * Recommendations for Tool Writers::  What tool writers can do to help
12959 * Future Directions for Dependencies::  Languages Automake does not know
12960 @end menu
12961
12962 @node First Take on Dependencies
12963 @subsection First Take on Dependency Tracking
12964 @unnumberedsubsubsec Description
12965
12966 Our first attempt at automatic dependency tracking was based on the
12967 method recommended by GNU @command{make}.  (@pxref{Automatic
12968 Prerequisites, , Generating Prerequisites Automatically, make, The GNU
12969 make Manual})
12970
12971 This version worked by precomputing dependencies ahead of time.  For
12972 each source file, it had a special @file{.P} file that held the
12973 dependencies.  There was a rule to generate a @file{.P} file by
12974 invoking the compiler appropriately.  All such @file{.P} files were
12975 included by the @file{Makefile}, thus implicitly becoming dependencies
12976 of @file{Makefile}.
12977
12978 @unnumberedsubsubsec Bugs
12979
12980 This approach had several critical bugs.
12981
12982 @itemize
12983 @item
12984 The code to generate the @file{.P} file relied on @command{gcc}.
12985 (A limitation, not technically a bug.)
12986 @item
12987 The dependency tracking mechanism itself relied on GNU @command{make}.
12988 (A limitation, not technically a bug.)
12989 @item
12990 Because each @file{.P} file was a dependency of @file{Makefile}, this
12991 meant that dependency tracking was done eagerly by @command{make}.
12992 For instance, @samp{make clean} would cause all the dependency files
12993 to be updated, and then immediately removed.  This eagerness also
12994 caused problems with some configurations; if a certain source file
12995 could not be compiled on a given architecture for some reason,
12996 dependency tracking would fail, aborting the entire build.
12997 @item
12998 As dependency tracking was done as a pre-pass, compile times were
12999 doubled--the compiler had to be run twice per source file.
13000 @item
13001 @samp{make dist} re-ran @command{automake} to generate a
13002 @file{Makefile} that did not have automatic dependency tracking (and
13003 that was thus portable to any version of @command{make}).  In order to
13004 do this portably, Automake had to scan the dependency files and remove
13005 any reference that was to a source file not in the distribution.
13006 This process was error-prone.  Also, if @samp{make dist} was run in an
13007 environment where some object file had a dependency on a source file
13008 that was only conditionally created, Automake would generate a
13009 @file{Makefile} that referred to a file that might not appear in the
13010 end user's build.  A special, hacky mechanism was required to work
13011 around this.
13012 @end itemize
13013
13014 @unnumberedsubsubsec Historical Note
13015
13016 The code generated by Automake is often inspired by the
13017 @file{Makefile} style of a particular author.  In the case of the first
13018 implementation of dependency tracking, I believe the impetus and
13019 inspiration was Jim Meyering.  (I could be mistaken.  If you know
13020 otherwise feel free to correct me.)
13021
13022 @node Dependencies As Side Effects
13023 @subsection Dependencies As Side Effects
13024 @unnumberedsubsubsec Description
13025
13026 The next refinement of Automake's automatic dependency tracking scheme
13027 was to implement dependencies as side effects of the compilation.
13028 This was aimed at solving the most commonly reported problems with the
13029 first approach.  In particular we were most concerned with eliminating
13030 the weird rebuilding effect associated with make clean.
13031
13032 In this approach, the @file{.P} files were included using the
13033 @code{-include} command, which let us create these files lazily.  This
13034 avoided the @samp{make clean} problem.
13035
13036 We only computed dependencies when a file was actually compiled.  This
13037 avoided the performance penalty associated with scanning each file
13038 twice.  It also let us avoid the other problems associated with the
13039 first, eager, implementation.  For instance, dependencies would never
13040 be generated for a source file that was not compilable on a given
13041 architecture (because it in fact would never be compiled).
13042
13043 @unnumberedsubsubsec Bugs
13044
13045 @itemize
13046 @item
13047 This approach also relied on the existence of @command{gcc} and GNU
13048 @command{make}.  (A limitation, not technically a bug.)
13049 @item
13050 Dependency tracking was still done by the developer, so the problems
13051 from the first implementation relating to massaging of dependencies by
13052 @samp{make dist} were still in effect.
13053 @item
13054 This implementation suffered from the ``deleted header file'' problem.
13055 Suppose a lazily-created @file{.P} file includes a dependency on a
13056 given header file, like this:
13057
13058 @example
13059 maude.o: maude.c something.h
13060 @end example
13061
13062 Now suppose that you remove @file{something.h} and update @file{maude.c}
13063 so that this include is no longer needed.  If you run @command{make},
13064 you will get an error because there is no way to create
13065 @file{something.h}.
13066
13067 We fixed this problem in a later release by further massaging the
13068 output of @command{gcc} to include a dummy dependency for each header
13069 file.
13070 @end itemize
13071
13072 @node Dependencies for the User
13073 @subsection Dependencies for the User
13074 @unnumberedsubsubsec Description
13075
13076 The bugs associated with @samp{make dist}, over time, became a real
13077 problem.  Packages using Automake were being built on a large number
13078 of platforms, and were becoming increasingly complex.  Broken
13079 dependencies were distributed in ``portable'' @file{Makefile.in}s,
13080 leading to user complaints.  Also, the requirement for @command{gcc}
13081 and GNU @command{make} was a constant source of bug reports.  The next
13082 implementation of dependency tracking aimed to remove these problems.
13083
13084 We realized that the only truly reliable way to automatically track
13085 dependencies was to do it when the package itself was built.  This
13086 meant discovering a method portable to any version of make and any
13087 compiler.  Also, we wanted to preserve what we saw as the best point
13088 of the second implementation: dependency computation as a side effect
13089 of compilation.
13090
13091 In the end we found that most modern make implementations support some
13092 form of include directive.  Also, we wrote a wrapper script that let
13093 us abstract away differences between dependency tracking methods for
13094 compilers.  For instance, some compilers cannot generate dependencies
13095 as a side effect of compilation.  In this case we simply have the
13096 script run the compiler twice.  Currently our wrapper script
13097 (@command{depcomp}) knows about twelve different compilers (including
13098 a "compiler" that simply invokes @command{makedepend} and then the
13099 real compiler, which is assumed to be a standard Unix-like C compiler
13100 with no way to do dependency tracking).
13101
13102 @unnumberedsubsubsec Bugs
13103
13104 @itemize
13105 @item
13106 Running a wrapper script for each compilation slows down the build.
13107 @item
13108 Many users don't really care about precise dependencies.
13109 @item
13110 This implementation, like every other automatic dependency tracking
13111 scheme in common use today (indeed, every one we've ever heard of),
13112 suffers from the ``duplicated new header'' bug.
13113
13114 This bug occurs because dependency tracking tools, such as the
13115 compiler, only generate dependencies on the successful opening of a
13116 file, and not on every probe.
13117
13118 Suppose for instance that the compiler searches three directories for
13119 a given header, and that the header is found in the third directory.
13120 If the programmer erroneously adds a header file with the same name to
13121 the first directory, then a clean rebuild from scratch could fail
13122 (suppose the new header file is buggy), whereas an incremental rebuild
13123 will succeed.
13124
13125 What has happened here is that people have a misunderstanding of what
13126 a dependency is.  Tool writers think a dependency encodes information
13127 about which files were read by the compiler.  However, a dependency
13128 must actually encode information about what the compiler tried to do.
13129
13130 This problem is not serious in practice.  Programmers typically do not
13131 use the same name for a header file twice in a given project.  (At
13132 least, not in C or C++.  This problem may be more troublesome in
13133 Java.)  This problem is easy to fix, by modifying dependency
13134 generators to record every probe, instead of every successful open.
13135
13136 @item
13137 Since Automake generates dependencies as a side effect of compilation,
13138 there is a bootstrapping problem when header files are generated by
13139 running a program.  The problem is that, the first time the build is
13140 done, there is no way by default to know that the headers are
13141 required, so make might try to run a compilation for which the headers
13142 have not yet been built.
13143
13144 This was also a problem in the previous dependency tracking implementation.
13145
13146 The current fix is to use @code{BUILT_SOURCES} to list built headers
13147 (@pxref{Sources}).  This causes them to be built before any other
13148 build rules are run.  This is unsatisfactory as a general solution,
13149 however in practice it seems sufficient for most actual programs.
13150 @end itemize
13151
13152 This code is used since Automake 1.5.
13153
13154 In GCC 3.0, we managed to convince the maintainers to add special
13155 command-line options to help Automake more efficiently do its job.  We
13156 hoped this would let us avoid the use of a wrapper script when
13157 Automake's automatic dependency tracking was used with @command{gcc}.
13158
13159 Unfortunately, this code doesn't quite do what we want.  In
13160 particular, it removes the dependency file if the compilation fails;
13161 we'd prefer that it instead only touch the file in any way if the
13162 compilation succeeds.
13163
13164 Nevertheless, since Automake 1.7, when a recent @command{gcc} is
13165 detected at @command{configure} time, we inline the
13166 dependency-generation code and do not use the @command{depcomp}
13167 wrapper script.  This makes compilations faster for those using this
13168 compiler (probably our primary user base).  The counterpart is that
13169 because we have to encode two compilation rules in @file{Makefile}
13170 (with or without @command{depcomp}), the produced @file{Makefile}s are
13171 larger.
13172
13173 @node Techniques for Dependencies
13174 @subsection Techniques for Computing Dependencies
13175
13176 There are actually several ways for a build tool like Automake to
13177 cause tools to generate dependencies.
13178
13179 @table @asis
13180 @item @command{makedepend}
13181 This was a commonly-used method in the past.  The idea is to run a
13182 special program over the source and have it generate dependency
13183 information.  Traditional implementations of @command{makedepend} are
13184 not completely precise; ordinarily they were conservative and
13185 discovered too many dependencies.
13186 @item The tool
13187 An obvious way to generate dependencies is to simply write the tool so
13188 that it can generate the information needed by the build tool.  This is
13189 also the most portable method.  Many compilers have an option to
13190 generate dependencies.  Unfortunately, not all tools provide such an
13191 option.
13192 @item The file system
13193 It is possible to write a special file system that tracks opens,
13194 reads, writes, etc, and then feed this information back to the build
13195 tool.  @command{clearmake} does this.  This is a very powerful
13196 technique, as it doesn't require cooperation from the
13197 tool.  Unfortunately it is also very difficult to implement and also
13198 not practical in the general case.
13199 @item @code{LD_PRELOAD}
13200 Rather than use the file system, one could write a special library to
13201 intercept @code{open} and other syscalls.  This technique is also quite
13202 powerful, but unfortunately it is not portable enough for use in
13203 @command{automake}.
13204 @end table
13205
13206 @node Recommendations for Tool Writers
13207 @subsection Recommendations for Tool Writers
13208
13209 We think that every compilation tool ought to be able to generate
13210 dependencies as a side effect of compilation.  Furthermore, at least
13211 while @command{make}-based tools are nearly universally in use (at
13212 least in the free software community), the tool itself should generate
13213 dummy dependencies for header files, to avoid the deleted header file
13214 bug.  Finally, the tool should generate a dependency for each probe,
13215 instead of each successful file open, in order to avoid the duplicated
13216 new header bug.
13217
13218 @node Future Directions for Dependencies
13219 @subsection Future Directions for Dependencies
13220
13221 Currently, only languages and compilers understood by Automake can
13222 have dependency tracking enabled.  We would like to see if it is
13223 practical (and worthwhile) to let this support be extended by the user
13224 to languages unknown to Automake.
13225
13226 @node Releases
13227 @section Release Statistics
13228
13229 The following table (inspired by @samp{perlhist(1)}) quantifies the
13230 evolution of Automake using these metrics:
13231
13232 @table @asis
13233 @item Date, Rel
13234 The date and version of the release.
13235 @item am
13236 The number of lines of the @command{automake} script.
13237 @item acl
13238 The number of lines of the @command{aclocal} script.
13239 @item pm
13240 The number of lines of the @command{Perl} supporting modules.
13241 @item @file{*.am}
13242 The number of lines of the @file{Makefile} fragments.  The number in
13243 parentheses is the number of files.
13244 @item m4
13245 The number of lines (and files) of Autoconf macros.
13246 @item doc
13247 The number of pages of the documentation (the Postscript version).
13248 @item t
13249 The number of test cases in the test suite.  Of those, the number in
13250 parentheses is the number of generated test cases.
13251 @end table
13252
13253 @multitable {8888-88-88} {8.8-p8} {8888} {8888} {8888} {8888 (88)} {8888 (88)} {888} {888 (88)}
13254 @headitem Date   @tab Rel    @tab   am @tab acl @tab   pm @tab @file{*.am} @tab m4 @tab doc @tab t
13255 @item 1994-09-19 @tab CVS    @tab  141 @tab     @tab      @tab  299 (24) @tab           @tab     @tab
13256 @item 1994-11-05 @tab CVS    @tab  208 @tab     @tab      @tab  332 (28) @tab           @tab     @tab
13257 @item 1995-11-23 @tab 0.20   @tab  533 @tab     @tab      @tab  458 (35) @tab           @tab   9 @tab
13258 @item 1995-11-26 @tab 0.21   @tab  613 @tab     @tab      @tab  480 (36) @tab           @tab  11 @tab
13259 @item 1995-11-28 @tab 0.22   @tab 1116 @tab     @tab      @tab  539 (38) @tab           @tab  12 @tab
13260 @item 1995-11-29 @tab 0.23   @tab 1240 @tab     @tab      @tab  541 (38) @tab           @tab  12 @tab
13261 @item 1995-12-08 @tab 0.24   @tab 1462 @tab     @tab      @tab  504 (33) @tab           @tab  14 @tab
13262 @item 1995-12-10 @tab 0.25   @tab 1513 @tab     @tab      @tab  511 (37) @tab           @tab  15 @tab
13263 @item 1996-01-03 @tab 0.26   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
13264 @item 1996-01-03 @tab 0.27   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
13265 @item 1996-01-13 @tab 0.28   @tab 1964 @tab     @tab      @tab  934 (33) @tab           @tab  16 @tab
13266 @item 1996-02-07 @tab 0.29   @tab 2299 @tab     @tab      @tab  936 (33) @tab           @tab  17 @tab
13267 @item 1996-02-24 @tab 0.30   @tab 2544 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  20 @tab 9
13268 @item 1996-03-11 @tab 0.31   @tab 2877 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  29 @tab 17
13269 @item 1996-04-27 @tab 0.32   @tab 3058 @tab     @tab      @tab  921 (31) @tab   85 (1)  @tab  30 @tab 26
13270 @item 1996-05-18 @tab 0.33   @tab 3110 @tab     @tab      @tab  926 (31) @tab  105 (1)  @tab  30 @tab 35
13271 @item 1996-05-28 @tab 1.0    @tab 3134 @tab     @tab      @tab  973 (32) @tab  105 (1)  @tab  30 @tab 38
13272 @item 1997-06-22 @tab 1.2    @tab 6089 @tab 385 @tab      @tab 1294 (36) @tab  592 (20) @tab  37 @tab 126
13273 @item 1998-04-05 @tab 1.3    @tab 6415 @tab 422 @tab      @tab 1470 (39) @tab  741 (23) @tab  39 @tab 156
13274 @item 1999-01-14 @tab 1.4    @tab 7240 @tab 426 @tab      @tab 1591 (40) @tab  734 (20) @tab  51 @tab 197
13275 @item 2001-05-08 @tab 1.4-p1 @tab 7251 @tab 426 @tab      @tab 1591 (40) @tab  734 (20) @tab  51 @tab 197
13276 @item 2001-05-24 @tab 1.4-p2 @tab 7268 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 197
13277 @item 2001-06-07 @tab 1.4-p3 @tab 7312 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 197
13278 @item 2001-06-10 @tab 1.4-p4 @tab 7321 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 198
13279 @item 2001-07-15 @tab 1.4-p5 @tab 7228 @tab 426 @tab      @tab 1596 (40) @tab  734 (20) @tab  51 @tab 198
13280 @item 2001-08-23 @tab 1.5    @tab 8016 @tab 475 @tab  600 @tab 2654 (39) @tab 1166 (29) @tab  63 @tab 327
13281 @item 2002-03-05 @tab 1.6    @tab 8465 @tab 475 @tab 1136 @tab 2732 (39) @tab 1603 (27) @tab  66 @tab 365
13282 @item 2002-04-11 @tab 1.6.1  @tab 8544 @tab 475 @tab 1136 @tab 2741 (39) @tab 1603 (27) @tab  66 @tab 372
13283 @item 2002-06-14 @tab 1.6.2  @tab 8575 @tab 475 @tab 1136 @tab 2800 (39) @tab 1609 (27) @tab  67 @tab 386
13284 @item 2002-07-28 @tab 1.6.3  @tab 8600 @tab 475 @tab 1153 @tab 2809 (39) @tab 1609 (27) @tab  67 @tab 391
13285 @item 2002-07-28 @tab 1.4-p6 @tab 7332 @tab 455 @tab      @tab 1596 (40) @tab  735 (20) @tab  49 @tab 197
13286 @item 2002-09-25 @tab 1.7    @tab 9189 @tab 471 @tab 1790 @tab 2965 (39) @tab 1606 (28) @tab  73 @tab 430
13287 @item 2002-10-16 @tab 1.7.1  @tab 9229 @tab 475 @tab 1790 @tab 2977 (39) @tab 1606 (28) @tab  73 @tab 437
13288 @item 2002-12-06 @tab 1.7.2  @tab 9334 @tab 475 @tab 1790 @tab 2988 (39) @tab 1606 (28) @tab  77 @tab 445
13289 @item 2003-02-20 @tab 1.7.3  @tab 9389 @tab 475 @tab 1790 @tab 3023 (39) @tab 1651 (29) @tab  84 @tab 448
13290 @item 2003-04-23 @tab 1.7.4  @tab 9429 @tab 475 @tab 1790 @tab 3031 (39) @tab 1644 (29) @tab  85 @tab 458
13291 @item 2003-05-18 @tab 1.7.5  @tab 9429 @tab 475 @tab 1790 @tab 3033 (39) @tab 1645 (29) @tab  85 @tab 459
13292 @item 2003-07-10 @tab 1.7.6  @tab 9442 @tab 475 @tab 1790 @tab 3033 (39) @tab 1660 (29) @tab  85 @tab 461
13293 @item 2003-09-07 @tab 1.7.7  @tab 9443 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (29) @tab  90 @tab 467
13294 @item 2003-10-07 @tab 1.7.8  @tab 9444 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (29) @tab  90 @tab 468
13295 @item 2003-11-09 @tab 1.7.9  @tab 9444 @tab 475 @tab 1790 @tab 3048 (39) @tab 1660 (29) @tab  90 @tab 468
13296 @item 2003-12-10 @tab 1.8    @tab 7171 @tab 585 @tab 7730 @tab 3236 (39) @tab 1666 (31) @tab 104 @tab 521
13297 @item 2004-01-11 @tab 1.8.1  @tab 7217 @tab 663 @tab 7726 @tab 3287 (39) @tab 1686 (31) @tab 104 @tab 525
13298 @item 2004-01-12 @tab 1.8.2  @tab 7217 @tab 663 @tab 7726 @tab 3288 (39) @tab 1686 (31) @tab 104 @tab 526
13299 @item 2004-03-07 @tab 1.8.3  @tab 7214 @tab 686 @tab 7735 @tab 3303 (39) @tab 1695 (31) @tab 111 @tab 530
13300 @item 2004-04-25 @tab 1.8.4  @tab 7214 @tab 686 @tab 7736 @tab 3310 (39) @tab 1701 (31) @tab 112 @tab 531
13301 @item 2004-05-16 @tab 1.8.5  @tab 7240 @tab 686 @tab 7736 @tab 3299 (39) @tab 1701 (31) @tab 112 @tab 533
13302 @item 2004-07-28 @tab 1.9    @tab 7508 @tab 715 @tab 7794 @tab 3352 (40) @tab 1812 (32) @tab 115 @tab 551
13303 @item 2004-08-11 @tab 1.9.1  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (32) @tab 115 @tab 552
13304 @item 2004-09-19 @tab 1.9.2  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (32) @tab 132 @tab 554
13305 @item 2004-11-01 @tab 1.9.3  @tab 7507 @tab 718 @tab 7804 @tab 3354 (40) @tab 1812 (32) @tab 134 @tab 556
13306 @item 2004-12-18 @tab 1.9.4  @tab 7508 @tab 718 @tab 7856 @tab 3361 (40) @tab 1811 (32) @tab 140 @tab 560
13307 @item 2005-02-13 @tab 1.9.5  @tab 7523 @tab 719 @tab 7859 @tab 3373 (40) @tab 1453 (32) @tab 142 @tab 562
13308 @item 2005-07-10 @tab 1.9.6  @tab 7539 @tab 699 @tab 7867 @tab 3400 (40) @tab 1453 (32) @tab 144 @tab 570
13309 @item 2006-10-15 @tab 1.10   @tab 7859 @tab 1072 @tab 8024 @tab 3512 (40) @tab 1496 (34) @tab 172 @tab 604
13310 @item 2008-01-19 @tab 1.10.1 @tab 7870 @tab 1089 @tab 8025 @tab 3520 (40) @tab 1499 (34) @tab 173 @tab 617
13311 @item 2008-11-23 @tab 1.10.2 @tab 7882 @tab 1089 @tab 8027 @tab 3540 (40) @tab 1509 (34) @tab 176 @tab 628
13312 @item 2009-05-17 @tab 1.11   @tab 8721 @tab 1092 @tab 8289 @tab 4164 (42) @tab 1714 (37) @tab 181 @tab 732 (20)
13313 @end multitable
13314
13315
13316 @c ========================================================== Appendices
13317
13318 @page
13319 @node Copying This Manual
13320 @appendix Copying This Manual
13321
13322 @menu
13323 * GNU Free Documentation License::  License for copying this manual
13324 @end menu
13325
13326 @node GNU Free Documentation License
13327 @appendixsec GNU Free Documentation License
13328 @include fdl.texi
13329
13330 @page
13331 @node Indices
13332 @appendix Indices
13333
13334 @menu
13335 * Macro Index::                 Index of Autoconf macros
13336 * Variable Index::              Index of Makefile variables
13337 * General Index::               General index
13338 @end menu
13339
13340 @node Macro Index
13341 @appendixsec Macro Index
13342
13343 @printindex fn
13344
13345 @node Variable Index
13346 @appendixsec Variable Index
13347
13348 @printindex vr
13349
13350 @node General Index
13351 @appendixsec General Index
13352
13353 @printindex cp
13354
13355
13356 @bye
13357
13358 @c  LocalWords:  texinfo setfilename settitle setchapternewpage texi direntry
13359 @c  LocalWords:  dircategory in's aclocal ifinfo titlepage Tromey vskip pt sp
13360 @c  LocalWords:  filll defcodeindex ov cv op tr syncodeindex fn cp vr ifnottex
13361 @c  LocalWords:  dir Automake's ac Dist Gnits gnits cygnus dfn Autoconf's pxref
13362 @c  LocalWords:  cindex Autoconf autoconf perl samp cvs dist trindex SUBST foo
13363 @c  LocalWords:  xs emph FIXME ref vindex pkglibdir pkgincludedir pkgdatadir mt
13364 @c  LocalWords:  pkg libdir cpio bindir sbindir rmt pax sbin zar zardir acindex
13365 @c  LocalWords:  HTML htmldir html noinst TEXINFOS nodist nobase strudel CFLAGS
13366 @c  LocalWords:  libmumble CC YFLAGS ansi knr itemx de fication config url comp
13367 @c  LocalWords:  depcomp elisp sh mdate mkinstalldirs mkdir py tex dvi ps pdf
13368 @c  LocalWords:  ylwrap zardoz INIT gettext acinclude mv FUNCS LIBOBJS LDADD fr
13369 @c  LocalWords:  uref featureful dnl src LINGUAS es ko nl pl sl sv PROG ISC doc
13370 @c  LocalWords:  POSIX STDC fcntl FUNC ALLOCA blksize struct stat intl po chmod
13371 @c  LocalWords:  ChangeLog SUBDIRS gettextize gpl testdata getopt INTLLIBS cpp
13372 @c  LocalWords:  localedir datadir DLOCALEDIR DEXIT CPPFLAGS autoreconf opindex
13373 @c  LocalWords:  AUX var symlink deps Wno Wnone package's aclocal's distclean
13374 @c  LocalWords:  ltmain xref LIBSOURCE LIBSOURCES LIBOBJ MEMCMP vs RANLIB CXX
13375 @c  LocalWords:  LDFLAGS LIBTOOL libtool XTRA LIBS gettext's acdir APIVERSION
13376 @c  LocalWords:  dirlist noindent usr MULTILIB multilib Multilibs TIOCGWINSZ sc
13377 @c  LocalWords:  GWINSZ termios SRCDIR tarball bzip LISPDIR lispdir XEmacs CCAS
13378 @c  LocalWords:  emacsen MicroEmacs CCASFLAGS UX GCJ gcj GCJFLAGS posix DMALLOC
13379 @c  LocalWords:  dmalloc ldmalloc REGEX regex rx DEPDIR DEP DEFUN aclocaldir fi
13380 @c  LocalWords:  mymacro myothermacro AMFLAGS autopoint autogen libtoolize yum
13381 @c  LocalWords:  autoheader README MAKEFLAGS subdir Inetutils sync COND endif
13382 @c  LocalWords:  Miller's installable includedir inc pkgdata EXEEXT libexec bsd
13383 @c  LocalWords:  pkglib libexecdir prog libcpio cpio's dlopen dlpreopen linux
13384 @c  LocalWords:  subsubsection OBJEXT esac lib LTLIBRARIES liblob LIBADD AR ar
13385 @c  LocalWords:  ARFLAGS cru ing maude libgettext lo LTLIBOBJS rpath SGI PRE yy
13386 @c  LocalWords:  libmaude CCLD CXXFLAGS FFLAGS LFLAGS OBJCFLAGS RFLAGS DEFS cc
13387 @c  LocalWords:  SHORTNAME vtable srcdir nostdinc basename yxx cxx ll lxx gdb
13388 @c  LocalWords:  lexers yymaxdepth maxdepth yyparse yylex yyerror yylval lval
13389 @c  LocalWords:  yychar yydebug yypact yyr yydef def yychk chk yypgo pgo yyact
13390 @c  LocalWords:  yyexca exca yyerrflag errflag yynerrs nerrs yyps yypv pv yys
13391 @c  LocalWords:  yystate yytmp tmp yyv yyval val yylloc lloc yyreds yytoks toks
13392 @c  LocalWords:  yylhs yylen yydefred yydgoto yysindex yyrindex yygindex yyname
13393 @c  LocalWords:  yytable yycheck yyrule byacc CXXCOMPILE CXXLINK FLINK cfortran
13394 @c  LocalWords:  Catalogue preprocessable FLIBS libfoo baz JAVACFLAGS java exe
13395 @c  LocalWords:  SunOS fying basenames exeext uninstalled oldinclude kr FSF's
13396 @c  LocalWords:  pkginclude oldincludedir sysconf sharedstate localstate gcc rm
13397 @c  LocalWords:  sysconfdir sharedstatedir localstatedir preexist CLEANFILES gz
13398 @c  LocalWords:  depfile tmpdepfile depmode const interoperate
13399 @c  LocalWords:  JAVAC javac JAVAROOT builddir CLASSPATH ENV pyc pyo pkgpython
13400 @c  LocalWords:  pyexecdir pkgpyexecdir Python's pythondir pkgpythondir txi ois
13401 @c  LocalWords:  installinfo vers MAKEINFO makeinfo MAKEINFOFLAGS noinstall rf
13402 @c  LocalWords:  mandir thesame alsothesame installman myexecbin DESTDIR Pinard
13403 @c  LocalWords:  uninstall installdirs uninstalls MOSTLYCLEANFILES mostlyclean
13404 @c  LocalWords:  DISTCLEANFILES MAINTAINERCLEANFILES GZIP gzip shar exp
13405 @c  LocalWords:  distdir distcheck distcleancheck listfiles distuninstallcheck
13406 @c  LocalWords:  VPATH tarfile stdout XFAIL DejaGnu dejagnu DEJATOOL runtest ln
13407 @c  LocalWords:  RUNTESTDEFAULTFLAGS toolchain RUNTESTFLAGS asis readme DVIPS
13408 @c  LocalWords:  installcheck gzipped tarZ std utils etags mkid multilibbing cd
13409 @c  LocalWords:  ARGS taggable ETAGSFLAGS lang ctags CTAGSFLAGS GTAGS gtags idl
13410 @c  LocalWords:  foocc doit idlC multilibs ABIs cmindex defmac ARG enableval FC
13411 @c  LocalWords:  MSG xtrue DBG pathchk CYGWIN afile proglink versioned CVS's TE
13412 @c  LocalWords:  wildcards Autoconfiscated subsubheading autotools Meyering API
13413 @c  LocalWords:  ois's wildcard Wportability cartouche vrindex printindex Duret
13414 @c  LocalWords:  DSOMEFLAG DVERSION automake Lutz insertcopying versioning FAQ
13415 @c  LocalWords:  LTLIBOBJ Libtool's libtool's libltdl dlopening itutions libbar
13416 @c  LocalWords:  WANTEDLIBS libhello sublibraries libtop libsub dlopened Ratfor
13417 @c  LocalWords:  mymodule timestamps timestamp underquoted MAKEINFOHTMLFLAGS te
13418 @c  LocalWords:  GNUmakefile Subpackages subpackage's subpackages aux
13419 @c  LocalWords:  detailmenu Timeline pwd reldir AUTOM autom PREREQ FOOBAR libc
13420 @c  LocalWords:  libhand subpackage moduleN libmain libmisc FCFLAGS FCCOMPILE
13421 @c  LocalWords:  FCLINK subst sed ELCFILES elc MAKEINFOHTML dvips esyscmd ustar
13422 @c  LocalWords:  tarballs Woverride vfi ELFILES djm AutoMake honkin FSF
13423 @c  LocalWords:  fileutils precanned MacKenzie's reimplement termutils Tromey's
13424 @c  LocalWords:  cois gnitsians LIBPROGRAMS progs LIBLIBRARIES Textutils Ulrich
13425 @c  LocalWords:  Matzigkeit Drepper's Gord Matzigkeit's jm Dalley Debian org
13426 @c  LocalWords:  Administrivia ILU CORBA Sourceware Molenda sourceware Elliston
13427 @c  LocalWords:  dep Oliva Akim Demaille Aiieeee Demaillator Akim's sourcequake
13428 @c  LocalWords:  grep backported screenshots libgcj KB unnumberedsubsubsec pre
13429 @c  LocalWords:  precomputing hacky makedepend inline clearmake LD PRELOAD Rel
13430 @c  LocalWords:  syscalls perlhist acl pm multitable headitem fdl appendixsec
13431 @c  LocalWords:  LTALLOCA MALLOC malloc memcmp strdup alloca libcompat xyz DFOO
13432 @c  LocalWords:  unprefixed buildable preprocessed DBAZ DDATADIR WARNINGCFLAGS
13433 @c  LocalWords:  LIBFOOCFLAGS LIBFOOLDFLAGS ftable testSubDir obj LIBTOOLFLAGS
13434 @c  LocalWords:  barexec Pinard's automatize initialize lzma xz