c21a5b7e039a8db4dbbb8f85bbc8d1b27f618819
[platform/upstream/automake.git] / doc / automake.texi
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename automake.info
4 @settitle automake
5 @setchapternewpage off
6 @c %**end of header
7
8 @include version.texi
9
10 @c @ovar(ARG, DEFAULT)
11 @c -------------------
12 @c The ARG is an optional argument.  To be used for macro arguments in
13 @c their documentation (@defmac).
14 @macro ovar{varname}
15 @r{[}@var{\varname\}@r{]}
16 @end macro
17
18 @set PACKAGE_BUGREPORT bug-automake@@gnu.org
19
20 @copying
21
22 This manual is for GNU Automake (version @value{VERSION},
23 @value{UPDATED}), a program that creates GNU standards-compliant
24 Makefiles from template files.
25
26 Copyright @copyright{} 1995-2012 Free Software Foundation, Inc.
27
28 @quotation
29 Permission is granted to copy, distribute and/or modify this document
30 under the terms of the GNU Free Documentation License,
31 Version 1.3 or any later version published by the Free Software
32 Foundation; with no Invariant Sections, with no Front-Cover texts,
33 and with no Back-Cover Texts.  A copy of the license is included in the
34 section entitled ``GNU Free Documentation License.''
35
36 @end quotation
37 @end copying
38
39 @dircategory Software development
40 @direntry
41 * Automake: (automake).         Making GNU standards-compliant Makefiles.
42 @end direntry
43
44 @dircategory Individual utilities
45 @direntry
46 * aclocal-invocation: (automake)aclocal Invocation.   Generating aclocal.m4.
47 * automake-invocation: (automake)automake Invocation. Generating Makefile.in.
48 @end direntry
49
50 @titlepage
51 @title GNU Automake
52 @subtitle For version @value{VERSION}, @value{UPDATED}
53 @author David MacKenzie
54 @author Tom Tromey
55 @author Alexandre Duret-Lutz
56 @page
57 @vskip 0pt plus 1filll
58 @insertcopying
59 @end titlepage
60
61 @contents
62
63 @c We use the following macros to define indices:
64 @c   @cindex   concepts, and anything that does not fit elsewhere
65 @c   @vindex   Makefile variables
66 @c   @trindex  targets
67 @c   @acindex  Autoconf/Automake/Libtool/M4/... macros
68 @c   @opindex  tool options
69
70 @c Define an index of configure macros.
71 @defcodeindex ac
72 @c Define an index of options.
73 @defcodeindex op
74 @c Define an index of targets.
75 @defcodeindex tr
76 @c Define an index of commands.
77 @defcodeindex cm
78
79 @c Put the macros in the function index.
80 @syncodeindex ac fn
81
82 @c Put everything else into one index (arbitrarily chosen to be the
83 @c concept index).
84 @syncodeindex op cp
85 @syncodeindex tr cp
86 @syncodeindex cm cp
87
88 @ifnottex
89 @node Top
90 @comment  node-name,  next,  previous,  up
91 @top GNU Automake
92
93 @insertcopying
94
95 @menu
96 * Introduction::                Automake's purpose
97 * Autotools Introduction::      An Introduction to the Autotools
98 * Generalities::                General ideas
99 * Examples::                    Some example packages
100 * automake Invocation::         Creating a Makefile.in
101 * configure::                   Scanning configure.ac, using aclocal
102 * Directories::                 Declaring subdirectories
103 * Programs::                    Building programs and libraries
104 * Other Objects::               Other derived objects
105 * Other GNU Tools::             Other GNU Tools
106 * Documentation::               Building documentation
107 * Install::                     What gets installed
108 * Clean::                       What gets cleaned
109 * Dist::                        What goes in a distribution
110 * Tests::                       Support for test suites
111 * Rebuilding::                  Automatic rebuilding of Makefile
112 * Options::                     Changing Automake's behavior
113 * Miscellaneous::               Miscellaneous rules
114 * Include::                     Including extra files in an Automake template
115 * Conditionals::                Conditionals
116 * Silencing Make::              Obtain less verbose output from @command{make}
117 * Gnits::                       The effect of @option{--gnu} and @option{--gnits}
118 * Cygnus::                      The effect of @option{--cygnus} (deprecated, soon to be removed)
119 * Not Enough::                  When Automake is not Enough
120 * Distributing::                Distributing the Makefile.in
121 * API Versioning::              About compatibility between Automake versions
122 * Upgrading::                   Upgrading to a Newer Automake Version
123 * FAQ::                         Frequently Asked Questions
124 * Copying This Manual::         How to make copies of this manual
125 * Indices::                     Indices of variables, macros, and concepts
126
127 @detailmenu
128  --- The Detailed Node Listing ---
129
130 An Introduction to the Autotools
131
132 * GNU Build System::            Introducing the GNU Build System
133 * Use Cases::                   Use Cases for the GNU Build System
134 * Why Autotools::               How Autotools Help
135 * Hello World::                 A Small Hello World Package
136
137 Use Cases for the GNU Build System
138
139 * Basic Installation::          Common installation procedure
140 * Standard Targets::            A list of standard Makefile targets
141 * Standard Directory Variables::  A list of standard directory variables
142 * Standard Configuration Variables::  Using configuration variables
143 * config.site::                 Using a config.site file
144 * VPATH Builds::                Parallel build trees
145 * Two-Part Install::            Installing data and programs separately
146 * Cross-Compilation::           Building for other architectures
147 * Renaming::                    Renaming programs at install time
148 * DESTDIR::                     Building binary packages with DESTDIR
149 * Preparing Distributions::     Rolling out tarballs
150 * Dependency Tracking::         Automatic dependency tracking
151 * Nested Packages::             The GNU Build Systems can be nested
152
153 A Small Hello World
154
155 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
156 * amhello's configure.ac Setup Explained::
157 * amhello's Makefile.am Setup Explained::
158
159 General ideas
160
161 * General Operation::           General operation of Automake
162 * Strictness::                  Standards conformance checking
163 * Uniform::                     The Uniform Naming Scheme
164 * Length Limitations::          Staying below the command line length limit
165 * Canonicalization::            How derived variables are named
166 * User Variables::              Variables reserved for the user
167 * Auxiliary Programs::          Programs automake might require
168
169 Some example packages
170
171 * Complete::                    A simple example, start to finish
172 * true::                        Building true and false
173
174 Scanning @file{configure.ac}, using @command{aclocal}
175
176 * Requirements::                Configuration requirements
177 * Optional::                    Other things Automake recognizes
178 * aclocal Invocation::          Auto-generating aclocal.m4
179 * Macros::                      Autoconf macros supplied with Automake
180
181 Auto-generating aclocal.m4
182
183 * aclocal Options::             Options supported by aclocal
184 * Macro Search Path::           How aclocal finds .m4 files
185 * Extending aclocal::           Writing your own aclocal macros
186 * Local Macros::                Organizing local macros
187 * Serials::                     Serial lines in Autoconf macros
188 * Future of aclocal::           aclocal's scheduled death
189
190 Autoconf macros supplied with Automake
191
192 * Public Macros::               Macros that you can use.
193 * Obsolete Macros::             Macros that will soon be removed.
194 * Private Macros::              Macros that you should not use.
195
196 Directories
197
198 * Subdirectories::              Building subdirectories recursively
199 * Conditional Subdirectories::  Conditionally not building directories
200 * Alternative::                 Subdirectories without recursion
201 * Subpackages::                 Nesting packages
202
203 Conditional Subdirectories
204
205 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
206 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
207 * Subdirectories with AC_SUBST::  Another way for conditional recursion
208 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
209
210 Building Programs and Libraries
211
212 * A Program::                   Building a program
213 * A Library::                   Building a library
214 * A Shared Library::            Building a Libtool library
215 * Program and Library Variables::  Variables controlling program and
216                                 library builds
217 * Default _SOURCES::            Default source files
218 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
219 * Program Variables::           Variables used when building a program
220 * Yacc and Lex::                Yacc and Lex support
221 * C++ Support::                 Compiling C++ sources
222 * Objective C Support::         Compiling Objective C sources
223 * Unified Parallel C Support::  Compiling Unified Parallel C sources
224 * Assembly Support::            Compiling assembly sources
225 * Fortran 77 Support::          Compiling Fortran 77 sources
226 * Fortran 9x Support::          Compiling Fortran 9x sources
227 * Java Support with gcj::       Compiling Java sources using gcj
228 * Vala Support::                Compiling Vala sources
229 * Support for Other Languages::  Compiling other languages
230 * Dependencies::                Automatic dependency tracking
231 * EXEEXT::                      Support for executable extensions
232
233 Building a program
234
235 * Program Sources::             Defining program sources
236 * Linking::                     Linking with libraries or extra objects
237 * Conditional Sources::         Handling conditional sources
238 * Conditional Programs::        Building a program conditionally
239
240 Building a Shared Library
241
242 * Libtool Concept::             Introducing Libtool
243 * Libtool Libraries::           Declaring Libtool Libraries
244 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
245 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
246 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
247 * Libtool Modules::             Building Libtool Modules
248 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
249 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
250 * Libtool Issues::              Common Issues Related to Libtool's Use
251
252 Common Issues Related to Libtool's Use
253
254 * Error required file ltmain.sh not found::  The need to run libtoolize
255 * Objects created both with libtool and without::  Avoid a specific build race
256
257 Fortran 77 Support
258
259 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
260 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
261 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
262
263 Mixing Fortran 77 With C and C++
264
265 * How the Linker is Chosen::    Automatic linker selection
266
267 Fortran 9x Support
268
269 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
270
271 Other Derived Objects
272
273 * Scripts::                     Executable scripts
274 * Headers::                     Header files
275 * Data::                        Architecture-independent data files
276 * Sources::                     Derived sources
277
278 Built Sources
279
280 * Built Sources Example::       Several ways to handle built sources.
281
282 Other GNU Tools
283
284 * Emacs Lisp::                  Emacs Lisp
285 * gettext::                     Gettext
286 * Libtool::                     Libtool
287 * Java::                        Java bytecode compilation (deprecated)
288 * Python::                      Python
289
290 Building documentation
291
292 * Texinfo::                     Texinfo
293 * Man Pages::                   Man pages
294
295 What Gets Installed
296
297 * Basics of Installation::      What gets installed where
298 * The Two Parts of Install::    Installing data and programs separately
299 * Extending Installation::      Adding your own rules for installation
300 * Staged Installs::             Installation in a temporary location
301 * Install Rules for the User::  Useful additional rules
302
303 What Goes in a Distribution
304
305 * Basics of Distribution::      Files distributed by default
306 * Fine-grained Distribution Control::  @code{dist_} and @code{nodist_} prefixes
307 * The dist Hook::               A target for last-minute distribution changes
308 * Checking the Distribution::   @samp{make distcheck} explained
309 * The Types of Distributions::  A variety of formats and compression methods
310
311 Support for test suites
312
313 * Generalities about Testing::  Generic concepts and terminology about testing
314 * Simple Tests::                Listing test scripts in @code{TESTS}
315 * Custom Test Drivers::         Writing and using custom test drivers
316 * Using the TAP test protocol:: Integrating test scripts that use the TAP protocol
317 * DejaGnu Tests::               Interfacing with the @command{dejagnu} testing framework
318 * Install Tests::               Running tests on installed packages
319
320 Simple Tests
321
322 * Scripts-based Testsuites::    Automake-specific concepts and terminology
323 * Serial Test Harness::         Older (and obsolescent) serial test harness
324 * Parallel Test Harness::       Generic concurrent test harness
325
326 Using the TAP test protocol
327
328 * Introduction to TAP::
329 * Use TAP with the Automake test harness::
330 * Incompatibilities with other TAP parsers and drivers::
331 * Links and external resources on TAP::
332
333 Custom Test Drivers
334
335 * Overview of Custom Test Drivers Support::
336 * Declaring Custom Test Drivers::
337 * API for Custom Test Drivers::
338
339 API for Custom Test Drivers
340
341 * Command-line arguments for test drivers::
342 * Log files generation and test results recording::
343 * Testsuite progress output::
344
345 Changing Automake's Behavior
346
347 * Options generalities::        Semantics of Automake option
348 * List of Automake options::    A comprehensive list of Automake options
349
350 Miscellaneous Rules
351
352 * Tags::                        Interfacing to cscope, etags and mkid
353 * Suffixes::                    Handling new file extensions
354
355 Conditionals
356
357 * Usage of Conditionals::       Declaring conditional content
358 * Limits of Conditionals::      Enclosing complete statements
359
360 Silencing Make
361
362 * Make verbosity::               Make is verbose by default
363 * Tricks For Silencing Make::    Standard and generic ways to silence make
364 * Automake silent-rules Option:: How Automake can help in silencing make
365
366 When Automake Isn't Enough
367
368 * Extending::                   Adding new rules or overriding existing ones.
369 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
370
371 Frequently Asked Questions about Automake
372
373 * CVS::                         CVS and generated files
374 * maintainer-mode::             missing and AM_MAINTAINER_MODE
375 * Wildcards::                   Why doesn't Automake support wildcards?
376 * Limitations on File Names::   Limitations on source and installed file names
377 * Errors with distclean::       Files left in build directory after distclean
378 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
379 * Renamed Objects::             Why are object files sometimes renamed?
380 * Per-Object Flags::            How to simulate per-object flags?
381 * Multiple Outputs::            Writing rules for tools with many output files
382 * Hard-Coded Install Paths::    Installing to hard-coded locations
383 * Debugging Make Rules::        Strategies when things don't work as expected
384 * Reporting Bugs::              Feedback on bugs and feature requests
385
386 Copying This Manual
387
388 * GNU Free Documentation License::  License for copying this manual
389
390 Indices
391
392 * Macro Index::                 Index of Autoconf macros
393 * Variable Index::              Index of Makefile variables
394 * General Index::               General index
395
396 @end detailmenu
397 @end menu
398
399 @end ifnottex
400
401
402 @node Introduction
403 @chapter Introduction
404
405 Automake is a tool for automatically generating @file{Makefile.in}s
406 from files called @file{Makefile.am}.  Each @file{Makefile.am} is
407 basically a series of @command{make} variable
408 definitions@footnote{These variables are also called @dfn{make macros}
409 in Make terminology, however in this manual we reserve the term
410 @dfn{macro} for Autoconf's macros.}, with rules being thrown in
411 occasionally.  The generated @file{Makefile.in}s are compliant with
412 the GNU Makefile standards.
413
414 @cindex GNU Makefile standards
415
416 The GNU Makefile Standards Document
417 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
418 is long, complicated, and subject to change.  The goal of Automake is to
419 remove the burden of Makefile maintenance from the back of the
420 individual GNU maintainer (and put it on the back of the Automake
421 maintainers).
422
423 The typical Automake input file is simply a series of variable definitions.
424 Each such file is processed to create a @file{Makefile.in}.  There
425 should generally be one @file{Makefile.am} per directory of a project.
426
427 @cindex Constraints of Automake
428 @cindex Automake constraints
429
430 Automake does constrain a project in certain ways; for instance, it
431 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
432 autoconf, The Autoconf Manual}), and enforces certain restrictions on
433 the @file{configure.ac} contents.
434
435 @cindex Automake requirements
436 @cindex Requirements, Automake
437
438 Automake requires @command{perl} in order to generate the
439 @file{Makefile.in}s.  However, the distributions created by Automake are
440 fully GNU standards-compliant, and do not require @command{perl} in order
441 to be built.
442
443 @cindex Bugs, reporting
444 @cindex Reporting bugs
445 @cindex E-mail, bug reports
446
447 For more information on bug reports, @xref{Reporting Bugs}.
448
449 @node Autotools Introduction
450 @chapter An Introduction to the Autotools
451
452 If you are new to Automake, maybe you know that it is part of a set of
453 tools called @emph{The Autotools}.  Maybe you've already delved into a
454 package full of files named @file{configure}, @file{configure.ac},
455 @file{Makefile.in}, @file{Makefile.am}, @file{aclocal.m4}, @dots{},
456 some of them claiming to be @emph{generated by} Autoconf or Automake.
457 But the exact purpose of these files and their relations is probably
458 fuzzy.  The goal of this chapter is to introduce you to this machinery,
459 to show you how it works and how powerful it is.  If you've never
460 installed or seen such a package, do not worry: this chapter will walk
461 you through it.
462
463 If you need some teaching material, more illustrations, or a less
464 @command{automake}-centered continuation, some slides for this
465 introduction are available in Alexandre Duret-Lutz's
466 @uref{http://www.lrde.epita.fr/@/~adl/@/autotools.html,
467 Autotools Tutorial}.
468 This chapter is the written version of the first part of his tutorial.
469
470 @menu
471 * GNU Build System::            Introducing the GNU Build System
472 * Use Cases::                   Use Cases for the GNU Build System
473 * Why Autotools::               How Autotools Help
474 * Hello World::                 A Small Hello World Package
475 @end menu
476
477 @node GNU Build System
478 @section Introducing the GNU Build System
479 @cindex GNU Build System, introduction
480
481 It is a truth universally acknowledged, that as a developer in
482 possession of a new package, you must be in want of a build system.
483
484 In the Unix world, such a build system is traditionally achieved using
485 the command @command{make} (@pxref{Top, , Overview, make, The GNU Make
486 Manual}).  You express the recipe to build your package in a
487 @file{Makefile}.  This file is a set of rules to build the files in
488 the package.  For instance the program @file{prog} may be built by
489 running the linker on the files @file{main.o}, @file{foo.o}, and
490 @file{bar.o}; the file @file{main.o} may be built by running the
491 compiler on @file{main.c}; etc.  Each time @command{make} is run, it
492 reads @file{Makefile}, checks the existence and modification time of
493 the files mentioned, decides what files need to be built (or rebuilt),
494 and runs the associated commands.
495
496 When a package needs to be built on a different platform than the one
497 it was developed on, its @file{Makefile} usually needs to be adjusted.
498 For instance the compiler may have another name or require more
499 options.  In 1991, David J. MacKenzie got tired of customizing
500 @file{Makefile} for the 20 platforms he had to deal with.  Instead, he
501 handcrafted a little shell script called @file{configure} to
502 automatically adjust the @file{Makefile} (@pxref{Genesis, , Genesis,
503 autoconf, The Autoconf Manual}).  Compiling his package was now
504 as simple as running @code{./configure && make}.
505
506 @cindex GNU Coding Standards
507
508 Today this process has been standardized in the GNU project.  The GNU
509 Coding Standards (@pxref{Managing Releases, The Release Process, ,
510 standards, The GNU Coding Standards}) explains how each package of the
511 GNU project should have a @file{configure} script, and the minimal
512 interface it should have.  The @file{Makefile} too should follow some
513 established conventions.  The result?  A unified build system that
514 makes all packages almost indistinguishable by the installer.  In its
515 simplest scenario, all the installer has to do is to unpack the
516 package, run @code{./configure && make && make install}, and repeat
517 with the next package to install.
518
519 We call this build system the @dfn{GNU Build System}, since it was
520 grown out of the GNU project.  However it is used by a vast number of
521 other packages: following any existing convention has its advantages.
522
523 @cindex Autotools, introduction
524
525 The Autotools are tools that will create a GNU Build System for your
526 package.  Autoconf mostly focuses on @file{configure} and Automake on
527 @file{Makefile}s.  It is entirely possible to create a GNU Build
528 System without the help of these tools.  However it is rather
529 burdensome and error-prone.  We will discuss this again after some
530 illustration of the GNU Build System in action.
531
532 @node Use Cases
533 @section Use Cases for the GNU Build System
534 @cindex GNU Build System, use cases
535 @cindex GNU Build System, features
536 @cindex Features of the GNU Build System
537 @cindex Use Cases for the GNU Build System
538 @cindex @file{amhello-1.0.tar.gz}, location
539 @cindex @file{amhello-1.0.tar.gz}, use cases
540
541 In this section we explore several use cases for the GNU Build System.
542 You can replay all these examples on the @file{amhello-1.0.tar.gz}
543 package distributed with Automake.  If Automake is installed on your
544 system, you should find a copy of this file in
545 @file{@var{prefix}/share/doc/automake/amhello-1.0.tar.gz}, where
546 @var{prefix} is the installation prefix specified during configuration
547 (@var{prefix} defaults to @file{/usr/local}, however if Automake was
548 installed by some GNU/Linux distribution it most likely has been set
549 to @file{/usr}).  If you do not have a copy of Automake installed,
550 you can find a copy of this file inside the @file{doc/} directory of
551 the Automake package.
552
553 Some of the following use cases present features that are in fact
554 extensions to the GNU Build System.  Read: they are not specified by
555 the GNU Coding Standards, but they are nonetheless part of the build
556 system created by the Autotools.  To keep things simple, we do not
557 point out the difference.  Our objective is to show you many of the
558 features that the build system created by the Autotools will offer to
559 you.
560
561 @menu
562 * Basic Installation::          Common installation procedure
563 * Standard Targets::            A list of standard Makefile targets
564 * Standard Directory Variables::  A list of standard directory variables
565 * Standard Configuration Variables::  Using configuration variables
566 * config.site::                 Using a config.site file
567 * VPATH Builds::                Parallel build trees
568 * Two-Part Install::            Installing data and programs separately
569 * Cross-Compilation::           Building for other architectures
570 * Renaming::                    Renaming programs at install time
571 * DESTDIR::                     Building binary packages with DESTDIR
572 * Preparing Distributions::     Rolling out tarballs
573 * Dependency Tracking::         Automatic dependency tracking
574 * Nested Packages::             The GNU Build Systems can be nested
575 @end menu
576
577 @node Basic Installation
578 @subsection Basic Installation
579 @cindex Configuration, basics
580 @cindex Installation, basics
581 @cindex GNU Build System, basics
582
583 The most common installation procedure looks as follows.
584
585 @example
586 ~ % @kbd{tar zxf amhello-1.0.tar.gz}
587 ~ % @kbd{cd amhello-1.0}
588 ~/amhello-1.0 % @kbd{./configure}
589 @dots{}
590 config.status: creating Makefile
591 config.status: creating src/Makefile
592 @dots{}
593 ~/amhello-1.0 % @kbd{make}
594 @dots{}
595 ~/amhello-1.0 % @kbd{make check}
596 @dots{}
597 ~/amhello-1.0 % @kbd{su}
598 Password:
599 /home/adl/amhello-1.0 # @kbd{make install}
600 @dots{}
601 /home/adl/amhello-1.0 # @kbd{exit}
602 ~/amhello-1.0 % @kbd{make installcheck}
603 @dots{}
604 @end example
605
606 @cindex Unpacking
607
608 The user first unpacks the package.  Here, and in the following
609 examples, we will use the non-portable @code{tar zxf} command for
610 simplicity.  On a system without GNU @command{tar} installed, this
611 command should read @code{gunzip -c amhello-1.0.tar.gz | tar xf -}.
612
613 The user then enters the newly created directory to run the
614 @file{configure} script.  This script probes the system for various
615 features, and finally creates the @file{Makefile}s.  In this toy
616 example there are only two @file{Makefile}s, but in real-world projects,
617 there may be many more, usually one @file{Makefile} per directory.
618
619 It is now possible to run @code{make}.  This will construct all the
620 programs, libraries, and scripts that need to be constructed for the
621 package.  In our example, this compiles the @file{hello} program.
622 All files are constructed in place, in the source tree; we will see
623 later how this can be changed.
624
625 @code{make check} causes the package's tests to be run.  This step is
626 not mandatory, but it is often good to make sure the programs that
627 have been built behave as they should, before you decide to install
628 them.  Our example does not contain any tests, so running @code{make
629 check} is a no-op.
630
631 @cindex su, before @code{make install}
632 After everything has been built, and maybe tested, it is time to
633 install it on the system.  That means copying the programs,
634 libraries, header files, scripts, and other data files from the
635 source directory to their final destination on the system.  The
636 command @code{make install} will do that.  However, by default
637 everything will be installed in subdirectories of @file{/usr/local}:
638 binaries will go into @file{/usr/local/bin}, libraries will end up in
639 @file{/usr/local/lib}, etc.  This destination is usually not writable
640 by any user, so we assume that we have to become root before we can
641 run @code{make install}.  In our example, running @code{make install}
642 will copy the program @file{hello} into @file{/usr/local/bin}
643 and @file{README} into @file{/usr/local/share/doc/amhello}.
644
645 A last and optional step is to run @code{make installcheck}.  This
646 command may run tests on the installed files.  @code{make check} tests
647 the files in the source tree, while @code{make installcheck} tests
648 their installed copies.  The tests run by the latter can be different
649 from those run by the former.  For instance, there are tests that
650 cannot be run in the source tree.  Conversely, some packages are set
651 up so that @code{make installcheck} will run the very same tests as
652 @code{make check}, only on different files (non-installed
653 vs.@: installed).  It can make a difference, for instance when the
654 source tree's layout is different from that of the installation.
655 Furthermore it may help to diagnose an incomplete installation.
656
657 Presently most packages do not have any @code{installcheck} tests
658 because the existence of @code{installcheck} is little known, and its
659 usefulness is neglected.  Our little toy package is no better: @code{make
660 installcheck} does nothing.
661
662 @node Standard Targets
663 @subsection Standard @file{Makefile} Targets
664
665 So far we have come across four ways to run @command{make} in the GNU
666 Build System: @code{make}, @code{make check}, @code{make install}, and
667 @code{make installcheck}.  The words @code{check}, @code{install}, and
668 @code{installcheck}, passed as arguments to @command{make}, are called
669 @dfn{targets}.  @code{make} is a shorthand for @code{make all},
670 @code{all} being the default target in the GNU Build System.
671
672 Here is a list of the most useful targets that the GNU Coding Standards
673 specify.
674
675 @table @code
676 @item make all
677 @trindex all
678 Build programs, libraries, documentation, etc.@: (same as @code{make}).
679 @item make install
680 @trindex install
681 Install what needs to be installed, copying the files from the
682 package's tree to system-wide directories.
683 @item make install-strip
684 @trindex install-strip
685 Same as @code{make install}, then strip debugging symbols.  Some
686 users like to trade space for useful bug reports@enddots{}
687 @item make uninstall
688 @trindex uninstall
689 The opposite of @code{make install}: erase the installed files.
690 (This needs to be run from the same build tree that was installed.)
691 @item make clean
692 @trindex clean
693 Erase from the build tree the files built by @code{make all}.
694 @item make distclean
695 @trindex distclean
696 Additionally erase anything @code{./configure} created.
697 @item make check
698 @trindex check
699 Run the test suite, if any.
700 @item make installcheck
701 @trindex installcheck
702 Check the installed programs or libraries, if supported.
703 @item make dist
704 @trindex dist
705 Recreate @file{@var{package}-@var{version}.tar.gz} from all the source
706 files.
707 @end table
708
709 @node Standard Directory Variables
710 @subsection Standard Directory Variables
711 @cindex directory variables
712
713 The GNU Coding Standards also specify a hierarchy of variables to
714 denote installation directories.  Some of these are:
715
716 @multitable {Directory variable} {@code{$@{datarootdir@}/doc/$@{PACKAGE@}}}
717 @headitem Directory variable    @tab Default value
718 @item @code{prefix}              @tab @code{/usr/local}
719 @item @w{@ @ @code{exec_prefix}} @tab @code{$@{prefix@}}
720 @item @w{@ @ @ @ @code{bindir}}  @tab @code{$@{exec_prefix@}/bin}
721 @item @w{@ @ @ @ @code{libdir}}  @tab @code{$@{exec_prefix@}/lib}
722 @item @w{@ @ @ @ @dots{}}
723 @item @w{@ @ @code{includedir}}  @tab @code{$@{prefix@}/include}
724 @item @w{@ @ @code{datarootdir}} @tab @code{$@{prefix@}/share}
725 @item @w{@ @ @ @ @code{datadir}} @tab @code{$@{datarootdir@}}
726 @item @w{@ @ @ @ @code{mandir}}  @tab @code{$@{datarootdir@}/man}
727 @item @w{@ @ @ @ @code{infodir}} @tab @code{$@{datarootdir@}/info}
728 @item @w{@ @ @ @ @code{docdir}}  @tab @code{$@{datarootdir@}/doc/$@{PACKAGE@}}
729 @item @w{@ @ @dots{}}
730 @end multitable
731
732 @c We should provide a complete table somewhere, but not here.  The
733 @c complete list of directory variables it too confusing as-is.  It
734 @c requires some explanations that are too complicated for this
735 @c introduction.  Besides listing directories like localstatedir
736 @c would make the explanations in ``Two-Part Install'' harder.
737
738 Each of these directories has a role which is often obvious from its
739 name.  In a package, any installable file will be installed in one of
740 these directories.  For instance in @code{amhello-1.0}, the program
741 @file{hello} is to be installed in @var{bindir}, the directory for
742 binaries.  The default value for this directory is
743 @file{/usr/local/bin}, but the user can supply a different value when
744 calling @command{configure}.  Also the file @file{README} will be
745 installed into @var{docdir}, which defaults to
746 @file{/usr/local/share/doc/amhello}.
747
748 @opindex --prefix
749
750 As a user, if you wish to install a package on your own account, you
751 could proceed as follows:
752
753 @example
754 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
755 @dots{}
756 ~/amhello-1.0 % @kbd{make}
757 @dots{}
758 ~/amhello-1.0 % @kbd{make install}
759 @dots{}
760 @end example
761
762 This would install @file{~/usr/bin/hello} and
763 @file{~/usr/share/doc/amhello/README}.
764
765 The list of all such directory options is shown by
766 @code{./configure --help}.
767
768 @node Standard Configuration Variables
769 @subsection Standard Configuration Variables
770 @cindex configuration variables, overriding
771
772 The GNU Coding Standards also define a set of standard configuration
773 variables used during the build.  Here are some:
774
775 @table @asis
776 @item @code{CC}
777 C compiler command
778 @item @code{CFLAGS}
779 C compiler flags
780 @item @code{CXX}
781 C++ compiler command
782 @item @code{CXXFLAGS}
783 C++ compiler flags
784 @item @code{LDFLAGS}
785 linker flags
786 @item @code{CPPFLAGS}
787 C/C++ preprocessor flags
788 @item @dots{}
789 @end table
790
791 @command{configure} usually does a good job at setting appropriate
792 values for these variables, but there are cases where you may want to
793 override them.  For instance you may have several versions of a
794 compiler installed and would like to use another one, you may have
795 header files installed outside the default search path of the
796 compiler, or even libraries out of the way of the linker.
797
798 Here is how one would call @command{configure} to force it to use
799 @command{gcc-3} as C compiler, use header files from
800 @file{~/usr/include} when compiling, and libraries from
801 @file{~/usr/lib} when linking.
802
803 @example
804 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
805 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
806 @end example
807
808 Again, a full list of these variables appears in the output of
809 @code{./configure --help}.
810
811 @node config.site
812 @subsection Overriding Default Configuration Setting with @file{config.site}
813 @cindex @file{config.site} example
814
815 When installing several packages using the same setup, it can be
816 convenient to create a file to capture common settings.
817 If a file named @file{@var{prefix}/share/config.site} exists,
818 @command{configure} will source it at the beginning of its execution.
819
820 Recall the command from the previous section:
821
822 @example
823 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
824 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
825 @end example
826
827 Assuming we are installing many package in @file{~/usr}, and will
828 always want to use these definitions of @code{CC}, @code{CPPFLAGS}, and
829 @code{LDFLAGS}, we can automate this by creating the following
830 @file{~/usr/share/config.site} file:
831
832 @example
833 test -z "$CC" && CC=gcc-3
834 test -z "$CPPFLAGS" && CPPFLAGS=-I$HOME/usr/include
835 test -z "$LDFLAGS" && LDFLAGS=-L$HOME/usr/lib
836 @end example
837
838 Now, any time a @file{configure} script is using the @file{~/usr}
839 prefix, it will execute the above @file{config.site} and define
840 these three variables.
841
842 @example
843 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
844 configure: loading site script /home/adl/usr/share/config.site
845 @dots{}
846 @end example
847
848 @xref{Site Defaults, , Setting Site Defaults, autoconf, The Autoconf
849 Manual}, for more information about this feature.
850
851
852 @node VPATH Builds
853 @subsection Parallel Build Trees (a.k.a.@: VPATH Builds)
854 @cindex Parallel build trees
855 @cindex VPATH builds
856 @cindex source tree and build tree
857 @cindex build tree and source tree
858 @cindex trees, source vs.@: build
859
860 The GNU Build System distinguishes two trees: the source tree, and
861 the build tree.
862
863 The source tree is rooted in the directory containing
864 @file{configure}.  It contains all the sources files (those that are
865 distributed), and may be arranged using several subdirectories.
866
867 The build tree is rooted in the directory in which @file{configure}
868 was run, and is populated with all object files, programs, libraries,
869 and other derived files built from the sources (and hence not
870 distributed).  The build tree usually has the same subdirectory layout
871 as the source tree; its subdirectories are created automatically by
872 the build system.
873
874 If @file{configure} is executed in its own directory, the source and
875 build trees are combined: derived files are constructed in the same
876 directories as their sources.  This was the case in our first
877 installation example (@pxref{Basic Installation}).
878
879 A common request from users is that they want to confine all derived
880 files to a single directory, to keep their source directories
881 uncluttered.  Here is how we could run @file{configure} to build
882 everything in a subdirectory called @file{build/}.
883
884 @example
885 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
886 ~ % @kbd{cd amhello-1.0}
887 ~/amhello-1.0 % @kbd{mkdir build && cd build}
888 ~/amhello-1.0/build % @kbd{../configure}
889 @dots{}
890 ~/amhello-1.0/build % @kbd{make}
891 @dots{}
892 @end example
893
894 These setups, where source and build trees are different, are often
895 called @dfn{parallel builds} or @dfn{VPATH builds}.  The expression
896 @emph{parallel build} is misleading: the word @emph{parallel} is a
897 reference to the way the build tree shadows the source tree, it is not
898 about some concurrency in the way build commands are run.  For this
899 reason we refer to such setups using the name @emph{VPATH builds} in
900 the following.  @emph{VPATH} is the name of the @command{make} feature
901 used by the @file{Makefile}s to allow these builds (@pxref{General
902 Search, , @code{VPATH} Search Path for All Prerequisites, make, The
903 GNU Make Manual}).
904
905 @cindex multiple configurations, example
906 @cindex debug build, example
907 @cindex optimized build, example
908
909 VPATH builds have other interesting uses.  One is to build the same
910 sources with multiple configurations.  For instance:
911
912 @c Keep in sync with amhello-cflags.sh
913 @example
914 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
915 ~ % @kbd{cd amhello-1.0}
916 ~/amhello-1.0 % @kbd{mkdir debug optim && cd debug}
917 ~/amhello-1.0/debug % @kbd{../configure CFLAGS='-g -O0'}
918 @dots{}
919 ~/amhello-1.0/debug % @kbd{make}
920 @dots{}
921 ~/amhello-1.0/debug % cd ../optim
922 ~/amhello-1.0/optim % @kbd{../configure CFLAGS='-O3 -fomit-frame-pointer'}
923 @dots{}
924 ~/amhello-1.0/optim % @kbd{make}
925 @dots{}
926 @end example
927
928 With network file systems, a similar approach can be used to build the
929 same sources on different machines.  For instance, suppose that the
930 sources are installed on a directory shared by two hosts: @code{HOST1}
931 and @code{HOST2}, which may be different platforms.
932
933 @example
934 ~ % @kbd{cd /nfs/src}
935 /nfs/src % @kbd{tar zxf ~/amhello-1.0.tar.gz}
936 @end example
937
938 On the first host, you could create a local build directory:
939 @example
940 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
941 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
942 ...
943 [HOST1] /tmp/amh % @kbd{make && sudo make install}
944 ...
945 @end example
946
947 @noindent
948 (Here we assume that the installer has configured @command{sudo} so it
949 can execute @code{make install} with root privileges; it is more convenient
950 than using @command{su} like in @ref{Basic Installation}).
951
952 On the second host, you would do exactly the same, possibly at
953 the same time:
954 @example
955 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
956 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
957 ...
958 [HOST2] /tmp/amh % @kbd{make && sudo make install}
959 ...
960 @end example
961
962 @cindex read-only source tree
963 @cindex source tree, read-only
964
965 In this scenario, nothing forbids the @file{/nfs/src/amhello-1.0}
966 directory from being read-only.  In fact VPATH builds are also a means
967 of building packages from a read-only medium such as a CD-ROM.  (The
968 FSF used to sell CD-ROM with unpacked source code, before the GNU
969 project grew so big.)
970
971 @node Two-Part Install
972 @subsection Two-Part Installation
973
974 In our last example (@pxref{VPATH Builds}), a source tree was shared
975 by two hosts, but compilation and installation were done separately on
976 each host.
977
978 The GNU Build System also supports networked setups where part of the
979 installed files should be shared amongst multiple hosts.  It does so
980 by distinguishing architecture-dependent files from
981 architecture-independent files, and providing two @file{Makefile}
982 targets to install each of these classes of files.
983
984 @trindex install-exec
985 @trindex install-data
986
987 These targets are @code{install-exec} for architecture-dependent files
988 and @code{install-data} for architecture-independent files.
989 The command we used up to now, @code{make install}, can be thought of
990 as a shorthand for @code{make install-exec install-data}.
991
992 From the GNU Build System point of view, the distinction between
993 architecture-dependent files and architecture-independent files is
994 based exclusively on the directory variable used to specify their
995 installation destination.  In the list of directory variables we
996 provided earlier (@pxref{Standard Directory Variables}), all the
997 variables based on @var{exec-prefix} designate architecture-dependent
998 directories whose files will be installed by @code{make install-exec}.
999 The others designate architecture-independent directories and will
1000 serve files installed by @code{make install-data}.  @xref{The Two Parts
1001 of Install}, for more details.
1002
1003 Here is how we could revisit our two-host installation example,
1004 assuming that (1) we want to install the package directly in
1005 @file{/usr}, and (2) the directory @file{/usr/share} is shared by the
1006 two hosts.
1007
1008 On the first host we would run
1009 @example
1010 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1011 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1012 ...
1013 [HOST1] /tmp/amh % @kbd{make && sudo make install}
1014 ...
1015 @end example
1016
1017 On the second host, however, we need only install the
1018 architecture-specific files.
1019 @example
1020 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1021 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1022 ...
1023 [HOST2] /tmp/amh % @kbd{make && sudo make install-exec}
1024 ...
1025 @end example
1026
1027 In packages that have installation checks, it would make sense to run
1028 @code{make installcheck} (@pxref{Basic Installation}) to verify that
1029 the package works correctly despite the apparent partial installation.
1030
1031 @node Cross-Compilation
1032 @subsection Cross-Compilation
1033 @cindex cross-compilation
1034
1035 To @dfn{cross-compile} is to build on one platform a binary that will
1036 run on another platform.  When speaking of cross-compilation, it is
1037 important to distinguish between the @dfn{build platform} on which
1038 the compilation is performed, and the @dfn{host platform} on which the
1039 resulting executable is expected to run.  The following
1040 @command{configure} options are used to specify each of them:
1041
1042 @table @option
1043 @item --build=@var{build}
1044 @opindex --build=@var{build}
1045 The system on which the package is built.
1046 @item --host=@var{host}
1047 @opindex --host=@var{host}
1048 The system where built programs and libraries will run.
1049 @end table
1050
1051 When the @option{--host} is used, @command{configure} will search for
1052 the cross-compiling suite for this platform.  Cross-compilation tools
1053 commonly have their target architecture as prefix of their name.  For
1054 instance my cross-compiler for MinGW32 has its binaries called
1055 @code{i586-mingw32msvc-gcc}, @code{i586-mingw32msvc-ld},
1056 @code{i586-mingw32msvc-as}, etc.
1057
1058 @cindex MinGW cross-compilation example
1059 @cindex cross-compilation example
1060
1061 Here is how we could build @code{amhello-1.0} for
1062 @code{i586-mingw32msvc} on a GNU/Linux PC.
1063
1064 @c Keep in sync with amhello-cross-compile.sh
1065 @smallexample
1066 ~/amhello-1.0 % @kbd{./configure --build i686-pc-linux-gnu --host i586-mingw32msvc}
1067 checking for a BSD-compatible install... /usr/bin/install -c
1068 checking whether build environment is sane... yes
1069 checking for gawk... gawk
1070 checking whether make sets $(MAKE)... yes
1071 checking for i586-mingw32msvc-strip... i586-mingw32msvc-strip
1072 checking for i586-mingw32msvc-gcc... i586-mingw32msvc-gcc
1073 checking for C compiler default output file name... a.exe
1074 checking whether the C compiler works... yes
1075 checking whether we are cross compiling... yes
1076 checking for suffix of executables... .exe
1077 checking for suffix of object files... o
1078 checking whether we are using the GNU C compiler... yes
1079 checking whether i586-mingw32msvc-gcc accepts -g... yes
1080 checking for i586-mingw32msvc-gcc option to accept ANSI C...
1081 @dots{}
1082 ~/amhello-1.0 % @kbd{make}
1083 @dots{}
1084 ~/amhello-1.0 % @kbd{cd src; file hello.exe}
1085 hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable
1086 @end smallexample
1087
1088 The @option{--host} and @option{--build} options are usually all we
1089 need for cross-compiling.  The only exception is if the package being
1090 built is itself a cross-compiler: we need a third option to specify
1091 its target architecture.
1092
1093 @table @option
1094 @item --target=@var{target}
1095 @opindex --target=@var{target}
1096 When building compiler tools: the system for which the tools will
1097 create output.
1098 @end table
1099
1100 For instance when installing GCC, the GNU Compiler Collection, we can
1101 use @option{--target=@/@var{target}} to specify that we want to build
1102 GCC as a cross-compiler for @var{target}.  Mixing @option{--build} and
1103 @option{--target}, we can actually cross-compile a cross-compiler;
1104 such a three-way cross-compilation is known as a @dfn{Canadian cross}.
1105
1106 @xref{Specifying Names, , Specifying the System Type, autoconf, The
1107 Autoconf Manual}, for more information about these @command{configure}
1108 options.
1109
1110 @node Renaming
1111 @subsection Renaming Programs at Install Time
1112 @cindex Renaming programs
1113 @cindex Transforming program names
1114 @cindex Programs, renaming during installation
1115
1116 The GNU Build System provides means to automatically rename
1117 executables and manpages before they are installed (@pxref{Man Pages}).
1118 This is especially convenient
1119 when installing a GNU package on a system that already has a
1120 proprietary implementation you do not want to overwrite.  For instance,
1121 you may want to install GNU @command{tar} as @command{gtar} so you can
1122 distinguish it from your vendor's @command{tar}.
1123
1124 This can be done using one of these three @command{configure} options.
1125
1126 @table @option
1127 @item --program-prefix=@var{prefix}
1128 @opindex --program-prefix=@var{prefix}
1129 Prepend @var{prefix} to installed program names.
1130 @item --program-suffix=@var{suffix}
1131 @opindex --program-suffix=@var{suffix}
1132 Append @var{suffix} to installed program names.
1133 @item --program-transform-name=@var{program}
1134 @opindex --program-transform-name=@var{program}
1135 Run @code{sed @var{program}} on installed program names.
1136 @end table
1137
1138 The following commands would install @file{hello}
1139 as @file{/usr/local/bin/test-hello}, for instance.
1140
1141 @example
1142 ~/amhello-1.0 % @kbd{./configure --program-prefix test-}
1143 @dots{}
1144 ~/amhello-1.0 % @kbd{make}
1145 @dots{}
1146 ~/amhello-1.0 % @kbd{sudo make install}
1147 @dots{}
1148 @end example
1149
1150 @node DESTDIR
1151 @subsection Building Binary Packages Using DESTDIR
1152 @vindex DESTDIR
1153
1154 The GNU Build System's @code{make install} and @code{make uninstall}
1155 interface does not exactly fit the needs of a system administrator
1156 who has to deploy and upgrade packages on lots of hosts.  In other
1157 words, the GNU Build System does not replace a package manager.
1158
1159 Such package managers usually need to know which files have been
1160 installed by a package, so a mere @code{make install} is
1161 inappropriate.
1162
1163 @cindex Staged installation
1164
1165 The @code{DESTDIR} variable can be used to perform a staged
1166 installation.  The package should be configured as if it was going to
1167 be installed in its final location (e.g., @code{--prefix /usr}), but
1168 when running @code{make install}, the @code{DESTDIR} should be set to
1169 the absolute name of a directory into which the installation will be
1170 diverted.  From this directory it is easy to review which files are
1171 being installed where, and finally copy them to their final location
1172 by some means.
1173
1174 @cindex Binary package
1175
1176 For instance here is how we could create a binary package containing a
1177 snapshot of all the files to be installed.
1178
1179 @c Keep in sync with amhello-binpkg.sh
1180 @example
1181 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1182 @dots{}
1183 ~/amhello-1.0 % @kbd{make}
1184 @dots{}
1185 ~/amhello-1.0 % @kbd{make DESTDIR=$HOME/inst install}
1186 @dots{}
1187 ~/amhello-1.0 % @kbd{cd ~/inst}
1188 ~/inst % @kbd{find . -type f -print > ../files.lst}
1189 ~/inst % @kbd{tar zcvf ~/amhello-1.0-i686.tar.gz `cat ../files.lst`}
1190 ./usr/bin/hello
1191 ./usr/share/doc/amhello/README
1192 @end example
1193
1194 After this example, @code{amhello-1.0-i686.tar.gz} is ready to be
1195 uncompressed in @file{/} on many hosts.  (Using @code{`cat ../files.lst`}
1196 instead of @samp{.} as argument for @command{tar} avoids entries for
1197 each subdirectory in the archive: we would not like @command{tar} to
1198 restore the modification time of @file{/}, @file{/usr/}, etc.)
1199
1200 Note that when building packages for several architectures, it might
1201 be convenient to use @code{make install-data} and @code{make
1202 install-exec} (@pxref{Two-Part Install}) to gather
1203 architecture-independent files in a single package.
1204
1205 @xref{Install}, for more information.
1206
1207 @c We should document PRE_INSTALL/POST_INSTALL/NORMAL_INSTALL and their
1208 @c UNINSTALL counterparts.
1209
1210 @node Preparing Distributions
1211 @subsection Preparing Distributions
1212 @cindex Preparing distributions
1213 @cindex Packages, preparation
1214 @cindex Distributions, preparation
1215
1216 We have already mentioned @code{make dist}.  This target collects all
1217 your source files and the necessary parts of the build system to
1218 create a tarball named @file{@var{package}-@var{version}.tar.gz}.
1219
1220 @cindex @code{distcheck} better than @code{dist}
1221
1222 Another, more useful command is @code{make distcheck}.  The
1223 @code{distcheck} target constructs
1224 @file{@var{package}-@var{version}.tar.gz} just as well as @code{dist},
1225 but it additionally ensures most of the use cases presented so far
1226 work:
1227
1228 @itemize @bullet
1229 @item
1230 It attempts a full compilation of the package (@pxref{Basic
1231 Installation}), unpacking the newly constructed tarball, running
1232 @code{make}, @code{make check}, @code{make install}, as well as
1233 @code{make installcheck}, and even @code{make dist},
1234 @item
1235 it tests VPATH builds with read-only source tree (@pxref{VPATH Builds}),
1236 @item
1237 it makes sure @code{make clean}, @code{make distclean}, and @code{make
1238 uninstall} do not omit any file (@pxref{Standard Targets}),
1239 @item
1240 and it checks that @code{DESTDIR} installations work (@pxref{DESTDIR}).
1241 @end itemize
1242
1243 All of these actions are performed in a temporary subdirectory, so
1244 that no root privileges are required.
1245
1246 Releasing a package that fails @code{make distcheck} means that one of
1247 the scenarios we presented will not work and some users will be
1248 disappointed.  Therefore it is a good practice to release a package
1249 only after a successful @code{make distcheck}.  This of course does
1250 not imply that the package will be flawless, but at least it will
1251 prevent some of the embarrassing errors you may find in packages
1252 released by people who have never heard about @code{distcheck} (like
1253 @code{DESTDIR} not working because of a typo, or a distributed file
1254 being erased by @code{make clean}, or even @code{VPATH} builds not
1255 working).
1256
1257 @xref{Creating amhello}, to recreate @file{amhello-1.0.tar.gz} using
1258 @code{make distcheck}.  @xref{Checking the Distribution}, for more
1259 information about @code{distcheck}.
1260
1261 @node Dependency Tracking
1262 @subsection Automatic Dependency Tracking
1263 @cindex Dependency tracking
1264
1265 Dependency tracking is performed as a side-effect of compilation.
1266 Each time the build system compiles a source file, it computes its
1267 list of dependencies (in C these are the header files included by the
1268 source being compiled).  Later, any time @command{make} is run and a
1269 dependency appears to have changed, the dependent files will be
1270 rebuilt.
1271
1272 Automake generates code for automatic dependency tracking by default,
1273 unless the developer chooses to override it; for more information,
1274 @pxref{Dependencies}.
1275
1276 When @command{configure} is executed, you can see it probing each
1277 compiler for the dependency mechanism it supports (several mechanisms
1278 can be used):
1279
1280 @example
1281 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1282 @dots{}
1283 checking dependency style of gcc... gcc3
1284 @dots{}
1285 @end example
1286
1287 Because dependencies are only computed as a side-effect of the
1288 compilation, no dependency information exists the first time a package
1289 is built.  This is OK because all the files need to be built anyway:
1290 @code{make} does not have to decide which files need to be rebuilt.
1291 In fact, dependency tracking is completely useless for one-time builds
1292 and there is a @command{configure} option to disable this:
1293
1294 @table @option
1295 @item --disable-dependency-tracking
1296 @opindex --disable-dependency-tracking
1297 Speed up one-time builds.
1298 @end table
1299
1300 Some compilers do not offer any practical way to derive the list of
1301 dependencies as a side-effect of the compilation, requiring a separate
1302 run (maybe of another tool) to compute these dependencies.  The
1303 performance penalty implied by these methods is important enough to
1304 disable them by default.  The option @option{--enable-dependency-tracking}
1305 must be passed to @command{configure} to activate them.
1306
1307 @table @option
1308 @item --enable-dependency-tracking
1309 @opindex --enable-dependency-tracking
1310 Do not reject slow dependency extractors.
1311 @end table
1312
1313 @xref{Dependency Tracking Evolution, , Dependency Tracking Evolution,
1314 automake-history, Brief History of Automake}, for some discussion about
1315 the different dependency tracking schemes used by Automake over the years.
1316
1317 @node Nested Packages
1318 @subsection Nested Packages
1319 @cindex Nested packages
1320 @cindex Packages, nested
1321 @cindex Subpackages
1322
1323 Although nesting packages isn't something we would recommend to
1324 someone who is discovering the Autotools, it is a nice feature worthy
1325 of mention in this small advertising tour.
1326
1327 Autoconfiscated packages (that means packages whose build system have
1328 been created by Autoconf and friends) can be nested to arbitrary
1329 depth.
1330
1331 A typical setup is that package A will distribute one of the libraries
1332 it needs in a subdirectory.  This library B is a complete package with
1333 its own GNU Build System.  The @command{configure} script of A will
1334 run the @command{configure} script of B as part of its execution,
1335 building and installing A will also build and install B.  Generating a
1336 distribution for A will also include B.
1337
1338 It is possible to gather several packages like this.  GCC is a heavy
1339 user of this feature.  This gives installers a single package to
1340 configure, build and install, while it allows developers to work on
1341 subpackages independently.
1342
1343 When configuring nested packages, the @command{configure} options
1344 given to the top-level @command{configure} are passed recursively to
1345 nested @command{configure}s.  A package that does not understand an
1346 option will ignore it, assuming it is meaningful to some other
1347 package.
1348
1349 @opindex --help=recursive
1350
1351 The command @code{configure --help=recursive} can be used to display
1352 the options supported by all the included packages.
1353
1354 @xref{Subpackages}, for an example setup.
1355
1356 @node Why Autotools
1357 @section How Autotools Help
1358 @cindex Autotools, purpose
1359
1360 There are several reasons why you may not want to implement the GNU
1361 Build System yourself (read: write a @file{configure} script and
1362 @file{Makefile}s yourself).
1363
1364 @itemize @bullet
1365 @item
1366 As we have seen, the GNU Build System has a lot of
1367 features (@pxref{Use Cases}).
1368 Some users may expect features you have not implemented because
1369 you did not need them.
1370 @item
1371 Implementing these features portably is difficult and exhausting.
1372 Think of writing portable shell scripts, and portable
1373 @file{Makefile}s, for systems you may not have handy.  @xref{Portable
1374 Shell, , Portable Shell Programming, autoconf, The Autoconf Manual}, to
1375 convince yourself.
1376 @item
1377 You will have to upgrade your setup to follow changes to the GNU
1378 Coding Standards.
1379 @end itemize
1380
1381 The GNU Autotools take all this burden off your back and provide:
1382
1383 @itemize @bullet
1384 @item
1385 Tools to create a portable, complete, and self-contained GNU Build
1386 System, from simple instructions.
1387 @emph{Self-contained} meaning the resulting build system does not
1388 require the GNU Autotools.
1389 @item
1390 A central place where fixes and improvements are made:
1391 a bug-fix for a portability issue will benefit every package.
1392 @end itemize
1393
1394 Yet there also exist reasons why you may want NOT to use the
1395 Autotools@enddots{} For instance you may be already using (or used to)
1396 another incompatible build system.  Autotools will only be useful if
1397 you do accept the concepts of the GNU Build System.  People who have their
1398 own idea of how a build system should work will feel frustrated by the
1399 Autotools.
1400
1401 @node Hello World
1402 @section A Small Hello World
1403 @cindex Example Hello World
1404 @cindex Hello World example
1405 @cindex @file{amhello-1.0.tar.gz}, creation
1406
1407 In this section we recreate the @file{amhello-1.0} package from
1408 scratch.  The first subsection shows how to call the Autotools to
1409 instantiate the GNU Build System, while the second explains the
1410 meaning of the @file{configure.ac} and @file{Makefile.am} files read
1411 by the Autotools.
1412
1413 @anchor{amhello Explained}
1414 @menu
1415 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
1416 * amhello's configure.ac Setup Explained::
1417 * amhello's Makefile.am Setup Explained::
1418 @end menu
1419
1420 @node Creating amhello
1421 @subsection Creating @file{amhello-1.0.tar.gz}
1422
1423 Here is how we can recreate @file{amhello-1.0.tar.gz} from scratch.
1424 The package is simple enough so that we will only need to write 5
1425 files.  (You may copy them from the final @file{amhello-1.0.tar.gz}
1426 that is distributed with Automake if you do not want to write them.)
1427
1428 Create the following files in an empty directory.
1429
1430 @itemize @bullet
1431
1432 @item
1433 @file{src/main.c} is the source file for the @file{hello} program.  We
1434 store it in the @file{src/} subdirectory, because later, when the package
1435 evolves, it will ease the addition of a @file{man/} directory for man
1436 pages, a @file{data/} directory for data files, etc.
1437 @example
1438 ~/amhello % @kbd{cat src/main.c}
1439 #include <config.h>
1440 #include <stdio.h>
1441
1442 int
1443 main (void)
1444 @{
1445   puts ("Hello World!");
1446   puts ("This is " PACKAGE_STRING ".");
1447   return 0;
1448 @}
1449 @end example
1450
1451 @item
1452 @file{README} contains some very limited documentation for our little
1453 package.
1454 @example
1455 ~/amhello % @kbd{cat README}
1456 This is a demonstration package for GNU Automake.
1457 Type `info Automake' to read the Automake manual.
1458 @end example
1459
1460 @item
1461 @file{Makefile.am} and @file{src/Makefile.am} contain Automake
1462 instructions for these two directories.
1463
1464 @example
1465 ~/amhello % @kbd{cat src/Makefile.am}
1466 bin_PROGRAMS = hello
1467 hello_SOURCES = main.c
1468 ~/amhello % @kbd{cat Makefile.am}
1469 SUBDIRS = src
1470 dist_doc_DATA = README
1471 @end example
1472
1473 @item
1474 Finally, @file{configure.ac} contains Autoconf instructions to
1475 create the @command{configure} script.
1476
1477 @example
1478 ~/amhello % @kbd{cat configure.ac}
1479 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1480 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1481 AC_PROG_CC
1482 AC_CONFIG_HEADERS([config.h])
1483 AC_CONFIG_FILES([
1484  Makefile
1485  src/Makefile
1486 ])
1487 AC_OUTPUT
1488 @end example
1489 @end itemize
1490
1491 @cindex @command{autoreconf}, example
1492
1493 Once you have these five files, it is time to run the Autotools to
1494 instantiate the build system.  Do this using the @command{autoreconf}
1495 command as follows:
1496
1497 @example
1498 ~/amhello % @kbd{autoreconf --install}
1499 configure.ac: installing `./install-sh'
1500 configure.ac: installing `./missing'
1501 src/Makefile.am: installing `./depcomp'
1502 @end example
1503
1504 At this point the build system is complete.
1505
1506 In addition to the three scripts mentioned in its output, you can see
1507 that @command{autoreconf} created four other files: @file{configure},
1508 @file{config.h.in}, @file{Makefile.in}, and @file{src/Makefile.in}.
1509 The latter three files are templates that will be adapted to the
1510 system by @command{configure} under the names @file{config.h},
1511 @file{Makefile}, and @file{src/Makefile}.  Let's do this:
1512
1513 @example
1514 ~/amhello % @kbd{./configure}
1515 checking for a BSD-compatible install... /usr/bin/install -c
1516 checking whether build environment is sane... yes
1517 checking for gawk... no
1518 checking for mawk... mawk
1519 checking whether make sets $(MAKE)... yes
1520 checking for gcc... gcc
1521 checking for C compiler default output file name... a.out
1522 checking whether the C compiler works... yes
1523 checking whether we are cross compiling... no
1524 checking for suffix of executables...
1525 checking for suffix of object files... o
1526 checking whether we are using the GNU C compiler... yes
1527 checking whether gcc accepts -g... yes
1528 checking for gcc option to accept ISO C89... none needed
1529 checking for style of include used by make... GNU
1530 checking dependency style of gcc... gcc3
1531 configure: creating ./config.status
1532 config.status: creating Makefile
1533 config.status: creating src/Makefile
1534 config.status: creating config.h
1535 config.status: executing depfiles commands
1536 @end example
1537
1538 @trindex distcheck
1539 @cindex @code{distcheck} example
1540
1541 You can see @file{Makefile}, @file{src/Makefile}, and @file{config.h}
1542 being created at the end after @command{configure} has probed the
1543 system.  It is now possible to run all the targets we wish
1544 (@pxref{Standard Targets}).  For instance:
1545
1546 @example
1547 ~/amhello % @kbd{make}
1548 @dots{}
1549 ~/amhello % @kbd{src/hello}
1550 Hello World!
1551 This is amhello 1.0.
1552 ~/amhello % @kbd{make distcheck}
1553 @dots{}
1554 =============================================
1555 amhello-1.0 archives ready for distribution:
1556 amhello-1.0.tar.gz
1557 =============================================
1558 @end example
1559
1560 Note that running @command{autoreconf} is only needed initially when
1561 the GNU Build System does not exist.  When you later change some
1562 instructions in a @file{Makefile.am} or @file{configure.ac}, the
1563 relevant part of the build system will be regenerated automatically
1564 when you execute @command{make}.
1565
1566 @command{autoreconf} is a script that calls @command{autoconf},
1567 @command{automake}, and a bunch of other commands in the right order.
1568 If you are beginning with these tools, it is not important to figure
1569 out in which order all these tools should be invoked and why.  However,
1570 because Autoconf and Automake have separate manuals, the important
1571 point to understand is that @command{autoconf} is in charge of
1572 creating @file{configure} from @file{configure.ac}, while
1573 @command{automake} is in charge of creating @file{Makefile.in}s from
1574 @file{Makefile.am}s and @file{configure.ac}.  This should at least
1575 direct you to the right manual when seeking answers.
1576
1577
1578 @node amhello's configure.ac Setup Explained
1579 @subsection @code{amhello}'s @file{configure.ac} Setup Explained
1580
1581 @cindex @file{configure.ac}, Hello World
1582
1583 Let us begin with the contents of @file{configure.ac}.
1584
1585 @example
1586 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1587 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1588 AC_PROG_CC
1589 AC_CONFIG_HEADERS([config.h])
1590 AC_CONFIG_FILES([
1591  Makefile
1592  src/Makefile
1593 ])
1594 AC_OUTPUT
1595 @end example
1596
1597 This file is read by both @command{autoconf} (to create
1598 @file{configure}) and @command{automake} (to create the various
1599 @file{Makefile.in}s).  It contains a series of M4 macros that will be
1600 expanded as shell code to finally form the @file{configure} script.
1601 We will not elaborate on the syntax of this file, because the Autoconf
1602 manual has a whole section about it (@pxref{Writing Autoconf Input, ,
1603 Writing @file{configure.ac}, autoconf, The Autoconf Manual}).
1604
1605 The macros prefixed with @code{AC_} are Autoconf macros, documented
1606 in the Autoconf manual (@pxref{Autoconf Macro Index, , Autoconf Macro
1607 Index, autoconf, The Autoconf Manual}).  The macros that start with
1608 @code{AM_} are Automake macros, documented later in this manual
1609 (@pxref{Macro Index}).
1610
1611 The first two lines of @file{configure.ac} initialize Autoconf and
1612 Automake.  @code{AC_INIT} takes in as parameters the name of the package,
1613 its version number, and a contact address for bug-reports about the
1614 package (this address is output at the end of @code{./configure
1615 --help}, for instance).  When adapting this setup to your own package,
1616 by all means please do not blindly copy Automake's address: use the
1617 mailing list of your package, or your own mail address.
1618
1619 @opindex -Wall
1620 @opindex -Werror
1621 @opindex foreign
1622
1623 The argument to @code{AM_INIT_AUTOMAKE} is a list of options for
1624 @command{automake} (@pxref{Options}).  @option{-Wall} and
1625 @option{-Werror} ask @command{automake} to turn on all warnings and
1626 report them as errors.  We are speaking of @strong{Automake} warnings
1627 here, such as dubious instructions in @file{Makefile.am}.  This has
1628 absolutely nothing to do with how the compiler will be called, even
1629 though it may support options with similar names.  Using @option{-Wall
1630 -Werror} is a safe setting when starting to work on a package: you do
1631 not want to miss any issues.  Later you may decide to relax things a
1632 bit.  The @option{foreign} option tells Automake that this package
1633 will not follow the GNU Standards.  GNU packages should always
1634 distribute additional files such as @file{ChangeLog}, @file{AUTHORS},
1635 etc.  We do not want @command{automake} to complain about these
1636 missing files in our small example.
1637
1638 The @code{AC_PROG_CC} line causes the @command{configure} script to
1639 search for a C compiler and define the variable @code{CC} with its
1640 name.  The @file{src/Makefile.in} file generated by Automake uses the
1641 variable @code{CC} to build @file{hello}, so when @command{configure}
1642 creates @file{src/Makefile} from @file{src/Makefile.in}, it will define
1643 @code{CC} with the value it has found.  If Automake is asked to create
1644 a @file{Makefile.in} that uses @code{CC} but @file{configure.ac} does
1645 not define it, it will suggest you add a call to @code{AC_PROG_CC}.
1646
1647 The @code{AC_CONFIG_HEADERS([config.h])} invocation causes the
1648 @command{configure} script to create a @file{config.h} file gathering
1649 @samp{#define}s defined by other macros in @file{configure.ac}.  In our
1650 case, the @code{AC_INIT} macro already defined a few of them.  Here
1651 is an excerpt of @file{config.h} after @command{configure} has run:
1652
1653 @smallexample
1654 @dots{}
1655 /* Define to the address where bug reports for this package should be sent. */
1656 #define PACKAGE_BUGREPORT "@value{PACKAGE_BUGREPORT}"
1657
1658 /* Define to the full name and version of this package. */
1659 #define PACKAGE_STRING "amhello 1.0"
1660 @dots{}
1661 @end smallexample
1662
1663 As you probably noticed, @file{src/main.c} includes @file{config.h} so
1664 it can use @code{PACKAGE_STRING}.  In a real-world project,
1665 @file{config.h} can grow really big, with one @samp{#define} per
1666 feature probed on the system.
1667
1668 The @code{AC_CONFIG_FILES} macro declares the list of files that
1669 @command{configure} should create from their @file{*.in} templates.
1670 Automake also scans this list to find the @file{Makefile.am} files it must
1671 process.  (This is important to remember: when adding a new directory
1672 to your project, you should add its @file{Makefile} to this list,
1673 otherwise Automake will never process the new @file{Makefile.am} you
1674 wrote in that directory.)
1675
1676 Finally, the @code{AC_OUTPUT} line is a closing command that actually
1677 produces the part of the script in charge of creating the files
1678 registered with @code{AC_CONFIG_HEADERS} and @code{AC_CONFIG_FILES}.
1679
1680 @cindex @command{autoscan}
1681
1682 When starting a new project, we suggest you start with such a simple
1683 @file{configure.ac}, and gradually add the other tests it requires.
1684 The command @command{autoscan} can also suggest a few of the tests
1685 your package may need (@pxref{autoscan Invocation, , Using
1686 @command{autoscan} to Create @file{configure.ac}, autoconf, The
1687 Autoconf Manual}).
1688
1689
1690 @node amhello's Makefile.am Setup Explained
1691 @subsection @code{amhello}'s @file{Makefile.am} Setup Explained
1692
1693 @cindex @file{Makefile.am}, Hello World
1694
1695 We now turn to @file{src/Makefile.am}.  This file contains
1696 Automake instructions to build and install @file{hello}.
1697
1698 @example
1699 bin_PROGRAMS = hello
1700 hello_SOURCES = main.c
1701 @end example
1702
1703 A @file{Makefile.am} has the same syntax as an ordinary
1704 @file{Makefile}.  When @command{automake} processes a
1705 @file{Makefile.am} it copies the entire file into the output
1706 @file{Makefile.in} (that will be later turned into @file{Makefile} by
1707 @command{configure}) but will react to certain variable definitions
1708 by generating some build rules and other variables.
1709 Often @file{Makefile.am}s contain only a list of variable definitions as
1710 above, but they can also contain other variable and rule definitions that
1711 @command{automake} will pass along without interpretation.
1712
1713 Variables that end with @code{_PROGRAMS} are special variables
1714 that list programs that the resulting @file{Makefile} should build.
1715 In Automake speak, this @code{_PROGRAMS} suffix is called a
1716 @dfn{primary}; Automake recognizes other primaries such as
1717 @code{_SCRIPTS}, @code{_DATA}, @code{_LIBRARIES}, etc.@: corresponding
1718 to different types of files.
1719
1720 The @samp{bin} part of the @code{bin_PROGRAMS} tells
1721 @command{automake} that the resulting programs should be installed in
1722 @var{bindir}.  Recall that the GNU Build System uses a set of variables
1723 to denote destination directories and allow users to customize these
1724 locations (@pxref{Standard Directory Variables}).  Any such directory
1725 variable can be put in front of a primary (omitting the @code{dir}
1726 suffix) to tell @command{automake} where to install the listed files.
1727
1728 Programs need to be built from source files, so for each program
1729 @code{@var{prog}} listed in a @code{@w{_PROGRAMS}} variable,
1730 @command{automake} will look for another variable named
1731 @code{@var{prog}_SOURCES} listing its source files.  There may be more
1732 than one source file: they will all be compiled and linked together.
1733
1734 Automake also knows that source files need to be distributed when
1735 creating a tarball (unlike built programs).  So a side-effect of this
1736 @code{hello_SOURCES} declaration is that @file{main.c} will be
1737 part of the tarball created by @code{make dist}.
1738
1739 Finally here are some explanations regarding the top-level
1740 @file{Makefile.am}.
1741
1742 @example
1743 SUBDIRS = src
1744 dist_doc_DATA = README
1745 @end example
1746
1747 @code{SUBDIRS} is a special variable listing all directories that
1748 @command{make} should recurse into before processing the current
1749 directory.  So this line is responsible for @command{make} building
1750 @file{src/hello} even though we run it from the top-level.  This line
1751 also causes @code{make install} to install @file{src/hello} before
1752 installing @file{README} (not that this order matters).
1753
1754 The line @code{dist_doc_DATA = README} causes @file{README} to be
1755 distributed and installed in @var{docdir}.  Files listed with the
1756 @code{_DATA} primary are not automatically part of the tarball built
1757 with @code{make dist}, so we add the @code{dist_} prefix so they get
1758 distributed.  However, for @file{README} it would not have been
1759 necessary: @command{automake} automatically distributes any
1760 @file{README} file it encounters (the list of other files
1761 automatically distributed is presented by @code{automake --help}).
1762 The only important effect of this second line is therefore to install
1763 @file{README} during @code{make install}.
1764
1765 One thing not covered in this example is accessing the installation
1766 directory values (@pxref{Standard Directory Variables}) from your
1767 program code, that is, converting them into defined macros.  For this,
1768 @pxref{Defining Directories,,, autoconf, The Autoconf Manual}.
1769
1770
1771 @node Generalities
1772 @chapter General ideas
1773
1774 The following sections cover a few basic ideas that will help you
1775 understand how Automake works.
1776
1777 @menu
1778 * General Operation::           General operation of Automake
1779 * Strictness::                  Standards conformance checking
1780 * Uniform::                     The Uniform Naming Scheme
1781 * Length Limitations::          Staying below the command line length limit
1782 * Canonicalization::            How derived variables are named
1783 * User Variables::              Variables reserved for the user
1784 * Auxiliary Programs::          Programs automake might require
1785 @end menu
1786
1787
1788 @node General Operation
1789 @section General Operation
1790
1791 Automake works by reading a @file{Makefile.am} and generating a
1792 @file{Makefile.in}.  Certain variables and rules defined in the
1793 @file{Makefile.am} instruct Automake to generate more specialized code;
1794 for instance, a @code{bin_PROGRAMS} variable definition will cause rules
1795 for compiling and linking programs to be generated.
1796
1797 @cindex Non-standard targets
1798 @cindex @code{git-dist}, non-standard example
1799 @trindex git-dist
1800
1801 The variable definitions and rules in the @file{Makefile.am} are
1802 copied mostly verbatim into the generated file, with all variable
1803 definitions preceding all rules.  This allows you to add almost
1804 arbitrary code into the generated @file{Makefile.in}.  For instance,
1805 the Automake distribution includes a non-standard rule for the
1806 @code{git-dist} target, which the Automake maintainer uses to make
1807 distributions from the source control system.
1808
1809 @cindex GNU make extensions
1810
1811 Note that most GNU make extensions are not recognized by Automake.  Using
1812 such extensions in a @file{Makefile.am} will lead to errors or confusing
1813 behavior.
1814
1815 @cindex Append operator
1816 @cmindex +=
1817 A special exception is that the GNU make append operator, @samp{+=}, is
1818 supported.  This operator appends its right hand argument to the variable
1819 specified on the left.  Automake will translate the operator into
1820 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
1821
1822 Automake tries to keep comments grouped with any adjoining rules or
1823 variable definitions.
1824
1825 @cindex Limitations of automake parser
1826 @cindex Automake parser, limitations of
1827 @cindex indentation in Makefile.am
1828 Generally, Automake is not particularly smart in the parsing of unusual
1829 Makefile constructs, so you're advised to avoid fancy constructs or
1830 ``creative'' use of whitespaces.
1831 @c Keep this in sync with doc-parsing-buglets-tabs.sh
1832 For example, @key{TAB} characters cannot be used between a target name
1833 and the following ``@code{:}'' character, and variable assignments
1834 shouldn't be indented with @key{TAB} characters.
1835 @c Keep this in sync with doc-parsing-buglets-colneq-subst.sh
1836 Also, using more complex macro in target names can cause trouble:
1837
1838 @example
1839 % @kbd{cat Makefile.am}
1840 $(FOO:=x): bar
1841 % @kbd{automake}
1842 Makefile.am:1: bad characters in variable name `$(FOO'
1843 Makefile.am:1: `:='-style assignments are not portable
1844 @end example
1845
1846 @cindex Make targets, overriding
1847 @cindex Make rules, overriding
1848 @cindex Overriding make rules
1849 @cindex Overriding make targets
1850
1851 A rule defined in @file{Makefile.am} generally overrides any such
1852 rule of a similar name that would be automatically generated by
1853 @command{automake}.  Although this is a supported feature, it is generally
1854 best to avoid making use of it, as sometimes the generated rules are
1855 very particular.
1856
1857 @cindex Variables, overriding
1858 @cindex Overriding make variables
1859
1860 Similarly, a variable defined in @file{Makefile.am} or
1861 @code{AC_SUBST}ed from @file{configure.ac} will override any
1862 definition of the variable that @command{automake} would ordinarily
1863 create.  This feature is more often useful than the ability to
1864 override a rule.  Be warned that many of the variables generated by
1865 @command{automake} are considered to be for internal use only, and their
1866 names might change in future releases.
1867
1868 @cindex Recursive operation of Automake
1869 @cindex Automake, recursive operation
1870 @cindex Example of recursive operation
1871
1872 When examining a variable definition, Automake will recursively examine
1873 variables referenced in the definition.  For example, if Automake is
1874 looking at the content of @code{foo_SOURCES} in this snippet
1875
1876 @c Keep in sync with interp.sh
1877 @example
1878 xs = a.c b.c
1879 foo_SOURCES = c.c $(xs)
1880 @end example
1881
1882 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
1883 contents of @code{foo_SOURCES}.
1884
1885 @cindex @code{##} (special Automake comment)
1886 @cindex Special Automake comment
1887 @cindex Comment, special to Automake
1888
1889 Automake also allows a form of comment that is @emph{not} copied into
1890 the output; all lines beginning with @samp{##} (leading spaces allowed)
1891 are completely ignored by Automake.
1892
1893 It is customary to make the first line of @file{Makefile.am} read:
1894
1895 @cindex Makefile.am, first line
1896 @cindex First line of Makefile.am
1897
1898 @example
1899 ## Process this file with automake to produce Makefile.in
1900 @end example
1901
1902 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
1903 @c I don't know quite what to say.
1904
1905 @c FIXME document customary ordering of Makefile.am here!
1906
1907
1908 @node Strictness
1909 @section Strictness
1910
1911 @cindex Non-GNU packages
1912
1913 While Automake is intended to be used by maintainers of GNU packages, it
1914 does make some effort to accommodate those who wish to use it, but do
1915 not want to use all the GNU conventions.
1916
1917 @cindex Strictness, defined
1918 @cindex Strictness, @option{foreign}
1919 @cindex @option{foreign} strictness
1920 @cindex Strictness, @option{gnu}
1921 @cindex @option{gnu} strictness
1922 @cindex Strictness, @option{gnits}
1923 @cindex @option{gnits} strictness
1924
1925 To this end, Automake supports three levels of @dfn{strictness}---the
1926 strictness indicating how stringently Automake should check standards
1927 conformance.
1928
1929 The valid strictness levels are:
1930
1931 @table @option
1932 @item foreign
1933 Automake will check for only those things that are absolutely
1934 required for proper operations.  For instance, whereas GNU standards
1935 dictate the existence of a @file{NEWS} file, it will not be required in
1936 this mode.  This strictness will also turn off some warnings by default
1937 (among them, portability warnings).
1938 The name comes from the fact that Automake is intended to be
1939 used for GNU programs; these relaxed rules are not the standard mode of
1940 operation.
1941
1942 @item gnu
1943 Automake will check---as much as possible---for compliance to the GNU
1944 standards for packages.  This is the default.
1945
1946 @item gnits
1947 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
1948 standards}.  These are based on the GNU standards, but are even more
1949 detailed.  Unless you are a Gnits standards contributor, it is
1950 recommended that you avoid this option until such time as the Gnits
1951 standard is actually published (which may never happen).
1952 @end table
1953
1954 @xref{Gnits}, for more information on the precise implications of the
1955 strictness level.
1956
1957 Automake also has a special (and @emph{today deprecated}) ``cygnus'' mode
1958 that is similar to strictness but handled differently.  This mode is
1959 useful for packages that are put into a ``Cygnus'' style tree (e.g., older
1960 versions of the GCC and gdb trees).  @xref{Cygnus}, for more information
1961 on this mode.  Please note that this mode is deprecated and @emph{will be
1962 removed in the future automake versions}; you must avoid its use in new
1963 packages, and should stop using it in existing packages as well.
1964
1965
1966 @node Uniform
1967 @section The Uniform Naming Scheme
1968
1969 @cindex Uniform naming scheme
1970
1971 Automake variables generally follow a @dfn{uniform naming scheme} that
1972 makes it easy to decide how programs (and other derived objects) are
1973 built, and how they are installed.  This scheme also supports
1974 @command{configure} time determination of what should be built.
1975
1976 @cindex @code{_PROGRAMS} primary variable
1977 @cindex @code{PROGRAMS} primary variable
1978 @cindex Primary variable, @code{PROGRAMS}
1979 @cindex Primary variable, defined
1980 @vindex _PROGRAMS
1981
1982 At @command{make} time, certain variables are used to determine which
1983 objects are to be built.  The variable names are made of several pieces
1984 that are concatenated together.
1985
1986 The piece that tells @command{automake} what is being built is commonly called
1987 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
1988 list of programs that are to be compiled and linked.
1989 @vindex PROGRAMS
1990
1991 @cindex @code{pkgdatadir}, defined
1992 @cindex @code{pkgincludedir}, defined
1993 @cindex @code{pkglibdir}, defined
1994 @cindex @code{pkglibexecdir}, defined
1995
1996 @vindex pkgdatadir
1997 @vindex pkgincludedir
1998 @vindex pkglibdir
1999 @vindex pkglibexecdir
2000
2001 @cindex @code{PACKAGE}, directory
2002 A different set of names is used to decide where the built objects
2003 should be installed.  These names are prefixes to the primary, and they
2004 indicate which standard directory should be used as the installation
2005 directory.  The standard directory names are given in the GNU standards
2006 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
2007 Automake extends this list with @code{pkgdatadir}, @code{pkgincludedir},
2008 @code{pkglibdir}, and @code{pkglibexecdir}; these are the same as the
2009 non-@samp{pkg} versions, but with @samp{$(PACKAGE)} appended.  For instance,
2010 @code{pkglibdir} is defined as @samp{$(libdir)/$(PACKAGE)}.
2011
2012 @cindex @code{EXTRA_}, prepending
2013 For each primary, there is one additional variable named by prepending
2014 @samp{EXTRA_} to the primary name.  This variable is used to list
2015 objects that may or may not be built, depending on what
2016 @command{configure} decides.  This variable is required because Automake
2017 must statically know the entire list of objects that may be built in
2018 order to generate a @file{Makefile.in} that will work in all cases.
2019
2020 @cindex @code{EXTRA_PROGRAMS}, defined
2021 @cindex Example, @code{EXTRA_PROGRAMS}
2022 @cindex @command{cpio} example
2023
2024 For instance, @command{cpio} decides at configure time which programs
2025 should be built.  Some of the programs are installed in @code{bindir},
2026 and some are installed in @code{sbindir}:
2027
2028 @example
2029 EXTRA_PROGRAMS = mt rmt
2030 bin_PROGRAMS = cpio pax
2031 sbin_PROGRAMS = $(MORE_PROGRAMS)
2032 @end example
2033
2034 Defining a primary without a prefix as a variable, e.g.,
2035 @samp{PROGRAMS}, is an error.
2036
2037 Note that the common @samp{dir} suffix is left off when constructing the
2038 variable names; thus one writes @samp{bin_PROGRAMS} and not
2039 @samp{bindir_PROGRAMS}.
2040
2041 Not every sort of object can be installed in every directory.  Automake
2042 will flag those attempts it finds in error (but see below how to override
2043 the check if you really need to).
2044 Automake will also diagnose obvious misspellings in directory names.
2045
2046 @cindex Extending list of installation directories
2047 @cindex Installation directories, extending list
2048
2049 Sometimes the standard directories---even as augmented by
2050 Automake---are not enough.  In particular it is sometimes useful, for
2051 clarity, to install objects in a subdirectory of some predefined
2052 directory.  To this end, Automake allows you to extend the list of
2053 possible installation directories.  A given prefix (e.g., @samp{zar})
2054 is valid if a variable of the same name with @samp{dir} appended is
2055 defined (e.g., @samp{zardir}).
2056
2057 For instance, the following snippet will install @file{file.xml} into
2058 @samp{$(datadir)/xml}.
2059
2060 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2061 @example
2062 xmldir = $(datadir)/xml
2063 xml_DATA = file.xml
2064 @end example
2065
2066 This feature can also be used to override the sanity checks Automake
2067 performs to diagnose suspicious directory/primary couples (in the
2068 unlikely case these checks are undesirable, and you really know what
2069 you're doing).  For example, Automake would error out on this input:
2070
2071 @c Should be tested in primary-prefix-invalid-couples.sh
2072 @example
2073 # Forbidden directory combinations, automake will error out on this.
2074 pkglib_PROGRAMS = foo
2075 doc_LIBRARIES = libquux.a
2076 @end example
2077
2078 @noindent
2079 but it will succeed with this:
2080
2081 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2082 @example
2083 # Work around forbidden directory combinations.  Do not use this
2084 # without a very good reason!
2085 my_execbindir = $(pkglibdir)
2086 my_doclibdir = $(docdir)
2087 my_execbin_PROGRAMS = foo
2088 my_doclib_LIBRARIES = libquux.a
2089 @end example
2090
2091 The @samp{exec} substring of the @samp{my_execbindir} variable lets
2092 the files be installed at the right time (@pxref{The Two Parts of
2093 Install}).
2094
2095 @cindex @samp{noinst_} primary prefix, definition
2096 @vindex noinst_
2097
2098 The special prefix @samp{noinst_} indicates that the objects in question
2099 should be built but not installed at all.  This is usually used for
2100 objects required to build the rest of your package, for instance static
2101 libraries (@pxref{A Library}), or helper scripts.
2102
2103 @cindex @samp{check_} primary prefix, definition
2104 @vindex check_
2105
2106 The special prefix @samp{check_} indicates that the objects in question
2107 should not be built until the @samp{make check} command is run.  Those
2108 objects are not installed either.
2109
2110 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
2111 @samp{LTLIBRARIES}, @samp{LISP}, @samp{PYTHON}, @samp{JAVA},
2112 @samp{SCRIPTS}, @samp{DATA}, @samp{HEADERS}, @samp{MANS}, and
2113 @samp{TEXINFOS}.
2114 @vindex PROGRAMS
2115 @vindex LIBRARIES
2116 @vindex LTLIBRARIES
2117 @vindex LISP
2118 @vindex PYTHON
2119 @vindex JAVA
2120 @vindex SCRIPTS
2121 @vindex DATA
2122 @vindex HEADERS
2123 @vindex MANS
2124 @vindex TEXINFOS
2125
2126 Some primaries also allow additional prefixes that control other
2127 aspects of @command{automake}'s behavior.  The currently defined prefixes
2128 are @samp{dist_}, @samp{nodist_}, @samp{nobase_}, and @samp{notrans_}.
2129 These prefixes are explained later (@pxref{Program and Library Variables})
2130 (@pxref{Man Pages}).
2131
2132
2133 @node Length Limitations
2134 @section Staying below the command line length limit
2135
2136 @cindex command line length limit
2137 @cindex ARG_MAX
2138
2139 Traditionally, most unix-like systems have a length limitation for the
2140 command line arguments and environment contents when creating new
2141 processes (see for example
2142 @uref{http://www.in-ulm.de/@/~mascheck/@/various/@/argmax/} for an
2143 overview on this issue),
2144 which of course also applies to commands spawned by @command{make}.
2145 POSIX requires this limit to be at least 4096 bytes, and most modern
2146 systems have quite high limits (or are unlimited).
2147
2148 In order to create portable Makefiles that do not trip over these
2149 limits, it is necessary to keep the length of file lists bounded.
2150 Unfortunately, it is not possible to do so fully transparently within
2151 Automake, so your help may be needed.  Typically, you can split long
2152 file lists manually and use different installation directory names for
2153 each list.  For example,
2154
2155 @example
2156 data_DATA = file1 @dots{} file@var{N} file@var{N+1} @dots{} file@var{2N}
2157 @end example
2158
2159 @noindent
2160 may also be written as
2161
2162 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2163 @example
2164 data_DATA = file1 @dots{} file@var{N}
2165 data2dir = $(datadir)
2166 data2_DATA = file@var{N+1} @dots{} file@var{2N}
2167 @end example
2168
2169 @noindent
2170 and will cause Automake to treat the two lists separately during
2171 @code{make install}.  See @ref{The Two Parts of Install} for choosing
2172 directory names that will keep the ordering of the two parts of
2173 installation Note that @code{make dist} may still only work on a host
2174 with a higher length limit in this example.
2175
2176 Automake itself employs a couple of strategies to avoid long command
2177 lines.  For example, when @samp{$@{srcdir@}/} is prepended to file
2178 names, as can happen with above @code{$(data_DATA)} lists, it limits
2179 the amount of arguments passed to external commands.
2180
2181 Unfortunately, some system's @command{make} commands may prepend
2182 @code{VPATH} prefixes like @samp{$@{srcdir@}/} to file names from the
2183 source tree automatically (@pxref{Automatic Rule Rewriting, , Automatic
2184 Rule Rewriting, autoconf, The Autoconf Manual}).  In this case, the user
2185 may have to switch to use GNU Make, or refrain from using VPATH builds,
2186 in order to stay below the length limit.
2187
2188 For libraries and programs built from many sources, convenience archives
2189 may be used as intermediates in order to limit the object list length
2190 (@pxref{Libtool Convenience Libraries}).
2191
2192
2193 @node Canonicalization
2194 @section How derived variables are named
2195
2196 @cindex canonicalizing Automake variables
2197
2198 Sometimes a Makefile variable name is derived from some text the
2199 maintainer supplies.  For instance, a program name listed in
2200 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
2201 variable.  In cases like this, Automake canonicalizes the text, so that
2202 program names and the like do not have to follow Makefile variable naming
2203 rules.  All characters in the name except for letters, numbers, the
2204 strudel (@@), and the underscore are turned into underscores when making
2205 variable references.
2206
2207 For example, if your program is named @file{sniff-glue}, the derived
2208 variable name would be @samp{sniff_glue_SOURCES}, not
2209 @samp{sniff-glue_SOURCES}.  Similarly the sources for a library named
2210 @file{libmumble++.a} should be listed in the
2211 @samp{libmumble___a_SOURCES} variable.
2212
2213 The strudel is an addition, to make the use of Autoconf substitutions in
2214 variable names less obfuscating.
2215
2216
2217 @node User Variables
2218 @section Variables reserved for the user
2219
2220 @cindex variables, reserved for the user
2221 @cindex user variables
2222
2223 Some @file{Makefile} variables are reserved by the GNU Coding Standards
2224 for the use of the ``user''---the person building the package.  For
2225 instance, @code{CFLAGS} is one such variable.
2226
2227 Sometimes package developers are tempted to set user variables such as
2228 @code{CFLAGS} because it appears to make their job easier.  However,
2229 the package itself should never set a user variable, particularly not
2230 to include switches that are required for proper compilation of the
2231 package.  Since these variables are documented as being for the
2232 package builder, that person rightfully expects to be able to override
2233 any of these variables at build time.
2234
2235 To get around this problem, Automake introduces an automake-specific
2236 shadow variable for each user flag variable.  (Shadow variables are
2237 not introduced for variables like @code{CC}, where they would make no
2238 sense.)  The shadow variable is named by prepending @samp{AM_} to the
2239 user variable's name.  For instance, the shadow variable for
2240 @code{YFLAGS} is @code{AM_YFLAGS}.  The package maintainer---that is,
2241 the author(s) of the @file{Makefile.am} and @file{configure.ac}
2242 files---may adjust these shadow variables however necessary.
2243
2244 @xref{Flag Variables Ordering}, for more discussion about these
2245 variables and how they interact with per-target variables.
2246
2247 @node Auxiliary Programs
2248 @section Programs automake might require
2249
2250 @cindex Programs, auxiliary
2251 @cindex Auxiliary programs
2252
2253 Automake sometimes requires helper programs so that the generated
2254 @file{Makefile} can do its work properly.  There are a fairly large
2255 number of them, and we list them here.
2256
2257 Although all of these files are distributed and installed with
2258 Automake, a couple of them are maintained separately.  The Automake
2259 copies are updated before each release, but we mention the original
2260 source in case you need more recent versions.
2261
2262 @table @code
2263 @item ar-lib
2264 This is a wrapper primarily for the Microsoft lib archiver, to make
2265 it more POSIX-like.
2266
2267 @item compile
2268 This is a wrapper for compilers that do not accept options @option{-c}
2269 and @option{-o} at the same time.  It is only used when absolutely
2270 required.  Such compilers are rare, with the Microsoft C/C++ Compiler
2271 as the most notable exception. This wrapper also makes the following
2272 common options available for that compiler, while performing file name
2273 translation where needed: @option{-I}, @option{-L}, @option{-l},
2274 @option{-Wl,} and @option{-Xlinker}.
2275
2276 @item config.guess
2277 @itemx config.sub
2278 These two programs compute the canonical triplets for the given build,
2279 host, or target architecture.  These programs are updated regularly to
2280 support new architectures and fix probes broken by changes in new
2281 kernel versions.  Each new release of Automake comes with up-to-date
2282 copies of these programs.  If your copy of Automake is getting old,
2283 you are encouraged to fetch the latest versions of these files from
2284 @url{http://savannah.gnu.org/git/?group=config} before making a
2285 release.
2286
2287 @item depcomp
2288 This program understands how to run a compiler so that it will
2289 generate not only the desired output but also dependency information
2290 that is then used by the automatic dependency tracking feature
2291 (@pxref{Dependencies}).
2292
2293 @item elisp-comp
2294 This program is used to byte-compile Emacs Lisp code.
2295
2296 @item install-sh
2297 This is a replacement for the @command{install} program that works on
2298 platforms where @command{install} is unavailable or unusable.
2299
2300 @item mdate-sh
2301 This script is used to generate a @file{version.texi} file.  It examines
2302 a file and prints some date information about it.
2303
2304 @item missing
2305 This wraps a number of programs that are typically only required by
2306 maintainers.  If the program in question doesn't exist,
2307 @command{missing} prints an informative warning and attempts to fix
2308 things so that the build can continue.
2309
2310 @item mkinstalldirs
2311 This script used to be a wrapper around @samp{mkdir -p}, which is not
2312 portable.  Now we prefer to use @samp{install-sh -d} when @command{configure}
2313 finds that @samp{mkdir -p} does not work, this makes one less script to
2314 distribute.
2315
2316 For backward compatibility @file{mkinstalldirs} is still used and
2317 distributed when @command{automake} finds it in a package.  But it is no
2318 longer installed automatically, and it should be safe to remove it.
2319
2320 @item py-compile
2321 This is used to byte-compile Python scripts.
2322
2323 @item test-driver
2324 This implements the default test driver offered by the parallel
2325 testsuite harness.
2326
2327 @item texinfo.tex
2328 Not a program, this file is required for @samp{make dvi}, @samp{make
2329 ps} and @samp{make pdf} to work when Texinfo sources are in the
2330 package.  The latest version can be downloaded from
2331 @url{http://www.gnu.org/software/texinfo/}.
2332
2333 @item ylwrap
2334 This program wraps @command{lex} and @command{yacc} to rename their
2335 output files.  It also ensures that, for instance, multiple
2336 @command{yacc} instances can be invoked in a single directory in
2337 parallel.
2338
2339 @end table
2340
2341
2342 @node Examples
2343 @chapter Some example packages
2344
2345 This section contains two small examples.
2346
2347 The first example (@pxref{Complete}) assumes you have an existing
2348 project already using Autoconf, with handcrafted @file{Makefile}s, and
2349 that you want to convert it to using Automake.  If you are discovering
2350 both tools, it is probably better that you look at the Hello World
2351 example presented earlier (@pxref{Hello World}).
2352
2353 The second example (@pxref{true}) shows how two programs can be built
2354 from the same file, using different compilation parameters.  It
2355 contains some technical digressions that are probably best skipped on
2356 first read.
2357
2358 @menu
2359 * Complete::                    A simple example, start to finish
2360 * true::                        Building true and false
2361 @end menu
2362
2363
2364 @node Complete
2365 @section A simple example, start to finish
2366
2367 @cindex Complete example
2368
2369 Let's suppose you just finished writing @code{zardoz}, a program to make
2370 your head float from vortex to vortex.  You've been using Autoconf to
2371 provide a portability framework, but your @file{Makefile.in}s have been
2372 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
2373
2374 @cindex @code{AM_INIT_AUTOMAKE}, example use
2375
2376 The first step is to update your @file{configure.ac} to include the
2377 commands that @command{automake} needs.  The way to do this is to add an
2378 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
2379
2380 @example
2381 AC_INIT([zardoz], [1.0])
2382 AM_INIT_AUTOMAKE
2383 @dots{}
2384 @end example
2385
2386 Since your program doesn't have any complicating factors (e.g., it
2387 doesn't use @code{gettext}, it doesn't want to build a shared library),
2388 you're done with this part.  That was easy!
2389
2390 @cindex @command{aclocal} program, introduction
2391 @cindex @file{aclocal.m4}, preexisting
2392 @cindex @file{acinclude.m4}, defined
2393
2394 Now you must regenerate @file{configure}.  But to do that, you'll need
2395 to tell @command{autoconf} how to find the new macro you've used.  The
2396 easiest way to do this is to use the @command{aclocal} program to
2397 generate your @file{aclocal.m4} for you.  But wait@dots{} maybe you
2398 already have an @file{aclocal.m4}, because you had to write some hairy
2399 macros for your program.  The @command{aclocal} program lets you put
2400 your own macros into @file{acinclude.m4}, so simply rename and then
2401 run:
2402
2403 @example
2404 mv aclocal.m4 acinclude.m4
2405 aclocal
2406 autoconf
2407 @end example
2408
2409 @cindex @command{zardoz} example
2410
2411 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
2412 Since @code{zardoz} is a user program, you want to install it where the
2413 rest of the user programs go: @code{bindir}.  Additionally,
2414 @code{zardoz} has some Texinfo documentation.  Your @file{configure.ac}
2415 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
2416 @samp{$(LIBOBJS)}.  So here's what you'd write:
2417
2418 @example
2419 bin_PROGRAMS = zardoz
2420 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
2421 zardoz_LDADD = $(LIBOBJS)
2422
2423 info_TEXINFOS = zardoz.texi
2424 @end example
2425
2426 Now you can run @samp{automake --add-missing} to generate your
2427 @file{Makefile.in} and grab any auxiliary files you might need, and
2428 you're done!
2429
2430
2431 @node true
2432 @section Building true and false
2433
2434 @cindex Example, @command{false} and @command{true}
2435 @cindex @command{false} Example
2436 @cindex @command{true} Example
2437
2438 Here is another, trickier example.  It shows how to generate two
2439 programs (@code{true} and @code{false}) from the same source file
2440 (@file{true.c}).  The difficult part is that each compilation of
2441 @file{true.c} requires different @code{cpp} flags.
2442
2443 @example
2444 bin_PROGRAMS = true false
2445 false_SOURCES =
2446 false_LDADD = false.o
2447
2448 true.o: true.c
2449         $(COMPILE) -DEXIT_CODE=0 -c true.c
2450
2451 false.o: true.c
2452         $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
2453 @end example
2454
2455 Note that there is no @code{true_SOURCES} definition.  Automake will
2456 implicitly assume that there is a source file named @file{true.c}
2457 (@pxref{Default _SOURCES}), and
2458 define rules to compile @file{true.o} and link @file{true}.  The
2459 @samp{true.o: true.c} rule supplied by the above @file{Makefile.am},
2460 will override the Automake generated rule to build @file{true.o}.
2461
2462 @code{false_SOURCES} is defined to be empty---that way no implicit value
2463 is substituted.  Because we have not listed the source of
2464 @file{false}, we have to tell Automake how to link the program.  This is
2465 the purpose of the @code{false_LDADD} line.  A @code{false_DEPENDENCIES}
2466 variable, holding the dependencies of the @file{false} target will be
2467 automatically generated by Automake from the content of
2468 @code{false_LDADD}.
2469
2470 The above rules won't work if your compiler doesn't accept both
2471 @option{-c} and @option{-o}.  The simplest fix for this is to introduce a
2472 bogus dependency (to avoid problems with a parallel @command{make}):
2473
2474 @example
2475 true.o: true.c false.o
2476         $(COMPILE) -DEXIT_CODE=0 -c true.c
2477
2478 false.o: true.c
2479         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
2480 @end example
2481
2482 As it turns out, there is also a much easier way to do this same task.
2483 Some of the above technique is useful enough that we've kept the
2484 example in the manual.  However if you were to build @code{true} and
2485 @code{false} in real life, you would probably use per-program
2486 compilation flags, like so:
2487
2488 @c Keep in sync with specflg7.sh and specflg8.sh
2489 @example
2490 bin_PROGRAMS = false true
2491
2492 false_SOURCES = true.c
2493 false_CPPFLAGS = -DEXIT_CODE=1
2494
2495 true_SOURCES = true.c
2496 true_CPPFLAGS = -DEXIT_CODE=0
2497 @end example
2498
2499 In this case Automake will cause @file{true.c} to be compiled twice,
2500 with different flags.  In this instance, the names of the object files
2501 would be chosen by automake; they would be @file{false-true.o} and
2502 @file{true-true.o}. (The name of the object files rarely matters.)
2503
2504 @node automake Invocation
2505 @chapter Creating a @file{Makefile.in}
2506 @c This node used to be named "Invoking automake".  This @anchor
2507 @c allows old links to still work.
2508 @anchor{Invoking automake}
2509
2510 @cindex Multiple @file{configure.ac} files
2511 @cindex Invoking @command{automake}
2512 @cindex @command{automake}, invoking
2513 @cindex Invocation of @command{automake}
2514 @cindex @command{automake}, invocation
2515
2516 To create all the @file{Makefile.in}s for a package, run the
2517 @command{automake} program in the top level directory, with no
2518 arguments.  @command{automake} will automatically find each
2519 appropriate @file{Makefile.am} (by scanning @file{configure.ac};
2520 @pxref{configure}) and generate the corresponding @file{Makefile.in}.
2521 Note that @command{automake} has a rather simplistic view of what
2522 constitutes a package; it assumes that a package has only one
2523 @file{configure.ac}, at the top.  If your package has multiple
2524 @file{configure.ac}s, then you must run @command{automake} in each
2525 directory holding a @file{configure.ac}.  (Alternatively, you may rely
2526 on Autoconf's @command{autoreconf}, which is able to recurse your
2527 package tree and run @command{automake} where appropriate.)
2528
2529 You can optionally give @command{automake} an argument; @file{.am} is
2530 appended to the argument and the result is used as the name of the
2531 input file.  This feature is generally only used to automatically
2532 rebuild an out-of-date @file{Makefile.in}.  Note that
2533 @command{automake} must always be run from the topmost directory of a
2534 project, even if being used to regenerate the @file{Makefile.in} in
2535 some subdirectory.  This is necessary because @command{automake} must
2536 scan @file{configure.ac}, and because @command{automake} uses the
2537 knowledge that a @file{Makefile.in} is in a subdirectory to change its
2538 behavior in some cases.
2539
2540 @vindex AUTOCONF
2541 Automake will run @command{autoconf} to scan @file{configure.ac} and
2542 its dependencies (i.e., @file{aclocal.m4} and any included file),
2543 therefore @command{autoconf} must be in your @env{PATH}.  If there is
2544 an @env{AUTOCONF} variable in your environment it will be used
2545 instead of @command{autoconf}, this allows you to select a particular
2546 version of Autoconf.  By the way, don't misunderstand this paragraph:
2547 @command{automake} runs @command{autoconf} to @strong{scan} your
2548 @file{configure.ac}, this won't build @file{configure} and you still
2549 have to run @command{autoconf} yourself for this purpose.
2550
2551 @cindex @command{automake} options
2552 @cindex Options, @command{automake}
2553 @cindex Strictness, command line
2554
2555 @command{automake} accepts the following options:
2556
2557 @cindex Extra files distributed with Automake
2558 @cindex Files distributed with Automake
2559 @cindex @file{config.guess}
2560
2561 @table @code
2562 @item -a
2563 @itemx --add-missing
2564 @opindex -a
2565 @opindex --add-missing
2566 Automake requires certain common files to exist in certain situations;
2567 for instance, @file{config.guess} is required if @file{configure.ac} invokes
2568 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
2569 files (@pxref{Auxiliary Programs}); this option will cause the missing
2570 ones to be automatically added to the package, whenever possible.  In
2571 general if Automake tells you a file is missing, try using this option.
2572 By default Automake tries to make a symbolic link pointing to its own
2573 copy of the missing file; this can be changed with @option{--copy}.
2574
2575 Many of the potentially-missing files are common scripts whose
2576 location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
2577 Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
2578 file is considered missing, and where the missing file is added
2579 (@pxref{Optional}).
2580
2581 In some strictness modes, additional files are installed, see @ref{Gnits}
2582 for more information.
2583
2584 @item --libdir=@var{dir}
2585 @opindex --libdir
2586 Look for Automake data files in directory @var{dir} instead of in the
2587 installation directory.  This is typically used for debugging.
2588
2589 @item --print-libdir
2590 @opindex --print-libdir
2591 Print the path of the installation directory containing Automake-provided
2592 scripts and data files (like e.g., @file{texinfo.texi} and
2593 @file{install-sh}).
2594
2595 @item -c
2596 @opindex -c
2597 @itemx --copy
2598 @opindex --copy
2599 When used with @option{--add-missing}, causes installed files to be
2600 copied.  The default is to make a symbolic link.
2601
2602 @item --cygnus
2603 @opindex --cygnus
2604 Causes the generated @file{Makefile.in}s to follow Cygnus rules, instead
2605 of GNU or Gnits rules.  For more information, see @ref{Cygnus}.
2606 Note that @emph{this mode of operation is deprecated, and will be removed}
2607 in a future Automake release.
2608
2609 @item -f
2610 @opindex -f
2611 @itemx --force-missing
2612 @opindex --force-missing
2613 When used with @option{--add-missing}, causes standard files to be reinstalled
2614 even if they already exist in the source tree.  This involves removing
2615 the file from the source tree before creating the new symlink (or, with
2616 @option{--copy}, copying the new file).
2617
2618 @item --foreign
2619 @opindex --foreign
2620 Set the global strictness to @option{foreign}.  For more information, see
2621 @ref{Strictness}.
2622
2623 @item --gnits
2624 @opindex --gnits
2625 Set the global strictness to @option{gnits}.  For more information, see
2626 @ref{Gnits}.
2627
2628 @item --gnu
2629 @opindex --gnu
2630 Set the global strictness to @option{gnu}.  For more information, see
2631 @ref{Gnits}.  This is the default strictness.
2632
2633 @item --help
2634 @opindex --help
2635 Print a summary of the command line options and exit.
2636
2637 @item -i
2638 @itemx --ignore-deps
2639 @opindex -i
2640 This disables the dependency tracking feature in generated
2641 @file{Makefile}s; see @ref{Dependencies}.
2642
2643 @item --include-deps
2644 @opindex --include-deps
2645 This enables the dependency tracking feature.  This feature is enabled
2646 by default.  This option is provided for historical reasons only and
2647 probably should not be used.
2648
2649 @item --no-force
2650 @opindex --no-force
2651 Ordinarily @command{automake} creates all @file{Makefile.in}s mentioned in
2652 @file{configure.ac}.  This option causes it to only update those
2653 @file{Makefile.in}s that are out of date with respect to one of their
2654 dependents.
2655
2656 @item -o @var{dir}
2657 @itemx --output-dir=@var{dir}
2658 @opindex -o
2659 @opindex --output-dir
2660 Put the generated @file{Makefile.in} in the directory @var{dir}.
2661 Ordinarily each @file{Makefile.in} is created in the directory of the
2662 corresponding @file{Makefile.am}.  This option is deprecated and will be
2663 removed in a future release.
2664
2665 @item -v
2666 @itemx --verbose
2667 @opindex -v
2668 @opindex --verbose
2669 Cause Automake to print information about which files are being read or
2670 created.
2671
2672 @item --version
2673 @opindex --version
2674 Print the version number of Automake and exit.
2675
2676 @item -W CATEGORY
2677 @itemx --warnings=@var{category}
2678 @opindex -W
2679 @opindex --warnings
2680 Output warnings falling in @var{category}.  @var{category} can be
2681 one of:
2682 @table @code
2683 @item gnu
2684 warnings related to the GNU Coding Standards
2685 (@pxref{Top, , , standards, The GNU Coding Standards}).
2686 @item obsolete
2687 obsolete features or constructions
2688 @item override
2689 user redefinitions of Automake rules or variables
2690 @item portability
2691 portability issues (e.g., use of @command{make} features that are
2692 known to be not portable)
2693 @item extra-portability
2694 extra portability issues related to obscure tools.  One example of such
2695 a tool is the Microsoft @command{lib} archiver.
2696 @item syntax
2697 weird syntax, unused variables, typos
2698 @item unsupported
2699 unsupported or incomplete features
2700 @item all
2701 all the warnings
2702 @item none
2703 turn off all the warnings
2704 @item error
2705 treat warnings as errors
2706 @end table
2707
2708 A category can be turned off by prefixing its name with @samp{no-}.  For
2709 instance, @option{-Wno-syntax} will hide the warnings about unused
2710 variables.
2711
2712 The categories output by default are @samp{syntax} and
2713 @samp{unsupported}.  Additionally, @samp{gnu} and @samp{portability}
2714 are enabled in @option{--gnu} and @option{--gnits} strictness.
2715 On the other hand, the @option{silent-rules} options (@pxref{Options})
2716 turns off portability warnings about recursive variable expansions.
2717
2718 @c Checked by extra-portability.sh
2719 Turning off @samp{portability} will also turn off @samp{extra-portability},
2720 and similarly turning on @samp{extra-portability} will also turn on
2721 @samp{portability}.  However, turning on @samp{portability} or turning
2722 off @samp{extra-portability} will not affect the other category.
2723
2724 @vindex WARNINGS
2725 The environment variable @env{WARNINGS} can contain a comma separated
2726 list of categories to enable.  It will be taken into account before the
2727 command-line switches, this way @option{-Wnone} will also ignore any
2728 warning category enabled by @env{WARNINGS}.  This variable is also used
2729 by other tools like @command{autoconf}; unknown categories are ignored
2730 for this reason.
2731
2732 @end table
2733
2734 @vindex AUTOMAKE_JOBS
2735 If the environment variable @env{AUTOMAKE_JOBS} contains a positive
2736 number, it is taken as the maximum number of Perl threads to use in
2737 @command{automake} for generating multiple @file{Makefile.in} files
2738 concurrently.  This is an experimental feature.
2739
2740
2741 @node configure
2742 @chapter Scanning @file{configure.ac}, using @command{aclocal}
2743
2744 @cindex @file{configure.ac}, scanning
2745 @cindex Scanning @file{configure.ac}
2746 @cindex Using @command{aclocal}
2747 @cindex @command{aclocal}, using
2748
2749 Automake scans the package's @file{configure.ac} to determine certain
2750 information about the package.  Some @command{autoconf} macros are required
2751 and some variables must be defined in @file{configure.ac}.  Automake
2752 will also use information from @file{configure.ac} to further tailor its
2753 output.
2754
2755 Automake also supplies some Autoconf macros to make the maintenance
2756 easier.  These macros can automatically be put into your
2757 @file{aclocal.m4} using the @command{aclocal} program.
2758
2759 @menu
2760 * Requirements::                Configuration requirements
2761 * Optional::                    Other things Automake recognizes
2762 * aclocal Invocation::          Auto-generating aclocal.m4
2763 * Macros::                      Autoconf macros supplied with Automake
2764 @end menu
2765
2766
2767 @node Requirements
2768 @section Configuration requirements
2769
2770 @cindex Automake requirements
2771 @cindex Requirements of Automake
2772
2773 @acindex AM_INIT_AUTOMAKE
2774 The one real requirement of Automake is that your @file{configure.ac}
2775 call @code{AM_INIT_AUTOMAKE}.  This macro does several things that are
2776 required for proper Automake operation (@pxref{Macros}).
2777
2778 Here are the other macros that Automake requires but which are not run
2779 by @code{AM_INIT_AUTOMAKE}:
2780
2781 @table @code
2782 @item AC_CONFIG_FILES
2783 @itemx AC_OUTPUT
2784 @acindex AC_CONFIG_FILES
2785 @acindex AC_OUTPUT
2786 These two macros are usually invoked as follows near the end of
2787 @file{configure.ac}.
2788
2789 @example
2790 @dots{}
2791 AC_CONFIG_FILES([
2792   Makefile
2793   doc/Makefile
2794   src/Makefile
2795   src/lib/Makefile
2796   @dots{}
2797 ])
2798 AC_OUTPUT
2799 @end example
2800
2801 Automake uses these to determine which files to create (@pxref{Output, ,
2802 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
2803 is considered to be an Automake generated @file{Makefile} if there
2804 exists a file with the same name and the @file{.am} extension appended.
2805 Typically, @samp{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
2806 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
2807
2808 When using @code{AC_CONFIG_FILES} with multiple input files, as in
2809
2810 @example
2811 AC_CONFIG_FILES([Makefile:top.in:Makefile.in:bot.in])
2812 @end example
2813
2814 @noindent
2815 @command{automake} will generate the first @file{.in} input file for
2816 which a @file{.am} file exists.  If no such file exists the output
2817 file is not considered to be generated by Automake.
2818
2819 Files created by @code{AC_CONFIG_FILES}, be they Automake
2820 @file{Makefile}s or not, are all removed by @samp{make distclean}.
2821 Their inputs are automatically distributed, unless they
2822 are the output of prior @code{AC_CONFIG_FILES} commands.
2823 Finally, rebuild rules are generated in the Automake @file{Makefile}
2824 existing in the subdirectory of the output file, if there is one, or
2825 in the top-level @file{Makefile} otherwise.
2826
2827 The above machinery (cleaning, distributing, and rebuilding) works
2828 fine if the @code{AC_CONFIG_FILES} specifications contain only
2829 literals.  If part of the specification uses shell variables,
2830 @command{automake} will not be able to fulfill this setup, and you will
2831 have to complete the missing bits by hand.  For instance, on
2832
2833 @c Keep in sync with output11.sh
2834 @example
2835 file=input
2836 @dots{}
2837 AC_CONFIG_FILES([output:$file],, [file=$file])
2838 @end example
2839
2840 @noindent
2841 @command{automake} will output rules to clean @file{output}, and
2842 rebuild it.  However the rebuild rule will not depend on @file{input},
2843 and this file will not be distributed either.  (You must add
2844 @samp{EXTRA_DIST = input} to your @file{Makefile.am} if @file{input} is a
2845 source file.)
2846
2847 Similarly
2848
2849 @c Keep in sync with output11.sh
2850 @example
2851 file=output
2852 file2=out:in
2853 @dots{}
2854 AC_CONFIG_FILES([$file:input],, [file=$file])
2855 AC_CONFIG_FILES([$file2],, [file2=$file2])
2856 @end example
2857
2858 @noindent
2859 will only cause @file{input} to be distributed.  No file will be
2860 cleaned automatically (add @samp{DISTCLEANFILES = output out}
2861 yourself), and no rebuild rule will be output.
2862
2863 Obviously @command{automake} cannot guess what value @samp{$file} is
2864 going to hold later when @file{configure} is run, and it cannot use
2865 the shell variable @samp{$file} in a @file{Makefile}.  However, if you
2866 make reference to @samp{$file} as @samp{$@{file@}} (i.e., in a way
2867 that is compatible with @command{make}'s syntax) and furthermore use
2868 @code{AC_SUBST} to ensure that @samp{$@{file@}} is meaningful in a
2869 @file{Makefile}, then @command{automake} will be able to use
2870 @samp{$@{file@}} to generate all these rules.  For instance, here is
2871 how the Automake package itself generates versioned scripts for its
2872 test suite:
2873
2874 @example
2875 AC_SUBST([APIVERSION], @dots{})
2876 @dots{}
2877 AC_CONFIG_FILES(
2878   [tests/aclocal-$@{APIVERSION@}:tests/aclocal.in],
2879   [chmod +x tests/aclocal-$@{APIVERSION@}],
2880   [APIVERSION=$APIVERSION])
2881 AC_CONFIG_FILES(
2882   [tests/automake-$@{APIVERSION@}:tests/automake.in],
2883   [chmod +x tests/automake-$@{APIVERSION@}])
2884 @end example
2885
2886 @noindent
2887 Here cleaning, distributing, and rebuilding are done automatically,
2888 because @samp{$@{APIVERSION@}} is known at @command{make}-time.
2889
2890 Note that you should not use shell variables to declare
2891 @file{Makefile} files for which @command{automake} must create
2892 @file{Makefile.in}.  Even @code{AC_SUBST} does not help here, because
2893 @command{automake} needs to know the file name when it runs in order
2894 to check whether @file{Makefile.am} exists.  (In the very hairy case
2895 that your setup requires such use of variables, you will have to tell
2896 Automake which @file{Makefile.in}s to generate on the command-line.)
2897
2898 It is possible to let @command{automake} emit conditional rules for
2899 @code{AC_CONFIG_FILES} with the help of @code{AM_COND_IF}
2900 (@pxref{Optional}).
2901
2902 To summarize:
2903 @itemize @bullet
2904 @item
2905 Use literals for @file{Makefile}s, and for other files whenever possible.
2906 @item
2907 Use @samp{$file} (or @samp{$@{file@}} without @samp{AC_SUBST([file])})
2908 for files that @command{automake} should ignore.
2909 @item
2910 Use @samp{$@{file@}} and @samp{AC_SUBST([file])} for files
2911 that @command{automake} should not ignore.
2912 @end itemize
2913
2914 @end table
2915
2916
2917 @node Optional
2918 @section Other things Automake recognizes
2919
2920 @cindex Macros Automake recognizes
2921 @cindex Recognized macros by Automake
2922
2923 Every time Automake is run it calls Autoconf to trace
2924 @file{configure.ac}.  This way it can recognize the use of certain
2925 macros and tailor the generated @file{Makefile.in} appropriately.
2926 Currently recognized macros and their effects are:
2927
2928 @ftable @code
2929 @item AC_CANONICAL_BUILD
2930 @itemx AC_CANONICAL_HOST
2931 @itemx AC_CANONICAL_TARGET
2932 @vindex build_triplet
2933 @vindex host_triplet
2934 @vindex target_triplet
2935 Automake will ensure that @file{config.guess} and @file{config.sub}
2936 exist.  Also, the @file{Makefile} variables @code{build_triplet},
2937 @code{host_triplet} and @code{target_triplet} are introduced.  See
2938 @ref{Canonicalizing, , Getting the Canonical System Type, autoconf,
2939 The Autoconf Manual}.
2940
2941 @item AC_CONFIG_AUX_DIR
2942 Automake will look for various helper scripts, such as
2943 @file{install-sh}, in the directory named in this macro invocation.
2944 @c This list is accurate relative to version 1.11
2945 (The full list of scripts is:
2946 @file{ar-lib},
2947 @file{config.guess},
2948 @file{config.sub},
2949 @file{depcomp},
2950 @file{elisp-comp},
2951 @file{compile},
2952 @file{install-sh},
2953 @file{ltmain.sh},
2954 @file{mdate-sh},
2955 @file{missing},
2956 @file{mkinstalldirs},
2957 @file{py-compile},
2958 @file{test-driver},
2959 @file{texinfo.tex},
2960 @file{ylwrap}.)
2961 Not all scripts are always searched for; some scripts
2962 will only be sought if the generated @file{Makefile.in} requires them.
2963
2964 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
2965 their standard locations.  For @file{mdate-sh},
2966 @file{texinfo.tex}, and @file{ylwrap}, the standard location is the
2967 source directory corresponding to the current @file{Makefile.am}.  For
2968 the rest, the standard location is the first one of @file{.}, @file{..},
2969 or @file{../..} (relative to the top source directory) that provides any
2970 one of the helper scripts.  @xref{Input, , Finding `configure' Input,
2971 autoconf, The Autoconf Manual}.
2972
2973 Required files from @code{AC_CONFIG_AUX_DIR} are automatically
2974 distributed, even if there is no @file{Makefile.am} in this directory.
2975
2976 @item AC_CONFIG_LIBOBJ_DIR
2977 Automake will require the sources file declared with
2978 @code{AC_LIBSOURCE} (see below) in the directory specified by this
2979 macro.
2980
2981 @item AC_CONFIG_HEADERS
2982 Automake will generate rules to rebuild these headers.  Older versions
2983 of Automake required the use of @code{AM_CONFIG_HEADER}
2984 (@pxref{Macros}); this is no longer the case.
2985
2986 As with @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2987 specification using shell variables will be ignored as far as
2988 cleaning, distributing, and rebuilding is concerned.
2989
2990 @item AC_CONFIG_LINKS
2991 Automake will generate rules to remove @file{configure} generated
2992 links on @samp{make distclean} and to distribute named source files as
2993 part of @samp{make dist}.
2994
2995 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2996 specification using shell variables will be ignored as far as cleaning
2997 and distributing is concerned.  (There are no rebuild rules for links.)
2998
2999 @item AC_LIBOBJ
3000 @itemx AC_LIBSOURCE
3001 @itemx AC_LIBSOURCES
3002 @vindex LIBOBJS
3003 Automake will automatically distribute any file listed in
3004 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
3005
3006 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}.  So if
3007 an Autoconf macro is documented to call @samp{AC_LIBOBJ([file])}, then
3008 @file{file.c} will be distributed automatically by Automake.  This
3009 encompasses many macros like @code{AC_FUNC_ALLOCA},
3010 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
3011
3012 By the way, direct assignments to @code{LIBOBJS} are no longer
3013 supported.  You should always use @code{AC_LIBOBJ} for this purpose.
3014 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
3015 autoconf, The Autoconf Manual}.
3016
3017 @item AC_PROG_RANLIB
3018 This is required if any libraries are built in the package.
3019 @xref{Particular Programs, , Particular Program Checks, autoconf, The
3020 Autoconf Manual}.
3021
3022 @item AC_PROG_CXX
3023 This is required if any C++ source is included.  @xref{Particular
3024 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3025
3026 @item AC_PROG_OBJC
3027 This is required if any Objective C source is included.  @xref{Particular
3028 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3029
3030 @item AC_PROG_F77
3031 This is required if any Fortran 77 source is included.  @xref{Particular
3032 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3033
3034 @item AC_F77_LIBRARY_LDFLAGS
3035 This is required for programs and shared libraries that are a mixture of
3036 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
3037 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
3038
3039 @item AC_FC_SRCEXT
3040 Automake will add the flags computed by @code{AC_FC_SRCEXT} to compilation
3041 of files with the respective source extension (@pxref{Fortran Compiler, ,
3042 Fortran Compiler Characteristics, autoconf, The Autoconf Manual}).
3043
3044 @item AC_PROG_FC
3045 This is required if any Fortran 90/95 source is included.  This macro is
3046 distributed with Autoconf version 2.58 and later.  @xref{Particular
3047 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3048
3049 @item AC_PROG_LIBTOOL
3050 Automake will turn on processing for @command{libtool} (@pxref{Top, ,
3051 Introduction, libtool, The Libtool Manual}).
3052
3053 @item AC_PROG_YACC
3054 @vindex YACC
3055 If a Yacc source file is seen, then you must either use this macro or
3056 define the variable @code{YACC} in @file{configure.ac}.  The former is
3057 preferred (@pxref{Particular Programs, , Particular Program Checks,
3058 autoconf, The Autoconf Manual}).
3059
3060 @item AC_PROG_LEX
3061 If a Lex source file is seen, then this macro must be used.
3062 @xref{Particular Programs, , Particular Program Checks, autoconf, The
3063 Autoconf Manual}.
3064
3065 @item AC_REQUIRE_AUX_FILE
3066 For each @code{AC_REQUIRE_AUX_FILE([@var{file}])},
3067 @command{automake} will ensure that @file{@var{file}} exists in the
3068 aux directory, and will complain otherwise.  It
3069 will also automatically distribute the file.  This macro should be
3070 used by third-party Autoconf macros that require some supporting
3071 files in the aux directory specified with @code{AC_CONFIG_AUX_DIR}
3072 above.  @xref{Input, , Finding @command{configure} Input, autoconf,
3073 The Autoconf Manual}.
3074
3075 @item AC_SUBST
3076 The first argument is automatically defined as a variable in each
3077 generated @file{Makefile.in}, unless @code{AM_SUBST_NOTMAKE} is also
3078 used for this variable.  @xref{Setting Output Variables, , Setting
3079 Output Variables, autoconf, The Autoconf Manual}.
3080
3081 For every substituted variable @var{var}, @command{automake} will add
3082 a line @code{@var{var} = @var{value}} to each @file{Makefile.in} file.
3083 Many Autoconf macros invoke @code{AC_SUBST} to set output variables
3084 this way, e.g., @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and
3085 @code{X_LIBS}.  Thus, you can access these variables as
3086 @code{$(X_CFLAGS)} and @code{$(X_LIBS)} in any @file{Makefile.am}
3087 if @code{AC_PATH_XTRA} is called.
3088
3089 @item AM_CONDITIONAL
3090 This introduces an Automake conditional (@pxref{Conditionals}).
3091
3092 @item AM_COND_IF
3093 This macro allows @code{automake} to detect subsequent access within
3094 @file{configure.ac} to a conditional previously introduced with
3095 @code{AM_CONDITIONAL}, thus enabling conditional @code{AC_CONFIG_FILES}
3096 (@pxref{Usage of Conditionals}).
3097
3098 @item AM_GNU_GETTEXT
3099 This macro is required for packages that use GNU gettext
3100 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
3101 this macro it ensures that the package meets some of gettext's
3102 requirements.
3103
3104 @item AM_GNU_GETTEXT_INTL_SUBDIR
3105 This macro specifies that the @file{intl/} subdirectory is to be built,
3106 even if the @code{AM_GNU_GETTEXT} macro was invoked with a first argument
3107 of @samp{external}.
3108
3109 @item AM_MAINTAINER_MODE(@ovar{default-mode})
3110 @opindex --enable-maintainer-mode
3111 @opindex --disable-maintainer-mode
3112 This macro adds an @option{--enable-maintainer-mode} option to
3113 @command{configure}.  If this is used, @command{automake} will cause
3114 ``maintainer-only'' rules to be turned off by default in the
3115 generated @file{Makefile.in}s, unless @var{default-mode} is
3116 @samp{enable}.  This macro defines the @code{MAINTAINER_MODE}
3117 conditional, which you can use in your own @file{Makefile.am}.
3118 @xref{maintainer-mode}.
3119
3120 @item AM_SUBST_NOTMAKE(@var{var})
3121 Prevent Automake from defining a variable @var{var}, even if it is
3122 substituted by @command{config.status}.  Normally, Automake defines a
3123 @command{make} variable for each @command{configure} substitution,
3124 i.e., for each @code{AC_SUBST([@var{var}])}.  This macro prevents that
3125 definition from Automake.  If @code{AC_SUBST} has not been called
3126 for this variable, then @code{AM_SUBST_NOTMAKE} has no effects.
3127 Preventing variable definitions may be useful for substitution of
3128 multi-line values, where @code{@var{var} = @@@var{value}@@} might yield
3129 unintended results.
3130
3131 @item m4_include
3132 Files included by @file{configure.ac} using this macro will be
3133 detected by Automake and automatically distributed.  They will also
3134 appear as dependencies in @file{Makefile} rules.
3135
3136 @code{m4_include} is seldom used by @file{configure.ac} authors, but
3137 can appear in @file{aclocal.m4} when @command{aclocal} detects that
3138 some required macros come from files local to your package (as opposed to
3139 macros installed in a system-wide directory, @pxref{aclocal Invocation}).
3140
3141 @end ftable
3142
3143 @node aclocal Invocation
3144 @section Auto-generating aclocal.m4
3145 @c This node used to be named "Invoking automake".  This @anchor
3146 @c allows old links to still work.
3147 @anchor{Invoking aclocal}
3148
3149 @cindex Invocation of @command{aclocal}
3150 @cindex @command{aclocal}, Invocation
3151 @cindex Invoking @command{aclocal}
3152 @cindex @command{aclocal}, Invoking
3153
3154 Automake includes a number of Autoconf macros that can be used in
3155 your package (@pxref{Macros}); some of them are actually required by
3156 Automake in certain situations.  These macros must be defined in your
3157 @file{aclocal.m4}; otherwise they will not be seen by
3158 @command{autoconf}.
3159
3160 The @command{aclocal} program will automatically generate
3161 @file{aclocal.m4} files based on the contents of @file{configure.ac}.
3162 This provides a convenient way to get Automake-provided macros,
3163 without having to search around.  The @command{aclocal} mechanism
3164 allows other packages to supply their own macros (@pxref{Extending
3165 aclocal}).  You can also use it to maintain your own set of custom
3166 macros (@pxref{Local Macros}).
3167
3168 At startup, @command{aclocal} scans all the @file{.m4} files it can
3169 find, looking for macro definitions (@pxref{Macro Search Path}).  Then
3170 it scans @file{configure.ac}.  Any mention of one of the macros found
3171 in the first step causes that macro, and any macros it in turn
3172 requires, to be put into @file{aclocal.m4}.
3173
3174 @emph{Putting} the file that contains the macro definition into
3175 @file{aclocal.m4} is usually done by copying the entire text of this
3176 file, including unused macro definitions as well as both @samp{#} and
3177 @samp{dnl} comments.  If you want to make a comment that will be
3178 completely ignored by @command{aclocal}, use @samp{##} as the comment
3179 leader.
3180
3181 When a file selected by @command{aclocal} is located in a subdirectory
3182 specified as a relative search path with @command{aclocal}'s @option{-I}
3183 argument, @command{aclocal} assumes the file belongs to the package
3184 and uses @code{m4_include} instead of copying it into
3185 @file{aclocal.m4}.  This makes the package smaller, eases dependency
3186 tracking, and cause the file to be distributed automatically.
3187 (@xref{Local Macros}, for an example.)  Any macro that is found in a
3188 system-wide directory, or via an absolute search path will be copied.
3189 So use @samp{-I `pwd`/reldir} instead of @samp{-I reldir} whenever
3190 some relative directory should be considered outside the package.
3191
3192 The contents of @file{acinclude.m4}, if this file exists, are also
3193 automatically included in @file{aclocal.m4}.  We recommend against
3194 using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
3195
3196 @vindex AUTOM4TE
3197 @cindex autom4te
3198 While computing @file{aclocal.m4}, @command{aclocal} runs
3199 @command{autom4te} (@pxref{Using autom4te, , Using @command{Autom4te},
3200 autoconf, The Autoconf Manual}) in order to trace the macros that are
3201 really used, and omit from @file{aclocal.m4} all macros that are
3202 mentioned but otherwise unexpanded (this can happen when a macro is
3203 called conditionally).  @command{autom4te} is expected to be in the
3204 @env{PATH}, just as @command{autoconf}.  Its location can be
3205 overridden using the @env{AUTOM4TE} environment variable.
3206
3207 @menu
3208 * aclocal Options::             Options supported by aclocal
3209 * Macro Search Path::           How aclocal finds .m4 files
3210 * Extending aclocal::           Writing your own aclocal macros
3211 * Local Macros::                Organizing local macros
3212 * Serials::                     Serial lines in Autoconf macros
3213 * Future of aclocal::           aclocal's scheduled death
3214 @end menu
3215
3216 @node aclocal Options
3217 @subsection aclocal Options
3218
3219 @cindex @command{aclocal}, Options
3220 @cindex Options, @command{aclocal}
3221
3222 @command{aclocal} accepts the following options:
3223
3224 @table @code
3225 @item --automake-acdir=@var{dir}
3226 @opindex --automake-acdir
3227 Look for the automake-provided macro files in @var{dir} instead of
3228 in the installation directory.  This is typically used for debugging.
3229
3230 @item --system-acdir=@var{dir}
3231 @opindex --system-acdir
3232 Look for the system-wide third-party macro files (and the special
3233 @file{dirlist} file) in @var{dir} instead of in the installation
3234 directory.  This is typically used for debugging.
3235
3236 @item --diff[=@var{command}]
3237 @opindex --diff
3238 Run @var{command} on M4 file that would be installed or overwritten
3239 by @option{--install}.  The default @var{command} is @samp{diff -u}.
3240 This option implies @option{--install} and @option{--dry-run}.
3241
3242 @item --dry-run
3243 @opindex --dry-run
3244 Do not actually overwrite (or create) @file{aclocal.m4} and M4
3245 files installed by @option{--install}.
3246
3247 @item --help
3248 @opindex --help
3249 Print a summary of the command line options and exit.
3250
3251 @item -I @var{dir}
3252 @opindex -I
3253 Add the directory @var{dir} to the list of directories searched for
3254 @file{.m4} files.
3255
3256 @item --install
3257 @opindex --install
3258 Install system-wide third-party macros into the first directory
3259 specified with @samp{-I @var{dir}} instead of copying them in the
3260 output file.
3261 @c Keep in sync with aclocal-install-absdir.sh
3262 Note that this will happen also if @var{dir} is an absolute path.
3263
3264 @cindex serial number and @option{--install}
3265 When this option is used, and only when this option is used,
3266 @command{aclocal} will also honor @samp{#serial @var{number}} lines
3267 that appear in macros: an M4 file is ignored if there exists another
3268 M4 file with the same basename and a greater serial number in the
3269 search path (@pxref{Serials}).
3270
3271 @item --force
3272 @opindex --force
3273 Always overwrite the output file.  The default is to overwrite the output
3274 file only when really needed, i.e., when its contents changes or if one
3275 of its dependencies is younger.
3276
3277 This option forces the update of @file{aclocal.m4} (or the file
3278 specified with @file{--output} below) and only this file, it has
3279 absolutely no influence on files that may need to be installed by
3280 @option{--install}.
3281
3282 @item --output=@var{file}
3283 @opindex --output
3284 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
3285
3286 @item --print-ac-dir
3287 @opindex --print-ac-dir
3288 Prints the name of the directory that @command{aclocal} will search to
3289 find third-party @file{.m4} files.  When this option is given, normal
3290 processing is suppressed.  This option was used @emph{in the past} by
3291 third-party packages to determine where to install @file{.m4} macro
3292 files, but @emph{this usage is today discouraged}, since it causes
3293 @samp{$(prefix)} not to be thoroughly honoured (which violates the
3294 GNU Coding Standards), and a similar semantics can be better obtained
3295 with the @env{ACLOCAL_PATH} environment variable; @pxref{Extending aclocal}.
3296
3297 @item --verbose
3298 @opindex --verbose
3299 Print the names of the files it examines.
3300
3301 @item --version
3302 @opindex --version
3303 Print the version number of Automake and exit.
3304
3305 @item -W CATEGORY
3306 @item --warnings=@var{category}
3307 @opindex -W
3308 @opindex --warnings
3309 Output warnings falling in @var{category}.  @var{category} can be
3310 one of:
3311 @table @code
3312 @item syntax
3313 dubious syntactic constructs, underquoted macros, unused macros, etc.
3314 @item unsupported
3315 unknown macros
3316 @item all
3317 all the warnings, this is the default
3318 @item none
3319 turn off all the warnings
3320 @item error
3321 treat warnings as errors
3322 @end table
3323
3324 All warnings are output by default.
3325
3326 @vindex WARNINGS
3327 The environment variable @env{WARNINGS} is honored in the same
3328 way as it is for @command{automake} (@pxref{automake Invocation}).
3329
3330 @end table
3331
3332 @node Macro Search Path
3333 @subsection Macro Search Path
3334
3335 @cindex Macro search path
3336 @cindex @command{aclocal} search path
3337
3338 By default, @command{aclocal} searches for @file{.m4} files in the following
3339 directories, in this order:
3340
3341 @table @code
3342 @item @var{acdir-APIVERSION}
3343 This is where the @file{.m4} macros distributed with Automake itself
3344 are stored.  @var{APIVERSION} depends on the Automake release used;
3345 for example, for Automake 1.11.x, @var{APIVERSION} = @code{1.11}.
3346
3347 @item @var{acdir}
3348 This directory is intended for third party @file{.m4} files, and is
3349 configured when @command{automake} itself is built.  This is
3350 @file{@@datadir@@/aclocal/}, which typically
3351 expands to @file{$@{prefix@}/share/aclocal/}.  To find the compiled-in
3352 value of @var{acdir}, use the @option{--print-ac-dir} option
3353 (@pxref{aclocal Options}).
3354 @end table
3355
3356 As an example, suppose that @command{automake-1.11.2} was configured with
3357 @option{--prefix=@-/usr/local}.  Then, the search path would be:
3358
3359 @enumerate
3360 @item @file{/usr/local/share/aclocal-1.11.2/}
3361 @item @file{/usr/local/share/aclocal/}
3362 @end enumerate
3363
3364 The paths for the @var{acdir} and @var{acdir-APIVERSION} directories can
3365 be changed respectively through aclocal options @option{--system-acdir}
3366 and @option{--automake-acdir} (@pxref{aclocal Options}).  Note however
3367 that these options are only intended for use by the internal Automake
3368 test suite, or for debugging under highly unusual situations; they are
3369 not ordinarily needed by end-users.
3370
3371 As explained in (@pxref{aclocal Options}), there are several options that
3372 can be used to change or extend this search path.
3373
3374 @subsubheading Modifying the Macro Search Path: @samp{-I @var{dir}}
3375
3376 Any extra directories specified using @option{-I} options
3377 (@pxref{aclocal Options}) are @emph{prepended} to this search list.  Thus,
3378 @samp{aclocal -I /foo -I /bar} results in the following search path:
3379
3380 @enumerate
3381 @item @file{/foo}
3382 @item @file{/bar}
3383 @item @var{acdir}-@var{APIVERSION}
3384 @item @var{acdir}
3385 @end enumerate
3386
3387 @subsubheading Modifying the Macro Search Path: @file{dirlist}
3388 @cindex @file{dirlist}
3389
3390 There is a third mechanism for customizing the search path.  If a
3391 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
3392 contain a list of directory patterns, one per line.  @command{aclocal}
3393 expands these patterns to directory names, and adds them to the search
3394 list @emph{after} all other directories.  @file{dirlist} entries may
3395 use shell wildcards such as @samp{*}, @samp{?}, or @code{[...]}.
3396
3397 For example, suppose
3398 @file{@var{acdir}/dirlist} contains the following:
3399
3400 @example
3401 /test1
3402 /test2
3403 /test3*
3404 @end example
3405
3406 @noindent
3407 and that @command{aclocal} was called with the @samp{-I /foo -I /bar} options.
3408 Then, the search path would be
3409
3410 @c @code looks better than @file here
3411 @enumerate
3412 @item @code{/foo}
3413 @item @code{/bar}
3414 @item @var{acdir}-@var{APIVERSION}
3415 @item @var{acdir}
3416 @item @code{/test1}
3417 @item @code{/test2}
3418 @end enumerate
3419
3420 @noindent
3421 and all directories with path names starting with @code{/test3}.
3422
3423 If the @option{--system-acdir=@var{dir}} option is used, then
3424 @command{aclocal} will search for the @file{dirlist} file in
3425 @var{dir}; but remember the warnings  above against the use of
3426 @option{--system-acdir}.
3427
3428 @file{dirlist} is useful in the following situation: suppose that
3429 @command{automake} version @code{1.11.2} is installed with
3430 @samp{--prefix=/usr} by the system vendor.  Thus, the default search
3431 directories are
3432
3433 @c @code looks better than @file here
3434 @enumerate
3435 @item @code{/usr/share/aclocal-1.11/}
3436 @item @code{/usr/share/aclocal/}
3437 @end enumerate
3438
3439 However, suppose further that many packages have been manually
3440 installed on the system, with $prefix=/usr/local, as is typical.  In
3441 that case, many of these ``extra'' @file{.m4} files are in
3442 @file{/usr/local/share/aclocal}.  The only way to force
3443 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files is to
3444 always call @samp{aclocal -I /usr/local/share/aclocal}.  This is
3445 inconvenient.  With @file{dirlist}, one may create a file
3446 @file{/usr/share/aclocal/dirlist} containing only the single line
3447
3448 @example
3449 /usr/local/share/aclocal
3450 @end example
3451
3452 Now, the ``default'' search path on the affected system is
3453
3454 @c @code looks better than @file here
3455 @enumerate
3456 @item @code{/usr/share/aclocal-1.11/}
3457 @item @code{/usr/share/aclocal/}
3458 @item @code{/usr/local/share/aclocal/}
3459 @end enumerate
3460
3461 without the need for @option{-I} options; @option{-I} options can be reserved
3462 for project-specific needs (@file{my-source-dir/m4/}), rather than
3463 using it to work around local system-dependent tool installation
3464 directories.
3465
3466 Similarly, @file{dirlist} can be handy if you have installed a local
3467 copy of Automake in your account and want @command{aclocal} to look for
3468 macros installed at other places on the system.
3469
3470 @anchor{ACLOCAL_PATH}
3471 @subsubheading Modifying the Macro Search Path: @file{ACLOCAL_PATH}
3472 @cindex @env{ACLOCAL_PATH}
3473
3474 The fourth and last mechanism to customize the macro search path is
3475 also the simplest.  Any directory included in the colon-separated
3476 environment variable @env{ACLOCAL_PATH} is added to the search path
3477 @c Keep in sync with aclocal-path-precedence.sh
3478 and takes precedence over system directories (including those found via
3479 @file{dirlist}), with the exception of the versioned directory
3480 @var{acdir-APIVERSION} (@pxref{Macro Search Path}).  However, directories
3481 passed via @option{-I} will take precedence over directories in
3482 @env{ACLOCAL_PATH}.
3483
3484 @c Keep in sync with aclocal-path-installed.sh
3485 Also note that, if the @option{--install} option is used, any @file{.m4}
3486 file containing a required macro that is found in a directory listed in
3487 @env{ACLOCAL_PATH} will be installed locally.
3488 @c Keep in sync with aclocal-path-installed-serial.sh
3489 In this case, serial numbers in @file{.m4} are honoured too,
3490 @pxref{Serials}.
3491
3492 Conversely to @file{dirlist}, @env{ACLOCAL_PATH} is useful if you are
3493 using a global copy of Automake and want @command{aclocal} to look for
3494 macros somewhere under your home directory.
3495
3496 @subsubheading Planned future incompatibilities
3497
3498 The order in which the directories in the macro search path are currently
3499 looked up is confusing and/or suboptimal in various aspects, and is
3500 probably going to be changed in the future Automake release.  In
3501 particular, directories in @env{ACLOCAL_PATH} and @file{@var{acdir}}
3502 might end up taking precedence over @file{@var{acdir-APIVERSION}}, and
3503 directories in @file{@var{acdir}/dirlist} might end up taking precedence
3504 over @file{@var{acdir}}.  @emph{This is a possible future incompatibility!}
3505
3506 @node Extending aclocal
3507 @subsection Writing your own aclocal macros
3508
3509 @cindex @command{aclocal}, extending
3510 @cindex Extending @command{aclocal}
3511
3512 The @command{aclocal} program doesn't have any built-in knowledge of any
3513 macros, so it is easy to extend it with your own macros.
3514
3515 This can be used by libraries that want to supply their own Autoconf
3516 macros for use by other programs.  For instance, the @command{gettext}
3517 library supplies a macro @code{AM_GNU_GETTEXT} that should be used by
3518 any package using @command{gettext}.  When the library is installed, it
3519 installs this macro so that @command{aclocal} will find it.
3520
3521 A macro file's name should end in @file{.m4}.  Such files should be
3522 installed in @file{$(datadir)/aclocal}.  This is as simple as writing:
3523
3524 @c Keep in sync with primary-prefix-couples-documented-valid.sh
3525 @example
3526 aclocaldir = $(datadir)/aclocal
3527 aclocal_DATA = mymacro.m4 myothermacro.m4
3528 @end example
3529
3530 @noindent
3531 Please do use @file{$(datadir)/aclocal}, and not something based on
3532 the result of @samp{aclocal --print-ac-dir} (@pxref{Hard-Coded Install
3533 Paths}, for arguments).  It might also be helpful to suggest to
3534 the user to add the @file{$(datadir)/aclocal} directory to his
3535 @env{ACLOCAL_PATH} variable (@pxref{ACLOCAL_PATH}) so that
3536 @command{aclocal} will find the @file{.m4} files installed by your
3537 package automatically.
3538
3539 A file of macros should be a series of properly quoted
3540 @code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
3541 Autoconf Manual}).  The @command{aclocal} programs also understands
3542 @code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
3543 Autoconf Manual}), so it is safe to put each macro in a separate file.
3544 Each file should have no side effects but macro definitions.
3545 Especially, any call to @code{AC_PREREQ} should be done inside the
3546 defined macro, not at the beginning of the file.
3547
3548 @cindex underquoted @code{AC_DEFUN}
3549 @acindex AC_DEFUN
3550 @acindex AC_PREREQ
3551
3552 Starting with Automake 1.8, @command{aclocal} will warn about all
3553 underquoted calls to @code{AC_DEFUN}.  We realize this will annoy a
3554 lot of people, because @command{aclocal} was not so strict in the past
3555 and many third party macros are underquoted; and we have to apologize
3556 for this temporary inconvenience.  The reason we have to be stricter
3557 is that a future implementation of @command{aclocal} (@pxref{Future of
3558 aclocal}) will have to temporarily include all these third party
3559 @file{.m4} files, maybe several times, including even files that are
3560 not actually needed.  Doing so should alleviate many problems of the
3561 current implementation, however it requires a stricter style from the
3562 macro authors.  Hopefully it is easy to revise the existing macros.
3563 For instance,
3564
3565 @example
3566 # bad style
3567 AC_PREREQ(2.68)
3568 AC_DEFUN(AX_FOOBAR,
3569 [AC_REQUIRE([AX_SOMETHING])dnl
3570 AX_FOO
3571 AX_BAR
3572 ])
3573 @end example
3574
3575 @noindent
3576 should be rewritten as
3577
3578 @example
3579 AC_DEFUN([AX_FOOBAR],
3580 [AC_PREREQ([2.68])dnl
3581 AC_REQUIRE([AX_SOMETHING])dnl
3582 AX_FOO
3583 AX_BAR
3584 ])
3585 @end example
3586
3587 Wrapping the @code{AC_PREREQ} call inside the macro ensures that
3588 Autoconf 2.68 will not be required if @code{AX_FOOBAR} is not actually
3589 used.  Most importantly, quoting the first argument of @code{AC_DEFUN}
3590 allows the macro to be redefined or included twice (otherwise this
3591 first argument would be expanded during the second definition).  For
3592 consistency we like to quote even arguments such as @code{2.68} that
3593 do not require it.
3594
3595 If you have been directed here by the @command{aclocal} diagnostic but
3596 are not the maintainer of the implicated macro, you will want to
3597 contact the maintainer of that macro.  Please make sure you have the
3598 latest version of the macro and that the problem hasn't already been
3599 reported before doing so: people tend to work faster when they aren't
3600 flooded by mails.
3601
3602 Another situation where @command{aclocal} is commonly used is to
3603 manage macros that are used locally by the package, @ref{Local
3604 Macros}.
3605
3606 @node Local Macros
3607 @subsection Handling Local Macros
3608
3609 Feature tests offered by Autoconf do not cover all needs.  People
3610 often have to supplement existing tests with their own macros, or
3611 with third-party macros.
3612
3613 There are two ways to organize custom macros in a package.
3614
3615 The first possibility (the historical practice) is to list all your
3616 macros in @file{acinclude.m4}.  This file will be included in
3617 @file{aclocal.m4} when you run @command{aclocal}, and its macro(s) will
3618 henceforth be visible to @command{autoconf}.  However if it contains
3619 numerous macros, it will rapidly become difficult to maintain, and it
3620 will be almost impossible to share macros between packages.
3621
3622 @vindex ACLOCAL_AMFLAGS
3623 The second possibility, which we do recommend, is to write each macro
3624 in its own file and gather all these files in a directory.  This
3625 directory is usually called @file{m4/}.  To build @file{aclocal.m4},
3626 one should therefore instruct @command{aclocal} to scan @file{m4/}.
3627 From the command line, this is done with @samp{aclocal -I m4}.  The
3628 top-level @file{Makefile.am} should also be updated to define
3629
3630 @example
3631 ACLOCAL_AMFLAGS = -I m4
3632 @end example
3633
3634 @code{ACLOCAL_AMFLAGS} contains options to pass to @command{aclocal}
3635 when @file{aclocal.m4} is to be rebuilt by @command{make}.  This line is
3636 also used by @command{autoreconf} (@pxref{autoreconf Invocation, ,
3637 Using @command{autoreconf} to Update @file{configure} Scripts,
3638 autoconf, The Autoconf Manual}) to run @command{aclocal} with suitable
3639 options, or by @command{autopoint} (@pxref{autopoint Invocation, ,
3640 Invoking the @command{autopoint} Program, gettext, GNU gettext tools})
3641 and @command{gettextize} (@pxref{gettextize Invocation, , Invoking the
3642 @command{gettextize} Program, gettext, GNU gettext tools}) to locate
3643 the place where Gettext's macros should be installed.  So even if you
3644 do not really care about the rebuild rules, you should define
3645 @code{ACLOCAL_AMFLAGS}.
3646
3647 When @samp{aclocal -I m4} is run, it will build an @file{aclocal.m4}
3648 that @code{m4_include}s any file from @file{m4/} that defines a
3649 required macro.  Macros not found locally will still be searched in
3650 system-wide directories, as explained in @ref{Macro Search Path}.
3651
3652 Custom macros should be distributed for the same reason that
3653 @file{configure.ac} is: so that other people have all the sources of
3654 your package if they want to work on it.  Actually, this distribution
3655 happens automatically because all @code{m4_include}d files are
3656 distributed.
3657
3658 However there is no consensus on the distribution of third-party
3659 macros that your package may use.  Many libraries install their own
3660 macro in the system-wide @command{aclocal} directory (@pxref{Extending
3661 aclocal}).  For instance, Guile ships with a file called
3662 @file{guile.m4} that contains the macro @code{GUILE_FLAGS} that can
3663 be used to define setup compiler and linker flags appropriate for
3664 using Guile.  Using @code{GUILE_FLAGS} in @file{configure.ac} will
3665 cause @command{aclocal} to copy @file{guile.m4} into
3666 @file{aclocal.m4}, but as @file{guile.m4} is not part of the project,
3667 it will not be distributed.  Technically, that means a user who
3668 needs to rebuild @file{aclocal.m4} will have to install Guile first.
3669 This is probably OK, if Guile already is a requirement to build the
3670 package.  However, if Guile is only an optional feature, or if your
3671 package might run on architectures where Guile cannot be installed,
3672 this requirement will hinder development.  An easy solution is to copy
3673 such third-party macros in your local @file{m4/} directory so they get
3674 distributed.
3675
3676 Since Automake 1.10, @command{aclocal} offers an option to copy these
3677 system-wide third-party macros in your local macro directory, solving
3678 the above problem.  Simply use:
3679
3680 @example
3681 ACLOCAL_AMFLAGS = -I m4 --install
3682 @end example
3683
3684 @noindent
3685 With this setup, system-wide macros will be copied to @file{m4/}
3686 the first time you run @command{autoreconf}.  Then the locally
3687 installed macros will have precedence over the system-wide installed
3688 macros each time @command{aclocal} is run again.
3689
3690 One reason why you should keep @option{--install} in the flags even
3691 after the first run is that when you later edit @file{configure.ac}
3692 and depend on a new macro, this macro will be installed in your
3693 @file{m4/} automatically.  Another one is that serial numbers
3694 (@pxref{Serials}) can be used to update the macros in your source tree
3695 automatically when new system-wide versions are installed.  A serial
3696 number should be a single line of the form
3697
3698 @example
3699 #serial @var{nnn}
3700 @end example
3701
3702 @noindent
3703 where @var{nnn} contains only digits and dots.  It should appear in
3704 the M4 file before any macro definition.  It is a good practice to
3705 maintain a serial number for each macro you distribute, even if you do
3706 not use the @option{--install} option of @command{aclocal}: this allows
3707 other people to use it.
3708
3709
3710 @node Serials
3711 @subsection Serial Numbers
3712 @cindex serial numbers in macros
3713 @cindex macro serial numbers
3714 @cindex @code{#serial} syntax
3715 @cindex @command{aclocal} and serial numbers
3716
3717 Because third-party macros defined in @file{*.m4} files are naturally
3718 shared between multiple projects, some people like to version them.
3719 This makes it easier to tell which of two M4 files is newer.  Since at
3720 least 1996, the tradition is to use a @samp{#serial} line for this.
3721
3722 A serial number should be a single line of the form
3723
3724 @example
3725 # serial @var{version}
3726 @end example
3727
3728 @noindent
3729 where @var{version} is a version number containing only digits and
3730 dots.  Usually people use a single integer, and they increment it each
3731 time they change the macro (hence the name of ``serial'').  Such a
3732 line should appear in the M4 file before any macro definition.
3733
3734 The @samp{#} must be the first character on the line,
3735 and it is OK to have extra words after the version, as in
3736
3737 @example
3738 #serial @var{version} @var{garbage}
3739 @end example
3740
3741 Normally these serial numbers are completely ignored by
3742 @command{aclocal} and @command{autoconf}, like any genuine comment.
3743 However when using @command{aclocal}'s @option{--install} feature, these
3744 serial numbers will modify the way @command{aclocal} selects the
3745 macros to install in the package: if two files with the same basename
3746 exist in your search path, and if at least one of them uses a
3747 @samp{#serial} line, @command{aclocal} will ignore the file that has
3748 the older @samp{#serial} line (or the file that has none).
3749
3750 Note that a serial number applies to a whole M4 file, not to any macro
3751 it contains.  A file can contains multiple macros, but only one
3752 serial.
3753
3754 Here is a use case that illustrates the use of @option{--install} and
3755 its interaction with serial numbers.  Let's assume we maintain a
3756 package called MyPackage, the @file{configure.ac} of which requires a
3757 third-party macro @code{AX_THIRD_PARTY} defined in
3758 @file{/usr/share/aclocal/thirdparty.m4} as follows:
3759
3760 @example
3761 # serial 1
3762 AC_DEFUN([AX_THIRD_PARTY], [...])
3763 @end example
3764
3765 MyPackage uses an @file{m4/} directory to store local macros as
3766 explained in @ref{Local Macros}, and has
3767
3768 @example
3769 ACLOCAL_AMFLAGS = -I m4 --install
3770 @end example
3771
3772 @noindent
3773 in its top-level @file{Makefile.am}.
3774
3775 Initially the @file{m4/} directory is empty.  The first time we run
3776 @command{autoreconf}, it will fetch the options to pass to
3777 @command{aclocal} in @file{Makefile.am}, and run @samp{aclocal -I m4
3778 --install}.  @command{aclocal} will notice that
3779
3780 @itemize @bullet
3781 @item
3782 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3783 @item
3784 No local macros define @code{AX_THIRD_PARTY}
3785 @item
3786 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3787 with serial 1.
3788 @end itemize
3789
3790 @noindent
3791 Because @file{/usr/share/aclocal/thirdparty.m4} is a system-wide macro
3792 and @command{aclocal} was given the @option{--install} option, it will
3793 copy this file in @file{m4/thirdparty.m4}, and output an
3794 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3795
3796 The next time @samp{aclocal -I m4 --install} is run (either via
3797 @command{autoreconf}, by hand, or from the @file{Makefile} rebuild
3798 rules) something different happens.  @command{aclocal} notices that
3799
3800 @itemize @bullet
3801 @item
3802 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3803 @item
3804 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3805 with serial 1.
3806 @item
3807 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3808 with serial 1.
3809 @end itemize
3810
3811 @noindent
3812 Because both files have the same serial number, @command{aclocal} uses
3813 the first it found in its search path order (@pxref{Macro Search
3814 Path}).  @command{aclocal} therefore ignores
3815 @file{/usr/share/aclocal/thirdparty.m4} and outputs an
3816 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3817
3818 Local directories specified with @option{-I} are always searched before
3819 system-wide directories, so a local file will always be preferred to
3820 the system-wide file in case of equal serial numbers.
3821
3822 Now suppose the system-wide third-party macro is changed.  This can
3823 happen if the package installing this macro is updated.  Let's suppose
3824 the new macro has serial number 2.  The next time @samp{aclocal -I m4
3825 --install} is run the situation is the following:
3826
3827 @itemize @bullet
3828 @item
3829 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3830 @item
3831 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3832 with serial 1.
3833 @item
3834 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3835 with serial 2.
3836 @end itemize
3837
3838 @noindent
3839 When @command{aclocal} sees a greater serial number, it immediately
3840 forgets anything it knows from files that have the same basename and a
3841 smaller serial number.  So after it has found
3842 @file{/usr/share/aclocal/thirdparty.m4} with serial 2,
3843 @command{aclocal} will proceed as if it had never seen
3844 @file{m4/thirdparty.m4}.  This brings us back to a situation similar
3845 to that at the beginning of our example, where no local file defined
3846 the macro.  @command{aclocal} will install the new version of the
3847 macro in @file{m4/thirdparty.m4}, in this case overriding the old
3848 version.  MyPackage just had its macro updated as a side effect of
3849 running @command{aclocal}.
3850
3851 If you are leery of letting @command{aclocal} update your local macro,
3852 you can run @samp{aclocal -I m4 --diff} to review the changes
3853 @samp{aclocal -I m4 --install} would perform on these macros.
3854
3855 Finally, note that the @option{--force} option of @command{aclocal} has
3856 absolutely no effect on the files installed by @option{--install}.  For
3857 instance, if you have modified your local macros, do not expect
3858 @option{--install --force} to replace the local macros by their
3859 system-wide versions.  If you want to do so, simply erase the local
3860 macros you want to revert, and run @samp{aclocal -I m4 --install}.
3861
3862
3863 @node Future of aclocal
3864 @subsection The Future of @command{aclocal}
3865 @cindex @command{aclocal}'s scheduled death
3866
3867 @command{aclocal} is expected to disappear.  This feature really
3868 should not be offered by Automake.  Automake should focus on
3869 generating @file{Makefile}s; dealing with M4 macros really is
3870 Autoconf's job.  The fact that some people install Automake just to use
3871 @command{aclocal}, but do not use @command{automake} otherwise is an
3872 indication of how that feature is misplaced.
3873
3874 The new implementation will probably be done slightly differently.
3875 For instance, it could enforce the @file{m4/}-style layout discussed in
3876 @ref{Local Macros}.
3877
3878 We have no idea when and how this will happen.  This has been
3879 discussed several times in the past, but someone still has to commit
3880 to that non-trivial task.
3881
3882 From the user point of view, @command{aclocal}'s removal might turn
3883 out to be painful.  There is a simple precaution that you may take to
3884 make that switch more seamless: never call @command{aclocal} yourself.
3885 Keep this guy under the exclusive control of @command{autoreconf} and
3886 Automake's rebuild rules.  Hopefully you won't need to worry about
3887 things breaking, when @command{aclocal} disappears, because everything
3888 will have been taken care of.  If otherwise you used to call
3889 @command{aclocal} directly yourself or from some script, you will
3890 quickly notice the change.
3891
3892 Many packages come with a script called @file{bootstrap.sh} or
3893 @file{autogen.sh}, that will just call @command{aclocal},
3894 @command{libtoolize}, @command{gettextize} or @command{autopoint},
3895 @command{autoconf}, @command{autoheader}, and @command{automake} in
3896 the right order.  Actually this is precisely what @command{autoreconf}
3897 can do for you.  If your package has such a @file{bootstrap.sh} or
3898 @file{autogen.sh} script, consider using @command{autoreconf}.  That
3899 should simplify its logic a lot (less things to maintain, yum!), it's
3900 even likely you will not need the script anymore, and more to the point
3901 you will not call @command{aclocal} directly anymore.
3902
3903 For the time being, third-party packages should continue to install
3904 public macros into @file{/usr/share/aclocal/}.  If @command{aclocal}
3905 is replaced by another tool it might make sense to rename the
3906 directory, but supporting @file{/usr/share/aclocal/} for backward
3907 compatibility should be really easy provided all macros are properly
3908 written (@pxref{Extending aclocal}).
3909
3910
3911
3912 @node Macros
3913 @section Autoconf macros supplied with Automake
3914
3915 Automake ships with several Autoconf macros that you can use from your
3916 @file{configure.ac}.  When you use one of them it will be included by
3917 @command{aclocal} in @file{aclocal.m4}.
3918
3919 @menu
3920 * Public Macros::               Macros that you can use.
3921 * Obsolete Macros::             Macros that will soon be removed.
3922 * Private Macros::              Macros that you should not use.
3923 @end menu
3924
3925 @c consider generating the following subsections automatically from m4 files.
3926
3927 @node Public Macros
3928 @subsection Public Macros
3929
3930 @table @code
3931
3932 @item AM_INIT_AUTOMAKE([OPTIONS])
3933 @acindex AM_INIT_AUTOMAKE
3934 Runs many macros required for proper operation of the generated Makefiles.
3935
3936 @vindex AUTOMAKE_OPTIONS
3937 Today, @code{AM_INIT_AUTOMAKE} is called with a single argument: a
3938 space-separated list of Automake options that should
3939 be applied to every @file{Makefile.am} in the tree.  The effect is as if
3940 each option were listed in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
3941
3942 @acindex AC_INIT
3943 This macro can also be called in @emph{another, deprecated form} (support
3944 for which will be @emph{removed in the next major Automake release}):
3945 @code{AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])}.  In this form,
3946 there are two required arguments: the package and the version number.
3947 This form is obsolete because the @var{package} and @var{version} can
3948 be obtained from Autoconf's @code{AC_INIT} macro (which itself has an
3949 old and a new form).
3950
3951 If your @file{configure.ac} has:
3952
3953 @example
3954 AC_INIT([src/foo.c])
3955 AM_INIT_AUTOMAKE([mumble], [1.5])
3956 @end example
3957
3958 @noindent
3959 you should modernize it as follows:
3960
3961 @example
3962 AC_INIT([mumble], [1.5])
3963 AC_CONFIG_SRCDIR([src/foo.c])
3964 AM_INIT_AUTOMAKE
3965 @end example
3966
3967 Note that if you're upgrading your @file{configure.ac} from an earlier
3968 version of Automake, it is not always correct to simply move the
3969 package and version arguments from @code{AM_INIT_AUTOMAKE} directly to
3970 @code{AC_INIT}, as in the example above.  The first argument to
3971 @code{AC_INIT} should be the name of your package (e.g., @samp{GNU
3972 Automake}), not the tarball name (e.g., @samp{automake}) that you used
3973 to pass to @code{AM_INIT_AUTOMAKE}.  Autoconf tries to derive a
3974 tarball name from the package name, which should work for most but not
3975 all package names.  (If it doesn't work for yours, you can use the
3976 four-argument form of @code{AC_INIT} to provide the tarball name
3977 explicitly).
3978
3979 @cindex @code{PACKAGE}, prevent definition
3980 @cindex @code{VERSION}, prevent definition
3981 @opindex no-define
3982 By default this macro @code{AC_DEFINE}'s @code{PACKAGE} and
3983 @code{VERSION}.  This can be avoided by passing the @option{no-define}
3984 option:
3985 @example
3986 AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
3987 @end example
3988
3989 @item AM_PATH_LISPDIR
3990 @acindex AM_PATH_LISPDIR
3991 @vindex EMACS
3992 @vindex lispdir
3993 Searches for the program @command{emacs}, and, if found, sets the
3994 output variable @code{lispdir} to the full path to Emacs' site-lisp
3995 directory.
3996
3997 Note that this test assumes the @command{emacs} found to be a version
3998 that supports Emacs Lisp (such as GNU Emacs or XEmacs).  Other
3999 emacsen can cause this test to hang (some, like old versions of
4000 MicroEmacs, start up in interactive mode, requiring @kbd{C-x C-c} to
4001 exit, which is hardly obvious for a non-emacs user).  In most cases,
4002 however, you should be able to use @kbd{C-c} to kill the test.  In
4003 order to avoid problems, you can set @env{EMACS} to ``no'' in the
4004 environment, or use the @option{--with-lispdir} option to
4005 @command{configure} to explicitly set the correct path (if you're sure
4006 you have an @command{emacs} that supports Emacs Lisp).
4007
4008 @item AM_PROG_AR(@ovar{act-if-fail})
4009 @acindex AM_PROG_AR
4010 @vindex AR
4011 You must use this macro when you use the archiver in your project, if
4012 you want support for unusual archivers such as Microsoft @command{lib}.
4013 The content of the optional argument is executed if the archiver
4014 interface is not recognized; the default action is to abort configure
4015 with an error message.
4016
4017 @item AM_PROG_AS
4018 @acindex AM_PROG_AS
4019 @vindex CCAS
4020 @vindex CCASFLAGS
4021 Use this macro when you have assembly code in your project.  This will
4022 choose the assembler for you (by default the C compiler) and set
4023 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
4024
4025 @item AM_PROG_CC_C_O
4026 @acindex AM_PROG_CC_C_O
4027 @acindex AC_PROG_CC_C_O
4028 This is like @code{AC_PROG_CC_C_O}, but it generates its results in
4029 the manner required by Automake.  You must use this instead of
4030 @code{AC_PROG_CC_C_O} when you need this functionality, that is, when
4031 using per-target flags or subdir-objects with C sources.
4032
4033 @item AM_PROG_LEX
4034 @acindex AM_PROG_LEX
4035 @acindex AC_PROG_LEX
4036 @cindex HP-UX 10, @command{lex} problems
4037 @cindex @command{lex} problems with HP-UX 10
4038 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
4039 Program Checks, autoconf, The Autoconf Manual}), but uses the
4040 @command{missing} script on systems that do not have @command{lex}.
4041 HP-UX 10 is one such system.
4042
4043 @item AM_PROG_GCJ
4044 @acindex AM_PROG_GCJ
4045 @vindex GCJ
4046 @vindex GCJFLAGS
4047 This macro finds the @command{gcj} program or causes an error.  It sets
4048 @code{GCJ} and @code{GCJFLAGS}.  @command{gcj} is the Java front-end to the
4049 GNU Compiler Collection.
4050
4051 @item AM_PROG_UPC([@var{compiler-search-list}])
4052 @acindex AM_PROG_UPC
4053 @vindex UPC
4054 Find a compiler for Unified Parallel C and define the @code{UPC}
4055 variable.  The default @var{compiler-search-list} is @samp{upcc upc}.
4056 This macro will abort @command{configure} if no Unified Parallel C
4057 compiler is found.
4058
4059 @item AM_SILENT_RULES
4060 @acindex AM_SILENT_RULES
4061 Enable the machinery for less verbose build output (@pxref{Options}).
4062
4063 @item AM_WITH_DMALLOC
4064 @acindex AM_WITH_DMALLOC
4065 @cindex @command{dmalloc}, support for
4066 @vindex WITH_DMALLOC
4067 @opindex --with-dmalloc
4068 Add support for the @uref{http://dmalloc.com/, Dmalloc package}.  If
4069 the user runs @command{configure} with @option{--with-dmalloc}, then
4070 define @code{WITH_DMALLOC} and add @option{-ldmalloc} to @code{LIBS}.
4071
4072 @end table
4073
4074
4075 @node Obsolete Macros
4076 @subsection Obsolete Macros
4077 @cindex obsolete macros
4078 @cindex autoupdate
4079
4080 Although using some of the following macros was required in past
4081 releases, you should not use any of them in new code.  @emph{All
4082 these macros will be removed in the next major Automake version};
4083 if you are still using them, running @command{autoupdate} should
4084 adjust your @file{configure.ac} automatically (@pxref{autoupdate
4085 Invocation, , Using @command{autoupdate} to Modernize
4086 @file{configure.ac}, autoconf, The Autoconf Manual}).
4087 @emph{Do it NOW!}
4088
4089 @table @code
4090
4091 @item AM_CONFIG_HEADER
4092 @acindex AM_CONFIG_HEADER
4093 Automake will generate rules to automatically regenerate the config
4094 header.  This obsolete macro is a synonym of @code{AC_CONFIG_HEADERS}
4095 today (@pxref{Optional}).
4096
4097 @item AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
4098 @acindex AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
4099 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
4100 define @code{GWINSZ_IN_SYS_IOCTL}.  Otherwise @code{TIOCGWINSZ} can be
4101 found in @file{<termios.h>}.  This macro is obsolete, you should
4102 use Autoconf's @code{AC_HEADER_TIOCGWINSZ} instead.
4103
4104 @item AM_PROG_MKDIR_P
4105 @acindex AM_PROG_MKDIR_P
4106 @cindex @code{mkdir -p}, macro check
4107 @vindex MKDIR_P
4108 @vindex mkdir_p
4109
4110 From Automake 1.8 to 1.9.6 this macro used to define the output
4111 variable @code{mkdir_p} to one of @code{mkdir -p}, @code{install-sh
4112 -d}, or @code{mkinstalldirs}.
4113
4114 Nowadays Autoconf provides a similar functionality with
4115 @code{AC_PROG_MKDIR_P} (@pxref{Particular Programs, , Particular
4116 Program Checks, autoconf, The Autoconf Manual}), however this defines
4117 the output variable @code{MKDIR_P} instead.  In case you are still
4118 using the @code{AM_PROG_MKDIR_P} macro in your @file{configure.ac},
4119 or its provided variable @code{$(mkdir_p)} in your @file{Makefile.am},
4120 you are advised to switch ASAP to the more modern Autoconf-provided
4121 interface instead; both the macro and the variable @emph{will be
4122 removed} in the next major Automake release.
4123
4124 @item AM_SYS_POSIX_TERMIOS
4125 @acindex AM_SYS_POSIX_TERMIOS
4126 @cindex POSIX termios headers
4127 @cindex termios POSIX headers
4128 Check to see if POSIX termios headers and functions are available on the
4129 system.  If so, set the shell variable @code{am_cv_sys_posix_termios} to
4130 @samp{yes}.  If not, set the variable to @samp{no}.  This macro is obsolete,
4131 you should use Autoconf's @code{AC_SYS_POSIX_TERMIOS} instead.
4132
4133 @end table
4134
4135
4136 @node Private Macros
4137 @subsection Private Macros
4138
4139 The following macros are private macros you should not call directly.
4140 They are called by the other public macros when appropriate.  Do not
4141 rely on them, as they might be changed in a future version.  Consider
4142 them as implementation details; or better, do not consider them at all:
4143 skip this section!
4144
4145 @ftable @code
4146 @item _AM_DEPENDENCIES
4147 @itemx AM_SET_DEPDIR
4148 @itemx AM_DEP_TRACK
4149 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
4150 These macros are used to implement Automake's automatic dependency
4151 tracking scheme.  They are called automatically by Automake when
4152 required, and there should be no need to invoke them manually.
4153
4154 @item AM_MAKE_INCLUDE
4155 This macro is used to discover how the user's @command{make} handles
4156 @code{include} statements.  This macro is automatically invoked when
4157 needed; there should be no need to invoke it manually.
4158
4159 @item AM_PROG_INSTALL_STRIP
4160 This is used to find a version of @code{install} that can be used to
4161 strip a program at installation time.  This macro is automatically
4162 included when required.
4163
4164 @item AM_SANITY_CHECK
4165 This checks to make sure that a file created in the build directory is
4166 newer than a file in the source directory.  This can fail on systems
4167 where the clock is set incorrectly.  This macro is automatically run
4168 from @code{AM_INIT_AUTOMAKE}.
4169
4170 @end ftable
4171
4172
4173 @node Directories
4174 @chapter Directories
4175
4176 For simple projects that distribute all files in the same directory
4177 it is enough to have a single @file{Makefile.am} that builds
4178 everything in place.
4179
4180 In larger projects it is common to organize files in different
4181 directories, in a tree.  For instance one directory per program, per
4182 library or per module.  The traditional approach is to build these
4183 subdirectories recursively: each directory contains its @file{Makefile}
4184 (generated from @file{Makefile.am}), and when @command{make} is run
4185 from the top level directory it enters each subdirectory in turn to
4186 build its contents.
4187
4188 @menu
4189 * Subdirectories::              Building subdirectories recursively
4190 * Conditional Subdirectories::  Conditionally not building directories
4191 * Alternative::                 Subdirectories without recursion
4192 * Subpackages::                 Nesting packages
4193 @end menu
4194
4195 @node Subdirectories
4196 @section Recursing subdirectories
4197
4198 @cindex @code{SUBDIRS}, explained
4199
4200 In packages with subdirectories, the top level @file{Makefile.am} must
4201 tell Automake which subdirectories are to be built.  This is done via
4202 the @code{SUBDIRS} variable.
4203 @vindex SUBDIRS
4204
4205 The @code{SUBDIRS} variable holds a list of subdirectories in which
4206 building of various sorts can occur.  The rules for many targets
4207 (e.g., @code{all}) in the generated @file{Makefile} will run commands
4208 both locally and in all specified subdirectories.  Note that the
4209 directories listed in @code{SUBDIRS} are not required to contain
4210 @file{Makefile.am}s; only @file{Makefile}s (after configuration).
4211 This allows inclusion of libraries from packages that do not use
4212 Automake (such as @code{gettext}; see also @ref{Third-Party
4213 Makefiles}).
4214
4215 In packages that use subdirectories, the top-level @file{Makefile.am} is
4216 often very short.  For instance, here is the @file{Makefile.am} from the
4217 GNU Hello distribution:
4218
4219 @example
4220 EXTRA_DIST = BUGS ChangeLog.O README-alpha
4221 SUBDIRS = doc intl po src tests
4222 @end example
4223
4224 When Automake invokes @command{make} in a subdirectory, it uses the value
4225 of the @code{MAKE} variable.  It passes the value of the variable
4226 @code{AM_MAKEFLAGS} to the @command{make} invocation; this can be set in
4227 @file{Makefile.am} if there are flags you must always pass to
4228 @command{make}.
4229 @vindex MAKE
4230 @vindex AM_MAKEFLAGS
4231
4232 The directories mentioned in @code{SUBDIRS} are usually direct
4233 children of the current directory, each subdirectory containing its
4234 own @file{Makefile.am} with a @code{SUBDIRS} pointing to deeper
4235 subdirectories.  Automake can be used to construct packages of
4236 arbitrary depth this way.
4237
4238 By default, Automake generates @file{Makefiles} that work depth-first
4239 in postfix order: the subdirectories are built before the current
4240 directory.  However, it is possible to change this ordering.  You can
4241 do this by putting @samp{.} into @code{SUBDIRS}.  For instance,
4242 putting @samp{.} first will cause a prefix ordering of
4243 directories.
4244
4245 Using
4246
4247 @example
4248 SUBDIRS = lib src . test
4249 @end example
4250
4251 @noindent
4252 will cause @file{lib/} to be built before @file{src/}, then the
4253 current directory will be built, finally the @file{test/} directory
4254 will be built.  It is customary to arrange test directories to be
4255 built after everything else since they are meant to test what has
4256 been constructed.
4257
4258 All @code{clean} rules are run in reverse order of build rules.
4259
4260 @node Conditional Subdirectories
4261 @section Conditional Subdirectories
4262 @cindex Subdirectories, building conditionally
4263 @cindex Conditional subdirectories
4264 @cindex @code{SUBDIRS}, conditional
4265 @cindex Conditional @code{SUBDIRS}
4266
4267 It is possible to define the @code{SUBDIRS} variable conditionally if,
4268 like in the case of GNU Inetutils, you want to only build a subset of
4269 the entire package.
4270
4271 To illustrate how this works, let's assume we have two directories
4272 @file{src/} and @file{opt/}.  @file{src/} should always be built, but we
4273 want to decide in @command{configure} whether @file{opt/} will be built
4274 or not.  (For this example we will assume that @file{opt/} should be
4275 built when the variable @samp{$want_opt} was set to @samp{yes}.)
4276
4277 Running @command{make} should thus recurse into @file{src/} always, and
4278 then maybe in @file{opt/}.
4279
4280 However @samp{make dist} should always recurse into both @file{src/}
4281 and @file{opt/}.  Because @file{opt/} should be distributed even if it
4282 is not needed in the current configuration.  This means
4283 @file{opt/Makefile} should be created @emph{unconditionally}.
4284
4285 There are two ways to setup a project like this.  You can use Automake
4286 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
4287 variables (@pxref{Setting Output Variables, , Setting Output
4288 Variables, autoconf, The Autoconf Manual}).  Using Automake
4289 conditionals is the preferred solution.  Before we illustrate these
4290 two possibilities, let's introduce @code{DIST_SUBDIRS}.
4291
4292 @menu
4293 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
4294 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
4295 * Subdirectories with AC_SUBST::  Another way for conditional recursion
4296 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
4297 @end menu
4298
4299 @node SUBDIRS vs DIST_SUBDIRS
4300 @subsection @code{SUBDIRS} vs.@: @code{DIST_SUBDIRS}
4301 @cindex @code{DIST_SUBDIRS}, explained
4302
4303 Automake considers two sets of directories, defined by the variables
4304 @code{SUBDIRS} and @code{DIST_SUBDIRS}.
4305
4306 @code{SUBDIRS} contains the subdirectories of the current directory
4307 that must be built (@pxref{Subdirectories}).  It must be defined
4308 manually; Automake will never guess a directory is to be built.  As we
4309 will see in the next two sections, it is possible to define it
4310 conditionally so that some directory will be omitted from the build.
4311
4312 @code{DIST_SUBDIRS} is used in rules that need to recurse in all
4313 directories, even those that have been conditionally left out of the
4314 build.  Recall our example where we may not want to build subdirectory
4315 @file{opt/}, but yet we want to distribute it?  This is where
4316 @code{DIST_SUBDIRS} comes into play: @samp{opt} may not appear in
4317 @code{SUBDIRS}, but it must appear in @code{DIST_SUBDIRS}.
4318
4319 Precisely, @code{DIST_SUBDIRS} is used by @samp{make
4320 maintainer-clean}, @samp{make distclean} and @samp{make dist}.  All
4321 other recursive rules use @code{SUBDIRS}.
4322
4323 If @code{SUBDIRS} is defined conditionally using Automake
4324 conditionals, Automake will define @code{DIST_SUBDIRS} automatically
4325 from the possible values of @code{SUBDIRS} in all conditions.
4326
4327 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
4328 @code{DIST_SUBDIRS} will not be defined correctly because Automake
4329 does not know the possible values of these variables.  In this case
4330 @code{DIST_SUBDIRS} needs to be defined manually.
4331
4332 @node Subdirectories with AM_CONDITIONAL
4333 @subsection Subdirectories with @code{AM_CONDITIONAL}
4334 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
4335 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
4336
4337 @c Keep in sync with subcond2.sh
4338
4339 @file{configure} should output the @file{Makefile} for each directory
4340 and define a condition into which @file{opt/} should be built.
4341
4342 @example
4343 @dots{}
4344 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
4345 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4346 @dots{}
4347 @end example
4348
4349 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
4350 as follows.
4351
4352 @example
4353 if COND_OPT
4354   MAYBE_OPT = opt
4355 endif
4356 SUBDIRS = src $(MAYBE_OPT)
4357 @end example
4358
4359 As you can see, running @command{make} will rightly recurse into
4360 @file{src/} and maybe @file{opt/}.
4361
4362 @vindex DIST_SUBDIRS
4363 As you can't see, running @samp{make dist} will recurse into both
4364 @file{src/} and @file{opt/} directories because @samp{make dist}, unlike
4365 @samp{make all}, doesn't use the @code{SUBDIRS} variable.  It uses the
4366 @code{DIST_SUBDIRS} variable.
4367
4368 In this case Automake will define @samp{DIST_SUBDIRS = src opt}
4369 automatically because it knows that @code{MAYBE_OPT} can contain
4370 @samp{opt} in some condition.
4371
4372 @node Subdirectories with AC_SUBST
4373 @subsection Subdirectories with @code{AC_SUBST}
4374 @cindex @code{SUBDIRS} and @code{AC_SUBST}
4375 @cindex @code{AC_SUBST} and @code{SUBDIRS}
4376
4377 @c Keep in sync with subcond3.sh
4378
4379 Another possibility is to define @code{MAYBE_OPT} from
4380 @file{./configure} using @code{AC_SUBST}:
4381
4382 @example
4383 @dots{}
4384 if test "$want_opt" = yes; then
4385   MAYBE_OPT=opt
4386 else
4387   MAYBE_OPT=
4388 fi
4389 AC_SUBST([MAYBE_OPT])
4390 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4391 @dots{}
4392 @end example
4393
4394 In this case the top-level @file{Makefile.am} should look as follows.
4395
4396 @example
4397 SUBDIRS = src $(MAYBE_OPT)
4398 DIST_SUBDIRS = src opt
4399 @end example
4400
4401 The drawback is that since Automake cannot guess what the possible
4402 values of @code{MAYBE_OPT} are, it is necessary to define
4403 @code{DIST_SUBDIRS}.
4404
4405 @node Unconfigured Subdirectories
4406 @subsection Unconfigured Subdirectories
4407 @cindex Subdirectories, configured conditionally
4408
4409 The semantics of @code{DIST_SUBDIRS} are often misunderstood by some
4410 users that try to @emph{configure and build} subdirectories
4411 conditionally.  Here by configuring we mean creating the
4412 @file{Makefile} (it might also involve running a nested
4413 @command{configure} script: this is a costly operation that explains
4414 why people want to do it conditionally, but only the @file{Makefile}
4415 is relevant to the discussion).
4416
4417 The above examples all assume that every @file{Makefile} is created,
4418 even in directories that are not going to be built.  The simple reason
4419 is that we want @samp{make dist} to distribute even the directories
4420 that are not being built (e.g., platform-dependent code), hence
4421 @file{make dist} must recurse into the subdirectory, hence this
4422 directory must be configured and appear in @code{DIST_SUBDIRS}.
4423
4424 Building packages that do not configure every subdirectory is a tricky
4425 business, and we do not recommend it to the novice as it is easy to
4426 produce an incomplete tarball by mistake.  We will not discuss this
4427 topic in depth here, yet for the adventurous here are a few rules to
4428 remember.
4429
4430 @cartouche
4431 @itemize
4432 @item @code{SUBDIRS} should always be a subset of @code{DIST_SUBDIRS}.
4433
4434 It makes little sense to have a directory in @code{SUBDIRS} that
4435 is not in @code{DIST_SUBDIRS}.  Think of the former as a way to tell
4436 which directories listed in the latter should be built.
4437 @item Any directory listed in @code{DIST_SUBDIRS} and @code{SUBDIRS}
4438 must be configured.
4439
4440 I.e., the @file{Makefile} must exists or the recursive @command{make}
4441 rules will not be able to process the directory.
4442 @item Any configured directory must be listed in @code{DIST_SUBDIRS}.
4443
4444 So that the cleaning rules remove the generated @file{Makefile}s.
4445 It would be correct to see @code{DIST_SUBDIRS} as a variable that
4446 lists all the directories that have been configured.
4447 @end itemize
4448 @end cartouche
4449
4450 In order to prevent recursion in some unconfigured directory you
4451 must therefore ensure that this directory does not appear in
4452 @code{DIST_SUBDIRS} (and @code{SUBDIRS}).  For instance, if you define
4453 @code{SUBDIRS} conditionally using @code{AC_SUBST} and do not define
4454 @code{DIST_SUBDIRS} explicitly, it will be default to
4455 @samp{$(SUBDIRS)}; another possibility is to force @code{DIST_SUBDIRS
4456 = $(SUBDIRS)}.
4457
4458 Of course, directories that are omitted from @code{DIST_SUBDIRS} will
4459 not be distributed unless you make other arrangements for this to
4460 happen (for instance, always running @samp{make dist} in a
4461 configuration where all directories are known to appear in
4462 @code{DIST_SUBDIRS}; or writing a @code{dist-hook} target to
4463 distribute these directories).
4464
4465 @cindex Subdirectories, not distributed
4466 In few packages, unconfigured directories are not even expected to
4467 be distributed.  Although these packages do not require the
4468 aforementioned extra arrangements, there is another pitfall.  If the
4469 name of a directory appears in @code{SUBDIRS} or @code{DIST_SUBDIRS},
4470 @command{automake} will make sure the directory exists.  Consequently
4471 @command{automake} cannot be run on such a distribution when one
4472 directory has been omitted.  One way to avoid this check is to use the
4473 @code{AC_SUBST} method to declare conditional directories; since
4474 @command{automake} does not know the values of @code{AC_SUBST}
4475 variables it cannot ensure the corresponding directory exists.
4476
4477 @node Alternative
4478 @section An Alternative Approach to Subdirectories
4479
4480 If you've ever read Peter Miller's excellent paper,
4481 @uref{http://miller.emu.id.au/pmiller/books/rmch/,
4482 Recursive Make Considered Harmful}, the preceding sections on the use of
4483 subdirectories will probably come as unwelcome advice.  For those who
4484 haven't read the paper, Miller's main thesis is that recursive
4485 @command{make} invocations are both slow and error-prone.
4486
4487 Automake provides sufficient cross-directory support @footnote{We
4488 believe.  This work is new and there are probably warts.
4489 @xref{Introduction}, for information on reporting bugs.} to enable you
4490 to write a single @file{Makefile.am} for a complex multi-directory
4491 package.
4492
4493
4494 By default an installable file specified in a subdirectory will have its
4495 directory name stripped before installation.  For instance, in this
4496 example, the header file will be installed as
4497 @file{$(includedir)/stdio.h}:
4498
4499 @example
4500 include_HEADERS = inc/stdio.h
4501 @end example
4502
4503 @vindex nobase_
4504 @cindex @code{nobase_} prefix
4505 @cindex Path stripping, avoiding
4506 @cindex Avoiding path stripping
4507
4508 However, the @samp{nobase_} prefix can be used to circumvent this path
4509 stripping.  In this example, the header file will be installed as
4510 @file{$(includedir)/sys/types.h}:
4511
4512 @example
4513 nobase_include_HEADERS = sys/types.h
4514 @end example
4515
4516 @cindex @code{nobase_} and @code{dist_} or @code{nodist_}
4517 @cindex @code{dist_} and @code{nobase_}
4518 @cindex @code{nodist_} and @code{nobase_}
4519 @vindex dist_
4520 @vindex nodist_
4521
4522 @samp{nobase_} should be specified first when used in conjunction with
4523 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
4524 Control}).  For instance:
4525
4526 @example
4527 nobase_dist_pkgdata_DATA = images/vortex.pgm sounds/whirl.ogg
4528 @end example
4529
4530 Finally, note that a variable using the @samp{nobase_} prefix can
4531 often be replaced by several variables, one for each destination
4532 directory (@pxref{Uniform}).  For instance, the last example could be
4533 rewritten as follows:
4534
4535 @c Keep in sync with primary-prefix-couples-documented-valid.sh
4536 @example
4537 imagesdir = $(pkgdatadir)/images
4538 soundsdir = $(pkgdatadir)/sounds
4539 dist_images_DATA = images/vortex.pgm
4540 dist_sounds_DATA = sounds/whirl.ogg
4541 @end example
4542
4543 @noindent
4544 This latter syntax makes it possible to change one destination
4545 directory without changing the layout of the source tree.
4546
4547 Currently, @samp{nobase_*_LTLIBRARIES} are the only exception to this
4548 rule, in that there is no particular installation order guarantee for
4549 an otherwise equivalent set of variables without @samp{nobase_} prefix.
4550
4551 @node Subpackages
4552 @section Nesting Packages
4553 @cindex Nesting packages
4554 @cindex Subpackages
4555 @acindex AC_CONFIG_SUBDIRS
4556 @acindex AC_CONFIG_AUX_DIR
4557
4558
4559 In the GNU Build System, packages can be nested to arbitrary depth.
4560 This means that a package can embed other packages with their own
4561 @file{configure}, @file{Makefile}s, etc.
4562
4563 These other packages should just appear as subdirectories of their
4564 parent package.  They must be listed in @code{SUBDIRS} like other
4565 ordinary directories.  However the subpackage's @file{Makefile}s
4566 should be output by its own @file{configure} script, not by the
4567 parent's @file{configure}.  This is achieved using the
4568 @code{AC_CONFIG_SUBDIRS} Autoconf macro (@pxref{Subdirectories,
4569 AC_CONFIG_SUBDIRS, Configuring Other Packages in Subdirectories,
4570 autoconf, The Autoconf Manual}).
4571
4572 Here is an example package for an @code{arm} program that links with
4573 a @code{hand} library that is a nested package in subdirectory
4574 @file{hand/}.
4575
4576 @code{arm}'s @file{configure.ac}:
4577
4578 @example
4579 AC_INIT([arm], [1.0])
4580 AC_CONFIG_AUX_DIR([.])
4581 AM_INIT_AUTOMAKE
4582 AC_PROG_CC
4583 AC_CONFIG_FILES([Makefile])
4584 # Call hand's ./configure script recursively.
4585 AC_CONFIG_SUBDIRS([hand])
4586 AC_OUTPUT
4587 @end example
4588
4589 @code{arm}'s @file{Makefile.am}:
4590
4591 @example
4592 # Build the library in the hand subdirectory first.
4593 SUBDIRS = hand
4594
4595 # Include hand's header when compiling this directory.
4596 AM_CPPFLAGS = -I$(srcdir)/hand
4597
4598 bin_PROGRAMS = arm
4599 arm_SOURCES = arm.c
4600 # link with the hand library.
4601 arm_LDADD = hand/libhand.a
4602 @end example
4603
4604 Now here is @code{hand}'s @file{hand/configure.ac}:
4605
4606 @example
4607 AC_INIT([hand], [1.2])
4608 AC_CONFIG_AUX_DIR([.])
4609 AM_INIT_AUTOMAKE
4610 AC_PROG_CC
4611 AM_PROG_AR
4612 AC_PROG_RANLIB
4613 AC_CONFIG_FILES([Makefile])
4614 AC_OUTPUT
4615 @end example
4616
4617 @noindent
4618 and its @file{hand/Makefile.am}:
4619
4620 @example
4621 lib_LIBRARIES = libhand.a
4622 libhand_a_SOURCES = hand.c
4623 @end example
4624
4625 When @samp{make dist} is run from the top-level directory it will
4626 create an archive @file{arm-1.0.tar.gz} that contains the @code{arm}
4627 code as well as the @file{hand} subdirectory.  This package can be
4628 built and installed like any ordinary package, with the usual
4629 @samp{./configure && make && make install} sequence (the @code{hand}
4630 subpackage will be built and installed by the process).
4631
4632 When @samp{make dist} is run from the hand directory, it will create a
4633 self-contained @file{hand-1.2.tar.gz} archive.  So although it appears
4634 to be embedded in another package, it can still be used separately.
4635
4636 The purpose of the @samp{AC_CONFIG_AUX_DIR([.])} instruction is to
4637 force Automake and Autoconf to search for auxiliary scripts in the
4638 current directory.  For instance, this means that there will be two
4639 copies of @file{install-sh}: one in the top-level of the @code{arm}
4640 package, and another one in the @file{hand/} subdirectory for the
4641 @code{hand} package.
4642
4643 The historical default is to search for these auxiliary scripts in
4644 the parent directory and the grandparent directory.  So if the
4645 @samp{AC_CONFIG_AUX_DIR([.])} line was removed from
4646 @file{hand/configure.ac}, that subpackage would share the auxiliary
4647 script of the @code{arm} package.  This may looks like a gain in size
4648 (a few kilobytes), but it is actually a loss of modularity as the
4649 @code{hand} subpackage is no longer self-contained (@samp{make dist}
4650 in the subdirectory will not work anymore).
4651
4652 Packages that do not use Automake need more work to be integrated this
4653 way.  @xref{Third-Party Makefiles}.
4654
4655 @node Programs
4656 @chapter Building Programs and Libraries
4657
4658 A large part of Automake's functionality is dedicated to making it easy
4659 to build programs and libraries.
4660
4661 @menu
4662 * A Program::                   Building a program
4663 * A Library::                   Building a library
4664 * A Shared Library::            Building a Libtool library
4665 * Program and Library Variables::  Variables controlling program and
4666                                 library builds
4667 * Default _SOURCES::            Default source files
4668 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
4669 * Program Variables::           Variables used when building a program
4670 * Yacc and Lex::                Yacc and Lex support
4671 * C++ Support::                 Compiling C++ sources
4672 * Objective C Support::         Compiling Objective C sources
4673 * Unified Parallel C Support::  Compiling Unified Parallel C sources
4674 * Assembly Support::            Compiling assembly sources
4675 * Fortran 77 Support::          Compiling Fortran 77 sources
4676 * Fortran 9x Support::          Compiling Fortran 9x sources
4677 * Java Support with gcj::       Compiling Java sources using gcj
4678 * Vala Support::                Compiling Vala sources
4679 * Support for Other Languages::  Compiling other languages
4680 * Dependencies::                Automatic dependency tracking
4681 * EXEEXT::                      Support for executable extensions
4682 @end menu
4683
4684
4685 @node A Program
4686 @section Building a program
4687
4688 In order to build a program, you need to tell Automake which sources
4689 are part of it, and which libraries it should be linked with.
4690
4691 This section also covers conditional compilation of sources or
4692 programs.  Most of the comments about these also apply to libraries
4693 (@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
4694
4695 @menu
4696 * Program Sources::             Defining program sources
4697 * Linking::                     Linking with libraries or extra objects
4698 * Conditional Sources::         Handling conditional sources
4699 * Conditional Programs::        Building a program conditionally
4700 @end menu
4701
4702 @node Program Sources
4703 @subsection Defining program sources
4704
4705 @cindex @code{PROGRAMS}, @code{bindir}
4706 @vindex _PROGRAMS
4707 @vindex bin_PROGRAMS
4708 @vindex sbin_PROGRAMS
4709 @vindex libexec_PROGRAMS
4710 @vindex pkglibexec_PROGRAMS
4711 @vindex noinst_PROGRAMS
4712 @vindex check_PROGRAMS
4713
4714 In a directory containing source that gets built into a program (as
4715 opposed to a library or a script), the @code{PROGRAMS} primary is used.
4716 Programs can be installed in @code{bindir}, @code{sbindir},
4717 @code{libexecdir}, @code{pkglibexecdir}, or not at all
4718 (@code{noinst_}).  They can also be built only for @samp{make check}, in
4719 which case the prefix is @samp{check_}.
4720
4721 For instance:
4722
4723 @example
4724 bin_PROGRAMS = hello
4725 @end example
4726
4727 In this simple case, the resulting @file{Makefile.in} will contain code
4728 to generate a program named @code{hello}.
4729
4730 Associated with each program are several assisting variables that are
4731 named after the program.  These variables are all optional, and have
4732 reasonable defaults.  Each variable, its use, and default is spelled out
4733 below; we use the ``hello'' example throughout.
4734
4735 The variable @code{hello_SOURCES} is used to specify which source files
4736 get built into an executable:
4737
4738 @example
4739 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
4740 @end example
4741
4742 This causes each mentioned @file{.c} file to be compiled into the
4743 corresponding @file{.o}.  Then all are linked to produce @file{hello}.
4744
4745 @cindex @code{_SOURCES} primary, defined
4746 @cindex @code{SOURCES} primary, defined
4747 @cindex Primary variable, @code{SOURCES}
4748 @vindex _SOURCES
4749
4750 If @code{hello_SOURCES} is not specified, then it defaults to the single
4751 file @file{hello.c} (@pxref{Default _SOURCES}).
4752 @vindex _SOURCES
4753 @vindex SOURCES
4754
4755 Multiple programs can be built in a single directory.  Multiple programs
4756 can share a single source file, which must be listed in each
4757 @code{_SOURCES} definition.
4758
4759 @cindex Header files in @code{_SOURCES}
4760 @cindex @code{_SOURCES} and header files
4761
4762 Header files listed in a @code{_SOURCES} definition will be included in
4763 the distribution but otherwise ignored.  In case it isn't obvious, you
4764 should not include the header file generated by @file{configure} in a
4765 @code{_SOURCES} variable; this file should not be distributed.  Lex
4766 (@file{.l}) and Yacc (@file{.y}) files can also be listed; see @ref{Yacc
4767 and Lex}.
4768
4769
4770 @node Linking
4771 @subsection Linking the program
4772
4773 If you need to link against libraries that are not found by
4774 @command{configure}, you can use @code{LDADD} to do so.  This variable is
4775 used to specify additional objects or libraries to link with; it is
4776 inappropriate for specifying specific linker flags, you should use
4777 @code{AM_LDFLAGS} for this purpose.
4778 @vindex LDADD
4779 @vindex AM_LDFLAGS
4780
4781 @cindex @code{prog_LDADD}, defined
4782
4783 Sometimes, multiple programs are built in one directory but do not share
4784 the same link-time requirements.  In this case, you can use the
4785 @code{@var{prog}_LDADD} variable (where @var{prog} is the name of the
4786 program as it appears in some @code{_PROGRAMS} variable, and usually
4787 written in lowercase) to override @code{LDADD}.  If this variable exists
4788 for a given program, then that program is not linked using @code{LDADD}.
4789 @vindex maude_LDADD
4790
4791 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
4792 linked against the library @file{libcpio.a}.  However, @code{rmt} is
4793 built in the same directory, and has no such link requirement.  Also,
4794 @code{mt} and @code{rmt} are only built on certain architectures.  Here
4795 is what cpio's @file{src/Makefile.am} looks like (abridged):
4796
4797 @example
4798 bin_PROGRAMS = cpio pax $(MT)
4799 libexec_PROGRAMS = $(RMT)
4800 EXTRA_PROGRAMS = mt rmt
4801
4802 LDADD = ../lib/libcpio.a $(INTLLIBS)
4803 rmt_LDADD =
4804
4805 cpio_SOURCES = @dots{}
4806 pax_SOURCES = @dots{}
4807 mt_SOURCES = @dots{}
4808 rmt_SOURCES = @dots{}
4809 @end example
4810
4811 @cindex @code{_LDFLAGS}, defined
4812 @vindex maude_LDFLAGS
4813 @code{@var{prog}_LDADD} is inappropriate for passing program-specific
4814 linker flags (except for @option{-l}, @option{-L}, @option{-dlopen} and
4815 @option{-dlpreopen}).  So, use the @code{@var{prog}_LDFLAGS} variable for
4816 this purpose.
4817
4818 @cindex @code{_DEPENDENCIES}, defined
4819 @vindex maude_DEPENDENCIES
4820 @vindex EXTRA_maude_DEPENDENCIES
4821 It is also occasionally useful to have a program depend on some other
4822 target that is not actually part of that program.  This can be done
4823 using either the @code{@var{prog}_DEPENDENCIES} or the
4824 @code{EXTRA_@var{prog}_DEPENDENCIES} variable.  Each program depends on
4825 the contents both variables, but no further interpretation is done.
4826
4827 Since these dependencies are associated to the link rule used to
4828 create the programs they should normally list files used by the link
4829 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la}
4830 files.  In rare cases you may need to add other kinds of files such as
4831 linker scripts, but @emph{listing a source file in
4832 @code{_DEPENDENCIES} is wrong}.  If some source file needs to be built
4833 before all the components of a program are built, consider using the
4834 @code{BUILT_SOURCES} variable instead (@pxref{Sources}).
4835
4836 If @code{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
4837 Automake.  The automatically-assigned value is the contents of
4838 @code{@var{prog}_LDADD}, with most configure substitutions, @option{-l},
4839 @option{-L}, @option{-dlopen} and @option{-dlpreopen} options removed.  The
4840 configure substitutions that are left in are only @samp{$(LIBOBJS)} and
4841 @samp{$(ALLOCA)}; these are left because it is known that they will not
4842 cause an invalid value for @code{@var{prog}_DEPENDENCIES} to be
4843 generated.
4844
4845 @ref{Conditional Sources} shows a situation where @code{_DEPENDENCIES}
4846 may be used.
4847
4848 The @code{EXTRA_@var{prog}_DEPENDENCIES} may be useful for cases where
4849 you merely want to augment the @command{automake}-generated
4850 @code{@var{prog}_DEPENDENCIES} rather than replacing it.
4851
4852 @cindex @code{LDADD} and @option{-l}
4853 @cindex @option{-l} and @code{LDADD}
4854 We recommend that you avoid using @option{-l} options in @code{LDADD}
4855 or @code{@var{prog}_LDADD} when referring to libraries built by your
4856 package.  Instead, write the file name of the library explicitly as in
4857 the above @code{cpio} example.  Use @option{-l} only to list
4858 third-party libraries.  If you follow this rule, the default value of
4859 @code{@var{prog}_DEPENDENCIES} will list all your local libraries and
4860 omit the other ones.
4861
4862
4863 @node Conditional Sources
4864 @subsection Conditional compilation of sources
4865
4866 You can't put a configure substitution (e.g., @samp{@@FOO@@} or
4867 @samp{$(FOO)} where @code{FOO} is defined via @code{AC_SUBST}) into a
4868 @code{_SOURCES} variable.  The reason for this is a bit hard to
4869 explain, but suffice to say that it simply won't work.  Automake will
4870 give an error if you try to do this.
4871
4872 Fortunately there are two other ways to achieve the same result.  One is
4873 to use configure substitutions in @code{_LDADD} variables, the other is
4874 to use an Automake conditional.
4875
4876 @subsubheading Conditional Compilation using @code{_LDADD} Substitutions
4877
4878 @cindex @code{EXTRA_prog_SOURCES}, defined
4879
4880 Automake must know all the source files that could possibly go into a
4881 program, even if not all the files are built in every circumstance.  Any
4882 files that are only conditionally built should be listed in the
4883 appropriate @code{EXTRA_} variable.  For instance, if
4884 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
4885 in @code{hello}, the @file{Makefile.am} would contain:
4886
4887 @example
4888 bin_PROGRAMS = hello
4889 hello_SOURCES = hello-common.c
4890 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
4891 hello_LDADD = $(HELLO_SYSTEM)
4892 hello_DEPENDENCIES = $(HELLO_SYSTEM)
4893 @end example
4894
4895 @noindent
4896 You can then setup the @samp{$(HELLO_SYSTEM)} substitution from
4897 @file{configure.ac}:
4898
4899 @example
4900 @dots{}
4901 case $host in
4902   *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
4903   *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
4904 esac
4905 AC_SUBST([HELLO_SYSTEM])
4906 @dots{}
4907 @end example
4908
4909 In this case, the variable @code{HELLO_SYSTEM} should be replaced by
4910 either @file{hello-linux.o} or @file{hello-generic.o}, and added to
4911 both @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be
4912 built and linked in.
4913
4914 @subsubheading Conditional Compilation using Automake Conditionals
4915
4916 An often simpler way to compile source files conditionally is to use
4917 Automake conditionals.  For instance, you could use this
4918 @file{Makefile.am} construct to build the same @file{hello} example:
4919
4920 @example
4921 bin_PROGRAMS = hello
4922 if LINUX
4923 hello_SOURCES = hello-linux.c hello-common.c
4924 else
4925 hello_SOURCES = hello-generic.c hello-common.c
4926 endif
4927 @end example
4928
4929 In this case, @file{configure.ac} should setup the @code{LINUX}
4930 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
4931
4932 When using conditionals like this you don't need to use the
4933 @code{EXTRA_} variable, because Automake will examine the contents of
4934 each variable to construct the complete list of source files.
4935
4936 If your program uses a lot of files, you will probably prefer a
4937 conditional @samp{+=}.
4938
4939 @example
4940 bin_PROGRAMS = hello
4941 hello_SOURCES = hello-common.c
4942 if LINUX
4943 hello_SOURCES += hello-linux.c
4944 else
4945 hello_SOURCES += hello-generic.c
4946 endif
4947 @end example
4948
4949 @node Conditional Programs
4950 @subsection Conditional compilation of programs
4951 @cindex Conditional programs
4952 @cindex Programs, conditional
4953
4954 Sometimes it is useful to determine the programs that are to be built
4955 at configure time.  For instance, GNU @code{cpio} only builds
4956 @code{mt} and @code{rmt} under special circumstances.  The means to
4957 achieve conditional compilation of programs are the same you can use
4958 to compile source files conditionally: substitutions or conditionals.
4959
4960 @subsubheading Conditional Programs using @command{configure} Substitutions
4961
4962 @vindex EXTRA_PROGRAMS
4963 @cindex @code{EXTRA_PROGRAMS}, defined
4964 In this case, you must notify Automake of all the programs that can
4965 possibly be built, but at the same time cause the generated
4966 @file{Makefile.in} to use the programs specified by @command{configure}.
4967 This is done by having @command{configure} substitute values into each
4968 @code{_PROGRAMS} definition, while listing all optionally built programs
4969 in @code{EXTRA_PROGRAMS}.
4970
4971 @example
4972 bin_PROGRAMS = cpio pax $(MT)
4973 libexec_PROGRAMS = $(RMT)
4974 EXTRA_PROGRAMS = mt rmt
4975 @end example
4976
4977 As explained in @ref{EXEEXT}, Automake will rewrite
4978 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
4979 @code{EXTRA_PROGRAMS}, appending @samp{$(EXEEXT)} to each binary.
4980 Obviously it cannot rewrite values obtained at run-time through
4981 @command{configure} substitutions, therefore you should take care of
4982 appending @samp{$(EXEEXT)} yourself, as in @samp{AC_SUBST([MT],
4983 ['mt$@{EXEEXT@}'])}.
4984
4985 @subsubheading Conditional Programs using Automake Conditionals
4986
4987 You can also use Automake conditionals (@pxref{Conditionals}) to
4988 select programs to be built.  In this case you don't have to worry
4989 about @samp{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
4990
4991 @c Keep in sync with exeext.sh
4992 @example
4993 bin_PROGRAMS = cpio pax
4994 if WANT_MT
4995   bin_PROGRAMS += mt
4996 endif
4997 if WANT_RMT
4998   libexec_PROGRAMS = rmt
4999 endif
5000 @end example
5001
5002
5003 @node A Library
5004 @section Building a library
5005
5006 @cindex @code{_LIBRARIES} primary, defined
5007 @cindex @code{LIBRARIES} primary, defined
5008 @cindex Primary variable, @code{LIBRARIES}
5009 @vindex _LIBRARIES
5010
5011 @vindex lib_LIBRARIES
5012 @vindex pkglib_LIBRARIES
5013 @vindex noinst_LIBRARIES
5014
5015 Building a library is much like building a program.  In this case, the
5016 name of the primary is @code{LIBRARIES}.  Libraries can be installed in
5017 @code{libdir} or @code{pkglibdir}.
5018
5019 @xref{A Shared Library}, for information on how to build shared
5020 libraries using libtool and the @code{LTLIBRARIES} primary.
5021
5022 Each @code{_LIBRARIES} variable is a list of the libraries to be built.
5023 For instance, to create a library named @file{libcpio.a}, but not install
5024 it, you would write:
5025
5026 @example
5027 noinst_LIBRARIES = libcpio.a
5028 libcpio_a_SOURCES = @dots{}
5029 @end example
5030
5031 The sources that go into a library are determined exactly as they are
5032 for programs, via the @code{_SOURCES} variables.  Note that the library
5033 name is canonicalized (@pxref{Canonicalization}), so the @code{_SOURCES}
5034 variable corresponding to @file{libcpio.a} is @samp{libcpio_a_SOURCES},
5035 not @samp{libcpio.a_SOURCES}.
5036
5037 @vindex maude_LIBADD
5038 Extra objects can be added to a library using the
5039 @code{@var{library}_LIBADD} variable.  This should be used for objects
5040 determined by @command{configure}.  Again from @code{cpio}:
5041
5042 @c Keep in sync with pr401c.sh
5043 @example
5044 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
5045 @end example
5046
5047 In addition, sources for extra objects that will not exist until
5048 configure-time must be added to the @code{BUILT_SOURCES} variable
5049 (@pxref{Sources}).
5050
5051 Building a static library is done by compiling all object files, then
5052 by invoking @samp{$(AR) $(ARFLAGS)} followed by the name of the
5053 library and the list of objects, and finally by calling
5054 @samp{$(RANLIB)} on that library.  You should call
5055 @code{AC_PROG_RANLIB} from your @file{configure.ac} to define
5056 @code{RANLIB} (Automake will complain otherwise).  You should also
5057 call @code{AM_PROG_AR} to define @code{AR}, in order to support unusual
5058 archivers such as Microsoft lib.  @code{ARFLAGS} will default to
5059 @code{cru}; you can override this variable by setting it in your
5060 @file{Makefile.am} or by @code{AC_SUBST}ing it from your
5061 @file{configure.ac}.  You can override the @code{AR} variable by
5062 defining a per-library @code{maude_AR} variable (@pxref{Program and
5063 Library Variables}).
5064
5065 @cindex Empty libraries
5066 Be careful when selecting library components conditionally.  Because
5067 building an empty library is not portable, you should ensure that any
5068 library always contains at least one object.
5069
5070 To use a static library when building a program, add it to
5071 @code{LDADD} for this program.  In the following example, the program
5072 @file{cpio} is statically linked with the library @file{libcpio.a}.
5073
5074 @example
5075 noinst_LIBRARIES = libcpio.a
5076 libcpio_a_SOURCES = @dots{}
5077
5078 bin_PROGRAMS = cpio
5079 cpio_SOURCES = cpio.c @dots{}
5080 cpio_LDADD = libcpio.a
5081 @end example
5082
5083
5084 @node A Shared Library
5085 @section Building a Shared Library
5086
5087 @cindex Shared libraries, support for
5088
5089 Building shared libraries portably is a relatively complex matter.
5090 For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
5091 Libtool Manual}) was created to help build shared libraries in a
5092 platform-independent way.
5093
5094 @menu
5095 * Libtool Concept::             Introducing Libtool
5096 * Libtool Libraries::           Declaring Libtool Libraries
5097 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
5098 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
5099 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
5100 * Libtool Modules::             Building Libtool Modules
5101 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
5102 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
5103 * Libtool Issues::              Common Issues Related to Libtool's Use
5104 @end menu
5105
5106 @node Libtool Concept
5107 @subsection The Libtool Concept
5108
5109 @cindex @command{libtool}, introduction
5110 @cindex libtool library, definition
5111 @cindex suffix @file{.la}, defined
5112 @cindex @file{.la} suffix, defined
5113
5114 Libtool abstracts shared and static libraries into a unified concept
5115 henceforth called @dfn{libtool libraries}.  Libtool libraries are
5116 files using the @file{.la} suffix, and can designate a static library,
5117 a shared library, or maybe both.  Their exact nature cannot be
5118 determined until @file{./configure} is run: not all platforms support
5119 all kinds of libraries, and users can explicitly select which
5120 libraries should be built.  (However the package's maintainers can
5121 tune the default, @pxref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
5122 macro, libtool, The Libtool Manual}.)
5123
5124 @cindex suffix @file{.lo}, defined
5125 Because object files for shared and static libraries must be compiled
5126 differently, libtool is also used during compilation.  Object files
5127 built by libtool are called @dfn{libtool objects}: these are files
5128 using the @file{.lo} suffix.  Libtool libraries are built from these
5129 libtool objects.
5130
5131 You should not assume anything about the structure of @file{.la} or
5132 @file{.lo} files and how libtool constructs them: this is libtool's
5133 concern, and the last thing one wants is to learn about libtool's
5134 guts.  However the existence of these files matters, because they are
5135 used as targets and dependencies in @file{Makefile}s rules when
5136 building libtool libraries.  There are situations where you may have
5137 to refer to these, for instance when expressing dependencies for
5138 building source files conditionally (@pxref{Conditional Libtool
5139 Sources}).
5140
5141 @cindex @file{libltdl}, introduction
5142
5143 People considering writing a plug-in system, with dynamically loaded
5144 modules, should look into @file{libltdl}: libtool's dlopening library
5145 (@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
5146 This offers a portable dlopening facility to load libtool libraries
5147 dynamically, and can also achieve static linking where unavoidable.
5148
5149 Before we discuss how to use libtool with Automake in details, it
5150 should be noted that the libtool manual also has a section about how
5151 to use Automake with libtool (@pxref{Using Automake, , Using Automake
5152 with Libtool, libtool, The Libtool Manual}).
5153
5154 @node Libtool Libraries
5155 @subsection Building Libtool Libraries
5156
5157 @cindex @code{_LTLIBRARIES} primary, defined
5158 @cindex @code{LTLIBRARIES} primary, defined
5159 @cindex Primary variable, @code{LTLIBRARIES}
5160 @cindex Example of shared libraries
5161 @vindex lib_LTLIBRARIES
5162 @vindex pkglib_LTLIBRARIES
5163 @vindex _LTLIBRARIES
5164
5165 Automake uses libtool to build libraries declared with the
5166 @code{LTLIBRARIES} primary.  Each @code{_LTLIBRARIES} variable is a
5167 list of libtool libraries to build.  For instance, to create a libtool
5168 library named @file{libgettext.la}, and install it in @code{libdir},
5169 write:
5170
5171 @example
5172 lib_LTLIBRARIES = libgettext.la
5173 libgettext_la_SOURCES = gettext.c gettext.h @dots{}
5174 @end example
5175
5176 Automake predefines the variable @code{pkglibdir}, so you can use
5177 @code{pkglib_LTLIBRARIES} to install libraries in
5178 @samp{$(libdir)/@@PACKAGE@@/}.
5179
5180 If @file{gettext.h} is a public header file that needs to be installed
5181 in order for people to use the library, it should be declared using a
5182 @code{_HEADERS} variable, not in @code{libgettext_la_SOURCES}.
5183 Headers listed in the latter should be internal headers that are not
5184 part of the public interface.
5185
5186 @example
5187 lib_LTLIBRARIES = libgettext.la
5188 libgettext_la_SOURCES = gettext.c @dots{}
5189 include_HEADERS = gettext.h @dots{}
5190 @end example
5191
5192 A package can build and install such a library along with other
5193 programs that use it.  This dependency should be specified using
5194 @code{LDADD}.  The following example builds a program named
5195 @file{hello} that is linked with @file{libgettext.la}.
5196
5197 @example
5198 lib_LTLIBRARIES = libgettext.la
5199 libgettext_la_SOURCES = gettext.c @dots{}
5200
5201 bin_PROGRAMS = hello
5202 hello_SOURCES = hello.c @dots{}
5203 hello_LDADD = libgettext.la
5204 @end example
5205
5206 @noindent
5207 Whether @file{hello} is statically or dynamically linked with
5208 @file{libgettext.la} is not yet known: this will depend on the
5209 configuration of libtool and the capabilities of the host.
5210
5211
5212 @node Conditional Libtool Libraries
5213 @subsection Building Libtool Libraries Conditionally
5214 @cindex libtool libraries, conditional
5215 @cindex conditional libtool libraries
5216
5217 Like conditional programs (@pxref{Conditional Programs}), there are
5218 two main ways to build conditional libraries: using Automake
5219 conditionals or using Autoconf @code{AC_SUBST}itutions.
5220
5221 The important implementation detail you have to be aware of is that
5222 the place where a library will be installed matters to libtool: it
5223 needs to be indicated @emph{at link-time} using the @option{-rpath}
5224 option.
5225
5226 For libraries whose destination directory is known when Automake runs,
5227 Automake will automatically supply the appropriate @option{-rpath}
5228 option to libtool.  This is the case for libraries listed explicitly in
5229 some installable @code{_LTLIBRARIES} variables such as
5230 @code{lib_LTLIBRARIES}.
5231
5232 However, for libraries determined at configure time (and thus
5233 mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
5234 final installation directory.  For such libraries you must add the
5235 @option{-rpath} option to the appropriate @code{_LDFLAGS} variable by
5236 hand.
5237
5238 The examples below illustrate the differences between these two methods.
5239
5240 Here is an example where @code{WANTEDLIBS} is an @code{AC_SUBST}ed
5241 variable set at @file{./configure}-time to either @file{libfoo.la},
5242 @file{libbar.la}, both, or none.  Although @samp{$(WANTEDLIBS)}
5243 appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
5244 relates to @file{libfoo.la} or @file{libbar.la} at the time it creates
5245 the link rule for these two libraries.  Therefore the @option{-rpath}
5246 argument must be explicitly supplied.
5247
5248 @c Keep in sync with ltcond.sh
5249 @example
5250 EXTRA_LTLIBRARIES = libfoo.la libbar.la
5251 lib_LTLIBRARIES = $(WANTEDLIBS)
5252 libfoo_la_SOURCES = foo.c @dots{}
5253 libfoo_la_LDFLAGS = -rpath '$(libdir)'
5254 libbar_la_SOURCES = bar.c @dots{}
5255 libbar_la_LDFLAGS = -rpath '$(libdir)'
5256 @end example
5257
5258 Here is how the same @file{Makefile.am} would look using Automake
5259 conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}.  Now
5260 Automake is able to compute the @option{-rpath} setting itself, because
5261 it's clear that both libraries will end up in @samp{$(libdir)} if they
5262 are installed.
5263
5264 @c Keep in sync with ltcond.sh
5265 @example
5266 lib_LTLIBRARIES =
5267 if WANT_LIBFOO
5268 lib_LTLIBRARIES += libfoo.la
5269 endif
5270 if WANT_LIBBAR
5271 lib_LTLIBRARIES += libbar.la
5272 endif
5273 libfoo_la_SOURCES = foo.c @dots{}
5274 libbar_la_SOURCES = bar.c @dots{}
5275 @end example
5276
5277 @node Conditional Libtool Sources
5278 @subsection Libtool Libraries with Conditional Sources
5279
5280 Conditional compilation of sources in a library can be achieved in the
5281 same way as conditional compilation of sources in a program
5282 (@pxref{Conditional Sources}).  The only difference is that
5283 @code{_LIBADD} should be used instead of @code{_LDADD} and that it
5284 should mention libtool objects (@file{.lo} files).
5285
5286 So, to mimic the @file{hello} example from @ref{Conditional Sources},
5287 we could build a @file{libhello.la} library using either
5288 @file{hello-linux.c} or @file{hello-generic.c} with the following
5289 @file{Makefile.am}.
5290
5291 @c Keep in sync with ltcond2.sh
5292 @example
5293 lib_LTLIBRARIES = libhello.la
5294 libhello_la_SOURCES = hello-common.c
5295 EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
5296 libhello_la_LIBADD = $(HELLO_SYSTEM)
5297 libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
5298 @end example
5299
5300 @noindent
5301 And make sure @command{configure} defines @code{HELLO_SYSTEM} as
5302 either @file{hello-linux.lo} or @file{hello-@-generic.lo}.
5303
5304 Or we could simply use an Automake conditional as follows.
5305
5306 @c Keep in sync with ltcond2.sh
5307 @example
5308 lib_LTLIBRARIES = libhello.la
5309 libhello_la_SOURCES = hello-common.c
5310 if LINUX
5311 libhello_la_SOURCES += hello-linux.c
5312 else
5313 libhello_la_SOURCES += hello-generic.c
5314 endif
5315 @end example
5316
5317 @node Libtool Convenience Libraries
5318 @subsection Libtool Convenience Libraries
5319 @cindex convenience libraries, libtool
5320 @cindex libtool convenience libraries
5321 @vindex noinst_LTLIBRARIES
5322 @vindex check_LTLIBRARIES
5323
5324 Sometimes you want to build libtool libraries that should not be
5325 installed.  These are called @dfn{libtool convenience libraries} and
5326 are typically used to encapsulate many sublibraries, later gathered
5327 into one big installed library.
5328
5329 Libtool convenience libraries are declared by directory-less variables
5330 such as @code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
5331 @code{EXTRA_LTLIBRARIES}.  Unlike installed libtool libraries they do
5332 not need an @option{-rpath} flag at link time (actually this is the only
5333 difference).
5334
5335 Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
5336 built.  Those listed in @code{check_LTLIBRARIES} are built only upon
5337 @samp{make check}.  Finally, libraries listed in
5338 @code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
5339 rules to build them, but if the library does not appear as a Makefile
5340 dependency anywhere it won't be built (this is why
5341 @code{EXTRA_LTLIBRARIES} is used for conditional compilation).
5342
5343 Here is a sample setup merging libtool convenience libraries from
5344 subdirectories into one main @file{libtop.la} library.
5345
5346 @c Keep in sync with ltconv.sh
5347 @example
5348 # -- Top-level Makefile.am --
5349 SUBDIRS = sub1 sub2 @dots{}
5350 lib_LTLIBRARIES = libtop.la
5351 libtop_la_SOURCES =
5352 libtop_la_LIBADD = \
5353   sub1/libsub1.la \
5354   sub2/libsub2.la \
5355   @dots{}
5356
5357 # -- sub1/Makefile.am --
5358 noinst_LTLIBRARIES = libsub1.la
5359 libsub1_la_SOURCES = @dots{}
5360
5361 # -- sub2/Makefile.am --
5362 # showing nested convenience libraries
5363 SUBDIRS = sub2.1 sub2.2 @dots{}
5364 noinst_LTLIBRARIES = libsub2.la
5365 libsub2_la_SOURCES =
5366 libsub2_la_LIBADD = \
5367   sub21/libsub21.la \
5368   sub22/libsub22.la \
5369   @dots{}
5370 @end example
5371
5372 When using such setup, beware that @command{automake} will assume
5373 @file{libtop.la} is to be linked with the C linker.  This is because
5374 @code{libtop_la_SOURCES} is empty, so @command{automake} picks C as
5375 default language.  If @code{libtop_la_SOURCES} was not empty,
5376 @command{automake} would select the linker as explained in @ref{How
5377 the Linker is Chosen}.
5378
5379 If one of the sublibraries contains non-C source, it is important that
5380 the appropriate linker be chosen.  One way to achieve this is to
5381 pretend that there is such a non-C file among the sources of the
5382 library, thus forcing @command{automake} to select the appropriate
5383 linker.  Here is the top-level @file{Makefile} of our example updated
5384 to force C++ linking.
5385
5386 @example
5387 SUBDIRS = sub1 sub2 @dots{}
5388 lib_LTLIBRARIES = libtop.la
5389 libtop_la_SOURCES =
5390 # Dummy C++ source to cause C++ linking.
5391 nodist_EXTRA_libtop_la_SOURCES = dummy.cxx
5392 libtop_la_LIBADD = \
5393   sub1/libsub1.la \
5394   sub2/libsub2.la \
5395   @dots{}
5396 @end example
5397
5398 @samp{EXTRA_*_SOURCES} variables are used to keep track of source
5399 files that might be compiled (this is mostly useful when doing
5400 conditional compilation using @code{AC_SUBST}, @pxref{Conditional
5401 Libtool Sources}), and the @code{nodist_} prefix means the listed
5402 sources are not to be distributed (@pxref{Program and Library
5403 Variables}).  In effect the file @file{dummy.cxx} does not need to
5404 exist in the source tree.  Of course if you have some real source file
5405 to list in @code{libtop_la_SOURCES} there is no point in cheating with
5406 @code{nodist_EXTRA_libtop_la_SOURCES}.
5407
5408
5409 @node Libtool Modules
5410 @subsection Libtool Modules
5411 @cindex modules, libtool
5412 @cindex libtool modules
5413 @cindex @option{-module}, libtool
5414
5415 These are libtool libraries meant to be dlopened.  They are
5416 indicated to libtool by passing @option{-module} at link-time.
5417
5418 @example
5419 pkglib_LTLIBRARIES = mymodule.la
5420 mymodule_la_SOURCES = doit.c
5421 mymodule_la_LDFLAGS = -module
5422 @end example
5423
5424 Ordinarily, Automake requires that a library's name start with
5425 @code{lib}.  However, when building a dynamically loadable module you
5426 might wish to use a "nonstandard" name.  Automake will not complain
5427 about such nonstandard names if it knows the library being built is a
5428 libtool module, i.e., if @option{-module} explicitly appears in the
5429 library's @code{_LDFLAGS} variable (or in the common @code{AM_LDFLAGS}
5430 variable when no per-library @code{_LDFLAGS} variable is defined).
5431
5432 As always, @code{AC_SUBST} variables are black boxes to Automake since
5433 their values are not yet known when @command{automake} is run.
5434 Therefore if @option{-module} is set via such a variable, Automake
5435 cannot notice it and will proceed as if the library was an ordinary
5436 libtool library, with strict naming.
5437
5438 If @code{mymodule_la_SOURCES} is not specified, then it defaults to
5439 the single file @file{mymodule.c} (@pxref{Default _SOURCES}).
5440
5441 @node Libtool Flags
5442 @subsection @code{_LIBADD}, @code{_LDFLAGS}, and @code{_LIBTOOLFLAGS}
5443 @cindex @code{_LIBADD}, libtool
5444 @cindex @code{_LDFLAGS}, libtool
5445 @cindex @code{_LIBTOOLFLAGS}, libtool
5446 @vindex AM_LIBTOOLFLAGS
5447 @vindex LIBTOOLFLAGS
5448 @vindex maude_LIBTOOLFLAGS
5449
5450 As shown in previous sections, the @samp{@var{library}_LIBADD}
5451 variable should be used to list extra libtool objects (@file{.lo}
5452 files) or libtool libraries (@file{.la}) to add to @var{library}.
5453
5454 The @samp{@var{library}_LDFLAGS} variable is the place to list
5455 additional libtool linking flags, such as @option{-version-info},
5456 @option{-static}, and a lot more.  @xref{Link mode, , Link mode,
5457 libtool, The Libtool Manual}.
5458
5459 The @command{libtool} command has two kinds of options: mode-specific
5460 options and generic options.  Mode-specific options such as the
5461 aforementioned linking flags should be lumped with the other flags
5462 passed to the tool invoked by @command{libtool} (hence the use of
5463 @samp{@var{library}_LDFLAGS} for libtool linking flags).  Generic
5464 options include @option{--tag=@var{tag}} and @option{--silent}
5465 (@pxref{Invoking libtool, , Invoking @command{libtool}, libtool, The
5466 Libtool Manual} for more options) should appear before the mode
5467 selection on the command line; in @file{Makefile.am}s they should
5468 be listed in the @samp{@var{library}_LIBTOOLFLAGS} variable.
5469
5470 If @samp{@var{library}_LIBTOOLFLAGS} is not defined, then the variable
5471 @code{AM_LIBTOOLFLAGS} is used instead.
5472
5473 These flags are passed to libtool after the @option{--tag=@var{tag}}
5474 option computed by Automake (if any), so
5475 @samp{@var{library}_LIBTOOLFLAGS} (or @code{AM_LIBTOOLFLAGS}) is a
5476 good place to override or supplement the @option{--tag=@var{tag}}
5477 setting.
5478
5479 The libtool rules also use a @code{LIBTOOLFLAGS} variable that should
5480 not be set in @file{Makefile.am}: this is a user variable (@pxref{Flag
5481 Variables Ordering}.  It allows users to run @samp{make
5482 LIBTOOLFLAGS=--silent}, for instance.  Note that the verbosity of
5483 @command{libtool} can also be influenced with the Automake
5484 @option{silent-rules} option (@pxref{Options}).
5485
5486
5487 @node LTLIBOBJS, Libtool Issues, Libtool Flags, A Shared Library
5488 @subsection @code{LTLIBOBJS} and @code{LTALLOCA}
5489 @cindex @code{LTLIBOBJS}, special handling
5490 @cindex @code{LIBOBJS}, and Libtool
5491 @cindex @code{LTALLOCA}, special handling
5492 @cindex @code{ALLOCA}, and Libtool
5493 @vindex LTLIBOBJS
5494 @vindex LIBOBJS
5495 @vindex LTALLOCA
5496 @vindex ALLOCA
5497 @acindex AC_LIBOBJ
5498
5499 Where an ordinary library might include @samp{$(LIBOBJS)} or
5500 @samp{$(ALLOCA)} (@pxref{LIBOBJS}), a libtool library must use
5501 @samp{$(LTLIBOBJS)} or @samp{$(LTALLOCA)}.  This is required because
5502 the object files that libtool operates on do not necessarily end in
5503 @file{.o}.
5504
5505 Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
5506 performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
5507 @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual}).
5508
5509 @node Libtool Issues
5510 @subsection Common Issues Related to Libtool's Use
5511
5512 @menu
5513 * Error required file ltmain.sh not found::  The need to run libtoolize
5514 * Objects created both with libtool and without::  Avoid a specific build race
5515 @end menu
5516
5517 @node Error required file ltmain.sh not found
5518 @subsubsection Error: @samp{required file `./ltmain.sh' not found}
5519 @cindex @file{ltmain.sh} not found
5520 @cindex @command{libtoolize}, no longer run by @command{automake}
5521 @cindex @command{libtoolize} and @command{autoreconf}
5522 @cindex @command{autoreconf} and @command{libtoolize}
5523 @cindex @file{bootstrap.sh} and @command{autoreconf}
5524 @cindex @file{autogen.sh} and @command{autoreconf}
5525
5526 Libtool comes with a tool called @command{libtoolize} that will
5527 install libtool's supporting files into a package.  Running this
5528 command will install @file{ltmain.sh}.  You should execute it before
5529 @command{aclocal} and @command{automake}.
5530
5531 People upgrading old packages to newer autotools are likely to face
5532 this issue because older Automake versions used to call
5533 @command{libtoolize}.  Therefore old build scripts do not call
5534 @command{libtoolize}.
5535
5536 Since Automake 1.6, it has been decided that running
5537 @command{libtoolize} was none of Automake's business.  Instead, that
5538 functionality has been moved into the @command{autoreconf} command
5539 (@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
5540 The Autoconf Manual}).  If you do not want to remember what to run and
5541 when, just learn the @command{autoreconf} command.  Hopefully,
5542 replacing existing @file{bootstrap.sh} or @file{autogen.sh} scripts by
5543 a call to @command{autoreconf} should also free you from any similar
5544 incompatible change in the future.
5545
5546 @node Objects created both with libtool and without
5547 @subsubsection Objects @samp{created with both libtool and without}
5548
5549 Sometimes, the same source file is used both to build a libtool
5550 library and to build another non-libtool target (be it a program or
5551 another library).
5552
5553 Let's consider the following @file{Makefile.am}.
5554
5555 @example
5556 bin_PROGRAMS = prog
5557 prog_SOURCES = prog.c foo.c @dots{}
5558
5559 lib_LTLIBRARIES = libfoo.la
5560 libfoo_la_SOURCES = foo.c @dots{}
5561 @end example
5562
5563 @noindent
5564 (In this trivial case the issue could be avoided by linking
5565 @file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
5566 @code{prog_SOURCES}.  But let's assume we really want to keep
5567 @file{prog} and @file{libfoo.la} separate.)
5568
5569 Technically, it means that we should build @file{foo.$(OBJEXT)} for
5570 @file{prog}, and @file{foo.lo} for @file{libfoo.la}.  The problem is
5571 that in the course of creating @file{foo.lo}, libtool may erase (or
5572 replace) @file{foo.$(OBJEXT)}, and this cannot be avoided.
5573
5574 Therefore, when Automake detects this situation it will complain
5575 with a message such as
5576 @example
5577 object `foo.$(OBJEXT)' created both with libtool and without
5578 @end example
5579
5580 A workaround for this issue is to ensure that these two objects get
5581 different basenames.  As explained in @ref{Renamed Objects}, this
5582 happens automatically when per-targets flags are used.
5583
5584 @example
5585 bin_PROGRAMS = prog
5586 prog_SOURCES = prog.c foo.c @dots{}
5587 prog_CFLAGS = $(AM_CFLAGS)
5588
5589 lib_LTLIBRARIES = libfoo.la
5590 libfoo_la_SOURCES = foo.c @dots{}
5591 @end example
5592
5593 @noindent
5594 Adding @samp{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
5595 when the @code{prog_CFLAGS} is defined, it is used instead of
5596 @code{AM_CFLAGS}.  However as a side effect it will cause
5597 @file{prog.c} and @file{foo.c} to be compiled as
5598 @file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)}, which solves
5599 the issue.
5600
5601 @node Program and Library Variables
5602 @section Program and Library Variables
5603
5604 Associated with each program is a collection of variables that can be
5605 used to modify how that program is built.  There is a similar list of
5606 such variables for each library.  The canonical name of the program (or
5607 library) is used as a base for naming these variables.
5608
5609 In the list below, we use the name ``maude'' to refer to the program or
5610 library.  In your @file{Makefile.am} you would replace this with the
5611 canonical name of your program.  This list also refers to ``maude'' as a
5612 program, but in general the same rules apply for both static and dynamic
5613 libraries; the documentation below notes situations where programs and
5614 libraries differ.
5615
5616 @vtable @code
5617 @item maude_SOURCES
5618 This variable, if it exists, lists all the source files that are
5619 compiled to build the program.  These files are added to the
5620 distribution by default.  When building the program, Automake will cause
5621 each source file to be compiled to a single @file{.o} file (or
5622 @file{.lo} when using libtool).  Normally these object files are named
5623 after the source file, but other factors can change this.  If a file in
5624 the @code{_SOURCES} variable has an unrecognized extension, Automake
5625 will do one of two things with it.  If a suffix rule exists for turning
5626 files with the unrecognized extension into @file{.o} files, then
5627 @command{automake} will treat this file as it will any other source file
5628 (@pxref{Support for Other Languages}).  Otherwise, the file will be
5629 ignored as though it were a header file.
5630
5631 The prefixes @code{dist_} and @code{nodist_} can be used to control
5632 whether files listed in a @code{_SOURCES} variable are distributed.
5633 @code{dist_} is redundant, as sources are distributed by default, but it
5634 can be specified for clarity if desired.
5635
5636 It is possible to have both @code{dist_} and @code{nodist_} variants of
5637 a given @code{_SOURCES} variable at once; this lets you easily
5638 distribute some files and not others, for instance:
5639
5640 @example
5641 nodist_maude_SOURCES = nodist.c
5642 dist_maude_SOURCES = dist-me.c
5643 @end example
5644
5645 By default the output file (on Unix systems, the @file{.o} file) will
5646 be put into the current build directory.  However, if the option
5647 @option{subdir-objects} is in effect in the current directory then the
5648 @file{.o} file will be put into the subdirectory named after the
5649 source file.  For instance, with @option{subdir-objects} enabled,
5650 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
5651 people prefer this mode of operation.  You can specify
5652 @option{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
5653 @cindex Subdirectory, objects in
5654 @cindex Objects in subdirectory
5655
5656
5657 @item EXTRA_maude_SOURCES
5658 Automake needs to know the list of files you intend to compile
5659 @emph{statically}.  For one thing, this is the only way Automake has of
5660 knowing what sort of language support a given @file{Makefile.in}
5661 requires.  @footnote{There are other, more obscure reasons for
5662 this limitation as well.}  This means that, for example, you can't put a
5663 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
5664 variable.  If you intend to conditionally compile source files and use
5665 @file{configure} to substitute the appropriate object names into, e.g.,
5666 @code{_LDADD} (see below), then you should list the corresponding source
5667 files in the @code{EXTRA_} variable.
5668
5669 This variable also supports @code{dist_} and @code{nodist_} prefixes.
5670 For instance, @code{nodist_EXTRA_maude_SOURCES} would list extra
5671 sources that may need to be built, but should not be distributed.
5672
5673 @item maude_AR
5674 A static library is created by default by invoking @samp{$(AR)
5675 $(ARFLAGS)} followed by the name of the library and then the objects
5676 being put into the library.  You can override this by setting the
5677 @code{_AR} variable.  This is usually used with C++; some C++
5678 compilers require a special invocation in order to instantiate all the
5679 templates that should go into a library.  For instance, the SGI C++
5680 compiler likes this variable set like so:
5681 @example
5682 libmaude_a_AR = $(CXX) -ar -o
5683 @end example
5684
5685 @item maude_LIBADD
5686 Extra objects can be added to a @emph{library} using the @code{_LIBADD}
5687 variable.  For instance, this should be used for objects determined by
5688 @command{configure} (@pxref{A Library}).
5689
5690 In the case of libtool libraries, @code{maude_LIBADD} can also refer
5691 to other libtool libraries.
5692
5693 @item maude_LDADD
5694 Extra objects (@file{*.$(OBJEXT)}) and libraries (@file{*.a},
5695 @file{*.la}) can be added to a @emph{program} by listing them in the
5696 @code{_LDADD} variable.  For instance, this should be used for objects
5697 determined by @command{configure} (@pxref{Linking}).
5698
5699 @code{_LDADD} and @code{_LIBADD} are inappropriate for passing
5700 program-specific linker flags (except for @option{-l}, @option{-L},
5701 @option{-dlopen} and @option{-dlpreopen}).  Use the @code{_LDFLAGS} variable
5702 for this purpose.
5703
5704 For instance, if your @file{configure.ac} uses @code{AC_PATH_XTRA}, you
5705 could link your program against the X libraries like so:
5706
5707 @example
5708 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
5709 @end example
5710
5711 We recommend that you use @option{-l} and @option{-L} only when
5712 referring to third-party libraries, and give the explicit file names
5713 of any library built by your package.  Doing so will ensure that
5714 @code{maude_DEPENDENCIES} (see below) is correctly defined by default.
5715
5716 @item maude_LDFLAGS
5717 This variable is used to pass extra flags to the link step of a program
5718 or a shared library.  It overrides the @code{AM_LDFLAGS} variable.
5719
5720 @item maude_LIBTOOLFLAGS
5721 This variable is used to pass extra options to @command{libtool}.
5722 It overrides the @code{AM_LIBTOOLFLAGS} variable.
5723 These options are output before @command{libtool}'s @option{--mode=@var{mode}}
5724 option, so they should not be mode-specific options (those belong to
5725 the compiler or linker flags).  @xref{Libtool Flags}.
5726
5727 @item maude_DEPENDENCIES
5728 @itemx EXTRA_maude_DEPENDENCIES
5729 It is also occasionally useful to have a target (program or library)
5730 depend on some other file that is not actually part of that target.
5731 This can be done using the @code{_DEPENDENCIES} variable.  Each
5732 target depends on the contents of such a variable, but no further
5733 interpretation is done.
5734
5735 Since these dependencies are associated to the link rule used to
5736 create the programs they should normally list files used by the link
5737 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la} files
5738 for programs; @file{*.lo} and @file{*.la} files for Libtool libraries;
5739 and @file{*.$(OBJEXT)} files for static libraries.  In rare cases you
5740 may need to add other kinds of files such as linker scripts, but
5741 @emph{listing a source file in @code{_DEPENDENCIES} is wrong}.  If
5742 some source file needs to be built before all the components of a
5743 program are built, consider using the @code{BUILT_SOURCES} variable
5744 (@pxref{Sources}).
5745
5746 If @code{_DEPENDENCIES} is not supplied, it is computed by Automake.
5747 The automatically-assigned value is the contents of @code{_LDADD} or
5748 @code{_LIBADD}, with most configure substitutions, @option{-l}, @option{-L},
5749 @option{-dlopen} and @option{-dlpreopen} options removed.  The configure
5750 substitutions that are left in are only @samp{$(LIBOBJS)} and
5751 @samp{$(ALLOCA)}; these are left because it is known that they will not
5752 cause an invalid value for @code{_DEPENDENCIES} to be generated.
5753
5754 @code{_DEPENDENCIES} is more likely used to perform conditional
5755 compilation using an @code{AC_SUBST} variable that contains a list of
5756 objects.  @xref{Conditional Sources}, and @ref{Conditional Libtool
5757 Sources}.
5758
5759 The @code{EXTRA_*_DEPENDENCIES} variable may be useful for cases where
5760 you merely want to augment the @command{automake}-generated
5761 @code{_DEPENDENCIES} variable rather than replacing it.
5762
5763 @item maude_LINK
5764 You can override the linker on a per-program basis.  By default the
5765 linker is chosen according to the languages used by the program.  For
5766 instance, a program that includes C++ source code would use the C++
5767 compiler to link.  The @code{_LINK} variable must hold the name of a
5768 command that can be passed all the @file{.o} file names and libraries
5769 to link against as arguments.  Note that the name of the underlying
5770 program is @emph{not} passed to @code{_LINK}; typically one uses
5771 @samp{$@@}:
5772
5773 @example
5774 maude_LINK = $(CCLD) -magic -o $@@
5775 @end example
5776
5777 If a @code{_LINK} variable is not supplied, it may still be generated
5778 and used by Automake due to the use of per-target link flags such as
5779 @code{_CFLAGS}, @code{_LDFLAGS} or @code{_LIBTOOLFLAGS}, in cases where
5780 they apply.
5781
5782 @item maude_CCASFLAGS
5783 @itemx maude_CFLAGS
5784 @itemx maude_CPPFLAGS
5785 @itemx maude_CXXFLAGS
5786 @itemx maude_FFLAGS
5787 @itemx maude_GCJFLAGS
5788 @itemx maude_LFLAGS
5789 @itemx maude_OBJCFLAGS
5790 @itemx maude_RFLAGS
5791 @itemx maude_UPCFLAGS
5792 @itemx maude_YFLAGS
5793 @cindex per-target compilation flags, defined
5794 Automake allows you to set compilation flags on a per-program (or
5795 per-library) basis.  A single source file can be included in several
5796 programs, and it will potentially be compiled with different flags for
5797 each program.  This works for any language directly supported by
5798 Automake.  These @dfn{per-target compilation flags} are
5799 @samp{_CCASFLAGS},
5800 @samp{_CFLAGS},
5801 @samp{_CPPFLAGS},
5802 @samp{_CXXFLAGS},
5803 @samp{_FFLAGS},
5804 @samp{_GCJFLAGS},
5805 @samp{_LFLAGS},
5806 @samp{_OBJCFLAGS},
5807 @samp{_RFLAGS},
5808 @samp{_UPCFLAGS}, and
5809 @samp{_YFLAGS}.
5810
5811 When using a per-target compilation flag, Automake will choose a
5812 different name for the intermediate object files.  Ordinarily a file
5813 like @file{sample.c} will be compiled to produce @file{sample.o}.
5814 However, if the program's @code{_CFLAGS} variable is set, then the
5815 object file will be named, for instance, @file{maude-sample.o}.  (See
5816 also @ref{Renamed Objects}.)  The use of per-target compilation flags
5817 with C sources requires that the macro @code{AM_PROG_CC_C_O} be called
5818 from @file{configure.ac}.
5819
5820 In compilations with per-target flags, the ordinary @samp{AM_} form of
5821 the flags variable is @emph{not} automatically included in the
5822 compilation (however, the user form of the variable @emph{is} included).
5823 So for instance, if you want the hypothetical @file{maude} compilations
5824 to also use the value of @code{AM_CFLAGS}, you would need to write:
5825
5826 @example
5827 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
5828 @end example
5829
5830 @xref{Flag Variables Ordering}, for more discussion about the
5831 interaction between user variables, @samp{AM_} shadow variables, and
5832 per-target variables.
5833
5834 @item maude_SHORTNAME
5835 On some platforms the allowable file names are very short.  In order to
5836 support these systems and per-target compilation flags at the same
5837 time, Automake allows you to set a ``short name'' that will influence
5838 how intermediate object files are named.  For instance, in the following
5839 example,
5840
5841 @example
5842 bin_PROGRAMS = maude
5843 maude_CPPFLAGS = -DSOMEFLAG
5844 maude_SHORTNAME = m
5845 maude_SOURCES = sample.c @dots{}
5846 @end example
5847
5848 @noindent
5849 the object file would be named @file{m-sample.o} rather than
5850 @file{maude-sample.o}.
5851
5852 This facility is rarely needed in practice,
5853 and we recommend avoiding it until you find it is required.
5854 @end vtable
5855
5856 @node Default _SOURCES
5857 @section Default @code{_SOURCES}
5858
5859 @vindex _SOURCES
5860 @vindex SOURCES
5861 @cindex @code{_SOURCES}, default
5862 @cindex default @code{_SOURCES}
5863 @vindex AM_DEFAULT_SOURCE_EXT
5864
5865 @code{_SOURCES} variables are used to specify source files of programs
5866 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
5867 libraries (@pxref{A Shared Library}).
5868
5869 When no such variable is specified for a target, Automake will define
5870 one itself.  The default is to compile a single C file whose base name
5871 is the name of the target itself, with any extension replaced by
5872 @code{AM_DEFAULT_SOURCE_EXT}, which defaults to @file{.c}.
5873
5874 For example if you have the following somewhere in your
5875 @file{Makefile.am} with no corresponding @code{libfoo_a_SOURCES}:
5876
5877 @example
5878 lib_LIBRARIES = libfoo.a sub/libc++.a
5879 @end example
5880
5881 @noindent
5882 @file{libfoo.a} will be built using a default source file named
5883 @file{libfoo.c}, and @file{sub/libc++.a} will be built from
5884 @file{sub/libc++.c}.  (In older versions @file{sub/libc++.a}
5885 would be built from @file{sub_libc___a.c}, i.e., the default source
5886 was the canonized name of the target, with @file{.c} appended.
5887 We believe the new behavior is more sensible, but for backward
5888 compatibility @command{automake} will use the old name if a file or a rule
5889 with that name exists and @code{AM_DEFAULT_SOURCE_EXT} is not used.)
5890
5891 @cindex @code{check_PROGRAMS} example
5892 @vindex check_PROGRAMS
5893 Default sources are mainly useful in test suites, when building many
5894 test programs each from a single source.  For instance, in
5895
5896 @example
5897 check_PROGRAMS = test1 test2 test3
5898 AM_DEFAULT_SOURCE_EXT = .cpp
5899 @end example
5900
5901 @noindent
5902 @file{test1}, @file{test2}, and @file{test3} will be built
5903 from @file{test1.cpp}, @file{test2.cpp}, and @file{test3.cpp}.
5904 Without the last line, they will be built from @file{test1.c},
5905 @file{test2.c}, and @file{test3.c}.
5906
5907 @cindex Libtool modules, default source example
5908 @cindex default source, Libtool modules example
5909 Another case where this is convenient is building many Libtool modules
5910 (@file{module@var{n}.la}), each defined in its own file
5911 (@file{module@var{n}.c}).
5912
5913 @example
5914 AM_LDFLAGS = -module
5915 lib_LTLIBRARIES = module1.la module2.la module3.la
5916 @end example
5917
5918 @cindex empty @code{_SOURCES}
5919 @cindex @code{_SOURCES}, empty
5920 Finally, there is one situation where this default source computation
5921 needs to be avoided: when a target should not be built from sources.
5922 We already saw such an example in @ref{true}; this happens when all
5923 the constituents of a target have already been compiled and just need
5924 to be combined using a @code{_LDADD} variable.  Then it is necessary
5925 to define an empty @code{_SOURCES} variable, so that @command{automake}
5926 does not compute a default.
5927
5928 @example
5929 bin_PROGRAMS = target
5930 target_SOURCES =
5931 target_LDADD = libmain.a libmisc.a
5932 @end example
5933
5934 @node LIBOBJS
5935 @section Special handling for @code{LIBOBJS} and @code{ALLOCA}
5936
5937 @cindex @code{LIBOBJS}, example
5938 @cindex @code{ALLOCA}, example
5939 @cindex @code{LIBOBJS}, special handling
5940 @cindex @code{ALLOCA}, special handling
5941 @vindex LTLIBOBJS
5942 @vindex LIBOBJS
5943 @vindex LTALLOCA
5944 @vindex ALLOCA
5945
5946 The @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} variables list object
5947 files that should be compiled into the project to provide an
5948 implementation for functions that are missing or broken on the host
5949 system.  They are substituted by @file{configure}.
5950
5951 @acindex AC_LIBOBJ
5952
5953 These variables are defined by Autoconf macros such as
5954 @code{AC_LIBOBJ}, @code{AC_REPLACE_FUNCS} (@pxref{Generic Functions, ,
5955 Generic Function Checks, autoconf, The Autoconf Manual}), or
5956 @code{AC_FUNC_ALLOCA} (@pxref{Particular Functions, , Particular
5957 Function Checks, autoconf, The Autoconf Manual}).  Many other Autoconf
5958 macros call @code{AC_LIBOBJ} or @code{AC_REPLACE_FUNCS} to
5959 populate @samp{$(LIBOBJS)}.
5960
5961 @acindex AC_LIBSOURCE
5962
5963 Using these variables is very similar to doing conditional compilation
5964 using @code{AC_SUBST} variables, as described in @ref{Conditional
5965 Sources}.  That is, when building a program, @samp{$(LIBOBJS)} and
5966 @samp{$(ALLOCA)} should be added to the associated @samp{*_LDADD}
5967 variable, or to the @samp{*_LIBADD} variable when building a library.
5968 However there is no need to list the corresponding sources in
5969 @samp{EXTRA_*_SOURCES} nor to define @samp{*_DEPENDENCIES}.  Automake
5970 automatically adds @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} to the
5971 dependencies, and it will discover the list of corresponding source
5972 files automatically (by tracing the invocations of the
5973 @code{AC_LIBSOURCE} Autoconf macros).  If you have already defined
5974 @samp{*_DEPENDENCIES} explicitly for an unrelated reason, then you
5975 either need to add these variables manually, or use
5976 @samp{EXTRA_*_DEPENDENCIES} instead of @samp{*_DEPENDENCIES}.
5977
5978 These variables are usually used to build a portability library that
5979 is linked with all the programs of the project.  We now review a
5980 sample setup.  First, @file{configure.ac} contains some checks that
5981 affect either @code{LIBOBJS} or @code{ALLOCA}.
5982
5983 @example
5984 # configure.ac
5985 @dots{}
5986 AC_CONFIG_LIBOBJ_DIR([lib])
5987 @dots{}
5988 AC_FUNC_MALLOC             dnl May add malloc.$(OBJEXT) to LIBOBJS
5989 AC_FUNC_MEMCMP             dnl May add memcmp.$(OBJEXT) to LIBOBJS
5990 AC_REPLACE_FUNCS([strdup]) dnl May add strdup.$(OBJEXT) to LIBOBJS
5991 AC_FUNC_ALLOCA             dnl May add alloca.$(OBJEXT) to ALLOCA
5992 @dots{}
5993 AC_CONFIG_FILES([
5994   lib/Makefile
5995   src/Makefile
5996 ])
5997 AC_OUTPUT
5998 @end example
5999
6000 @acindex AC_CONFIG_LIBOBJ_DIR
6001
6002 The @code{AC_CONFIG_LIBOBJ_DIR} tells Autoconf that the source files
6003 of these object files are to be found in the @file{lib/} directory.
6004 Automake can also use this information, otherwise it expects the
6005 source files are to be in the directory where the @samp{$(LIBOBJS)}
6006 and @samp{$(ALLOCA)} variables are used.
6007
6008 The @file{lib/} directory should therefore contain @file{malloc.c},
6009 @file{memcmp.c}, @file{strdup.c}, @file{alloca.c}.  Here is its
6010 @file{Makefile.am}:
6011
6012 @example
6013 # lib/Makefile.am
6014
6015 noinst_LIBRARIES = libcompat.a
6016 libcompat_a_SOURCES =
6017 libcompat_a_LIBADD = $(LIBOBJS) $(ALLOCA)
6018 @end example
6019
6020 The library can have any name, of course, and anyway it is not going
6021 to be installed: it just holds the replacement versions of the missing
6022 or broken functions so we can later link them in.  Many projects
6023 also include extra functions, specific to the project, in that
6024 library: they are simply added on the @code{_SOURCES} line.
6025
6026 @cindex Empty libraries and @samp{$(LIBOBJS)}
6027 @cindex @samp{$(LIBOBJS)} and empty libraries
6028 There is a small trap here, though: @samp{$(LIBOBJS)} and
6029 @samp{$(ALLOCA)} might be empty, and building an empty library is not
6030 portable.  You should ensure that there is always something to put in
6031 @file{libcompat.a}.  Most projects will also add some utility
6032 functions in that directory, and list them in
6033 @code{libcompat_a_SOURCES}, so in practice @file{libcompat.a} cannot
6034 be empty.
6035
6036 Finally here is how this library could be used from the @file{src/}
6037 directory.
6038
6039 @example
6040 # src/Makefile.am
6041
6042 # Link all programs in this directory with libcompat.a
6043 LDADD = ../lib/libcompat.a
6044
6045 bin_PROGRAMS = tool1 tool2 @dots{}
6046 tool1_SOURCES = @dots{}
6047 tool2_SOURCES = @dots{}
6048 @end example
6049
6050 When option @option{subdir-objects} is not used, as in the above
6051 example, the variables @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} can only
6052 be used in the directory where their sources lie.  E.g., here it would
6053 be wrong to use @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} in
6054 @file{src/Makefile.am}.  However if both @option{subdir-objects} and
6055 @code{AC_CONFIG_LIBOBJ_DIR} are used, it is OK to use these variables
6056 in other directories.  For instance @file{src/Makefile.am} could be
6057 changed as follows.
6058
6059 @example
6060 # src/Makefile.am
6061
6062 AUTOMAKE_OPTIONS = subdir-objects
6063 LDADD = $(LIBOBJS) $(ALLOCA)
6064
6065 bin_PROGRAMS = tool1 tool2 @dots{}
6066 tool1_SOURCES = @dots{}
6067 tool2_SOURCES = @dots{}
6068 @end example
6069
6070 Because @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} contain object
6071 file names that end with @samp{.$(OBJEXT)}, they are not suitable for
6072 Libtool libraries (where the expected object extension is @file{.lo}):
6073 @code{LTLIBOBJS} and @code{LTALLOCA} should be used instead.
6074
6075 @code{LTLIBOBJS} is defined automatically by Autoconf and should not
6076 be defined by hand (as in the past), however at the time of writing
6077 @code{LTALLOCA} still needs to be defined from @code{ALLOCA} manually.
6078 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
6079 autoconf, The Autoconf Manual}.
6080
6081
6082 @node Program Variables
6083 @section Variables used when building a program
6084
6085 Occasionally it is useful to know which @file{Makefile} variables
6086 Automake uses for compilations, and in which order (@pxref{Flag
6087 Variables Ordering}); for instance, you might need to do your own
6088 compilation in some special cases.
6089
6090 Some variables are inherited from Autoconf; these are @code{CC},
6091 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
6092 @code{LIBS}.
6093 @vindex CC
6094 @vindex CFLAGS
6095 @vindex CPPFLAGS
6096 @vindex DEFS
6097 @vindex LDFLAGS
6098 @vindex LIBS
6099
6100 There are some additional variables that Automake defines on its own:
6101
6102 @vtable @code
6103 @item AM_CPPFLAGS
6104 The contents of this variable are passed to every compilation that invokes
6105 the C preprocessor; it is a list of arguments to the preprocessor.  For
6106 instance, @option{-I} and @option{-D} options should be listed here.
6107
6108 Automake already provides some @option{-I} options automatically, in a
6109 separate variable that is also passed to every compilation that invokes
6110 the C preprocessor.  In particular it generates @samp{-I.},
6111 @samp{-I$(srcdir)}, and a @option{-I} pointing to the directory holding
6112 @file{config.h} (if you've used @code{AC_CONFIG_HEADERS} or
6113 @code{AM_CONFIG_HEADER}).  You can disable the default @option{-I}
6114 options using the @option{nostdinc} option.
6115
6116 When a file to be included is generated during the build and not part
6117 of a distribution tarball, its location is under @code{$(builddir)},
6118 not under @code{$(srcdir)}.  This matters especially for packages that
6119 use header files placed in sub-directories and want to allow builds
6120 outside the source tree (@pxref{VPATH Builds}). In that case we
6121 recommend to use a pair of @option{-I} options, such as, e.g.,
6122 @samp{-Isome/subdir -I$(srcdir)/some/subdir} or
6123 @samp{-I$(top_builddir)/some/subdir -I$(top_srcdir)/some/subdir}.
6124 Note that the reference to the build tree should come before the
6125 reference to the source tree, so that accidentally leftover generated
6126 files in the source directory are ignored.
6127
6128 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
6129 per-library) @code{_CPPFLAGS} variable if it is defined.
6130
6131 @item INCLUDES
6132 This does the same job as @code{AM_CPPFLAGS} (or any per-target
6133 @code{_CPPFLAGS} variable if it is used).  It is an older name for the
6134 same functionality.  This variable is deprecated; we suggest using
6135 @code{AM_CPPFLAGS} and per-target @code{_CPPFLAGS} instead.
6136
6137 @item AM_CFLAGS
6138 This is the variable the @file{Makefile.am} author can use to pass
6139 in additional C compiler flags.  It is more fully documented elsewhere.
6140 In some situations, this is not used, in preference to the
6141 per-executable (or per-library) @code{_CFLAGS}.
6142
6143 @item COMPILE
6144 This is the command used to actually compile a C source file.  The
6145 file name is appended to form the complete command line.
6146
6147 @item AM_LDFLAGS
6148 This is the variable the @file{Makefile.am} author can use to pass
6149 in additional linker flags.  In some situations, this is not used, in
6150 preference to the per-executable (or per-library) @code{_LDFLAGS}.
6151
6152 @item LINK
6153 This is the command used to actually link a C program.  It already
6154 includes @samp{-o $@@} and the usual variable references (for instance,
6155 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
6156 and libraries to link in.  This variable is not used when the linker is
6157 overridden with a per-target @code{_LINK} variable or per-target flags
6158 cause Automake to define such a @code{_LINK} variable.
6159 @end vtable
6160
6161
6162 @node Yacc and Lex
6163 @section Yacc and Lex support
6164
6165 Automake has somewhat idiosyncratic support for Yacc and Lex.
6166
6167 Automake assumes that the @file{.c} file generated by @command{yacc}
6168 (or @command{lex}) should be named using the basename of the input
6169 file.  That is, for a yacc source file @file{foo.y}, Automake will
6170 cause the intermediate file to be named @file{foo.c} (as opposed to
6171 @file{y.tab.c}, which is more traditional).
6172
6173 The extension of a yacc source file is used to determine the extension
6174 of the resulting C or C++ source and header files.  Note that header
6175 files are generated only when the @option{-d} Yacc option is used; see
6176 below for more information about this flag, and how to specify it.
6177 Files with the extension @file{.y} will thus be turned into @file{.c}
6178 sources and @file{.h} headers; likewise, @file{.yy} will become
6179 @file{.cc} and @file{.hh}, @file{.y++} will become @file{c++} and
6180 @file{h++}, @file{.yxx} will become @file{.cxx} and @file{.hxx},
6181 and @file{.ypp} will become @file{.cpp} and @file{.hpp}.
6182
6183 Similarly, lex source files can be used to generate C or C++; the
6184 extensions @file{.l}, @file{.ll}, @file{.l++}, @file{.lxx}, and
6185 @file{.lpp} are recognized.
6186
6187 You should never explicitly mention the intermediate (C or C++) file
6188 in any @code{SOURCES} variable; only list the source file.
6189
6190 The intermediate files generated by @command{yacc} (or @command{lex})
6191 will be included in any distribution that is made.  That way the user
6192 doesn't need to have @command{yacc} or @command{lex}.
6193
6194 If a @command{yacc} source file is seen, then your @file{configure.ac} must
6195 define the variable @code{YACC}.  This is most easily done by invoking
6196 the macro @code{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
6197 Program Checks, autoconf, The Autoconf Manual}).
6198
6199 @vindex YFLAGS
6200 @vindex AM_YFLAGS
6201 When @code{yacc} is invoked, it is passed @code{AM_YFLAGS} and
6202 @code{YFLAGS}.  The latter is a user variable and the former is
6203 intended for the @file{Makefile.am} author.
6204
6205 @code{AM_YFLAGS} is usually used to pass the @option{-d} option to
6206 @command{yacc}.  Automake knows what this means and will automatically
6207 adjust its rules to update and distribute the header file built by
6208 @samp{yacc -d}@footnote{Please note that @command{automake} recognizes
6209 @option{-d} in @code{AM_YFLAGS} only if it is not clustered with other
6210 options; for example, it won't be recognized if @code{AM_YFLAGS} is
6211 @option{-dt}, but it will be if @code{AM_YFLAGS} is @option{-d -t} or
6212 @option{-t -d}.}.
6213 What Automake cannot guess, though, is where this
6214 header will be used: it is up to you to ensure the header gets built
6215 before it is first used.  Typically this is necessary in order for
6216 dependency tracking to work when the header is included by another
6217 file.  The common solution is listing the header file in
6218 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
6219
6220 @example
6221 BUILT_SOURCES = parser.h
6222 AM_YFLAGS = -d
6223 bin_PROGRAMS = foo
6224 foo_SOURCES = @dots{} parser.y @dots{}
6225 @end example
6226
6227 If a @command{lex} source file is seen, then your @file{configure.ac}
6228 must define the variable @code{LEX}.  You can use @code{AC_PROG_LEX}
6229 to do this (@pxref{Particular Programs, , Particular Program Checks,
6230 autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
6231 (@pxref{Macros}) is recommended.
6232
6233 @vindex LFLAGS
6234 @vindex AM_LFLAGS
6235 When @command{lex} is invoked, it is passed @code{AM_LFLAGS} and
6236 @code{LFLAGS}.  The latter is a user variable and the former is
6237 intended for the @file{Makefile.am} author.
6238
6239 When @code{AM_MAINTAINER_MODE} (@pxref{maintainer-mode}) is used, the
6240 rebuild rule for distributed Yacc and Lex sources are only used when
6241 @code{maintainer-mode} is enabled, or when the files have been erased.
6242
6243 @cindex @command{ylwrap}
6244 @cindex @command{yacc}, multiple parsers
6245 @cindex Multiple @command{yacc} parsers
6246 @cindex Multiple @command{lex} lexers
6247 @cindex @command{lex}, multiple lexers
6248
6249 When @command{lex} or @command{yacc} sources are used, @code{automake
6250 -i} automatically installs an auxiliary program called
6251 @command{ylwrap} in your package (@pxref{Auxiliary Programs}).  This
6252 program is used by the build rules to rename the output of these
6253 tools, and makes it possible to include multiple @command{yacc} (or
6254 @command{lex}) source files in a single directory.  (This is necessary
6255 because yacc's output file name is fixed, and a parallel make could
6256 conceivably invoke more than one instance of @command{yacc}
6257 simultaneously.)
6258
6259 For @command{yacc}, simply managing locking is insufficient.  The output of
6260 @command{yacc} always uses the same symbol names internally, so it isn't
6261 possible to link two @command{yacc} parsers into the same executable.
6262
6263 We recommend using the following renaming hack used in @command{gdb}:
6264 @example
6265 #define yymaxdepth c_maxdepth
6266 #define yyparse c_parse
6267 #define yylex   c_lex
6268 #define yyerror c_error
6269 #define yylval  c_lval
6270 #define yychar  c_char
6271 #define yydebug c_debug
6272 #define yypact  c_pact
6273 #define yyr1    c_r1
6274 #define yyr2    c_r2
6275 #define yydef   c_def
6276 #define yychk   c_chk
6277 #define yypgo   c_pgo
6278 #define yyact   c_act
6279 #define yyexca  c_exca
6280 #define yyerrflag c_errflag
6281 #define yynerrs c_nerrs
6282 #define yyps    c_ps
6283 #define yypv    c_pv
6284 #define yys     c_s
6285 #define yy_yys  c_yys
6286 #define yystate c_state
6287 #define yytmp   c_tmp
6288 #define yyv     c_v
6289 #define yy_yyv  c_yyv
6290 #define yyval   c_val
6291 #define yylloc  c_lloc
6292 #define yyreds  c_reds
6293 #define yytoks  c_toks
6294 #define yylhs   c_yylhs
6295 #define yylen   c_yylen
6296 #define yydefred c_yydefred
6297 #define yydgoto  c_yydgoto
6298 #define yysindex c_yysindex
6299 #define yyrindex c_yyrindex
6300 #define yygindex c_yygindex
6301 #define yytable  c_yytable
6302 #define yycheck  c_yycheck
6303 #define yyname   c_yyname
6304 #define yyrule   c_yyrule
6305 @end example
6306
6307 For each define, replace the @samp{c_} prefix with whatever you like.
6308 These defines work for @command{bison}, @command{byacc}, and
6309 traditional @code{yacc}s.  If you find a parser generator that uses a
6310 symbol not covered here, please report the new name so it can be added
6311 to the list.
6312
6313
6314 @node C++ Support
6315 @section C++ Support
6316
6317 @cindex C++ support
6318 @cindex Support for C++
6319
6320 Automake includes full support for C++.
6321
6322 Any package including C++ code must define the output variable
6323 @code{CXX} in @file{configure.ac}; the simplest way to do this is to use
6324 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
6325 Program Checks, autoconf, The Autoconf Manual}).
6326
6327 A few additional variables are defined when a C++ source file is seen:
6328
6329 @vtable @code
6330 @item CXX
6331 The name of the C++ compiler.
6332
6333 @item CXXFLAGS
6334 Any flags to pass to the C++ compiler.
6335
6336 @item AM_CXXFLAGS
6337 The maintainer's variant of @code{CXXFLAGS}.
6338
6339 @item CXXCOMPILE
6340 The command used to actually compile a C++ source file.  The file name
6341 is appended to form the complete command line.
6342
6343 @item CXXLINK
6344 The command used to actually link a C++ program.
6345 @end vtable
6346
6347
6348 @node Objective C Support
6349 @section Objective C Support
6350
6351 @cindex Objective C support
6352 @cindex Support for Objective C
6353
6354 Automake includes some support for Objective C.
6355
6356 Any package including Objective C code must define the output variable
6357 @code{OBJC} in @file{configure.ac}; the simplest way to do this is to use
6358 the @code{AC_PROG_OBJC} macro (@pxref{Particular Programs, , Particular
6359 Program Checks, autoconf, The Autoconf Manual}).
6360
6361 A few additional variables are defined when an Objective C source file
6362 is seen:
6363
6364 @vtable @code
6365 @item OBJC
6366 The name of the Objective C compiler.
6367
6368 @item OBJCFLAGS
6369 Any flags to pass to the Objective C compiler.
6370
6371 @item AM_OBJCFLAGS
6372 The maintainer's variant of @code{OBJCFLAGS}.
6373
6374 @item OBJCCOMPILE
6375 The command used to actually compile an Objective C source file.  The
6376 file name is appended to form the complete command line.
6377
6378 @item OBJCLINK
6379 The command used to actually link an Objective C program.
6380 @end vtable
6381
6382
6383 @node Unified Parallel C Support
6384 @section Unified Parallel C Support
6385
6386 @cindex Unified Parallel C support
6387 @cindex Support for Unified Parallel C
6388
6389 Automake includes some support for Unified Parallel C.
6390
6391 Any package including Unified Parallel C code must define the output
6392 variable @code{UPC} in @file{configure.ac}; the simplest way to do
6393 this is to use the @code{AM_PROG_UPC} macro (@pxref{Public Macros}).
6394
6395 A few additional variables are defined when a Unified Parallel C
6396 source file is seen:
6397
6398 @vtable @code
6399 @item UPC
6400 The name of the Unified Parallel C compiler.
6401
6402 @item UPCFLAGS
6403 Any flags to pass to the Unified Parallel C compiler.
6404
6405 @item AM_UPCFLAGS
6406 The maintainer's variant of @code{UPCFLAGS}.
6407
6408 @item UPCCOMPILE
6409 The command used to actually compile a Unified Parallel C source file.
6410 The file name is appended to form the complete command line.
6411
6412 @item UPCLINK
6413 The command used to actually link a Unified Parallel C program.
6414 @end vtable
6415
6416
6417 @node Assembly Support
6418 @section Assembly Support
6419
6420 Automake includes some support for assembly code.  There are two forms
6421 of assembler files: normal (@file{*.s}) and preprocessed by @code{CPP}
6422 (@file{*.S} or @file{*.sx}).
6423
6424 @vindex CCAS
6425 @vindex CCASFLAGS
6426 @vindex CPPFLAGS
6427 @vindex AM_CCASFLAGS
6428 @vindex AM_CPPFLAGS
6429 The variable @code{CCAS} holds the name of the compiler used to build
6430 assembly code.  This compiler must work a bit like a C compiler; in
6431 particular it must accept @option{-c} and @option{-o}.  The values of
6432 @code{CCASFLAGS} and @code{AM_CCASFLAGS} (or its per-target
6433 definition) is passed to the compilation.  For preprocessed files,
6434 @code{DEFS}, @code{DEFAULT_INCLUDES}, @code{INCLUDES}, @code{CPPFLAGS}
6435 and @code{AM_CPPFLAGS} are also used.
6436
6437 The autoconf macro @code{AM_PROG_AS} will define @code{CCAS} and
6438 @code{CCASFLAGS} for you (unless they are already set, it simply sets
6439 @code{CCAS} to the C compiler and @code{CCASFLAGS} to the C compiler
6440 flags), but you are free to define these variables by other means.
6441
6442 Only the suffixes @file{.s}, @file{.S}, and @file{.sx} are recognized by
6443 @command{automake} as being files containing assembly code.
6444
6445
6446 @node Fortran 77 Support
6447 @comment  node-name,  next,  previous,  up
6448 @section Fortran 77 Support
6449
6450 @cindex Fortran 77 support
6451 @cindex Support for Fortran 77
6452
6453 Automake includes full support for Fortran 77.
6454
6455 Any package including Fortran 77 code must define the output variable
6456 @code{F77} in @file{configure.ac}; the simplest way to do this is to use
6457 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
6458 Program Checks, autoconf, The Autoconf Manual}).
6459
6460 A few additional variables are defined when a Fortran 77 source file is
6461 seen:
6462
6463 @vtable @code
6464
6465 @item F77
6466 The name of the Fortran 77 compiler.
6467
6468 @item FFLAGS
6469 Any flags to pass to the Fortran 77 compiler.
6470
6471 @item AM_FFLAGS
6472 The maintainer's variant of @code{FFLAGS}.
6473
6474 @item RFLAGS
6475 Any flags to pass to the Ratfor compiler.
6476
6477 @item AM_RFLAGS
6478 The maintainer's variant of @code{RFLAGS}.
6479
6480 @item F77COMPILE
6481 The command used to actually compile a Fortran 77 source file.  The file
6482 name is appended to form the complete command line.
6483
6484 @item FLINK
6485 The command used to actually link a pure Fortran 77 program or shared
6486 library.
6487
6488 @end vtable
6489
6490 Automake can handle preprocessing Fortran 77 and Ratfor source files in
6491 addition to compiling them@footnote{Much, if not most, of the
6492 information in the following sections pertaining to preprocessing
6493 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
6494 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
6495 also contains some support for creating programs and shared libraries
6496 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
6497 Fortran 77 With C and C++}).
6498
6499 These issues are covered in the following sections.
6500
6501 @menu
6502 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
6503 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
6504 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
6505 @end menu
6506
6507
6508 @node Preprocessing Fortran 77
6509 @comment  node-name,  next,  previous,  up
6510 @subsection Preprocessing Fortran 77
6511
6512 @cindex Preprocessing Fortran 77
6513 @cindex Fortran 77, Preprocessing
6514 @cindex Ratfor programs
6515
6516 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
6517 rule runs just the preprocessor to convert a preprocessable Fortran 77
6518 or Ratfor source file into a strict Fortran 77 source file.  The precise
6519 command used is as follows:
6520
6521 @table @file
6522
6523 @item .F
6524 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6525 $(AM_FFLAGS) $(FFLAGS)}
6526
6527 @item .r
6528 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6529
6530 @end table
6531
6532
6533 @node Compiling Fortran 77 Files
6534 @comment  node-name,  next,  previous,  up
6535 @subsection Compiling Fortran 77 Files
6536
6537 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
6538 @file{N.r} by running the Fortran 77 compiler.  The precise command used
6539 is as follows:
6540
6541 @table @file
6542
6543 @item .f
6544 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
6545
6546 @item .F
6547 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6548 $(AM_FFLAGS) $(FFLAGS)}
6549
6550 @item .r
6551 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6552
6553 @end table
6554
6555
6556 @node Mixing Fortran 77 With C and C++
6557 @comment  node-name,  next,  previous,  up
6558 @subsection Mixing Fortran 77 With C and C++
6559
6560 @cindex Fortran 77, mixing with C and C++
6561 @cindex Mixing Fortran 77 with C and C++
6562 @cindex Linking Fortran 77 with C and C++
6563 @cindex cfortran
6564 @cindex Mixing Fortran 77 with C and/or C++
6565
6566 Automake currently provides @emph{limited} support for creating programs
6567 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
6568 However, there are many other issues related to mixing Fortran 77 with
6569 other languages that are @emph{not} (currently) handled by Automake, but
6570 that are handled by other packages@footnote{For example,
6571 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
6572 addresses all of these inter-language issues, and runs under nearly all
6573 Fortran 77, C and C++ compilers on nearly all platforms.  However,
6574 @command{cfortran} is not yet Free Software, but it will be in the next
6575 major release.}.
6576
6577 Automake can help in two ways:
6578
6579 @enumerate
6580 @item
6581 Automatic selection of the linker depending on which combinations of
6582 source code.
6583
6584 @item
6585 Automatic selection of the appropriate linker flags (e.g., @option{-L} and
6586 @option{-l}) to pass to the automatically selected linker in order to link
6587 in the appropriate Fortran 77 intrinsic and run-time libraries.
6588
6589 @cindex @code{FLIBS}, defined
6590 @vindex FLIBS
6591 These extra Fortran 77 linker flags are supplied in the output variable
6592 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro.
6593 @xref{Fortran Compiler, , Fortran Compiler Characteristics, autoconf,
6594 The Autoconf Manual}.
6595 @end enumerate
6596
6597 If Automake detects that a program or shared library (as mentioned in
6598 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
6599 code that is a mixture of Fortran 77 and C and/or C++, then it requires
6600 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
6601 @file{configure.ac}, and that either @code{$(FLIBS)}
6602 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
6603 (for shared libraries) variables.  It is the responsibility of the
6604 person writing the @file{Makefile.am} to make sure that @samp{$(FLIBS)}
6605 appears in the appropriate @code{_LDADD} or
6606 @code{_LIBADD} variable.
6607
6608 @cindex Mixed language example
6609 @cindex Example, mixed language
6610
6611 For example, consider the following @file{Makefile.am}:
6612
6613 @example
6614 bin_PROGRAMS = foo
6615 foo_SOURCES  = main.cc foo.f
6616 foo_LDADD    = libfoo.la $(FLIBS)
6617
6618 pkglib_LTLIBRARIES = libfoo.la
6619 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
6620 libfoo_la_LIBADD   = $(FLIBS)
6621 @end example
6622
6623 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
6624 is mentioned in @file{configure.ac}.  Also, if @samp{$(FLIBS)} hadn't
6625 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
6626 Automake would have issued a warning.
6627
6628 @menu
6629 * How the Linker is Chosen::    Automatic linker selection
6630 @end menu
6631
6632 @node How the Linker is Chosen
6633 @comment  node-name,  next,  previous,  up
6634 @subsubsection How the Linker is Chosen
6635
6636 @cindex Automatic linker selection
6637 @cindex Selecting the linker automatically
6638
6639 When a program or library mixes several languages, Automake choose the
6640 linker according to the following priorities.  (The names in
6641 parentheses are the variables containing the link command.)
6642
6643 @enumerate
6644 @item
6645 @vindex GCJLINK
6646 Native Java (@code{GCJLINK})
6647 @item
6648 @vindex CXXLINK
6649 C++ (@code{CXXLINK})
6650 @item
6651 @vindex F77LINK
6652 Fortran 77 (@code{F77LINK})
6653 @item
6654 @vindex FCLINK
6655 Fortran (@code{FCLINK})
6656 @item
6657 @vindex OBJCLINK
6658 Objective C (@code{OBJCLINK})
6659 @item
6660 @vindex UPCLINK
6661 Unified Parallel C (@code{UPCLINK})
6662 @item
6663 @vindex LINK
6664 C (@code{LINK})
6665 @end enumerate
6666
6667 For example, if Fortran 77, C and C++ source code is compiled
6668 into a program, then the C++ linker will be used.  In this case, if the
6669 C or Fortran 77 linkers required any special libraries that weren't
6670 included by the C++ linker, then they must be manually added to an
6671 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
6672 @file{Makefile.am}.
6673
6674 Automake only looks at the file names listed in @file{_SOURCES}
6675 variables to choose the linker, and defaults to the C linker.
6676 Sometimes this is inconvenient because you are linking against a
6677 library written in another language and would like to set the linker
6678 more appropriately.  @xref{Libtool Convenience Libraries}, for a
6679 trick with @code{nodist_EXTRA_@dots{}_SOURCES}.
6680
6681 A per-target @code{_LINK} variable will override the above selection.
6682 Per-target link flags will cause Automake to write a per-target
6683 @code{_LINK} variable according to the language chosen as above.
6684
6685
6686 @node Fortran 9x Support
6687 @comment  node-name,  next,  previous,  up
6688 @section Fortran 9x Support
6689
6690 @cindex Fortran 9x support
6691 @cindex Support for Fortran 9x
6692
6693 Automake includes support for Fortran 9x.
6694
6695 Any package including Fortran 9x code must define the output variable
6696 @code{FC} in @file{configure.ac}; the simplest way to do this is to use
6697 the @code{AC_PROG_FC} macro (@pxref{Particular Programs, , Particular
6698 Program Checks, autoconf, The Autoconf Manual}).
6699
6700 A few additional variables are defined when a Fortran 9x source file is
6701 seen:
6702
6703 @vtable @code
6704
6705 @item FC
6706 The name of the Fortran 9x compiler.
6707
6708 @item FCFLAGS
6709 Any flags to pass to the Fortran 9x compiler.
6710
6711 @item AM_FCFLAGS
6712 The maintainer's variant of @code{FCFLAGS}.
6713
6714 @item FCCOMPILE
6715 The command used to actually compile a Fortran 9x source file.  The file
6716 name is appended to form the complete command line.
6717
6718 @item FCLINK
6719 The command used to actually link a pure Fortran 9x program or shared
6720 library.
6721
6722 @end vtable
6723
6724 @menu
6725 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
6726 @end menu
6727
6728 @node Compiling Fortran 9x Files
6729 @comment  node-name,  next,  previous,  up
6730 @subsection Compiling Fortran 9x Files
6731
6732 @file{@var{file}.o} is made automatically from @file{@var{file}.f90},
6733 @file{@var{file}.f95}, @file{@var{file}.f03}, or @file{@var{file}.f08}
6734 by running the Fortran 9x compiler.  The precise command used
6735 is as follows:
6736
6737 @table @file
6738
6739 @item .f90
6740 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f90) $<}
6741
6742 @item .f95
6743 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f95) $<}
6744
6745 @item .f03
6746 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f03) $<}
6747
6748 @item .f08
6749 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f08) $<}
6750
6751 @end table
6752
6753 @node Java Support with gcj
6754 @comment  node-name,  next,  previous,  up
6755 @section Compiling Java sources using gcj
6756
6757 @cindex Java support with gcj
6758 @cindex Support for Java with gcj
6759 @cindex Java to native code, compilation
6760 @cindex Compilation of Java to native code
6761
6762 Automake includes support for natively compiled Java, using @command{gcj},
6763 the Java front end to the GNU Compiler Collection (rudimentary support
6764 for compiling Java to bytecode using the @command{javac} compiler is
6765 also present, @emph{albeit deprecated}; @pxref{Java}).
6766
6767 Any package including Java code to be compiled must define the output
6768 variable @code{GCJ} in @file{configure.ac}; the variable @code{GCJFLAGS}
6769 must also be defined somehow (either in @file{configure.ac} or
6770 @file{Makefile.am}).  The simplest way to do this is to use the
6771 @code{AM_PROG_GCJ} macro.
6772
6773 @vindex GCJFLAGS
6774
6775 By default, programs including Java source files are linked with
6776 @command{gcj}.
6777
6778 As always, the contents of @code{AM_GCJFLAGS} are passed to every
6779 compilation invoking @command{gcj} (in its role as an ahead-of-time
6780 compiler, when invoking it to create @file{.class} files,
6781 @code{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
6782 options to @command{gcj} from @file{Makefile.am}, this variable, and not
6783 the user variable @code{GCJFLAGS}, should be used.
6784
6785 @vindex AM_GCJFLAGS
6786
6787 @command{gcj} can be used to compile @file{.java}, @file{.class},
6788 @file{.zip}, or @file{.jar} files.
6789
6790 When linking, @command{gcj} requires that the main class be specified
6791 using the @option{--main=} option.  The easiest way to do this is to use
6792 the @code{_LDFLAGS} variable for the program.
6793
6794
6795 @node Vala Support
6796 @comment  node-name,  next,  previous,  up
6797 @section Vala Support
6798
6799 @cindex Vala Support
6800 @cindex Support for Vala
6801
6802 Automake provides initial support for Vala
6803 (@uref{http://www.vala-project.org/}).
6804 This requires valac version 0.7.0 or later, and currently requires
6805 the user to use GNU @command{make}.
6806
6807 @example
6808 foo_SOURCES = foo.vala bar.vala zardoc.c
6809 @end example
6810
6811 Any @file{.vala} file listed in a @code{_SOURCES} variable will be
6812 compiled into C code by the Vala compiler. The generated @file{.c} files are
6813 distributed. The end user does not need to have a Vala compiler installed.
6814
6815 Automake ships with an Autoconf macro called @code{AM_PROG_VALAC}
6816 that will locate the Vala compiler and optionally check its version
6817 number.
6818
6819 @defmac AM_PROG_VALAC (@ovar{minimum-version})
6820 Try to find a Vala compiler in @env{PATH}. If it is found, the variable
6821 @code{VALAC} is set. Optionally a minimum release number of the compiler
6822 can be requested:
6823
6824 @example
6825 AM_PROG_VALAC([0.7.0])
6826 @end example
6827 @end defmac
6828
6829 There are a few variables that are used when compiling Vala sources:
6830
6831 @vtable @code
6832 @item VALAC
6833 Path to the Vala compiler.
6834
6835 @item VALAFLAGS
6836 Additional arguments for the Vala compiler.
6837
6838 @item AM_VALAFLAGS
6839 The maintainer's variant of @code{VALAFLAGS}.
6840
6841 @example
6842 lib_LTLIBRARIES = libfoo.la
6843 libfoo_la_SOURCES = foo.vala
6844 @end example
6845 @end vtable
6846
6847 Note that currently, you cannot use per-target @code{*_VALAFLAGS}
6848 (@pxref{Renamed Objects}) to produce different C files from one Vala
6849 source file.
6850
6851
6852 @node Support for Other Languages
6853 @comment  node-name,  next,  previous,  up
6854 @section Support for Other Languages
6855
6856 Automake currently only includes full support for C, C++ (@pxref{C++
6857 Support}), Objective C (@pxref{Objective C Support}), Fortran 77
6858 (@pxref{Fortran 77 Support}), Fortran 9x (@pxref{Fortran 9x Support}),
6859 and Java (@pxref{Java Support with gcj}).  There is only rudimentary
6860 support for other languages, support for which will be improved based
6861 on user demand.
6862
6863 Some limited support for adding your own languages is available via the
6864 suffix rule handling (@pxref{Suffixes}).
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 Tracking
6892 Evolution, , Dependency Tracking Evolution, automake-history, Brief History
6893 of Automake}) taught us that it is not reliable to generate dependencies
6894 only on the maintainer's system, as configurations vary too much.  So
6895 instead Automake implements dependency tracking at build 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 Sometimes maintainers like to write an explicit link rule for their
6957 program.  Without executable extension support, this is easy---you
6958 simply write a rule whose target is the name of the program.  However,
6959 when executable extension support is enabled, you must instead add the
6960 @samp{$(EXEEXT)} suffix.
6961
6962 This might be a nuisance for maintainers who know their package will
6963 never run on a platform that has
6964 executable extensions.  For those maintainers, the @option{no-exeext}
6965 option (@pxref{Options}) will disable this feature.  This works in a
6966 fairly ugly way; if @option{no-exeext} is seen, then the presence of a
6967 rule for a target named @code{foo} in @file{Makefile.am} will override
6968 an @command{automake}-generated rule for @samp{foo$(EXEEXT)}.  Without
6969 the @option{no-exeext} option, this use will give a diagnostic.
6970
6971
6972 @node Other Objects
6973 @chapter Other Derived Objects
6974
6975 Automake can handle derived objects that are not C programs.  Sometimes
6976 the support for actually building such objects must be explicitly
6977 supplied, but Automake will still automatically handle installation and
6978 distribution.
6979
6980 @menu
6981 * Scripts::                     Executable scripts
6982 * Headers::                     Header files
6983 * Data::                        Architecture-independent data files
6984 * Sources::                     Derived sources
6985 @end menu
6986
6987
6988 @node Scripts
6989 @section Executable Scripts
6990
6991 @cindex @code{_SCRIPTS} primary, defined
6992 @cindex @code{SCRIPTS} primary, defined
6993 @cindex Primary variable, @code{SCRIPTS}
6994 @vindex _SCRIPTS
6995 @cindex Installing scripts
6996
6997 It is possible to define and install programs that are scripts.  Such
6998 programs are listed using the @code{SCRIPTS} primary name.  When the
6999 script is distributed in its final, installable form, the
7000 @file{Makefile} usually looks as follows:
7001 @vindex SCRIPTS
7002
7003 @example
7004 # Install my_script in $(bindir) and distribute it.
7005 dist_bin_SCRIPTS = my_script
7006 @end example
7007
7008 Scripts are not distributed by default; as we have just seen, those
7009 that should be distributed can be specified using a @code{dist_}
7010 prefix as with other primaries.
7011
7012 @cindex @code{SCRIPTS}, installation directories
7013 @vindex bin_SCRIPTS
7014 @vindex sbin_SCRIPTS
7015 @vindex libexec_SCRIPTS
7016 @vindex pkgdata_SCRIPTS
7017 @vindex pkglibexec_SCRIPTS
7018 @vindex noinst_SCRIPTS
7019 @vindex check_SCRIPTS
7020
7021 Scripts can be installed in @code{bindir}, @code{sbindir},
7022 @code{libexecdir}, @code{pkglibexecdir}, or @code{pkgdatadir}.
7023
7024 Scripts that need not be installed can be listed in
7025 @code{noinst_SCRIPTS}, and among them, those which are needed only by
7026 @samp{make check} should go in @code{check_SCRIPTS}.
7027
7028 When a script needs to be built, the @file{Makefile.am} should include
7029 the appropriate rules.  For instance the @command{automake} program
7030 itself is a Perl script that is generated from @file{automake.in}.
7031 Here is how this is handled:
7032
7033 @example
7034 bin_SCRIPTS = automake
7035 CLEANFILES = $(bin_SCRIPTS)
7036 EXTRA_DIST = automake.in
7037
7038 do_subst = sed -e 's,[@@]datadir[@@],$(datadir),g' \
7039             -e 's,[@@]PERL[@@],$(PERL),g' \
7040             -e 's,[@@]PACKAGE[@@],$(PACKAGE),g' \
7041             -e 's,[@@]VERSION[@@],$(VERSION),g' \
7042             @dots{}
7043
7044 automake: automake.in Makefile
7045         $(do_subst) < $(srcdir)/automake.in > automake
7046         chmod +x automake
7047 @end example
7048
7049 Such scripts for which a build rule has been supplied need to be
7050 deleted explicitly using @code{CLEANFILES} (@pxref{Clean}), and their
7051 sources have to be distributed, usually with @code{EXTRA_DIST}
7052 (@pxref{Basics of Distribution}).
7053
7054 Another common way to build scripts is to process them from
7055 @file{configure} with @code{AC_CONFIG_FILES}.  In this situation
7056 Automake knows which files should be cleaned and distributed, and what
7057 the rebuild rules should look like.
7058
7059 For instance if @file{configure.ac} contains
7060
7061 @example
7062 AC_CONFIG_FILES([src/my_script], [chmod +x src/my_script])
7063 @end example
7064
7065 @noindent
7066 to build @file{src/my_script} from @file{src/my_script.in}, then a
7067 @file{src/Makefile.am} to install this script in @code{$(bindir)} can
7068 be as simple as
7069
7070 @example
7071 bin_SCRIPTS = my_script
7072 CLEANFILES = $(bin_SCRIPTS)
7073 @end example
7074
7075 @noindent
7076 There is no need for @code{EXTRA_DIST} or any build rule: Automake
7077 infers them from @code{AC_CONFIG_FILES} (@pxref{Requirements}).
7078 @code{CLEANFILES} is still useful, because by default Automake will
7079 clean targets of @code{AC_CONFIG_FILES} in @code{distclean}, not
7080 @code{clean}.
7081
7082 Although this looks simpler, building scripts this way has one
7083 drawback: directory variables such as @code{$(datadir)} are not fully
7084 expanded and may refer to other directory variables.
7085
7086 @node Headers
7087 @section Header files
7088
7089 @cindex @code{_HEADERS} primary, defined
7090 @cindex @code{HEADERS} primary, defined
7091 @cindex Primary variable, @code{HEADERS}
7092 @vindex _HEADERS
7093 @vindex noinst_HEADERS
7094 @cindex @code{HEADERS}, installation directories
7095 @cindex Installing headers
7096 @vindex include_HEADERS
7097 @vindex oldinclude_HEADERS
7098 @vindex pkginclude_HEADERS
7099
7100
7101 Header files that must be installed are specified by the
7102 @code{HEADERS} family of variables.  Headers can be installed in
7103 @code{includedir}, @code{oldincludedir}, @code{pkgincludedir} or any
7104 other directory you may have defined (@pxref{Uniform}).  For instance,
7105
7106 @example
7107 include_HEADERS = foo.h bar/bar.h
7108 @end example
7109
7110 @noindent
7111 will install the two files as @file{$(includedir)/foo.h} and
7112 @file{$(includedir)/bar.h}.
7113
7114 The @code{nobase_} prefix is also supported,
7115
7116 @example
7117 nobase_include_HEADERS = foo.h bar/bar.h
7118 @end example
7119
7120 @noindent
7121 will install the two files as @file{$(includedir)/foo.h} and
7122 @file{$(includedir)/bar/bar.h} (@pxref{Alternative}).
7123
7124 @vindex noinst_HEADERS
7125 Usually, only header files that accompany installed libraries need to
7126 be installed.  Headers used by programs or convenience libraries are
7127 not installed.  The @code{noinst_HEADERS} variable can be used for
7128 such headers.  However when the header actually belongs to a single
7129 convenience library or program, we recommend listing it in the
7130 program's or library's @code{_SOURCES} variable (@pxref{Program
7131 Sources}) instead of in @code{noinst_HEADERS}.  This is clearer for
7132 the @file{Makefile.am} reader.  @code{noinst_HEADERS} would be the
7133 right variable to use in a directory containing only headers and no
7134 associated library or program.
7135
7136 All header files must be listed somewhere; in a @code{_SOURCES}
7137 variable or in a @code{_HEADERS} variable.  Missing ones will not
7138 appear in the distribution.
7139
7140 For header files that are built and must not be distributed, use the
7141 @code{nodist_} prefix as in @code{nodist_include_HEADERS} or
7142 @code{nodist_prog_SOURCES}.  If these generated headers are needed
7143 during the build, you must also ensure they exist before they are
7144 used (@pxref{Sources}).
7145
7146
7147 @node Data
7148 @section Architecture-independent data files
7149
7150 @cindex @code{_DATA} primary, defined
7151 @cindex @code{DATA} primary, defined
7152 @cindex Primary variable, @code{DATA}
7153 @vindex _DATA
7154
7155 Automake supports the installation of miscellaneous data files using the
7156 @code{DATA} family of variables.
7157 @vindex DATA
7158
7159 @vindex data_DATA
7160 @vindex sysconf_DATA
7161 @vindex sharedstate_DATA
7162 @vindex localstate_DATA
7163 @vindex pkgdata_DATA
7164
7165 Such data can be installed in the directories @code{datadir},
7166 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
7167 @code{pkgdatadir}.
7168
7169 By default, data files are @emph{not} included in a distribution.  Of
7170 course, you can use the @code{dist_} prefix to change this on a
7171 per-variable basis.
7172
7173 Here is how Automake declares its auxiliary data files:
7174
7175 @example
7176 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
7177 @end example
7178
7179
7180 @node Sources
7181 @section Built Sources
7182
7183 Because Automake's automatic dependency tracking works as a side-effect
7184 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
7185 target should not be compiled before its dependencies are made, but
7186 these dependencies are unknown until the target is first compiled.
7187
7188 Ordinarily this is not a problem, because dependencies are distributed
7189 sources: they preexist and do not need to be built.  Suppose that
7190 @file{foo.c} includes @file{foo.h}.  When it first compiles
7191 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
7192 @file{foo.c}.  As a side-effect of this compilation @command{depcomp}
7193 records the @file{foo.h} dependency so that following invocations of
7194 @command{make} will honor it.  In these conditions, it's clear there is
7195 no problem: either @file{foo.o} doesn't exist and has to be built
7196 (regardless of the dependencies), or accurate dependencies exist and
7197 they can be used to decide whether @file{foo.o} should be rebuilt.
7198
7199 It's a different story if @file{foo.h} doesn't exist by the first
7200 @command{make} run.  For instance, there might be a rule to build
7201 @file{foo.h}.  This time @file{file.o}'s build will fail because the
7202 compiler can't find @file{foo.h}.  @command{make} failed to trigger the
7203 rule to build @file{foo.h} first by lack of dependency information.
7204
7205 @vindex BUILT_SOURCES
7206 @cindex @code{BUILT_SOURCES}, defined
7207
7208 The @code{BUILT_SOURCES} variable is a workaround for this problem.  A
7209 source file listed in @code{BUILT_SOURCES} is made on @samp{make all}
7210 or @samp{make check} (or even @samp{make install}) before other
7211 targets are processed.  However, such a source file is not
7212 @emph{compiled} unless explicitly requested by mentioning it in some
7213 other @code{_SOURCES} variable.
7214
7215 So, to conclude our introductory example, we could use
7216 @samp{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
7217 any other target (including @file{foo.o}) during @samp{make all} or
7218 @samp{make check}.
7219
7220 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
7221 must be created early in the build process can be listed in this
7222 variable.  Moreover, all built sources do not necessarily have to be
7223 listed in @code{BUILT_SOURCES}.  For instance, a generated @file{.c} file
7224 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
7225 another source), because it's a known dependency of the associated
7226 object.
7227
7228 It might be important to emphasize that @code{BUILT_SOURCES} is
7229 honored only by @samp{make all}, @samp{make check} and @samp{make
7230 install}.  This means you cannot build a specific target (e.g.,
7231 @samp{make foo}) in a clean tree if it depends on a built source.
7232 However it will succeed if you have run @samp{make all} earlier,
7233 because accurate dependencies are already available.
7234
7235 The next section illustrates and discusses the handling of built sources
7236 on a toy example.
7237
7238 @menu
7239 * Built Sources Example::       Several ways to handle built sources.
7240 @end menu
7241
7242 @node Built Sources Example
7243 @subsection Built Sources Example
7244
7245 Suppose that @file{foo.c} includes @file{bindir.h}, which is
7246 installation-dependent and not distributed: it needs to be built.  Here
7247 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
7248 value of the @command{make} variable @code{bindir} (inherited from
7249 @file{configure}).
7250
7251 We suggest several implementations below.  It's not meant to be an
7252 exhaustive listing of all ways to handle built sources, but it will give
7253 you a few ideas if you encounter this issue.
7254
7255 @subsubheading First Try
7256
7257 This first implementation will illustrate the bootstrap issue mentioned
7258 in the previous section (@pxref{Sources}).
7259
7260 Here is a tentative @file{Makefile.am}.
7261
7262 @example
7263 # This won't work.
7264 bin_PROGRAMS = foo
7265 foo_SOURCES = foo.c
7266 nodist_foo_SOURCES = bindir.h
7267 CLEANFILES = bindir.h
7268 bindir.h: Makefile
7269         echo '#define bindir "$(bindir)"' >$@@
7270 @end example
7271
7272 This setup doesn't work, because Automake doesn't know that @file{foo.c}
7273 includes @file{bindir.h}.  Remember, automatic dependency tracking works
7274 as a side-effect of compilation, so the dependencies of @file{foo.o} will
7275 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
7276 The symptom is as follows.
7277
7278 @example
7279 % make
7280 source='foo.c' object='foo.o' libtool=no \
7281 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7282 depmode=gcc /bin/sh ./depcomp \
7283 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7284 foo.c:2: bindir.h: No such file or directory
7285 make: *** [foo.o] Error 1
7286 @end example
7287
7288 In this example @file{bindir.h} is not distributed nor installed, and
7289 it is not even being built on-time.  One may wonder if the
7290 @samp{nodist_foo_SOURCES = bindir.h} line has any use at all.  This
7291 line simply states that @file{bindir.h} is a source of @code{foo}, so
7292 for instance, it should be inspected while generating tags
7293 (@pxref{Tags}).  In other words, it does not help our present problem,
7294 and the build would fail identically without it.
7295
7296 @subsubheading Using @code{BUILT_SOURCES}
7297
7298 A solution is to require @file{bindir.h} to be built before anything
7299 else.  This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
7300
7301 @example
7302 bin_PROGRAMS = foo
7303 foo_SOURCES = foo.c
7304 nodist_foo_SOURCES = bindir.h
7305 BUILT_SOURCES = bindir.h
7306 CLEANFILES = bindir.h
7307 bindir.h: Makefile
7308         echo '#define bindir "$(bindir)"' >$@@
7309 @end example
7310
7311 See how @file{bindir.h} gets built first:
7312
7313 @example
7314 % make
7315 echo '#define bindir "/usr/local/bin"' >bindir.h
7316 make  all-am
7317 make[1]: Entering directory `/home/adl/tmp'
7318 source='foo.c' object='foo.o' libtool=no \
7319 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7320 depmode=gcc /bin/sh ./depcomp \
7321 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7322 gcc  -g -O2   -o foo  foo.o
7323 make[1]: Leaving directory `/home/adl/tmp'
7324 @end example
7325
7326 However, as said earlier, @code{BUILT_SOURCES} applies only to the
7327 @code{all}, @code{check}, and @code{install} targets.  It still fails
7328 if you try to run @samp{make foo} explicitly:
7329
7330 @example
7331 % make clean
7332 test -z "bindir.h" || rm -f bindir.h
7333 test -z "foo" || rm -f foo
7334 rm -f *.o
7335 % : > .deps/foo.Po # Suppress previously recorded dependencies
7336 % make foo
7337 source='foo.c' object='foo.o' libtool=no \
7338 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7339 depmode=gcc /bin/sh ./depcomp \
7340 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7341 foo.c:2: bindir.h: No such file or directory
7342 make: *** [foo.o] Error 1
7343 @end example
7344
7345 @subsubheading Recording Dependencies manually
7346
7347 Usually people are happy enough with @code{BUILT_SOURCES} because they
7348 never build targets such as @samp{make foo} before @samp{make all}, as
7349 in the previous example.  However if this matters to you, you can
7350 avoid @code{BUILT_SOURCES} and record such dependencies explicitly in
7351 the @file{Makefile.am}.
7352
7353 @example
7354 bin_PROGRAMS = foo
7355 foo_SOURCES = foo.c
7356 nodist_foo_SOURCES = bindir.h
7357 foo.$(OBJEXT): bindir.h
7358 CLEANFILES = bindir.h
7359 bindir.h: Makefile
7360         echo '#define bindir "$(bindir)"' >$@@
7361 @end example
7362
7363 You don't have to list @emph{all} the dependencies of @file{foo.o}
7364 explicitly, only those that might need to be built.  If a dependency
7365 already exists, it will not hinder the first compilation and will be
7366 recorded by the normal dependency tracking code.  (Note that after
7367 this first compilation the dependency tracking code will also have
7368 recorded the dependency between @file{foo.o} and
7369 @file{bindir.h}; so our explicit dependency is really useful to
7370 the first build only.)
7371
7372 Adding explicit dependencies like this can be a bit dangerous if you are
7373 not careful enough.  This is due to the way Automake tries not to
7374 overwrite your rules (it assumes you know better than it).
7375 @samp{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
7376 output to build @samp{foo.$(OBJEXT)}.  It happens to work in this case
7377 because Automake doesn't have to output any @samp{foo.$(OBJEXT):}
7378 target: it relies on a suffix rule instead (i.e., @samp{.c.$(OBJEXT):}).
7379 Always check the generated @file{Makefile.in} if you do this.
7380
7381 @subsubheading Build @file{bindir.h} from @file{configure}
7382
7383 It's possible to define this preprocessor macro from @file{configure},
7384 either in @file{config.h} (@pxref{Defining Directories, , Defining
7385 Directories, autoconf, The Autoconf Manual}), or by processing a
7386 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
7387 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
7388 Autoconf Manual}).
7389
7390 At this point it should be clear that building @file{bindir.h} from
7391 @file{configure} works well for this example.  @file{bindir.h} will exist
7392 before you build any target, hence will not cause any dependency issue.
7393
7394 The Makefile can be shrunk as follows.  We do not even have to mention
7395 @file{bindir.h}.
7396
7397 @example
7398 bin_PROGRAMS = foo
7399 foo_SOURCES = foo.c
7400 @end example
7401
7402 However, it's not always possible to build sources from
7403 @file{configure}, especially when these sources are generated by a tool
7404 that needs to be built first.
7405
7406 @subsubheading Build @file{bindir.c}, not @file{bindir.h}.
7407
7408 Another attractive idea is to define @code{bindir} as a variable or
7409 function exported from @file{bindir.o}, and build @file{bindir.c}
7410 instead of @file{bindir.h}.
7411
7412 @example
7413 noinst_PROGRAMS = foo
7414 foo_SOURCES = foo.c bindir.h
7415 nodist_foo_SOURCES = bindir.c
7416 CLEANFILES = bindir.c
7417 bindir.c: Makefile
7418         echo 'const char bindir[] = "$(bindir)";' >$@@
7419 @end example
7420
7421 @file{bindir.h} contains just the variable's declaration and doesn't
7422 need to be built, so it won't cause any trouble.  @file{bindir.o} is
7423 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
7424 first.
7425
7426 @subsubheading Which is best?
7427
7428 There is no panacea, of course.  Each solution has its merits and
7429 drawbacks.
7430
7431 You cannot use @code{BUILT_SOURCES} if the ability to run @samp{make
7432 foo} on a clean tree is important to you.
7433
7434 You won't add explicit dependencies if you are leery of overriding
7435 an Automake rule by mistake.
7436
7437 Building files from @file{./configure} is not always possible, neither
7438 is converting @file{.h} files into @file{.c} files.
7439
7440
7441 @node Other GNU Tools
7442 @chapter Other GNU Tools
7443
7444 Since Automake is primarily intended to generate @file{Makefile.in}s for
7445 use in GNU programs, it tries hard to interoperate with other GNU tools.
7446
7447 @menu
7448 * Emacs Lisp::                  Emacs Lisp
7449 * gettext::                     Gettext
7450 * Libtool::                     Libtool
7451 * Java::                        Java bytecode compilation (deprecated)
7452 * Python::                      Python
7453 @end menu
7454
7455
7456 @node Emacs Lisp
7457 @section Emacs Lisp
7458
7459 @cindex @code{_LISP} primary, defined
7460 @cindex @code{LISP} primary, defined
7461 @cindex Primary variable, @code{LISP}
7462
7463 @vindex _LISP
7464 @vindex lisp_LISP
7465 @vindex noinst_LISP
7466
7467 Automake provides some support for Emacs Lisp.  The @code{LISP} primary
7468 is used to hold a list of @file{.el} files.  Possible prefixes for this
7469 primary are @code{lisp_} and @code{noinst_}.  Note that if
7470 @code{lisp_LISP} is defined, then @file{configure.ac} must run
7471 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
7472
7473 @vindex dist_lisp_LISP
7474 @vindex dist_noinst_LISP
7475 Lisp sources are not distributed by default.  You can prefix the
7476 @code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
7477 @code{dist_noinst_LISP}, to indicate that these files should be
7478 distributed.
7479
7480 Automake will byte-compile all Emacs Lisp source files using the Emacs
7481 found by @code{AM_PATH_LISPDIR}, if any was found.
7482
7483 Byte-compiled Emacs Lisp files are not portable among all versions of
7484 Emacs, so it makes sense to turn this off if you expect sites to have
7485 more than one version of Emacs installed.  Furthermore, many packages
7486 don't actually benefit from byte-compilation.  Still, we recommend
7487 that you byte-compile your Emacs Lisp sources.  It is probably better
7488 for sites with strange setups to cope for themselves than to make the
7489 installation less nice for everybody else.
7490
7491 There are two ways to avoid byte-compiling.  Historically, we have
7492 recommended the following construct.
7493
7494 @example
7495 lisp_LISP = file1.el file2.el
7496 ELCFILES =
7497 @end example
7498
7499 @noindent
7500 @code{ELCFILES} is an internal Automake variable that normally lists
7501 all @file{.elc} files that must be byte-compiled.  Automake defines
7502 @code{ELCFILES} automatically from @code{lisp_LISP}.  Emptying this
7503 variable explicitly prevents byte-compilation.
7504
7505 Since Automake 1.8, we now recommend using @code{lisp_DATA} instead:
7506
7507 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7508 @example
7509 lisp_DATA = file1.el file2.el
7510 @end example
7511
7512 Note that these two constructs are not equivalent.  @code{_LISP} will
7513 not install a file if Emacs is not installed, while @code{_DATA} will
7514 always install its files.
7515
7516 @node gettext
7517 @section Gettext
7518
7519 @cindex GNU Gettext support
7520 @cindex Gettext support
7521 @cindex Support for GNU Gettext
7522
7523 If @code{AM_GNU_GETTEXT} is seen in @file{configure.ac}, then Automake
7524 turns on support for GNU gettext, a message catalog system for
7525 internationalization
7526 (@pxref{Top, , Introduction, gettext, GNU gettext utilities}).
7527
7528 The @code{gettext} support in Automake requires the addition of one or
7529 two subdirectories to the package: @file{po} and possibly also @file{intl}.
7530 The latter is needed if @code{AM_GNU_GETTEXT} is not invoked with the
7531 @samp{external} argument, or if @code{AM_GNU_GETTEXT_INTL_SUBDIR} is used.
7532 Automake ensures that these directories exist and are mentioned in
7533 @code{SUBDIRS}.
7534
7535 @node Libtool
7536 @section Libtool
7537
7538 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
7539 libtool, The Libtool Manual}) with the @code{LTLIBRARIES} primary.
7540 @xref{A Shared Library}.
7541
7542
7543 @node Java
7544 @section Java bytecode compilation (deprecated)
7545
7546 @cindex @code{_JAVA} primary, defined
7547 @cindex @code{JAVA} primary, defined
7548 @cindex Primary variable, @code{JAVA}
7549 @cindex Java to bytecode, compilation
7550 @cindex Compilation of Java to bytecode
7551
7552 Automake provides some minimal support for Java bytecode compilation with
7553 the @code{JAVA} primary (in addition to the support for compiling Java to
7554 native machine code; @pxref{Java Support with gcj}).  Note however that
7555 @emph{the interface and most features described here are deprecated}; the
7556 next automake release will strive to provide a better and cleaner
7557 interface, which however @emph{won't be backward-compatible}; the present
7558 interface will probably be removed altogether in future automake releases
7559 (1.13 or later), so don't use it in new code.
7560
7561 Any @file{.java} files listed in a @code{_JAVA} variable will be
7562 compiled with @code{JAVAC} at build time.  By default, @file{.java}
7563 files are not included in the distribution, you should use the
7564 @code{dist_} prefix to distribute them.
7565
7566 Here is a typical setup for distributing @file{.java} files and
7567 installing the @file{.class} files resulting from their compilation.
7568
7569 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7570 @example
7571 javadir = $(datadir)/java
7572 dist_java_JAVA = a.java b.java @dots{}
7573 @end example
7574
7575 @cindex @code{JAVA} restrictions
7576 @cindex Restrictions for @code{JAVA}
7577
7578 Currently Automake enforces the restriction that only one @code{_JAVA}
7579 primary can be used in a given @file{Makefile.am}.  The reason for this
7580 restriction is that, in general, it isn't possible to know which
7581 @file{.class} files were generated from which @file{.java} files, so
7582 it would be impossible to know which files to install where.  For
7583 instance, a @file{.java} file can define multiple classes; the resulting
7584 @file{.class} file names cannot be predicted without parsing the
7585 @file{.java} file.
7586
7587 There are a few variables that are used when compiling Java sources:
7588
7589 @vtable @code
7590 @item JAVAC
7591 The name of the Java compiler.  This defaults to @samp{javac}.
7592
7593 @item JAVACFLAGS
7594 The flags to pass to the compiler.  This is considered to be a user
7595 variable (@pxref{User Variables}).
7596
7597 @item AM_JAVACFLAGS
7598 More flags to pass to the Java compiler.  This, and not
7599 @code{JAVACFLAGS}, should be used when it is necessary to put Java
7600 compiler flags into @file{Makefile.am}.
7601
7602 @item JAVAROOT
7603 The value of this variable is passed to the @option{-d} option to
7604 @code{javac}.  It defaults to @samp{$(top_builddir)}.
7605
7606 @item CLASSPATH_ENV
7607 This variable is a shell expression that is used to set the
7608 @env{CLASSPATH} environment variable on the @code{javac} command line.
7609 (In the future we will probably handle class path setting differently.)
7610 @end vtable
7611
7612
7613 @node Python
7614 @section Python
7615
7616 @cindex @code{_PYTHON} primary, defined
7617 @cindex @code{PYTHON} primary, defined
7618 @cindex Primary variable, @code{PYTHON}
7619 @vindex _PYTHON
7620
7621 Automake provides support for Python compilation with the
7622 @code{PYTHON} primary.  A typical setup is to call
7623 @code{AM_PATH_PYTHON} in @file{configure.ac} and use a line like the
7624 following in @file{Makefile.am}:
7625
7626 @example
7627 python_PYTHON = tree.py leave.py
7628 @end example
7629
7630 Any files listed in a @code{_PYTHON} variable will be byte-compiled
7631 with @command{py-compile} at install time.  @command{py-compile}
7632 actually creates both standard (@file{.pyc}) and optimized
7633 (@file{.pyo}) byte-compiled versions of the source files.  Note that
7634 because byte-compilation occurs at install time, any files listed in
7635 @code{noinst_PYTHON} will not be compiled.  Python source files are
7636 included in the distribution by default, prepend @code{nodist_} (as in
7637 @code{nodist_python_PYTHON}) to omit them.
7638
7639 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON}
7640 that will determine some Python-related directory variables (see
7641 below).  If you have called @code{AM_PATH_PYTHON} from
7642 @file{configure.ac}, then you may use the variables
7643 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7644 @code{python_PYTHON} or @code{pkgpython_PYTHON} to list Python source
7645 files in your @file{Makefile.am}, depending on where you want your files
7646 installed (see the definitions of @code{pythondir} and
7647 @code{pkgpythondir} below).
7648
7649 @defmac AM_PATH_PYTHON (@ovar{version}, @ovar{action-if-found},
7650   @ovar{action-if-not-found})
7651
7652 Search for a Python interpreter on the system.  This macro takes three
7653 optional arguments.  The first argument, if present, is the minimum
7654 version of Python required for this package: @code{AM_PATH_PYTHON}
7655 will skip any Python interpreter that is older than @var{version}.
7656 If an interpreter is found and satisfies @var{version}, then
7657 @var{action-if-found} is run.  Otherwise, @var{action-if-not-found} is
7658 run.
7659
7660 If @var{action-if-not-found} is not specified, as in the following
7661 example, the default is to abort @command{configure}.
7662
7663 @example
7664 AM_PATH_PYTHON([2.2])
7665 @end example
7666
7667 @noindent
7668 This is fine when Python is an absolute requirement for the package.
7669 If Python >= 2.5 was only @emph{optional} to the package,
7670 @code{AM_PATH_PYTHON} could be called as follows.
7671
7672 @example
7673 AM_PATH_PYTHON([2.5],, [:])
7674 @end example
7675
7676 If the @env{PYTHON} variable is set when @code{AM_PATH_PYTHON} is
7677 called, then that will be the only Python interpreter that is tried.
7678
7679 @code{AM_PATH_PYTHON} creates the following output variables based on
7680 the Python installation found during configuration.
7681 @end defmac
7682
7683 @vtable @code
7684 @item PYTHON
7685 The name of the Python executable, or @samp{:} if no suitable
7686 interpreter could be found.
7687
7688 Assuming @var{action-if-not-found} is used (otherwise @file{./configure}
7689 will abort if Python is absent), the value of @code{PYTHON} can be used
7690 to setup a conditional in order to disable the relevant part of a build
7691 as follows.
7692
7693 @example
7694 AM_PATH_PYTHON(,, [:])
7695 AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
7696 @end example
7697
7698 @item PYTHON_VERSION
7699 The Python version number, in the form @var{major}.@var{minor}
7700 (e.g., @samp{2.5}).  This is currently the value of
7701 @samp{sys.version[:3]}.
7702
7703 @item PYTHON_PREFIX
7704 The string @samp{$@{prefix@}}.  This term may be used in future work
7705 that needs the contents of Python's @samp{sys.prefix}, but general
7706 consensus is to always use the value from @command{configure}.
7707
7708 @item PYTHON_EXEC_PREFIX
7709 The string @samp{$@{exec_prefix@}}.  This term may be used in future work
7710 that needs the contents of Python's @samp{sys.exec_prefix}, but general
7711 consensus is to always use the value from @command{configure}.
7712
7713 @item PYTHON_PLATFORM
7714 The canonical name used by Python to describe the operating system, as
7715 given by @samp{sys.platform}.  This value is sometimes needed when
7716 building Python extensions.
7717
7718 @item pythondir
7719 The directory name for the @file{site-packages} subdirectory of the
7720 standard Python install tree.
7721
7722 @item pkgpythondir
7723 This is the directory under @code{pythondir} that is named after the
7724 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
7725 as a convenience.
7726
7727 @item pyexecdir
7728 This is the directory where Python extension modules (shared libraries)
7729 should be installed.  An extension module written in C could be declared
7730 as follows to Automake:
7731
7732 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7733 @example
7734 pyexec_LTLIBRARIES = quaternion.la
7735 quaternion_la_SOURCES = quaternion.c support.c support.h
7736 quaternion_la_LDFLAGS = -avoid-version -module
7737 @end example
7738
7739 @item pkgpyexecdir
7740 This is a convenience variable that is defined as
7741 @samp{$(pyexecdir)/$(PACKAGE)}.
7742 @end vtable
7743
7744 All these directory variables have values that start with either
7745 @samp{$@{prefix@}} or @samp{$@{exec_prefix@}} unexpanded.  This works
7746 fine in @file{Makefiles}, but it makes these variables hard to use in
7747 @file{configure}.  This is mandated by the GNU coding standards, so
7748 that the user can run @samp{make prefix=/foo install}.  The Autoconf
7749 manual has a section with more details on this topic
7750 (@pxref{Installation Directory Variables, , Installation Directory
7751 Variables, autoconf, The Autoconf Manual}).  See also @ref{Hard-Coded
7752 Install Paths}.
7753
7754
7755 @node Documentation
7756 @chapter Building documentation
7757
7758 Currently Automake provides support for Texinfo and man pages.
7759
7760 @menu
7761 * Texinfo::                     Texinfo
7762 * Man Pages::                   Man pages
7763 @end menu
7764
7765
7766 @node Texinfo
7767 @section Texinfo
7768
7769 @cindex @code{_TEXINFOS} primary, defined
7770 @cindex @code{TEXINFOS} primary, defined
7771 @cindex Primary variable, @code{TEXINFOS}
7772 @cindex HTML output using Texinfo
7773 @cindex PDF output using Texinfo
7774 @cindex PS output using Texinfo
7775 @cindex DVI output using Texinfo
7776 @vindex _TEXINFOS
7777 @vindex info_TEXINFOS
7778
7779 If the current directory contains Texinfo source, you must declare it
7780 with the @code{TEXINFOS} primary.  Generally Texinfo files are converted
7781 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
7782 here.  Any Texinfo source file must end in the @file{.texi},
7783 @file{.txi}, or @file{.texinfo} extension.  We recommend @file{.texi}
7784 for new manuals.
7785
7786 Automake generates rules to build @file{.info}, @file{.dvi},
7787 @file{.ps}, @file{.pdf} and @file{.html} files from your Texinfo
7788 sources.  Following the GNU Coding Standards, only the @file{.info}
7789 files are built by @samp{make all} and installed by @samp{make
7790 install} (unless you use @option{no-installinfo}, see below).
7791 Furthermore, @file{.info} files are automatically distributed so that
7792 Texinfo is not a prerequisite for installing your package.
7793
7794 @trindex dvi
7795 @trindex html
7796 @trindex pdf
7797 @trindex ps
7798 @trindex install-dvi
7799 @trindex install-html
7800 @trindex install-pdf
7801 @trindex install-ps
7802 Other documentation formats can be built on request by @samp{make
7803 dvi}, @samp{make ps}, @samp{make pdf} and @samp{make html}, and they
7804 can be installed with @samp{make install-dvi}, @samp{make install-ps},
7805 @samp{make install-pdf} and @samp{make install-html} explicitly.
7806 @samp{make uninstall} will remove everything: the Texinfo
7807 documentation installed by default as well as all the above optional
7808 formats.
7809
7810 All these targets can be extended using @samp{-local} rules
7811 (@pxref{Extending}).
7812
7813 @cindex Texinfo flag, @code{VERSION}
7814 @cindex Texinfo flag, @code{UPDATED}
7815 @cindex Texinfo flag, @code{EDITION}
7816 @cindex Texinfo flag, @code{UPDATED-MONTH}
7817
7818 @cindex @code{VERSION} Texinfo flag
7819 @cindex @code{UPDATED} Texinfo flag
7820 @cindex @code{EDITION} Texinfo flag
7821 @cindex @code{UPDATED-MONTH} Texinfo flag
7822
7823 @cindex @file{mdate-sh}
7824
7825 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
7826 that file will be automatically generated.  The file @file{version.texi}
7827 defines four Texinfo flag you can reference using
7828 @code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
7829 @code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
7830
7831 @table @code
7832 @item EDITION
7833 @itemx VERSION
7834 Both of these flags hold the version number of your program.  They are
7835 kept separate for clarity.
7836
7837 @item UPDATED
7838 This holds the date the primary @file{.texi} file was last modified.
7839
7840 @item UPDATED-MONTH
7841 This holds the name of the month in which the primary @file{.texi} file
7842 was last modified.
7843 @end table
7844
7845 The @file{version.texi} support requires the @command{mdate-sh}
7846 script; this script is supplied with Automake and automatically
7847 included when @command{automake} is invoked with the
7848 @option{--add-missing} option.
7849
7850 If you have multiple Texinfo files, and you want to use the
7851 @file{version.texi} feature, then you have to have a separate version
7852 file for each Texinfo file.  Automake will treat any include in a
7853 Texinfo file that matches @file{vers*.texi} just as an automatically
7854 generated version file.
7855
7856 Sometimes an info file actually depends on more than one @file{.texi}
7857 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
7858 @file{fdl.texi}.  You can tell Automake about these dependencies using
7859 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
7860 @vindex TEXINFOS
7861 @vindex _TEXINFOS
7862
7863 @example
7864 info_TEXINFOS = hello.texi
7865 hello_TEXINFOS = fdl.texi
7866 @end example
7867
7868 @cindex @file{texinfo.tex}
7869
7870 By default, Automake requires the file @file{texinfo.tex} to appear in
7871 the same directory as the @file{Makefile.am} file that lists the
7872 @file{.texi} files.  If you used @code{AC_CONFIG_AUX_DIR} in
7873 @file{configure.ac} (@pxref{Input, , Finding `configure' Input,
7874 autoconf, The Autoconf Manual}), then @file{texinfo.tex} is looked for
7875 there.  In both cases, @command{automake} then supplies @file{texinfo.tex} if
7876 @option{--add-missing} is given, and takes care of its distribution.
7877 However, if you set the @code{TEXINFO_TEX} variable (see below),
7878 it overrides the location of the file and turns off its installation
7879 into the source as well as its distribution.
7880
7881 The option @option{no-texinfo.tex} can be used to eliminate the
7882 requirement for the file @file{texinfo.tex}.  Use of the variable
7883 @code{TEXINFO_TEX} is preferable, however, because that allows the
7884 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
7885
7886 @cindex Option, @code{no-installinfo}
7887 @cindex Target, @code{install-info}
7888 @cindex @code{install-info} target
7889 @cindex @code{no-installinfo} option
7890
7891 @opindex no-installinfo
7892 @trindex install-info
7893
7894 Automake generates an @code{install-info} rule; some people apparently
7895 use this.  By default, info pages are installed by @samp{make
7896 install}, so running @code{make install-info} is pointless.  This can
7897 be prevented via the @code{no-installinfo} option.  In this case,
7898 @file{.info} files are not installed by default, and user must
7899 request this explicitly using @samp{make install-info}.
7900
7901 @vindex AM_UPDATE_INFO_DIR
7902 By default, @code{make install-info} and @code{make install-info}
7903 will try to run the @command{install-info} program (if available)
7904 to update (or create) the @file{@code{$@{infodir@}}/dir} index.
7905 If this is undesired, it can be prevented by exporting the
7906 @code{AM_UPDATE_INFO_DIR} variable to "@code{no}".
7907
7908 The following variables are used by the Texinfo build rules.
7909
7910 @vtable @code
7911 @item MAKEINFO
7912 The name of the program invoked to build @file{.info} files.  This
7913 variable is defined by Automake.  If the @command{makeinfo} program is
7914 found on the system then it will be used by default; otherwise
7915 @command{missing} will be used instead.
7916
7917 @item MAKEINFOHTML
7918 The command invoked to build @file{.html} files.  Automake
7919 defines this to @samp{$(MAKEINFO) --html}.
7920
7921 @item MAKEINFOFLAGS
7922 User flags passed to each invocation of @samp{$(MAKEINFO)} and
7923 @samp{$(MAKEINFOHTML)}.  This user variable (@pxref{User Variables}) is
7924 not expected to be defined in any @file{Makefile}; it can be used by
7925 users to pass extra flags to suit their needs.
7926
7927 @item AM_MAKEINFOFLAGS
7928 @itemx AM_MAKEINFOHTMLFLAGS
7929 Maintainer flags passed to each @command{makeinfo} invocation.  Unlike
7930 @code{MAKEINFOFLAGS}, these variables are meant to be defined by
7931 maintainers in @file{Makefile.am}.  @samp{$(AM_MAKEINFOFLAGS)} is
7932 passed to @code{makeinfo} when building @file{.info} files; and
7933 @samp{$(AM_MAKEINFOHTMLFLAGS)} is used when building @file{.html}
7934 files.
7935
7936 @c Keep in sync with txinfo21.sh
7937 For instance, the following setting can be used to obtain one single
7938 @file{.html} file per manual, without node separators.
7939 @example
7940 AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
7941 @end example
7942
7943 @code{AM_MAKEINFOHTMLFLAGS} defaults to @samp{$(AM_MAKEINFOFLAGS)}.
7944 This means that defining @code{AM_MAKEINFOFLAGS} without defining
7945 @code{AM_MAKEINFOHTMLFLAGS} will impact builds of both @file{.info}
7946 and @file{.html} files.
7947
7948 @item TEXI2DVI
7949 The name of the command that converts a @file{.texi} file into a
7950 @file{.dvi} file.  This defaults to @samp{texi2dvi}, a script that ships
7951 with the Texinfo package.
7952
7953 @item TEXI2PDF
7954 The name of the command that translates a @file{.texi} file into a
7955 @file{.pdf} file.  This defaults to @samp{$(TEXI2DVI) --pdf --batch}.
7956
7957 @item DVIPS
7958 The name of the command that builds a @file{.ps} file out of a
7959 @file{.dvi} file.  This defaults to @samp{dvips}.
7960
7961 @item TEXINFO_TEX
7962
7963 If your package has Texinfo files in many directories, you can use the
7964 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
7965 @file{texinfo.tex} for your package.  The value of this variable should
7966 be the relative path from the current @file{Makefile.am} to
7967 @file{texinfo.tex}:
7968
7969 @example
7970 TEXINFO_TEX = ../doc/texinfo.tex
7971 @end example
7972 @end vtable
7973
7974
7975 @node Man Pages
7976 @section Man Pages
7977
7978 @cindex @code{_MANS} primary, defined
7979 @cindex @code{MANS} primary, defined
7980 @cindex Primary variable, @code{MANS}
7981
7982 @vindex _MANS
7983 @vindex man_MANS
7984 A package can also include man pages (but see the GNU standards on this
7985 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
7986 pages are declared using the @code{MANS} primary.  Generally the
7987 @code{man_MANS} variable is used.  Man pages are automatically installed in
7988 the correct subdirectory of @code{mandir}, based on the file extension.
7989
7990 File extensions such as @file{.1c} are handled by looking for the valid
7991 part of the extension and using that to determine the correct
7992 subdirectory of @code{mandir}.  Valid section names are the digits
7993 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
7994
7995 Sometimes developers prefer to name a man page something like
7996 @file{foo.man} in the source, and then rename it to have the correct
7997 suffix, for example @file{foo.1}, when installing the file.  Automake
7998 also supports this mode.  For a valid section named @var{section},
7999 there is a corresponding directory named @samp{man@var{section}dir},
8000 and a corresponding @code{_MANS} variable.  Files listed in such a
8001 variable are installed in the indicated section.  If the file already
8002 has a valid suffix, then it is installed as-is; otherwise the file
8003 suffix is changed to match the section.
8004
8005 For instance, consider this example:
8006 @example
8007 man1_MANS = rename.man thesame.1 alsothesame.1c
8008 @end example
8009
8010 @noindent
8011 In this case, @file{rename.man} will be renamed to @file{rename.1} when
8012 installed, but the other files will keep their names.
8013
8014 @cindex Target, @code{install-man}
8015 @cindex Option, @option{no-installman}
8016 @cindex @code{install-man} target
8017 @cindex @option{no-installman} option
8018 @opindex no-installman
8019 @trindex install-man
8020
8021 By default, man pages are installed by @samp{make install}.  However,
8022 since the GNU project does not require man pages, many maintainers do
8023 not expend effort to keep the man pages up to date.  In these cases, the
8024 @option{no-installman} option will prevent the man pages from being
8025 installed by default.  The user can still explicitly install them via
8026 @samp{make install-man}.
8027
8028 For fast installation, with many files it is preferable to use
8029 @samp{man@var{section}_MANS} over @samp{man_MANS} as well as files that
8030 do not need to be renamed.
8031
8032 Man pages are not currently considered to be source, because it is not
8033 uncommon for man pages to be automatically generated.  Therefore they
8034 are not automatically included in the distribution.  However, this can
8035 be changed by use of the @code{dist_} prefix.  For instance here is
8036 how to distribute and install the two man pages of GNU @command{cpio}
8037 (which includes both Texinfo documentation and man pages):
8038
8039 @example
8040 dist_man_MANS = cpio.1 mt.1
8041 @end example
8042
8043 The @code{nobase_} prefix is meaningless for man pages and is
8044 disallowed.
8045
8046 @vindex notrans_
8047 @cindex @code{notrans_} prefix
8048 @cindex Man page renaming, avoiding
8049 @cindex Avoiding man page renaming
8050
8051 Executables and manpages may be renamed upon installation
8052 (@pxref{Renaming}).  For manpages this can be avoided by use of the
8053 @code{notrans_} prefix.  For instance, suppose an executable @samp{foo}
8054 allowing to access a library function @samp{foo} from the command line.
8055 The way to avoid renaming of the @file{foo.3} manpage is:
8056
8057 @example
8058 man_MANS = foo.1
8059 notrans_man_MANS = foo.3
8060 @end example
8061
8062 @cindex @code{notrans_} and @code{dist_} or @code{nodist_}
8063 @cindex @code{dist_} and @code{notrans_}
8064 @cindex @code{nodist_} and @code{notrans_}
8065
8066 @samp{notrans_} must be specified first when used in conjunction with
8067 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
8068 Control}).  For instance:
8069
8070 @example
8071 notrans_dist_man3_MANS = bar.3
8072 @end example
8073
8074 @node Install
8075 @chapter What Gets Installed
8076
8077 @cindex Installation support
8078 @cindex @samp{make install} support
8079
8080 Naturally, Automake handles the details of actually installing your
8081 program once it has been built.  All files named by the various
8082 primaries are automatically installed in the appropriate places when the
8083 user runs @samp{make install}.
8084
8085 @menu
8086 * Basics of Installation::      What gets installed where
8087 * The Two Parts of Install::    Installing data and programs separately
8088 * Extending Installation::      Adding your own rules for installation
8089 * Staged Installs::             Installation in a temporary location
8090 * Install Rules for the User::  Useful additional rules
8091 @end menu
8092
8093 @node Basics of Installation
8094 @section Basics of Installation
8095
8096 A file named in a primary is installed by copying the built file into
8097 the appropriate directory.  The base name of the file is used when
8098 installing.
8099
8100 @example
8101 bin_PROGRAMS = hello subdir/goodbye
8102 @end example
8103
8104 In this example, both @samp{hello} and @samp{goodbye} will be installed
8105 in @samp{$(bindir)}.
8106
8107 Sometimes it is useful to avoid the basename step at install time.  For
8108 instance, you might have a number of header files in subdirectories of
8109 the source tree that are laid out precisely how you want to install
8110 them.  In this situation you can use the @code{nobase_} prefix to
8111 suppress the base name step.  For example:
8112
8113 @example
8114 nobase_include_HEADERS = stdio.h sys/types.h
8115 @end example
8116
8117 @noindent
8118 will install @file{stdio.h} in @samp{$(includedir)} and @file{types.h}
8119 in @samp{$(includedir)/sys}.
8120
8121 For most file types, Automake will install multiple files at once, while
8122 avoiding command line length issues (@pxref{Length Limitations}).  Since
8123 some @command{install} programs will not install the same file twice in
8124 one invocation, you may need to ensure that file lists are unique within
8125 one variable such as @samp{nobase_include_HEADERS} above.
8126
8127 You should not rely on the order in which files listed in one variable
8128 are installed.  Likewise, to cater for parallel make, you should not
8129 rely on any particular file installation order even among different
8130 file types (library dependencies are an exception here).
8131
8132
8133 @node The Two Parts of Install
8134 @section The Two Parts of Install
8135
8136 Automake generates separate @code{install-data} and @code{install-exec}
8137 rules, in case the installer is installing on multiple machines that
8138 share directory structure---these targets allow the machine-independent
8139 parts to be installed only once.  @code{install-exec} installs
8140 platform-dependent files, and @code{install-data} installs
8141 platform-independent files.  The @code{install} target depends on both
8142 of these targets.  While Automake tries to automatically segregate
8143 objects into the correct category, the @file{Makefile.am} author is, in
8144 the end, responsible for making sure this is done correctly.
8145 @trindex install-data
8146 @trindex install-exec
8147 @trindex install
8148 @cindex Install, two parts of
8149
8150 Variables using the standard directory prefixes @samp{data},
8151 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
8152 @samp{pkgdata}, or @samp{pkginclude} are installed by
8153 @code{install-data}.
8154
8155 Variables using the standard directory prefixes @samp{bin},
8156 @samp{sbin}, @samp{libexec}, @samp{sysconf}, @samp{localstate},
8157 @samp{lib}, or @samp{pkglib} are installed by @code{install-exec}.
8158
8159 For instance, @code{data_DATA} files are installed by @code{install-data},
8160 while @code{bin_PROGRAMS} files are installed by @code{install-exec}.
8161
8162 Any variable using a user-defined directory prefix with
8163 @samp{exec} in the name (e.g.,
8164 @c Keep in sync with primary-prefix-couples-documented-valid.sh
8165 @code{myexecbin_PROGRAMS}) is installed by @code{install-exec}.  All
8166 other user-defined prefixes are installed by @code{install-data}.
8167
8168 @node Extending Installation
8169 @section Extending Installation
8170
8171 It is possible to extend this mechanism by defining an
8172 @code{install-exec-local} or @code{install-data-local} rule.  If these
8173 rules exist, they will be run at @samp{make install} time.  These
8174 rules can do almost anything; care is required.
8175 @trindex install-exec-local
8176 @trindex install-data-local
8177
8178 Automake also supports two install hooks, @code{install-exec-hook} and
8179 @code{install-data-hook}.  These hooks are run after all other install
8180 rules of the appropriate type, exec or data, have completed.  So, for
8181 instance, it is possible to perform post-installation modifications
8182 using an install hook.  @xref{Extending}, for some examples.
8183 @cindex Install hook
8184
8185 @node Staged Installs
8186 @section Staged Installs
8187
8188 @vindex DESTDIR
8189 Automake generates support for the @code{DESTDIR} variable in all
8190 install rules.  @code{DESTDIR} is used during the @samp{make install}
8191 step to relocate install objects into a staging area.  Each object and
8192 path is prefixed with the value of @code{DESTDIR} before being copied
8193 into the install area.  Here is an example of typical DESTDIR usage:
8194
8195 @example
8196 mkdir /tmp/staging &&
8197 make DESTDIR=/tmp/staging install
8198 @end example
8199
8200 The @command{mkdir} command avoids a security problem if the attacker
8201 creates a symbolic link from @file{/tmp/staging} to a victim area;
8202 then @command{make} places install objects in a directory tree built under
8203 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
8204 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
8205 would install @file{/tmp/staging/gnu/bin/foo} and
8206 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
8207
8208 This feature is commonly used to build install images and packages
8209 (@pxref{DESTDIR}).
8210
8211 Support for @code{DESTDIR} is implemented by coding it directly into
8212 the install rules.  If your @file{Makefile.am} uses a local install
8213 rule (e.g., @code{install-exec-local}) or an install hook, then you
8214 must write that code to respect @code{DESTDIR}.
8215
8216 @xref{Makefile Conventions, , , standards, The GNU Coding Standards},
8217 for another usage example.
8218
8219 @node Install Rules for the User
8220 @section Install Rules for the User
8221
8222 Automake also generates rules for targets @code{uninstall},
8223 @code{installdirs}, and @code{install-strip}.
8224 @trindex uninstall
8225 @trindex installdirs
8226 @trindex install-strip
8227
8228 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
8229 There is no notion of separate uninstalls for ``exec'' and ``data'', as
8230 these features would not provide additional functionality.
8231
8232 Note that @code{uninstall} is not meant as a replacement for a real
8233 packaging tool.
8234
8235
8236 @node Clean
8237 @chapter What Gets Cleaned
8238
8239 @cindex @samp{make clean} support
8240
8241 The GNU Makefile Standards specify a number of different clean rules.
8242 @xref{Standard Targets, , Standard Targets for Users, standards,
8243 The GNU Coding Standards}.
8244
8245 Generally the files that can be cleaned are determined automatically by
8246 Automake.  Of course, Automake also recognizes some variables that can
8247 be defined to specify additional files to clean.  These variables are
8248 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
8249 @code{MAINTAINERCLEANFILES}.
8250 @vindex MOSTLYCLEANFILES
8251 @vindex CLEANFILES
8252 @vindex DISTCLEANFILES
8253 @vindex MAINTAINERCLEANFILES
8254
8255 @trindex mostlyclean-local
8256 @trindex clean-local
8257 @trindex distclean-local
8258 @trindex maintainer-clean-local
8259 When cleaning involves more than deleting some hard-coded list of
8260 files, it is also possible to supplement the cleaning rules with your
8261 own commands.  Simply define a rule for any of the
8262 @code{mostlyclean-local}, @code{clean-local}, @code{distclean-local},
8263 or @code{maintainer-clean-local} targets (@pxref{Extending}).  A common
8264 case is deleting a directory, for instance, a directory created by the
8265 test suite:
8266
8267 @example
8268 clean-local:
8269         -rm -rf testSubDir
8270 @end example
8271
8272 Since @command{make} allows only one set of rules for a given target,
8273 a more extensible way of writing this is to use a separate target
8274 listed as a dependency:
8275
8276 @example
8277 clean-local: clean-local-check
8278 .PHONY: clean-local-check
8279 clean-local-check:
8280         -rm -rf testSubDir
8281 @end example
8282
8283 As the GNU Standards aren't always explicit as to which files should
8284 be removed by which rule, we've adopted a heuristic that we believe
8285 was first formulated by Fran@,{c}ois Pinard:
8286
8287 @itemize @bullet
8288 @item
8289 If @command{make} built it, and it is commonly something that one would
8290 want to rebuild (for instance, a @file{.o} file), then
8291 @code{mostlyclean} should delete it.
8292
8293 @item
8294 Otherwise, if @command{make} built it, then @code{clean} should delete it.
8295
8296 @item
8297 If @command{configure} built it, then @code{distclean} should delete it.
8298
8299 @item
8300 If the maintainer built it (for instance, a @file{.info} file), then
8301 @code{maintainer-clean} should delete it.  However
8302 @code{maintainer-clean} should not delete anything that needs to exist
8303 in order to run @samp{./configure && make}.
8304 @end itemize
8305
8306 We recommend that you follow this same set of heuristics in your
8307 @file{Makefile.am}.
8308
8309
8310 @node Dist
8311 @chapter What Goes in a Distribution
8312
8313 @menu
8314 * Basics of Distribution::      Files distributed by default
8315 * Fine-grained Distribution Control::  @code{dist_} and @code{nodist_} prefixes
8316 * The dist Hook::               A target for last-minute distribution changes
8317 * Checking the Distribution::   @samp{make distcheck} explained
8318 * The Types of Distributions::  A variety of formats and compression methods
8319 @end menu
8320
8321 @node Basics of Distribution
8322 @section Basics of Distribution
8323
8324 @cindex @samp{make dist}
8325
8326 @vindex PACKAGE
8327 @vindex VERSION
8328 @trindex dist
8329 The @code{dist} rule in the generated @file{Makefile.in} can be used
8330 to generate a gzipped @code{tar} file and other flavors of archive for
8331 distribution.  The file is named based on the @code{PACKAGE} and
8332 @code{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
8333 (@pxref{Macros}); more precisely the gzipped @code{tar} file is named
8334 @samp{@var{package}-@var{version}.tar.gz}.
8335 @vindex GZIP_ENV
8336 You can use the @command{make} variable @code{GZIP_ENV} to control how gzip
8337 is run.  The default setting is @option{--best}.
8338
8339 @cindex @code{m4_include}, distribution
8340 @cindex @code{include}, distribution
8341 @acindex m4_include
8342 @cmindex include
8343 For the most part, the files to distribute are automatically found by
8344 Automake: all source files are automatically included in a distribution,
8345 as are all @file{Makefile.am} and @file{Makefile.in} files.  Automake also
8346 has a built-in list of commonly used files that are automatically
8347 included if they are found in the current directory (either physically,
8348 or as the target of a @file{Makefile.am} rule); this list is printed by
8349 @samp{automake --help}.  Note that some files in this list are actually
8350 distributed only if other certain conditions hold (for example,
8351 @c Keep in sync with autodist-config-headers.sh
8352 the @file{config.h.top} and @file{config.h.bot} files are automatically
8353 distributed only if, e.g., @samp{AC_CONFIG_HEADERS([config.h])} is used
8354 in @file{configure.ac}).  Also, files that are read by @command{configure}
8355 (i.e.@: the source files corresponding to the files specified in various
8356 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
8357 automatically distributed.  Files included in a @file{Makefile.am} (using
8358 @code{include}) or in @file{configure.ac} (using @code{m4_include}), and
8359 helper scripts installed with @samp{automake --add-missing} are also
8360 distributed.
8361
8362 @vindex EXTRA_DIST
8363 Still, sometimes there are files that must be distributed, but which
8364 are not covered in the automatic rules.  These files should be listed in
8365 the @code{EXTRA_DIST} variable.  You can mention files from
8366 subdirectories in @code{EXTRA_DIST}.
8367
8368 You can also mention a directory in @code{EXTRA_DIST}; in this case the
8369 entire directory will be recursively copied into the distribution.
8370 Please note that this will also copy @emph{everything} in the directory,
8371 including, e.g., Subversion's @file{.svn} private directories or CVS/RCS
8372 version control files.  We recommend against using this feature.
8373
8374 @vindex SUBDIRS
8375 @vindex DIST_SUBDIRS
8376 If you define @code{SUBDIRS}, Automake will recursively include the
8377 subdirectories in the distribution.  If @code{SUBDIRS} is defined
8378 conditionally (@pxref{Conditionals}), Automake will normally include
8379 all directories that could possibly appear in @code{SUBDIRS} in the
8380 distribution.  If you need to specify the set of directories
8381 conditionally, you can set the variable @code{DIST_SUBDIRS} to the
8382 exact list of subdirectories to include in the distribution
8383 (@pxref{Conditional Subdirectories}).
8384
8385
8386 @node Fine-grained Distribution Control
8387 @section Fine-grained Distribution Control
8388
8389 @vindex dist_
8390 @vindex nodist_
8391 Sometimes you need tighter control over what does @emph{not} go into the
8392 distribution; for instance, you might have source files that are
8393 generated and that you do not want to distribute.  In this case
8394 Automake gives fine-grained control using the @code{dist} and
8395 @code{nodist} prefixes.  Any primary or @code{_SOURCES} variable can be
8396 prefixed with @code{dist_} to add the listed files to the distribution.
8397 Similarly, @code{nodist_} can be used to omit the files from the
8398 distribution.
8399
8400 As an example, here is how you would cause some data to be distributed
8401 while leaving some source code out of the distribution:
8402
8403 @example
8404 dist_data_DATA = distribute-this
8405 bin_PROGRAMS = foo
8406 nodist_foo_SOURCES = do-not-distribute.c
8407 @end example
8408
8409 @node The dist Hook
8410 @section The dist Hook
8411
8412 @trindex dist-hook
8413
8414 Occasionally it is useful to be able to change the distribution before
8415 it is packaged up.  If the @code{dist-hook} rule exists, it is run
8416 after the distribution directory is filled, but before the actual
8417 distribution archives are created.  One way to use this is for
8418 removing unnecessary files that get recursively included by specifying
8419 a directory in @code{EXTRA_DIST}:
8420
8421 @example
8422 EXTRA_DIST = doc
8423 dist-hook:
8424         rm -rf `find $(distdir)/doc -type d -name .svn`
8425 @end example
8426
8427 @c The caveates described here should be documented in 'disthook.test'.
8428 @noindent
8429 Note that the @code{dist-hook} recipe shouldn't assume that the regular
8430 files in the distribution directory are writable; this might not be the
8431 case if one is packaging from a read-only source tree, or when a
8432 @code{make distcheck} is being done.  For similar reasons, the recipe
8433 shouldn't assume that the subdirectories put into the distribution
8434 directory as effect of having them listed in @code{EXTRA_DIST} are
8435 writable.  So, if the @code{dist-hook} recipe wants to modify the
8436 content of an existing file (or @code{EXTRA_DIST} subdirectory) in the
8437 distribution directory, it should explicitly to make it writable first:
8438
8439 @example
8440 EXTRA_DIST = README doc
8441 dist-hook:
8442         chmod u+w $(distdir)/README $(distdir)/doc
8443         echo "Distribution date: `date`" >> README
8444         rm -f $(distdir)/doc/HACKING
8445 @end example
8446
8447 @vindex distdir
8448 @vindex top_distdir
8449 Two variables that come handy when writing @code{dist-hook} rules are
8450 @samp{$(distdir)} and @samp{$(top_distdir)}.
8451
8452 @samp{$(distdir)} points to the directory where the @code{dist} rule
8453 will copy files from the current directory before creating the
8454 tarball.  If you are at the top-level directory, then @samp{distdir =
8455 $(PACKAGE)-$(VERSION)}.  When used from subdirectory named
8456 @file{foo/}, then @samp{distdir = ../$(PACKAGE)-$(VERSION)/foo}.
8457 @samp{$(distdir)} can be a relative or absolute path, do not assume
8458 any form.
8459
8460 @samp{$(top_distdir)} always points to the root directory of the
8461 distributed tree.  At the top-level it's equal to @samp{$(distdir)}.
8462 In the @file{foo/} subdirectory
8463 @samp{top_distdir = ../$(PACKAGE)-$(VERSION)}.
8464 @samp{$(top_distdir)} too can be a relative or absolute path.
8465
8466 Note that when packages are nested using @code{AC_CONFIG_SUBDIRS}
8467 (@pxref{Subpackages}), then @samp{$(distdir)} and
8468 @samp{$(top_distdir)} are relative to the package where @samp{make
8469 dist} was run, not to any sub-packages involved.
8470
8471 @node Checking the Distribution
8472 @section Checking the Distribution
8473
8474 @cindex @samp{make distcheck}
8475 @trindex distcheck
8476 Automake also generates a @code{distcheck} rule that can be of help
8477 to ensure that a given distribution will actually work.  Simplifying
8478 a bit, we can say this rule first makes a distribution, and then,
8479 @emph{operating from it}, takes the following steps:
8480 @itemize
8481 @item
8482 tries to do a @code{VPATH} build (@pxref{VPATH Builds}), with the
8483 @code{srcdir} and all its content made @emph{read-only};
8484 @item
8485 runs the test suite (with @command{make check}) on this fresh build;
8486 @item
8487 installs the package in a temporary directory (with @command{make
8488 install}), and tries runs the test suite on the resulting installation
8489 (with @command{make installcheck});
8490 @item
8491 checks that the package can be correctly uninstalled (by @command{make
8492 uninstall}) and cleaned (by @code{make distclean});
8493 @item
8494 finally, makes another tarball to ensure the distribution is
8495 self-contained.
8496 @end itemize
8497
8498 @vindex AM_DISTCHECK_CONFIGURE_FLAGS
8499 @vindex DISTCHECK_CONFIGURE_FLAGS
8500 @subheading DISTCHECK_CONFIGURE_FLAGS
8501 Building the package involves running @samp{./configure}.  If you need
8502 to supply additional flags to @command{configure}, define them in the
8503 @code{AM_DISTCHECK_CONFIGURE_FLAGS} variable in your top-level
8504 @file{Makefile.am}.  The user can still extend or override the flags
8505 provided there by defining the @code{DISTCHECK_CONFIGURE_FLAGS} variable,
8506 on the command line when invoking @command{make}.
8507
8508 Still, developers are encouraged to strive to make their code buildable
8509 without requiring any special configure option; thus, in general, you
8510 shouldn't define @code{AM_DISTCHECK_CONFIGURE_FLAGS}. However, there
8511 might be few scenarios in which the use of this variable is justified.
8512 GNU @command{m4} offers an example.  GNU @command{m4} configures by
8513 default with its experimental and seldom used "changeword" feature
8514 disabled; so in its case it is useful to have @command{make distcheck}
8515 run configure with the @option{--with-changeword} option, to ensure that
8516 the code for changeword support still compiles correctly.
8517 GNU @command{m4} also employs the @code{AM_DISTCHECK_CONFIGURE_FLAGS}
8518 variable to stress-test the use of @option{--program-prefix=g}, since at
8519 one point the @command{m4} build system had a bug where @command{make
8520 installcheck} was wrongly assuming it could blindly test "@command{m4}",
8521 rather than the just-installed "@command{gm4}".
8522
8523 @trindex distcheck-hook
8524 @subheading distcheck-hook
8525 If the @code{distcheck-hook} rule is defined in your top-level
8526 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
8527 the new distribution has been unpacked, but before the unpacked copy
8528 is configured and built.  Your @code{distcheck-hook} can do almost
8529 anything, though as always caution is advised.  Generally this hook is
8530 used to check for potential distribution errors not caught by the
8531 standard mechanism.  Note that @code{distcheck-hook} as well as
8532 @code{AM_DISTCHECK_CONFIGURE_FLAGS} and @code{DISTCHECK_CONFIGURE_FLAGS}
8533 are not honored in a subpackage @file{Makefile.am}, but the flags from
8534 @code{AM_DISTCHECK_CONFIGURE_FLAGS} and @code{DISTCHECK_CONFIGURE_FLAGS}
8535 are passed down to the @command{configure} script of the subpackage.
8536
8537 @cindex @samp{make distcleancheck}
8538 @trindex distcleancheck
8539 @vindex DISTCLEANFILES
8540 @vindex distcleancheck_listfiles
8541
8542 @subheading distcleancheck
8543 Speaking of potential distribution errors, @code{distcheck} also
8544 ensures that the @code{distclean} rule actually removes all built
8545 files.  This is done by running @samp{make distcleancheck} at the end of
8546 the @code{VPATH} build.  By default, @code{distcleancheck} will run
8547 @code{distclean} and then make sure the build tree has been emptied by
8548 running @samp{$(distcleancheck_listfiles)}.  Usually this check will
8549 find generated files that you forgot to add to the @code{DISTCLEANFILES}
8550 variable (@pxref{Clean}).
8551
8552 The @code{distcleancheck} behavior should be OK for most packages,
8553 otherwise you have the possibility to override the definition of
8554 either the @code{distcleancheck} rule, or the
8555 @samp{$(distcleancheck_listfiles)} variable.  For instance, to disable
8556 @code{distcleancheck} completely, add the following rule to your
8557 top-level @file{Makefile.am}:
8558
8559 @example
8560 distcleancheck:
8561         @@:
8562 @end example
8563
8564 If you want @code{distcleancheck} to ignore built files that have not
8565 been cleaned because they are also part of the distribution, add the
8566 following definition instead:
8567
8568 @c Keep in sync with distcleancheck.sh
8569 @example
8570 distcleancheck_listfiles = \
8571   find . -type f -exec sh -c 'test -f $(srcdir)/$$1 || echo $$1' \
8572        sh '@{@}' ';'
8573 @end example
8574
8575 The above definition is not the default because it's usually an error if
8576 your Makefiles cause some distributed files to be rebuilt when the user
8577 build the package.  (Think about the user missing the tool required to
8578 build the file; or if the required tool is built by your package,
8579 consider the cross-compilation case where it can't be run.)  There is
8580 an entry in the FAQ about this (@pxref{Errors with distclean}), make
8581 sure you read it before playing with @code{distcleancheck_listfiles}.
8582
8583 @cindex @samp{make distuninstallcheck}
8584 @trindex distuninstallcheck
8585 @vindex distuninstallcheck_listfiles
8586
8587 @subheading distuninstallcheck
8588 @code{distcheck} also checks that the @code{uninstall} rule works
8589 properly, both for ordinary and @code{DESTDIR} builds.  It does this
8590 by invoking @samp{make uninstall}, and then it checks the install tree
8591 to see if any files are left over.  This check will make sure that you
8592 correctly coded your @code{uninstall}-related rules.
8593
8594 By default, the checking is done by the @code{distuninstallcheck} rule,
8595 and the list of files in the install tree is generated by
8596 @samp{$(distuninstallcheck_listfiles)} (this is a variable whose value is
8597 a shell command to run that prints the list of files to stdout).
8598
8599 Either of these can be overridden to modify the behavior of
8600 @code{distcheck}.  For instance, to disable this check completely, you
8601 would write:
8602
8603 @example
8604 distuninstallcheck:
8605         @@:
8606 @end example
8607
8608 @node The Types of Distributions
8609 @section The Types of Distributions
8610
8611 Automake generates rules to provide archives of the project for
8612 distributions in various formats.  Their targets are:
8613
8614 @table @asis
8615 @vindex BZIP2
8616 @item @code{dist-bzip2}
8617 Generate a bzip2 tar archive of the distribution.  bzip2 archives are
8618 frequently smaller than gzipped archives.
8619 By default, this rule makes @samp{bzip2} use a compression option of @option{-9}.
8620 To make it use a different one, set the @env{BZIP2} environment variable.
8621 For example, @samp{make dist-bzip2 BZIP2=-7}.
8622 @trindex dist-bzip2
8623
8624 @item @code{dist-gzip}
8625 Generate a gzip tar archive of the distribution.
8626 @trindex dist-gzip
8627
8628 @item @code{dist-lzip}
8629 Generate an @samp{lzip} tar archive of the distribution.  @command{lzip}
8630 archives are frequently smaller than @command{bzip2}-compressed archives.
8631 @trindex dist-lzip
8632
8633 @item @code{dist-shar}
8634 Generate a shar archive of the distribution.
8635 @trindex dist-shar
8636
8637 @vindex XZ_OPT
8638 @item @code{dist-xz}
8639 Generate an @samp{xz} tar archive of the distribution.  @command{xz}
8640 archives are frequently smaller than @command{bzip2}-compressed archives.
8641 By default, this rule makes @samp{xz} use a compression option of
8642 @option{-e}.  To make it use a different one, set the @env{XZ_OPT}
8643 environment variable.  For example, run this command to use the
8644 default compression ratio, but with a progress indicator:
8645 @samp{make dist-xz XZ_OPT=-7e}.
8646 @trindex dist-xz
8647
8648 @item @code{dist-zip}
8649 Generate a zip archive of the distribution.
8650 @trindex dist-zip
8651
8652 @item @code{dist-tarZ}
8653 Generate a compressed tar archive of
8654 the distribution.
8655 @trindex dist-tarZ
8656 @end table
8657
8658 The rule @code{dist} (and its historical synonym @code{dist-all}) will
8659 create archives in all the enabled formats, @ref{Options}.  By
8660 default, only the @code{dist-gzip} target is hooked to @code{dist}.
8661
8662
8663 @node Tests
8664 @chapter Support for test suites
8665
8666 @cindex Test suites
8667 @cindex @code{make check}
8668 @trindex check
8669
8670 Automake can generate code to handle two kinds of test suites.  One is
8671 based on integration with the @command{dejagnu} framework.  The other
8672 (and most used) form is based on the use of generic test scripts, and
8673 its activation is triggered by the definition of the special @code{TESTS}
8674 variable.  This second form allows for various degrees of sophistication
8675 and customization; in particular, it allows for concurrent execution
8676 of test scripts, use of established test protocols such as TAP, and
8677 definition of custom test drivers and test runners.
8678
8679 @noindent
8680 In either case, the testsuite is invoked via @samp{make check}.
8681
8682 @menu
8683 * Generalities about Testing::  Concepts and terminology about testing
8684 * Simple Tests::                Listing test scripts in @code{TESTS}
8685 * Custom Test Drivers::         Writing and using custom test drivers
8686 * Using the TAP test protocol:: Integrating test scripts that use the TAP protocol
8687 * DejaGnu Tests::               Interfacing with the @command{dejagnu} testing framework
8688 * Install Tests::               Running tests on installed packages
8689 @end menu
8690
8691 @node Generalities about Testing
8692 @section Generalities about Testing
8693
8694 The purpose of testing is to determine whether a program or system behaves
8695 as expected (e.g., known inputs produce the expected outputs, error
8696 conditions are correctly handled or reported, and older bugs do not
8697 resurface).
8698
8699 @cindex test case
8700 The minimal unit of testing is usually called @emph{test case}, or simply
8701 @emph{test}.  How a test case is defined or delimited, and even what
8702 exactly @emph{constitutes} a test case, depends heavily on the testing
8703 paradigm and/or framework in use, so we won't attempt any more precise
8704 definition.  The set of the test cases for a given program or system
8705 constitutes its @emph{testsuite}.
8706
8707 @cindex test harness
8708 @cindex testsuite harness
8709 A @emph{test harness} (also @emph{testsuite harness}) is a program or
8710 software component that executes all (or part of) the defined test cases,
8711 analyzes their outcomes, and report or register these outcomes
8712 appropriately.  Again, the details of how this is accomplished (and how
8713 the developer and user can influence it or interface with it) varies
8714 wildly, and we'll attempt no precise definition.
8715
8716 @cindex test pass
8717 @cindex test failure
8718 A test is said to @emph{pass} when it can determine that the condition or
8719 behaviour it means to verify holds, and is said to @emph{fail} when it can
8720 determine that such condition of behaviour does @emph{not} hold.
8721
8722 @cindex test skip
8723 Sometimes, tests can rely on non-portable tools or prerequisites, or
8724 simply make no sense on a given system (for example, a test checking a
8725 Windows-specific feature makes no sense on a GNU/Linux system).  In this
8726 case, accordingly to the definition above, the tests can neither be
8727 considered passed nor failed; instead, they are @emph{skipped} -- i.e.,
8728 they are not run, or their result is anyway ignored for what concerns
8729 the count of failures an successes.  Skips are usually explicitly
8730 reported though, so that the user will be aware that not all of the
8731 testsuite has really run.
8732
8733 @cindex xfail
8734 @cindex expected failure
8735 @cindex expected test failure
8736 @cindex xpass
8737 @cindex unexpected pass
8738 @cindex unexpected test pass
8739 It's not uncommon, especially during early development stages, that some
8740 tests fail for known reasons, and that the developer doesn't want to
8741 tackle these failures immediately (this is especially true when the
8742 failing tests deal with corner cases).  In this situation, the better
8743 policy is to declare that each of those failures is an @emph{expected
8744 failure} (or @emph{xfail}).  In case a test that is expected to fail ends
8745 up passing instead, many testing environments will flag the result as a
8746 special kind of failure called @emph{unexpected pass} (or @emph{xpass}).
8747
8748 @cindex hard error
8749 @cindex Distinction between errors and failures in testsuites
8750 Many testing environments and frameworks distinguish between test failures
8751 and hard errors.  As we've seen, a test failure happens when some invariant
8752 or expected behaviour of the software under test is not met.  An @emph{hard
8753 error} happens when e.g., the set-up of a test case scenario fails, or when
8754 some other unexpected or highly undesirable condition is encountered (for
8755 example, the program under test experiences a segmentation fault).
8756
8757 @emph{TODO}: Links to other test harnesses (esp. those sharing our
8758 terminology)?
8759
8760 @node Simple Tests
8761 @section Simple Tests
8762
8763 @menu
8764 * Scripts-based Testsuites::    Automake-specific concepts and terminology
8765 * Serial Test Harness::         Older (and obsolescent) serial test harness
8766 * Parallel Test Harness::       Generic concurrent test harness
8767 @end menu
8768
8769 @node Scripts-based Testsuites
8770 @subsection Scripts-based Testsuites
8771
8772 If the special variable @code{TESTS} is defined, its value is taken to be
8773 a list of programs or scripts to run in order to do the testing.  Under
8774 the appropriate circumstances, it's possible for @code{TESTS} to list
8775 also data files to be passed to one or more test scripts defined by
8776 different means (the so-called ``log compilers'', @pxref{Parallel Test
8777 Harness}).
8778
8779 Test scripts can be executed serially or concurrently.  Automake
8780 supports both these kinds of test execution, with the serial test harness
8781 being the default (for backward-compatibility reasons only, as its use
8782 is nowadays discouraged).  The concurrent test harness relies on the
8783 concurrence capabilities (if any) offered by the underlying @command{make}
8784 implementation, and can thus only be as good as those are.
8785
8786 By default, only the exit statuses of the test scripts are considered when
8787 determining the testsuite outcome.  But Automake allows also the use of
8788 more complex test protocols, either standard (@pxref{Using the TAP test
8789 protocol}) or custom (@pxref{Custom Test Drivers}).  Note that you can
8790 enable such protocols only when the parallel harness is used: they won't
8791 work with the serial test harness.  In the rest of this section we are
8792 going to concentrate mostly on protocol-less tests, since  we'll have later
8793 a whole section devoted to the use of test protocols (again, @pxref{Custom
8794 Test Drivers}).
8795
8796 @cindex Exit status 77, special interpretation
8797 @cindex Exit status 99, special interpretation
8798 When no test protocol is in use, an exit status of 0 from a test script will
8799 denote a success, an exit status of 77 a skipped test, an exit status of 99
8800 an hard error, and any other exit status will denote a failure.
8801
8802 @cindex Tests, expected failure
8803 @cindex Expected test failure
8804 @vindex XFAIL_TESTS
8805 @vindex DISABLE_HARD_ERRORS
8806 @cindex Disabling hard errors
8807 You may define the variable @code{XFAIL_TESTS} to a list of tests
8808 (usually a subset of @code{TESTS}) that are expected to fail; this will
8809 effectively reverse the result of those tests (with the provision that
8810 skips and hard errors remain untouched).  You may also instruct the
8811 testsuite harness to treat hard errors like simple failures, by defining
8812 the @code{DISABLE_HARD_ERRORS} make variable to a nonempty value.
8813
8814 Note however that, for tests based on more complex test protocols,
8815 the exact effects of @code{XFAIL_TESTS} and @code{DISABLE_HARD_ERRORS}
8816 might change, or they might even have no effect at all (for example,
8817 @c Keep this in sync with tap-no-disable-hard-errors.sh
8818 in tests using TAP, there is not way to disable hard errors, and the
8819 @code{DISABLE_HARD_ERRORS} variable has no effect on them).
8820
8821 @anchor{Testsuite progress on console}
8822 @cindex Testsuite progress on console
8823 The result of each test case run by the scripts in @code{TESTS} will be
8824 printed on standard output, along with the test name.  For test protocols
8825 that allow more test cases per test script (such as TAP), a number,
8826 identifier and/or brief description specific for the single test case is
8827 expected to be printed in addition to the name of the test script.  The
8828 possible results (whose meanings should be clear from the previous
8829 @ref{Generalities about Testing}) are @code{PASS}, @code{FAIL},
8830 @code{SKIP}, @code{XFAIL}, @code{XPASS} and @code{ERROR}.  Here is an
8831 example of output from an hypothetical testsuite that uses both plain
8832 and TAP tests:
8833 @c Keep in sync with tap-doc.sh
8834 @example
8835 PASS: foo.sh
8836 PASS: zardoz.tap 1 - Daemon started
8837 PASS: zardoz.tap 2 - Daemon responding
8838 SKIP: zardoz.tap 3 - Daemon uses /proc # SKIP /proc is not mounted
8839 PASS: zardoz.tap 4 - Daemon stopped
8840 SKIP: bar.sh
8841 PASS: mu.tap 1
8842 XFAIL: mu.tap 2 # TODO frobnication not yet implemented
8843 @end example
8844
8845 @noindent
8846 A testsuite summary (expected to report at least the number of run,
8847 skipped and failed tests) will be printed at the end of the testsuite
8848 run.
8849
8850 @anchor{Simple tests and color-tests}
8851 @vindex AM_COLOR_TESTS
8852 @cindex Colorized testsuite output
8853 If the Automake option @code{color-tests} is used (@pxref{Options})
8854 and standard output is connected to a capable terminal, then the test
8855 results and the summary are colored appropriately.  The user can disable
8856 colored output by setting the @command{make} variable
8857 @samp{AM_COLOR_TESTS=no}, or force colored output even without a connecting
8858 terminal with @samp{AM_COLOR_TESTS=always}.  It's also worth noting that
8859 some @command{make} implementations, when used in parallel mode, have
8860 slightly different semantics (@pxref{Parallel make,,, autoconf,
8861 The Autoconf Manual}), which can break the automatic detection of a
8862 connection to a capable terminal.  If this is the case, you'll have to
8863 resort to the use of @samp{AM_COLOR_TESTS=always} in order to have the
8864 testsuite output colorized.
8865
8866 Test programs that need data files should look for them in @code{srcdir}
8867 (which is both a make variable and an environment variable made available
8868 to the tests), so that they work when building in a separate directory
8869 (@pxref{Build Directories, , Build Directories , autoconf,
8870 The Autoconf Manual}), and in particular for the @code{distcheck} rule
8871 (@pxref{Checking the Distribution}).
8872
8873 @vindex TESTS
8874 @vindex TESTS_ENVIRONMENT
8875 @vindex AM_TESTS_ENVIRONMENT
8876 The @code{AM_TESTS_ENVIRONMENT} and @code{TESTS_ENVIRONMENT} variables can
8877 be used to run initialization code and set environment variables for the
8878 test scripts.  The former variable is developer-reserved, and can be
8879 defined in the @file{Makefile.am}, while the latter is reserved for the
8880 user, which can employ it to extend or override the settings in the
8881 former; for this to work portably, however, the contents of a non-empty
8882 @code{AM_TESTS_ENVIRONMENT} @emph{must} be terminated by a semicolon.
8883
8884 @vindex AM_TESTS_FD_REDIRECT
8885 The @code{AM_TESTS_FD_REDIRECT} variable can be used to define file
8886 descriptor redirections for the test scripts.  One might think that
8887 @code{AM_TESTS_ENVIRONMENT} could be used for this purpose, but experience
8888 has shown that doing so portably is practically impossible.  The main
8889 hurdle is constituted by Korn shells, which usually set the close-on-exec
8890 flag on file descriptors opened with the @command{exec} builtin, thus
8891 rendering an idiom like @code{AM_TESTS_ENVIRONMENT = exec 9>&2;}
8892 ineffectual.  This issue also affects some Bourne shells, such as the
8893 HP-UX's @command{/bin/sh},
8894 @c FIXME: should we offer a link to the relevant discussions on the
8895 @c bug-autoconf list?
8896
8897 @c Keep in sync with tests-environment-backcompat.sh
8898 @example
8899 AM_TESTS_ENVIRONMENT = \
8900 ## Some environment initializations are kept in a separate shell
8901 ## file `tests-env.sh', which can make it easier to also run tests
8902 ## from the command line.
8903   . $(srcdir)/tests-env.sh; \
8904 ## On Solaris, prefer more POSIX-compliant versions of the standard
8905 ## tools by default.
8906   if test -d /usr/xpg4/bin; then \
8907     PATH=/usr/xpg4/bin:$$PATH; export PATH; \
8908   fi;
8909 @c $$ restore font-lock
8910 ## With this, the test scripts will be able to print diagnostic
8911 ## messages to the original standard error stream, even if the test
8912 ## driver redirects the stderr of the test scripts to a log file
8913 ## before executing them.
8914 AM_TESTS_FD_REDIRECT = 9>&2
8915 @end example
8916
8917 @noindent
8918 Note however that @code{AM_TESTS_ENVIRONMENT} is, for historical and
8919 implementation reasons, @emph{not} supported by the serial harness
8920 (@pxref{Serial Test Harness}).
8921
8922 Automake ensures that each file listed in @code{TESTS} is built before
8923 it is run; you can list both source and derived programs (or scripts)
8924 in @code{TESTS}; the generated rule will look both in @code{srcdir} and
8925 @file{.}.  For instance, you might want to run a C program as a test.
8926 To do this you would list its name in @code{TESTS} and also in
8927 @code{check_PROGRAMS}, and then specify it as you would any other
8928 program.
8929
8930 Programs listed in @code{check_PROGRAMS} (and @code{check_LIBRARIES},
8931 @code{check_LTLIBRARIES}...) are only built during @code{make check},
8932 not during @code{make all}.  You should list there any program needed
8933 by your tests that does not need to be built by @code{make all}.  Note
8934 that @code{check_PROGRAMS} are @emph{not} automatically added to
8935 @code{TESTS} because @code{check_PROGRAMS} usually lists programs used
8936 by the tests, not the tests themselves.  Of course you can set
8937 @code{TESTS = $(check_PROGRAMS)} if all your programs are test cases.
8938
8939 @node Serial Test Harness
8940 @subsection Serial Test Harness
8941 @cindex @option{serial-tests}, Using
8942
8943 @emph{NOTE:} This harness, while still being the default one, is
8944 obsolescent, and kept mostly for backward-compatibility reasons.  The user
8945 is advised to use the parallel test harness instead (@pxref{Parallel Test
8946 Harness}).  Be warned that future Automake versions might switch to use
8947 that more modern and feature-rich harness by default.
8948
8949 The serial test harness is enabled by the Automake option
8950 @option{serial-tests}. It operates by simply running the tests serially,
8951 one at the time, without any I/O redirection.  It's up to the user to
8952 implement logging of tests' output, if that's requited or desired.
8953 @c TODO: give an example of how this can be done.
8954
8955 For historical and implementation reasons, the @code{AM_TESTS_ENVIRONMENT}
8956 variable is @emph{not} supported by this harness (it will be silently
8957 ignored if defined); only @code{TESTS_ENVIRONMENT} is, and it is to be
8958 considered a developer-reserved variable.  This is done so that, when
8959 using the serial harness, @code{TESTS_ENVIRONMENT} can be defined to an
8960 invocation of an interpreter through which the tests are to be run.
8961 For instance, the following setup may be used to run tests with Perl:
8962
8963 @example
8964 TESTS_ENVIRONMENT = $(PERL) -Mstrict -w
8965 TESTS = foo.pl bar.pl baz.pl
8966 @end example
8967
8968 @noindent
8969 It's important to note that the use of @code{TESTS_ENVIRONMENT} endorsed
8970 here would be @emph{invalid} with the parallel harness.  That harness
8971 provides a more elegant way to achieve the same effect, with the further
8972 benefit of freeing the @code{TESTS_ENVIRONMENT} variable for the user
8973 (@pxref{Parallel Test Harness}).
8974
8975 Another, less serious limit of the serial harness is that it doesn't
8976 really distinguish between simple failures and hard errors; this is
8977 due to historical reasons only, and might be fixed in future Automake
8978 versions.
8979
8980 @node Parallel Test Harness
8981 @subsection Parallel Test Harness
8982 @cindex @option{parallel-tests}, Using
8983
8984 The parallel (or concurrent) test harness is enabled by the Automake option
8985 @option{parallel-tests}.  It features automatic collection of the test
8986 scripts output in @file{.log} files, concurrent execution of tests with
8987 @code{make -j}, specification of inter-test dependencies, lazy reruns of
8988 tests that have not completed in a prior run, and hard errors for exceptional
8989 failures.
8990
8991 This harness is still somewhat experimental and may undergo changes in
8992 order to satisfy additional portability requirements.
8993
8994 @anchor{Basics of test metadata}
8995 @vindex TEST_SUITE_LOG
8996 @vindex TESTS
8997 @cindex @file{.log} files
8998 @cindex @file{.trs} files
8999 @cindex test metadata
9000 The parallel test harness operates by defining a set of @command{make}
9001 rules that run the test scripts listed in @code{TESTS}, and, for each
9002 such script, save its output in a corresponding @file{.log} file and
9003 its results (and other ``metadata'', @pxref{API for Custom Test Drivers})
9004 in a corresponding @file{.trs} (as in @b{T}est @b{R}e@b{S}ults) file.
9005 @c We choose the `.trs' extension also because, at the time of writing,
9006 @c it isn't already used for other significant purposes; see e.g.:
9007 @c   - http://filext.com/file-extension/trs
9008 @c   - http://www.file-extensions.org/search/?searchstring=trs
9009 The @file{.log} file will contain all the output emitted by the test on
9010 its standard output and its standard error.  The @file{.trs} file will
9011 contain, among the other things, the results of the test cases run by
9012 the script.
9013
9014 The parallel test harness will also create a summary log file,
9015 @code{TEST_SUITE_LOG}, which defaults to @file{test-suite.log} and requires
9016 a @file{.log} suffix.  This file depends upon all the @file{.log} and
9017 @file{.trs} files created for the test scripts listed in @code{TESTS}.
9018
9019 @vindex VERBOSE
9020 As with the serial harness above, by default one status line is printed
9021 per completed test, and a short summary after the suite has completed.
9022 However, standard output and standard error of the test are redirected
9023 to a per-test log file, so that parallel execution does not produce
9024 intermingled output.  The output from failed tests is collected in the
9025 @file{test-suite.log} file.  If the variable @samp{VERBOSE} is set, this
9026 file is output after the summary.
9027 @c FIXME: we should be clearer about what we mean exactly here ...
9028 For best results, the tests should be verbose by default now.
9029
9030 @vindex TEST_EXTENSIONS
9031 @vindex TEST_LOGS
9032 Each couple of @file{.log} and @file{.trs} files is created when the
9033 corresponding test has completed.  The set of log files is listed in
9034 the read-only variable @code{TEST_LOGS}, and defaults to @code{TESTS},
9035 with the executable extension if any (@pxref{EXEEXT}), as well as any
9036 suffix listed in @code{TEST_EXTENSIONS} removed, and @file{.log} appended.
9037 Results are undefined if a test file name ends in several concatenated
9038 suffixes.  @code{TEST_EXTENSIONS} defaults to @file{.test}; it can be
9039 overridden by the user, in which case any extension listed in it must be
9040 constituted by a dot, followed by a non-digit alphabetic character,
9041 followed by any number of alphabetic characters.
9042 @c Keep in sync with test-extensions.sh
9043 For example, @samp{.sh}, @samp{.T} and @samp{.t1} are valid extensions,
9044 while @samp{.x-y}, @samp{.6c} and @samp{.t.1} are not.
9045
9046 @vindex _LOG_COMPILE
9047 @vindex _LOG_COMPILER
9048 @vindex _LOG_FLAGS
9049 @vindex LOG_COMPILE
9050 @vindex LOG_COMPILER
9051 @vindex LOG_FLAGS
9052 @vindex @var{ext}_LOG_COMPILE
9053 @vindex @var{ext}_LOG_COMPILER
9054 @vindex @var{ext}_LOG_FLAGS
9055 @vindex AM_@var{ext}_LOG_FLAGS
9056 @vindex AM_LOG_FLAGS
9057 For tests that match an extension @code{.@var{ext}} listed in
9058 @code{TEST_EXTENSIONS}, you can provide a custom ``test runner'' using
9059 the variable @code{@var{ext}_LOG_COMPILER} (note the upper-case
9060 extension) and pass options in @code{AM_@var{ext}_LOG_FLAGS} and allow
9061 the user to pass options in @code{@var{ext}_LOG_FLAGS}.  It will cause
9062 all tests with this extension to be called with this runner.  For all
9063 tests without a registered extension, the variables @code{LOG_COMPILER},
9064 @code{AM_LOG_FLAGS}, and @code{LOG_FLAGS} may be used.  For example,
9065
9066 @c Keep in sync with parallel-tests-log-compiler-example.sh
9067 @example
9068 TESTS = foo.pl bar.py baz
9069 TEST_EXTENSIONS = .pl .py
9070 PL_LOG_COMPILER = $(PERL)
9071 AM_PL_LOG_FLAGS = -w
9072 PY_LOG_COMPILER = $(PYTHON)
9073 AM_PY_LOG_FLAGS = -v
9074 LOG_COMPILER = ./wrapper-script
9075 AM_LOG_FLAGS = -d
9076 @end example
9077
9078 @noindent
9079 will invoke @samp{$(PERL) -w foo.pl}, @samp{$(PYTHON) -v bar.py},
9080 and @samp{./wrapper-script -d baz} to produce @file{foo.log},
9081 @file{bar.log}, and @file{baz.log}, respectively.  The @file{foo.trs},
9082 @file{bar.trs} and @file{baz.trs} files will be automatically produced
9083 as a side-effect.
9084
9085 It's important to note that, differently from what we've seen for the
9086 serial test harness (@pxref{Parallel Test Harness}), the
9087 @code{AM_TESTS_ENVIRONMENT} and @code{TESTS_ENVIRONMENT} variables
9088 @emph{cannot} be use to define a custom test runner; the
9089 @code{LOG_COMPILER} and @code{LOG_FLAGS} (or their extension-specific
9090 counterparts) should be used instead:
9091
9092 @example
9093 ## This is WRONG!
9094 AM_TESTS_ENVIRONMENT = PERL5LIB='$(srcdir)/lib' $(PERL) -Mstrict -w
9095 @end example
9096
9097 @example
9098 ## Do this instead.
9099 AM_TESTS_ENVIRONMENT = PERL5LIB='$(srcdir)/lib'; export PERL5LIB;
9100 LOG_COMPILER = $(PERL)
9101 AM_LOG_FLAGS = -Mstrict -w
9102 @end example
9103
9104 By default, the test suite harness will run all tests, but there are
9105 several ways to limit the set of tests that are run:
9106
9107 @itemize @bullet
9108 @item
9109 You can set the @code{TESTS} variable.  For example, you can use a
9110 command like this to run only a subset of the tests:
9111
9112 @example
9113 env TESTS="foo.test bar.test" make -e check
9114 @end example
9115
9116 Note however that the command above will unconditionally overwrite the
9117 @file{test-suite.log} file, thus clobbering the recorded results
9118 of any previous testsuite run.  This might be undesirable for packages
9119 whose testsuite takes long time to execute.  Luckily, this problem can
9120 easily be avoided by overriding also @code{TEST_SUITE_LOG} at runtime;
9121 for example,
9122
9123 @c Keep in sync with parallel-tests-log-override-2.sh
9124 @example
9125 env TEST_SUITE_LOG=partial.log TESTS="..." make -e check
9126 @end example
9127
9128 will write the result of the partial testsuite runs to the
9129 @file{partial.log}, without touching @file{test-suite.log}.
9130
9131 @item
9132 You can set the @code{TEST_LOGS} variable.  By default, this variable is
9133 computed at @command{make} run time from the value of @code{TESTS} as
9134 described above.  For example, you can use the following:
9135
9136 @example
9137 set x subset*.log; shift
9138 env TEST_LOGS="foo.log $*" make -e check
9139 @end example
9140
9141 The comments made above about @code{TEST_SUITE_LOG} overriding applies
9142 here too.
9143
9144 @item
9145 @vindex RECHECK_LOGS
9146 @cindex lazy test execution
9147 By default, the test harness removes all old per-test @file{.log} and
9148 @file{.trs} files before it starts running tests to regenerate them.  The
9149 variable @code{RECHECK_LOGS} contains the set of @file{.log} (and, by
9150 implication, @file{.trs}) files which are removed.  @code{RECHECK_LOGS}
9151 defaults to @code{TEST_LOGS}, which means all tests need to be rechecked.
9152 By overriding this variable, you can choose which tests need to be
9153 reconsidered.  For example, you can lazily rerun only those tests which
9154 are outdated, i.e., older than their prerequisite test files, by setting
9155 this variable to the empty value:
9156
9157 @example
9158 env RECHECK_LOGS= make -e check
9159 @end example
9160
9161 @item
9162 @trindex recheck
9163 You can ensure that all tests are rerun which have failed or passed
9164 unexpectedly, by running @code{make recheck} in the test directory.
9165 This convenience target will set @code{RECHECK_LOGS} appropriately
9166 before invoking the main test harness.
9167 @end itemize
9168
9169 @noindent
9170 In order to guarantee an ordering between tests even with @code{make
9171 -j@var{N}}, dependencies between the corresponding @file{.log} files
9172 may be specified through usual @command{make} dependencies.  For example,
9173 the following snippet lets the test named @file{foo-execute.test} depend
9174 upon completion of the test @file{foo-compile.test}:
9175
9176 @example
9177 TESTS = foo-compile.test foo-execute.test
9178 foo-execute.log: foo-compile.log
9179 @end example
9180
9181 @noindent
9182 Please note that this ordering ignores the @emph{results} of required
9183 tests, thus the test @file{foo-execute.test} is run even if the test
9184 @file{foo-compile.test} failed or was skipped beforehand.  Further,
9185 please note that specifying such dependencies currently works only for
9186 tests that end in one of the suffixes listed in @code{TEST_EXTENSIONS}.
9187
9188 Tests without such specified dependencies may be run concurrently with
9189 parallel @command{make -j@var{N}}, so be sure they are prepared for
9190 concurrent execution.
9191
9192 @cindex Unit tests
9193 @c Keep in sync with 'parallel-tests-extra-programs.test'.
9194 The combination of lazy test execution and correct dependencies between
9195 tests and their sources may be exploited for efficient unit testing
9196 during development.  To further speed up the edit-compile-test cycle, it
9197 may even be useful to specify compiled programs in @code{EXTRA_PROGRAMS}
9198 instead of with @code{check_PROGRAMS}, as the former allows intertwined
9199 compilation and test execution (but note that @code{EXTRA_PROGRAMS} are
9200 not cleaned automatically, @pxref{Uniform}).
9201
9202 The variables @code{TESTS} and @code{XFAIL_TESTS} may contain
9203 conditional parts as well as configure substitutions.  In the latter
9204 case, however, certain restrictions apply: substituted test names
9205 must end with a nonempty test suffix like @file{.test}, so that one of
9206 the inference rules generated by @command{automake} can apply.  For
9207 literal test names, @command{automake} can generate per-target rules
9208 to avoid this limitation.
9209
9210 Please note that it is currently not possible to use @code{$(srcdir)/}
9211 or @code{$(top_srcdir)/} in the @code{TESTS} variable.  This technical
9212 limitation is necessary to avoid generating test logs in the source tree
9213 and has the unfortunate consequence that it is not possible to specify
9214 distributed tests that are themselves generated by means of explicit
9215 rules, in a way that is portable to all @command{make} implementations
9216 (@pxref{Make Target Lookup,,, autoconf, The Autoconf Manual}, the
9217 semantics of FreeBSD and OpenBSD @command{make} conflict with this).
9218 In case of doubt you may want to require to use GNU @command{make},
9219 or work around the issue with inference rules to generate the tests.
9220
9221 @node Custom Test Drivers
9222 @section Custom Test Drivers
9223
9224 @menu
9225 * Overview of Custom Test Drivers Support::
9226 * Declaring Custom Test Drivers::
9227 * API for Custom Test Drivers::
9228 @end menu
9229
9230 @node Overview of Custom Test Drivers Support
9231 @subsection Overview of Custom Test Drivers Support
9232
9233 Starting from Automake version 1.12, the parallel test harness allows
9234 the package authors to use third-party custom test drivers, in case the
9235 default ones are inadequate for their purposes, or do not support their
9236 testing protocol of choice.
9237
9238 A custom test driver is expected to properly run the test programs passed
9239 to it (including the command-line arguments passed to those programs, if
9240 any), to analyze their execution and outcome, to create the @file{.log}
9241 and @file{.trs} files associated to these test runs, and to display the test
9242 results on the console. It is responsibility of the author of the test
9243 driver to ensure that it implements all the above steps meaningfully and
9244 correctly; Automake isn't and can't be of any help here.  On the other
9245 hand, the Automake-provided code for testsuite summary generation offers
9246 support for test drivers allowing several test results per test script,
9247 if they take care to register such results properly (@pxref{Log files
9248 generation and test results recording}).
9249
9250 The exact details of how test scripts' results are to be determined and
9251 analyzed is left to the individual drivers.  Some drivers might only
9252 consider the test script exit status (this is done for example by the
9253 default test driver used by the parallel test harness, described
9254 in the previous section).  Other drivers might implement more complex and
9255 advanced test protocols, which might require them to parse and interpreter
9256 the output emitted by the test script they're running (examples of such
9257 protocols are TAP and SubUnit).
9258
9259 It's very important to note that, even when using custom test drivers,
9260 most of the infrastructure described in the previous section about the
9261 parallel harness remains in place; this includes:
9262
9263 @itemize
9264 @item
9265 list of test scripts defined in @code{TESTS}, and overridable at
9266 runtime through the redefinition of @code{TESTS} or @code{TEST_LOGS};
9267 @item
9268 concurrency through the use of @command{make}'s option @option{-j};
9269 @item
9270 per-test @file{.log} and @file{.trs} files, and generation of a summary
9271 @file{.log} file from them;
9272 @item
9273 @code{recheck} target, @code{RECHECK_LOGS} variable, and lazy reruns
9274 of tests;
9275 @item
9276 inter-test dependencies;
9277 @item
9278 support for @code{check_*} variables (@code{check_PROGRAMS},
9279 @code{check_LIBRARIES}, ...);
9280 @item
9281 use of @code{VERBOSE} environment variable to get verbose output on
9282 testsuite failures;
9283 @item
9284 definition and honoring of @code{TESTS_ENVIRONMENT},
9285 @code{AM_TESTS_ENVIRONMENT} and @code{AM_TESTS_FD_REDIRECT}
9286 variables;
9287 @item
9288 definition of generic and extension-specific @code{LOG_COMPILER} and
9289 @code{LOG_FLAGS} variables.
9290 @end itemize
9291
9292 @noindent
9293 On the other hand, the exact semantics of how (and if)
9294 @option{color-tests}, @code{XFAIL_TESTS}, and hard errors are supported
9295 and handled is left to the individual test drivers.
9296
9297 @c TODO: We should really add a working example in the doc/ directory,
9298 @c TODO: and reference if from here.
9299
9300 @node Declaring Custom Test Drivers
9301 @subsection Declaring Custom Test Drivers
9302
9303 @vindex _LOG_DRIVER
9304 @vindex _LOG_DRIVER_FLAGS
9305 @vindex LOG_DRIVER
9306 @vindex LOG_DRIVER_FLAGS
9307 @vindex @var{ext}_LOG_DRIVER
9308 @vindex @var{ext}_LOG_DRIVER_FLAGS
9309 @vindex AM_@var{ext}_LOG_DRIVER_FLAGS
9310 @vindex AM_LOG_DRIVER_FLAGS
9311 Custom testsuite drivers are declared by defining the make variables
9312 @code{LOG_DRIVER} or @code{@var{ext}_LOG_DRIVER} (where @var{ext} must
9313 be declared in @code{TEST_EXTENSIONS}).  They must be defined to
9314 programs or scripts that will be used to drive the execution, logging,
9315 and outcome report of the tests with corresponding extensions (or of
9316 those with no registered extension in the case of @code{LOG_DRIVER}).
9317 Clearly, multiple distinct test drivers can be declared in the same
9318 @file{Makefile.am}.  Note moreover that the @code{LOG_DRIVER} variables
9319 are @emph{not} a substitute for the @code{LOG_COMPILER} variables: the
9320 two sets of variables can, and often do, usefully and legitimately
9321 coexist.
9322
9323 @c TODO: We should really be able to point to a clarifying example here!
9324
9325 The developer-reserved variable @code{AM_LOG_DRIVER_FLAGS} and the
9326 user-reserved variable @code{LOG_DRIVER_FLAGS} can be used to define
9327 flags that will be passed to each invocation of @code{LOG_DRIVER},
9328 with the user-defined flags obviously taking precedence over the
9329 developer-reserved ones.  Similarly, for each extension @var{ext}
9330 declared in @code{TEST_EXTENSIONS}, flags listed in
9331 @code{AM_@var{ext}_LOG_DRIVER_FLAGS} and
9332 @code{@var{ext}_LOG_DRIVER_FLAGS} will be passed to
9333 invocations of @code{@var{ext}_LOG_DRIVER}.
9334
9335 @node API for Custom Test Drivers
9336 @subsection API for Custom Test Drivers
9337
9338 Note that @emph{the APIs described here are still highly experimental},
9339 and will very likely undergo tightenings and likely also extensive changes
9340 in the future, to accommodate for new features or to satisfy additional
9341 portability requirements.
9342
9343 The main characteristic of these APIs is that they are designed to share
9344 as much infrastructure, semantics, and implementation details as possible
9345 with the parallel test harness and its default driver.
9346
9347 @menu
9348 * Command-line arguments for test drivers::
9349 * Log files generation and test results recording::
9350 * Testsuite progress output::
9351 @end menu
9352
9353 @node Command-line arguments for test drivers
9354 @subsubsection Command-line arguments for test drivers
9355
9356 A custom driver can rely on various command-line options and arguments
9357 being passed to it automatically by the Automake's @option{parallel-tests}
9358 harness.  It is @emph{mandatory} that it understands all of them (even
9359 if the exact interpretation of the associated semantics can legitimately
9360 change between a test driver and another, and even be a no-op in some
9361 drivers).
9362
9363 @noindent
9364 Here is the list of options:
9365
9366 @table @option
9367 @item --test-name=@var{NAME}
9368 The name of the test, with VPATH prefix (if any) removed.  This can have a
9369 suffix and a directory component (as in e.g., @file{sub/foo.test}), and is
9370 mostly meant to be used in console reports about testsuite advancements and
9371 results (@pxref{Testsuite progress output}).
9372 @item --log-file=@file{@var{PATH}.log}
9373 The @file{.log} file the test driver must create (@pxref{Basics of
9374 test metadata}).  If it has a directory component (as in e.g.,
9375 @file{sub/foo.log}), the test harness will ensure that such directory
9376 exists @emph{before} the test driver is called.
9377 @item --trs-file=@file{@var{PATH}.trs}
9378 The @file{.trs} file the test driver must create (@pxref{Basics of
9379 test metadata}).  If it has a directory component (as in e.g.,
9380 @file{sub/foo.trs}), the test harness will ensure that such directory
9381 exists @emph{before} the test driver is called.
9382 @item --color-tests=@{yes|no@}
9383 Whether the console output should be colorized or not (@pxref{Simple
9384 tests and color-tests}, to learn when this option gets activated and
9385 when it doesn't).
9386 @item --expect-failure=@{yes|no@}
9387 Whether the tested program is expected to fail.
9388 @item --enable-hard-errors=@{yes|no@}
9389 Whether ``hard errors'' in the tested program should be treated differently
9390 from normal failures or not (the default should be @code{yes}).  The exact
9391 meaning of ``hard error'' is highly dependent from the test protocols or
9392 conventions in use.
9393 @item --
9394 Explicitly terminate the list of options.
9395 @end table
9396
9397 @noindent
9398 The first non-option argument passed to the test driver is the program to
9399 be run, and all the following ones are command-line options and arguments
9400 for this program.
9401
9402 Note that the exact semantics attached to the @option{--color-tests},
9403 @option{--expect-failure} and @option{--enable-hard-errors} options are
9404 left up to the individual test drivers.  Still, having a behaviour
9405 compatible or at least similar to that provided by the default
9406 @option{parallel-tests} driver is advised, as that would offer a better
9407 consistency and a more pleasant user experience.
9408
9409 @node Log files generation and test results recording
9410 @subsubsection Log files generation and test results recording
9411
9412 The test driver must correctly generate the files specified by the
9413 @option{--log-file} and @option{--trs-file} option (even when the tested
9414 program fails or crashes).
9415
9416 The @file{.log} file should ideally contain all the output produced by the
9417 tested program, plus optionally other information that might facilitate
9418 debugging or analysis of bug reports.  Apart from that, its format is
9419 basically free.
9420
9421 The @file{.trs} file is used to register some metadata through the use
9422 of custom reStructuredText fields.  This metadata is expected to be
9423 employed in various ways by the parallel test harness; for example, to
9424 count the test results when printing the testsuite summary, or to decide
9425 which tests to re-run upon @command{make reheck}.  Unrecognized metadata
9426 in a @file{.trs} file is currently ignored by the harness, but this might
9427 change in the future. The list of currently recognized metadata follows.
9428
9429 @table @code
9430
9431 @item :test-result:
9432 @cindex Register test result
9433 @cindex Register test case result
9434 @cindex Test result, registering
9435 @cindex Test case result, registering
9436 @cindex @code{:test-result:}
9437 @cindex reStructuredText field, @code{:test-result:}
9438 The test driver must use this field to register the results of @emph{each}
9439 test case run by a test script file.  Several @code{:test-result:} fields
9440 can be present in the same @file{.trs} file; this is done in order to
9441 support test protocols that allow a single test script to run more test
9442 cases.
9443
9444 @c Keep this in sync with lib/am/check-am:$(TEST_SUITE_LOG).
9445 The only recognized test results are currently @code{PASS}, @code{XFAIL},
9446 @code{SKIP}, @code{FAIL}, @code{XPASS} and @code{ERROR}.  These results,
9447 when declared with @code{:test-result:}, can be optionally followed by
9448 text holding the name and/or a brief description of the corresponding
9449 test; the @option{parallel-tests} harness will ignore such extra text when
9450 generating @file{test-suite.log} and preparing the testsuite summary.
9451
9452 @c Keep in sync with 'test-metadata-recheck.test'.
9453 @item @code{:recheck:}
9454 @cindex :recheck:
9455 @cindex reStructuredText field, @code{:recheck:}
9456 If this field is present and defined to @code{no}, then the corresponding
9457 test script will @emph{not} be run upon a @command{make recheck}.  What
9458 happens when two or more @code{:recheck:} fields are present in the same
9459 @file{.trs} file is undefined behaviour.
9460
9461 @c Keep in sync with 'test-metadata-global-log.test'.
9462 @item @code{:copy-in-global-log:}
9463 @cindex :copy-in-global-log:
9464 @cindex reStructuredText field, @code{:copy-in-global-log:}
9465 If this field is present and defined to @code{no}, then the content
9466 of the @file{.log} file will @emph{not} be copied into the global
9467 @file{test-suite.log}.  We allow to forsake such copying because, while
9468 it can be useful in debugging and analysis of bug report, it can also be
9469 just a waste of space in normal situations, e.g., when a test script is
9470 successful.  What happens when two or more @code{:copy-in-global-log:}
9471 fields are present in the same @file{.trs} file is undefined behaviour.
9472
9473 @c Keep in sync with 'test-metadata-global-result.test'.
9474 @item @code{:test-global-result:}
9475 @cindex :test-global-result:
9476 @cindex reStructuredText field, @code{:test-global-result:}
9477 This is used to declare the "global result" of the script.  Currently,
9478 the value of this field is needed only to be reported (more or less
9479 verbatim) in the generated global log file @code{$(TEST_SUITE_LOG)},
9480 so it's quite free-form.  For example, a test script which run 10 test
9481 cases, 6 of which pass and 4 of which are skipped, could reasonably have
9482 a @code{PASS/SKIP} value for this field, while a test script which run
9483 19 successful tests and one failed test could have an @code{ALMOST
9484 PASSED} value.  What happens when two or more @code{:test-global-result:}
9485 fields are present in the same @file{.trs} file is undefined behaviour.
9486 @end table
9487
9488 @noindent
9489 Let's see a small example.  Assume a @file{.trs} file contains the
9490 following lines:
9491
9492 @example
9493 :test-result: PASS server starts
9494 :global-log-copy: no
9495 :test-result: PASS HTTP/1.1 request
9496 :test-result: FAIL HTTP/1.0 request
9497 :recheck: yes
9498 :test-result: SKIP HTTPS request (TLS library wasn't available)
9499 :test-result: PASS server stops
9500 @end example
9501
9502 @noindent
9503 Then the corresponding test script will be re-run by @command{make check},
9504 will contribute with @emph{five} test results to the testsuite summary
9505 (three of these tests being successful, one failed, and one skipped), and
9506 the content of the corresponding @file{.log} file will @emph{not} be
9507 copied in the global log file @file{test-suite.log}.
9508
9509 @node Testsuite progress output
9510 @subsubsection Testsuite progress output
9511
9512 A custom test driver also has the task of displaying, on the standard
9513 output, the test results as soon as they become available.  Depending on
9514 the protocol in use, it can also display the reasons for failures and
9515 skips, and, more generally, any useful diagnostic output (but remember
9516 that each line on the screen is precious, so that cluttering the screen
9517 with overly verbose information is bad idea).  The exact format of this
9518 progress output is left up to the test driver; in fact, a custom test
9519 driver might @emph{theoretically} even decide not to do any such report,
9520 leaving it all to the testsuite summary (that would be a very lousy idea,
9521 of course, and serves only to illustrate the flexibility that is
9522 granted here).
9523
9524 Remember that consistency is good; so, if possible, try to be consistent
9525 with the output of the built-in Automake test drivers, providing a similar
9526 ``look & feel''.  In particular, the testsuite progress output should be
9527 colorized when the @option{--color-tests} is passed to the driver.  On the
9528 other end, if you are using a known and widespread test protocol with
9529 well-established implementations, being consistent with those
9530 implementations' output might be a good idea too.
9531
9532 @c TODO: Give an example, maybe inspired to py.test-style output.
9533 @c TODO: That is a good idea because it shows a test driver that allows
9534 @c TODO: for different levels of verbosity in the progress output (could
9535 @c TODO: be implemented either using a driver cmdline flag, or an
9536 @c TODO: environment variable, or both).
9537
9538 @node Using the TAP test protocol
9539 @section Using the TAP test protocol
9540
9541 @menu
9542 * Introduction to TAP::
9543 * Use TAP with the Automake test harness::
9544 * Incompatibilities with other TAP parsers and drivers::
9545 * Links and external resources on TAP::
9546 @end menu
9547
9548 @node Introduction to TAP
9549 @subsection Introduction to TAP
9550
9551 TAP, the Test Anything Protocol, is a simple text-based interface between
9552 testing modules or programs and a test harness.  The tests (also called
9553 ``TAP producers'' in this context) write test results in a simple format
9554 on standard output; a test harness (also called ``TAP consumer'') will
9555 parse and interpret these results, and properly present them to the user,
9556 and/or register them for later analysis.  The exact details of how this
9557 is accomplished can vary among different test harnesses.  The Automake
9558 parallel harness will present the results on the console in the usual
9559 fashion (@pxref{Testsuite progress on console}), and will use the
9560 @file{.trs} files (@pxref{Basics of test metadata}) to store the test
9561 results and related metadata.  Apart from that, it will try to remain
9562 as much compatible as possible with pre-existing and widespread utilities,
9563 such as the @uref{http://search.cpan.org/~andya/Test-Harness/bin/prove,
9564 @command{prove} utility}, at least for the simpler usages.
9565
9566 TAP started its life as part of the test harness for Perl, but today
9567 it has been (mostly) standardized, and has various independent
9568 implementations in different languages; among them, C, C++, Perl,
9569 Python, PHP, and Java.  For a semi-official specification of the
9570 TAP protocol, please refer to the documentation of
9571 @uref{http://search.cpan.org/~petdance/Test-Harness/lib/Test/Harness/TAP.pod,
9572       @samp{Test::Harness::TAP}}.
9573
9574 The most relevant real-world usages of TAP are obviously in the testsuites
9575 of @command{perl} and of many perl modules.  Still, also other important
9576 third-party packages, such as @uref{http://git-scm.com/, @command{git}},
9577 use TAP in their testsuite.
9578
9579 @node Use TAP with the Automake test harness
9580 @subsection Use TAP with the Automake test harness
9581
9582 Currently, the TAP driver that comes with Automake requires some by-hand
9583 steps on the developer's part (this situation should hopefully be improved
9584 in future Automake versions).  You'll have to grab the @file{tap-driver.sh}
9585 script from the Automake distribution by hand, copy it in your source tree,
9586 add a call to @code{AC_PROG_AWK} in @file{configure.ac} to search for a
9587 proper awk program, and use the Automake support for third-party test
9588 drivers to instruct the harness to use the @file{tap-driver.sh} script
9589 and that awk program to run your TAP-producing tests.  See the example
9590 below for clarification.
9591
9592 Apart from the options common to all the Automake test drivers
9593 (@pxref{Command-line arguments for test drivers}), the @file{tap-driver.sh}
9594 supports the following options, whose names are chosen for enhanced
9595 compatibility with the @command{prove} utility.
9596
9597 @table @option
9598 @c Keep in sync with 'tap-exit.test' and 'tap-signal.tap'.
9599 @item --ignore-exit
9600 Causes the test driver to ignore the exit status of the test scripts;
9601 by default, the driver will report an error if the script exits with a
9602 non-zero status.  This option has effect also on non-zero exit statuses
9603 due to termination by a signal.
9604 @item --comments
9605 Instruct the test driver to display TAP diagnostic (i.e., lines beginning
9606 with the @samp{#} character) in the testsuite progress output too; by
9607 default, TAP diagnostic is only copied to the @file{.log} file.
9608 @item --no-comments
9609 Revert the effects of @option{--comments}.
9610 @item --merge
9611 Instruct the test driver to merge the test scripts' standard error into
9612 their standard output.  This is necessary if you want to ensure that
9613 diagnostics from the test scripts are displayed in the correct order
9614 relative to test results; this can be of great help in debugging
9615 (especially if your test scripts are shell scripts run with shell
9616 tracing active).  As a downside, this option might cause the test
9617 harness to get confused if anything that appears on standard error
9618 looks like a test result.
9619 @item --no-merge
9620 Revert the effects of @option{--merge}.
9621 @item --diagnostic-string=@var{STRING}
9622 Change the string that introduces TAP diagnostic from the default value
9623 of ``@code{#}'' to @code{@var{STRING}}.  This can be useful if your
9624 TAP-based test scripts produce verbose output on which they have limited
9625 control (because, say, the output comes from other tools invoked in the
9626 scripts), and it might contain text that gets spuriously interpreted as
9627 TAP diagnostic: such an issue can be solved by redefining the string that
9628 activates TAP diagnostic to a value you know won't appear by chance in
9629 the tests' output.  Note however that this feature is non-standard, as
9630 the ``official'' TAP protocol does not allow for such a customization; so
9631 don't use it if you can avoid it.
9632 @end table
9633
9634 @noindent
9635 Here is an example of how the TAP driver can be set up and used.
9636
9637 @c Keep in sync with tap-doc2.sh
9638 @example
9639 % @kbd{cat configure.ac}
9640 AC_INIT([GNU Try Tap], [1.0], [bug-automake@@gnu.org])
9641 AC_CONFIG_AUX_DIR([build-aux])
9642 AM_INIT_AUTOMAKE([foreign parallel-tests -Wall -Werror])
9643 AC_CONFIG_FILES([Makefile])
9644 AC_REQUIRE_AUX_FILE([tap-driver.sh])
9645 AC_PROG_AWK
9646 AC_OUTPUT
9647
9648 % @kbd{cat Makefile.am}
9649 TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
9650                   $(top_srcdir)/build-aux/tap-driver.sh
9651 TESTS = foo.test bar.test baz.test
9652 EXTRA_DIST = $(TESTS)
9653
9654 % @kbd{cat foo.test}
9655 #!/bin/sh
9656 echo 1..4 # Number of tests to be executed.
9657 echo 'ok 1 - Swallows fly'
9658 echo 'not ok 2 - Caterpillars fly # TODO metamorphosis in progress'
9659 echo 'ok 3 - Pigs fly # SKIP not enough acid'
9660 echo '# I just love word plays ...'
9661 echo 'ok 4 - Flies fly too :-)'
9662
9663 % @kbd{cat bar.test}
9664 #!/bin/sh
9665 echo 1..3
9666 echo 'not ok 1 - Bummer, this test has failed.'
9667 echo 'ok 2 - This passed though.'
9668 echo 'Bail out! Ennui kicking in, sorry...'
9669 echo 'ok 3 - This will not be seen.'
9670
9671 % @kbd{cat baz.test}
9672 #!/bin/sh
9673 echo 1..1
9674 echo ok 1
9675 # Exit with error, even if all the tests have been successful.
9676 exit 7
9677
9678 % @kbd{cp @var{PREFIX}/share/automake-@var{APIVERSION}/tap-driver.pl .}
9679 % @kbd{autoreconf -vi && ./configure && make check}
9680 ...
9681 PASS: foo.test 1 - Swallows fly
9682 XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
9683 SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
9684 PASS: foo.test 4 - Flies fly too :-)
9685 FAIL: bar.test 1 - Bummer, this test has failed.
9686 PASS: bar.test 2 - This passed though.
9687 ERROR: bar.test - Bail out! Ennui kicking in, sorry...
9688 PASS: baz.test 1
9689 ERROR: baz.test - exited with status 7
9690 ...
9691 Please report to bug-automake@@gnu.org
9692 ...
9693 % @kbd{echo exit status: $?}
9694 exit status: 1
9695
9696 @c Keep the "skewed" indentation below, it produces pretty PDF output.
9697 % @kbd{env TEST_LOG_DRIVER_FLAGS='--comments --ignore-exit' \
9698       TESTS='foo.test baz.test' make -e check}
9699 ...
9700 PASS: foo.test 1 - Swallows fly
9701 XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
9702 SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
9703 # foo.test: I just love word plays...
9704 PASS: foo.test 4 - Flies fly too :-)
9705 PASS: baz.test 1
9706 ...
9707 % @kbd{echo exit status: $?}
9708 exit status: 0
9709 @end example
9710
9711 @node Incompatibilities with other TAP parsers and drivers
9712 @subsection Incompatibilities with other TAP parsers and drivers
9713
9714 For implementation or historical reasons, the TAP driver and harness as
9715 implemented by Automake have some minors incompatibilities with the
9716 mainstream versions, which you should be aware of.
9717
9718 @itemize @bullet
9719 @item
9720 A @code{Bail out!} directive doesn't stop the whole testsuite, but only
9721 the test script it occurs in.  This doesn't follow TAP specifications,
9722 but on the other hand it maximizes compatibility (and code sharing) with
9723 the ``hard error'' concept of the default @option{parallel-tests} driver.
9724 @item
9725 The @code{version} and @code{pragma} directives are not supported.
9726 @item
9727 The @option{--diagnostic-string} option of our driver allows to modify
9728 the string that introduces TAP diagnostic from the default value
9729 of ``@code{#}''.  The standard TAP protocol has currently no way to
9730 allow this, so if you use it your diagnostic will be lost to more
9731 compliant tools like @command{prove} and @code{Test::Harness}
9732 @item
9733 And there are probably some other small and yet undiscovered
9734 incompatibilities, especially in corner cases or with rare usages.
9735 @end itemize
9736
9737 @node Links and external resources on TAP
9738 @subsection Links and external resources on TAP
9739
9740 @noindent
9741 Here are some links to more extensive official or third-party
9742 documentation and resources about the TAP protocol and related
9743 tools and libraries.
9744 @itemize @bullet
9745 @item
9746 @uref{http://search.cpan.org/~petdance/Test-Harness/lib/Test/Harness/TAP.pod,
9747       @samp{Test::Harness::TAP}},
9748 the (mostly) official documentation about the TAP format and protocol.
9749 @item
9750 @uref{http://search.cpan.org/~andya/Test-Harness/bin/prove,
9751       @command{prove}},
9752 the most famous command-line TAP test driver, included in the distribution
9753 of @command{perl} and
9754 @uref{http://search.cpan.org/~andya/Test-Harness/lib/Test/Harness.pm,
9755       @samp{Test::Harness}}.
9756 @item
9757 The @uref{http://testanything.org/wiki/index.php/Main_Page,TAP wiki}.
9758 @item
9759 A ``gentle introduction'' to testing for perl coders:
9760 @uref{http://search.cpan.org/dist/Test-Simple/lib/Test/Tutorial.pod,
9761       @samp{Test::Tutorial}}.
9762 @item
9763 @uref{http://search.cpan.org/~mschwern/Test-Simple/lib/Test/Simple.pm,
9764       @samp{Test::Simple}}
9765 and
9766 @uref{http://search.cpan.org/~mschwern/Test-Simple/lib/Test/More.pm,
9767       @samp{Test::More}},
9768 the standard perl testing libraries, which are based on TAP.
9769 @item
9770 @uref{http://www.eyrie.org/~eagle/software/c-tap-harness/,C TAP Harness},
9771 a C-based project implementing both a TAP producer and a TAP consumer.
9772 @item
9773 @uref{http://www.tap4j.org/,tap4j},
9774 a Java-based project implementing both a TAP producer and a TAP consumer.
9775 @end itemize
9776
9777 @node DejaGnu Tests
9778 @section DejaGnu Tests
9779
9780 If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @command{dejagnu}} appears in
9781 @code{AUTOMAKE_OPTIONS}, then a @command{dejagnu}-based test suite is
9782 assumed.  The variable @code{DEJATOOL} is a list of names that are
9783 passed, one at a time, as the @option{--tool} argument to
9784 @command{runtest} invocations; it defaults to the name of the package.
9785
9786 The variable @code{RUNTESTDEFAULTFLAGS} holds the @option{--tool} and
9787 @option{--srcdir} flags that are passed to dejagnu by default; this can be
9788 overridden if necessary.
9789 @vindex RUNTESTDEFAULTFLAGS
9790
9791 The variables @code{EXPECT} and @code{RUNTEST} can
9792 also be overridden to provide project-specific values.  For instance,
9793 you will need to do this if you are testing a compiler toolchain,
9794 because the default values do not take into account host and target
9795 names.
9796 @opindex dejagnu
9797 @vindex DEJATOOL
9798 @vindex EXPECT
9799 @vindex RUNTEST
9800
9801 The contents of the variable @code{RUNTESTFLAGS} are passed to the
9802 @code{runtest} invocation.  This is considered a ``user variable''
9803 (@pxref{User Variables}).  If you need to set @command{runtest} flags in
9804 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
9805 @vindex RUNTESTFLAGS
9806 @vindex AM_RUNTESTFLAGS
9807
9808 @cindex @file{site.exp}
9809 Automake will generate rules to create a local @file{site.exp} file,
9810 defining various variables detected by @command{configure}.  This file
9811 is automatically read by DejaGnu.  It is OK for the user of a package
9812 to edit this file in order to tune the test suite.  However this is
9813 not the place where the test suite author should define new variables:
9814 this should be done elsewhere in the real test suite code.
9815 Especially, @file{site.exp} should not be distributed.
9816
9817 Still, if the package author has legitimate reasons to extend
9818 @file{site.exp} at @command{make} time, he can do so by defining
9819 the variable @code{EXTRA_DEJAGNU_SITE_CONFIG}; the files listed
9820 there will be considered @file{site.exp} prerequisites, and their
9821 content will be appended to it (in the same order in which they
9822 appear in @code{EXTRA_DEJAGNU_SITE_CONFIG}).  Note that files are
9823 @emph{not} distributed by default.
9824
9825 For more information regarding DejaGnu test suites, see @ref{Top, , ,
9826 dejagnu, The DejaGnu Manual}.
9827
9828 @node Install Tests
9829 @section Install Tests
9830
9831 The @code{installcheck} target is available to the user as a way to
9832 run any tests after the package has been installed.  You can add tests
9833 to this by writing an @code{installcheck-local} rule.
9834
9835
9836 @node Rebuilding
9837 @chapter Rebuilding Makefiles
9838 @cindex rebuild rules
9839
9840 Automake generates rules to automatically rebuild @file{Makefile}s,
9841 @file{configure}, and other derived files like @file{Makefile.in}.
9842
9843 @acindex AM_MAINTAINER_MODE
9844 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.ac}, then
9845 these automatic rebuilding rules are only enabled in maintainer mode.
9846
9847 @vindex ACLOCAL_AMFLAGS
9848 Sometimes you need to run @command{aclocal} with an argument like
9849 @option{-I} to tell it where to find @file{.m4} files.  Since
9850 sometimes @command{make} will automatically run @command{aclocal}, you
9851 need a way to specify these arguments.  You can do this by defining
9852 @code{ACLOCAL_AMFLAGS}; this holds arguments that are passed verbatim
9853 to @command{aclocal}.  This variable is only useful in the top-level
9854 @file{Makefile.am}.
9855
9856 @vindex CONFIG_STATUS_DEPENDENCIES
9857 @vindex CONFIGURE_DEPENDENCIES
9858 @cindex @file{version.sh}, example
9859 @cindex @file{version.m4}, example
9860
9861 Sometimes it is convenient to supplement the rebuild rules for
9862 @file{configure} or @file{config.status} with additional dependencies.
9863 The variables @code{CONFIGURE_DEPENDENCIES} and
9864 @code{CONFIG_STATUS_DEPENDENCIES} can be used to list these extra
9865 dependencies.  These variables should be defined in all
9866 @file{Makefile}s of the tree (because these two rebuild rules are
9867 output in all them), so it is safer and easier to @code{AC_SUBST} them
9868 from @file{configure.ac}.  For instance, the following statement will
9869 cause @file{configure} to be rerun each time @file{version.sh} is
9870 changed.
9871
9872 @example
9873 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh'])
9874 @end example
9875
9876 @noindent
9877 Note the @samp{$(top_srcdir)/} in the file name.  Since this variable
9878 is to be used in all @file{Makefile}s, its value must be sensible at
9879 any level in the build hierarchy.
9880
9881 Beware not to mistake @code{CONFIGURE_DEPENDENCIES} for
9882 @code{CONFIG_STATUS_DEPENDENCIES}.
9883
9884 @code{CONFIGURE_DEPENDENCIES} adds dependencies to the
9885 @file{configure} rule, whose effect is to run @command{autoconf}.  This
9886 variable should be seldom used, because @command{automake} already tracks
9887 @code{m4_include}d files.  However it can be useful when playing
9888 tricky games with @code{m4_esyscmd} or similar non-recommendable
9889 macros with side effects.
9890
9891 @code{CONFIG_STATUS_DEPENDENCIES} adds dependencies to the
9892 @file{config.status} rule, whose effect is to run @file{configure}.
9893 This variable should therefore carry any non-standard source that may
9894 be read as a side effect of running @command{configure}, like @file{version.sh}
9895 in the example above.
9896
9897 Speaking of @file{version.sh} scripts, we recommend against them
9898 today.  They are mainly used when the version of a package is updated
9899 automatically by a script (e.g., in daily builds).  Here is what some
9900 old-style @file{configure.ac}s may look like:
9901
9902 @example
9903 AC_INIT
9904 . $srcdir/version.sh
9905 AM_INIT_AUTOMAKE([name], $VERSION_NUMBER)
9906 @dots{}
9907 @end example
9908
9909 @noindent
9910 Here, @file{version.sh} is a shell fragment that sets
9911 @code{VERSION_NUMBER}.  The problem with this example is that
9912 @command{automake} cannot track dependencies (listing @file{version.sh}
9913 in @command{CONFIG_STATUS_DEPENDENCIES}, and distributing this file is up
9914 to the user), and that it uses the obsolete form of @code{AC_INIT} and
9915 @code{AM_INIT_AUTOMAKE}.  Upgrading to the new syntax is not
9916 straightforward, because shell variables are not allowed in
9917 @code{AC_INIT}'s arguments.  We recommend that @file{version.sh} be
9918 replaced by an M4 file that is included by @file{configure.ac}:
9919
9920 @example
9921 m4_include([version.m4])
9922 AC_INIT([name], VERSION_NUMBER)
9923 AM_INIT_AUTOMAKE
9924 @dots{}
9925 @end example
9926
9927 @noindent
9928 Here @file{version.m4} could contain something like
9929 @samp{m4_define([VERSION_NUMBER], [1.2])}.  The advantage of this
9930 second form is that @command{automake} will take care of the
9931 dependencies when defining the rebuild rule, and will also distribute
9932 the file automatically.  An inconvenience is that @command{autoconf}
9933 will now be rerun each time the version number is bumped, when only
9934 @file{configure} had to be rerun in the previous setup.
9935
9936
9937 @node Options
9938 @chapter Changing Automake's Behavior
9939
9940 @menu
9941 * Options generalities::        Semantics of Automake option
9942 * List of Automake options::    A comprehensive list of Automake options
9943 @end menu
9944
9945 @node Options generalities
9946 @section Options generalities
9947
9948 Various features of Automake can be controlled by options.  Except where
9949 noted otherwise, options can be specified in one of several ways.  Most
9950 options can be applied on a per-@file{Makefile} basis when listed in a
9951 special @file{Makefile} variable named @code{AUTOMAKE_OPTIONS}.  Some
9952 of these options only make sense when specified in the toplevel
9953 @file{Makefile.am} file.  Options are applied globally to all processed
9954 @file{Makefile} files when listed in the first argument of
9955 @code{AM_INIT_AUTOMAKE} in @file{configure.ac}, and some options which
9956 require changes to the @command{configure} script can only be specified
9957 there.  These are annotated below.
9958
9959 As a general rule, options specified in @code{AUTOMAKE_OPTIONS} take
9960 precedence over those specified in @code{AM_INIT_AUTOMAKE}, which in
9961 turn take precedence over those specified on the command line.
9962
9963 Also, some care must be taken about the interactions among strictness
9964 level and warning categories.  As a general rule, strictness-implied
9965 warnings are overridden by those specified by explicit options.  For
9966 example, even if @samp{portability} warnings are disabled by default
9967 in @option{foreign} strictness, an usage like this will end up enabling
9968 them:
9969
9970 @example
9971 AUTOMAKE_OPTIONS = -Wportability foreign
9972 @end example
9973
9974 However, a strictness level specified in a higher-priority context
9975 will override all the explicit warnings specified in a lower-priority
9976 context.  For example, if @file{configure.ac} contains:
9977
9978 @example
9979 AM_INIT_AUTOMAKE([-Wportability])
9980 @end example
9981
9982 @noindent
9983 and @file{Makefile.am} contains:
9984
9985 @example
9986 AUTOMAKE_OPTIONS = foreign
9987 @end example
9988
9989 @noindent
9990 then @samp{portability} warnings will be @emph{disabled} in
9991 @file{Makefile.am}.
9992
9993 @node List of Automake options
9994 @section List of Automake options
9995
9996 @vindex AUTOMAKE_OPTIONS
9997
9998 @table @asis
9999 @item @option{gnits}
10000 @itemx @option{gnu}
10001 @itemx @option{foreign}
10002 @itemx @option{cygnus}
10003 @cindex Option, @option{gnits}
10004 @cindex Option, @option{gnu}
10005 @cindex Option, @option{foreign}
10006 @cindex Option, @option{cygnus}
10007 @opindex gnits
10008 @opindex gnu
10009 @opindex foreign
10010 @opindex cygnus
10011
10012 Set the strictness as appropriate.  The @option{gnits} option also
10013 implies options @option{readme-alpha} and @option{check-news}.
10014
10015 @item @option{check-news}
10016 @cindex Option, @option{check-news}
10017 @opindex check-news
10018 Cause @samp{make dist} to fail unless the current version number appears
10019 in the first few lines of the @file{NEWS} file.
10020
10021 @item @option{color-tests}
10022 @cindex Option, @option{color-tests}
10023 @opindex color-tests
10024 Cause output of the serial and parallel test harnesses (see @ref{Simple
10025 Tests}) and of properly-written custom test drivers (@pxref{Custom Test
10026 Drivers}) to be colorized on capable terminals.
10027
10028 @item @option{dejagnu}
10029 @cindex Option, @option{dejagnu}
10030 @opindex dejagnu
10031 Cause @command{dejagnu}-specific rules to be generated.  @xref{DejaGnu Tests}.
10032
10033 @item @option{dist-bzip2}
10034 @cindex Option, @option{dist-bzip2}
10035 @opindex dist-bzip2
10036 Hook @code{dist-bzip2} to @code{dist}.
10037 @trindex dist-bzip2
10038
10039 @item @option{dist-lzip}
10040 @cindex Option, @option{dist-lzip}
10041 @opindex dist-lzip
10042 Hook @code{dist-lzip} to @code{dist}.
10043 @trindex dist-lzip
10044
10045 @item @option{dist-shar}
10046 @cindex Option, @option{dist-shar}
10047 @opindex dist-shar
10048 Hook @code{dist-shar} to @code{dist}.
10049 @trindex dist-shar
10050
10051 @item @option{dist-zip}
10052 @cindex Option, @option{dist-zip}
10053 @opindex dist-zip
10054 Hook @code{dist-zip} to @code{dist}.
10055 @trindex dist-zip
10056
10057 @item @option{dist-tarZ}
10058 @cindex Option, @option{dist-tarZ}
10059 @opindex dist-tarZ
10060 Hook @code{dist-tarZ} to @code{dist}.
10061 @trindex dist-tarZ
10062
10063 @item @option{filename-length-max=99}
10064 @cindex Option, @option{filename-length-max=99}
10065 @opindex filename-length-max=99
10066 Abort if file names longer than 99 characters are found during
10067 @samp{make dist}.  Such long file names are generally considered not to
10068 be portable in tarballs.  See the @option{tar-v7} and @option{tar-ustar}
10069 options below.  This option should be used in the top-level
10070 @file{Makefile.am} or as an argument of @code{AM_INIT_AUTOMAKE} in
10071 @file{configure.ac}, it will be ignored otherwise.  It will also be
10072 ignored in sub-packages of nested packages (@pxref{Subpackages}).
10073
10074 @item @option{no-define}
10075 @cindex Option, @option{no-define}
10076 @opindex no-define
10077 This option is meaningful only when passed as an argument to
10078 @code{AM_INIT_AUTOMAKE}.  It will prevent the @code{PACKAGE} and
10079 @code{VERSION} variables from being @code{AC_DEFINE}d.
10080
10081 @item @option{no-dependencies}
10082 @cindex Option, @option{no-dependencies}
10083 @opindex no-dependencies
10084 This is similar to using @option{--ignore-deps} on the command line,
10085 but is useful for those situations where you don't have the necessary
10086 bits to make automatic dependency tracking work
10087 (@pxref{Dependencies}).  In this case the effect is to effectively
10088 disable automatic dependency tracking.
10089
10090 @item @option{no-dist}
10091 @cindex Option, @option{no-dist}
10092 @opindex no-dist
10093 Don't emit any code related to @code{dist} target.  This is useful
10094 when a package has its own method for making distributions.
10095
10096 @item @option{no-dist-gzip}
10097 @cindex Option, @option{no-dist-gzip}
10098 @opindex no-dist-gzip
10099 Do not hook @code{dist-gzip} to @code{dist}.
10100 @trindex no-dist-gzip
10101
10102 @item @option{no-exeext}
10103 @cindex Option, @option{no-exeext}
10104 @opindex no-exeext
10105 If your @file{Makefile.am} defines a rule for target @code{foo}, it
10106 will override a rule for a target named @samp{foo$(EXEEXT)}.  This is
10107 necessary when @code{EXEEXT} is found to be empty.  However, by
10108 default @command{automake} will generate an error for this use.  The
10109 @option{no-exeext} option will disable this error.  This is intended for
10110 use only where it is known in advance that the package will not be
10111 ported to Windows, or any other operating system using extensions on
10112 executables.
10113
10114 @item @option{no-installinfo}
10115 @cindex Option, @option{no-installinfo}
10116 @opindex no-installinfo
10117 The generated @file{Makefile.in} will not cause info pages to be built
10118 or installed by default.  However, @code{info} and @code{install-info}
10119 targets will still be available.  This option is disallowed at
10120 @option{gnu} strictness and above.
10121 @trindex info
10122 @trindex install-info
10123
10124 @item @option{no-installman}
10125 @cindex Option, @option{no-installman}
10126 @opindex no-installman
10127 The generated @file{Makefile.in} will not cause man pages to be
10128 installed by default.  However, an @code{install-man} target will still
10129 be available for optional installation.  This option is disallowed at
10130 @option{gnu} strictness and above.
10131 @trindex install-man
10132
10133 @item @option{nostdinc}
10134 @cindex Option, @option{nostdinc}
10135 @opindex nostdinc
10136 This option can be used to disable the standard @option{-I} options that
10137 are ordinarily automatically provided by Automake.
10138
10139 @item @option{no-texinfo.tex}
10140 @cindex Option, @option{no-texinfo.tex}
10141 @opindex no-texinfo.tex
10142 Don't require @file{texinfo.tex}, even if there are texinfo files in
10143 this directory.
10144
10145 @item @option{parallel-tests}
10146 @cindex Option, @option{parallel-tests}
10147 @opindex parallel-tests
10148 Enable test suite harness for @code{TESTS} that can run tests in parallel
10149 (@pxref{Parallel Test Harness}, for more information).
10150
10151 @item @option{serial-tests}
10152 @cindex Option, @option{serial-tests}
10153 @opindex serial-tests
10154 Enable the older serial test suite harness for @code{TESTS} (@pxref{Serial
10155 Test Harness}, for more information).  This is still the default for the
10156 moment.
10157
10158 @item @option{readme-alpha}
10159 @cindex Option, @option{readme-alpha}
10160 @opindex readme-alpha
10161 If this release is an alpha release, and the file @file{README-alpha}
10162 exists, then it will be added to the distribution.  If this option is
10163 given, version numbers are expected to follow one of two forms.  The
10164 first form is @samp{@var{major}.@var{minor}.@var{alpha}}, where each
10165 element is a number; the final period and number should be left off for
10166 non-alpha releases.  The second form is
10167 @samp{@var{major}.@var{minor}@var{alpha}}, where @var{alpha} is a
10168 letter; it should be omitted for non-alpha releases.
10169
10170 @item @option{silent-rules}
10171 @cindex Option, @option{silent-rules}
10172 @opindex silent-rules
10173 Enable less verbose build rules.  This can be used to let build rules
10174 output status lines of the form:
10175 @example
10176 GEN @var{output-file}
10177  CC @var{object-file}
10178 @end example
10179 @noindent
10180 instead of printing the command that will be executed to update
10181 @var{output-file} or to compile @var{object-file}.  It can also
10182 silence @command{libtool} output.
10183
10184 For more information about how to use, enable, or disable silent
10185 rules, @pxref{Automake silent-rules Option}.
10186
10187 @item @option{std-options}
10188 @cindex Options, @option{std-options}
10189 @cindex @samp{make installcheck}, testing @option{--help} and @option{--version}
10190 @cindex @option{--help} check
10191 @cindex @option{--version} check
10192 @opindex std-options
10193
10194 Make the @code{installcheck} rule check that installed scripts and
10195 programs support the @option{--help} and @option{--version} options.
10196 This also provides a basic check that the program's
10197 run-time dependencies are satisfied after installation.
10198
10199 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
10200 In a few situations, programs (or scripts) have to be exempted from this
10201 test.  For instance, @command{false} (from GNU coreutils) is never
10202 successful, even for @option{--help} or @option{--version}.  You can list
10203 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
10204 Programs (not scripts) listed in this variable should be suffixed by
10205 @samp{$(EXEEXT)} for the sake of Windows or OS/2.  For instance, suppose we
10206 build @file{false} as a program but @file{true.sh} as a script, and that
10207 neither of them support @option{--help} or @option{--version}:
10208
10209 @example
10210 AUTOMAKE_OPTIONS = std-options
10211 bin_PROGRAMS = false ...
10212 bin_SCRIPTS = true.sh ...
10213 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
10214 @end example
10215
10216 @item @option{subdir-objects}
10217 @cindex Options, @option{subdir-objects}
10218 @opindex subdir-objects
10219 If this option is specified, then objects are placed into the
10220 subdirectory of the build directory corresponding to the subdirectory of
10221 the source file.  For instance, if the source file is
10222 @file{subdir/file.cxx}, then the output file would be
10223 @file{subdir/file.o}.
10224
10225 In order to use this option with C sources, you should add
10226 @code{AM_PROG_CC_C_O} to @file{configure.ac}.
10227
10228 @anchor{tar-formats}
10229 @item @option{tar-v7}
10230 @itemx @option{tar-ustar}
10231 @itemx @option{tar-pax}
10232 @cindex Option, @option{tar-v7}
10233 @cindex Option, @option{tar-ustar}
10234 @cindex Option, @option{tar-pax}
10235 @cindex @command{tar} formats
10236 @cindex v7 @command{tar} format
10237 @cindex ustar format
10238 @cindex pax format
10239 @opindex tar-v7
10240 @opindex tar-ustar
10241 @opindex tar-pax
10242
10243 These three mutually exclusive options select the tar format to use
10244 when generating tarballs with @samp{make dist}.  (The tar file created
10245 is then compressed according to the set of @option{no-dist-gzip},
10246 @option{dist-bzip2}, @option{dist-lzip}, @option{dist-xz} and
10247 @option{dist-tarZ} options in use.)
10248
10249 These options must be passed as arguments to @code{AM_INIT_AUTOMAKE}
10250 (@pxref{Macros}) because they can require additional configure checks.
10251 Automake will complain if it sees such options in an
10252 @code{AUTOMAKE_OPTIONS} variable.
10253
10254 @option{tar-v7} selects the old V7 tar format.  This is the historical
10255 default.  This antiquated format is understood by all tar
10256 implementations and supports file names with up to 99 characters.  When
10257 given longer file names some tar implementations will diagnose the
10258 problem while other will generate broken tarballs or use non-portable
10259 extensions.  Furthermore, the V7 format cannot store empty
10260 directories.  When using this format, consider using the
10261 @option{filename-length-max=99} option to catch file names too long.
10262
10263 @option{tar-ustar} selects the ustar format defined by POSIX
10264 1003.1-1988.  This format is believed to be old enough to be portable.
10265 It fully supports empty directories.  It can store file names with up
10266 to 256 characters, provided that the file name can be split at
10267 directory separator in two parts, first of them being at most 155
10268 bytes long.  So, in most cases the maximum file name length will be
10269 shorter than 256 characters.  However you may run against broken tar
10270 implementations that incorrectly handle file names longer than 99
10271 characters (please report them to @email{@value{PACKAGE_BUGREPORT}} so we
10272 can document this accurately).
10273
10274 @option{tar-pax} selects the new pax interchange format defined by POSIX
10275 1003.1-2001.  It does not limit the length of file names.  However,
10276 this format is very young and should probably be restricted to
10277 packages that target only very modern platforms.  There are moves to
10278 change the pax format in an upward-compatible way, so this option may
10279 refer to a more recent version in the future.
10280
10281 @xref{Formats, , Controlling the Archive Format, tar, GNU Tar}, for
10282 further discussion about tar formats.
10283
10284 @command{configure} knows several ways to construct these formats.  It
10285 will not abort if it cannot find a tool up to the task (so that the
10286 package can still be built), but @samp{make dist} will fail.
10287
10288 @item @var{version}
10289 @cindex Option, @var{version}
10290 A version number (e.g., @samp{0.30}) can be specified.  If Automake is not
10291 newer than the version specified, creation of the @file{Makefile.in}
10292 will be suppressed.
10293
10294 @item @option{-W@var{category}} or @option{--warnings=@var{category}}
10295 @cindex Option, warnings
10296 @cindex Option, @option{-W@var{category}}
10297 @cindex Option, @option{--warnings=@var{category}}
10298 These options behave exactly like their command-line counterpart
10299 (@pxref{automake Invocation}).  This allows you to enable or disable some
10300 warning categories on a per-file basis.  You can also setup some warnings
10301 for your entire project; for instance, try @samp{AM_INIT_AUTOMAKE([-Wall])}
10302 in your @file{configure.ac}.
10303
10304 @end table
10305
10306 Unrecognized options are diagnosed by @command{automake}.
10307
10308 If you want an option to apply to all the files in the tree, you can use
10309 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.ac}.
10310 @xref{Macros}.
10311
10312
10313 @node Miscellaneous
10314 @chapter Miscellaneous Rules
10315
10316 There are a few rules and variables that didn't fit anywhere else.
10317
10318 @menu
10319 * Tags::                        Interfacing to cscope, etags and mkid
10320 * Suffixes::                    Handling new file extensions
10321 @end menu
10322
10323
10324 @node Tags
10325 @section Interfacing to @command{etags}
10326
10327 @cindex @file{TAGS} support
10328
10329 Automake will generate rules to generate @file{TAGS} files for use with
10330 GNU Emacs under some circumstances.
10331
10332 @trindex tags
10333 If any C, C++ or Fortran 77 source code or headers are present, then
10334 @code{tags} and @code{TAGS} rules will be generated for the directory.
10335 All files listed using the @code{_SOURCES}, @code{_HEADERS}, and
10336 @code{_LISP} primaries will be used to generate tags.  Note that
10337 generated source files that are not distributed must be declared in
10338 variables like @code{nodist_noinst_HEADERS} or
10339 @code{nodist_@var{prog}_SOURCES} or they will be ignored.
10340
10341 A @code{tags} rule will be output at the topmost directory of a
10342 multi-directory package.  When run from this topmost directory,
10343 @samp{make tags} will generate a @file{TAGS} file that includes by
10344 reference all @file{TAGS} files from subdirectories.
10345
10346 The @code{tags} rule will also be generated if the variable
10347 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
10348 directories that contain taggable source that @command{etags} does
10349 not understand.  The user can use the @code{ETAGSFLAGS} to pass
10350 additional flags to @command{etags}; @code{AM_ETAGSFLAGS} is also
10351 available for use in @file{Makefile.am}.
10352 @vindex ETAGS_ARGS
10353 @vindex ETAGSFLAGS
10354 @vindex AM_ETAGSFLAGS
10355
10356 Here is how Automake generates tags for its source, and for nodes in its
10357 Texinfo file:
10358
10359 @example
10360 ETAGS_ARGS = automake.in --lang=none \
10361  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
10362 @end example
10363
10364 If you add file names to @code{ETAGS_ARGS}, you will probably also
10365 want to define @code{TAGS_DEPENDENCIES}.  The contents of this variable
10366 are added directly to the dependencies for the @code{tags} rule.
10367 @vindex TAGS_DEPENDENCIES
10368
10369 Automake also generates a @code{ctags} rule that can be used to
10370 build @command{vi}-style @file{tags} files.  The variable @code{CTAGS}
10371 is the name of the program to invoke (by default @command{ctags});
10372 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
10373 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
10374
10375 @trindex id
10376 Automake will also generate an @code{ID} rule that will run
10377 @command{mkid} on the source.  This is only supported on a
10378 directory-by-directory basis.
10379
10380 Similarly, the @code{cscope} rule will create a list of all the source
10381 files in the tree and run @command{cscope} to build an inverted index
10382 database.  The variable @code{CSCOPE} is the name of the program to invoke
10383 (by default @command{cscope}); @code{CSCOPEFLAGS} and
10384 @code{CSCOPE_ARGS} can be used by the user to pass additional flags and
10385 file names respectively, while @code{AM_CSCOPEFLAGS} can be used by the
10386 @file{Makefile.am}.  Note that, currently, the Automake-provided
10387 @code{cscope} support, when used in a VPATH build, might not work well
10388 with non-GNU make implementations (especially with make implementations
10389 performing @ref{Automatic Rule Rewriting, , VPATH rewrites, autoconf,
10390 The Autoconf Manual}).
10391
10392 Finally, Automake also emits rules to support the
10393 @uref{http://www.gnu.org/software/global/, GNU Global Tags program}.
10394 The @code{GTAGS} rule runs Global Tags and puts the
10395 result in the top build directory.  The variable @code{GTAGS_ARGS}
10396 holds arguments that are passed to @command{gtags}.
10397 @vindex GTAGS_ARGS
10398
10399
10400 @node Suffixes
10401 @section Handling new file extensions
10402
10403 @cindex Adding new @code{SUFFIXES}
10404 @cindex @code{SUFFIXES}, adding
10405 @vindex SUFFIXES
10406
10407 It is sometimes useful to introduce a new implicit rule to handle a file
10408 type that Automake does not know about.
10409
10410 For instance, suppose you had a compiler that could compile @file{.foo}
10411 files to @file{.o} files.  You would simply define a suffix rule for
10412 your language:
10413
10414 @example
10415 .foo.o:
10416         foocc -c -o $@@ $<
10417 @end example
10418
10419 Then you could directly use a @file{.foo} file in a @code{_SOURCES}
10420 variable and expect the correct results:
10421
10422 @example
10423 bin_PROGRAMS = doit
10424 doit_SOURCES = doit.foo
10425 @end example
10426
10427 This was the simpler and more common case.  In other cases, you will
10428 have to help Automake to figure out which extensions you are defining your
10429 suffix rule for.  This usually happens when your extension does not
10430 start with a dot.  Then, all you have to do is to put a list of new
10431 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
10432 implicit rule.
10433
10434 For instance, the following definition prevents Automake from misinterpreting
10435 the @samp{.idlC.cpp:} rule as an attempt to transform @file{.idlC} files into
10436 @file{.cpp} files.
10437
10438 @c Keep in sync with suffix7.sh
10439 @example
10440 SUFFIXES = .idl C.cpp
10441 .idlC.cpp:
10442         # whatever
10443 @end example
10444
10445 As you may have noted, the @code{SUFFIXES} variable behaves like the
10446 @code{.SUFFIXES} special target of @command{make}.  You should not touch
10447 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
10448 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
10449 @code{SUFFIXES} go at the start of the generated suffixes list, followed
10450 by Automake generated suffixes not already in the list.
10451
10452 @node Include
10453 @chapter Include
10454
10455 @cmindex include
10456 @cindex Including @file{Makefile} fragment
10457 @cindex @file{Makefile} fragment, including
10458
10459 Automake supports an @code{include} directive that  can be used to
10460 include other @file{Makefile} fragments when @command{automake} is run.
10461 Note that these fragments are read and interpreted by @command{automake},
10462 not by @command{make}.  As with conditionals, @command{make} has no idea that
10463 @code{include} is in use.
10464
10465 There are two forms of @code{include}:
10466
10467 @table @code
10468 @item include $(srcdir)/file
10469 Include a fragment that is found relative to the current source
10470 directory.
10471
10472 @item include $(top_srcdir)/file
10473 Include a fragment that is found relative to the top source directory.
10474 @end table
10475
10476 Note that if a fragment is included inside a conditional, then the
10477 condition applies to the entire contents of that fragment.
10478
10479 Makefile fragments included this way are always distributed because
10480 they are needed to rebuild @file{Makefile.in}.
10481
10482 @node Conditionals
10483 @chapter Conditionals
10484
10485 @cindex Conditionals
10486
10487 Automake supports a simple type of conditionals.
10488
10489 These conditionals are not the same as conditionals in
10490 GNU Make.  Automake conditionals are checked at configure time by the
10491 @file{configure} script, and affect the translation from
10492 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
10493 to @file{configure} and on results that @file{configure} has discovered
10494 about the host system.  GNU Make conditionals are checked at @command{make}
10495 time, and are based on variables passed to the make program or defined
10496 in the @file{Makefile}.
10497
10498 Automake conditionals will work with any make program.
10499
10500 @menu
10501 * Usage of Conditionals::       Declaring conditional content
10502 * Limits of Conditionals::      Enclosing complete statements
10503 @end menu
10504
10505 @node Usage of Conditionals
10506 @section Usage of Conditionals
10507
10508 @acindex AM_CONDITIONAL
10509 Before using a conditional, you must define it by using
10510 @code{AM_CONDITIONAL} in the @file{configure.ac} file (@pxref{Macros}).
10511
10512 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
10513 The conditional name, @var{conditional}, should be a simple string
10514 starting with a letter and containing only letters, digits, and
10515 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
10516 that are reserved by Automake.
10517
10518 The shell @var{condition} (suitable for use in a shell @code{if}
10519 statement) is evaluated when @command{configure} is run.  Note that you
10520 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
10521 time @command{configure} is run.  If @code{AM_CONDITIONAL} is run
10522 conditionally (e.g., in a shell @code{if} statement), then the result
10523 will confuse @command{automake}.
10524 @end defmac
10525
10526 @cindex @option{--enable-debug}, example
10527 @cindex Example conditional @option{--enable-debug}
10528 @cindex Conditional example, @option{--enable-debug}
10529
10530 Conditionals typically depend upon options that the user provides to
10531 the @command{configure} script.  Here is an example of how to write a
10532 conditional that is true if the user uses the @option{--enable-debug}
10533 option.
10534
10535 @example
10536 AC_ARG_ENABLE([debug],
10537 [  --enable-debug    Turn on debugging],
10538 [case "$@{enableval@}" in
10539   yes) debug=true ;;
10540   no)  debug=false ;;
10541   *) AC_MSG_ERROR([bad value $@{enableval@} for --enable-debug]) ;;
10542 esac],[debug=false])
10543 AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
10544 @end example
10545
10546 Here is an example of how to use that conditional in @file{Makefile.am}:
10547
10548 @cmindex if
10549 @cmindex endif
10550 @cmindex else
10551
10552 @example
10553 if DEBUG
10554 DBG = debug
10555 else
10556 DBG =
10557 endif
10558 noinst_PROGRAMS = $(DBG)
10559 @end example
10560
10561 This trivial example could also be handled using @code{EXTRA_PROGRAMS}
10562 (@pxref{Conditional Programs}).
10563
10564 You may only test a single variable in an @code{if} statement, possibly
10565 negated using @samp{!}.  The @code{else} statement may be omitted.
10566 Conditionals may be nested to any depth.  You may specify an argument to
10567 @code{else} in which case it must be the negation of the condition used
10568 for the current @code{if}.  Similarly you may specify the condition
10569 that is closed on the @code{endif} line:
10570
10571 @example
10572 if DEBUG
10573 DBG = debug
10574 else !DEBUG
10575 DBG =
10576 endif !DEBUG
10577 @end example
10578
10579 @noindent
10580 Unbalanced conditions are errors.  The @code{if}, @code{else}, and
10581 @code{endif} statements should not be indented, i.e., start on column
10582 one.
10583
10584 The @code{else} branch of the above two examples could be omitted,
10585 since assigning the empty string to an otherwise undefined variable
10586 makes no difference.
10587
10588 @acindex AM_COND_IF
10589 In order to allow access to the condition registered by
10590 @code{AM_CONDITIONAL} inside @file{configure.ac}, and to allow
10591 conditional @code{AC_CONFIG_FILES}, @code{AM_COND_IF} may be used:
10592
10593 @defmac AM_COND_IF (@var{conditional}, @ovar{if-true}, @ovar{if-false})
10594 If @var{conditional} is fulfilled, execute @var{if-true}, otherwise
10595 execute @var{if-false}.  If either branch contains @code{AC_CONFIG_FILES},
10596 it will cause @command{automake} to output the rules for the respective
10597 files only for the given condition.
10598 @end defmac
10599
10600 @code{AM_COND_IF} macros may be nested when m4 quotation is used
10601 properly (@pxref{M4 Quotation, ,, autoconf, The Autoconf Manual}).
10602
10603 @cindex Example conditional @code{AC_CONFIG_FILES}
10604 @cindex @code{AC_CONFIG_FILES}, conditional
10605
10606 Here is an example of how to define a conditional config file:
10607
10608 @example
10609 AM_CONDITIONAL([SHELL_WRAPPER], [test "x$with_wrapper" = xtrue])
10610 AM_COND_IF([SHELL_WRAPPER],
10611            [AC_CONFIG_FILES([wrapper:wrapper.in])])
10612 @end example
10613
10614 @node Limits of Conditionals
10615 @section Limits of Conditionals
10616
10617 Conditionals should enclose complete statements like variables or
10618 rules definitions.  Automake cannot deal with conditionals used inside
10619 a variable definition, for instance, and is not even able to diagnose
10620 this situation.  The following example would not work:
10621
10622 @example
10623 # This syntax is not understood by Automake
10624 AM_CPPFLAGS = \
10625   -DFEATURE_A \
10626 if WANT_DEBUG
10627   -DDEBUG \
10628 endif
10629   -DFEATURE_B
10630 @end example
10631
10632 However the intended definition of @code{AM_CPPFLAGS} can be achieved
10633 with
10634
10635 @example
10636 if WANT_DEBUG
10637   DEBUGFLAGS = -DDEBUG
10638 endif
10639 AM_CPPFLAGS = -DFEATURE_A $(DEBUGFLAGS) -DFEATURE_B
10640 @end example
10641
10642 @noindent
10643 or
10644
10645 @example
10646 AM_CPPFLAGS = -DFEATURE_A
10647 if WANT_DEBUG
10648 AM_CPPFLAGS += -DDEBUG
10649 endif
10650 AM_CPPFLAGS += -DFEATURE_B
10651 @end example
10652
10653 More details and examples of conditionals are described alongside
10654 various Automake features in this manual (@pxref{Conditional
10655 Subdirectories}, @pxref{Conditional Sources}, @pxref{Conditional
10656 Programs}, @pxref{Conditional Libtool Libraries}, @pxref{Conditional
10657 Libtool Sources}).
10658
10659 @node Silencing Make
10660 @chapter Silencing @command{make}
10661
10662 @cindex Silent @command{make}
10663 @cindex Silencing @command{make}
10664 @cindex Silent rules
10665 @cindex Silent @command{make} rules
10666
10667 @menu
10668 * Make verbosity::               Make is verbose by default
10669 * Tricks For Silencing Make::    Standard and generic ways to silence make
10670 * Automake silent-rules Option:: How Automake can help in silencing make
10671 @end menu
10672
10673 @node Make verbosity
10674 @section Make is verbose by default
10675
10676 Normally, when executing the set of rules associated with a target,
10677 @command{make} prints each rule before it is executed.  This behaviour,
10678 while having been in place for a long time, and being even mandated by
10679 the POSIX standard, starkly violates the ``silence is golden'' UNIX
10680 principle@footnote{See also
10681 @uref{http://catb.org/~esr/writings/taoup/html/ch11s09.html}.}:
10682
10683 @quotation
10684 When a program has nothing interesting or surprising to say, it should
10685 say nothing.  Well-behaved Unix programs do their jobs unobtrusively,
10686 with a minimum of fuss and bother.  Silence is golden.
10687 @end quotation
10688
10689 In fact, while such verbosity of @command{make} can theoretically be
10690 useful to track bugs and understand reasons of failures right away, it
10691 can also hide warning and error messages from @command{make}-invoked
10692 tools, drowning them in a flood of uninteresting and seldom useful
10693 messages, and thus allowing them to go easily undetected.
10694
10695 This problem can be very annoying, especially for developers, who usually
10696 know quite well what's going on behind the scenes, and for whom the
10697 verbose output from @command{make} ends up being mostly noise that hampers
10698 the easy detection of potentially important warning messages.
10699
10700 @node Tricks For Silencing Make
10701 @section Standard and generic ways to silence make
10702
10703 Here we describe some common idioms/tricks to obtain a quieter make
10704 output, with their relative advantages and drawbacks.  In the next
10705 section (@ref{Automake silent-rules Option}) we'll see how Automake
10706 can help in this respect.
10707
10708 @itemize @bullet
10709
10710 @item @command{make -s}
10711
10712 This simply causes @command{make} not to print @emph{any} rule before
10713 executing it.
10714
10715 The @option{-s} flag is mandated by POSIX, universally supported, and
10716 its purpose and function are easy to understand.
10717
10718 But it also has its serious limitations too.  First of all, it embodies
10719 an ``all or nothing'' strategy, i.e., either everything is silenced, or
10720 nothing is; this lack of granularity can sometimes be a fatal flaw.
10721 Moreover, when the @option{-s} flag is used, the @command{make} output
10722 might turn out to be too much terse; in case of errors, the user won't
10723 be able to easily see what rule or command have caused them, or even,
10724 in case of tools with poor error reporting, what the errors were!
10725
10726 @item @command{make >/dev/null || make}
10727
10728 Apparently, this perfectly obeys the ``silence is golden'' rule: warnings
10729 from stderr are passed through, output reporting is done only in case of
10730 error, and in that case it should provide a verbose-enough report to allow
10731 an easy determination of the error location and causes.
10732
10733 However, calling @command{make} two times in a row might hide errors
10734 (especially intermittent ones), or subtly change the expected semantic
10735 of the @command{make} calls --- things these which can clearly make
10736 debugging and error assessment very difficult.
10737
10738 @item @command{make --no-print-directory}
10739
10740 This is GNU @command{make} specific.  When called with the
10741 @option{--no-print-directory} option, GNU @command{make} will disable
10742 printing of the working directory by invoked sub-@command{make}s (the
10743 well-known ``@i{Entering/Leaving directory ...}'' messages).  This helps
10744 to decrease the verbosity of the output, but experience has shown that
10745 it can also often render debugging considerably harder in projects using
10746 deeply-nested @command{make} recursion.
10747
10748 As an aside, notice that the @option{--no-print-directory} option is
10749 automatically activated if the @option{-s} flag is used.
10750
10751 @c TODO: Other tricks?
10752 @c TODO: Maybe speak about the @code{.SILENT} target?
10753 @c TODO:  - Pros: More granularity on what to silence.
10754 @c TODO:  - Cons: No easy way to temporarily override.
10755
10756 @end itemize
10757
10758 @node Automake silent-rules Option
10759 @section How Automake can help in silencing make
10760
10761 The tricks and idioms for silencing @command{make} described in the
10762 previous section can be useful from time to time, but we've seen that
10763 they all have their serious drawbacks and limitations.  That's why
10764 automake provides support for a more advanced and flexible way of
10765 obtaining quieter output from @command{make}: the @option{silent-rules}
10766 mode.
10767
10768 @c TODO: Maybe describe in brief the precedent set by the build system
10769 @c of the Linux Kernel, from which Automake took inspiration ... Links?
10770
10771 To give the gist of what @option{silent-rules} can do, here is a simple
10772 comparison between a typical @command{make} output (where silent rules
10773 are disabled) and one with silent rules enabled:
10774
10775 @example
10776 % @kbd{cat Makefile.am}
10777 bin_PROGRAMS = foo
10778 foo_SOURCES = main.c func.c
10779 % @kbd{cat main.c}
10780 int main (void) @{ return func (); @}  /* func used undeclared */
10781 % @kbd{cat func.c}
10782 int func (void) @{ int i; return i; @} /* i used uninitialized */
10783
10784 @i{The make output is by default very verbose.  This causes warnings
10785 from the compiler to be somewhat hidden, and not immediate to spot.}
10786 % @kbd{make CFLAGS=-Wall}
10787 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
10788 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
10789 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT main.o
10790 -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
10791 main.c: In function â€˜main’:
10792 main.c:3:3: warning: implicit declaration of function â€˜func’
10793 mv -f .deps/main.Tpo .deps/main.Po
10794 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
10795 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
10796 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT func.o
10797 -MD -MP -MF .deps/func.Tpo -c -o func.o func.c
10798 func.c: In function â€˜func’:
10799 func.c:4:3: warning: â€˜i’ used uninitialized in this function
10800 mv -f .deps/func.Tpo .deps/func.Po
10801 gcc -Wall -o foo main.o func.o
10802
10803 @i{Clean up, so that we we can rebuild everything from scratch.}
10804 % @kbd{make clean}
10805 test -z "foo" || rm -f foo
10806 rm -f *.o
10807
10808 @i{Silent rules enabled: the output is minimal but informative.  In
10809 particular, the warnings from the compiler stick out very clearly.}
10810 % @kbd{make V=0 CFLAGS=-Wall}
10811   CC     main.o
10812 main.c: In function â€˜main’:
10813 main.c:3:3: warning: implicit declaration of function â€˜func’
10814   CC     func.o
10815 func.c: In function â€˜func’:
10816 func.c:4:3: warning: â€˜i’ used uninitialized in this function
10817   CCLD   foo
10818 @end example
10819
10820 @cindex silent-rules and libtool
10821 Also, in projects using @command{libtool}, the use of silent rules can
10822 automatically enable the @command{libtool}'s @option{--silent} option:
10823
10824 @example
10825 % @kbd{cat Makefile.am}
10826 lib_LTLIBRARIES = libx.la
10827
10828 % @kbd{make # Both make and libtool are verbose by default.}
10829 ...
10830 libtool: compile: gcc -DPACKAGE_NAME=\"foo\" ... -DLT_OBJDIR=\".libs/\"
10831   -I. -g -O2 -MT libx.lo -MD -MP -MF .deps/libx.Tpo -c libx.c -fPIC
10832   -DPIC -o .libs/libx.o
10833 mv -f .deps/libx.Tpo .deps/libx.Plo
10834 /bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -o libx.la -rpath
10835   /usr/local/lib libx.lo
10836 libtool: link: gcc -shared .libs/libx.o -Wl,-soname -Wl,libx.so.0
10837   -o .libs/libx.so.0.0.0
10838 libtool: link: cd .libs && rm -f libx.so && ln -s libx.so.0.0.0 libx.so
10839 ...
10840
10841 % @kbd{make V=0}
10842   CC     libx.lo
10843   CCLD   libx.la
10844 @end example
10845
10846 Let's now see how the @option{silent-rules} mode interfaces with the
10847 package developer and the package user.
10848
10849 To enable the use of @option{silent-rules} in his package, a developer
10850 needs to do either of the following:
10851
10852 @itemize @bullet
10853 @item
10854 Add the @option{silent-rules} option as argument to @code{AM_INIT_AUTOMAKE}.
10855 @item
10856 Call the @code{AM_SILENT_RULES} macro from within the @file{configure.ac}
10857 file.
10858 @end itemize
10859
10860 It is not possible to instead specify @option{silent-rules} in a
10861 @file{Makefile.am} file.
10862
10863 If the developer has done either of the above, then the user of the
10864 package may influence the verbosity at @command{configure} run time as
10865 well as at @command{make} run time:
10866
10867 @itemize @bullet
10868 @item
10869 @opindex --enable-silent-rules
10870 @opindex --disable-silent-rules
10871 Passing @option{--enable-silent-rules} to @command{configure} will cause
10872 build rules to be less verbose; the option @option{--disable-silent-rules}
10873 will cause normal verbose output.
10874 @item
10875 @vindex @code{V}
10876 At @command{make} run time, the default chosen at @command{configure}
10877 time may be overridden: @code{make V=1} will produce verbose output,
10878 @code{make V=0} less verbose output.
10879 @end itemize
10880
10881 @cindex default verbosity for silent-rules
10882 Note that silent rules are @emph{disabled} by default; the user must
10883 enable them explicitly at either @command{configure} run time or at
10884 @command{make} run time.  We think that this is a good policy, since
10885 it provides the casual user with enough information to prepare a good
10886 bug report in case anything breaks.
10887
10888 Still, notwithstanding the rationales above, a developer who wants to
10889 make silent rules enabled by default in his own package can do so by
10890 adding a @samp{yes} argument to the @code{AM_SILENT_RULES} call in
10891 @file{configure.ac}.  We advise against this approach, though.
10892
10893 @c Keep in sync with silent-configsite.sh
10894 Users who prefer to have silent rules enabled by default can edit their
10895 @file{config.site} file to make the variable @code{enable_silent_rules}
10896 default to @samp{yes}.  This should still allow disabling silent rules
10897 at @command{configure} time and at @command{make} time.
10898
10899 @c FIXME: there's really a need to specify this explicitly?
10900 For portability to different @command{make} implementations, package authors
10901 are advised to not set the variable @code{V} inside the @file{Makefile.am}
10902 file, to allow the user to override the value for subdirectories as well.
10903
10904 The current implementation of this feature normally uses nested
10905 variable expansion @samp{$(@var{var1}$(V))}, a @file{Makefile} feature
10906 that is not required by POSIX 2008 but is widely supported in
10907 practice.  The @option{silent-rules} option thus turns off warnings
10908 about recursive variable expansion, which are in turn enabled by
10909 @option{-Wportability} (@pxref{automake Invocation}).  On the rare
10910 @command{make} implementations that do not support nested variable
10911 expansion, whether rules are silent is always determined at configure
10912 time, and cannot be overridden at make time.  Future versions of POSIX
10913 are likely to require nested variable expansion, so this minor
10914 limitation should go away with time.
10915
10916 @vindex @code{AM_V_GEN}
10917 @vindex @code{AM_V_at}
10918 @vindex @code{AM_DEFAULT_VERBOSITY}
10919 @vindex @code{AM_V}
10920 @vindex @code{AM_DEFAULT_V}
10921 To extend the silent mode to your own rules, you have two choices:
10922
10923 @itemize @bullet
10924 @item
10925 You can use the predefined variable @code{AM_V_GEN} as a prefix to
10926 commands that should output a status line in silent mode, and
10927 @code{AM_V_at} as a prefix to commands that should not output anything
10928 in silent mode.  When output is to be verbose, both of these variables
10929 will expand to the empty string.
10930 @item
10931 You can add your own variables, so strings of your own choice are shown.
10932 The following snippet shows how you would define your own equivalent of
10933 @code{AM_V_GEN}:
10934
10935 @example
10936 pkg_verbose = $(pkg_verbose_@@AM_V@@)
10937 pkg_verbose_ = $(pkg_verbose_@@AM_DEFAULT_V@@)
10938 pkg_verbose_0 = @@echo PKG-GEN $@@;
10939
10940 foo: foo.in
10941         $(pkg_verbose)cp $(srcdir)/foo.in $@@
10942 @end example
10943
10944 @end itemize
10945
10946 As a final note, observe that, even when silent rules are enabled,
10947 the @option{--no-print-directory} option is still required with GNU
10948 @command{make} if the ``@i{Entering/Leaving directory ...}'' messages
10949 are to be disabled.
10950
10951 @node Gnits
10952 @chapter The effect of @option{--gnu} and @option{--gnits}
10953
10954 @cindex @option{--gnu}, required files
10955 @cindex @option{--gnu}, complete description
10956
10957 The @option{--gnu} option (or @option{gnu} in the
10958 @code{AUTOMAKE_OPTIONS} variable) causes @command{automake} to check
10959 the following:
10960
10961 @itemize @bullet
10962 @item
10963 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
10964 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
10965 or @file{COPYING}, are required at the topmost directory of the package.
10966
10967 If the @option{--add-missing} option is given, @command{automake} will
10968 add a generic version of the @file{INSTALL} file as well as the
10969 @file{COPYING} file containing the text of the current version of the
10970 GNU General Public License existing at the time of this Automake release
10971 (version 3 as this is written, @uref{http://www.gnu.org/@/copyleft/@/gpl.html}).
10972 However, an existing @file{COPYING} file will never be overwritten by
10973 @command{automake}.
10974
10975 @item
10976 The options @option{no-installman} and @option{no-installinfo} are
10977 prohibited.
10978 @end itemize
10979
10980 Note that this option will be extended in the future to do even more
10981 checking; it is advisable to be familiar with the precise requirements
10982 of the GNU standards.  Also, @option{--gnu} can require certain
10983 non-standard GNU programs to exist for use by various maintainer-only
10984 rules; for instance, in the future @command{pathchk} might be required for
10985 @samp{make dist}.
10986
10987 @cindex @option{--gnits}, complete description
10988
10989 The @option{--gnits} option does everything that @option{--gnu} does, and
10990 checks the following as well:
10991
10992 @itemize @bullet
10993 @item
10994 @samp{make installcheck} will check to make sure that the @option{--help}
10995 and @option{--version} really print a usage message and a version string,
10996 respectively.  This is the @option{std-options} option (@pxref{Options}).
10997
10998 @item
10999 @samp{make dist} will check to make sure the @file{NEWS} file has been
11000 updated to the current version.
11001
11002 @item
11003 @code{VERSION} is checked to make sure its format complies with Gnits
11004 standards.
11005 @c FIXME xref when standards are finished
11006
11007 @item
11008 @cindex @file{README-alpha}
11009 If @code{VERSION} indicates that this is an alpha release, and the file
11010 @file{README-alpha} appears in the topmost directory of a package, then
11011 it is included in the distribution.  This is done in @option{--gnits}
11012 mode, and no other, because this mode is the only one where version
11013 number formats are constrained, and hence the only mode where Automake
11014 can automatically determine whether @file{README-alpha} should be
11015 included.
11016
11017 @item
11018 The file @file{THANKS} is required.
11019 @end itemize
11020
11021
11022 @node Cygnus
11023 @chapter The effect of @option{--cygnus}
11024
11025 @cindex @option{cygnus} strictness
11026
11027 @emph{The features described in this section are deprecated; you must
11028 not use any of them in new code, and should remove their use from older
11029 but still maintained code: they will be withdrawn in a future Automake
11030 release.}
11031
11032 Some packages, notably GNU GCC and GNU gdb, used to have a build
11033 environment originally written at Cygnus Support (subsequently renamed
11034 Cygnus Solutions, and then later purchased by Red Hat).  Packages with
11035 this ancestry are sometimes referred to as ``Cygnus'' trees.
11036
11037 A Cygnus tree has slightly different rules for how a
11038 @file{Makefile.in} is to be constructed.  Passing @option{--cygnus} to
11039 @command{automake} will cause any generated @file{Makefile.in} to
11040 comply with Cygnus rules.
11041
11042 Here are the precise effects of @option{--cygnus}:
11043
11044 @itemize @bullet
11045
11046 @item
11047 The @option{foreign} strictness is implied.
11048
11049 @item
11050 The options @option{no-installinfo}, @option{no-dependencies} and
11051 @option{no-dist} are implied (@pxref{Options}).
11052
11053 @item
11054 The macro @code{AM_MAINTAINER_MODE} is required.
11055
11056 @item
11057 Info files are always created in the build directory, and not in the
11058 source directory.  Packages that don't use the @option{cygnus} option
11059 can emulate this effect by using the @option{no-installinfo} option
11060 and listing the generated info files in the @code{CLEANFILES} variable.
11061
11062 @item
11063 @file{texinfo.tex} is not required if a Texinfo source file is
11064 specified.  The assumption is that the file will be supplied, but in a
11065 place that Automake cannot find -- it is an artifact of how Cygnus
11066 packages are typically bundled.  This effect can be emulated in
11067 packages not using the @option{cygnus} option with a proper definition
11068 of the @code{TEXINFO_TEX} variable (@pxref{Texinfo}).
11069
11070 @item
11071 Certain tools will be searched for in the build tree as well as in the
11072 user's @env{PATH}.  These tools are @command{runtest}, @command{expect},
11073 @command{makeinfo} and @command{texi2dvi}.
11074
11075 @item
11076 The @code{check} target doesn't depend on @code{all}.
11077 @end itemize
11078
11079
11080 @node Not Enough
11081 @chapter When Automake Isn't Enough
11082
11083 In some situations, where Automake is not up to one task, one has to
11084 resort to handwritten rules or even handwritten @file{Makefile}s.
11085
11086 @menu
11087 * Extending::                   Adding new rules or overriding existing ones.
11088 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
11089 @end menu
11090
11091 @node Extending
11092 @section Extending Automake Rules
11093
11094 With some minor exceptions (for example @code{_PROGRAMS} variables,
11095 @code{TESTS}, or @code{XFAIL_TESTS}) being rewritten to append
11096 @samp{$(EXEEXT)}), the contents of a @file{Makefile.am} is copied to
11097 @file{Makefile.in} verbatim.
11098
11099 @cindex copying semantics
11100
11101 These copying semantics mean that many problems can be worked around
11102 by simply adding some @command{make} variables and rules to
11103 @file{Makefile.am}.  Automake will ignore these additions.
11104
11105 @cindex conflicting definitions
11106 @cindex rules, conflicting
11107 @cindex variables, conflicting
11108 @cindex definitions, conflicts
11109
11110 Since a @file{Makefile.in} is built from data gathered from three
11111 different places (@file{Makefile.am}, @file{configure.ac}, and
11112 @command{automake} itself), it is possible to have conflicting
11113 definitions of rules or variables.  When building @file{Makefile.in}
11114 the following priorities are respected by @command{automake} to ensure
11115 the user always has the last word:
11116
11117 @itemize
11118 @item
11119 User defined variables in @file{Makefile.am} have priority over
11120 variables @code{AC_SUBST}ed from @file{configure.ac}, and
11121 @code{AC_SUBST}ed variables have priority over
11122 @command{automake}-defined variables.
11123 @item
11124 As far as rules are concerned, a user-defined rule overrides any
11125 @command{automake}-defined rule for the same target.
11126 @end itemize
11127
11128 @cindex overriding rules
11129 @cindex overriding semantics
11130 @cindex rules, overriding
11131
11132 These overriding semantics make it possible to fine tune some default
11133 settings of Automake, or replace some of its rules.  Overriding
11134 Automake rules is often inadvisable, particularly in the topmost
11135 directory of a package with subdirectories.  The @option{-Woverride}
11136 option (@pxref{automake Invocation}) comes in handy to catch overridden
11137 definitions.
11138
11139 Note that Automake does not make any distinction between rules with
11140 commands and rules that only specify dependencies.  So it is not
11141 possible to append new dependencies to an @command{automake}-defined
11142 target without redefining the entire rule.
11143
11144 @cindex @option{-local} targets
11145 @cindex local targets
11146
11147 However, various useful targets have a @samp{-local} version you can
11148 specify in your @file{Makefile.am}.  Automake will supplement the
11149 standard target with these user-supplied targets.
11150
11151 @trindex  all
11152 @trindex  all-local
11153 @trindex  info
11154 @trindex  info-local
11155 @trindex  dvi
11156 @trindex  dvi-local
11157 @trindex  ps
11158 @trindex  ps-local
11159 @trindex  pdf
11160 @trindex  pdf-local
11161 @trindex  html
11162 @trindex  html-local
11163 @trindex  check
11164 @trindex  check-local
11165 @trindex  install
11166 @trindex  install-data
11167 @trindex  install-data-local
11168 @trindex  install-dvi
11169 @trindex  install-dvi-local
11170 @trindex  install-exec
11171 @trindex  install-exec-local
11172 @trindex  install-html
11173 @trindex  install-html-local
11174 @trindex  install-info
11175 @trindex  install-info-local
11176 @trindex  install-pdf
11177 @trindex  install-pdf-local
11178 @trindex  install-ps
11179 @trindex  install-ps-local
11180 @trindex  uninstall
11181 @trindex  uninstall-local
11182 @trindex  mostlyclean
11183 @trindex  mostlyclean-local
11184 @trindex  clean
11185 @trindex  clean-local
11186 @trindex  distclean
11187 @trindex  distclean-local
11188 @trindex  installdirs
11189 @trindex  installdirs-local
11190 @trindex  installcheck
11191 @trindex  installcheck-local
11192
11193 The targets that support a local version are @code{all}, @code{info},
11194 @code{dvi}, @code{ps}, @code{pdf}, @code{html}, @code{check},
11195 @code{install-data}, @code{install-dvi}, @code{install-exec},
11196 @code{install-html}, @code{install-info}, @code{install-pdf},
11197 @code{install-ps}, @code{uninstall}, @code{installdirs},
11198 @code{installcheck} and the various @code{clean} targets
11199 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
11200 @code{maintainer-clean}).
11201
11202 Note that there are no @code{uninstall-exec-local} or
11203 @code{uninstall-data-local} targets; just use @code{uninstall-local}.
11204 It doesn't make sense to uninstall just data or just executables.
11205
11206 For instance, here is one way to erase a subdirectory during
11207 @samp{make clean} (@pxref{Clean}).
11208
11209 @example
11210 clean-local:
11211         -rm -rf testSubDir
11212 @end example
11213
11214 You may be tempted to use @code{install-data-local} to install a file
11215 to some hard-coded location, but you should avoid this
11216 (@pxref{Hard-Coded Install Paths}).
11217
11218 With the @code{-local} targets, there is no particular guarantee of
11219 execution order; typically, they are run early, but with parallel
11220 make, there is no way to be sure of that.
11221
11222 @cindex @option{-hook} targets
11223 @cindex hook targets
11224 @trindex install-data-hook
11225 @trindex install-exec-hook
11226 @trindex uninstall-hook
11227 @trindex dist-hook
11228
11229 In contrast, some rules also have a way to run another rule, called a
11230 @dfn{hook}; hooks are always executed after the main rule's work is done.
11231 The hook is named after the principal target, with @samp{-hook} appended.
11232 The targets allowing hooks are @code{install-data},
11233 @code{install-exec}, @code{uninstall}, @code{dist}, and
11234 @code{distcheck}.
11235
11236 For instance, here is how to create a hard link to an installed program:
11237
11238 @example
11239 install-exec-hook:
11240         ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
11241            $(DESTDIR)$(bindir)/proglink$(EXEEXT)
11242 @end example
11243
11244 Although cheaper and more portable than symbolic links, hard links
11245 will not work everywhere (for instance, OS/2 does not have
11246 @command{ln}).  Ideally you should fall back to @samp{cp -p} when
11247 @command{ln} does not work.  An easy way, if symbolic links are
11248 acceptable to you, is to add @code{AC_PROG_LN_S} to
11249 @file{configure.ac} (@pxref{Particular Programs, , Particular Program
11250 Checks, autoconf, The Autoconf Manual}) and use @samp{$(LN_S)} in
11251 @file{Makefile.am}.
11252
11253 @cindex versioned binaries, installing
11254 @cindex installing versioned binaries
11255 @cindex @code{LN_S} example
11256 For instance, here is how you could install a versioned copy of a
11257 program using @samp{$(LN_S)}:
11258
11259 @c Keep in sync with insthook.sh
11260 @example
11261 install-exec-hook:
11262         cd $(DESTDIR)$(bindir) && \
11263           mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
11264           $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
11265 @end example
11266
11267 Note that we rename the program so that a new version will erase the
11268 symbolic link, not the real binary.  Also we @command{cd} into the
11269 destination directory in order to create relative links.
11270
11271 When writing @code{install-exec-hook} or @code{install-data-hook},
11272 please bear in mind that the exec/data distinction is based on the
11273 installation directory, not on the primary used (@pxref{The Two Parts of
11274 Install}).
11275 @c Keep in sync with primary-prefix-couples-documented-valid.sh
11276 So a @code{foo_SCRIPTS} will be installed by
11277 @code{install-data}, and a @code{barexec_SCRIPTS} will be installed by
11278 @code{install-exec}.  You should define your hooks consequently.
11279
11280 @c FIXME should include discussion of variables you can use in these
11281 @c rules
11282
11283 @node Third-Party Makefiles
11284 @section Third-Party @file{Makefile}s
11285
11286 @cindex Third-party packages, interfacing with
11287 @cindex Interfacing with third-party packages
11288
11289 In most projects all @file{Makefile}s are generated by Automake.  In
11290 some cases, however, projects need to embed subdirectories with
11291 handwritten @file{Makefile}s.  For instance, one subdirectory could be
11292 a third-party project with its own build system, not using Automake.
11293
11294 It is possible to list arbitrary directories in @code{SUBDIRS} or
11295 @code{DIST_SUBDIRS} provided each of these directories has a
11296 @file{Makefile} that recognizes all the following recursive targets.
11297
11298 @cindex recursive targets and third-party @file{Makefile}s
11299 When a user runs one of these targets, that target is run recursively
11300 in all subdirectories.  This is why it is important that even
11301 third-party @file{Makefile}s support them.
11302
11303 @table @code
11304 @item all
11305 Compile the entire package.  This is the default target in
11306 Automake-generated @file{Makefile}s, but it does not need to be the
11307 default in third-party @file{Makefile}s.
11308
11309 @item distdir
11310 @trindex distdir
11311 @vindex distdir
11312 @vindex top_distdir
11313 Copy files to distribute into @samp{$(distdir)}, before a tarball is
11314 constructed.  Of course this target is not required if the
11315 @option{no-dist} option (@pxref{Options}) is used.
11316
11317 The variables @samp{$(top_distdir)} and @samp{$(distdir)}
11318 (@pxref{The dist Hook}) will be passed from the outer package to the subpackage
11319 when the @code{distdir} target is invoked.  These two variables have
11320 been adjusted for the directory that is being recursed into, so they
11321 are ready to use.
11322
11323 @item install
11324 @itemx install-data
11325 @itemx install-exec
11326 @itemx uninstall
11327 Install or uninstall files (@pxref{Install}).
11328
11329 @item install-dvi
11330 @itemx install-html
11331 @itemx install-info
11332 @itemx install-ps
11333 @itemx install-pdf
11334 Install only some specific documentation format (@pxref{Texinfo}).
11335
11336 @item installdirs
11337 Create install directories, but do not install any files.
11338
11339 @item check
11340 @itemx installcheck
11341 Check the package (@pxref{Tests}).
11342
11343 @item mostlyclean
11344 @itemx clean
11345 @itemx distclean
11346 @itemx maintainer-clean
11347 Cleaning rules (@pxref{Clean}).
11348
11349 @item dvi
11350 @itemx pdf
11351 @itemx ps
11352 @itemx info
11353 @itemx html
11354 Build the documentation in various formats (@pxref{Texinfo}).
11355
11356 @item tags
11357 @itemx ctags
11358 Build @file{TAGS} and @file{CTAGS} (@pxref{Tags}).
11359 @end table
11360
11361 If you have ever used Gettext in a project, this is a good example of
11362 how third-party @file{Makefile}s can be used with Automake.  The
11363 @file{Makefile}s @command{gettextize} puts in the @file{po/} and
11364 @file{intl/} directories are handwritten @file{Makefile}s that
11365 implement all these targets.  That way they can be added to
11366 @code{SUBDIRS} in Automake packages.
11367
11368 Directories that are only listed in @code{DIST_SUBDIRS} but not in
11369 @code{SUBDIRS} need only the @code{distclean},
11370 @code{maintainer-clean}, and @code{distdir} rules (@pxref{Conditional
11371 Subdirectories}).
11372
11373 Usually, many of these rules are irrelevant to the third-party
11374 subproject, but they are required for the whole package to work.  It's
11375 OK to have a rule that does nothing, so if you are integrating a
11376 third-party project with no documentation or tag support, you could
11377 simply augment its @file{Makefile} as follows:
11378
11379 @example
11380 EMPTY_AUTOMAKE_TARGETS = dvi pdf ps info html tags ctags
11381 .PHONY: $(EMPTY_AUTOMAKE_TARGETS)
11382 $(EMPTY_AUTOMAKE_TARGETS):
11383 @end example
11384
11385 Another aspect of integrating third-party build systems is whether
11386 they support VPATH builds (@pxref{VPATH Builds}).  Obviously if the
11387 subpackage does not support VPATH builds the whole package will not
11388 support VPATH builds.  This in turns means that @samp{make distcheck}
11389 will not work, because it relies on VPATH builds.  Some people can
11390 live without this (actually, many Automake users have never heard of
11391 @samp{make distcheck}).  Other people may prefer to revamp the
11392 existing @file{Makefile}s to support VPATH@.  Doing so does not
11393 necessarily require Automake, only Autoconf is needed (@pxref{Build
11394 Directories, , Build Directories, autoconf, The Autoconf Manual}).
11395 The necessary substitutions: @samp{@@srcdir@@}, @samp{@@top_srcdir@@},
11396 and @samp{@@top_builddir@@} are defined by @file{configure} when it
11397 processes a @file{Makefile} (@pxref{Preset Output Variables, , Preset
11398 Output Variables, autoconf, The Autoconf Manual}), they are not
11399 computed by the Makefile like the aforementioned @samp{$(distdir)} and
11400 @samp{$(top_distdir)} variables.
11401
11402 It is sometimes inconvenient to modify a third-party @file{Makefile}
11403 to introduce the above required targets.  For instance, one may want to
11404 keep the third-party sources untouched to ease upgrades to new
11405 versions.
11406
11407 @cindex @file{GNUmakefile} including @file{Makefile}
11408 Here are two other ideas.  If GNU make is assumed, one possibility is
11409 to add to that subdirectory a @file{GNUmakefile} that defines the
11410 required targets and includes the third-party @file{Makefile}.  For
11411 this to work in VPATH builds, @file{GNUmakefile} must lie in the build
11412 directory; the easiest way to do this is to write a
11413 @file{GNUmakefile.in} instead, and have it processed with
11414 @code{AC_CONFIG_FILES} from the outer package.  For example if we
11415 assume @file{Makefile} defines all targets except the documentation
11416 targets, and that the @code{check} target is actually called
11417 @code{test}, we could write @file{GNUmakefile} (or
11418 @file{GNUmakefile.in}) like this:
11419
11420 @example
11421 # First, include the real Makefile
11422 include Makefile
11423 # Then, define the other targets needed by Automake Makefiles.
11424 .PHONY: dvi pdf ps info html check
11425 dvi pdf ps info html:
11426 check: test
11427 @end example
11428
11429 @cindex Proxy @file{Makefile} for third-party packages
11430 A similar idea that does not use @code{include} is to write a proxy
11431 @file{Makefile} that dispatches rules to the real @file{Makefile},
11432 either with @samp{$(MAKE) -f Makefile.real $(AM_MAKEFLAGS) target} (if
11433 it's OK to rename the original @file{Makefile}) or with @samp{cd
11434 subdir && $(MAKE) $(AM_MAKEFLAGS) target} (if it's OK to store the
11435 subdirectory project one directory deeper).  The good news is that
11436 this proxy @file{Makefile} can be generated with Automake.  All we
11437 need are @option{-local} targets (@pxref{Extending}) that perform the
11438 dispatch.  Of course the other Automake features are available, so you
11439 could decide to let Automake perform distribution or installation.
11440 Here is a possible @file{Makefile.am}:
11441
11442 @example
11443 all-local:
11444         cd subdir && $(MAKE) $(AM_MAKEFLAGS) all
11445 check-local:
11446         cd subdir && $(MAKE) $(AM_MAKEFLAGS) test
11447 clean-local:
11448         cd subdir && $(MAKE) $(AM_MAKEFLAGS) clean
11449
11450 # Assuming the package knows how to install itself
11451 install-data-local:
11452         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-data
11453 install-exec-local:
11454         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-exec
11455 uninstall-local:
11456         cd subdir && $(MAKE) $(AM_MAKEFLAGS) uninstall
11457
11458 # Distribute files from here.
11459 EXTRA_DIST = subdir/Makefile subdir/program.c ...
11460 @end example
11461
11462 Pushing this idea to the extreme, it is also possible to ignore the
11463 subproject build system and build everything from this proxy
11464 @file{Makefile.am}.  This might sound very sensible if you need VPATH
11465 builds but the subproject does not support them.
11466
11467 @node Distributing
11468 @chapter Distributing @file{Makefile.in}s
11469
11470 Automake places no restrictions on the distribution of the resulting
11471 @file{Makefile.in}s.  We still encourage software authors to
11472 distribute their work under terms like those of the GPL, but doing so
11473 is not required to use Automake.
11474
11475 Some of the files that can be automatically installed via the
11476 @option{--add-missing} switch do fall under the GPL@.  However, these also
11477 have a special exception allowing you to distribute them with your
11478 package, regardless of the licensing you choose.
11479
11480
11481 @node API Versioning
11482 @chapter Automake API Versioning
11483
11484 New Automake releases usually include bug fixes and new features.
11485 Unfortunately they may also introduce new bugs and incompatibilities.
11486 This makes four reasons why a package may require a particular Automake
11487 version.
11488
11489 Things get worse when maintaining a large tree of packages, each one
11490 requiring a different version of Automake.  In the past, this meant that
11491 any developer (and sometimes users) had to install several versions of
11492 Automake in different places, and switch @samp{$PATH} appropriately for
11493 each package.
11494
11495 Starting with version 1.6, Automake installs versioned binaries.  This
11496 means you can install several versions of Automake in the same
11497 @samp{$prefix}, and can select an arbitrary Automake version by running
11498 @command{automake-1.6} or @command{automake-1.7} without juggling with
11499 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
11500 will use @command{automake-1.6} explicitly in their rebuild rules.
11501
11502 The number @samp{1.6} in @command{automake-1.6} is Automake's API version,
11503 not Automake's version.  If a bug fix release is made, for instance
11504 Automake 1.6.1, the API version will remain 1.6.  This means that a
11505 package that works with Automake 1.6 should also work with 1.6.1; after
11506 all, this is what people expect from bug fix releases.
11507
11508 If your package relies on a feature or a bug fix introduced in
11509 a release, you can pass this version as an option to Automake to ensure
11510 older releases will not be used.  For instance, use this in your
11511 @file{configure.ac}:
11512
11513 @example
11514   AM_INIT_AUTOMAKE([1.6.1])    dnl Require Automake 1.6.1 or better.
11515 @end example
11516
11517 @noindent
11518 or, in a particular @file{Makefile.am}:
11519
11520 @example
11521   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
11522 @end example
11523
11524 @noindent
11525 Automake will print an error message if its version is
11526 older than the requested version.
11527
11528
11529 @heading What is in the API
11530
11531 Automake's programming interface is not easy to define.  Basically it
11532 should include at least all @strong{documented} variables and targets
11533 that a @file{Makefile.am} author can use, any behavior associated with
11534 them (e.g., the places where @samp{-hook}'s are run), the command line
11535 interface of @command{automake} and @command{aclocal}, @dots{}
11536
11537 @heading What is not in the API
11538
11539 Every undocumented variable, target, or command line option, is not part
11540 of the API@.  You should avoid using them, as they could change from one
11541 version to the other (even in bug fix releases, if this helps to fix a
11542 bug).
11543
11544 If it turns out you need to use such an undocumented feature, contact
11545 @email{automake@@gnu.org} and try to get it documented and exercised by
11546 the test-suite.
11547
11548 @node Upgrading
11549 @chapter Upgrading a Package to a Newer Automake Version
11550
11551 Automake maintains three kind of files in a package.
11552
11553 @itemize
11554 @item @file{aclocal.m4}
11555 @item @file{Makefile.in}s
11556 @item auxiliary tools like @file{install-sh} or @file{py-compile}
11557 @end itemize
11558
11559 @file{aclocal.m4} is generated by @command{aclocal} and contains some
11560 Automake-supplied M4 macros.  Auxiliary tools are installed by
11561 @samp{automake --add-missing} when needed.  @file{Makefile.in}s are
11562 built from @file{Makefile.am} by @command{automake}, and rely on the
11563 definitions of the M4 macros put in @file{aclocal.m4} as well as the
11564 behavior of the auxiliary tools installed.
11565
11566 Because all these files are closely related, it is important to
11567 regenerate all of them when upgrading to a newer Automake release.
11568 The usual way to do that is
11569
11570 @example
11571 aclocal # with any option needed (such a -I m4)
11572 autoconf
11573 automake --add-missing --force-missing
11574 @end example
11575
11576 @noindent
11577 or more conveniently:
11578
11579 @example
11580 autoreconf -vfi
11581 @end example
11582
11583 The use of @option{--force-missing} ensures that auxiliary tools will be
11584 overridden by new versions (@pxref{automake Invocation}).
11585
11586 It is important to regenerate all these files each time Automake is
11587 upgraded, even between bug fixes releases.  For instance, it is not
11588 unusual for a bug fix to involve changes to both the rules generated
11589 in @file{Makefile.in} and the supporting M4 macros copied to
11590 @file{aclocal.m4}.
11591
11592 Presently @command{automake} is able to diagnose situations where
11593 @file{aclocal.m4} has been generated with another version of
11594 @command{aclocal}.  However it never checks whether auxiliary scripts
11595 are up-to-date.  In other words, @command{automake} will tell you when
11596 @command{aclocal} needs to be rerun, but it will never diagnose a
11597 missing @option{--force-missing}.
11598
11599 Before upgrading to a new major release, it is a good idea to read the
11600 file @file{NEWS}.  This file lists all changes between releases: new
11601 features, obsolete constructs, known incompatibilities, and
11602 workarounds.
11603
11604 @node FAQ
11605 @chapter Frequently Asked Questions about Automake
11606
11607 This chapter covers some questions that often come up on the mailing
11608 lists.
11609
11610 @menu
11611 * CVS::                         CVS and generated files
11612 * maintainer-mode::             missing and AM_MAINTAINER_MODE
11613 * Wildcards::                   Why doesn't Automake support wildcards?
11614 * Limitations on File Names::   Limitations on source and installed file names
11615 * Errors with distclean::       Files left in build directory after distclean
11616 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
11617 * Renamed Objects::             Why are object files sometimes renamed?
11618 * Per-Object Flags::            How to simulate per-object flags?
11619 * Multiple Outputs::            Writing rules for tools with many output files
11620 * Hard-Coded Install Paths::    Installing to hard-coded locations
11621 * Debugging Make Rules::        Strategies when things don't work as expected
11622 * Reporting Bugs::              Feedback on bugs and feature requests
11623 @end menu
11624
11625 @node CVS
11626 @section CVS and generated files
11627
11628 @subheading Background: distributed generated Files
11629 @cindex generated files, distributed
11630 @cindex rebuild rules
11631
11632 Packages made with Autoconf and Automake ship with some generated
11633 files like @file{configure} or @file{Makefile.in}.  These files were
11634 generated on the developer's host and are distributed so that
11635 end-users do not have to install the maintainer tools required to
11636 rebuild them.  Other generated files like Lex scanners, Yacc parsers,
11637 or Info documentation, are usually distributed on similar grounds.
11638
11639 Automake outputs rules in @file{Makefile}s to rebuild these files.  For
11640 instance, @command{make} will run @command{autoconf} to rebuild
11641 @file{configure} whenever @file{configure.ac} is changed.  This makes
11642 development safer by ensuring a @file{configure} is never out-of-date
11643 with respect to @file{configure.ac}.
11644
11645 As generated files shipped in packages are up-to-date, and because
11646 @command{tar} preserves times-tamps, these rebuild rules are not
11647 triggered when a user unpacks and builds a package.
11648
11649 @subheading Background: CVS and Timestamps
11650 @cindex timestamps and CVS
11651 @cindex CVS and timestamps
11652
11653 Unless you use CVS keywords (in which case files must be updated at
11654 commit time), CVS preserves timestamp during @samp{cvs commit} and
11655 @samp{cvs import -d} operations.
11656
11657 When you check out a file using @samp{cvs checkout} its timestamp is
11658 set to that of the revision that is being checked out.
11659
11660 However, during @command{cvs update}, files will have the date of the
11661 update, not the original timestamp of this revision.  This is meant to
11662 make sure that @command{make} notices sources files have been updated.
11663
11664 This timestamp shift is troublesome when both sources and generated
11665 files are kept under CVS@.  Because CVS processes files in lexical
11666 order, @file{configure.ac} will appear newer than @file{configure}
11667 after a @command{cvs update} that updates both files, even if
11668 @file{configure} was newer than @file{configure.ac} when it was
11669 checked in.  Calling @command{make} will then trigger a spurious rebuild
11670 of @file{configure}.
11671
11672 @subheading Living with CVS in Autoconfiscated Projects
11673 @cindex CVS and generated files
11674 @cindex generated files and CVS
11675
11676 There are basically two clans amongst maintainers: those who keep all
11677 distributed files under CVS, including generated files, and those who
11678 keep generated files @emph{out} of CVS.
11679
11680 @subsubheading All Files in CVS
11681
11682 @itemize @bullet
11683 @item
11684 The CVS repository contains all distributed files so you know exactly
11685 what is distributed, and you can checkout any prior version entirely.
11686
11687 @item
11688 Maintainers can see how generated files evolve (for instance, you can
11689 see what happens to your @file{Makefile.in}s when you upgrade Automake
11690 and make sure they look OK).
11691
11692 @item
11693 Users do not need the autotools to build a checkout of the project, it
11694 works just like a released tarball.
11695
11696 @item
11697 If users use @command{cvs update} to update their copy, instead of
11698 @command{cvs checkout} to fetch a fresh one, timestamps will be
11699 inaccurate.  Some rebuild rules will be triggered and attempt to
11700 run developer tools such as @command{autoconf} or @command{automake}.
11701
11702 Actually, calls to such tools are all wrapped into a call to the
11703 @command{missing} script discussed later (@pxref{maintainer-mode}).
11704 @command{missing} will take care of fixing the timestamps when these
11705 tools are not installed, so that the build can continue.
11706
11707 @item
11708 In distributed development, developers are likely to have different
11709 version of the maintainer tools installed.  In this case rebuilds
11710 triggered by timestamp lossage will lead to spurious changes
11711 to generated files.  There are several solutions to this:
11712
11713 @itemize
11714 @item
11715 All developers should use the same versions, so that the rebuilt files
11716 are identical to files in CVS@.  (This starts to be difficult when each
11717 project you work on uses different versions.)
11718 @item
11719 Or people use a script to fix the timestamp after a checkout (the GCC
11720 folks have such a script).
11721 @item
11722 Or @file{configure.ac} uses @code{AM_MAINTAINER_MODE}, which will
11723 disable all these rebuild rules by default.  This is further discussed
11724 in @ref{maintainer-mode}.
11725 @end itemize
11726
11727 @item
11728 Although we focused on spurious rebuilds, the converse can also
11729 happen.  CVS's timestamp handling can also let you think an
11730 out-of-date file is up-to-date.
11731
11732 For instance, suppose a developer has modified @file{Makefile.am} and
11733 has rebuilt @file{Makefile.in}, and then decides to do a last-minute
11734 change to @file{Makefile.am} right before checking in both files
11735 (without rebuilding @file{Makefile.in} to account for the change).
11736
11737 This last change to @file{Makefile.am} makes the copy of
11738 @file{Makefile.in} out-of-date.  Since CVS processes files
11739 alphabetically, when another developer @samp{cvs update}s his or her
11740 tree, @file{Makefile.in} will happen to be newer than
11741 @file{Makefile.am}.  This other developer will not see that
11742 @file{Makefile.in} is out-of-date.
11743
11744 @end itemize
11745
11746 @subsubheading Generated Files out of CVS
11747
11748 One way to get CVS and @command{make} working peacefully is to never
11749 store generated files in CVS, i.e., do not CVS-control files that
11750 are @file{Makefile} targets (also called @emph{derived} files).
11751
11752 This way developers are not annoyed by changes to generated files.  It
11753 does not matter if they all have different versions (assuming they are
11754 compatible, of course).  And finally, timestamps are not lost, changes
11755 to sources files can't be missed as in the
11756 @file{Makefile.am}/@file{Makefile.in} example discussed earlier.
11757
11758 The drawback is that the CVS repository is not an exact copy of what
11759 is distributed and that users now need to install various development
11760 tools (maybe even specific versions) before they can build a checkout.
11761 But, after all, CVS's job is versioning, not distribution.
11762
11763 Allowing developers to use different versions of their tools can also
11764 hide bugs during distributed development.  Indeed, developers will be
11765 using (hence testing) their own generated files, instead of the
11766 generated files that will be released actually.  The developer who
11767 prepares the tarball might be using a version of the tool that
11768 produces bogus output (for instance a non-portable C file), something
11769 other developers could have noticed if they weren't using their own
11770 versions of this tool.
11771
11772 @subheading Third-party Files
11773 @cindex CVS and third-party files
11774 @cindex third-party files and CVS
11775
11776 Another class of files not discussed here (because they do not cause
11777 timestamp issues) are files that are shipped with a package, but
11778 maintained elsewhere.  For instance, tools like @command{gettextize}
11779 and @command{autopoint} (from Gettext) or @command{libtoolize} (from
11780 Libtool), will install or update files in your package.
11781
11782 These files, whether they are kept under CVS or not, raise similar
11783 concerns about version mismatch between developers' tools.  The
11784 Gettext manual has a section about this, see @ref{CVS Issues, CVS
11785 Issues, Integrating with CVS, gettext, GNU gettext tools}.
11786
11787 @node maintainer-mode
11788 @section @command{missing} and @code{AM_MAINTAINER_MODE}
11789
11790 @subheading @command{missing}
11791 @cindex @command{missing}, purpose
11792
11793 The @command{missing} script is a wrapper around several maintainer
11794 tools, designed to warn users if a maintainer tool is required but
11795 missing.  Typical maintainer tools are @command{autoconf},
11796 @command{automake}, @command{bison}, etc.  Because file generated by
11797 these tools are shipped with the other sources of a package, these
11798 tools shouldn't be required during a user build and they are not
11799 checked for in @file{configure}.
11800
11801 However, if for some reason a rebuild rule is triggered and involves a
11802 missing tool, @command{missing} will notice it and warn the user.
11803 Besides the warning, when a tool is missing, @command{missing} will
11804 attempt to fix timestamps in a way that allows the build to continue.
11805 For instance, @command{missing} will touch @file{configure} if
11806 @command{autoconf} is not installed.  When all distributed files are
11807 kept under version control, this feature of @command{missing} allows a
11808 user @emph{with no maintainer tools} to build a package off its version
11809 control repository, bypassing any timestamp inconsistency (implied by
11810 e.g.@: @samp{cvs update} or @samp{git clone}).
11811
11812 If the required tool is installed, @command{missing} will run it and
11813 won't attempt to continue after failures.  This is correct during
11814 development: developers love fixing failures.  However, users with
11815 wrong versions of maintainer tools may get an error when the rebuild
11816 rule is spuriously triggered, halting the build.  This failure to let
11817 the build continue is one of the arguments of the
11818 @code{AM_MAINTAINER_MODE} advocates.
11819
11820 @subheading @code{AM_MAINTAINER_MODE}
11821 @cindex @code{AM_MAINTAINER_MODE}, purpose
11822 @acindex AM_MAINTAINER_MODE
11823
11824 @code{AM_MAINTAINER_MODE} allows you to choose whether the so called
11825 "rebuild rules" should be enabled or disabled.  With
11826 @code{AM_MAINTAINER_MODE([enable])}, they are enabled by default,
11827 otherwise they are disabled by default.  In the latter case, if
11828 you have @code{AM_MAINTAINER_MODE} in @file{configure.ac}, and run
11829 @samp{./configure && make}, then @command{make} will *never* attempt to
11830 rebuild @file{configure}, @file{Makefile.in}s, Lex or Yacc outputs, etc.
11831 I.e., this disables build rules for files that are usually distributed
11832 and that users should normally not have to update.
11833
11834 The user can override the default setting by passing either
11835 @samp{--enable-maintainer-mode} or @samp{--disable-maintainer-mode}
11836 to @command{configure}.
11837
11838 People use @code{AM_MAINTAINER_MODE} either because they do not want their
11839 users (or themselves) annoyed by timestamps lossage (@pxref{CVS}), or
11840 because they simply can't stand the rebuild rules and prefer running
11841 maintainer tools explicitly.
11842
11843 @code{AM_MAINTAINER_MODE} also allows you to disable some custom build
11844 rules conditionally.  Some developers use this feature to disable
11845 rules that need exotic tools that users may not have available.
11846
11847 Several years ago Fran@,{c}ois Pinard pointed out several arguments
11848 against this @code{AM_MAINTAINER_MODE} macro.  Most of them relate to
11849 insecurity.  By removing dependencies you get non-dependable builds:
11850 changes to sources files can have no effect on generated files and this
11851 can be very confusing when unnoticed.  He adds that security shouldn't
11852 be reserved to maintainers (what @option{--enable-maintainer-mode}
11853 suggests), on the contrary.  If one user has to modify a
11854 @file{Makefile.am}, then either @file{Makefile.in} should be updated
11855 or a warning should be output (this is what Automake uses
11856 @command{missing} for) but the last thing you want is that nothing
11857 happens and the user doesn't notice it (this is what happens when
11858 rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
11859
11860 Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro was
11861 swayed by Fran@,{c}ois's arguments, and got rid of
11862 @code{AM_MAINTAINER_MODE} in all of his packages.
11863
11864 Still many people continue to use @code{AM_MAINTAINER_MODE}, because
11865 it helps them working on projects where all files are kept under version
11866 control, and because @command{missing} isn't enough if you have the
11867 wrong version of the tools.
11868
11869
11870 @node Wildcards
11871 @section Why doesn't Automake support wildcards?
11872 @cindex wildcards
11873
11874 Developers are lazy.  They would often like to use wildcards in
11875 @file{Makefile.am}s, so that they would not need to remember to
11876 update @file{Makefile.am}s every time they add, delete, or rename
11877 a file.
11878
11879 There are several objections to this:
11880 @itemize
11881 @item
11882 When using CVS (or similar) developers need to remember they have to
11883 run @samp{cvs add} or @samp{cvs rm} anyway.  Updating
11884 @file{Makefile.am} accordingly quickly becomes a reflex.
11885
11886 Conversely, if your application doesn't compile
11887 because you forgot to add a file in @file{Makefile.am}, it will help
11888 you remember to @samp{cvs add} it.
11889
11890 @item
11891 Using wildcards makes it easy to distribute files by mistake.  For
11892 instance, some code a developer is experimenting with (a test case,
11893 say) that should not be part of the distribution.
11894
11895 @item
11896 Using wildcards it's easy to omit some files by mistake.  For
11897 instance, one developer creates a new file, uses it in many places,
11898 but forgets to commit it.  Another developer then checks out the
11899 incomplete project and is able to run @samp{make dist} successfully,
11900 even though a file is missing. By listing files, @samp{make dist}
11901 @emph{will} complain.
11902
11903 @item
11904 Wildcards are not portable to some non-GNU @command{make} implementations,
11905 e.g., NetBSD @command{make} will not expand globs such as @samp{*} in
11906 prerequisites of a target.
11907
11908 @item
11909 Finally, it's really hard to @emph{forget} to add a file to
11910 @file{Makefile.am}: files that are not listed in @file{Makefile.am} are
11911 not compiled or installed, so you can't even test them.
11912 @end itemize
11913
11914 Still, these are philosophical objections, and as such you may disagree,
11915 or find enough value in wildcards to dismiss all of them.  Before you
11916 start writing a patch against Automake to teach it about wildcards,
11917 let's see the main technical issue: portability.
11918
11919 Although @samp{$(wildcard ...)} works with GNU @command{make}, it is
11920 not portable to other @command{make} implementations.
11921
11922 The only way Automake could support @command{$(wildcard ...)} is by
11923 expending @command{$(wildcard ...)} when @command{automake} is run.
11924 The resulting @file{Makefile.in}s would be portable since they would
11925 list all files and not use @samp{$(wildcard ...)}.  However that
11926 means developers would need to remember to run @command{automake} each
11927 time they add, delete, or rename files.
11928
11929 Compared to editing @file{Makefile.am}, this is a very small gain.  Sure,
11930 it's easier and faster to type @samp{automake; make} than to type
11931 @samp{emacs Makefile.am; make}.  But nobody bothered enough to write a
11932 patch to add support for this syntax.  Some people use scripts to
11933 generate file lists in @file{Makefile.am} or in separate
11934 @file{Makefile} fragments.
11935
11936 Even if you don't care about portability, and are tempted to use
11937 @samp{$(wildcard ...)} anyway because you target only GNU Make, you
11938 should know there are many places where Automake needs to know exactly
11939 which files should be processed.  As Automake doesn't know how to
11940 expand @samp{$(wildcard ...)}, you cannot use it in these places.
11941 @samp{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
11942 variables as far Automake is concerned.
11943
11944 You can get warnings about @samp{$(wildcard ...}) constructs using the
11945 @option{-Wportability} flag.
11946
11947 @node Limitations on File Names
11948 @section Limitations on File Names
11949 @cindex file names, limitations on
11950
11951 Automake attempts to support all kinds of file names, even those that
11952 contain unusual characters or are unusually long.  However, some
11953 limitations are imposed by the underlying operating system and tools.
11954
11955 Most operating systems prohibit the use of the null byte in file
11956 names, and reserve @samp{/} as a directory separator.  Also, they
11957 require that file names are properly encoded for the user's locale.
11958 Automake is subject to these limits.
11959
11960 Portable packages should limit themselves to POSIX file
11961 names.  These can contain ASCII letters and digits,
11962 @samp{_}, @samp{.}, and @samp{-}.  File names consist of components
11963 separated by @samp{/}.  File name components cannot begin with
11964 @samp{-}.
11965
11966 Portable POSIX file names cannot contain components that exceed a
11967 14-byte limit, but nowadays it's normally safe to assume the
11968 more-generous XOPEN limit of 255 bytes.  POSIX
11969 limits file names to 255 bytes (XOPEN allows 1023 bytes),
11970 but you may want to limit a source tarball to file names of 99 bytes
11971 to avoid interoperability problems with old versions of @command{tar}.
11972
11973 If you depart from these rules (e.g., by using non-ASCII
11974 characters in file names, or by using lengthy file names), your
11975 installers may have problems for reasons unrelated to Automake.
11976 However, if this does not concern you, you should know about the
11977 limitations imposed by Automake itself.  These limitations are
11978 undesirable, but some of them seem to be inherent to underlying tools
11979 like Autoconf, Make, M4, and the shell.  They fall into three
11980 categories: install directories, build directories, and file names.
11981
11982 The following characters:
11983
11984 @example
11985 @r{newline} " # $ ' `
11986 @end example
11987
11988 should not appear in the names of install directories.  For example,
11989 the operand of @command{configure}'s @option{--prefix} option should
11990 not contain these characters.
11991
11992 Build directories suffer the same limitations as install directories,
11993 and in addition should not contain the following characters:
11994
11995 @example
11996 & @@ \
11997 @end example
11998
11999 For example, the full name of the directory containing the source
12000 files should not contain these characters.
12001
12002 Source and installation file names like @file{main.c} are limited even
12003 further: they should conform to the POSIX/XOPEN
12004 rules described above.  In addition, if you plan to port to
12005 non-POSIX environments, you should avoid file names that
12006 differ only in case (e.g., @file{makefile} and @file{Makefile}).
12007 Nowadays it is no longer worth worrying about the 8.3 limits of
12008 DOS file systems.
12009
12010 @c FIXME This should probably be moved in the "Checking the Distribution"
12011 @c FIXME section...
12012 @node Errors with distclean
12013 @section Errors with distclean
12014 @cindex @code{distclean}, diagnostic
12015 @cindex @samp{make distclean}, diagnostic
12016 @cindex dependencies and distributed files
12017 @trindex distclean
12018
12019 This is a diagnostic you might encounter while running @samp{make
12020 distcheck}.
12021
12022 As explained in @ref{Checking the Distribution}, @samp{make distcheck}
12023 attempts to build and check your package for errors like this one.
12024
12025 @samp{make distcheck} will perform a @code{VPATH} build of your
12026 package (@pxref{VPATH Builds}), and then call @samp{make distclean}.
12027 Files left in the build directory after @samp{make distclean} has run
12028 are listed after this error.
12029
12030 This diagnostic really covers two kinds of errors:
12031
12032 @itemize @bullet
12033 @item
12034 files that are forgotten by distclean;
12035 @item
12036 distributed files that are erroneously rebuilt.
12037 @end itemize
12038
12039 The former left-over files are not distributed, so the fix is to mark
12040 them for cleaning (@pxref{Clean}), this is obvious and doesn't deserve
12041 more explanations.
12042
12043 The latter bug is not always easy to understand and fix, so let's
12044 proceed with an example.  Suppose our package contains a program for
12045 which we want to build a man page using @command{help2man}.  GNU
12046 @command{help2man} produces simple manual pages from the @option{--help}
12047 and @option{--version} output of other commands (@pxref{Top, , Overview,
12048 help2man, The Help2man Manual}).  Because we don't want to force our
12049 users to install @command{help2man}, we decide to distribute the
12050 generated man page using the following setup.
12051
12052 @example
12053 # This Makefile.am is bogus.
12054 bin_PROGRAMS = foo
12055 foo_SOURCES = foo.c
12056 dist_man_MANS = foo.1
12057
12058 foo.1: foo$(EXEEXT)
12059         help2man --output=foo.1 ./foo$(EXEEXT)
12060 @end example
12061
12062 This will effectively distribute the man page.  However,
12063 @samp{make distcheck} will fail with:
12064
12065 @example
12066 ERROR: files left in build directory after distclean:
12067 ./foo.1
12068 @end example
12069
12070 Why was @file{foo.1} rebuilt?  Because although distributed,
12071 @file{foo.1} depends on a non-distributed built file:
12072 @file{foo$(EXEEXT)}.  @file{foo$(EXEEXT)} is built by the user, so it
12073 will always appear to be newer than the distributed @file{foo.1}.
12074
12075 @samp{make distcheck} caught an inconsistency in our package.  Our
12076 intent was to distribute @file{foo.1} so users do not need to install
12077 @command{help2man}, however since this rule causes this file to be
12078 always rebuilt, users @emph{do} need @command{help2man}.  Either we
12079 should ensure that @file{foo.1} is not rebuilt by users, or there is
12080 no point in distributing @file{foo.1}.
12081
12082 More generally, the rule is that distributed files should never depend
12083 on non-distributed built files.  If you distribute something
12084 generated, distribute its sources.
12085
12086 One way to fix the above example, while still distributing
12087 @file{foo.1} is to not depend on @file{foo$(EXEEXT)}.  For instance,
12088 assuming @command{foo --version} and @command{foo --help} do not
12089 change unless @file{foo.c} or @file{configure.ac} change, we could
12090 write the following @file{Makefile.am}:
12091
12092 @example
12093 bin_PROGRAMS = foo
12094 foo_SOURCES = foo.c
12095 dist_man_MANS = foo.1
12096
12097 foo.1: foo.c $(top_srcdir)/configure.ac
12098         $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
12099         help2man --output=foo.1 ./foo$(EXEEXT)
12100 @end example
12101
12102 This way, @file{foo.1} will not get rebuilt every time
12103 @file{foo$(EXEEXT)} changes.  The @command{make} call makes sure
12104 @file{foo$(EXEEXT)} is up-to-date before @command{help2man}.  Another
12105 way to ensure this would be to use separate directories for binaries
12106 and man pages, and set @code{SUBDIRS} so that binaries are built
12107 before man pages.
12108
12109 We could also decide not to distribute @file{foo.1}.  In
12110 this case it's fine to have @file{foo.1} dependent upon
12111 @file{foo$(EXEEXT)}, since both will have to be rebuilt.
12112 However it would be impossible to build the package in a
12113 cross-compilation, because building @file{foo.1} involves
12114 an @emph{execution} of @file{foo$(EXEEXT)}.
12115
12116 Another context where such errors are common is when distributed files
12117 are built by tools that are built by the package.  The pattern is
12118 similar:
12119
12120 @example
12121 distributed-file: built-tools distributed-sources
12122         build-command
12123 @end example
12124
12125 @noindent
12126 should be changed to
12127
12128 @example
12129 distributed-file: distributed-sources
12130         $(MAKE) $(AM_MAKEFLAGS) built-tools
12131         build-command
12132 @end example
12133
12134 @noindent
12135 or you could choose not to distribute @file{distributed-file}, if
12136 cross-compilation does not matter.
12137
12138 The points made through these examples are worth a summary:
12139
12140 @cartouche
12141 @itemize
12142 @item
12143 Distributed files should never depend upon non-distributed built
12144 files.
12145 @item
12146 Distributed files should be distributed with all their dependencies.
12147 @item
12148 If a file is @emph{intended} to be rebuilt by users, then there is no point
12149 in distributing it.
12150 @end itemize
12151 @end cartouche
12152
12153 @vrindex distcleancheck_listfiles
12154 For desperate cases, it's always possible to disable this check by
12155 setting @code{distcleancheck_listfiles} as documented in @ref{Checking
12156 the Distribution}.
12157 Make sure you do understand the reason why @samp{make distcheck}
12158 complains before you do this.  @code{distcleancheck_listfiles} is a
12159 way to @emph{hide} errors, not to fix them.  You can always do better.
12160
12161 @node Flag Variables Ordering
12162 @section Flag Variables Ordering
12163 @cindex Ordering flag variables
12164 @cindex Flag variables, ordering
12165
12166 @display
12167 What is the difference between @code{AM_CFLAGS}, @code{CFLAGS}, and
12168 @code{mumble_CFLAGS}?
12169 @end display
12170
12171 @display
12172 Why does @command{automake} output @code{CPPFLAGS} after
12173 @code{AM_CPPFLAGS} on compile lines?  Shouldn't it be the converse?
12174 @end display
12175
12176 @display
12177 My @file{configure} adds some warning flags into @code{CXXFLAGS}.  In
12178 one @file{Makefile.am} I would like to append a new flag, however if I
12179 put the flag into @code{AM_CXXFLAGS} it is prepended to the other
12180 flags, not appended.
12181 @end display
12182
12183 @subheading Compile Flag Variables
12184 @cindex Flag Variables, Ordering
12185 @cindex Compile Flag Variables
12186 @cindex @code{AM_CCASFLAGS} and @code{CCASFLAGS}
12187 @cindex @code{AM_CFLAGS} and @code{CFLAGS}
12188 @cindex @code{AM_CPPFLAGS} and @code{CPPFLAGS}
12189 @cindex @code{AM_CXXFLAGS} and @code{CXXFLAGS}
12190 @cindex @code{AM_FCFLAGS} and @code{FCFLAGS}
12191 @cindex @code{AM_FFLAGS} and @code{FFLAGS}
12192 @cindex @code{AM_GCJFLAGS} and @code{GCJFLAGS}
12193 @cindex @code{AM_LDFLAGS} and @code{LDFLAGS}
12194 @cindex @code{AM_LFLAGS} and @code{LFLAGS}
12195 @cindex @code{AM_LIBTOOLFLAGS} and @code{LIBTOOLFLAGS}
12196 @cindex @code{AM_OBJCFLAGS} and @code{OBJCFLAGS}
12197 @cindex @code{AM_RFLAGS} and @code{RFLAGS}
12198 @cindex @code{AM_UPCFLAGS} and @code{UPCFLAGS}
12199 @cindex @code{AM_YFLAGS} and @code{YFLAGS}
12200 @cindex @code{CCASFLAGS} and @code{AM_CCASFLAGS}
12201 @cindex @code{CFLAGS} and @code{AM_CFLAGS}
12202 @cindex @code{CPPFLAGS} and @code{AM_CPPFLAGS}
12203 @cindex @code{CXXFLAGS} and @code{AM_CXXFLAGS}
12204 @cindex @code{FCFLAGS} and @code{AM_FCFLAGS}
12205 @cindex @code{FFLAGS} and @code{AM_FFLAGS}
12206 @cindex @code{GCJFLAGS} and @code{AM_GCJFLAGS}
12207 @cindex @code{LDFLAGS} and @code{AM_LDFLAGS}
12208 @cindex @code{LFLAGS} and @code{AM_LFLAGS}
12209 @cindex @code{LIBTOOLFLAGS} and @code{AM_LIBTOOLFLAGS}
12210 @cindex @code{OBJCFLAGS} and @code{AM_OBJCFLAGS}
12211 @cindex @code{RFLAGS} and @code{AM_RFLAGS}
12212 @cindex @code{UPCFLAGS} and @code{AM_UPCFLAGS}
12213 @cindex @code{YFLAGS} and @code{AM_YFLAGS}
12214
12215 This section attempts to answer all the above questions.  We will
12216 mostly discuss @code{CPPFLAGS} in our examples, but actually the
12217 answer holds for all the compile flags used in Automake:
12218 @code{CCASFLAGS}, @code{CFLAGS}, @code{CPPFLAGS}, @code{CXXFLAGS},
12219 @code{FCFLAGS}, @code{FFLAGS}, @code{GCJFLAGS}, @code{LDFLAGS},
12220 @code{LFLAGS}, @code{LIBTOOLFLAGS}, @code{OBJCFLAGS}, @code{RFLAGS},
12221 @code{UPCFLAGS}, and @code{YFLAGS}.
12222
12223 @code{CPPFLAGS}, @code{AM_CPPFLAGS}, and @code{mumble_CPPFLAGS} are
12224 three variables that can be used to pass flags to the C preprocessor
12225 (actually these variables are also used for other languages like C++
12226 or preprocessed Fortran).  @code{CPPFLAGS} is the user variable
12227 (@pxref{User Variables}), @code{AM_CPPFLAGS} is the Automake variable,
12228 and @code{mumble_CPPFLAGS} is the variable specific to the
12229 @code{mumble} target (we call this a per-target variable,
12230 @pxref{Program and Library Variables}).
12231
12232 Automake always uses two of these variables when compiling C sources
12233 files.  When compiling an object file for the @code{mumble} target,
12234 the first variable will be @code{mumble_CPPFLAGS} if it is defined, or
12235 @code{AM_CPPFLAGS} otherwise.  The second variable is always
12236 @code{CPPFLAGS}.
12237
12238 In the following example,
12239
12240 @example
12241 bin_PROGRAMS = foo bar
12242 foo_SOURCES = xyz.c
12243 bar_SOURCES = main.c
12244 foo_CPPFLAGS = -DFOO
12245 AM_CPPFLAGS = -DBAZ
12246 @end example
12247
12248 @noindent
12249 @file{xyz.o} will be compiled with @samp{$(foo_CPPFLAGS) $(CPPFLAGS)},
12250 (because @file{xyz.o} is part of the @code{foo} target), while
12251 @file{main.o} will be compiled with @samp{$(AM_CPPFLAGS) $(CPPFLAGS)}
12252 (because there is no per-target variable for target @code{bar}).
12253
12254 The difference between @code{mumble_CPPFLAGS} and @code{AM_CPPFLAGS}
12255 being clear enough, let's focus on @code{CPPFLAGS}.  @code{CPPFLAGS}
12256 is a user variable, i.e., a variable that users are entitled to modify
12257 in order to compile the package.  This variable, like many others,
12258 is documented at the end of the output of @samp{configure --help}.
12259
12260 For instance, someone who needs to add @file{/home/my/usr/include} to
12261 the C compiler's search path would configure a package with
12262
12263 @example
12264 ./configure CPPFLAGS='-I /home/my/usr/include'
12265 @end example
12266
12267 @noindent
12268 and this flag would be propagated to the compile rules of all
12269 @file{Makefile}s.
12270
12271 It is also not uncommon to override a user variable at
12272 @command{make}-time.  Many installers do this with @code{prefix}, but
12273 this can be useful with compiler flags too.  For instance, if, while
12274 debugging a C++ project, you need to disable optimization in one
12275 specific object file, you can run something like
12276
12277 @example
12278 rm file.o
12279 make CXXFLAGS=-O0 file.o
12280 make
12281 @end example
12282
12283 The reason @samp{$(CPPFLAGS)} appears after @samp{$(AM_CPPFLAGS)} or
12284 @samp{$(mumble_CPPFLAGS)} in the compile command is that users
12285 should always have the last say.  It probably makes more sense if you
12286 think about it while looking at the @samp{CXXFLAGS=-O0} above, which
12287 should supersede any other switch from @code{AM_CXXFLAGS} or
12288 @code{mumble_CXXFLAGS} (and this of course replaces the previous value
12289 of @code{CXXFLAGS}).
12290
12291 You should never redefine a user variable such as @code{CPPFLAGS} in
12292 @file{Makefile.am}.  Use @samp{automake -Woverride} to diagnose such
12293 mistakes.  Even something like
12294
12295 @example
12296 CPPFLAGS = -DDATADIR=\"$(datadir)\" @@CPPFLAGS@@
12297 @end example
12298
12299 @noindent
12300 is erroneous.  Although this preserves @file{configure}'s value of
12301 @code{CPPFLAGS}, the definition of @code{DATADIR} will disappear if a
12302 user attempts to override @code{CPPFLAGS} from the @command{make}
12303 command line.
12304
12305 @example
12306 AM_CPPFLAGS = -DDATADIR=\"$(datadir)\"
12307 @end example
12308
12309 @noindent
12310 is all that is needed here if no per-target flags are used.
12311
12312 You should not add options to these user variables within
12313 @file{configure} either, for the same reason.  Occasionally you need
12314 to modify these variables to perform a test, but you should reset
12315 their values afterwards.  In contrast, it is OK to modify the
12316 @samp{AM_} variables within @file{configure} if you @code{AC_SUBST}
12317 them, but it is rather rare that you need to do this, unless you
12318 really want to change the default definitions of the @samp{AM_}
12319 variables in all @file{Makefile}s.
12320
12321 What we recommend is that you define extra flags in separate
12322 variables.  For instance, you may write an Autoconf macro that computes
12323 a set of warning options for the C compiler, and @code{AC_SUBST} them
12324 in @code{WARNINGCFLAGS}; you may also have an Autoconf macro that
12325 determines which compiler and which linker flags should be used to
12326 link with library @file{libfoo}, and @code{AC_SUBST} these in
12327 @code{LIBFOOCFLAGS} and @code{LIBFOOLDFLAGS}.  Then, a
12328 @file{Makefile.am} could use these variables as follows:
12329
12330 @example
12331 AM_CFLAGS = $(WARNINGCFLAGS)
12332 bin_PROGRAMS = prog1 prog2
12333 prog1_SOURCES = @dots{}
12334 prog2_SOURCES = @dots{}
12335 prog2_CFLAGS = $(LIBFOOCFLAGS) $(AM_CFLAGS)
12336 prog2_LDFLAGS = $(LIBFOOLDFLAGS)
12337 @end example
12338
12339 In this example both programs will be compiled with the flags
12340 substituted into @samp{$(WARNINGCFLAGS)}, and @code{prog2} will
12341 additionally be compiled with the flags required to link with
12342 @file{libfoo}.
12343
12344 Note that listing @code{AM_CFLAGS} in a per-target @code{CFLAGS}
12345 variable is a common idiom to ensure that @code{AM_CFLAGS} applies to
12346 every target in a @file{Makefile.in}.
12347
12348 Using variables like this gives you full control over the ordering of
12349 the flags.  For instance, if there is a flag in $(WARNINGCFLAGS) that
12350 you want to negate for a particular target, you can use something like
12351 @samp{prog1_CFLAGS = $(AM_CFLAGS) -no-flag}.  If all these flags had
12352 been forcefully appended to @code{CFLAGS}, there would be no way to
12353 disable one flag.  Yet another reason to leave user variables to
12354 users.
12355
12356 Finally, we have avoided naming the variable of the example
12357 @code{LIBFOO_LDFLAGS} (with an underscore) because that would cause
12358 Automake to think that this is actually a per-target variable (like
12359 @code{mumble_LDFLAGS}) for some non-declared @code{LIBFOO} target.
12360
12361 @subheading Other Variables
12362
12363 There are other variables in Automake that follow similar principles
12364 to allow user options.  For instance, Texinfo rules (@pxref{Texinfo})
12365 use @code{MAKEINFOFLAGS} and @code{AM_MAKEINFOFLAGS}.  Similarly,
12366 DejaGnu tests (@pxref{DejaGnu Tests}) use @code{RUNTESTDEFAULTFLAGS} and
12367 @code{AM_RUNTESTDEFAULTFLAGS}.  The tags and ctags rules
12368 (@pxref{Tags}) use @code{ETAGSFLAGS}, @code{AM_ETAGSFLAGS},
12369 @code{CTAGSFLAGS}, and @code{AM_CTAGSFLAGS}.  Java rules
12370 (@pxref{Java}) use @code{JAVACFLAGS} and @code{AM_JAVACFLAGS}.  None
12371 of these rules support per-target flags (yet).
12372
12373 To some extent, even @code{AM_MAKEFLAGS} (@pxref{Subdirectories})
12374 obeys this naming scheme.  The slight difference is that
12375 @code{MAKEFLAGS} is passed to sub-@command{make}s implicitly by
12376 @command{make} itself.
12377
12378 However you should not think that all variables ending with
12379 @code{FLAGS} follow this convention.  For instance,
12380 @code{DISTCHECK_CONFIGURE_FLAGS} (@pxref{Checking the Distribution}) and
12381 @code{ACLOCAL_AMFLAGS} (see @ref{Rebuilding} and @ref{Local Macros}),
12382 are two variables that are only useful to the maintainer and have no
12383 user counterpart.
12384
12385 @code{ARFLAGS} (@pxref{A Library}) is usually defined by Automake and
12386 has neither @code{AM_} nor per-target cousin.
12387
12388 Finally you should not think that the existence of a per-target
12389 variable implies the existence of an @code{AM_} variable or of a user
12390 variable.  For instance, the @code{mumble_LDADD} per-target variable
12391 overrides the makefile-wide @code{LDADD} variable (which is not a user
12392 variable), and @code{mumble_LIBADD} exists only as a per-target
12393 variable.  @xref{Program and Library Variables}.
12394
12395
12396 @node Renamed Objects
12397 @section Why are object files sometimes renamed?
12398
12399 This happens when per-target compilation flags are used.  Object
12400 files need to be renamed just in case they would clash with object
12401 files compiled from the same sources, but with different flags.
12402 Consider the following example.
12403
12404 @example
12405 bin_PROGRAMS = true false
12406 true_SOURCES = generic.c
12407 true_CPPFLAGS = -DEXIT_CODE=0
12408 false_SOURCES = generic.c
12409 false_CPPFLAGS = -DEXIT_CODE=1
12410 @end example
12411
12412 @noindent
12413 Obviously the two programs are built from the same source, but it
12414 would be bad if they shared the same object, because @file{generic.o}
12415 cannot be built with both @samp{-DEXIT_CODE=0} @emph{and}
12416 @samp{-DEXIT_CODE=1}.  Therefore @command{automake} outputs rules to
12417 build two different objects: @file{true-generic.o} and
12418 @file{false-generic.o}.
12419
12420 @command{automake} doesn't actually look whether source files are
12421 shared to decide if it must rename objects.  It will just rename all
12422 objects of a target as soon as it sees per-target compilation flags
12423 used.
12424
12425 It's OK to share object files when per-target compilation flags are not
12426 used.  For instance, @file{true} and @file{false} will both use
12427 @file{version.o} in the following example.
12428
12429 @example
12430 AM_CPPFLAGS = -DVERSION=1.0
12431 bin_PROGRAMS = true false
12432 true_SOURCES = true.c version.c
12433 false_SOURCES = false.c version.c
12434 @end example
12435
12436 Note that the renaming of objects is also affected by the
12437 @code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
12438
12439
12440 @node Per-Object Flags
12441 @section Per-Object Flags Emulation
12442 @cindex Per-object flags, emulated
12443
12444 @display
12445 One of my source files needs to be compiled with different flags.  How
12446 do I do?
12447 @end display
12448
12449 Automake supports per-program and per-library compilation flags (see
12450 @ref{Program and Library Variables} and @ref{Flag Variables
12451 Ordering}).  With this you can define compilation flags that apply to
12452 all files compiled for a target.  For instance, in
12453
12454 @example
12455 bin_PROGRAMS = foo
12456 foo_SOURCES = foo.c foo.h bar.c bar.h main.c
12457 foo_CFLAGS = -some -flags
12458 @end example
12459
12460 @noindent
12461 @file{foo-foo.o}, @file{foo-bar.o}, and @file{foo-main.o} will all be
12462 compiled with @samp{-some -flags}.  (If you wonder about the names of
12463 these object files, see @ref{Renamed Objects}.)  Note that
12464 @code{foo_CFLAGS} gives the flags to use when compiling all the C
12465 sources of the @emph{program} @code{foo}, it has nothing to do with
12466 @file{foo.c} or @file{foo-foo.o} specifically.
12467
12468 What if @file{foo.c} needs to be compiled into @file{foo.o} using some
12469 specific flags, that none of the other files requires?  Obviously
12470 per-program flags are not directly applicable here.  Something like
12471 per-object flags are expected, i.e., flags that would be used only
12472 when creating @file{foo-foo.o}.  Automake does not support that,
12473 however this is easy to simulate using a library that contains only
12474 that object, and compiling this library with per-library flags.
12475
12476 @example
12477 bin_PROGRAMS = foo
12478 foo_SOURCES = bar.c bar.h main.c
12479 foo_CFLAGS = -some -flags
12480 foo_LDADD = libfoo.a
12481 noinst_LIBRARIES = libfoo.a
12482 libfoo_a_SOURCES = foo.c foo.h
12483 libfoo_a_CFLAGS = -some -other -flags
12484 @end example
12485
12486 Here @file{foo-bar.o} and @file{foo-main.o} will all be
12487 compiled with @samp{-some -flags}, while @file{libfoo_a-foo.o} will
12488 be compiled using @samp{-some -other -flags}.  Eventually, all
12489 three objects will be linked to form @file{foo}.
12490
12491 This trick can also be achieved using Libtool convenience libraries,
12492 for instance @samp{noinst_LTLIBRARIES = libfoo.la} (@pxref{Libtool
12493 Convenience Libraries}).
12494
12495 Another tempting idea to implement per-object flags is to override the
12496 compile rules @command{automake} would output for these files.
12497 Automake will not define a rule for a target you have defined, so you
12498 could think about defining the @samp{foo-foo.o: foo.c} rule yourself.
12499 We recommend against this, because this is error prone.  For instance,
12500 if you add such a rule to the first example, it will break the day you
12501 decide to remove @code{foo_CFLAGS} (because @file{foo.c} will then be
12502 compiled as @file{foo.o} instead of @file{foo-foo.o}, @pxref{Renamed
12503 Objects}).  Also in order to support dependency tracking, the two
12504 @file{.o}/@file{.obj} extensions, and all the other flags variables
12505 involved in a compilation, you will end up modifying a copy of the
12506 rule previously output by @command{automake} for this file.  If a new
12507 release of Automake generates a different rule, your copy will need to
12508 be updated by hand.
12509
12510 @node Multiple Outputs
12511 @section Handling Tools that Produce Many Outputs
12512 @cindex multiple outputs, rules with
12513 @cindex many outputs, rules with
12514 @cindex rules with multiple outputs
12515
12516 This section describes a @command{make} idiom that can be used when a
12517 tool produces multiple output files.  It is not specific to Automake
12518 and can be used in ordinary @file{Makefile}s.
12519
12520 Suppose we have a program called @command{foo} that will read one file
12521 called @file{data.foo} and produce two files named @file{data.c} and
12522 @file{data.h}.  We want to write a @file{Makefile} rule that captures
12523 this one-to-two dependency.
12524
12525 The naive rule is incorrect:
12526
12527 @example
12528 # This is incorrect.
12529 data.c data.h: data.foo
12530         foo data.foo
12531 @end example
12532
12533 @noindent
12534 What the above rule really says is that @file{data.c} and
12535 @file{data.h} each depend on @file{data.foo}, and can each be built by
12536 running @samp{foo data.foo}.  In other words it is equivalent to:
12537
12538 @example
12539 # We do not want this.
12540 data.c: data.foo
12541         foo data.foo
12542 data.h: data.foo
12543         foo data.foo
12544 @end example
12545
12546 @noindent
12547 which means that @command{foo} can be run twice.  Usually it will not
12548 be run twice, because @command{make} implementations are smart enough
12549 to check for the existence of the second file after the first one has
12550 been built; they will therefore detect that it already exists.
12551 However there are a few situations where it can run twice anyway:
12552
12553 @itemize
12554 @item
12555 The most worrying case is when running a parallel @command{make}.  If
12556 @file{data.c} and @file{data.h} are built in parallel, two @samp{foo
12557 data.foo} commands will run concurrently.  This is harmful.
12558 @item
12559 Another case is when the dependency (here @file{data.foo}) is
12560 (or depends upon) a phony target.
12561 @end itemize
12562
12563 A solution that works with parallel @command{make} but not with
12564 phony dependencies is the following:
12565
12566 @example
12567 data.c data.h: data.foo
12568         foo data.foo
12569 data.h: data.c
12570 @end example
12571
12572 @noindent
12573 The above rules are equivalent to
12574
12575 @example
12576 data.c: data.foo
12577         foo data.foo
12578 data.h: data.foo data.c
12579         foo data.foo
12580 @end example
12581
12582 @noindent
12583 therefore a parallel @command{make} will have to serialize the builds
12584 of @file{data.c} and @file{data.h}, and will detect that the second is
12585 no longer needed once the first is over.
12586
12587 Using this pattern is probably enough for most cases.  However it does
12588 not scale easily to more output files (in this scheme all output files
12589 must be totally ordered by the dependency relation), so we will
12590 explore a more complicated solution.
12591
12592 Another idea is to write the following:
12593
12594 @example
12595 # There is still a problem with this one.
12596 data.c: data.foo
12597         foo data.foo
12598 data.h: data.c
12599 @end example
12600
12601 @noindent
12602 The idea is that @samp{foo data.foo} is run only when @file{data.c}
12603 needs to be updated, but we further state that @file{data.h} depends
12604 upon @file{data.c}.  That way, if @file{data.h} is required and
12605 @file{data.foo} is out of date, the dependency on @file{data.c} will
12606 trigger the build.
12607
12608 This is almost perfect, but suppose we have built @file{data.h} and
12609 @file{data.c}, and then we erase @file{data.h}.  Then, running
12610 @samp{make data.h} will not rebuild @file{data.h}.  The above rules
12611 just state that @file{data.c} must be up-to-date with respect to
12612 @file{data.foo}, and this is already the case.
12613
12614 What we need is a rule that forces a rebuild when @file{data.h} is
12615 missing.  Here it is:
12616
12617 @example
12618 data.c: data.foo
12619         foo data.foo
12620 data.h: data.c
12621 ## Recover from the removal of $@@
12622         @@if test -f $@@; then :; else \
12623           rm -f data.c; \
12624           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12625         fi
12626 @end example
12627
12628 The above scheme can be extended to handle more outputs and more
12629 inputs.  One of the outputs is selected to serve as a witness to the
12630 successful completion of the command, it depends upon all inputs, and
12631 all other outputs depend upon it.  For instance, if @command{foo}
12632 should additionally read @file{data.bar} and also produce
12633 @file{data.w} and @file{data.x}, we would write:
12634
12635 @example
12636 data.c: data.foo data.bar
12637         foo data.foo data.bar
12638 data.h data.w data.x: data.c
12639 ## Recover from the removal of $@@
12640         @@if test -f $@@; then :; else \
12641           rm -f data.c; \
12642           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12643         fi
12644 @end example
12645
12646 However there are now three minor problems in this setup.  One is related
12647 to the timestamp ordering of @file{data.h}, @file{data.w},
12648 @file{data.x}, and @file{data.c}.  Another one is a race condition
12649 if a parallel @command{make} attempts to run multiple instances of the
12650 recover block at once.  Finally, the recursive rule breaks @samp{make -n}
12651 when run with GNU @command{make} (as well as some other @command{make}
12652 implementations), as it may remove @file{data.h} even when it should not
12653 (@pxref{MAKE Variable, , How the @code{MAKE} Variable Works, make,
12654 The GNU Make Manual}).
12655
12656 Let us deal with the first problem.  @command{foo} outputs four files,
12657 but we do not know in which order these files are created.  Suppose
12658 that @file{data.h} is created before @file{data.c}.  Then we have a
12659 weird situation.  The next time @command{make} is run, @file{data.h}
12660 will appear older than @file{data.c}, the second rule will be
12661 triggered, a shell will be started to execute the @samp{if@dots{}fi}
12662 command, but actually it will just execute the @code{then} branch,
12663 that is: nothing.  In other words, because the witness we selected is
12664 not the first file created by @command{foo}, @command{make} will start
12665 a shell to do nothing each time it is run.
12666
12667 A simple riposte is to fix the timestamps when this happens.
12668
12669 @example
12670 data.c: data.foo data.bar
12671         foo data.foo data.bar
12672 data.h data.w data.x: data.c
12673         @@if test -f $@@; then \
12674           touch $@@; \
12675         else \
12676 ## Recover from the removal of $@@
12677           rm -f data.c; \
12678           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12679         fi
12680 @end example
12681
12682 Another solution is to use a different and dedicated file as witness,
12683 rather than using any of @command{foo}'s outputs.
12684
12685 @example
12686 data.stamp: data.foo data.bar
12687         @@rm -f data.tmp
12688         @@touch data.tmp
12689         foo data.foo data.bar
12690         @@mv -f data.tmp $@@
12691 data.c data.h data.w data.x: data.stamp
12692 ## Recover from the removal of $@@
12693         @@if test -f $@@; then :; else \
12694           rm -f data.stamp; \
12695           $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
12696         fi
12697 @end example
12698
12699 @file{data.tmp} is created before @command{foo} is run, so it has a
12700 timestamp older than output files output by @command{foo}.  It is then
12701 renamed to @file{data.stamp} after @command{foo} has run, because we
12702 do not want to update @file{data.stamp} if @command{foo} fails.
12703
12704 This solution still suffers from the second problem: the race
12705 condition in the recover rule.  If, after a successful build, a user
12706 erases @file{data.c} and @file{data.h}, and runs @samp{make -j}, then
12707 @command{make} may start both recover rules in parallel.  If the two
12708 instances of the rule execute @samp{$(MAKE) $(AM_MAKEFLAGS)
12709 data.stamp} concurrently the build is likely to fail (for instance, the
12710 two rules will create @file{data.tmp}, but only one can rename it).
12711
12712 Admittedly, such a weird situation does not arise during ordinary
12713 builds.  It occurs only when the build tree is mutilated.  Here
12714 @file{data.c} and @file{data.h} have been explicitly removed without
12715 also removing @file{data.stamp} and the other output files.
12716 @code{make clean; make} will always recover from these situations even
12717 with parallel makes, so you may decide that the recover rule is solely
12718 to help non-parallel make users and leave things as-is.  Fixing this
12719 requires some locking mechanism to ensure only one instance of the
12720 recover rule rebuilds @file{data.stamp}.  One could imagine something
12721 along the following lines.
12722
12723 @example
12724 data.c data.h data.w data.x: data.stamp
12725 ## Recover from the removal of $@@
12726         @@if test -f $@@; then :; else \
12727           trap 'rm -rf data.lock data.stamp' 1 2 13 15; \
12728 ## mkdir is a portable test-and-set
12729           if mkdir data.lock 2>/dev/null; then \
12730 ## This code is being executed by the first process.
12731             rm -f data.stamp; \
12732             $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
12733             result=$$?; rm -rf data.lock; exit $$result; \
12734           else \
12735 ## This code is being executed by the follower processes.
12736 ## Wait until the first process is done.
12737             while test -d data.lock; do sleep 1; done; \
12738 ## Succeed if and only if the first process succeeded.
12739             test -f data.stamp; \
12740           fi; \
12741         fi
12742 @end example
12743
12744 Using a dedicated witness, like @file{data.stamp}, is very handy when
12745 the list of output files is not known beforehand.  As an illustration,
12746 consider the following rules to compile many @file{*.el} files into
12747 @file{*.elc} files in a single command.  It does not matter how
12748 @code{ELFILES} is defined (as long as it is not empty: empty targets
12749 are not accepted by POSIX).
12750
12751 @example
12752 ELFILES = one.el two.el three.el @dots{}
12753 ELCFILES = $(ELFILES:=c)
12754
12755 elc-stamp: $(ELFILES)
12756         @@rm -f elc-temp
12757         @@touch elc-temp
12758         $(elisp_comp) $(ELFILES)
12759         @@mv -f elc-temp $@@
12760
12761 $(ELCFILES): elc-stamp
12762         @@if test -f $@@; then :; else \
12763 ## Recover from the removal of $@@
12764           trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
12765           if mkdir elc-lock 2>/dev/null; then \
12766 ## This code is being executed by the first process.
12767             rm -f elc-stamp; \
12768             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
12769             rmdir elc-lock; \
12770           else \
12771 ## This code is being executed by the follower processes.
12772 ## Wait until the first process is done.
12773             while test -d elc-lock; do sleep 1; done; \
12774 ## Succeed if and only if the first process succeeded.
12775             test -f elc-stamp; exit $$?; \
12776 @c $$
12777           fi; \
12778         fi
12779 @end example
12780
12781 These solutions all still suffer from the third problem, namely that
12782 they break the promise that @samp{make -n} should not cause any actual
12783 changes to the tree.  For those solutions that do not create lock files,
12784 it is possible to split the recover rules into two separate recipe
12785 commands, one of which does all work but the recursion, and the
12786 other invokes the recursive @samp{$(MAKE)}.  The solutions involving
12787 locking could act upon the contents of the @samp{MAKEFLAGS} variable,
12788 but parsing that portably is not easy (@pxref{The Make Macro MAKEFLAGS,,,
12789 autoconf, The Autoconf Manual}).  Here is an example:
12790
12791 @example
12792 ELFILES = one.el two.el three.el @dots{}
12793 ELCFILES = $(ELFILES:=c)
12794
12795 elc-stamp: $(ELFILES)
12796         @@rm -f elc-temp
12797         @@touch elc-temp
12798         $(elisp_comp) $(ELFILES)
12799         @@mv -f elc-temp $@@
12800
12801 $(ELCFILES): elc-stamp
12802 ## Recover from the removal of $@@
12803         @@dry=; for f in x $$MAKEFLAGS; do \
12804           case $$f in \
12805             *=*|--*);; \
12806             *n*) dry=:;; \
12807           esac; \
12808         done; \
12809         if test -f $@@; then :; else \
12810           $$dry trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
12811           if $$dry mkdir elc-lock 2>/dev/null; then \
12812 ## This code is being executed by the first process.
12813             $$dry rm -f elc-stamp; \
12814             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
12815             $$dry rmdir elc-lock; \
12816           else \
12817 ## This code is being executed by the follower processes.
12818 ## Wait until the first process is done.
12819             while test -d elc-lock && test -z "$$dry"; do \
12820 @c $$
12821               sleep 1; \
12822             done; \
12823 ## Succeed if and only if the first process succeeded.
12824             $$dry test -f elc-stamp; exit $$?; \
12825           fi; \
12826         fi
12827 @end example
12828
12829 For completeness it should be noted that GNU @command{make} is able to
12830 express rules with multiple output files using pattern rules
12831 (@pxref{Pattern Examples, , Pattern Rule Examples, make, The GNU Make
12832 Manual}).  We do not discuss pattern rules here because they are not
12833 portable, but they can be convenient in packages that assume GNU
12834 @command{make}.
12835
12836
12837 @node Hard-Coded Install Paths
12838 @section Installing to Hard-Coded Locations
12839
12840 @display
12841 My package needs to install some configuration file.  I tried to use
12842 the following rule, but @samp{make distcheck} fails.  Why?
12843
12844 @example
12845 # Do not do this.
12846 install-data-local:
12847         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
12848 @end example
12849 @end display
12850
12851 @display
12852 My package needs to populate the installation directory of another
12853 package at install-time.  I can easily compute that installation
12854 directory in @file{configure}, but if I install files therein,
12855 @samp{make distcheck} fails.  How else should I do?
12856 @end display
12857
12858 These two setups share their symptoms: @samp{make distcheck} fails
12859 because they are installing files to hard-coded paths.  In the later
12860 case the path is not really hard-coded in the package, but we can
12861 consider it to be hard-coded in the system (or in whichever tool that
12862 supplies the path).  As long as the path does not use any of the
12863 standard directory variables (@samp{$(prefix)}, @samp{$(bindir)},
12864 @samp{$(datadir)}, etc.), the effect will be the same:
12865 user-installations are impossible.
12866
12867 As a (non-root) user who wants to install a package, you usually have no
12868 right to install anything in @file{/usr} or @file{/usr/local}.  So you
12869 do something like @samp{./configure --prefix ~/usr} to install a
12870 package in your own @file{~/usr} tree.
12871
12872 If a package attempts to install something to some hard-coded path
12873 (e.g., @file{/etc/afile}), regardless of this @option{--prefix} setting,
12874 then the installation will fail.  @samp{make distcheck} performs such
12875 a @option{--prefix} installation, hence it will fail too.
12876
12877 Now, there are some easy solutions.
12878
12879 The above @code{install-data-local} example for installing
12880 @file{/etc/afile} would be better replaced by
12881
12882 @example
12883 sysconf_DATA = afile
12884 @end example
12885
12886 @noindent
12887 by default @code{sysconfdir} will be @samp{$(prefix)/etc}, because
12888 this is what the GNU Standards require.  When such a package is
12889 installed on an FHS compliant system, the installer will have to set
12890 @samp{--sysconfdir=/etc}.  As the maintainer of the package you
12891 should not be concerned by such site policies: use the appropriate
12892 standard directory variable to install your files so that the installer
12893 can easily redefine these variables to match their site conventions.
12894
12895 Installing files that should be used by another package is slightly
12896 more involved.  Let's take an example and assume you want to install
12897 a shared library that is a Python extension module.  If you ask Python
12898 where to install the library, it will answer something like this:
12899
12900 @example
12901 % @kbd{python -c 'from distutils import sysconfig;
12902              print sysconfig.get_python_lib(1,0)'}
12903 /usr/lib/python2.5/site-packages
12904 @end example
12905
12906 If you indeed use this absolute path to install your shared library,
12907 non-root users will not be able to install the package, hence
12908 distcheck fails.
12909
12910 Let's do better.  The @samp{sysconfig.get_python_lib()} function
12911 actually accepts a third argument that will replace Python's
12912 installation prefix.
12913
12914 @example
12915 % @kbd{python -c 'from distutils import sysconfig;
12916              print sysconfig.get_python_lib(1,0,"$@{exec_prefix@}")'}
12917 $@{exec_prefix@}/lib/python2.5/site-packages
12918 @end example
12919
12920 You can also use this new path.  If you do
12921 @itemize @bullet
12922 @item
12923 root users can install your package with the same @option{--prefix}
12924 as Python (you get the behavior of the previous attempt)
12925
12926 @item
12927 non-root users can install your package too, they will have the
12928 extension module in a place that is not searched by Python but they
12929 can work around this using environment variables (and if you installed
12930 scripts that use this shared library, it's easy to tell Python were to
12931 look in the beginning of your script, so the script works in both
12932 cases).
12933 @end itemize
12934
12935 The @code{AM_PATH_PYTHON} macro uses similar commands to define
12936 @samp{$(pythondir)} and @samp{$(pyexecdir)} (@pxref{Python}).
12937
12938 Of course not all tools are as advanced as Python regarding that
12939 substitution of @var{prefix}.  So another strategy is to figure the
12940 part of the installation directory that must be preserved.  For
12941 instance, here is how @code{AM_PATH_LISPDIR} (@pxref{Emacs Lisp})
12942 computes @samp{$(lispdir)}:
12943
12944 @example
12945 $EMACS -batch -q -eval '(while load-path
12946   (princ (concat (car load-path) "\n"))
12947   (setq load-path (cdr load-path)))' >conftest.out
12948 lispdir=`sed -n
12949   -e 's,/$,,'
12950   -e '/.*\/lib\/x*emacs\/site-lisp$/@{
12951         s,.*/lib/\(x*emacs/site-lisp\)$,$@{libdir@}/\1,;p;q;
12952       @}'
12953   -e '/.*\/share\/x*emacs\/site-lisp$/@{
12954         s,.*/share/\(x*emacs/site-lisp\),$@{datarootdir@}/\1,;p;q;
12955       @}'
12956   conftest.out`
12957 @end example
12958
12959 I.e., it just picks the first directory that looks like
12960 @file{*/lib/*emacs/site-lisp} or @file{*/share/*emacs/site-lisp} in
12961 the search path of emacs, and then substitutes @samp{$@{libdir@}} or
12962 @samp{$@{datadir@}} appropriately.
12963
12964 The emacs case looks complicated because it processes a list and
12965 expects two possible layouts, otherwise it's easy, and the benefits for
12966 non-root users are really worth the extra @command{sed} invocation.
12967
12968
12969 @node Debugging Make Rules
12970 @section Debugging Make Rules
12971 @cindex debugging rules
12972 @cindex rules, debugging
12973
12974 The rules and dependency trees generated by @command{automake} can get
12975 rather complex, and leave the developer head-scratching when things
12976 don't work as expected.  Besides the debug options provided by the
12977 @command{make} command (@pxref{Options Summary,,, make, The GNU Make
12978 Manual}), here's a couple of further hints for debugging makefiles
12979 generated by @command{automake} effectively:
12980
12981 @itemize
12982 @item
12983 If less verbose output has been enabled in the package with the
12984 @samp{silent-rules} option (@pxref{Options}), you can use
12985 @code{make V=1} to see the commands being executed.
12986 @item
12987 @code{make -n} can help show what would be done without actually doing
12988 it.  Note however, that this will @emph{still execute} commands prefixed
12989 with @samp{+}, and, when using GNU @command{make}, commands that contain
12990 the strings @samp{$(MAKE)} or @samp{$@{MAKE@}} (@pxref{Instead of
12991 Execution,,, make, The GNU Make Manual}).
12992 Typically, this is helpful to show what recursive rules would do, but it
12993 means that, in your own rules, you should not mix such recursion with
12994 actions that change any files.@footnote{Automake's @samp{dist} and
12995 @samp{distcheck} rules had a bug in this regard in that they created
12996 directories even with @option{-n}, but this has been fixed in Automake
12997 1.11.}  Furthermore, note that GNU @command{make} will update
12998 prerequisites for the @file{Makefile} file itself even with @option{-n}
12999 (@pxref{Remaking Makefiles,,, make, The GNU Make Manual}).
13000 @item
13001 @code{make SHELL="/bin/bash -vx"} can help debug complex rules.
13002 @xref{The Make Macro SHELL,,, autoconf, The Autoconf Manual}, for some
13003 portability quirks associated with this construct.
13004 @item
13005 @code{echo 'print: ; @@echo "$(VAR)"' | make -f Makefile -f - print}
13006 can be handy to examine the expanded value of variables.  You may need
13007 to use a target other than @samp{print} if that is already used or a
13008 file with that name exists.
13009 @item
13010 @url{http://bashdb.sourceforge.net/@/remake/} provides a modified
13011 GNU @command{make} command called @command{remake} that copes with
13012 complex GNU @command{make}-specific Makefiles and allows to trace
13013 execution, examine variables, and call rules interactively, much like
13014 a debugger.
13015 @end itemize
13016
13017
13018 @node Reporting Bugs
13019 @section Reporting Bugs
13020
13021 Most nontrivial software has bugs.  Automake is no exception.  Although
13022 we cannot promise we can or will fix a bug, and we might not even agree
13023 that it is a bug, we want to hear about problems you encounter. Often we
13024 agree they are bugs and want to fix them.
13025
13026 To make it possible for us to fix a bug, please report it. In order to
13027 do so effectively, it helps to know when and how to do it.
13028
13029 Before reporting a bug, it is a good idea to see if it is already known.
13030 You can look at the @uref{http://debbugs.gnu.org/, GNU Bug Tracker}
13031 and the @uref{http://lists.gnu.org/@/archive/@/html/@/bug-automake/,
13032 bug-automake mailing list archives} for previous bug reports.  We
13033 previously used a
13034 @uref{http://sourceware.org/@/cgi-bin/@/gnatsweb.pl?database=automake,
13035 Gnats database} for bug tracking, so some bugs might have been reported
13036 there already.  Please do not use it for new bug reports, however.
13037
13038 If the bug is not already known, it should be reported.  It is very
13039 important to report bugs in a way that is useful and efficient.  For
13040 this, please familiarize yourself with
13041 @uref{http://www.chiark.greenend.org.uk/@/~sgtatham/@/bugs.html, How to
13042 Report Bugs Effectively} and
13043 @uref{http://catb.org/@/~esr/@/faqs/@/smart-questions.html, How to Ask
13044 Questions the Smart Way}.  This helps you and developers to save time
13045 which can then be spent on fixing more bugs and implementing more
13046 features.
13047
13048 For a bug report, a feature request or other suggestions, please send
13049 email to @email{@value{PACKAGE_BUGREPORT}}.  This will then open a new
13050 bug in the @uref{http://debbugs.gnu.org/@/automake, bug tracker}.  Be
13051 sure to include the versions of Autoconf and Automake that you use.
13052 Ideally, post a minimal @file{Makefile.am} and @file{configure.ac} that
13053 reproduces the problem you encounter.  If you have encountered test
13054 suite failures, please attach the @file{tests/test-suite.log} file.
13055
13056 @c ========================================================== Appendices
13057
13058 @page
13059 @node Copying This Manual
13060 @appendix Copying This Manual
13061
13062 @menu
13063 * GNU Free Documentation License::  License for copying this manual
13064 @end menu
13065
13066 @node GNU Free Documentation License
13067 @appendixsec GNU Free Documentation License
13068 @include fdl.texi
13069
13070 @page
13071 @node Indices
13072 @appendix Indices
13073
13074 @menu
13075 * Macro Index::                 Index of Autoconf macros
13076 * Variable Index::              Index of Makefile variables
13077 * General Index::               General index
13078 @end menu
13079
13080 @node Macro Index
13081 @appendixsec Macro Index
13082
13083 @printindex fn
13084
13085 @node Variable Index
13086 @appendixsec Variable Index
13087
13088 @printindex vr
13089
13090 @node General Index
13091 @appendixsec General Index
13092
13093 @printindex cp
13094
13095
13096 @bye
13097
13098 @c  LocalWords:  texinfo setfilename settitle setchapternewpage texi direntry
13099 @c  LocalWords:  dircategory in's aclocal ifinfo titlepage Tromey vskip pt sp
13100 @c  LocalWords:  filll defcodeindex ov cv op tr syncodeindex fn cp vr ifnottex
13101 @c  LocalWords:  dir Automake's ac Dist Gnits gnits cygnus dfn Autoconf's pxref
13102 @c  LocalWords:  cindex Autoconf autoconf perl samp cvs dist trindex SUBST foo
13103 @c  LocalWords:  xs emph FIXME ref vindex pkglibdir pkgincludedir pkgdatadir mt
13104 @c  LocalWords:  pkg libdir cpio bindir sbindir rmt pax sbin zar zardir acindex
13105 @c  LocalWords:  HTML htmldir html noinst TEXINFOS nodist nobase strudel CFLAGS
13106 @c  LocalWords:  libmumble CC YFLAGS itemx de fication config url comp
13107 @c  LocalWords:  depcomp elisp sh mdate mkinstalldirs mkdir py tex dvi ps pdf
13108 @c  LocalWords:  ylwrap zardoz INIT gettext acinclude mv FUNCS LIBOBJS LDADD fr
13109 @c  LocalWords:  uref featureful dnl src LINGUAS es ko nl pl sl sv PROG ISC doc
13110 @c  LocalWords:  POSIX STDC fcntl FUNC ALLOCA blksize struct stat intl po chmod
13111 @c  LocalWords:  ChangeLog SUBDIRS gettextize gpl testdata getopt INTLLIBS cpp
13112 @c  LocalWords:  localedir datadir DLOCALEDIR DEXIT CPPFLAGS autoreconf opindex
13113 @c  LocalWords:  AUX var symlink deps Wno Wnone package's aclocal's distclean
13114 @c  LocalWords:  ltmain xref LIBSOURCE LIBSOURCES LIBOBJ MEMCMP vs RANLIB CXX
13115 @c  LocalWords:  LDFLAGS LIBTOOL libtool XTRA LIBS gettext's acdir APIVERSION
13116 @c  LocalWords:  dirlist noindent usr TIOCGWINSZ sc
13117 @c  LocalWords:  GWINSZ termios SRCDIR tarball bzip LISPDIR lispdir XEmacs CCAS
13118 @c  LocalWords:  emacsen MicroEmacs CCASFLAGS UX GCJ gcj GCJFLAGS posix DMALLOC
13119 @c  LocalWords:  dmalloc ldmalloc REGEX regex DEPDIR DEP DEFUN aclocaldir fi
13120 @c  LocalWords:  mymacro myothermacro AMFLAGS autopoint autogen libtoolize yum
13121 @c  LocalWords:  autoheader README MAKEFLAGS subdir Inetutils sync COND endif
13122 @c  LocalWords:  Miller's installable includedir inc pkgdata EXEEXT libexec bsd
13123 @c  LocalWords:  pkglib libexecdir prog libcpio cpio's dlopen dlpreopen linux
13124 @c  LocalWords:  subsubsection OBJEXT esac lib LTLIBRARIES liblob LIBADD AR ar
13125 @c  LocalWords:  ARFLAGS cru ing maude libgettext lo LTLIBOBJS rpath SGI PRE yy
13126 @c  LocalWords:  libmaude CCLD CXXFLAGS FFLAGS LFLAGS OBJCFLAGS RFLAGS DEFS cc
13127 @c  LocalWords:  SHORTNAME vtable srcdir nostdinc basename yxx cxx ll lxx gdb
13128 @c  LocalWords:  lexers yymaxdepth maxdepth yyparse yylex yyerror yylval lval
13129 @c  LocalWords:  yychar yydebug yypact yyr yydef def yychk chk yypgo pgo yyact
13130 @c  LocalWords:  yyexca exca yyerrflag errflag yynerrs nerrs yyps yypv pv yys
13131 @c  LocalWords:  yystate yytmp tmp yyv yyval val yylloc lloc yyreds yytoks toks
13132 @c  LocalWords:  yylhs yylen yydefred yydgoto yysindex yyrindex yygindex yyname
13133 @c  LocalWords:  yytable yycheck yyrule byacc CXXCOMPILE CXXLINK FLINK cfortran
13134 @c  LocalWords:  Catalogue preprocessable FLIBS libfoo baz JAVACFLAGS java exe
13135 @c  LocalWords:  SunOS fying basenames exeext uninstalled oldinclude kr FSF's
13136 @c  LocalWords:  pkginclude oldincludedir sysconf sharedstate localstate gcc rm
13137 @c  LocalWords:  sysconfdir sharedstatedir localstatedir preexist CLEANFILES gz
13138 @c  LocalWords:  depfile tmpdepfile depmode const interoperate
13139 @c  LocalWords:  JAVAC javac JAVAROOT builddir CLASSPATH ENV pyc pyo pkgpython
13140 @c  LocalWords:  pyexecdir pkgpyexecdir Python's pythondir pkgpythondir txi ois
13141 @c  LocalWords:  installinfo vers MAKEINFO makeinfo MAKEINFOFLAGS noinstall rf
13142 @c  LocalWords:  mandir thesame alsothesame installman myexecbin DESTDIR Pinard
13143 @c  LocalWords:  uninstall installdirs uninstalls MOSTLYCLEANFILES mostlyclean
13144 @c  LocalWords:  DISTCLEANFILES MAINTAINERCLEANFILES GZIP gzip shar exp
13145 @c  LocalWords:  distdir distcheck distcleancheck listfiles distuninstallcheck
13146 @c  LocalWords:  VPATH tarfile stdout XFAIL DejaGnu dejagnu DEJATOOL runtest ln
13147 @c  LocalWords:  RUNTESTDEFAULTFLAGS toolchain RUNTESTFLAGS asis readme DVIPS
13148 @c  LocalWords:  installcheck gzipped tarZ std utils etags mkid cd
13149 @c  LocalWords:  ARGS taggable ETAGSFLAGS lang ctags CTAGSFLAGS GTAGS gtags idl
13150 @c  LocalWords:  foocc doit idlC multilibs ABIs cmindex defmac ARG enableval FC
13151 @c  LocalWords:  MSG xtrue DBG pathchk CYGWIN afile proglink versioned CVS's TE
13152 @c  LocalWords:  wildcards Autoconfiscated subsubheading autotools Meyering API
13153 @c  LocalWords:  ois's wildcard Wportability cartouche vrindex printindex Duret
13154 @c  LocalWords:  DSOMEFLAG DVERSION automake Lutz insertcopying versioning FAQ
13155 @c  LocalWords:  LTLIBOBJ Libtool's libtool's libltdl dlopening itutions libbar
13156 @c  LocalWords:  WANTEDLIBS libhello sublibraries libtop libsub dlopened Ratfor
13157 @c  LocalWords:  mymodule timestamps timestamp underquoted MAKEINFOHTMLFLAGS te
13158 @c  LocalWords:  GNUmakefile Subpackages subpackage's subpackages aux
13159 @c  LocalWords:  detailmenu Timeline pwd reldir AUTOM autom PREREQ FOOBAR libc
13160 @c  LocalWords:  libhand subpackage moduleN libmain libmisc FCFLAGS FCCOMPILE
13161 @c  LocalWords:  FCLINK subst sed ELCFILES elc MAKEINFOHTML dvips esyscmd ustar
13162 @c  LocalWords:  tarballs Woverride vfi ELFILES djm AutoMake honkin FSF
13163 @c  LocalWords:  fileutils precanned MacKenzie's reimplement termutils Tromey's
13164 @c  LocalWords:  cois gnitsians LIBPROGRAMS progs LIBLIBRARIES Textutils Ulrich
13165 @c  LocalWords:  Matzigkeit Drepper's Gord Matzigkeit's jm Dalley Debian org
13166 @c  LocalWords:  Administrivia ILU CORBA Sourceware Molenda sourceware Elliston
13167 @c  LocalWords:  dep Oliva Akim Demaille Aiieeee Demaillator Akim's sourcequake
13168 @c  LocalWords:  grep backported screenshots libgcj KB unnumberedsubsubsec pre
13169 @c  LocalWords:  precomputing hacky makedepend inline clearmake LD PRELOAD Rel
13170 @c  LocalWords:  syscalls perlhist acl pm multitable headitem fdl appendixsec
13171 @c  LocalWords:  LTALLOCA MALLOC malloc memcmp strdup alloca libcompat xyz DFOO
13172 @c  LocalWords:  unprefixed buildable preprocessed DBAZ DDATADIR WARNINGCFLAGS
13173 @c  LocalWords:  LIBFOOCFLAGS LIBFOOLDFLAGS ftable testSubDir obj LIBTOOLFLAGS
13174 @c  LocalWords:  barexec Pinard's automatize initialize lzip xz cscope