* doc/automake.texi (Include, Extending aclocal): Typos.
[automake.git] / doc / automake.texi
blob2e8d4b30d70e1d1d5f89485b8adf727bf766f3c1
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
8 @include version.texi
10 @copying
12 This manual is for @acronym{GNU} Automake (version @value{VERSION},
13 @value{UPDATED}), a program that creates GNU standards-compliant
14 Makefiles from template files.
16 Copyright @copyright{} 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
17 2003, 2004, 2005 Free Software Foundation, Inc.
19 @quotation
20 Permission is granted to copy, distribute and/or modify this document
21 under the terms of the @acronym{GNU} Free Documentation License,
22 Version 1.2 or any later version published by the Free Software
23 Foundation; with no Invariant Sections, with the Front-Cover texts
24 being ``A @acronym{GNU} Manual,'' and with the Back-Cover Texts as in
25 (a) below.  A copy of the license is included in the section entitled
26 ``@acronym{GNU} Free Documentation License.''
28 (a) The FSF's Back-Cover Text is: ``You have freedom to copy and
29 modify this @acronym{GNU} Manual, like @acronym{GNU} software.  Copies
30 published by the Free Software Foundation raise funds for
31 @acronym{GNU} development.''
32 @end quotation
33 @end copying
35 @c info Automake  points to the Automake package's documentation
36 @c info automake  points to the automake script's documentation
37 @c (Autoconf has a similar setup.)
38 @dircategory Software development
39 @direntry
40 * Automake: (automake).         Making GNU standards-compliant Makefiles.
41 @end direntry
43 @dircategory Individual utilities
44 @direntry
45 * aclocal: (automake)Invoking aclocal.          Generating aclocal.m4.
46 * automake: (automake)Invoking automake.        Generating Makefile.in.
47 @end direntry
49 @titlepage
50 @title GNU Automake
51 @subtitle For version @value{VERSION}, @value{UPDATED}
52 @author David MacKenzie
53 @author Tom Tromey
54 @author Alexandre Duret-Lutz
55 @page
56 @vskip 0pt plus 1filll
57 @insertcopying
58 @end titlepage
60 @c Define an index of configure macros.
61 @defcodeindex ac
62 @c Define an index of options.
63 @defcodeindex op
64 @c Define an index of targets.
65 @defcodeindex tr
66 @c Define an index of commands.
67 @defcodeindex cm
69 @c Put the macros in the function index.
70 @syncodeindex ac fn
72 @c Put everything else into one index (arbitrarily chosen to be the concept index).
73 @syncodeindex op cp
74 @syncodeindex tr cp
75 @syncodeindex cm cp
77 @ifnottex
78 @node Top
79 @comment  node-name,  next,  previous,  up
80 @top GNU Automake
82 @insertcopying
84 @menu
85 * Introduction::                Automake's purpose
86 * Generalities::                General ideas
87 * Examples::                    Some example packages
88 * Invoking Automake::           Creating a Makefile.in
89 * configure::                   Scanning configure.ac or configure.in
90 * Directories::                 Declaring subdirectories
91 * Programs::                    Building programs and libraries
92 * Other objects::               Other derived objects
93 * Other GNU Tools::             Other GNU Tools
94 * Documentation::               Building documentation
95 * Install::                     What gets installed
96 * Clean::                       What gets cleaned
97 * Dist::                        What goes in a distribution
98 * Tests::                       Support for test suites
99 * Rebuilding::                  Automatic rebuilding of Makefile
100 * Options::                     Changing Automake's behavior
101 * Miscellaneous::               Miscellaneous rules
102 * Include::                     Including extra files in an Automake template.
103 * Conditionals::                Conditionals
104 * Gnits::                       The effect of @option{--gnu} and @option{--gnits}
105 * Cygnus::                      The effect of @option{--cygnus}
106 * Not Enough::                  When Automake is not Enough
107 * Distributing::                Distributing the Makefile.in
108 * API versioning::              About compatibility between Automake versions
109 * Upgrading::                   Upgrading to a Newer Automake Version
110 * FAQ::                         Frequently Asked Questions
111 * History::                     Notes about the history of Automake
112 * Copying This Manual::         How to make copies of this manual
113 * Indices::                     Indices of variables, macros, and concepts
115 @detailmenu
116  --- The Detailed Node Listing ---
118 General ideas
120 * General Operation::           General operation of Automake
121 * Strictness::                  Standards conformance checking
122 * Uniform::                     The Uniform Naming Scheme
123 * Canonicalization::            How derived variables are named
124 * User Variables::              Variables reserved for the user
125 * Auxiliary Programs::          Programs automake might require
127 Some example packages
129 * Complete::                    A simple example, start to finish
130 * Hello::                       A classic program
131 * true::                        Building true and false
133 Scanning @file{configure.ac}
135 * Requirements::                Configuration requirements
136 * Optional::                    Other things Automake recognizes
137 * Invoking aclocal::            Auto-generating aclocal.m4
138 * Macros::                      Autoconf macros supplied with Automake
140 Auto-generating aclocal.m4
142 * aclocal options::             Options supported by aclocal
143 * Macro search path::           How aclocal finds .m4 files
144 * Extending aclocal::           Writing your own aclocal macros
145 * Local Macros::                Organizing local macros
146 * Serials::                     Serial lines in Autoconf macros
147 * Future of aclocal::           aclocal's scheduled death
149 Autoconf macros supplied with Automake
151 * Public macros::               Macros that you can use.
152 * Obsolete macros::             Macros that you should stop using.
153 * Private macros::              Macros that you should not use.
155 Directories
157 * Subdirectories::              Building subdirectories recursively
158 * Conditional Subdirectories::  Conditionally not building directories
159 * Alternative::                 Subdirectories without recursion
160 * Subpackages::                 Nesting packages
162 Building Programs and Libraries
164 * A Program::                   Building a program
165 * A Library::                   Building a library
166 * A Shared Library::            Building a Libtool library
167 * Program and Library Variables::  Variables controlling program and
168                                 library builds
169 * Default _SOURCES::            Default source files
170 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
171 * Program variables::           Variables used when building a program
172 * Yacc and Lex::                Yacc and Lex support
173 * C++ Support::                 Compiling C++ sources
174 * Assembly Support::            Compiling assembly sources
175 * Fortran 77 Support::          Compiling Fortran 77 sources
176 * Fortran 9x Support::          Compiling Fortran 9x sources
177 * Java Support::                Compiling Java sources
178 * Support for Other Languages::  Compiling other languages
179 * ANSI::                        Automatic de-ANSI-fication
180 * Dependencies::                Automatic dependency tracking
181 * EXEEXT::                      Support for executable extensions
183 Building a program
185 * Program Sources::             Defining program sources
186 * Linking::                     Linking with libraries or extra objects
187 * Conditional Sources::         Handling conditional sources
188 * Conditional Programs::        Building program conditionally
190 Building a Shared Library
192 * Libtool Concept::             Introducing Libtool
193 * Libtool Libraries::           Declaring Libtool Libraries
194 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
195 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
196 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
197 * Libtool Modules::             Building Libtool Modules
198 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
199 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
200 * Libtool Issues::              Common Issues Related to Libtool's Use
202 Fortran 77 Support
204 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
205 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
206 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
208 Mixing Fortran 77 With C and C++
210 * How the Linker is Chosen::    Automatic linker selection
212 Fortran 9x Support
214 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
216 Other Derived Objects
218 * Scripts::                     Executable scripts
219 * Headers::                     Header files
220 * Data::                        Architecture-independent data files
221 * Sources::                     Derived sources
223 Built sources
225 * Built sources example::       Several ways to handle built sources.
227 Other GNU Tools
229 * Emacs Lisp::                  Emacs Lisp
230 * gettext::                     Gettext
231 * Libtool::                     Libtool
232 * Java::                        Java
233 * Python::                      Python
235 Building documentation
237 * Texinfo::                     Texinfo
238 * Man pages::                   Man pages
240 Miscellaneous Rules
242 * Tags::                        Interfacing to etags and mkid
243 * Suffixes::                    Handling new file extensions
244 * Multilibs::                   Support for multilibs.
246 When Automake Isn't Enough
248 * Extending::                   Adding new rules or overriding existing ones.
249 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
251 Frequently Asked Questions about Automake
253 * CVS::                         CVS and generated files
254 * maintainer-mode::             missing and AM_MAINTAINER_MODE
255 * wildcards::                   Why doesn't Automake support wildcards?
256 * distcleancheck::              Files left in build directory after distclean
257 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
258 * renamed objects::             Why are object files sometimes renamed?
259 * Per-Object Flags::            How to simulate per-object flags?
260 * Multiple Outputs::            Writing rules for tools with many output files
261 * Hard-Coded Install Paths::    Installing to Hard-Coded Locations
263 History of Automake
265 * Timeline::                    The Automake story.
266 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
267 * Releases::                    Statistics about Automake Releases
269 Copying This Manual
271 * GNU Free Documentation License::  License for copying this manual
273 Indices
275 * Macro Index::                 Index of Autoconf macros
276 * Variable Index::              Index of Makefile variables
277 * General Index::               General index
279 @end detailmenu
280 @end menu
282 @end ifnottex
285 @node Introduction
286 @chapter Introduction
288 Automake is a tool for automatically generating @file{Makefile.in}s from
289 files called @file{Makefile.am}.  Each @file{Makefile.am} is basically a
290 series of @command{make} variable definitions@footnote{These variables are
291 also called @dfn{make macros} in Make terminology, however in this
292 manual we reserve the term @dfn{macro} for Autoconf's macros.}, with
293 rules being thrown in occasionally.  The generated @file{Makefile.in}s
294 are compliant with the GNU Makefile standards.
296 @cindex GNU Makefile standards
298 The GNU Makefile Standards Document
299 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
300 is long, complicated, and subject to change.  The goal of Automake is to
301 remove the burden of Makefile maintenance from the back of the
302 individual GNU maintainer (and put it on the back of the Automake
303 maintainer).
305 The typical Automake input file is simply a series of variable definitions.
306 Each such file is processed to create a @file{Makefile.in}.  There
307 should generally be one @file{Makefile.am} per directory of a project.
309 @cindex Constraints of Automake
310 @cindex Automake constraints
312 Automake does constrain a project in certain ways; for instance, it
313 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
314 autoconf, The Autoconf Manual}), and enforces certain restrictions on
315 the @file{configure.ac} contents@footnote{Older Autoconf versions used
316 @file{configure.in}.  Autoconf 2.50 and greater promotes
317 @file{configure.ac} over @file{configure.in}.  The rest of this
318 documentation will refer to @file{configure.ac}, but Automake also
319 supports @file{configure.in} for backward compatibility.}.
321 @cindex Automake requirements
322 @cindex Requirements, Automake
324 Automake requires @command{perl} in order to generate the
325 @file{Makefile.in}s.  However, the distributions created by Automake are
326 fully GNU standards-compliant, and do not require @command{perl} in order
327 to be built.
329 @cindex Bugs, reporting
330 @cindex Reporting bugs
331 @cindex E-mail, bug reports
333 Mail suggestions and bug reports for Automake to
334 @email{bug-automake@@gnu.org}.
337 @node Generalities
338 @chapter General ideas
340 The following sections cover a few basic ideas that will help you
341 understand how Automake works.
343 @menu
344 * General Operation::           General operation of Automake
345 * Strictness::                  Standards conformance checking
346 * Uniform::                     The Uniform Naming Scheme
347 * Canonicalization::            How derived variables are named
348 * User Variables::              Variables reserved for the user
349 * Auxiliary Programs::          Programs automake might require
350 @end menu
353 @node General Operation
354 @section General Operation
356 Automake works by reading a @file{Makefile.am} and generating a
357 @file{Makefile.in}.  Certain variables and rules defined in the
358 @file{Makefile.am} instruct Automake to generate more specialized code;
359 for instance, a @code{bin_PROGRAMS} variable definition will cause rules
360 for compiling and linking programs to be generated.
362 @cindex Non-standard targets
363 @cindex @code{cvs-dist}, non-standard example
364 @trindex cvs-dist
366 The variable definitions and rules in the @file{Makefile.am} are
367 copied verbatim into the generated file.  This allows you to add
368 arbitrary code into the generated @file{Makefile.in}.  For instance,
369 the Automake distribution includes a non-standard rule for the
370 @code{cvs-dist} target, which the Automake maintainer uses to make
371 distributions from his source control system.
373 @cindex GNU make extensions
375 Note that most GNU make extensions are not recognized by Automake.  Using
376 such extensions in a @file{Makefile.am} will lead to errors or confusing
377 behavior.
379 @cindex Append operator
380 @cmindex +=
381 A special exception is that the GNU make append operator, @samp{+=}, is
382 supported.  This operator appends its right hand argument to the variable
383 specified on the left.  Automake will translate the operator into
384 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
386 Automake tries to keep comments grouped with any adjoining rules or
387 variable definitions.
389 @cindex Make targets, overriding
390 @cindex Make rules, overriding
391 @cindex Overriding make rules
392 @cindex Overriding make targets
394 A rule defined in @file{Makefile.am} generally overrides any such
395 rule of a similar name that would be automatically generated by
396 @command{automake}.  Although this is a supported feature, it is generally
397 best to avoid making use of it, as sometimes the generated rules are
398 very particular.
400 @cindex Variables, overriding
401 @cindex Overriding make variables
403 Similarly, a variable defined in @file{Makefile.am} or
404 @code{AC_SUBST}ed from @file{configure.ac} will override any
405 definition of the variable that @command{automake} would ordinarily
406 create.  This feature is more often useful than the ability to
407 override a rule.  Be warned that many of the variables generated by
408 @command{automake} are considered to be for internal use only, and their
409 names might change in future releases.
411 @cindex Recursive operation of Automake
412 @cindex Automake, recursive operation
413 @cindex Example of recursive operation
415 When examining a variable definition, Automake will recursively examine
416 variables referenced in the definition.  For example, if Automake is
417 looking at the content of @code{foo_SOURCES} in this snippet
419 @example
420 xs = a.c b.c
421 foo_SOURCES = c.c $(xs)
422 @end example
424 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
425 contents of @code{foo_SOURCES}.
427 @cindex @code{##} (special Automake comment)
428 @cindex Special Automake comment
429 @cindex Comment, special to Automake
431 Automake also allows a form of comment that is @emph{not} copied into
432 the output; all lines beginning with @samp{##} (leading spaces allowed)
433 are completely ignored by Automake.
435 It is customary to make the first line of @file{Makefile.am} read:
437 @cindex Makefile.am, first line
438 @cindex First line of Makefile.am
440 @example
441 ## Process this file with automake to produce Makefile.in
442 @end example
444 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
445 @c I don't know quite what to say.
447 @c FIXME document customary ordering of Makefile.am here!
450 @node Strictness
451 @section Strictness
453 @cindex Non-GNU packages
455 While Automake is intended to be used by maintainers of GNU packages, it
456 does make some effort to accommodate those who wish to use it, but do
457 not want to use all the GNU conventions.
459 @cindex Strictness, defined
460 @cindex Strictness, @option{foreign}
461 @cindex @option{foreign} strictness
462 @cindex Strictness, @option{gnu}
463 @cindex @option{gnu} strictness
464 @cindex Strictness, @option{gnits}
465 @cindex @option{gnits} strictness
467 To this end, Automake supports three levels of @dfn{strictness}---the
468 strictness indicating how stringently Automake should check standards
469 conformance.
471 The valid strictness levels are:
473 @table @option
474 @item foreign
475 Automake will check for only those things that are absolutely
476 required for proper operations.  For instance, whereas GNU standards
477 dictate the existence of a @file{NEWS} file, it will not be required in
478 this mode.  The name comes from the fact that Automake is intended to be
479 used for GNU programs; these relaxed rules are not the standard mode of
480 operation.
482 @item gnu
483 Automake will check---as much as possible---for compliance to the GNU
484 standards for packages.  This is the default.
486 @item gnits
487 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
488 standards}.  These are based on the GNU standards, but are even more
489 detailed.  Unless you are a Gnits standards contributor, it is
490 recommended that you avoid this option until such time as the Gnits
491 standard is actually published (which may never happen).
492 @end table
494 @xref{Gnits}, for more information on the precise implications of the
495 strictness level.
497 Automake also has a special ``cygnus'' mode that is similar to
498 strictness but handled differently.  This mode is useful for packages
499 that are put into a ``Cygnus'' style tree (e.g., the GCC tree).
500 @xref{Cygnus}, for more information on this mode.
503 @node Uniform
504 @section The Uniform Naming Scheme
506 @cindex Uniform naming scheme
508 Automake variables generally follow a @dfn{uniform naming scheme} that
509 makes it easy to decide how programs (and other derived objects) are
510 built, and how they are installed.  This scheme also supports
511 @command{configure} time determination of what should be built.
513 @cindex @code{_PROGRAMS} primary variable
514 @cindex @code{PROGRAMS} primary variable
515 @cindex Primary variable, @code{PROGRAMS}
516 @cindex Primary variable, defined
517 @vindex _PROGRAMS
519 At @command{make} time, certain variables are used to determine which
520 objects are to be built.  The variable names are made of several pieces
521 that are concatenated together.
523 The piece that tells automake what is being built is commonly called
524 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
525 list of programs that are to be compiled and linked.
526 @vindex PROGRAMS
528 @cindex @code{pkglibdir}, defined
529 @cindex @code{pkgincludedir}, defined
530 @cindex @code{pkgdatadir}, defined
532 @vindex pkglibdir
533 @vindex pkgincludedir
534 @vindex pkgdatadir
536 @cindex @code{PACKAGE}, directory
537 A different set of names is used to decide where the built objects
538 should be installed.  These names are prefixes to the primary, and they
539 indicate which standard directory should be used as the installation
540 directory.  The standard directory names are given in the GNU standards
541 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
542 Automake extends this list with @code{pkglibdir}, @code{pkgincludedir},
543 and @code{pkgdatadir}; these are the same as the non-@samp{pkg}
544 versions, but with @samp{$(PACKAGE)} appended.  For instance,
545 @code{pkglibdir} is defined as @samp{$(libdir)/$(PACKAGE)}.
547 @cindex @code{EXTRA_}, prepending
548 For each primary, there is one additional variable named by prepending
549 @samp{EXTRA_} to the primary name.  This variable is used to list
550 objects that may or may not be built, depending on what
551 @command{configure} decides.  This variable is required because Automake
552 must statically know the entire list of objects that may be built in
553 order to generate a @file{Makefile.in} that will work in all cases.
555 @cindex @code{EXTRA_PROGRAMS}, defined
556 @cindex Example, @code{EXTRA_PROGRAMS}
557 @cindex @command{cpio} example
559 For instance, @command{cpio} decides at configure time which programs
560 should be built.  Some of the programs are installed in @code{bindir},
561 and some are installed in @code{sbindir}:
563 @example
564 EXTRA_PROGRAMS = mt rmt
565 bin_PROGRAMS = cpio pax
566 sbin_PROGRAMS = $(MORE_PROGRAMS)
567 @end example
569 Defining a primary without a prefix as a variable, e.g.,
570 @samp{PROGRAMS}, is an error.
572 Note that the common @samp{dir} suffix is left off when constructing the
573 variable names; thus one writes @samp{bin_PROGRAMS} and not
574 @samp{bindir_PROGRAMS}.
576 Not every sort of object can be installed in every directory.  Automake
577 will flag those attempts it finds in error.
578 Automake will also diagnose obvious misspellings in directory names.
580 @cindex Extending list of installation directories
581 @cindex Installation directories, extending list
583 Sometimes the standard directories---even as augmented by
584 Automake---are not enough.  In particular it is sometimes useful, for
585 clarity, to install objects in a subdirectory of some predefined
586 directory.  To this end, Automake allows you to extend the list of
587 possible installation directories.  A given prefix (e.g., @samp{zar})
588 is valid if a variable of the same name with @samp{dir} appended is
589 defined (e.g., @samp{zardir}).
591 For instance, the following snippet will install @file{file.xml} into
592 @samp{$(datadir)/xml}.
594 @example
595 xmldir = $(datadir)/xml
596 xml_DATA = file.xml
597 @end example
599 @cindex @samp{noinst_} primary prefix, definition
600 @vindex noinst_
602 The special prefix @samp{noinst_} indicates that the objects in question
603 should be built but not installed at all.  This is usually used for
604 objects required to build the rest of your package, for instance static
605 libraries (@pxref{A Library}), or helper scripts.
607 @cindex @samp{check_} primary prefix, definition
608 @vindex check_
610 The special prefix @samp{check_} indicates that the objects in question
611 should not be built until the @samp{make check} command is run.  Those
612 objects are not installed either.
614 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
615 @samp{LISP}, @samp{PYTHON}, @samp{JAVA}, @samp{SCRIPTS}, @samp{DATA},
616 @samp{HEADERS}, @samp{MANS}, and @samp{TEXINFOS}.
617 @vindex PROGRAMS
618 @vindex LIBRARIES
619 @vindex LISP
620 @vindex PYTHON
621 @vindex JAVA
622 @vindex SCRIPTS
623 @vindex DATA
624 @vindex HEADERS
625 @vindex MANS
626 @vindex TEXINFOS
628 Some primaries also allow additional prefixes that control other
629 aspects of @command{automake}'s behavior.  The currently defined prefixes
630 are @samp{dist_}, @samp{nodist_}, and @samp{nobase_}.  These prefixes
631 are explained later (@pxref{Program and Library Variables}).
634 @node Canonicalization
635 @section How derived variables are named
637 @cindex canonicalizing Automake variables
639 Sometimes a Makefile variable name is derived from some text the
640 maintainer supplies.  For instance, a program name listed in
641 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
642 variable.  In cases like this, Automake canonicalizes the text, so that
643 program names and the like do not have to follow Makefile variable naming
644 rules.  All characters in the name except for letters, numbers, the
645 strudel (@@), and the underscore are turned into underscores when making
646 variable references.
648 For example, if your program is named @file{sniff-glue}, the derived
649 variable name would be @samp{sniff_glue_SOURCES}, not
650 @samp{sniff-glue_SOURCES}.  Similarly the sources for a library named
651 @file{libmumble++.a} should be listed in the
652 @samp{libmumble___a_SOURCES} variable.
654 The strudel is an addition, to make the use of Autoconf substitutions in
655 variable names less obfuscating.
658 @node User Variables
659 @section Variables reserved for the user
661 @cindex variables, reserved for the user
662 @cindex user variables
664 Some @file{Makefile} variables are reserved by the GNU Coding Standards
665 for the use of the ``user''---the person building the package.  For
666 instance, @code{CFLAGS} is one such variable.
668 Sometimes package developers are tempted to set user variables such as
669 @code{CFLAGS} because it appears to make their job easier.  However,
670 the package itself should never set a user variable, particularly not
671 to include switches that are required for proper compilation of the
672 package.  Since these variables are documented as being for the
673 package builder, that person rightfully expects to be able to override
674 any of these variables at build time.
676 To get around this problem, Automake introduces an automake-specific
677 shadow variable for each user flag variable.  (Shadow variables are
678 not introduced for variables like @code{CC}, where they would make no
679 sense.)  The shadow variable is named by prepending @samp{AM_} to the
680 user variable's name.  For instance, the shadow variable for
681 @code{YFLAGS} is @code{AM_YFLAGS}.  The package maintainer---that is,
682 the author(s) of the @file{Makefile.am} and @file{configure.ac}
683 files---may adjust these shadow variables however necessary.
685 @xref{Flag Variables Ordering}, for more discussion about these
686 variables and how they interact with per-target variables.
688 @node Auxiliary Programs
689 @section Programs automake might require
691 @cindex Programs, auxiliary
692 @cindex Auxiliary programs
694 Automake sometimes requires helper programs so that the generated
695 @file{Makefile} can do its work properly.  There are a fairly large
696 number of them, and we list them here.
698 Although all of these files are distributed and installed with
699 Automake, a couple of them are maintained separately.  The Automake
700 copies are updated before each release, but we mention the original
701 source in case you need more recent versions.
703 @table @code
704 @item ansi2knr.c
705 @itemx ansi2knr.1
706 These two files are used by the automatic de-ANSI-fication support
707 (@pxref{ANSI}).
709 @item compile
710 This is a wrapper for compilers that do not accept options @option{-c}
711 and @option{-o} at the same time.  It is only used when absolutely
712 required.  Such compilers are rare.
714 @item config.guess
715 @itemx config.sub
716 These two programs compute the canonical triplets for the given build,
717 host, or target architecture.  These programs are updated regularly to
718 support new architectures and fix probes broken by changes in new
719 kernel versions.  Each new release of Automake comes with up-to-date
720 copies of these programs.  If your copy of Automake is getting old,
721 you are encouraged to fetch the latest versions of these files from
722 @url{http://savannah.gnu.org/cvs/?group=config} before making a
723 release.
725 @item config-ml.in
726 This file is not a program, it is a @file{configure} fragment used for
727 multilib support (@pxref{Multilibs}).  This file is maintained in the
728 GCC tree at @url{http://gcc.gnu.org/cvs.html}.
730 @item depcomp
731 This program understands how to run a compiler so that it will
732 generate not only the desired output but also dependency information
733 that is then used by the automatic dependency tracking feature.
735 @item elisp-comp
736 This program is used to byte-compile Emacs Lisp code.
738 @item install-sh
739 This is a replacement for the @command{install} program that works on
740 platforms where @command{install} is unavailable or unusable.
742 @item mdate-sh
743 This script is used to generate a @file{version.texi} file.  It examines
744 a file and prints some date information about it.
746 @item missing
747 This wraps a number of programs that are typically only required by
748 maintainers.  If the program in question doesn't exist,
749 @command{missing} prints an informative warning and attempts to fix
750 things so that the build can continue.
752 @item mkinstalldirs
753 This script used to be a wrapper around @samp{mkdir -p}, which is not
754 portable.  Now we use prefer to use @samp{install-sh -d} when configure
755 finds that @samp{mkdir -p} does not work, this makes one less script to
756 distribute.
758 For backward compatibility @file{mkinstalldirs} is still used and
759 distributed when @command{automake} finds it in a package.  But it is no
760 longer installed automatically, and it should be safe to remove it.
762 @item py-compile
763 This is used to byte-compile Python scripts.
765 @item symlink-tree
766 This program duplicates a tree of directories, using symbolic links
767 instead of copying files.  Such operation is performed when building
768 multilibs (@pxref{Multilibs}).  This file is maintained in the GCC
769 tree at @url{http://gcc.gnu.org/cvs.html}.
771 @item texinfo.tex
772 Not a program, this file is required for @samp{make dvi}, @samp{make
773 ps} and @samp{make pdf} to work when Texinfo sources are in the
774 package.  The latest version can be downloaded from
775 @url{http://www.gnu.org/software/texinfo/}.
777 @item ylwrap
778 This program wraps @command{lex} and @command{yacc} and ensures that,
779 for instance, multiple @command{yacc} instances can be invoked in a
780 single directory in parallel.
782 @end table
785 @node Examples
786 @chapter Some example packages
788 @menu
789 * Complete::                    A simple example, start to finish
790 * Hello::                       A classic program
791 * true::                        Building true and false
792 @end menu
795 @node Complete
796 @section A simple example, start to finish
798 @cindex Complete example
800 Let's suppose you just finished writing @code{zardoz}, a program to make
801 your head float from vortex to vortex.  You've been using Autoconf to
802 provide a portability framework, but your @file{Makefile.in}s have been
803 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
805 @cindex @code{AM_INIT_AUTOMAKE}, example use
807 The first step is to update your @file{configure.ac} to include the
808 commands that @command{automake} needs.  The way to do this is to add an
809 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
811 @example
812 AC_INIT(zardoz, 1.0)
813 AM_INIT_AUTOMAKE
814 @dots{}
815 @end example
817 Since your program doesn't have any complicating factors (e.g., it
818 doesn't use @code{gettext}, it doesn't want to build a shared library),
819 you're done with this part.  That was easy!
821 @cindex @command{aclocal} program, introduction
822 @cindex @file{aclocal.m4}, preexisting
823 @cindex @file{acinclude.m4}, defined
825 Now you must regenerate @file{configure}.  But to do that, you'll need
826 to tell @command{autoconf} how to find the new macro you've used.  The
827 easiest way to do this is to use the @command{aclocal} program to
828 generate your @file{aclocal.m4} for you.  But wait@dots{} maybe you
829 already have an @file{aclocal.m4}, because you had to write some hairy
830 macros for your program.  The @command{aclocal} program lets you put
831 your own macros into @file{acinclude.m4}, so simply rename and then
832 run:
834 @example
835 mv aclocal.m4 acinclude.m4
836 aclocal
837 autoconf
838 @end example
840 @cindex @command{zardoz} example
842 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
843 Since @code{zardoz} is a user program, you want to install it where the
844 rest of the user programs go: @code{bindir}.  Additionally,
845 @code{zardoz} has some Texinfo documentation.  Your @file{configure.ac}
846 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
847 @samp{$(LIBOBJS)}.  So here's what you'd write:
849 @example
850 bin_PROGRAMS = zardoz
851 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
852 zardoz_LDADD = $(LIBOBJS)
854 info_TEXINFOS = zardoz.texi
855 @end example
857 Now you can run @samp{automake --add-missing} to generate your
858 @file{Makefile.in} and grab any auxiliary files you might need, and
859 you're done!
862 @node Hello
863 @section A classic program
865 @cindex Example, GNU Hello
866 @cindex Hello example
867 @cindex GNU Hello, example
869 @uref{ftp://prep.ai.mit.edu/pub/gnu/hello-1.3.tar.gz, GNU hello} is
870 renowned for its classic simplicity and versatility.  This section shows
871 how Automake could be used with the GNU Hello package.  The examples
872 below are from the latest beta version of GNU Hello, but with all of the
873 maintainer-only code stripped out, as well as all copyright comments.
875 Of course, GNU Hello is somewhat more featureful than your traditional
876 two-liner.  GNU Hello is internationalized, does option processing, and
877 has a manual and a test suite.
879 @cindex @file{configure.ac}, from GNU Hello
880 @cindex GNU Hello, @file{configure.ac}
881 @cindex Hello, @file{configure.ac}
883 Here is the @file{configure.ac} from GNU Hello.
884 @strong{Please note:} The calls to @code{AC_INIT} and @code{AM_INIT_AUTOMAKE}
885 in this example use a deprecated syntax.  For the current approach,
886 see the description of @code{AM_INIT_AUTOMAKE} in @ref{Public macros}.
888 @c FIXME: This definitely requires an update, e.g., to GNU Hello 2.1.1.
890 @example
891 dnl Process this file with autoconf to produce a configure script.
892 AC_INIT(src/hello.c)
893 AM_INIT_AUTOMAKE(hello, 1.3.11)
894 AM_CONFIG_HEADER(config.h)
896 dnl Set of available languages.
897 ALL_LINGUAS="de fr es ko nl no pl pt sl sv"
899 dnl Checks for programs.
900 AC_PROG_CC
901 AC_ISC_POSIX
903 dnl Checks for libraries.
905 dnl Checks for header files.
906 AC_STDC_HEADERS
907 AC_HAVE_HEADERS(string.h fcntl.h sys/file.h sys/param.h)
909 dnl Checks for library functions.
910 AC_FUNC_ALLOCA
912 dnl Check for st_blksize in struct stat
913 AC_ST_BLKSIZE
915 dnl internationalization macros
916 AM_GNU_GETTEXT
917 AC_OUTPUT([Makefile doc/Makefile intl/Makefile po/Makefile.in \
918            src/Makefile tests/Makefile tests/hello],
919    [chmod +x tests/hello])
920 @end example
922 The @samp{AM_} macros are provided by Automake (or the Gettext library);
923 the rest are standard Autoconf macros.
926 The top-level @file{Makefile.am}:
928 @example
929 EXTRA_DIST = BUGS ChangeLog.O
930 SUBDIRS = doc intl po src tests
931 @end example
933 As you can see, all the work here is really done in subdirectories.
935 The @file{po} and @file{intl} directories are automatically generated
936 using @command{gettextize}; they will not be discussed here.
938 @cindex Texinfo file handling example
939 @cindex Example, handling Texinfo files
941 In @file{doc/Makefile.am} we see:
943 @example
944 info_TEXINFOS = hello.texi
945 hello_TEXINFOS = gpl.texi
946 @end example
948 This is sufficient to build, install, and distribute the GNU Hello
949 manual.
951 @cindex Regression test example
952 @cindex Example, regression test
954 Here is @file{tests/Makefile.am}:
956 @example
957 TESTS = hello
958 EXTRA_DIST = hello.in testdata
959 @end example
961 The script @file{hello} is generated by @command{configure}, and is the
962 only test case.  @samp{make check} will run this test.
964 @cindex @code{INCLUDES}, example usage
965 @vindex INCLUDES
967 Last we have @file{src/Makefile.am}, where all the real work is done:
968 @c FIXME: As all the Hello World excerpts in this manual, this
969 @c shows deprecated features (here: $(INCLUDES)).
971 @example
972 bin_PROGRAMS = hello
973 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
974 hello_LDADD = $(INTLLIBS) $(ALLOCA)
975 localedir = $(datadir)/locale
976 INCLUDES = -I../intl -DLOCALEDIR=\"$(localedir)\"
977 @end example
980 @node true
981 @section Building true and false
983 @cindex Example, @command{false} and @command{true}
984 @cindex @command{false} Example
985 @cindex @command{true} Example
987 Here is another, trickier example.  It shows how to generate two
988 programs (@code{true} and @code{false}) from the same source file
989 (@file{true.c}).  The difficult part is that each compilation of
990 @file{true.c} requires different @code{cpp} flags.
992 @example
993 bin_PROGRAMS = true false
994 false_SOURCES =
995 false_LDADD = false.o
997 true.o: true.c
998         $(COMPILE) -DEXIT_CODE=0 -c true.c
1000 false.o: true.c
1001         $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
1002 @end example
1004 Note that there is no @code{true_SOURCES} definition.  Automake will
1005 implicitly assume that there is a source file named @file{true.c}, and
1006 define rules to compile @file{true.o} and link @file{true}.  The
1007 @samp{true.o: true.c} rule supplied by the above @file{Makefile.am},
1008 will override the Automake generated rule to build @file{true.o}.
1010 @code{false_SOURCES} is defined to be empty---that way no implicit value
1011 is substituted.  Because we have not listed the source of
1012 @file{false}, we have to tell Automake how to link the program.  This is
1013 the purpose of the @code{false_LDADD} line.  A @code{false_DEPENDENCIES}
1014 variable, holding the dependencies of the @file{false} target will be
1015 automatically generated by Automake from the content of
1016 @code{false_LDADD}.
1018 The above rules won't work if your compiler doesn't accept both
1019 @option{-c} and @option{-o}.  The simplest fix for this is to introduce a
1020 bogus dependency (to avoid problems with a parallel @command{make}):
1022 @example
1023 true.o: true.c false.o
1024         $(COMPILE) -DEXIT_CODE=0 -c true.c
1026 false.o: true.c
1027         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
1028 @end example
1030 Also, these explicit rules do not work if the de-ANSI-fication feature
1031 is used (@pxref{ANSI}).  Supporting de-ANSI-fication requires a little
1032 more work:
1034 @example
1035 true_.o: true_.c false_.o
1036         $(COMPILE) -DEXIT_CODE=0 -c true_.c
1038 false_.o: true_.c
1039         $(COMPILE) -DEXIT_CODE=1 -c true_.c && mv true_.o false_.o
1040 @end example
1042 As it turns out, there is also a much easier way to do this same task.
1043 Some of the above techniques are useful enough that we've kept the
1044 example in the manual.  However if you were to build @code{true} and
1045 @code{false} in real life, you would probably use per-program
1046 compilation flags, like so:
1048 @example
1049 bin_PROGRAMS = false true
1051 false_SOURCES = true.c
1052 false_CPPFLAGS = -DEXIT_CODE=1
1054 true_SOURCES = true.c
1055 true_CPPFLAGS = -DEXIT_CODE=0
1056 @end example
1058 In this case Automake will cause @file{true.c} to be compiled twice,
1059 with different flags.  De-ANSI-fication will work automatically.  In
1060 this instance, the names of the object files would be chosen by
1061 automake; they would be @file{false-true.o} and @file{true-true.o}.
1062 (The name of the object files rarely matters.)
1065 @node Invoking Automake
1066 @chapter Creating a @file{Makefile.in}
1068 @cindex Multiple @file{configure.ac} files
1069 @cindex Invoking @command{automake}
1070 @cindex @command{automake}, invoking
1072 To create all the @file{Makefile.in}s for a package, run the
1073 @command{automake} program in the top level directory, with no
1074 arguments.  @command{automake} will automatically find each
1075 appropriate @file{Makefile.am} (by scanning @file{configure.ac};
1076 @pxref{configure}) and generate the corresponding @file{Makefile.in}.
1077 Note that @command{automake} has a rather simplistic view of what
1078 constitutes a package; it assumes that a package has only one
1079 @file{configure.ac}, at the top.  If your package has multiple
1080 @file{configure.ac}s, then you must run @command{automake} in each
1081 directory holding a @file{configure.ac}.  (Alternatively, you may rely
1082 on Autoconf's @command{autoreconf}, which is able to recurse your
1083 package tree and run @command{automake} where appropriate.)
1085 You can optionally give @command{automake} an argument; @file{.am} is
1086 appended to the argument and the result is used as the name of the
1087 input file.  This feature is generally only used to automatically
1088 rebuild an out-of-date @file{Makefile.in}.  Note that
1089 @command{automake} must always be run from the topmost directory of a
1090 project, even if being used to regenerate the @file{Makefile.in} in
1091 some subdirectory.  This is necessary because @command{automake} must
1092 scan @file{configure.ac}, and because @command{automake} uses the
1093 knowledge that a @file{Makefile.in} is in a subdirectory to change its
1094 behavior in some cases.
1096 @vindex AUTOCONF
1097 Automake will run @command{autoconf} to scan @file{configure.ac} and
1098 its dependencies (i.e., @file{aclocal.m4} and any included file),
1099 therefore @command{autoconf} must be in your @env{PATH}.  If there is
1100 an @env{AUTOCONF} variable in your environment it will be used
1101 instead of @command{autoconf}, this allows you to select a particular
1102 version of Autoconf.  By the way, don't misunderstand this paragraph:
1103 @command{automake} runs @command{autoconf} to @strong{scan} your
1104 @file{configure.ac}, this won't build @file{configure} and you still
1105 have to run @command{autoconf} yourself for this purpose.
1107 @cindex @command{automake} options
1108 @cindex Options, @command{automake}
1109 @cindex Strictness, command line
1111 @command{automake} accepts the following options:
1113 @cindex Extra files distributed with Automake
1114 @cindex Files distributed with Automake
1115 @cindex @file{config.guess}
1117 @table @code
1118 @item -a
1119 @itemx --add-missing
1120 @opindex -a
1121 @opindex --add-missing
1122 Automake requires certain common files to exist in certain situations;
1123 for instance, @file{config.guess} is required if @file{configure.ac} runs
1124 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
1125 files (@pxref{Auxiliary Programs}); this option will cause the missing
1126 ones to be automatically added to the package, whenever possible.  In
1127 general if Automake tells you a file is missing, try using this option.
1128 By default Automake tries to make a symbolic link pointing to its own
1129 copy of the missing file; this can be changed with @option{--copy}.
1131 Many of the potentially-missing files are common scripts whose
1132 location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
1133 Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
1134 file is considered missing, and where the missing file is added
1135 (@pxref{Optional}).
1137 @item --libdir=@var{dir}
1138 @opindex --libdir
1139 Look for Automake data files in directory @var{dir} instead of in the
1140 installation directory.  This is typically used for debugging.
1142 @item -c
1143 @opindex -c
1144 @itemx --copy
1145 @opindex --copy
1146 When used with @option{--add-missing}, causes installed files to be
1147 copied.  The default is to make a symbolic link.
1149 @item --cygnus
1150 @opindex --cygnus
1151 Causes the generated @file{Makefile.in}s to follow Cygnus rules, instead
1152 of GNU or Gnits rules.  For more information, see @ref{Cygnus}.
1154 @item -f
1155 @opindex -f
1156 @itemx --force-missing
1157 @opindex --force-missing
1158 When used with @option{--add-missing}, causes standard files to be reinstalled
1159 even if they already exist in the source tree.  This involves removing
1160 the file from the source tree before creating the new symlink (or, with
1161 @option{--copy}, copying the new file).
1163 @item --foreign
1164 @opindex --foreign
1165 Set the global strictness to @option{foreign}.  For more information, see
1166 @ref{Strictness}.
1168 @item --gnits
1169 @opindex --gnits
1170 Set the global strictness to @option{gnits}.  For more information, see
1171 @ref{Gnits}.
1173 @item --gnu
1174 @opindex --gnu
1175 Set the global strictness to @option{gnu}.  For more information, see
1176 @ref{Gnits}.  This is the default strictness.
1178 @item --help
1179 @opindex --help
1180 Print a summary of the command line options and exit.
1182 @item -i
1183 @itemx --ignore-deps
1184 @opindex -i
1185 This disables the dependency tracking feature in generated
1186 @file{Makefile}s; see @ref{Dependencies}.
1188 @item --include-deps
1189 @opindex --include-deps
1190 This enables the dependency tracking feature.  This feature is enabled
1191 by default.  This option is provided for historical reasons only and
1192 probably should not be used.
1194 @item --no-force
1195 @opindex --no-force
1196 Ordinarily @command{automake} creates all @file{Makefile.in}s mentioned in
1197 @file{configure.ac}.  This option causes it to only update those
1198 @file{Makefile.in}s that are out of date with respect to one of their
1199 dependents.
1201 @item -o @var{dir}
1202 @itemx --output-dir=@var{dir}
1203 @opindex -o
1204 @opindex --output-dir
1205 Put the generated @file{Makefile.in} in the directory @var{dir}.
1206 Ordinarily each @file{Makefile.in} is created in the directory of the
1207 corresponding @file{Makefile.am}.  This option is deprecated and will be
1208 removed in a future release.
1210 @item -v
1211 @itemx --verbose
1212 @opindex -v
1213 @opindex --verbose
1214 Cause Automake to print information about which files are being read or
1215 created.
1217 @item --version
1218 @opindex --version
1219 Print the version number of Automake and exit.
1221 @item -W CATEGORY
1222 @item --warnings=@var{category}
1223 @opindex -W
1224 @opindex --warnings
1225 Output warnings falling in @var{category}.  @var{category} can be
1226 one of:
1227 @table @code
1228 @item gnu
1229 warnings related to the GNU Coding Standards
1230 (@pxref{Top, , , standards, The GNU Coding Standards}).
1231 @item obsolete
1232 obsolete features or constructions
1233 @item override
1234 user redefinitions of Automake rules or variables
1235 @item portability
1236 portability issues (e.g., use of @command{make} features that are
1237 known to be not portable)
1238 @item syntax
1239 weird syntax, unused variables, typos
1240 @item unsupported
1241 unsupported or incomplete features
1242 @item all
1243 all the warnings
1244 @item none
1245 turn off all the warnings
1246 @item error
1247 treat warnings as errors
1248 @end table
1250 A category can be turned off by prefixing its name with @samp{no-}.  For
1251 instance, @option{-Wno-syntax} will hide the warnings about unused
1252 variables.
1254 The categories output by default are @samp{syntax} and
1255 @samp{unsupported}.  Additionally, @samp{gnu} is enabled in @option{--gnu} and
1256 @option{--gnits} strictness.
1258 @samp{portability} warnings are currently disabled by default, but they
1259 will be enabled in @option{--gnu} and @option{--gnits} strictness in a
1260 future release.
1262 @vindex WARNINGS
1263 The environment variable @env{WARNINGS} can contain a comma separated
1264 list of categories to enable.  It will be taken into account before the
1265 command-line switches, this way @option{-Wnone} will also ignore any
1266 warning category enabled by @env{WARNINGS}.  This variable is also used
1267 by other tools like @command{autoconf}; unknown categories are ignored
1268 for this reason.
1270 @end table
1273 @node configure
1274 @chapter Scanning @file{configure.ac}
1276 @cindex @file{configure.ac}, scanning
1277 @cindex Scanning @file{configure.ac}
1279 Automake scans the package's @file{configure.ac} to determine certain
1280 information about the package.  Some @command{autoconf} macros are required
1281 and some variables must be defined in @file{configure.ac}.  Automake
1282 will also use information from @file{configure.ac} to further tailor its
1283 output.
1285 Automake also supplies some Autoconf macros to make the maintenance
1286 easier.  These macros can automatically be put into your
1287 @file{aclocal.m4} using the @command{aclocal} program.
1289 @menu
1290 * Requirements::                Configuration requirements
1291 * Optional::                    Other things Automake recognizes
1292 * Invoking aclocal::            Auto-generating aclocal.m4
1293 * Macros::                      Autoconf macros supplied with Automake
1294 @end menu
1297 @node Requirements
1298 @section Configuration requirements
1300 @cindex Automake requirements
1301 @cindex Requirements of Automake
1303 @acindex AM_INIT_AUTOMAKE
1304 The one real requirement of Automake is that your @file{configure.ac}
1305 call @code{AM_INIT_AUTOMAKE}.  This macro does several things that are
1306 required for proper Automake operation (@pxref{Macros}).
1308 Here are the other macros that Automake requires but which are not run
1309 by @code{AM_INIT_AUTOMAKE}:
1311 @table @code
1312 @item AC_CONFIG_FILES
1313 @itemx AC_OUTPUT
1314 @acindex AC_CONFIG_FILES
1315 @acindex AC_OUTPUT
1316 These two macros are usually invoked as follows near the end of
1317 @file{configure.ac}.
1319 @example
1320 @dots{}
1321 AC_CONFIG_FILES([
1322   Makefile
1323   doc/Makefile
1324   src/Makefile
1325   src/lib/Makefile
1326   @dots{}
1328 AC_OUTPUT
1329 @end example
1331 Automake uses these to determine which files to create (@pxref{Output, ,
1332 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
1333 is considered to be an Automake generated @file{Makefile} if there
1334 exists a file with the same name and the @file{.am} extension appended.
1335 Typically, @samp{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
1336 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
1338 When using @code{AC_CONFIG_FILES} with multiple input files, as in
1340 @example
1341 AC_CONFIG_FILES([Makefile:top.in:Makefile.in:bot.in])
1342 @end example
1344 @noindent
1345 @command{automake} will generate the first @file{.in} input file for
1346 which a @file{.am} file exists.  If no such file exists the output
1347 file is not considered to be Automake generated.
1349 Files created by @code{AC_CONFIG_FILES}, be they Automake
1350 @file{Makefile}s or not, are all removed by @samp{make distclean}.
1351 Their inputs are automatically distributed, except for inputs that
1352 turn out the be outputs of prior @code{AC_CONFIG_FILES} commands.
1353 Finally, rebuild rules are generated in the Automake @file{Makefile}
1354 existing in the subdirectory of the output file, if there is one, or
1355 in the top-level @file{Makefile} otherwise.
1357 The above machinery (cleaning, distributing, and rebuilding) works
1358 fine if the @code{AC_CONFIG_FILES} specifications contain only
1359 literals.  If part of the specification uses shell variables,
1360 @command{automake} will not be able to fulfil this setup, and you will
1361 have to complete the missing bits by hand.  For instance, on
1363 @example
1364 file=input
1365 @dots{}
1366 AC_CONFIG_FILES([output:$file],, [file=$file])
1367 @end example
1369 @noindent
1370 @command{automake} will output rules to clean @file{output}, and
1371 rebuild it.  However the rebuild rule will not depend on @file{input},
1372 and this file will not be distributed either.  (You must add
1373 @samp{EXTRA_DIST = input} to your @file{Makefile} if @file{input} is a
1374 source file.)
1376 Similarly
1378 @example
1379 file=output
1380 file2=out:in
1381 @dots{}
1382 AC_CONFIG_FILES([$file:input],, [file=$file])
1383 AC_CONFIG_FILES([$file2],, [file2=$file2])
1384 @end example
1386 @noindent
1387 will only cause @file{input} to be distributed.  No file will be
1388 cleaned automatically (add @samp{DISTCLEANFILES = output out}
1389 yourself), and no rebuild rule will be output.
1391 Obviously @command{automake} cannot guess what value @samp{$file} is
1392 going to hold later when @file{configure} is run, and it cannot use
1393 the shell variable @samp{$file} in a @file{Makefile}.  However, if you
1394 make reference to @samp{$file} as @samp{$@{file@}} (i.e., in a way
1395 that is compatible with @command{make}'s syntax) and furthermore use
1396 @code{AC_SUBST} to ensure that @samp{$@{file@}} is meaningful in a
1397 @file{Makefile}, then @command{automake} will be able to use
1398 @samp{$@{file@}} to generate all these rules.  For instance, here is
1399 how the Automake package itself generates versioned scripts for its
1400 test suite:
1402 @example
1403 AC_SUBST([APIVERSION], @dots{})
1404 @dots{}
1405 AC_CONFIG_FILES(
1406   [tests/aclocal-$@{APIVERSION@}:tests/aclocal.in],
1407   [chmod +x tests/aclocal-$@{APIVERSION@}],
1408   [APIVERSION=$APIVERSION])
1409 AC_CONFIG_FILES(
1410   [tests/automake-$@{APIVERSION@}:tests/automake.in],
1411   [chmod +x tests/automake-$@{APIVERSION@}])
1412 @end example
1414 @noindent
1415 Here cleaning, distributing, and rebuilding are done automatically,
1416 because @samp{$@{APIVERSION@}} is known at @command{make}-time.
1418 Note that you should not use shell variables to declare
1419 @file{Makefile} files for which @command{automake} must create
1420 @file{Makefile.in}.  Even @code{AC_SUBST} does not help here, because
1421 @command{automake} needs to know the file name when it runs in order
1422 to check whether @file{Makefile.am} exists.  (In the very hairy case
1423 that your setup requires such use of variables, you will have to tell
1424 Automake which @file{Makefile.in}s to generate on the command-line.)
1426 To summarize:
1427 @itemize @bullet
1428 @item
1429 Use literals for @file{Makefile}s, and for other files whenever possible.
1430 @item
1431 Use @samp{$file} (or @samp{$@{file@}} without @samp{AC_SUBST([file])})
1432 for files that @command{automake} should ignore.
1433 @item
1434 Use @samp{$@{file@}} and @samp{AC_SUBST([file])} for files
1435 that @command{automake} should not ignore.
1436 @end itemize
1438 @end table
1441 @node Optional
1442 @section Other things Automake recognizes
1444 @cindex Macros Automake recognizes
1445 @cindex Recognized macros by Automake
1447 Every time Automake is run it calls Autoconf to trace
1448 @file{configure.ac}.  This way it can recognize the use of certain
1449 macros and tailor the generated @file{Makefile.in} appropriately.
1450 Currently recognized macros and their effects are:
1452 @ftable @code
1453 @item AC_CANONICAL_BUILD
1454 @itemx AC_CANONICAL_HOST
1455 @itemx AC_CANONICAL_TARGET
1456 @vindex build_triplet
1457 @vindex host_triplet
1458 @vindex target_triplet
1459 Automake will ensure that @file{config.guess} and @file{config.sub}
1460 exist.  Also, the @file{Makefile} variables @code{build_triplet},
1461 @code{host_triplet} and @code{target_triplet} are introduced.  See
1462 @ref{Canonicalizing, , Getting the Canonical System Type, autoconf,
1463 The Autoconf Manual}.
1465 @item AC_CONFIG_AUX_DIR
1466 Automake will look for various helper scripts, such as
1467 @file{install-sh}, in the directory named in this macro invocation.
1468 @c This list is accurate relative to version 1.8
1469 (The full list of scripts is: @file{config.guess}, @file{config.sub},
1470 @file{depcomp}, @file{elisp-comp}, @file{compile}, @file{install-sh},
1471 @file{ltmain.sh}, @file{mdate-sh}, @file{missing}, @file{mkinstalldirs},
1472 @file{py-compile}, @file{texinfo.tex}, and @file{ylwrap}.)  Not all
1473 scripts are always searched for; some scripts will only be sought if the
1474 generated @file{Makefile.in} requires them.
1476 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
1477 their standard locations.  For @file{mdate-sh},
1478 @file{texinfo.tex}, and @file{ylwrap}, the standard location is the
1479 source directory corresponding to the current @file{Makefile.am}.  For
1480 the rest, the standard location is the first one of @file{.}, @file{..},
1481 or @file{../..} (relative to the top source directory) that provides any
1482 one of the helper scripts.  @xref{Input, , Finding `configure' Input,
1483 autoconf, The Autoconf Manual}.
1485 Required files from @code{AC_CONFIG_AUX_DIR} are automatically
1486 distributed, even if there is no @file{Makefile.am} in this directory.
1488 @item AC_CONFIG_LIBOBJ_DIR
1489 Automake will require the sources file declared with
1490 @code{AC_LIBSOURCE} (see below) in the directory specified by this
1491 macro.
1493 @item AC_CONFIG_HEADERS
1494 Automake will generate rules to rebuild these headers.  Older versions
1495 of Automake required the use of @code{AM_CONFIG_HEADER}
1496 (@pxref{Macros}); this is no longer the case today.
1498 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
1499 specification using shell variables will be ignored as far as
1500 cleaning, distributing, and rebuilding is concerned.
1502 @item AC_CONFIG_LINKS
1503 Automake will generate rules to remove @file{configure} generated
1504 links on @samp{make distclean} and to distribute named source files as
1505 part of @samp{make dist}.
1507 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
1508 specification using shell variables will be ignored as far as cleaning
1509 and distributing is concerned.  (There is no rebuild rules for links.)
1511 @item AC_LIBOBJ
1512 @itemx AC_LIBSOURCE
1513 @itemx AC_LIBSOURCES
1514 @vindex LIBOBJS
1515 Automake will automatically distribute any file listed in
1516 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
1518 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}.  So if
1519 an Autoconf macro is documented to call @samp{AC_LIBOBJ([file])}, then
1520 @file{file.c} will be distributed automatically by Automake.  This
1521 encompasses many macros like @code{AC_FUNC_ALLOCA},
1522 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
1524 By the way, direct assignments to @code{LIBOBJS} are no longer
1525 supported.  You should always use @code{AC_LIBOBJ} for this purpose.
1526 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
1527 autoconf, The Autoconf Manual}.
1529 @item AC_PROG_RANLIB
1530 This is required if any libraries are built in the package.
1531 @xref{Particular Programs, , Particular Program Checks, autoconf, The
1532 Autoconf Manual}.
1534 @item AC_PROG_CXX
1535 This is required if any C++ source is included.  @xref{Particular
1536 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
1538 @item AC_PROG_F77
1539 This is required if any Fortran 77 source is included.  This macro is
1540 distributed with Autoconf version 2.13 and later.  @xref{Particular
1541 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
1543 @item AC_F77_LIBRARY_LDFLAGS
1544 This is required for programs and shared libraries that are a mixture of
1545 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
1546 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
1548 @item AC_PROG_FC
1549 This is required if any Fortran 90/95 source is included.  This macro is
1550 distributed with Autoconf version 2.58 and later.  @xref{Particular
1551 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
1553 @item AC_PROG_LIBTOOL
1554 Automake will turn on processing for @command{libtool} (@pxref{Top, ,
1555 Introduction, libtool, The Libtool Manual}).
1557 @item AC_PROG_YACC
1558 @vindex YACC
1559 If a Yacc source file is seen, then you must either use this macro or
1560 define the variable @code{YACC} in @file{configure.ac}.  The former is
1561 preferred (@pxref{Particular Programs, , Particular Program Checks,
1562 autoconf, The Autoconf Manual}).
1564 @item AC_PROG_LEX
1565 If a Lex source file is seen, then this macro must be used.
1566 @xref{Particular Programs, , Particular Program Checks, autoconf, The
1567 Autoconf Manual}.
1569 @item AC_REQUIRE_AUX_FILE
1570 @command{automake} will ensure each file for which this macro is
1571 called exists in the aux directory, and will complain otherwise.  It
1572 will also automatically distribute the file.  This macro should be
1573 used by third-party Autoconf macros that requires some supporting
1574 files in the aux directory specified with @code{AC_CONFIG_AUX_DIR}
1575 above.  @xref{Input, , Finding @command{configure} Input, autoconf,
1576 The Autoconf Manual}.
1578 @item AC_SUBST
1579 The first argument is automatically defined as a variable in each
1580 generated @file{Makefile.in}.  @xref{Setting Output Variables, , Setting
1581 Output Variables, autoconf, The Autoconf Manual}.
1583 If the Autoconf manual says that a macro calls @code{AC_SUBST} for
1584 @var{var}, or defines the output variable @var{var} then @var{var} will
1585 be defined in each @file{Makefile.in} generated by Automake.
1586 E.g.@: @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and @code{X_LIBS}, so
1587 you can use these variables in any @file{Makefile.am} if
1588 @code{AC_PATH_XTRA} is called.
1590 @item AM_C_PROTOTYPES
1591 This is required when using automatic de-ANSI-fication; see @ref{ANSI}.
1593 @item AM_GNU_GETTEXT
1594 This macro is required for packages that use GNU gettext
1595 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
1596 this macro it ensures that the package meets some of gettext's
1597 requirements.
1599 @item AM_MAINTAINER_MODE
1600 @opindex --enable-maintainer-mode
1601 This macro adds a @option{--enable-maintainer-mode} option to
1602 @command{configure}.  If this is used, @command{automake} will cause
1603 ``maintainer-only'' rules to be turned off by default in the
1604 generated @file{Makefile.in}s.  This macro defines the
1605 @code{MAINTAINER_MODE} conditional, which you can use in your own
1606 @file{Makefile.am}.  @xref{maintainer-mode}.
1608 @item m4_include
1609 Files included by @file{configure.ac} using this macro will be
1610 detected by Automake and automatically distributed.  They will also
1611 appear as dependencies in @file{Makefile} rules.
1613 @code{m4_include} is seldom used by @file{configure.ac} authors, but
1614 can appear in @file{aclocal.m4} when @command{aclocal} detects that
1615 some required macros come from files local to your package (as opposed
1616 to macros installed in a system-wide directory, @pxref{Invoking
1617 aclocal}).
1619 @end ftable
1622 @node Invoking aclocal
1623 @section Auto-generating aclocal.m4
1625 @cindex Invoking @command{aclocal}
1626 @cindex @command{aclocal}, Invoking
1628 Automake includes a number of Autoconf macros that can be used in
1629 your package (@pxref{Macros}); some of them are actually required by
1630 Automake in certain situations.  These macros must be defined in your
1631 @file{aclocal.m4}; otherwise they will not be seen by
1632 @command{autoconf}.
1634 The @command{aclocal} program will automatically generate
1635 @file{aclocal.m4} files based on the contents of @file{configure.ac}.
1636 This provides a convenient way to get Automake-provided macros,
1637 without having to search around.  The @command{aclocal} mechanism
1638 allows other packages to supply their own macros (@pxref{Extending
1639 aclocal}).  You can also use it to maintain your own set of custom
1640 macros (@pxref{Local Macros}).
1642 At startup, @command{aclocal} scans all the @file{.m4} files it can
1643 find, looking for macro definitions (@pxref{Macro search path}).  Then
1644 it scans @file{configure.ac}.  Any mention of one of the macros found
1645 in the first step causes that macro, and any macros it in turn
1646 requires, to be put into @file{aclocal.m4}.
1648 @emph{Putting} the file that contains the macro definition into
1649 @file{aclocal.m4} is usually done by copying the entire text of this
1650 file, including unused macro definitions as well as both @samp{#} and
1651 @samp{dnl} comments.  If you want to make a comment that will be
1652 completely ignored by @command{aclocal}, use @samp{##} as the comment
1653 leader.
1655 When a file selected by @command{aclocal} is located in a subdirectory
1656 specified as a relative search path with @command{aclocal}'s @option{-I}
1657 argument, @command{aclocal} assumes the file belongs to the package
1658 and uses @code{m4_include} instead of copying it into
1659 @file{aclocal.m4}.  This makes the package smaller, eases dependency
1660 tracking, and cause the file to be distributed automatically.
1661 (@xref{Local Macros}, for an example.)  Any macro that is found in a
1662 system-wide directory, or via an absolute search path will be copied.
1663 So use @samp{-I `pwd`/reldir} instead of @samp{-I reldir} whenever
1664 some relative directory need to be considered outside the package.
1666 The contents of @file{acinclude.m4}, if this file exists, are also
1667 automatically included in @file{aclocal.m4}.  We recommend against
1668 using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
1670 @vindex AUTOM4TE
1671 @cindex autom4te
1672 While computing @file{aclocal.m4}, @command{aclocal} runs
1673 @command{autom4te} (@pxref{Using autom4te, , Using @command{Autom4te},
1674 autoconf, The Autoconf Manual}) in order to trace the macros that are
1675 really used, and omit from @file{aclocal.m4} all macros that are
1676 mentioned but otherwise unexpanded (this can happen when a macro is
1677 called conditionally).  @command{autom4te} is expected to be in the
1678 @env{PATH}, just as @command{autoconf}.  Its location can be
1679 overridden using the @env{AUTOM4TE} environment variable.
1681 @menu
1682 * aclocal options::             Options supported by aclocal
1683 * Macro search path::           How aclocal finds .m4 files
1684 * Extending aclocal::           Writing your own aclocal macros
1685 * Local Macros::                Organizing local macros
1686 * Serials::                     Serial lines in Autoconf macros
1687 * Future of aclocal::           aclocal's scheduled death
1688 @end menu
1690 @node aclocal options
1691 @subsection aclocal options
1693 @cindex @command{aclocal}, Options
1694 @cindex Options, @command{aclocal}
1696 @command{aclocal} accepts the following options:
1698 @table @code
1699 @item --acdir=@var{dir}
1700 @opindex --acdir
1701 Look for the macro files in @var{dir} instead of the installation
1702 directory.  This is typically used for debugging.
1704 @item --diff[=@var{command}]
1705 @opindex --diff
1706 Run @var{command} on M4 file that would be installed or overwritten
1707 by @option{--install}.  The default @var{command} is @samp{diff -u}.
1708 This option implies @option{--install} and @option{--dry-run}.
1710 @item --dry-run
1711 @opindex --dry-run
1712 Do not actually overwrite (or create) @file{aclocal.m4} and M4
1713 files installed by @option{--install}.
1715 @item --help
1716 @opindex --help
1717 Print a summary of the command line options and exit.
1719 @item -I @var{dir}
1720 @opindex -I
1721 Add the directory @var{dir} to the list of directories searched for
1722 @file{.m4} files.
1724 @item --install
1725 @opindex --install
1726 Install system-wide third-party macros into the first directory
1727 specified with @samp{-I @var{dir}} instead of copying them in the
1728 output file.
1730 @cindex serial number and @option{--install}
1731 When this option is used, and only when this option is used,
1732 @command{aclocal} will also honor @samp{#serial @var{NUMBER}} lines
1733 that appear in macros: an M4 file is ignored if there exists another
1734 M4 file with the same basename and a greater serial number in the
1735 search path (@pxref{Serials}).
1737 @item --force
1738 @opindex --force
1739 Always overwrite the output file.  The default is to overwrite the output
1740 file only when really needed, i.e., when its contents changes or if one
1741 of its dependencies is younger.
1743 This option forces the update of @file{aclocal.m4} (or the file
1744 specified with @file{--output} below) and only this file, it has
1745 absolutely no influence on files that may need to be installed by
1746 @option{--install}.
1748 @item --output=@var{file}
1749 @opindex --output
1750 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
1752 @item --print-ac-dir
1753 @opindex --print-ac-dir
1754 Prints the name of the directory that @command{aclocal} will search to
1755 find third-party @file{.m4} files.  When this option is given, normal
1756 processing is suppressed.  This option can be used by a package to
1757 determine where to install a macro file.
1759 @item --verbose
1760 @opindex --verbose
1761 Print the names of the files it examines.
1763 @item --version
1764 @opindex --version
1765 Print the version number of Automake and exit.
1767 @item -W CATEGORY
1768 @item --warnings=@var{category}
1769 @opindex -W
1770 @opindex --warnings
1771 Output warnings falling in @var{category}.  @var{category} can be
1772 one of:
1773 @table @code
1774 @item syntax
1775 dubious syntactic constructs, underquoted macros, unused macros, etc.
1776 @item unsupported
1777 unknown macros
1778 @item all
1779 all the warnings, this is the default
1780 @item none
1781 turn off all the warnings
1782 @item error
1783 treat warnings as errors
1784 @end table
1786 All warnings are output by default.
1788 @vindex WARNINGS
1789 The environment variable @env{WARNINGS} is honored in the same
1790 way as it is for @command{automake} (@pxref{Invoking Automake}).
1792 @end table
1794 @node Macro search path
1795 @subsection Macro search path
1797 @cindex Macro search path
1798 @cindex @command{aclocal} search path
1800 By default, @command{aclocal} searches for @file{.m4} files in the following
1801 directories, in this order:
1803 @table @code
1804 @item @var{acdir-APIVERSION}
1805 This is where the @file{.m4} macros distributed with automake itself
1806 are stored.  @var{APIVERSION} depends on the automake release used;
1807 for automake 1.6.x, @var{APIVERSION} = @code{1.6}.
1809 @item @var{acdir}
1810 This directory is intended for third party @file{.m4} files, and is
1811 configured when @command{automake} itself is built.  This is
1812 @file{@@datadir@@/aclocal/}, which typically
1813 expands to @file{$@{prefix@}/share/aclocal/}.  To find the compiled-in
1814 value of @var{acdir}, use the @option{--print-ac-dir} option
1815 (@pxref{aclocal options}).
1816 @end table
1818 As an example, suppose that @command{automake-1.6.2} was configured with
1819 @option{--prefix=@-/usr/local}.  Then, the search path would be:
1821 @enumerate
1822 @item @file{/usr/local/share/aclocal-1.6/}
1823 @item @file{/usr/local/share/aclocal/}
1824 @end enumerate
1826 As explained in (@pxref{aclocal options}), there are several options that
1827 can be used to change or extend this search path.
1829 @subsubsection Modifying the macro search path: @option{--acdir}
1831 The most erroneous option to modify the search path is
1832 @option{--acdir=@var{dir}}, which changes default directory and
1833 drops the @var{APIVERSION} directory.  For example, if one specifies
1834 @samp{--acdir=/opt/private/}, then the search path becomes:
1836 @enumerate
1837 @item @file{/opt/private/}
1838 @end enumerate
1840 This option, @option{--acdir}, is intended for use by the internal
1841 automake test suite only; it is not ordinarily needed by end-users.
1843 @subsubsection Modifying the macro search path: @samp{-I @var{dir}}
1845 Any extra directories specified using @option{-I} options
1846 (@pxref{aclocal options}) are @emph{prepended} to this search list.  Thus,
1847 @samp{aclocal -I /foo -I /bar} results in the following search path:
1849 @enumerate
1850 @item @file{/foo}
1851 @item @file{/bar}
1852 @item @var{acdir}-@var{APIVERSION}
1853 @item @var{acdir}
1854 @end enumerate
1856 @subsubsection Modifying the macro search path: @file{dirlist}
1857 @cindex @file{dirlist}
1859 There is a third mechanism for customizing the search path.  If a
1860 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
1861 contain a list of directories, one per line, to be added to the search
1862 list.  These directories are searched @emph{after} all other
1863 directories.
1865 For example, suppose
1866 @file{@var{acdir}/dirlist} contains the following:
1868 @example
1869 /test1
1870 /test2
1871 @end example
1873 @noindent
1874 and that @command{aclocal} was called with the @samp{-I /foo -I /bar} options.
1875 Then, the search path would be
1877 @c @code looks better than @file here
1878 @enumerate
1879 @item @code{/foo}
1880 @item @code{/bar}
1881 @item @var{acdir}-@var{APIVERSION}
1882 @item @var{acdir}
1883 @item @code{/test1}
1884 @item @code{/test2}
1885 @end enumerate
1887 If the @option{--acdir=@var{dir}} option is used, then @command{aclocal}
1888 will search for the @file{dirlist} file in @var{dir}.  In the
1889 @samp{--acdir=/opt/private/} example above, @command{aclocal} would look
1890 for @file{/opt/private/dirlist}.  Again, however, the @option{--acdir}
1891 option is intended for use by the internal automake test suite only;
1892 @option{--acdir} is not ordinarily needed by end-users.
1894 @file{dirlist} is useful in the following situation: suppose that
1895 @command{automake} version @code{1.6.2} is installed with
1896 @samp{--prefix=/usr} by the system vendor.  Thus, the default search
1897 directories are
1899 @c @code looks better than @file here
1900 @enumerate
1901 @item @code{/usr/share/aclocal-1.6/}
1902 @item @code{/usr/share/aclocal/}
1903 @end enumerate
1905 However, suppose further that many packages have been manually
1906 installed on the system, with $prefix=/usr/local, as is typical.  In
1907 that case, many of these ``extra'' @file{.m4} files are in
1908 @file{/usr/local/share/aclocal}.  The only way to force
1909 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files is to
1910 always call @samp{aclocal -I /usr/local/share/aclocal}.  This is
1911 inconvenient.  With @file{dirlist}, one may create a file
1912 @file{/usr/share/aclocal/dirlist} containing only the single line
1914 @example
1915 /usr/local/share/aclocal
1916 @end example
1918 Now, the ``default'' search path on the affected system is
1920 @c @code looks better than @file here
1921 @enumerate
1922 @item @code{/usr/share/aclocal-1.6/}
1923 @item @code{/usr/share/aclocal/}
1924 @item @code{/usr/local/share/aclocal/}
1925 @end enumerate
1927 without the need for @option{-I} options; @option{-I} options can be reserved
1928 for project-specific needs (@file{my-source-dir/m4/}), rather than
1929 using it to work around local system-dependent tool installation
1930 directories.
1932 Similarly, @file{dirlist} can be handy if you have installed a local
1933 copy Automake on your account and want @command{aclocal} to look for
1934 macros installed at other places on the system.
1937 @node Extending aclocal
1938 @subsection Writing your own aclocal macros
1940 @cindex @command{aclocal}, extending
1941 @cindex Extending @command{aclocal}
1943 The @command{aclocal} program doesn't have any built-in knowledge of any
1944 macros, so it is easy to extend it with your own macros.
1946 This can be used by libraries that want to supply their own Autoconf
1947 macros for use by other programs.  For instance, the @command{gettext}
1948 library supplies a macro @code{AM_GNU_GETTEXT} that should be used by
1949 any package using @command{gettext}.  When the library is installed, it
1950 installs this macro so that @command{aclocal} will find it.
1952 A macro file's name should end in @file{.m4}.  Such files should be
1953 installed in @file{$(datadir)/aclocal}.  This is as simple as writing:
1955 @example
1956 aclocaldir = $(datadir)/aclocal
1957 aclocal_DATA = mymacro.m4 myothermacro.m4
1958 @end example
1960 @noindent
1961 Please do use @file{$(datadir)/aclocal}, and not something based on
1962 the result of @samp{aclocal --print-ac-dir}.  @xref{Hard-Coded Install
1963 Paths}, for arguments.
1965 A file of macros should be a series of properly quoted
1966 @code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
1967 Autoconf Manual}).  The @command{aclocal} programs also understands
1968 @code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
1969 Autoconf Manual}), so it is safe to put each macro in a separate file.
1970 Each file should have no side effects but macro definitions.
1971 Especially, any call to @code{AC_PREREQ} should be done inside the
1972 defined macro, not at the beginning of the file.
1974 @cindex underquoted @code{AC_DEFUN}
1975 @acindex AC_DEFUN
1976 @acindex AC_PREREQ
1978 Starting with Automake 1.8, @command{aclocal} will warn about all
1979 underquoted calls to @code{AC_DEFUN}.  We realize this will annoy a
1980 lot of people, because @command{aclocal} was not so strict in the past
1981 and many third party macros are underquoted; and we have to apologize
1982 for this temporary inconvenience.  The reason we have to be stricter
1983 is that a future implementation of @command{aclocal} (@pxref{Future of
1984 aclocal}) will have to temporarily include all these third party
1985 @file{.m4} files, maybe several times, including even files that are
1986 not actually needed.  Doing so should alleviate many problems of the
1987 current implementation, however it requires a stricter style from the
1988 macro authors.  Hopefully it is easy to revise the existing macros.
1989 For instance,
1990 @example
1991 # bad style
1992 AC_PREREQ(2.57)
1993 AC_DEFUN(AX_FOOBAR,
1994 [AC_REQUIRE([AX_SOMETHING])dnl
1995 AX_FOO
1996 AX_BAR
1998 @end example
1999 @noindent
2000 should be rewritten as
2001 @example
2002 AC_DEFUN([AX_FOOBAR],
2003 [AC_PREREQ(2.57)dnl
2004 AC_REQUIRE([AX_SOMETHING])dnl
2005 AX_FOO
2006 AX_BAR
2008 @end example
2010 Wrapping the @code{AC_PREREQ} call inside the macro ensures that
2011 Autoconf 2.57 will not be required if @code{AX_FOOBAR} is not actually
2012 used.  Most importantly, quoting the first argument of @code{AC_DEFUN}
2013 allows the macro to be redefined or included twice (otherwise this
2014 first argument would be expanded during the second definition).
2016 If you have been directed here by the @command{aclocal} diagnostic but
2017 are not the maintainer of the implicated macro, you will want to
2018 contact the maintainer of that macro.  Please make sure you have the
2019 last version of the macro and that the problem already hasn't been
2020 reported before doing so: people tend to work faster when they aren't
2021 flooded by mails.
2023 Another situation where @command{aclocal} is commonly used is to
2024 manage macros that are used locally by the package, @ref{Local
2025 Macros}.
2027 @node Local Macros
2028 @subsection Handling Local Macros
2030 Feature tests offered by Autoconf do not cover all needs.  People
2031 often have to supplement existing tests with their own macros, or
2032 with third-party macros.
2034 There are two ways to organize custom macros in a package.
2036 The first possibility (the historical practice) is to list all your
2037 macros in @file{acinclude.m4}.  This file will be included in
2038 @file{aclocal.m4} when you run @command{aclocal}, and its macro(s) will
2039 henceforth be visible to @command{autoconf}.  However if it contains
2040 numerous macros, it will rapidly become difficult to maintain, and it
2041 will be almost impossible to share macros between packages.
2043 @vindex ACLOCAL_AMFLAGS
2044 The second possibility, which we do recommend, is to write each macro
2045 in its own file and gather all these files in a directory.  This
2046 directory is usually called @file{m4/}.  To build @file{aclocal.m4},
2047 one should therefore instruct @command{aclocal} to scan @file{m4/}.
2048 From the command line, this is done with @samp{aclocal -I m4}.  The
2049 top-level @file{Makefile.am} should also be updated to define
2051 @example
2052 ACLOCAL_AMFLAGS = -I m4
2053 @end example
2055 @code{ACLOCAL_AMFLAGS} contains options to pass to @command{aclocal}
2056 when @file{aclocal.m4} is to be rebuilt by @command{make}.  This line is
2057 also used by @command{autoreconf} (@pxref{autoreconf Invocation, ,
2058 Using @command{autoreconf} to Update @file{configure} Scripts,
2059 autoconf, The Autoconf Manual}) to run @command{aclocal} with suitable
2060 options, or by @command{autopoint} (@pxref{autopoint Invocation, ,
2061 Invoking the @command{autopoint} Program, gettext, GNU gettext tools})
2062 and @command{gettextize} (@pxref{gettextize Invocation, , Invoking the
2063 @command{gettextize} Program, gettext, GNU gettext tools}) to locate
2064 the place where Gettext's macros should be installed.  So even if you
2065 do not really care about the rebuild rules, you should define
2066 @code{ACLOCAL_AMFLAGS}.
2068 When @samp{aclocal -I m4} is run, it will build a @file{aclocal.m4}
2069 that @code{m4_include}s any file from @file{m4/} that defines a
2070 required macro.  Macros not found locally will still be searched in
2071 system-wide directories, as explained in @ref{Macro search path}.
2073 Custom macros should be distributed for the same reason that
2074 @file{configure.ac} is: so that other people have all the sources of
2075 your package if they want to work on it.  Actually, this distribution
2076 happens automatically because all @code{m4_include}d files are
2077 distributed.
2079 However there is no consensus on the distribution of third-party
2080 macros that your package may use.  Many libraries install their own
2081 macro in the system-wide @command{aclocal} directory (@pxref{Extending
2082 aclocal}).  For instance, Guile ships with a file called
2083 @file{guile.m4} that contains the macro @code{GUILE_FLAGS} that can
2084 be used to define setup compiler and linker flags appropriate for
2085 using Guile.  Using @code{GUILE_FLAGS} in @file{configure.ac} will
2086 cause @command{aclocal} to copy @file{guile.m4} into
2087 @file{aclocal.m4}, but as @file{guile.m4} is not part of the project,
2088 it will not be distributed.  Technically, that means a user who
2089 needs to rebuild @file{aclocal.m4} will have to install Guile first.
2090 This is probably OK, if Guile already is a requirement to build the
2091 package.  However, if Guile is only an optional feature, or if your
2092 package might run on architectures where Guile cannot be installed,
2093 this requirement will hinder development.  An easy solution is to copy
2094 such third-party macros in your local @file{m4/} directory so they get
2095 distributed.
2097 Since Automake 1.10, @command{aclocal} offers an option to copy these
2098 system-wide third-party macros in your local macro directory, solving
2099 the above problem.  Simply use:
2101 @example
2102 ACLOCAL_AMFLAGS = -I m4 --install
2103 @end example
2105 @noindent
2106 With this setup, system-wide macros will be copied to @file{m4/}
2107 the first time you run @command{autoreconf}.  Then the locally
2108 installed macros will have precedence over the system-wide installed
2109 macros each time @command{aclocal} is run again.
2111 One reason why you should keep @option{--install} in the flags even
2112 after the first run is that when you later edit @file{configure.ac}
2113 and depend on a new macro, this macro will be installed in your
2114 @file{m4/} automatically.  Another one is that serial numbers
2115 (@pxref{Serials}) can be used to update the macros in your source tree
2116 automatically when new system-wide versions are installed.  A serial
2117 number should be a single line of the form
2119 @example
2120 #serial @var{NNN}
2121 @end example
2123 @noindent
2124 where @var{NNN} contains only digits and dots.  It should appear in
2125 the M4 file before any macro definition.  It is a good practice to
2126 maintain a serial number for each macro you distribute, even if you do
2127 not use the @option{--install} option of @command{aclocal}: this allows
2128 other people to use it.
2131 @node Serials
2132 @subsection Serial Numbers
2133 @cindex serial numbers in macros
2134 @cindex macro serial numbers
2135 @cindex @code{#serial} syntax
2136 @cindex @command{aclocal} and serial numbers
2138 Because third-party macros defined in @file{*.m4} files are naturally
2139 shared between multiple projects, some people like to version them.
2140 This makes it easier to tell which of two M4 files is newer.  Since at
2141 least 1996, the tradition is to use a @samp{#serial} line for this.
2143 A serial number should be a single line of the form
2145 @example
2146 # serial @var{version}
2147 @end example
2149 @noindent
2150 where @var{version} is a version number containing only digits and
2151 dots.  Usually people use a single integer, and they increment it each
2152 time they change the macro (hence the name of ``serial'').  Such a
2153 line should appear in the M4 file before any macro definition.
2155 The @samp{#} must be the first character on the line,
2156 and it is OK to have extra words after the version, as in
2158 @example
2159 #serial @var{version} @var{garbage}
2160 @end example
2162 Normally these serial numbers are completely ignored by
2163 @command{aclocal} and @command{autoconf}, like any genuine comment.
2164 However when using @command{aclocal}'s @option{--install} feature, these
2165 serial numbers will modify the way @command{aclocal} selects the
2166 macros to install in the package: if two files with the same basename
2167 exists in your search path, and if at least one of them use a
2168 @samp{#serial} line, @command{aclocal} will ignore the file that has
2169 the older @samp{#serial} line (or the file that has none).
2171 Note that a serial number applies to a whole M4 file, not to any macro
2172 it contains.  A file can contains multiple macros, but only one
2173 serial.
2175 Here is a use case that illustrate the use of @option{--install} and
2176 its interaction with serial numbers.  Let's assume we maintain a
2177 package called MyPackage, the @file{configure.ac} of which requires a
2178 third-party macro @code{AX_THIRD_PARTY} defined in
2179 @file{/usr/share/aclocal/thirdparty.m4} as follows:
2181 @example
2182 # serial 1
2183 AC_DEFUN([AX_THIRD_PARTY], [...])
2184 @end example
2186 MyPackage uses an @file{m4/} directory to store local macros as
2187 explained in @ref{Local Macros}, and has
2189 @example
2190 ACLOCAL_AMFLAGS = -I m4 --install
2191 @end example
2193 @noindent
2194 in its top-level @file{Makefile.am}.
2196 Initially the @file{m4/} directory is empty.  The first time we run
2197 @command{autoreconf}, it will fetch the options to pass to
2198 @command{aclocal} in @file{Makefile.am}, and run @samp{aclocal -I m4
2199 --install}.  @command{aclocal} will notice that
2201 @itemize @bullet
2202 @item
2203 @file{configure.ac} uses @code{AX_THIRD_PARTY}
2204 @item
2205 No local macros define @code{AX_THIRD_PARTY}
2206 @item
2207 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
2208 with serial 1.
2209 @end itemize
2211 @noindent
2212 Because @file{/usr/share/aclocal/thirdparty.m4} is a system-wide macro
2213 and @command{aclocal} was given the @option{--install} option, it will
2214 copy this file in @file{m4/thirdparty.m4}, and output an
2215 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
2217 The next time @samp{aclocal -I m4 --install} is run (either via
2218 @command{autoreconf}, by hand, or from the @file{Makefile} rebuild
2219 rules) something different happens.  @command{aclocal} notices that
2221 @itemize @bullet
2222 @item
2223 @file{configure.ac} uses @code{AX_THIRD_PARTY}
2224 @item
2225 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
2226 with serial 1.
2227 @item
2228 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
2229 with serial 1.
2230 @end itemize
2232 @noindent
2233 Because both files have the same serial number, @command{aclocal} uses
2234 the first it found in its search path order (@pxref{Macro search
2235 path}).  @command{aclocal} therefore ignores
2236 @file{/usr/share/aclocal/thirdparty.m4} and outputs an
2237 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
2239 Local directories specified with @option{-I} are always searched before
2240 system-wide directories, so a local file will always be preferred to
2241 the system-wide file in case of equal serial numbers.
2243 Now suppose the system-wide third-party macro is changed.  This can
2244 happen if the package installing this macro is updated.  Let's suppose
2245 the new macro has serial number 2.  The next time @samp{aclocal -I m4
2246 --install} is run the situation is the following:
2248 @itemize @bullet
2249 @item
2250 @file{configure.ac} uses @code{AX_THIRD_PARTY}
2251 @item
2252 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
2253 with serial 1.
2254 @item
2255 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
2256 with serial 2.
2257 @end itemize
2259 @noindent
2260 When @command{aclocal} sees a greater serial number, it immediately
2261 forgets anything it knows from files that have the same basename and a
2262 smaller serial number.  So after it has found
2263 @file{/usr/share/aclocal/thirdparty.m4} with serial 2,
2264 @command{aclocal} will proceed as if it had never seen
2265 @file{m4/thirdparty.m4}.  This brings us back to a situation similar
2266 to that at the beginning of our example, where no local file defined
2267 the macro.  @command{aclocal} will install the new version of the
2268 macro in @file{m4/thirdparty.m4}, in this case overriding the old
2269 version.  MyPackage just had its macro updated as a side effect of
2270 running @command{aclocal}.
2272 If you are leery of letting @command{aclocal} update your local macro,
2273 you can run @samp{aclocal -I m4 --diff} to review the changes
2274 @samp{aclocal -I m4 --install} would perform on these macros.
2276 Finally, note that the @option{--force} option of @command{aclocal} has
2277 absolutely no effect on the files installed by @option{--install}.  For
2278 instance, if you have modified your local macros, do not expect
2279 @option{--install --force} to replace the local macros by their
2280 system-wide versions.  If you want to do so, simply erase the local
2281 macros you want to revert, and run @samp{aclocal -I m4 --install}.
2284 @node Future of aclocal
2285 @subsection The Future of @command{aclocal}
2286 @cindex @command{aclocal}'s scheduled death
2288 @command{aclocal} is expected to disappear.  This feature really
2289 should not be offered by Automake.  Automake should focus on
2290 generating @file{Makefile}s; dealing with M4 macros really is
2291 Autoconf's job.  That some people install Automake just to use
2292 @command{aclocal}, but do not use @command{automake} otherwise is an
2293 indication of how that feature is misplaced.
2295 The new implementation will probably be done slightly differently.
2296 For instance, it could enforce the @file{m4/}-style layout discussed in
2297 @ref{Local Macros}.
2299 We have no idea when and how this will happen.  This has been
2300 discussed several times in the past, but someone still has to commit
2301 itself to that non-trivial task.
2303 From the user point of view, @command{aclocal}'s removal might turn
2304 out to be painful.  There is a simple precaution that you may take to
2305 make that switch more seamless: never call @command{aclocal} yourself.
2306 Keep this guy under the exclusive control of @command{autoreconf} and
2307 Automake's rebuild rules.  Hopefully you won't need to worry about
2308 things breaking, when @command{aclocal} disappears, because everything
2309 will have been taken care of.  If otherwise you used to call
2310 @command{aclocal} directly yourself or from some script, you will
2311 quickly notice the change.
2313 Many packages come with a script called @file{bootstrap.sh} or
2314 @file{autogen.sh}, that will just call @command{aclocal},
2315 @command{libtoolize}, @command{gettextize} or @command{autopoint},
2316 @command{autoconf}, @command{autoheader}, and @command{automake} in
2317 the right order.  Actually this is precisely what @command{autoreconf}
2318 can do for you.  If your package has such a @file{bootstrap.sh} or
2319 @file{autogen.sh} script, consider using @command{autoreconf}.  That
2320 should simplify its logic a lot (less things to maintain, yum!), it's
2321 even likely you will not need the script anymore, and more to the point
2322 you will not call @command{aclocal} directly anymore.
2324 For the time being, third-party packages should continue to install
2325 public macros into @file{/usr/share/aclocal/}.  If @command{aclocal}
2326 is replaced by another tool it might make sense to rename the
2327 directory, but supporting @file{/usr/share/aclocal/} for backward
2328 compatibility should be really easy provided all macros are properly
2329 written (@pxref{Extending aclocal}).
2333 @node Macros
2334 @section Autoconf macros supplied with Automake
2336 Automake ships with several Autoconf macros that you can use from your
2337 @file{configure.ac}.  When you use one of them it will be included by
2338 @command{aclocal} in @file{aclocal.m4}.
2340 @menu
2341 * Public macros::               Macros that you can use.
2342 * Obsolete macros::             Macros that you should stop using.
2343 * Private macros::              Macros that you should not use.
2344 @end menu
2346 @c consider generating the following subsections automatically from m4 files.
2348 @node Public macros
2349 @subsection Public macros
2351 @table @code
2352 @item AM_C_PROTOTYPES
2353 @acindex AM_C_PROTOTYPES
2354 @vindex ANSI2KNR
2355 @vindex U
2356 Check to see if function prototypes are understood by the compiler.  If
2357 so, define @samp{PROTOTYPES} and set the output variables @code{U} and
2358 @code{ANSI2KNR} to the empty string.  Otherwise, set @code{U} to
2359 @samp{_} and @code{ANSI2KNR} to @samp{./ansi2knr}.  Automake uses these
2360 values to implement automatic de-ANSI-fication.
2362 @item AM_ENABLE_MULTILIB
2363 @acindex AM_ENABLE_MULTILIB
2364 This is used when a ``multilib'' library is being built.  The first
2365 optional argument is the name of the @file{Makefile} being generated; it
2366 defaults to @samp{Makefile}.  The second option argument is used to find
2367 the top source directory; it defaults to the empty string (generally
2368 this should not be used unless you are familiar with the internals).
2369 @xref{Multilibs}.
2371 @item AM_INIT_AUTOMAKE([OPTIONS])
2372 @itemx AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
2373 @acindex AM_INIT_AUTOMAKE
2374 Runs many macros required for proper operation of the generated Makefiles.
2376 @vindex AUTOMAKE_OPTIONS
2377 This macro has two forms, the first of which is preferred.
2378 In this form, @code{AM_INIT_AUTOMAKE} is called with a
2379 single argument: a space-separated list of Automake options that should
2380 be applied to every @file{Makefile.am} in the tree.  The effect is as if
2381 each option were listed in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
2383 @acindex AC_INIT
2384 The second, deprecated, form of @code{AM_INIT_AUTOMAKE} has two required
2385 arguments: the package and the version number.  This form is
2386 obsolete because the @var{package} and @var{version} can be obtained
2387 from Autoconf's @code{AC_INIT} macro (which itself has an old and a new
2388 form).
2390 If your @file{configure.ac} has:
2392 @example
2393 AC_INIT(src/foo.c)
2394 AM_INIT_AUTOMAKE(mumble, 1.5)
2395 @end example
2397 @noindent
2398 you can modernize it as follows:
2400 @example
2401 AC_INIT(mumble, 1.5)
2402 AC_CONFIG_SRCDIR(src/foo.c)
2403 AM_INIT_AUTOMAKE
2404 @end example
2406 Note that if you're upgrading your @file{configure.ac} from an earlier
2407 version of Automake, it is not always correct to simply move the
2408 package and version arguments from @code{AM_INIT_AUTOMAKE} directly to
2409 @code{AC_INIT}, as in the example above.  The first argument to
2410 @code{AC_INIT} should be the name of your package (e.g., @samp{GNU
2411 Automake}), not the tarball name (e.g., @samp{automake}) that you used
2412 to pass to @code{AM_INIT_AUTOMAKE}.  Autoconf tries to derive a
2413 tarball name from the package name, which should work for most but not
2414 all package names.  (If it doesn't work for yours, you can use the
2415 four-argument form of @code{AC_INIT} to provide the tarball name
2416 explicitly).
2418 @cindex @code{PACKAGE}, prevent definition
2419 @cindex @code{VERSION}, prevent definition
2420 @opindex no-define
2421 By default this macro @code{AC_DEFINE}'s @code{PACKAGE} and
2422 @code{VERSION}.  This can be avoided by passing the @option{no-define}
2423 option, as in:
2424 @example
2425 AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
2426 @end example
2427 or by passing a third non-empty argument to the obsolete form.
2429 @item AM_PATH_LISPDIR
2430 @acindex AM_PATH_LISPDIR
2431 @vindex EMACS
2432 @vindex lispdir
2433 Searches for the program @command{emacs}, and, if found, sets the
2434 output variable @code{lispdir} to the full path to Emacs' site-lisp
2435 directory.
2437 Note that this test assumes the @command{emacs} found to be a version
2438 that supports Emacs Lisp (such as @sc{gnu} Emacs or XEmacs).  Other
2439 emacsen can cause this test to hang (some, like old versions of
2440 MicroEmacs, start up in interactive mode, requiring @kbd{C-x C-c} to
2441 exit, which is hardly obvious for a non-emacs user).  In most cases,
2442 however, you should be able to use @kbd{C-c} to kill the test.  In
2443 order to avoid problems, you can set @env{EMACS} to ``no'' in the
2444 environment, or use the @option{--with-lispdir} option to
2445 @command{configure} to explicitly set the correct path (if you're sure
2446 you have an @command{emacs} that supports Emacs Lisp.
2448 @item AM_PROG_AS
2449 @acindex AM_PROG_AS
2450 @vindex CCAS
2451 @vindex CCASFLAGS
2452 Use this macro when you have assembly code in your project.  This will
2453 choose the assembler for you (by default the C compiler) and set
2454 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
2456 @item AM_PROG_CC_C_O
2457 @acindex AM_PROG_CC_C_O
2458 @acindex AC_PROG_CC_C_O
2459 This is like @code{AC_PROG_CC_C_O}, but it generates its results in
2460 the manner required by automake.  You must use this instead of
2461 @code{AC_PROG_CC_C_O} when you need this functionality, that is, when
2462 using per-target flags or subdir-objects with C sources.
2464 @item AM_PROG_LEX
2465 @acindex AM_PROG_LEX
2466 @acindex AC_PROG_LEX
2467 @cindex HP-UX 10, @command{lex} problems
2468 @cindex @command{lex} problems with HP-UX 10
2469 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
2470 Program Checks, autoconf, The Autoconf Manual}), but uses the
2471 @command{missing} script on systems that do not have @command{lex}.
2472 HP-UX 10 is one such system.
2474 @item AM_PROG_GCJ
2475 @acindex AM_PROG_GCJ
2476 @vindex GCJ
2477 @vindex GCJFLAGS
2478 This macro finds the @command{gcj} program or causes an error.  It sets
2479 @code{GCJ} and @code{GCJFLAGS}.  @command{gcj} is the Java front-end to the
2480 GNU Compiler Collection.
2482 @item AM_WITH_DMALLOC
2483 @acindex AM_WITH_DMALLOC
2484 @cindex @command{dmalloc}, support for
2485 @vindex WITH_DMALLOC
2486 @opindex --with-dmalloc
2487 Add support for the @uref{http://dmalloc.com/, Dmalloc package}.
2488 If the user configures with @option{--with-dmalloc}, then define
2489 @code{WITH_DMALLOC} and add @option{-ldmalloc} to @code{LIBS}.
2491 @item AM_WITH_REGEX
2492 @acindex AM_WITH_REGEX
2493 @vindex WITH_REGEX
2494 @opindex --with-regex
2495 @cindex regex package
2496 @cindex rx package
2497 Adds @option{--with-regex} to the @command{configure} command line.  If
2498 specified (the default), then the @samp{regex} regular expression
2499 library is used, @file{regex.o} is put into @code{LIBOBJS}, and
2500 @code{WITH_REGEX} is defined.  If @option{--without-regex} is given, then
2501 the @code{rx} regular expression library is used, and @file{rx.o} is put
2502 into @code{LIBOBJS}.
2504 @end table
2507 @node Obsolete macros
2508 @subsection Obsolete macros
2509 @cindex obsolete macros
2510 @cindex autoupdate
2512 Although using some of the following macros was required in past
2513 releases, you should not used any of them in new code.  Running
2514 @command{autoupdate} should adjust your @file{configure.ac}
2515 automatically (@pxref{autoupdate Invocation, , Using
2516 @command{autoupdate} to Modernize @file{configure.ac}, autoconf, The
2517 Autoconf Manual}).
2519 @table @code
2520 @item AM_CONFIG_HEADER
2521 @acindex AM_CONFIG_HEADER
2522 Automake will generate rules to automatically regenerate the config
2523 header.  This obsolete macro is a synonym of @code{AC_CONFIG_HEADERS}
2524 today (@pxref{Optional}).
2526 @item AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
2527 @acindex AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
2528 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
2529 define @code{GWINSZ_IN_SYS_IOCTL}.  Otherwise @code{TIOCGWINSZ} can be
2530 found in @file{<termios.h>}.  This macro is obsolete, you should
2531 use Autoconf's @code{AC_HEADER_TIOCGWINSZ} instead.
2533 @item AM_SYS_POSIX_TERMIOS
2534 @acindex AM_SYS_POSIX_TERMIOS
2535 @cindex POSIX termios headers
2536 @cindex termios POSIX headers
2537 Check to see if POSIX termios headers and functions are available on the
2538 system.  If so, set the shell variable @code{am_cv_sys_posix_termios} to
2539 @samp{yes}.  If not, set the variable to @samp{no}.  This macro is obsolete,
2540 you should use Autoconf's @code{AC_SYS_POSIX_TERMIOS} instead.
2542 @end table
2545 @node Private macros
2546 @subsection Private macros
2548 The following macros are private macros you should not call directly.
2549 They are called by the other public macros when appropriate.  Do not
2550 rely on them, as they might be changed in a future version.  Consider
2551 them as implementation details; or better, do not consider them at all:
2552 skip this section!
2554 @ftable @code
2555 @item _AM_DEPENDENCIES
2556 @itemx AM_SET_DEPDIR
2557 @itemx AM_DEP_TRACK
2558 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
2559 These macros are used to implement Automake's automatic dependency
2560 tracking scheme.  They are called automatically by automake when
2561 required, and there should be no need to invoke them manually.
2563 @item AM_MAKE_INCLUDE
2564 This macro is used to discover how the user's @command{make} handles
2565 @code{include} statements.  This macro is automatically invoked when
2566 needed; there should be no need to invoke it manually.
2568 @item AM_PROG_INSTALL_STRIP
2569 This is used to find a version of @code{install} that can be used to
2570 strip a program at installation time.  This macro is automatically
2571 included when required.
2573 @item AM_SANITY_CHECK
2574 This checks to make sure that a file created in the build directory is
2575 newer than a file in the source directory.  This can fail on systems
2576 where the clock is set incorrectly.  This macro is automatically run
2577 from @code{AM_INIT_AUTOMAKE}.
2579 @end ftable
2582 @node Directories
2583 @chapter Directories
2585 For simple projects that distributes all files in the same directory
2586 it is enough to have a single @file{Makefile.am} that builds
2587 everything in place.
2589 In larger projects it is common to organize files in different
2590 directories, in a tree.  For instance one directory per program, per
2591 library or per module.  The traditional approach is to build these
2592 subdirectory recursively: each directory contains its @file{Makefile}
2593 (generated from @file{Makefile.am}), and when @command{make} is run
2594 from the top level directory it enters each subdirectory in turn to
2595 build its contents.
2597 @menu
2598 * Subdirectories::              Building subdirectories recursively
2599 * Conditional Subdirectories::  Conditionally not building directories
2600 * Alternative::                 Subdirectories without recursion
2601 * Subpackages::                 Nesting packages
2602 @end menu
2604 @node Subdirectories
2605 @section Recursing subdirectories
2607 @cindex @code{SUBDIRS}, explained
2609 In packages with subdirectories, the top level @file{Makefile.am} must
2610 tell Automake which subdirectories are to be built.  This is done via
2611 the @code{SUBDIRS} variable.
2612 @vindex SUBDIRS
2614 The @code{SUBDIRS} variable holds a list of subdirectories in which
2615 building of various sorts can occur.  The rules for many targets
2616 (e.g., @code{all}) in the generated @file{Makefile} will run commands
2617 both locally and in all specified subdirectories.  Note that the
2618 directories listed in @code{SUBDIRS} are not required to contain
2619 @file{Makefile.am}s; only @file{Makefile}s (after configuration).
2620 This allows inclusion of libraries from packages that do not use
2621 Automake (such as @code{gettext}; see also @ref{Third-Party
2622 Makefiles}).
2624 In packages that use subdirectories, the top-level @file{Makefile.am} is
2625 often very short.  For instance, here is the @file{Makefile.am} from the
2626 GNU Hello distribution:
2628 @example
2629 EXTRA_DIST = BUGS ChangeLog.O README-alpha
2630 SUBDIRS = doc intl po src tests
2631 @end example
2633 When Automake invokes @command{make} in a subdirectory, it uses the value
2634 of the @code{MAKE} variable.  It passes the value of the variable
2635 @code{AM_MAKEFLAGS} to the @command{make} invocation; this can be set in
2636 @file{Makefile.am} if there are flags you must always pass to
2637 @command{make}.
2638 @vindex MAKE
2639 @vindex AM_MAKEFLAGS
2641 The directories mentioned in @code{SUBDIRS} are usually direct
2642 children of the current directory, each subdirectory containing its
2643 own @file{Makefile.am} with a @code{SUBDIRS} pointing to deeper
2644 subdirectories.  Automake can be used to construct packages of
2645 arbitrary depth this way.
2647 By default, Automake generates @file{Makefiles} that work depth-first
2648 in postfix order: the subdirectories are built before the current
2649 directory.  However, it is possible to change this ordering.  You can
2650 do this by putting @samp{.} into @code{SUBDIRS}.  For instance,
2651 putting @samp{.} first will cause a prefix ordering of
2652 directories.
2654 Using
2656 @example
2657 SUBDIRS = lib src . test
2658 @end example
2660 @noindent
2661 will cause @file{lib/} to be built before @file{src/}, then the
2662 current directory will be built, finally the @file{test/} directory
2663 will be built.  It is customary to arrange test directories to be
2664 built after everything else since they are meant to test what has
2665 been constructed.
2667 All @code{clean} rules are run in reverse order of build rules.
2669 @node Conditional Subdirectories
2670 @section Conditional Subdirectories
2671 @cindex Subdirectories, building conditionally
2672 @cindex Conditional subdirectories
2673 @cindex @code{SUBDIRS}, conditional
2674 @cindex Conditional @code{SUBDIRS}
2676 It is possible to define the @code{SUBDIRS} variable conditionally if,
2677 like in the case of GNU Inetutils, you want to only build a subset of
2678 the entire package.
2680 To illustrate how this works, let's assume we have two directories
2681 @file{src/} and @file{opt/}.  @file{src/} should always be built, but we
2682 want to decide in @command{configure} whether @file{opt/} will be built
2683 or not.  (For this example we will assume that @file{opt/} should be
2684 built when the variable @samp{$want_opt} was set to @samp{yes}.)
2686 Running @command{make} should thus recurse into @file{src/} always, and
2687 then maybe in @file{opt/}.
2689 However @samp{make dist} should always recurse into both @file{src/}
2690 and @file{opt/}.  Because @file{opt/} should be distributed even if it
2691 is not needed in the current configuration.  This means
2692 @file{opt/Makefile} should be created @emph{unconditionally}.
2694 There are two ways to setup a project like this.  You can use Automake
2695 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
2696 variables (@pxref{Setting Output Variables, , Setting Output
2697 Variables, autoconf, The Autoconf Manual}).  Using Automake
2698 conditionals is the preferred solution.  Before we illustrate these
2699 two possibility, let's introduce @code{DIST_SUBDIRS}.
2701 @subsection @code{SUBDIRS} vs.@: @code{DIST_SUBDIRS}
2702 @cindex @code{DIST_SUBDIRS}, explained
2704 Automake considers two sets of directories, defined by the variables
2705 @code{SUBDIRS} and @code{DIST_SUBDIRS}.
2707 @code{SUBDIRS} contains the subdirectories of the current directory
2708 that must be built (@pxref{Subdirectories}).  It must be defined
2709 manually; Automake will never guess a directory is to be built.  As we
2710 will see in the next two sections, it is possible to define it
2711 conditionally so that some directory will be omitted from the build.
2713 @code{DIST_SUBDIRS} is used in rules that need to recurse in all
2714 directories, even those that have been conditionally left out of the
2715 build.  Recall our example where we may not want to build subdirectory
2716 @file{opt/}, but yet we want to distribute it?  This is where
2717 @code{DIST_SUBDIRS} come into play: @samp{opt} may not appear in
2718 @code{SUBDIRS}, but it must appear in @code{DIST_SUBDIRS}.
2720 Precisely, @code{DIST_SUBDIRS} is used by @samp{make
2721 maintainer-clean}, @samp{make distclean} and @samp{make dist}.  All
2722 other recursive rules use @code{SUBDIRS}.
2724 If @code{SUBDIRS} is defined conditionally using Automake
2725 conditionals, Automake will define @code{DIST_SUBDIRS} automatically
2726 from the possibles values of @code{SUBDIRS} in all conditions.
2728 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
2729 @code{DIST_SUBDIRS} will not be defined correctly because Automake
2730 does not know the possible values of these variables.  In this case
2731 @code{DIST_SUBDIRS} needs to be defined manually.
2733 @subsection Conditional subdirectories with @code{AM_CONDITIONAL}
2734 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
2735 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
2737 @c The test case for the setup described here is
2738 @c     test/subdircond2.test
2739 @c Try to keep it in sync.
2741 @file{configure} should output the @file{Makefile} for each directory
2742 and define a condition into which @file{opt/} should be built.
2744 @example
2745 @dots{}
2746 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
2747 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
2748 @dots{}
2749 @end example
2751 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
2752 as follows.
2754 @example
2755 if COND_OPT
2756   MAYBE_OPT = opt
2757 endif
2758 SUBDIRS = src $(MAYBE_OPT)
2759 @end example
2761 As you can see, running @command{make} will rightly recurse into
2762 @file{src/} and maybe @file{opt/}.
2764 @vindex DIST_SUBDIRS
2765 As you can't see, running @samp{make dist} will recurse into both
2766 @file{src/} and @file{opt/} directories because @samp{make dist}, unlike
2767 @samp{make all}, doesn't use the @code{SUBDIRS} variable.  It uses the
2768 @code{DIST_SUBDIRS} variable.
2770 In this case Automake will define @samp{DIST_SUBDIRS = src opt}
2771 automatically because it knows that @code{MAYBE_OPT} can contain
2772 @samp{opt} in some condition.
2774 @subsection Conditional Subdirectories with @code{AC_SUBST}
2775 @cindex @code{SUBDIRS} and @code{AC_SUBST}
2776 @cindex @code{AC_SUBST} and @code{SUBDIRS}
2778 @c The test case for the setup described here is
2779 @c     test/subdircond3.test
2780 @c Try to keep it in sync.
2782 Another possibility is to define @code{MAYBE_OPT} from
2783 @file{./configure} using @code{AC_SUBST}:
2785 @example
2786 @dots{}
2787 if test "$want_opt" = yes; then
2788   MAYBE_OPT=opt
2789 else
2790   MAYBE_OPT=
2792 AC_SUBST([MAYBE_OPT])
2793 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
2794 @dots{}
2795 @end example
2797 In this case the top-level @file{Makefile.am} should look as follows.
2799 @example
2800 SUBDIRS = src $(MAYBE_OPT)
2801 DIST_SUBDIRS = src opt
2802 @end example
2804 The drawback is that since Automake cannot guess what the possible
2805 values of @code{MAYBE_OPT} are, it is necessary to define
2806 @code{DIST_SUBDIRS}.
2808 @subsection Non-configured Subdirectories
2809 @cindex Subdirectories, configured conditionally
2811 The semantic of @code{DIST_SUBDIRS} is often misunderstood by some
2812 users that try to @emph{configure and build} subdirectories
2813 conditionally.  Here by configuring we mean creating the
2814 @file{Makefile} (it might also involve running a nested
2815 @command{configure} script: this is a costly operation that explains
2816 why people want to do it conditionally, but only the @file{Makefile}
2817 is relevant to the discussion).
2819 The above examples all assume that every @file{Makefile} is created,
2820 even in directories that are not going to be built.  The simple reason
2821 is that we want @samp{make dist} to distribute even the directories
2822 that are not being built (e.g., platform-dependent code), hence
2823 @file{make dist} must recurse into the subdirectory, hence this
2824 directory must be configured and appear in @code{DIST_SUBDIRS}.
2826 Building packages that do not configure every subdirectory is a tricky
2827 business, and we do not recommend it to the novice as it is easy to
2828 produce an incomplete tarball by mistake.  We will not discuss this
2829 topic in depth here, yet for the adventurous here are a few rules to
2830 remember.
2832 @cartouche
2833 @itemize
2834 @item @code{SUBDIRS} should always be a subset of @code{DIST_SUBDIRS}.
2836 It makes little sense to have a directory in @code{SUBDIRS} that
2837 is not in @code{DIST_SUBDIRS}.  Think of the former as a way to tell
2838 which directories listed in the latter should be built.
2839 @item Any directory listed in @code{DIST_SUBDIRS} and @code{SUBDIRS}
2840 must be configured.
2842 I.e., the @file{Makefile} must exists or the recursive @command{make}
2843 rules will not be able to process the directory.
2844 @item Any configured directory must be listed in @code{DIST_SUBDIRS}.
2846 So that the cleaning rule remove the generated @file{Makefile}s.
2847 It would be correct to see @code{DIST_SUBDIRS} as a variable that
2848 lists all the directories that have been configured.
2849 @end itemize
2850 @end cartouche
2852 In order to prevent recursion in some non-configured directory you
2853 must therefore ensure that this directory does not appear in
2854 @code{DIST_SUBDIRS} (and @code{SUBDIRS}).  For instance, if you define
2855 @code{SUBDIRS} conditionally using @code{AC_SUBST} and do not define
2856 @code{DIST_SUBDIRS} explicitly, it will be default to
2857 @samp{$(SUBDIRS)}; another possibility is to force @code{DIST_SUBDIRS
2858 = $(SUBDIRS)}.
2860 Of course, directories that are omitted from @code{DIST_SUBDIRS} will
2861 not be distributed unless you make other arrangements for this to
2862 happen (for instance, always running @samp{make dist} in a
2863 configuration where all directories are known to appear in
2864 @code{DIST_SUBDIRS}; or writing a @code{dist-hook} target to
2865 distribute these directories).
2867 @cindex Subdirectories, not distributed
2868 In few packages, non-configured directories are not even expected to
2869 be distributed.  Although these packages do not require the
2870 aforementioned extra arrangements, there is another pitfall.  If the
2871 name of a directory appears in @code{SUBDIRS} or @code{DIST_SUBDIRS},
2872 @command{automake} will make sure the directory exists.  Consequently
2873 @command{automake} cannot be run on such a distribution when one
2874 directory has been omitted.  One way to avoid this check is to use the
2875 @code{AC_SUBST} method to declare conditional directories; since
2876 @command{automake} does not know the values of @code{AC_SUBST}
2877 variables it cannot ensure the corresponding directory exist.
2879 @node Alternative
2880 @section An Alternative Approach to Subdirectories
2882 If you've ever read Peter Miller's excellent paper,
2883 @uref{http://www.pcug.org.au/~millerp/rmch/recu-make-cons-harm.html,
2884 Recursive Make Considered Harmful}, the preceding sections on the use of
2885 subdirectories will probably come as unwelcome advice.  For those who
2886 haven't read the paper, Miller's main thesis is that recursive
2887 @command{make} invocations are both slow and error-prone.
2889 Automake provides sufficient cross-directory support @footnote{We
2890 believe.  This work is new and there are probably warts.
2891 @xref{Introduction}, for information on reporting bugs.} to enable you
2892 to write a single @file{Makefile.am} for a complex multi-directory
2893 package.
2896 By default an installable file specified in a subdirectory will have its
2897 directory name stripped before installation.  For instance, in this
2898 example, the header file will be installed as
2899 @file{$(includedir)/stdio.h}:
2901 @example
2902 include_HEADERS = inc/stdio.h
2903 @end example
2905 @vindex nobase_
2906 @cindex @code{nobase_} prefix
2907 @cindex Path stripping, avoiding
2908 @cindex Avoiding path stripping
2910 However, the @samp{nobase_} prefix can be used to circumvent this path
2911 stripping.  In this example, the header file will be installed as
2912 @file{$(includedir)/sys/types.h}:
2914 @example
2915 nobase_include_HEADERS = sys/types.h
2916 @end example
2918 @cindex @code{nobase_} and @code{dist_} or @code{nodist_}
2919 @cindex @code{dist_} and @code{nobase_}
2920 @cindex @code{nodist_} and @code{nobase_}
2921 @vindex dist_
2922 @vindex nodist_
2924 @samp{nobase_} should be specified first when used in conjunction with
2925 either @samp{dist_} or @samp{nodist_} (@pxref{Dist}).  For instance:
2927 @example
2928 nobase_dist_pkgdata_DATA = images/vortex.pgm sounds/whirl.ogg
2929 @end example
2931 Finally, note that a variable using the @samp{nobase_} prefix can
2932 always be replaced by several variables, one for each destination
2933 directory (@pxref{Uniform}).  For instance, the last example could be
2934 rewritten as follows:
2936 @example
2937 imagesdir = $(pkgdatadir)/images
2938 soundsdir = $(pkgdatadir)/sounds
2939 dist_images_DATA = images/vortex.pgm
2940 dist_sounds_DATA = sounds/whirl.ogg
2941 @end example
2943 @noindent
2944 This latter syntax makes it possible to change one destination
2945 directory without changing the layout of the source tree.
2947 @node Subpackages
2948 @section Nesting Packages
2949 @cindex Nesting packages
2950 @cindex Subpackages
2951 @acindex AC_CONFIG_SUBDIRS
2952 @acindex AC_CONFIG_AUX_DIR
2955 In the GNU Build System, packages can be nested to arbitrary depth.
2956 This means that a package can embedded other packages with their own
2957 @file{configure}, @file{Makefile}s, etc.
2959 These other packages should just appear as subdirectories of their
2960 parent package.  They must be listed in @code{SUBDIRS} like other
2961 ordinary directories.  However the subpackage's @file{Makefile}s
2962 should be output by its own @file{configure} script, not by the
2963 parent's @file{configure}.  This is achieved using the
2964 @code{AC_CONFIG_SUBDIRS} Autoconf macro (@pxref{Subdirectories,
2965 AC_CONFIG_SUBDIRS, Configuring Other Packages in Subdirectories,
2966 autoconf, The Autoconf Manual}).
2968 Here is an example package for an @code{arm} program that links with
2969 an @code{hand} library that is a nested package in subdirectory
2970 @file{hand/}.
2972 @code{arm}'s @file{configure.ac}:
2974 @example
2975 AC_INIT([arm], [1.0])
2976 AC_CONFIG_AUX_DIR([.])
2977 AM_INIT_AUTOMAKE
2978 AC_PROG_CC
2979 AC_CONFIG_FILES([Makefile])
2980 # Call hand's ./configure script recursively.
2981 AC_CONFIG_SUBDIRS([hand])
2982 AC_OUTPUT
2983 @end example
2985 @code{arm}'s @file{Makefile.am}:
2987 @example
2988 # Build the library in the hand subdirectory first.
2989 SUBDIRS = hand
2991 # Include hand's header when compiling this directory.
2992 AM_CPPFLAGS = -I$(srcdir)/hand
2994 bin_PROGRAMS = arm
2995 arm_SOURCES = arm.c
2996 # link with the hand library.
2997 arm_LDADD = hand/libhand.a
2998 @end example
3000 Now here is @code{hand}'s @file{hand/configure.ac}:
3002 @example
3003 AC_INIT([hand], [1.2])
3004 AC_CONFIG_AUX_DIR([.])
3005 AM_INIT_AUTOMAKE
3006 AC_PROG_CC
3007 AC_PROG_RANLIB
3008 AC_CONFIG_FILES([Makefile])
3009 AC_OUTPUT
3010 @end example
3012 @noindent
3013 and its @file{hand/Makefile.am}:
3015 @example
3016 lib_LIBRARIES = libhand.a
3017 libhand_a_SOURCES = hand.c
3018 @end example
3020 When @samp{make dist} is run from the top-level directory it will
3021 create an archive @file{arm-1.0.tar.gz} that contains the @code{arm}
3022 code as well as the @file{hand} subdirectory.  This package can be
3023 built and installed like any ordinary package, with the usual
3024 @samp{./configure && make && make install} sequence (the @code{hand}
3025 subpackage will be built and installed by the process).
3027 When @samp{make dist} is run from the hand directory, it will create a
3028 self-contained @file{hand-1.2.tar.gz} archive.  So although it appears
3029 to be embedded in another package, it can still be used separately.
3031 The purpose of the @samp{AC_CONFIG_AUX_DIR([.])} instruction is to
3032 force Automake and Autoconf into search auxiliary script in the
3033 current directory.  For instance, this means that there will be two
3034 copies of @file{install-sh}: one in the top-level of the @code{arm}
3035 package, and another one in the @file{hand/} subdirectory for the
3036 @code{hand} package.
3038 The historical default is to search these auxiliary scripts in the
3039 immediate parent and grand-parent directories.  So if the
3040 @samp{AC_CONFIG_AUX_DIR([.])} line was removed from
3041 @file{hand/configure.ac}, that subpackage would share the auxiliary
3042 script of the @code{arm} package.  This may looks like a gain in size
3043 (a few kilobytes), but it is actually a loss of modularity as the
3044 @code{hand} subpackage is no longer self-contained (@samp{make dist}
3045 in the subdirectory will not work anymore).
3047 Packages that do not use Automake need more work to be integrated this
3048 way.  @xref{Third-Party Makefiles}.
3050 @node Programs
3051 @chapter Building Programs and Libraries
3053 A large part of Automake's functionality is dedicated to making it easy
3054 to build programs and libraries.
3056 @menu
3057 * A Program::                   Building a program
3058 * A Library::                   Building a library
3059 * A Shared Library::            Building a Libtool library
3060 * Program and Library Variables::  Variables controlling program and
3061                                 library builds
3062 * Default _SOURCES::            Default source files
3063 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
3064 * Program variables::           Variables used when building a program
3065 * Yacc and Lex::                Yacc and Lex support
3066 * C++ Support::                 Compiling C++ sources
3067 * Assembly Support::            Compiling assembly sources
3068 * Fortran 77 Support::          Compiling Fortran 77 sources
3069 * Fortran 9x Support::          Compiling Fortran 9x sources
3070 * Java Support::                Compiling Java sources
3071 * Support for Other Languages::  Compiling other languages
3072 * ANSI::                        Automatic de-ANSI-fication
3073 * Dependencies::                Automatic dependency tracking
3074 * EXEEXT::                      Support for executable extensions
3075 @end menu
3078 @node A Program
3079 @section Building a program
3081 In order to build a program, you need to tell Automake which sources
3082 are part of it, and which libraries it should be linked with.
3084 This section also covers conditional compilation of sources or
3085 programs.  Most of the comments about these also apply to libraries
3086 (@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
3088 @menu
3089 * Program Sources::             Defining program sources
3090 * Linking::                     Linking with libraries or extra objects
3091 * Conditional Sources::         Handling conditional sources
3092 * Conditional Programs::        Building program conditionally
3093 @end menu
3095 @node Program Sources
3096 @subsection Defining program sources
3098 @cindex @code{PROGRAMS}, @code{bindir}
3099 @vindex _PROGRAMS
3100 @vindex bin_PROGRAMS
3101 @vindex sbin_PROGRAMS
3102 @vindex libexec_PROGRAMS
3103 @vindex pkglib_PROGRAMS
3104 @vindex noinst_PROGRAMS
3105 @vindex check_PROGRAMS
3107 In a directory containing source that gets built into a program (as
3108 opposed to a library or a script), the @code{PROGRAMS} primary is used.
3109 Programs can be installed in @code{bindir}, @code{sbindir},
3110 @code{libexecdir}, @code{pkglibdir}, or not at all (@code{noinst_}).
3111 They can also be built only for @samp{make check}, in which case the
3112 prefix is @samp{check_}.
3114 For instance:
3116 @example
3117 bin_PROGRAMS = hello
3118 @end example
3120 In this simple case, the resulting @file{Makefile.in} will contain code
3121 to generate a program named @code{hello}.
3123 Associated with each program are several assisting variables that are
3124 named after the program.  These variables are all optional, and have
3125 reasonable defaults.  Each variable, its use, and default is spelled out
3126 below; we use the ``hello'' example throughout.
3128 The variable @code{hello_SOURCES} is used to specify which source files
3129 get built into an executable:
3131 @example
3132 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
3133 @end example
3135 This causes each mentioned @file{.c} file to be compiled into the
3136 corresponding @file{.o}.  Then all are linked to produce @file{hello}.
3138 @cindex @code{_SOURCES} primary, defined
3139 @cindex @code{SOURCES} primary, defined
3140 @cindex Primary variable, @code{SOURCES}
3141 @vindex _SOURCES
3143 If @code{hello_SOURCES} is not specified, then it defaults to the single
3144 file @file{hello.c} (@pxref{Default _SOURCES}).
3145 @vindex _SOURCES
3146 @vindex SOURCES
3148 Multiple programs can be built in a single directory.  Multiple programs
3149 can share a single source file, which must be listed in each
3150 @code{_SOURCES} definition.
3152 @cindex Header files in @code{_SOURCES}
3153 @cindex @code{_SOURCES} and header files
3155 Header files listed in a @code{_SOURCES} definition will be included in
3156 the distribution but otherwise ignored.  In case it isn't obvious, you
3157 should not include the header file generated by @file{configure} in a
3158 @code{_SOURCES} variable; this file should not be distributed.  Lex
3159 (@file{.l}) and Yacc (@file{.y}) files can also be listed; see @ref{Yacc
3160 and Lex}.
3163 @node Linking
3164 @subsection Linking the program
3166 If you need to link against libraries that are not found by
3167 @command{configure}, you can use @code{LDADD} to do so.  This variable is
3168 used to specify additional objects or libraries to link with; it is
3169 inappropriate for specifying specific linker flags, you should use
3170 @code{AM_LDFLAGS} for this purpose.
3171 @vindex LDADD
3172 @vindex AM_LDFLAGS
3174 @cindex @code{prog_LDADD}, defined
3176 Sometimes, multiple programs are built in one directory but do not share
3177 the same link-time requirements.  In this case, you can use the
3178 @code{@var{prog}_LDADD} variable (where @var{prog} is the name of the
3179 program as it appears in some @code{_PROGRAMS} variable, and usually
3180 written in lowercase) to override the global @code{LDADD}.  If this
3181 variable exists for a given program, then that program is not linked
3182 using @code{LDADD}.
3183 @vindex maude_LDADD
3185 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
3186 linked against the library @file{libcpio.a}.  However, @code{rmt} is
3187 built in the same directory, and has no such link requirement.  Also,
3188 @code{mt} and @code{rmt} are only built on certain architectures.  Here
3189 is what cpio's @file{src/Makefile.am} looks like (abridged):
3191 @example
3192 bin_PROGRAMS = cpio pax $(MT)
3193 libexec_PROGRAMS = $(RMT)
3194 EXTRA_PROGRAMS = mt rmt
3196 LDADD = ../lib/libcpio.a $(INTLLIBS)
3197 rmt_LDADD =
3199 cpio_SOURCES = @dots{}
3200 pax_SOURCES = @dots{}
3201 mt_SOURCES = @dots{}
3202 rmt_SOURCES = @dots{}
3203 @end example
3205 @cindex @code{_LDFLAGS}, defined
3206 @vindex maude_LDFLAGS
3207 @code{@var{prog}_LDADD} is inappropriate for passing program-specific
3208 linker flags (except for @option{-l}, @option{-L}, @option{-dlopen} and
3209 @option{-dlpreopen}).  So, use the @code{@var{prog}_LDFLAGS} variable for
3210 this purpose.
3212 @cindex @code{_DEPENDENCIES}, defined
3213 @vindex maude_DEPENDENCIES
3214 It is also occasionally useful to have a program depend on some other
3215 target that is not actually part of that program.  This can be done
3216 using the @code{@var{prog}_DEPENDENCIES} variable.  Each program depends
3217 on the contents of such a variable, but no further interpretation is
3218 done.
3220 If @code{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
3221 Automake.  The automatically-assigned value is the contents of
3222 @code{@var{prog}_LDADD}, with most configure substitutions, @option{-l},
3223 @option{-L}, @option{-dlopen} and @option{-dlpreopen} options removed.  The
3224 configure substitutions that are left in are only @samp{$(LIBOBJS)} and
3225 @samp{$(ALLOCA)}; these are left because it is known that they will not
3226 cause an invalid value for @code{@var{prog}_DEPENDENCIES} to be
3227 generated.
3230 @node Conditional Sources
3231 @subsection Conditional compilation of sources
3233 You can't put a configure substitution (e.g., @samp{@@FOO@@} or
3234 @samp{$(FOO)} where @code{FOO} is defined via @code{AC_SUBST}) into a
3235 @code{_SOURCES} variable.  The reason for this is a bit hard to
3236 explain, but suffice to say that it simply won't work.  Automake will
3237 give an error if you try to do this.
3239 Fortunately there are two other ways to achieve the same result.  One is
3240 to use configure substitutions in @code{_LDADD} variables, the other is
3241 to use an Automake conditional.
3243 @subsubsection Conditional compilation using @code{_LDADD} substitutions
3245 @cindex @code{EXTRA_prog_SOURCES}, defined
3247 Automake must know all the source files that could possibly go into a
3248 program, even if not all the files are built in every circumstance.  Any
3249 files that are only conditionally built should be listed in the
3250 appropriate @code{EXTRA_} variable.  For instance, if
3251 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
3252 in @code{hello}, the @file{Makefile.am} would contain:
3254 @example
3255 bin_PROGRAMS = hello
3256 hello_SOURCES = hello-common.c
3257 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
3258 hello_LDADD = $(HELLO_SYSTEM)
3259 hello_DEPENDENCIES = $(HELLO_SYSTEM)
3260 @end example
3262 @noindent
3263 You can then setup the @samp{$(HELLO_SYSTEM)} substitution from
3264 @file{configure.ac}:
3266 @example
3267 @dots{}
3268 case $host in
3269   *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
3270   *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
3271 esac
3272 AC_SUBST([HELLO_SYSTEM])
3273 @dots{}
3274 @end example
3276 In this case, the variable @code{HELLO_SYSTEM} should be replaced by
3277 either @file{hello-linux.o} or @file{hello-generic.o}, and added to
3278 both @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be
3279 built and linked in.
3281 @subsubsection Conditional compilation using Automake conditionals
3283 An often simpler way to compile source files conditionally is to use
3284 Automake conditionals.  For instance, you could use this
3285 @file{Makefile.am} construct to build the same @file{hello} example:
3287 @example
3288 bin_PROGRAMS = hello
3289 if LINUX
3290 hello_SOURCES = hello-linux.c hello-common.c
3291 else
3292 hello_SOURCES = hello-generic.c hello-common.c
3293 endif
3294 @end example
3296 In this case, @file{configure.ac} should setup the @code{LINUX}
3297 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
3299 When using conditionals like this you don't need to use the
3300 @code{EXTRA_} variable, because Automake will examine the contents of
3301 each variable to construct the complete list of source files.
3303 If your program uses a lot of files, you will probably prefer a
3304 conditional @samp{+=}.
3306 @example
3307 bin_PROGRAMS = hello
3308 hello_SOURCES = hello-common.c
3309 if LINUX
3310 hello_SOURCES += hello-linux.c
3311 else
3312 hello_SOURCES += hello-generic.c
3313 endif
3314 @end example
3316 @node Conditional Programs
3317 @subsection Conditional compilation of programs
3318 @cindex Conditional programs
3319 @cindex Programs, conditional
3321 Sometimes it is useful to determine the programs that are to be built
3322 at configure time.  For instance, GNU @code{cpio} only builds
3323 @code{mt} and @code{rmt} under special circumstances.  The means to
3324 achieve conditional compilation of programs are the same you can use
3325 to compile source files conditionally: substitutions or conditionals.
3327 @subsubsection Conditional programs using @command{configure} substitutions
3329 @vindex EXTRA_PROGRAMS
3330 @cindex @code{EXTRA_PROGRAMS}, defined
3331 In this case, you must notify Automake of all the programs that can
3332 possibly be built, but at the same time cause the generated
3333 @file{Makefile.in} to use the programs specified by @command{configure}.
3334 This is done by having @command{configure} substitute values into each
3335 @code{_PROGRAMS} definition, while listing all optionally built programs
3336 in @code{EXTRA_PROGRAMS}.
3338 @example
3339 bin_PROGRAMS = cpio pax $(MT)
3340 libexec_PROGRAMS = $(RMT)
3341 EXTRA_PROGRAMS = mt rmt
3342 @end example
3344 As explained in @ref{EXEEXT}, Automake will rewrite
3345 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
3346 @code{EXTRA_PROGRAMS}, appending @samp{$(EXEEXT)} to each binary.
3347 Obviously it cannot rewrite values obtained at run-time through
3348 @command{configure} substitutions, therefore you should take care of
3349 appending @samp{$(EXEEXT)} yourself, as in @samp{AC_SUBST([MT],
3350 ['mt$@{EXEEXT@}'])}.
3352 @subsubsection Conditional programs using Automake conditionals
3354 You can also use Automake conditionals (@pxref{Conditionals}) to
3355 select programs to be built.  In this case you don't have to worry
3356 about @samp{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
3358 @example
3359 bin_PROGRAMS = cpio pax
3360 if WANT_MT
3361   bin_PROGRAMS += mt
3362 endif
3363 if WANT_RMT
3364   libexec_PROGRAMS = rmt
3365 endif
3366 @end example
3369 @node A Library
3370 @section Building a library
3372 @cindex @code{_LIBRARIES} primary, defined
3373 @cindex @code{LIBRARIES} primary, defined
3374 @cindex Primary variable, @code{LIBRARIES}
3375 @vindex _LIBRARIES
3377 @vindex lib_LIBRARIES
3378 @vindex pkglib_LIBRARIES
3379 @vindex noinst_LIBRARIES
3381 Building a library is much like building a program.  In this case, the
3382 name of the primary is @code{LIBRARIES}.  Libraries can be installed in
3383 @code{libdir} or @code{pkglibdir}.
3385 @xref{A Shared Library}, for information on how to build shared
3386 libraries using libtool and the @code{LTLIBRARIES} primary.
3388 Each @code{_LIBRARIES} variable is a list of the libraries to be built.
3389 For instance, to create a library named @file{libcpio.a}, but not install
3390 it, you would write:
3392 @example
3393 noinst_LIBRARIES = libcpio.a
3394 libcpio_a_SOURCES = @dots{}
3395 @end example
3397 The sources that go into a library are determined exactly as they are
3398 for programs, via the @code{_SOURCES} variables.  Note that the library
3399 name is canonicalized (@pxref{Canonicalization}), so the @code{_SOURCES}
3400 variable corresponding to @file{libcpio.a} is @samp{libcpio_a_SOURCES},
3401 not @samp{libcpio.a_SOURCES}.
3403 @vindex maude_LIBADD
3404 Extra objects can be added to a library using the
3405 @code{@var{library}_LIBADD} variable.  This should be used for objects
3406 determined by @command{configure}.  Again from @code{cpio}:
3408 @example
3409 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
3410 @end example
3412 In addition, sources for extra objects that will not exist until
3413 configure-time must be added to the @code{BUILT_SOURCES} variable
3414 (@pxref{Sources}).
3416 Building a static library is done by compiling all object files, then
3417 by invoking @samp{$(AR) $(ARFLAGS)} followed by the name of the
3418 library and the list of objects, and finally by calling
3419 @samp{$(RANLIB)} on that library.  You should call
3420 @code{AC_PROG_RANLIB} from your @file{configure.ac} to define
3421 @code{RANLIB} (Automake will complain otherwise).  @code{AR} and
3422 @code{ARFLAGS} default to @code{ar} and @code{cru} respectively; you
3423 can override these two variables my setting them in your
3424 @file{Makefile.am}, by @code{AC_SUBST}ing them from your
3425 @file{configure.ac}, or by defining a per-library @code{maude_AR}
3426 variable (@pxref{Program and Library Variables}).
3428 @cindex Empty libraries
3429 Be careful when selecting library components conditionally.  Because
3430 building an empty library is not portable, you should ensure that any
3431 library contains always at least one object.
3433 To use a static library when building a program, add it to
3434 @code{LDADD} for this program.  In the following example, the program
3435 @file{cpio} is statically linked with the library @file{libcpio.a}.
3437 @example
3438 noinst_LIBRARIES = libcpio.a
3439 libcpio_a_SOURCES = @dots{}
3441 bin_PROGRAMS = cpio
3442 cpio_SOURCES = cpio.c @dots{}
3443 cpio_LDADD = libcpio.a
3444 @end example
3447 @node A Shared Library
3448 @section Building a Shared Library
3450 @cindex Shared libraries, support for
3452 Building shared libraries portably is a relatively complex matter.
3453 For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
3454 Libtool Manual}) was created to help build shared libraries in a
3455 platform-independent way.
3457 @menu
3458 * Libtool Concept::             Introducing Libtool
3459 * Libtool Libraries::           Declaring Libtool Libraries
3460 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
3461 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
3462 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
3463 * Libtool Modules::             Building Libtool Modules
3464 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
3465 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
3466 * Libtool Issues::              Common Issues Related to Libtool's Use
3467 @end menu
3469 @node Libtool Concept
3470 @subsection The Libtool Concept
3472 @cindex @command{libtool}, introduction
3473 @cindex libtool library, definition
3474 @cindex suffix @file{.la}, defined
3475 @cindex @file{.la} suffix, defined
3477 Libtool abstracts shared and static libraries into a unified concept
3478 henceforth called @dfn{libtool libraries}.  Libtool libraries are
3479 files using the @file{.la} suffix, and can designate a static library,
3480 a shared library, or maybe both.  Their exact nature cannot be
3481 determined until @file{./configure} is run: not all platforms support
3482 all kinds of libraries, and users can explicitly select which
3483 libraries should be built.  (However the package's maintainers can
3484 tune the default, @pxref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
3485 macro, libtool, The Libtool Manual}.)
3487 @cindex suffix @file{.lo}, defined
3488 Because object files for shared and static libraries must be compiled
3489 differently, libtool is also used during compilation.  Object files
3490 built by libtool are called @dfn{libtool objects}: these are files
3491 using the @file{.lo} suffix.  Libtool libraries are built from these
3492 libtool objects.
3494 You should not assume anything about the structure of @file{.la} or
3495 @file{.lo} files and how libtool constructs them: this is libtool's
3496 concern, and the last thing one wants is to learn about libtool's
3497 guts.  However the existence of these files matters, because they are
3498 used as targets and dependencies in @file{Makefile}s rules when
3499 building libtool libraries.  There are situations where you may have
3500 to refer to these, for instance when expressing dependencies for
3501 building source files conditionally (@pxref{Conditional Libtool
3502 Sources}).
3504 @cindex @file{libltdl}, introduction
3506 People considering writing a plug-in system, with dynamically loaded
3507 modules, should look into @file{libltdl}: libtool's dlopening library
3508 (@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
3509 This offers a portable dlopening facility to load libtool libraries
3510 dynamically, and can also achieve static linking where unavoidable.
3512 Before we discuss how to use libtool with Automake in details, it
3513 should be noted that the libtool manual also has a section about how
3514 to use Automake with libtool (@pxref{Using Automake, , Using Automake
3515 with Libtool, libtool, The Libtool Manual}).
3517 @node Libtool Libraries
3518 @subsection Building Libtool Libraries
3520 @cindex @code{_LTLIBRARIES} primary, defined
3521 @cindex @code{LTLIBRARIES} primary, defined
3522 @cindex Primary variable, @code{LTLIBRARIES}
3523 @cindex Example of shared libraries
3524 @vindex lib_LTLIBRARIES
3525 @vindex pkglib_LTLIBRARIES
3526 @vindex _LTLIBRARIES
3528 Automake uses libtool to build libraries declared with the
3529 @code{LTLIBRARIES} primary.  Each @code{_LTLIBRARIES} variable is a
3530 list of libtool libraries to build.  For instance, to create a libtool
3531 library named @file{libgettext.la}, and install it in @code{libdir},
3532 write:
3534 @example
3535 lib_LTLIBRARIES = libgettext.la
3536 libgettext_la_SOURCES = gettext.c gettext.h @dots{}
3537 @end example
3539 Automake predefines the variable @code{pkglibdir}, so you can use
3540 @code{pkglib_LTLIBRARIES} to install libraries in
3541 @samp{$(libdir)/@@PACKAGE@@/}.
3543 If @file{gettext.h} is a public header file that needs to be installed
3544 in order for people to use the library, it should be declared using a
3545 @code{_HEADERS} variable, not in @code{libgettext_la_SOURCES}.
3546 Headers listed in the latter should be internal headers that are not
3547 part of the public interface.
3549 @example
3550 lib_LTLIBRARIES = libgettext.la
3551 libgettext_la_SOURCES = gettext.c @dots{}
3552 include_HEADERS = gettext.h @dots{}
3553 @end example
3555 A package can build and install such a library along with other
3556 programs that use it.  This dependency should be specified using
3557 @code{LDADD}.  The following example builds a program named
3558 @file{hello} that is linked with @file{libgettext.la}.
3560 @example
3561 lib_LTLIBRARIES = libgettext.la
3562 libgettext_la_SOURCES = gettext.c @dots{}
3564 bin_PROGRAMS = hello
3565 hello_SOURCES = hello.c @dots{}
3566 hello_LDADD = libgettext.la
3567 @end example
3569 @noindent
3570 Whether @file{hello} is statically or dynamically linked with
3571 @file{libgettext.la} is not yet known: this will depend on the
3572 configuration of libtool and the capabilities of the host.
3575 @node Conditional Libtool Libraries
3576 @subsection Building Libtool Libraries Conditionally
3577 @cindex libtool libraries, conditional
3578 @cindex conditional libtool libraries
3580 Like conditional programs (@pxref{Conditional Programs}), there are
3581 two main ways to build conditional libraries: using Automake
3582 conditionals or using Autoconf @code{AC_SUBST}itutions.
3584 The important implementation detail you have to be aware of is that
3585 the place where a library will be installed matters to libtool: it
3586 needs to be indicated @emph{at link-time} using the @option{-rpath}
3587 option.
3589 For libraries whose destination directory is known when Automake runs,
3590 Automake will automatically supply the appropriate @option{-rpath}
3591 option to libtool.  This is the case for libraries listed explicitly in
3592 some installable @code{_LTLIBRARIES} variables such as
3593 @code{lib_LTLIBRARIES}.
3595 However, for libraries determined at configure time (and thus
3596 mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
3597 final installation directory.  For such libraries you must add the
3598 @option{-rpath} option to the appropriate @code{_LDFLAGS} variable by
3599 hand.
3601 The examples below illustrate the differences between these two methods.
3603 Here is an example where @code{WANTEDLIBS} is an @code{AC_SUBST}ed
3604 variable set at @file{./configure}-time to either @file{libfoo.la},
3605 @file{libbar.la}, both, or none.  Although @samp{$(WANTEDLIBS)}
3606 appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
3607 relates to @file{libfoo.la} or @file{libbar.la} by the time it creates
3608 the link rule for these two libraries.  Therefore the @option{-rpath}
3609 argument must be explicitly supplied.
3611 @example
3612 EXTRA_LTLIBRARIES = libfoo.la libbar.la
3613 lib_LTLIBRARIES = $(WANTEDLIBS)
3614 libfoo_la_SOURCES = foo.c @dots{}
3615 libfoo_la_LDFLAGS = -rpath '$(libdir)'
3616 libbar_la_SOURCES = bar.c @dots{}
3617 libbar_la_LDFLAGS = -rpath '$(libdir)'
3618 @end example
3620 Here is how the same @file{Makefile.am} would look using Automake
3621 conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}.  Now
3622 Automake is able to compute the @option{-rpath} setting itself, because
3623 it's clear that both libraries will end up in @samp{$(libdir)} if they
3624 are installed.
3626 @example
3627 lib_LTLIBRARIES =
3628 if WANT_LIBFOO
3629 lib_LTLIBRARIES += libfoo.la
3630 endif
3631 if WANT_LIBBAR
3632 lib_LTLIBRARIES += libbar.la
3633 endif
3634 libfoo_la_SOURCES = foo.c @dots{}
3635 libbar_la_SOURCES = bar.c @dots{}
3636 @end example
3638 @node Conditional Libtool Sources
3639 @subsection Libtool Libraries with Conditional Sources
3641 Conditional compilation of sources in a library can be achieved in the
3642 same way as conditional compilation of sources in a program
3643 (@pxref{Conditional Sources}).  The only difference is that
3644 @code{_LIBADD} should be used instead of @code{_LDADD} and that it
3645 should mention libtool objects (@file{.lo} files).
3647 So, to mimic the @file{hello} example from @ref{Conditional Sources},
3648 we could build a @file{libhello.la} library using either
3649 @file{hello-linux.c} or @file{hello-generic.c} with the following
3650 @file{Makefile.am}.
3652 @example
3653 lib_LTLIBRARIES = libhello.la
3654 libhello_la_SOURCES = hello-common.c
3655 EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
3656 libhello_la_LIBADD = $(HELLO_SYSTEM)
3657 libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
3658 @end example
3660 @noindent
3661 And make sure @command{configure} defines @code{HELLO_SYSTEM} as
3662 either @file{hello-linux.lo} or @file{hello-@-generic.lo}.
3664 Or we could simply use an Automake conditional as follows.
3666 @example
3667 lib_LTLIBRARIES = libhello.la
3668 libhello_la_SOURCES = hello-common.c
3669 if LINUX
3670 libhello_la_SOURCES += hello-linux.c
3671 else
3672 libhello_la_SOURCES += hello-generic.c
3673 endif
3674 @end example
3676 @node Libtool Convenience Libraries
3677 @subsection Libtool Convenience Libraries
3678 @cindex convenience libraries, libtool
3679 @cindex libtool convenience libraries
3680 @vindex noinst_LTLIBRARIES
3681 @vindex check_LTLIBRARIES
3683 Sometimes you want to build libtool libraries that should not be
3684 installed.  These are called @dfn{libtool convenience libraries} and
3685 are typically used to encapsulate many sublibraries, later gathered
3686 into one big installed library.
3688 Libtool convenience libraries are declared by directory-less variables
3689 such as @code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
3690 @code{EXTRA_LTLIBRARIES}.  Unlike installed libtool libraries they do
3691 not need an @option{-rpath} flag at link time (actually this is the only
3692 difference).
3694 Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
3695 built.  Those listed in @code{check_LTLIBRARIES} are built only upon
3696 @samp{make check}.  Finally, libraries listed in
3697 @code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
3698 rules to build them, but if the library does not appear as a Makefile
3699 dependency anywhere it won't be built (this is why
3700 @code{EXTRA_LTLIBRARIES} is used for conditional compilation).
3702 Here is a sample setup merging libtool convenience libraries from
3703 subdirectories into one main @file{libtop.la} library.
3705 @example
3706 # -- Top-level Makefile.am --
3707 SUBDIRS = sub1 sub2 @dots{}
3708 lib_LTLIBRARIES = libtop.la
3709 libtop_la_SOURCES =
3710 libtop_la_LIBADD = \
3711   sub1/libsub1.la \
3712   sub2/libsub2.la \
3713   @dots{}
3715 # -- sub1/Makefile.am --
3716 noinst_LTLIBRARIES = libsub1.la
3717 libsub1_la_SOURCES = @dots{}
3719 # -- sub2/Makefile.am --
3720 # showing nested convenience libraries
3721 SUBDIRS = sub2.1 sub2.2 @dots{}
3722 noinst_LTLIBRARIES = libsub2.la
3723 libsub2_la_SOURCES =
3724 libsub2_la_LIBADD = \
3725   sub21/libsub21.la \
3726   sub22/libsub22.la \
3727   @dots{}
3728 @end example
3730 When using such setup, beware that @command{automake} will assume
3731 @file{libtop.la} is to be linked with the C linker.  This is because
3732 @code{libtop_la_SOURCES} is empty, so @command{automake} picks C as
3733 default language.  If @code{libtop_la_SOURCES} was not empty,
3734 @command{automake} would select the linker as explained in @ref{How
3735 the Linker is Chosen}.
3737 If one of the sublibraries contains non-C source, it is important that
3738 the appropriate linker be chosen.  One way to achieve this is to
3739 pretend that there is such a non-C file among the sources of the
3740 library, thus forcing @command{automake} to select the appropriate
3741 linker.  Here is the top-level @file{Makefile} of our example updated
3742 to force C++ linking.
3744 @example
3745 SUBDIRS = sub1 sub2 @dots{}
3746 lib_LTLIBRARIES = libtop.la
3747 libtop_la_SOURCES =
3748 # Dummy C++ source to cause C++ linking.
3749 nodist_EXTRA_libtop_la_SOURCES = dummy.cxx
3750 libtop_la_LIBADD = \
3751   sub1/libsub1.la \
3752   sub2/libsub2.la \
3753   @dots{}
3754 @end example
3756 @samp{EXTRA_*_SOURCES} variables are used to keep track of source
3757 files that might be compiled (this is mostly useful when doing
3758 conditional compilation using @code{AC_SUBST}, @pxref{Conditional
3759 Libtool Sources}), and the @code{nodist_} prefix means the listed
3760 sources are not to be distributed (@pxref{Program and Library
3761 Variables}).  In effect the file @file{dummy.cxx} does not need to
3762 exist in the source tree.  Of course if you have some real source file
3763 to list in @code{libtop_la_SOURCES} there is no point in cheating with
3764 @code{nodist_EXTRA_libtop_la_SOURCES}.
3767 @node Libtool Modules
3768 @subsection Libtool Modules
3769 @cindex modules, libtool
3770 @cindex libtool modules
3771 @cindex @option{-module}, libtool
3773 These are libtool libraries meant to be dlopened.  They are
3774 indicated to libtool by passing @option{-module} at link-time.
3776 @example
3777 pkglib_LTLIBRARIES = mymodule.la
3778 mymodule_la_SOURCES = doit.c
3779 mymodule_la_LDFLAGS = -module
3780 @end example
3782 Ordinarily, Automake requires that a library's name starts with
3783 @code{lib}.  However, when building a dynamically loadable module you
3784 might wish to use a "nonstandard" name.  Automake will not complain
3785 about such nonstandard name if it knows the library being built is a
3786 libtool module, i.e., if @option{-module} explicitly appears in the
3787 library's @code{_LDFLAGS} variable (or in the common @code{AM_LDFLAGS}
3788 variable when no per-library @code{_LDFLAGS} variable is defined).
3790 As always, @code{AC_SUBST} variables are black boxes to Automake since
3791 their values are not yet known when @command{automake} is run.
3792 Therefore if @option{-module} is set via such a variable, Automake
3793 cannot notice it and will proceed as if the library was an ordinary
3794 libtool library, with strict naming.
3796 If @code{mymodule_la_SOURCES} is not specified, then it defaults to
3797 the single file @file{mymodule.c} (@pxref{Default _SOURCES}).
3799 @node Libtool Flags
3800 @subsection @code{_LIBADD}, @code{_LDFLAGS}, and @code{_LIBTOOLFLAGS}
3801 @cindex @code{_LIBADD}, libtool
3802 @cindex @code{_LDFLAGS}, libtool
3803 @cindex @code{_LIBTOOLFLAGS}, libtool
3804 @vindex AM_LIBTOOLFLAGS
3805 @vindex LIBTOOLFLAGS
3806 @vindex maude_LIBTOOLFLAGS
3808 As shown in previous sections, the @samp{@var{library}_LIBADD}
3809 variable should be used to list extra libtool objects (@file{.lo}
3810 files) or libtool libraries (@file{.la}) to add to @var{library}.
3812 The @samp{@var{library}_LDFLAGS} variable is the place to list
3813 additional libtool linking flags, such as @option{-version-info},
3814 @option{-static}, and a lot more.  @xref{Link mode, , Link mode,
3815 libtool, The Libtool Manual}.
3817 The @command{libtool} command has two kinds of options: mode-specific
3818 options and generic options.  Mode-specific options such as the
3819 aforementioned linking flags should be lumped with the other flags
3820 passed to the tool invoked by @command{libtool} (hence the use of
3821 @samp{@var{library}_LDFLAGS} for libtool linking flags).  Generic
3822 options include @option{--tag=@var{TAG}} and @option{--silent}
3823 (@pxref{Invoking libtool, , Invoking @command{libtool}, libtool, The
3824 Libtool Manual} for more options) should appear before the mode
3825 selection on the command line; in @file{Makefile.am}s they should
3826 be listed in the @samp{@var{library}_LIBTOOLFLAGS} variable.
3828 If @samp{@var{library}_LIBTOOLFLAGS} is not defined, the global
3829 @code{AM_LIBTOOLFLAGS} variable is used instead.
3831 These flags are passed to libtool after the @option{--tag=@var{TAG}}
3832 option computed by Automake (if any), so
3833 @samp{@var{library}_LIBTOOLFLAGS} (or @code{AM_LIBTOOLFLAGS}) is the
3834 good place to override or supplement the @option{--tag=@var{TAG}}
3835 setting.
3837 The libtool rules also use a @code{LIBTOOLFLAGS} variable that should
3838 not be set in @file{Makefile.am}: this is a user variable (@pxref{Flag
3839 Variables Ordering}.  It allows users to run @samp{make
3840 LIBTOOLFLAGS=--silent}, for instance.
3843 @node LTLIBOBJS, Libtool Issues, Libtool Flags, A Shared Library
3844 @subsection @code{LTLIBOBJS} and @code{LTALLOCA}
3845 @cindex @code{LTLIBOBJS}, special handling
3846 @cindex @code{LIBOBJS}, and Libtool
3847 @cindex @code{LTALLOCA}, special handling
3848 @cindex @code{ALLOCA}, and Libtool
3849 @vindex LTLIBOBJS
3850 @vindex LIBOBJS
3851 @vindex LTALLOCA
3852 @vindex ALLOCA
3853 @acindex AC_LIBOBJ
3855 Where an ordinary library might include @samp{$(LIBOBJS)} or
3856 @samp{$(ALLOCA)} (@pxref{LIBOBJS}), a libtool library must use
3857 @samp{$(LTLIBOBJS)} or @samp{$(LTALLOCA)}.  This is required because
3858 the object files that libtool operates on do not necessarily end in
3859 @file{.o}.
3861 Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
3862 performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
3863 @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual}).
3865 @node Libtool Issues
3866 @subsection Common Issues Related to Libtool's Use
3868 @subsubsection @samp{required file `./ltmain.sh' not found}
3869 @cindex @file{ltmain.sh} not found
3870 @cindex @command{libtoolize}, no longer run by @command{automake}
3871 @cindex @command{libtoolize} and @command{autoreconf}
3872 @cindex @command{autoreconf} and @command{libtoolize}
3873 @cindex @file{bootstrap.sh} and @command{autoreconf}
3874 @cindex @file{autogen.sh} and @command{autoreconf}
3876 Libtool comes with a tool called @command{libtoolize} that will
3877 install libtool's supporting files into a package.  Running this
3878 command will install @file{ltmain.sh}.  You should execute it before
3879 @command{aclocal} and @command{automake}.
3881 People upgrading old packages to newer autotools are likely to face
3882 this issue because older Automake versions used to call
3883 @command{libtoolize}.  Therefore old build scripts do not call
3884 @command{libtoolize}.
3886 Since Automake 1.6, it has been decided that running
3887 @command{libtoolize} was none of Automake's business.  Instead, that
3888 functionality has been moved into the @command{autoreconf} command
3889 (@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
3890 The Autoconf Manual}).  If you do not want to remember what to run and
3891 when, just learn the @command{autoreconf} command.  Hopefully,
3892 replacing existing @file{bootstrap.sh} or @file{autogen.sh} scripts by
3893 a call to @command{autoreconf} should also free you from any similar
3894 incompatible change in the future.
3896 @subsubsection Objects @samp{created with both libtool and without}
3898 Sometimes, the same source file is used both to build a libtool
3899 library and to build another non-libtool target (be it a program or
3900 another library).
3902 Let's consider the following @file{Makefile.am}.
3904 @example
3905 bin_PROGRAMS = prog
3906 prog_SOURCES = prog.c foo.c @dots{}
3908 lib_LTLIBRARIES = libfoo.la
3909 libfoo_la_SOURCES = foo.c @dots{}
3910 @end example
3912 @noindent
3913 (In this trivial case the issue could be avoided by linking
3914 @file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
3915 @code{prog_SOURCES}.  But let's assume we really want to keep
3916 @file{prog} and @file{libfoo.la} separate.)
3918 Technically, it means that we should build @file{foo.$(OBJEXT)} for
3919 @file{prog}, and @file{foo.lo} for @file{libfoo.la}.  The problem is
3920 that in the course of creating @file{foo.lo}, libtool may erase (or
3921 replace) @file{foo.$(OBJEXT)}, and this cannot be avoided.
3923 Therefore, when Automake detects this situation it will complain
3924 with a message such as
3925 @example
3926 object `foo.$(OBJEXT)' created both with libtool and without
3927 @end example
3929 A workaround for this issue is to ensure that these two objects get
3930 different basenames.  As explained in @ref{renamed objects}, this
3931 happens automatically when per-targets flags are used.
3933 @example
3934 bin_PROGRAMS = prog
3935 prog_SOURCES = prog.c foo.c @dots{}
3936 prog_CFLAGS = $(AM_CFLAGS)
3938 lib_LTLIBRARIES = libfoo.la
3939 libfoo_la_SOURCES = foo.c @dots{}
3940 @end example
3942 @noindent
3943 Adding @samp{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
3944 when the @code{prog_CFLAGS} is defined, it is used instead of
3945 @code{AM_CFLAGS}.  However as a side effect it will cause
3946 @file{prog.c} and @file{foo.c} to be compiled as
3947 @file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)}, which solves
3948 the issue.
3950 @node Program and Library Variables
3951 @section Program and Library Variables
3953 Associated with each program are a collection of variables that can be
3954 used to modify how that program is built.  There is a similar list of
3955 such variables for each library.  The canonical name of the program (or
3956 library) is used as a base for naming these variables.
3958 In the list below, we use the name ``maude'' to refer to the program or
3959 library.  In your @file{Makefile.am} you would replace this with the
3960 canonical name of your program.  This list also refers to ``maude'' as a
3961 program, but in general the same rules apply for both static and dynamic
3962 libraries; the documentation below notes situations where programs and
3963 libraries differ.
3965 @vtable @code
3966 @item maude_SOURCES
3967 This variable, if it exists, lists all the source files that are
3968 compiled to build the program.  These files are added to the
3969 distribution by default.  When building the program, Automake will cause
3970 each source file to be compiled to a single @file{.o} file (or
3971 @file{.lo} when using libtool).  Normally these object files are named
3972 after the source file, but other factors can change this.  If a file in
3973 the @code{_SOURCES} variable has an unrecognized extension, Automake
3974 will do one of two things with it.  If a suffix rule exists for turning
3975 files with the unrecognized extension into @file{.o} files, then
3976 automake will treat this file as it will any other source file
3977 (@pxref{Support for Other Languages}).  Otherwise, the file will be
3978 ignored as though it were a header file.
3980 The prefixes @code{dist_} and @code{nodist_} can be used to control
3981 whether files listed in a @code{_SOURCES} variable are distributed.
3982 @code{dist_} is redundant, as sources are distributed by default, but it
3983 can be specified for clarity if desired.
3985 It is possible to have both @code{dist_} and @code{nodist_} variants of
3986 a given @code{_SOURCES} variable at once; this lets you easily
3987 distribute some files and not others, for instance:
3989 @example
3990 nodist_maude_SOURCES = nodist.c
3991 dist_maude_SOURCES = dist-me.c
3992 @end example
3994 By default the output file (on Unix systems, the @file{.o} file) will
3995 be put into the current build directory.  However, if the option
3996 @option{subdir-objects} is in effect in the current directory then the
3997 @file{.o} file will be put into the subdirectory named after the
3998 source file.  For instance, with @option{subdir-objects} enabled,
3999 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
4000 people prefer this mode of operation.  You can specify
4001 @option{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
4002 @cindex Subdirectory, objects in
4003 @cindex Objects in subdirectory
4006 @item EXTRA_maude_SOURCES
4007 Automake needs to know the list of files you intend to compile
4008 @emph{statically}.  For one thing, this is the only way Automake has of
4009 knowing what sort of language support a given @file{Makefile.in}
4010 requires.  @footnote{There are other, more obscure reasons for
4011 this limitation as well.}  This means that, for example, you can't put a
4012 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
4013 variable.  If you intend to conditionally compile source files and use
4014 @file{configure} to substitute the appropriate object names into, e.g.,
4015 @code{_LDADD} (see below), then you should list the corresponding source
4016 files in the @code{EXTRA_} variable.
4018 This variable also supports @code{dist_} and @code{nodist_} prefixes.
4019 For instance, @code{nodist_EXTRA_maude_SOURCES} would list extra
4020 sources that may need to be built, but should not be distributed.
4022 @item maude_AR
4023 A static library is created by default by invoking @samp{$(AR)
4024 $(ARFLAGS)} followed by the name of the library and then the objects
4025 being put into the library.  You can override this by setting the
4026 @code{_AR} variable.  This is usually used with C++; some C++
4027 compilers require a special invocation in order to instantiate all the
4028 templates that should go into a library.  For instance, the SGI C++
4029 compiler likes this variable set like so:
4030 @example
4031 libmaude_a_AR = $(CXX) -ar -o
4032 @end example
4034 @item maude_LIBADD
4035 Extra objects can be added to a @emph{library} using the @code{_LIBADD}
4036 variable.  For instance, this should be used for objects determined by
4037 @command{configure} (@pxref{A Library}).
4039 In the case of libtool libraries, @code{maude_LIBADD} can also refer
4040 to other libtool libraries.
4042 @item maude_LDADD
4043 Extra objects (@file{*.$(OBJDIR)}) and libraries (@file{*.a},
4044 @file{*.la}) can be added to a @emph{program} by listing them in the
4045 @code{_LDADD} variable.  For instance, this should be used for objects
4046 determined by @command{configure} (@pxref{Linking}).
4048 @code{_LDADD} and @code{_LIBADD} are inappropriate for passing
4049 program-specific linker flags (except for @option{-l}, @option{-L},
4050 @option{-dlopen} and @option{-dlpreopen}).  Use the @code{_LDFLAGS} variable
4051 for this purpose.
4053 For instance, if your @file{configure.ac} uses @code{AC_PATH_XTRA}, you
4054 could link your program against the X libraries like so:
4056 @example
4057 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
4058 @end example
4060 @item maude_LDFLAGS
4061 This variable is used to pass extra flags to the link step of a program
4062 or a shared library.  It overrides the global @code{AM_LDFLAGS} variable.
4064 @item maude_LIBTOOLFLAGS
4065 This variable is used to pass extra options to @command{libtool}.
4066 It overrides the global @code{AM_LIBTOOLFLAGS} variable.
4067 These options are output before @command{libtool}'s @option{--mode=@var{MODE}}
4068 option, so they should not be mode-specific options (those belong to
4069 the compiler or linker flags).  @xref{Libtool Flags}.
4071 @item maude_DEPENDENCIES
4072 It is also occasionally useful to have a program depend on some other
4073 target that is not actually part of that program.  This can be done
4074 using the @code{_DEPENDENCIES} variable.  Each program depends on the
4075 contents of such a variable, but no further interpretation is done.
4077 If @code{_DEPENDENCIES} is not supplied, it is computed by Automake.
4078 The automatically-assigned value is the contents of @code{_LDADD} or
4079 @code{_LIBADD}, with most configure substitutions, @option{-l}, @option{-L},
4080 @option{-dlopen} and @option{-dlpreopen} options removed.  The configure
4081 substitutions that are left in are only @samp{$(LIBOBJS)} and
4082 @samp{$(ALLOCA)}; these are left because it is known that they will not
4083 cause an invalid value for @code{_DEPENDENCIES} to be generated.
4085 @item maude_LINK
4086 You can override the linker on a per-program basis.  By default the
4087 linker is chosen according to the languages used by the program.  For
4088 instance, a program that includes C++ source code would use the C++
4089 compiler to link.  The @code{_LINK} variable must hold the name of a
4090 command that can be passed all the @file{.o} file names as arguments.
4091 Note that the name of the underlying program is @emph{not} passed to
4092 @code{_LINK}; typically one uses @samp{$@@}:
4094 @example
4095 maude_LINK = $(CCLD) -magic -o $@@
4096 @end example
4098 @item maude_CCASFLAGS
4099 @itemx maude_CFLAGS
4100 @itemx maude_CPPFLAGS
4101 @itemx maude_CXXFLAGS
4102 @itemx maude_FFLAGS
4103 @itemx maude_GCJFLAGS
4104 @itemx maude_LFLAGS
4105 @itemx maude_OBJCFLAGS
4106 @itemx maude_RFLAGS
4107 @itemx maude_YFLAGS
4108 @cindex per-target compilation flags, defined
4109 Automake allows you to set compilation flags on a per-program (or
4110 per-library) basis.  A single source file can be included in several
4111 programs, and it will potentially be compiled with different flags for
4112 each program.  This works for any language directly supported by
4113 Automake.  These @dfn{per-target compilation flags} are
4114 @samp{_CCASFLAGS},
4115 @samp{_CFLAGS},
4116 @samp{_CPPFLAGS},
4117 @samp{_CXXFLAGS},
4118 @samp{_FFLAGS},
4119 @samp{_GCJFLAGS},
4120 @samp{_LFLAGS},
4121 @samp{_OBJCFLAGS},
4122 @samp{_RFLAGS}, and
4123 @samp{_YFLAGS}.
4125 When using a per-target compilation flag, Automake will choose a
4126 different name for the intermediate object files.  Ordinarily a file
4127 like @file{sample.c} will be compiled to produce @file{sample.o}.
4128 However, if the program's @code{_CFLAGS} variable is set, then the
4129 object file will be named, for instance, @file{maude-sample.o}.  (See
4130 also @ref{renamed objects}.)  The use of per-target compilation flags
4131 with C sources requires that the macro @code{AM_PROG_CC_C_O} be called
4132 from @file{configure.ac}.
4134 In compilations with per-target flags, the ordinary @samp{AM_} form of
4135 the flags variable is @emph{not} automatically included in the
4136 compilation (however, the user form of the variable @emph{is} included).
4137 So for instance, if you want the hypothetical @file{maude} compilations
4138 to also use the value of @code{AM_CFLAGS}, you would need to write:
4140 @example
4141 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
4142 @end example
4144 @xref{Flag Variables Ordering}, for more discussion about the
4145 interaction between user variables, @samp{AM_} shadow variables, and
4146 per-target variables.
4148 @item maude_SHORTNAME
4149 On some platforms the allowable file names are very short.  In order to
4150 support these systems and per-target compilation flags at the same
4151 time, Automake allows you to set a ``short name'' that will influence
4152 how intermediate object files are named.  For instance, in the following
4153 example,
4155 @example
4156 bin_PROGRAMS = maude
4157 maude_CPPFLAGS = -DSOMEFLAG
4158 maude_SHORTNAME = m
4159 maude_SOURCES = sample.c @dots{}
4160 @end example
4162 @noindent
4163 the object file would be named @file{m-sample.o} rather than
4164 @file{maude-sample.o}.
4166 This facility is rarely needed in practice,
4167 and we recommend avoiding it until you find it is required.
4168 @end vtable
4170 @node Default _SOURCES
4171 @section Default @code{_SOURCES}
4173 @vindex _SOURCES
4174 @vindex SOURCES
4175 @cindex @code{_SOURCES}, default
4176 @cindex default @code{_SOURCES}
4178 @code{_SOURCES} variables are used to specify source files of programs
4179 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
4180 libraries (@pxref{A Shared Library}).
4182 When no such variable is specified for a target, Automake will define
4183 one itself.  The default is to compile a single C file whose base name
4184 is the name of the target itself, with any extension replaced by
4185 @file{.c}.  (Defaulting to C is terrible but we are stuck with it for
4186 historical reasons.)
4188 For example if you have the following somewhere in your
4189 @file{Makefile.am} with no corresponding @code{libfoo_a_SOURCES}:
4191 @example
4192 lib_LIBRARIES = libfoo.a sub/libc++.a
4193 @end example
4195 @noindent
4196 @file{libfoo.a} will be built using a default source file named
4197 @file{libfoo.c}, and @file{sub/libc++.a} will be built from
4198 @file{sub/libc++.c}.  (In older versions @file{sub/libc++.a}
4199 would be built from @file{sub_libc___a.c}, i.e., the default source
4200 was the canonized name of the target, with @file{.c} appended.
4201 We believe the new behavior is more sensible, but for backward
4202 compatibility automake will use the old name if a file or a rule
4203 with that name exist.)
4205 @cindex @code{check_PROGRAMS} example
4206 @vindex check_PROGRAMS
4207 Default sources are mainly useful in test suites, when building many
4208 tests programs each from a single source.  For instance, in
4210 @example
4211 check_PROGRAMS = test1 test2 test3
4212 @end example
4214 @noindent
4215 @file{test1}, @file{test2}, and @file{test3} will be built
4216 from @file{test1.c}, @file{test2.c}, and @file{test3.c}.
4218 @cindex Libtool modules, default source example
4219 @cindex default source, Libtool modules example
4220 Another case where is this convenient is building many Libtool modules
4221 (@file{moduleN.la}), each defined in its own file (@file{moduleN.c}).
4223 @example
4224 AM_LDFLAGS = -module
4225 lib_LTLIBRARIES = module1.la module2.la module3.la
4226 @end example
4228 @cindex empty @code{_SOURCES}
4229 @cindex @code{_SOURCES}, empty
4230 Finally, there is one situation where this default source computation
4231 needs to be avoided: when a target should not be built from sources.
4232 We already saw such an example in @ref{true}; this happens when all
4233 the constituents of a target have already been compiled and need just
4234 to be combined using a @code{_LDADD} variable.  Then it is necessary
4235 to define an empty @code{_SOURCES} variable, so that automake does not
4236 compute a default.
4238 @example
4239 bin_PROGRAMS = target
4240 target_SOURCES =
4241 target_LDADD = libmain.a libmisc.a
4242 @end example
4244 @node LIBOBJS
4245 @section Special handling for @code{LIBOBJS} and @code{ALLOCA}
4247 @cindex @code{LIBOBJS}, example
4248 @cindex @code{ALLOCA}, example
4249 @cindex @code{LIBOBJS}, special handling
4250 @cindex @code{ALLOCA}, special handling
4251 @vindex LTLIBOBJS
4252 @vindex LIBOBJS
4253 @vindex LTALLOCA
4254 @vindex ALLOCA
4256 The @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} variables list object
4257 files that should be compiled into the project to provide an
4258 implementation for functions that are missing or broken on the host
4259 system.  They are substituted by @file{configure}.
4261 @acindex AC_LIBOBJ
4263 These variables are defined by Autoconf macros such as
4264 @code{AC_LIBOBJ}, @code{AC_REPLACE_FUNCS} (@pxref{Generic Functions, ,
4265 Generic Function Checks, autoconf, The Autoconf Manual}), or
4266 @code{AC_FUNC_ALLOCA} (@pxref{Particular Functions, , Particular
4267 Function Checks, autoconf, The Autoconf Manual}).  Many other Autoconf
4268 macros call @code{AC_LIBOBJ} or @code{AC_REPLACE_FUNCS} to
4269 populate @samp{$(LIBOBJS)}.
4271 @acindex AC_LIBSOURCE
4273 Using these variables is very similar to doing conditional compilation
4274 using @code{AC_SUBST} variables, as described in @ref{Conditional
4275 Sources}.  That is, when building a program, @samp{$(LIBOBJS)} and
4276 @samp{$(ALLOCA)} should be added to the associated @samp{*_LDADD}
4277 variable, or to the @samp{*_LIBADD} variable when building a library.
4278 However there is no need to list the corresponding sources in
4279 @samp{EXTRA_*_SOURCES} nor to define @samp{*_DEPENDENCIES}.  Automake
4280 automatically adds @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} to the
4281 dependencies, and it will discover the list of corresponding source
4282 files automatically (by tracing the invocations of the
4283 @code{AC_LIBSOURCE} Autoconf macros).
4285 These variables are usually used to build a portability library that
4286 is linked with all the programs of the project.  We now review a
4287 sample setup.  First, @file{configure.ac} contains some checks that
4288 affect either @code{LIBOBJS} or @code{ALLOCA}.
4290 @example
4291 # configure.ac
4292 @dots{}
4293 AC_CONFIG_LIBOBJ_DIR([lib])
4294 @dots{}
4295 AC_FUNC_MALLOC             dnl May add malloc.$(OBJEXT) to LIBOBJS
4296 AC_FUNC_MEMCMP             dnl May add memcmp.$(OBJEXT) to LIBOBJS
4297 AC_REPLACE_FUNCS([strdup]) dnl May add strdup.$(OBJEXT) to LIBOBJS
4298 AC_FUNC_ALLOCA             dnl May add alloca.$(OBJEXT) to ALLOCA
4299 @dots{}
4300 AC_CONFIG_FILES([
4301   lib/Makefile
4302   src/Makefile
4304 AC_OUTPUT
4305 @end example
4307 @acindex AC_CONFIG_LIBOBJ_DIR
4309 The @code{AC_CONFIG_LIBOBJ_DIR} tells Autoconf that the source files
4310 of these object files are to be found in the @file{lib/} directory.
4311 Automake can also use this information, otherwise it expects the
4312 source files are to be in the directory where the @samp{$(LIBOBJS)}
4313 and @samp{$(ALLOCA)} variables are used.
4315 The @file{lib/} directory should therefore contain @file{malloc.c},
4316 @file{memcmp.c}, @file{strdup.c}, @file{alloca.c}.  Here is its
4317 @file{Makefile.am}:
4319 @example
4320 # lib/Makefile.am
4322 noinst_LIBRARIES = libcompat.a
4323 libcompat_a_SOURCES =
4324 libcompat_a_LIBADD = $(LIBOBJS) $(ALLOCA)
4325 @end example
4327 The library can have any name, of course, and anyway it is not going
4328 to be installed: it just holds the replacement versions of the missing
4329 or broken functions so we can later link them in.  In many projects
4330 also include extra functions, specific to the project, in that
4331 library: they are simply added on the @code{_SOURCES} line.
4333 @cindex Empty libraries and @samp{$(LIBOBJS)}
4334 @cindex @samp{$(LIBOBJS)} and empty libraries
4335 There is a small trap here, though: @samp{$(LIBOBJS)} and
4336 @samp{$(ALLOCA)} might be empty, and building an empty library is not
4337 portable.  You should ensure that there is always something to put in
4338 @file{libcompat.a}.  Most projects will also add some utility
4339 functions in that directory, and list them in
4340 @code{libcompat_a_SOURCES}, so in practice @file{libcompat.a} cannot
4341 be empty.
4343 Finally here is how this library could be used from the @file{src/}
4344 directory.
4346 @example
4347 # src/Makefile.am
4349 # Link all programs in this directory with libcompat.a
4350 LDADD = ../lib/libcompat.a
4352 bin_PROGRAMS = tool1 tool2 @dots{}
4353 tool1_SOURCES = @dots{}
4354 tool2_SOURCES = @dots{}
4355 @end example
4357 When option @option{subdir-objects} is not used, as in the above
4358 example, the variables @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} can only
4359 be used in the directory where their sources lie.  E.g., here it would
4360 be wrong to use @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} in
4361 @file{src/Makefile.am}.  However if both @option{subdir-objects} and
4362 @code{AC_CONFIG_LIBOBJ_DIR} are used, it is OK to use these variables
4363 in other directories.  For instance @file{src/Makefile.am} could be
4364 changed as follows.
4366 @example
4367 # src/Makefile.am
4369 AUTOMAKE_OPTIONS = subdir-objects
4370 LDADD = $(LIBOBJS) $(ALLOCA)
4372 bin_PROGRAMS = tool1 tool2 @dots{}
4373 tool1_SOURCES = @dots{}
4374 tool2_SOURCES = @dots{}
4375 @end example
4377 Because @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} contain object
4378 file names that end with @samp{.$(OBJEXT)}, they are not suitable for
4379 Libtool libraries (where the expected object extension is @file{.lo}):
4380 @code{LTLIBOBJS} and @code{LTALLOCA} should be used instead.
4382 @code{LTLIBOBJS} is defined automatically by Autoconf and should not
4383 be defined by hand (as in the past), however at the time of writing
4384 @code{LTALLOCA} still needs to be defined from @code{ALLOCA} manually.
4385 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
4386 autoconf, The Autoconf Manual}.
4389 @node Program variables
4390 @section Variables used when building a program
4392 Occasionally it is useful to know which @file{Makefile} variables
4393 Automake uses for compilations; for instance, you might need to do your
4394 own compilation in some special cases.
4396 Some variables are inherited from Autoconf; these are @code{CC},
4397 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
4398 @code{LIBS}.
4399 @vindex CC
4400 @vindex CFLAGS
4401 @vindex CPPFLAGS
4402 @vindex DEFS
4403 @vindex LDFLAGS
4404 @vindex LIBS
4406 There are some additional variables that Automake defines on its own:
4408 @vtable @code
4409 @item AM_CPPFLAGS
4410 The contents of this variable are passed to every compilation that invokes
4411 the C preprocessor; it is a list of arguments to the preprocessor.  For
4412 instance, @option{-I} and @option{-D} options should be listed here.
4414 Automake already provides some @option{-I} options automatically.  In
4415 particular it generates @samp{-I$(srcdir)}, @samp{-I.}, and a
4416 @option{-I} pointing to the directory holding @file{config.h} (if
4417 you've used @code{AC_CONFIG_HEADERS} or @code{AM_CONFIG_HEADER}).  You
4418 can disable the default @option{-I} options using the
4419 @option{nostdinc} option.
4421 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
4422 per-library) @code{_CPPFLAGS} variable if it is defined.
4424 @item INCLUDES
4425 This does the same job as @code{AM_CPPFLAGS} (or any per-target
4426 @code{_CPPFLAGS} variable if it is used).  It is an older name for the
4427 same functionality.  This variable is deprecated; we suggest using
4428 @code{AM_CPPFLAGS} and per-target @code{_CPPFLAGS} instead.
4430 @item AM_CFLAGS
4431 This is the variable the @file{Makefile.am} author can use to pass
4432 in additional C compiler flags.  It is more fully documented elsewhere.
4433 In some situations, this is not used, in preference to the
4434 per-executable (or per-library) @code{_CFLAGS}.
4436 @item COMPILE
4437 This is the command used to actually compile a C source file.  The
4438 file name is appended to form the complete command line.
4440 @item AM_LDFLAGS
4441 This is the variable the @file{Makefile.am} author can use to pass
4442 in additional linker flags.  In some situations, this is not used, in
4443 preference to the per-executable (or per-library) @code{_LDFLAGS}.
4445 @item LINK
4446 This is the command used to actually link a C program.  It already
4447 includes @samp{-o $@@} and the usual variable references (for instance,
4448 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
4449 and libraries to link in.
4450 @end vtable
4453 @node Yacc and Lex
4454 @section Yacc and Lex support
4456 Automake has somewhat idiosyncratic support for Yacc and Lex.
4458 Automake assumes that the @file{.c} file generated by @command{yacc}
4459 (or @command{lex}) should be named using the basename of the input
4460 file.  That is, for a yacc source file @file{foo.y}, Automake will
4461 cause the intermediate file to be named @file{foo.c} (as opposed to
4462 @file{y.tab.c}, which is more traditional).
4464 The extension of a yacc source file is used to determine the extension
4465 of the resulting C or C++ file.  Files with the extension @file{.y}
4466 will be turned into @file{.c} files; likewise, @file{.yy} will become
4467 @file{.cc}; @file{.y++}, @file{c++}; and @file{.yxx}, @file{.cxx}.
4469 Likewise, lex source files can be used to generate C or C++; the
4470 extensions @file{.l}, @file{.ll}, @file{.l++}, and @file{.lxx} are
4471 recognized.
4473 You should never explicitly mention the intermediate (C or C++) file
4474 in any @code{SOURCES} variable; only list the source file.
4476 The intermediate files generated by @command{yacc} (or @command{lex})
4477 will be included in any distribution that is made.  That way the user
4478 doesn't need to have @command{yacc} or @command{lex}.
4480 If a @command{yacc} source file is seen, then your @file{configure.ac} must
4481 define the variable @code{YACC}.  This is most easily done by invoking
4482 the macro @code{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
4483 Program Checks, autoconf, The Autoconf Manual}).
4485 @vindex YFLAGS
4486 @vindex AM_YFLAGS
4487 When @code{yacc} is invoked, it is passed @code{YFLAGS} and
4488 @code{AM_YFLAGS}.  The former is a user variable and the latter is
4489 intended for the @file{Makefile.am} author.
4491 @code{AM_YFLAGS} is usually used to pass the @option{-d} option to
4492 @command{yacc}.  Automake knows what this means and will automatically
4493 adjust its rules to update and distribute the header file built by
4494 @samp{yacc -d}.  What Automake cannot guess, though, is where this
4495 header will be used: it is up to you to ensure the header gets built
4496 before it is first used.  Typically this is necessary in order for
4497 dependency tracking to work when the header is included by another
4498 file.  The common solution is listing the header file in
4499 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
4501 @example
4502 BUILT_SOURCES = parser.h
4503 AM_YFLAGS = -d
4504 bin_PROGRAMS = foo
4505 foo_SOURCES = @dots{} parser.y @dots{}
4506 @end example
4508 If a @command{lex} source file is seen, then your @file{configure.ac}
4509 must define the variable @code{LEX}.  You can use @code{AC_PROG_LEX}
4510 to do this (@pxref{Particular Programs, , Particular Program Checks,
4511 autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
4512 (@pxref{Macros}) is recommended.
4514 @vindex LFLAGS
4515 @vindex AM_LFLAGS
4516 When @command{lex} is invoked, it is passed @code{LFLAGS} and
4517 @code{AM_LFLAGS}.  The former is a user variable and the latter is
4518 intended for the @file{Makefile.am} author.
4520 When @code{AM_MAINTAINER_MODE} (@pxref{maintainer-mode}) is used, the
4521 rebuild rule for distributed Yacc and Lex sources are only used when
4522 @code{maintainer-mode} is enabled, or when the files have been erased.
4525 @cindex @command{ylwrap}
4526 @cindex @command{yacc}, multiple parsers
4527 @cindex Multiple @command{yacc} parsers
4528 @cindex Multiple @command{lex} lexers
4529 @cindex @command{lex}, multiple lexers
4532 Automake makes it possible to include multiple @command{yacc} (or
4533 @command{lex}) source files in a single program.  When there is more
4534 than one distinct @command{yacc} (or @command{lex}) source file in a
4535 directory, Automake uses a small program called @command{ylwrap} to run
4536 @command{yacc} (or @command{lex}) in a subdirectory.  This is
4537 necessary because yacc's output file name is fixed, and a parallel
4538 make could conceivably invoke more than one instance of @command{yacc}
4539 simultaneously.  The @command{ylwrap} program is distributed with
4540 Automake.  It should appear in the directory specified by
4541 @code{AC_CONFIG_AUX_DIR}, or one of its default locations
4542 (@pxref{Input, , Finding `configure' Input, autoconf, The Autoconf
4543 Manual}).
4545 For @command{yacc}, simply managing locking is insufficient.  The output of
4546 @command{yacc} always uses the same symbol names internally, so it isn't
4547 possible to link two @command{yacc} parsers into the same executable.
4549 We recommend using the following renaming hack used in @command{gdb}:
4550 @example
4551 #define yymaxdepth c_maxdepth
4552 #define yyparse c_parse
4553 #define yylex   c_lex
4554 #define yyerror c_error
4555 #define yylval  c_lval
4556 #define yychar  c_char
4557 #define yydebug c_debug
4558 #define yypact  c_pact
4559 #define yyr1    c_r1
4560 #define yyr2    c_r2
4561 #define yydef   c_def
4562 #define yychk   c_chk
4563 #define yypgo   c_pgo
4564 #define yyact   c_act
4565 #define yyexca  c_exca
4566 #define yyerrflag c_errflag
4567 #define yynerrs c_nerrs
4568 #define yyps    c_ps
4569 #define yypv    c_pv
4570 #define yys     c_s
4571 #define yy_yys  c_yys
4572 #define yystate c_state
4573 #define yytmp   c_tmp
4574 #define yyv     c_v
4575 #define yy_yyv  c_yyv
4576 #define yyval   c_val
4577 #define yylloc  c_lloc
4578 #define yyreds  c_reds
4579 #define yytoks  c_toks
4580 #define yylhs   c_yylhs
4581 #define yylen   c_yylen
4582 #define yydefred c_yydefred
4583 #define yydgoto c_yydgoto
4584 #define yysindex c_yysindex
4585 #define yyrindex c_yyrindex
4586 #define yygindex c_yygindex
4587 #define yytable  c_yytable
4588 #define yycheck  c_yycheck
4589 #define yyname   c_yyname
4590 #define yyrule   c_yyrule
4591 @end example
4593 For each define, replace the @samp{c_} prefix with whatever you like.
4594 These defines work for @command{bison}, @command{byacc}, and
4595 traditional @code{yacc}s.  If you find a parser generator that uses a
4596 symbol not covered here, please report the new name so it can be added
4597 to the list.
4600 @node C++ Support
4601 @section C++ Support
4603 @cindex C++ support
4604 @cindex Support for C++
4606 Automake includes full support for C++.
4608 Any package including C++ code must define the output variable
4609 @code{CXX} in @file{configure.ac}; the simplest way to do this is to use
4610 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
4611 Program Checks, autoconf, The Autoconf Manual}).
4613 A few additional variables are defined when a C++ source file is seen:
4615 @vtable @code
4616 @item CXX
4617 The name of the C++ compiler.
4619 @item CXXFLAGS
4620 Any flags to pass to the C++ compiler.
4622 @item AM_CXXFLAGS
4623 The maintainer's variant of @code{CXXFLAGS}.
4625 @item CXXCOMPILE
4626 The command used to actually compile a C++ source file.  The file name
4627 is appended to form the complete command line.
4629 @item CXXLINK
4630 The command used to actually link a C++ program.
4631 @end vtable
4634 @node Assembly Support
4635 @section Assembly Support
4637 Automake includes some support for assembly code.  There are two forms
4638 of assembler files: normal (@file{*.s}) and preprocessed by @code{CPP}
4639 (@file{*.S}).
4641 @vindex CCAS
4642 @vindex CCASFLAGS
4643 @vindex CPPFLAGS
4644 @vindex AM_CCASFLAGS
4645 @vindex AM_CPPFLAGS
4646 The variable @code{CCAS} holds the name of the compiler used to build
4647 assembly code.  This compiler must work a bit like a C compiler; in
4648 particular it must accept @option{-c} and @option{-o}.  The values of
4649 @code{CCASFLAGS} and @code{AM_CCASFLAGS} (or its per-target
4650 definition) is passed to the compilation.  For preprocessed files,
4651 @code{CPPFLAGS} and @code{AM_CPPFLAGS} are also used.
4653 The autoconf macro @code{AM_PROG_AS} will define @code{CCAS} and
4654 @code{CCASFLAGS} for you (unless they are already set, it simply sets
4655 @code{CCAS} to the C compiler and @code{CCASFLAGS} to the C compiler
4656 flags), but you are free to define these variables by other means.
4658 Only the suffixes @file{.s} and @file{.S} are recognized by
4659 @command{automake} as being files containing assembly code.
4662 @node Fortran 77 Support
4663 @comment  node-name,  next,  previous,  up
4664 @section Fortran 77 Support
4666 @cindex Fortran 77 support
4667 @cindex Support for Fortran 77
4669 Automake includes full support for Fortran 77.
4671 Any package including Fortran 77 code must define the output variable
4672 @code{F77} in @file{configure.ac}; the simplest way to do this is to use
4673 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
4674 Program Checks, autoconf, The Autoconf Manual}).
4676 A few additional variables are defined when a Fortran 77 source file is
4677 seen:
4679 @vtable @code
4681 @item F77
4682 The name of the Fortran 77 compiler.
4684 @item FFLAGS
4685 Any flags to pass to the Fortran 77 compiler.
4687 @item AM_FFLAGS
4688 The maintainer's variant of @code{FFLAGS}.
4690 @item RFLAGS
4691 Any flags to pass to the Ratfor compiler.
4693 @item AM_RFLAGS
4694 The maintainer's variant of @code{RFLAGS}.
4696 @item F77COMPILE
4697 The command used to actually compile a Fortran 77 source file.  The file
4698 name is appended to form the complete command line.
4700 @item FLINK
4701 The command used to actually link a pure Fortran 77 program or shared
4702 library.
4704 @end vtable
4706 Automake can handle preprocessing Fortran 77 and Ratfor source files in
4707 addition to compiling them@footnote{Much, if not most, of the
4708 information in the following sections pertaining to preprocessing
4709 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
4710 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
4711 also contains some support for creating programs and shared libraries
4712 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
4713 Fortran 77 With C and C++}).
4715 These issues are covered in the following sections.
4717 @menu
4718 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
4719 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
4720 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
4721 @end menu
4724 @node Preprocessing Fortran 77
4725 @comment  node-name,  next,  previous,  up
4726 @subsection Preprocessing Fortran 77
4728 @cindex Preprocessing Fortran 77
4729 @cindex Fortran 77, Preprocessing
4730 @cindex Ratfor programs
4732 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
4733 rule runs just the preprocessor to convert a preprocessable Fortran 77
4734 or Ratfor source file into a strict Fortran 77 source file.  The precise
4735 command used is as follows:
4737 @table @file
4739 @item .F
4740 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
4741 $(AM_FFLAGS) $(FFLAGS)}
4743 @item .r
4744 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
4746 @end table
4749 @node Compiling Fortran 77 Files
4750 @comment  node-name,  next,  previous,  up
4751 @subsection Compiling Fortran 77 Files
4753 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
4754 @file{N.r} by running the Fortran 77 compiler.  The precise command used
4755 is as follows:
4757 @table @file
4759 @item .f
4760 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
4762 @item .F
4763 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
4764 $(AM_FFLAGS) $(FFLAGS)}
4766 @item .r
4767 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
4769 @end table
4772 @node Mixing Fortran 77 With C and C++
4773 @comment  node-name,  next,  previous,  up
4774 @subsection Mixing Fortran 77 With C and C++
4776 @cindex Fortran 77, mixing with C and C++
4777 @cindex Mixing Fortran 77 with C and C++
4778 @cindex Linking Fortran 77 with C and C++
4779 @cindex cfortran
4780 @cindex Mixing Fortran 77 with C and/or C++
4782 Automake currently provides @emph{limited} support for creating programs
4783 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
4784 However, there are many other issues related to mixing Fortran 77 with
4785 other languages that are @emph{not} (currently) handled by Automake, but
4786 that are handled by other packages@footnote{For example,
4787 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
4788 addresses all of these inter-language issues, and runs under nearly all
4789 Fortran 77, C and C++ compilers on nearly all platforms.  However,
4790 @command{cfortran} is not yet Free Software, but it will be in the next
4791 major release.}.
4793 @page
4794 Automake can help in two ways:
4796 @enumerate
4797 @item
4798 Automatic selection of the linker depending on which combinations of
4799 source code.
4801 @item
4802 Automatic selection of the appropriate linker flags (e.g., @option{-L} and
4803 @option{-l}) to pass to the automatically selected linker in order to link
4804 in the appropriate Fortran 77 intrinsic and run-time libraries.
4806 @cindex @code{FLIBS}, defined
4807 @vindex FLIBS
4808 These extra Fortran 77 linker flags are supplied in the output variable
4809 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro
4810 supplied with newer versions of Autoconf (Autoconf version 2.13 and
4811 later).  @xref{Fortran 77 Compiler Characteristics, , , autoconf, The
4812 Autoconf}.
4813 @end enumerate
4815 If Automake detects that a program or shared library (as mentioned in
4816 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
4817 code that is a mixture of Fortran 77 and C and/or C++, then it requires
4818 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
4819 @file{configure.ac}, and that either @code{$(FLIBS)}
4820 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
4821 (for shared libraries) variables.  It is the responsibility of the
4822 person writing the @file{Makefile.am} to make sure that @samp{$(FLIBS)}
4823 appears in the appropriate @code{_LDADD} or
4824 @code{_LIBADD} variable.
4826 @cindex Mixed language example
4827 @cindex Example, mixed language
4829 For example, consider the following @file{Makefile.am}:
4831 @example
4832 bin_PROGRAMS = foo
4833 foo_SOURCES  = main.cc foo.f
4834 foo_LDADD    = libfoo.la $(FLIBS)
4836 pkglib_LTLIBRARIES = libfoo.la
4837 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
4838 libfoo_la_LIBADD   = $(FLIBS)
4839 @end example
4841 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
4842 is mentioned in @file{configure.ac}.  Also, if @samp{$(FLIBS)} hadn't
4843 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
4844 Automake would have issued a warning.
4847 @page
4848 @menu
4849 * How the Linker is Chosen::    Automatic linker selection
4850 @end menu
4852 @node How the Linker is Chosen
4853 @comment  node-name,  next,  previous,  up
4854 @subsubsection How the Linker is Chosen
4856 @cindex Automatic linker selection
4857 @cindex Selecting the linker automatically
4859 When a program or library mixes several languages, Automake choose the
4860 linker according to the following priorities.  (The names in
4861 parentheses are the variables containing the link command.)
4863 @enumerate
4864 @item
4865 @vindex GCJLINK
4866 Native Java (@code{GCJLINK})
4867 @item
4868 @vindex CXXLINK
4869 C++ (@code{CXXLINK})
4870 @item
4871 @vindex F77LINK
4872 Fortran 77 (@code{F77LINK})
4873 @item
4874 @vindex FCLINK
4875 Fortran (@code{FCLINK})
4876 @item
4877 @vindex OBJCLINK
4878 Objective C (@code{OBJCLINK})
4879 @item
4880 @vindex LINK
4881 C (@code{LINK})
4882 @end enumerate
4884 For example, if Fortran 77, C and C++ source code is compiled
4885 into a program, then the C++ linker will be used.  In this case, if the
4886 C or Fortran 77 linkers required any special libraries that weren't
4887 included by the C++ linker, then they must be manually added to an
4888 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
4889 @file{Makefile.am}.
4891 Automake only looks at the file names listed in @file{_SOURCES}
4892 variables to choose the linker, and defaults to the C linker.
4893 Sometimes this is inconvenient because you are linking against a
4894 library written in another language and would like to set the linker
4895 more appropriately.  @xref{Libtool Convenience Libraries}, for a
4896 trick with @code{nodist_EXTRA_@dots{}_SOURCES}.
4899 @node Fortran 9x Support
4900 @comment  node-name,  next,  previous,  up
4901 @section Fortran 9x Support
4903 @cindex Fortran 9x support
4904 @cindex Support for Fortran 9x
4906 Automake includes full support for Fortran 9x.
4908 Any package including Fortran 9x code must define the output variable
4909 @code{FC} in @file{configure.ac}; the simplest way to do this is to use
4910 the @code{AC_PROG_FC} macro (@pxref{Particular Programs, , Particular
4911 Program Checks, autoconf, The Autoconf Manual}).
4913 A few additional variables are defined when a Fortran 9x source file is
4914 seen:
4916 @vtable @code
4918 @item FC
4919 The name of the Fortran 9x compiler.
4921 @item FCFLAGS
4922 Any flags to pass to the Fortran 9x compiler.
4924 @item AM_FCFLAGS
4925 The maintainer's variant of @code{FCFLAGS}.
4927 @item FCCOMPILE
4928 The command used to actually compile a Fortran 9x source file.  The file
4929 name is appended to form the complete command line.
4931 @item FCLINK
4932 The command used to actually link a pure Fortran 9x program or shared
4933 library.
4935 @end vtable
4937 @menu
4938 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
4939 @end menu
4941 @node Compiling Fortran 9x Files
4942 @comment  node-name,  next,  previous,  up
4943 @subsection Compiling Fortran 9x Files
4945 @file{N.o} is made automatically from @file{N.f90} or @file{N.f95}
4946 by running the Fortran 9x compiler.  The precise command used
4947 is as follows:
4949 @table @file
4951 @item .f9x
4952 @code{$(FC) -c $(AM_FCFLAGS) $(FCFLAGS)}
4954 @end table
4956 @node Java Support
4957 @comment  node-name,  next,  previous,  up
4958 @section Java Support
4960 @cindex Java support
4961 @cindex Support for Java
4963 Automake includes support for compiled Java, using @command{gcj}, the Java
4964 front end to the GNU Compiler Collection.
4966 Any package including Java code to be compiled must define the output
4967 variable @code{GCJ} in @file{configure.ac}; the variable @code{GCJFLAGS}
4968 must also be defined somehow (either in @file{configure.ac} or
4969 @file{Makefile.am}).  The simplest way to do this is to use the
4970 @code{AM_PROG_GCJ} macro.
4972 @vindex GCJFLAGS
4974 By default, programs including Java source files are linked with
4975 @command{gcj}.
4977 As always, the contents of @code{AM_GCJFLAGS} are passed to every
4978 compilation invoking @command{gcj} (in its role as an ahead-of-time
4979 compiler, when invoking it to create @file{.class} files,
4980 @code{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
4981 options to @command{gcj} from @file{Makefile.am}, this variable, and not
4982 the user variable @code{GCJFLAGS}, should be used.
4984 @vindex AM_GCJFLAGS
4986 @command{gcj} can be used to compile @file{.java}, @file{.class},
4987 @file{.zip}, or @file{.jar} files.
4989 When linking, @command{gcj} requires that the main class be specified
4990 using the @option{--main=} option.  The easiest way to do this is to use
4991 the @code{_LDFLAGS} variable for the program.
4994 @node Support for Other Languages
4995 @comment  node-name,  next,  previous,  up
4996 @section Support for Other Languages
4998 Automake currently only includes full support for C, C++ (@pxref{C++
4999 Support}), Fortran 77 (@pxref{Fortran 77 Support}),
5000 Fortran 9x (@pxref{Fortran 9x Support}),
5001 and Java (@pxref{Java Support}).  There is only rudimentary support for other
5002 languages, support for which will be improved based on user demand.
5004 Some limited support for adding your own languages is available via the
5005 suffix rule handling (@pxref{Suffixes}).
5008 @node ANSI
5009 @section Automatic de-ANSI-fication
5011 @cindex de-ANSI-fication, defined
5013 Although the GNU standards allow the use of ANSI C, this can have the
5014 effect of limiting portability of a package to some older compilers
5015 (notably the SunOS C compiler).
5017 Automake allows you to work around this problem on such machines by
5018 @dfn{de-ANSI-fying} each source file before the actual compilation takes
5019 place.
5021 @vindex AUTOMAKE_OPTIONS
5022 @opindex ansi2knr
5024 If the @file{Makefile.am} variable @code{AUTOMAKE_OPTIONS}
5025 (@pxref{Options}) contains the option @option{ansi2knr} then code to
5026 handle de-ANSI-fication is inserted into the generated
5027 @file{Makefile.in}.
5029 This causes each C source file in the directory to be treated as ANSI C@.
5030 If an ANSI C compiler is available, it is used.  If no ANSI C compiler
5031 is available, the @command{ansi2knr} program is used to convert the source
5032 files into K&R C, which is then compiled.
5034 The @command{ansi2knr} program is simple-minded.  It assumes the source
5035 code will be formatted in a particular way; see the @command{ansi2knr} man
5036 page for details.
5038 @acindex AM_C_PROTOTYPES
5039 Support for de-ANSI-fication requires the source files @file{ansi2knr.c}
5040 and @file{ansi2knr.1} to be in the same package as the ANSI C source;
5041 these files are distributed with Automake.  Also, the package
5042 @file{configure.ac} must call the macro @code{AM_C_PROTOTYPES}
5043 (@pxref{Macros}).
5045 Automake also handles finding the @command{ansi2knr} support files in some
5046 other directory in the current package.  This is done by prepending the
5047 relative path to the appropriate directory to the @command{ansi2knr}
5048 option.  For instance, suppose the package has ANSI C code in the
5049 @file{src} and @file{lib} subdirectories.  The files @file{ansi2knr.c} and
5050 @file{ansi2knr.1} appear in @file{lib}.  Then this could appear in
5051 @file{src/Makefile.am}:
5053 @example
5054 AUTOMAKE_OPTIONS = ../lib/ansi2knr
5055 @end example
5057 If no directory prefix is given, the files are assumed to be in the
5058 current directory.
5060 Note that automatic de-ANSI-fication will not work when the package is
5061 being built for a different host architecture.  That is because automake
5062 currently has no way to build @command{ansi2knr} for the build machine.
5064 @c FIXME: this paragraph might be better moved to an `upgrading' section.
5065 @cindex @code{LTLIBOBJS} and @code{ansi2knr}
5066 @cindex @code{LIBOBJS} and @code{ansi2knr}
5067 @cindex @code{ansi2knr} and @code{LTLIBOBJS}
5068 @cindex @code{ansi2knr} and @code{LIBOBJS}
5069 Using @code{LIBOBJS} with source de-ANSI-fication used to require
5070 hand-crafted code in @file{configure} to append @samp{$U} to basenames
5071 in @code{LIBOBJS}.  This is no longer true today.  Starting with version
5072 2.54, Autoconf takes care of rewriting @code{LIBOBJS} and
5073 @code{LTLIBOBJS}.  (@pxref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ}
5074 vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual})
5076 @node Dependencies
5077 @section Automatic dependency tracking
5079 As a developer it is often painful to continually update the
5080 @file{Makefile.in} whenever the include-file dependencies change in a
5081 project.  Automake supplies a way to automatically track dependency
5082 changes.
5084 @cindex Dependency tracking
5085 @cindex Automatic dependency tracking
5087 Automake always uses complete dependencies for a compilation,
5088 including system headers.  Automake's model is that dependency
5089 computation should be a side effect of the build.  To this end,
5090 dependencies are computed by running all compilations through a
5091 special wrapper program called @command{depcomp}.  @command{depcomp}
5092 understands how to coax many different C and C++ compilers into
5093 generating dependency information in the format it requires.
5094 @samp{automake -a} will install @command{depcomp} into your source
5095 tree for you.  If @command{depcomp} can't figure out how to properly
5096 invoke your compiler, dependency tracking will simply be disabled for
5097 your build.
5099 @cindex @command{depcomp}
5101 Experience with earlier versions of Automake (@pxref{Dependency
5102 Tracking Evolution}) taught us that it is not reliable to generate
5103 dependencies only on the maintainer's system, as configurations vary
5104 too much.  So instead Automake implements dependency tracking at build
5105 time.
5107 Automatic dependency tracking can be suppressed by putting
5108 @option{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
5109 passing @option{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
5110 (this should be the preferred way).  Or, you can invoke @command{automake}
5111 with the @option{-i} option.  Dependency tracking is enabled by default.
5113 @vindex AUTOMAKE_OPTIONS
5114 @opindex no-dependencies
5116 The person building your package also can choose to disable dependency
5117 tracking by configuring with @option{--disable-dependency-tracking}.
5119 @cindex Disabling dependency tracking
5120 @cindex Dependency tracking, disabling
5123 @node EXEEXT
5124 @section Support for executable extensions
5126 @cindex Executable extension
5127 @cindex Extension, executable
5128 @cindex Windows
5130 On some platforms, such as Windows, executables are expected to have an
5131 extension such as @file{.exe}.  On these platforms, some compilers (GCC
5132 among them) will automatically generate @file{foo.exe} when asked to
5133 generate @file{foo}.
5135 Automake provides mostly-transparent support for this.  Unfortunately
5136 @emph{mostly} doesn't yet mean @emph{fully}.  Until the English
5137 dictionary is revised, you will have to assist Automake if your package
5138 must support those platforms.
5140 One thing you must be aware of is that, internally, Automake rewrites
5141 something like this:
5143 @example
5144 bin_PROGRAMS = liver
5145 @end example
5147 to this:
5149 @example
5150 bin_PROGRAMS = liver$(EXEEXT)
5151 @end example
5153 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
5154 extension.
5156 However, Automake cannot apply this rewriting to @command{configure}
5157 substitutions.  This means that if you are conditionally building a
5158 program using such a substitution, then your @file{configure.ac} must
5159 take care to add @samp{$(EXEEXT)} when constructing the output variable.
5161 With Autoconf 2.13 and earlier, you must explicitly use @code{AC_EXEEXT}
5162 to get this support.  With Autoconf 2.50, @code{AC_EXEEXT} is run
5163 automatically if you configure a compiler (say, through
5164 @code{AC_PROG_CC}).
5166 Sometimes maintainers like to write an explicit link rule for their
5167 program.  Without executable extension support, this is easy---you
5168 simply write a rule whose target is the name of the program.  However,
5169 when executable extension support is enabled, you must instead add the
5170 @samp{$(EXEEXT)} suffix.
5172 Unfortunately, due to the change in Autoconf 2.50, this means you must
5173 always add this extension.  However, this is a problem for maintainers
5174 who know their package will never run on a platform that has
5175 executable extensions.  For those maintainers, the @option{no-exeext}
5176 option (@pxref{Options}) will disable this feature.  This works in a
5177 fairly ugly way; if @option{no-exeext} is seen, then the presence of a
5178 rule for a target named @code{foo} in @file{Makefile.am} will override
5179 an automake-generated rule for @samp{foo$(EXEEXT)}.  Without
5180 the @option{no-exeext} option, this use will give a diagnostic.
5183 @node Other objects
5184 @chapter Other Derived Objects
5186 Automake can handle derived objects that are not C programs.  Sometimes
5187 the support for actually building such objects must be explicitly
5188 supplied, but Automake will still automatically handle installation and
5189 distribution.
5191 @menu
5192 * Scripts::                     Executable scripts
5193 * Headers::                     Header files
5194 * Data::                        Architecture-independent data files
5195 * Sources::                     Derived sources
5196 @end menu
5199 @node Scripts
5200 @section Executable Scripts
5202 @cindex @code{_SCRIPTS} primary, defined
5203 @cindex @code{SCRIPTS} primary, defined
5204 @cindex Primary variable, @code{SCRIPTS}
5205 @vindex _SCRIPTS
5207 It is possible to define and install programs that are scripts.  Such
5208 programs are listed using the @code{SCRIPTS} primary name.  Automake
5209 doesn't define any dependencies for scripts; the @file{Makefile.am}
5210 should include the appropriate rules.
5211 @vindex SCRIPTS
5213 Automake does not assume that scripts are derived objects; such objects
5214 must be deleted by hand (@pxref{Clean}).
5216 The @command{automake} program itself is a Perl script that is generated
5217 from @file{automake.in}.  Here is how this is handled:
5219 @example
5220 bin_SCRIPTS = automake
5221 CLEANFILES = $(bin_SCRIPTS)
5223 do_subst = sed -e 's,[@@]datadir[@@],$(datadir),g' \
5224             -e 's,[@@]PERL[@@],$(PERL),g' \
5225             -e 's,[@@]PACKAGE[@@],$(PACKAGE),g' \
5226             -e 's,[@@]VERSION[@@],$(VERSION),g' \
5227             @dots{}
5229 automake: automake.in Makefile
5230         $(do_subst) < $(srcdir)/automake.in > automake
5231         chmod +x automake
5232 @end example
5234 Because---as we have just seen---scripts can be built, they are not
5235 distributed by default.  Scripts that should be distributed can be
5236 specified using a @code{dist_} prefix as in other primaries.  For
5237 instance, the following @file{Makefile.am} declares that
5238 @file{my_script} should be distributed and installed in
5239 @samp{$(sbindir)}.
5241 @example
5242 dist_sbin_SCRIPTS = my_script
5243 @end example
5245 @cindex @code{SCRIPTS}, installation directories
5246 @cindex Installing scripts
5248 @vindex bin_SCRIPTS
5249 @vindex sbin_SCRIPTS
5250 @vindex libexec_SCRIPTS
5251 @vindex pkgdata_SCRIPTS
5252 @vindex noinst_SCRIPTS
5253 @vindex check_SCRIPTS
5255 Script objects can be installed in @code{bindir}, @code{sbindir},
5256 @code{libexecdir}, or @code{pkgdatadir}.
5258 Scripts that need not being installed can be listed in
5259 @code{noinst_SCRIPTS}, and among them, those which are needed only by
5260 @samp{make check} should go in @code{check_SCRIPTS}.
5263 @node Headers
5264 @section Header files
5266 @cindex @code{_HEADERS} primary, defined
5267 @cindex @code{HEADERS} primary, defined
5268 @cindex Primary variable, @code{HEADERS}
5269 @vindex _HEADERS
5270 @vindex noinst_HEADERS
5271 @cindex @code{HEADERS}, installation directories
5272 @cindex Installing headers
5273 @vindex include_HEADERS
5274 @vindex oldinclude_HEADERS
5275 @vindex pkginclude_HEADERS
5278 Header files that must be installed are specified by the
5279 @code{HEADERS} family of variables.  Headers can be installed in
5280 @code{includedir}, @code{oldincludedir}, @code{pkgincludedir} or any
5281 other directory you may have defined (@pxref{Uniform}).  For instance,
5283 @example
5284 include_HEADERS = foo.h bar/bar.h
5285 @end example
5287 @noindent
5288 will install the two files as @file{$(includedir)/foo.h} and
5289 @file{$(includedir)/bar.h}.
5291 The @code{nobase_} prefix is also supported,
5293 @example
5294 nobase_include_HEADERS = foo.h bar/bar.h
5295 @end example
5297 @noindent
5298 will install the two files as @file{$(includedir)/foo.h} and
5299 @file{$(includedir)/bar/bar.h} (@pxref{Alternative}).
5301 @vindex noinst_HEADERS
5302 Usually, only header files that accompany installed libraries need to
5303 be installed.  Headers used by programs or convenience libraries are
5304 not installed.  The @code{noinst_HEADERS} variable can be used for
5305 such headers.  However when the header actually belongs to one
5306 convenient library or program, we recommend listing it in the
5307 program's or library's @code{_SOURCES} variable (@pxref{Program
5308 Sources}) instead of in @code{noinst_HEADERS}.  This is clearer for
5309 the @file{Makefile.am} reader.  @code{noinst_HEADERS} would be the
5310 right variable to use in a directory containing only headers and no
5311 associated library or program.
5313 All header files must be listed somewhere; in a @code{_SOURCES}
5314 variable or in a @code{_HEADERS} variable.  Missing ones will not
5315 appear in the distribution.
5317 For header files that are built and must not be distributed, use the
5318 @code{nodist_} prefix as in @code{nodist_include_HEADERS} or
5319 @code{nodist_prog_SOURCES}.  If these generated headers are needed
5320 during the build, you must also ensure they exist before they are
5321 used (@pxref{Sources}).
5324 @node Data
5325 @section Architecture-independent data files
5327 @cindex @code{_DATA} primary, defined
5328 @cindex @code{DATA} primary, defined
5329 @cindex Primary variable, @code{DATA}
5330 @vindex _DATA
5332 Automake supports the installation of miscellaneous data files using the
5333 @code{DATA} family of variables.
5334 @vindex DATA
5336 @vindex data_DATA
5337 @vindex sysconf_DATA
5338 @vindex sharedstate_DATA
5339 @vindex localstate_DATA
5340 @vindex pkgdata_DATA
5342 Such data can be installed in the directories @code{datadir},
5343 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
5344 @code{pkgdatadir}.
5346 By default, data files are @emph{not} included in a distribution.  Of
5347 course, you can use the @code{dist_} prefix to change this on a
5348 per-variable basis.
5350 Here is how Automake declares its auxiliary data files:
5352 @example
5353 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
5354 @end example
5357 @node Sources
5358 @section Built sources
5360 Because Automake's automatic dependency tracking works as a side-effect
5361 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
5362 target should not be compiled before its dependencies are made, but
5363 these dependencies are unknown until the target is first compiled.
5365 Ordinarily this is not a problem, because dependencies are distributed
5366 sources: they preexist and do not need to be built.  Suppose that
5367 @file{foo.c} includes @file{foo.h}.  When it first compiles
5368 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
5369 @file{foo.c}.  As a side-effect of this compilation @command{depcomp}
5370 records the @file{foo.h} dependency so that following invocations of
5371 @command{make} will honor it.  In these conditions, it's clear there is
5372 no problem: either @file{foo.o} doesn't exist and has to be built
5373 (regardless of the dependencies), or accurate dependencies exist and
5374 they can be used to decide whether @file{foo.o} should be rebuilt.
5376 It's a different story if @file{foo.h} doesn't exist by the first
5377 @command{make} run.  For instance, there might be a rule to build
5378 @file{foo.h}.  This time @file{file.o}'s build will fail because the
5379 compiler can't find @file{foo.h}.  @command{make} failed to trigger the
5380 rule to build @file{foo.h} first by lack of dependency information.
5382 @vindex BUILT_SOURCES
5383 @cindex @code{BUILT_SOURCES}, defined
5385 The @code{BUILT_SOURCES} variable is a workaround for this problem.  A
5386 source file listed in @code{BUILT_SOURCES} is made on @samp{make all}
5387 or @samp{make check} (or even @samp{make install}) before other
5388 targets are processed.  However, such a source file is not
5389 @emph{compiled} unless explicitly requested by mentioning it in some
5390 other @code{_SOURCES} variable.
5392 So, to conclude our introductory example, we could use
5393 @samp{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
5394 any other target (including @file{foo.o}) during @samp{make all} or
5395 @samp{make check}.
5397 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
5398 must be created early in the build process can be listed in this
5399 variable.  Moreover, all built sources do not necessarily have to be
5400 listed in @code{BUILT_SOURCES}.  For instance, a generated @file{.c} file
5401 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
5402 another source), because it's a known dependency of the associated
5403 object.
5405 It might be important to emphasize that @code{BUILT_SOURCES} is
5406 honored only by @samp{make all}, @samp{make check} and @samp{make
5407 install}.  This means you cannot build a specific target (e.g.,
5408 @samp{make foo}) in a clean tree if it depends on a built source.
5409 However it will succeed if you have run @samp{make all} earlier,
5410 because accurate dependencies are already available.
5412 The next section illustrates and discusses the handling of built sources
5413 on a toy example.
5415 @menu
5416 * Built sources example::       Several ways to handle built sources.
5417 @end menu
5419 @node Built sources example
5420 @subsection Built sources example
5422 Suppose that @file{foo.c} includes @file{bindir.h}, which is
5423 installation-dependent and not distributed: it needs to be built.  Here
5424 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
5425 value of the @command{make} variable @code{bindir} (inherited from
5426 @file{configure}).
5428 We suggest several implementations below.  It's not meant to be an
5429 exhaustive listing of all ways to handle built sources, but it will give
5430 you a few ideas if you encounter this issue.
5432 @unnumberedsubsec First try
5434 This first implementation will illustrate the bootstrap issue mentioned
5435 in the previous section (@pxref{Sources}).
5437 Here is a tentative @file{Makefile.am}.
5439 @example
5440 # This won't work.
5441 bin_PROGRAMS = foo
5442 foo_SOURCES = foo.c
5443 nodist_foo_SOURCES = bindir.h
5444 CLEANFILES = bindir.h
5445 bindir.h: Makefile
5446         echo '#define bindir "$(bindir)"' >$@@
5447 @end example
5449 This setup doesn't work, because Automake doesn't know that @file{foo.c}
5450 includes @file{bindir.h}.  Remember, automatic dependency tracking works
5451 as a side-effect of compilation, so the dependencies of @file{foo.o} will
5452 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
5453 The symptom is as follows.
5455 @example
5456 % make
5457 source='foo.c' object='foo.o' libtool=no \
5458 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
5459 depmode=gcc /bin/sh ./depcomp \
5460 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
5461 foo.c:2: bindir.h: No such file or directory
5462 make: *** [foo.o] Error 1
5463 @end example
5465 In this example @file{bindir.h} is not distributed, not installed, and
5466 it is not even being built on-time.  One may wonder what the
5467 @samp{nodist_foo_SOURCES = bindir.h} line has any use at all.  This
5468 line simply states that @file{bindir.h} is a source of @code{foo}, so
5469 for instance, it should be inspected while generating tags
5470 (@pxref{Tags}).  In other words, it does not help our present problem,
5471 and the build would fail identically without it.
5473 @unnumberedsubsec Using @code{BUILT_SOURCES}
5475 A solution is to require @file{bindir.h} to be built before anything
5476 else.  This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
5478 @example
5479 bin_PROGRAMS = foo
5480 foo_SOURCES = foo.c
5481 nodist_foo_SOURCES = bindir.h
5482 BUILT_SOURCES = bindir.h
5483 CLEANFILES = bindir.h
5484 bindir.h: Makefile
5485         echo '#define bindir "$(bindir)"' >$@@
5486 @end example
5488 See how @file{bindir.h} get built first:
5490 @example
5491 % make
5492 echo '#define bindir "/usr/local/bin"' >bindir.h
5493 make  all-am
5494 make[1]: Entering directory `/home/adl/tmp'
5495 source='foo.c' object='foo.o' libtool=no \
5496 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
5497 depmode=gcc /bin/sh ./depcomp \
5498 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
5499 gcc  -g -O2   -o foo  foo.o
5500 make[1]: Leaving directory `/home/adl/tmp'
5501 @end example
5503 However, as said earlier, @code{BUILT_SOURCES} applies only to the
5504 @code{all}, @code{check}, and @code{install} targets.  It still fails
5505 if you try to run @samp{make foo} explicitly:
5507 @example
5508 % make clean
5509 test -z "bindir.h" || rm -f bindir.h
5510 test -z "foo" || rm -f foo
5511 rm -f *.o
5512 % : > .deps/foo.Po # Suppress previously recorded dependencies
5513 % make foo
5514 source='foo.c' object='foo.o' libtool=no \
5515 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
5516 depmode=gcc /bin/sh ./depcomp \
5517 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
5518 foo.c:2: bindir.h: No such file or directory
5519 make: *** [foo.o] Error 1
5520 @end example
5522 @unnumberedsubsec Recording dependencies manually
5524 Usually people are happy enough with @code{BUILT_SOURCES} because they
5525 never build targets such as @samp{make foo} before @samp{make all}, as
5526 in the previous example.  However if this matters to you, you can
5527 avoid @code{BUILT_SOURCES} and record such dependencies explicitly in
5528 the @file{Makefile.am}.
5530 @example
5531 bin_PROGRAMS = foo
5532 foo_SOURCES = foo.c
5533 nodist_foo_SOURCES = bindir.h
5534 foo.$(OBJEXT): bindir.h
5535 CLEANFILES = bindir.h
5536 bindir.h: Makefile
5537         echo '#define bindir "$(bindir)"' >$@@
5538 @end example
5540 You don't have to list @emph{all} the dependencies of @file{foo.o}
5541 explicitly, only those that might need to be built.  If a dependency
5542 already exists, it will not hinder the first compilation and will be
5543 recorded by the normal dependency tracking code.  (Note that after
5544 this first compilation the dependency tracking code will also have
5545 recorded the dependency between @file{foo.o} and
5546 @file{bindir.h}; so our explicit dependency is really useful to
5547 the first build only.)
5549 Adding explicit dependencies like this can be a bit dangerous if you are
5550 not careful enough.  This is due to the way Automake tries not to
5551 overwrite your rules (it assumes you know better than it).
5552 @samp{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
5553 output to build @samp{foo.$(OBJEXT)}.  It happens to work in this case
5554 because Automake doesn't have to output any @samp{foo.$(OBJEXT):}
5555 target: it relies on a suffix rule instead (i.e., @samp{.c.$(OBJEXT):}).
5556 Always check the generated @file{Makefile.in} if you do this.
5558 @unnumberedsubsec Build @file{bindir.h} from @file{configure}
5560 It's possible to define this preprocessor macro from @file{configure},
5561 either in @file{config.h} (@pxref{Defining Directories, , Defining
5562 Directories, autoconf, The Autoconf Manual}), or by processing a
5563 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
5564 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
5565 Autoconf Manual}).
5567 At this point it should be clear that building @file{bindir.h} from
5568 @file{configure} work well for this example.  @file{bindir.h} will exist
5569 before you build any target, hence will not cause any dependency issue.
5571 The Makefile can be shrunk as follows.  We do not even have to mention
5572 @file{bindir.h}.
5574 @example
5575 bin_PROGRAMS = foo
5576 foo_SOURCES = foo.c
5577 @end example
5579 However, it's not always possible to build sources from
5580 @file{configure}, especially when these sources are generated by a tool
5581 that needs to be built first...
5583 @unnumberedsubsec Build @file{bindir.c}, not @file{bindir.h}.
5585 Another attractive idea is to define @code{bindir} as a variable or
5586 function exported from @file{bindir.o}, and build @file{bindir.c}
5587 instead of @file{bindir.h}.
5589 @example
5590 noinst_PROGRAMS = foo
5591 foo_SOURCES = foo.c bindir.h
5592 nodist_foo_SOURCES = bindir.c
5593 CLEANFILES = bindir.c
5594 bindir.c: Makefile
5595         echo 'const char bindir[] = "$(bindir)";' >$@@
5596 @end example
5598 @file{bindir.h} contains just the variable's declaration and doesn't
5599 need to be built, so it won't cause any trouble.  @file{bindir.o} is
5600 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
5601 first.
5603 @unnumberedsubsec Which is best?
5605 There is no panacea, of course.  Each solution has its merits and
5606 drawbacks.
5608 You cannot use @code{BUILT_SOURCES} if the ability to run @samp{make
5609 foo} on a clean tree is important to you.
5611 You won't add explicit dependencies if you are leery of overriding
5612 an Automake rule by mistake.
5614 Building files from @file{./configure} is not always possible, neither
5615 is converting @file{.h} files into @file{.c} files.
5618 @node Other GNU Tools
5619 @chapter Other GNU Tools
5621 Since Automake is primarily intended to generate @file{Makefile.in}s for
5622 use in GNU programs, it tries hard to interoperate with other GNU tools.
5624 @menu
5625 * Emacs Lisp::                  Emacs Lisp
5626 * gettext::                     Gettext
5627 * Libtool::                     Libtool
5628 * Java::                        Java
5629 * Python::                      Python
5630 @end menu
5633 @node Emacs Lisp
5634 @section Emacs Lisp
5636 @cindex @code{_LISP} primary, defined
5637 @cindex @code{LISP} primary, defined
5638 @cindex Primary variable, @code{LISP}
5640 @vindex _LISP
5641 @vindex lisp_LISP
5642 @vindex noinst_LISP
5644 Automake provides some support for Emacs Lisp.  The @code{LISP} primary
5645 is used to hold a list of @file{.el} files.  Possible prefixes for this
5646 primary are @code{lisp_} and @code{noinst_}.  Note that if
5647 @code{lisp_LISP} is defined, then @file{configure.ac} must run
5648 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
5650 @vindex dist_lisp_LISP
5651 @vindex dist_noinst_LISP
5652 Lisp sources are not distributed by default.  You can prefix the
5653 @code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
5654 @code{dist_noinst_LISP}, to indicate that these files should be
5655 distributed.
5657 Automake will byte-compile all Emacs Lisp source files using the Emacs
5658 found by @code{AM_PATH_LISPDIR}, if any was found.
5660 Byte-compiled Emacs Lisp files are not portable among all versions of
5661 Emacs, so it makes sense to turn this off if you expect sites to have
5662 more than one version of Emacs installed.  Furthermore, many packages
5663 don't actually benefit from byte-compilation.  Still, we recommend
5664 that you byte-compile your Emacs Lisp sources.  It is probably better
5665 for sites with strange setups to cope for themselves than to make the
5666 installation less nice for everybody else.
5668 There are two ways to avoid byte-compiling.  Historically, we have
5669 recommended the following construct.
5670 @example
5671 lisp_LISP = file1.el file2.el
5672 ELCFILES =
5673 @end example
5674 @noindent
5675 @code{ELCFILES} is an internal Automake variable that normally lists
5676 all @file{.elc} files that must be byte-compiled.  Automake defines
5677 @code{ELCFILES} automatically from @code{lisp_LISP}.  Emptying this
5678 variable explicitly prevents byte-compilation to occur.
5680 Since Automake 1.8, we now recommend using @code{lisp_DATA} instead.  As
5682 @example
5683 lisp_DATA = file1.el file2.el
5684 @end example
5686 Note that these two constructs are not equivalent.  @code{_LISP} will
5687 not install a file if Emacs is not installed, while @code{_DATA} will
5688 always install its files.
5690 @node gettext
5691 @section Gettext
5693 @cindex GNU Gettext support
5694 @cindex Gettext support
5695 @cindex Support for GNU Gettext
5697 If @code{AM_GNU_GETTEXT} is seen in @file{configure.ac}, then Automake
5698 turns on support for GNU gettext, a message catalog system for
5699 internationalization
5700 (@pxref{GNU Gettext, , , gettext, GNU gettext utilities}).
5702 The @code{gettext} support in Automake requires the addition of two
5703 subdirectories to the package, @file{intl} and @file{po}.  Automake
5704 insures that these directories exist and are mentioned in
5705 @code{SUBDIRS}.
5707 @node Libtool
5708 @section Libtool
5710 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
5711 libtool, The Libtool Manual}) with the @code{LTLIBRARIES} primary.
5712 @xref{A Shared Library}.
5715 @node Java
5716 @section Java
5718 @cindex @code{_JAVA} primary, defined
5719 @cindex @code{JAVA} primary, defined
5720 @cindex Primary variable, @code{JAVA}
5722 Automake provides some minimal support for Java compilation with the
5723 @code{JAVA} primary.
5725 Any @file{.java} files listed in a @code{_JAVA} variable will be
5726 compiled with @code{JAVAC} at build time.  By default, @file{.java}
5727 files are not included in the distribution, you should use the
5728 @code{dist_} prefix to distribute them.
5730 Here is a typical setup for distributing @file{.java} files and
5731 installing the @file{.class} files resulting from their compilation.
5733 @example
5734 javadir = $(datadir)/java
5735 dist_java_JAVA = a.java b.java @dots{}
5736 @end example
5738 @cindex @code{JAVA} restrictions
5739 @cindex Restrictions for @code{JAVA}
5741 Currently Automake enforces the restriction that only one @code{_JAVA}
5742 primary can be used in a given @file{Makefile.am}.  The reason for this
5743 restriction is that, in general, it isn't possible to know which
5744 @file{.class} files were generated from which @file{.java} files, so
5745 it would be impossible to know which files to install where.  For
5746 instance, a @file{.java} file can define multiple classes; the resulting
5747 @file{.class} file names cannot be predicted without parsing the
5748 @file{.java} file.
5750 There are a few variables that are used when compiling Java sources:
5752 @vtable @code
5753 @item JAVAC
5754 The name of the Java compiler.  This defaults to @samp{javac}.
5756 @item JAVACFLAGS
5757 The flags to pass to the compiler.  This is considered to be a user
5758 variable (@pxref{User Variables}).
5760 @item AM_JAVACFLAGS
5761 More flags to pass to the Java compiler.  This, and not
5762 @code{JAVACFLAGS}, should be used when it is necessary to put Java
5763 compiler flags into @file{Makefile.am}.
5765 @item JAVAROOT
5766 The value of this variable is passed to the @option{-d} option to
5767 @code{javac}.  It defaults to @samp{$(top_builddir)}.
5769 @item CLASSPATH_ENV
5770 This variable is an @code{sh} expression that is used to set the
5771 @env{CLASSPATH} environment variable on the @code{javac} command line.
5772 (In the future we will probably handle class path setting differently.)
5773 @end vtable
5776 @node Python
5777 @section Python
5779 @cindex @code{_PYTHON} primary, defined
5780 @cindex @code{PYTHON} primary, defined
5781 @cindex Primary variable, @code{PYTHON}
5782 @vindex _PYTHON
5784 Automake provides support for Python compilation with the @code{PYTHON}
5785 primary.
5787 Any files listed in a @code{_PYTHON} variable will be byte-compiled
5788 with @command{py-compile} at install time.  @command{py-compile}
5789 actually creates both standard (@file{.pyc}) and byte-compiled
5790 (@file{.pyo}) versions of the source files.  Note that because
5791 byte-compilation occurs at install time, any files listed in
5792 @code{noinst_PYTHON} will not be compiled.  Python source files are
5793 included in the distribution by default.
5795 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON} that
5796 will determine some Python-related directory variables (see below).  If
5797 you have called @code{AM_PATH_PYTHON} from @file{configure.ac}, then you
5798 may use the following variables to list you Python source files in your
5799 variables: @code{python_PYTHON}, @code{pkgpython_PYTHON},
5800 @code{pyexecdir_PYTHON}, @code{pkgpyexecdir_PYTHON}, depending where you
5801 want your files installed.
5803 @defmac AM_PATH_PYTHON ([@var{VERSION}], [@var{ACTION-IF-FOUND}], [@var{ACTION-IF-NOT-FOUND}])
5805 Search a Python interpreter on the system.  This macro takes three
5806 optional arguments.  The first argument, if present, is the minimum
5807 version of Python required for this package: @code{AM_PATH_PYTHON}
5808 will skip any Python interpreter that is older than @var{VERSION}.
5809 If an interpreter is found and satisfies @var{VERSION}, then
5810 @var{ACTION-IF-FOUND} is run.  Otherwise, @var{ACTION-IF-NOT-FOUND} is
5811 run.
5813 If @var{ACTION-IF-NOT-FOUND} is not specified, the default is to abort
5814 configure.  This is fine when Python is an absolute requirement for the
5815 package.  Therefore if Python >= 2.2 is only @emph{optional} to the
5816 package, @code{AM_PATH_PYTHON} could be called as follows.
5818 @example
5819 AM_PATH_PYTHON(2.2,, :)
5820 @end example
5822 @code{AM_PATH_PYTHON} creates the following output variables based on
5823 the Python installation found during configuration.
5824 @end defmac
5826 @vtable @code
5827 @item PYTHON
5828 The name of the Python executable, or @samp{:} if no suitable
5829 interpreter could be found.
5831 Assuming @var{ACTION-IF-NOT-FOUND} is used (otherwise @file{./configure}
5832 will abort if Python is absent), the value of @code{PYTHON} can be used
5833 to setup a conditional in order to disable the relevant part of a build
5834 as follows.
5836 @example
5837   AM_PATH_PYTHON(,, :)
5838   AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
5839 @end example
5841 @item PYTHON_VERSION
5842 The Python version number, in the form @var{major}.@var{minor}
5843 (e.g., @samp{1.5}).  This is currently the value of
5844 @samp{sys.version[:3]}.
5846 @item PYTHON_PREFIX
5847 The string @samp{$@{prefix@}}.  This term may be used in future work
5848 that needs the contents of Python's @samp{sys.prefix}, but general
5849 consensus is to always use the value from configure.
5851 @item PYTHON_EXEC_PREFIX
5852 The string @samp{$@{exec_prefix@}}.  This term may be used in future work
5853 that needs the contents of Python's @samp{sys.exec_prefix}, but general
5854 consensus is to always use the value from configure.
5856 @item PYTHON_PLATFORM
5857 The canonical name used by Python to describe the operating system, as
5858 given by @samp{sys.platform}.  This value is sometimes needed when
5859 building Python extensions.
5861 @item pythondir
5862 The directory name for the @file{site-packages} subdirectory of the
5863 standard Python install tree.
5865 @item pkgpythondir
5866 This is the directory under @code{pythondir} that is named after the
5867 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
5868 as a convenience.
5870 @item pyexecdir
5871 This is the directory where Python extension modules (shared libraries)
5872 should be installed.
5874 @item pkgpyexecdir
5875 This is a convenience variable that is defined as
5876 @samp{$(pyexecdir)/$(PACKAGE)}.
5877 @end vtable
5879 All these directory variables have values that start with either
5880 @samp{$@{prefix@}} or @samp{$@{exec_prefix@}} unexpanded.  This works
5881 fine in @file{Makefiles}, but it makes these variables hard to use in
5882 @file{configure}.  This is mandated by the GNU coding standards, so
5883 that the user can run @samp{make prefix=/foo install}.  The Autoconf
5884 manual has a section with more details on this topic
5885 (@pxref{Installation Directory Variables, , Installation Directory
5886 Variables, autoconf, The Autoconf Manual}).  See also @ref{Hard-Coded
5887 Install Paths}.
5890 @node Documentation
5891 @chapter Building documentation
5893 Currently Automake provides support for Texinfo and man pages.
5895 @menu
5896 * Texinfo::                     Texinfo
5897 * Man pages::                   Man pages
5898 @end menu
5901 @node Texinfo
5902 @section Texinfo
5904 @cindex @code{_TEXINFOS} primary, defined
5905 @cindex @code{TEXINFOS} primary, defined
5906 @cindex Primary variable, @code{TEXINFOS}
5907 @cindex HTML output using Texinfo
5908 @cindex PDF output using Texinfo
5909 @cindex PS output using Texinfo
5910 @cindex DVI output using Texinfo
5911 @vindex _TEXINFOS
5912 @vindex info_TEXINFOS
5914 If the current directory contains Texinfo source, you must declare it
5915 with the @code{TEXINFOS} primary.  Generally Texinfo files are converted
5916 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
5917 here.  Any Texinfo source file must end in the @file{.texi},
5918 @file{.txi}, or @file{.texinfo} extension.  We recommend @file{.texi}
5919 for new manuals.
5921 Automake generates rules to build @file{.info}, @file{.dvi},
5922 @file{.ps}, @file{.pdf} and @file{.html} files from your Texinfo
5923 sources.  Following the GNU Coding Standards, only the @file{.info}
5924 files are built by @samp{make all} and installed by @samp{make
5925 install} (unless you use @option{no-installinfo}, see below).
5926 Furthermore, @file{.info} files are automatically distributed so that
5927 Texinfo is not a prerequisite for installing your package.
5929 @trindex dvi
5930 @trindex html
5931 @trindex pdf
5932 @trindex ps
5933 @trindex install-dvi
5934 @trindex install-html
5935 @trindex install-pdf
5936 @trindex install-ps
5937 Other documentation formats can be built on request by @samp{make
5938 dvi}, @samp{make ps}, @samp{make pdf} and @samp{make html}, and they
5939 can be installed with @samp{make install-dvi}, @samp{make install-ps},
5940 @samp{make install-pdf} and @samp{make install-html} explicitly.
5941 @samp{make uninstall} will remove everything: the Texinfo
5942 documentation installed by default as well as all the above optional
5943 formats.
5945 All these targets can be extended using @samp{-local} rules
5946 (@pxref{Extending}).
5948 @cindex Texinfo flag, @code{VERSION}
5949 @cindex Texinfo flag, @code{UPDATED}
5950 @cindex Texinfo flag, @code{EDITION}
5951 @cindex Texinfo flag, @code{UPDATED-MONTH}
5953 @cindex @code{VERSION} Texinfo flag
5954 @cindex @code{UPDATED} Texinfo flag
5955 @cindex @code{EDITION} Texinfo flag
5956 @cindex @code{UPDATED-MONTH} Texinfo flag
5958 @cindex @file{mdate-sh}
5960 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
5961 that file will be automatically generated.  The file @file{version.texi}
5962 defines four Texinfo flag you can reference using
5963 @code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
5964 @code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
5966 @table @code
5967 @item EDITION
5968 @itemx VERSION
5969 Both of these flags hold the version number of your program.  They are
5970 kept separate for clarity.
5972 @item UPDATED
5973 This holds the date the primary @file{.texi} file was last modified.
5975 @item UPDATED-MONTH
5976 This holds the name of the month in which the primary @file{.texi} file
5977 was last modified.
5978 @end table
5980 The @file{version.texi} support requires the @command{mdate-sh}
5981 script; this script is supplied with Automake and automatically
5982 included when @command{automake} is invoked with the
5983 @option{--add-missing} option.
5985 If you have multiple Texinfo files, and you want to use the
5986 @file{version.texi} feature, then you have to have a separate version
5987 file for each Texinfo file.  Automake will treat any include in a
5988 Texinfo file that matches @file{vers*.texi} just as an automatically
5989 generated version file.
5991 Sometimes an info file actually depends on more than one @file{.texi}
5992 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
5993 @file{gpl.texi}.  You can tell Automake about these dependencies using
5994 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
5995 @vindex TEXINFOS
5996 @vindex _TEXINFOS
5998 @example
5999 info_TEXINFOS = hello.texi
6000 hello_TEXINFOS = gpl.texi
6001 @end example
6003 @cindex @file{texinfo.tex}
6005 By default, Automake requires the file @file{texinfo.tex} to appear in
6006 the same directory as the Texinfo source (this can be changed using the
6007 @code{TEXINFO_TEX} variable, see below).  However, if you used
6008 @code{AC_CONFIG_AUX_DIR} in @file{configure.ac} (@pxref{Input, , Finding
6009 `configure' Input, autoconf, The Autoconf Manual}), then
6010 @file{texinfo.tex} is looked for there.  Automake supplies
6011 @file{texinfo.tex} if @option{--add-missing} is given.
6013 @opindex no-texinfo.tex
6015 The option @option{no-texinfo.tex} can be used to eliminate the
6016 requirement for the file @file{texinfo.tex}.  Use of the variable
6017 @code{TEXINFO_TEX} is preferable, however, because that allows the
6018 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
6020 @cindex Option, @code{noinstall-info}
6021 @cindex Target, @code{install-info}
6022 @cindex @code{install-info} target
6023 @cindex @code{noinstall-info} option
6025 @opindex no-installinfo
6026 @trindex install-info
6028 Automake generates an @code{install-info} rule; some people apparently
6029 use this.  By default, info pages are installed by @samp{make
6030 install}, so running @code{make install-info} is pointless.  This can
6031 be prevented via the @code{no-installinfo} option.  In this case,
6032 @file{.info} files are not installed by default, and user must
6033 request this explicitly using @samp{make install-info}
6035 The following variables are used by the Texinfo build rules.
6037 @vtable @code
6038 @item MAKEINFO
6039 The name of the program invoked to build @file{.info} files.  This
6040 variable is defined by Automake.  If the @command{makeinfo} program is
6041 found on the system then it will be used by default; otherwise
6042 @command{missing} will be used instead.
6044 @item MAKEINFOHTML
6045 The command invoked to build @file{.html} files.  Automake
6046 defines this to @samp{$(MAKEINFO) --html}.
6048 @item MAKEINFOFLAGS
6049 User flags passed to each invocation of @samp{$(MAKEINFO)} and
6050 @samp{$(MAKEINFOHTML)}.  This user variable (@pxref{User Variables}) is
6051 not expected to be defined in any @file{Makefile}; it can be used by
6052 users to pass extra flags to suit their needs.
6054 @item AM_MAKEINFOFLAGS
6055 @itemx AM_MAKEINFOHTMLFLAGS
6056 Maintainer flags passed to each @command{makeinfo} invocation.  Unlike
6057 @code{MAKEINFOFLAGS}, these variables are meant to be defined by
6058 maintainers in @file{Makefile.am}.  @samp{$(AM_MAKEINFOFLAGS)} is
6059 passed to @code{makeinfo} when building @file{.info} files; and
6060 @samp{$(AM_MAKEINFOHTMLFLAGS)} is used when building @file{.html}
6061 files.
6063 For instance, the following setting can be used to obtain one single
6064 @file{.html} file per manual, without node separators.
6065 @example
6066 AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
6067 @end example
6069 @code{AM_MAKEINFOHTMLFLAGS} defaults to @samp{$(AM_MAKEINFOFLAGS)}.
6070 This means that defining @code{AM_MAKEINFOFLAGS} without defining
6071 @code{AM_MAKEINFOHTMLFLAGS} will impact builds of both @file{.info}
6072 and @file{.html} files.
6074 @item TEXI2DVI
6075 The name of the command that converts a @file{.texi} file into a
6076 @file{.dvi} file.  This defaults to @samp{texi2dvi}, a script that ships
6077 with the Texinfo package.
6079 @item TEXI2PDF
6080 The name of the command that translates a @file{.texi} file into a
6081 @file{.pdf} file.  This defaults to @samp{$(TEXI2DVI) --pdf --batch}.
6083 @item DVIPS
6084 The name of the command that build a @file{.ps} file out of a
6085 @file{.dvi} file.  This defaults to @samp{dvips}.
6087 @item TEXINFO_TEX
6089 If your package has Texinfo files in many directories, you can use the
6090 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
6091 @file{texinfo.tex} for your package.  The value of this variable should
6092 be the relative path from the current @file{Makefile.am} to
6093 @file{texinfo.tex}:
6095 @example
6096 TEXINFO_TEX = ../doc/texinfo.tex
6097 @end example
6098 @end vtable
6101 @node Man pages
6102 @section Man pages
6104 @cindex @code{_MANS} primary, defined
6105 @cindex @code{MANS} primary, defined
6106 @cindex Primary variable, @code{MANS}
6108 @vindex _MANS
6109 @vindex man_MANS
6110 A package can also include man pages (but see the GNU standards on this
6111 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
6112 pages are declared using the @code{MANS} primary.  Generally the
6113 @code{man_MANS} variable is used.  Man pages are automatically installed in
6114 the correct subdirectory of @code{mandir}, based on the file extension.
6116 File extensions such as @file{.1c} are handled by looking for the valid
6117 part of the extension and using that to determine the correct
6118 subdirectory of @code{mandir}.  Valid section names are the digits
6119 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
6121 Sometimes developers prefer to name a man page something like
6122 @file{foo.man} in the source, and then rename it to have the correct
6123 suffix, for example @file{foo.1}, when installing the file.  Automake
6124 also supports this mode.  For a valid section named @var{SECTION},
6125 there is a corresponding directory named @samp{man@var{SECTION}dir},
6126 and a corresponding @code{_MANS} variable.  Files listed in such a
6127 variable are installed in the indicated section.  If the file already
6128 has a valid suffix, then it is installed as-is; otherwise the file
6129 suffix is changed to match the section.
6131 For instance, consider this example:
6132 @example
6133 man1_MANS = rename.man thesame.1 alsothesame.1c
6134 @end example
6136 In this case, @file{rename.man} will be renamed to @file{rename.1} when
6137 installed, but the other files will keep their names.
6139 @cindex Target, @code{install-man}
6140 @cindex Option, @option{noinstall-man}
6141 @cindex @code{install-man} target
6142 @cindex @option{noinstall-man} option
6143 @opindex no-installman
6144 @trindex install-man
6146 By default, man pages are installed by @samp{make install}.  However,
6147 since the GNU project does not require man pages, many maintainers do
6148 not expend effort to keep the man pages up to date.  In these cases, the
6149 @option{no-installman} option will prevent the man pages from being
6150 installed by default.  The user can still explicitly install them via
6151 @samp{make install-man}.
6153 Here is how the man pages are handled in GNU @command{cpio} (which
6154 includes both Texinfo documentation and man pages):
6156 @example
6157 man_MANS = cpio.1 mt.1
6158 EXTRA_DIST = $(man_MANS)
6159 @end example
6161 Man pages are not currently considered to be source, because it is not
6162 uncommon for man pages to be automatically generated.  Therefore they
6163 are not automatically included in the distribution.  However, this can
6164 be changed by use of the @code{dist_} prefix.
6166 The @code{nobase_} prefix is meaningless for man pages and is
6167 disallowed.
6170 @node Install
6171 @chapter What Gets Installed
6173 @cindex Installation support
6174 @cindex @samp{make install} support
6176 @section Basics of installation
6178 Naturally, Automake handles the details of actually installing your
6179 program once it has been built.  All files named by the various
6180 primaries are automatically installed in the appropriate places when the
6181 user runs @samp{make install}.
6183 A file named in a primary is installed by copying the built file into
6184 the appropriate directory.  The base name of the file is used when
6185 installing.
6187 @example
6188 bin_PROGRAMS = hello subdir/goodbye
6189 @end example
6191 In this example, both @samp{hello} and @samp{goodbye} will be installed
6192 in @samp{$(bindir)}.
6194 Sometimes it is useful to avoid the basename step at install time.  For
6195 instance, you might have a number of header files in subdirectories of
6196 the source tree that are laid out precisely how you want to install
6197 them.  In this situation you can use the @code{nobase_} prefix to
6198 suppress the base name step.  For example:
6200 @example
6201 nobase_include_HEADERS = stdio.h sys/types.h
6202 @end example
6204 Will install @file{stdio.h} in @samp{$(includedir)} and @file{types.h}
6205 in @samp{$(includedir)/sys}.
6207 @section The two parts of install
6209 Automake generates separate @code{install-data} and @code{install-exec}
6210 rules, in case the installer is installing on multiple machines that
6211 share directory structure---these targets allow the machine-independent
6212 parts to be installed only once.  @code{install-exec} installs
6213 platform-dependent files, and @code{install-data} installs
6214 platform-independent files.  The @code{install} target depends on both
6215 of these targets.  While Automake tries to automatically segregate
6216 objects into the correct category, the @file{Makefile.am} author is, in
6217 the end, responsible for making sure this is done correctly.
6218 @trindex install-data
6219 @trindex install-exec
6220 @trindex install
6221 @cindex Install, two parts of
6223 Variables using the standard directory prefixes @samp{data},
6224 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
6225 @samp{pkgdata}, or @samp{pkginclude} are installed by
6226 @code{install-data}.
6228 Variables using the standard directory prefixes @samp{bin},
6229 @samp{sbin}, @samp{libexec}, @samp{sysconf}, @samp{localstate},
6230 @samp{lib}, or @samp{pkglib} are installed by @code{install-exec}.
6232 For instance, @code{data_DATA} files are installed by @code{install-data},
6233 while @code{bin_PROGRAMS} files are installed by @code{install-exec}.
6235 Any variable using a user-defined directory prefix with @samp{exec} in
6236 the name (e.g., @code{myexecbin_PROGRAMS}) is installed by
6237 @code{install-exec}.  All other user-defined prefixes are installed by
6238 @code{install-data}.
6240 @section Extending installation
6242 It is possible to extend this mechanism by defining an
6243 @code{install-exec-local} or @code{install-data-local} rule.  If these
6244 rules exist, they will be run at @samp{make install} time.  These
6245 rules can do almost anything; care is required.
6246 @trindex install-exec-local
6247 @trindex install-data-local
6249 Automake also supports two install hooks, @code{install-exec-hook} and
6250 @code{install-data-hook}.  These hooks are run after all other install
6251 rules of the appropriate type, exec or data, have completed.  So, for
6252 instance, it is possible to perform post-installation modifications
6253 using an install hook.  @ref{Extending} gives some examples.
6254 @cindex Install hook
6256 @section Staged installs
6258 @vindex DESTDIR
6259 Automake generates support for the @code{DESTDIR} variable in all
6260 install rules.  @code{DESTDIR} is used during the @samp{make install}
6261 step to relocate install objects into a staging area.  Each object and
6262 path is prefixed with the value of @code{DESTDIR} before being copied
6263 into the install area.  Here is an example of typical DESTDIR usage:
6265 @example
6266 mkdir /tmp/staging &&
6267 make DESTDIR=/tmp/staging install
6268 @end example
6270 The @command{mkdir} command avoids a security problem if the attacker
6271 creates a symbolic link from @file{/tmp/staging} to a victim area;
6272 then @command{make} places install objects in a directory tree built under
6273 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
6274 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
6275 would install @file{/tmp/staging/gnu/bin/foo} and
6276 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
6278 This feature is commonly used to build install images and packages.  For
6279 more information, see @ref{Makefile Conventions, , , standards, The GNU
6280 Coding Standards}.
6282 Support for @code{DESTDIR} is implemented by coding it directly into the
6283 install rules.  If your @file{Makefile.am} uses a local install rule
6284 (e.g., @code{install-exec-local}) or an install hook, then you must
6285 write that code to respect @code{DESTDIR}.
6287 @section Rules for the user
6289 Automake also generates rules for targets @code{uninstall},
6290 @code{installdirs}, and @code{install-strip}.
6291 @trindex uninstall
6292 @trindex installdirs
6293 @trindex install-strip
6295 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
6296 There is no notion of separate uninstalls for ``exec'' and ``data'', as
6297 these features would not provide additional functionality.
6299 Note that @code{uninstall} is not meant as a replacement for a real
6300 packaging tool.
6303 @node Clean
6304 @chapter What Gets Cleaned
6306 @cindex @samp{make clean} support
6308 The GNU Makefile Standards specify a number of different clean rules.
6309 @xref{Standard Targets, , Standard Targets for Users, standards,
6310 The GNU Coding Standards}.
6312 Generally the files that can be cleaned are determined automatically by
6313 Automake.  Of course, Automake also recognizes some variables that can
6314 be defined to specify additional files to clean.  These variables are
6315 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
6316 @code{MAINTAINERCLEANFILES}.
6317 @vindex MOSTLYCLEANFILES
6318 @vindex CLEANFILES
6319 @vindex DISTCLEANFILES
6320 @vindex MAINTAINERCLEANFILES
6322 @trindex mostlyclean-local
6323 @trindex clean-local
6324 @trindex distclean-local
6325 @trindex maintainer-clean-local
6326 When cleaning involves more than deleting some hard-coded list of
6327 files, it is also possible to supplement the cleaning rules with your
6328 own commands.  Simply define a rule for any of the
6329 @code{mostlyclean-local}, @code{clean-local}, @code{distclean-local},
6330 or @code{maintainer-clean-local} targets (@pxref{Extending}).  A common
6331 case is deleting a directory, for instance, a directory created by the
6332 test suite:
6334 @example
6335 clean-local:
6336         -rm -rf testSubDir
6337 @end example
6339 As the GNU Standards aren't always explicit as to which files should
6340 be removed by which rule, we've adopted a heuristic that we believe
6341 was first formulated by Fran@,{c}ois Pinard:
6343 @itemize @bullet
6344 @item
6345 If @command{make} built it, and it is commonly something that one would
6346 want to rebuild (for instance, a @file{.o} file), then
6347 @code{mostlyclean} should delete it.
6349 @item
6350 Otherwise, if @command{make} built it, then @code{clean} should delete it.
6352 @item
6353 If @command{configure} built it, then @code{distclean} should delete it.
6355 @item
6356 If the maintainer built it (for instance, a @file{.info} file), then
6357 @code{maintainer-clean} should delete it.  However
6358 @code{maintainer-clean} should not delete anything that needs to exist
6359 in order to run @samp{./configure && make}.
6360 @end itemize
6362 We recommend that you follow this same set of heuristics in your
6363 @file{Makefile.am}.
6366 @node Dist
6367 @chapter What Goes in a Distribution
6369 @section Basics of distribution
6371 @cindex @samp{make dist}
6373 @vindex PACKAGE
6374 @vindex VERSION
6375 @trindex dist
6376 The @code{dist} rule in the generated @file{Makefile.in} can be used
6377 to generate a gzip'd @code{tar} file and other flavors of archive for
6378 distribution.  The files is named based on the @code{PACKAGE} and
6379 @code{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
6380 (@pxref{Macros}); more precisely the gzip'd @code{tar} file is named
6381 @samp{@var{package}-@var{version}.tar.gz}.
6382 @vindex GZIP_ENV
6383 You can use the @command{make} variable @code{GZIP_ENV} to control how gzip
6384 is run.  The default setting is @option{--best}.
6386 @cindex @code{m4_include}, distribution
6387 @cindex @code{include}, distribution
6388 @acindex m4_include
6389 @cmindex include
6390 For the most part, the files to distribute are automatically found by
6391 Automake: all source files are automatically included in a distribution,
6392 as are all @file{Makefile.am}s and @file{Makefile.in}s.  Automake also
6393 has a built-in list of commonly used files that are automatically
6394 included if they are found in the current directory (either physically,
6395 or as the target of a @file{Makefile.am} rule).  This list is printed by
6396 @samp{automake --help}.  Also, files that are read by @command{configure}
6397 (i.e.@: the source files corresponding to the files specified in various
6398 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
6399 automatically distributed.  Files included in @file{Makefile.am}s (using
6400 @code{include}) or in @file{configure.ac} (using @code{m4_include}), and
6401 helper scripts installed with @samp{automake --add-missing} are also
6402 distributed.
6404 @vindex EXTRA_DIST
6405 Still, sometimes there are files that must be distributed, but which
6406 are not covered in the automatic rules.  These files should be listed in
6407 the @code{EXTRA_DIST} variable.  You can mention files from
6408 subdirectories in @code{EXTRA_DIST}.
6410 You can also mention a directory in @code{EXTRA_DIST}; in this case the
6411 entire directory will be recursively copied into the distribution.
6412 Please note that this will also copy @emph{everything} in the directory,
6413 including CVS/RCS version control files.  We recommend against using
6414 this feature.
6416 @vindex SUBDIRS
6417 @vindex DIST_SUBDIRS
6418 If you define @code{SUBDIRS}, Automake will recursively include the
6419 subdirectories in the distribution.  If @code{SUBDIRS} is defined
6420 conditionally (@pxref{Conditionals}), Automake will normally include
6421 all directories that could possibly appear in @code{SUBDIRS} in the
6422 distribution.  If you need to specify the set of directories
6423 conditionally, you can set the variable @code{DIST_SUBDIRS} to the
6424 exact list of subdirectories to include in the distribution
6425 (@pxref{Conditional Subdirectories}).
6428 @section Fine-grained distribution control
6430 @vindex dist_
6431 @vindex nodist_
6432 Sometimes you need tighter control over what does @emph{not} go into the
6433 distribution; for instance, you might have source files that are
6434 generated and that you do not want to distribute.  In this case
6435 Automake gives fine-grained control using the @code{dist} and
6436 @code{nodist} prefixes.  Any primary or @code{_SOURCES} variable can be
6437 prefixed with @code{dist_} to add the listed files to the distribution.
6438 Similarly, @code{nodist_} can be used to omit the files from the
6439 distribution.
6441 As an example, here is how you would cause some data to be distributed
6442 while leaving some source code out of the distribution:
6444 @example
6445 dist_data_DATA = distribute-this
6446 bin_PROGRAMS = foo
6447 nodist_foo_SOURCES = do-not-distribute.c
6448 @end example
6450 @section The dist hook
6452 @trindex dist-hook
6454 Occasionally it is useful to be able to change the distribution before
6455 it is packaged up.  If the @code{dist-hook} rule exists, it is run
6456 after the distribution directory is filled, but before the actual tar
6457 (or shar) file is created.  One way to use this is for distributing
6458 files in subdirectories for which a new @file{Makefile.am} is overkill:
6460 @example
6461 dist-hook:
6462         mkdir $(distdir)/random
6463         cp -p $(srcdir)/random/a1 $(srcdir)/random/a2 $(distdir)/random
6464 @end example
6466 Another way to to use this is for removing unnecessary files that get
6467 recursively included by specifying a directory in EXTRA_DIST:
6469 @example
6470 EXTRA_DIST = doc
6472 dist-hook:
6473         rm -rf `find $(distdir)/doc -name CVS`
6474 @end example
6476 @vindex distdir
6477 @vindex top_distdir
6478 Two variables that come handy when writing @code{dist-hook} rules are
6479 @samp{$(distdir)} and @samp{$(top_distdir)}.
6481 @samp{$(distdir)} points to the directory where the @code{dist} rule
6482 will copy files from the current directory before creating the
6483 tarball.  If you are at the top-level directory, then @samp{distdir =
6484 $(PACKAGE)-$(VERSION)}.  When used from subdirectory named
6485 @file{foo/}, then @samp{distdir = ../$(PACKAGE)-$(VERSION)/foo}.
6486 @samp{$(distdir)} can be a relative or absolute path, do not assume
6487 any form.
6489 @samp{$(top_distdir)} always points to the root directory of the
6490 distributed tree.  At the top-level it's equal to @samp{$(distdir)}.
6491 In the @file{foo/} subdirectory
6492 @samp{top_distdir = ../$(PACKAGE)-$(VERSION)}.
6493 @samp{$(top_distdir)} too can be a relative or absolute path.
6495 Note that when packages are nested using @code{AC_CONFIG_SUBDIRS}
6496 (@pxref{Subpackages}), then @samp{$(distdir)} and
6497 @samp{$(top_distdir)} are relative to the package where @samp{make
6498 dist} was run, not to any sub-packages involved.
6500 @section Checking the distribution
6502 @cindex @samp{make distcheck}
6503 @cindex @samp{make distcleancheck}
6504 @vindex distcleancheck_listfiles
6505 @cindex @samp{make distuninstallcheck}
6506 @vindex distuninstallcheck_listfiles
6508 @trindex distcheck
6509 Automake also generates a @code{distcheck} rule that can be of help
6510 to ensure that a given distribution will actually work.
6511 @code{distcheck} makes a distribution, then tries to do a @code{VPATH}
6512 build, run the test suite, and finally make another tarfile to ensure the
6513 distribution is self-contained.
6515 @vindex DISTCHECK_CONFIGURE_FLAGS
6516 Building the package involves running @samp{./configure}.  If you need
6517 to supply additional flags to @command{configure}, define them in the
6518 @code{DISTCHECK_CONFIGURE_FLAGS} variable, either in your top-level
6519 @file{Makefile.am}, or on the command line when invoking @command{make}.
6521 @trindex distcheck-hook
6522 If the @code{distcheck-hook} rule is defined in your top-level
6523 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
6524 the new distribution has been unpacked, but before the unpacked copy
6525 is configured and built.  Your @code{distcheck-hook} can do almost
6526 anything, though as always caution is advised.  Generally this hook is
6527 used to check for potential distribution errors not caught by the
6528 standard mechanism.  Note that @code{distcheck-hook} as well as
6529 @code{DISTCHECK_CONFIGURE_FLAGS} are not honored in a subpackage
6530 @file{Makefile.am}, but the @code{DISTCHECK_CONFIGURE_FLAGS} are
6531 passed down to the @command{configure} script of the subpackage.
6533 @trindex distcleancheck
6534 @vindex DISTCLEANFILES
6535 @vindex distcleancheck_listfiles
6536 Speaking of potential distribution errors, @code{distcheck} also
6537 ensures that the @code{distclean} rule actually removes all built
6538 files.  This is done by running @samp{make distcleancheck} at the end of
6539 the @code{VPATH} build.  By default, @code{distcleancheck} will run
6540 @code{distclean} and then make sure the build tree has been emptied by
6541 running @samp{$(distcleancheck_listfiles)}.  Usually this check will
6542 find generated files that you forgot to add to the @code{DISTCLEANFILES}
6543 variable (@pxref{Clean}).
6545 The @code{distcleancheck} behavior should be OK for most packages,
6546 otherwise you have the possibility to override the definition of
6547 either the @code{distcleancheck} rule, or the
6548 @samp{$(distcleancheck_listfiles)} variable.  For instance, to disable
6549 @code{distcleancheck} completely, add the following rule to your
6550 top-level @file{Makefile.am}:
6552 @example
6553 distcleancheck:
6554         @@:
6555 @end example
6557 If you want @code{distcleancheck} to ignore built files that have not
6558 been cleaned because they are also part of the distribution, add the
6559 following definition instead:
6561 @example
6562 distcleancheck_listfiles = \
6563   find -type f -exec sh -c 'test -f $(srcdir)/@{@} || echo @{@}' ';'
6564 @end example
6566 The above definition is not the default because it's usually an error if
6567 your Makefiles cause some distributed files to be rebuilt when the user
6568 build the package.  (Think about the user missing the tool required to
6569 build the file; or if the required tool is built by your package,
6570 consider the cross-compilation case where it can't be run.)  There is
6571 a FAQ entry about this (@pxref{distcleancheck}), make sure you read it
6572 before playing with @code{distcleancheck_listfiles}.
6574 @code{distcheck} also checks that the @code{uninstall} rule works
6575 properly, both for ordinary and @code{DESTDIR} builds.  It does this
6576 by invoking @samp{make uninstall}, and then it checks the install tree
6577 to see if any files are left over.  This check will make sure that you
6578 correctly coded your @code{uninstall}-related rules.
6580 By default, the checking is done by the @code{distuninstallcheck} rule,
6581 and the list of files in the install tree is generated by
6582 @samp{$(distuninstallcheck_listfiles}) (this is a variable whose value is
6583 a shell command to run that prints the list of files to stdout).
6585 Either of these can be overridden to modify the behavior of
6586 @code{distcheck}.  For instance, to disable this check completely, you
6587 would write:
6589 @example
6590 distuninstallcheck:
6591         @@:
6592 @end example
6594 @section The types of distributions
6596 Automake generates rules to provide archives of the project for
6597 distributions in various formats.  Their targets are:
6599 @table @asis
6600 @item @code{dist-bzip2}
6601 Generate a bzip2 tar archive of the distribution.  bzip2 archives are
6602 frequently smaller than gzipped archives.
6603 @trindex dist-bzip2
6605 @item @code{dist-gzip}
6606 Generate a gzip tar archive of the distribution.
6607 @trindex dist-gzip
6609 @item @code{dist-shar}
6610 Generate a shar archive of the distribution.
6611 @trindex dist-shar
6613 @item @code{dist-zip}
6614 Generate a zip archive of the distribution.
6615 @trindex dist-zip
6617 @item @code{dist-tarZ}
6618 Generate a compressed tar archive of
6619 the distribution.
6620 @trindex dist-tarZ
6621 @end table
6623 The rule @code{dist} (and its historical synonym @code{dist-all}) will
6624 create archives in all the enabled formats, @ref{Options}.  By
6625 default, only the @code{dist-gzip} target is hooked to @code{dist}.
6628 @node Tests
6629 @chapter Support for test suites
6631 @cindex Test suites
6632 @cindex @code{make check}
6633 @trindex check
6635 Automake supports two forms of test suites.
6637 @section Simple Tests
6639 If the variable @code{TESTS} is defined, its value is taken to be a list
6640 of programs to run in order to do the testing.  The programs can either
6641 be derived objects or source objects; the generated rule will look both
6642 in @code{srcdir} and @file{.}.  Programs needing data files should look
6643 for them in @code{srcdir} (which is both an environment variable and a
6644 make variable) so they work when building in a separate directory
6645 (@pxref{Build Directories, , Build Directories , autoconf, The Autoconf
6646 Manual}), and in particular for the @code{distcheck} rule
6647 (@pxref{Dist}).
6649 @cindex Exit status 77, special interpretation
6651 The number of failures will be printed at the end of the run.  If a
6652 given test program exits with a status of 77, then its result is ignored
6653 in the final count.  This feature allows non-portable tests to be
6654 ignored in environments where they don't make sense.
6656 The variable @code{TESTS_ENVIRONMENT} can be used to set environment
6657 variables for the test run; the environment variable @code{srcdir} is
6658 set in the rule.  If all your test programs are scripts, you can also
6659 set @code{TESTS_ENVIRONMENT} to an invocation of the shell (e.g.
6660 @samp{$(SHELL) -x}); this can be useful for debugging the tests.
6661 @vindex TESTS
6662 @vindex TESTS_ENVIRONMENT
6664 @cindex Tests, expected failure
6665 @cindex Expected test failure
6667 You may define the variable @code{XFAIL_TESTS} to a list of tests
6668 (usually a subset of @code{TESTS}) that are expected to fail.  This will
6669 reverse the result of those tests.
6670 @vindex XFAIL_TESTS
6672 Automake ensures that each program listed in @code{TESTS} is built
6673 before any tests are run; you can list both source and derived programs
6674 in @code{TESTS}.  For instance, you might want to run a C program as a
6675 test.  To do this you would list its name in @code{TESTS} and also in
6676 @code{check_PROGRAMS}, and then specify it as you would any other
6677 program.
6679 @section DejaGnu Tests
6681 If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @command{dejagnu}} appears in
6682 @code{AUTOMAKE_OPTIONS}, then a @command{dejagnu}-based test suite is
6683 assumed.  The variable @code{DEJATOOL} is a list of names that are
6684 passed, one at a time, as the @option{--tool} argument to
6685 @command{runtest} invocations; it defaults to the name of the package.
6687 The variable @code{RUNTESTDEFAULTFLAGS} holds the @option{--tool} and
6688 @option{--srcdir} flags that are passed to dejagnu by default; this can be
6689 overridden if necessary.
6690 @vindex RUNTESTDEFAULTFLAGS
6692 The variables @code{EXPECT} and @code{RUNTEST} can
6693 also be overridden to provide project-specific values.  For instance,
6694 you will need to do this if you are testing a compiler toolchain,
6695 because the default values do not take into account host and target
6696 names.
6697 @opindex dejagnu
6698 @vindex DEJATOOL
6699 @vindex EXPECT
6700 @vindex RUNTEST
6702 The contents of the variable @code{RUNTESTFLAGS} are passed to the
6703 @code{runtest} invocation.  This is considered a ``user variable''
6704 (@pxref{User Variables}).  If you need to set @command{runtest} flags in
6705 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
6706 @vindex RUNTESTFLAGS
6707 @vindex AM_RUNTESTFLAGS
6709 @cindex @file{site.exp}
6710 Automake will generate rules to create a local @file{site.exp} file,
6711 defining various variables detected by @command{configure}.  This file
6712 is automatically read by DejaGnu.  It is OK for the user of a package
6713 to edit this file in order to tune the test suite.  However this is
6714 not the place where the test suite author should define new variables:
6715 this should be done elsewhere in the real test suite code.
6716 Especially, @file{site.exp} should not be distributed.
6718 For more information regarding DejaGnu test suites, see @ref{Top, , ,
6719 dejagnu, The DejaGnu Manual}.
6721 In either case, the testing is done via @samp{make check}.
6723 @section Install Tests
6725 The @code{installcheck} target is available to the user as a way to
6726 run any tests after the package has been installed.  You can add tests
6727 to this by writing an @code{installcheck-local} rule.
6730 @node Rebuilding
6731 @chapter Rebuilding Makefiles
6732 @cindex rebuild rules
6734 Automake generates rules to automatically rebuild @file{Makefile}s,
6735 @file{configure}, and other derived files like @file{Makefile.in}.
6737 @acindex AM_MAINTAINER_MODE
6738 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.ac}, then
6739 these automatic rebuilding rules are only enabled in maintainer mode.
6741 @vindex ACLOCAL_AMFLAGS
6742 Sometimes you need to run @command{aclocal} with an argument like
6743 @option{-I} to tell it where to find @file{.m4} files.  Since
6744 sometimes @command{make} will automatically run @command{aclocal}, you
6745 need a way to specify these arguments.  You can do this by defining
6746 @code{ACLOCAL_AMFLAGS}; this holds arguments that are passed verbatim
6747 to @command{aclocal}.  This variable is only useful in the top-level
6748 @file{Makefile.am}.
6750 @vindex CONFIG_STATUS_DEPENDENCIES
6751 @vindex CONFIGURE_DEPENDENCIES
6752 @cindex @file{version.sh}, example
6753 @cindex @file{version.m4}, example
6755 Sometimes it is convenient to supplement the rebuild rules for
6756 @file{configure} or @file{config.status} with additional dependencies.
6757 The variables @code{CONFIGURE_DEPENDENCIES} and
6758 @code{CONFIG_STATUS_DEPENDENCIES} can be used to list these extra
6759 dependencies.  These variable should be defined in all
6760 @file{Makefile}s of the tree (because these two rebuild rules are
6761 output in all them), so it is safer and easier to @code{AC_SUBST} them
6762 from @file{configure.ac}.  For instance, the following statement will
6763 cause @file{configure} to be rerun each time @file{version.sh} is
6764 changed.
6765 @example
6766 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh'])
6767 @end example
6768 @noindent
6769 Note the @samp{$(top_srcdir)/} in the file name.  Since this variable
6770 is to be used in all @file{Makefile}s, its value must be sensible at
6771 any level in the build hierarchy.
6773 Beware not to mistake @code{CONFIGURE_DEPENDENCIES} for
6774 @code{CONFIG_STATUS_DEPENDENCIES}.
6776 @code{CONFIGURE_DEPENDENCIES} adds dependencies to the
6777 @file{configure} rule, whose effect is to run @command{autoconf}.  This
6778 variable should be seldom used, because @command{automake} already tracks
6779 @code{m4_include}d files.  However it can be useful when playing
6780 tricky games with @code{m4_esyscmd} or similar non-recommendable
6781 macros with side effects.
6783 @code{CONFIG_STATUS_DEPENDENCIES} adds dependencies to the
6784 @file{config.status} rule, whose effect is to run @file{configure}.
6785 This variable should therefore carry any non-standard source that may
6786 be read as a side effect of running configure, like @file{version.sh}
6787 in the example above.
6789 Speaking of @file{version.sh} scripts, we recommend against them
6790 today.  They are mainly used when the version of a package is updated
6791 automatically by a script (e.g., in daily builds).  Here is what some
6792 old-style @file{configure.ac}s may look like:
6793 @example
6794 AC_INIT
6795 . $srcdir/version.sh
6796 AM_INIT_AUTOMAKE([name], $VERSION_NUMBER)
6797 @dots{}
6798 @end example
6799 @noindent
6800 Here, @file{version.sh} is a shell fragment that sets
6801 @code{VERSION_NUMBER}.  The problem with this example is that
6802 @command{automake} cannot track dependencies (listing @file{version.sh}
6803 in @command{CONFIG_STATUS_DEPENDENCIES}, and distributing this file is up
6804 to the user), and that it uses the obsolete form of @code{AC_INIT} and
6805 @code{AM_INIT_AUTOMAKE}.  Upgrading to the new syntax is not
6806 straightforward, because shell variables are not allowed in
6807 @code{AC_INIT}'s arguments.  We recommend that @file{version.sh} be
6808 replaced by an M4 file that is included by @file{configure.ac}:
6809 @example
6810 m4_include([version.m4])
6811 AC_INIT([name], VERSION_NUMBER)
6812 AM_INIT_AUTOMAKE
6813 @dots{}
6814 @end example
6815 @noindent
6816 Here @file{version.m4} could contain something like
6817 @samp{m4_define([VERSION_NUMBER], [1.2])}.  The advantage of this
6818 second form is that @command{automake} will take care of the
6819 dependencies when defining the rebuild rule, and will also distribute
6820 the file automatically.  An inconvenience is that @command{autoconf}
6821 will now be rerun each time the version number is bumped, when only
6822 @file{configure} had to be rerun in the previous setup.
6825 @node Options
6826 @chapter Changing Automake's Behavior
6828 Various features of Automake can be controlled by options in the
6829 @file{Makefile.am}.  Such options are applied on a per-@file{Makefile}
6830 basis when listed in a special @file{Makefile} variable named
6831 @code{AUTOMAKE_OPTIONS}.  They are applied globally to all processed
6832 @file{Makefiles} when listed in the first argument of
6833 @code{AM_INIT_AUTOMAKE} in @file{configure.ac}.  Currently understood
6834 options are:
6835 @vindex AUTOMAKE_OPTIONS
6837 @table @asis
6838 @item @option{gnits}
6839 @itemx @option{gnu}
6840 @itemx @option{foreign}
6841 @itemx @option{cygnus}
6842 @cindex Option, @option{gnits}
6843 @cindex Option, @option{gnu}
6844 @cindex Option, @option{foreign}
6845 @cindex Option, @option{cygnus}
6846 @opindex gnits
6847 @opindex gnu
6848 @opindex foreign
6849 @opindex cygnus
6851 Set the strictness as appropriate.  The @option{gnits} option also
6852 implies options @option{readme-alpha} and @option{check-news}.
6854 @item @option{ansi2knr}
6855 @itemx @option{@var{path}/ansi2knr}
6856 @cindex Option, @option{ansi2knr}
6857 @opindex ansi2knr
6858 Turn on automatic de-ANSI-fication.  @xref{ANSI}.  If preceded by a
6859 path, the generated @file{Makefile.in} will look in the specified
6860 directory to find the @file{ansi2knr} program.  The path should be a
6861 relative path to another directory in the same distribution (Automake
6862 currently does not check this).
6864 @item @option{check-news}
6865 @cindex Option, @option{check-news}
6866 @opindex check-news
6867 Cause @samp{make dist} to fail unless the current version number appears
6868 in the first few lines of the @file{NEWS} file.
6870 @item @option{dejagnu}
6871 @cindex Option, @option{dejagnu}
6872 @opindex dejagnu
6873 Cause @command{dejagnu}-specific rules to be generated.  @xref{Tests}.
6875 @item @option{dist-bzip2}
6876 @cindex Option, @option{dist-bzip2}
6877 @opindex dist-bzip2
6878 Hook @code{dist-bzip2} to @code{dist}.
6879 @trindex dist-bzip2
6881 @item @option{dist-shar}
6882 @cindex Option, @option{dist-shar}
6883 @opindex dist-shar
6884 Hook @code{dist-shar} to @code{dist}.
6885 @trindex dist-shar
6887 @item @option{dist-zip}
6888 @cindex Option, @option{dist-zip}
6889 @opindex dist-zip
6890 Hook @code{dist-zip} to @code{dist}.
6891 @trindex dist-zip
6893 @item @option{dist-tarZ}
6894 @cindex Option, @option{dist-tarZ}
6895 @opindex dist-tarZ
6896 Hook @code{dist-tarZ} to @code{dist}.
6897 @trindex dist-tarZ
6899 @item @option{filename-length-max=99}
6900 @cindex Option, @option{filename-length-max=99}
6901 @opindex filename-length-max=99
6902 Abort if file names longer than 99 characters are found during
6903 @samp{make dist}.  Such long file names are generally considered not to
6904 be portable in tarballs.  See the @option{tar-v7} and @option{tar-ustar}
6905 options below.  This option should be used in the top-level
6906 @file{Makefile.am} or as an argument of @code{AM_INIT_AUTOMAKE} in
6907 @file{configure.ac}, it will be ignored otherwise.
6909 @item @option{no-define}
6910 @cindex Option, @option{no-define}
6911 @opindex no-define
6912 This options is meaningful only when passed as an argument to
6913 @code{AM_INIT_AUTOMAKE}.  It will prevent the @code{PACKAGE} and
6914 @code{VERSION} variables to be @code{AC_DEFINE}d.
6916 @item @option{no-dependencies}
6917 @cindex Option, @option{no-dependencies}
6918 @opindex no-dependencies
6919 This is similar to using @option{--include-deps} on the command line,
6920 but is useful for those situations where you don't have the necessary
6921 bits to make automatic dependency tracking work
6922 (@pxref{Dependencies}).  In this case the effect is to effectively
6923 disable automatic dependency tracking.
6925 @item @option{no-dist}
6926 @cindex Option, @option{no-dist}
6927 @opindex no-dist
6928 Don't emit any code related to @code{dist} target.  This is useful
6929 when a package has its own method for making distributions.
6931 @item @option{no-dist-gzip}
6932 @cindex Option, @option{no-dist-gzip}
6933 @opindex no-dist-gzip
6934 Do not hook @code{dist-gzip} to @code{dist}.
6935 @trindex no-dist-gzip
6937 @item @option{no-exeext}
6938 @cindex Option, @option{no-exeext}
6939 @opindex no-exeext
6940 If your @file{Makefile.am} defines a rule for target @code{foo}, it
6941 will override a rule for a target named @samp{foo$(EXEEXT)}.  This is
6942 necessary when @code{EXEEXT} is found to be empty.  However, by
6943 default automake will generate an error for this use.  The
6944 @option{no-exeext} option will disable this error.  This is intended for
6945 use only where it is known in advance that the package will not be
6946 ported to Windows, or any other operating system using extensions on
6947 executables.
6949 @item @option{no-installinfo}
6950 @cindex Option, @option{no-installinfo}
6951 @opindex no-installinfo
6952 The generated @file{Makefile.in} will not cause info pages to be built
6953 or installed by default.  However, @code{info} and @code{install-info}
6954 targets will still be available.  This option is disallowed at
6955 @option{gnu} strictness and above.
6956 @trindex info
6957 @trindex install-info
6959 @item @option{no-installman}
6960 @cindex Option, @option{no-installman}
6961 @opindex no-installman
6962 The generated @file{Makefile.in} will not cause man pages to be
6963 installed by default.  However, an @code{install-man} target will still
6964 be available for optional installation.  This option is disallowed at
6965 @option{gnu} strictness and above.
6966 @trindex install-man
6968 @item @option{nostdinc}
6969 @cindex Option, @option{nostdinc}
6970 @opindex nostdinc
6971 This option can be used to disable the standard @option{-I} options that
6972 are ordinarily automatically provided by Automake.
6974 @item @option{no-texinfo.tex}
6975 @cindex Option, @option{no-texinfo.tex}
6976 @opindex no-texinfo.tex
6977 Don't require @file{texinfo.tex}, even if there are texinfo files in
6978 this directory.
6980 @item @option{readme-alpha}
6981 @cindex Option, @option{readme-alpha}
6982 @opindex readme-alpha
6983 If this release is an alpha release, and the file @file{README-alpha}
6984 exists, then it will be added to the distribution.  If this option is
6985 given, version numbers are expected to follow one of two forms.  The
6986 first form is @samp{@var{MAJOR}.@var{MINOR}.@var{ALPHA}}, where each
6987 element is a number; the final period and number should be left off for
6988 non-alpha releases.  The second form is
6989 @samp{@var{MAJOR}.@var{MINOR}@var{ALPHA}}, where @var{ALPHA} is a
6990 letter; it should be omitted for non-alpha releases.
6992 @item @option{std-options}
6993 @cindex Options, @option{std-options}
6994 @cindex @samp{make installcheck}, testing @option{--help} and @option{--version}
6995 @cindex @option{--help} check
6996 @cindex @option{--version} check
6997 @opindex std-options
6999 Make the @code{installcheck} rule check that installed scripts and
7000 programs support the @option{--help} and @option{--version} options.
7001 This also provides a basic check that the program's
7002 run-time dependencies are satisfied after installation.
7004 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
7005 In a few situations, programs (or scripts) have to be exempted from this
7006 test.  For instance, @command{false} (from GNU sh-utils) is never
7007 successful, even for @option{--help} or @option{--version}.  You can list
7008 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
7009 Programs (not scripts) listed in this variable should be suffixed by
7010 @samp{$(EXEEXT)} for the sake of Win32 or OS/2.  For instance, suppose we
7011 build @file{false} as a program but @file{true.sh} as a script, and that
7012 neither of them support @option{--help} or @option{--version}:
7014 @example
7015 AUTOMAKE_OPTIONS = std-options
7016 bin_PROGRAMS = false ...
7017 bin_SCRIPTS = true.sh ...
7018 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
7019 @end example
7021 @item @option{subdir-objects}
7022 @cindex Options, @option{subdir-objects}
7023 @opindex subdir-objects
7024 If this option is specified, then objects are placed into the
7025 subdirectory of the build directory corresponding to the subdirectory of
7026 the source file.  For instance, if the source file is
7027 @file{subdir/file.cxx}, then the output file would be
7028 @file{subdir/file.o}.
7030 In order to use this option with C sources, you should add
7031 @code{AM_PROG_CC_C_O} to @file{configure.ac}.
7033 @item @option{tar-v7}
7034 @itemx @option{tar-ustar}
7035 @itemx @option{tar-pax}
7036 @cindex Option, @option{tar-v7}
7037 @cindex Option, @option{tar-ustar}
7038 @cindex Option, @option{tar-pax}
7039 @cindex @command{tar} formats
7040 @cindex v7 @command{tar} format
7041 @cindex ustar format
7042 @cindex pax format
7043 @opindex tar-v7
7044 @opindex tar-ustar
7045 @opindex tar-pax
7047 These three mutually exclusive options select the tar format to use
7048 when generating tarballs with @samp{make dist}.  (The tar file created
7049 is then compressed according to the set of @option{no-dist-gzip},
7050 @option{dist-bzip2} and @option{dist-tarZ} options in use.)
7052 These options must be passed as argument to @code{AM_INIT_AUTOMAKE}
7053 (@pxref{Macros}) because they can require additional configure checks.
7054 Automake will complain if it sees such options in an
7055 @code{AUTOMAKE_OPTIONS} variable.
7057 @option{tar-v7} selects the old V7 tar format.  This is the historical
7058 default.  This antiquated format is understood by all tar
7059 implementations and supports file names with up to 99 characters.  When
7060 given longer file names some tar implementations will diagnose the
7061 problem while other will generate broken tarballs or use non-portable
7062 extensions.  Furthermore, the V7 format cannot store empty
7063 directories.  When using this format, consider using the
7064 @option{filename-length-max=99} option to catch file names too long.
7066 @option{tar-ustar} selects the ustar format defined by POSIX
7067 1003.1-1988.  This format is believed to be old enough to be portable.
7068 It fully supports empty directories.  It can store file names with up
7069 to 256 characters, provided that the file name can be split at
7070 directory separator in two parts, first of them being at most 155
7071 bytes long.  So, in most cases the maximum file name length will be
7072 shorter than 256 characters.  However you may run against broken tar
7073 implementations that incorrectly handle file names longer than 99
7074 characters (please report them to @email{bug-automake@@gnu.org} so we
7075 can document this accurately).
7077 @option{tar-pax} selects the new pax interchange format defined by POSIX
7078 1003.1-2001.  It does not limit the length of file names.  However,
7079 this format is very young and should probably be restricted to
7080 packages that target only very modern platforms.  There are moves to
7081 change the pax format in an upward-compatible way, so this option may
7082 refer to a more recent version in the future.
7084 @xref{Formats, , Controlling the Archive Format, tar, GNU Tar}, for
7085 further discussion about tar formats.
7087 @command{configure} knows several ways to construct these formats.  It
7088 will not abort if it cannot find a tool up to the task (so that the
7089 package can still be built), but @samp{make dist} will fail.
7091 @item @var{version}
7092 @cindex Option, @var{version}
7093 A version number (e.g., @samp{0.30}) can be specified.  If Automake is not
7094 newer than the version specified, creation of the @file{Makefile.in}
7095 will be suppressed.
7097 @item @option{-W@var{category}} or @option{--warnings=@var{category}}
7098 @cindex Option, warnings
7099 @cindex Option, @option{-W@var{category}}
7100 @cindex Option, @option{--warnings=@var{category}}
7101 These options behave exactly like their command-line counterpart
7102 (@pxref{Invoking Automake}).  This allows you to enable or disable some
7103 warning categories on a per-file basis.  You can also setup some warnings
7104 for your entire project; for instance, try @samp{AM_INIT_AUTOMAKE([-Wall])}
7105 in your @file{configure.ac}.
7107 @end table
7109 Unrecognized options are diagnosed by @command{automake}.
7111 If you want an option to apply to all the files in the tree, you can use
7112 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.ac}.
7113 @xref{Macros}.
7116 @node Miscellaneous
7117 @chapter Miscellaneous Rules
7119 There are a few rules and variables that didn't fit anywhere else.
7121 @menu
7122 * Tags::                        Interfacing to etags and mkid
7123 * Suffixes::                    Handling new file extensions
7124 * Multilibs::                   Support for multilibs.
7125 @end menu
7128 @node Tags
7129 @section Interfacing to @command{etags}
7131 @cindex @file{TAGS} support
7133 Automake will generate rules to generate @file{TAGS} files for use with
7134 GNU Emacs under some circumstances.
7136 @trindex tags
7137 If any C, C++ or Fortran 77 source code or headers are present, then
7138 @code{tags} and @code{TAGS} rules will be generated for the directory.
7139 All files listed using the @code{_SOURCES}, @code{_HEADERS}, and
7140 @code{_LISP} primaries will be used to generate tags.  Note that
7141 generated source files that are not distributed must be declared in
7142 variables like @code{nodist_noinst_HEADERS} or
7143 @code{nodist_@var{prog}_SOURCES} or they will be ignored.
7145 A @code{tags} rule will be output at the topmost directory of a
7146 multi-directory package.  When run from this topmost directory,
7147 @samp{make tags} will generate a @file{TAGS} file that includes by
7148 reference all @file{TAGS} files from subdirectories.
7150 The @code{tags} rule will also be generated if the variable
7151 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
7152 directories that contain taggable source that @command{etags} does
7153 not understand.  The user can use the @code{ETAGSFLAGS} to pass
7154 additional flags to @command{etags}; @code{AM_ETAGSFLAGS} is also
7155 available for use in @file{Makefile.am}.
7156 @vindex ETAGS_ARGS
7157 @vindex ETAGSFLAGS
7158 @vindex AM_ETAGSFLAGS
7160 Here is how Automake generates tags for its source, and for nodes in its
7161 Texinfo file:
7163 @example
7164 ETAGS_ARGS = automake.in --lang=none \
7165  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
7166 @end example
7168 If you add file names to @code{ETAGS_ARGS}, you will probably also
7169 want to define @code{TAGS_DEPENDENCIES}.  The contents of this variable
7170 are added directly to the dependencies for the @code{tags} rule.
7171 @vindex TAGS_DEPENDENCIES
7173 Automake also generates a @code{ctags} rule that can be used to
7174 build @command{vi}-style @file{tags} files.  The variable @code{CTAGS}
7175 is the name of the program to invoke (by default @command{ctags});
7176 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
7177 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
7179 Automake will also generate an @code{ID} rule that will run
7180 @command{mkid} on the source.  This is only supported on a
7181 directory-by-directory basis.
7182 @trindex id
7184 Finally, Automake also emit rules to support the
7185 @uref{http://www.gnu.org/software/global/, GNU Global Tags program}.
7186 The @code{GTAGS} rule runs Global Tags and puts the
7187 result in the top build directory.  The variable @code{GTAGS_ARGS}
7188 holds arguments that are passed to @command{gtags}.
7189 @vindex GTAGS_ARGS
7192 @node Suffixes
7193 @section Handling new file extensions
7195 @cindex Adding new @code{SUFFIXES}
7196 @cindex @code{SUFFIXES}, adding
7197 @vindex SUFFIXES
7199 It is sometimes useful to introduce a new implicit rule to handle a file
7200 type that Automake does not know about.
7202 For instance, suppose you had a compiler that could compile @file{.foo}
7203 files to @file{.o} files.  You would simply define an suffix rule for
7204 your language:
7206 @example
7207 .foo.o:
7208         foocc -c -o $@@ $<
7209 @end example
7211 Then you could directly use a @file{.foo} file in a @code{_SOURCES}
7212 variable and expect the correct results:
7214 @example
7215 bin_PROGRAMS = doit
7216 doit_SOURCES = doit.foo
7217 @end example
7219 This was the simpler and more common case.  In other cases, you will
7220 have to help Automake to figure which extensions you are defining your
7221 suffix rule for.  This usually happens when your extensions does not
7222 start with a dot.  Then, all you have to do is to put a list of new
7223 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
7224 implicit rule.
7226 For instance, the following definition prevents Automake to misinterpret
7227 @samp{.idlC.cpp:} as an attempt to transform @file{.idlC} files into
7228 @file{.cpp} files.
7230 @example
7231 SUFFIXES = .idl C.cpp
7232 .idlC.cpp:
7233         # whatever
7234 @end example
7236 As you may have noted, the @code{SUFFIXES} variable behaves like the
7237 @code{.SUFFIXES} special target of @command{make}.  You should not touch
7238 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
7239 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
7240 @code{SUFFIXES} go at the start of the generated suffixes list, followed
7241 by Automake generated suffixes not already in the list.
7243 @node Multilibs
7244 @section Support for Multilibs
7246 Automake has support for an obscure feature called multilibs.  A
7247 @dfn{multilib} is a library that is built for multiple different ABIs
7248 at a single time; each time the library is built with a different target
7249 flag combination.  This is only useful when the library is intended to
7250 be cross-compiled, and it is almost exclusively used for compiler
7251 support libraries.
7253 The multilib support is still experimental.  Only use it if you are
7254 familiar with multilibs and can debug problems you might encounter.
7257 @node Include
7258 @chapter Include
7260 @cmindex include
7261 @cindex Including @file{Makefile} fragment
7262 @cindex @file{Makefile} fragment, including
7264 Automake supports an @code{include} directive that  can be used to
7265 include other @file{Makefile} fragments when @command{automake} is run.
7266 Note that these fragments are read and interpreted by @command{automake},
7267 not by @command{make}.  As with conditionals, @command{make} has no idea that
7268 @code{include} is in use.
7270 There are two forms of @code{include}:
7272 @table @code
7273 @item include $(srcdir)/file
7274 Include a fragment that is found relative to the current source
7275 directory.
7277 @item include $(top_srcdir)/file
7278 Include a fragment that is found relative to the top source directory.
7279 @end table
7281 Note that if a fragment is included inside a conditional, then the
7282 condition applies to the entire contents of that fragment.
7284 Makefile fragments included this way are always distributed because
7285 they are needed to rebuild @file{Makefile.in}.
7287 @node Conditionals
7288 @chapter Conditionals
7290 @cindex Conditionals
7292 Automake supports a simple type of conditionals.
7294 @acindex AM_CONDITIONAL
7295 Before using a conditional, you must define it by using
7296 @code{AM_CONDITIONAL} in the @file{configure.ac} file (@pxref{Macros}).
7298 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
7299 The conditional name, @var{conditional}, should be a simple string
7300 starting with a letter and containing only letters, digits, and
7301 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
7302 that are reserved by Automake.
7304 The shell @var{condition} (suitable for use in a shell @code{if}
7305 statement) is evaluated when @command{configure} is run.  Note that you
7306 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
7307 time @command{configure} is run.  If @code{AM_CONDITIONAL} is run
7308 conditionally (e.g., in a shell @code{if} statement), then the result
7309 will confuse automake.
7310 @end defmac
7312 @cindex @option{--enable-debug}, example
7313 @cindex Example conditional @option{--enable-debug}
7314 @cindex Conditional example, @option{--enable-debug}
7316 Conditionals typically depend upon options that the user provides to
7317 the @command{configure} script.  Here is an example of how to write a
7318 conditional that is true if the user uses the @option{--enable-debug}
7319 option.
7321 @example
7322 AC_ARG_ENABLE(debug,
7323 [  --enable-debug    Turn on debugging],
7324 [case "$@{enableval@}" in
7325   yes) debug=true ;;
7326   no)  debug=false ;;
7327   *) AC_MSG_ERROR(bad value $@{enableval@} for --enable-debug) ;;
7328 esac],[debug=false])
7329 AM_CONDITIONAL(DEBUG, test x$debug = xtrue)
7330 @end example
7332 Here is an example of how to use that conditional in @file{Makefile.am}:
7334 @cmindex if
7335 @cmindex endif
7336 @cmindex else
7338 @example
7339 if DEBUG
7340 DBG = debug
7341 else
7342 DBG =
7343 endif
7344 noinst_PROGRAMS = $(DBG)
7345 @end example
7347 This trivial example could also be handled using @code{EXTRA_PROGRAMS}
7348 (@pxref{Conditional Programs}).
7350 You may only test a single variable in an @code{if} statement, possibly
7351 negated using @samp{!}.  The @code{else} statement may be omitted.
7352 Conditionals may be nested to any depth.  You may specify an argument to
7353 @code{else} in which case it must be the negation of the condition used
7354 for the current @code{if}.  Similarly you may specify the condition
7355 that is closed by an @code{end}:
7357 @example
7358 if DEBUG
7359 DBG = debug
7360 else !DEBUG
7361 DBG =
7362 endif !DEBUG
7363 @end example
7365 @noindent
7366 Unbalanced conditions are errors.
7368 Note that conditionals in Automake are not the same as conditionals in
7369 GNU Make.  Automake conditionals are checked at configure time by the
7370 @file{configure} script, and affect the translation from
7371 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
7372 to @file{configure} and on results that @file{configure} has discovered
7373 about the host system.  GNU Make conditionals are checked at @command{make}
7374 time, and are based on variables passed to the make program or defined
7375 in the @file{Makefile}.
7377 Automake conditionals will work with any make program.
7380 @node Gnits
7381 @chapter The effect of @option{--gnu} and @option{--gnits}
7383 @cindex @option{--gnu}, required files
7384 @cindex @option{--gnu}, complete description
7386 The @option{--gnu} option (or @option{gnu} in the
7387 @code{AUTOMAKE_OPTIONS} variable) causes @command{automake} to check
7388 the following:
7390 @itemize @bullet
7391 @item
7392 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
7393 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
7394 or @file{COPYING}, are required at the topmost directory of the package.
7396 @item
7397 The options @option{no-installman} and @option{no-installinfo} are
7398 prohibited.
7399 @end itemize
7401 Note that this option will be extended in the future to do even more
7402 checking; it is advisable to be familiar with the precise requirements
7403 of the GNU standards.  Also, @option{--gnu} can require certain
7404 non-standard GNU programs to exist for use by various maintainer-only
7405 rules; for instance, in the future @command{pathchk} might be required for
7406 @samp{make dist}.
7408 @cindex @option{--gnits}, complete description
7410 The @option{--gnits} option does everything that @option{--gnu} does, and
7411 checks the following as well:
7413 @itemize @bullet
7414 @item
7415 @samp{make installcheck} will check to make sure that the @option{--help}
7416 and @option{--version} really print a usage message and a version string,
7417 respectively.  This is the @option{std-options} option (@pxref{Options}).
7419 @item
7420 @samp{make dist} will check to make sure the @file{NEWS} file has been
7421 updated to the current version.
7423 @item
7424 @code{VERSION} is checked to make sure its format complies with Gnits
7425 standards.
7426 @c FIXME xref when standards are finished
7428 @item
7429 @cindex @file{README-alpha}
7430 If @code{VERSION} indicates that this is an alpha release, and the file
7431 @file{README-alpha} appears in the topmost directory of a package, then
7432 it is included in the distribution.  This is done in @option{--gnits}
7433 mode, and no other, because this mode is the only one where version
7434 number formats are constrained, and hence the only mode where Automake
7435 can automatically determine whether @file{README-alpha} should be
7436 included.
7438 @item
7439 The file @file{THANKS} is required.
7440 @end itemize
7443 @node Cygnus
7444 @chapter The effect of @option{--cygnus}
7446 @cindex @option{cygnus} strictness
7448 Some packages, notably GNU GCC and GNU gdb, have a build environment
7449 originally written at Cygnus Support (subsequently renamed Cygnus
7450 Solutions, and then later purchased by Red Hat).  Packages with this
7451 ancestry are sometimes referred to as ``Cygnus'' trees.
7453 A Cygnus tree has slightly different rules for how a
7454 @file{Makefile.in} is to be constructed.  Passing @option{--cygnus} to
7455 @command{automake} will cause any generated @file{Makefile.in} to
7456 comply with Cygnus rules.
7458 Here are the precise effects of @option{--cygnus}:
7460 @itemize @bullet
7461 @item
7462 Info files are always created in the build directory, and not in the
7463 source directory.
7465 @item
7466 @file{texinfo.tex} is not required if a Texinfo source file is
7467 specified.  The assumption is that the file will be supplied, but in a
7468 place that Automake cannot find.  This assumption is an artifact of how
7469 Cygnus packages are typically bundled.
7471 @item
7472 @samp{make dist} is not supported, and the rules for it are not
7473 generated.  Cygnus-style trees use their own distribution mechanism.
7475 @item
7476 Certain tools will be searched for in the build tree as well as in the
7477 user's @env{PATH}.  These tools are @command{runtest}, @command{expect},
7478 @command{makeinfo} and @command{texi2dvi}.
7480 @item
7481 @option{--foreign} is implied.
7483 @item
7484 The options @option{no-installinfo} and @option{no-dependencies} are
7485 implied.
7487 @item
7488 The macros @code{AM_MAINTAINER_MODE} and @code{AM_CYGWIN32} are
7489 required.
7491 @item
7492 The @code{check} target doesn't depend on @code{all}.
7493 @end itemize
7495 GNU maintainers are advised to use @option{gnu} strictness in preference
7496 to the special Cygnus mode.  Some day, perhaps, the differences between
7497 Cygnus trees and GNU trees will disappear (for instance, as GCC is made
7498 more standards compliant).  At that time the special Cygnus mode will be
7499 removed.
7502 @node Not Enough
7503 @chapter When Automake Isn't Enough
7505 In some situations, where Automake is not up to one task, one has to
7506 resort to handwritten rules or even handwritten @file{Makefile}s.
7508 @menu
7509 * Extending::                   Adding new rules or overriding existing ones.
7510 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
7511 @end menu
7513 @node Extending
7514 @section Extending Automake Rules
7516 With some minor exceptions (like @code{_PROGRAMS} variables being
7517 rewritten to append @samp{$(EXEEXT)}), the contents of a
7518 @file{Makefile.am} is copied to @file{Makefile.in} verbatim.
7520 @cindex copying semantics
7522 These copying semantics means that many problems can be worked around
7523 by simply adding some @command{make} variables and rules to
7524 @file{Makefile.am}.  Automake will ignore these additions.
7526 @cindex conflicting definitions
7527 @cindex rules, conflicting
7528 @cindex variables, conflicting
7529 @cindex definitions, conflicts
7531 Since a @file{Makefile.in} is built from data gathered from three
7532 different places (@file{Makefile.am}, @file{configure.ac}, and
7533 @command{automake} itself), it is possible to have conflicting
7534 definitions of rules or variables.  When building @file{Makefile.in}
7535 the following priorities are respected by @command{automake} to ensure
7536 the user always have the last word.  User defined variables in
7537 @file{Makefile.am} have priority over variables @code{AC_SUBST}ed from
7538 @file{configure.ac}, and @code{AC_SUBST}ed variables have priority
7539 over @command{automake}-defined variables.  As far rules are
7540 concerned, a user-defined rule overrides any
7541 @command{automake}-defined rule for the same target.
7543 @cindex overriding rules
7544 @cindex overriding semantics
7545 @cindex rules, overriding
7547 These overriding semantics make it possible to fine tune some default
7548 settings of Automake, or replace some of its rules.  Overriding
7549 Automake rules is often inadvisable, particularly in the topmost
7550 directory of a package with subdirectories.  The @option{-Woverride}
7551 option (@pxref{Invoking Automake}) comes handy to catch overridden
7552 definitions.
7554 Note that Automake does not make any difference between rules with
7555 commands and rules that only specify dependencies.  So it is not
7556 possible to append new dependencies to an @command{automake}-defined
7557 target without redefining the entire rule.
7559 @cindex @option{-local} targets
7560 @cindex local targets
7562 However, various useful targets have a @samp{-local} version you can
7563 specify in your @file{Makefile.am}.  Automake will supplement the
7564 standard target with these user-supplied targets.
7566 @trindex  all
7567 @trindex  all-local
7568 @trindex  info
7569 @trindex  info-local
7570 @trindex  dvi
7571 @trindex  dvi-local
7572 @trindex  ps
7573 @trindex  ps-local
7574 @trindex  pdf
7575 @trindex  pdf-local
7576 @trindex  html
7577 @trindex  html-local
7578 @trindex  check
7579 @trindex  check-local
7580 @trindex  install
7581 @trindex  install-data
7582 @trindex  install-data-local
7583 @trindex  install-dvi
7584 @trindex  install-dvi-local
7585 @trindex  install-exec
7586 @trindex  install-exec-local
7587 @trindex  install-html
7588 @trindex  install-html-local
7589 @trindex  install-info
7590 @trindex  install-info-local
7591 @trindex  install-pdf
7592 @trindex  install-pdf-local
7593 @trindex  install-ps
7594 @trindex  install-ps-local
7595 @trindex  uninstall
7596 @trindex  uninstall-local
7597 @trindex  mostlyclean
7598 @trindex  mostlyclean-local
7599 @trindex  clean
7600 @trindex  clean-local
7601 @trindex  distclean
7602 @trindex  distclean-local
7603 @trindex  installdirs
7604 @trindex  installdirs-local
7605 @trindex  installcheck
7606 @trindex  installcheck-local
7608 The targets that support a local version are @code{all}, @code{info},
7609 @code{dvi}, @code{ps}, @code{pdf}, @code{html}, @code{check},
7610 @code{install-data}, @code{install-dvi}, @code{install-exec},
7611 @code{install-html}, @code{install-info}, @code{install-pdf},
7612 @code{install-ps}, @code{uninstall}, @code{installdirs},
7613 @code{installcheck} and the various @code{clean} targets
7614 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
7615 @code{maintainer-clean}).
7617 Note that there are no @code{uninstall-exec-local} or
7618 @code{uninstall-data-local} targets; just use @code{uninstall-local}.
7619 It doesn't make sense to uninstall just data or just executables.
7621 For instance, here is one way to erase a subdirectory during
7622 @samp{make clean} (@pxref{Clean}).
7624 @example
7625 clean-local:
7626         -rm -rf testSubDir
7627 @end example
7629 Older version of this manual used to show how to use
7630 @code{install-data-local} to install a file to some hard-coded
7631 location, but you should avoid this.  (@pxref{Hard-Coded Install Paths})
7633 @cindex @option{-hook} targets
7634 @cindex hook targets
7636 Some rule also have a way to run another rule, called a @dfn{hook},
7637 after their work is done.  The hook is named after the principal target,
7638 with @samp{-hook} appended.  The targets allowing hooks are
7639 @code{install-data}, @code{install-exec}, @code{uninstall}, @code{dist},
7640 and @code{distcheck}.
7641 @trindex install-data-hook
7642 @trindex install-exec-hook
7643 @trindex uninstall-hook
7644 @trindex dist-hook
7646 For instance, here is how to create a hard link to an installed program:
7648 @example
7649 install-exec-hook:
7650         ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
7651            $(DESTDIR)$(bindir)/proglink$(EXEEXT)
7652 @end example
7654 Although cheaper and more portable than symbolic links, hard links
7655 will not work everywhere (for instance, OS/2 does not have
7656 @command{ln}).  Ideally you should fall back to @samp{cp -p} when
7657 @command{ln} does not work.  An easy way, if symbolic links are
7658 acceptable to you, is to add @code{AC_PROG_LN_S} to
7659 @file{configure.ac} (@pxref{Particular Programs, , Particular Program
7660 Checks, autoconf, The Autoconf Manual}) and use @samp{$(LN_S)} in
7661 @file{Makefile.am}.
7663 @cindex versioned binaries, installing
7664 @cindex installing versioned binaries
7665 @cindex @code{LN_S} example
7666 For instance, here is how you could install a versioned copy of a
7667 program using @samp{$(LN_S)}:
7669 @example
7670 install-exec-hook:
7671         cd $(DESTDIR)$(bindir) && \
7672           mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
7673           $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
7674 @end example
7676 Note that we rename the program so that a new version will erase the
7677 symbolic link, not the real binary.  Also we @command{cd} into the
7678 destination directory in order to create relative links.
7680 When writing @code{install-exec-hook} or @code{install-data-hook},
7681 please bear in mind that the exec/data distinction is based on the
7682 installation directory, not on the primary used (@pxref{Install}).  So
7683 a @code{foo_SCRIPTS} will be installed by @code{install-data}, and a
7684 @code{barexec_SCRIPTS} will be installed by @code{install-exec}.  You
7685 should define your hooks consequently.
7687 @c FIXME should include discussion of variables you can use in these
7688 @c rules
7690 @node Third-Party Makefiles
7691 @section Third-Party @file{Makefile}s
7693 @cindex Third-party packages, interfacing with
7694 @cindex Interfacing with third-party packages
7696 In most projects all @file{Makefile}s are generated by Automake.  In
7697 some cases, however, projects need to embed subdirectories with
7698 handwritten @file{Makefile}s.  For instance, one subdirectory could be
7699 a third-party project with its own build system, not using Automake.
7701 It is possible to list arbitrary directories in @code{SUBDIRS} or
7702 @code{DIST_SUBDIRS} provided each of these directories has a
7703 @file{Makefile} that recognizes all the following recursive targets.
7705 @cindex recursive targets and third-party @file{Makefile}s
7706 When a user runs one of these targets, that target is run recursively
7707 in all subdirectories.  This is why it is important that even
7708 third-party @file{Makefile}s support them.
7710 @table @code
7711 @item all
7712 Compile the entire package.  This is the default target in
7713 Automake-generated @file{Makefile}s, but it does not need to be the
7714 default in third-party @file{Makefile}s.
7716 @item distdir
7717 @trindex distdir
7718 @vindex distdir
7719 @vindex top_distdir
7720 Copy files to distribute into @samp{$(distdir)}, before a tarball is
7721 constructed.  Of course this target is not required if the
7722 @option{no-dist} option (@pxref{Options}) is used.
7724 The variables @samp{$(top_distdir)} and @samp{$(distdir)}
7725 (@pxref{Dist}) will be passed from the outer package to the subpackage
7726 when the @code{distdir} target is invoked.  These two variables have
7727 been adjusted for the directory that is being recursed into, so they
7728 are ready to use.
7730 @item install
7731 @itemx install-data
7732 @itemx install-exec
7733 @itemx uninstall
7734 Install or uninstall files (@pxref{Install}).
7736 @item install-dvi
7737 @itemx install-html
7738 @itemx install-info
7739 @itemx install-ps
7740 @itemx install-pdf
7741 Install only some specific documentation format (@pxref{Texinfo}).
7743 @item installdirs
7744 Create install directories, but do not install any files.
7746 @item check
7747 @itemx installcheck
7748 Check the package (@pxref{Tests}).
7750 @item mostlyclean
7751 @itemx clean
7752 @itemx distclean
7753 @itemx maintainer-clean
7754 Cleaning rules (@pxref{Clean}).
7756 @item dvi
7757 @itemx pdf
7758 @itemx ps
7759 @itemx info
7760 @itemx html
7761 Build the documentation in various formats (@pxref{Texinfo}).
7763 @item tags
7764 @itemx ctags
7765 Build @file{TAGS} and @file{CTAGS} (@pxref{Tags}).
7766 @end table
7768 If you have ever used Gettext in a project, this is a good example of
7769 how third-party @file{Makefile}s can be used with Automake.  The
7770 @file{Makefile}s @command{gettextize} puts in the @file{po/} and
7771 @file{intl/} directories are handwritten @file{Makefile}s that
7772 implement all these targets.  That way they can be added to
7773 @code{SUBDIRS} in Automake packages.
7775 Directories that are only listed in @code{DIST_SUBDIRS} but not in
7776 @code{SUBDIRS} need only the @code{distclean},
7777 @code{maintainer-clean}, and @code{distdir} rules (@pxref{Conditional
7778 Subdirectories}).
7780 Usually, many of these rules are irrelevant to the third-party
7781 subproject, but they are required for the whole package to work.  It's
7782 OK to have a rule that does nothing, so if you are integrating a
7783 third-party project with no documentation or tag support, you could
7784 simply augment its @file{Makefile} as follows:
7786 @example
7787 EMPTY_AUTOMAKE_TARGETS = dvi pdf ps info html tags ctags
7788 .PHONY: $(EMPTY_AUTOMAKE_TARGETS)
7789 $(EMPTY_AUTOMAKE_TARGETS):
7790 @end example
7792 Another aspect of integrating third-party build systems is whether
7793 they support VPATH builds.  Obviously if the subpackage does not
7794 support VPATH builds the whole package will not support VPATH builds.
7795 This in turns means that @samp{make distcheck} will not work, because
7796 it relies on VPATH builds.  Some people can live without this
7797 (actually, many Automake users have never heard of @samp{make
7798 distcheck}).  Other people may prefer to revamp the existing
7799 @file{Makefile}s to support VPATH@.  Doing so does not necessarily
7800 require Automake, only Autoconf is needed (@pxref{Build Directories, ,
7801 Build Directories, autoconf, The Autoconf Manual}).  The necessary
7802 substitutions: @samp{@@scrdir@@}, @samp{@@top_srcdir@@}, and
7803 @samp{@@top_builddir@@} are defined by @file{configure} when it
7804 processes a @file{Makefile} (@pxref{Preset Output Variables, , Preset
7805 Output Variables, autoconf, The Autoconf Manual}), they are not
7806 computed by the Makefile like the aforementioned @samp{$(distdir)} and
7807 @samp{$(top_distdir)} variables..
7809 It is sometimes inconvenient to modify a third-party @file{Makefile}
7810 to introduce the above required targets.  For instance, one may want to
7811 keep the third-party sources untouched to ease upgrades to new
7812 versions.
7814 @cindex @file{GNUmakefile} including @file{Makefile}
7815 Here are two other ideas.  If GNU make is assumed, one possibility is
7816 to add to that subdirectory a @file{GNUmakefile} that defines the
7817 required targets and include the third-party @file{Makefile}.  For
7818 this to work in VPATH builds, @file{GNUmakefile} must lie in the build
7819 directory; the easiest way to do this is to write a
7820 @file{GNUmakefile.in} instead, and have it processed with
7821 @code{AC_CONFIG_FILES} from the outer package.  For example if we
7822 assume @file{Makefile} defines all targets except the documentation
7823 targets, and that the @code{check} target is actually called
7824 @code{test}, we could write @file{GNUmakefile} (or
7825 @file{GNUmakefile.in}) like this:
7827 @example
7828 # First, include the real Makefile
7829 include Makefile
7830 # Then, define the other targets needed by Automake Makefiles.
7831 .PHONY: dvi pdf ps info html check
7832 dvi pdf ps info html:
7833 check: test
7834 @end example
7836 @cindex Proxy @file{Makefile} for third-party packages
7837 A similar idea that does not use @code{include} is to write a proxy
7838 @file{Makefile} that dispatches rules to the real @file{Makefile},
7839 either with @samp{$(MAKE) -f Makefile.real $(AM_MAKEFLAGS) target} (if
7840 it's OK to rename the original @file{Makefile}) or with @samp{cd
7841 subdir && $(MAKE) $(AM_MAKEFLAGS) target} (if it's OK to store the
7842 subdirectory project one directory deeper).  The good news is that
7843 this proxy @file{Makefile} can be generated with Automake.  All we
7844 need are @option{-local} targets (@pxref{Extending}) that perform the
7845 dispatch.  Of course the other Automake features are available, so you
7846 could decide to let Automake perform distribution or installation.
7847 Here is a possible @file{Makefile.am}:
7849 @example
7850 all-local:
7851         cd subdir && $(MAKE) $(AM_MAKEFLAGS) all
7852 check-local:
7853         cd subdir && $(MAKE) $(AM_MAKEFLAGS) test
7854 clean-local:
7855         cd subdir && $(MAKE) $(AM_MAKEFLAGS) clean
7857 # Assuming the package knows how to install itself
7858 install-data-local:
7859         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-data
7860 install-exec-local:
7861         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-exec
7862 uninstall-local:
7863         cd subdir && $(MAKE) $(AM_MAKEFLAGS) uninstall
7865 # Distribute files from here.
7866 EXTRA_DIST = subdir/Makefile subdir/program.c ...
7867 @end example
7869 Pushing this idea to the extreme, it is also possible to ignore the
7870 subproject build system and build everything from this proxy
7871 @file{Makefile.am}.  This might sounds very sensible if you need VPATH
7872 builds but the subproject does not support them.
7874 @node Distributing
7875 @chapter Distributing @file{Makefile.in}s
7877 Automake places no restrictions on the distribution of the resulting
7878 @file{Makefile.in}s.  We still encourage software authors to
7879 distribute their work under terms like those of the GPL, but doing so
7880 is not required to use Automake.
7882 Some of the files that can be automatically installed via the
7883 @option{--add-missing} switch do fall under the GPL@.  However, these also
7884 have a special exception allowing you to distribute them with your
7885 package, regardless of the licensing you choose.
7888 @node API versioning
7889 @chapter Automake API versioning
7891 New Automake releases usually include bug fixes and new features.
7892 Unfortunately they may also introduce new bugs and incompatibilities.
7893 This makes four reasons why a package may require a particular Automake
7894 version.
7896 Things get worse when maintaining a large tree of packages, each one
7897 requiring a different version of Automake.  In the past, this meant that
7898 any developer (and sometime users) had to install several versions of
7899 Automake in different places, and switch @samp{$PATH} appropriately for
7900 each package.
7902 Starting with version 1.6, Automake installs versioned binaries.  This
7903 means you can install several versions of Automake in the same
7904 @samp{$prefix}, and can select an arbitrary Automake version by running
7905 @command{automake-1.6} or @command{automake-1.7} without juggling with
7906 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
7907 will use @command{automake-1.6} explicitly in their rebuild rules.
7909 The number @samp{1.6} in @command{automake-1.6} is Automake's API version,
7910 not Automake's version.  If a bug fix release is made, for instance
7911 Automake 1.6.1, the API version will remain 1.6.  This means that a
7912 package that works with Automake 1.6 should also work with 1.6.1; after
7913 all, this is what people expect from bug fix releases.
7915 If your package relies on a feature or a bug fix introduced in
7916 a release, you can pass this version as an option to Automake to ensure
7917 older releases will not be used.  For instance, use this in your
7918 @file{configure.ac}:
7920 @example
7921   AM_INIT_AUTOMAKE(1.6.1)    dnl Require Automake 1.6.1 or better.
7922 @end example
7923 @noindent
7924 or, in a particular @file{Makefile.am}:
7926 @example
7927   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
7928 @end example
7929 @noindent
7930 Automake will print an error message if its version is
7931 older than the requested version.
7934 @heading What is in the API
7936 Automake's programming interface is not easy to define.  Basically it
7937 should include at least all @strong{documented} variables and targets
7938 that a @file{Makefile.am} author can use, any behavior associated with
7939 them (e.g., the places where @samp{-hook}'s are run), the command line
7940 interface of @command{automake} and @command{aclocal}, @dots{}
7942 @heading What is not in the API
7944 Every undocumented variable, target, or command line option, is not part
7945 of the API@.  You should avoid using them, as they could change from one
7946 version to the other (even in bug fix releases, if this helps to fix a
7947 bug).
7949 If it turns out you need to use such a undocumented feature, contact
7950 @email{automake@@gnu.org} and try to get it documented and exercised by
7951 the test-suite.
7953 @node Upgrading
7954 @chapter Upgrading a Package to a Newer Automake Version
7956 Automake maintains three kind of files in a package.
7958 @itemize
7959 @item @file{aclocal.m4}
7960 @item @file{Makefile.in}s
7961 @item auxiliary tools like @file{install-sh} or @file{py-compile}
7962 @end itemize
7964 @file{aclocal.m4} is generated by @command{aclocal} and contains some
7965 Automake-supplied M4 macros.  Auxiliary tools are installed by
7966 @samp{automake --add-missing} when needed.  @file{Makefile.in}s are
7967 built from @file{Makefile.am} by @command{automake}, and rely on the
7968 definitions of the M4 macros put in @file{aclocal.m4} as well as the
7969 behavior of the auxiliary tools installed.
7971 Because all these files are closely related, it is important to
7972 regenerate all of them when upgrading to a newer Automake release.
7973 The usual way to do that is
7975 @example
7976 aclocal # with any option needed (such a -I m4)
7977 autoconf
7978 automake --add-missing --force-missing
7979 @end example
7981 @noindent
7982 or more conveniently:
7984 @example
7985 autoreconf -vfi
7986 @end example
7988 The use of @option{--force-missing} ensures that auxiliary tools will be
7989 overridden by new versions (@pxref{Invoking Automake}).
7991 It is important to regenerate all these files each time Automake is
7992 upgraded, even between bug fixes releases.  For instance, it is not
7993 unusual for a bug fix to involve changes to both the rules generated
7994 in @file{Makefile.in} and the supporting M4 macros copied to
7995 @file{aclocal.m4}.
7997 Presently @command{automake} is able to diagnose situations where
7998 @file{aclocal.m4} has been generated with another version of
7999 @command{aclocal}.  However it never checks whether auxiliary scripts
8000 are up-to-date.  In other words, @command{automake} will tell you when
8001 @command{aclocal} needs to be rerun, but it will never diagnose a
8002 missing @option{--force-missing}.
8004 Before upgrading to a new major release, it is a good idea to read the
8005 file @file{NEWS}.  This file lists all changes between releases: new
8006 features, obsolete constructs, known incompatibilities, and
8007 workarounds.
8009 @node FAQ
8010 @chapter Frequently Asked Questions about Automake
8012 This chapter covers some questions that often come up on the mailing
8013 lists.
8015 @menu
8016 * CVS::                         CVS and generated files
8017 * maintainer-mode::             missing and AM_MAINTAINER_MODE
8018 * wildcards::                   Why doesn't Automake support wildcards?
8019 * distcleancheck::              Files left in build directory after distclean
8020 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
8021 * renamed objects::             Why are object files sometimes renamed?
8022 * Per-Object Flags::            How to simulate per-object flags?
8023 * Multiple Outputs::            Writing rules for tools with many output files
8024 * Hard-Coded Install Paths::    Installing to Hard-Coded Locations
8025 @end menu
8027 @node CVS
8028 @section CVS and generated files
8030 @subsection Background: distributed generated files
8031 @cindex generated files, distributed
8032 @cindex rebuild rules
8034 Packages made with Autoconf and Automake ship with some generated
8035 files like @file{configure} or @file{Makefile.in}.  These files were
8036 generated on the developer's host and are distributed so that
8037 end-users do not have to install the maintainer tools required to
8038 rebuild them.  Other generated files like Lex scanners, Yacc parsers,
8039 or Info documentation, are usually distributed on similar grounds.
8041 Automake outputs rules in @file{Makefile}s to rebuild these files.  For
8042 instance, @command{make} will run @command{autoconf} to rebuild
8043 @file{configure} whenever @file{configure.ac} is changed.  This makes
8044 development safer by ensuring a @file{configure} is never out-of-date
8045 with respect to @file{configure.ac}.
8047 As generated files shipped in packages are up-to-date, and because
8048 @command{tar} preserves times-tamps, these rebuild rules are not
8049 triggered when a user unpacks and builds a package.
8051 @subsection Background: CVS and timestamps
8052 @cindex timestamps and CVS
8053 @cindex CVS and timestamps
8055 Unless you use CVS keywords (in which case files must be updated at
8056 commit time), CVS preserves timestamp during @samp{cvs commit} and
8057 @samp{cvs import -d} operations.
8059 When you check out a file using @samp{cvs checkout} its timestamp is
8060 set to that of the revision that is being checked out.
8062 However, during @command{cvs update}, files will have the date of the
8063 update, not the original timestamp of this revision.  This is meant to
8064 make sure that @command{make} notices sources files have been updated.
8066 This timestamp shift is troublesome when both sources and generated
8067 files are kept under CVS@.  Because CVS processes files in alphabetical
8068 order, @file{configure.ac} will appear older than @file{configure}
8069 after a @command{cvs update} that updates both files, even if
8070 @file{configure} was newer than @file{configure.ac} when it was
8071 checked in.  Calling @command{make} will then trigger a spurious rebuild
8072 of @file{configure}.
8074 @subsection Living with CVS in Autoconfiscated projects
8075 @cindex CVS and generated files
8076 @cindex generated files and CVS
8078 There are basically two clans amongst maintainers: those who keep all
8079 distributed files under CVS, including generated files, and those who
8080 keep generated files @emph{out} of CVS.
8082 @subsubheading All files in CVS
8084 @itemize @bullet
8085 @item
8086 The CVS repository contains all distributed files so you know exactly
8087 what is distributed, and you can checkout any prior version entirely.
8089 @item
8090 Maintainers can see how generated files evolve (for instance, you can
8091 see what happens to your @file{Makefile.in}s when you upgrade Automake
8092 and make sure they look OK).
8094 @item
8095 Users do not need the autotools to build a checkout of the project, it
8096 works just like a released tarball.
8098 @item
8099 If users use @command{cvs update} to update their copy, instead of
8100 @command{cvs checkout} to fetch a fresh one, timestamps will be
8101 inaccurate.  Some rebuild rules will be triggered and attempt to
8102 run developer tools such as @command{autoconf} or @command{automake}.
8104 Actually, calls to such tools are all wrapped into a call to the
8105 @command{missing} script discussed later (@pxref{maintainer-mode}).
8106 @command{missing} will take care of fixing the timestamps when these
8107 tools are not installed, so that the build can continue.
8109 @item
8110 In distributed development, developers are likely to have different
8111 version of the maintainer tools installed.  In this case rebuilds
8112 triggered by timestamp lossage will lead to spurious changes
8113 to generated files.  There are several solutions to this:
8115 @itemize
8116 @item
8117 All developers should use the same versions, so that the rebuilt files
8118 are identical to files in CVS@.  (This starts to be difficult when each
8119 project you work on uses different versions.)
8120 @item
8121 Or people use a script to fix the timestamp after a checkout (the GCC
8122 folks have such a script).
8123 @item
8124 Or @file{configure.ac} uses @code{AM_MAINTAINER_MODE}, which will
8125 disable all these rebuild rules by default.  This is further discussed
8126 in @ref{maintainer-mode}.
8127 @end itemize
8129 @item
8130 Although we focused on spurious rebuilds, the converse can also
8131 happen.  CVS's timestamp handling can also let you think an
8132 out-of-date file is up-to-date.
8134 For instance, suppose a developer has modified @file{Makefile.am} and
8135 has rebuilt @file{Makefile.in}.  He then decide to do a last-minute
8136 change to @file{Makefile.am} right before checking in both files
8137 (without rebuilding @file{Makefile.in} to account for the change).
8139 This last change to @file{Makefile.am} make the copy of
8140 @file{Makefile.in} out-of-date.  Since CVS processes files
8141 alphabetically, when another developer @samp{cvs update} his or her
8142 tree, @file{Makefile.in} will happen to be newer than
8143 @file{Makefile.am}.  This other developer will not see
8144 @file{Makefile.in} is out-of-date.
8146 @end itemize
8148 @subsubheading Generated files out of CVS
8150 One way to get CVS and @command{make} working peacefully is to never
8151 store generated files in CVS, i.e., do not CVS-control files that
8152 are @file{Makefile} targets (also called @emph{derived} files).
8154 This way developers are not annoyed by changes to generated files.  It
8155 does not matter if they all have different versions (assuming they are
8156 compatible, of course).  And finally, timestamps are not lost, changes
8157 to sources files can't be missed as in the
8158 @file{Makefile.am}/@file{Makefile.in} example discussed earlier.
8160 The drawback is that the CVS repository is not an exact copy of what
8161 is distributed and that users now need to install various development
8162 tools (maybe even specific versions) before they can build a checkout.
8163 But, after all, CVS's job is versioning, not distribution.
8165 Allowing developers to use different versions of their tools can also
8166 hide bugs during distributed development.  Indeed, developers will be
8167 using (hence testing) their own generated files, instead of the
8168 generated files that will be released actually.  The developer who
8169 prepares the tarball might be using a version of the tool that
8170 produces bogus output (for instance a non-portable C file), something
8171 other developers could have noticed if they weren't using their own
8172 versions of this tool.
8174 @subsection Third-party files
8175 @cindex CVS and third-party files
8176 @cindex third-party files and CVS
8178 Another class of files not discussed here (because they do not cause
8179 timestamp issues) are files that are shipped with a package, but
8180 maintained elsewhere.  For instance, tools like @command{gettextize}
8181 and @command{autopoint} (from Gettext) or @command{libtoolize} (from
8182 Libtool), will install or update files in your package.
8184 These files, whether they are kept under CVS or not, raise similar
8185 concerns about version mismatch between developers' tools.  The
8186 Gettext manual has a section about this, see @ref{CVS Issues, CVS
8187 Issues, Integrating with CVS, gettext, GNU gettext tools}.
8189 @node maintainer-mode
8190 @section @command{missing} and @code{AM_MAINTAINER_MODE}
8192 @subsection @command{missing}
8193 @cindex @command{missing}, purpose
8195 The @command{missing} script is a wrapper around several maintainer
8196 tools, designed to warn users if a maintainer tool is required but
8197 missing.  Typical maintainer tools are @command{autoconf},
8198 @command{automake}, @command{bison}, etc.  Because file generated by
8199 these tools are shipped with the other sources of a package, these
8200 tools shouldn't be required during a user build and they are not
8201 checked for in @file{configure}.
8203 However, if for some reason a rebuild rule is triggered and involves a
8204 missing tool, @command{missing} will notice it and warn the user.
8205 Besides the warning, when a tool is missing, @command{missing} will
8206 attempt to fix timestamps in a way that allows the build to continue.
8207 For instance, @command{missing} will touch @file{configure} if
8208 @command{autoconf} is not installed.  When all distributed files are
8209 kept under CVS, this feature of @command{missing} allows user
8210 @emph{with no maintainer tools} to build a package off CVS, bypassing
8211 any timestamp inconsistency implied by @samp{cvs update}.
8213 If the required tool is installed, @command{missing} will run it and
8214 won't attempt to continue after failures.  This is correct during
8215 development: developers love fixing failures.  However, users with
8216 wrong versions of maintainer tools may get an error when the rebuild
8217 rule is spuriously triggered, halting the build.  This failure to let
8218 the build continue is one of the arguments of the
8219 @code{AM_MAINTAINER_MODE} advocates.
8221 @subsection @code{AM_MAINTAINER_MODE}
8222 @cindex @code{AM_MAINTAINER_MODE}, purpose
8223 @acindex AM_MAINTAINER_MODE
8225 @code{AM_MAINTAINER_MODE} disables the so called "rebuild rules" by
8226 default.  If you have @code{AM_MAINTAINER_MODE} in
8227 @file{configure.ac}, and run @samp{./configure && make}, then
8228 @command{make} will *never* attempt to rebuilt @file{configure},
8229 @file{Makefile.in}s, Lex or Yacc outputs, etc.  I.e., this disables
8230 build rules for files that are usually distributed and that users
8231 should normally not have to update.
8233 If you run @samp{./configure --enable-maintainer-mode}, then these
8234 rebuild rules will be active.
8236 People use @code{AM_MAINTAINER_MODE} either because they do want their
8237 users (or themselves) annoyed by timestamps lossage (@pxref{CVS}), or
8238 because they simply can't stand the rebuild rules and prefer running
8239 maintainer tools explicitly.
8241 @code{AM_MAINTAINER_MODE} also allows you to disable some custom build
8242 rules conditionally.  Some developers use this feature to disable
8243 rules that need exotic tools that users may not have available.
8245 Several years ago Fran@,{c}ois Pinard pointed out several arguments
8246 against this @code{AM_MAINTAINER_MODE} macro.  Most of them relate to
8247 insecurity.  By removing dependencies you get non-dependable builds:
8248 change to sources files can have no effect on generated files and this
8249 can be very confusing when unnoticed.  He adds that security shouldn't
8250 be reserved to maintainers (what @option{--enable-maintainer-mode}
8251 suggests), on the contrary.  If one user has to modify a
8252 @file{Makefile.am}, then either @file{Makefile.in} should be updated
8253 or a warning should be output (this is what Automake uses
8254 @command{missing} for) but the last thing you want is that nothing
8255 happens and the user doesn't notice it (this is what happens when
8256 rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
8258 Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro was
8259 swayed by Fran@,{c}ois's arguments, and got rid of
8260 @code{AM_MAINTAINER_MODE} in all of his packages.
8262 Still many people continue to use @code{AM_MAINTAINER_MODE}, because
8263 it helps them working on projects where all files are kept under CVS,
8264 and because @command{missing} isn't enough if you have the wrong
8265 version of the tools.
8268 @node wildcards
8269 @section Why doesn't Automake support wildcards?
8270 @cindex wildcards
8272 Developers are lazy.  They often would like to use wildcards in
8273 @file{Makefile.am}s, so they don't need to remember they have to
8274 update @file{Makefile.am}s every time they add, delete, or rename a
8275 file.
8277 There are several objections to this:
8278 @itemize
8279 @item
8280 When using CVS (or similar) developers need to remember they have to
8281 run @samp{cvs add} or @samp{cvs rm} anyway.  Updating
8282 @file{Makefile.am} accordingly quickly becomes a reflex.
8284 Conversely, if your application doesn't compile
8285 because you forgot to add a file in @file{Makefile.am}, it will help
8286 you remember to @samp{cvs add} it.
8288 @item
8289 Using wildcards makes easy to distribute files by mistake.  For
8290 instance, some code a developer is experimenting with (a test case,
8291 say) but that should not be part of the distribution.
8293 @item
8294 Using wildcards it's easy to omit some files by mistake.  For
8295 instance, one developer creates a new file, uses it at many places,
8296 but forget to commit it.  Another developer then checkout the
8297 incomplete project and is able to run `make dist' successfully,
8298 even though a file is missing.
8300 @item
8301 Listing files, you control *exactly* what you distribute.
8302 If some file that should be distributed is missing from your
8303 tree, @samp{make dist} will complain.  Besides, you don't distribute
8304 more than what you listed.
8306 @item
8307 Finally it's really hard to @file{forget} adding a file to
8308 @file{Makefile.am}, because if you don't add it, it doesn't get
8309 compiled nor installed, so you can't even test it.
8310 @end itemize
8312 Still, these are philosophical objections, and as such you may disagree,
8313 or find enough value in wildcards to dismiss all of them.  Before you
8314 start writing a patch against Automake to teach it about wildcards,
8315 let's see the main technical issue: portability.
8317 Although @samp{$(wildcard ...)} works with GNU @command{make}, it is
8318 not portable to other @command{make} implementations.
8320 The only way Automake could support @command{$(wildcard ...)} is by
8321 expending @command{$(wildcard ...)} when @command{automake} is run.
8322 Resulting @file{Makefile.in}s would be portable since they would
8323 list all files and not use @samp{$(wildcard ...)}.  However that
8324 means developers need to remember they must run @command{automake} each
8325 time they add, delete, or rename files.
8327 Compared to editing @file{Makefile.am}, this is really little win.  Sure,
8328 it's easier and faster to type @samp{automake; make} than to type
8329 @samp{emacs Makefile.am; make}.  But nobody bothered enough to write a
8330 patch add support for this syntax.  Some people use scripts to
8331 generated file lists in @file{Makefile.am} or in separate
8332 @file{Makefile} fragments.
8334 Even if you don't care about portability, and are tempted to use
8335 @samp{$(wildcard ...)} anyway because you target only GNU Make, you
8336 should know there are many places where Automake need to know exactly
8337 which files should be processed.  As Automake doesn't know how to
8338 expand @samp{$(wildcard ...)}, you cannot use it in these places.
8339 @samp{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
8340 variables as far Automake is concerned.
8342 You can get warnings about @samp{$(wildcard ...}) constructs using the
8343 @option{-Wportability} flag.
8345 @node distcleancheck
8346 @section Files left in build directory after distclean
8347 @cindex @code{distclean}, diagnostic
8348 @cindex @samp{make distclean}, diagnostic
8349 @cindex dependencies and distributed files
8350 @trindex distclean
8351 @trindex distcleancheck
8353 This is a diagnostic you might encounter while running @samp{make
8354 distcheck}.
8356 As explained in @ref{Dist}, @samp{make distcheck} attempts to build
8357 and check your package for errors like this one.
8359 @samp{make distcheck} will perform a @code{VPATH} build of your
8360 package, and then call @samp{make distclean}.  Files left in the build
8361 directory after @samp{make distclean} has run are listed after this
8362 error.
8364 This diagnostic really covers two kinds of errors:
8366 @itemize @bullet
8367 @item
8368 files that are forgotten by distclean;
8369 @item
8370 distributed files that are erroneously rebuilt.
8371 @end itemize
8373 The former left-over files are not distributed, so the fix is to mark
8374 them for cleaning (@pxref{Clean}), this is obvious and doesn't deserve
8375 more explanations.
8377 The latter bug is not always easy to understand and fix, so let's
8378 proceed with an example.  Suppose our package contains a program for
8379 which we want to build a man page using @command{help2man}.  GNU
8380 @command{help2man} produces simple manual pages from the @option{--help}
8381 and @option{--version} output of other commands (@pxref{Top, , Overview,
8382 help2man, The Help2man Manual}).  Because we don't to force want our
8383 users to install @command{help2man}, we decide to distribute the
8384 generated man page using the following setup.
8386 @example
8387 # This Makefile.am is bogus.
8388 bin_PROGRAMS = foo
8389 foo_SOURCES = foo.c
8390 dist_man_MANS = foo.1
8392 foo.1: foo$(EXEEXT)
8393         help2man --output=foo.1 ./foo$(EXEEXT)
8394 @end example
8396 This will effectively distribute the man page.  However,
8397 @samp{make distcheck} will fail with:
8399 @example
8400 ERROR: files left in build directory after distclean:
8401 ./foo.1
8402 @end example
8404 Why was @file{foo.1} rebuilt?  Because although distributed,
8405 @file{foo.1} depends on a non-distributed built file:
8406 @file{foo$(EXEEXT)}.  @file{foo$(EXEEXT)} is built by the user, so it
8407 will always appear to be newer than the distributed @file{foo.1}.
8409 @samp{make distcheck} caught an inconsistency in our package.  Our
8410 intent was to distribute @file{foo.1} so users do not need installing
8411 @command{help2man}, however since this our rule causes this file to be
8412 always rebuilt, users @emph{do} need @command{help2man}.  Either we
8413 should ensure that @file{foo.1} is not rebuilt by users, or there is
8414 no point in distributing @file{foo.1}.
8416 More generally, the rule is that distributed files should never depend
8417 on non-distributed built files.  If you distribute something
8418 generated, distribute its sources.
8420 One way to fix the above example, while still distributing
8421 @file{foo.1} is to not depend on @file{foo$(EXEEXT)}.  For instance,
8422 assuming @command{foo --version} and @command{foo --help} do not
8423 change unless @file{foo.c} or @file{configure.ac} change, we could
8424 write the following @file{Makefile.am}:
8426 @example
8427 bin_PROGRAMS = foo
8428 foo_SOURCES = foo.c
8429 dist_man_MANS = foo.1
8431 foo.1: foo.c $(top_srcdir)/configure.ac
8432         $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
8433         help2man --output=foo.1 ./foo$(EXEEXT)
8434 @end example
8436 This way, @file{foo.1} will not get rebuilt every time
8437 @file{foo$(EXEEXT)} changes.  The @command{make} call makes sure
8438 @file{foo$(EXEEXT)} is up-to-date before @command{help2man}.  Another
8439 way to ensure this would be to use separate directories for binaries
8440 and man pages, and set @code{SUBDIRS} so that binaries are built
8441 before man pages.
8443 We could also decide not to distribute @file{foo.1}.  In
8444 this case it's fine to have @file{foo.1} dependent upon
8445 @file{foo$(EXEEXT)}, since both will have to be rebuilt.
8446 However it would be impossible to build the package in a
8447 cross-compilation, because building @file{foo.1} involves
8448 an @emph{execution} of @file{foo$(EXEEXT)}.
8450 Another context where such errors are common is when distributed files
8451 are built by tools that are built by the package.  The pattern is
8452 similar:
8454 @example
8455 distributed-file: built-tools distributed-sources
8456         build-command
8457 @end example
8459 @noindent
8460 should be changed to
8462 @example
8463 distributed-file: distributed-sources
8464         $(MAKE) $(AM_MAKEFLAGS) built-tools
8465         build-command
8466 @end example
8468 @noindent
8469 or you could choose not to distribute @file{distributed-file}, if
8470 cross-compilation does not matter.
8472 The points made through these examples are worth a summary:
8474 @cartouche
8475 @itemize
8476 @item
8477 Distributed files should never depend upon non-distributed built
8478 files.
8479 @item
8480 Distributed files should be distributed will all their dependencies.
8481 @item
8482 If a file is @emph{intended} be rebuilt by users, there is no point in
8483 distributing it.
8484 @end itemize
8485 @end cartouche
8487 @vrindex distcleancheck_listfiles
8488 For desperate cases, it's always possible to disable this check by
8489 setting @code{distcleancheck_listfiles} as documented in @ref{Dist}.
8490 Make sure you do understand the reason why @samp{make distcheck}
8491 complains before you do this.  @code{distcleancheck_listfiles} is a
8492 way to @emph{hide} errors, not to fix them.  You can always do better.
8494 @node Flag Variables Ordering
8495 @section Flag Variables Ordering
8496 @cindex Ordering flag variables
8497 @cindex Flag variables, ordering
8499 @display
8500 What is the difference between @code{AM_CFLAGS}, @code{CFLAGS}, and
8501 @code{mumble_CFLAGS}?
8502 @end display
8504 @display
8505 Why does @command{automake} output @code{CPPFLAGS} after
8506 @code{AM_CPPFLAGS} on compile lines?  Shouldn't it be the converse?
8507 @end display
8509 @display
8510 My @file{configure} adds some warning flags into @code{CXXFLAGS}.  In
8511 one @file{Makefile.am} I would like to append a new flag, however if I
8512 put the flag into @code{AM_CXXFLAGS} it is prepended to the other
8513 flags, not appended.
8514 @end display
8516 @subsection Compile Flag Variables
8517 @cindex Flag Variables, Ordering
8518 @cindex Compile Flag Variables
8519 @cindex @code{AM_CCASFLAGS} and @code{CCASFLAGS}
8520 @cindex @code{AM_CFLAGS} and @code{CFLAGS}
8521 @cindex @code{AM_CPPFLAGS} and @code{CPPFLAGS}
8522 @cindex @code{AM_CXXFLAGS} and @code{CXXFLAGS}
8523 @cindex @code{AM_FCFLAGS} and @code{FCFLAGS}
8524 @cindex @code{AM_FFLAGS} and @code{FFLAGS}
8525 @cindex @code{AM_GCJFLAGS} and @code{GCJFLAGS}
8526 @cindex @code{AM_LDFLAGS} and @code{LDFLAGS}
8527 @cindex @code{AM_LFLAGS} and @code{LFLAGS}
8528 @cindex @code{AM_LIBTOOLFLAGS} and @code{LIBTOOLFLAGS}
8529 @cindex @code{AM_OBJCFLAGS} and @code{OBJCFLAGS}
8530 @cindex @code{AM_RFLAGS} and @code{RFLAGS}
8531 @cindex @code{AM_YFLAGS} and @code{YFLAGS}
8532 @cindex @code{CCASFLAGS} and @code{AM_CCASFLAGS}
8533 @cindex @code{CFLAGS} and @code{AM_CFLAGS}
8534 @cindex @code{CPPFLAGS} and @code{AM_CPPFLAGS}
8535 @cindex @code{CXXFLAGS} and @code{AM_CXXFLAGS}
8536 @cindex @code{FCFLAGS} and @code{AM_FCFLAGS}
8537 @cindex @code{FFLAGS} and @code{AM_FFLAGS}
8538 @cindex @code{GCJFLAGS} and @code{AM_GCJFLAGS}
8539 @cindex @code{LDFLAGS} and @code{AM_LDFLAGS}
8540 @cindex @code{LFLAGS} and @code{AM_LFLAGS}
8541 @cindex @code{LIBTOOLFLAGS} and @code{AM_LIBTOOLFLAGS}
8542 @cindex @code{OBJCFLAGS} and @code{AM_OBJCFLAGS}
8543 @cindex @code{RFLAGS} and @code{AM_RFLAGS}
8544 @cindex @code{YFLAGS} and @code{AM_YFLAGS}
8546 This section attempts to answer all the above questions.  We will
8547 mostly discuss @code{CPPFLAGS} in our examples, but actually the
8548 answer holds for all the compile flags used in Automake:
8549 @code{CCASFLAGS}, @code{CFLAGS}, @code{CPPFLAGS}, @code{CXXFLAGS},
8550 @code{FCFLAGS}, @code{FFLAGS}, @code{GCJFLAGS}, @code{LDFLAGS},
8551 @code{LFLAGS}, @code{LIBTOOLFLAGS}, @code{OBJCFLAGS}, @code{RFLAGS},
8552 and @code{YFLAGS}.
8554 @code{CPPFLAGS}, @code{AM_CPPFLAGS}, and @code{mumble_CPPFLAGS} are
8555 three variables that can be used to pass flags to the C preprocessor
8556 (actually these variables are also used for other languages like C++
8557 or preprocessed Fortran).  @code{CPPFLAGS} is the user variable
8558 (@pxref{User Variables}), @code{AM_CPPFLAGS} is the Automake variable,
8559 and @code{mumble_CPPFLAGS} is the variable specific to the
8560 @code{mumble} target (we call this a per-target variable,
8561 @pxref{Program and Library Variables}).
8563 Automake always uses two of these variables when compiling C sources
8564 files.  When compiling an object file for the @code{mumble} target,
8565 the first variable will be @code{mumble_CPPFLAGS} if it is defined, or
8566 @code{AM_CPPFLAGS} otherwise.  The second variable is always
8567 @code{CPPFLAGS}.
8569 In the following example,
8571 @example
8572 bin_PROGRAMS = foo bar
8573 foo_SOURCES = xyz.c
8574 bar_SOURCES = main.c
8575 foo_CPPFLAGS = -DFOO
8576 AM_CPPFLAGS = -DBAZ
8577 @end example
8579 @noindent
8580 @file{xyz.o} will be compiled with @samp{$(foo_CPPFLAGS) $(CPPFLAGS)},
8581 (because @file{xyz.o} is part of the @code{foo} target), while
8582 @file{main.o} will be compiled with @samp{$(AM_CPPFLAGS) $(CPPFLAGS)}
8583 (because there is no per-target variable for target @code{bar}).
8585 The difference between @code{mumble_CPPFLAGS} and @code{AM_CPPFLAGS}
8586 being clear enough, let's focus on @code{CPPFLAGS}.  @code{CPPFLAGS}
8587 is a user variable, i.e., a variable that users are entitled to modify
8588 in order to compile the package.  This variable, like many others,
8589 is documented at the end of the output of @samp{configure --help}.
8591 For instance, someone who needs to add @file{/home/my/usr/include} to
8592 the C compiler's search path would configure a package with
8594 @example
8595 ./configure CPPFLAGS='-I /home/my/usr/include'
8596 @end example
8598 @noindent
8599 and this flag would be propagated to the compile rules of all
8600 @file{Makefile}s.
8602 It is also not uncommon to override a user variable at
8603 @command{make}-time.  Many installers do this with @code{prefix}, but
8604 this can be useful with compiler flags too.  For instance, if, while
8605 debugging a C++ project, you need to disable optimization in one
8606 specific object file, you can run something like
8608 @example
8609 rm file.o
8610 make CXXFLAGS=-O0 file.o
8611 make
8612 @end example
8614 The reason @samp{$(CPPFLAGS)} appears after @samp{$(AM_CPPFLAGS)} or
8615 @samp{$(mumble_CPPFLAGS)} in the compile command is that users
8616 should always have the last say.  It probably makes more sense if you
8617 think about it while looking at the @samp{CXXFLAGS=-O0} above, which
8618 should supersede any other switch from @code{AM_CXXFLAGS} or
8619 @code{mumble_CXXFLAGS} (and this of course replaces the previous value
8620 of @code{CXXFLAGS}).
8622 You should never redefine a user variable such as @code{CPPFLAGS} in
8623 @file{Makefile.am}.  Use @samp{automake -Woverride} to diagnose such
8624 mistakes.  Even something like
8626 @example
8627 CPPFLAGS = -DDATADIR=\"$(datadir)\" @@CPPFLAGS@@
8628 @end example
8630 @noindent
8631 is erroneous.  Although this preserves @file{configure}'s value of
8632 @code{CPPFLAGS}, the definition of @code{DATADIR} will disappear if a
8633 user attempts to override @code{CPPFLAGS} from the @command{make}
8634 command line.
8636 @example
8637 AM_CPPFLAGS = -DDATADIR=\"$(datadir)\"
8638 @end example
8640 @noindent
8641 is all what is needed here if no per-target flags are used.
8643 You should not add options to these user variables within
8644 @file{configure} either, for the same reason.  Occasionally you need
8645 to modify these variables to perform a test, but you should reset
8646 their values afterwards.  In contrast, it is OK to modify the
8647 @samp{AM_} variables within @file{configure} if you @code{AC_SUBST}
8648 them, but it is rather rare that you need to do this, unless you
8649 really want to change the default definitions of the @samp{AM_}
8650 variables in all @file{Makefile}s.
8652 What we recommend is that you define extra flags in separate
8653 variables.  For instance, you may write an Autoconf macro that computes
8654 a set of warning options for the C compiler, and @code{AC_SUBST} them
8655 in @code{WARNINGCFLAGS}; you may also have an Autoconf macro that
8656 determines which compiler and which linker flags should be used to
8657 link with library @file{libfoo}, and @code{AC_SUBST} these in
8658 @code{LIBFOOCFLAGS} and @code{LIBFOOLDFLAGS}.  Then, a
8659 @file{Makefile.am} could use these variables as follows:
8661 @example
8662 AM_CFLAGS = $(WARNINGCFLAGS)
8663 bin_PROGRAMS = prog1 prog2
8664 prog1_SOURCES = @dots{}
8665 prog2_SOURCES = @dots{}
8666 prog2_CFLAGS = $(LIBFOOCFLAGS) $(AM_CFLAGS)
8667 prog2_LDFLAGS = $(LIBFOOLDFLAGS)
8668 @end example
8670 In this example both programs will be compiled with the flags
8671 substituted into @samp{$(WARNINGCFLAGS)}, and @code{prog2} will
8672 additionally be compiled with the flags required to link with
8673 @file{libfoo}.
8675 Note that listing @code{AM_CFLAGS} in a per-target @code{CFLAGS}
8676 variable is a common idiom to ensure that @code{AM_CFLAGS} applies to
8677 every target in a @file{Makefile.in}.
8679 Using variables like this gives you full control over the ordering of
8680 the flags.  For instance, if there is a flag in $(WARNINGCFLAGS) that
8681 you want to negate for a particular target, you can use something like
8682 @samp{prog1_CFLAGS = $(AM_CFLAGS) -no-flag}.  If all these flags had
8683 been forcefully appended to @code{CFLAGS}, there would be no way to
8684 disable one flag.  Yet another reason to leave user variables to
8685 users.
8687 Finally, we have avoided naming the variable of the example
8688 @code{LIBFOO_LDFLAGS} (with an underscore) because that would cause
8689 Automake to think that this is actually a per-target variable (like
8690 @code{mumble_LDFLAGS}) for some non-declared @code{LIBFOO} target.
8692 @subsection Other Variables
8694 There are other variables in Automake that follow similar principles
8695 to allow user options.  For instance, Texinfo rules (@pxref{Texinfo})
8696 use @code{MAKEINFOFLAGS} and @code{AM_MAKEINFOFLAGS}.  Similarly,
8697 DejaGnu tests (@pxref{Tests}) use @code{RUNTESTDEFAULTFLAGS} and
8698 @code{AM_RUNTESTDEFAULTFLAGS}.  The tags and ctags rules
8699 (@pxref{Tags}) use @code{ETAGSFLAGS}, @code{AM_ETAGSFLAGS},
8700 @code{CTAGSFLAGS}, and @code{AM_CTAGSFLAGS}.  Java rules
8701 (@pxref{Java}) use @code{JAVACFLAGS} and @code{AM_JAVACFLAGS}.  None
8702 of these rules do support per-target flags (yet).
8704 To some extent, even @code{AM_MAKEFLAGS} (@pxref{Subdirectories})
8705 obeys this naming scheme.  The slight difference is that
8706 @code{MAKEFLAGS} is passed to sub-@command{make}s implicitly by
8707 @command{make} itself.
8709 However you should not think that all variables ending with
8710 @code{FLAGS} follow this convention.  For instance,
8711 @code{DISTCHECK_CONFIGURE_FLAGS} (@pxref{Dist}),
8712 @code{ACLOCAL_AMFLAGS} (see @ref{Rebuilding} and @ref{Local Macros}),
8713 are two variables that are only useful to the maintainer and have no
8714 user counterpart.
8716 @code{ARFLAGS} (@pxref{A Library}) is usually defined by Automake and
8717 has neither @code{AM_} nor per-target cousin.
8719 Finally you should not think either that the existence of a per-target
8720 variable implies that of an @code{AM_} variable or that of a user
8721 variable.  For instance, the @code{mumble_LDADD} per-target variable
8722 overrides the global @code{LDADD} variable (which is not a user
8723 variable), and @code{mumble_LIBADD} exists only as a per-target
8724 variable.  @xref{Program and Library Variables}.
8727 @node renamed objects
8728 @section Why are object files sometimes renamed?
8730 This happens when per-target compilation flags are used.  Object
8731 files need to be renamed just in case they would clash with object
8732 files compiled from the same sources, but with different flags.
8733 Consider the following example.
8735 @example
8736 bin_PROGRAMS = true false
8737 true_SOURCES = generic.c
8738 true_CPPFLAGS = -DEXIT_CODE=0
8739 false_SOURCES = generic.c
8740 false_CPPFLAGS = -DEXIT_CODE=1
8741 @end example
8742 @noindent
8743 Obviously the two programs are built from the same source, but it
8744 would be bad if they shared the same object, because @file{generic.o}
8745 cannot be built with both @samp{-DEXIT_CODE=0} @emph{and}
8746 @samp{-DEXIT_CODE=1}.  Therefore @command{automake} outputs rules to
8747 build two different objects: @file{true-generic.o} and
8748 @file{false-generic.o}.
8750 @command{automake} doesn't actually look whether source files are
8751 shared to decide if it must rename objects.  It will just rename all
8752 objects of a target as soon as it sees per-target compilation flags
8753 are used.
8755 It's OK to share object files when per-target compilation flags are not
8756 used.  For instance, @file{true} and @file{false} will both use
8757 @file{version.o} in the following example.
8759 @example
8760 AM_CPPFLAGS = -DVERSION=1.0
8761 bin_PROGRAMS = true false
8762 true_SOURCES = true.c version.c
8763 false_SOURCES = false.c version.c
8764 @end example
8766 Note that the renaming of objects is also affected by the
8767 @code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
8770 @node Per-Object Flags
8771 @section Per-Object Flags Emulation
8772 @cindex Per-object flags, emulated
8774 @display
8775 One of my source files needs to be compiled with different flags.  How
8776 do I do?
8777 @end display
8779 Automake supports per-program and per-library compilation flags (see
8780 @ref{Program and Library Variables} and @ref{Flag Variables
8781 Ordering}).  With this you can define compilation flags that apply to
8782 all files compiled for a target.  For instance, in
8784 @example
8785 bin_PROGRAMS = foo
8786 foo_SOURCES = foo.c foo.h bar.c bar.h main.c
8787 foo_CFLAGS = -some -flags
8788 @end example
8790 @noindent
8791 @file{foo-foo.o}, @file{foo-bar.o}, and @file{foo-main.o} will all be
8792 compiled with @samp{-some -flags}.  (If you wonder about the names of
8793 these object files, see @ref{renamed objects}.)  Note that
8794 @code{foo_CFLAGS} gives the flags to use when compiling all the C
8795 sources of the @emph{program} @code{foo}, it has nothing to do with
8796 @file{foo.c} or @file{foo-foo.o} specifically.
8798 What if @file{foo.c} needs to be compiled into @file{foo.o} using some
8799 specific flags, that none of the other files require?  Obviously
8800 per-program flags are not directly applicable here.  Something like
8801 per-object flags are expected, i.e., flags that would be used only
8802 when creating @file{foo-foo.o}.  Automake does not support that,
8803 however this is easy to simulate using a library that contains only
8804 that object, and compiling this library with per-library flags.
8806 @example
8807 bin_PROGRAMS = foo
8808 foo_SOURCES = bar.c bar.h main.c
8809 foo_CFLAGS = -some -flags
8810 foo_LDADD = libfoo.a
8811 noinst_LIBRARIES = libfoo.a
8812 libfoo_a_SOURCES = foo.c foo.h
8813 libfoo_a_CFLAGS = -some -other -flags
8814 @end example
8816 Here @file{foo-bar.o} and @file{foo-main.o} will all be
8817 compiled with @samp{-some -flags}, while @file{libfoo_a-foo.o} will
8818 be compiled using @samp{-some -other -flags}.  Eventually, all
8819 three objects will be linked to form @file{foo}.
8821 This trick can also be achieved using Libtool convenience libraries,
8822 for instance @samp{noinst_LTLIBRARIES = libfoo.la} (@pxref{Libtool
8823 Convenience Libraries}).
8825 Another tempting idea to implement per-object flags is to override the
8826 compile rules @command{automake} would output for these files.
8827 Automake will not define a rule for a target you have defined, so you
8828 could think about defining the @samp{foo-foo.o: foo.c} rule yourself.
8829 We recommend against this, because this is error prone.  For instance,
8830 if you add such a rule to the first example, it will break the day you
8831 decide to remove @code{foo_CFLAGS} (because @file{foo.c} will then be
8832 compiled as @file{foo.o} instead of @file{foo-foo.o}, @pxref{renamed
8833 objects}).  Also in order to support dependency tracking, the two
8834 @file{.o}/@file{.obj} extensions, and all the other flags variables
8835 involved in a compilation, you will end up modifying a copy of the
8836 rule previously output by @command{automake} for this file.  If a new
8837 release of Automake generates a different rule, your copy will need to
8838 be updated by hand.
8840 @node Multiple Outputs
8841 @section Handling Tools that Produce Many Outputs
8842 @cindex multiple outputs, rules with
8843 @cindex many outputs, rules with
8844 @cindex rules with multiple outputs
8846 This section describes a @command{make} idiom that can be used when a
8847 tool produces multiple output files.  It is not specific to Automake
8848 and can be used in ordinary @file{Makefile}s.
8850 Suppose we have a program called @command{foo} that will read one file
8851 called @file{data.foo} and produce two files named @file{data.c} and
8852 @file{data.h}.  We want to write a @file{Makefile} rule that captures
8853 this one-to-two dependency.
8855 The naive rule is incorrect:
8857 @example
8858 # This is incorrect.
8859 data.c data.h: data.foo
8860         foo data.foo
8861 @end example
8863 @noindent
8864 What the above rule really says is that @file{data.c} and
8865 @file{data.h} each depend on @file{data.foo}, and can each be built by
8866 running @samp{foo data.foo}.  In other words it is equivalent to:
8868 @example
8869 # We do not want this.
8870 data.c: data.foo
8871         foo data.foo
8872 data.h: data.foo
8873         foo data.foo
8874 @end example
8876 @noindent
8877 which means that @command{foo} can be run twice.  Usually it will not
8878 be run twice, because @command{make} implementations are smart enough
8879 to check for the existence of the second file after the first one has
8880 been built; they will therefore detect that it already exists.
8881 However there are a few situations where it can run twice anyway:
8883 @itemize
8884 @item
8885 The most worrying case is when running a parallel @command{make}.  If
8886 @file{data.c} and @file{data.h} are built in parallel, two @samp{foo
8887 data.foo} commands will run concurrently.  This is harmful.
8888 @item
8889 Another case is when the dependency (here @file{data.foo}) is
8890 (or depends upon) a phony target.
8891 @end itemize
8893 A solution that works with parallel @command{make} but not with
8894 phony dependencies is the following:
8896 @example
8897 data.c data.h: data.foo
8898         foo data.foo
8899 data.h: data.c
8900 @end example
8902 @noindent
8903 The above rules are equivalent to
8905 @example
8906 data.c: data.foo
8907         foo data.foo
8908 data.h: data.foo data.c
8909         foo data.foo
8910 @end example
8911 @noindent
8912 therefore a parallel @command{make} will have to serialize the builds
8913 of @file{data.c} and @file{data.h}, and will detect that the second is
8914 no longer needed once the first is over.
8916 Using this pattern is probably enough for most cases.  However it does
8917 not scale easily to more output files (in this scheme all output files
8918 must be totally ordered by the dependency relation), so we will
8919 explore a more complicated solution.
8921 Another idea is to write the following:
8923 @example
8924 # There is still a problem with this one.
8925 data.c: data.foo
8926         foo data.foo
8927 data.h: data.c
8928 @end example
8930 @noindent
8931 The idea is that @samp{foo data.foo} is run only when @file{data.c}
8932 needs to be updated, but we further state that @file{data.h} depends
8933 upon @file{data.c}.  That way, if @file{data.h} is required and
8934 @file{data.foo} is out of date, the dependency on @file{data.c} will
8935 trigger the build.
8937 This is almost perfect, but suppose we have built @file{data.h} and
8938 @file{data.c}, and then we erase @file{data.h}.  Then, running
8939 @samp{make data.h} will not rebuild @file{data.h}.  The above rules
8940 just state that @file{data.c} must be up-to-date with respect to
8941 @file{data.foo}, and this is already the case.
8943 What we need is a rule that forces a rebuild when @file{data.h} is
8944 missing.  Here it is:
8946 @example
8947 data.c: data.foo
8948         foo data.foo
8949 data.h: data.c
8950 ## Recover from the removal of $@@
8951         @@if test -f $@@; then :; else \
8952           rm -f data.c; \
8953           $(MAKE) $(AM_MAKEFLAGS) data.c; \
8954         fi
8955 @end example
8957 The above scheme can be extended to handle more outputs and more
8958 inputs.  One of the outputs is selected to serve as a witness to the
8959 successful completion of the command, it depends upon all inputs, and
8960 all other outputs depend upon it.  For instance, if @command{foo}
8961 should additionally read @file{data.bar} and also produce
8962 @file{data.w} and @file{data.x}, we would write:
8964 @example
8965 data.c: data.foo data.bar
8966         foo data.foo data.bar
8967 data.h data.w data.x: data.c
8968 ## Recover from the removal of $@@
8969         @@if test -f $@@; then :; else \
8970           rm -f data.c; \
8971           $(MAKE) $(AM_MAKEFLAGS) data.c; \
8972         fi
8973 @end example
8975 However there are now two minor problems in this setup.  One is related
8976 to the timestamp ordering of @file{data.h}, @file{data.w},
8977 @file{data.x}, and @file{data.c}.  The other one is a race condition
8978 if a parallel @command{make} attempts to run multiple instances of the
8979 recover block at once.
8981 Let us deal with the first problem.  @command{foo} outputs four files,
8982 but we do not know in which order these files are created.  Suppose
8983 that @file{data.h} is created before @file{data.c}.  Then we have a
8984 weird situation.  The next time @command{make} is run, @file{data.h}
8985 will appear older than @file{data.c}, the second rule will be
8986 triggered, a shell will be started to execute the @samp{if@dots{}fi}
8987 command, but actually it will just execute the @code{then} branch,
8988 that is: nothing.  In other words, because the witness we selected is
8989 not the first file created by @command{foo}, @command{make} will start
8990 a shell to do nothing each time it is run.
8992 A simple riposte is to fix the timestamps when this happens.
8994 @example
8995 data.c: data.foo data.bar
8996         foo data.foo data.bar
8997 data.h data.w data.x: data.c
8998         @@if test -f $@@; then \
8999           touch $@@; \
9000         else \
9001 ## Recover from the removal of $@@
9002           rm -f data.c; \
9003           $(MAKE) $(AM_MAKEFLAGS) data.c; \
9004         fi
9005 @end example
9007 Another solution is to use a different and dedicated file as witness,
9008 rather than using any of @command{foo}'s outputs.
9010 @example
9011 data.stamp: data.foo data.bar
9012         @@rm -f data.tmp
9013         @@touch data.tmp
9014         foo data.foo data.bar
9015         @@mv -f data.tmp $@@
9016 data.c data.h data.w data.x: data.stamp
9017 ## Recover from the removal of $@@
9018         @@if test -f $@@; then :; else \
9019           rm -f data.stamp; \
9020           $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
9021         fi
9022 @end example
9024 @file{data.tmp} is created before @command{foo} is run, so it has a
9025 timestamp older than output files output by @command{foo}.  It is then
9026 renamed to @file{data.stamp} after @command{foo} has run, because we
9027 do not want to update @file{data.stamp} if @command{foo} fails.
9029 This solution still suffers from the second problem: the race
9030 condition in the recover rule.  If, after a successful build, a user
9031 erases @file{data.c} and @file{data.h}, and runs @samp{make -j}, then
9032 @command{make} may start both recover rules in parallel.  If the two
9033 instances of the rule execute @samp{$(MAKE) $(AM_MAKEFLAGS)
9034 data.stamp} concurrently the build is likely to fail (for instance, the
9035 two rules will create @file{data.tmp}, but only one can rename it).
9037 Admittedly, such a weird situation does not arise during ordinary
9038 builds.  It occurs only when the build tree is mutilated.  Here
9039 @file{data.c} and @file{data.h} have been explicitly removed without
9040 also removing @file{data.stamp} and the other output files.
9041 @code{make clean; make} will always recover from these situations even
9042 with parallel makes, so you may decide that the recover rule is solely
9043 to help non-parallel make users and leave things as-is.  Fixing this
9044 requires some locking mechanism to ensure only one instance of the
9045 recover rule rebuilds @file{data.stamp}.  One could imagine something
9046 along the following lines.
9048 @example
9049 data.c data.h data.w data.x: data.stamp
9050 ## Recover from the removal of $@@
9051         @@if test -f $@@; then :; else \
9052           trap 'rm -rf data.lock data.stamp 1 2 13 15; \
9053 ## mkdir is a portable test-and-set
9054           if mkdir data.lock 2>/dev/null; then \
9055 ## This code is being executed by the first process.
9056             rm -f data.stamp; \
9057             $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
9058           else \
9059 ## This code is being executed by the follower processes.
9060 ## Wait until the first process is done.
9061             while test -d data.lock; do sleep 1; done; \
9062 ## Succeed if and only if the first process succeeded.
9063             test -f data.stamp; exit $$?; \
9064           fi; \
9065         fi
9066 @end example
9068 Using a dedicated witness, like @file{data.stamp}, is very handy when
9069 the list of output files is not known beforehand.  As an illustration,
9070 consider the following rules to compile many @file{*.el} files into
9071 @file{*.elc} files in a single command.  It does not matter how
9072 @code{ELFILES} is defined (as long as it is not empty: empty targets
9073 are not accepted by POSIX).
9075 @example
9076 ELFILES = one.el two.el three.el @dots{}
9077 ELCFILES = $(ELFILES:=c)
9079 elc-stamp: $(ELFILES)
9080         @@rm -f elc-temp
9081         @@touch elc-temp
9082         $(elisp_comp) $(ELFILES)
9083         @@mv -f elc-temp $@@
9085 $(ELCFILES): elc-stamp
9086 ## Recover from the removal of $@@
9087         @@if test -f $@@; then :; else \
9088           trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
9089           if mkdir elc-lock 2>/dev/null; then \
9090 ## This code is being executed by the first process.
9091             rm -f elc-stamp; \
9092             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
9093             rmdir elc-lock; \
9094           else \
9095 ## This code is being executed by the follower processes.
9096 ## Wait until the first process is done.
9097             while test -d elc-lock; do sleep 1; done; \
9098 ## Succeed if and only if the first process succeeded.
9099             test -f elc-stamp; exit $$?; \
9100           fi; \
9101         fi
9102 @end example
9104 For completeness it should be noted that GNU @command{make} is able to
9105 express rules with multiple output files using pattern rules
9106 (@pxref{Pattern Examples, , Pattern Rule Examples, make, The GNU Make
9107 Manual}).  We do not discuss pattern rules here because they are not
9108 portable, but they can be convenient in packages that assume GNU
9109 @command{make}.
9112 @node Hard-Coded Install Paths
9113 @section Installing to Hard-Coded Locations
9115 @display
9116 My package needs to install some configuration file.  I tried to use
9117 the following rule, but @samp{make distcheck} fails.  Why?
9119 @example
9120 # Do not do this.
9121 install-data-local:
9122         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
9123 @end example
9124 @end display
9126 @display
9127 My package needs to populate the installation directory of another
9128 package at install-time.  I can easily compute that installation
9129 directory in @file{configure}, but if I install files therein,
9130 @samp{make distcheck} fails.  How else should I do?
9131 @end display
9133 These two setups share their symptoms: @samp{make distcheck} fails
9134 because they are installing files to hard-coded paths.  In the later
9135 case the path is not really hard-coded in the package, but we can
9136 consider it to be hard-coded in the system (or in whichever tool that
9137 supplies the path).  As long as the path does not use any of the
9138 standard directory variables (@samp{$(prefix)}, @samp{$(bindir)},
9139 @samp{$(datadir)}, etc.), the effect will be the same:
9140 user-installations are impossible.
9142 When a (non-root) user wants to install a package, he usually has no
9143 right to install anything in @file{/usr} or @file{/usr/local}.  So he
9144 does something like @samp{./configure --prefix ~/usr} to install
9145 package in his own @file{~/usr} tree.
9147 If a package attempts to install something to some hard-coded path
9148 (e.g., @file{/etc/afile}), regardless of this @option{--prefix} setting,
9149 then the installation will fail.  @samp{make distcheck} performs such
9150 a @option{--prefix} installation, hence it will fail too.
9152 Now, there are some easy solutions.
9154 The above @code{install-data-local} example for installing
9155 @file{/etc/afile} would be better replaced by
9157 @example
9158 sysconf_DATA = afile
9159 @end example
9161 @noindent
9162 by default @code{sysconfdir} will be @samp{$(prefix)/etc}, because
9163 this is what the GNU Standards require.  When such a package is
9164 installed on a FHS compliant system, the installer will have to set
9165 @samp{--sysconfdir=/etc}.  As the maintainer of the package you
9166 should not be concerned by such site policies: use the appropriate
9167 standard directory variable to install your files so that installer
9168 can easily redefine these variables to match their site conventions.
9170 Installing files that should be used by another package, is slightly
9171 more involved.  Let's take an example and assume you want to install
9172 shared library that is a Python extension module.  If you ask Python
9173 where to install the library, it will answer something like this:
9175 @example
9176 % @kbd{python -c 'from distutils import sysconfig;
9177              print sysconfig.get_python_lib(1,0)'}
9178 /usr/lib/python2.3/site-packages
9179 @end example
9181 If you indeed use this absolute path to install your shared library,
9182 non-root users will not be able to install the package, hence
9183 distcheck fails.
9185 Let's do better.  The @samp{sysconfig.get_python_lib()} function
9186 actually accepts a third argument that will replace Python's
9187 installation prefix.
9189 @example
9190 % @kbd{python -c 'from distutils import sysconfig;
9191              print sysconfig.get_python_lib(1,0,"$@{exec_prefix@}")'}
9192 $@{exec_prefix@}/lib/python2.3/site-packages
9193 @end example
9195 You can also use this new path.  If you do
9196 @itemize @bullet
9197 @item
9198 root users can install your package with the same @option{--prefix}
9199 as Python (you get the behavior of the previous attempt)
9201 @item
9202 non-root users can install your package too, they will have the
9203 extension module in a place that is not searched by Python but they
9204 can work around this using environment variables (and if you installed
9205 scripts that use this shared library, it's easy to tell Python were to
9206 look in the beginning of your script, so the script works in both
9207 cases).
9208 @end itemize
9210 The @code{AM_PATH_PYTHON} macro uses similar commands to define
9211 @samp{$(pythondir)} and @samp{$(pyexecdir)} (@pxref{Python}).
9213 Of course not all tools are as advanced as Python regarding that
9214 substitution of @var{prefix}.  So another strategy is to figure the
9215 part of the of the installation directory that must be preserved.  For
9216 instance, here is how @code{AM_PATH_LISPDIR} (@pxref{Emacs Lisp})
9217 computes @samp{$(lispdir)}:
9219 @example
9220 $EMACS -batch -q -eval '(while load-path
9221   (princ (concat (car load-path) "\n"))
9222   (setq load-path (cdr load-path)))' >conftest.out
9223 lispdir=`sed -n
9224   -e 's,/$,,'
9225   -e '/.*\/lib\/x*emacs\/site-lisp$/@{
9226         s,.*/lib/\(x*emacs/site-lisp\)$,$@{libdir@}/\1,;p;q;
9227       @}'
9228   -e '/.*\/share\/x*emacs\/site-lisp$/@{
9229         s,.*/share/\(x*emacs/site-lisp\),$@{datarootdir@}/\1,;p;q;
9230       @}'
9231   conftest.out`
9232 @end example
9234 I.e., it just picks the first directory that looks like
9235 @file{*/lib/*emacs/site-lisp} or @file{*/share/*emacs/site-lisp} in
9236 the search path of emacs, and then substitutes @samp{$@{libdir@}} or
9237 @samp{$@{datadir@}} appropriately.
9239 The emacs case looks complicated because it processes a list and
9240 expect two possible layouts, otherwise it's easy, and the benefit for
9241 non-root users are really worth the extra @command{sed} invocation.
9244 @node History
9245 @chapter History of Automake
9247 This chapter presents various aspects of the history of Automake.  The
9248 exhausted reader can safely skip it; this will be more of interest to
9249 nostalgic people, or to those curious to learn about the evolution of
9250 Automake.
9252 @menu
9253 * Timeline::                    The Automake story.
9254 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
9255 * Releases::                    Statistics about Automake Releases
9256 @end menu
9258 @node Timeline
9259 @section Timeline
9261 @table @asis
9262 @item 1994-09-19 First CVS commit.
9264 If we can trust the CVS repository, David J.@tie{}MacKenzie (djm) started
9265 working on Automake (or AutoMake, as it was spelt then) this Monday.
9267 The first version of the @command{automake} script looks as follows.
9269 @example
9270 #!/bin/sh
9272 status=0
9274 for makefile
9276   if test ! -f $@{makefile@}.am; then
9277     echo "automake: $@{makefile@}.am: No such honkin' file"
9278     status=1
9279     continue
9280   fi
9282   exec 4> $@{makefile@}.in
9284 done
9285 @end example
9287 From this you can already see that Automake will be about reading
9288 @file{*.am} file and producing @file{*.in} files.  You cannot see
9289 anything else, but if you also know that David is the one who created
9290 Autoconf two years before you can guess the rest.
9292 Several commits follow, and by the end of the day Automake is
9293 reported to work for GNU fileutils and GNU m4.
9295 The modus operandi is the one that is still used today: variables
9296 assignments in @file{Makefile.am} files trigger injections of
9297 precanned @file{Makefile} fragments into the generated
9298 @file{Makefile.in}.  The use of @file{Makefile} fragments was inspired
9299 by the 4.4BSD @command{make} and include files, however Automake aims
9300 to be portable and to conform to the GNU standards for @file{Makefile}
9301 variables and targets.
9303 At this point, the most recent release of Autoconf is version 1.11,
9304 and David is preparing to release Autoconf 2.0 in late October.  As a
9305 matter of fact, he will barely touch Automake after September.
9307 @item 1994-11-05 David MacKenzie's last commit.
9309 At this point Automake is a 200 line portable shell script, plus 332
9310 lines of @file{Makefile} fragments.  In the @file{README}, David
9311 states his ambivalence between ``portable shell'' and ``more
9312 appropriate language'':
9314 @quotation
9315 I wrote it keeping in mind the possibility of it becoming an Autoconf
9316 macro, so it would run at configure-time.  That would slow
9317 configuration down a bit, but allow users to modify the Makefile.am
9318 without needing to fetch the AutoMake package.  And, the Makefile.in
9319 files wouldn't need to be distributed.  But all of AutoMake would.  So
9320 I might reimplement AutoMake in Perl, m4, or some other more
9321 appropriate language.
9322 @end quotation
9324 Automake is described as ``an experimental Makefile generator''.
9325 There is no documentation.  Adventurous users are referred to the
9326 examples and patches needed to use Automake with GNU m4 1.3, fileutils
9327 3.9, time 1.6, and development versions of find and indent.
9329 These examples seem to have been lost.  However at the time of writing
9330 (10 years later in September, 2004) the FSF still distributes a
9331 package that uses this version of Automake: check out GNU termutils
9332 2.0.
9334 @item 1995-11-12 Tom Tromey's first commit.
9336 After one year of inactivity, Tom Tromey takes over the package.
9337 Tom was working on GNU cpio back then, and doing this just for fun,
9338 having trouble finding a project to contribute to.  So while hacking
9339 he wanted to bring the @file{Makefile.in} up to GNU standards.  This
9340 was hard, and one day he saw Automake on @url{ftp://alpha.gnu.org/},
9341 grabbed it and tried it out.
9343 Tom didn't talk to djm about it until later, just to make sure he
9344 didn't mind if he made a release.  He did a bunch of early releases to
9345 the Gnits folks.
9347 Gnits was (and still is) totally informal, just a few GNU friends who
9348 Fran@,cois Pinard knew, who were all interested in making a common
9349 infrastructure for GNU projects, and shared a similar outlook on how
9350 to do it.  So they were able to make some progress.  It came along
9351 with Autoconf and extensions thereof, and then Automake from David and
9352 Tom (who were both gnitsians).  One of their ideas was to write a
9353 document paralleling the GNU standards, that was more strict in some
9354 ways and more detailed.  They never finished the GNITS standards, but
9355 the ideas mostly made their way into Automake.
9357 @item 1995-11-23 Automake 0.20
9359 Besides introducing automatic dependency tracking (@pxref{Dependency
9360 Tracking Evolution}), this version also supplies a 9-page manual.
9362 At this time @command{aclocal} and @code{AM_INIT_AUTOMAKE} did not
9363 exist, so many things had to be done by hand.  For instance, here is
9364 what a configure.in (this is the former name of the
9365 @file{configure.ac} we use today) must contain in order to use
9366 Automake 0.20:
9368 @example
9369 PACKAGE=cpio
9370 VERSION=2.3.911
9371 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
9372 AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
9373 AC_SUBST(PACKAGE)
9374 AC_SUBST(VERSION)
9375 AC_ARG_PROGRAM
9376 AC_PROG_INSTALL
9377 @end example
9379 (Today all of the above is achieved by @code{AC_INIT} and
9380 @code{AM_INIT_AUTOMAKE}.)
9382 Here is how programs are specified in @file{Makefile.am}:
9384 @example
9385 PROGRAMS = hello
9386 hello_SOURCES = hello.c
9387 @end example
9389 This looks pretty much like what we do today, except the
9390 @code{PROGRAMS} variable has no directory prefix specifying where
9391 @file{hello} should be installed: all programs are installed in
9392 @samp{$(bindir)}.  @code{LIBPROGRAMS} can be used to specify programs
9393 that must be built but not installed (it is called
9394 @code{noinst_PROGRAMS} nowadays).
9396 Programs can be built conditionally using @code{AC_SUBST}itutions:
9398 @example
9399 PROGRAMS = @@progs@@
9400 AM_PROGRAMS = foo bar baz
9401 @end example
9403 (@code{AM_PROGRAMS} has since then been renamed to
9404 @code{EXTRA_PROGRAMS}.)
9406 Similarly scripts, static libraries, and data can built and installed
9407 using the @code{LIBRARIES}, @code{SCRIPTS}, and @code{DATA} variables.
9408 However @code{LIBRARIES} were treated a bit specially in that Automake
9409 did automatically supply the @file{lib} and @file{.a} prefixes.
9410 Therefore to build @file{libcpio.a}, one had to write
9412 @example
9413 LIBRARIES = cpio
9414 cpio_SOURCES = ...
9415 @end example
9417 Extra files to distribute must be listed in @code{DIST_OTHER} (the
9418 ancestor of @code{EXTRA_DIST}).  Also extra directories that are to be
9419 distributed should appear in @code{DIST_SUBDIRS}, but the manual
9420 describes this as a temporary ugly hack (today extra directories should
9421 also be listed in @code{EXTRA_DIST}, and @code{DIST_SUBDIRS} is used
9422 for another purpose, @pxref{Conditional Subdirectories}).
9424 @item 1995-11-26 Automake 0.21
9426 In less time that it takes to cook a frozen pizza, Tom rewrites
9427 Automake using Perl.  At this time Perl 5 is only one year old, and
9428 Perl 4.036 is in use at many sites.  Supporting several Perl versions
9429 has been a source of problems through the whole history of Automake.
9431 If you never used Perl 4, imagine Perl 5 without objects, without
9432 @samp{my} variables (only dynamically scoped @samp{local} variables),
9433 without function prototypes, with function calls that needs to be
9434 prefixed with @samp{&}, etc.  Traces of this old style can still be
9435 found in today's @command{automake}.
9437 @item 1995-11-28 Automake 0.22
9438 @itemx 1995-11-29 Automake 0.23
9440 Bug fixes.
9442 @item 1995-12-08 Automake 0.24
9443 @itemx 1995-12-10 Automake 0.25
9445 Releases are raining.  0.24 introduces the uniform naming scheme we
9446 use today, i.e., @code{bin_PROGRAMS} instead of @code{PROGRAMS},
9447 @code{noinst_LIBRARIES} instead of @code{LIBLIBRARIES}, etc.  (However
9448 @code{EXTRA_PROGRAMS} does not exist yet, @code{AM_PROGRAMS} is still
9449 in use; and @code{TEXINFOS} and @code{MANS} still have no directory
9450 prefixes.)  Adding support for prefixes like that was one of the major
9451 ideas in automake; it has lasted pretty well.
9453 AutoMake is renamed to Automake (Tom seems to recall it was Fran@,cois
9454 Pinard's doing).
9456 0.25 fixes a Perl 4 portability bug.
9458 @item 1995-12-18 Jim Meyering starts using Automake in GNU Textutils.
9459 @item 1995-12-31 Fran@,cois Pinard starts using Automake in GNU tar.
9461 @item 1996-01-03 Automake 0.26
9462 @itemx 1996-01-03 Automake 0.27
9464 Of the many change and suggestions sent by Fran@,cois Pinard and
9465 included in 0.26, the most important is perhaps the advise that to
9466 ease customization a user rule or variable definition should always
9467 override an Automake rule or definition.
9469 Gordon Matzigkeit and Jim Meyering are two other early contributors
9470 that have been sending fixes.
9472 0.27 fixes yet another Perl 4 portability bug.
9474 @item 1996-01-13 Automake 0.28
9476 Automake starts scanning @file{configure.in} for @code{LIBOBJS}
9477 support.  This is an important step because until this version
9478 Automake did only know about the @file{Makefile.am}s it processed.
9479 @file{configure.in} was Autoconf's world and the link between Autoconf
9480 and Automake had to be done by the @file{Makefile.am} author.  For
9481 instance, if @file{config.h} was generated by @file{configure}, it was the
9482 package maintainer's responsibility to define the @code{CONFIG_HEADER}
9483 variable in each @file{Makefile.am}.
9485 Succeeding releases will rely more and more on scanning
9486 @file{configure.in} to better automate the Autoconf integration.
9488 0.28 also introduces the @code{AUTOMAKE_OPTIONS} variable and the
9489 @option{--gnu} and @option{--gnits} options, the latter being stricter.
9491 @item 1996-02-07 Automake 0.29
9493 Thanks to @file{configure.in} scanning, @code{CONFIG_HEADER} is gone,
9494 and rebuild rules for @file{configure}-generated file are
9495 automatically output.
9497 @code{TEXINFOS} and @code{MANS} converted to the uniform naming
9498 scheme.
9500 @item 1996-02-24 Automake 0.30
9502 The test suite is born.  It contains 9 tests.  From now on test cases
9503 will be added pretty regularly (@pxref{Releases}), and this proved to
9504 be really helpful later on.
9506 @code{EXTRA_PROGRAMS} finally replaces @code{AM_PROGRAMS}.
9508 All the third-party Autoconf macros, written mostly by Fran@,cois
9509 Pinard (and later Jim Meyering), are distributed in Automake's
9510 hand-written @file{aclocal.m4} file.  Package maintainers are expected
9511 to extract the necessary macros from this file.  (In previous version
9512 you had to copy and paste them from the manual...)
9514 @item 1996-03-11 Automake 0.31
9516 The test suite in 0.30 was run via a long @code{check-local} rule.  Upon
9517 Ulrich Drepper's suggestion, 0.31 makes it an Automake rule output
9518 whenever the @code{TESTS} variable is defined.
9520 @code{DIST_OTHER} is renamed to @code{EXTRA_DIST}, and the @code{check_}
9521 prefix is introduced.  The syntax is now the same as today.
9523 @item 1996-03-15 Gordon Matzigkeit starts writing libtool.
9525 @item 1996-04-27 Automake 0.32
9527 @code{-hook} targets are introduced; an idea from Dieter Baron.
9529 @file{*.info} files, which were output in the build directory are
9530 now built in the source directory, because they are distributed.  It
9531 seems these files like to move back and forth as that will happen
9532 again in future versions.
9534 @item 1996-05-18 Automake 0.33
9536 Gord Matzigkeit's main two contributions:
9538 @itemize
9539 @item very preliminary libtool support
9540 @item the distcheck rule
9541 @end itemize
9543 Although they were very basic at this point, these are probably
9544 among the top features for Automake today.
9546 Jim Meyering also provides the infamous @code{jm_MAINTAINER_MODE},
9547 since then renamed to @code{AM_MAINTAINER_MODE} and abandoned by its
9548 author (@pxref{maintainer-mode}).
9550 @item 1996-05-28 Automake 1.0
9552 After only six months of heavy development, the automake script is
9553 3134 lines long, plus 973 lines of @file{Makefile} fragments.  The
9554 package has 30 pages of documentation, and 38 test cases.
9555 @file{aclocal.m4} contains 4 macros.
9557 From now on and until version 1.4, new releases will occur at a rate
9558 of about one a year.  1.1 did not exist, actually 1.1b to 1.1p have
9559 been the name of beta releases for 1.2.  This is the first time
9560 Automake uses suffix letters to designate beta releases, an habit that
9561 lasts.
9563 @item 1996-10-10 Kevin Dalley packages Automake 1.0 for Debian GNU/Linux.
9565 @item 1996-11-26 David J.@tie{}MacKenzie releases Autoconf 2.12.
9567 Between June and October, the Autoconf development is almost staled.
9568 Roland McGrath has been working at the beginning of the year.  David
9569 comes back in November to release 2.12, but he won't touch Autoconf
9570 anymore after this year, and Autoconf then really stagnates.  The
9571 desolate Autoconf @file{ChangeLog} for 1997 lists only 7 commits.
9573 @item 1997-02-28 @email{automake@@gnu.ai.mit.edu} list alive
9575 The mailing list is announced as follows:
9576 @smallexample
9577 I've created the "automake" mailing list.  It is
9578 "automake@@gnu.ai.mit.edu".  Administrivia, as always, to
9579 automake-request@@gnu.ai.mit.edu.
9581 The charter of this list is discussion of automake, autoconf, and
9582 other configuration/portability tools (eg libtool).  It is expected
9583 that discussion will range from pleas for help all the way up to
9584 patches.
9586 This list is archived on the FSF machines.  Offhand I don't know if
9587 you can get the archive without an account there.
9589 This list is open to anybody who wants to join.  Tell all your
9590 friends!
9591 -- Tom Tromey
9592 @end smallexample
9594 Before that people were discussing Automake privately, on the Gnits
9595 mailing list (which is not public either), and less frequently on
9596 @code{gnu.misc.discuss}.
9598 @code{gnu.ai.mit.edu} is now @code{gnu.org}, in case you never
9599 noticed.  The archives of the early years of the
9600 @code{automake@@gnu.org} list have been lost, so today it is almost
9601 impossible to find traces of discussions that occurred before 1999.
9602 This has been annoying more than once, as such discussions can be
9603 useful to understand the rationale behind a piece of uncommented code
9604 that was introduced back then.
9606 @item 1997-06-22 Automake 1.2
9608 Automake developments continues, and more and more new Autoconf macros
9609 are required.  Distributing them in @file{aclocal.m4} and requiring
9610 people to browse this file to extract the relevant macros becomes
9611 uncomfortable.  Ideally, some of them should be contributed to
9612 Autoconf so that they can be used directly, however Autoconf is
9613 currently inactive.  Automake 1.2 consequently introduces
9614 @command{aclocal} (@command{aclocal} was actually started on
9615 1996-07-28), a tool that automatically constructs an @file{aclocal.m4}
9616 file from a repository of third-party macros.  Because Autoconf has
9617 stalled, Automake also becomes a kind of repository for such
9618 third-party macros, even macros completely unrelated to Automake (for
9619 instance macros that fix broken Autoconf macros).
9621 The 1.2 release contains 20 macros, among which the
9622 @code{AM_INIT_AUTOMAKE} macro that simplifies the creation of
9623 @file{configure.in}.
9625 Libtool is fully supported using @code{*_LTLIBRARIES}.
9627 The missing script is introduced by Fran@,cois Pinard; it is meant to be
9628 a better solution than @code{AM_MAINTAINER_MODE}
9629 (@pxref{maintainer-mode}).
9631 Conditionals support was implemented by Ian Lance Taylor.  At the
9632 time, Tom and Ian were working on an internal project at Cygnus.  They
9633 were using ILU, which is pretty similar to CORBA@.  They wanted to
9634 integrate ILU into their build, which was all @file{configure}-based,
9635 and Ian thought that adding conditionals to @command{automake} was
9636 simpler than doing all the work in @file{configure} (which was the
9637 standard at the time).  So this was actually funded by Cygnus.
9639 This very useful but tricky feature will take a lot of time to
9640 stabilize.  (At the time this text is written, there are still
9641 primaries that have not been updated to support conditional
9642 definitions in Automake 1.9.)
9644 The @command{automake} script has almost doubled: 6089 lines of Perl,
9645 plus 1294 lines of @file{Makefile} fragments.
9647 @item 1997-07-08 Gordon Matzigkeit releases Libtool 1.0.
9649 @item 1998-04-05 Automake 1.3
9651 This is a small advance compared to 1.2.
9652 It add support for assembly, and preliminary support for Java.
9654 Perl 5.004_04 is out, but fixes to support Perl 4 are still
9655 regularly submitted whenever Automake breaks it.
9657 @item 1998-09-06 @code{sourceware.cygnus.com} is on-line.
9659 Sourceware was setup by Jason Molenda to host open source projects.
9661 @item 1998-09-19  Automake CVS repository moved to @code{sourceware.cygnus.com}
9662 @itemx 1998-10-26  @code{sourceware.cygnus.com} announces it hosts Automake
9663 Automake is now hosted on @code{sourceware.cygnus.com}.  It has a
9664 publicly accessible CVS repository.  This CVS repository is a copy of
9665 the one Tom was using on his machine, which in turn is based on
9666 a copy of the CVS repository of David MacKenzie.  This is why we still
9667 have to full source history.  (Automake is still on Sourceware today,
9668 but the host has been renamed to @code{sources.redhat.com}.)
9670 The oldest file in the administrative directory of the CVS repository
9671 that was created on Sourceware is dated 1998-09-19, while the
9672 announcement that @command{automake} and @command{autoconf} had joined
9673 @command{sourceware} was made on 1998-10-26.  They were among the
9674 first projects to be hosted there.
9676 The heedful reader will have noticed Automake was exactly 4-year-old
9677 on 1998-09-19.
9679 @item 1999-01-05 Ben Elliston releases Autoconf 2.13.
9681 @item 1999-01-14 Automake 1.4
9683 This release adds support for Fortran 77 and for the @code{include}
9684 statement.  Also, @samp{+=} assignments are introduced, but it is
9685 still quite easy to fool Automake when mixing this with conditionals.
9687 These two releases, Automake 1.4 and Autoconf 2.13 makes a duo that
9688 will be used together for years.
9690 @command{automake} is 7228 lines, plus 1591 lines of Makefile
9691 fragment, 20 macros (some 1.3 macros were finally contributed back to
9692 Autoconf), 197 test cases, and 51 pages of documentation.
9694 @item 1999-03-27 The @code{user-dep-branch} is created on the CVS repository.
9696 This implements a new dependency tracking schemed that should be
9697 able to handle automatic dependency tracking using any compiler (not
9698 just gcc) and any make (not just GNU @command{make}).  In addition,
9699 the new scheme should be more reliable than the old one, as
9700 dependencies are generated on the end user's machine.  Alexandre Oliva
9701 creates depcomp for this purpose.
9703 @xref{Dependency Tracking Evolution}, for more details about the
9704 evolution of automatic dependency tracking in Automake.
9706 @item 1999-11-21 The @code{user-dep-branch} is merged into the main trunk.
9708 This was a huge problem since we also had patches going in on the
9709 trunk.  The merge took a long time and was very painful.
9711 @item 2000-05-10
9713 Since September 1999 and until 2003, Akim Demaille will be zealously
9714 revamping Autoconf.
9716 @quotation
9717 I think the next release should be called "3.0".@*
9718 Let's face it: you've basically rewritten autoconf.@*
9719 Every weekend there are 30 new patches.@*
9720 I don't see how we could call this "2.15" with a straight face.@*
9721 -- Tom Tromey on @email{autoconf@@gnu.org}
9722 @end quotation
9724 Actually Akim works like a submarine: he will pile up patches while he
9725 works off-line during the weekend, and flush them in batch when he
9726 resurfaces on Monday.
9728 @item 2001-01-24
9730 On this Wednesday, Autoconf 2.49c, the last beta before Autoconf 2.50
9731 is out, and Akim has to find something to do during his week-end :)
9733 @item 2001-01-28
9735 Akim sends a batch of 14 patches to @email{automake@@gnu.org}.
9737 @quotation
9738 Aiieeee!  I was dreading the day that the Demaillator turned his
9739 sights on automake@dots{} and now it has arrived! -- Tom Tromey
9740 @end quotation
9742 It's only the beginning: in two months he will send 192 patches.  Then
9743 he would slow down so Tom can catch up and review all this.  Initially
9744 Tom actually read all these patches, then he probably trustingly
9745 answered OK to most of them, and finally gave up and let Akim apply
9746 whatever he wanted.  There was no way to keep up with that patch rate.
9748 @quotation
9749 Anyway the patch below won't apply since it predates Akim's
9750 sourcequake; I have yet to figure where the relevant passage has
9751 been moved :) -- Alexandre Duret-Lutz
9752 @end quotation
9754 All these patches were sent to and discussed on
9755 @email{automake@@gnu.org}, so subscribed users were literally drown in
9756 technical mails.  Eventually, the @email{automake-patches@@gnu.org}
9757 mailing list was created in May.
9759 Year after year, Automake had drifted away from its initial design:
9760 construct @file{Makefile.in} by assembling various @file{Makefile}
9761 fragments.  In 1.4, lots of @file{Makefile} rules are being emitted at
9762 various places in the @command{automake} script itself; this does not
9763 help ensuring a consistent treatment of these rules (for instance
9764 making sure that user-defined rules override Automake's own rules).
9765 One of Akim's goal was moving all these hard-coded rules to separate
9766 @file{Makefile} fragments, so the logic could be centralized in a
9767 @file{Makefile} fragment processor.
9769 Another significant contribution of Akim is the interface with the
9770 ``trace'' feature of Autoconf.  The way to scan @file{configure.in} at
9771 this time was to read the file and grep the various macro of interest
9772 to Automake.  Doing so could break in many unexpected ways; automake
9773 could miss some definition (for instance @samp{AC_SUBST([$1], [$2])}
9774 where the arguments are known only when M4 is run), or conversely it
9775 could detect some macro that was not expanded (because it is called
9776 conditionally).  In the CVS version of Autoconf, Akim had implemented
9777 the @option{--trace} option, which provides accurate information about
9778 where macros are actually called and with what arguments.  Akim will
9779 equip Automake with a second @file{configure.in} scanner that uses
9780 this @option{--trace} interface.  Since it was not sensible to drop the
9781 Autoconf 2.13 compatibility yet, this experimental scanner was only
9782 used when an environment variable was set, the traditional
9783 grep-scanner being still the default.
9785 @item 2001-04-25 Gary V.@tie{}Vaughan releases Libtool 1.4
9787 It has been more than two years since Automake 1.4, CVS Automake has
9788 suffered lot's of heavy changes and still is not ready for release.
9789 Libtool 1.4 had to be distributed with a patch against Automake 1.4.
9791 @item 2001-05-08 Automake 1.4-p1
9792 @itemx 2001-05-24 Automake 1.4-p2
9794 Gary V.@tie{}Vaughan, the principal Libtool maintainer, makes a ``patch
9795 release'' of Automake:
9797 @quotation
9798 The main purpose of this release is to have a stable automake
9799 which is compatible with the latest stable libtool.
9800 @end quotation
9802 The release also contains obvious fixes for bugs in Automake 1.4,
9803 some of which were reported almost monthly.
9805 @item 2001-05-21 Akim Demaille releases Autoconf 2.50
9807 @item 2001-06-07 Automake 1.4-p3
9808 @itemx 2001-06-10 Automake 1.4-p4
9809 @itemx 2001-07-15 Automake 1.4-p5
9811 Gary continues his patch-release series.  These also add support for
9812 some new Autoconf 2.50 idioms.  Essentially, Autoconf now advocates
9813 @file{configure.ac} over @file{configure.in}, and it introduces a new
9814 syntax for @code{AC_OUTPUT}ing files.
9816 @item 2001-08-23 Automake 1.5
9818 A major and long-awaited release, that comes more than two years after
9819 1.4.  It brings many changes, among which:
9820 @itemize
9821 @item The new dependency tracking scheme that uses @command{depcomp}.
9822 Aside from the improvement on the dependency tracking itself
9823 (@pxref{Dependency Tracking Evolution}), this also streamlines the use
9824 of automake generated @file{Makefile.in}s as the @file{Makefile.in}s
9825 used during development are now the same as those used in
9826 distributions.  Before that the @file{Makefile.in}s generated for
9827 maintainers required GNU @command{make} and GCC, they were different
9828 from the portable @file{Makefile} generated for distribution; this was
9829 causing some confusion.
9831 @item Support for per-target compilation flags.
9833 @item Support for reference to files in subdirectories in most
9834 @file{Makefile.am} variables.
9836 @item Introduction of the @code{dist_}, @code{nodist_}, and @code{nobase_}
9837 prefixes.
9838 @item Perl 4 support is finally dropped.
9839 @end itemize
9841 1.5 did broke several packages that worked with 1.4.  Enough so that
9842 Linux distributions could not easily install the new Automake version
9843 without breaking many of the packages for which they had to run
9844 @command{automake}.
9846 Some of these breakages were effectively bugs that would eventually be
9847 fixed in the next release.  However, a lot of damage was caused by
9848 some changes made deliberately to render Automake stricter on some
9849 setup we did consider bogus.  For instance, @samp{make distcheck} was
9850 improved to check that @samp{make uninstall} did remove all the files
9851 @samp{make install} installed, that @samp{make distclean} did not omit
9852 some file, and that a VPATH build would work even if the source
9853 directory was read-only.  Similarly, Automake now rejects multiple
9854 definitions of the same variable (because that would mix very badly
9855 with conditionals), and @samp{+=} assignments with no previous
9856 definition.  Because these changes all occurred suddenly after 1.4 had
9857 been established for more that two years, it hurt users.
9859 To make matter worse, meanwhile Autoconf (now at version 2.52) was
9860 facing similar troubles, for similar reasons.
9862 @item 2002-03-05 Automake 1.6
9864 This release introduced versioned installation (@pxref{API
9865 versioning}).  This was mainly pushed by Havoc Pennington, taking the
9866 GNOME source tree as motive: due to incompatibilities between the
9867 autotools it's impossible for the GNOME packages to switch to Autoconf
9868 2.53 and Automake 1.5 all at once, so they are currently stuck with
9869 Autoconf 2.13 and Automake 1.4.
9871 The idea was to call this version @file{automake-1.6}, call all its
9872 bug-fix versions identically, and switch to @file{automake-1.7} for
9873 the next release that adds new features or changes some rules.  This
9874 scheme implies maintaining a bug-fix branch in addition to the
9875 development trunk, which means more work from the maintainer, but
9876 providing regular bug-fix releases proved to be really worthwhile.
9878 Like 1.5, 1.6 also introduced a bunch of incompatibilities, meant or
9879 not.  Perhaps the more annoying was the dependence on the newly
9880 released Autoconf 2.53.  Autoconf seemed to have stabilized enough
9881 since its explosive 2.50 release, and included changes required to fix
9882 some bugs in Automake.  In order to upgrade to Automake 1.6, people
9883 now had to upgrade Autoconf too; for some packages it was no picnic.
9885 While versioned installation helped people to upgrade, it also
9886 unfortunately allowed people not to upgrade.  At the time of writing,
9887 some Linux distributions are shipping packages for Automake 1.4, 1.5,
9888 1.6, 1.7, 1.8, and 1.9.  Most of these still install 1.4 by default.
9889 Some distribution also call 1.4 the ``stable'' version, and present
9890 ``1.9'' as the development version; this does not really makes sense
9891 since 1.9 is way more solid than 1.4.  All this does not help the
9892 newcomer.
9894 @item 2002-04-11 Automake 1.6.1
9896 1.6, and the upcoming 1.4-p6 release were the last release by Tom.
9897 This one and those following will be handled by Alexandre
9898 Duret-Lutz.  Tom is still around, and will be there until about 1.7,
9899 but his interest into Automake is drifting away towards projects like
9900 @command{gcj}.
9902 Alexandre has been using Automake since 2000, and started to
9903 contribute mostly on Akim's incitement (Akim and Alexandre have been
9904 working in the same room from 1999 to 2002).  In 2001 and 2002 he had
9905 a lot of free time to enjoy hacking Automake.
9907 @item 2002-06-14 Automake 1.6.2
9909 @item 2002-07-28 Automake 1.6.3
9910 @itemx 2002-07-28 Automake 1.4-p6
9912 Two releases on the same day.  1.6.3 is a bug-fix release.
9914 Tom Tromey backported the versioned installation mechanism on the 1.4
9915 branch, so that Automake 1.6.x and Automake 1.4-p6 could be installed
9916 side by side.  Another request from the GNOME folks.
9918 @item 2002-09-25 Automake 1.7
9920 This release switches to the new @file{configure.ac} scanner Akim
9921 was experimenting in 1.5.
9923 @item 2002-10-16 Automake 1.7.1
9924 @itemx 2002-12-06 Automake 1.7.2
9925 @itemx 2003-02-20 Automake 1.7.3
9926 @itemx 2003-04-23 Automake 1.7.4
9927 @itemx 2003-05-18 Automake 1.7.5
9928 @itemx 2003-07-10 Automake 1.7.6
9929 @itemx 2003-09-07 Automake 1.7.7
9930 @itemx 2003-10-07 Automake 1.7.8
9932 Many bug-fix releases.  1.7 lasted because the development version
9933 (upcoming 1.8) was suffering some major internal revamping.
9935 @item 2003-10-26 Automake on screen
9937 Episode 49, `Repercussions', in the third season of the `Alias' TV
9938 show is first aired.
9940 Marshall, one of the character, is working on a computer virus that he
9941 has to modify before it gets into the wrong hands or something like
9942 that.  The screenshots you see do not show any program code, they show
9943 a @file{Makefile.in} @code{generated by automake}...
9945 @item 2003-11-09 Automake 1.7.9
9947 @item 2003-12-10 Automake 1.8
9949 The most striking update is probably that of @command{aclocal}.
9951 @command{aclocal} now uses @code{m4_include} in the produced
9952 @code{aclocal.m4} when the included macros are already distributed
9953 with the package (an idiom used in many packages), which reduces code
9954 duplication.  Many people liked that, but in fact this change was
9955 really introduced to fix a bug in rebuild rules: @file{Makefile.in}
9956 must be rebuilt whenever a dependency of @file{configure} changes, but
9957 all the @file{m4} files included in @file{aclocal.m4} where unknown
9958 from @command{automake}.  Now @command{automake} can just trace the
9959 @code{m4_include}s to discover the dependencies.
9961 @command{aclocal} also starts using the @option{--trace} Autoconf option
9962 in order to discover used macros more accurately.  This will turn out
9963 to be very tricky (later releases will improve this) as people had
9964 devised many ways to cope with the limitation of previous
9965 @command{aclocal} versions, notably using handwritten
9966 @code{m4_include}s: @command{aclocal} must make sure not to redefine a
9967 rule that is already included by such statement.
9969 Automake also has seen its guts rewritten.  Although this rewriting
9970 took a lot of efforts, it is only apparent to the users in that some
9971 constructions previously disallowed by the implementation now work
9972 nicely.  Conditionals, Locations, Variable and Rule definitions,
9973 Options: these items on which Automake works have been rewritten as
9974 separate Perl modules, and documented.
9976 @itemx 2004-01-11 Automake 1.8.1
9977 @itemx 2004-01-12 Automake 1.8.2
9978 @itemx 2004-03-07 Automake 1.8.3
9979 @itemx 2004-04-25 Automake 1.8.4
9980 @itemx 2004-05-16 Automake 1.8.5
9982 @item 2004-07-28 Automake 1.9
9984 This release tries to simplify the compilation rules it outputs to
9985 reduce the size of the Makefile.  The complaint initially come from
9986 the libgcj developers.  Their @file{Makefile.in} generated with
9987 Automake 1.4 and custom build rules (1.4 did not support compiled
9988 Java) is 250KB@.  The one generated by 1.8 was over 9MB@!  1.9 gets it
9989 down to 1.2MB@.
9991 Aside from this it contains mainly minor changes and bug-fixes.
9993 @itemx 2004-08-11 Automake 1.9.1
9994 @itemx 2004-09-19 Automake 1.9.2
9996 Automake has ten years.  This chapter of the manual was initially
9997 written for this occasion.
9999 @end table
10001 @node Dependency Tracking Evolution
10002 @section Dependency Tracking in Automake
10004 Over the years Automake has deployed three different dependency
10005 tracking methods.  Each method, including the current one, has had
10006 flaws of various sorts.  Here we lay out the different dependency
10007 tracking methods, their flaws, and their fixes.  We conclude with
10008 recommendations for tool writers, and by indicating future directions
10009 for dependency tracking work in Automake.
10011 @subsection First Take
10012 @unnumberedsubsubsec Description
10014 Our first attempt at automatic dependency tracking was based on the
10015 method recommended by GNU @command{make}.  (@pxref{Automatic
10016 Prerequisites, , Generating Prerequisites Automatically, make, The GNU
10017 make Manual})
10019 This version worked by precomputing dependencies ahead of time.  For
10020 each source file, it had a special @file{.P} file that held the
10021 dependencies.  There was a rule to generate a @file{.P} file by
10022 invoking the compiler appropriately.  All such @file{.P} files were
10023 included by the @file{Makefile}, thus implicitly becoming dependencies
10024 of @file{Makefile}.
10026 @unnumberedsubsubsec Bugs
10028 This approach had several critical bugs.
10030 @itemize
10031 @item
10032 The code to generate the @file{.P} file relied on @command{gcc}.
10033 (A limitation, not technically a bug.)
10034 @item
10035 The dependency tracking mechanism itself relied on GNU @command{make}.
10036 (A limitation, not technically a bug.)
10037 @item
10038 Because each @file{.P} file was a dependency of @file{Makefile}, this
10039 meant that dependency tracking was done eagerly by @command{make}.
10040 For instance, @samp{make clean} would cause all the dependency files
10041 to be updated, and then immediately removed.  This eagerness also
10042 caused problems with some configurations; if a certain source file
10043 could not be compiled on a given architecture for some reason,
10044 dependency tracking would fail, aborting the entire build.
10045 @item
10046 As dependency tracking was done as a pre-pass, compile times were
10047 doubled--the compiler had to be run twice per source file.
10048 @item
10049 @samp{make dist} re-ran @command{automake} to generate a
10050 @file{Makefile} that did not have automatic dependency tracking (and
10051 that was thus portable to any version of @command{make}).  In order to
10052 do this portably, Automake had to scan the dependency files and remove
10053 any reference that was to a source file not in the distribution.
10054 This process was error-prone.  Also, if @samp{make dist} was run in an
10055 environment where some object file had a dependency on a source file
10056 that was only conditionally created, Automake would generate a
10057 @file{Makefile} that referred to a file that might not appear in the
10058 end user's build.  A special, hacky mechanism was required to work
10059 around this.
10060 @end itemize
10062 @unnumberedsubsubsec Historical Note
10064 The code generated by Automake is often inspired by the
10065 @file{Makefile} style of a particular author.  In the case of the first
10066 implementation of dependency tracking, I believe the impetus and
10067 inspiration was Jim Meyering.  (I could be mistaken.  If you know
10068 otherwise feel free to correct me.)
10070 @subsection Dependencies As Side Effects
10071 @unnumberedsubsubsec Description
10073 The next refinement of Automake's automatic dependency tracking scheme
10074 was to implement dependencies as side effects of the compilation.
10075 This was aimed at solving the most commonly reported problems with the
10076 first approach.  In particular we were most concerned with eliminating
10077 the weird rebuilding effect associated with make clean.
10079 In this approach, the @file{.P} files were included using the
10080 @code{-include} command, which let us create these files lazily.  This
10081 avoided the @samp{make clean} problem.
10083 We only computed dependencies when a file was actually compiled.  This
10084 avoided the performance penalty associated with scanning each file
10085 twice.  It also let us avoid the other problems associated with the
10086 first, eager, implementation.  For instance, dependencies would never
10087 be generated for a source file that was not compilable on a given
10088 architecture (because it in fact would never be compiled).
10090 @unnumberedsubsubsec Bugs
10092 @itemize
10093 @item
10094 This approach also relied on the existence of @command{gcc} and GNU
10095 @command{make}.  (A limitation, not technically a bug.)
10096 @item
10097 Dependency tracking was still done by the developer, so the problems
10098 from the first implementation relating to massaging of dependencies by
10099 @samp{make dist} were still in effect.
10100 @item
10101 This implementation suffered from the ``deleted header file'' problem.
10102 Suppose a lazily-created @file{.P} file includes a dependency on a
10103 given header file, like this:
10105 @example
10106 maude.o: maude.c something.h
10107 @end example
10109 Now suppose that the developer removes @file{something.h} and updates
10110 @file{maude.c} so that this include is no longer needed.  If he runs
10111 @command{make}, he will get an error because there is no way to create
10112 @file{something.h}.
10114 We fixed this problem in a later release by further massaging the
10115 output of @command{gcc} to include a dummy dependency for each header
10116 file.
10117 @end itemize
10119 @subsection Dependencies for the User
10120 @unnumberedsubsubsec Description
10122 The bugs associated with @samp{make dist}, over time, became a real
10123 problem.  Packages using Automake were being built on a large number
10124 of platforms, and were becoming increasingly complex.  Broken
10125 dependencies were distributed in ``portable'' @file{Makefile.in}s,
10126 leading to user complaints.  Also, the requirement for @command{gcc}
10127 and GNU @command{make} was a constant source of bug reports.  The next
10128 implementation of dependency tracking aimed to remove these problems.
10130 We realized that the only truly reliable way to automatically track
10131 dependencies was to do it when the package itself was built.  This
10132 meant discovering a method portable to any version of make and any
10133 compiler.  Also, we wanted to preserve what we saw as the best point
10134 of the second implementation: dependency computation as a side effect
10135 of compilation.
10137 In the end we found that most modern make implementations support some
10138 form of include directive.  Also, we wrote a wrapper script that let
10139 us abstract away differences between dependency tracking methods for
10140 compilers.  For instance, some compilers cannot generate dependencies
10141 as a side effect of compilation.  In this case we simply have the
10142 script run the compiler twice.  Currently our wrapper script
10143 (@command{depcomp}) knows about twelve different compilers (including
10144 a "compiler" that simply invokes @command{makedepend} and then the
10145 real compiler, which is assumed to be a standard Unix-like C compiler
10146 with no way to do dependency tracking).
10148 @unnumberedsubsubsec Bugs
10150 @itemize
10151 @item
10152 Running a wrapper script for each compilation slows down the build.
10153 @item
10154 Many users don't really care about precise dependencies.
10155 @item
10156 This implementation, like every other automatic dependency tracking
10157 scheme in common use today (indeed, every one we've ever heard of),
10158 suffers from the ``duplicated new header'' bug.
10160 This bug occurs because dependency tracking tools, such as the
10161 compiler, only generate dependencies on the successful opening of a
10162 file, and not on every probe.
10164 Suppose for instance that the compiler searches three directories for
10165 a given header, and that the header is found in the third directory.
10166 If the programmer erroneously adds a header file with the same name to
10167 the first directory, then a clean rebuild from scratch could fail
10168 (suppose the new header file is buggy), whereas an incremental rebuild
10169 will succeed.
10171 What has happened here is that people have a misunderstanding of what
10172 a dependency is.  Tool writers think a dependency encodes information
10173 about which files were read by the compiler.  However, a dependency
10174 must actually encode information about what the compiler tried to do.
10176 This problem is not serious in practice.  Programmers typically do not
10177 use the same name for a header file twice in a given project.  (At
10178 least, not in C or C++.  This problem may be more troublesome in
10179 Java.)  This problem is easy to fix, by modifying dependency
10180 generators to record every probe, instead of every successful open.
10182 @item
10183 Since automake generates dependencies as a side effect of compilation,
10184 there is a bootstrapping problem when header files are generated by
10185 running a program.  The problem is that, the first time the build is
10186 done, there is no way by default to know that the headers are
10187 required, so make might try to run a compilation for which the headers
10188 have not yet been built.
10190 This was also a problem in the previous dependency tracking implementation.
10192 The current fix is to use @code{BUILT_SOURCES} to list built headers
10193 (@pxref{Sources}).  This causes them to be built before any other
10194 other build rules are run.  This is unsatisfactory as a general
10195 solution, however in practice it seems sufficient for most actual
10196 programs.
10197 @end itemize
10199 This code is used since Automake 1.5.
10201 In GCC 3.0, we managed to convince the maintainers to add special
10202 command-line options to help Automake more efficiently do its job.  We
10203 hoped this would let us avoid the use of a wrapper script when
10204 Automake's automatic dependency tracking was used with @command{gcc}.
10206 Unfortunately, this code doesn't quite do what we want.  In
10207 particular, it removes the dependency file if the compilation fails;
10208 we'd prefer that it instead only touch the file in any way if the
10209 compilation succeeds.
10211 Nevertheless, since Automake 1.7, when a recent @command{gcc} is
10212 detected at @command{configure} time, we inline the
10213 dependency-generation code and do not use the @command{depcomp}
10214 wrapper script.  This makes compilations faster for those using this
10215 compiler (probably our primary user base).  The counterpart is that
10216 because we have to encode two compilation rules in @file{Makefile}
10217 (with or without @command{depcomp}), the produced @file{Makefile}s are
10218 larger.
10220 @subsection Techniques for Computing Dependencies
10222 There are actually several ways for a build tool like Automake to
10223 cause tools to generate dependencies.
10225 @table @asis
10226 @item @command{makedepend}
10227 This was a commonly-used method in the past.  The idea is to run a
10228 special program over the source and have it generate dependency
10229 information.  Traditional implementations of @command{makedepend} ere
10230 not completely precise; ordinarily they were conservative and
10231 discovered too many dependencies.
10232 @item The tool
10233 An obvious way to generate dependencies is to simply write the tool so
10234 that it can generate the information needed by the build tool.  This is
10235 also the most portable method.  Many compilers have an option to
10236 generate dependencies.  Unfortunately, not all tools provide such an
10237 option.
10238 @item The file system
10239 It is possible to write a special file system that tracks opens,
10240 reads, writes, etc, and then feed this information back to the build
10241 tool.  @command{clearmake} does this.  This is a very powerful
10242 technique, as it doesn't require cooperation from the
10243 tool.  Unfortunately it is also very difficult to implement and also
10244 not practical in the general case.
10245 @item @code{LD_PRELOAD}
10246 Rather than use the file system, one could write a special library to
10247 intercept @code{open} and other syscalls.  This technique is also quite
10248 powerful, but unfortunately it is not portable enough for use in
10249 @command{automake}.
10250 @end table
10252 @subsection Recommendations for Tool Writers
10254 We think that every compilation tool ought to be able to generate
10255 dependencies as a side effect of compilation.  Furthermore, at least
10256 while @command{make}-based tools are nearly universally in use (at
10257 least in the free software community), the tool itself should generate
10258 dummy dependencies for header files, to avoid the deleted header file
10259 bug.  Finally, the tool should generate a dependency for each probe,
10260 instead of each successful file open, in order to avoid the duplicated
10261 new header bug.
10263 @subsection Future Directions for Automake's Dependency Tracking
10265 Currently, only languages and compilers understood by Automake can
10266 have dependency tracking enabled.  We would like to see if it is
10267 practical (and worthwhile) to let this support be extended by the user
10268 to languages unknown to Automake.
10270 @node Releases
10271 @section Release Statistics
10273 The following table (inspired by @samp{perlhist(1)}) quantifies the
10274 evolution of Automake using these metrics:
10276 @table @asis
10277 @item Date, Rel
10278 The date and version of the release.
10279 @item am
10280 The number of lines of the @command{automake} script.
10281 @item acl
10282 The number of lines of the @command{aclocal} script.
10283 @item pm
10284 The number of lines of the @command{Perl} supporting modules.
10285 @item @file{*.am}
10286 The number of lines of the @file{Makefile} fragments.  The number in parenthesis
10287 is the number of files.
10288 @item m4
10289 The number of lines (and files) of Autoconf macros.
10290 @item doc
10291 The number of pages of the documentation (the Postscript version).
10292 @item t
10293 The number of test cases in the test suite.
10294 @end table
10296 @multitable {8888-88-88} {8.8-p8} {8888} {888} {8888} {8888 (88)} {8888 (88)} {888} {888}
10297 @headitem Date   @tab Rel @tab am @tab acl @tab pm @tab @file{*.am} @tab m4 @tab doc @tab t
10298 @item 1994-09-19 @tab CVS    @tab  141 @tab     @tab      @tab  299 (24) @tab           @tab     @tab
10299 @item 1994-11-05 @tab CVS    @tab  208 @tab     @tab      @tab  332 (28) @tab           @tab     @tab
10300 @item 1995-11-23 @tab 0.20   @tab  533 @tab     @tab      @tab  458 (35) @tab           @tab   9 @tab
10301 @item 1995-11-26 @tab 0.21   @tab  613 @tab     @tab      @tab  480 (36) @tab           @tab  11 @tab
10302 @item 1995-11-28 @tab 0.22   @tab 1116 @tab     @tab      @tab  539 (38) @tab           @tab  12 @tab
10303 @item 1995-11-29 @tab 0.23   @tab 1240 @tab     @tab      @tab  541 (38) @tab           @tab  12 @tab
10304 @item 1995-12-08 @tab 0.24   @tab 1462 @tab     @tab      @tab  504 (33) @tab           @tab  14 @tab
10305 @item 1995-12-10 @tab 0.25   @tab 1513 @tab     @tab      @tab  511 (37) @tab           @tab  15 @tab
10306 @item 1996-01-03 @tab 0.26   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
10307 @item 1996-01-03 @tab 0.27   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
10308 @item 1996-01-13 @tab 0.28   @tab 1964 @tab     @tab      @tab  934 (33) @tab           @tab  16 @tab
10309 @item 1996-02-07 @tab 0.29   @tab 2299 @tab     @tab      @tab  936 (33) @tab           @tab  17 @tab
10310 @item 1996-02-24 @tab 0.30   @tab 2544 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  20 @tab 9
10311 @item 1996-03-11 @tab 0.31   @tab 2877 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  29 @tab 17
10312 @item 1996-04-27 @tab 0.32   @tab 3058 @tab     @tab      @tab  921 (31) @tab   85 (1)  @tab  30 @tab 26
10313 @item 1996-05-18 @tab 0.33   @tab 3110 @tab     @tab      @tab  926 (31) @tab  105 (1)  @tab  30 @tab 35
10314 @item 1996-05-28 @tab 1.0    @tab 3134 @tab     @tab      @tab  973 (32) @tab  105 (1)  @tab  30 @tab 38
10315 @item 1997-06-22 @tab 1.2    @tab 6089 @tab 385 @tab      @tab 1294 (36) @tab  592 (23) @tab  37 @tab 126
10316 @item 1998-04-05 @tab 1.3    @tab 6415 @tab 422 @tab      @tab 1470 (39) @tab  741 (26) @tab  39 @tab 156
10317 @item 1999-01-14 @tab 1.4    @tab 7240 @tab 426 @tab      @tab 1591 (40) @tab  734 (23) @tab  51 @tab 197
10318 @item 2001-05-08 @tab 1.4-p1 @tab 7251 @tab 426 @tab      @tab 1591 (40) @tab  734 (23) @tab  51 @tab 197
10319 @item 2001-05-24 @tab 1.4-p2 @tab 7268 @tab 439 @tab      @tab 1591 (40) @tab  734 (23) @tab  49 @tab 197
10320 @item 2001-06-07 @tab 1.4-p3 @tab 7312 @tab 439 @tab      @tab 1591 (40) @tab  734 (23) @tab  49 @tab 197
10321 @item 2001-06-10 @tab 1.4-p4 @tab 7321 @tab 439 @tab      @tab 1591 (40) @tab  734 (23) @tab  49 @tab 198
10322 @item 2001-07-15 @tab 1.4-p5 @tab 7228 @tab 426 @tab      @tab 1596 (40) @tab  734 (23) @tab  51 @tab 198
10323 @item 2001-08-23 @tab 1.5    @tab 8016 @tab 475 @tab  600 @tab 2654 (39) @tab 1166 (32) @tab  63 @tab 327
10324 @item 2002-03-05 @tab 1.6    @tab 8465 @tab 475 @tab 1136 @tab 2732 (39) @tab 1603 (31) @tab  66 @tab 365
10325 @item 2002-04-11 @tab 1.6.1  @tab 8544 @tab 475 @tab 1136 @tab 2741 (39) @tab 1603 (31) @tab  66 @tab 372
10326 @item 2002-06-14 @tab 1.6.2  @tab 8575 @tab 475 @tab 1136 @tab 2800 (39) @tab 1609 (31) @tab  67 @tab 386
10327 @item 2002-07-28 @tab 1.6.3  @tab 8600 @tab 475 @tab 1153 @tab 2809 (39) @tab 1609 (31) @tab  67 @tab 391
10328 @item 2002-07-28 @tab 1.4-p6 @tab 7332 @tab 455 @tab      @tab 1596 (40) @tab  735 (24) @tab  49 @tab 197
10329 @item 2002-09-25 @tab 1.7    @tab 9189 @tab 471 @tab 1790 @tab 2965 (39) @tab 1606 (33) @tab  73 @tab 430
10330 @item 2002-10-16 @tab 1.7.1  @tab 9229 @tab 475 @tab 1790 @tab 2977 (39) @tab 1606 (33) @tab  73 @tab 437
10331 @item 2002-12-06 @tab 1.7.2  @tab 9334 @tab 475 @tab 1790 @tab 2988 (39) @tab 1606 (33) @tab  77 @tab 445
10332 @item 2003-02-20 @tab 1.7.3  @tab 9389 @tab 475 @tab 1790 @tab 3023 (39) @tab 1651 (34) @tab  84 @tab 448
10333 @item 2003-04-23 @tab 1.7.4  @tab 9429 @tab 475 @tab 1790 @tab 3031 (39) @tab 1644 (34) @tab  85 @tab 458
10334 @item 2003-05-18 @tab 1.7.5  @tab 9429 @tab 475 @tab 1790 @tab 3033 (39) @tab 1645 (34) @tab  85 @tab 459
10335 @item 2003-07-10 @tab 1.7.6  @tab 9442 @tab 475 @tab 1790 @tab 3033 (39) @tab 1660 (34) @tab  85 @tab 461
10336 @item 2003-09-07 @tab 1.7.7  @tab 9443 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (34) @tab  90 @tab 467
10337 @item 2003-10-07 @tab 1.7.8  @tab 9444 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (34) @tab  90 @tab 468
10338 @item 2003-11-09 @tab 1.7.9  @tab 9444 @tab 475 @tab 1790 @tab 3048 (39) @tab 1660 (34) @tab  90 @tab 468
10339 @item 2003-12-10 @tab 1.8    @tab 7171 @tab 585 @tab 7730 @tab 3236 (39) @tab 1666 (36) @tab 104 @tab 521
10340 @item 2004-01-11 @tab 1.8.1  @tab 7217 @tab 663 @tab 7726 @tab 3287 (39) @tab 1686 (36) @tab 104 @tab 525
10341 @item 2004-01-12 @tab 1.8.2  @tab 7217 @tab 663 @tab 7726 @tab 3288 (39) @tab 1686 (36) @tab 104 @tab 526
10342 @item 2004-03-07 @tab 1.8.3  @tab 7214 @tab 686 @tab 7735 @tab 3303 (39) @tab 1695 (36) @tab 111 @tab 530
10343 @item 2004-04-25 @tab 1.8.4  @tab 7214 @tab 686 @tab 7736 @tab 3310 (39) @tab 1701 (36) @tab 112 @tab 531
10344 @item 2004-05-16 @tab 1.8.5  @tab 7240 @tab 686 @tab 7736 @tab 3299 (39) @tab 1701 (36) @tab 112 @tab 533
10345 @item 2004-07-28 @tab 1.9    @tab 7508 @tab 715 @tab 7794 @tab 3352 (40) @tab 1812 (37) @tab 115 @tab 551
10346 @item 2004-08-11 @tab 1.9.1  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (37) @tab 115 @tab 552
10347 @item 2004-09-19 @tab 1.9.2  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (37) @tab 132 @tab 554
10348 @end multitable
10351 @c ========================================================== Appendices
10353 @page
10354 @node Copying This Manual
10355 @appendix Copying This Manual
10357 @menu
10358 * GNU Free Documentation License::  License for copying this manual
10359 @end menu
10361 @include fdl.texi
10363 @page
10364 @node Indices
10365 @appendix Indices
10367 @menu
10368 * Macro Index::                 Index of Autoconf macros
10369 * Variable Index::              Index of Makefile variables
10370 * General Index::               General index
10371 @end menu
10373 @node Macro Index
10374 @appendixsec Macro Index
10376 @printindex fn
10378 @node Variable Index
10379 @appendixsec Variable Index
10381 @printindex vr
10383 @node General Index
10384 @appendixsec General Index
10386 @printindex cp
10389 @page
10390 @contents
10391 @bye
10393 @c  LocalWords:  texinfo setfilename settitle setchapternewpage texi direntry
10394 @c  LocalWords:  dircategory in's aclocal ifinfo titlepage Tromey vskip pt sp
10395 @c  LocalWords:  filll defcodeindex ov cv op tr syncodeindex fn cp vr ifnottex
10396 @c  LocalWords:  dir Automake's ac Dist Gnits gnits cygnus dfn Autoconf's pxref
10397 @c  LocalWords:  cindex Autoconf autoconf perl samp cvs dist trindex SUBST foo
10398 @c  LocalWords:  xs emph FIXME ref vindex pkglibdir pkgincludedir pkgdatadir mt
10399 @c  LocalWords:  pkg libdir cpio bindir sbindir rmt pax sbin zar zardir acindex
10400 @c  LocalWords:  HTML htmldir html noinst TEXINFOS nodist nobase strudel CFLAGS
10401 @c  LocalWords:  libmumble CC YFLAGS ansi knr itemx de fication config url comp
10402 @c  LocalWords:  depcomp elisp sh mdate mkinstalldirs mkdir py tex dvi ps pdf
10403 @c  LocalWords:  ylwrap zardoz INIT gettext acinclude mv FUNCS LIBOBJS LDADD fr
10404 @c  LocalWords:  uref featureful dnl src LINGUAS es ko nl pl sl sv PROG ISC doc
10405 @c  LocalWords:  POSIX STDC fcntl FUNC ALLOCA blksize struct stat intl po chmod
10406 @c  LocalWords:  ChangeLog SUBDIRS gettextize gpl testdata getopt INTLLIBS cpp
10407 @c  LocalWords:  localedir datadir DLOCALEDIR DEXIT CPPFLAGS autoreconf opindex
10408 @c  LocalWords:  AUX var symlink deps Wno Wnone package's aclocal's distclean
10409 @c  LocalWords:  ltmain xref LIBSOURCE LIBSOURCES LIBOBJ MEMCMP vs RANLIB CXX
10410 @c  LocalWords:  LDFLAGS LIBTOOL libtool XTRA LIBS gettext's acdir APIVERSION
10411 @c  LocalWords:  dirlist noindent usr MULTILIB multilib Multilibs TIOCGWINSZ sc
10412 @c  LocalWords:  GWINSZ termios SRCDIR tarball bzip LISPDIR lispdir XEmacs CCAS
10413 @c  LocalWords:  emacsen MicroEmacs CCASFLAGS UX GCJ gcj GCJFLAGS posix DMALLOC
10414 @c  LocalWords:  dmalloc ldmalloc REGEX regex rx DEPDIR DEP DEFUN aclocaldir fi
10415 @c  LocalWords:  mymacro myothermacro AMFLAGS autopoint autogen libtoolize yum
10416 @c  LocalWords:  autoheader README MAKEFLAGS subdir Inetutils sync COND endif
10417 @c  LocalWords:  Miller's installable includedir inc pkgdata EXEEXT libexec bsd
10418 @c  LocalWords:  pkglib libexecdir prog libcpio cpio's dlopen dlpreopen linux
10419 @c  LocalWords:  subsubsection OBJEXT esac lib LTLIBRARIES liblob LIBADD AR ar
10420 @c  LocalWords:  ARFLAGS cru ing maude libgettext lo LTLIBOBJS rpath SGI PRE yy
10421 @c  LocalWords:  libmaude CCLD CXXFLAGS FFLAGS LFLAGS OBJCFLAGS RFLAGS DEFS cc
10422 @c  LocalWords:  SHORTNAME vtable srcdir nostdinc basename yxx cxx ll lxx gdb
10423 @c  LocalWords:  lexers yymaxdepth maxdepth yyparse yylex yyerror yylval lval
10424 @c  LocalWords:  yychar yydebug yypact yyr yydef def yychk chk yypgo pgo yyact
10425 @c  LocalWords:  yyexca exca yyerrflag errflag yynerrs nerrs yyps yypv pv yys
10426 @c  LocalWords:  yystate yytmp tmp yyv yyval val yylloc lloc yyreds yytoks toks
10427 @c  LocalWords:  yylhs yylen yydefred yydgoto yysindex yyrindex yygindex yyname
10428 @c  LocalWords:  yytable yycheck yyrule byacc CXXCOMPILE CXXLINK FLINK cfortran
10429 @c  LocalWords:  Catalogue preprocessable FLIBS libfoo baz JAVACFLAGS java exe
10430 @c  LocalWords:  SunOS fying basenames exeext uninstalled oldinclude kr FSF's
10431 @c  LocalWords:  pkginclude oldincludedir sysconf sharedstate localstate gcc rm
10432 @c  LocalWords:  sysconfdir sharedstatedir localstatedir preexist CLEANFILES gz
10433 @c  LocalWords:  unnumberedsubsec depfile tmpdepfile depmode const interoperate
10434 @c  LocalWords:  JAVAC javac JAVAROOT builddir CLASSPATH ENV pyc pyo pkgpython
10435 @c  LocalWords:  pyexecdir pkgpyexecdir Python's pythondir pkgpythondir txi ois
10436 @c  LocalWords:  installinfo vers MAKEINFO makeinfo MAKEINFOFLAGS noinstall rf
10437 @c  LocalWords:  mandir thesame alsothesame installman myexecbin DESTDIR Pinard
10438 @c  LocalWords:  uninstall installdirs uninstalls MOSTLYCLEANFILES mostlyclean
10439 @c  LocalWords:  DISTCLEANFILES MAINTAINERCLEANFILES gzip'd GZIP gzip shar exp
10440 @c  LocalWords:  distdir distcheck distcleancheck listfiles distuninstallcheck
10441 @c  LocalWords:  VPATH tarfile stdout XFAIL DejaGnu dejagnu DEJATOOL runtest ln
10442 @c  LocalWords:  RUNTESTDEFAULTFLAGS toolchain RUNTESTFLAGS asis readme DVIPS
10443 @c  LocalWords:  installcheck gzipped tarZ std utils etags mkid multilibbing cd
10444 @c  LocalWords:  ARGS taggable ETAGSFLAGS lang ctags CTAGSFLAGS GTAGS gtags idl
10445 @c  LocalWords:  foocc doit idlC multilibs ABIs cmindex defmac ARG enableval FC
10446 @c  LocalWords:  MSG xtrue DBG pathchk CYGWIN afile proglink versioned CVS's TE
10447 @c  LocalWords:  wildcards Autoconfiscated subsubheading autotools Meyering API
10448 @c  LocalWords:  ois's wildcard Wportability cartouche vrindex printindex Duret
10449 @c  LocalWords:  DSOMEFLAG DVERSION automake Lutz insertcopying versioning FAQ
10450 @c  LocalWords:  LTLIBOBJ Libtool's libtool's libltdl dlopening itutions libbar
10451 @c  LocalWords:  WANTEDLIBS libhello sublibraries libtop libsub dlopened Ratfor
10452 @c  LocalWords:  mymodule timestamps timestamp underquoted MAKEINFOHTMLFLAGS te
10453 @c  LocalWords:  GNUmakefile buildir Subpackages subpackage's subpackages aux
10454 @c  LocalWords:  detailmenu Timeline pwd reldir AUTOM autom PREREQ FOOBAR libc
10455 @c  LocalWords:  libhand subpackage moduleN libmain libmisc FCFLAGS FCCOMPILE
10456 @c  LocalWords:  FCLINK subst sed ELCFILES elc MAKEINFOHTML dvips esyscmd ustar
10457 @c  LocalWords:  tarballs Woverride scrdir vfi ELFILES djm AutoMake honkin FSF
10458 @c  LocalWords:  fileutils precanned MacKenzie's reimplement termutils Tromey's
10459 @c  LocalWords:  cois gnitsians LIBPROGRAMS progs LIBLIBRARIES Textutils Ulrich
10460 @c  LocalWords:  Matzigkeit Drepper's Gord Matzigkeit's jm Dalley Debian eg org
10461 @c  LocalWords:  Administrivia ILU CORBA Sourceware Molenda sourceware Elliston
10462 @c  LocalWords:  dep Oliva Akim Demaille Aiieeee Demaillator Akim's sourcequake
10463 @c  LocalWords:  grep backported screenshots libgcj KB unnumberedsubsubsec pre
10464 @c  LocalWords:  precomputing hacky makedepend inline clearmake LD PRELOAD Rel
10465 @c  LocalWords:  syscalls perlhist acl pm multitable headitem fdl appendixsec
10466 @c  LocalWords:  LTALLOCA MALLOC malloc memcmp strdup alloca libcompat xyz DFOO
10467 @c  LocalWords:  unprefixed buildable preprocessed DBAZ DDATADIR WARNINGCFLAGS
10468 @c  LocalWords:  LIBFOOCFLAGS LIBFOOLDFLAGS ftable testSubDir obj LIBTOOLFLAGS
10469 @c  LocalWords:  barexec Pinard's