* configure.ac, NEWS: Bump version to 1.8.0c.
[automake.git] / doc / automake.texi
blobb4d2ea154a03ea006d89d45acb9de53cf911d23c
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 which creates GNU standards-compliant
14 Makefiles from template files.
16 Copyright @copyright{} 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
17 2003 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.1 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 @dircategory Software development
36 @direntry
37 * automake: (automake).         Making Makefile.in's.
38 @end direntry
40 @dircategory Individual utilities
41 @direntry
42 * aclocal: (automake)Invoking aclocal.          Generating aclocal.m4.
43 @end direntry
45 @titlepage
46 @title GNU Automake
47 @subtitle For version @value{VERSION}, @value{UPDATED}
48 @author David MacKenzie
49 @author Tom Tromey
50 @author Alexandre Duret-Lutz
51 @page
52 @vskip 0pt plus 1filll
53 @insertcopying
54 @end titlepage
56 @c Define an index of configure output variables.
57 @defcodeindex ov
58 @c Define an index of configure variables.
59 @defcodeindex cv
60 @c Define an index of options.
61 @defcodeindex op
62 @c Define an index of targets.
63 @defcodeindex tr
64 @c Define an index of commands.
65 @defcodeindex cm
67 @c Put the macros and variables into their own index.
68 @c @syncodeindex fn cp
69 @syncodeindex ov vr
70 @syncodeindex cv vr
71 @syncodeindex fn vr
73 @c Put everything else into one index (arbitrarily chosen to be the concept index).
74 @syncodeindex op cp
75 @syncodeindex tr cp
76 @syncodeindex cm cp
78 @ifnottex
79 @node Top
80 @comment  node-name,  next,  previous,  up
81 @top GNU Automake
83 @insertcopying
85 @menu
86 * Introduction::                Automake's purpose
87 * Generalities::                General ideas
88 * Examples::                    Some example packages
89 * Invoking Automake::           Creating a Makefile.in
90 * configure::                   Scanning configure.ac or configure.in
91 * Top level::                   The top-level Makefile.am
92 * Alternative::                 An alternative approach to subdirectories
93 * Programs::                    Building programs and libraries
94 * Other objects::               Other derived objects
95 * Other GNU Tools::             Other GNU Tools
96 * Documentation::               Building documentation
97 * Install::                     What gets installed
98 * Clean::                       What gets cleaned
99 * Dist::                        What goes in a distribution
100 * Tests::                       Support for test suites
101 * Rebuilding::                  Automatic rebuilding of Makefile
102 * Options::                     Changing Automake's behavior
103 * Miscellaneous::               Miscellaneous rules
104 * Include::                     Including extra files in an Automake template.
105 * Conditionals::                Conditionals
106 * Gnits::                       The effect of @code{--gnu} and @code{--gnits}
107 * Cygnus::                      The effect of @code{--cygnus}
108 * Extending::                   Extending Automake
109 * Distributing::                Distributing the Makefile.in
110 * API versioning::              About compatibility between Automake versions
111 * FAQ::                         Frequently Asked Questions
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 * aclocal options::             aclocal command line arguments
139 * Macro search path::           Modifying aclocal's search path
140 * Macros::                      Autoconf macros supplied with Automake
141 * Extending aclocal::           Writing your own aclocal macros
142 * Local Macros::                Organizing local macros
143 * Future of aclocal::           aclocal's scheduled death
145 Auto-generating aclocal.m4
147 * aclocal options::             Options supported by aclocal
148 * Macro search path::           How aclocal finds .m4 files
150 Autoconf macros supplied with Automake
152 * Public macros::               Macros that you can use.
153 * Private macros::              Macros that you should not use.
155 Building Programs and Libraries
157 * A Program::                   Building a program
158 * A Library::                   Building a library
159 * A Shared Library::            Building a Libtool library
160 * Program and Library Variables::  Variables controlling program and
161                                 library builds
162 * Default _SOURCES::            Default source files
163 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
164 * Program variables::           Variables used when building a program
165 * Yacc and Lex::                Yacc and Lex support
166 * C++ Support::                 Compiling C++ sources
167 * Assembly Support::            Compiling assembly sources
168 * Fortran 77 Support::          Compiling Fortran 77 sources
169 * Java Support::                Compiling Java sources
170 * Support for Other Languages::  Compiling other languages
171 * ANSI::                        Automatic de-ANSI-fication
172 * Dependencies::                Automatic dependency tracking
173 * EXEEXT::                      Support for executable extensions
175 Building a program
177 * Program Sources::             Defining program sources
178 * Linking::                     Linking with libraries or extra objects
179 * Conditional Sources::         Handling conditional sources
180 * Conditional Programs::        Building program conditionally
182 Building a Shared Library
184 * Libtool Concept::             Introducing Libtool
185 * Libtool Libraries::           Declaring Libtool Libraries
186 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
187 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
188 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
189 * Libtool Modules::             Building Libtool Modules
190 * Libtool Flags::               Using _LIBADD and _LDFLAGS
191 * LTLIBOBJ::                    Using $(LTLIBOBJ)
192 * Libtool Issues::              Common Issues Related to Libtool's Use
194 Fortran 77 Support
196 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
197 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
198 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
200 Mixing Fortran 77 With C and C++
202 * How the Linker is Chosen::    Automatic linker selection
204 Other Derived Objects
206 * Scripts::                     Executable scripts
207 * Headers::                     Header files
208 * Data::                        Architecture-independent data files
209 * Sources::                     Derived sources
211 Built sources
213 * Built sources example::       Several ways to handle built sources.
215 Other GNU Tools
217 * Emacs Lisp::                  Emacs Lisp
218 * gettext::                     Gettext
219 * Libtool::                     Libtool
220 * Java::                        Java
221 * Python::                      Python
223 Building documentation
225 * Texinfo::                     Texinfo
226 * Man pages::                   Man pages
228 Miscellaneous Rules
230 * Tags::                        Interfacing to etags and mkid
231 * Suffixes::                    Handling new file extensions
232 * Multilibs::                   Support for multilibs.
234 Frequently Asked Questions about Automake
236 * CVS::                         CVS and generated files
237 * maintainer-mode::             missing and AM_MAINTAINER_MODE
238 * wildcards::                   Why doesn't Automake support wildcards?
239 * distcleancheck::              Files left in build directory after distclean
240 * renamed objects::             Why are object files sometimes renamed?
242 Copying This Manual
244 * GNU Free Documentation License::  License for copying this manual
246 Indices
248 * Macro and Variable Index::    Index of Autoconf macros and Automake variables
249 * General Index::               General index
251 @end detailmenu
252 @end menu
254 @end ifnottex
257 @node Introduction
258 @chapter Introduction
260 Automake is a tool for automatically generating @file{Makefile.in}s from
261 files called @file{Makefile.am}.  Each @file{Makefile.am} is basically a
262 series of @code{make} variable definitions@footnote{These variables are
263 also called @dfn{make macros} in Make terminology, however in this
264 manual we reserve the term @dfn{macro} for Autoconf's macros.}, with
265 rules being thrown in occasionally.  The generated @file{Makefile.in}s
266 are compliant with the GNU Makefile standards.
268 @cindex GNU Makefile standards
270 The GNU Makefile Standards Document
271 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
272 is long, complicated, and subject to change.  The goal of Automake is to
273 remove the burden of Makefile maintenance from the back of the
274 individual GNU maintainer (and put it on the back of the Automake
275 maintainer).
277 The typical Automake input file is simply a series of variable definitions.
278 Each such file is processed to create a @file{Makefile.in}.  There
279 should generally be one @file{Makefile.am} per directory of a project.
281 @cindex Constraints of Automake
282 @cindex Automake constraints
284 Automake does constrain a project in certain ways; for instance it
285 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
286 autoconf, The Autoconf Manual}), and enforces certain restrictions on
287 the @file{configure.ac} contents@footnote{Older Autoconf versions used
288 @file{configure.in}.  Autoconf 2.50 and greater promotes
289 @file{configure.ac} over @file{configure.in}.  The rest of this
290 documentation will refer to @file{configure.ac}, but Automake also
291 supports @file{configure.in} for backward compatibility.}.
293 @cindex Automake requirements
294 @cindex Requirements, Automake
296 Automake requires @code{perl} in order to generate the
297 @file{Makefile.in}s.  However, the distributions created by Automake are
298 fully GNU standards-compliant, and do not require @code{perl} in order
299 to be built.
301 @cindex BUGS, reporting
302 @cindex Reporting BUGS
303 @cindex E-mail, bug reports
305 Mail suggestions and bug reports for Automake to
306 @email{bug-automake@@gnu.org}.
309 @node Generalities
310 @chapter General ideas
312 The following sections cover a few basic ideas that will help you
313 understand how Automake works.
315 @menu
316 * General Operation::           General operation of Automake
317 * Strictness::                  Standards conformance checking
318 * Uniform::                     The Uniform Naming Scheme
319 * Canonicalization::            How derived variables are named
320 * User Variables::              Variables reserved for the user
321 * Auxiliary Programs::          Programs automake might require
322 @end menu
325 @node General Operation
326 @section General Operation
328 Automake works by reading a @file{Makefile.am} and generating a
329 @file{Makefile.in}.  Certain variables and rules defined in the
330 @file{Makefile.am} instruct Automake to generate more specialized code;
331 for instance, a @samp{bin_PROGRAMS} variable definition will cause rules
332 for compiling and linking programs to be generated.
334 @cindex Non-standard targets
335 @cindex cvs-dist, non-standard example
336 @trindex cvs-dist
338 The variable definitions and rules in the @file{Makefile.am} are
339 copied verbatim into the generated file.  This allows you to add
340 arbitrary code into the generated @file{Makefile.in}.  For instance
341 the Automake distribution includes a non-standard rule for the
342 @code{cvs-dist} target, which the Automake maintainer uses to make
343 distributions from his source control system.
345 @cindex GNU make extensions
347 Note that most GNU make extensions are not recognized by Automake.  Using
348 such extensions in a @file{Makefile.am} will lead to errors or confusing
349 behavior.
351 @cindex Append operator
352 A special exception is that the GNU make append operator, @samp{+=}, is
353 supported.  This operator appends its right hand argument to the variable
354 specified on the left.  Automake will translate the operator into
355 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
357 Automake tries to keep comments grouped with any adjoining rules or
358 variable definitions.
360 @cindex Make targets, overriding
361 @cindex Make rules, overriding
362 @cindex Overriding make rules
363 @cindex Overriding make targets
365 A rule defined in @file{Makefile.am} generally overrides any such
366 rule of a similar name that would be automatically generated by
367 @code{automake}.  Although this is a supported feature, it is generally
368 best to avoid making use of it, as sometimes the generated rules are
369 very particular.
371 @cindex Variables, overriding
372 @cindex Overriding make variables
374 Similarly, a variable defined in @file{Makefile.am} or
375 @code{AC_SUBST}'ed from @file{configure.ac} will override any
376 definition of the variable that @code{automake} would ordinarily
377 create.  This feature is more often useful than the ability to
378 override a rule.  Be warned that many of the variables generated by
379 @code{automake} are considered to be for internal use only, and their
380 names might change in future releases.
382 @cindex Recursive operation of Automake
383 @cindex Automake, recursive operation
384 @cindex Example of recursive operation
386 When examining a variable definition, Automake will recursively examine
387 variables referenced in the definition.  For example, if Automake is
388 looking at the content of @code{foo_SOURCES} in this snippet
390 @example
391 xs = a.c b.c
392 foo_SOURCES = c.c $(xs)
393 @end example
395 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
396 contents of @code{foo_SOURCES}.
398 @cindex ## (special Automake comment)
399 @cindex Special Automake comment
400 @cindex Comment, special to Automake
402 Automake also allows a form of comment which is @emph{not} copied into
403 the output; all lines beginning with @samp{##} (leading spaces allowed)
404 are completely ignored by Automake.
406 It is customary to make the first line of @file{Makefile.am} read:
408 @cindex Makefile.am, first line
409 @cindex First line of Makefile.am
411 @example
412 ## Process this file with automake to produce Makefile.in
413 @end example
415 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
416 @c I don't know quite what to say.
418 @c FIXME document customary ordering of Makefile.am here!
421 @node Strictness
422 @section Strictness
424 @cindex Non-GNU packages
426 While Automake is intended to be used by maintainers of GNU packages, it
427 does make some effort to accommodate those who wish to use it, but do
428 not want to use all the GNU conventions.
430 @cindex Strictness, defined
431 @cindex Strictness, foreign
432 @cindex foreign strictness
433 @cindex Strictness, gnu
434 @cindex gnu strictness
435 @cindex Strictness, gnits
436 @cindex gnits strictness
438 To this end, Automake supports three levels of @dfn{strictness}---the
439 strictness indicating how stringently Automake should check standards
440 conformance.
442 The valid strictness levels are:
444 @table @samp
445 @item foreign
446 Automake will check for only those things which are absolutely
447 required for proper operations.  For instance, whereas GNU standards
448 dictate the existence of a @file{NEWS} file, it will not be required in
449 this mode.  The name comes from the fact that Automake is intended to be
450 used for GNU programs; these relaxed rules are not the standard mode of
451 operation.
453 @item gnu
454 Automake will check---as much as possible---for compliance to the GNU
455 standards for packages.  This is the default.
457 @item gnits
458 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
459 standards}.  These are based on the GNU standards, but are even more
460 detailed.  Unless you are a Gnits standards contributor, it is
461 recommended that you avoid this option until such time as the Gnits
462 standard is actually published (which may never happen).
463 @end table
465 For more information on the precise implications of the strictness
466 level, see @ref{Gnits}.
468 Automake also has a special ``cygnus'' mode which is similar to
469 strictness but handled differently.  This mode is useful for packages
470 which are put into a ``Cygnus'' style tree (e.g., the GCC tree).  For
471 more information on this mode, see @ref{Cygnus}.
474 @node Uniform
475 @section The Uniform Naming Scheme
477 @cindex Uniform naming scheme
479 Automake variables generally follow a @dfn{uniform naming scheme} that
480 makes it easy to decide how programs (and other derived objects) are
481 built, and how they are installed.  This scheme also supports
482 @code{configure} time determination of what should be built.
484 @cindex _PROGRAMS primary variable
485 @cindex PROGRAMS primary variable
486 @cindex Primary variable, PROGRAMS
487 @cindex Primary variable, defined
489 At @code{make} time, certain variables are used to determine which
490 objects are to be built.  The variable names are made of several pieces
491 which are concatenated together.
493 The piece which tells automake what is being built is commonly called
494 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
495 list of programs which are to be compiled and linked.
496 @vindex PROGRAMS
498 @cindex pkglibdir, defined
499 @cindex pkgincludedir, defined
500 @cindex pkgdatadir, defined
502 @vindex pkglibdir
503 @vindex pkgincludedir
504 @vindex pkgdatadir
506 A different set of names is used to decide where the built objects
507 should be installed.  These names are prefixes to the primary which
508 indicate which standard directory should be used as the installation
509 directory.  The standard directory names are given in the GNU standards
510 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
511 Automake extends this list with @code{pkglibdir}, @code{pkgincludedir},
512 and @code{pkgdatadir}; these are the same as the non-@samp{pkg}
513 versions, but with @samp{$(PACKAGE)} appended.  For instance,
514 @code{pkglibdir} is defined as @code{$(libdir)/$(PACKAGE)}.
515 @cvindex PACKAGE, directory
517 @cindex EXTRA_, prepending
519 For each primary, there is one additional variable named by prepending
520 @samp{EXTRA_} to the primary name.  This variable is used to list
521 objects which may or may not be built, depending on what
522 @code{configure} decides.  This variable is required because Automake
523 must statically know the entire list of objects that may be built in
524 order to generate a @file{Makefile.in} that will work in all cases.
526 @cindex EXTRA_PROGRAMS, defined
527 @cindex Example, EXTRA_PROGRAMS
528 @cindex cpio example
530 For instance, @code{cpio} decides at configure time which programs are
531 built.  Some of the programs are installed in @code{bindir}, and some
532 are installed in @code{sbindir}:
534 @example
535 EXTRA_PROGRAMS = mt rmt
536 bin_PROGRAMS = cpio pax
537 sbin_PROGRAMS = $(MORE_PROGRAMS)
538 @end example
540 Defining a primary without a prefix as a variable, e.g.,
541 @code{PROGRAMS}, is an error.
543 Note that the common @samp{dir} suffix is left off when constructing the
544 variable names; thus one writes @samp{bin_PROGRAMS} and not
545 @samp{bindir_PROGRAMS}.
547 Not every sort of object can be installed in every directory.  Automake
548 will flag those attempts it finds in error.
549 Automake will also diagnose obvious misspellings in directory names.
551 @cindex Extending list of installation directories
552 @cindex Installation directories, extending list
554 Sometimes the standard directories---even as augmented by Automake---
555 are not enough.  In particular it is sometimes useful, for clarity, to
556 install objects in a subdirectory of some predefined directory.  To this
557 end, Automake allows you to extend the list of possible installation
558 directories.  A given prefix (e.g. @samp{zar}) is valid if a variable of
559 the same name with @samp{dir} appended is defined (e.g. @code{zardir}).
561 @cindex HTML installation, example
563 For instance, installation of HTML files is part of Automake, you could
564 use this to install raw HTML documentation:
566 @example
567 htmldir = $(prefix)/html
568 html_DATA = automake.html
569 @end example
571 @cindex noinst primary prefix, definition
573 The special prefix @samp{noinst} indicates that the objects in question
574 should be built but not installed at all.  This is usually used for
575 objects required to build the rest of your package, for instance static
576 libraries (@pxref{A Library}), or helper scripts.
578 @cindex check primary prefix, definition
580 The special prefix @samp{check} indicates that the objects in question
581 should not be built until the @code{make check} command is run.  Those
582 objects are not installed either.
584 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
585 @samp{LISP}, @samp{PYTHON}, @samp{JAVA}, @samp{SCRIPTS}, @samp{DATA},
586 @samp{HEADERS}, @samp{MANS}, and @samp{TEXINFOS}.
587 @vindex PROGRAMS
588 @vindex LIBRARIES
589 @vindex LISP
590 @vindex PYTHON
591 @vindex JAVA
592 @vindex SCRIPTS
593 @vindex DATA
594 @vindex HEADERS
595 @vindex MANS
596 @vindex TEXINFOS
598 Some primaries also allow additional prefixes which control other
599 aspects of @code{automake}'s behavior.  The currently defined prefixes
600 are @samp{dist_}, @samp{nodist_}, and @samp{nobase_}.  These prefixes
601 are explained later (@pxref{Program and Library Variables}).
604 @node Canonicalization
605 @section How derived variables are named
607 @cindex canonicalizing Automake variables
609 Sometimes a Makefile variable name is derived from some text the
610 maintainer supplies.  For instance, a program name listed in
611 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
612 variable.  In cases like this, Automake canonicalizes the text, so that
613 program names and the like do not have to follow Makefile variable naming
614 rules.  All characters in the name except for letters, numbers, the
615 strudel (@@), and the underscore are turned into underscores when making
616 variable references.
618 For example, if your program is named @code{sniff-glue}, the derived
619 variable name would be @code{sniff_glue_SOURCES}, not
620 @code{sniff-glue_SOURCES}.  Similarly the sources for a library named
621 @code{libmumble++.a} should be listed in the
622 @code{libmumble___a_SOURCES} variable.
624 The strudel is an addition, to make the use of Autoconf substitutions in
625 variable names less obfuscating.
628 @node User Variables
629 @section Variables reserved for the user
631 @cindex variables, reserved for the user
632 @cindex user variables
634 Some @code{Makefile} variables are reserved by the GNU Coding Standards
635 for the use of the ``user'' -- the person building the package.  For
636 instance, @code{CFLAGS} is one such variable.
638 Sometimes package developers are tempted to set user variables such as
639 @code{CFLAGS} because it appears to make their job easier.  However,
640 the package itself should never set a user variable, particularly not
641 to include switches which are required for proper compilation of the
642 package.  Since these variables are documented as being for the
643 package builder, that person rightfully expects to be able to override
644 any of these variables at build time.
646 To get around this problem, automake introduces an automake-specific
647 shadow variable for each user flag variable.  (Shadow variables are not
648 introduced for variables like @code{CC}, where they would make no
649 sense.)  The shadow variable is named by prepending @samp{AM_} to the
650 user variable's name.  For instance, the shadow variable for
651 @code{YFLAGS} is @code{AM_YFLAGS}.
654 @node Auxiliary Programs
655 @section Programs automake might require
657 @cindex Programs, auxiliary
658 @cindex Auxiliary programs
660 Automake sometimes requires helper programs so that the generated
661 @file{Makefile} can do its work properly.  There are a fairly large
662 number of them, and we list them here.
664 @table @code
665 @item ansi2knr.c
666 @itemx ansi2knr.1
667 These two files are used by the automatic de-ANSI-fication support
668 (@pxref{ANSI}).
670 @item compile
671 This is a wrapper for compilers which don't accept both @samp{-c} and
672 @samp{-o} at the same time.  It is only used when absolutely required.
673 Such compilers are rare.
675 @item config.guess
676 @itemx config.sub
677 These programs compute the canonical triplets for the given build, host,
678 or target architecture.  These programs are updated regularly to support
679 new architectures and fix probes broken by changes in new kernel
680 versions.  You are encouraged to fetch the latest versions of these
681 files from @url{ftp://ftp.gnu.org/gnu/config/} before making a release.
683 @item depcomp
684 This program understands how to run a compiler so that it will generate
685 not only the desired output but also dependency information which is
686 then used by the automatic dependency tracking feature.
688 @item elisp-comp
689 This program is used to byte-compile Emacs Lisp code.
691 @item install-sh
692 This is a replacement for the @code{install} program which works on
693 platforms where @code{install} is unavailable or unusable.
695 @item mdate-sh
696 This script is used to generate a @file{version.texi} file.  It examines
697 a file and prints some date information about it.
699 @item missing
700 This wraps a number of programs which are typically only required by
701 maintainers.  If the program in question doesn't exist, @code{missing}
702 prints an informative warning and attempts to fix things so that the
703 build can continue.
705 @item mkinstalldirs
706 This script used to be a wrapper around @code{mkdir -p}, which is not
707 portable.  Now we use prefer to use @code{install-sh -d} when configure
708 finds that @code{mkdir -p} does not work, this makes one less script to
709 distribute.
711 For backward compatibility @code{mkinstalldirs} is still used and
712 distributed when @code{automake} finds it in a package.  But it is no
713 longer installed automatically, and it should be safe to remove it.
715 @item py-compile
716 This is used to byte-compile Python scripts.
718 @item texinfo.tex
719 Not a program, this file is required for @code{make dvi}, @code{make ps}
720 and @code{make pdf} to work when Texinfo sources are in the package.
722 @item ylwrap
723 This program wraps @code{lex} and @code{yacc} and ensures that, for
724 instance, multiple @code{yacc} instances can be invoked in a single
725 directory in parallel.
727 @end table
730 @node Examples
731 @chapter Some example packages
733 @menu
734 * Complete::                    A simple example, start to finish
735 * Hello::                       A classic program
736 * true::                        Building true and false
737 @end menu
740 @node Complete
741 @section A simple example, start to finish
743 @cindex Complete example
745 Let's suppose you just finished writing @code{zardoz}, a program to make
746 your head float from vortex to vortex.  You've been using Autoconf to
747 provide a portability framework, but your @file{Makefile.in}s have been
748 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
750 @cindex AM_INIT_AUTOMAKE, example use
752 The first step is to update your @file{configure.ac} to include the
753 commands that @code{automake} needs.  The way to do this is to add an
754 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
756 @example
757 AC_INIT(zardoz, 1.0)
758 AM_INIT_AUTOMAKE
759 @dots{}
760 @end example
762 Since your program doesn't have any complicating factors (e.g., it
763 doesn't use @code{gettext}, it doesn't want to build a shared library),
764 you're done with this part.  That was easy!
766 @cindex aclocal program, introduction
767 @cindex aclocal.m4, preexisting
768 @cindex acinclude.m4, defined
770 Now you must regenerate @file{configure}.  But to do that, you'll need
771 to tell @code{autoconf} how to find the new macro you've used.  The
772 easiest way to do this is to use the @code{aclocal} program to generate
773 your @file{aclocal.m4} for you.  But wait@dots{} maybe you already have an
774 @file{aclocal.m4}, because you had to write some hairy macros for your
775 program.  The @code{aclocal} program lets you put your own macros into
776 @file{acinclude.m4}, so simply rename and then run:
778 @example
779 mv aclocal.m4 acinclude.m4
780 aclocal
781 autoconf
782 @end example
784 @cindex zardoz example
786 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
787 Since @code{zardoz} is a user program, you want to install it where the
788 rest of the user programs go: @code{bindir}.  Additionally,
789 @code{zardoz} has some Texinfo documentation.  Your @file{configure.ac}
790 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
791 @samp{$(LIBOBJS)}.  So here's what you'd write:
793 @example
794 bin_PROGRAMS = zardoz
795 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
796 zardoz_LDADD = $(LIBOBJS)
798 info_TEXINFOS = zardoz.texi
799 @end example
801 Now you can run @code{automake --add-missing} to generate your
802 @file{Makefile.in} and grab any auxiliary files you might need, and
803 you're done!
806 @node Hello
807 @section A classic program
809 @cindex Example, GNU Hello
810 @cindex Hello example
811 @cindex GNU Hello, example
813 @uref{ftp://prep.ai.mit.edu/pub/gnu/hello-1.3.tar.gz, GNU hello} is
814 renowned for its classic simplicity and versatility.  This section shows
815 how Automake could be used with the GNU Hello package.  The examples
816 below are from the latest beta version of GNU Hello, but with all of the
817 maintainer-only code stripped out, as well as all copyright comments.
819 Of course, GNU Hello is somewhat more featureful than your traditional
820 two-liner.  GNU Hello is internationalized, does option processing, and
821 has a manual and a test suite.
823 @cindex configure.ac, from GNU Hello
824 @cindex GNU Hello, configure.ac
825 @cindex Hello, configure.ac
827 Here is the @file{configure.ac} from GNU Hello.
828 @strong{Please note:} The calls to @code{AC_INIT} and @code{AM_INIT_AUTOMAKE}
829 in this example use a deprecated syntax.  For the current approach,
830 see the description of @code{AM_INIT_AUTOMAKE} in @ref{Public macros}.
832 @c FIXME: This definitely requires an update, e.g. to GNU Hello 2.1.1.
834 @example
835 dnl Process this file with autoconf to produce a configure script.
836 AC_INIT(src/hello.c)
837 AM_INIT_AUTOMAKE(hello, 1.3.11)
838 AM_CONFIG_HEADER(config.h)
840 dnl Set of available languages.
841 ALL_LINGUAS="de fr es ko nl no pl pt sl sv"
843 dnl Checks for programs.
844 AC_PROG_CC
845 AC_ISC_POSIX
847 dnl Checks for libraries.
849 dnl Checks for header files.
850 AC_STDC_HEADERS
851 AC_HAVE_HEADERS(string.h fcntl.h sys/file.h sys/param.h)
853 dnl Checks for library functions.
854 AC_FUNC_ALLOCA
856 dnl Check for st_blksize in struct stat
857 AC_ST_BLKSIZE
859 dnl internationalization macros
860 AM_GNU_GETTEXT
861 AC_OUTPUT([Makefile doc/Makefile intl/Makefile po/Makefile.in \
862            src/Makefile tests/Makefile tests/hello],
863    [chmod +x tests/hello])
864 @end example
866 The @samp{AM_} macros are provided by Automake (or the Gettext library);
867 the rest are standard Autoconf macros.
870 The top-level @file{Makefile.am}:
872 @example
873 EXTRA_DIST = BUGS ChangeLog.O
874 SUBDIRS = doc intl po src tests
875 @end example
877 As you can see, all the work here is really done in subdirectories.
879 The @file{po} and @file{intl} directories are automatically generated
880 using @code{gettextize}; they will not be discussed here.
882 @cindex Texinfo file handling example
883 @cindex Example, handling Texinfo files
885 In @file{doc/Makefile.am} we see:
887 @example
888 info_TEXINFOS = hello.texi
889 hello_TEXINFOS = gpl.texi
890 @end example
892 This is sufficient to build, install, and distribute the GNU Hello
893 manual.
895 @cindex Regression test example
896 @cindex Example, regression test
898 Here is @file{tests/Makefile.am}:
900 @example
901 TESTS = hello
902 EXTRA_DIST = hello.in testdata
903 @end example
905 The script @file{hello} is generated by @code{configure}, and is the
906 only test case.  @code{make check} will run this test.
908 @cindex INCLUDES, example usage
910 Last we have @file{src/Makefile.am}, where all the real work is done:
911 @c FIXME: As all the Hello World excerpts in this manual, this
912 @c shows deprecated features (here: $(INCLUDES)).
914 @example
915 bin_PROGRAMS = hello
916 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
917 hello_LDADD = $(INTLLIBS) $(ALLOCA)
918 localedir = $(datadir)/locale
919 INCLUDES = -I../intl -DLOCALEDIR=\"$(localedir)\"
920 @end example
923 @node true
924 @section Building true and false
926 @cindex Example, false and true
927 @cindex false Example
928 @cindex true Example
930 Here is another, trickier example.  It shows how to generate two
931 programs (@code{true} and @code{false}) from the same source file
932 (@file{true.c}).  The difficult part is that each compilation of
933 @file{true.c} requires different @code{cpp} flags.
935 @example
936 bin_PROGRAMS = true false
937 false_SOURCES =
938 false_LDADD = false.o
940 true.o: true.c
941         $(COMPILE) -DEXIT_CODE=0 -c true.c
943 false.o: true.c
944         $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
945 @end example
947 Note that there is no @code{true_SOURCES} definition.  Automake will
948 implicitly assume that there is a source file named @file{true.c}, and
949 define rules to compile @file{true.o} and link @file{true}.  The
950 @code{true.o: true.c} rule supplied by the above @file{Makefile.am},
951 will override the Automake generated rule to build @file{true.o}.
953 @code{false_SOURCES} is defined to be empty---that way no implicit value
954 is substituted.  Because we have not listed the source of
955 @file{false}, we have to tell Automake how to link the program.  This is
956 the purpose of the @code{false_LDADD} line.  A @code{false_DEPENDENCIES}
957 variable, holding the dependencies of the @file{false} target will be
958 automatically generated by Automake from the content of
959 @code{false_LDADD}.
961 The above rules won't work if your compiler doesn't accept both
962 @samp{-c} and @samp{-o}.  The simplest fix for this is to introduce a
963 bogus dependency (to avoid problems with a parallel @code{make}):
965 @example
966 true.o: true.c false.o
967         $(COMPILE) -DEXIT_CODE=0 -c true.c
969 false.o: true.c
970         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
971 @end example
973 Also, these explicit rules do not work if the de-ANSI-fication feature
974 is used (@pxref{ANSI}).  Supporting de-ANSI-fication requires a little
975 more work:
977 @example
978 true._o: true._c false.o
979         $(COMPILE) -DEXIT_CODE=0 -c true.c
981 false._o: true._c
982         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true._o false.o
983 @end example
985 As it turns out, there is also a much easier way to do this same task.
986 Some of the above techniques are useful enough that we've kept the
987 example in the manual.  However if you were to build @code{true} and
988 @code{false} in real life, you would probably use per-program
989 compilation flags, like so:
991 @example
992 bin_PROGRAMS = false true
994 false_SOURCES = true.c
995 false_CPPFLAGS = -DEXIT_CODE=1
997 true_SOURCES = true.c
998 true_CPPFLAGS = -DEXIT_CODE=0
999 @end example
1001 In this case Automake will cause @file{true.c} to be compiled twice,
1002 with different flags.  De-ANSI-fication will work automatically.  In
1003 this instance, the names of the object files would be chosen by
1004 automake; they would be @file{false-true.o} and @file{true-true.o}.
1005 (The name of the object files rarely matters.)
1008 @node Invoking Automake
1009 @chapter Creating a @file{Makefile.in}
1011 @cindex Multiple configure.ac files
1012 @cindex Invoking Automake
1013 @cindex Automake, invoking
1015 To create all the @file{Makefile.in}s for a package, run the
1016 @code{automake} program in the top level directory, with no arguments.
1017 @code{automake} will automatically find each appropriate
1018 @file{Makefile.am} (by scanning @file{configure.ac}; @pxref{configure})
1019 and generate the corresponding @file{Makefile.in}.  Note that
1020 @code{automake} has a rather simplistic view of what constitutes a
1021 package; it assumes that a package has only one @file{configure.ac}, at
1022 the top.  If your package has multiple @file{configure.ac}s, then you
1023 must run @code{automake} in each directory holding a
1024 @file{configure.ac}.  (Alternatively, you may rely on Autoconf's
1025 @code{autoreconf}, which is able to recurse your package tree and run
1026 @code{automake} where appropriate.)
1028 You can optionally give @code{automake} an argument; @file{.am} is
1029 appended to the argument and the result is used as the name of the input
1030 file.  This feature is generally only used to automatically rebuild an
1031 out-of-date @file{Makefile.in}.  Note that @code{automake} must always
1032 be run from the topmost directory of a project, even if being used to
1033 regenerate the @file{Makefile.in} in some subdirectory.  This is
1034 necessary because @code{automake} must scan @file{configure.ac}, and
1035 because @code{automake} uses the knowledge that a @file{Makefile.in} is
1036 in a subdirectory to change its behavior in some cases.
1038 @vindex AUTOCONF
1039 Automake will run @code{autoconf} to scan @file{configure.ac} and its
1040 dependencies (@file{aclocal.m4}), therefore @code{autoconf} must be in
1041 your @code{PATH}.  If there is an @code{AUTOCONF} variable in your
1042 environment it will be used instead of @code{autoconf}, this allows you
1043 to select a particular version of Autoconf.  By the way, don't
1044 misunderstand this paragraph: Automake runs @code{autoconf} to
1045 @strong{scan} your @file{configure.ac}, this won't build
1046 @file{configure} and you still have to run @code{autoconf} yourself for
1047 this purpose.
1049 @cindex Automake options
1050 @cindex Options, Automake
1051 @cindex Strictness, command line
1053 @code{automake} accepts the following options:
1055 @cindex Extra files distributed with Automake
1056 @cindex Files distributed with Automake
1057 @cindex config.guess
1059 @table @samp
1060 @item -a
1061 @itemx --add-missing
1062 @opindex -a
1063 @opindex --add-missing
1064 Automake requires certain common files to exist in certain situations;
1065 for instance @file{config.guess} is required if @file{configure.ac} runs
1066 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
1067 files (@pxref{Auxiliary Programs}); this option will cause the missing
1068 ones to be automatically added to the package, whenever possible.  In
1069 general if Automake tells you a file is missing, try using this option.
1070 By default Automake tries to make a symbolic link pointing to its own
1071 copy of the missing file; this can be changed with @code{--copy}.
1073 Many of the potentially-missing files are common scripts whose
1074 location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
1075 Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
1076 file is considered missing, and where the missing file is added
1077 (@pxref{Optional}).
1079 @item --libdir=@var{dir}
1080 @opindex --libdir
1081 Look for Automake data files in directory @var{dir} instead of in the
1082 installation directory.  This is typically used for debugging.
1084 @item -c
1085 @opindex -c
1086 @itemx --copy
1087 @opindex --copy
1088 When used with @code{--add-missing}, causes installed files to be
1089 copied.  The default is to make a symbolic link.
1091 @item --cygnus
1092 @opindex --cygnus
1093 Causes the generated @file{Makefile.in}s to follow Cygnus rules, instead
1094 of GNU or Gnits rules.  For more information, see @ref{Cygnus}.
1096 @item -f
1097 @opindex -f
1098 @itemx --force-missing
1099 @opindex --force-missing
1100 When used with @code{--add-missing}, causes standard files to be reinstalled
1101 even if they already exist in the source tree.  This involves removing
1102 the file from the source tree before creating the new symlink (or, with
1103 @code{--copy}, copying the new file).
1105 @item --foreign
1106 @opindex --foreign
1107 Set the global strictness to @samp{foreign}.  For more information, see
1108 @ref{Strictness}.
1110 @item --gnits
1111 @opindex --gnits
1112 Set the global strictness to @samp{gnits}.  For more information, see
1113 @ref{Gnits}.
1115 @item --gnu
1116 @opindex --gnu
1117 Set the global strictness to @samp{gnu}.  For more information, see
1118 @ref{Gnits}.  This is the default strictness.
1120 @item --help
1121 @opindex --help
1122 Print a summary of the command line options and exit.
1124 @item -i
1125 @itemx --ignore-deps
1126 @opindex -i
1127 This disables the dependency tracking feature in generated
1128 @file{Makefile}s; see @ref{Dependencies}.
1130 @item --include-deps
1131 @opindex --include-deps
1132 This enables the dependency tracking feature.  This feature is enabled
1133 by default.  This option is provided for historical reasons only and
1134 probably should not be used.
1136 @item --no-force
1137 @opindex --no-force
1138 Ordinarily @code{automake} creates all @file{Makefile.in}s mentioned in
1139 @file{configure.ac}.  This option causes it to only update those
1140 @file{Makefile.in}s which are out of date with respect to one of their
1141 dependents.
1143 @item -o @var{dir}
1144 @itemx --output-dir=@var{dir}
1145 @opindex -o
1146 @opindex --output-dir
1147 Put the generated @file{Makefile.in} in the directory @var{dir}.
1148 Ordinarily each @file{Makefile.in} is created in the directory of the
1149 corresponding @file{Makefile.am}.  This option is deprecated and will be
1150 removed in a future release.
1152 @item -v
1153 @itemx --verbose
1154 @opindex -v
1155 @opindex --verbose
1156 Cause Automake to print information about which files are being read or
1157 created.
1159 @item --version
1160 @opindex --version
1161 Print the version number of Automake and exit.
1163 @item -W CATEGORY
1164 @item --warnings=@var{category}
1165 @opindex -W
1166 @opindex --warnings
1167 Output warnings falling in @var{category}.  @var{category} can be
1168 one of:
1169 @table @samp
1170 @item gnu
1171 warnings related to the GNU Coding Standards
1172 (@pxref{Top, , , standards, The GNU Coding Standards}).
1173 @item obsolete
1174 obsolete features or constructions
1175 @item override
1176 user redefinitions of Automake rules or variables
1177 @item portability
1178 portability issues (e.g., use of Make features which are known not portable)
1179 @item syntax
1180 weird syntax, unused variables, typos
1181 @item unsupported
1182 unsupported or incomplete features
1183 @item all
1184 all the warnings
1185 @item none
1186 turn off all the warnings
1187 @item error
1188 treat warnings as errors
1189 @end table
1191 A category can be turned off by prefixing its name with @samp{no-}.  For
1192 instance @samp{-Wno-syntax} will hide the warnings about unused
1193 variables.
1195 The categories output by default are @samp{syntax} and
1196 @samp{unsupported}.  Additionally, @samp{gnu} is enabled in @samp{--gnu} and
1197 @samp{--gnits} strictness.
1199 @samp{portability} warnings are currently disabled by default, but they
1200 will be enabled in @samp{--gnu} and @samp{--gnits} strictness in a
1201 future release.
1203 @vindex WARNINGS
1204 The environment variable @samp{WARNINGS} can contain a comma separated
1205 list of categories to enable.  It will be taken into account before the
1206 command-line switches, this way @samp{-Wnone} will also ignore any
1207 warning category enabled by @samp{WARNINGS}.  This variable is also used
1208 by other tools like @command{autoconf}; unknown categories are ignored
1209 for this reason.
1211 @end table
1214 @node configure
1215 @chapter Scanning @file{configure.ac}
1217 @cindex configure.ac, scanning
1218 @cindex Scanning configure.ac
1220 Automake scans the package's @file{configure.ac} to determine certain
1221 information about the package.  Some @code{autoconf} macros are required
1222 and some variables must be defined in @file{configure.ac}.  Automake
1223 will also use information from @file{configure.ac} to further tailor its
1224 output.
1226 Automake also supplies some Autoconf macros to make the maintenance
1227 easier.  These macros can automatically be put into your
1228 @file{aclocal.m4} using the @code{aclocal} program.
1230 @menu
1231 * Requirements::                Configuration requirements
1232 * Optional::                    Other things Automake recognizes
1233 * Invoking aclocal::            Auto-generating aclocal.m4
1234 * aclocal options::             aclocal command line arguments
1235 * Macro search path::           Modifying aclocal's search path
1236 * Macros::                      Autoconf macros supplied with Automake
1237 * Extending aclocal::           Writing your own aclocal macros
1238 * Local Macros::                Organizing local macros
1239 * Future of aclocal::           aclocal's scheduled death
1240 @end menu
1243 @node Requirements
1244 @section Configuration requirements
1246 @cindex Automake requirements
1247 @cindex Requirements of Automake
1249 The one real requirement of Automake is that your @file{configure.ac}
1250 call @code{AM_INIT_AUTOMAKE}.  This macro does several things which are
1251 required for proper Automake operation (@pxref{Macros}).
1252 @cvindex AM_INIT_AUTOMAKE
1254 Here are the other macros which Automake requires but which are not run
1255 by @code{AM_INIT_AUTOMAKE}:
1257 @table @code
1258 @item AC_CONFIG_FILES
1259 @itemx AC_OUTPUT
1260 Automake uses these to determine which files to create (@pxref{Output, ,
1261 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
1262 is considered to be an Automake generated @file{Makefile} if there
1263 exists a file with the same name and the @file{.am} extension appended.
1264 Typically, @code{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
1265 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
1267 When using @code{AC_CONFIG_FILES} with multiple input files, as in
1268 @code{AC_CONFIG_FILES([Makefile:top.in:Makefile.in:bot.in])}, Automake
1269 will generate the first @file{.in} input file for which a @file{.am}
1270 file exists.  If no such file exists the output file is not considered
1271 to be Automake generated.
1273 Files created by @code{AC_CONFIG_FILES} are removed by @code{make distclean}.
1274 @cvindex AC_CONFIG_FILES
1275 @cvindex AC_OUTPUT
1276 @end table
1279 @node Optional
1280 @section Other things Automake recognizes
1282 @cindex Macros Automake recognizes
1283 @cindex Recognized macros by Automake
1285 Every time Automake is run it calls Autoconf to trace
1286 @file{configure.ac}.  This way it can recognize the use of certain
1287 macros and tailor the generated @file{Makefile.in} appropriately.
1288 Currently recognized macros and their effects are:
1290 @table @code
1291 @item AC_CONFIG_HEADERS
1292 Automake will generate rules to rebuild these headers.  Older versions
1293 of Automake required the use of @code{AM_CONFIG_HEADER}
1294 (@pxref{Macros}); this is no longer the case today.
1295 @cvindex AC_CONFIG_HEADERS
1297 @item AC_CONFIG_LINKS
1298 Automake will generate rules to remove @file{configure} generated links on
1299 @code{make distclean} and to distribute named source files as part of
1300 @code{make dist}.
1301 @cvindex AC_CONFIG_LINKS
1303 @item AC_CONFIG_AUX_DIR
1304 Automake will look for various helper scripts, such as
1305 @file{install-sh}, in the directory named in this macro invocation.
1306 @c This list is accurate relative to version 1.8
1307 (The full list of scripts is: @file{config.guess}, @file{config.sub},
1308 @file{depcomp}, @file{elisp-comp}, @file{compile}, @file{install-sh},
1309 @file{ltmain.sh}, @file{mdate-sh}, @file{missing}, @file{mkinstalldirs},
1310 @file{py-compile}, @file{texinfo.tex}, and @file{ylwrap}.)  Not all
1311 scripts are always searched for; some scripts will only be sought if the
1312 generated @file{Makefile.in} requires them.
1313 @cvindex AC_CONFIG_AUX_DIR
1315 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
1316 their @samp{standard} locations.  For @file{mdate-sh},
1317 @file{texinfo.tex}, and @file{ylwrap}, the standard location is the
1318 source directory corresponding to the current @file{Makefile.am}.  For
1319 the rest, the standard location is the first one of @file{.}, @file{..},
1320 or @file{../..} (relative to the top source directory) that provides any
1321 one of the helper scripts.  @xref{Input, , Finding `configure' Input,
1322 autoconf, The Autoconf Manual}.
1324 Required files from @code{AC_CONFIG_AUX_DIR} are automatically
1325 distributed, even if there is no @file{Makefile.am} in this directory.
1327 @item AC_CANONICAL_HOST
1328 Automake will ensure that @file{config.guess} and @file{config.sub}
1329 exist.  Also, the @file{Makefile} variables @samp{host_alias} and
1330 @samp{host_triplet} are introduced.  See @ref{Canonicalizing, ,
1331 Getting the Canonical System Type, autoconf, The Autoconf Manual}.
1332 @cvindex AC_CANONICAL_HOST
1333 @vindex host_alias
1334 @vindex host_triplet
1336 @item AC_CANONICAL_SYSTEM
1337 This is similar to @code{AC_CANONICAL_HOST}, but also defines the
1338 @file{Makefile} variables @samp{build_alias} and @samp{target_alias}.
1339 @xref{Canonicalizing, , Getting the Canonical System Type, autoconf, The
1340 Autoconf Manual}.
1341 @cvindex AC_CANONICAL_SYSTEM
1342 @vindex build_alias
1343 @vindex target_alias
1345 @item AC_LIBSOURCE
1346 @itemx AC_LIBSOURCES
1347 @itemx AC_LIBOBJ
1348 Automake will automatically distribute any file listed in
1349 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
1351 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}.  So if
1352 an Autoconf macro is documented to call @code{AC_LIBOBJ([file])}, then
1353 @file{file.c} will be distributed automatically by Automake.  This
1354 encompasses many macros like @code{AC_FUNC_ALLOCA},
1355 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
1356 @cvindex AC_LIBOBJ
1357 @cvindex AC_LIBSOURCE
1358 @cvindex AC_LIBSOURCES
1360 By the way, direct assignments to @code{LIBOBJS} are no longer
1361 supported.  You should always use @code{AC_LIBOBJ} for this purpose.
1362 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs. @code{LIBOBJS},
1363 autoconf, The Autoconf Manual}.
1364 @cvindex LIBOBJS
1366 @item AC_PROG_RANLIB
1367 This is required if any libraries are built in the package.
1368 @xref{Particular Programs, , Particular Program Checks, autoconf, The
1369 Autoconf Manual}.
1370 @cvindex AC_PROG_RANLIB
1372 @item AC_PROG_CXX
1373 This is required if any C++ source is included.  @xref{Particular
1374 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
1375 @cvindex AC_PROG_CXX
1377 @item AC_PROG_F77
1378 This is required if any Fortran 77 source is included.  This macro is
1379 distributed with Autoconf version 2.13 and later.  @xref{Particular
1380 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
1381 @cvindex AC_PROG_F77
1383 @item AC_F77_LIBRARY_LDFLAGS
1384 This is required for programs and shared libraries that are a mixture of
1385 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
1386 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
1387 @cvindex AC_F77_LIBRARY_LDFLAGS
1389 @item AC_PROG_LIBTOOL
1390 Automake will turn on processing for @code{libtool} (@pxref{Top, ,
1391 Introduction, libtool, The Libtool Manual}).
1392 @cvindex AC_PROG_LIBTOOL
1394 @item AC_PROG_YACC
1395 If a Yacc source file is seen, then you must either use this macro or
1396 define the variable @samp{YACC} in @file{configure.ac}.  The former is
1397 preferred (@pxref{Particular Programs, , Particular Program Checks,
1398 autoconf, The Autoconf Manual}).
1399 @cvindex AC_PROG_YACC
1400 @cvindex YACC
1402 @item AC_PROG_LEX
1403 If a Lex source file is seen, then this macro must be used.
1404 @xref{Particular Programs, , Particular Program Checks, autoconf, The
1405 Autoconf Manual}.
1406 @cvindex AC_PROG_LEX
1408 @item AC_SUBST
1409 @cvindex AC_SUBST
1410 The first argument is automatically defined as a variable in each
1411 generated @file{Makefile.in}.  @xref{Setting Output Variables, , Setting
1412 Output Variables, autoconf, The Autoconf Manual}.
1414 If the Autoconf manual says that a macro calls @code{AC_SUBST} for
1415 @var{var}, or defines the output variable @var{var} then @var{var} will
1416 be defined in each @file{Makefile.in} generated by Automake.
1417 E.g. @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and @code{X_LIBS}, so
1418 you can use these variables in any @file{Makefile.am} if
1419 @code{AC_PATH_XTRA} is called.
1421 @item AM_C_PROTOTYPES
1422 This is required when using automatic de-ANSI-fication; see @ref{ANSI}.
1423 @cvindex AM_C_PROTOTYPES
1425 @item AM_GNU_GETTEXT
1426 This macro is required for packages which use GNU gettext
1427 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
1428 this macro it ensures that the package meets some of gettext's
1429 requirements.
1430 @cvindex AM_GNU_GETTEXT
1432 @item AM_MAINTAINER_MODE
1433 @opindex --enable-maintainer-mode
1434 This macro adds a @samp{--enable-maintainer-mode} option to
1435 @code{configure}.  If this is used, @code{automake} will cause
1436 @samp{maintainer-only} rules to be turned off by default in the
1437 generated @file{Makefile.in}s. This macro defines the
1438 @samp{MAINTAINER_MODE} conditional, which you can use in your own
1439 @file{Makefile.am}.
1440 @cvindex AM_MAINTAINER_MODE
1442 @item m4_include
1443 @cvindex m4_include
1444 Files included by @file{configure.ac} using this macro will be
1445 detected by Automake and automatically distributed.  They will also
1446 appear as dependencies in @file{Makefile} rules.
1448 @code{m4_include} is seldom used by @file{configure.ac} authors, but
1449 can appear in @file{aclocal.m4} when @command{aclocal} detects that
1450 some required macros come from files local to your package (as
1451 opposed to macros installed in a system-wide directory, see
1452 @ref{Invoking aclocal}).
1454 @end table
1457 @node Invoking aclocal
1458 @section Auto-generating aclocal.m4
1460 @cindex Invoking aclocal
1461 @cindex aclocal, Invoking
1463 Automake includes a number of Autoconf macros which can be used in
1464 your package (@pxref{Macros}); some of them are actually required by
1465 Automake in certain situations.  These macros must be defined in your
1466 @file{aclocal.m4}; otherwise they will not be seen by
1467 @command{autoconf}.
1469 The @command{aclocal} program will automatically generate
1470 @file{aclocal.m4} files based on the contents of @file{configure.ac}.
1471 This provides a convenient way to get Automake-provided macros,
1472 without having to search around.  The @command{aclocal} mechanism
1473 allows other packages to supply their own macros (@pxref{Extending
1474 aclocal}).  You can also use it to maintain your own set of custom
1475 macros (@pxref{Local Macros}).
1477 At startup, @command{aclocal} scans all the @file{.m4} files it can
1478 find, looking for macro definitions (@pxref{Macro search path}).  Then
1479 it scans @file{configure.ac}.  Any mention of one of the macros found
1480 in the first step causes that macro, and any macros it in turn
1481 requires, to be put into @file{aclocal.m4}.
1483 @emph{Putting} the file that contains the macro definition into
1484 @file{aclocal.m4} is usually done by copying the entire text of this
1485 file, including unused macro definitions as well as both @samp{#} and
1486 @samp{dnl} comments.  If you want to make a comment which will be
1487 completely ignored by @command{aclocal}, use @samp{##} as the comment
1488 leader.
1490 When @command{aclocal} detects that the file containing the macro
1491 definition is in a subdirectory of your package, it will use
1492 @code{m4_include} instead of copying it; this makes the package
1493 smaller and eases dependency tracking.  This only works if the
1494 subdirectory containing the macro was specified as a relative search
1495 path with @command{aclocal}'s @code{-I} argument.  (@pxref{Local
1496 Macros} for an example.)  Any macro which is found in a system-wide
1497 directory, or via an absolute search path will be copied.
1499 The contents of @file{acinclude.m4}, if it exists, are also
1500 automatically included in @file{aclocal.m4}.  We recommend against
1501 using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
1503 @vindex AUTOM4TE
1504 While computing @file{aclocal.m4}, @code{aclocal} runs @code{autom4te}
1505 (@pxref{Using autom4te, , Using @code{Autom4te}, autoconf, The
1506 Autoconf Manual}) in order to trace the macros which are really used,
1507 and omit from @file{aclocal.m4} all macros which are mentioned but
1508 otherwise unexpanded (this can happen when a macro is called
1509 conditionally).  @code{autom4te} is expected to be in the @code{PATH},
1510 just as @code{autoconf}.  Its location can be overridden using the
1511 @code{AUTOM4TE} environment variable.
1513 @menu
1514 * aclocal options::             Options supported by aclocal
1515 * Macro search path::           How aclocal finds .m4 files
1516 @end menu
1518 @node aclocal options
1519 @section aclocal options
1521 @cindex aclocal, Options
1522 @cindex Options, aclocal
1524 @code{aclocal} accepts the following options:
1526 @table @code
1527 @item --acdir=@var{dir}
1528 @opindex --acdir
1529 Look for the macro files in @var{dir} instead of the installation
1530 directory.  This is typically used for debugging.
1532 @item --help
1533 @opindex --help
1534 Print a summary of the command line options and exit.
1536 @item -I @var{dir}
1537 @opindex -I
1538 Add the directory @var{dir} to the list of directories searched for
1539 @file{.m4} files.
1541 @item --force
1542 @opindex --force
1543 Always overwrite the output file.  The default is to overwrite the output
1544 file only when really needed, i.e., when its contents changes or if one
1545 of its dependencies is younger.
1547 @item --output=@var{file}
1548 @opindex --output
1549 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
1551 @item --print-ac-dir
1552 @opindex --print-ac-dir
1553 Prints the name of the directory which @code{aclocal} will search to
1554 find third-party @file{.m4} files.  When this option is given, normal
1555 processing is suppressed.  This option can be used by a package to
1556 determine where to install a macro file.
1558 @item --verbose
1559 @opindex --verbose
1560 Print the names of the files it examines.
1562 @item --version
1563 @opindex --version
1564 Print the version number of Automake and exit.
1565 @end table
1567 @node Macro search path
1568 @section Macro search path
1570 @cindex Macro search path
1571 @cindex aclocal search path
1573 By default, @command{aclocal} searches for @file{.m4} files in the following
1574 directories, in this order:
1576 @table @code
1577 @item @var{acdir-APIVERSION}
1578 This is where the @file{.m4} macros distributed with automake itself
1579 are stored.  @var{APIVERSION} depends on the automake release used;
1580 for automake 1.6.x, @var{APIVERSION} = @code{1.6}.
1582 @item @var{acdir}
1583 This directory is intended for third party @file{.m4} files, and is
1584 configured when @command{automake} itself is built.  This is
1585 @file{@@datadir@@/aclocal/}, which typically
1586 expands to @file{$@{prefix@}/share/aclocal/}.  To find the compiled-in
1587 value of @var{acdir}, use the @code{--print-ac-dir} option
1588 (@pxref{aclocal options}).
1589 @end table
1591 As an example, suppose that automake-1.6.2 was configured with
1592 @code{--prefix=/usr/local}.  Then, the search path would be:
1594 @enumerate
1595 @item @file{/usr/local/share/aclocal-1.6/}
1596 @item @file{/usr/local/share/aclocal/}
1597 @end enumerate
1599 As explained in (@pxref{aclocal options}), there are several options that
1600 can be used to change or extend this search path.
1602 @subsection Modifying the macro search path: @code{--acdir}
1604 The most obvious option to modify the search path is
1605 @code{--acdir=@var{dir}}, which changes default directory and
1606 drops the @var{APIVERSION} directory.  For example, if one specifies
1607 @code{--acdir=/opt/private/}, then the search path becomes:
1609 @enumerate
1610 @item @file{/opt/private/}
1611 @end enumerate
1613 Note that this option, @code{--acdir}, is intended for use
1614 by the internal automake test suite only; it is not ordinarily
1615 needed by end-users.
1617 @subsection Modifying the macro search path: @code{-I @var{dir}}
1619 Any extra directories specified using @code{-I} options
1620 (@pxref{aclocal options}) are @emph{prepended} to this search list.  Thus,
1621 @code{aclocal -I /foo -I /bar} results in the following search path:
1623 @enumerate
1624 @item @file{/foo}
1625 @item @file{/bar}
1626 @item @var{acdir}-@var{APIVERSION}
1627 @item @var{acdir}
1628 @end enumerate
1630 @subsection Modifying the macro search path: @file{dirlist}
1631 @cindex @file{dirlist}
1633 There is a third mechanism for customizing the search path.  If a
1634 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
1635 contain a list of directories, one per line, to be added to the search
1636 list.  These directories are searched @emph{after} all other
1637 directories.
1639 For example, suppose
1640 @file{@var{acdir}/dirlist} contains the following:
1642 @example
1643 /test1
1644 /test2
1645 @end example
1647 @noindent
1648 and that @code{aclocal} was called with the @code{-I /foo -I /bar} options.
1649 Then, the search path would be
1651 @enumerate
1652 @item @file{/foo}
1653 @item @file{/bar}
1654 @item @var{acdir}-@var{APIVERSION}
1655 @item @var{acdir}
1656 @item @file{/test1}
1657 @item @file{/test2}
1658 @end enumerate
1660 If the @code{--acdir=@var{dir}} option is used, then @command{aclocal}
1661 will search for the @file{dirlist} file in @var{dir}.  In the
1662 @code{--acdir=/opt/private/} example above, @command{aclocal} would look
1663 for @file{/opt/private/dirlist}.  Again, however, the @code{--acdir}
1664 option is intended for use by the internal automake test suite only;
1665 @code{--acdir} is not ordinarily needed by end-users.
1667 @file{dirlist} is useful in the following situation: suppose that
1668 @code{automake} version @code{1.6.2} is installed with
1669 $prefix=/usr by the system vendor. Thus, the default search
1670 directories are
1672 @enumerate
1673 @item @file{/usr/share/aclocal-1.6/}
1674 @item @file{/usr/share/aclocal/}
1675 @end enumerate
1677 However, suppose further that many packages have been manually
1678 installed on the system, with $prefix=/usr/local, as is typical.
1679 In that case, many of these ``extra'' @file{.m4} files are in
1680 @file{/usr/local/share/aclocal}.  The only way to force
1681 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files
1682 is to always call @code{aclocal -I /usr/local/share/aclocal}.
1683 This is inconvenient.  With @file{dirlist}, one may create the file
1685 @file{/usr/share/aclocal/dirlist}
1687 @noindent
1688 which contains only the single line
1690 @file{/usr/local/share/aclocal}
1692 Now, the ``default'' search path on the affected system is
1694 @enumerate
1695 @item @file{/usr/share/aclocal-1.6/}
1696 @item @file{/usr/share/aclocal/}
1697 @item @file{/usr/local/share/aclocal/}
1698 @end enumerate
1700 without the need for @code{-I} options; @code{-I} options can be reserved
1701 for project-specific needs (@file{my-source-dir/m4/}), rather than
1702 using it to work around local system-dependent tool installation
1703 directories.
1705 Similarly, @file{dirlist} can be handy if you have installed a local
1706 copy Automake on your account and want @command{aclocal} to look for
1707 macros installed at other places on the system.
1710 @node Macros
1711 @section Autoconf macros supplied with Automake
1713 Automake ships with several Autoconf macros that you can use from your
1714 @file{configure.ac}.  When you use one of them it will be included by
1715 @code{aclocal} in @file{aclocal.m4}.
1717 @menu
1718 * Public macros::               Macros that you can use.
1719 * Private macros::              Macros that you should not use.
1720 @end menu
1722 @c consider generating the following subsections automatically from m4 files.
1724 @node Public macros
1725 @subsection Public macros
1727 @table @code
1728 @item AM_CONFIG_HEADER
1729 Automake will generate rules to automatically regenerate the config
1730 header.  This obsolete macro is a synonym of @code{AC_CONFIG_HEADERS}
1731 today (@pxref{Optional}).
1732 @cvindex AM_CONFIG_HEADER
1734 @item AM_ENABLE_MULTILIB
1735 This is used when a ``multilib'' library is being built.  The first
1736 optional argument is the name of the @file{Makefile} being generated; it
1737 defaults to @samp{Makefile}.  The second option argument is used to find
1738 the top source directory; it defaults to the empty string (generally
1739 this should not be used unless you are familiar with the internals).
1740 @xref{Multilibs}.
1742 @item AM_C_PROTOTYPES
1743 Check to see if function prototypes are understood by the compiler.  If
1744 so, define @samp{PROTOTYPES} and set the output variables @samp{U} and
1745 @samp{ANSI2KNR} to the empty string.  Otherwise, set @samp{U} to
1746 @samp{_} and @samp{ANSI2KNR} to @samp{./ansi2knr}.  Automake uses these
1747 values to implement automatic de-ANSI-fication.
1748 @cvindex AM_C_PROTOTYPES
1750 @item AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
1751 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
1752 define @code{GWINSZ_IN_SYS_IOCTL}.  Otherwise @code{TIOCGWINSZ} can be
1753 found in @file{<termios.h>}.
1754 @cvindex AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
1756 @item AM_INIT_AUTOMAKE([OPTIONS])
1757 @itemx AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
1758 Runs many macros required for proper operation of the generated Makefiles.
1760 This macro has two forms, the first of which is preferred.
1761 In this form, @code{AM_INIT_AUTOMAKE} is called with a
1762 single argument --- a space-separated list of Automake options which should
1763 be applied to every @file{Makefile.am} in the tree.  The effect is as if
1764 each option were listed in @code{AUTOMAKE_OPTIONS}.
1766 The second, deprecated, form of @code{AM_INIT_AUTOMAKE} has two required
1767 arguments: the package and the version number.  This form is
1768 obsolete because the @var{package} and @var{version} can be obtained
1769 from Autoconf's @code{AC_INIT} macro (which itself has an old and a new
1770 form).
1772 If your @file{configure.ac} has:
1773 @example
1774 AC_INIT(src/foo.c)
1775 AM_INIT_AUTOMAKE(mumble, 1.5)
1776 @end example
1777 you can modernize it as follows:
1778 @example
1779 AC_INIT(mumble, 1.5)
1780 AC_CONFIG_SRCDIR(src/foo.c)
1781 AM_INIT_AUTOMAKE
1782 @end example
1784 Note that if you're upgrading your @file{configure.ac} from an earlier
1785 version of Automake, it is not always correct to simply move the package
1786 and version arguments from @code{AM_INIT_AUTOMAKE} directly to
1787 @code{AC_INIT}, as in the example above.  The first argument to
1788 @code{AC_INIT} should be the name of your package (e.g. @samp{GNU Automake}),
1789 not the tarball name (e.g. @samp{automake}) that you used to pass to
1790 @code{AM_INIT_AUTOMAKE}.  Autoconf tries to derive a tarball name from
1791 the package name, which should work for most but not all package names.
1792 (If it doesn't work for yours, you can use the
1793 four-argument form of @code{AC_INIT} --- supported in Autoconf versions
1794 greater than 2.52g --- to provide the tarball name explicitly).
1796 By default this macro @code{AC_DEFINE}'s @samp{PACKAGE} and
1797 @samp{VERSION}.  This can be avoided by passing the @samp{no-define}
1798 option, as in:
1799 @example
1800 AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
1801 @end example
1802 or by passing a third non-empty argument to the obsolete form.
1804 @cvindex PACKAGE, prevent definition
1805 @cvindex VERSION, prevent definition
1808 @item AM_PATH_LISPDIR
1809 Searches for the program @code{emacs}, and, if found, sets the output
1810 variable @code{lispdir} to the full path to Emacs' site-lisp directory.
1812 Note that this test assumes the @code{emacs} found to be a version that
1813 supports Emacs Lisp (such as @sc{gnu} Emacs or XEmacs).  Other emacsen
1814 can cause this test to hang (some, like old versions of MicroEmacs,
1815 start up in interactive mode, requiring @samp{C-x C-c} to exit, which
1816 is hardly obvious for a non-emacs user).  In most cases, however, you
1817 should be able to use @samp{C-c} to kill the test.  In order to avoid
1818 problems, you can set @code{EMACS} to ``no'' in the environment, or
1819 use the @samp{--with-lispdir} option to @command{configure} to
1820 explicitly set the correct path (if you're sure you have an @code{emacs}
1821 that supports Emacs Lisp.
1822 @cvindex AM_PATH_LISPDIR
1824 @item AM_PROG_AS
1825 Use this macro when you have assembly code in your project.  This will
1826 choose the assembler for you (by default the C compiler) and set
1827 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
1829 @item AM_PROG_CC_C_O
1830 This is like @code{AC_PROG_CC_C_O}, but it generates its results in the
1831 manner required by automake.  You must use this instead of
1832 @code{AC_PROG_CC_C_O} when you need this functionality.
1834 @item AM_PROG_LEX
1835 @cindex HP-UX 10, lex problems
1836 @cindex lex problems with HP-UX 10
1837 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
1838 Program Checks, autoconf, The Autoconf Manual}), but uses the
1839 @code{missing} script on systems that do not have @code{lex}.
1840 @samp{HP-UX 10} is one such system.
1842 @item AM_PROG_GCJ
1843 This macro finds the @code{gcj} program or causes an error.  It sets
1844 @samp{GCJ} and @samp{GCJFLAGS}.  @code{gcj} is the Java front-end to the
1845 GNU Compiler Collection.
1846 @cvindex AM_PROG_GCJ
1848 @item AM_SYS_POSIX_TERMIOS
1849 @cvindex am_cv_sys_posix_termios
1850 @cindex POSIX termios headers
1851 @cindex termios POSIX headers
1852 Check to see if POSIX termios headers and functions are available on the
1853 system.  If so, set the shell variable @code{am_cv_sys_posix_termios} to
1854 @samp{yes}.  If not, set the variable to @samp{no}.
1856 @item AM_WITH_DMALLOC
1857 @cvindex WITH_DMALLOC
1858 @cindex dmalloc, support for
1859 @opindex --with-dmalloc
1860 Add support for the
1861 @uref{ftp://ftp.letters.com/src/dmalloc/dmalloc.tar.gz, dmalloc}
1862 package.  If the user configures with @samp{--with-dmalloc}, then define
1863 @code{WITH_DMALLOC} and add @samp{-ldmalloc} to @code{LIBS}.
1865 @item AM_WITH_REGEX
1866 @cvindex WITH_REGEX
1867 @opindex --with-regex
1868 @cindex regex package
1869 @cindex rx package
1870 Adds @samp{--with-regex} to the @code{configure} command line.  If
1871 specified (the default), then the @samp{regex} regular expression
1872 library is used, @file{regex.o} is put into @samp{LIBOBJS}, and
1873 @samp{WITH_REGEX} is defined.  If @samp{--without-regex} is given, then
1874 the @samp{rx} regular expression library is used, and @file{rx.o} is put
1875 into @samp{LIBOBJS}.
1877 @end table
1879 @node Private macros
1880 @subsection Private macros
1882 The following macros are private macros you should not call directly.
1883 They are called by the other public macros when appropriate.  Do not
1884 rely on them, as they might be changed in a future version.  Consider
1885 them as implementation details; or better, do not consider them at all:
1886 skip this section!
1888 @table @code
1889 @item _AM_DEPENDENCIES
1890 @itemx AM_SET_DEPDIR
1891 @itemx AM_DEP_TRACK
1892 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
1893 These macros are used to implement Automake's automatic dependency
1894 tracking scheme.  They are called automatically by automake when
1895 required, and there should be no need to invoke them manually.
1897 @item AM_MAKE_INCLUDE
1898 This macro is used to discover how the user's @code{make} handles
1899 @code{include} statements.  This macro is automatically invoked when
1900 needed; there should be no need to invoke it manually.
1902 @item AM_PROG_INSTALL_STRIP
1903 This is used to find a version of @code{install} which can be used to
1904 @code{strip} a program at installation time.  This macro is
1905 automatically included when required.
1907 @item AM_SANITY_CHECK
1908 This checks to make sure that a file created in the build directory is
1909 newer than a file in the source directory.  This can fail on systems
1910 where the clock is set incorrectly.  This macro is automatically run
1911 from @code{AM_INIT_AUTOMAKE}.
1913 @end table
1916 @node Extending aclocal
1917 @section Writing your own aclocal macros
1919 @cindex aclocal, extending
1920 @cindex Extending aclocal
1922 The @command{aclocal} program doesn't have any built-in knowledge of any
1923 macros, so it is easy to extend it with your own macros.
1925 This can be used by libraries which want to supply their own Autoconf
1926 macros for use by other programs.  For instance the @command{gettext}
1927 library supplies a macro @code{AM_GNU_GETTEXT} which should be used by
1928 any package using @command{gettext}.  When the library is installed, it
1929 installs this macro so that @command{aclocal} will find it.
1931 A macro file's name should end in @file{.m4}.  Such files should be
1932 installed in @file{$(datadir)/aclocal}.  This is as simple as writing:
1934 @example
1935 aclocaldir = $(datadir)/aclocal
1936 aclocal_DATA = mymacro.m4 myothermacro.m4
1937 @end example
1939 A file of macros should be a series of properly quoted
1940 @code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
1941 Autoconf Manual}).  The @command{aclocal} programs also understands
1942 @code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
1943 Autoconf Manual}), so it is safe to put each macro in a separate file.
1944 Each file should have no side effects but macro definitions.
1945 Especially, any call to @code{AC_PREREQ} should be done inside the
1946 defined macro, not at the beginning of the file.
1948 @cindex underquoted AC_DEFUN
1949 @cvindex AC_DEFUN
1950 @cvindex AC_PREREQ
1952 Starting with Automake 1.8, @command{aclocal} will warn about all
1953 underquoted calls to @code{AC_DEFUN}.  We realize this will annoy a
1954 lot of people, because @command{aclocal} was not so strict in the past
1955 and many third party macros are underquoted; and we have to apologize
1956 for this temporary inconvenience.  The reason we have to be stricter
1957 is that a future implementation of @command{aclocal} (@pxref{Future of
1958 aclocal}) will have to temporary include all these third party
1959 @file{.m4} files, maybe several times, even those which are not
1960 actually needed.  Doing so should alleviate many problem of the
1961 current implementation, however it requires a stricter style from the
1962 macro authors.  Hopefully it is easy to revise the existing macros.
1963 For instance
1964 @example
1965 # bad style
1966 AC_PREREQ(2.57)
1967 AC_DEFUN(AX_FOOBAR,
1968 [AC_REQUIRE([AX_SOMETHING])dnl
1969 AX_FOO
1970 AX_BAR
1972 @end example
1973 @noindent
1974 should be rewritten as
1975 @example
1976 AC_DEFUN([AX_FOOBAR],
1977 [AC_PREREQ(2.57)dnl
1978 AC_REQUIRE([AX_SOMETHING])dnl
1979 AX_FOO
1980 AX_BAR
1982 @end example
1984 Wrapping the @code{AC_PREREQ} call inside the macro ensures that
1985 Autoconf 2.57 will not be required if @code{AX_FOOBAR} is not actually
1986 used.  Most importantly, quoting the first argument of @code{AC_DEFUN}
1987 allows the macro to be redefined or included twice (otherwise this
1988 first argument would be expansed during the second definition).
1990 If you have been directed here by the @command{aclocal} diagnostic but
1991 are not the maintainer of the implicated macro, you will want to
1992 contact the maintainer of that macro.  Please make sure you have the
1993 last version of the macro and that the problem already hasn't been
1994 reported before doing so: people tend to work faster when they aren't
1995 flooded by mails.
1997 Another situation where @command{aclocal} is commonly used is to
1998 manage macros which are used locally by the package, @ref{Local
1999 Macros}.
2001 @node Local Macros
2002 @section Handling Local Macros
2004 Feature tests offered by Autoconf do not cover all needs.  People
2005 often have to supplement existing tests with their own macros, or
2006 with third-party macros.
2008 There are two ways to organize custom macros in a package.
2010 The first possibility (the historical practice) is to list all your
2011 macros in @file{acinclude.m4}.  This file will be included in
2012 @file{aclocal.m4} when you run @command{aclocal}, and its macro(s) will
2013 henceforth be visible to @command{autoconf}.  However if it contains
2014 numerous macros, it will rapidly become difficult to maintain, and it
2015 will be almost impossible to share macros between packages.
2017 @vindex ACLOCAL_AMFLAGS
2018 The second possibility, which we do recommend, is to write each macro
2019 in its own file and gather all these files in a directory.  This
2020 directory is usually called @file{m4/}.  To build @file{aclocal.m4},
2021 one should therefore instruct @command{aclocal} to scan @file{m4/}.
2022 From the command line, this is done with @code{aclocal -I m4}.  The
2023 top-level @file{Makefile.am} should also be updated to define
2025 @example
2026  ACLOCAL_AMFLAGS = -I m4
2027 @end example
2029 @code{ACLOCAL_AMFLAGS} contains options to pass to @command{aclocal}
2030 when @file{aclocal.m4} is to be rebuilt by @code{make}.  This line is
2031 also used by @command{autoreconf} (@pxref{autoreconf Invocation, ,
2032 Using @command{autoreconf} to Update @file{configure} Scripts,
2033 autoconf, The Autoconf Manual}) to run @command{aclocal} with suitable
2034 options, or by @command{autopoint} (@pxref{autopoint Invocation, ,
2035 Invoking the @command{autopoint} Program, gettext, GNU gettext tools})
2036 and @command{gettextize} (@pxref{gettextize Invocation, , Invoking the
2037 @command{gettextize} Program, gettext, GNU gettext tools}) to locate
2038 the place where Gettext's macros should be installed.  So even if you
2039 do not really care about the rebuild rules, you should define
2040 @code{ACLOCAL_AMFLAGS}.
2042 When @code{aclocal -I m4} is run, it will build a @code{aclocal.m4}
2043 that @code{m4_include}s any file from @file{m4/} that defines a
2044 required macro.  Macros not found locally will still be searched in
2045 system-wide directories, as explained in @ref{Macro search path}.
2047 Custom macros should be distributed for the same reason that
2048 @file{configure.ac} is: so that other people have all the sources of
2049 your package if they want to work on it.  Actually, this distribution
2050 happens automatically because all @code{m4_include}d files are
2051 distributed.
2053 However there is no consensus on the distribution of third-party
2054 macros that your package may use.  Many libraries install their own
2055 macro in the system-wide @command{aclocal} directory (@pxref{Extending
2056 aclocal}).  For instance Guile ships with a file called
2057 @file{guile.m4} that contains the macro @code{GUILE_FLAGS} which can
2058 be used to define setup compiler and linker flags appropriate for
2059 using Guile.  Using @code{GUILE_FLAGS} in @file{configure.ac} will
2060 cause @command{aclocal} to copy @file{guile.m4} into
2061 @file{aclocal.m4}, but as @file{guile.m4} is not part of the project,
2062 it will not be distributed.  Technically, that means a user which
2063 needs to rebuild @file{aclocal.m4} will have to install Guile first.
2064 This is probably OK, if Guile already is a requirement to build the
2065 package.  However, if Guile is only an optional feature, or if your
2066 package might run on architectures where Guile cannot be installed,
2067 this requirement will hinder development.  An easy solution is to copy
2068 such third-party macros in your local @file{m4/} directory so they get
2069 distributed.
2071 @node Future of aclocal
2072 @section The Future of @command{aclocal}
2073 @cindex aclocal's scheduled death
2075 @command{aclocal} is expected to disappear.  This feature really
2076 should not be offered by Automake.  Automake should focus on generating
2077 @file{Makefile}s; dealing with M4 macros really is Autoconf's job.
2078 That some people install Automake just to use @command{aclocal}, but
2079 do not use @command{automake} otherwise is an indication of how that
2080 feature is misplaced.
2082 The new implementation will probably be done slightly differently.
2083 For instance it could enforce the @file{m4/}-style layout discussed in
2084 @ref{Local Macros}, and take care of copying (or even updating)
2085 third-party macro into this directory.
2087 We have no idea when and how this will happen.  This has been
2088 discussed several times in the past, but someone still has to commit
2089 itself to that non-trivial task.
2091 From the user point of view, @command{aclocal}'s removal might turn
2092 out to be painful.  There is a simple precaution that you may take to
2093 make that switch more seamless: never call @command{aclocal} yourself.
2094 Keep this guy under the exclusive control of @command{autoreconf} and
2095 Automake's rebuild rules.  Hopefully you won't need to worry about
2096 things breaking, when @command{aclocal} disappears, because everything
2097 will have been taken care of.  If otherwise you used to call
2098 @command{aclocal} directly yourself or from some script, you will
2099 quickly notice the change.
2101 Many packages come with a script called @file{bootstrap.sh} or
2102 @file{autogen.sh}, that will just call @command{aclocal},
2103 @command{libtoolize}, @command{gettextize} or @command{autopoint},
2104 @command{autoconf}, @command{autoheader}, and @command{automake} in
2105 the right order.  Actually this is precisely what @command{autoreconf}
2106 can do for you.  If your package has such a @file{bootstrap.sh} or
2107 @file{autogen.sh} script, consider using @command{autoreconf}.  That
2108 should simplify its logic a lot (less things to maintain, yum!), it's
2109 even likely you will not need the script anymore, and more to the point
2110 you will not call @command{aclocal} directly anymore.
2113 @node Top level
2114 @chapter The top-level @file{Makefile.am}
2116 @section Recursing subdirectories
2118 @cindex SUBDIRS, explained
2120 In packages with subdirectories, the top level @file{Makefile.am} must
2121 tell Automake which subdirectories are to be built.  This is done via
2122 the @code{SUBDIRS} variable.
2123 @vindex SUBDIRS
2125 The @code{SUBDIRS} variable holds a list of subdirectories in which
2126 building of various sorts can occur.  The rules for many targets
2127 (e.g. @code{all}) in the generated @file{Makefile} will run commands
2128 both locally and in all specified subdirectories.  Note that the
2129 directories listed in @code{SUBDIRS} are not required to contain
2130 @file{Makefile.am}s; only @file{Makefile}s (after configuration).
2131 This allows inclusion of libraries from packages which do not use
2132 Automake (such as @code{gettext}).
2134 In packages that use subdirectories, the top-level @file{Makefile.am} is
2135 often very short.  For instance, here is the @file{Makefile.am} from the
2136 GNU Hello distribution:
2138 @example
2139 EXTRA_DIST = BUGS ChangeLog.O README-alpha
2140 SUBDIRS = doc intl po src tests
2141 @end example
2143 When Automake invokes @code{make} in a subdirectory, it uses the value
2144 of the @code{MAKE} variable.  It passes the value of the variable
2145 @code{AM_MAKEFLAGS} to the @code{make} invocation; this can be set in
2146 @file{Makefile.am} if there are flags you must always pass to
2147 @code{make}.
2148 @vindex MAKE
2149 @vindex MAKEFLAGS
2151 The directories mentioned in @code{SUBDIRS} must be direct children of
2152 the current directory.  For instance, you cannot put @samp{src/subdir}
2153 into @code{SUBDIRS}.  Instead you should put @code{SUBDIRS = subdir}
2154 into @file{src/Makefile.am}.  Automake can be used to construct packages
2155 of arbitrary depth this way.
2157 By default, Automake generates @file{Makefiles} which work depth-first
2158 (@samp{postfix}).  However, it is possible to change this ordering.
2159 You can do this by putting @samp{.} into @code{SUBDIRS}.  For
2160 instance, putting @samp{.}  first will cause a @samp{prefix} ordering
2161 of directories.  All @samp{clean} rules are run in reverse
2162 order of build rules.
2164 @section Conditional subdirectories
2165 @cindex Subdirectories, building conditionally
2166 @cindex Conditional subdirectories
2167 @cindex @code{SUBDIRS}, conditional
2168 @cindex Conditional @code{SUBDIRS}
2170 It is possible to define the @code{SUBDIRS} variable conditionally if,
2171 like in the case of GNU @code{Inetutils}, you want to only build a
2172 subset of the entire package.
2174 To illustrate how this works, let's assume we have two directories
2175 @file{src/} and @file{opt/}.  @file{src/} should always be built, but we
2176 want to decide in @code{./configure} whether @file{opt/} will be built
2177 or not.  (For this example we will assume that @file{opt/} should be
2178 built when the variable @code{$want_opt} was set to @code{yes}.)
2180 Running @code{make} should thus recurse into @file{src/} always, and
2181 then maybe in @file{opt/}.
2183 However @code{make dist} should always recurse into both @file{src/} and
2184 @file{opt/}.  Because @file{opt/} should be distributed even if it is
2185 not needed in the current configuration. This means @file{opt/Makefile}
2186 should be created unconditionally.  @footnote{Don't try seeking a
2187 solution where @file{opt/Makefile} is created conditionally, this is a
2188 lot trickier than the solutions presented here.}
2190 There are two ways to setup a project like this.  You can use Automake
2191 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
2192 variables (@pxref{Setting Output Variables, , Setting Output Variables,
2193 autoconf, The Autoconf Manual}).  Using Automake conditionals is the
2194 preferred solution.
2196 @subsection Conditional subdirectories with @code{AM_CONDITIONAL}
2197 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
2198 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
2200 @c The test case for the setup described here is
2201 @c     test/subdircond2.test
2202 @c Try to keep it in sync.
2204 @file{configure} should output the @file{Makefile} for each directory
2205 and define a condition into which @file{opt/} should be built.
2207 @example
2208 @dots{}
2209 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
2210 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
2211 @dots{}
2212 @end example
2214 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
2215 as follows.
2217 @example
2218 if COND_OPT
2219   MAYBE_OPT = opt
2220 endif
2221 SUBDIRS = src $(MAYBE_OPT)
2222 @end example
2224 As you can see, running @code{make} will rightly recurse into
2225 @file{src/} and maybe @file{opt/}.
2227 @vindex DIST_SUBDIRS
2228 As you can't see, running @code{make dist} will recurse into both
2229 @file{src/} and @file{opt/} directories because @code{make dist}, unlike
2230 @code{make all}, doesn't use the @code{SUBDIRS} variable.  It uses the
2231 @code{DIST_SUBDIRS} variable.
2233 In this case Automake will define @code{DIST_SUBDIRS = src opt}
2234 automatically because it knows that @code{MAYBE_OPT} can contain
2235 @code{opt} in some condition.
2237 @subsection Conditional subdirectories with @code{AC_SUBST}
2238 @cindex @code{SUBDIRS} and @code{AC_SUBST}
2239 @cindex @code{AC_SUBST} and @code{SUBDIRS}
2241 @c The test case for the setup described here is
2242 @c     test/subdircond3.test
2243 @c Try to keep it in sync.
2245 Another idea is to define @code{MAYBE_OPT} from @file{./configure} using
2246 @code{AC_SUBST}:
2248 @example
2249 @dots{}
2250 if test "$want_opt" = yes; then
2251   MAYBE_OPT=opt
2252 else
2253   MAYBE_OPT=
2255 AC_SUBST([MAYBE_OPT])
2256 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
2257 @dots{}
2258 @end example
2260 In this case the top-level @file{Makefile.am} should look as follows.
2262 @example
2263 SUBDIRS = src $(MAYBE_OPT)
2264 DIST_SUBDIRS = src opt
2265 @end example
2267 The drawback is that since Automake cannot guess what the possible
2268 values of @code{MAYBE_OPT} are, it is necessary to define
2269 @code{DIST_SUBDIRS}.
2271 @subsection How @code{DIST_SUBDIRS} is used
2272 @cindex @code{DIST_SUBDIRS}, explained
2274 As shown in the above examples, @code{DIST_SUBDIRS} is used in rules
2275 that need to recurse in all directories, even those which have been
2276 conditionally left out of the build.
2278 Precisely, @code{DIST_SUBDIRS} is used by @code{make dist}, @code{make
2279 distclean}, and @code{make maintainer-clean}.  All other recursive
2280 rules use @code{SUBDIRS}.
2282 Automake will define @code{DIST_SUBDIRS} automatically from the
2283 possibles values of @code{SUBDIRS} in all conditions.
2285 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
2286 @code{DIST_SUBDIRS} will not be defined correctly because Automake
2287 doesn't know the possible values of these variables.  In this case
2288 @code{DIST_SUBDIRS} needs to be defined manually.
2291 @node Alternative
2292 @chapter An Alternative Approach to Subdirectories
2294 If you've ever read Peter Miller's excellent paper,
2295 @uref{http://www.pcug.org.au/~millerp/rmch/recu-make-cons-harm.html,
2296 Recursive Make Considered Harmful}, the preceding section on the use of
2297 subdirectories will probably come as unwelcome advice.  For those who
2298 haven't read the paper, Miller's main thesis is that recursive
2299 @code{make} invocations are both slow and error-prone.
2301 Automake provides sufficient cross-directory support @footnote{We
2302 believe.  This work is new and there are probably warts.
2303 @xref{Introduction}, for information on reporting bugs.} to enable you
2304 to write a single @file{Makefile.am} for a complex multi-directory
2305 package.
2308 By default an installable file specified in a subdirectory will have its
2309 directory name stripped before installation.  For instance, in this
2310 example, the header file will be installed as
2311 @file{$(includedir)/stdio.h}:
2313 @example
2314 include_HEADERS = inc/stdio.h
2315 @end example
2317 @cindex nobase_
2318 @cindex Path stripping, avoiding
2319 @cindex Avoiding path stripping
2321 However, the @samp{nobase_} prefix can be used to circumvent this path
2322 stripping.  In this example, the header file will be installed as
2323 @file{$(includedir)/sys/types.h}:
2325 @example
2326 nobase_include_HEADERS = sys/types.h
2327 @end example
2329 @cindex nobase_ and dist_ or nodist_
2330 @cindex dist_ and nobase_
2331 @cindex nodist_ and nobase_
2333 @samp{nobase_} should be specified first when used in conjunction with
2334 either @samp{dist_} or @samp{nodist_} (@pxref{Dist}).  For instance:
2336 @example
2337 nobase_dist_pkgdata_DATA = images/vortex.pgm
2338 @end example
2340 @node Programs
2341 @chapter Building Programs and Libraries
2343 A large part of Automake's functionality is dedicated to making it easy
2344 to build programs and libraries.
2346 @menu
2347 * A Program::                   Building a program
2348 * A Library::                   Building a library
2349 * A Shared Library::            Building a Libtool library
2350 * Program and Library Variables::  Variables controlling program and
2351                                 library builds
2352 * Default _SOURCES::            Default source files
2353 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
2354 * Program variables::           Variables used when building a program
2355 * Yacc and Lex::                Yacc and Lex support
2356 * C++ Support::                 Compiling C++ sources
2357 * Assembly Support::            Compiling assembly sources
2358 * Fortran 77 Support::          Compiling Fortran 77 sources
2359 * Java Support::                Compiling Java sources
2360 * Support for Other Languages::  Compiling other languages
2361 * ANSI::                        Automatic de-ANSI-fication
2362 * Dependencies::                Automatic dependency tracking
2363 * EXEEXT::                      Support for executable extensions
2364 @end menu
2367 @node A Program
2368 @section Building a program
2370 In order to build a program, you need to tell Automake which sources
2371 are part of it, and which libraries it should be linked with.
2373 This section also covers conditional compilation of sources or
2374 programs.  Most of the comments about these also apply to libraries
2375 (@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
2377 @menu
2378 * Program Sources::             Defining program sources
2379 * Linking::                     Linking with libraries or extra objects
2380 * Conditional Sources::         Handling conditional sources
2381 * Conditional Programs::        Building program conditionally
2382 @end menu
2384 @node Program Sources
2385 @subsection Defining program sources
2387 @cindex PROGRAMS, bindir
2388 @vindex bin_PROGRAMS
2389 @vindex sbin_PROGRAMS
2390 @vindex libexec_PROGRAMS
2391 @vindex pkglib_PROGRAMS
2392 @vindex noinst_PROGRAMS
2393 @vindex check_PROGRAMS
2395 In a directory containing source that gets built into a program (as
2396 opposed to a library or a script), the @samp{PROGRAMS} primary is used.
2397 Programs can be installed in @code{bindir}, @code{sbindir},
2398 @code{libexecdir}, @code{pkglibdir}, or not at all (@samp{noinst}).
2399 They can also be built only for @code{make check}, in which case the
2400 prefix is @samp{check}.
2402 For instance:
2404 @example
2405 bin_PROGRAMS = hello
2406 @end example
2408 In this simple case, the resulting @file{Makefile.in} will contain code
2409 to generate a program named @code{hello}.
2411 Associated with each program are several assisting variables which are
2412 named after the program.  These variables are all optional, and have
2413 reasonable defaults.  Each variable, its use, and default is spelled out
2414 below; we use the ``hello'' example throughout.
2416 The variable @code{hello_SOURCES} is used to specify which source files
2417 get built into an executable:
2419 @example
2420 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
2421 @end example
2423 This causes each mentioned @samp{.c} file to be compiled into the
2424 corresponding @samp{.o}.  Then all are linked to produce @file{hello}.
2426 @cindex _SOURCES primary, defined
2427 @cindex SOURCES primary, defined
2428 @cindex Primary variable, SOURCES
2430 If @samp{hello_SOURCES} is not specified, then it defaults to the single
2431 file @file{hello.c} (@pxref{Default _SOURCES}).
2432 @vindex _SOURCES
2433 @vindex SOURCES
2435 Multiple programs can be built in a single directory.  Multiple programs
2436 can share a single source file, which must be listed in each
2437 @samp{_SOURCES} definition.
2439 @cindex Header files in _SOURCES
2440 @cindex _SOURCES and header files
2442 Header files listed in a @samp{_SOURCES} definition will be included in
2443 the distribution but otherwise ignored.  In case it isn't obvious, you
2444 should not include the header file generated by @file{configure} in a
2445 @samp{_SOURCES} variable; this file should not be distributed.  Lex
2446 (@samp{.l}) and Yacc (@samp{.y}) files can also be listed; see @ref{Yacc
2447 and Lex}.
2450 @node Linking
2451 @subsection Linking the program
2453 If you need to link against libraries that are not found by
2454 @code{configure}, you can use @code{LDADD} to do so.  This variable is
2455 used to specify additional objects or libraries to link with; it is
2456 inappropriate for specifying specific linker flags, you should use
2457 @code{AM_LDFLAGS} for this purpose.
2458 @vindex LDADD
2459 @vindex AM_LDFLAGS
2461 @cindex prog_LDADD, defined
2463 Sometimes, multiple programs are built in one directory but do not share
2464 the same link-time requirements.  In this case, you can use the
2465 @samp{@var{prog}_LDADD} variable (where @var{prog} is the name of the
2466 program as it appears in some @samp{_PROGRAMS} variable, and usually
2467 written in lowercase) to override the global @code{LDADD}.  If this
2468 variable exists for a given program, then that program is not linked
2469 using @code{LDADD}.
2470 @vindex _LDADD
2472 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
2473 linked against the library @file{libcpio.a}.  However, @code{rmt} is
2474 built in the same directory, and has no such link requirement.  Also,
2475 @code{mt} and @code{rmt} are only built on certain architectures.  Here
2476 is what cpio's @file{src/Makefile.am} looks like (abridged):
2478 @example
2479 bin_PROGRAMS = cpio pax $(MT)
2480 libexec_PROGRAMS = $(RMT)
2481 EXTRA_PROGRAMS = mt rmt
2483 LDADD = ../lib/libcpio.a $(INTLLIBS)
2484 rmt_LDADD =
2486 cpio_SOURCES = @dots{}
2487 pax_SOURCES = @dots{}
2488 mt_SOURCES = @dots{}
2489 rmt_SOURCES = @dots{}
2490 @end example
2492 @cindex _LDFLAGS, defined
2494 @samp{@var{prog}_LDADD} is inappropriate for passing program-specific
2495 linker flags (except for @samp{-l}, @samp{-L}, @samp{-dlopen} and
2496 @samp{-dlpreopen}).  So, use the @samp{@var{prog}_LDFLAGS} variable for
2497 this purpose.
2498 @vindex _LDFLAGS
2500 @cindex _DEPENDENCIES, defined
2502 It is also occasionally useful to have a program depend on some other
2503 target which is not actually part of that program.  This can be done
2504 using the @samp{@var{prog}_DEPENDENCIES} variable.  Each program depends
2505 on the contents of such a variable, but no further interpretation is
2506 done.
2508 If @samp{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
2509 Automake.  The automatically-assigned value is the contents of
2510 @samp{@var{prog}_LDADD}, with most configure substitutions, @samp{-l},
2511 @samp{-L}, @samp{-dlopen} and @samp{-dlpreopen} options removed.  The
2512 configure substitutions that are left in are only @samp{$(LIBOBJS)} and
2513 @samp{$(ALLOCA)}; these are left because it is known that they will not
2514 cause an invalid value for @samp{@var{prog}_DEPENDENCIES} to be
2515 generated.
2518 @node Conditional Sources
2519 @subsection Conditional compilation of sources
2521 You can't put a configure substitution (e.g., @samp{@@FOO@@} or
2522 @samp{$(FOO)} where @code{FOO} is defined via @code{AC_SUBST}) into a
2523 @samp{_SOURCES} variable.  The reason for this is a bit hard to
2524 explain, but suffice to say that it simply won't work.  Automake will
2525 give an error if you try to do this.
2527 Fortunately there are two other ways to achieve the same result.  One is
2528 to use configure substitutions in @code{_LDADD} variables, the other is
2529 to use an Automake conditional.
2531 @subsubsection Conditional compilation using @code{_LDADD} substitutions
2533 @cindex EXTRA_prog_SOURCES, defined
2535 Automake must know all the source files that could possibly go into a
2536 program, even if not all the files are built in every circumstance.  Any
2537 files which are only conditionally built should be listed in the
2538 appropriate @samp{EXTRA_} variable.  For instance, if
2539 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
2540 in @code{hello}, the @file{Makefile.am} would contain:
2542 @example
2543 bin_PROGRAMS = hello
2544 hello_SOURCES = hello-common.c
2545 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
2546 hello_LDADD = $(HELLO_SYSTEM)
2547 hello_DEPENDENCIES = $(HELLO_SYSTEM)
2548 @end example
2550 @noindent
2551 You can then setup the @code{$(HELLO_SYSTEM)} substitution from
2552 @file{configure.ac}:
2554 @example
2555 @dots{}
2556 case $host in
2557   *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
2558   *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
2559 esac
2560 AC_SUBST([HELLO_SYSTEM])
2561 @dots{}
2562 @end example
2564 In this case, @code{HELLO_SYSTEM} should be replaced by
2565 @file{hello-linux.o} or @file{hello-generic.o}, and added to
2566 @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be built
2567 and linked in.
2569 @subsubsection Conditional compilation using Automake conditionals
2571 An often simpler way to compile source files conditionally is to use
2572 Automake conditionals.  For instance, you could use this
2573 @file{Makefile.am} construct to build the same @file{hello} example:
2575 @example
2576 bin_PROGRAMS = hello
2577 if LINUX
2578 hello_SOURCES = hello-linux.c hello-common.c
2579 else
2580 hello_SOURCES = hello-generic.c hello-common.c
2581 endif
2582 @end example
2584 In this case, your @file{configure.ac} should setup the @code{LINUX}
2585 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
2587 When using conditionals like this you don't need to use the
2588 @samp{EXTRA_} variable, because Automake will examine the contents of
2589 each variable to construct the complete list of source files.
2591 If your program uses a lot of files, you will probably prefer a
2592 conditional @code{+=}.
2594 @example
2595 bin_PROGRAMS = hello
2596 hello_SOURCES = hello-common.c
2597 if LINUX
2598 hello_SOURCES += hello-linux.c
2599 else
2600 hello_SOURCES += hello-generic.c
2601 endif
2602 @end example
2604 @node Conditional Programs
2605 @subsection Conditional compilation of programs
2606 @cindex Conditional programs
2607 @cindex Programs, conditional
2609 Sometimes it is useful to determine the programs that are to be built
2610 at configure time.  For instance, GNU @code{cpio} only builds
2611 @code{mt} and @code{rmt} under special circumstances.  The means to
2612 achieve conditional compilation of programs are the same you can use
2613 to compile source files conditionally: substitutions or conditionals.
2615 @subsubsection Conditional programs using @code{configure} substitutions
2617 In this case, you must notify Automake of all the programs that can
2618 possibly be built, but at the same time cause the generated
2619 @file{Makefile.in} to use the programs specified by @code{configure}.
2620 This is done by having @code{configure} substitute values into each
2621 @samp{_PROGRAMS} definition, while listing all optionally built programs
2622 in @code{EXTRA_PROGRAMS}.
2623 @vindex EXTRA_PROGRAMS
2624 @cindex EXTRA_PROGRAMS, defined
2626 @example
2627 bin_PROGRAMS = cpio pax $(MT)
2628 libexec_PROGRAMS = $(RMT)
2629 EXTRA_PROGRAMS = mt rmt
2630 @end example
2632 As explained in @ref{EXEEXT}, Automake will rewrite
2633 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
2634 @code{EXTRA_PROGRAMS}, appending @code{$(EXEEXT)} to each binary.
2635 Obviously it cannot rewrite values obtained at run-time through
2636 @code{configure} substitutions, therefore you should take care of
2637 appending @code{$(EXEEXT)} yourself, as in @code{AC_SUBST([MT],
2638 ['mt$@{EXEEXT@}'])}.
2640 @subsubsection Conditional programs using Automake conditionals
2642 You can also use Automake conditionals (@pxref{Conditionals}) to
2643 select programs to be built.  In this case you don't have to worry
2644 about @code{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
2646 @example
2647 bin_PROGRAMS = cpio pax
2648 if WANT_MT
2649   bin_PROGRAMS += mt
2650 endif
2651 if WANT_RMT
2652   libexec_PROGRAMS = rmt
2653 endif
2654 @end example
2657 @node A Library
2658 @section Building a library
2660 @cindex _LIBRARIES primary, defined
2661 @cindex LIBRARIES primary, defined
2662 @cindex Primary variable, LIBRARIES
2664 @vindex lib_LIBRARIES
2665 @vindex pkglib_LIBRARIES
2666 @vindex noinst_LIBRARIES
2668 Building a library is much like building a program.  In this case, the
2669 name of the primary is @samp{LIBRARIES}.  Libraries can be installed in
2670 @code{libdir} or @code{pkglibdir}.
2672 @xref{A Shared Library}, for information on how to build shared
2673 libraries using libtool and the @samp{LTLIBRARIES} primary.
2675 Each @samp{_LIBRARIES} variable is a list of the libraries to be built.
2676 For instance to create a library named @file{libcpio.a}, but not install
2677 it, you would write:
2679 @example
2680 noinst_LIBRARIES = libcpio.a
2681 @end example
2683 The sources that go into a library are determined exactly as they are
2684 for programs, via the @samp{_SOURCES} variables.  Note that the library
2685 name is canonicalized (@pxref{Canonicalization}), so the @samp{_SOURCES}
2686 variable corresponding to @file{liblob.a} is @samp{liblob_a_SOURCES},
2687 not @samp{liblob.a_SOURCES}.
2689 @cindex _LIBADD primary, defined
2690 @cindex LIBADD primary, defined
2691 @cindex Primary variable, LIBADD
2693 Extra objects can be added to a library using the
2694 @samp{@var{library}_LIBADD} variable.  This should be used for objects
2695 determined by @code{configure}.  Again from @code{cpio}:
2696 @vindex _LIBADD
2697 @vindex LIBADD
2699 @example
2700 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
2701 @end example
2703 In addition, sources for extra objects that will not exist until
2704 configure-time must be added to the @code{BUILT_SOURCES} variable
2705 (@pxref{Sources}).
2707 Building a static library is done by compiling all object files, then
2708 by invoking @code{$(AR) $(ARFLAGS)} followed by the name of the
2709 library and the list of objects, and finally by calling
2710 @code{$(RANLIB)} on that library.  You should call
2711 @code{AC_PROG_RANLIB} from your @file{configure.ac} to define
2712 @code{RANLIB} (Automake will complain otherwise).  @code{AR} and
2713 @code{ARFLAGS} default to @code{ar} and @code{cru} respectively; you
2714 can override these two variables my setting them in your
2715 @file{Makefile.am}, by @code{AC_SUBST}ing them from your
2716 @file{configure.ac}, or by defining a per-library @code{maude_AR}
2717 variable (@pxref{Program and Library Variables}).
2719 @node A Shared Library
2720 @section Building a Shared Library
2722 @cindex Shared libraries, support for
2724 Building shared libraries portably is a relatively complex matter.
2725 For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
2726 Libtool Manual}) was created to help build shared libraries in a
2727 platform-independent way.
2729 @menu
2730 * Libtool Concept::             Introducing Libtool
2731 * Libtool Libraries::           Declaring Libtool Libraries
2732 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
2733 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
2734 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
2735 * Libtool Modules::             Building Libtool Modules
2736 * Libtool Flags::               Using _LIBADD and _LDFLAGS
2737 * LTLIBOBJ::                    Using $(LTLIBOBJ)
2738 * Libtool Issues::              Common Issues Related to Libtool's Use
2739 @end menu
2741 @node Libtool Concept
2742 @subsection The Libtool Concept
2744 @cindex libtool, introduction
2745 @cindex libtool library, definition
2746 @cindex suffix .la, defined
2747 @cindex .la suffix, defined
2749 Libtool abstracts shared and static libraries into a unified
2750 concept henceforth called @dfn{libtool libraries}.  Libtool libraries
2751 are files using the @file{.la} suffix, and can designate a static
2752 library, a shared library, or maybe both.  Their exact nature cannot
2753 be determined until @file{./configure} is run: not all platforms
2754 support all kinds of libraries, and users can explicitly select which
2755 libraries should be built.  (However the package's maintainers can
2756 tune the default, @xref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
2757 macro, libtool, The Libtool Manual}.)
2759 @cindex suffix .lo, defined
2760 Because object files for shared and static libraries must be compiled
2761 differently, libtool is also used during compilation.  Object files
2762 built by libtool are called @dfn{libtool objects}: these are files
2763 using the @file{.lo} suffix.  Libtool libraries are built from these
2764 libtool objects.
2766 You should not assume anything about the structure of @file{.la} or
2767 @file{.lo} files and how libtool constructs them: this is libtool's
2768 concern, and the last thing one wants is to learn about libtool's
2769 guts.  However the existence of these files matters, because they are
2770 used as targets and dependencies in @file{Makefile}s rules when
2771 building libtool libraries.  There are situations where you may have
2772 to refer to these, for instance when expressing dependencies for
2773 building source files conditionally (@pxref{Conditional Libtool
2774 Sources}).
2776 @cindex libltdl, introduction
2778 People considering writing a plug-in system, with dynamically loaded
2779 modules, should look into @file{libltdl}: libtool's dlopening library
2780 (@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
2781 This offers a portable dlopening facility to load libtool libraries
2782 dynamically, and can also achieve static linking where unavoidable.
2784 Before we discuss how to use libtool with Automake in details, it
2785 should be noted that the libtool manual also has a section about how
2786 to use Automake with libtool (@pxref{Using Automake, , Using Automake
2787 with Libtool, libtool, The Libtool Manual}).
2789 @node Libtool Libraries
2790 @subsection Building Libtool Libraries
2792 @cindex _LTLIBRARIES primary, defined
2793 @cindex LTLIBRARIES primary, defined
2794 @cindex Primary variable, LTLIBRARIES
2795 @cindex Example of shared libraries
2796 @vindex lib_LTLIBRARIES
2797 @vindex pkglib_LTLIBRARIES
2799 Automake uses libtool to build libraries declared with the
2800 @samp{LTLIBRARIES} primary.  Each @samp{_LTLIBRARIES} variable is a
2801 list of libtool libraries to build.  For instance, to create a libtool
2802 library named @file{libgettext.la}, and install it in @samp{libdir},
2803 write:
2805 @example
2806 lib_LTLIBRARIES = libgettext.la
2807 libgettext_la_SOURCES = gettext.c gettext.h @dots{}
2808 @end example
2810 Automake predefines the variable @samp{pkglibdir}, so you can use
2811 @code{pkglib_LTLIBRARIES} to install libraries in
2812 @code{$(libdir)/@@PACKAGE@@/}.
2814 @node Conditional Libtool Libraries
2815 @subsection Building Libtool Libraries Conditionally
2816 @cindex libtool libraries, conditional
2817 @cindex conditional libtool libraries
2819 Like conditional programs (@pxref{Conditional Programs}), there are
2820 two main ways to build conditional libraries: using Automake
2821 conditionals or using Autoconf @code{AC_SUBST}itutions.
2823 The important implementation detail you have to be aware of is that
2824 the place where a library will be installed matters to libtool: it
2825 needs to be indicated @emph{at link-time} using the @code{-rpath}
2826 option.
2828 For libraries whose destination directory is known when Automake runs,
2829 Automake will automatically supply the appropriate @samp{-rpath}
2830 option to libtool. This is the case for libraries listed explicitly in
2831 some installable @code{_LTLIBRARIES} variables such as
2832 @code{lib_LTLIBRARIES}.
2834 However, for libraries determined at configure time (and thus
2835 mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
2836 final installation directory.  For such libraries you must add the
2837 @samp{-rpath} option to the appropriate @samp{_LDFLAGS} variable by
2838 hand.
2840 The examples below illustrate the differences between these two methods.
2842 Here is an example where @code{$(WANTEDLIBS)} is an @code{AC_SUBST}ed
2843 variable set at @file{./configure}-time to either @file{libfoo.la},
2844 @file{libbar.la}, both, or none.  Although @code{$(WANTEDLIBS)}
2845 appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
2846 relates to @file{libfoo.la} or @file{libbar.la} by the time it creates
2847 the link rule for these two libraries.  Therefore the @code{-rpath}
2848 argument must be explicitly supplied.
2850 @example
2851 EXTRA_LTLIBRARIES = libfoo.la libbar.la
2852 lib_LTLIBRARIES = $(WANTEDLIBS)
2853 libfoo_la_SOURCES = foo.c @dots{}
2854 libfoo_la_LDFLAGS = -rpath '$(libdir)'
2855 libbar_la_SOURCES = bar.c @dots{}
2856 libbar_la_LDFLAGS = -rpath '$(libdir)'
2857 @end example
2859 Here is how the same @file{Makefile.am} would look using Automake
2860 conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}.  Now
2861 Automake is able to compute the @code{-rpath} setting itself, because
2862 it's clear that both libraries will end up in @code{$(libdir)} if they
2863 are installed.
2865 @example
2866 lib_LTLIBRARIES =
2867 if WANT_LIBFOO
2868 lib_LTLIBRARIES += libfoo.la
2869 endif
2870 if WANT_LIBBAR
2871 lib_LTLIBRARIES += libbar.la
2872 endif
2873 libfoo_la_SOURCES = foo.c @dots{}
2874 libbar_la_SOURCES = bar.c @dots{}
2875 @end example
2877 @node Conditional Libtool Sources
2878 @subsection Libtool Libraries with Conditional Sources
2880 Conditional compilation of sources in a library can be achieved in the
2881 same way as conditional compilation of sources in a program
2882 (@pxref{Conditional Sources}).  The only difference is that
2883 @code{_LIBADD} should be used instead of @code{_LDADD} and that it
2884 should mention libtool objects (@file{.lo} files).
2886 So, to mimic the @file{hello} example from @ref{Conditional Sources},
2887 we could build a @file{libhello.la} library using either
2888 @file{hello-linux.c} or @file{hello-generic.c} with the following
2889 @file{Makefile.am}.
2891 @example
2892 lib_LTLIBRARIES = libhello.la
2893 libhello_la_SOURCES = hello-common.c
2894 EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
2895 libhello_la_LIBADD = $(HELLO_SYSTEM)
2896 libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
2897 @end example
2899 @noindent
2900 And make sure @code{$(HELLO_SYSTEM)} is set to either
2901 @file{hello-linux.lo} or @file{hello-generic.lo} in
2902 @file{./configure}.
2904 Or we could simply use an Automake conditional as follows.
2906 @example
2907 lib_LTLIBRARIES = libhello.la
2908 libhello_la_SOURCES = hello-common.c
2909 if LINUX
2910 libhello_la_SOURCES += hello-linux.c
2911 else
2912 libhello_la_SOURCES += hello-generic.c
2913 endif
2914 @end example
2916 @node Libtool Convenience Libraries
2917 @subsection Libtool Convenience Libraries
2918 @cindex convenience libraries, libtool
2919 @cindex libtool convenience libraries
2920 @vindex noinst_LTLIBRARIES
2921 @vindex check_LTLIBRARIES
2923 Sometimes you want to build libtool libraries which should not be
2924 installed.  These are called @dfn{libtool convenience libraries} and
2925 are typically used to encapsulate many sublibraries, later gathered
2926 into one big installed library.
2928 Libtool convenience libraries are declared by
2929 @code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
2930 @code{EXTRA_LTLIBRARIES}.  Unlike installed libtool libraries they do
2931 not need an @code{-rpath} flag at link time (actually this is the only
2932 difference).
2934 Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
2935 built.  Those listed in @code{check_LTLIBRARIES} are built only upon
2936 @code{make check}.  Finally, libraries listed in
2937 @code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
2938 rules to build them, but if the library does not appear as a Makefile
2939 dependency anywhere it won't be built (this is why
2940 @code{EXTRA_LTLIBRARIES} is used for conditional compilation).
2942 Here is a sample setup merging libtool convenience libraries from
2943 subdirectories into one main @file{libtop.la} library.
2945 @example
2946 # -- Top-level Makefile.am --
2947 SUBDIRS = sub1 sub2 @dots{}
2948 lib_LTLIBRARIES = libtop.la
2949 libtop_la_SOURCES =
2950 libtop_la_LIBADD = \
2951   sub1/libsub1.la \
2952   sub2/libsub2.la \
2953   @dots{}
2955 # -- sub1/Makefile.am --
2956 noinst_LTLIBRARIES = libsub1.la
2957 libsub1_la_SOURCES = @dots{}
2959 # -- sub2/Makefile.am --
2960 # showing nested convenience libraries
2961 SUBDIRS = sub2.1 sub2.2 @dots{}
2962 noinst_LTLIBRARIES = libsub2.la
2963 libsub2_la_SOURCES =
2964 libsub2_la_LIBADD = \
2965   sub21/libsub21.la \
2966   sub22/libsub22.la \
2967   @dots{}
2968 @end example
2970 @node Libtool Modules
2971 @subsection Libtool Modules
2972 @cindex modules, libtool
2973 @cindex libtool modules
2974 @cindex -module, libtool
2976 These are libtool libraries meant to be dlopened.  They are
2977 indicated to libtool by passing @code{-module} at link-time.
2979 @example
2980 pkglib_LTLIBRARIES = mymodule.la
2981 mymodule_la_SOURCES = doit.c
2982 mymodule_LDFLAGS = -module
2983 @end example
2985 Ordinarily, Automake requires that a Library's name starts with
2986 @samp{lib}.  However, when building a dynamically loadable module you
2987 might wish to use a "nonstandard" name.
2989 If @samp{mymodule_la_SOURCES} is not specified, then it defaults to the single
2990 file @file{mymodule.c} (@pxref{Default _SOURCES}).
2992 @node Libtool Flags
2993 @subsection _LIBADD and _LDFLAGS
2994 @cindex _LIBADD, libtool
2995 @cindex _LDFLAGS, libtool
2997 As shown in previous sections, the @samp{@var{library}_LIBADD}
2998 variable should be used to list extra libtool objects (@file{.lo}
2999 files) or libtool libraries (@file{.la}) to add to @var{library}.
3001 The @samp{@var{library}_LDFLAGS} variable is the place to list
3002 additional libtool flags, such as @samp{-version-info},
3003 @samp{-static}, and a lot more.  See @xref{Link mode, , Using libltdl,
3004 libtool, The Libtool Manual}.
3006 @node LTLIBOBJ, Libtool Issues, Libtool Flags, A Shared Library
3007 @subsection @code{LTLIBOBJS}
3008 @cindex @code{LTLIBOBJS}, special handling
3009 @vindex LTLIBOBJS
3010 @vindex LIBOBJS
3011 @cvindex AC_LIBOBJ
3013 Where an ordinary library might include @code{$(LIBOBJS)}, a libtool
3014 library must use @code{$(LTLIBOBJS)}.  This is required because the
3015 object files that libtool operates on do not necessarily end in
3016 @file{.o}.
3018 Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
3019 performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
3020 @code{AC_LIBOBJ} vs. @code{LIBOBJS}, autoconf, The Autoconf Manual}).
3022 @node Libtool Issues
3023 @subsection Common Issues Related to Libtool's Use
3025 @subsubsection @code{required file `./ltmain.sh' not found}
3026 @cindex ltmain.sh not found
3027 @cindex libtoolize, no longer run by Automake
3028 @cindex libtoolize and autoreconf
3029 @cindex autoreconf and libtoolize
3030 @cindex bootstrap.sh and autoreconf
3031 @cindex autogen.sh and autoreconf
3033 Libtool comes with a tool called @command{libtoolize} that will
3034 install libtool's supporting files into a package.  Running this
3035 command will install @file{ltmain.sh}.  You should execute it before
3036 @command{aclocal} and @command{automake}.
3038 People upgrading old packages to newer autotools are likely to face
3039 this issue because older Automake versions used to call
3040 @command{libtoolize}.  Therefore old build scripts do not call
3041 @command{libtoolize}.
3043 Since Automake 1.6, it has been decided that running
3044 @command{libtoolize} was none of Automake's business.  Instead, that
3045 functionality has been moved into the @command{autoreconf} command
3046 (@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
3047 The Autoconf Manual}).  If you do not want to remember what to run and
3048 when, just learn the @command{autoreconf} command.  Hopefully,
3049 replacing existing @file{bootstrap.sh} or @file{autogen.sh} scripts by
3050 a call to @command{autoreconf} should also free you from any similar
3051 incompatible change in the future.
3053 @subsubsection Objects @code{created with both libtool and without}
3055 Sometimes, the same source file is used both to build a libtool
3056 library and to build another non-libtool target (be it a program or
3057 another library).
3059 Let's consider the following @file{Makefile.am}.
3061 @example
3062 bin_PROGRAMS = prog
3063 prog_SOURCES = prog.c foo.c @dots{}
3065 lib_LTLIBRARIES = libfoo.la
3066 libfoo_la_SOURCES = foo.c @dots{}
3067 @end example
3069 @noindent
3070 (In this trivial case the issue could be avoided by linking
3071 @file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
3072 @code{prog_SOURCES}.  But let's assume we really want to keep
3073 @file{prog} and @file{libfoo.la} separate.)
3075 Technically, it means that we should build @file{foo.$(OBJEXT)} for
3076 @file{prog}, and @file{foo.lo} for @file{libfoo.la}.  The problem is
3077 that in the course of creating @file{foo.lo}, libtool may erase (or
3078 replace) @file{foo.$(OBJEXT)} -- and this cannot be avoided.
3080 Therefore, when Automake detects this situation it will complain
3081 with a message such as
3082 @example
3083 object `foo.$(OBJEXT)' created both with libtool and without
3084 @end example
3086 A workaround for this issue is to ensure that these two objects get
3087 different basenames.  As explained in @ref{renamed objects}, this
3088 happens automatically when per-targets flags are used.
3090 @example
3091 bin_PROGRAMS = prog
3092 prog_SOURCES = prog.c foo.c @dots{}
3093 prog_CFLAGS = $(AM_CFLAGS)
3095 lib_LTLIBRARIES = libfoo.la
3096 libfoo_la_SOURCES = foo.c @dots{}
3097 @end example
3099 @noindent
3100 Adding @code{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
3101 when the @code{prog_CFLAGS} is defined, it is used instead of
3102 @code{AM_CFLAGS}.  However as a side effect it will cause
3103 @file{prog.c} and @file{foo.c} to be compiled as
3104 @file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)} which solves
3105 the issue.
3107 @node Program and Library Variables
3108 @section Program and Library Variables
3110 Associated with each program are a collection of variables which can be
3111 used to modify how that program is built.  There is a similar list of
3112 such variables for each library.  The canonical name of the program (or
3113 library) is used as a base for naming these variables.
3115 In the list below, we use the name ``maude'' to refer to the program or
3116 library.  In your @file{Makefile.am} you would replace this with the
3117 canonical name of your program.  This list also refers to ``maude'' as a
3118 program, but in general the same rules apply for both static and dynamic
3119 libraries; the documentation below notes situations where programs and
3120 libraries differ.
3122 @table @samp
3123 @item maude_SOURCES
3124 This variable, if it exists, lists all the source files which are
3125 compiled to build the program.  These files are added to the
3126 distribution by default.  When building the program, Automake will cause
3127 each source file to be compiled to a single @file{.o} file (or
3128 @file{.lo} when using libtool).  Normally these object files are named
3129 after the source file, but other factors can change this.  If a file in
3130 the @samp{_SOURCES} variable has an unrecognized extension, Automake
3131 will do one of two things with it.  If a suffix rule exists for turning
3132 files with the unrecognized extension into @file{.o} files, then
3133 automake will treat this file as it will any other source file
3134 (@pxref{Support for Other Languages}).  Otherwise, the file will be
3135 ignored as though it were a header file.
3137 The prefixes @samp{dist_} and @samp{nodist_} can be used to control
3138 whether files listed in a @samp{_SOURCES} variable are distributed.
3139 @samp{dist_} is redundant, as sources are distributed by default, but it
3140 can be specified for clarity if desired.
3142 It is possible to have both @samp{dist_} and @samp{nodist_} variants of
3143 a given @samp{_SOURCES} variable at once; this lets you easily
3144 distribute some files and not others, for instance:
3146 @example
3147 nodist_maude_SOURCES = nodist.c
3148 dist_maude_SOURCES = dist-me.c
3149 @end example
3151 By default the output file (on Unix systems, the @file{.o} file) will be
3152 put into the current build directory.  However, if the option
3153 @code{subdir-objects} is in effect in the current directory then the
3154 @file{.o} file will be put into the subdirectory named after the source
3155 file.  For instance, with @code{subdir-objects} enabled,
3156 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
3157 people prefer this mode of operation.  You can specify
3158 @code{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
3159 @cindex Subdirectory, objects in
3160 @cindex Objects in subdirectory
3163 @item EXTRA_maude_SOURCES
3164 Automake needs to know the list of files you intend to compile
3165 @emph{statically}.  For one thing, this is the only way Automake has of
3166 knowing what sort of language support a given @file{Makefile.in}
3167 requires.  @footnote{There are other, more obscure reasons reasons for
3168 this limitation as well.}  This means that, for example, you can't put a
3169 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
3170 variable.  If you intend to conditionally compile source files and use
3171 @file{configure} to substitute the appropriate object names into, e.g.,
3172 @samp{_LDADD} (see below), then you should list the corresponding source
3173 files in the @samp{EXTRA_} variable.
3175 This variable also supports @samp{dist_} and @samp{nodist_} prefixes,
3176 e.g., @samp{nodist_EXTRA_maude_SOURCES}.
3178 @item maude_AR
3179 A static library is created by default by invoking @code{$(AR)
3180 $(ARFLAGS)} followed by the name of the library and then the objects
3181 being put into the library.  You can override this by setting the
3182 @samp{_AR} variable.  This is usually used with C++; some C++
3183 compilers require a special invocation in order to instantiate all the
3184 templates which should go into a library.  For instance, the SGI C++
3185 compiler likes this variable set like so:
3186 @example
3187 libmaude_a_AR = $(CXX) -ar -o
3188 @end example
3190 @item maude_LIBADD
3191 Extra objects can be added to a @emph{library} using the @samp{_LIBADD}
3192 variable.  For instance this should be used for objects determined by
3193 @code{configure} (@pxref{A Library}).
3195 @item maude_LDADD
3196 Extra objects can be added to a @emph{program} by listing them in the
3197 @samp{_LDADD} variable.  For instance this should be used for objects
3198 determined by @code{configure} (@pxref{Linking}).
3200 @samp{_LDADD} and @samp{_LIBADD} are inappropriate for passing
3201 program-specific linker flags (except for @samp{-l}, @samp{-L},
3202 @samp{-dlopen} and @samp{-dlpreopen}).  Use the @samp{_LDFLAGS} variable
3203 for this purpose.
3205 For instance, if your @file{configure.ac} uses @code{AC_PATH_XTRA}, you
3206 could link your program against the X libraries like so:
3208 @example
3209 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
3210 @end example
3212 @item maude_LDFLAGS
3213 This variable is used to pass extra flags to the link step of a program
3214 or a shared library.
3216 @item maude_DEPENDENCIES
3217 It is also occasionally useful to have a program depend on some other
3218 target which is not actually part of that program.  This can be done
3219 using the @samp{_DEPENDENCIES} variable.  Each program depends on the
3220 contents of such a variable, but no further interpretation is done.
3222 If @samp{_DEPENDENCIES} is not supplied, it is computed by Automake.
3223 The automatically-assigned value is the contents of @samp{_LDADD} or
3224 @samp{_LIBADD}, with most configure substitutions, @samp{-l}, @samp{-L},
3225 @samp{-dlopen} and @samp{-dlpreopen} options removed.  The configure
3226 substitutions that are left in are only @samp{$(LIBOBJS)} and
3227 @samp{$(ALLOCA)}; these are left because it is known that they will not
3228 cause an invalid value for @samp{_DEPENDENCIES} to be generated.
3230 @item maude_LINK
3231 You can override the linker on a per-program basis.  By default the
3232 linker is chosen according to the languages used by the program.  For
3233 instance, a program that includes C++ source code would use the C++
3234 compiler to link.  The @samp{_LINK} variable must hold the name of a
3235 command which can be passed all the @file{.o} file names as arguments.
3236 Note that the name of the underlying program is @emph{not} passed to
3237 @samp{_LINK}; typically one uses @samp{$@@}:
3239 @example
3240 maude_LINK = $(CCLD) -magic -o $@@
3241 @end example
3243 @item maude_CCASFLAGS
3244 @itemx maude_CFLAGS
3245 @itemx maude_CPPFLAGS
3246 @itemx maude_CXXFLAGS
3247 @itemx maude_FFLAGS
3248 @itemx maude_GCJFLAGS
3249 @itemx maude_LFLAGS
3250 @itemx maude_OBJCFLAGS
3251 @itemx maude_RFLAGS
3252 @itemx maude_YFLAGS
3253 @cindex per-target compilation flags, defined
3254 Automake allows you to set compilation flags on a per-program (or
3255 per-library) basis.  A single source file can be included in several
3256 programs, and it will potentially be compiled with different flags for
3257 each program.  This works for any language directly supported by
3258 Automake.  These @dfn{per-target compilation flags} are
3259 @samp{_CCASFLAGS},
3260 @samp{_CFLAGS},
3261 @samp{_CPPFLAGS},
3262 @samp{_CXXFLAGS},
3263 @samp{_FFLAGS},
3264 @samp{_GCJFLAGS},
3265 @samp{_LFLAGS},
3266 @samp{_OBJCFLAGS},
3267 @samp{_RFLAGS}, and
3268 @samp{_YFLAGS}.
3270 When using a per-target compilation flag, Automake will choose a
3271 different name for the intermediate object files.  Ordinarily a file
3272 like @file{sample.c} will be compiled to produce @file{sample.o}.
3273 However, if the program's @samp{_CFLAGS} variable is set, then the
3274 object file will be named, for instance, @file{maude-sample.o}.
3275 (See also @ref{renamed objects}.)
3277 In compilations with per-target flags, the ordinary @samp{AM_} form of
3278 the flags variable is @emph{not} automatically included in the
3279 compilation (however, the user form of the variable @emph{is} included).
3280 So for instance, if you want the hypothetical @file{maude} compilations
3281 to also use the value of @samp{AM_CFLAGS}, you would need to write:
3283 @example
3284 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
3285 @end example
3288 @item maude_SHORTNAME
3289 On some platforms the allowable file names are very short.  In order to
3290 support these systems and per-target compilation flags at the same
3291 time, Automake allows you to set a ``short name'' which will influence
3292 how intermediate object files are named.  For instance, in the following
3293 example,
3295 @example
3296 bin_PROGRAMS = maude
3297 maude_CPPFLAGS = -DSOMEFLAG
3298 maude_SHORTNAME = m
3299 maude_SOURCES = sample.c @dots{}
3300 @end example
3302 @noindent
3303 the object file would be named @file{m-sample.o} rather than
3304 @file{maude-sample.o}.
3306 This facility is rarely needed in practice,
3307 and we recommend avoiding it until you find it is required.
3308 @end table
3310 @node Default _SOURCES
3311 @section Default @code{_SOURCES}
3313 @vindex _SOURCES
3314 @vindex SOURCES
3315 @cindex @code{_SOURCES}, default
3316 @cindex default @code{_SOURCES}
3318 @code{_SOURCES} variables are used to specify source files of programs
3319 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
3320 libraries (@pxref{A Shared Library}).
3322 When no such variable is specified for a target, Automake will define
3323 one itself.  The default is to compile a single C file whose base name
3324 is the name of the target itself, with any extension replaced by
3325 @file{.c}.  (Defaulting to C is terrible but we are stuck with it for
3326 historical reasons.)
3328 For example if you have the following somewhere in your
3329 @file{Makefile.am} with no corresponding @samp{libfoo_a_SOURCES}:
3331 @example
3332 lib_LIBRARIES = libfoo.a sub/libc++.a
3333 @end example
3335 @noindent
3336 @file{libfoo.a} will be built using a default source file named
3337 @file{libfoo.c}, and @file{sub/libc++.a} will be built from
3338 @file{sub/libc++.c}.  (In older versions @file{sub/libc++.a}
3339 would be built from @file{sub_libc___a.c}, i.e., the default source
3340 was the canonized name of the target, with @file{.c} appended.
3341 Be believe the new behavior is more sensible, but for backward
3342 compatibility automake will use the old name if a file or a rule
3343 with that name exist.)
3345 @cindex @code{check_PROGRAMS} example
3346 @vindex check_PROGRAMS
3347 Default sources are mainly useful in test suites, when building many
3348 tests programs each from a single source.  For instance in
3350 @example
3351 check_PROGRAMS = test1 test2 test3
3352 @end example
3354 @noindent
3355 @file{test1}, @file{test2}, and @file{test3} will be built
3356 from @file{test1.c}, @file{test2.c}, and @file{test3.c}.
3358 @cindex Libtool modules, default source example
3359 @cindex default source, Libtool modules example
3360 Another case where is this convenient is building many Libtool modules
3361 (@file{moduleN.la}), each defined in its own file (@file{moduleN.c}).
3363 @example
3364 AM_LDFLAGS = -module
3365 lib_LTLIBRARIES = module1.la module2.la module3.la
3366 @end example
3368 @cindex empty @code{_SOURCES}
3369 @cindex @code{_SOURCES}, empty
3370 Finally, there is one situation where this default source computation
3371 needs to be avoided: when a target should not be built from sources.
3372 We already saw such an example in @ref{true}; this happens when all
3373 the constituents of a target have already been compiled and need just
3374 to be combined using a @code{_LDADD} variable.  Then it is necessary
3375 to define an empty @code{_SOURCES} variable, so that automake does not
3376 compute a default.
3378 @example
3379 bin_PROGRAMS = target
3380 target_SOURCES =
3381 target_LDADD = libmain.a libmisc.a
3382 @end example
3384 @node LIBOBJS
3385 @section Special handling for LIBOBJS and ALLOCA
3387 @cindex @code{LIBOBJS}, special handling
3388 @cindex @code{ALLOCA}, special handling
3390 Automake explicitly recognizes the use of @code{$(LIBOBJS)} and
3391 @code{$(ALLOCA)}, and uses this information, plus the list of
3392 @code{LIBOBJS} files derived from @file{configure.ac} to automatically
3393 include the appropriate source files in the distribution (@pxref{Dist}).
3394 These source files are also automatically handled in the
3395 dependency-tracking scheme; see @xref{Dependencies}.
3397 @code{$(LIBOBJS)} and @code{$(ALLOCA)} are specially recognized in any
3398 @samp{_LDADD} or @samp{_LIBADD} variable.
3401 @node Program variables
3402 @section Variables used when building a program
3404 Occasionally it is useful to know which @file{Makefile} variables
3405 Automake uses for compilations; for instance you might need to do your
3406 own compilation in some special cases.
3408 Some variables are inherited from Autoconf; these are @code{CC},
3409 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
3410 @code{LIBS}.
3411 @vindex CC
3412 @vindex CFLAGS
3413 @vindex CPPFLAGS
3414 @vindex DEFS
3415 @vindex LDFLAGS
3416 @vindex LIBS
3418 There are some additional variables which Automake itself defines:
3420 @vtable @code
3421 @item AM_CPPFLAGS
3422 The contents of this variable are passed to every compilation which invokes
3423 the C preprocessor; it is a list of arguments to the preprocessor.  For
3424 instance, @samp{-I} and @samp{-D} options should be listed here.
3426 Automake already provides some @samp{-I} options automatically.  In
3427 particular it generates @samp{-I$(srcdir)}, @samp{-I.}, and a @samp{-I}
3428 pointing to the directory holding @file{config.h} (if you've used
3429 @code{AC_CONFIG_HEADERS} or @code{AM_CONFIG_HEADER}).  You can disable
3430 the default @samp{-I} options using the @samp{nostdinc} option.
3432 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
3433 per-library) @code{_CPPFLAGS} variable if it is defined.
3435 @item INCLUDES
3436 This does the same job as @samp{AM_CPPFLAGS} (or any per-target
3437 @samp{_CPPFLAGS} variable if it is used).  It is an older name for the
3438 same functionality.  This variable is deprecated; we suggest using
3439 @samp{AM_CPPFLAGS} and per-target @samp{_CPPFLAGS} instead.
3441 @item AM_CFLAGS
3442 This is the variable which the @file{Makefile.am} author can use to pass
3443 in additional C compiler flags.  It is more fully documented elsewhere.
3444 In some situations, this is not used, in preference to the
3445 per-executable (or per-library) @code{_CFLAGS}.
3447 @item COMPILE
3448 This is the command used to actually compile a C source file.  The
3449 filename is appended to form the complete command line.
3451 @item AM_LDFLAGS
3452 This is the variable which the @file{Makefile.am} author can use to pass
3453 in additional linker flags.  In some situations, this is not used, in
3454 preference to the per-executable (or per-library) @code{_LDFLAGS}.
3456 @item LINK
3457 This is the command used to actually link a C program.  It already
3458 includes @samp{-o $@@} and the usual variable references (for instance,
3459 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
3460 and libraries to link in.
3461 @end vtable
3464 @node Yacc and Lex
3465 @section Yacc and Lex support
3467 Automake has somewhat idiosyncratic support for Yacc and Lex.
3469 Automake assumes that the @file{.c} file generated by @code{yacc} (or
3470 @code{lex}) should be named using the basename of the input file.  That
3471 is, for a yacc source file @file{foo.y}, Automake will cause the
3472 intermediate file to be named @file{foo.c} (as opposed to
3473 @file{y.tab.c}, which is more traditional).
3475 The extension of a yacc source file is used to determine the extension
3476 of the resulting @samp{C} or @samp{C++} file.  Files with the extension
3477 @samp{.y} will be turned into @samp{.c} files; likewise, @samp{.yy} will
3478 become @samp{.cc}; @samp{.y++}, @samp{c++}; and @samp{.yxx},
3479 @samp{.cxx}.
3481 Likewise, lex source files can be used to generate @samp{C} or
3482 @samp{C++}; the extensions @samp{.l}, @samp{.ll}, @samp{.l++}, and
3483 @samp{.lxx} are recognized.
3485 You should never explicitly mention the intermediate (@samp{C} or
3486 @samp{C++}) file in any @samp{SOURCES} variable; only list the source
3487 file.
3489 The intermediate files generated by @code{yacc} (or @code{lex}) will be
3490 included in any distribution that is made.  That way the user doesn't
3491 need to have @code{yacc} or @code{lex}.
3493 If a @code{yacc} source file is seen, then your @file{configure.ac} must
3494 define the variable @samp{YACC}.  This is most easily done by invoking
3495 the macro @samp{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
3496 Program Checks, autoconf, The Autoconf Manual}).
3498 When @code{yacc} is invoked, it is passed @samp{YFLAGS} and
3499 @samp{AM_YFLAGS}.  The former is a user variable and the latter is
3500 intended for the @file{Makefile.am} author.
3502 @samp{AM_YFLAGS} is usually used to pass the @code{-d} option to
3503 @code{yacc}.  Automake knows what this means and will automatically
3504 adjust its rules to update and distribute the header file built by
3505 @code{yacc -d}.  What Automake cannot guess, though, is where this
3506 header will be used: it is up to you to ensure the header gets built
3507 before it is first used.  Typically this is necessary in order for
3508 dependency tracking to work when the header is included by another
3509 file.  The common solution is listing the header file in
3510 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
3512 @example
3513 BUILT_SOURCES = parser.h
3514 AM_YFLAGS = -d
3515 bin_PROGRAMS = foo
3516 foo_SOURCES = @dots{} parser.y @dots{}
3517 @end example
3519 If a @code{lex} source file is seen, then your @file{configure.ac}
3520 must define the variable @samp{LEX}.  You can use @samp{AC_PROG_LEX}
3521 to do this (@pxref{Particular Programs, , Particular Program Checks,
3522 autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
3523 (@pxref{Macros}) is recommended.
3525 When @code{lex} is invoked, it is passed @samp{LFLAGS} and
3526 @samp{AM_LFLAGS}.  The former is a user variable and the latter is
3527 intended for the @file{Makefile.am} author.
3531 @cindex ylwrap
3532 @cindex yacc, multiple parsers
3533 @cindex Multiple yacc parsers
3534 @cindex Multiple lex lexers
3535 @cindex lex, multiple lexers
3538 Automake makes it possible to include multiple @code{yacc} (or
3539 @code{lex}) source files in a single program.  When there is more than
3540 one distinct @code{yacc} (or @code{lex}) source file in a directory,
3541 Automake uses a small program called @code{ylwrap} to run @code{yacc}
3542 (or @code{lex}) in a subdirectory.  This is necessary because yacc's
3543 output filename is fixed, and a parallel make could conceivably invoke
3544 more than one instance of @code{yacc} simultaneously.  The @code{ylwrap}
3545 program is distributed with Automake.  It should appear in the directory
3546 specified by @samp{AC_CONFIG_AUX_DIR} (@pxref{Input, , Finding
3547 `configure' Input, autoconf, The Autoconf Manual}), or the current
3548 directory if that macro is not used in @file{configure.ac}.
3550 For @code{yacc}, simply managing locking is insufficient.  The output of
3551 @code{yacc} always uses the same symbol names internally, so it isn't
3552 possible to link two @code{yacc} parsers into the same executable.
3554 We recommend using the following renaming hack used in @code{gdb}:
3555 @example
3556 #define yymaxdepth c_maxdepth
3557 #define yyparse c_parse
3558 #define yylex   c_lex
3559 #define yyerror c_error
3560 #define yylval  c_lval
3561 #define yychar  c_char
3562 #define yydebug c_debug
3563 #define yypact  c_pact
3564 #define yyr1    c_r1
3565 #define yyr2    c_r2
3566 #define yydef   c_def
3567 #define yychk   c_chk
3568 #define yypgo   c_pgo
3569 #define yyact   c_act
3570 #define yyexca  c_exca
3571 #define yyerrflag c_errflag
3572 #define yynerrs c_nerrs
3573 #define yyps    c_ps
3574 #define yypv    c_pv
3575 #define yys     c_s
3576 #define yy_yys  c_yys
3577 #define yystate c_state
3578 #define yytmp   c_tmp
3579 #define yyv     c_v
3580 #define yy_yyv  c_yyv
3581 #define yyval   c_val
3582 #define yylloc  c_lloc
3583 #define yyreds  c_reds
3584 #define yytoks  c_toks
3585 #define yylhs   c_yylhs
3586 #define yylen   c_yylen
3587 #define yydefred c_yydefred
3588 #define yydgoto c_yydgoto
3589 #define yysindex c_yysindex
3590 #define yyrindex c_yyrindex
3591 #define yygindex c_yygindex
3592 #define yytable  c_yytable
3593 #define yycheck  c_yycheck
3594 #define yyname   c_yyname
3595 #define yyrule   c_yyrule
3596 @end example
3598 For each define, replace the @samp{c_} prefix with whatever you like.
3599 These defines work for @code{bison}, @code{byacc}, and traditional
3600 @code{yacc}s.  If you find a parser generator that uses a symbol not
3601 covered here, please report the new name so it can be added to the list.
3604 @node C++ Support
3605 @section C++ Support
3607 @cindex C++ support
3608 @cindex Support for C++
3610 Automake includes full support for C++.
3612 Any package including C++ code must define the output variable
3613 @samp{CXX} in @file{configure.ac}; the simplest way to do this is to use
3614 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
3615 Program Checks, autoconf, The Autoconf Manual}).
3617 A few additional variables are defined when a C++ source file is seen:
3619 @vtable @code
3620 @item CXX
3621 The name of the C++ compiler.
3623 @item CXXFLAGS
3624 Any flags to pass to the C++ compiler.
3626 @item AM_CXXFLAGS
3627 The maintainer's variant of @code{CXXFLAGS}.
3629 @item CXXCOMPILE
3630 The command used to actually compile a C++ source file.  The file name
3631 is appended to form the complete command line.
3633 @item CXXLINK
3634 The command used to actually link a C++ program.
3635 @end vtable
3638 @node Assembly Support
3639 @section Assembly Support
3641 Automake includes some support for assembly code.
3643 The variable @code{CCAS} holds the name of the compiler used to build
3644 assembly code.  This compiler must work a bit like a C compiler; in
3645 particular it must accept @samp{-c} and @samp{-o}.  The value of
3646 @code{CCASFLAGS} is passed to the compilation.
3647 @vindex CCAS
3648 @vindex CCASFLAGS
3650 You are required to set @code{CCAS} and @code{CCASFLAGS} via
3651 @file{configure.ac}.  The autoconf macro @code{AM_PROG_AS} will do this
3652 for you.  Unless they are already set, it simply sets @code{CCAS} to the
3653 C compiler and @code{CCASFLAGS} to the C compiler flags.
3655 Only the suffixes @samp{.s} and @samp{.S} are recognized by
3656 @code{automake} as being files containing assembly code.
3659 @node Fortran 77 Support
3660 @comment  node-name,  next,  previous,  up
3661 @section Fortran 77 Support
3663 @cindex Fortran 77 support
3664 @cindex Support for Fortran 77
3666 Automake includes full support for Fortran 77.
3668 Any package including Fortran 77 code must define the output variable
3669 @samp{F77} in @file{configure.ac}; the simplest way to do this is to use
3670 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
3671 Program Checks, autoconf, The Autoconf Manual}).
3673 A few additional variables are defined when a Fortran 77 source file is
3674 seen:
3676 @vtable @code
3678 @item F77
3679 The name of the Fortran 77 compiler.
3681 @item FFLAGS
3682 Any flags to pass to the Fortran 77 compiler.
3684 @item AM_FFLAGS
3685 The maintainer's variant of @code{FFLAGS}.
3687 @item RFLAGS
3688 Any flags to pass to the Ratfor compiler.
3690 @item AM_RFLAGS
3691 The maintainer's variant of @code{RFLAGS}.
3693 @item F77COMPILE
3694 The command used to actually compile a Fortran 77 source file.  The file
3695 name is appended to form the complete command line.
3697 @item FLINK
3698 The command used to actually link a pure Fortran 77 program or shared
3699 library.
3701 @end vtable
3703 Automake can handle preprocessing Fortran 77 and Ratfor source files in
3704 addition to compiling them@footnote{Much, if not most, of the
3705 information in the following sections pertaining to preprocessing
3706 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
3707 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
3708 also contains some support for creating programs and shared libraries
3709 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
3710 Fortran 77 With C and C++}).
3712 These issues are covered in the following sections.
3714 @menu
3715 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
3716 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
3717 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
3718 @end menu
3721 @node Preprocessing Fortran 77
3722 @comment  node-name,  next,  previous,  up
3723 @subsection Preprocessing Fortran 77
3725 @cindex Preprocessing Fortran 77
3726 @cindex Fortran 77, Preprocessing
3727 @cindex Ratfor programs
3729 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
3730 rule runs just the preprocessor to convert a preprocessable Fortran 77
3731 or Ratfor source file into a strict Fortran 77 source file.  The precise
3732 command used is as follows:
3734 @table @file
3736 @item .F
3737 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)}
3739 @item .r
3740 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
3742 @end table
3745 @node Compiling Fortran 77 Files
3746 @comment  node-name,  next,  previous,  up
3747 @subsection Compiling Fortran 77 Files
3749 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
3750 @file{N.r} by running the Fortran 77 compiler.  The precise command used
3751 is as follows:
3753 @table @file
3755 @item .f
3756 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
3758 @item .F
3759 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)}
3761 @item .r
3762 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
3764 @end table
3767 @node Mixing Fortran 77 With C and C++
3768 @comment  node-name,  next,  previous,  up
3769 @subsection Mixing Fortran 77 With C and C++
3771 @cindex Fortran 77, mixing with C and C++
3772 @cindex Mixing Fortran 77 with C and C++
3773 @cindex Linking Fortran 77 with C and C++
3774 @cindex cfortran
3775 @cindex Mixing Fortran 77 with C and/or C++
3777 Automake currently provides @emph{limited} support for creating programs
3778 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
3779 However, there are many other issues related to mixing Fortran 77 with
3780 other languages that are @emph{not} (currently) handled by Automake, but
3781 that are handled by other packages@footnote{For example,
3782 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
3783 addresses all of these inter-language issues, and runs under nearly all
3784 Fortran 77, C and C++ compilers on nearly all platforms.  However,
3785 @code{cfortran} is not yet Free Software, but it will be in the next
3786 major release.}.
3788 @page
3789 Automake can help in two ways:
3791 @enumerate
3792 @item
3793 Automatic selection of the linker depending on which combinations of
3794 source code.
3796 @item
3797 Automatic selection of the appropriate linker flags (e.g. @samp{-L} and
3798 @samp{-l}) to pass to the automatically selected linker in order to link
3799 in the appropriate Fortran 77 intrinsic and run-time libraries.
3801 @cindex FLIBS, defined
3802 These extra Fortran 77 linker flags are supplied in the output variable
3803 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro
3804 supplied with newer versions of Autoconf (Autoconf version 2.13 and
3805 later).  @xref{Fortran 77 Compiler Characteristics, , , autoconf, The
3806 Autoconf}.
3807 @end enumerate
3809 If Automake detects that a program or shared library (as mentioned in
3810 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
3811 code that is a mixture of Fortran 77 and C and/or C++, then it requires
3812 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
3813 @file{configure.ac}, and that either @code{$(FLIBS)}
3814 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
3815 (for shared libraries) variables.  It is the responsibility of the
3816 person writing the @file{Makefile.am} to make sure that @code{$(FLIBS)}
3817 appears in the appropriate @code{_LDADD} or
3818 @code{_LIBADD} variable.
3820 @cindex Mixed language example
3821 @cindex Example, mixed language
3823 For example, consider the following @file{Makefile.am}:
3825 @example
3826 bin_PROGRAMS = foo
3827 foo_SOURCES  = main.cc foo.f
3828 foo_LDADD    = libfoo.la $(FLIBS)
3830 pkglib_LTLIBRARIES = libfoo.la
3831 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
3832 libfoo_la_LIBADD   = $(FLIBS)
3833 @end example
3835 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
3836 is mentioned in @file{configure.ac}.  Also, if @code{$(FLIBS)} hadn't
3837 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
3838 Automake would have issued a warning.
3841 @page
3842 @menu
3843 * How the Linker is Chosen::    Automatic linker selection
3844 @end menu
3846 @node How the Linker is Chosen
3847 @comment  node-name,  next,  previous,  up
3848 @subsubsection How the Linker is Chosen
3850 @cindex Automatic linker selection
3851 @cindex Selecting the linker automatically
3853 The following diagram demonstrates under what conditions a particular
3854 linker is chosen by Automake.
3856 For example, if Fortran 77, C and C++ source code were to be compiled
3857 into a program, then the C++ linker will be used.  In this case, if the
3858 C or Fortran 77 linkers required any special libraries that weren't
3859 included by the C++ linker, then they must be manually added to an
3860 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
3861 @file{Makefile.am}.
3863 @example
3864                      \              Linker
3865           source      \
3866            code        \     C        C++     Fortran
3867      -----------------  +---------+---------+---------+
3868                         |         |         |         |
3869      C                  |    x    |         |         |
3870                         |         |         |         |
3871                         +---------+---------+---------+
3872                         |         |         |         |
3873          C++            |         |    x    |         |
3874                         |         |         |         |
3875                         +---------+---------+---------+
3876                         |         |         |         |
3877                Fortran  |         |         |    x    |
3878                         |         |         |         |
3879                         +---------+---------+---------+
3880                         |         |         |         |
3881      C + C++            |         |    x    |         |
3882                         |         |         |         |
3883                         +---------+---------+---------+
3884                         |         |         |         |
3885      C +       Fortran  |         |         |    x    |
3886                         |         |         |         |
3887                         +---------+---------+---------+
3888                         |         |         |         |
3889          C++ + Fortran  |         |    x    |         |
3890                         |         |         |         |
3891                         +---------+---------+---------+
3892                         |         |         |         |
3893      C + C++ + Fortran  |         |    x    |         |
3894                         |         |         |         |
3895                         +---------+---------+---------+
3896 @end example
3899 @node Java Support
3900 @comment  node-name,  next,  previous,  up
3901 @section Java Support
3903 @cindex Java support
3904 @cindex Support for Java
3906 Automake includes support for compiled Java, using @code{gcj}, the Java
3907 front end to the GNU Compiler Collection.
3909 Any package including Java code to be compiled must define the output
3910 variable @samp{GCJ} in @file{configure.ac}; the variable @samp{GCJFLAGS}
3911 must also be defined somehow (either in @file{configure.ac} or
3912 @file{Makefile.am}).  The simplest way to do this is to use the
3913 @code{AM_PROG_GCJ} macro.
3915 @vindex GCJFLAGS
3917 By default, programs including Java source files are linked with
3918 @code{gcj}.
3920 As always, the contents of @samp{AM_GCJFLAGS} are passed to every
3921 compilation invoking @code{gcj} (in its role as an ahead-of-time
3922 compiler -- when invoking it to create @file{.class} files,
3923 @samp{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
3924 options to @code{gcj} from @file{Makefile.am}, this variable, and not
3925 the user variable @samp{GCJFLAGS}, should be used.
3927 @vindex AM_GCJFLAGS
3929 @code{gcj} can be used to compile @file{.java}, @file{.class},
3930 @file{.zip}, or @file{.jar} files.
3932 When linking, @code{gcj} requires that the main class be specified
3933 using the @samp{--main=} option.  The easiest way to do this is to use
3934 the @code{_LDFLAGS} variable for the program.
3937 @node Support for Other Languages
3938 @comment  node-name,  next,  previous,  up
3939 @section Support for Other Languages
3941 Automake currently only includes full support for C, C++ (@pxref{C++
3942 Support}), Fortran 77 (@pxref{Fortran 77 Support}), and Java
3943 (@pxref{Java Support}).  There is only rudimentary support for other
3944 languages, support for which will be improved based on user demand.
3946 Some limited support for adding your own languages is available via the
3947 suffix rule handling; see @ref{Suffixes}.
3950 @node ANSI
3951 @section Automatic de-ANSI-fication
3953 @cindex de-ANSI-fication, defined
3955 Although the GNU standards allow the use of ANSI C, this can have the
3956 effect of limiting portability of a package to some older compilers
3957 (notably the SunOS C compiler).
3959 Automake allows you to work around this problem on such machines by
3960 @dfn{de-ANSI-fying} each source file before the actual compilation takes
3961 place.
3963 @vindex AUTOMAKE_OPTIONS
3964 @opindex ansi2knr
3966 If the @file{Makefile.am} variable @code{AUTOMAKE_OPTIONS}
3967 (@pxref{Options}) contains the option @code{ansi2knr} then code to
3968 handle de-ANSI-fication is inserted into the generated
3969 @file{Makefile.in}.
3971 This causes each C source file in the directory to be treated as ANSI C@.
3972 If an ANSI C compiler is available, it is used.  If no ANSI C compiler
3973 is available, the @code{ansi2knr} program is used to convert the source
3974 files into K&R C, which is then compiled.
3976 The @code{ansi2knr} program is simple-minded.  It assumes the source
3977 code will be formatted in a particular way; see the @code{ansi2knr} man
3978 page for details.
3980 Support for de-ANSI-fication requires the source files @file{ansi2knr.c}
3981 and @file{ansi2knr.1} to be in the same package as the ANSI C source;
3982 these files are distributed with Automake.  Also, the package
3983 @file{configure.ac} must call the macro @code{AM_C_PROTOTYPES}
3984 (@pxref{Macros}).
3985 @cvindex AM_C_PROTOTYPES
3987 Automake also handles finding the @code{ansi2knr} support files in some
3988 other directory in the current package.  This is done by prepending the
3989 relative path to the appropriate directory to the @code{ansi2knr}
3990 option.  For instance, suppose the package has ANSI C code in the
3991 @file{src} and @file{lib} subdirectories.  The files @file{ansi2knr.c} and
3992 @file{ansi2knr.1} appear in @file{lib}.  Then this could appear in
3993 @file{src/Makefile.am}:
3995 @example
3996 AUTOMAKE_OPTIONS = ../lib/ansi2knr
3997 @end example
3999 If no directory prefix is given, the files are assumed to be in the
4000 current directory.
4002 Note that automatic de-ANSI-fication will not work when the package is
4003 being built for a different host architecture.  That is because automake
4004 currently has no way to build @code{ansi2knr} for the build machine.
4006 @c FIXME: this paragraph might be better moved to an `upgrading' section.
4007 @cindex @code{LTLIBOBJS} and @code{ansi2knr}
4008 @cindex @code{LIBOBJS} and @code{ansi2knr}
4009 @cindex @code{ansi2knr} and @code{LTLIBOBJS}
4010 @cindex @code{ansi2knr} and @code{LIBOBJS}
4011 Using @code{LIBOBJS} with source de-ANSI-fication used to require
4012 hand-crafted code in @file{configure} to append @code{$U} to basenames
4013 in @code{LIBOBJS}.  This is no longer true today.  Starting with version
4014 2.54, Autoconf takes care of rewriting @code{LIBOBJS} and
4015 @code{LTLIBOBJS}.  (@pxref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ}
4016 vs. @code{LIBOBJS}, autoconf, The Autoconf Manual})
4018 @node Dependencies
4019 @section Automatic dependency tracking
4021 As a developer it is often painful to continually update the
4022 @file{Makefile.in} whenever the include-file dependencies change in a
4023 project.  Automake supplies a way to automatically track dependency
4024 changes.
4026 @cindex Dependency tracking
4027 @cindex Automatic dependency tracking
4029 Automake always uses complete dependencies for a compilation, including
4030 system headers.  Automake's model is that dependency computation should
4031 be a side effect of the build.  To this end, dependencies are computed
4032 by running all compilations through a special wrapper program called
4033 @code{depcomp}.  @code{depcomp} understands how to coax many different C
4034 and C++ compilers into generating dependency information in the format
4035 it requires.  @code{automake -a} will install @code{depcomp} into your
4036 source tree for you.  If @code{depcomp} can't figure out how to properly
4037 invoke your compiler, dependency tracking will simply be disabled for
4038 your build.
4040 @cindex depcomp
4042 Experience with earlier versions of Automake @footnote{See
4043 @uref{http://sources.redhat.com/automake/dependencies.html} for more
4044 information on the history and experiences with automatic dependency
4045 tracking in Automake} taught us that it is not reliable to generate
4046 dependencies only on the maintainer's system, as configurations vary too
4047 much.  So instead Automake implements dependency tracking at build time.
4049 Automatic dependency tracking can be suppressed by putting
4050 @code{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
4051 passing @code{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
4052 (this should be the preferred way).  Or, you can invoke @code{automake}
4053 with the @code{-i} option.  Dependency tracking is enabled by default.
4055 @vindex AUTOMAKE_OPTIONS
4056 @opindex no-dependencies
4058 The person building your package also can choose to disable dependency
4059 tracking by configuring with @code{--disable-dependency-tracking}.
4061 @cindex Disabling dependency tracking
4062 @cindex Dependency tracking, disabling
4065 @node EXEEXT
4066 @section Support for executable extensions
4068 @cindex Executable extension
4069 @cindex Extension, executable
4070 @cindex Windows
4072 On some platforms, such as Windows, executables are expected to have an
4073 extension such as @samp{.exe}.  On these platforms, some compilers (GCC
4074 among them) will automatically generate @file{foo.exe} when asked to
4075 generate @file{foo}.
4077 Automake provides mostly-transparent support for this.  Unfortunately
4078 @emph{mostly} doesn't yet mean @emph{fully}.  Until the English
4079 dictionary is revised, you will have to assist Automake if your package
4080 must support those platforms.
4082 One thing you must be aware of is that, internally, Automake rewrites
4083 something like this:
4085 @example
4086 bin_PROGRAMS = liver
4087 @end example
4089 to this:
4091 @example
4092 bin_PROGRAMS = liver$(EXEEXT)
4093 @end example
4095 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
4096 extension.  @code{EXEEXT}
4098 However, Automake cannot apply this rewriting to @code{configure}
4099 substitutions.  This means that if you are conditionally building a
4100 program using such a substitution, then your @file{configure.ac} must
4101 take care to add @samp{$(EXEEXT)} when constructing the output variable.
4103 With Autoconf 2.13 and earlier, you must explicitly use @code{AC_EXEEXT}
4104 to get this support.  With Autoconf 2.50, @code{AC_EXEEXT} is run
4105 automatically if you configure a compiler (say, through
4106 @code{AC_PROG_CC}).
4108 Sometimes maintainers like to write an explicit link rule for their
4109 program.  Without executable extension support, this is easy---you
4110 simply write a rule whose target is the name of the program.  However,
4111 when executable extension support is enabled, you must instead add the
4112 @samp{$(EXEEXT)} suffix.
4114 Unfortunately, due to the change in Autoconf 2.50, this means you must
4115 always add this extension.  However, this is a problem for maintainers
4116 who know their package will never run on a platform that has
4117 executable extensions.  For those maintainers, the @code{no-exeext}
4118 option (@pxref{Options}) will disable this feature.  This works in a
4119 fairly ugly way; if @code{no-exeext} is seen, then the presence of a
4120 rule for a target named @code{foo} in @file{Makefile.am} will override
4121 an automake-generated rule for @code{foo$(EXEEXT)}.  Without
4122 the @code{no-exeext} option, this use will give a diagnostic.
4125 @node Other objects
4126 @chapter Other Derived Objects
4128 Automake can handle derived objects which are not C programs.  Sometimes
4129 the support for actually building such objects must be explicitly
4130 supplied, but Automake will still automatically handle installation and
4131 distribution.
4133 @menu
4134 * Scripts::                     Executable scripts
4135 * Headers::                     Header files
4136 * Data::                        Architecture-independent data files
4137 * Sources::                     Derived sources
4138 @end menu
4141 @node Scripts
4142 @section Executable Scripts
4144 @cindex _SCRIPTS primary, defined
4145 @cindex SCRIPTS primary, defined
4146 @cindex Primary variable, SCRIPTS
4148 It is possible to define and install programs which are scripts.  Such
4149 programs are listed using the @samp{SCRIPTS} primary name.  Automake
4150 doesn't define any dependencies for scripts; the @file{Makefile.am}
4151 should include the appropriate rules.
4152 @vindex SCRIPTS
4154 Automake does not assume that scripts are derived objects; such objects
4155 must be deleted by hand (@pxref{Clean}).
4157 The @code{automake} program itself is a Perl script that is generated
4158 from @file{automake.in}.  Here is how this is handled:
4160 @example
4161 bin_SCRIPTS = automake
4162 CLEANFILES = $(bin_SCRIPTS)
4164 do_subst = sed -e 's,[@@]datadir[@@],$(datadir),g' \
4165             -e 's,[@@]PERL[@@],$(PERL),g' \
4166             -e 's,[@@]PACKAGE[@@],$(PACKAGE),g' \
4167             -e 's,[@@]VERSION[@@],$(VERSION),g' \
4168             @dots{}
4170 automake: automake.in Makefile
4171         $(do_subst) < $(srcdir)/automake.in > automake
4172         chmod +x automake
4173 @end example
4175 Because---as we have just seen---scripts can be built, they are not
4176 distributed by default.  Scripts that should be distributed can be
4177 specified using a @code{dist_} prefix as in other primaries.  For
4178 instance the following @file{Makefile.am} declares that
4179 @file{my_script} should be distributed and installed in
4180 @code{$(sbindir)}.
4182 @example
4183 dist_sbin_SCRIPTS = my_script
4184 @end example
4186 @cindex SCRIPTS, installation directories
4187 @cindex Installing scripts
4189 @vindex bin_SCRIPTS
4190 @vindex sbin_SCRIPTS
4191 @vindex libexec_SCRIPTS
4192 @vindex pkgdata_SCRIPTS
4193 @vindex noinst_SCRIPTS
4194 @vindex check_SCRIPTS
4196 Script objects can be installed in @code{bindir}, @code{sbindir},
4197 @code{libexecdir}, or @code{pkgdatadir}.
4199 Scripts that need not being installed can be listed in
4200 @code{noinst_SCRIPTS}, and among them, those which are needed only by
4201 @code{make check} should go in @code{check_SCRIPTS}.
4204 @node Headers
4205 @section Header files
4207 @cindex _HEADERS primary, defined
4208 @cindex HEADERS primary, defined
4209 @cindex Primary variable, HEADERS
4211 @vindex noinst_HEADERS
4213 Header files are specified by the @samp{HEADERS} family of variables.
4214 Generally header files are not installed, so the @code{noinst_HEADERS}
4215 variable will be the most used.  @footnote{However, for the case of a
4216 non-installed header file that is actually used by a particular program,
4217 we recommend listing it in the program's @samp{_SOURCES} variable
4218 instead of in @code{noinst_HEADERS}.  We believe this is more clear.}
4219 @vindex HEADERS
4221 All header files must be listed somewhere; missing ones will not appear
4222 in the distribution.  Often it is clearest to list uninstalled headers
4223 with the rest of the sources for a program.  @xref{A Program}.  Headers
4224 listed in a @samp{_SOURCES} variable need not be listed in any
4225 @samp{_HEADERS} variable.
4227 @cindex HEADERS, installation directories
4228 @cindex Installing headers
4230 @vindex include_HEADERS
4231 @vindex oldinclude_HEADERS
4232 @vindex pkginclude_HEADERS
4234 Headers can be installed in @code{includedir}, @code{oldincludedir}, or
4235 @code{pkgincludedir}.
4238 @node Data
4239 @section Architecture-independent data files
4241 @cindex _DATA primary, defined
4242 @cindex DATA primary, defined
4243 @cindex Primary variable, DATA
4245 Automake supports the installation of miscellaneous data files using the
4246 @samp{DATA} family of variables.
4247 @vindex DATA
4249 @vindex data_DATA
4250 @vindex sysconf_DATA
4251 @vindex sharedstate_DATA
4252 @vindex localstate_DATA
4253 @vindex pkgdata_DATA
4255 Such data can be installed in the directories @code{datadir},
4256 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
4257 @code{pkgdatadir}.
4259 By default, data files are @emph{not} included in a distribution.  Of
4260 course, you can use the @samp{dist_} prefix to change this on a
4261 per-variable basis.
4263 Here is how Automake declares its auxiliary data files:
4265 @example
4266 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
4267 @end example
4270 @node Sources
4271 @section Built sources
4273 Because Automake's automatic dependency tracking works as a side-effect
4274 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
4275 target should not be compiled before its dependencies are made, but
4276 these dependencies are unknown until the target is first compiled.
4278 Ordinarily this is not a problem, because dependencies are distributed
4279 sources: they preexist and do not need to be built.  Suppose that
4280 @file{foo.c} includes @file{foo.h}.  When it first compiles
4281 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
4282 @file{foo.c}.  As a side-effect of this compilation @code{depcomp}
4283 records the @file{foo.h} dependency so that following invocations of
4284 @command{make} will honor it.  In these conditions, it's clear there is
4285 no problem: either @file{foo.o} doesn't exist and has to be built
4286 (regardless of the dependencies), either accurate dependencies exist and
4287 they can be used to decide whether @file{foo.o} should be rebuilt.
4289 It's a different story if @file{foo.h} doesn't exist by the first
4290 @command{make} run.  For instance there might be a rule to build
4291 @file{foo.h}.  This time @file{file.o}'s build will fail because the
4292 compiler can't find @file{foo.h}. @command{make} failed to trigger the
4293 rule to build @file{foo.h} first by lack of dependency information.
4295 @vindex BUILT_SOURCES
4296 @cindex BUILT_SOURCES, defined
4298 The @code{BUILT_SOURCES} variable is a workaround for this problem.  A
4299 source file listed in @code{BUILT_SOURCES} is made on @code{make all}
4300 or @code{make check} (or even @code{make install}) before other
4301 targets are processed.  However, such a source file is not
4302 @emph{compiled} unless explicitly requested by mentioning it in some
4303 other @samp{_SOURCES} variable.
4305 So, to conclude our introductory example, we could use
4306 @code{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
4307 any other target (including @file{foo.o}) during @code{make all} or
4308 @code{make check}.
4310 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
4311 must be created early in the build process can be listed in this
4312 variable.  Moreover, all built sources do not necessarily have to be
4313 listed in @code{BUILT_SOURCES}.  For instance a generated @file{.c} file
4314 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
4315 another source), because it's a known dependency of the associated
4316 object.
4318 It might be important to emphasize that @code{BUILT_SOURCES} is
4319 honored only by @code{make all}, @code{make check} and @code{make
4320 install}.  This means you cannot build a specific target (e.g.,
4321 @code{make foo}) in a clean tree if it depends on a built source.
4322 However it will succeed if you have run @code{make all} earlier,
4323 because accurate dependencies are already available.
4325 The next section illustrates and discusses the handling of built sources
4326 on a toy example.
4328 @menu
4329 * Built sources example::       Several ways to handle built sources.
4330 @end menu
4332 @node Built sources example
4333 @subsection Built sources example
4335 Suppose that @file{foo.c} includes @file{bindir.h}, which is
4336 installation-dependent and not distributed: it needs to be built.  Here
4337 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
4338 value of the @command{make} variable @code{bindir} (inherited from
4339 @file{configure}).
4341 We suggest several implementations below.  It's not meant to be an
4342 exhaustive listing of all ways to handle built sources, but it will give
4343 you a few ideas if you encounter this issue.
4345 @unnumberedsubsec First try
4347 This first implementation will illustrate the bootstrap issue mentioned
4348 in the previous section (@pxref{Sources}).
4350 Here is a tentative @file{Makefile.am}.
4352 @example
4353 # This won't work.
4354 bin_PROGRAMS = foo
4355 foo_SOURCES = foo.c
4356 nodist_foo_SOURCES = bindir.h
4357 CLEANFILES = bindir.h
4358 bindir.h: Makefile
4359         echo '#define bindir "$(bindir)"' >$@@
4360 @end example
4362 This setup doesn't work, because Automake doesn't know that @file{foo.c}
4363 includes @file{bindir.h}.  Remember, automatic dependency tracking works
4364 as a side-effect of compilation, so the dependencies of @file{foo.o} will
4365 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
4366 The symptom is as follows.
4368 @example
4369 % make
4370 source='foo.c' object='foo.o' libtool=no \
4371 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
4372 depmode=gcc /bin/sh ./depcomp \
4373 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
4374 foo.c:2: bindir.h: No such file or directory
4375 make: *** [foo.o] Error 1
4376 @end example
4378 @unnumberedsubsec Using @code{BUILT_SOURCES}
4380 A solution is to require @file{bindir.h} to be built before anything
4381 else.  This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
4383 @example
4384 bin_PROGRAMS = foo
4385 foo_SOURCES = foo.c
4386 BUILT_SOURCES = bindir.h
4387 CLEANFILES = bindir.h
4388 bindir.h: Makefile
4389         echo '#define bindir "$(bindir)"' >$@@
4390 @end example
4392 See how @file{bindir.h} get built first:
4394 @example
4395 % make
4396 echo '#define bindir "/usr/local/bin"' >bindir.h
4397 make  all-am
4398 make[1]: Entering directory `/home/adl/tmp'
4399 source='foo.c' object='foo.o' libtool=no \
4400 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
4401 depmode=gcc /bin/sh ./depcomp \
4402 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
4403 gcc  -g -O2   -o foo  foo.o
4404 make[1]: Leaving directory `/home/adl/tmp'
4405 @end example
4407 However, as said earlier, @code{BUILT_SOURCES} applies only to the
4408 @code{all}, @code{check}, and @code{install} targets.  It still fails
4409 if you try to run @code{make foo} explicitly:
4411 @example
4412 % make clean
4413 test -z "bindir.h" || rm -f bindir.h
4414 test -z "foo" || rm -f foo
4415 rm -f *.o
4416 % : > .deps/foo.Po # Suppress previously recorded dependencies
4417 % make foo
4418 source='foo.c' object='foo.o' libtool=no \
4419 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
4420 depmode=gcc /bin/sh ./depcomp \
4421 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
4422 foo.c:2: bindir.h: No such file or directory
4423 make: *** [foo.o] Error 1
4424 @end example
4426 @unnumberedsubsec Recording dependencies manually
4428 Usually people are happy enough with @code{BUILT_SOURCES} because they
4429 never build targets such as @code{make foo} before @code{make all}, as
4430 in the previous example.  However if this matters to you, you can
4431 avoid @code{BUILT_SOURCES} and record such dependencies explicitly in
4432 the @file{Makefile.am}.
4434 @example
4435 bin_PROGRAMS = foo
4436 foo_SOURCES = foo.c
4437 foo.$(OBJEXT): bindir.h
4438 CLEANFILES = bindir.h
4439 bindir.h: Makefile
4440         echo '#define bindir "$(bindir)"' >$@@
4441 @end example
4443 You don't have to list @emph{all} the dependencies of @code{foo.o}
4444 explicitly, only those which might need to be built.  If a dependency
4445 already exists, it will not hinder the first compilation and will be
4446 recorded by the normal dependency tracking code.  (Note that after this
4447 first compilation the dependency tracking code will also have recorded
4448 the dependency between @code{foo.o} and @code{bindir.h}; so our explicit
4449 dependency is really useful to the first build only.)
4451 Adding explicit dependencies like this can be a bit dangerous if you are
4452 not careful enough.  This is due to the way Automake tries not to
4453 overwrite your rules (it assumes you know better than it).
4454 @code{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
4455 output to build @code{foo.$(OBJEXT)}.  It happens to work in this case
4456 because Automake doesn't have to output any @code{foo.$(OBJEXT):}
4457 target: it relies on a suffix rule instead (i.e., @code{.c.$(OBJEXT):}).
4458 Always check the generated @file{Makefile.in} if you do this.
4460 @unnumberedsubsec Build @file{bindir.h} from @file{configure}
4462 It's possible to define this preprocessor macro from @file{configure},
4463 either in @file{config.h} (@pxref{Defining Directories, , Defining
4464 Directories, autoconf, The Autoconf Manual}), or by processing a
4465 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
4466 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
4467 Autoconf Manual}).
4469 At this point it should be clear that building @file{bindir.h} from
4470 @file{configure} work well for this example.  @file{bindir.h} will exist
4471 before you build any target, hence will not cause any dependency issue.
4473 The Makefile can be shrunk as follows.  We do not even have to mention
4474 @file{bindir.h}.
4476 @example
4477 bin_PROGRAMS = foo
4478 foo_SOURCES = foo.c
4479 @end example
4481 However, it's not always possible to build sources from
4482 @file{configure}, especially when these sources are generated by a tool
4483 that needs to be built first...
4485 @unnumberedsubsec Build @file{bindir.c}, not @file{bindir.h}.
4487 Another attractive idea is to define @code{bindir} as a variable or
4488 function exported from @file{bindir.o}, and build @file{bindir.c}
4489 instead of @file{bindir.h}.
4491 @example
4492 noinst_PROGRAMS = foo
4493 foo_SOURCES = foo.c bindir.h
4494 nodist_foo_SOURCES = bindir.c
4495 CLEANFILES = bindir.c
4496 bindir.c: Makefile
4497         echo 'const char bindir[] = "$(bindir)";' >$@
4498 @end example
4500 @file{bindir.h} contains just the variable's declaration and doesn't
4501 need to be built, so it won't cause any trouble.  @file{bindir.o} is
4502 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
4503 first.
4505 @unnumberedsubsec Which is best?
4507 There is no panacea, of course.  Each solution has its merits and
4508 drawbacks.
4510 You cannot use @code{BUILT_SOURCES} if the ability to run @code{make
4511 foo} on a clean tree is important to you.
4513 You won't add explicit dependencies if you are leery of overriding
4514 an Automake rule by mistake.
4516 Building files from @file{./configure} is not always possible, neither
4517 is converting @file{.h} files into @file{.c} files.
4520 @node Other GNU Tools
4521 @chapter Other GNU Tools
4523 Since Automake is primarily intended to generate @file{Makefile.in}s for
4524 use in GNU programs, it tries hard to interoperate with other GNU tools.
4526 @menu
4527 * Emacs Lisp::                  Emacs Lisp
4528 * gettext::                     Gettext
4529 * Libtool::                     Libtool
4530 * Java::                        Java
4531 * Python::                      Python
4532 @end menu
4535 @node Emacs Lisp
4536 @section Emacs Lisp
4538 @cindex _LISP primary, defined
4539 @cindex LISP primary, defined
4540 @cindex Primary variable, LISP
4542 @vindex LISP
4543 @vindex lisp_LISP
4544 @vindex noinst_LISP
4546 Automake provides some support for Emacs Lisp.  The @samp{LISP} primary
4547 is used to hold a list of @file{.el} files.  Possible prefixes for this
4548 primary are @samp{lisp_} and @samp{noinst_}.  Note that if
4549 @code{lisp_LISP} is defined, then @file{configure.ac} must run
4550 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
4552 Automake will byte-compile all Emacs Lisp source files using the Emacs
4553 found by @code{AM_PATH_LISPDIR}, if any was found.
4555 Byte-compiled Emacs Lisp files are not portable among all versions of
4556 Emacs, so it makes sense to turn this off if you expect sites to have
4557 more than one version of Emacs installed.  Furthermore, many packages
4558 don't actually benefit from byte-compilation.  Still, we recommend
4559 that you byte-compile your Emacs Lisp sources.  It is probably better
4560 for sites with strange setups to cope for themselves than to make the
4561 installation less nice for everybody else.
4563 There are two ways to avoid byte-compiling.  Historically, we have
4564 recommended the following construct.
4565 @example
4566 lisp_LISP = file1.el file2.el
4567 ELCFILES =
4568 @end example
4569 @noindent
4570 @code{ELCFILES} is an internal Automake variables that normally lists
4571 all @file{.elc} files that must be byte-compiled.  Automake defines
4572 @code{ELCFILES} automatically from @code{lisp_LISP}.  Emptying this
4573 variables explicitly prevents byte-compilation to occur.
4575 Since Automake 1.8, we now recommend using @code{lisp_DATA} instead.  As
4577 @example
4578 lisp_DATA = file1.el file2.el
4579 @end example
4581 Note that these two constructs are not equivalent.  @code{_LISP} will
4582 not install a file if Emacs is not installed, while @code{_DATA} will
4583 always install its files.
4585 @node gettext
4586 @section Gettext
4588 @cindex GNU Gettext support
4589 @cindex Gettext support
4590 @cindex Support for GNU Gettext
4592 If @code{AM_GNU_GETTEXT} is seen in @file{configure.ac}, then Automake
4593 turns on support for GNU gettext, a message catalog system for
4594 internationalization
4595 (@pxref{GNU Gettext, , , gettext, GNU gettext utilities}).
4597 The @code{gettext} support in Automake requires the addition of two
4598 subdirectories to the package, @file{intl} and @file{po}.  Automake
4599 insures that these directories exist and are mentioned in
4600 @code{SUBDIRS}.
4602 @vindex dist_lisp_LISP
4603 @vindex dist_noinst_LISP
4604 Lisp sources are not distributed by default.  You can prefix the
4605 @code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
4606 @code{dist_noinst_LISP}, to indicate that these files should be
4607 distributed.
4609 @node Libtool
4610 @section Libtool
4612 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
4613 libtool, The Libtool Manual}) with the @samp{LTLIBRARIES} primary.
4614 @xref{A Shared Library}.
4617 @node Java
4618 @section Java
4620 @cindex _JAVA primary, defined
4621 @cindex JAVA primary, defined
4622 @cindex Primary variable, JAVA
4624 Automake provides some minimal support for Java compilation with the
4625 @samp{JAVA} primary.
4627 Any @file{.java} files listed in a @samp{_JAVA} variable will be
4628 compiled with @code{JAVAC} at build time.  By default, @file{.class}
4629 files are not included in the distribution.
4631 @cindex JAVA restrictions
4632 @cindex Restrictions for JAVA
4634 Currently Automake enforces the restriction that only one @samp{_JAVA}
4635 primary can be used in a given @file{Makefile.am}.  The reason for this
4636 restriction is that, in general, it isn't possible to know which
4637 @file{.class} files were generated from which @file{.java} files -- so
4638 it would be impossible to know which files to install where.  For
4639 instance, a @file{.java} file can define multiple classes; the resulting
4640 @file{.class} file names cannot be predicted without parsing the
4641 @file{.java} file.
4643 There are a few variables which are used when compiling Java sources:
4645 @vtable @code
4646 @item JAVAC
4647 The name of the Java compiler.  This defaults to @samp{javac}.
4649 @item JAVACFLAGS
4650 The flags to pass to the compiler.  This is considered to be a user
4651 variable (@pxref{User Variables}).
4653 @item AM_JAVACFLAGS
4654 More flags to pass to the Java compiler.  This, and not
4655 @code{JAVACFLAGS}, should be used when it is necessary to put Java
4656 compiler flags into @file{Makefile.am}.
4658 @item JAVAROOT
4659 The value of this variable is passed to the @samp{-d} option to
4660 @code{javac}.  It defaults to @samp{$(top_builddir)}.
4662 @item CLASSPATH_ENV
4663 This variable is an @code{sh} expression which is used to set the
4664 @code{CLASSPATH} environment variable on the @code{javac} command line.
4665 (In the future we will probably handle class path setting differently.)
4666 @end vtable
4669 @node Python
4670 @section Python
4672 @cindex _PYTHON primary, defined
4673 @cindex PYTHON primary, defined
4674 @cindex Primary variable, PYTHON
4677 Automake provides support for Python compilation with the @samp{PYTHON}
4678 primary.
4680 Any files listed in a @samp{_PYTHON} variable will be byte-compiled with
4681 @code{py-compile} at install time.  @code{py-compile} actually creates
4682 both standard (@file{.pyc}) and byte-compiled (@file{.pyo}) versions of
4683 the source files.  Note that because byte-compilation occurs at install
4684 time, any files listed in @samp{noinst_PYTHON} will not be compiled.
4685 Python source files are included in the distribution by default.
4687 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON} which
4688 will determine some Python-related directory variables (see below).  If
4689 you have called @code{AM_PATH_PYTHON} from @file{configure.ac}, then you
4690 may use the following variables to list you Python source files in your
4691 variables: @samp{python_PYTHON}, @samp{pkgpython_PYTHON},
4692 @samp{pyexecdir_PYTHON}, @samp{pkgpyexecdir_PYTHON}, depending where you
4693 want your files installed.
4695 @code{AM_PATH_PYTHON([@var{VERSION}], [@var{ACTION-IF-FOUND}],
4696 [@var{ACTION-IF-NOT-FOUND}])} takes three optional arguments.  It will
4697 search a Python interpreter on the system.  The first argument, if
4698 present, is the minimum version of Python required for this package:
4699 @code{AM_PATH_PYTHON} will skip any Python interpreter which is older
4700 than @var{VERSION}.  If an interpreter is found and satisfies
4701 @var{VERSION}, then @var{ACTION-IF-FOUND} is run.  Otherwise,
4702 @var{ACTION-IF-NOT-FOUND} is run.
4704 If @var{ACTION-IF-NOT-FOUND} is not specified, the default is to abort
4705 configure.  This is fine when Python is an absolute requirement for the
4706 package.  Therefore if Python >= 2.2 is only @emph{optional} to the
4707 package, @code{AM_PATH_PYTHON} could be called as follows.
4709 @example
4710   AM_PATH_PYTHON(2.2,, :)
4711 @end example
4713 @code{AM_PATH_PYTHON} creates several output variables based on the
4714 Python installation found during configuration.
4716 @vtable @code
4717 @item PYTHON
4718 The name of the Python executable, or @code{:} if no suitable
4719 interpreter could be found.
4721 Assuming @var{ACTION-IF-NOT-FOUND} is used (otherwise @file{./configure}
4722 will abort if Python is absent), the value of @code{PYTHON} can be used
4723 to setup a conditional in order to disable the relevant part of a build
4724 as follows.
4726 @example
4727   AM_PATH_PYTHON(,, :)
4728   AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
4729 @end example
4732 If the @var{ACTION-IF-NOT-FOUND}
4733 is specified
4735 @item PYTHON_VERSION
4736 The Python version number, in the form @var{major}.@var{minor}
4737 (e.g. @samp{1.5}).  This is currently the value of
4738 @code{sys.version[:3]}.
4740 @item PYTHON_PREFIX
4741 The string @code{$@{prefix@}}.  This term may be used in future work
4742 which needs the contents of Python's @code{sys.prefix}, but general
4743 consensus is to always use the value from configure.
4745 @item PYTHON_EXEC_PREFIX
4746 The string @code{$@{exec_prefix@}}.  This term may be used in future work
4747 which needs the contents of Python's @code{sys.exec_prefix}, but general
4748 consensus is to always use the value from configure.
4750 @item PYTHON_PLATFORM
4751 The canonical name used by Python to describe the operating system, as
4752 given by @code{sys.platform}.  This value is sometimes needed when
4753 building Python extensions.
4755 @item pythondir
4756 The directory name for the @file{site-packages} subdirectory of the
4757 standard Python install tree.
4759 @item pkgpythondir
4760 This is is the directory under @code{pythondir} which is named after the
4761 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
4762 as a convenience.
4764 @item pyexecdir
4765 This is the directory where Python extension modules (shared libraries)
4766 should be installed.
4768 @item pkgpyexecdir
4769 This is a convenience variable which is defined as
4770 @samp{$(pyexecdir)/$(PACKAGE)}.
4771 @end vtable
4773 All these directory variables have values that start with either
4774 @code{$@{prefix@}} or @code{$@{exec_prefix@}} unexpanded.  This works
4775 fine in @file{Makefiles}, but it makes these variables hard to use in
4776 @file{configure}.  This is mandated by the GNU coding standards, so
4777 that the user can run @code{make prefix=/foo install}.  The Autoconf
4778 manual has a section with more details on this topic
4779 (@pxref{Installation Directory Variables, , Installation Directory
4780 Variables, autoconf, The Autoconf Manual}).
4783 @node Documentation
4784 @chapter Building documentation
4786 Currently Automake provides support for Texinfo and man pages.
4788 @menu
4789 * Texinfo::                     Texinfo
4790 * Man pages::                   Man pages
4791 @end menu
4794 @node Texinfo
4795 @section Texinfo
4797 @cindex _TEXINFOS primary, defined
4798 @cindex TEXINFOS primary, defined
4799 @cindex Primary variable, TEXINFOS
4800 @cindex HTML output using Texinfo
4801 @cindex PDF output using Texinfo
4802 @cindex PS output using Texinfo
4803 @cindex DVI output using Texinfo
4805 If the current directory contains Texinfo source, you must declare it
4806 with the @samp{TEXINFOS} primary.  Generally Texinfo files are converted
4807 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
4808 here.  Any Texinfo source file must end in the @file{.texi},
4809 @file{.txi}, or @file{.texinfo} extension.  We recommend @file{.texi}
4810 for new manuals.
4811 @vindex TEXINFOS
4812 @vindex info_TEXINFOS
4814 Automake generates rules to build @file{.info}, @file{.dvi}, @file{.ps},
4815 @file{.pdf} and @file{.html} files from your Texinfo sources.
4816 The @file{.info} files are built by @code{make all} and installed
4817 by @code{make install} (unless you use @code{no-installinfo}, see below).
4818 The other files can be built on request by @code{make dvi}, @code{make ps},
4819 @code{make pdf} and @code{make html}.
4821 @cindex Texinfo flag, VERSION
4822 @cindex Texinfo flag, UPDATED
4823 @cindex Texinfo flag, EDITION
4824 @cindex Texinfo flag, UPDATED-MONTH
4826 @cindex VERSION Texinfo flag
4827 @cindex UPDATED Texinfo flag
4828 @cindex EDITION Texinfo flag
4829 @cindex UPDATED-MONTH Texinfo flag
4831 @cindex mdate-sh
4833 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
4834 that file will be automatically generated.  The file @file{version.texi}
4835 defines four Texinfo flag you can reference using
4836 @code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
4837 @code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
4839 @table @code
4840 @item EDITION
4841 @itemx VERSION
4842 Both of these flags hold the version number of your program.  They are
4843 kept separate for clarity.
4845 @item UPDATED
4846 This holds the date the primary @file{.texi} file was last modified.
4848 @item UPDATED-MONTH
4849 This holds the name of the month in which the primary @file{.texi} file
4850 was last modified.
4851 @end table
4853 The @file{version.texi} support requires the @code{mdate-sh} program;
4854 this program is supplied with Automake and automatically included when
4855 @code{automake} is invoked with the @code{--add-missing} option.
4857 If you have multiple Texinfo files, and you want to use the
4858 @file{version.texi} feature, then you have to have a separate version
4859 file for each Texinfo file.  Automake will treat any include in a
4860 Texinfo file that matches @samp{vers*.texi} just as an automatically
4861 generated version file.
4863 Sometimes an info file actually depends on more than one @file{.texi}
4864 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
4865 @file{gpl.texi}.  You can tell Automake about these dependencies using
4866 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
4867 @vindex TEXINFOS
4868 @vindex _TEXINFOS
4870 @example
4871 info_TEXINFOS = hello.texi
4872 hello_TEXINFOS = gpl.texi
4873 @end example
4875 @cindex texinfo.tex
4877 By default, Automake requires the file @file{texinfo.tex} to appear in
4878 the same directory as the Texinfo source (this can be changed using the
4879 @code{TEXINFO_TEX} variable, see below).  However, if you used
4880 @code{AC_CONFIG_AUX_DIR} in @file{configure.ac} (@pxref{Input, , Finding
4881 `configure' Input, autoconf, The Autoconf Manual}), then
4882 @file{texinfo.tex} is looked for there.  Automake supplies
4883 @file{texinfo.tex} if @samp{--add-missing} is given.
4885 @opindex no-texinfo.tex
4887 The option @samp{no-texinfo.tex} can be used to eliminate the
4888 requirement for @file{texinfo.tex}.  Use of the variable
4889 @code{TEXINFO_TEX} is preferable, however, because that allows the
4890 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
4892 @cindex Rule, install-info
4893 @cindex Rule, noinstall-info
4894 @cindex Target, install-info
4895 @cindex Target, noinstall-info
4896 @cindex install-info target
4897 @cindex noinstall-info target
4899 @opindex no-installinfo
4900 @trindex install-info
4902 Automake generates an @code{install-info} rule; some people apparently
4903 use this.  By default, info pages are installed by @samp{make install}.
4904 This can be prevented via the @code{no-installinfo} option.
4906 The following variables are used by the Texinfo build rules.
4908 @vtable @code
4909 @item MAKEINFO
4910 The name of the program invoked to build @file{.info} files.  This
4911 variable is defined by Automake.  If the @code{makeinfo} program is
4912 found on the system then it will be used by default; otherwise
4913 @code{missing} will be used instead.
4915 @item MAKEINFOHTML
4916 The command invoked to build @file{.html} files.  Automake
4917 defines this to @code{$(MAKEINFO) --html}.
4919 @item MAKEINFOFLAGS
4920 User flags passed to each invocation of @code{$(MAKEINFO)} and
4921 @code{$(MAKEINFOHTML)}.  This user variable (@pxref{User Variables}) is
4922 not expected to be defined in any @file{Makefile}; it can be used by
4923 users to pass extra flags to suit their needs.
4925 @item AM_MAKEINFOFLAGS
4926 @itemx AM_MAKEINFOHTMLFLAGS
4927 Maintainer flags passed to each @code{makeinfo} invocation.  These
4928 are maintainer variables that can be overridden in @file{Makefile.am}.
4929 @code{$(AM_MAKEINFOFLAGS)} is passed to @code{makeinfo} when building
4930 @file{.info} files; and @code{$(AM_MAKEINFOHTMLFLAGS)} is used when
4931 building @file{.html} files.
4933 For instance the following setting can be used to obtain one single
4934 @file{.html} file per manual, without node separators.
4935 @example
4936 AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
4937 @end example
4939 By default, @code{$(AM_MAKEINFOHTMLFLAGS)} is set to
4940 @code{$(AM_MAKEINFOFLAGS)}.  This means that defining
4941 @code{$(AM_MAKEINFOFLAGS)} without defining
4942 @code{$(AM_MAKEINFOHTMLFLAGS)} will impact builds of both @file{.info}
4943 and @file{.html} files.
4945 @item TEXI2DVI
4946 The name of the command that converts a @file{.texi} file into a
4947 @file{.dvi} file.  This defaults to @code{texi2dvi}, a script that ships
4948 with the Texinfo package.
4950 @item TEXI2PDF
4951 The name of the command that translates a @file{.texi} file into a
4952 @file{.pdf} file.  This defaults to @code{$(TEXI2DVI) --pdf --batch}.
4954 @item DVIPS
4955 The name of the command that build a @file{.ps} file out of a
4956 @file{.dvi} file.  This defaults to @code{dvips}.
4958 @item TEXINFO_TEX
4960 If your package has Texinfo files in many directories, you can use the
4961 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
4962 @file{texinfo.tex} for your package.  The value of this variable should
4963 be the relative path from the current @file{Makefile.am} to
4964 @file{texinfo.tex}:
4966 @example
4967 TEXINFO_TEX = ../doc/texinfo.tex
4968 @end example
4969 @end vtable
4972 @node Man pages
4973 @section Man pages
4975 @cindex _MANS primary, defined
4976 @cindex MANS primary, defined
4977 @cindex Primary variable, MANS
4979 A package can also include man pages (but see the GNU standards on this
4980 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
4981 pages are declared using the @samp{MANS} primary.  Generally the
4982 @code{man_MANS} variable is used.  Man pages are automatically installed in
4983 the correct subdirectory of @code{mandir}, based on the file extension.
4984 @vindex MANS
4985 @vindex man_MANS
4987 File extensions such as @samp{.1c} are handled by looking for the valid
4988 part of the extension and using that to determine the correct
4989 subdirectory of @code{mandir}.  Valid section names are the digits
4990 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
4992 Sometimes developers prefer to name a man page something like
4993 @file{foo.man} in the source, and then rename it to have the correct
4994 suffix, e.g. @file{foo.1}, when installing the file.  Automake also
4995 supports this mode.  For a valid section named @var{SECTION}, there is a
4996 corresponding directory named @samp{man@var{SECTION}dir}, and a
4997 corresponding @samp{_MANS} variable.  Files listed in such a variable
4998 are installed in the indicated section.  If the file already has a
4999 valid suffix, then it is installed as-is; otherwise the file suffix is
5000 changed to match the section.
5002 For instance, consider this example:
5003 @example
5004 man1_MANS = rename.man thesame.1 alsothesame.1c
5005 @end example
5007 In this case, @file{rename.man} will be renamed to @file{rename.1} when
5008 installed, but the other files will keep their names.
5010 @cindex Rule, install-man
5011 @cindex Rule, noinstall-man
5012 @cindex Target, install-man
5013 @cindex Target, noinstall-man
5014 @cindex install-man target
5015 @cindex noinstall-man target
5017 @c Use @samp{make install} per documentation: (texi)code.
5018 By default, man pages are installed by @samp{make install}.  However,
5019 since the GNU project does not require man pages, many maintainers do
5020 not expend effort to keep the man pages up to date.  In these cases, the
5021 @code{no-installman} option will prevent the man pages from being
5022 installed by default.  The user can still explicitly install them via
5023 @samp{make install-man}.
5024 @opindex no-installman
5025 @trindex install-man
5027 Here is how the man pages are handled in GNU @code{cpio} (which includes
5028 both Texinfo documentation and man pages):
5030 @example
5031 man_MANS = cpio.1 mt.1
5032 EXTRA_DIST = $(man_MANS)
5033 @end example
5035 Man pages are not currently considered to be source, because it is not
5036 uncommon for man pages to be automatically generated.  Therefore they
5037 are not automatically included in the distribution.  However, this can
5038 be changed by use of the @samp{dist_} prefix.
5040 The @samp{nobase_} prefix is meaningless for man pages and is
5041 disallowed.
5044 @node Install
5045 @chapter What Gets Installed
5047 @cindex Installation support
5048 @cindex make install support
5050 @section Basics of installation
5052 Naturally, Automake handles the details of actually installing your
5053 program once it has been built.  All files named by the various
5054 primaries are automatically installed in the appropriate places when the
5055 user runs @code{make install}.
5057 A file named in a primary is installed by copying the built file into
5058 the appropriate directory.  The base name of the file is used when
5059 installing.
5061 @example
5062 bin_PROGRAMS = hello subdir/goodbye
5063 @end example
5065 In this example, both @samp{hello} and @samp{goodbye} will be installed
5066 in @code{$(bindir)}.
5068 Sometimes it is useful to avoid the basename step at install time.  For
5069 instance, you might have a number of header files in subdirectories of
5070 the source tree which are laid out precisely how you want to install
5071 them.  In this situation you can use the @samp{nobase_} prefix to
5072 suppress the base name step.  For example:
5074 @example
5075 nobase_include_HEADERS = stdio.h sys/types.h
5076 @end example
5078 Will install @file{stdio.h} in @code{$(includedir)} and @file{types.h}
5079 in @code{$(includedir)/sys}.
5081 @section The two parts of install
5083 Automake generates separate @code{install-data} and @code{install-exec}
5084 rules, in case the installer is installing on multiple machines which
5085 share directory structure---these targets allow the machine-independent
5086 parts to be installed only once.  @code{install-exec} installs
5087 platform-dependent files, and @code{install-data} installs
5088 platform-independent files.  The @code{install} target depends on both
5089 of these targets.  While Automake tries to automatically segregate
5090 objects into the correct category, the @file{Makefile.am} author is, in
5091 the end, responsible for making sure this is done correctly.
5092 @trindex install-data
5093 @trindex install-exec
5094 @trindex install
5095 @cindex Install, two parts of
5097 Variables using the standard directory prefixes @samp{data},
5098 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
5099 @samp{pkgdata}, or @samp{pkginclude} (e.g. @samp{data_DATA}) are
5100 installed by @samp{install-data}.
5102 Variables using the standard directory prefixes @samp{bin}, @samp{sbin},
5103 @samp{libexec}, @samp{sysconf}, @samp{localstate}, @samp{lib}, or
5104 @samp{pkglib} (e.g. @samp{bin_PROGRAMS}) are installed by
5105 @samp{install-exec}.
5107 Any variable using a user-defined directory prefix with @samp{exec} in
5108 the name (e.g. @samp{myexecbin_PROGRAMS} is installed by
5109 @samp{install-exec}.  All other user-defined prefixes are installed by
5110 @samp{install-data}.
5112 @section Extending installation
5114 It is possible to extend this mechanism by defining an
5115 @code{install-exec-local} or @code{install-data-local} rule.  If these
5116 rules exist, they will be run at @samp{make install} time.  These
5117 rules can do almost anything; care is required.
5118 @trindex install-exec-local
5119 @trindex install-data-local
5121 Automake also supports two install hooks, @code{install-exec-hook} and
5122 @code{install-data-hook}.  These hooks are run after all other install
5123 rules of the appropriate type, exec or data, have completed.  So, for
5124 instance, it is possible to perform post-installation modifications
5125 using an install hook.
5126 @cindex Install hook
5128 @section Staged installs
5130 @vindex DESTDIR
5131 Automake generates support for the @samp{DESTDIR} variable in all
5132 install rules.  @samp{DESTDIR} is used during the @samp{make install}
5133 step to relocate install objects into a staging area.  Each object and
5134 path is prefixed with the value of @samp{DESTDIR} before being copied
5135 into the install area.  Here is an example of typical DESTDIR usage:
5137 @example
5138 make DESTDIR=/tmp/staging install
5139 @end example
5141 This places install objects in a directory tree built under
5142 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
5143 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
5144 would install @file{/tmp/staging/gnu/bin/foo} and
5145 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
5147 This feature is commonly used to build install images and packages.  For
5148 more information, see @ref{Makefile Conventions, , , standards, The GNU
5149 Coding Standards}.
5151 Support for @samp{DESTDIR} is implemented by coding it directly into the
5152 install rules.  If your @file{Makefile.am} uses a local install rule
5153 (e.g., @code{install-exec-local}) or an install hook, then you must
5154 write that code to respect @samp{DESTDIR}.
5156 @section Rules for the user
5158 Automake also generates rules for targets @code{uninstall},
5159 @code{installdirs}, and @code{install-strip}.
5160 @trindex uninstall
5161 @trindex installdirs
5162 @trindex install-strip
5164 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
5165 There is no notion of separate uninstalls for ``exec'' and ``data'', as
5166 these features would not provide additional functionality.
5168 Note that @code{uninstall} is not meant as a replacement for a real
5169 packaging tool.
5172 @node Clean
5173 @chapter What Gets Cleaned
5175 @cindex make clean support
5177 The GNU Makefile Standards specify a number of different clean rules.
5178 See @xref{Standard Targets, , Standard Targets for Users, standards,
5179 The GNU Coding Standards}.
5181 Generally the files that can be cleaned are determined automatically by
5182 Automake.  Of course, Automake also recognizes some variables that can
5183 be defined to specify additional files to clean.  These variables are
5184 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
5185 @code{MAINTAINERCLEANFILES}.
5186 @vindex MOSTLYCLEANFILES
5187 @vindex CLEANFILES
5188 @vindex DISTCLEANFILES
5189 @vindex MAINTAINERCLEANFILES
5191 As the GNU Standards aren't always explicit as to which files should be
5192 removed by which rule, we've adopted a heuristic which we believe was
5193 first formulated by Fran@,{c}ois Pinard:
5195 @itemize @bullet
5196 @item
5197 If @code{make} built it, and it is commonly something that one would
5198 want to rebuild (for instance, a @file{.o} file), then
5199 @code{mostlyclean} should delete it.
5201 @item
5202 Otherwise, if @code{make} built it, then @code{clean} should delete it.
5204 @item
5205 If @code{configure} built it, then @code{distclean} should delete it.
5207 @item
5208 If the maintainer built it (for instance, a @file{.info} file), then
5209 @code{maintainer-clean} should delete it.  However
5210 @code{maintainer-clean} should not delete anything that needs to exist
5211 in order to run @code{./configure && make}.
5212 @end itemize
5214 We recommend that you follow this same set of heuristics in your
5215 @file{Makefile.am}.
5218 @node Dist
5219 @chapter What Goes in a Distribution
5221 @section Basics of distribution
5223 @cindex make dist
5225 The @code{dist} rule in the generated @file{Makefile.in} can be used
5226 to generate a gzip'd @code{tar} file and other flavors of archive for
5227 distribution.  The files is named based on the @samp{PACKAGE} and
5228 @samp{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
5229 (@pxref{Macros}); more precisely the gzip'd @code{tar} file is named
5230 @samp{@var{package}-@var{version}.tar.gz}.
5231 @cvindex PACKAGE
5232 @cvindex VERSION
5233 @trindex dist
5234 You can use the @code{make} variable @samp{GZIP_ENV} to control how gzip
5235 is run.  The default setting is @samp{--best}.
5237 For the most part, the files to distribute are automatically found by
5238 Automake: all source files are automatically included in a distribution,
5239 as are all @file{Makefile.am}s and @file{Makefile.in}s.  Automake also
5240 has a built-in list of commonly used files which are automatically
5241 included if they are found in the current directory (either physically,
5242 or as the target of a @file{Makefile.am} rule).  This list is printed by
5243 @samp{automake --help}.  Also, files which are read by @code{configure}
5244 (i.e. the source files corresponding to the files specified in various
5245 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
5246 automatically distributed.  Files included in @file{Makefile.am}s (using
5247 @code{include}) or in @file{configure.ac} (using @code{m4_include}), and
5248 helper scripts installed with @samp{automake --add-missing} are also
5249 distributed.
5251 @cvindex m4_include, distribution
5253 Still, sometimes there are files which must be distributed, but which
5254 are not covered in the automatic rules.  These files should be listed in
5255 the @code{EXTRA_DIST} variable.  You can mention files from
5256 subdirectories in @code{EXTRA_DIST}.
5258 You can also mention a directory in @code{EXTRA_DIST}; in this case the
5259 entire directory will be recursively copied into the distribution.
5260 Please note that this will also copy @emph{everything} in the directory,
5261 including CVS/RCS version control files.  We recommend against using
5262 this feature.
5263 @vindex EXTRA_DIST
5265 If you define @code{SUBDIRS}, Automake will recursively include the
5266 subdirectories in the distribution.  If @code{SUBDIRS} is defined
5267 conditionally (@pxref{Conditionals}), Automake will normally include all
5268 directories that could possibly appear in @code{SUBDIRS} in the
5269 distribution.  If you need to specify the set of directories
5270 conditionally, you can set the variable @code{DIST_SUBDIRS} to the exact
5271 list of subdirectories to include in the distribution (@pxref{Top level}).
5272 @vindex DIST_SUBDIRS
5275 @section Fine-grained distribution control
5277 Sometimes you need tighter control over what does @emph{not} go into the
5278 distribution; for instance you might have source files which are
5279 generated and which you do not want to distribute.  In this case
5280 Automake gives fine-grained control using the @samp{dist} and
5281 @samp{nodist} prefixes.  Any primary or @samp{_SOURCES} variable can be
5282 prefixed with @samp{dist_} to add the listed files to the distribution.
5283 Similarly, @samp{nodist_} can be used to omit the files from the
5284 distribution.
5285 @vindex dist_
5286 @vindex nodist_
5288 As an example, here is how you would cause some data to be distributed
5289 while leaving some source code out of the distribution:
5291 @example
5292 dist_data_DATA = distribute-this
5293 bin_PROGRAMS = foo
5294 nodist_foo_SOURCES = do-not-distribute.c
5295 @end example
5297 @section The dist hook
5299 @trindex dist-hook
5301 Occasionally it is useful to be able to change the distribution before
5302 it is packaged up.  If the @code{dist-hook} rule exists, it is run
5303 after the distribution directory is filled, but before the actual tar
5304 (or shar) file is created.  One way to use this is for distributing
5305 files in subdirectories for which a new @file{Makefile.am} is overkill:
5307 @example
5308 dist-hook:
5309         mkdir $(distdir)/random
5310         cp -p $(srcdir)/random/a1 $(srcdir)/random/a2 $(distdir)/random
5311 @end example
5313 Another way to to use this is for removing unnecessary files that get
5314 recursively included by specifying a directory in EXTRA_DIST:
5316 @example
5317 EXTRA_DIST = doc
5319 dist-hook:
5320         rm -rf `find $(distdir)/doc -name CVS`
5321 @end example
5323 @vindex distdir
5324 @vindex top_distdir
5325 Two variables that come handy when writing @code{dist-hook} rules are
5326 @code{$(distdir)} and @code{$(top_distdir)}.
5328 @code{$(distdir)} points to the directory where the @code{dist} rule
5329 will copy files from the current directory before creating the
5330 tarball.  If you are at the top-level directory, then @code{distdir =
5331 $(PACKAGE)-$(VERSION)}.  When used from subdirectory named
5332 @file{foo/}, then @code{distdir = ../$(PACKAGE)-$(VERSION)/foo}.
5334 @code{$(top_distdir)} always points to the root directory of the
5335 distributed tree.  At the top-level it's equal to @code{$(distdir)}.
5336 In the @file{foo/} subdirectory
5337 @code{top_distdir = ../$(PACKAGE)-$(VERSION)}.
5339 Note that when packages are nested using @code{AC_CONFIG_SUBDIRS}
5340 (@pxref{Subdirectories, AC_CONFIG_SUBDIRS, Configuring Other Packages
5341 in Subdirectories, autoconf, The Autoconf Manual}), then
5342 @code{$(distdir)} and @code{$(top_distdir)} are relative to the
5343 package where @code{make dist} was run, not to any sub-packages
5344 involved.
5346 @section Checking the distribution
5348 @cindex make distcheck
5349 @cindex make distcleancheck
5350 @vindex distcleancheck_listfiles
5351 @cindex make distuninstallcheck
5352 @vindex distuninstallcheck_listfiles
5354 Automake also generates a @code{distcheck} rule which can be of help
5355 to ensure that a given distribution will actually work.
5356 @code{distcheck} makes a distribution, then tries to do a @code{VPATH}
5357 build, run the test suite, and finally make another tarfile to ensure the
5358 distribution is self-contained.
5359 @trindex distcheck
5361 Building the package involves running @code{./configure}.  If you need
5362 to supply additional flags to @code{configure}, define them in the
5363 @code{DISTCHECK_CONFIGURE_FLAGS} variable, either in your top-level
5364 @file{Makefile.am}, or on the command line when invoking @code{make}.
5365 @vindex DISTCHECK_CONFIGURE_FLAGS
5367 If the @code{distcheck-hook} rule is defined in your
5368 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
5369 the new distribution has been unpacked, but before the unpacked copy
5370 is configured and built.  Your @code{distcheck-hook} can do almost
5371 anything, though as always caution is advised.  Generally this hook is
5372 used to check for potential distribution errors not caught by the
5373 standard mechanism.
5375 Speaking about potential distribution errors, @code{distcheck} will also
5376 ensure that the @code{distclean} rule actually removes all built
5377 files.  This is done by running @code{make distcleancheck} at the end of
5378 the @code{VPATH} build.  By default, @code{distcleancheck} will run
5379 @code{distclean} and then make sure the build tree has been emptied by
5380 running @code{$(distcleancheck_listfiles)}.  Usually this check will
5381 find generated files that you forgot to add to the @code{DISTCLEANFILES}
5382 variable (@pxref{Clean}).
5383 @trindex distcleancheck
5385 The @code{distcleancheck} behavior should be OK for most packages,
5386 otherwise you have the possibility to override the definition of
5387 either the @code{distcleancheck} rule, or the
5388 @code{$(distcleancheck_listfiles)} variable.  For instance to disable
5389 @code{distcleancheck} completely, add the following rule to your
5390 top-level @file{Makefile.am}:
5391 @vindex distcleancheck_listfiles
5393 @example
5394 distcleancheck:
5395         @@:
5396 @end example
5398 If you want @code{distcleancheck} to ignore built files which have not
5399 been cleaned because they are also part of the distribution, add the
5400 following definition instead:
5402 @example
5403 distcleancheck_listfiles = \
5404   find -type f -exec sh -c 'test -f $(srcdir)/@{@} || echo @{@}' ';'
5405 @end example
5407 The above definition is not the default because it's usually an error if
5408 your Makefiles cause some distributed files to be rebuilt when the user
5409 build the package.  (Think about the user missing the tool required to
5410 build the file; or if the required tool is built by your package,
5411 consider the cross-compilation case where it can't be run.)  There is
5412 a FAQ entry about this (@pxref{distcleancheck}), make sure you read it
5413 before playing with @code{distcleancheck_listfiles}.
5415 @code{distcheck} also checks that the @code{uninstall} rule works
5416 properly, both for ordinary and @samp{DESTDIR} builds.  It does this
5417 by invoking @code{make uninstall}, and then it checks the install tree
5418 to see if any files are left over.  This check will make sure that you
5419 correctly coded your @code{uninstall}-related rules.
5421 By default, the checking is done by the @code{distuninstallcheck} rule,
5422 and the list of files in the install tree is generated by
5423 @code{$(distuninstallcheck_listfiles}) (this is a variable whose value is
5424 a shell command to run that prints the list of files to stdout).
5426 Either of these can be overridden to modify the behavior of
5427 @code{distcheck}.  For instance, to disable this check completely, you
5428 would write:
5430 @example
5431 distuninstallcheck:
5432         @@:
5433 @end example
5435 @section The types of distributions
5437 Automake generates rules to provide archives of the project for
5438 distributions in various formats.  Their targets are:
5440 @table @asis
5441 @item @code{dist-bzip2}
5442 Generate a bzip2 tar archive of the distribution.  bzip2 archives are
5443 frequently smaller than gzipped archives.
5444 @trindex dist-bzip2
5446 @item @code{dist-gzip}
5447 Generate a gzip tar archive of the distribution.
5448 @trindex dist-gzip
5450 @item @code{dist-shar}
5451 Generate a shar archive of the distribution.
5452 @trindex dist-shar
5454 @item @code{dist-zip}
5455 Generate a zip archive of the distribution.
5456 @trindex dist-zip
5458 @item @code{dist-tarZ}
5459 Generate a compressed tar archive of
5460 the distribution.
5461 @trindex dist-tarZ
5462 @end table
5464 The rule @code{dist} (and its historical synonym @code{dist-all}) will
5465 create archives in all the enabled formats, @ref{Options}.  By
5466 default, only the @code{dist-gzip} target is hooked to @code{dist}.
5469 @node Tests
5470 @chapter Support for test suites
5472 @cindex Test suites
5473 @cindex make check
5475 Automake supports two forms of test suites.
5477 @section Simple Tests
5479 If the variable @code{TESTS} is defined, its value is taken to be a list
5480 of programs to run in order to do the testing.  The programs can either
5481 be derived objects or source objects; the generated rule will look both
5482 in @code{srcdir} and @file{.}.  Programs needing data files should look
5483 for them in @code{srcdir} (which is both an environment variable and a
5484 make variable) so they work when building in a separate directory
5485 (@pxref{Build Directories, , Build Directories , autoconf, The Autoconf
5486 Manual}), and in particular for the @code{distcheck} rule
5487 (@pxref{Dist}).
5489 @cindex Exit status 77, special interpretation
5491 The number of failures will be printed at the end of the run.  If a
5492 given test program exits with a status of 77, then its result is ignored
5493 in the final count.  This feature allows non-portable tests to be
5494 ignored in environments where they don't make sense.
5496 The variable @code{TESTS_ENVIRONMENT} can be used to set environment
5497 variables for the test run; the environment variable @code{srcdir} is
5498 set in the rule.  If all your test programs are scripts, you can also
5499 set @code{TESTS_ENVIRONMENT} to an invocation of the shell (e.g.
5500 @samp{$(SHELL) -x}); this can be useful for debugging the tests.
5501 @vindex TESTS
5502 @vindex TESTS_ENVIRONMENT
5504 @cindex Tests, expected failure
5505 @cindex Expected test failure
5507 You may define the variable @code{XFAIL_TESTS} to a list of tests
5508 (usually a subset of @code{TESTS}) that are expected to fail.  This will
5509 reverse the result of those tests.
5510 @vindex XFAIL_TESTS
5512 Automake ensures that each program listed in @code{TESTS} is built
5513 before any tests are run; you can list both source and derived programs
5514 in @code{TESTS}.  For instance, you might want to run a C program as a
5515 test.  To do this you would list its name in @code{TESTS} and also in
5516 @code{check_PROGRAMS}, and then specify it as you would any other
5517 program.
5519 @section DejaGnu Tests
5521 If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @samp{dejagnu}} appears in
5522 @code{AUTOMAKE_OPTIONS}, then a @code{dejagnu}-based test suite is
5523 assumed.  The variable @code{DEJATOOL} is a list of names which are
5524 passed, one at a time, as the @code{--tool} argument to @code{runtest}
5525 invocations; it defaults to the name of the package.
5527 The variable @code{RUNTESTDEFAULTFLAGS} holds the @code{--tool} and
5528 @code{--srcdir} flags that are passed to dejagnu by default; this can be
5529 overridden if necessary.
5530 @vindex RUNTESTDEFAULTFLAGS
5532 The variables @code{EXPECT} and @code{RUNTEST} can
5533 also be overridden to provide project-specific values.  For instance,
5534 you will need to do this if you are testing a compiler toolchain,
5535 because the default values do not take into account host and target
5536 names.
5537 @opindex dejagnu
5538 @vindex DEJATOOL
5539 @vindex EXPECT
5540 @vindex RUNTEST
5542 The contents of the variable @code{RUNTESTFLAGS} are passed to the
5543 @code{runtest} invocation.  This is considered a ``user variable''
5544 (@pxref{User Variables}).  If you need to set @code{runtest} flags in
5545 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
5546 @vindex RUNTESTFLAGS
5547 @vindex AM_RUNTESTFLAGS
5549 @cindex @file{site.exp}
5550 Automake will generate rules to create a local @file{site.exp} file,
5551 defining various variables detected by @code{./configure}.  This file
5552 is automatically read by DejaGnu.  It is OK for the user of a package
5553 to edit this file in order to tune the test suite.  However this is
5554 not the place where the test suite author should define new variables:
5555 this should be done elsewhere in the real test suite code.
5556 Especially, @file{site.exp} should not be distributed.
5558 For more information regarding DejaGnu test suites, see @xref{Top, , ,
5559 dejagnu, The DejaGnu Manual}.
5561 In either case, the testing is done via @samp{make check}.
5563 @section Install Tests
5565 The @code{installcheck} target is available to the user as a way to
5566 run any tests after the package has been installed.  You can add tests
5567 to this by writing an @code{installcheck-local} rule.
5570 @node Rebuilding
5571 @chapter Rebuilding Makefiles
5572 @cindex rebuild rules
5574 Automake generates rules to automatically rebuild @file{Makefile}s,
5575 @file{configure}, and other derived files like @file{Makefile.in}.
5577 @cvindex AM_MAINTAINER_MODE
5578 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.ac}, then
5579 these automatic rebuilding rules are only enabled in maintainer mode.
5581 @vindex ACLOCAL_AMFLAGS
5582 Sometimes you need to run @code{aclocal} with an argument like @code{-I}
5583 to tell it where to find @file{.m4} files.  Since sometimes @code{make}
5584 will automatically run @code{aclocal}, you need a way to specify these
5585 arguments.  You can do this by defining @code{ACLOCAL_AMFLAGS}; this
5586 holds arguments which are passed verbatim to @code{aclocal}.  This variable
5587 is only useful in the top-level @file{Makefile.am}.
5589 @vindex CONFIG_STATUS_DEPENDENCIES
5590 @vindex CONFIGURE_DEPENDENCIES
5591 @cindex @file{version.sh}, example
5592 @cindex @file{version.m4}, example
5594 Sometimes it is convenient to supplement the rebuild rules for
5595 @file{configure} or @file{config.status} with additional dependencies.
5596 The variables @code{CONFIGURE_DEPENDENCIES} and
5597 @code{CONFIG_STATUS_DEPENDENCIES} can be used to list these extra
5598 dependencies.  These variable should be defined in all
5599 @file{Makefile}s of the tree (because these two rebuild rules are
5600 output in all them), so it is safer and easier to @code{AC_SUBST} them
5601 from @file{configure.ac}.  For instance the following statement will
5602 cause @file{configure} to be rerun each time @file{version.sh} is
5603 changed.
5604 @example
5605 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh'])
5606 @end example
5607 @noindent
5608 Note the @code{$(top_srcdir)/} in the filename.  Since this variable
5609 is to be used in all @file{Makefile}s, its value must be sensible at
5610 any level in the build hierarchy.
5612 Beware not to mistake @code{CONFIGURE_DEPENDENCIES} for
5613 @code{CONFIG_STATUS_DEPENDENCIES}.
5615 @code{CONFIGURE_DEPENDENCIES} adds dependencies to the
5616 @file{configure} rule, whose effect is to run @code{autoconf}.  This
5617 variable should be seldom used, because @code{automake} already tracks
5618 @code{m4_include}d files.  However it can be useful when playing
5619 tricky games with @code{m4_esyscmd} or similar non-recommendable
5620 macros with side effects.
5622 @code{CONFIG_STATUS_DEPENDENCIES} adds dependencies to the
5623 @file{config.status} rule, whose effect is to run @file{configure}.
5624 This variable should therefore carry any non-standard source that may
5625 be read as a side effect of running configure, like @file{version.sh}
5626 in the example above.
5628 Speaking of @file{version.sh} scripts, we recommend against them
5629 today.  They are mainly used when the version of a package is updated
5630 automatically by a script (e.g., in daily builds).  Here is what some
5631 old-style @file{configure.ac}s may look like:
5632 @example
5633 AC_INIT
5634 . $srcdir/version.sh
5635 AM_INIT_AUTOMAKE([name], $VERSION_NUMBER)
5636 @dots{}
5637 @end example
5638 @noindent
5639 Here, @file{version.sh} is a shell fragment that sets
5640 @code{VERSION_NUMBER}.  The problem with this example is that
5641 @code{automake} cannot track dependencies (listing @file{version.sh}
5642 in @code{CONFIG_STATUS_DEPENDENCIES}, and distributing this file is up
5643 to the user), and that it uses the obsolete form of @code{AC_INIT} and
5644 @code{AM_INIT_AUTOMAKE}.  Upgrading to the new syntax is not
5645 straightforward, because shell variables are not allowed in
5646 @code{AC_INIT}'s arguments.  We recommend that @file{version.sh} be
5647 replaced by an M4 file that is included by @file{configure.ac}:
5648 @example
5649 m4_include([version.m4])
5650 AC_INIT([name], VERSION_NUMBER)
5651 AM_INIT_AUTOMAKE
5652 @dots{}
5653 @end example
5654 @noindent
5655 Here @file{version.m4} could contain something like
5656 @code{m4_define([VERSION_NUMBER], [1.2])}.  The advantage of this
5657 second form is that @code{automake} will take care of the dependencies
5658 when defining the rebuild rule, and will also distribute the file
5659 automatically.  An inconvenient is that @code{autoconf} will now be
5660 rerun each time the version number is bumped, when only
5661 @file{configure} had to be rerun in the previous setup.
5664 @node Options
5665 @chapter Changing Automake's Behavior
5667 Various features of Automake can be controlled by options in the
5668 @file{Makefile.am}.  Such options are applied on a per-@file{Makefile}
5669 basis when listed in a special @file{Makefile} variable named
5670 @code{AUTOMAKE_OPTIONS}.  They are applied globally to all processed
5671 @file{Makefiles} when listed in the first argument of
5672 @code{AM_INIT_AUTOMAKE} in @file{configure.ac}.  Currently understood
5673 options are:
5674 @vindex AUTOMAKE_OPTIONS
5676 @table @asis
5677 @item @code{gnits}
5678 @itemx @code{gnu}
5679 @itemx @code{foreign}
5680 @itemx @code{cygnus}
5681 @cindex Option, gnits
5682 @cindex Option, gnu
5683 @cindex Option, foreign
5684 @cindex Option, cygnus
5686 Set the strictness as appropriate.  The @code{gnits} option also implies
5687 @code{readme-alpha} and @code{check-news}.
5689 @item @code{ansi2knr}
5690 @itemx @code{@var{path}/ansi2knr}
5691 @cindex Option, ansi2knr
5692 Turn on automatic de-ANSI-fication.  @xref{ANSI}.  If preceded by a
5693 path, the generated @file{Makefile.in} will look in the specified
5694 directory to find the @file{ansi2knr} program.  The path should be a
5695 relative path to another directory in the same distribution (Automake
5696 currently does not check this).
5698 @item @code{check-news}
5699 @cindex Option, check-news
5700 Cause @code{make dist} to fail unless the current version number appears
5701 in the first few lines of the @file{NEWS} file.
5703 @item @code{dejagnu}
5704 @cindex Option, dejagnu
5705 Cause @code{dejagnu}-specific rules to be generated.  @xref{Tests}.
5707 @item @code{dist-bzip2}
5708 @cindex Option, dist-bzip2
5709 Hook @code{dist-bzip2} to @code{dist}.
5710 @trindex dist-bzip2
5712 @item @code{dist-shar}
5713 @cindex Option, dist-shar
5714 Hook @code{dist-shar} to @code{dist}.
5715 @trindex dist-shar
5717 @item @code{dist-zip}
5718 @cindex Option, dist-zip
5719 Hook @code{dist-zip} to @code{dist}.
5720 @trindex dist-zip
5722 @item @code{dist-tarZ}
5723 @cindex Option, dist-tarZ
5724 Hook @code{dist-tarZ} to @code{dist}.
5725 @trindex dist-tarZ
5727 @item @code{no-define}
5728 @cindex Option, no-define
5729 This options is meaningful only when passed as an argument to
5730 @code{AM_INIT_AUTOMAKE}.  It will prevent the @code{PACKAGE} and
5731 @code{VERSION} variables to be @code{AC_DEFINE}d.
5733 @item @code{no-dependencies}
5734 @cindex Option, no-dependencies
5735 This is similar to using @samp{--include-deps} on the command line, but
5736 is useful for those situations where you don't have the necessary bits
5737 to make automatic dependency tracking work @xref{Dependencies}.  In this
5738 case the effect is to effectively disable automatic dependency tracking.
5740 @item @code{no-dist}
5741 @cindex Option, no-dist
5742 Don't emit any code related to @code{dist} target.  This is useful
5743 when a package has its own method for making distributions.
5745 @item @code{no-dist-gzip}
5746 @cindex Option, no-dist-gzip
5747 Do not hook @code{dist-gzip} to @code{dist}.
5748 @trindex no-dist-gzip
5750 @item @code{no-exeext}
5751 @cindex Option, no-exeext
5752 If your @file{Makefile.am} defines a rule for target @samp{foo}, it
5753 will override a rule for a target named @samp{foo$(EXEEXT)}.  This is
5754 necessary when @code{EXEEXT} is found to be empty.  However, by
5755 default automake will generate an error for this use.  The
5756 @code{no-exeext} option will disable this error.  This is intended for
5757 use only where it is known in advance that the package will not be
5758 ported to Windows, or any other operating system using extensions on
5759 executables.
5761 @item @code{no-installinfo}
5762 @cindex Option, no-installinfo
5763 The generated @file{Makefile.in} will not cause info pages to be built
5764 or installed by default.  However, @code{info} and @code{install-info}
5765 targets will still be available.  This option is disallowed at
5766 @samp{GNU} strictness and above.
5767 @trindex info
5768 @trindex install-info
5770 @item @code{no-installman}
5771 @cindex Option, no-installman
5772 The generated @file{Makefile.in} will not cause man pages to be
5773 installed by default.  However, an @code{install-man} target will still
5774 be available for optional installation.  This option is disallowed at
5775 @samp{GNU} strictness and above.
5776 @trindex install-man
5778 @item @code{nostdinc}
5779 @cindex Option, nostdinc
5780 This option can be used to disable the standard @samp{-I} options which
5781 are ordinarily automatically provided by Automake.
5783 @item @code{no-texinfo.tex}
5784 @cindex Option, no-texinfo
5785 Don't require @file{texinfo.tex}, even if there are texinfo files in
5786 this directory.
5788 @item @code{readme-alpha}
5789 @cindex Option, readme-alpha
5790 If this release is an alpha release, and the file @file{README-alpha}
5791 exists, then it will be added to the distribution.  If this option is
5792 given, version numbers are expected to follow one of two forms.  The
5793 first form is @samp{@var{MAJOR}.@var{MINOR}.@var{ALPHA}}, where each
5794 element is a number; the final period and number should be left off for
5795 non-alpha releases.  The second form is
5796 @samp{@var{MAJOR}.@var{MINOR}@var{ALPHA}}, where @var{ALPHA} is a
5797 letter; it should be omitted for non-alpha releases.
5799 @item @code{std-options}
5800 @cindex Options, std-options
5801 @cindex make installcheck
5802 Make the @code{installcheck} rule check that installed scripts and
5803 programs support the @code{--help} and @code{--version} options.
5804 This also provides a basic check that the program's
5805 run-time dependencies are satisfied after installation.
5807 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
5808 In a few situations, programs (or scripts) have to be exempted from this
5809 test.  For instance @command{false} (from GNU sh-utils) is never
5810 successful, even for @code{--help} or @code{--version}.  You can list
5811 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
5812 Programs (not scripts) listed in this variable should be suffixed by
5813 @code{$(EXEEXT)} for the sake of Win32 or OS/2.  For instance suppose we
5814 build @code{false} as a program but @code{true.sh} as a script, and that
5815 neither of them support @code{--help} or @code{--version}:
5817 @example
5818 AUTOMAKE_OPTIONS = std-options
5819 bin_PROGRAMS = false ...
5820 bin_SCRIPTS = true.sh ...
5821 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
5822 @end example
5824 @item @code{subdir-objects}
5825 If this option is specified, then objects are placed into the
5826 subdirectory of the build directory corresponding to the subdirectory of
5827 the source file.  For instance if the source file is
5828 @file{subdir/file.cxx}, then the output file would be
5829 @file{subdir/file.o}.
5831 @item @var{version}
5832 @cindex Option, version
5833 A version number (e.g. @samp{0.30}) can be specified.  If Automake is not
5834 newer than the version specified, creation of the @file{Makefile.in}
5835 will be suppressed.
5837 @item @code{-W@var{category}} or @code{--warnings=@var{category}}
5838 @cindex Option, warnings
5839 These options behave exactly like their command-line counterpart
5840 (@pxref{Invoking Automake}).  This allows you to enable or disable some
5841 warning categories on a per-file basis.  You can also setup some warnings
5842 for your entire project; for instance try @code{AM_INIT_AUTOMAKE([-Wall])}
5843 in your @file{configure.ac}.
5845 @end table
5847 Unrecognized options are diagnosed by @code{automake}.
5849 If you want an option to apply to all the files in the tree, you can use
5850 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.ac}.
5851 @xref{Macros}.
5854 @node Miscellaneous
5855 @chapter Miscellaneous Rules
5857 There are a few rules and variables that didn't fit anywhere else.
5859 @menu
5860 * Tags::                        Interfacing to etags and mkid
5861 * Suffixes::                    Handling new file extensions
5862 * Multilibs::                   Support for multilibs.
5863 @end menu
5866 @node Tags
5867 @section Interfacing to @code{etags}
5869 @cindex TAGS support
5871 Automake will generate rules to generate @file{TAGS} files for use with
5872 GNU Emacs under some circumstances.
5874 If any C, C++ or Fortran 77 source code or headers are present, then
5875 @code{tags} and @code{TAGS} rules will be generated for the directory.
5876 @trindex tags
5878 At the topmost directory of a multi-directory package, a @code{tags}
5879 rule will be output which, when run, will generate a @file{TAGS} file
5880 that includes by reference all @file{TAGS} files from subdirectories.
5882 The @code{tags} rule will also be generated if the variable
5883 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
5884 directories which contain taggable source that @code{etags} does not
5885 understand.  The user can use the @code{ETAGSFLAGS} to pass additional
5886 flags to @code{etags}; @code{AM_ETAGSFLAGS} is also available for use
5887 in @file{Makefile.am}.
5888 @vindex ETAGS_ARGS
5889 @vindex ETAGSFLAGS
5890 @vindex AM_ETAGSFLAGS
5892 Here is how Automake generates tags for its source, and for nodes in its
5893 Texinfo file:
5895 @example
5896 ETAGS_ARGS = automake.in --lang=none \
5897  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
5898 @end example
5900 If you add filenames to @samp{ETAGS_ARGS}, you will probably also
5901 want to set @samp{TAGS_DEPENDENCIES}.  The contents of this variable
5902 are added directly to the dependencies for the @code{tags} rule.
5903 @vindex TAGS_DEPENDENCIES
5905 Automake also generates a @code{ctags} rule which can be used to
5906 build @command{vi}-style @file{tags} files.  The variable @code{CTAGS}
5907 is the name of the program to invoke (by default @samp{ctags});
5908 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
5909 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
5911 Automake will also generate an @code{ID} rule which will run
5912 @code{mkid} on the source.  This is only supported on a
5913 directory-by-directory basis.
5914 @trindex id
5916 Automake also supports the @uref{http://www.gnu.org/software/global/,
5917 GNU Global Tags program}.  The @code{GTAGS} rule runs Global Tags
5918 automatically and puts the result in the top build directory.  The
5919 variable @code{GTAGS_ARGS} holds arguments which are passed to
5920 @code{gtags}.
5921 @vindex GTAGS_ARGS
5924 @node Suffixes
5925 @section Handling new file extensions
5927 @cindex Adding new SUFFIXES
5928 @cindex SUFFIXES, adding
5929 @vindex SUFFIXES
5931 It is sometimes useful to introduce a new implicit rule to handle a file
5932 type that Automake does not know about.
5934 For instance, suppose you had a compiler which could compile @samp{.foo}
5935 files to @samp{.o} files.  You would simply define an suffix rule for
5936 your language:
5938 @example
5939 .foo.o:
5940         foocc -c -o $@@ $<
5941 @end example
5943 Then you could directly use a @samp{.foo} file in a @samp{_SOURCES}
5944 variable and expect the correct results:
5946 @example
5947 bin_PROGRAMS = doit
5948 doit_SOURCES = doit.foo
5949 @end example
5951 This was the simpler and more common case.  In other cases, you will
5952 have to help Automake to figure which extensions you are defining your
5953 suffix rule for.  This usually happens when your extensions does not
5954 start with a dot.  Then, all you have to do is to put a list of new
5955 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
5956 implicit rule.
5958 For instance the following definition prevents Automake to misinterpret
5959 @samp{.idlC.cpp:} as an attempt to transform @samp{.idlC} into
5960 @samp{.cpp}.
5962 @example
5963 SUFFIXES = .idl C.cpp
5964 .idlC.cpp:
5965         # whatever
5966 @end example
5968 As you may have noted, the @code{SUFFIXES} variable behaves like the
5969 @code{.SUFFIXES} special target of @code{make}.  You should not touch
5970 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
5971 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
5972 @code{SUFFIXES} go at the start of the generated suffixes list, followed
5973 by Automake generated suffixes not already in the list.
5975 @node Multilibs
5976 @section Support for Multilibs
5978 Automake has support for an obscure feature called multilibs.  A
5979 @dfn{multilib} is a library which is built for multiple different ABIs
5980 at a single time; each time the library is built with a different target
5981 flag combination.  This is only useful when the library is intended to
5982 be cross-compiled, and it is almost exclusively used for compiler
5983 support libraries.
5985 The multilib support is still experimental.  Only use it if you are
5986 familiar with multilibs and can debug problems you might encounter.
5989 @node Include
5990 @chapter Include
5992 @cmindex include
5993 @cindex Including Makefile fragment
5994 @cindex Makefile fragment, including
5996 Automake supports an @code{include} directive which can be used to
5997 include other @file{Makefile} fragments when @code{automake} is run.
5998 Note that these fragments are read and interpreted by @code{automake},
5999 not by @code{make}.  As with conditionals, @code{make} has no idea that
6000 @code{include} is in use.
6002 There are two forms of @code{include}:
6004 @table @code
6005 @item include $(srcdir)/file
6006 Include a fragment which is found relative to the current source
6007 directory.
6009 @item include $(top_srcdir)/file
6010 Include a fragment which is found relative to the top source directory.
6011 @end table
6013 Note that if a fragment is included inside a conditional, then the
6014 condition applies to the entire contents of that fragment.
6016 Makefile fragments included this way are always distributed because
6017 there are needed to rebuild @file{Makefile.in}.
6019 @node Conditionals
6020 @chapter Conditionals
6022 @cindex Conditionals
6024 Automake supports a simple type of conditionals.
6026 @cvindex AM_CONDITIONAL
6027 Before using a conditional, you must define it by using
6028 @code{AM_CONDITIONAL} in the @code{configure.ac} file (@pxref{Macros}).
6030 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
6031 The conditional name, @var{conditional}, should be a simple string
6032 starting with a letter and containing only letters, digits, and
6033 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
6034 which are reserved by Automake.
6036 The shell @var{condition} (suitable for use in a shell @code{if}
6037 statement) is evaluated when @code{configure} is run.  Note that you
6038 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
6039 time @code{configure} is run -- if @code{AM_CONDITIONAL} is run
6040 conditionally (e.g., in a shell @code{if} statement), then the result
6041 will confuse automake.
6042 @end defmac
6044 @cindex --enable-debug, example
6045 @cindex Example conditional --enable-debug
6046 @cindex Conditional example,  --enable-debug
6048 Conditionals typically depend upon options which the user provides to
6049 the @code{configure} script.  Here is an example of how to write a
6050 conditional which is true if the user uses the @samp{--enable-debug}
6051 option.
6053 @example
6054 AC_ARG_ENABLE(debug,
6055 [  --enable-debug    Turn on debugging],
6056 [case "$@{enableval@}" in
6057   yes) debug=true ;;
6058   no)  debug=false ;;
6059   *) AC_MSG_ERROR(bad value $@{enableval@} for --enable-debug) ;;
6060 esac],[debug=false])
6061 AM_CONDITIONAL(DEBUG, test x$debug = xtrue)
6062 @end example
6064 Here is an example of how to use that conditional in @file{Makefile.am}:
6066 @cmindex if
6067 @cmindex endif
6068 @cmindex else
6070 @example
6071 if DEBUG
6072 DBG = debug
6073 else
6074 DBG =
6075 endif
6076 noinst_PROGRAMS = $(DBG)
6077 @end example
6079 This trivial example could also be handled using EXTRA_PROGRAMS
6080 (@pxref{Conditional Programs}).
6082 You may only test a single variable in an @code{if} statement, possibly
6083 negated using @samp{!}.  The @code{else} statement may be omitted.
6084 Conditionals may be nested to any depth.  You may specify an argument to
6085 @code{else} in which case it must be the negation of the condition used
6086 for the current @code{if}.  Similarly you may specify the condition
6087 which is closed by an @code{end}:
6089 @example
6090 if DEBUG
6091 DBG = debug
6092 else !DEBUG
6093 DBG =
6094 endif !DEBUG
6095 @end example
6097 @noindent
6098 Unbalanced conditions are errors.
6100 Note that conditionals in Automake are not the same as conditionals in
6101 GNU Make.  Automake conditionals are checked at configure time by the
6102 @file{configure} script, and affect the translation from
6103 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
6104 to @file{configure} and on results that @file{configure} has discovered
6105 about the host system.  GNU Make conditionals are checked at @code{make}
6106 time, and are based on variables passed to the make program or defined
6107 in the @file{Makefile}.
6109 Automake conditionals will work with any make program.
6112 @node Gnits
6113 @chapter The effect of @code{--gnu} and @code{--gnits}
6115 @cindex --gnu, required files
6116 @cindex --gnu, complete description
6118 The @samp{--gnu} option (or @samp{gnu} in the @samp{AUTOMAKE_OPTIONS}
6119 variable) causes @code{automake} to check the following:
6121 @itemize @bullet
6122 @item
6123 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
6124 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
6125 or @file{COPYING}, are required at the topmost directory of the package.
6127 @item
6128 The options @samp{no-installman} and @samp{no-installinfo} are
6129 prohibited.
6130 @end itemize
6132 Note that this option will be extended in the future to do even more
6133 checking; it is advisable to be familiar with the precise requirements
6134 of the GNU standards.  Also, @samp{--gnu} can require certain
6135 non-standard GNU programs to exist for use by various maintainer-only
6136 rules; for instance in the future @code{pathchk} might be required for
6137 @samp{make dist}.
6139 @cindex --gnits, complete description
6141 The @samp{--gnits} option does everything that @samp{--gnu} does, and
6142 checks the following as well:
6144 @itemize @bullet
6145 @item
6146 @samp{make installcheck} will check to make sure that the @code{--help}
6147 and @code{--version} really print a usage message and a version string,
6148 respectively.  This is the @code{std-options} option (@pxref{Options}).
6150 @item
6151 @samp{make dist} will check to make sure the @file{NEWS} file has been
6152 updated to the current version.
6154 @item
6155 @samp{VERSION} is checked to make sure its format complies with Gnits
6156 standards.
6157 @c FIXME xref when standards are finished
6159 @item
6160 @cindex README-alpha
6161 If @samp{VERSION} indicates that this is an alpha release, and the file
6162 @file{README-alpha} appears in the topmost directory of a package, then
6163 it is included in the distribution.  This is done in @samp{--gnits}
6164 mode, and no other, because this mode is the only one where version
6165 number formats are constrained, and hence the only mode where Automake
6166 can automatically determine whether @file{README-alpha} should be
6167 included.
6169 @item
6170 The file @file{THANKS} is required.
6171 @end itemize
6174 @node Cygnus
6175 @chapter The effect of @code{--cygnus}
6177 @cindex Cygnus strictness
6179 Some packages, notably GNU GCC and GNU gdb, have a build environment
6180 originally written at Cygnus Support (subsequently renamed Cygnus
6181 Solutions, and then later purchased by Red Hat).  Packages with this
6182 ancestry are sometimes referred to as ``Cygnus'' trees.
6184 A Cygnus tree has slightly different rules for how a @file{Makefile.in}
6185 is to be constructed.  Passing @samp{--cygnus} to @code{automake} will
6186 cause any generated @file{Makefile.in} to comply with Cygnus rules.
6188 Here are the precise effects of @samp{--cygnus}:
6190 @itemize @bullet
6191 @item
6192 Info files are always created in the build directory, and not in the
6193 source directory.
6195 @item
6196 @file{texinfo.tex} is not required if a Texinfo source file is
6197 specified.  The assumption is that the file will be supplied, but in a
6198 place that Automake cannot find.  This assumption is an artifact of how
6199 Cygnus packages are typically bundled.
6201 @item
6202 @samp{make dist} is not supported, and the rules for it are not
6203 generated.  Cygnus-style trees use their own distribution mechanism.
6205 @item
6206 Certain tools will be searched for in the build tree as well as in the
6207 user's @samp{PATH}.  These tools are @code{runtest}, @code{expect},
6208 @code{makeinfo} and @code{texi2dvi}.
6210 @item
6211 @code{--foreign} is implied.
6213 @item
6214 The options @samp{no-installinfo} and @samp{no-dependencies} are
6215 implied.
6217 @item
6218 The macros @samp{AM_MAINTAINER_MODE} and @samp{AM_CYGWIN32} are
6219 required.
6221 @item
6222 The @code{check} target doesn't depend on @code{all}.
6223 @end itemize
6225 GNU maintainers are advised to use @samp{gnu} strictness in preference
6226 to the special Cygnus mode.  Some day, perhaps, the differences between
6227 Cygnus trees and GNU trees will disappear (for instance, as GCC is made
6228 more standards compliant).  At that time the special Cygnus mode will be
6229 removed.
6232 @node Extending
6233 @chapter When Automake Isn't Enough
6235 With some minor exceptions (like @code{_PROGRAMS} variables being
6236 rewritten to append @code{$(EXEEXT)}), the contents of a
6237 @file{Makefile.am} is copied to @file{Makefile.in} verbatim.
6239 @cindex copying semantics
6241 These copying semantics means that many problems can be worked around
6242 by simply adding some @code{make} variables and rules to
6243 @file{Makefile.am}.  Automake will ignore these additions.
6245 @cindex conflicting definitions
6246 @cindex rules, conflicting
6247 @cindex variables, conflicting
6248 @cindex definitions, conflicts
6250 Since a @file{Makefile.in} is built from data gathered from three
6251 different places (@file{Makefile.am}, @file{configure.ac}, and
6252 @command{automake} itself), it is possible to have conflicting
6253 definitions of rules or variables.  When building @file{Makefile.in}
6254 the following priorities are respected by @command{automake} to ensure
6255 the user always have the last word.  User defined variables in
6256 @file{Makefile.am} have priority over variables @code{AC_SUBST}ed from
6257 @file{configure.ac}, and @code{AC_SUBST}ed variables have priority
6258 over @command{automake}-defined variables.  As far rules are
6259 concerned, a user-defined rule overrides any
6260 @command{automake}-defined rule for the same target.
6262 @cindex overriding rules
6263 @cindex overriding semantics
6264 @cindex rules, overriding
6266 These overriding semantics make it possible to fine tune some default
6267 settings of Automake, or replace some of its rules.  Overriding
6268 Automake rules is often inadvisable, particularly in the topmost
6269 directory of a package with subdirectories.  The @code{-Woverride}
6270 option (@pxref{Invoking Automake}) comes handy to catch overridden
6271 definitions.
6273 Note that Automake does not make any difference between rules with
6274 commands and rules that only specify dependencies.  So it is not
6275 possible to append new dependencies to an @code{automake}-defined
6276 target without redefining the entire rule.
6278 @cindex -local targets
6279 @cindex local targets
6281 However, various useful targets have a @samp{-local} version you can
6282 specify in your @file{Makefile.in}.  Automake will supplement the
6283 standard target with these user-supplied targets.
6285 @trindex  all
6286 @trindex  all-local
6287 @trindex  info
6288 @trindex  info-local
6289 @trindex  dvi
6290 @trindex  dvi-local
6291 @trindex  ps
6292 @trindex  ps-local
6293 @trindex  pdf
6294 @trindex  pdf-local
6295 @trindex  html
6296 @trindex  html-local
6297 @trindex  check
6298 @trindex  check-local
6299 @trindex  install
6300 @trindex  install-data-local
6301 @trindex  install-exec
6302 @trindex  install-exec-local
6303 @trindex  uninstall
6304 @trindex  uninstall-local
6305 @trindex  mostlyclean
6306 @trindex  mostlyclean-local
6307 @trindex  clean
6308 @trindex  clean-local
6309 @trindex  distclean
6310 @trindex  distclean-local
6311 @trindex  installdirs
6312 @trindex  installdirs-local
6313 @trindex  installcheck
6314 @trindex  installcheck-local
6316 The targets that support a local version are @code{all}, @code{info},
6317 @code{dvi}, @code{ps}, @code{pdf}, @code{html}, @code{check},
6318 @code{install-data}, @code{install-exec}, @code{uninstall},
6319 @code{installdirs}, @code{installcheck} and the various @code{clean} targets
6320 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
6321 @code{maintainer-clean}).  Note that there are no
6322 @code{uninstall-exec-local} or @code{uninstall-data-local} targets; just
6323 use @code{uninstall-local}.  It doesn't make sense to uninstall just
6324 data or just executables.
6326 For instance, here is one way to install a file in @file{/etc}:
6328 @example
6329 install-data-local:
6330         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
6331 @end example
6333 @cindex -hook targets
6334 @cindex hook targets
6336 Some rule also have a way to run another rule, called a @dfn{hook},
6337 after their work is done.  The hook is named after the principal target,
6338 with @samp{-hook} appended.  The targets allowing hooks are
6339 @code{install-data}, @code{install-exec}, @code{uninstall}, @code{dist},
6340 and @code{distcheck}.
6341 @trindex install-data-hook
6342 @trindex install-exec-hook
6343 @trindex uninstall-hook
6344 @trindex dist-hook
6346 For instance, here is how to create a hard link to an installed program:
6348 @example
6349 install-exec-hook:
6350         ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
6351            $(DESTDIR)$(bindir)/proglink$(EXEEXT)
6352 @end example
6354 Although cheaper and more portable than symbolic links, hard links
6355 will not work everywhere (for instance OS/2 does not have
6356 @command{ln}).  Ideally you should fall back to @code{cp -p} when
6357 @code{ln} does not work.  An easy way, if symbolic links are
6358 acceptable to you, is to add @code{AC_PROG_LN_S} to
6359 @file{configure.ac} (@pxref{Particular Programs, , Particular Program
6360 Checks, autoconf, The Autoconf Manual}) and use @code{$(LN_S)} in
6361 @file{Makefile.am}.
6363 @cindex versioned binaries, installing
6364 @cindex installing versioned binaries
6365 @cindex LN_S example
6366 For instance, here is how you could install a versioned copy of a
6367 program using @code{$(LN_S)}:
6369 @example
6370 install-exec-hook:
6371         cd $(DESTDIR)$(bindir) && \
6372           mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
6373           $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
6374 @end example
6376 Note that we rename the program so that a new version will erase the
6377 symbolic link, not the real binary.  Also we @code{cd} into the
6378 destination directory in order to create relative links.
6380 @c FIXME should include discussion of variables you can use in these
6381 @c rules
6383 @node Distributing
6384 @chapter Distributing @file{Makefile.in}s
6386 Automake places no restrictions on the distribution of the resulting
6387 @file{Makefile.in}s.  We still encourage software authors to distribute
6388 their work under terms like those of the GPL, but doing so is not
6389 required to use Automake.
6391 Some of the files that can be automatically installed via the
6392 @code{--add-missing} switch do fall under the GPL@.  However, these also
6393 have a special exception allowing you to distribute them with your
6394 package, regardless of the licensing you choose.
6397 @node API versioning
6398 @chapter Automake API versioning
6400 New Automake releases usually include bug fixes and new features.
6401 Unfortunately they may also introduce new bugs and incompatibilities.
6402 This makes four reasons why a package may require a particular Automake
6403 version.
6405 Things get worse when maintaining a large tree of packages, each one
6406 requiring a different version of Automake.  In the past, this meant that
6407 any developer (and sometime users) had to install several versions of
6408 Automake in different places, and switch @samp{$PATH} appropriately for
6409 each package.
6411 Starting with version 1.6, Automake installs versioned binaries.  This
6412 means you can install several versions of Automake in the same
6413 @samp{$prefix}, and can select an arbitrary Automake version by running
6414 @samp{automake-1.6} or @samp{automake-1.7} without juggling with
6415 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
6416 will use @samp{automake-1.6} explicitly in their rebuild rules.
6418 Note that @samp{1.6} in @samp{automake-1.6} is Automake's API version,
6419 not Automake's version.  If a bug fix release is made, for instance
6420 Automake 1.6.1, the API version will remain 1.6.  This means that a
6421 package which work with Automake 1.6 should also work with 1.6.1; after
6422 all, this is what people expect from bug fix releases.
6424 Note that if your package relies on a feature or a bug fix introduced in
6425 a release, you can pass this version as an option to Automake to ensure
6426 older releases will not be used.  For instance, use this in your
6427 @file{configure.ac}:
6429 @example
6430   AM_INIT_AUTOMAKE(1.6.1)    dnl Require Automake 1.6.1 or better.
6431 @end example
6432 @noindent
6433 or, in a particular @file{Makefile.am}:
6435 @example
6436   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
6437 @end example
6438 @noindent
6439 Automake will print an error message if its version is
6440 older than the requested version.
6443 @heading What is in the API
6445 Automake's programming interface is not easy to define.  Basically it
6446 should include at least all @strong{documented} variables and targets
6447 that a @samp{Makefile.am} author can use, any behavior associated with
6448 them (e.g. the places where @samp{-hook}'s are run), the command line
6449 interface of @samp{automake} and @samp{aclocal}, @dots{}
6451 @heading What is not in the API
6453 Every undocumented variable, target, or command line option, is not part
6454 of the API@.  You should avoid using them, as they could change from one
6455 version to the other (even in bug fix releases, if this helps to fix a
6456 bug).
6458 If it turns out you need to use such a undocumented feature, contact
6459 @email{automake@@gnu.org} and try to get it documented and exercised by
6460 the test-suite.
6462 @node FAQ
6463 @chapter Frequently Asked Questions about Automake
6465 This chapter covers some questions that often come up on the mailing
6466 lists.
6468 @menu
6469 * CVS::                         CVS and generated files
6470 * maintainer-mode::             missing and AM_MAINTAINER_MODE
6471 * wildcards::                   Why doesn't Automake support wildcards?
6472 * distcleancheck::              Files left in build directory after distclean
6473 * renamed objects::             Why are object files sometimes renamed?
6474 @end menu
6476 @node CVS
6477 @section CVS and generated files
6479 @subsection Background: distributed generated files
6480 @cindex generated files, distributed
6481 @cindex rebuild rules
6483 Packages made with Autoconf and Automake ship with some generated
6484 files like @file{configure} or @file{Makefile.in}.  These files were
6485 generated on the developer's host and are distributed so that
6486 end-users do not have to install the maintainer tools required to
6487 rebuild them.  Other generated files like Lex scanners, Yacc parsers,
6488 or Info documentation, are usually distributed on similar grounds.
6490 Automake outputs rules in @file{Makefile}s to rebuild these files.  For
6491 instance @command{make} will run @command{autoconf} to rebuild
6492 @file{configure} whenever @file{configure.ac} is changed.  This makes
6493 development safer by ensuring a @file{configure} is never out-of-date
6494 with respect to @file{configure.ac}.
6496 As generated files shipped in packages are up-to-date, and because
6497 @command{tar} preserves times-tamps, these rebuild rules are not
6498 triggered when a user unpacks and builds a package.
6500 @subsection Background: CVS and timestamps
6501 @cindex timestamps and CVS
6502 @cindex CVS and timestamps
6504 Unless you use CVS keywords (in which case files must be updated at
6505 commit time), CVS preserves timestamp during @code{cvs commit} and
6506 @code{cvs import -d} operations.
6508 When you check out a file using @code{cvs checkout} its timestamp is
6509 set to that of the revision which is being checked out.
6511 However, during @command{cvs update}, files will have the date of the
6512 update, not the original timestamp of this revision.  This is meant to
6513 make sure that @command{make} notices sources files have been updated.
6515 This times tamp shift is troublesome when both sources and generated
6516 files are kept under CVS.  Because CVS processes files in alphabetical
6517 order, @file{configure.ac} will appear older than @file{configure}
6518 after a @command{cvs update} that updates both files, even if
6519 @file{configure} was newer than @file{configure.ac} when it was
6520 checked in.  Calling @code{make} will then trigger a spurious rebuild
6521 of @file{configure}.
6523 @subsection Living with CVS in Autoconfiscated projects
6524 @cindex CVS and generated files
6525 @cindex generated files and CVS
6527 There are basically two clans amongst maintainers: those who keep all
6528 distributed files under CVS, including generated files, and those who
6529 keep generated files @emph{out} of CVS.
6531 @subsubheading All files in CVS
6533 @itemize @bullet
6534 @item
6535 The CVS repository contains all distributed files so you know exactly
6536 what is distributed, and you can checkout any prior version entirely.
6538 @item
6539 Maintainers can see how generated files evolve (for instance you can
6540 see what happens to your @file{Makefile.in}s when you upgrade Automake
6541 and make sure they look OK).
6543 @item
6544 Users do not need the autotools to build a checkout of the project, it
6545 works just like a released tarball.
6547 @item
6548 If users use @command{cvs update} to update their copy, instead of
6549 @command{cvs checkout} to fetch a fresh one, timestamps will be
6550 inaccurate.  Some rebuild rules will be triggered and attempt to
6551 run developer tools such as @command{autoconf} or @command{automake}.
6553 Actually, calls to such tools are all wrapped into a call to the
6554 @command{missing} script discussed later (@pxref{maintainer-mode}).
6555 @command{missing} will take care of fixing the timestamps when these
6556 tools are not installed, so that the build can continue.
6558 @item
6559 In distributed development, developers are likely to have different
6560 version of the maintainer tools installed.  In this case rebuilds
6561 triggered by timestamp lossage will lead to spurious changes
6562 to generated files.  There are several solutions to this:
6564 @itemize
6565 @item
6566 All developers should use the same versions, so that the rebuilt files
6567 are identical to files in CVS.  (This starts to be difficult when each
6568 project you work on uses different versions.)
6569 @item
6570 Or people use a script to fix the timestamp after a checkout (the GCC
6571 folks have such a script).
6572 @item
6573 Or @file{configure.ac} uses @code{AM_MAINTAINER_MODE}, which will
6574 disable all these rebuild rules by default.  This is further discussed
6575 in @ref{maintainer-mode}.
6576 @end itemize
6578 @item
6579 Although we focused on spurious rebuilds, the converse can also
6580 happen.  CVS's timestamp handling can also let you think an
6581 out-of-date file is up-to-date.
6583 For instance, suppose a developer has modified @file{Makefile.am} and
6584 rebuilt @file{Makefile.in}, and then decide to do a last-minute change
6585 to @file{Makefile.am} right before checking in both files (without
6586 rebuilding @file{Makefile.in} to account for the change).
6588 This last change to @file{Makefile.am} make the copy of
6589 @file{Makefile.in} out-of-date.  Since CVS processes files
6590 alphabetically, when another developer @code{cvs update} his or her
6591 tree, @file{Makefile.in} will happen to be newer than
6592 @file{Makefile.am}.  This other developer will not see
6593 @file{Makefile.in} is out-of-date.
6595 @end itemize
6597 @subsubheading Generated files out of CVS
6599 One way to get CVS and @code{make} working peacefully is to never
6600 store generated files in CVS, i.e., do not CVS-control files which
6601 are @code{Makefile} targets (also called @emph{derived} files).
6603 This way developers are not annoyed by changes to generated files.  It
6604 does not matter if they all have different versions (assuming they are
6605 compatible, of course).  And finally, timestamps are not lost, changes
6606 to sources files can't be missed as in the
6607 @file{Makefile.am}/@file{Makefile.in} example discussed earlier.
6609 The drawback is that the CVS repository is not an exact copy of what
6610 is distributed and that users now need to install various development
6611 tools (maybe even specific versions) before they can build a checkout.
6612 But, after all, CVS's job is versioning, not distribution.
6614 Allowing developers to use different versions of their tools can also
6615 hide bugs during distributed development.  Indeed, developers will be
6616 using (hence testing) their own generated files, instead of the
6617 generated files that will be released actually.  The developer who
6618 prepares the tarball might be using a version of the tool that
6619 produces bogus output (for instance a non-portable C file), something
6620 other developers could have noticed if they weren't using their own
6621 versions of this tool.
6623 @subsection Third-party files
6624 @cindex CVS and third-party files
6625 @cindex third-party files and CVS
6627 Another class of files not discussed here (because they do not cause
6628 timestamp issues) are files which are shipped with a package, but
6629 maintained elsewhere.  For instance tools like @command{gettextize}
6630 and @command{autopoint} (from Gettext) or @command{libtoolize} (from
6631 Libtool), will install or update files in your package.
6633 These files, whether they are kept under CVS or not, raise similar
6634 concerns about version mismatch between developers' tools.  The
6635 Gettext manual has a section about this, see @ref{CVS Issues, CVS
6636 Issues, Integrating with CVS, gettext, GNU gettext tools}.
6638 @node maintainer-mode
6639 @section @command{missing} and @code{AM_MAINTAINER_MODE}
6641 @subsection @command{missing}
6642 @cindex missing, purpose
6644 The @command{missing} script is a wrapper around several maintainer
6645 tools, designed to warn users if a maintainer tool is required but
6646 missing.  Typical maintainer tools are @command{autoconf},
6647 @command{automake}, @command{bison}, etc.  Because file generated by
6648 these tools are shipped with the other sources of a package, these
6649 tools shouldn't be required during a user build and they are not
6650 checked for in @file{configure}.
6652 However, if for some reason a rebuild rule is triggered and involves a
6653 missing tool, @command{missing} will notice it and warn the user.
6654 Besides the warning, when a tool is missing, @command{missing} will
6655 attempt to fix timestamps in a way which allow the build to continue.
6656 For instance @command{missing} will touch @file{configure} if
6657 @command{autoconf} is not installed.  When all distributed files are
6658 kept under CVS, this feature of @command{missing} allows user
6659 @emph{with no maintainer tools} to build a package off CVS, bypassing
6660 any timestamp inconsistency implied by @code{cvs update}.
6662 If the required tool is installed, @command{missing} will run it and
6663 won't attempt to continue after failures.  This is correct during
6664 development: developers love fixing failures.  However, users with
6665 wrong versions of maintainer tools may get an error when the rebuild
6666 rule is spuriously triggered, halting the build.  This failure to let
6667 the build continue is one of the arguments of the
6668 @code{AM_MAINTAINER_MODE} advocates.
6670 @subsection @code{AM_MAINTAINER_MODE}
6671 @cindex AM_MAINTAINER_MODE, purpose
6672 @cvindex AM_MAINTAINER_MODE
6674 @code{AM_MAINTAINER_MODE} disables the so called "rebuild rules" by
6675 default.  If you have @code{AM_MAINTAINER_MODE} in
6676 @file{configure.ac}, and run @code{./configure && make}, then
6677 @command{make} will *never* attempt to rebuilt @file{configure},
6678 @file{Makefile.in}s, Lex or Yacc outputs, etc.  I.e., this disables
6679 build rules for files which are usually distributed and that users
6680 should normally not have to update.
6682 If you run @code{./configure --enable-maintainer-mode}, then these
6683 rebuild rules will be active.
6685 People use @code{AM_MAINTAINER_MODE} either because they do want their
6686 users (or themselves) annoyed by timestamps lossage (@pxref{CVS}), or
6687 because they simply can't stand the rebuild rules and prefer running
6688 maintainer tools explicitly.
6690 @code{AM_MAINTAINER_MODE} also allows you to disable some custom build
6691 rules conditionally.  Some developers use this feature to disable
6692 rules that need exotic tools that users may not have available.
6694 Several years ago Fran@,{c}ois Pinard pointed out several arguments
6695 against @code{AM_MAINTAINER_MODE}.  Most of them relate to insecurity.
6696 By removing dependencies you get non-dependable builds: change to
6697 sources files can have no effect on generated files and this can be
6698 very confusing when unnoticed.  He adds that security shouldn't be
6699 reserved to maintainers (what @code{--enable-maintainer-mode}
6700 suggests), on the contrary.  If one user has to modify a
6701 @file{Makefile.am}, then either @file{Makefile.in} should be updated
6702 or a warning should be output (this is what Automake uses
6703 @code{missing} for) but the last thing you want is that nothing
6704 happens and the user doesn't notice it (this is what happens when
6705 rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
6707 Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro was
6708 swayed by Fran@,{c}ois's arguments, and got rid of
6709 @code{AM_MAINTAINER_MODE} in all of his packages.
6711 Still many people continue to use @code{AM_MAINTAINER_MODE}, because
6712 it helps them working on projects where all files are kept under CVS,
6713 and because @command{missing} isn't enough if you have the wrong
6714 version of the tools.
6717 @node wildcards
6718 @section Why doesn't Automake support wildcards?
6719 @cindex wildcards
6721 Developers are lazy.  They often would like to use wildcards in
6722 @file{Makefile.am}s, so they don't need to remember they have to
6723 update @file{Makefile.am}s every time they add, delete, or rename a
6724 file.
6726 There are several objections to this:
6727 @itemize
6728 @item
6729 When using CVS (or similar) developers need to remember they have to
6730 run @code{cvs add} or @code{cvs rm} anyway.  Updating
6731 @file{Makefile.am} accordingly quickly becomes a reflex.
6733 Conversely, if your application doesn't compile
6734 because you forgot to add a file in @file{Makefile.am}, it will help
6735 you remember to @code{cvs add} it.
6737 @item
6738 Using wildcards makes easy to distribute files by mistake.  For
6739 instance some code a developer is experimenting with (a test case,
6740 say) but which should not be part of the distribution.
6742 @item
6743 Using wildcards it's easy to omit some files by mistake.  For
6744 instance one developer creates a new file, uses it at many places,
6745 but forget to commit it.  Another developer then checkout the
6746 incomplete project and is able to run `make dist' successfully,
6747 even though a file is missing.
6749 @item
6750 Listing files, you control *exactly* what you distribute.
6751 If some file that should be distributed is missing from your
6752 tree, @code{make dist} will complain.  Besides, you don't distribute
6753 more than what you listed.
6755 @item
6756 Finally it's really hard to @file{forget} adding a file to
6757 @file{Makefile.am}, because if you don't add it, it doesn't get
6758 compiled nor installed, so you can't even test it.
6759 @end itemize
6761 Still, these are philosophical objections, and as such you may disagree,
6762 or find enough value in wildcards to dismiss all of them.  Before you
6763 start writing a patch against Automake to teach it about wildcards,
6764 let's see the main technical issue: portability.
6766 Although @code{$(wildcard ...)} works with GNU @command{make}, it is
6767 not portable to other @command{make} implementations.
6769 The only way Automake could support @command{$(wildcard ...)} is by
6770 expending @command{$(wildcard ...)} when @command{automake} is run.
6771 Resulting @file{Makefile.in}s would be portable since they would
6772 list all files and not use @code{$(wildcard ...)}.  However that
6773 means developers need to remember they must run @code{automake} each
6774 time they add, delete, or rename files.
6776 Compared to editing @file{Makefile.am}, this is really little win.  Sure,
6777 it's easier and faster to type @code{automake; make} than to type
6778 @code{emacs Makefile.am; make}.  But nobody bothered enough to write a
6779 patch add support for this syntax.  Some people use scripts to
6780 generated file lists in @file{Makefile.am} or in separate
6781 @file{Makefile} fragments.
6783 Even if you don't care about portability, and are tempted to use
6784 @code{$(wildcard ...)} anyway because you target only GNU Make, you
6785 should know there are many places where Automake need to know exactly
6786 which files should be processed.  As Automake doesn't know how to
6787 expand @code{$(wildcard ...)}, you cannot use it in these places.
6788 @code{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
6789 variables as far Automake is concerned.
6791 You can get warnings about @code{$(wildcard ...}) constructs using the
6792 @code{-Wportability} flag.
6794 @node distcleancheck
6795 @section Files left in build directory after distclean
6796 @cindex distclean, diagnostic
6797 @cindex dependencies and distributed files
6798 @trindex distclean
6799 @trindex distcleancheck
6801 This is a diagnostic you might encounter while running @code{make
6802 distcheck}.
6804 As explained in @ref{Dist}, @code{make distcheck} attempts to build
6805 and check your package for errors like this one.
6807 @code{make distcheck} will perform a @code{VPATH} build of your
6808 package, and then call @code{make distclean}.  Files left in the build
6809 directory after @code{make distclean} has run are listed after this
6810 error.
6812 This diagnostic really covers two kinds of errors:
6814 @itemize @bullet
6815 @item
6816 files that are forgotten by distclean;
6817 @item
6818 distributed files that are erroneously rebuilt.
6819 @end itemize
6821 The former left-over files are not distributed, so the fix is to mark
6822 them for cleaning (@pxref{Clean}), this is obvious and doesn't deserve
6823 more explanations.
6825 The latter bug is not always easy to understand and fix, so let's
6826 proceed with an example.  Suppose our package contains a program for
6827 which we want to build a man page using @command{help2man}.  GNU
6828 @command{help2man} produces simple manual pages from the @code{--help}
6829 and @code{--version} output of other commands (@pxref{Top, , Overview,
6830 help2man, The Help2man Manual}).  Because we don't to force want our
6831 users to install @command{help2man}, we decide to distribute the
6832 generated man page using the following setup.
6834 @example
6835 # This Makefile.am is bogus.
6836 bin_PROGRAMS = foo
6837 foo_SOURCES = foo.c
6838 dist_man_MANS = foo.1
6840 foo.1: foo$(EXEEXT)
6841         help2man --output=foo.1 ./foo$(EXEEXT)
6842 @end example
6844 This will effectively distribute the man page.  However,
6845 @code{make distcheck} will fail with:
6847 @example
6848 ERROR: files left in build directory after distclean:
6849 ./foo.1
6850 @end example
6852 Why was @file{foo.1} rebuilt?  Because although distributed,
6853 @file{foo.1} depends on a non-distributed built file:
6854 @file{foo$(EXEEXT)}.  @file{foo$(EXEEXT)} is built by the user, so it
6855 will always appear to be newer than the distributed @file{foo.1}.
6857 @code{make distcheck} caught an inconsistency in our package.  Our
6858 intent was to distribute @file{foo.1} so users do not need installing
6859 @command{help2man}, however since this our rule causes this file to be
6860 always rebuilt, users @emph{do} need @command{help2man}.  Either we
6861 should ensure that @file{foo.1} is not rebuilt by users, or there is
6862 no point in distributing @file{foo.1}.
6864 More generally, the rule is that distributed files should never depend
6865 on non-distributed built files.  If you distribute something
6866 generated, distribute its sources.
6868 One way to fix the above example, while still distributing
6869 @file{foo.1} is to not depend on @file{foo$(EXEEXT)}.  For instance,
6870 assuming @command{foo --version} and @command{foo --help} do not
6871 change unless @file{foo.c} or @file{configure.ac} change, we could
6872 write the following @file{Makefile.am}:
6874 @example
6875 bin_PROGRAMS = foo
6876 foo_SOURCES = foo.c
6877 dist_man_MANS = foo.1
6879 foo.1: foo.c $(top_srcdir)/configure.ac
6880         $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
6881         help2man --output=foo.1 ./foo$(EXEEXT)
6882 @end example
6884 This way, @file{foo.1} will not get rebuilt every time
6885 @file{foo$(EXEEXT)} changes.  The @command{make} call makes sure
6886 @file{foo$(EXEEXT)} is up-to-date before @command{help2man}.  Another
6887 way to ensure this would be to use separate directories for binaries
6888 and man pages, and set @code{SUBDIRS} so that binaries are built
6889 before man pages.
6891 We could also decide not to distribute @file{foo.1}.  In
6892 this case it's fine to have @file{foo.1} dependent upon
6893 @file{foo$(EXEEXT)}, since both will have to be rebuilt.
6894 However it would be impossible to build the package in a
6895 cross-compilation, because building @file{foo.1} involves
6896 an @emph{execution} of @file{foo$(EXEEXT)}.
6898 Another context where such errors are common is when distributed files
6899 are built by tools which are built by the package.  The pattern is similar:
6901 @example
6902 distributed-file: built-tools distributed-sources
6903         build-command
6904 @end example
6906 @noindent
6907 should be changed to
6909 @example
6910 distributed-file: distributed-sources
6911         $(MAKE) $(AM_MAKEFLAGS) built-tools
6912         build-command
6913 @end example
6915 @noindent
6916 or you could choose not to distribute @file{distributed-file}, if
6917 cross-compilation does not matter.
6919 The points made through these examples are worth a summary:
6921 @cartouche
6922 @itemize
6923 @item
6924 Distributed files should never depend upon non-distributed built
6925 files.
6926 @item
6927 Distributed files should be distributed will all their dependencies.
6928 @item
6929 If a file is @emph{intended} be rebuilt by users, there is no point in
6930 distributing it.
6931 @end itemize
6932 @end cartouche
6934 @vrindex distcleancheck_listfiles
6935 For desperate cases, it's always possible to disable this check by
6936 setting @code{distcleancheck_listfiles} as documented in @ref{Dist}.
6937 Make sure you do understand the reason why @code{make distcheck}
6938 complains before you do this.  @code{distcleancheck_listfiles} is a
6939 way to @emph{hide} errors, not to fix them.  You can always do better.
6941 @node renamed objects
6942 @section Why are object files sometimes renamed?
6944 This happens when per-target compilation flags are used.  Object
6945 files need to be renamed just in case they would clash with object
6946 files compiled from the same sources, but with different flags.
6947 Consider the following example.
6949 @example
6950 bin_PROGRAMS = true false
6951 true_SOURCES = generic.c
6952 true_CPPFLAGS = -DEXIT_CODE=0
6953 false_SOURCES = generic.c
6954 false_CPPFLAGS = -DEXIT_CODE=1
6955 @end example
6956 @noindent
6957 Obviously the two programs are built from the same source, but it
6958 would be bad if they shared the same object, because @file{generic.o}
6959 cannot be built with both @code{-DEXIT_CODE=0} *and*
6960 @code{-DEXIT_CODE=1}.  Therefore @command{automake} outputs rules to
6961 build two different objects: @file{true-generic.o} and
6962 @file{false-generic.o}.
6964 @command{automake} doesn't actually look whether sources files are
6965 shared to decide if it must rename objects.  It will just rename all
6966 objects of a target as soon as it sees per-target compilation flags
6967 are used.
6969 It's OK to share object files when per-target compilation flags are not
6970 used.  For instance @file{true} and @file{false} will both use
6971 @file{version.o} in the following example.
6973 @example
6974 AM_CPPFLAGS = -DVERSION=1.0
6975 bin_PROGRAMS = true false
6976 true_SOURCES = true.c version.c
6977 false_SOURCES = false.c version.c
6978 @end example
6980 Note that the renaming of objects is also affected by the
6981 @code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
6983 @c ========================================================== Appendices
6985 @page
6986 @node Copying This Manual
6987 @appendix Copying This Manual
6989 @menu
6990 * GNU Free Documentation License::  License for copying this manual
6991 @end menu
6993 @include fdl.texi
6995 @page
6996 @node Indices
6997 @appendix Indices
6999 @menu
7000 * Macro and Variable Index::    Index of Autoconf macros and Automake variables
7001 * General Index::               General index
7002 @end menu
7004 @node Macro and Variable Index
7005 @appendixsec Macro and Variable Index
7007 @printindex vr
7009 @node General Index
7010 @appendixsec General Index
7012 @printindex cp
7015 @page
7016 @contents
7017 @bye
7019 @c  LocalWords:  texinfo setfilename settitle setchapternewpage texi direntry
7020 @c  LocalWords:  dircategory in's aclocal ifinfo titlepage Tromey vskip pt sp
7021 @c  LocalWords:  filll defcodeindex ov cv op tr syncodeindex fn cp vr ifnottex
7022 @c  LocalWords:  dir Automake's ac Dist Gnits gnits cygnus dfn Autoconf's pxref
7023 @c  LocalWords:  cindex Autoconf autoconf perl samp cvs dist trindex SUBST foo
7024 @c  LocalWords:  xs emph FIXME ref vindex pkglibdir pkgincludedir pkgdatadir mt
7025 @c  LocalWords:  pkg libdir cvindex cpio bindir sbindir rmt pax sbin zar zardir
7026 @c  LocalWords:  HTML htmldir html noinst TEXINFOS nodist nobase strudel CFLAGS
7027 @c  LocalWords:  libmumble CC YFLAGS ansi knr itemx de fication config url comp
7028 @c  LocalWords:  depcomp elisp sh mdate mkinstalldirs mkdir py tex dvi ps pdf
7029 @c  LocalWords:  ylwrap zardoz INIT gettext acinclude mv FUNCS LIBOBJS LDADD fr
7030 @c  LocalWords:  uref featureful dnl src LINGUAS es ko nl pl sl sv PROG ISC doc
7031 @c  LocalWords:  POSIX STDC fcntl FUNC ALLOCA blksize struct stat intl po chmod
7032 @c  LocalWords:  ChangeLog SUBDIRS gettextize gpl testdata getopt INTLLIBS cpp
7033 @c  LocalWords:  localedir datadir DLOCALEDIR DEXIT CPPFLAGS autoreconf opindex
7034 @c  LocalWords:  AUX var symlink deps Wno Wnone package's aclocal's distclean
7035 @c  LocalWords:  ltmain xref LIBSOURCE LIBSOURCES LIBOBJ MEMCMP vs RANLIB CXX
7036 @c  LocalWords:  LDFLAGS LIBTOOL libtool XTRA LIBS gettext's acdir APIVERSION
7037 @c  LocalWords:  dirlist noindent usr MULTILIB multilib Multilibs TIOCGWINSZ sc
7038 @c  LocalWords:  GWINSZ termios SRCDIR tarball bzip LISPDIR lispdir XEmacs CCAS
7039 @c  LocalWords:  emacsen MicroEmacs CCASFLAGS UX GCJ gcj GCJFLAGS posix DMALLOC
7040 @c  LocalWords:  dmalloc ldmalloc REGEX regex rx DEPDIR DEP DEFUN aclocaldir fi
7041 @c  LocalWords:  mymacro myothermacro AMFLAGS autopoint autogen libtoolize yum
7042 @c  LocalWords:  autoheader README MAKEFLAGS subdir Inetutils sync COND endif
7043 @c  LocalWords:  Miller's installable includedir inc pkgdata EXEEXT libexec bsd
7044 @c  LocalWords:  pkglib libexecdir prog libcpio cpio's dlopen dlpreopen linux
7045 @c  LocalWords:  subsubsection OBJEXT esac lib LTLIBRARIES liblob LIBADD AR ar
7046 @c  LocalWords:  ARFLAGS cru ing maude libgettext lo LTLIBOBJS rpath SGI PRE yy
7047 @c  LocalWords:  libmaude CCLD CXXFLAGS FFLAGS LFLAGS OBJCFLAGS RFLAGS DEFS cc
7048 @c  LocalWords:  SHORTNAME vtable srcdir nostdinc basename yxx cxx ll lxx gdb
7049 @c  LocalWords:  lexers yymaxdepth maxdepth yyparse yylex yyerror yylval lval
7050 @c  LocalWords:  yychar yydebug yypact yyr yydef def yychk chk yypgo pgo yyact
7051 @c  LocalWords:  yyexca exca yyerrflag errflag yynerrs nerrs yyps yypv pv yys
7052 @c  LocalWords:  yystate yytmp tmp yyv yyval val yylloc lloc yyreds yytoks toks
7053 @c  LocalWords:  yylhs yylen yydefred yydgoto yysindex yyrindex yygindex yyname
7054 @c  LocalWords:  yytable yycheck yyrule byacc CXXCOMPILE CXXLINK FLINK cfortran
7055 @c  LocalWords:  Catalogue preprocessable FLIBS libfoo baz JAVACFLAGS java exe
7056 @c  LocalWords:  SunOS fying basenames exeext uninstalled oldinclude kr FSF's
7057 @c  LocalWords:  pkginclude oldincludedir sysconf sharedstate localstate gcc rm
7058 @c  LocalWords:  sysconfdir sharedstatedir localstatedir preexist CLEANFILES gz
7059 @c  LocalWords:  unnumberedsubsec depfile tmpdepfile depmode const interoperate
7060 @c  LocalWords:  JAVAC javac JAVAROOT builddir CLASSPATH ENV pyc pyo pkgpython
7061 @c  LocalWords:  pyexecdir pkgpyexecdir Python's pythondir pkgpythondir txi ois
7062 @c  LocalWords:  installinfo vers MAKEINFO makeinfo MAKEINFOFLAGS noinstall rf
7063 @c  LocalWords:  mandir thesame alsothesame installman myexecbin DESTDIR Pinard
7064 @c  LocalWords:  uninstall installdirs uninstalls MOSTLYCLEANFILES mostlyclean
7065 @c  LocalWords:  DISTCLEANFILES MAINTAINERCLEANFILES gzip'd GZIP gzip shar exp
7066 @c  LocalWords:  distdir distcheck distcleancheck listfiles distuninstallcheck
7067 @c  LocalWords:  VPATH tarfile stdout XFAIL DejaGnu dejagnu DEJATOOL runtest ln
7068 @c  LocalWords:  RUNTESTDEFAULTFLAGS toolchain RUNTESTFLAGS asis readme DVIPS
7069 @c  LocalWords:  installcheck gzipped tarZ std utils etags mkid multilibbing cd
7070 @c  LocalWords:  ARGS taggable ETAGSFLAGS lang ctags CTAGSFLAGS GTAGS gtags idl
7071 @c  LocalWords:  foocc doit idlC multilibs ABIs cmindex defmac ARG enableval
7072 @c  LocalWords:  MSG xtrue DBG pathchk CYGWIN afile proglink versioned CVS's
7073 @c  LocalWords:  wildcards Autoconfiscated subsubheading autotools Meyering API
7074 @c  LocalWords:  ois's wildcard Wportability cartouche vrindex printindex Duret
7075 @c  LocalWords:  DSOMEFLAG DVERSION automake Lutz insertcopying versioning FAQ
7076 @c  LocalWords:  LTLIBOBJ Libtool's libtool's libltdl dlopening itutions libbar
7077 @c  LocalWords:  WANTEDLIBS libhello sublibraries libtop libsub dlopened Ratfor
7078 @c  LocalWords:  mymodule timestamps timestamp underquoted MAKEINFOHTMLFLAGS