* tests/instsh.test: Do not reset $ACLOCAL and $AUTOMAKE now
[automake.git] / automake.texi
blob5d2d143c992ac91209fae460f61afc8d402e2eaf
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.  This edition documents version
15 @value{VERSION}.
17 Copyright @copyright{} 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
18 2003 Free Software Foundation, Inc.
20 @quotation
21 Permission is granted to copy, distribute and/or modify this document
22 under the terms of the @acronym{GNU} Free Documentation License,
23 Version 1.1 or any later version published by the Free Software
24 Foundation; with no Invariant Sections, with the Front-Cover texts
25 being ``A @acronym{GNU} Manual,'' and with the Back-Cover Texts as in
26 (a) below.  A copy of the license is included in the section entitled
27 ``@acronym{GNU} Free Documentation License.''
29 (a) The FSF's Back-Cover Text is: ``You have freedom to copy and
30 modify this @acronym{GNU} Manual, like @acronym{GNU} software.  Copies
31 published by the Free Software Foundation raise funds for
32 @acronym{GNU} development.''
33 @end quotation
34 @end copying
36 @dircategory Software development
37 @direntry
38 * automake: (automake).         Making Makefile.in's.
39 @end direntry
41 @dircategory Individual utilities
42 @direntry
43 * aclocal: (automake)Invoking aclocal.          Generating aclocal.m4.
44 @end direntry
46 @titlepage
47 @title GNU Automake
48 @subtitle For version @value{VERSION}, @value{UPDATED}
49 @author David MacKenzie
50 @author Tom Tromey
51 @author Alexandre Duret-Lutz
52 @page
53 @vskip 0pt plus 1filll
54 @insertcopying
55 @end titlepage
57 @c Define an index of configure output variables.
58 @defcodeindex ov
59 @c Define an index of configure variables.
60 @defcodeindex cv
61 @c Define an index of options.
62 @defcodeindex op
63 @c Define an index of targets.
64 @defcodeindex tr
65 @c Define an index of commands.
66 @defcodeindex cm
68 @c Put the macros and variables into their own index.
69 @c @syncodeindex fn cp
70 @syncodeindex ov vr
71 @syncodeindex cv vr
72 @syncodeindex fn vr
74 @c Put everything else into one index (arbitrarily chosen to be the concept index).
75 @syncodeindex op cp
76 @syncodeindex tr cp
77 @syncodeindex cm cp
79 @ifnottex
80 @node Top
81 @comment  node-name,  next,  previous,  up
82 @top GNU Automake
84 This file documents the GNU Automake package.  Automake is a program
85 which creates GNU standards-compliant Makefiles from template files.
86 This edition documents version @value{VERSION}.
88 @menu
89 * Introduction::                Automake's purpose
90 * Generalities::                General ideas
91 * Examples::                    Some example packages
92 * Invoking Automake::           Creating a Makefile.in
93 * configure::                   Scanning configure.ac or configure.in
94 * Top level::                   The top-level Makefile.am
95 * Alternative::                 An alternative approach to subdirectories
96 * Rebuilding::                  Automatic rebuilding of Makefile
97 * Programs::                    Building programs and libraries
98 * Other objects::               Other derived objects
99 * Other GNU Tools::             Other GNU Tools
100 * Documentation::               Building documentation
101 * Install::                     What gets installed
102 * Clean::                       What gets cleaned
103 * Dist::                        What goes in a distribution
104 * Tests::                       Support for test suites
105 * Options::                     Changing Automake's behavior
106 * Miscellaneous::               Miscellaneous rules
107 * Include::                     Including extra files in an Automake template.
108 * Conditionals::                Conditionals
109 * Gnits::                       The effect of @code{--gnu} and @code{--gnits}
110 * Cygnus::                      The effect of @code{--cygnus}
111 * Extending::                   Extending Automake
112 * Distributing::                Distributing the Makefile.in
113 * API versioning::              About compatibility between Automake versions
114 * FAQ::                         Frequently Asked Questions
115 * Macro and Variable Index::
116 * General Index::
117 @end menu
119 @end ifnottex
122 @node Introduction
123 @chapter Introduction
125 Automake is a tool for automatically generating @file{Makefile.in}s from
126 files called @file{Makefile.am}.  Each @file{Makefile.am} is basically a
127 series of @code{make} variable definitions@footnote{These variables are
128 also called @dfn{make macros} in Make terminology, however in this
129 manual we reserve the term @dfn{macro} for Autoconf's macros.}, with
130 rules being thrown in occasionally.  The generated @file{Makefile.in}s
131 are compliant with the GNU Makefile standards.
133 @cindex GNU Makefile standards
135 The GNU Makefile Standards Document
136 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
137 is long, complicated, and subject to change.  The goal of Automake is to
138 remove the burden of Makefile maintenance from the back of the
139 individual GNU maintainer (and put it on the back of the Automake
140 maintainer).
142 The typical Automake input file is simply a series of variable definitions.
143 Each such file is processed to create a @file{Makefile.in}.  There
144 should generally be one @file{Makefile.am} per directory of a project.
146 @cindex Constraints of Automake
147 @cindex Automake constraints
149 Automake does constrain a project in certain ways; for instance it
150 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
151 autoconf, The Autoconf Manual}), and enforces certain restrictions on
152 the @file{configure.in} contents@footnote{Autoconf 2.50 promotes
153 @file{configure.ac} over @file{configure.in}.  The rest of this
154 documentation will refer to @file{configure.in} as this use is not yet
155 spread, but Automake supports @file{configure.ac} too.}.
157 @cindex Automake requirements
158 @cindex Requirements, Automake
160 Automake requires @code{perl} in order to generate the
161 @file{Makefile.in}s.  However, the distributions created by Automake are
162 fully GNU standards-compliant, and do not require @code{perl} in order
163 to be built.
165 @cindex BUGS, reporting
166 @cindex Reporting BUGS
167 @cindex E-mail, bug reports
169 Mail suggestions and bug reports for Automake to
170 @email{bug-automake@@gnu.org}.
173 @node Generalities
174 @chapter General ideas
176 The following sections cover a few basic ideas that will help you
177 understand how Automake works.
179 @menu
180 * General Operation::           General operation of Automake
181 * Strictness::                  Standards conformance checking
182 * Uniform::                     The Uniform Naming Scheme
183 * Canonicalization::            How derived variables are named
184 * User Variables::              Variables reserved for the user
185 * Auxiliary Programs::          Programs automake might require
186 @end menu
189 @node General Operation
190 @section General Operation
192 Automake works by reading a @file{Makefile.am} and generating a
193 @file{Makefile.in}.  Certain variables and targets defined in the
194 @file{Makefile.am} instruct Automake to generate more specialized code;
195 for instance, a @samp{bin_PROGRAMS} variable definition will cause targets
196 for compiling and linking programs to be generated.
198 @cindex Non-standard targets
199 @cindex cvs-dist, non-standard example
200 @trindex cvs-dist
202 The variable definitions and targets in the @file{Makefile.am} are copied
203 verbatim into the generated file.  This allows you to add arbitrary code
204 into the generated @file{Makefile.in}.  For instance the Automake
205 distribution includes a non-standard @code{cvs-dist} target, which the
206 Automake maintainer uses to make distributions from his source control
207 system.
209 @cindex GNU make extensions
211 Note that most GNU make extensions are not recognized by Automake.  Using
212 such extensions in a @file{Makefile.am} will lead to errors or confusing
213 behavior.
215 @cindex Append operator
216 A special exception is that the GNU make append operator, @samp{+=}, is
217 supported.  This operator appends its right hand argument to the variable
218 specified on the left.  Automake will translate the operator into
219 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
221 Automake tries to keep comments grouped with any adjoining targets or
222 variable definitions.
224 @cindex Make targets, overriding
225 @cindex Overriding make targets
227 A target defined in @file{Makefile.am} generally overrides any such
228 target of a similar name that would be automatically generated by
229 @code{automake}.  Although this is a supported feature, it is generally
230 best to avoid making use of it, as sometimes the generated rules are
231 very particular.
233 @cindex Variables, overriding
234 @cindex Overriding make variables
236 Similarly, a variable defined in @file{Makefile.am} or @code{AC_SUBST}'ed
237 from @file{configure.in} will override any definition of the variable that
238 @code{automake} would ordinarily create.  This feature is more often
239 useful than the ability to override a target definition.  Be warned that
240 many of the variables generated by @code{automake} are considered to be for
241 internal use only, and their names might change in future releases.
243 @cindex Recursive operation of Automake
244 @cindex Automake, recursive operation
245 @cindex Example of recursive operation
247 When examining a variable definition, Automake will recursively examine
248 variables referenced in the definition.  For example, if Automake is
249 looking at the content of @code{foo_SOURCES} in this snippet
251 @example
252 xs = a.c b.c
253 foo_SOURCES = c.c $(xs)
254 @end example
256 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
257 contents of @code{foo_SOURCES}.
259 @cindex ## (special Automake comment)
260 @cindex Special Automake comment
261 @cindex Comment, special to Automake
263 Automake also allows a form of comment which is @emph{not} copied into
264 the output; all lines beginning with @samp{##} (leading spaces allowed)
265 are completely ignored by Automake.
267 It is customary to make the first line of @file{Makefile.am} read:
269 @cindex Makefile.am, first line
270 @cindex First line of Makefile.am
272 @example
273 ## Process this file with automake to produce Makefile.in
274 @end example
276 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
277 @c I don't know quite what to say.
279 @c FIXME document customary ordering of Makefile.am here!
282 @node Strictness
283 @section Strictness
285 @cindex Non-GNU packages
287 While Automake is intended to be used by maintainers of GNU packages, it
288 does make some effort to accommodate those who wish to use it, but do
289 not want to use all the GNU conventions.
291 @cindex Strictness, defined
292 @cindex Strictness, foreign
293 @cindex foreign strictness
294 @cindex Strictness, gnu
295 @cindex gnu strictness
296 @cindex Strictness, gnits
297 @cindex gnits strictness
299 To this end, Automake supports three levels of @dfn{strictness}---the
300 strictness indicating how stringently Automake should check standards
301 conformance.
303 The valid strictness levels are:
305 @table @samp
306 @item foreign
307 Automake will check for only those things which are absolutely
308 required for proper operations.  For instance, whereas GNU standards
309 dictate the existence of a @file{NEWS} file, it will not be required in
310 this mode.  The name comes from the fact that Automake is intended to be
311 used for GNU programs; these relaxed rules are not the standard mode of
312 operation.
314 @item gnu
315 Automake will check---as much as possible---for compliance to the GNU
316 standards for packages.  This is the default.
318 @item gnits
319 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
320 standards}.  These are based on the GNU standards, but are even more
321 detailed.  Unless you are a Gnits standards contributor, it is
322 recommended that you avoid this option until such time as the Gnits
323 standard is actually published (which may never happen).
324 @end table
326 For more information on the precise implications of the strictness
327 level, see @ref{Gnits}.
329 Automake also has a special ``cygnus'' mode which is similar to
330 strictness but handled differently.  This mode is useful for packages
331 which are put into a ``Cygnus'' style tree (e.g., the GCC tree).  For
332 more information on this mode, see @ref{Cygnus}.
335 @node Uniform
336 @section The Uniform Naming Scheme
338 @cindex Uniform naming scheme
340 Automake variables generally follow a @dfn{uniform naming scheme} that
341 makes it easy to decide how programs (and other derived objects) are
342 built, and how they are installed.  This scheme also supports
343 @code{configure} time determination of what should be built.
345 @cindex _PROGRAMS primary variable
346 @cindex PROGRAMS primary variable
347 @cindex Primary variable, PROGRAMS
348 @cindex Primary variable, defined
350 At @code{make} time, certain variables are used to determine which
351 objects are to be built.  The variable names are made of several pieces
352 which are concatenated together.
354 The piece which tells automake what is being built is commonly called
355 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
356 list of programs which are to be compiled and linked.
357 @vindex PROGRAMS
359 @cindex pkglibdir, defined
360 @cindex pkgincludedir, defined
361 @cindex pkgdatadir, defined
363 @vindex pkglibdir
364 @vindex pkgincludedir
365 @vindex pkgdatadir
367 A different set of names is used to decide where the built objects
368 should be installed.  These names are prefixes to the primary which
369 indicate which standard directory should be used as the installation
370 directory.  The standard directory names are given in the GNU standards
371 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
372 Automake extends this list with @code{pkglibdir}, @code{pkgincludedir},
373 and @code{pkgdatadir}; these are the same as the non-@samp{pkg}
374 versions, but with @samp{$(PACKAGE)} appended.  For instance,
375 @code{pkglibdir} is defined as @code{$(libdir)/$(PACKAGE)}.
376 @cvindex PACKAGE, directory
378 @cindex EXTRA_, prepending
380 For each primary, there is one additional variable named by prepending
381 @samp{EXTRA_} to the primary name.  This variable is used to list
382 objects which may or may not be built, depending on what
383 @code{configure} decides.  This variable is required because Automake
384 must statically know the entire list of objects that may be built in
385 order to generate a @file{Makefile.in} that will work in all cases.
387 @cindex EXTRA_PROGRAMS, defined
388 @cindex Example, EXTRA_PROGRAMS
389 @cindex cpio example
391 For instance, @code{cpio} decides at configure time which programs are
392 built.  Some of the programs are installed in @code{bindir}, and some
393 are installed in @code{sbindir}:
395 @example
396 EXTRA_PROGRAMS = mt rmt
397 bin_PROGRAMS = cpio pax
398 sbin_PROGRAMS = $(MORE_PROGRAMS)
399 @end example
401 Defining a primary without a prefix as a variable, e.g.,
402 @code{PROGRAMS}, is an error.
404 Note that the common @samp{dir} suffix is left off when constructing the
405 variable names; thus one writes @samp{bin_PROGRAMS} and not
406 @samp{bindir_PROGRAMS}.
408 Not every sort of object can be installed in every directory.  Automake
409 will flag those attempts it finds in error.
410 Automake will also diagnose obvious misspellings in directory names.
412 @cindex Extending list of installation directories
413 @cindex Installation directories, extending list
415 Sometimes the standard directories---even as augmented by Automake---
416 are not enough.  In particular it is sometimes useful, for clarity, to
417 install objects in a subdirectory of some predefined directory.  To this
418 end, Automake allows you to extend the list of possible installation
419 directories.  A given prefix (e.g. @samp{zar}) is valid if a variable of
420 the same name with @samp{dir} appended is defined (e.g. @code{zardir}).
422 @cindex HTML support, example
424 For instance, until HTML support is part of Automake, you could use this
425 to install raw HTML documentation:
427 @example
428 htmldir = $(prefix)/html
429 html_DATA = automake.html
430 @end example
432 @cindex noinst primary prefix, definition
434 The special prefix @samp{noinst} indicates that the objects in question
435 should be built but not installed at all.  This is usually used for
436 objects required to build the rest of your package, for instance static
437 libraries (@pxref{A Library}), or helper scripts.
439 @cindex check primary prefix, definition
441 The special prefix @samp{check} indicates that the objects in question
442 should not be built until the @code{make check} command is run.  Those
443 objects are not installed either.
445 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
446 @samp{LISP}, @samp{PYTHON}, @samp{JAVA}, @samp{SCRIPTS}, @samp{DATA},
447 @samp{HEADERS}, @samp{MANS}, and @samp{TEXINFOS}.
448 @vindex PROGRAMS
449 @vindex LIBRARIES
450 @vindex LISP
451 @vindex PYTHON
452 @vindex JAVA
453 @vindex SCRIPTS
454 @vindex DATA
455 @vindex HEADERS
456 @vindex MANS
457 @vindex TEXINFOS
459 Some primaries also allow additional prefixes which control other
460 aspects of @code{automake}'s behavior.  The currently defined prefixes
461 are @samp{dist_}, @samp{nodist_}, and @samp{nobase_}.  These prefixes
462 are explained later (@pxref{Program and Library Variables}).
465 @node Canonicalization
466 @section How derived variables are named
468 @cindex canonicalizing Automake variables
470 Sometimes a Makefile variable name is derived from some text the
471 maintainer supplies.  For instance, a program name listed in
472 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
473 variable.  In cases like this, Automake canonicalizes the text, so that
474 program names and the like do not have to follow Makefile variable naming
475 rules.  All characters in the name except for letters, numbers, the
476 strudel (@@), and the underscore are turned into underscores when making
477 variable references.
479 For example, if your program is named @code{sniff-glue}, the derived
480 variable name would be @code{sniff_glue_SOURCES}, not
481 @code{sniff-glue_SOURCES}.  Similarly the sources for a library named
482 @code{libmumble++.a} should be listed in the
483 @code{libmumble___a_SOURCES} variable.
485 The strudel is an addition, to make the use of Autoconf substitutions in
486 variable names less obfuscating.
489 @node User Variables
490 @section Variables reserved for the user
492 @cindex variables, reserved for the user
493 @cindex user variables
495 Some @code{Makefile} variables are reserved by the GNU Coding Standards
496 for the use of the ``user'' -- the person building the package.  For
497 instance, @code{CFLAGS} is one such variable.
499 Sometimes package developers are tempted to set user variables such as
500 @code{CFLAGS} because it appears to make their job easier -- they don't
501 have to introduce a second variable into every target.
503 However, the package itself should never set a user variable,
504 particularly not to include switches which are required for proper
505 compilation of the package.  Since these variables are documented as
506 being for the package builder, that person rightfully expects to be able
507 to override any of these variables at build time.
509 To get around this problem, automake introduces an automake-specific
510 shadow variable for each user flag variable.  (Shadow variables are not
511 introduced for variables like @code{CC}, where they would make no
512 sense.)  The shadow variable is named by prepending @samp{AM_} to the
513 user variable's name.  For instance, the shadow variable for
514 @code{YFLAGS} is @code{AM_YFLAGS}.
517 @node Auxiliary Programs
518 @section Programs automake might require
520 @cindex Programs, auxiliary
521 @cindex Auxiliary programs
523 Automake sometimes requires helper programs so that the generated
524 @file{Makefile} can do its work properly.  There are a fairly large
525 number of them, and we list them here.
527 @table @code
528 @item ansi2knr.c
529 @itemx ansi2knr.1
530 These two files are used by the automatic de-ANSI-fication support
531 (@pxref{ANSI}).
533 @item compile
534 This is a wrapper for compilers which don't accept both @samp{-c} and
535 @samp{-o} at the same time.  It is only used when absolutely required.
536 Such compilers are rare.
538 @item config.guess
539 @itemx config.sub
540 These programs compute the canonical triplets for the given build, host,
541 or target architecture.  These programs are updated regularly to support
542 new architectures and fix probes broken by changes in new kernel
543 versions.  You are encouraged to fetch the latest versions of these
544 files from @url{ftp://ftp.gnu.org/gnu/config/} before making a release.
546 @item depcomp
547 This program understands how to run a compiler so that it will generate
548 not only the desired output but also dependency information which is
549 then used by the automatic dependency tracking feature.
551 @item elisp-comp
552 This program is used to byte-compile Emacs Lisp code.
554 @item install-sh
555 This is a replacement for the @code{install} program which works on
556 platforms where @code{install} is unavailable or unusable.
558 @item mdate-sh
559 This script is used to generate a @file{version.texi} file.  It examines
560 a file and prints some date information about it.
562 @item missing
563 This wraps a number of programs which are typically only required by
564 maintainers.  If the program in question doesn't exist, @code{missing}
565 prints an informative warning and attempts to fix things so that the
566 build can continue.
568 @item mkinstalldirs
569 This works around the fact that @code{mkdir -p} is not portable.
571 @item py-compile
572 This is used to byte-compile Python scripts.
574 @item texinfo.tex
575 Not a program, this file is required for @code{make dvi}, @code{make ps}
576 and @code{make pdf} to work when Texinfo sources are in the package.
578 @item ylwrap
579 This program wraps @code{lex} and @code{yacc} and ensures that, for
580 instance, multiple @code{yacc} instances can be invoked in a single
581 directory in parallel.
583 @end table
586 @node Examples
587 @chapter Some example packages
589 @menu
590 * Complete::                    A simple example, start to finish
591 * Hello::                       A classic program
592 * true::                        Building true and false
593 @end menu
596 @node Complete
597 @section A simple example, start to finish
599 @cindex Complete example
601 Let's suppose you just finished writing @code{zardoz}, a program to make
602 your head float from vortex to vortex.  You've been using Autoconf to
603 provide a portability framework, but your @file{Makefile.in}s have been
604 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
606 @cindex AM_INIT_AUTOMAKE, example use
608 The first step is to update your @file{configure.in} to include the
609 commands that @code{automake} needs.  The way to do this is to add an
610 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
612 @example
613 AC_INIT(zardoz, 1.0)
614 AM_INIT_AUTOMAKE
615 @dots{}
616 @end example
618 Since your program doesn't have any complicating factors (e.g., it
619 doesn't use @code{gettext}, it doesn't want to build a shared library),
620 you're done with this part.  That was easy!
622 @cindex aclocal program, introduction
623 @cindex aclocal.m4, preexisting
624 @cindex acinclude.m4, defined
626 Now you must regenerate @file{configure}.  But to do that, you'll need
627 to tell @code{autoconf} how to find the new macro you've used.  The
628 easiest way to do this is to use the @code{aclocal} program to generate
629 your @file{aclocal.m4} for you.  But wait@dots{} maybe you already have an
630 @file{aclocal.m4}, because you had to write some hairy macros for your
631 program.  The @code{aclocal} program lets you put your own macros into
632 @file{acinclude.m4}, so simply rename and then run:
634 @example
635 mv aclocal.m4 acinclude.m4
636 aclocal
637 autoconf
638 @end example
640 @cindex zardoz example
642 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
643 Since @code{zardoz} is a user program, you want to install it where the
644 rest of the user programs go: @code{bindir}.  Additionally,
645 @code{zardoz} has some Texinfo documentation.  Your @file{configure.in}
646 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
647 @samp{$(LIBOBJS)}.  So here's what you'd write:
649 @example
650 bin_PROGRAMS = zardoz
651 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
652 zardoz_LDADD = $(LIBOBJS)
654 info_TEXINFOS = zardoz.texi
655 @end example
657 Now you can run @code{automake --add-missing} to generate your
658 @file{Makefile.in} and grab any auxiliary files you might need, and
659 you're done!
662 @node Hello
663 @section A classic program
665 @cindex Example, GNU Hello
666 @cindex Hello example
667 @cindex GNU Hello, example
669 @uref{ftp://prep.ai.mit.edu/pub/gnu/hello-1.3.tar.gz, GNU hello} is
670 renowned for its classic simplicity and versatility.  This section shows
671 how Automake could be used with the GNU Hello package.  The examples
672 below are from the latest beta version of GNU Hello, but with all of the
673 maintainer-only code stripped out, as well as all copyright comments.
675 Of course, GNU Hello is somewhat more featureful than your traditional
676 two-liner.  GNU Hello is internationalized, does option processing, and
677 has a manual and a test suite.
679 @cindex configure.in, from GNU Hello
680 @cindex GNU Hello, configure.in
681 @cindex Hello, configure.in
683 Here is the @file{configure.in} from GNU Hello.
684 @strong{Please note:} The calls to @code{AC_INIT} and @code{AM_INIT_AUTOMAKE}
685 in this example use a deprecated syntax.  For the current approach,
686 see the description of @code{AM_INIT_AUTOMAKE} in @ref{Public macros}.
688 @c FIXME: This definitely requires an update, e.g. to GNU Hello 2.1.1.
690 @example
691 dnl Process this file with autoconf to produce a configure script.
692 AC_INIT(src/hello.c)
693 AM_INIT_AUTOMAKE(hello, 1.3.11)
694 AM_CONFIG_HEADER(config.h)
696 dnl Set of available languages.
697 ALL_LINGUAS="de fr es ko nl no pl pt sl sv"
699 dnl Checks for programs.
700 AC_PROG_CC
701 AC_ISC_POSIX
703 dnl Checks for libraries.
705 dnl Checks for header files.
706 AC_STDC_HEADERS
707 AC_HAVE_HEADERS(string.h fcntl.h sys/file.h sys/param.h)
709 dnl Checks for library functions.
710 AC_FUNC_ALLOCA
712 dnl Check for st_blksize in struct stat
713 AC_ST_BLKSIZE
715 dnl internationalization macros
716 AM_GNU_GETTEXT
717 AC_OUTPUT([Makefile doc/Makefile intl/Makefile po/Makefile.in \
718            src/Makefile tests/Makefile tests/hello],
719    [chmod +x tests/hello])
720 @end example
722 The @samp{AM_} macros are provided by Automake (or the Gettext library);
723 the rest are standard Autoconf macros.
726 The top-level @file{Makefile.am}:
728 @example
729 EXTRA_DIST = BUGS ChangeLog.O
730 SUBDIRS = doc intl po src tests
731 @end example
733 As you can see, all the work here is really done in subdirectories.
735 The @file{po} and @file{intl} directories are automatically generated
736 using @code{gettextize}; they will not be discussed here.
738 @cindex Texinfo file handling example
739 @cindex Example, handling Texinfo files
741 In @file{doc/Makefile.am} we see:
743 @example
744 info_TEXINFOS = hello.texi
745 hello_TEXINFOS = gpl.texi
746 @end example
748 This is sufficient to build, install, and distribute the GNU Hello
749 manual.
751 @cindex Regression test example
752 @cindex Example, regression test
754 Here is @file{tests/Makefile.am}:
756 @example
757 TESTS = hello
758 EXTRA_DIST = hello.in testdata
759 @end example
761 The script @file{hello} is generated by @code{configure}, and is the
762 only test case.  @code{make check} will run this test.
764 @cindex INCLUDES, example usage
766 Last we have @file{src/Makefile.am}, where all the real work is done:
767 @c FIXME: As all the Hello World excerpts in this manual, this
768 @c shows deprecated features (here: $(INCLUDES)).
770 @example
771 bin_PROGRAMS = hello
772 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
773 hello_LDADD = $(INTLLIBS) $(ALLOCA)
774 localedir = $(datadir)/locale
775 INCLUDES = -I../intl -DLOCALEDIR=\"$(localedir)\"
776 @end example
779 @node true
780 @section Building true and false
782 @cindex Example, false and true
783 @cindex false Example
784 @cindex true Example
786 Here is another, trickier example.  It shows how to generate two
787 programs (@code{true} and @code{false}) from the same source file
788 (@file{true.c}).  The difficult part is that each compilation of
789 @file{true.c} requires different @code{cpp} flags.
791 @example
792 bin_PROGRAMS = true false
793 false_SOURCES =
794 false_LDADD = false.o
796 true.o: true.c
797         $(COMPILE) -DEXIT_CODE=0 -c true.c
799 false.o: true.c
800         $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
801 @end example
803 Note that there is no @code{true_SOURCES} definition.  Automake will
804 implicitly assume that there is a source file named @file{true.c}, and
805 define rules to compile @file{true.o} and link @file{true}.  The
806 @code{true.o: true.c} rule supplied by the above @file{Makefile.am},
807 will override the Automake generated rule to build @file{true.o}.
809 @code{false_SOURCES} is defined to be empty---that way no implicit value
810 is substituted.  Because we have not listed the source of
811 @file{false}, we have to tell Automake how to link the program.  This is
812 the purpose of the @code{false_LDADD} line.  A @code{false_DEPENDENCIES}
813 variable, holding the dependencies of the @file{false} target will be
814 automatically generated by Automake from the content of
815 @code{false_LDADD}.
817 The above rules won't work if your compiler doesn't accept both
818 @samp{-c} and @samp{-o}.  The simplest fix for this is to introduce a
819 bogus dependency (to avoid problems with a parallel @code{make}):
821 @example
822 true.o: true.c false.o
823         $(COMPILE) -DEXIT_CODE=0 -c true.c
825 false.o: true.c
826         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
827 @end example
829 Also, these explicit rules do not work if the de-ANSI-fication feature
830 is used (@pxref{ANSI}).  Supporting de-ANSI-fication requires a little
831 more work:
833 @example
834 true._o: true._c false.o
835         $(COMPILE) -DEXIT_CODE=0 -c true.c
837 false._o: true._c
838         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true._o false.o
839 @end example
841 As it turns out, there is also a much easier way to do this same task.
842 Some of the above techniques are useful enough that we've kept the
843 example in the manual.  However if you were to build @code{true} and
844 @code{false} in real life, you would probably use per-program
845 compilation flags, like so:
847 @example
848 bin_PROGRAMS = false true
850 false_SOURCES = true.c
851 false_CPPFLAGS = -DEXIT_CODE=1
853 true_SOURCES = true.c
854 true_CPPFLAGS = -DEXIT_CODE=0
855 @end example
857 In this case Automake will cause @file{true.c} to be compiled twice,
858 with different flags.  De-ANSI-fication will work automatically.  In
859 this instance, the names of the object files would be chosen by
860 automake; they would be @file{false-true.o} and @file{true-true.o}.
861 (The name of the object files rarely matters.)
864 @node Invoking Automake
865 @chapter Creating a @file{Makefile.in}
867 @cindex Multiple configure.in files
868 @cindex Invoking Automake
869 @cindex Automake, invoking
871 To create all the @file{Makefile.in}s for a package, run the
872 @code{automake} program in the top level directory, with no arguments.
873 @code{automake} will automatically find each appropriate
874 @file{Makefile.am} (by scanning @file{configure.in}; @pxref{configure})
875 and generate the corresponding @file{Makefile.in}.  Note that
876 @code{automake} has a rather simplistic view of what constitutes a
877 package; it assumes that a package has only one @file{configure.in}, at
878 the top.  If your package has multiple @file{configure.in}s, then you
879 must run @code{automake} in each directory holding a
880 @file{configure.in}.  (Alternatively, you may rely on Autoconf's
881 @code{autoreconf}, which is able to recurse your package tree and run
882 @code{automake} where appropriate.)
884 You can optionally give @code{automake} an argument; @file{.am} is
885 appended to the argument and the result is used as the name of the input
886 file.  This feature is generally only used to automatically rebuild an
887 out-of-date @file{Makefile.in}.  Note that @code{automake} must always
888 be run from the topmost directory of a project, even if being used to
889 regenerate the @file{Makefile.in} in some subdirectory.  This is
890 necessary because @code{automake} must scan @file{configure.in}, and
891 because @code{automake} uses the knowledge that a @file{Makefile.in} is
892 in a subdirectory to change its behavior in some cases.
894 @vindex AUTOCONF
895 Automake will run @code{autoconf} to scan @file{configure.in} and its
896 dependencies (@file{aclocal.m4}), therefore @code{autoconf} must be in
897 your @code{PATH}.  If there is an @code{AUTOCONF} variable in your
898 environment it will be used instead of @code{autoconf}, this allows you
899 to select a particular version of Autoconf.  By the way, don't
900 misunderstand this paragraph: Automake runs @code{autoconf} to
901 @strong{scan} your @file{configure.in}, this won't build
902 @file{configure} and you still have to run @code{autoconf} yourself for
903 this purpose.
905 @cindex Automake options
906 @cindex Options, Automake
907 @cindex Strictness, command line
909 @code{automake} accepts the following options:
911 @cindex Extra files distributed with Automake
912 @cindex Files distributed with Automake
913 @cindex config.guess
915 @table @samp
916 @item -a
917 @itemx --add-missing
918 @opindex -a
919 @opindex --add-missing
920 Automake requires certain common files to exist in certain situations;
921 for instance @file{config.guess} is required if @file{configure.in} runs
922 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
923 files (@pxref{Auxiliary Programs}); this option will cause the missing
924 ones to be automatically added to the package, whenever possible.  In
925 general if Automake tells you a file is missing, try using this option.
926 By default Automake tries to make a symbolic link pointing to its own
927 copy of the missing file; this can be changed with @code{--copy}.
929 Many of the potentially-missing files are common scripts whose
930 location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
931 Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
932 file is considered missing, and where the missing file is added
933 (@pxref{Optional}).
935 @item --libdir=@var{dir}
936 @opindex --libdir
937 Look for Automake data files in directory @var{dir} instead of in the
938 installation directory.  This is typically used for debugging.
940 @item -c
941 @opindex -c
942 @itemx --copy
943 @opindex --copy
944 When used with @code{--add-missing}, causes installed files to be
945 copied.  The default is to make a symbolic link.
947 @item --cygnus
948 @opindex --cygnus
949 Causes the generated @file{Makefile.in}s to follow Cygnus rules, instead
950 of GNU or Gnits rules.  For more information, see @ref{Cygnus}.
952 @item -f
953 @opindex -f
954 @itemx --force-missing
955 @opindex --force-missing
956 When used with @code{--add-missing}, causes standard files to be reinstalled
957 even if they already exist in the source tree.  This involves removing
958 the file from the source tree before creating the new symlink (or, with
959 @code{--copy}, copying the new file).
961 @item --foreign
962 @opindex --foreign
963 Set the global strictness to @samp{foreign}.  For more information, see
964 @ref{Strictness}.
966 @item --gnits
967 @opindex --gnits
968 Set the global strictness to @samp{gnits}.  For more information, see
969 @ref{Gnits}.
971 @item --gnu
972 @opindex --gnu
973 Set the global strictness to @samp{gnu}.  For more information, see
974 @ref{Gnits}.  This is the default strictness.
976 @item --help
977 @opindex --help
978 Print a summary of the command line options and exit.
980 @item -i
981 @itemx --ignore-deps
982 @opindex -i
983 This disables the dependency tracking feature in generated
984 @file{Makefile}s; see @ref{Dependencies}.
986 @item --include-deps
987 @opindex --include-deps
988 This enables the dependency tracking feature.  This feature is enabled
989 by default.  This option is provided for historical reasons only and
990 probably should not be used.
992 @item --no-force
993 @opindex --no-force
994 Ordinarily @code{automake} creates all @file{Makefile.in}s mentioned in
995 @file{configure.in}.  This option causes it to only update those
996 @file{Makefile.in}s which are out of date with respect to one of their
997 dependents.
999 @item -o @var{dir}
1000 @itemx --output-dir=@var{dir}
1001 @opindex -o
1002 @opindex --output-dir
1003 Put the generated @file{Makefile.in} in the directory @var{dir}.
1004 Ordinarily each @file{Makefile.in} is created in the directory of the
1005 corresponding @file{Makefile.am}.  This option is deprecated and will be
1006 removed in a future release.
1008 @item -v
1009 @itemx --verbose
1010 @opindex -v
1011 @opindex --verbose
1012 Cause Automake to print information about which files are being read or
1013 created.
1015 @item --version
1016 @opindex --version
1017 Print the version number of Automake and exit.
1019 @item -W CATEGORY
1020 @item --warnings=@var{category}
1021 @opindex -W
1022 @opindex --warnings
1023 Output warnings falling in @var{category}.  @var{category} can be
1024 one of:
1025 @table @samp
1026 @item gnu
1027 warnings related to the GNU Coding Standards
1028 (@pxref{Top, , , standards, The GNU Coding Standards}).
1029 @item obsolete
1030 obsolete features or constructions
1031 @item override
1032 user redefinitions of Automake rules or variables
1033 @item portability
1034 portability issues (e.g., use of Make features which are known not portable)
1035 @item syntax
1036 weird syntax, unused variables, typos
1037 @item unsupported
1038 unsupported or incomplete features
1039 @item all
1040 all the warnings
1041 @item none
1042 turn off all the warnings
1043 @item error
1044 treat warnings as errors
1045 @end table
1047 A category can be turned off by prefixing its name with @samp{no-}.  For
1048 instance @samp{-Wno-syntax} will hide the warnings about unused
1049 variables.
1051 The categories output by default are @samp{syntax} and
1052 @samp{unsupported}.  Additionally, @samp{gnu} is enabled in @samp{--gnu} and
1053 @samp{--gnits} strictness.
1055 @samp{portability} warnings are currently disabled by default, but they
1056 will be enabled in @samp{--gnu} and @samp{--gnits} strictness in a
1057 future release.
1059 @vindex WARNINGS
1060 The environment variable @samp{WARNINGS} can contain a comma separated
1061 list of categories to enable.  It will be taken into account before the
1062 command-line switches, this way @samp{-Wnone} will also ignore any
1063 warning category enabled by @samp{WARNINGS}.  This variable is also used
1064 by other tools like @command{autoconf}; unknown categories are ignored
1065 for this reason.
1067 @end table
1070 @node configure
1071 @chapter Scanning @file{configure.in}
1073 @cindex configure.in, scanning
1074 @cindex Scanning configure.in
1076 Automake scans the package's @file{configure.in} to determine certain
1077 information about the package.  Some @code{autoconf} macros are required
1078 and some variables must be defined in @file{configure.in}.  Automake
1079 will also use information from @file{configure.in} to further tailor its
1080 output.
1082 Automake also supplies some Autoconf macros to make the maintenance
1083 easier.  These macros can automatically be put into your
1084 @file{aclocal.m4} using the @code{aclocal} program.
1086 @menu
1087 * Requirements::                Configuration requirements
1088 * Optional::                    Other things Automake recognizes
1089 * Invoking aclocal::            Auto-generating aclocal.m4
1090 * aclocal options::             aclocal command line arguments
1091 * Macro search path::           Modifying aclocal's search path
1092 * Macros::                      Autoconf macros supplied with Automake
1093 * Extending aclocal::           Writing your own aclocal macros
1094 * Local Macros::                Organizing local macros
1095 * Future of aclocal::           aclocal's scheduled death
1096 @end menu
1099 @node Requirements
1100 @section Configuration requirements
1102 @cindex Automake requirements
1103 @cindex Requirements of Automake
1105 The one real requirement of Automake is that your @file{configure.in}
1106 call @code{AM_INIT_AUTOMAKE}.  This macro does several things which are
1107 required for proper Automake operation (@pxref{Macros}).
1108 @cvindex AM_INIT_AUTOMAKE
1110 Here are the other macros which Automake requires but which are not run
1111 by @code{AM_INIT_AUTOMAKE}:
1113 @table @code
1114 @item AC_CONFIG_FILES
1115 @itemx AC_OUTPUT
1116 Automake uses these to determine which files to create (@pxref{Output, ,
1117 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
1118 is considered to be an Automake generated @file{Makefile} if there
1119 exists a file with the same name and the @file{.am} extension appended.
1120 Typically, @code{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
1121 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
1123 These files are all removed by @code{make distclean}.
1124 @cvindex AC_CONFIG_FILES
1125 @cvindex AC_OUTPUT
1126 @end table
1129 @node Optional
1130 @section Other things Automake recognizes
1132 @cindex Macros Automake recognizes
1133 @cindex Recognized macros by Automake
1135 Every time Automake is run it calls Autoconf to trace
1136 @file{configure.in}.  This way it can recognize the use of certain
1137 macros and tailor the generated @file{Makefile.in} appropriately.
1138 Currently recognized macros and their effects are:
1140 @table @code
1141 @item AC_CONFIG_HEADERS
1142 Automake will generate rules to rebuild these headers.  Older versions
1143 of Automake required the use of @code{AM_CONFIG_HEADER}
1144 (@pxref{Macros}); this is no longer the case today.
1145 @cvindex AC_CONFIG_HEADERS
1147 @item AC_CONFIG_LINKS
1148 Automake will generate rules to remove @file{configure} generated links on
1149 @code{make distclean} and to distribute named source files as part of
1150 @code{make dist}.
1151 @cvindex AC_CONFIG_LINKS
1153 @item AC_CONFIG_AUX_DIR
1154 Automake will look for various helper scripts, such as
1155 @file{mkinstalldirs}, in the directory named in this macro invocation.
1156 @c This list is accurate relative to version 1.7.2
1157 (The full list of scripts is: @file{config.guess}, @file{config.sub},
1158 @file{depcomp}, @file{elisp-comp}, @file{compile}, @file{install-sh},
1159 @file{ltmain.sh}, @file{mdate-sh}, @file{missing}, @file{mkinstalldirs},
1160 @file{py-compile}, @file{texinfo.tex}, and @file{ylwrap}.)  Not all
1161 scripts are always searched for; some scripts will only be sought if the
1162 generated @file{Makefile.in} requires them.
1163 @cvindex AC_CONFIG_AUX_DIR
1165 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
1166 their @samp{standard} locations.  For @file{mdate-sh},
1167 @file{texinfo.tex}, and @file{ylwrap}, the standard location is the
1168 source directory corresponding to the current @file{Makefile.am}.  For
1169 the rest, the standard location is the first one of @file{.}, @file{..},
1170 or @file{../..} (relative to the top source directory) that provides any
1171 one of the helper scripts.  @xref{Input, , Finding `configure' Input,
1172 autoconf, The Autoconf Manual}.
1174 Required files from @code{AC_CONFIG_AUX_DIR} are automatically
1175 distributed, even if there is no @file{Makefile.am} in this directory.
1177 @item AC_CANONICAL_HOST
1178 Automake will ensure that @file{config.guess} and @file{config.sub}
1179 exist.  Also, the @file{Makefile} variables @samp{host_alias} and
1180 @samp{host_triplet} are introduced.  See @ref{Canonicalizing, ,
1181 Getting the Canonical System Type, autoconf, The Autoconf Manual}.
1182 @cvindex AC_CANONICAL_HOST
1183 @vindex host_alias
1184 @vindex host_triplet
1186 @item AC_CANONICAL_SYSTEM
1187 This is similar to @code{AC_CANONICAL_HOST}, but also defines the
1188 @file{Makefile} variables @samp{build_alias} and @samp{target_alias}.
1189 @xref{Canonicalizing, , Getting the Canonical System Type, autoconf, The
1190 Autoconf Manual}.
1191 @cvindex AC_CANONICAL_SYSTEM
1192 @vindex build_alias
1193 @vindex target_alias
1195 @item AC_LIBSOURCE
1196 @itemx AC_LIBSOURCES
1197 @itemx AC_LIBOBJ
1198 Automake will automatically distribute any file listed in
1199 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
1201 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}.  So if
1202 an Autoconf macro is documented to call @code{AC_LIBOBJ([file])}, then
1203 @file{file.c} will be distributed automatically by Automake.  This
1204 encompasses many macros like @code{AC_FUNC_ALLOCA},
1205 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
1206 @cvindex AC_LIBOBJ
1207 @cvindex AC_LIBSOURCE
1208 @cvindex AC_LIBSOURCES
1210 By the way, direct assignments to @code{LIBOBJS} are no longer
1211 supported.  You should always use @code{AC_LIBOBJ} for this purpose.
1212 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs. @code{LIBOBJS},
1213 autoconf, The Autoconf Manual}.
1214 @cvindex LIBOBJS
1216 @item AC_PROG_RANLIB
1217 This is required if any libraries are built in the package.
1218 @xref{Particular Programs, , Particular Program Checks, autoconf, The
1219 Autoconf Manual}.
1220 @cvindex AC_PROG_RANLIB
1222 @item AC_PROG_CXX
1223 This is required if any C++ source is included.  @xref{Particular
1224 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
1225 @cvindex AC_PROG_CXX
1227 @item AC_PROG_F77
1228 This is required if any Fortran 77 source is included.  This macro is
1229 distributed with Autoconf version 2.13 and later.  @xref{Particular
1230 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
1231 @cvindex AC_PROG_F77
1233 @item AC_F77_LIBRARY_LDFLAGS
1234 This is required for programs and shared libraries that are a mixture of
1235 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
1236 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
1237 @cvindex AC_F77_LIBRARY_LDFLAGS
1239 @item AC_PROG_LIBTOOL
1240 Automake will turn on processing for @code{libtool} (@pxref{Top, ,
1241 Introduction, libtool, The Libtool Manual}).
1242 @cvindex AC_PROG_LIBTOOL
1244 @item AC_PROG_YACC
1245 If a Yacc source file is seen, then you must either use this macro or
1246 define the variable @samp{YACC} in @file{configure.in}.  The former is
1247 preferred (@pxref{Particular Programs, , Particular Program Checks,
1248 autoconf, The Autoconf Manual}).
1249 @cvindex AC_PROG_YACC
1250 @cvindex YACC
1252 @item AC_PROG_LEX
1253 If a Lex source file is seen, then this macro must be used.
1254 @xref{Particular Programs, , Particular Program Checks, autoconf, The
1255 Autoconf Manual}.
1256 @cvindex AC_PROG_LEX
1258 @item AC_SUBST
1259 @cvindex AC_SUBST
1260 The first argument is automatically defined as a variable in each
1261 generated @file{Makefile.in}.  @xref{Setting Output Variables, , Setting
1262 Output Variables, autoconf, The Autoconf Manual}.
1264 If the Autoconf manual says that a macro calls @code{AC_SUBST} for
1265 @var{var}, or defined the output variable @var{var} then @var{var} will
1266 be defined in each generated @file{Makefile.in}.
1267 E.g. @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and @code{X_LIBS}, so
1268 you can use the variable in any @file{Makefile.am} if
1269 @code{AC_PATH_XTRA} is called.
1271 @item AM_C_PROTOTYPES
1272 This is required when using automatic de-ANSI-fication; see @ref{ANSI}.
1273 @cvindex AM_C_PROTOTYPES
1275 @item AM_GNU_GETTEXT
1276 This macro is required for packages which use GNU gettext
1277 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
1278 this macro it ensures that the package meets some of gettext's
1279 requirements.
1280 @cvindex AM_GNU_GETTEXT
1282 @item AM_MAINTAINER_MODE
1283 @opindex --enable-maintainer-mode
1284 This macro adds a @samp{--enable-maintainer-mode} option to
1285 @code{configure}.  If this is used, @code{automake} will cause
1286 @samp{maintainer-only} rules to be turned off by default in the
1287 generated @file{Makefile.in}s. This macro defines the
1288 @samp{MAINTAINER_MODE} conditional, which you can use in your own
1289 @file{Makefile.am}.
1290 @cvindex AM_MAINTAINER_MODE
1292 @item m4_include
1293 @cvindex m4_include
1294 Files included by @file{configure.in} using this macro will be
1295 detected by Automake and automatically distributed.  They will also
1296 appear as dependencies in @file{Makefile} rules.
1298 @code{m4_include} is seldom used by @file{configure.in} authors, but
1299 can appear in @file{aclocal.m4} when @command{aclocal} detects that
1300 some required macros come from files local to your package (as
1301 opposed to macros installed in a system-wide directory, see
1302 @ref{Invoking aclocal}).
1304 @end table
1307 @node Invoking aclocal
1308 @section Auto-generating aclocal.m4
1310 @cindex Invoking aclocal
1311 @cindex aclocal, Invoking
1313 Automake includes a number of Autoconf macros which can be used in
1314 your package (@pxref{Macros}); some of them are actually required by
1315 Automake in certain situations.  These macros must be defined in your
1316 @file{aclocal.m4}; otherwise they will not be seen by
1317 @command{autoconf}.
1319 The @command{aclocal} program will automatically generate
1320 @file{aclocal.m4} files based on the contents of @file{configure.in}.
1321 This provides a convenient way to get Automake-provided macros,
1322 without having to search around.  The @command{aclocal} mechanism
1323 allows other packages to supply their own macros (@pxref{Extending
1324 aclocal}).  You can also use it to maintain your own set of custom
1325 macros (@pxref{Local Macros}).
1327 At startup, @command{aclocal} scans all the @file{.m4} files it can
1328 find, looking for macro definitions (@pxref{Macro search path}).  Then
1329 it scans @file{configure.in}.  Any mention of one of the macros found
1330 in the first step causes that macro, and any macros it in turn
1331 requires, to be put into @file{aclocal.m4}.
1333 @emph{Putting} the file that contains the macro definition into
1334 @file{aclocal.m4} is usually done by copying the entire text of this
1335 file, including unused macro definitions as well as both @samp{#} and
1336 @samp{dnl} comments.  If you want to make a comment which will be
1337 completely ignored by @command{aclocal}, use @samp{##} as the comment
1338 leader.
1340 When @command{aclocal} detects that the file containing the macro
1341 definition is in a subdirectory of your package, it will use
1342 @code{m4_include} instead of copying it; this makes the package
1343 smaller and eases dependency tracking.  This only works if the
1344 subdirectory containing the macro was specified as a relative search
1345 path with @command{aclocal}'s @code{-I} argument.  (@pxref{Local
1346 Macros} for an example.)  Any macro which is found in a system-wide
1347 directory, or via an absolute search path will be copied.
1349 The contents of @file{acinclude.m4}, if it exists, are also
1350 automatically included in @file{aclocal.m4}.  We recommend against
1351 using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
1353 @vindex AUTOM4TE
1354 While computing @file{aclocal.m4}, @code{aclocal} runs @code{autom4te}
1355 (@pxref{Using autom4te, , Using @code{Autom4te}, autoconf, The
1356 Autoconf Manual}) in order to trace the macros which are really used,
1357 and omit from @file{aclocal.m4} all macros which are mentioned but
1358 otherwise unexpanded (this can happen when a macro is called
1359 conditionally).  @code{autom4te} is expected to be in the @code{PATH},
1360 just as @code{autoconf}.  Its location can be overridden using the
1361 @code{AUTOM4TE} environment variable.
1363 @menu
1364 * aclocal options::             Options supported by aclocal
1365 * Macro search path::           How aclocal finds .m4 files
1366 @end menu
1368 @node aclocal options
1369 @section aclocal options
1371 @cindex aclocal, Options
1372 @cindex Options, aclocal
1374 @code{aclocal} accepts the following options:
1376 @table @code
1377 @item --acdir=@var{dir}
1378 @opindex --acdir
1379 Look for the macro files in @var{dir} instead of the installation
1380 directory.  This is typically used for debugging.
1382 @item --help
1383 @opindex --help
1384 Print a summary of the command line options and exit.
1386 @item -I @var{dir}
1387 @opindex -I
1388 Add the directory @var{dir} to the list of directories searched for
1389 @file{.m4} files.
1391 @item --force
1392 @opindex --force
1393 Always overwrite the output file.  The default is to overwrite the output
1394 file only when really needed, i.e., when its contents changes or if one
1395 of its dependencies is younger.
1397 @item --output=@var{file}
1398 @opindex --output
1399 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
1401 @item --print-ac-dir
1402 @opindex --print-ac-dir
1403 Prints the name of the directory which @code{aclocal} will search to
1404 find third-party @file{.m4} files.  When this option is given, normal
1405 processing is suppressed.  This option can be used by a package to
1406 determine where to install a macro file.
1408 @item --verbose
1409 @opindex --verbose
1410 Print the names of the files it examines.
1412 @item --version
1413 @opindex --version
1414 Print the version number of Automake and exit.
1415 @end table
1417 @node Macro search path
1418 @section Macro search path
1420 @cindex Macro search path
1421 @cindex aclocal search path
1423 By default, @command{aclocal} searches for @file{.m4} files in the following
1424 directories, in this order:
1426 @table @code
1427 @item @var{acdir-APIVERSION}
1428 This is where the @file{.m4} macros distributed with automake itself
1429 are stored.  @var{APIVERSION} depends on the automake release used;
1430 for automake 1.6.x, @var{APIVERSION} = @code{1.6}.
1432 @item @var{acdir}
1433 This directory is intended for third party @file{.m4} files, and is
1434 configured when @command{automake} itself is built.  This is
1435 @file{@@datadir@@/aclocal/}, which typically
1436 expands to @file{$@{prefix@}/share/aclocal/}.  To find the compiled-in
1437 value of @var{acdir}, use the @code{--print-ac-dir} option
1438 (@pxref{aclocal options}).
1439 @end table
1441 As an example, suppose that automake-1.6.2 was configured with
1442 @code{--prefix=/usr/local}.  Then, the search path would be:
1444 @enumerate
1445 @item @file{/usr/local/share/aclocal-1.6/}
1446 @item @file{/usr/local/share/aclocal/}
1447 @end enumerate
1449 As explained in (@pxref{aclocal options}), there are several options that
1450 can be used to change or extend this search path.
1452 @subsection Modifying the macro search path: @code{--acdir}
1454 The most obvious option to modify the search path is
1455 @code{--acdir=@var{dir}}, which changes default directory and
1456 drops the @var{APIVERSION} directory.  For example, if one specifies
1457 @code{--acdir=/opt/private/}, then the search path becomes:
1459 @enumerate
1460 @item @file{/opt/private/}
1461 @end enumerate
1463 Note that this option, @code{--acdir}, is intended for use
1464 by the internal automake test suite only; it is not ordinarily
1465 needed by end-users.
1467 @subsection Modifying the macro search path: @code{-I @var{dir}}
1469 Any extra directories specified using @code{-I} options
1470 (@pxref{aclocal options}) are @emph{prepended} to this search list.  Thus,
1471 @code{aclocal -I /foo -I /bar} results in the following search path:
1473 @enumerate
1474 @item @file{/foo}
1475 @item @file{/bar}
1476 @item @var{acdir}-@var{APIVERSION}
1477 @item @var{acdir}
1478 @end enumerate
1480 @subsection Modifying the macro search path: @file{dirlist}
1481 @cindex @file{dirlist}
1483 There is a third mechanism for customizing the search path.  If a
1484 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
1485 contain a list of directories, one per line, to be added to the search
1486 list.  These directories are searched @emph{after} all other
1487 directories.
1489 For example, suppose
1490 @file{@var{acdir}/dirlist} contains the following:
1492 @example
1493 /test1
1494 /test2
1495 @end example
1497 @noindent
1498 and that @code{aclocal} was called with the @code{-I /foo -I /bar} options.
1499 Then, the search path would be
1501 @enumerate
1502 @item @file{/foo}
1503 @item @file{/bar}
1504 @item @var{acdir}-@var{APIVERSION}
1505 @item @var{acdir}
1506 @item @file{/test1}
1507 @item @file{/test2}
1508 @end enumerate
1510 If the @code{--acdir=@var{dir}} option is used, then @command{aclocal}
1511 will search for the @file{dirlist} file in @var{dir}.  In the
1512 @code{--acdir=/opt/private/} example above, @command{aclocal} would look
1513 for @file{/opt/private/dirlist}.  Again, however, the @code{--acdir}
1514 option is intended for use by the internal automake test suite only;
1515 @code{--acdir} is not ordinarily needed by end-users.
1517 @file{dirlist} is useful in the following situation: suppose that
1518 @code{automake} version @code{1.6.2} is installed with
1519 $prefix=/usr by the system vendor. Thus, the default search
1520 directories are
1522 @enumerate
1523 @item @file{/usr/share/aclocal-1.6/}
1524 @item @file{/usr/share/aclocal/}
1525 @end enumerate
1527 However, suppose further that many packages have been manually
1528 installed on the system, with $prefix=/usr/local, as is typical.
1529 In that case, many of these ``extra'' @file{.m4} files are in
1530 @file{/usr/local/share/aclocal}.  The only way to force
1531 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files
1532 is to always call @code{aclocal -I /usr/local/share/aclocal}.
1533 This is inconvenient.  With @file{dirlist}, one may create the file
1535 @file{/usr/share/aclocal/dirlist}
1537 @noindent
1538 which contains only the single line
1540 @file{/usr/local/share/aclocal}
1542 Now, the ``default'' search path on the affected system is
1544 @enumerate
1545 @item @file{/usr/share/aclocal-1.6/}
1546 @item @file{/usr/share/aclocal/}
1547 @item @file{/usr/local/share/aclocal/}
1548 @end enumerate
1550 without the need for @code{-I} options; @code{-I} options can be reserved
1551 for project-specific needs (@file{my-source-dir/m4/}), rather than
1552 using it to work around local system-dependent tool installation
1553 directories.
1555 Similarly, @file{dirlist} can be handy if you have installed a local
1556 copy Automake on your account and want @command{aclocal} to look for
1557 macros installed at other places on the system.
1560 @node Macros
1561 @section Autoconf macros supplied with Automake
1563 Automake ships with several Autoconf macros that you can use from your
1564 @file{configure.in}.  When you use one of them it will be included by
1565 @code{aclocal} in @file{aclocal.m4}.
1567 @menu
1568 * Public macros::               Macros that you can use.
1569 * Private macros::              Macros that you should not use.
1570 @end menu
1572 @c consider generating the following subsections automatically from m4 files.
1574 @node Public macros
1575 @subsection Public macros
1577 @table @code
1578 @item AM_CONFIG_HEADER
1579 Automake will generate rules to automatically regenerate the config
1580 header.  This obsolete macro is a synonym of @code{AC_CONFIG_HEADERS}
1581 today (@pxref{Optional}).
1582 @cvindex AM_CONFIG_HEADER
1584 @item AM_ENABLE_MULTILIB
1585 This is used when a ``multilib'' library is being built.  The first
1586 optional argument is the name of the @file{Makefile} being generated; it
1587 defaults to @samp{Makefile}.  The second option argument is used to find
1588 the top source directory; it defaults to the empty string (generally
1589 this should not be used unless you are familiar with the internals).
1590 @xref{Multilibs}.
1592 @item AM_C_PROTOTYPES
1593 Check to see if function prototypes are understood by the compiler.  If
1594 so, define @samp{PROTOTYPES} and set the output variables @samp{U} and
1595 @samp{ANSI2KNR} to the empty string.  Otherwise, set @samp{U} to
1596 @samp{_} and @samp{ANSI2KNR} to @samp{./ansi2knr}.  Automake uses these
1597 values to implement automatic de-ANSI-fication.
1598 @cvindex AM_C_PROTOTYPES
1600 @item AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
1601 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
1602 define @code{GWINSZ_IN_SYS_IOCTL}.  Otherwise @code{TIOCGWINSZ} can be
1603 found in @file{<termios.h>}.
1604 @cvindex AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
1606 @item AM_INIT_AUTOMAKE([OPTIONS])
1607 @itemx AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
1608 Runs many macros required for proper operation of the generated Makefiles.
1610 This macro has two forms, the first of which is preferred.
1611 In this form, @code{AM_INIT_AUTOMAKE} is called with a
1612 single argument --- a space-separated list of Automake options which should
1613 be applied to every @file{Makefile.am} in the tree.  The effect is as if
1614 each option were listed in @code{AUTOMAKE_OPTIONS}.
1616 The second, deprecated, form of @code{AM_INIT_AUTOMAKE} has two required
1617 arguments: the package and the version number.  This form is
1618 obsolete because the @var{package} and @var{version} can be obtained
1619 from Autoconf's @code{AC_INIT} macro (which itself has an old and a new
1620 form).
1622 If your @file{configure.in} has:
1623 @example
1624 AC_INIT(src/foo.c)
1625 AM_INIT_AUTOMAKE(mumble, 1.5)
1626 @end example
1627 you can modernize it as follows:
1628 @example
1629 AC_INIT(mumble, 1.5)
1630 AC_CONFIG_SRCDIR(src/foo.c)
1631 AM_INIT_AUTOMAKE
1632 @end example
1634 Note that if you're upgrading your @file{configure.in} from an earlier
1635 version of Automake, it is not always correct to simply move the package
1636 and version arguments from @code{AM_INIT_AUTOMAKE} directly to
1637 @code{AC_INIT}, as in the example above.  The first argument to
1638 @code{AC_INIT} should be the name of your package (e.g. @samp{GNU Automake}),
1639 not the tarball name (e.g. @samp{automake}) that you used to pass to
1640 @code{AM_INIT_AUTOMAKE}.  Autoconf tries to derive a tarball name from
1641 the package name, which should work for most but not all package names.
1642 (If it doesn't work for yours, you can use the
1643 four-argument form of @code{AC_INIT} --- supported in Autoconf versions
1644 greater than 2.52g --- to provide the tarball name explicitly).
1646 By default this macro @code{AC_DEFINE}'s @samp{PACKAGE} and
1647 @samp{VERSION}.  This can be avoided by passing the @samp{no-define}
1648 option, as in:
1649 @example
1650 AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
1651 @end example
1652 or by passing a third non-empty argument to the obsolete form.
1654 @cvindex PACKAGE, prevent definition
1655 @cvindex VERSION, prevent definition
1658 @item AM_PATH_LISPDIR
1659 Searches for the program @code{emacs}, and, if found, sets the output
1660 variable @code{lispdir} to the full path to Emacs' site-lisp directory.
1662 Note that this test assumes the @code{emacs} found to be a version that
1663 supports Emacs Lisp (such as @sc{gnu} Emacs or XEmacs).  Other emacsen
1664 can cause this test to hang (some, like old versions of MicroEmacs,
1665 start up in interactive mode, requiring @samp{C-x C-c} to exit, which
1666 is hardly obvious for a non-emacs user).  In most cases, however, you
1667 should be able to use @samp{C-c} to kill the test.  In order to avoid
1668 problems, you can set @code{EMACS} to ``no'' in the environment, or
1669 use the @samp{--with-lispdir} option to @command{configure} to
1670 explicitly set the correct path (if you're sure you have an @code{emacs}
1671 that supports Emacs Lisp.
1672 @cvindex AM_PATH_LISPDIR
1674 @item AM_PROG_AS
1675 Use this macro when you have assembly code in your project.  This will
1676 choose the assembler for you (by default the C compiler) and set
1677 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
1679 @item AM_PROG_CC_C_O
1680 This is like @code{AC_PROG_CC_C_O}, but it generates its results in the
1681 manner required by automake.  You must use this instead of
1682 @code{AC_PROG_CC_C_O} when you need this functionality.
1684 @item AM_PROG_LEX
1685 @cindex HP-UX 10, lex problems
1686 @cindex lex problems with HP-UX 10
1687 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
1688 Program Checks, autoconf, The Autoconf Manual}), but uses the
1689 @code{missing} script on systems that do not have @code{lex}.
1690 @samp{HP-UX 10} is one such system.
1692 @item AM_PROG_GCJ
1693 This macro finds the @code{gcj} program or causes an error.  It sets
1694 @samp{GCJ} and @samp{GCJFLAGS}.  @code{gcj} is the Java front-end to the
1695 GNU Compiler Collection.
1696 @cvindex AM_PROG_GCJ
1698 @item AM_SYS_POSIX_TERMIOS
1699 @cvindex am_cv_sys_posix_termios
1700 @cindex POSIX termios headers
1701 @cindex termios POSIX headers
1702 Check to see if POSIX termios headers and functions are available on the
1703 system.  If so, set the shell variable @code{am_cv_sys_posix_termios} to
1704 @samp{yes}.  If not, set the variable to @samp{no}.
1706 @item AM_WITH_DMALLOC
1707 @cvindex WITH_DMALLOC
1708 @cindex dmalloc, support for
1709 @opindex --with-dmalloc
1710 Add support for the
1711 @uref{ftp://ftp.letters.com/src/dmalloc/dmalloc.tar.gz, dmalloc}
1712 package.  If the user configures with @samp{--with-dmalloc}, then define
1713 @code{WITH_DMALLOC} and add @samp{-ldmalloc} to @code{LIBS}.
1715 @item AM_WITH_REGEX
1716 @cvindex WITH_REGEX
1717 @opindex --with-regex
1718 @cindex regex package
1719 @cindex rx package
1720 Adds @samp{--with-regex} to the @code{configure} command line.  If
1721 specified (the default), then the @samp{regex} regular expression
1722 library is used, @file{regex.o} is put into @samp{LIBOBJS}, and
1723 @samp{WITH_REGEX} is defined.  If @samp{--without-regex} is given, then
1724 the @samp{rx} regular expression library is used, and @file{rx.o} is put
1725 into @samp{LIBOBJS}.
1727 @end table
1729 @node Private macros
1730 @subsection Private macros
1732 The following macros are private macros you should not call directly.
1733 They are called by the other public macros when appropriate.  Do not
1734 rely on them, as they might be changed in a future version.  Consider
1735 them as implementation details; or better, do not consider them at all:
1736 skip this section!
1738 @table @code
1739 @item _AM_DEPENDENCIES
1740 @itemx AM_SET_DEPDIR
1741 @itemx AM_DEP_TRACK
1742 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
1743 These macros are used to implement Automake's automatic dependency
1744 tracking scheme.  They are called automatically by automake when
1745 required, and there should be no need to invoke them manually.
1747 @item AM_MAKE_INCLUDE
1748 This macro is used to discover how the user's @code{make} handles
1749 @code{include} statements.  This macro is automatically invoked when
1750 needed; there should be no need to invoke it manually.
1752 @item AM_PROG_INSTALL_STRIP
1753 This is used to find a version of @code{install} which can be used to
1754 @code{strip} a program at installation time.  This macro is
1755 automatically included when required.
1757 @item AM_SANITY_CHECK
1758 This checks to make sure that a file created in the build directory is
1759 newer than a file in the source directory.  This can fail on systems
1760 where the clock is set incorrectly.  This macro is automatically run
1761 from @code{AM_INIT_AUTOMAKE}.
1763 @end table
1766 @node Extending aclocal
1767 @section Writing your own aclocal macros
1769 @cindex aclocal, extending
1770 @cindex Extending aclocal
1772 The @command{aclocal} program doesn't have any built-in knowledge of any
1773 macros, so it is easy to extend it with your own macros.
1775 This can be used by libraries which want to supply their own Autoconf
1776 macros for use by other programs.  For instance the @command{gettext}
1777 library supplies a macro @code{AM_GNU_GETTEXT} which should be used by
1778 any package using @command{gettext}.  When the library is installed, it
1779 installs this macro so that @command{aclocal} will find it.
1781 A macro file's name should end in @file{.m4}.  Such files should be
1782 installed in @file{$(datadir)/aclocal}.  This is as simple as writing:
1784 @example
1785 aclocaldir = $(datadir)/aclocal
1786 aclocal_DATA = mymacro.m4 myothermacro.m4
1787 @end example
1789 A file of macros should be a series of properly quoted
1790 @code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
1791 Autoconf Manual}).  The @command{aclocal} programs also understands
1792 @code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
1793 Autoconf Manual}), so it is safe to put each macro in a separate file.
1794 Each file should have no side effects but macro definitions.
1795 Especially, any call to @code{AC_PREREQ} should be done inside the
1796 defined macro, not at the beginning of the file.
1798 @cindex underquoted AC_DEFUN
1799 @cvindex AC_DEFUN
1800 @cvindex AC_PREREQ
1802 Starting with Automake 1.8, @command{aclocal} will warn about all
1803 underquoted calls to @code{AC_DEFUN}.  We realize this will annoy a
1804 lot of people, because @command{aclocal} was not so strict in the past
1805 and many third party macros are underquoted; and we have to apologize
1806 for this temporary inconvenience.  The reason we have to be stricter
1807 is that a future implementation of @command{aclocal} (@pxref{Future of
1808 aclocal}) will have to temporary include all these third party
1809 @file{.m4} files, maybe several times, even those which are not
1810 actually needed.  Doing so should alleviate many problem of the
1811 current implementation, however it requires a stricter style from the
1812 macro authors.  Hopefully it is easy to revise the existing macros.
1813 For instance
1814 @example
1815 # bad style
1816 AC_PREREQ(2.57)
1817 AC_DEFUN(AX_FOOBAR,
1818 [AC_REQUIRE([AX_SOMETHING])dnl
1819 AX_FOO
1820 AX_BAR
1822 @end example
1823 @noindent
1824 should be rewritten as
1825 @example
1826 AC_DEFUN([AX_FOOBAR],
1827 [AC_PREREQ(2.57)dnl
1828 AC_REQUIRE([AX_SOMETHING])dnl
1829 AX_FOO
1830 AX_BAR
1832 @end example
1834 Wrapping the @code{AC_PREREQ} call inside the macro ensures that
1835 Autoconf 2.57 will not be required if @code{AX_FOOBAR} is not actually
1836 used.  Most importantly, quoting the first argument of @code{AC_DEFUN}
1837 allows the macro to be redefined or included twice (otherwise this
1838 first argument would be expansed during the second definition).
1840 If you have been directed here by the @command{aclocal} diagnostic but
1841 are not the maintainer of the implicated macro, you will want to
1842 contact the maintainer of that macro.  Please make sure you have the
1843 last version of the macro and that the problem already hasn't been
1844 reported before doing so: people tend to work faster when they aren't
1845 flooded by mails.
1847 Another situation where @command{aclocal} is commonly used is to
1848 manage macros which are used locally by the package, @ref{Local
1849 Macros}.
1851 @node Local Macros
1852 @section Handling Local Macros
1854 Feature tests offered by Autoconf do not cover all needs.  People
1855 often have to supplement existing tests with their own macros, or
1856 with third-party macros.
1858 There are two ways to organize custom macros in a package.
1860 The first possibility (the historical practice) is to list all your
1861 macros in @file{acinclude.m4}.  This file will be included in
1862 @file{aclocal.m4} when you run @command{aclocal}, and its macro(s) will
1863 henceforth be visible to @command{autoconf}.  However if it contains
1864 numerous macros, it will rapidly become difficult to maintain, and it
1865 will be almost impossible to share macros between package.
1867 The second possibility, which we do recommend, is to write each macro
1868 in its own file and gather all these files in a directory.  This
1869 directory is usually called @file{m4/}.  To build @file{aclocal.m4},
1870 one should therefore instruct @command{aclocal} to scan @file{m4/}.
1871 From the command line, this is done with @code{aclocal -I m4}.  The
1872 top-level @file{Makefile.am} should also be updated to define
1874 @example
1875  ACLOCAL_AMFLAGS = -I m4
1876 @end example
1878 @code{ACLOCAL_AMFLAGS} contains options to pass to @command{aclocal}
1879 when @file{aclocal.m4} is to be rebuilt by @code{make}.  This line is
1880 also used by @command{autoreconf} (@pxref{autoreconf Invocation, ,
1881 Using @command{autoreconf} to Update @file{configure} Scripts,
1882 autoconf, The Autoconf Manual}) to run @command{aclocal} with suitable
1883 options, or by @command{autopoint} (@pxref{autopoint Invocation, ,
1884 Invoking the @command{autopoint} Program, gettext, GNU gettext tools})
1885 and @command{gettextize} (@pxref{gettextize Invocation, , Invoking the
1886 @command{gettextize} Program, gettext, GNU gettext tools}) to locate
1887 the place where Gettext's macros should be installed.  So even if you
1888 do not really care about the rebuild rules, you should define
1889 @code{ACLOCAL_AMFLAGS}.
1891 When @code{aclocal -I m4} is run, it will build a @code{aclocal.m4}
1892 that @code{m4_include}s any file from @file{m4/} that defines a
1893 required macro.  Macros not found locally will still be searched in
1894 system-wide directories, as explained in @ref{Macro search path}.
1896 Custom macros should be distributed for the same reason that
1897 @file{configure.in} is: so that other people have all the sources of
1898 your package if they want to work on it.  Actually, this distribution
1899 happens automatically because all @code{m4_include}d files are
1900 distributed.
1902 However there is no consensus on the distribution of third-party
1903 macros that your package may use.  Many libraries install their own
1904 macro in the system-wide @command{aclocal} directory (@pxref{Extending
1905 aclocal}).  For instance Guile ships with a file called
1906 @file{guile.m4} that contains the macro @code{GUILE_FLAGS} which can
1907 be used to define setup compiler and linker flags appropriate for
1908 using Guile.  Using @code{GUILE_FLAGS} in @file{configure.in} will
1909 cause @command{aclocal} to copy @file{guile.m4} into
1910 @file{aclocal.m4}, but as @file{guile.m4} is not part of the project,
1911 it will not be distributed.  Technically, that means a user which
1912 needs to rebuild @file{aclocal.m4} will have to install Guile first.
1913 This is probably OK, if Guile already is a requirement to build the
1914 package.  However, if Guile is only an optional feature, or if your
1915 package might run on architectures where Guile cannot be installed,
1916 this requirement will hinder development.  An easy solution is to copy
1917 such third-party macros in your local @file{m4/} directory so they get
1918 distributed.
1920 @node Future of aclocal
1921 @section The Future of @command{aclocal}
1922 @cindex aclocal's scheduled death
1924 @command{aclocal} is expected to disappear.  This feature really
1925 should not be offered by Automake.  Automake should focus on generating
1926 @file{Makefile}s; dealing with M4 macros really is Autoconf's job.
1927 That some people install Automake just to use @command{aclocal}, but
1928 do not use @command{automake} otherwise is an indication of how that
1929 feature is misplaced.
1931 The new implementation will probably be done slightly differently.
1932 For instance it could enforce the @file{m4/}-style layout discussed in
1933 @ref{Local Macros}, and take care of copying (or even updating)
1934 third-party macro into this directory.
1936 We have no idea when and how this will happen.  This has been
1937 discussed several times in the past, but someone still has to commit
1938 itself to that non-trivial task.
1940 From the user point of view, @command{aclocal}'s removal might turn
1941 out to be painful.  There is a simple precaution that you may take to
1942 make that switch more seamless: never call @command{aclocal} yourself.
1943 Keep this guy under the exclusive control of @command{autoreconf} and
1944 Automake's rebuild rules.  Hopefully you won't need to worry about
1945 things breaking, when @command{aclocal} disappears, because everything
1946 will have been taken care of.  If otherwise you used to call
1947 @command{aclocal} directly yourself or from some script, you will
1948 quickly notice the change.
1950 Many packages come with a script called @file{bootstrap.sh} or
1951 @file{autogen.sh}, that will just call @command{aclocal},
1952 @command{libtoolize}, @command{gettextize} or @command{autopoint},
1953 @command{autoconf}, @command{autoheader}, and @command{automake} in
1954 the right order.  Actually this is precisely what @command{autoreconf}
1955 can do for you.  If your package has such a @file{bootstrap.sh} or
1956 @file{autogen.sh} script, consider using @command{autoreconf}.  That
1957 should simplify its logic a lot (less things to maintain, yum!), it's
1958 even likely you will not need the script anymore, and more to the point
1959 you will not call @command{aclocal} directly anymore.
1962 @node Top level
1963 @chapter The top-level @file{Makefile.am}
1965 @section Recursing subdirectories
1967 @cindex SUBDIRS, explained
1969 In packages with subdirectories, the top level @file{Makefile.am} must
1970 tell Automake which subdirectories are to be built.  This is done via
1971 the @code{SUBDIRS} variable.
1972 @vindex SUBDIRS
1974 The @code{SUBDIRS} variable holds a list of subdirectories in which
1975 building of various sorts can occur.  Many targets (e.g. @code{all}) in
1976 the generated @file{Makefile} will run both locally and in all specified
1977 subdirectories.  Note that the directories listed in @code{SUBDIRS} are
1978 not required to contain @file{Makefile.am}s; only @file{Makefile}s
1979 (after configuration).  This allows inclusion of libraries from packages
1980 which do not use Automake (such as @code{gettext}).
1982 In packages that use subdirectories, the top-level @file{Makefile.am} is
1983 often very short.  For instance, here is the @file{Makefile.am} from the
1984 GNU Hello distribution:
1986 @example
1987 EXTRA_DIST = BUGS ChangeLog.O README-alpha
1988 SUBDIRS = doc intl po src tests
1989 @end example
1991 When Automake invokes @code{make} in a subdirectory, it uses the value
1992 of the @code{MAKE} variable.  It passes the value of the variable
1993 @code{AM_MAKEFLAGS} to the @code{make} invocation; this can be set in
1994 @file{Makefile.am} if there are flags you must always pass to
1995 @code{make}.
1996 @vindex MAKE
1997 @vindex MAKEFLAGS
1999 The directories mentioned in @code{SUBDIRS} must be direct children of
2000 the current directory.  For instance, you cannot put @samp{src/subdir}
2001 into @code{SUBDIRS}.  Instead you should put @code{SUBDIRS = subdir}
2002 into @file{src/Makefile.am}.  Automake can be used to construct packages
2003 of arbitrary depth this way.
2005 By default, Automake generates @file{Makefiles} which work depth-first
2006 (@samp{postfix}).  However, it is possible to change this ordering.  You
2007 can do this by putting @samp{.} into @code{SUBDIRS}.  For instance,
2008 putting @samp{.}  first will cause a @samp{prefix} ordering of
2009 directories.  All @samp{clean} targets are run in reverse order of build
2010 targets.
2012 @section Conditional subdirectories
2013 @cindex Subdirectories, building conditionally
2014 @cindex Conditional subdirectories
2015 @cindex @code{SUBDIRS}, conditional
2016 @cindex Conditional @code{SUBDIRS}
2018 It is possible to define the @code{SUBDIRS} variable conditionally if,
2019 like in the case of GNU @code{Inetutils}, you want to only build a
2020 subset of the entire package.
2022 To illustrate how this works, let's assume we have two directories
2023 @file{src/} and @file{opt/}.  @file{src/} should always be built, but we
2024 want to decide in @code{./configure} whether @file{opt/} will be built
2025 or not.  (For this example we will assume that @file{opt/} should be
2026 built when the variable @code{$want_opt} was set to @code{yes}.)
2028 Running @code{make} should thus recurse into @file{src/} always, and
2029 then maybe in @file{opt/}.
2031 However @code{make dist} should always recurse into both @file{src/} and
2032 @file{opt/}.  Because @file{opt/} should be distributed even if it is
2033 not needed in the current configuration. This means @file{opt/Makefile}
2034 should be created unconditionally.  @footnote{Don't try seeking a
2035 solution where @file{opt/Makefile} is created conditionally, this is a
2036 lot trickier than the solutions presented here.}
2038 There are two ways to setup a project like this.  You can use Automake
2039 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
2040 variables (@pxref{Setting Output Variables, , Setting Output Variables,
2041 autoconf, The Autoconf Manual}).  Using Automake conditionals is the
2042 preferred solution.
2044 @subsection Conditional subdirectories with @code{AM_CONDITIONAL}
2045 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
2046 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
2048 @c The test case for the setup described here is
2049 @c     test/subdircond2.test
2050 @c Try to keep it in sync.
2052 @file{configure} should output the @file{Makefile} for each directory
2053 and define a condition into which @file{opt/} should be built.
2055 @example
2056 @dots{}
2057 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
2058 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
2059 @dots{}
2060 @end example
2062 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
2063 as follows.
2065 @example
2066 if COND_OPT
2067   MAYBE_OPT = opt
2068 endif
2069 SUBDIRS = src $(MAYBE_OPT)
2070 @end example
2072 As you can see, running @code{make} will rightly recurse into
2073 @file{src/} and maybe @file{opt/}.
2075 @vindex DIST_SUBDIRS
2076 As you can't see, running @code{make dist} will recurse into both
2077 @file{src/} and @file{opt/} directories because @code{make dist}, unlike
2078 @code{make all}, doesn't use the @code{SUBDIRS} variable.  It uses the
2079 @code{DIST_SUBDIRS} variable.
2081 In this case Automake will define @code{DIST_SUBDIRS = src opt}
2082 automatically because it knows that @code{MAYBE_OPT} can contain
2083 @code{opt} in some condition.
2085 @subsection Conditional subdirectories with @code{AC_SUBST}
2086 @cindex @code{SUBDIRS} and @code{AC_SUBST}
2087 @cindex @code{AC_SUBST} and @code{SUBDIRS}
2089 @c The test case for the setup described here is
2090 @c     test/subdircond3.test
2091 @c Try to keep it in sync.
2093 Another idea is to define @code{MAYBE_OPT} from @file{./configure} using
2094 @code{AC_SUBST}:
2096 @example
2097 @dots{}
2098 if test "$want_opt" = yes; then
2099   MAYBE_OPT=opt
2100 else
2101   MAYBE_OPT=
2103 AC_SUBST([MAYBE_OPT])
2104 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
2105 @dots{}
2106 @end example
2108 In this case the top-level @file{Makefile.am} should look as follows.
2110 @example
2111 SUBDIRS = src $(MAYBE_OPT)
2112 DIST_SUBDIRS = src opt
2113 @end example
2115 The drawback is that since Automake cannot guess what the possible
2116 values of @code{MAYBE_OPT} are, it is necessary to define
2117 @code{DIST_SUBDIRS}.
2119 @subsection How @code{DIST_SUBDIRS} is used
2120 @cindex @code{DIST_SUBDIRS}, explained
2122 As shown in the above examples, @code{DIST_SUBDIRS} is used by targets
2123 that need to recurse in all directories, even those which have been
2124 conditionally left out of the build.
2126 Precisely, @code{DIST_SUBDIRS} is used by @code{make dist}, @code{make
2127 distclean}, and @code{make maintainer-clean}.  All other recursive
2128 targets use @code{SUBDIRS}.
2130 Automake will define @code{DIST_SUBDIRS} automatically from the
2131 possibles values of @code{SUBDIRS} in all conditions.
2133 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
2134 @code{DIST_SUBDIRS} will not be defined correctly because Automake
2135 doesn't know the possible values of these variables.  In this case
2136 @code{DIST_SUBDIRS} needs to be defined manually.
2139 @node Alternative
2140 @chapter An Alternative Approach to Subdirectories
2142 If you've ever read Peter Miller's excellent paper,
2143 @uref{http://www.pcug.org.au/~millerp/rmch/recu-make-cons-harm.html,
2144 Recursive Make Considered Harmful}, the preceding section on the use of
2145 subdirectories will probably come as unwelcome advice.  For those who
2146 haven't read the paper, Miller's main thesis is that recursive
2147 @code{make} invocations are both slow and error-prone.
2149 Automake provides sufficient cross-directory support @footnote{We
2150 believe.  This work is new and there are probably warts.
2151 @xref{Introduction}, for information on reporting bugs.} to enable you
2152 to write a single @file{Makefile.am} for a complex multi-directory
2153 package.
2156 By default an installable file specified in a subdirectory will have its
2157 directory name stripped before installation.  For instance, in this
2158 example, the header file will be installed as
2159 @file{$(includedir)/stdio.h}:
2161 @example
2162 include_HEADERS = inc/stdio.h
2163 @end example
2165 @cindex nobase_
2166 @cindex Path stripping, avoiding
2167 @cindex Avoiding path stripping
2169 However, the @samp{nobase_} prefix can be used to circumvent this path
2170 stripping.  In this example, the header file will be installed as
2171 @file{$(includedir)/sys/types.h}:
2173 @example
2174 nobase_include_HEADERS = sys/types.h
2175 @end example
2177 @cindex nobase_ and dist_ or nodist_
2178 @cindex dist_ and nobase_
2179 @cindex nodist_ and nobase_
2181 @samp{nobase_} should be specified first when used in conjunction with
2182 either @samp{dist_} or @samp{nodist_} (@pxref{Dist}).  For instance:
2184 @example
2185 nobase_dist_pkgdata_DATA = images/vortex.pgm
2186 @end example
2188 @node Rebuilding
2189 @chapter Rebuilding Makefiles
2191 Automake generates rules to automatically rebuild @file{Makefile}s,
2192 @file{configure}, and other derived files like @file{Makefile.in}.
2194 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.in}, then
2195 these automatic rebuilding rules are only enabled in maintainer mode.
2197 Sometimes you need to run @code{aclocal} with an argument like @code{-I}
2198 to tell it where to find @file{.m4} files.  Since sometimes @code{make}
2199 will automatically run @code{aclocal}, you need a way to specify these
2200 arguments.  You can do this by defining @code{ACLOCAL_AMFLAGS}; this
2201 holds arguments which are passed verbatim to @code{aclocal}.  This variable
2202 is only useful in the top-level @file{Makefile.am}.
2203 @vindex ACLOCAL_AMFLAGS
2206 @node Programs
2207 @chapter Building Programs and Libraries
2209 A large part of Automake's functionality is dedicated to making it easy
2210 to build programs and libraries.
2212 @menu
2213 * A Program::                   Building a program
2214 * A Library::                   Building a library
2215 * A Shared Library::            Building a Libtool library
2216 * Program and Library Variables::  Variables controlling program and
2217                                 library builds
2218 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
2219 * Program variables::           Variables used when building a program
2220 * Yacc and Lex::                Yacc and Lex support
2221 * C++ Support::
2222 * Assembly Support::
2223 * Fortran 77 Support::
2224 * Java Support::
2225 * Support for Other Languages::
2226 * ANSI::                        Automatic de-ANSI-fication
2227 * Dependencies::                Automatic dependency tracking
2228 * EXEEXT::                      Support for executable extensions
2229 @end menu
2232 @node A Program
2233 @section Building a program
2235 In order to build a program, you need to tell Automake which sources
2236 are part of it, and which libraries it should be linked with.
2238 This section also covers conditional compilation of sources or
2239 programs.  Most of the comments about these also apply to libraries
2240 (@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
2242 @menu
2243 * Program Sources::             Defining program sources
2244 * Linking::                     Linking with libraries or extra objects
2245 * Conditional Sources::         Handling conditional sources
2246 * Conditional Programs::        Building program conditionally
2247 @end menu
2249 @node Program Sources
2250 @subsection Defining program sources
2252 @cindex PROGRAMS, bindir
2253 @vindex bin_PROGRAMS
2254 @vindex sbin_PROGRAMS
2255 @vindex libexec_PROGRAMS
2256 @vindex pkglib_PROGRAMS
2257 @vindex noinst_PROGRAMS
2258 @vindex check_PROGRAMS
2260 In a directory containing source that gets built into a program (as
2261 opposed to a library or a script), the @samp{PROGRAMS} primary is used.
2262 Programs can be installed in @code{bindir}, @code{sbindir},
2263 @code{libexecdir}, @code{pkglibdir}, or not at all (@samp{noinst}).
2264 They can also be built only for @code{make check}, in which case the
2265 prefix is @samp{check}.
2267 For instance:
2269 @example
2270 bin_PROGRAMS = hello
2271 @end example
2273 In this simple case, the resulting @file{Makefile.in} will contain code
2274 to generate a program named @code{hello}.
2276 Associated with each program are several assisting variables which are
2277 named after the program.  These variables are all optional, and have
2278 reasonable defaults.  Each variable, its use, and default is spelled out
2279 below; we use the ``hello'' example throughout.
2281 The variable @code{hello_SOURCES} is used to specify which source files
2282 get built into an executable:
2284 @example
2285 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
2286 @end example
2288 This causes each mentioned @samp{.c} file to be compiled into the
2289 corresponding @samp{.o}.  Then all are linked to produce @file{hello}.
2291 @cindex _SOURCES primary, defined
2292 @cindex SOURCES primary, defined
2293 @cindex Primary variable, SOURCES
2295 If @samp{hello_SOURCES} is not specified, then it defaults to the single
2296 file @file{hello.c}; that is, the default is to compile a single C file
2297 whose base name is the name of the program itself.  (This is a terrible
2298 default but we are stuck with it for historical reasons.)
2299 @vindex _SOURCES
2300 @vindex SOURCES
2302 Multiple programs can be built in a single directory.  Multiple programs
2303 can share a single source file, which must be listed in each
2304 @samp{_SOURCES} definition.
2306 @cindex Header files in _SOURCES
2307 @cindex _SOURCES and header files
2309 Header files listed in a @samp{_SOURCES} definition will be included in
2310 the distribution but otherwise ignored.  In case it isn't obvious, you
2311 should not include the header file generated by @file{configure} in a
2312 @samp{_SOURCES} variable; this file should not be distributed.  Lex
2313 (@samp{.l}) and Yacc (@samp{.y}) files can also be listed; see @ref{Yacc
2314 and Lex}.
2317 @node Linking
2318 @subsection Linking the program
2320 If you need to link against libraries that are not found by
2321 @code{configure}, you can use @code{LDADD} to do so.  This variable is
2322 used to specify additional objects or libraries to link with; it is
2323 inappropriate for specifying specific linker flags, you should use
2324 @code{AM_LDFLAGS} for this purpose.
2325 @vindex LDADD
2326 @vindex AM_LDFLAGS
2328 @cindex prog_LDADD, defined
2330 Sometimes, multiple programs are built in one directory but do not share
2331 the same link-time requirements.  In this case, you can use the
2332 @samp{@var{prog}_LDADD} variable (where @var{prog} is the name of the
2333 program as it appears in some @samp{_PROGRAMS} variable, and usually
2334 written in lowercase) to override the global @code{LDADD}.  If this
2335 variable exists for a given program, then that program is not linked
2336 using @code{LDADD}.
2337 @vindex _LDADD
2339 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
2340 linked against the library @file{libcpio.a}.  However, @code{rmt} is
2341 built in the same directory, and has no such link requirement.  Also,
2342 @code{mt} and @code{rmt} are only built on certain architectures.  Here
2343 is what cpio's @file{src/Makefile.am} looks like (abridged):
2345 @example
2346 bin_PROGRAMS = cpio pax $(MT)
2347 libexec_PROGRAMS = $(RMT)
2348 EXTRA_PROGRAMS = mt rmt
2350 LDADD = ../lib/libcpio.a $(INTLLIBS)
2351 rmt_LDADD =
2353 cpio_SOURCES = @dots{}
2354 pax_SOURCES = @dots{}
2355 mt_SOURCES = @dots{}
2356 rmt_SOURCES = @dots{}
2357 @end example
2359 @cindex _LDFLAGS, defined
2361 @samp{@var{prog}_LDADD} is inappropriate for passing program-specific
2362 linker flags (except for @samp{-l}, @samp{-L}, @samp{-dlopen} and
2363 @samp{-dlpreopen}).  So, use the @samp{@var{prog}_LDFLAGS} variable for
2364 this purpose.
2365 @vindex _LDFLAGS
2367 @cindex _DEPENDENCIES, defined
2369 It is also occasionally useful to have a program depend on some other
2370 target which is not actually part of that program.  This can be done
2371 using the @samp{@var{prog}_DEPENDENCIES} variable.  Each program depends
2372 on the contents of such a variable, but no further interpretation is
2373 done.
2375 If @samp{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
2376 Automake.  The automatically-assigned value is the contents of
2377 @samp{@var{prog}_LDADD}, with most configure substitutions, @samp{-l},
2378 @samp{-L}, @samp{-dlopen} and @samp{-dlpreopen} options removed.  The
2379 configure substitutions that are left in are only @samp{$(LIBOBJS)} and
2380 @samp{$(ALLOCA)}; these are left because it is known that they will not
2381 cause an invalid value for @samp{@var{prog}_DEPENDENCIES} to be
2382 generated.
2385 @node Conditional Sources
2386 @subsection Conditional compilation of sources
2388 You can't put a configure substitution (e.g., @samp{@@FOO@@} or
2389 @samp{$(FOO)} where @code{FOO} is defined via @code{AC_SUBST}) into a
2390 @samp{_SOURCES} variable.  The reason for this is a bit hard to
2391 explain, but suffice to say that it simply won't work.  Automake will
2392 give an error if you try to do this.
2394 Fortunately there are two other ways to achieve the same result.  One is
2395 to use configure substitutions in @code{_LDADD} variables, the other is
2396 to use an Automake conditional.
2398 @subsubsection Conditional compilation using @code{_LDADD} substitutions
2400 @cindex EXTRA_prog_SOURCES, defined
2402 Automake must know all the source files that could possibly go into a
2403 program, even if not all the files are built in every circumstance.  Any
2404 files which are only conditionally built should be listed in the
2405 appropriate @samp{EXTRA_} variable.  For instance, if
2406 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
2407 in @code{hello}, the @file{Makefile.am} would contain:
2409 @example
2410 bin_PROGRAMS = hello
2411 hello_SOURCES = hello-common.c
2412 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
2413 hello_LDADD = $(HELLO_SYSTEM)
2414 hello_DEPENDENCIES = $(HELLO_SYSTEM)
2415 @end example
2417 @noindent
2418 You can then setup the @code{$(HELLO_SYSTEM)} substitution from
2419 @file{configure.in}:
2421 @example
2422 @dots{}
2423 case $host in
2424   *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
2425   *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
2426 esac
2427 AC_SUBST([HELLO_SYSTEM])
2428 @dots{}
2429 @end example
2431 In this case, @code{HELLO_SYSTEM} should be replaced by
2432 @file{hello-linux.o} or @file{hello-bsd.o}, and added to
2433 @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be built
2434 and linked in.
2436 @subsubsection Conditional compilation using Automake conditionals
2438 An often simpler way to compile source files conditionally is to use
2439 Automake conditionals.  For instance, you could use this
2440 @file{Makefile.am} construct to build the same @file{hello} example:
2442 @example
2443 bin_PROGRAMS = hello
2444 if LINUX
2445 hello_SOURCES = hello-linux.c hello-common.c
2446 else
2447 hello_SOURCES = hello-generic.c hello-common.c
2448 endif
2449 @end example
2451 In this case, your @file{configure.in} should setup the @code{LINUX}
2452 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
2454 When using conditionals like this you don't need to use the
2455 @samp{EXTRA_} variable, because Automake will examine the contents of
2456 each variable to construct the complete list of source files.
2458 If your program uses a lot of files, you will probably prefer a
2459 conditional @code{+=}.
2461 @example
2462 bin_PROGRAMS = hello
2463 hello_SOURCES = hello-common.c
2464 if LINUX
2465 hello_SOURCES += hello-linux.c
2466 else
2467 hello_SOURCES += hello-generic.c
2468 endif
2469 @end example
2471 @node Conditional Programs
2472 @subsection Conditional compilation of programs
2473 @cindex Conditional programs
2474 @cindex Programs, conditional
2476 Sometimes it is useful to determine the programs that are to be built
2477 at configure time.  For instance, GNU @code{cpio} only builds
2478 @code{mt} and @code{rmt} under special circumstances.  The means to
2479 achieve conditional compilation of programs are the same you can use
2480 to compile source files conditionally: substitutions or conditionals.
2482 @subsubsection Conditional programs using @code{configure} substitutions
2484 In this case, you must notify Automake of all the programs that can
2485 possibly be built, but at the same time cause the generated
2486 @file{Makefile.in} to use the programs specified by @code{configure}.
2487 This is done by having @code{configure} substitute values into each
2488 @samp{_PROGRAMS} definition, while listing all optionally built programs
2489 in @code{EXTRA_PROGRAMS}.
2490 @vindex EXTRA_PROGRAMS
2491 @cindex EXTRA_PROGRAMS, defined
2493 @example
2494 bin_PROGRAMS = cpio pax $(MT)
2495 libexec_PROGRAMS = $(RMT)
2496 EXTRA_PROGRAMS = mt rmt
2497 @end example
2499 As explained in @ref{EXEEXT}, Automake will rewrite
2500 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
2501 @code{EXTRA_PROGRAMS}, appending @code{$(EXEEXT)} to each binary.
2502 Obviously it cannot rewrite values obtained at run-time through
2503 @code{configure} substitutions, therefore you should take care of
2504 appending @code{$(EXEEXT)} yourself, as in @code{AC_SUBST([MT],
2505 ['mt$@{EXEEXT@}'])}.
2507 @subsubsection Conditional programs using Automake conditionals
2509 You can also use Automake conditionals (@pxref{Conditionals}) to
2510 select programs to be built.  In this case you don't have to worry
2511 about @code{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
2513 @example
2514 bin_PROGRAMS = cpio pax
2515 if WANT_MT
2516   bin_PROGRAMS += mt
2517 endif
2518 if WANT_RMT
2519   libexec_PROGRAMS = rmt
2520 endif
2521 @end example
2524 @node A Library
2525 @section Building a library
2527 @cindex _LIBRARIES primary, defined
2528 @cindex LIBRARIES primary, defined
2529 @cindex Primary variable, LIBRARIES
2531 @vindex lib_LIBRARIES
2532 @vindex pkglib_LIBRARIES
2533 @vindex noinst_LIBRARIES
2535 Building a library is much like building a program.  In this case, the
2536 name of the primary is @samp{LIBRARIES}.  Libraries can be installed in
2537 @code{libdir} or @code{pkglibdir}.
2539 @xref{A Shared Library}, for information on how to build shared
2540 libraries using libtool and the @samp{LTLIBRARIES} primary.
2542 Each @samp{_LIBRARIES} variable is a list of the libraries to be built.
2543 For instance to create a library named @file{libcpio.a}, but not install
2544 it, you would write:
2546 @example
2547 noinst_LIBRARIES = libcpio.a
2548 @end example
2550 The sources that go into a library are determined exactly as they are
2551 for programs, via the @samp{_SOURCES} variables.  Note that the library
2552 name is canonicalized (@pxref{Canonicalization}), so the @samp{_SOURCES}
2553 variable corresponding to @file{liblob.a} is @samp{liblob_a_SOURCES},
2554 not @samp{liblob.a_SOURCES}.
2556 @cindex _LIBADD primary, defined
2557 @cindex LIBADD primary, defined
2558 @cindex Primary variable, LIBADD
2560 Extra objects can be added to a library using the
2561 @samp{@var{library}_LIBADD} variable.  This should be used for objects
2562 determined by @code{configure}.  Again from @code{cpio}:
2563 @vindex _LIBADD
2564 @vindex LIBADD
2566 @example
2567 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
2568 @end example
2570 In addition, sources for extra objects that will not exist until
2571 configure-time must be added to the @code{BUILT_SOURCES} variable
2572 (@pxref{Sources}).
2574 Building a static library is done by compiling all object files, then
2575 by invoking @code{$(AR) $(ARFLAGS)} followed by the name of the
2576 library and the list of objects, and finally by calling
2577 @code{$(RANLIB)} on that library.  You should call
2578 @code{AC_PROG_RANLIB} from your @file{configure.in} to define
2579 @code{RANLIB} (Automake will complain otherwise).  @code{AR} and
2580 @code{ARFLAGS} default to @code{ar} and @code{cru} respectively; you
2581 can override these two variables my setting them in your
2582 @file{Makefile.am}, by @code{AC_SUBST}ing them from your
2583 @file{configure.in}, or by defining a per-library @code{maude_AR}
2584 variable (@pxref{Program and Library Variables}).
2586 @node A Shared Library
2587 @section Building a Shared Library
2589 @cindex Shared libraries, support for
2591 Building shared libraries portably is a relatively complex matter.
2592 For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
2593 Libtool Manual}) was created to help build shared libraries in a
2594 platform-independent way.
2596 @menu
2597 * Libtool Concept::             Introducing Libtool
2598 * Libtool Libraries::           Declaring Libtool Libraries
2599 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
2600 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
2601 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
2602 * Libtool Modules::             Building Libtool Modules
2603 * Libtool Flags::               Using _LIBADD and _LDFLAGS
2604 * LTLIBOBJ::                    Using $(LTLIBOBJ)
2605 * Libtool Issues::              Common Issues Related to Libtool's Use
2606 @end menu
2608 @node Libtool Concept
2609 @subsection The Libtool Concept
2611 @cindex libtool, introduction
2612 @cindex libtool library, definition
2613 @cindex suffix .la, defined
2614 @cindex .la suffix, defined
2616 Libtool abstracts shared and static libraries into a unified
2617 concept henceforth called @dfn{libtool libraries}.  Libtool libraries
2618 are files using the @file{.la} suffix, and can designate a static
2619 library, a shared library, or maybe both.  Their exact nature cannot
2620 be determined until @file{./configure} is run: not all platforms
2621 support all kinds of libraries, and users can explicitly select which
2622 libraries should be built.  (However the package's maintainers can
2623 tune the default, @xref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
2624 macro, libtool, The Libtool Manual}.)
2626 @cindex suffix .lo, defined
2627 Because object files for shared and static libraries must be compiled
2628 differently, libtool is also used during compilation.  Object files
2629 built by libtool are called @dfn{libtool objects}: these are files
2630 using the @file{.lo} suffix.  Libtool libraries are built from these
2631 libtool objects.
2633 You should not assume anything about the structure of @file{.la} or
2634 @file{.lo} files and how libtool constructs them: this is libtool's
2635 concern, and the last thing one wants is to learn about libtool's
2636 guts.  However the existence of these files matters, because they are
2637 used as targets and dependencies in @file{Makefile}s when building
2638 libtool libraries.  There are situations where you may have to refer
2639 to these, for instance when expressing dependencies for building
2640 source files conditionally (@pxref{Conditional Libtool Sources}).
2642 @cindex libltdl, introduction
2644 People considering writing a plug-in system, with dynamically loaded
2645 modules, should look into @file{libltdl}: libtool's dlopening library
2646 (@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
2647 This offers a portable dlopening facility to load libtool libraries
2648 dynamically, and can also achieve static linking where unavoidable.
2650 Before we discuss how to use libtool with Automake in details, it
2651 should be noted that the libtool manual also has a section about how
2652 to use Automake with libtool (@pxref{Using Automake, , Using Automake
2653 with Libtool, libtool, The Libtool Manual}).
2655 @node Libtool Libraries
2656 @subsection Building Libtool Libraries
2658 @cindex _LTLIBRARIES primary, defined
2659 @cindex LTLIBRARIES primary, defined
2660 @cindex Primary variable, LTLIBRARIES
2661 @cindex Example of shared libraries
2662 @vindex lib_LTLIBRARIES
2663 @vindex pkglib_LTLIBRARIES
2665 Automake uses libtool to build libraries declared with the
2666 @samp{LTLIBRARIES} primary.  Each @samp{_LTLIBRARIES} variable is a
2667 list of libtool libraries to build.  For instance, to create a libtool
2668 library named @file{libgettext.la}, and install it in @samp{libdir},
2669 write:
2671 @example
2672 lib_LTLIBRARIES = libgettext.la
2673 libgettext_la_SOURCES = gettext.c gettext.h @dots{}
2674 @end example
2676 Automake predefines the variable @samp{pkglibdir}, so you can use
2677 @code{pkglib_LTLIBRARIES} to install libraries in
2678 @code{$(libdir)/@@PACKAGE@@/}.
2680 @node Conditional Libtool Libraries
2681 @subsection Building Libtool Libraries Conditionally
2682 @cindex libtool libraries, conditional
2683 @cindex conditional libtool libraries
2685 Like conditional programs (@pxref{Conditional Programs}), there are
2686 two main ways to build conditional libraries: using Automake
2687 conditionals or using Autoconf @code{AC_SUBST}itutions.
2689 The important implementation detail you have to be aware of is that
2690 the place where a library will be installed matters to libtool: it
2691 needs to be indicated @emph{at link-time} using the @code{-rpath}
2692 option.
2694 For libraries whose destination directory is known when Automake runs,
2695 Automake will automatically supply the appropriate @samp{-rpath}
2696 option to libtool. This is the case for libraries listed explicitly in
2697 some installable @code{_LTLIBRARIES} variables such as
2698 @code{lib_LTLIBRARIES}.
2700 However, for libraries determined at configure time (and thus
2701 mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
2702 final installation directory.  For such libraries you must add the
2703 @samp{-rpath} option to the appropriate @samp{_LDFLAGS} variable by
2704 hand.
2706 The examples below illustrate the differences between these two methods.
2708 Here is an example where @code{$(WANTEDLIBS)} is an @code{AC_SUBST}ed
2709 variable set at @file{./configure}-time to either @file{libfoo.la},
2710 @file{libbar.la}, both, or none.  Although @code{$(WANTEDLIBS)}
2711 appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
2712 relates to @file{libfoo.la} or @file{libbar.la} by the time it creates
2713 the link rule for these two libraries.  Therefore the @code{-rpath}
2714 argument must be explicitly supplied.
2716 @example
2717 EXTRA_LTLIBRARIES = libfoo.la libbar.la
2718 lib_LTLIBRARIES = $(WANTEDLIBS)
2719 libfoo_la_SOURCES = foo.c @dots{}
2720 libfoo_la_LDFLAGS = -rpath '$(libdir)'
2721 libbar_la_SOURCES = bar.c @dots{}
2722 libbar_la_LDFLAGS = -rpath '$(libdir)'
2723 @end example
2725 Here is how the same @file{Makefile.am} would look using Automake
2726 conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}.  Now
2727 Automake is able to compute the @code{-rpath} setting itself, because
2728 it's clear that both libraries will end up in @code{$(libdir)} if they
2729 are installed.
2731 @example
2732 lib_LTLIBRARIES =
2733 if WANT_LIBFOO
2734 lib_LTLIBRARIES += libfoo.la
2735 endif
2736 if WANT_LIBBAR
2737 lib_LTLIBRARIES += libbar.la
2738 endif
2739 libfoo_la_SOURCES = foo.c @dots{}
2740 libbar_la_SOURCES = bar.c @dots{}
2741 @end example
2743 @node Conditional Libtool Sources
2744 @subsection Libtool Libraries with Conditional Sources
2746 Conditional compilation of sources in a library can be achieved in the
2747 same way as conditional compilation of sources in a program
2748 (@pxref{Conditional Sources}).  The only difference is that
2749 @code{_LIBADD} should be used instead of @code{_LDADD} and that it
2750 should mention libtool objects (@file{.lo} files).
2752 So, to mimic the @file{hello} example from @ref{Conditional Sources},
2753 we could build a @file{libhello.la} library using either
2754 @file{hello-linux.c} or @file{hello-generic.c} with the following
2755 @file{Makefile.am}.
2757 @example
2758 lib_LTLIBRARIES = libhello.la
2759 libhello_la_SOURCES = hello-common.c
2760 EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
2761 libhello_la_LIBADD = $(HELLO_SYSTEM)
2762 libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
2763 @end example
2765 @noindent
2766 And make sure @code{$(HELLO_SYSTEM)} is set to either
2767 @file{hello-linux.lo} or @file{hello-generic.lo} in
2768 @file{./configure}.
2770 Or we could simply use an Automake conditional as follows.
2772 @example
2773 lib_LTLIBRARIES = libhello.la
2774 libhello_la_SOURCES = hello-common.c
2775 if LINUX
2776 libhello_la_SOURCES += hello-linux.c
2777 else
2778 libhello_la_SOURCES += hello-generic.c
2779 endif
2780 @end example
2782 @node Libtool Convenience Libraries
2783 @subsection Libtool Convenience Libraries
2784 @cindex convenience libraries, libtool
2785 @cindex libtool convenience libraries
2786 @vindex noinst_LTLIBRARIES
2787 @vindex check_LTLIBRARIES
2789 Sometimes you want to build libtool libraries which should not be
2790 installed.  These are called @dfn{libtool convenience libraries} and
2791 are typically used to encapsulate many sublibraries, later gathered
2792 into one big installed library.
2794 Libtool convenience libraries are declared by
2795 @code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
2796 @code{EXTRA_LTLIBRARIES}.  Unlike installed libtool libraries they do
2797 not need an @code{-rpath} flag at link time (actually this is the only
2798 difference).
2800 Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
2801 built.  Those listed in @code{check_LTLIBRARIES} are built only upon
2802 @code{make check}.  Finally, libraries listed in
2803 @code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
2804 rules to build them, but if the library does not appear as a Makefile
2805 dependency anywhere it won't be built (this is why
2806 @code{EXTRA_LTLIBRARIES} is used for conditional compilation).
2808 Here is a sample setup merging libtool convenience libraries from
2809 subdirectories into one main @file{libtop.la} library.
2811 @example
2812 # -- Top-level Makefile.am --
2813 SUBDIRS = sub1 sub2 @dots{}
2814 lib_LTLIBRARIES = libtop.la
2815 libtop_la_SOURCES =
2816 libtop_la_LIBADD = \
2817   sub1/libsub1.la \
2818   sub2/libsub2.la \
2819   @dots{}
2821 # -- sub1/Makefile.am --
2822 noinst_LTLIBRARIES = libsub1.la
2823 libsub1_la_SOURCES = @dots{}
2825 # -- sub2/Makefile.am --
2826 # showing nested convenience libraries
2827 SUBDIRS = sub2.1 sub2.2 @dots{}
2828 noinst_LTLIBRARIES = libsub2.la
2829 libsub2_la_SOURCES =
2830 libsub2_la_LIBADD = \
2831   sub21/libsub21.la \
2832   sub22/libsub22.la \
2833   @dots{}
2834 @end example
2836 @node Libtool Modules
2837 @subsection Libtool Modules
2838 @cindex modules, libtool
2839 @cindex libtool modules
2840 @cindex -module, libtool
2842 These are libtool libraries meant to be dlopened.  They are
2843 indicated to libtool by passing @code{-module} at link-time.
2845 @example
2846 pkglib_LTLIBRARIES = mymodule.la
2847 mymodule_la_SOURCES = doit.c
2848 mymodule_LDFLAGS = -module
2849 @end example
2851 Ordinarily, Automake requires that a Library's name starts with
2852 @samp{lib}.  However, when building a dynamically loadable module you
2853 might wish to use a "nonstandard" name.
2855 @node Libtool Flags
2856 @subsection _LIBADD and _LDFLAGS
2857 @cindex _LIBADD, libtool
2858 @cindex _LDFLAGS, libtool
2860 As shown in previous sections, the @samp{@var{library}_LIBADD}
2861 variable should be used to list extra libtool objects (@file{.lo}
2862 files) or libtool libraries (@file{.la}) to add to @var{library}.
2864 The @samp{@var{library}_LDFLAGS} variable is the place to list
2865 additional libtool flags, such as @samp{-version-info},
2866 @samp{-static}, and a lot more.  See @xref{Link mode, , Using libltdl,
2867 libtool, The Libtool Manual}.
2869 @node LTLIBOBJ, Libtool Issues, Libtool Flags, A Shared Library
2870 @subsection @code{LTLIBOBJS}
2871 @cindex @code{LTLIBOBJS}, special handling
2872 @vindex LTLIBOBJS
2873 @vindex LIBOBJS
2874 @cvindex AC_LIBOBJ
2876 Where an ordinary library might include @code{$(LIBOBJS)}, a libtool
2877 library must use @code{$(LTLIBOBJS)}.  This is required because the
2878 object files that libtool operates on do not necessarily end in
2879 @file{.o}.
2881 Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
2882 performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
2883 @code{AC_LIBOBJ} vs. @code{LIBOBJS}, autoconf, The Autoconf Manual}).
2885 @node Libtool Issues
2886 @subsection Common Issues Related to Libtool's Use
2888 @subsubsection @code{required file `./ltmain.sh' not found}
2889 @cindex ltmain.sh not found
2890 @cindex libtoolize, no longer run by Automake
2891 @cindex libtoolize and autoreconf
2892 @cindex autoreconf and libtoolize
2893 @cindex bootstrap.sh and autoreconf
2894 @cindex autogen.sh and autoreconf
2896 Libtool comes with a tool called @command{libtoolize} that will
2897 install libtool's supporting files into a package.  Running this
2898 command will install @file{ltmain.sh}.  You should execute it before
2899 @command{aclocal} and @command{automake}.
2901 People upgrading old packages to newer autotools are likely to face
2902 this issue because older Automake versions used to call
2903 @command{libtoolize}.  Therefore old build scripts do not call
2904 @command{libtoolize}.
2906 Since Automake 1.6, it has been decided that running
2907 @command{libtoolize} was none of Automake's business.  Instead, that
2908 functionality has been moved into the @command{autoreconf} command
2909 (@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
2910 The Autoconf Manual}).  If you do not want to remember what to run and
2911 when, just learn the @command{autoreconf} command.  Hopefully,
2912 replacing existing @file{bootstrap.sh} or @file{autogen.sh} scripts by
2913 a call to @command{autoreconf} should also free you from any similar
2914 incompatible change in the future.
2916 @subsubsection Objects @code{created with both libtool and without}
2918 Sometimes, the same source file is used both to build a libtool
2919 library and to build another non-libtool target (be it a program or
2920 another library).
2922 Let's consider the following @file{Makefile.am}.
2924 @example
2925 bin_PROGRAMS = prog
2926 prog_SOURCES = prog.c foo.c @dots{}
2928 lib_LTLIBRARIES = libfoo.la
2929 libfoo_la_SOURCES = foo.c @dots{}
2930 @end example
2932 @noindent
2933 (In this trivial case the issue could be avoided by linking
2934 @file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
2935 @code{prog_SOURCES}.  But let's assume we really want to keep
2936 @file{prog} and @file{libfoo.la} separate.)
2938 Technically, it means that we should build @file{foo.$(OBJEXT)} for
2939 @file{prog}, and @file{foo.lo} for @file{libfoo.la}.  The problem is
2940 that in the course of creating @file{foo.lo}, libtool may erase (or
2941 replace) @file{foo.$(OBJEXT)} -- and this cannot be avoided.
2943 Therefore, when Automake detects this situation it will complain
2944 with a message such as
2945 @example
2946 object `foo.$(OBJEXT)' created both with libtool and without
2947 @end example
2949 A workaround for this issue is to ensure that these two objects get
2950 different basenames.  As explained in @ref{renamed objects}, this
2951 happens automatically when per-targets flags are used.
2953 @example
2954 bin_PROGRAMS = prog
2955 prog_SOURCES = prog.c foo.c @dots{}
2956 prog_CFLAGS = $(AM_CFLAGS)
2958 lib_LTLIBRARIES = libfoo.la
2959 libfoo_la_SOURCES = foo.c @dots{}
2960 @end example
2962 @noindent
2963 Adding @code{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
2964 when the @code{prog_CFLAGS} is defined, it is used instead of
2965 @code{AM_CFLAGS}.  However as a side effect it will cause
2966 @file{prog.c} and @file{foo.c} to be compiled as
2967 @file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)} which solves
2968 the issue.
2970 @node Program and Library Variables
2971 @section Program and Library Variables
2973 Associated with each program are a collection of variables which can be
2974 used to modify how that program is built.  There is a similar list of
2975 such variables for each library.  The canonical name of the program (or
2976 library) is used as a base for naming these variables.
2978 In the list below, we use the name ``maude'' to refer to the program or
2979 library.  In your @file{Makefile.am} you would replace this with the
2980 canonical name of your program.  This list also refers to ``maude'' as a
2981 program, but in general the same rules apply for both static and dynamic
2982 libraries; the documentation below notes situations where programs and
2983 libraries differ.
2985 @table @samp
2986 @item maude_SOURCES
2987 This variable, if it exists, lists all the source files which are
2988 compiled to build the program.  These files are added to the
2989 distribution by default.  When building the program, Automake will cause
2990 each source file to be compiled to a single @file{.o} file (or
2991 @file{.lo} when using libtool).  Normally these object files are named
2992 after the source file, but other factors can change this.  If a file in
2993 the @samp{_SOURCES} variable has an unrecognized extension, Automake
2994 will do one of two things with it.  If a suffix rule exists for turning
2995 files with the unrecognized extension into @file{.o} files, then
2996 automake will treat this file as it will any other source file
2997 (@pxref{Support for Other Languages}).  Otherwise, the file will be
2998 ignored as though it were a header file.
3000 The prefixes @samp{dist_} and @samp{nodist_} can be used to control
3001 whether files listed in a @samp{_SOURCES} variable are distributed.
3002 @samp{dist_} is redundant, as sources are distributed by default, but it
3003 can be specified for clarity if desired.
3005 It is possible to have both @samp{dist_} and @samp{nodist_} variants of
3006 a given @samp{_SOURCES} variable at once; this lets you easily
3007 distribute some files and not others, for instance:
3009 @example
3010 nodist_maude_SOURCES = nodist.c
3011 dist_maude_SOURCES = dist-me.c
3012 @end example
3014 By default the output file (on Unix systems, the @file{.o} file) will be
3015 put into the current build directory.  However, if the option
3016 @code{subdir-objects} is in effect in the current directory then the
3017 @file{.o} file will be put into the subdirectory named after the source
3018 file.  For instance, with @code{subdir-objects} enabled,
3019 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
3020 people prefer this mode of operation.  You can specify
3021 @code{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
3022 @cindex Subdirectory, objects in
3023 @cindex Objects in subdirectory
3026 @item EXTRA_maude_SOURCES
3027 Automake needs to know the list of files you intend to compile
3028 @emph{statically}.  For one thing, this is the only way Automake has of
3029 knowing what sort of language support a given @file{Makefile.in}
3030 requires.  @footnote{There are other, more obscure reasons reasons for
3031 this limitation as well.}  This means that, for example, you can't put a
3032 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
3033 variable.  If you intend to conditionally compile source files and use
3034 @file{configure} to substitute the appropriate object names into, e.g.,
3035 @samp{_LDADD} (see below), then you should list the corresponding source
3036 files in the @samp{EXTRA_} variable.
3038 This variable also supports @samp{dist_} and @samp{nodist_} prefixes,
3039 e.g., @samp{nodist_EXTRA_maude_SOURCES}.
3041 @item maude_AR
3042 A static library is created by default by invoking @code{$(AR)
3043 $(ARFLAGS)} followed by the name of the library and then the objects
3044 being put into the library.  You can override this by setting the
3045 @samp{_AR} variable.  This is usually used with C++; some C++
3046 compilers require a special invocation in order to instantiate all the
3047 templates which should go into a library.  For instance, the SGI C++
3048 compiler likes this variable set like so:
3049 @example
3050 libmaude_a_AR = $(CXX) -ar -o
3051 @end example
3053 @item maude_LIBADD
3054 Extra objects can be added to a @emph{library} using the @samp{_LIBADD}
3055 variable.  For instance this should be used for objects determined by
3056 @code{configure} (@pxref{A Library}).
3058 @item maude_LDADD
3059 Extra objects can be added to a @emph{program} by listing them in the
3060 @samp{_LDADD} variable.  For instance this should be used for objects
3061 determined by @code{configure} (@pxref{Linking}).
3063 @samp{_LDADD} and @samp{_LIBADD} are inappropriate for passing
3064 program-specific linker flags (except for @samp{-l}, @samp{-L},
3065 @samp{-dlopen} and @samp{-dlpreopen}).  Use the @samp{_LDFLAGS} variable
3066 for this purpose.
3068 For instance, if your @file{configure.in} uses @code{AC_PATH_XTRA}, you
3069 could link your program against the X libraries like so:
3071 @example
3072 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
3073 @end example
3075 @item maude_LDFLAGS
3076 This variable is used to pass extra flags to the link step of a program
3077 or a shared library.
3079 @item maude_DEPENDENCIES
3080 It is also occasionally useful to have a program depend on some other
3081 target which is not actually part of that program.  This can be done
3082 using the @samp{_DEPENDENCIES} variable.  Each program depends on the
3083 contents of such a variable, but no further interpretation is done.
3085 If @samp{_DEPENDENCIES} is not supplied, it is computed by Automake.
3086 The automatically-assigned value is the contents of @samp{_LDADD} or
3087 @samp{_LIBADD}, with most configure substitutions, @samp{-l}, @samp{-L},
3088 @samp{-dlopen} and @samp{-dlpreopen} options removed.  The configure
3089 substitutions that are left in are only @samp{$(LIBOBJS)} and
3090 @samp{$(ALLOCA)}; these are left because it is known that they will not
3091 cause an invalid value for @samp{_DEPENDENCIES} to be generated.
3093 @item maude_LINK
3094 You can override the linker on a per-program basis.  By default the
3095 linker is chosen according to the languages used by the program.  For
3096 instance, a program that includes C++ source code would use the C++
3097 compiler to link.  The @samp{_LINK} variable must hold the name of a
3098 command which can be passed all the @file{.o} file names as arguments.
3099 Note that the name of the underlying program is @emph{not} passed to
3100 @samp{_LINK}; typically one uses @samp{$@@}:
3102 @example
3103 maude_LINK = $(CCLD) -magic -o $@@
3104 @end example
3106 @item maude_CCASFLAGS
3107 @itemx maude_CFLAGS
3108 @itemx maude_CPPFLAGS
3109 @itemx maude_CXXFLAGS
3110 @itemx maude_FFLAGS
3111 @itemx maude_GCJFLAGS
3112 @itemx maude_LFLAGS
3113 @itemx maude_OBJCFLAGS
3114 @itemx maude_RFLAGS
3115 @itemx maude_YFLAGS
3116 @cindex per-target compilation flags, defined
3117 Automake allows you to set compilation flags on a per-program (or
3118 per-library) basis.  A single source file can be included in several
3119 programs, and it will potentially be compiled with different flags for
3120 each program.  This works for any language directly supported by
3121 Automake.  These @dfn{per-target compilation flags} are
3122 @samp{_CCASFLAGS},
3123 @samp{_CFLAGS},
3124 @samp{_CPPFLAGS},
3125 @samp{_CXXFLAGS},
3126 @samp{_FFLAGS},
3127 @samp{_GCJFLAGS},
3128 @samp{_LFLAGS},
3129 @samp{_OBJCFLAGS},
3130 @samp{_RFLAGS}, and
3131 @samp{_YFLAGS}.
3133 When using a per-target compilation flag, Automake will choose a
3134 different name for the intermediate object files.  Ordinarily a file
3135 like @file{sample.c} will be compiled to produce @file{sample.o}.
3136 However, if the program's @samp{_CFLAGS} variable is set, then the
3137 object file will be named, for instance, @file{maude-sample.o}.
3138 (See also @ref{renamed objects}.)
3140 In compilations with per-target flags, the ordinary @samp{AM_} form of
3141 the flags variable is @emph{not} automatically included in the
3142 compilation (however, the user form of the variable @emph{is} included).
3143 So for instance, if you want the hypothetical @file{maude} compilations
3144 to also use the value of @samp{AM_CFLAGS}, you would need to write:
3146 @example
3147 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
3148 @end example
3151 @item maude_SHORTNAME
3152 On some platforms the allowable file names are very short.  In order to
3153 support these systems and per-target compilation flags at the same
3154 time, Automake allows you to set a ``short name'' which will influence
3155 how intermediate object files are named.  For instance, in the following
3156 example,
3158 @example
3159 bin_PROGRAMS = maude
3160 maude_CPPFLAGS = -DSOMEFLAG
3161 maude_SHORTNAME = m
3162 maude_SOURCES = sample.c @dots{}
3163 @end example
3165 @noindent
3166 the object file would be named @file{m-sample.o} rather than
3167 @file{maude-sample.o}.
3169 This facility is rarely needed in practice,
3170 and we recommend avoiding it until you find it is required.
3171 @end table
3173 @node LIBOBJS
3174 @section Special handling for LIBOBJS and ALLOCA
3176 @cindex @code{LIBOBJS}, special handling
3177 @cindex @code{ALLOCA}, special handling
3179 Automake explicitly recognizes the use of @code{$(LIBOBJS)} and
3180 @code{$(ALLOCA)}, and uses this information, plus the list of
3181 @code{LIBOBJS} files derived from @file{configure.in} to automatically
3182 include the appropriate source files in the distribution (@pxref{Dist}).
3183 These source files are also automatically handled in the
3184 dependency-tracking scheme; see @xref{Dependencies}.
3186 @code{$(LIBOBJS)} and @code{$(ALLOCA)} are specially recognized in any
3187 @samp{_LDADD} or @samp{_LIBADD} variable.
3190 @node Program variables
3191 @section Variables used when building a program
3193 Occasionally it is useful to know which @file{Makefile} variables
3194 Automake uses for compilations; for instance you might need to do your
3195 own compilation in some special cases.
3197 Some variables are inherited from Autoconf; these are @code{CC},
3198 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
3199 @code{LIBS}.
3200 @vindex CC
3201 @vindex CFLAGS
3202 @vindex CPPFLAGS
3203 @vindex DEFS
3204 @vindex LDFLAGS
3205 @vindex LIBS
3207 There are some additional variables which Automake itself defines:
3209 @vtable @code
3210 @item AM_CPPFLAGS
3211 The contents of this variable are passed to every compilation which invokes
3212 the C preprocessor; it is a list of arguments to the preprocessor.  For
3213 instance, @samp{-I} and @samp{-D} options should be listed here.
3215 Automake already provides some @samp{-I} options automatically.  In
3216 particular it generates @samp{-I$(srcdir)}, @samp{-I.}, and a @samp{-I}
3217 pointing to the directory holding @file{config.h} (if you've used
3218 @code{AC_CONFIG_HEADERS} or @code{AM_CONFIG_HEADER}).  You can disable
3219 the default @samp{-I} options using the @samp{nostdinc} option.
3221 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
3222 per-library) @code{_CPPFLAGS} variable if it is defined.
3224 @item INCLUDES
3225 This does the same job as @samp{AM_CPPFLAGS}.  It is an older name for
3226 the same functionality.  This variable is deprecated; we suggest using
3227 @samp{AM_CPPFLAGS} instead.
3229 @item AM_CFLAGS
3230 This is the variable which the @file{Makefile.am} author can use to pass
3231 in additional C compiler flags.  It is more fully documented elsewhere.
3232 In some situations, this is not used, in preference to the
3233 per-executable (or per-library) @code{_CFLAGS}.
3235 @item COMPILE
3236 This is the command used to actually compile a C source file.  The
3237 filename is appended to form the complete command line.
3239 @item AM_LDFLAGS
3240 This is the variable which the @file{Makefile.am} author can use to pass
3241 in additional linker flags.  In some situations, this is not used, in
3242 preference to the per-executable (or per-library) @code{_LDFLAGS}.
3244 @item LINK
3245 This is the command used to actually link a C program.  It already
3246 includes @samp{-o $@@} and the usual variable references (for instance,
3247 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
3248 and libraries to link in.
3249 @end vtable
3252 @node Yacc and Lex
3253 @section Yacc and Lex support
3255 Automake has somewhat idiosyncratic support for Yacc and Lex.
3257 Automake assumes that the @file{.c} file generated by @code{yacc} (or
3258 @code{lex}) should be named using the basename of the input file.  That
3259 is, for a yacc source file @file{foo.y}, Automake will cause the
3260 intermediate file to be named @file{foo.c} (as opposed to
3261 @file{y.tab.c}, which is more traditional).
3263 The extension of a yacc source file is used to determine the extension
3264 of the resulting @samp{C} or @samp{C++} file.  Files with the extension
3265 @samp{.y} will be turned into @samp{.c} files; likewise, @samp{.yy} will
3266 become @samp{.cc}; @samp{.y++}, @samp{c++}; and @samp{.yxx},
3267 @samp{.cxx}.
3269 Likewise, lex source files can be used to generate @samp{C} or
3270 @samp{C++}; the extensions @samp{.l}, @samp{.ll}, @samp{.l++}, and
3271 @samp{.lxx} are recognized.
3273 You should never explicitly mention the intermediate (@samp{C} or
3274 @samp{C++}) file in any @samp{SOURCES} variable; only list the source
3275 file.
3277 The intermediate files generated by @code{yacc} (or @code{lex}) will be
3278 included in any distribution that is made.  That way the user doesn't
3279 need to have @code{yacc} or @code{lex}.
3281 If a @code{yacc} source file is seen, then your @file{configure.in} must
3282 define the variable @samp{YACC}.  This is most easily done by invoking
3283 the macro @samp{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
3284 Program Checks, autoconf, The Autoconf Manual}).
3286 When @code{yacc} is invoked, it is passed @samp{YFLAGS} and
3287 @samp{AM_YFLAGS}.  The former is a user variable and the latter is
3288 intended for the @file{Makefile.am} author.
3290 @samp{AM_YFLAGS} is usually used to pass the @code{-d} option to
3291 @code{yacc}.  Automake knows what this means and will automatically
3292 adjust its rules to update and distribute the header file built by
3293 @code{yacc -d}.  What Automake cannot guess, though, is where this
3294 header will be used: it is up to you to ensure the header gets built
3295 before it is first used.  Typically this is necessary in order for
3296 dependency tracking to work when the header is included by another
3297 file.  The common solution is listing the header file in
3298 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
3300 @example
3301 BUILT_SOURCES = parser.h
3302 AM_YFLAGS = -d
3303 bin_PROGRAMS = foo
3304 foo_SOURCES = @dots{} parser.y @dots{}
3305 @end example
3307 If a @code{lex} source file is seen, then your @file{configure.in}
3308 must define the variable @samp{LEX}.  You can use @samp{AC_PROG_LEX}
3309 to do this (@pxref{Particular Programs, , Particular Program Checks,
3310 autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
3311 (@pxref{Macros}) is recommended.
3313 When @code{lex} is invoked, it is passed @samp{LFLAGS} and
3314 @samp{AM_LFLAGS}.  The former is a user variable and the latter is
3315 intended for the @file{Makefile.am} author.
3319 @cindex ylwrap
3320 @cindex yacc, multiple parsers
3321 @cindex Multiple yacc parsers
3322 @cindex Multiple lex lexers
3323 @cindex lex, multiple lexers
3326 Automake makes it possible to include multiple @code{yacc} (or
3327 @code{lex}) source files in a single program.  When there is more than
3328 one distinct @code{yacc} (or @code{lex}) source file in a directory,
3329 Automake uses a small program called @code{ylwrap} to run @code{yacc}
3330 (or @code{lex}) in a subdirectory.  This is necessary because yacc's
3331 output filename is fixed, and a parallel make could conceivably invoke
3332 more than one instance of @code{yacc} simultaneously.  The @code{ylwrap}
3333 program is distributed with Automake.  It should appear in the directory
3334 specified by @samp{AC_CONFIG_AUX_DIR} (@pxref{Input, , Finding
3335 `configure' Input, autoconf, The Autoconf Manual}), or the current
3336 directory if that macro is not used in @file{configure.in}.
3338 For @code{yacc}, simply managing locking is insufficient.  The output of
3339 @code{yacc} always uses the same symbol names internally, so it isn't
3340 possible to link two @code{yacc} parsers into the same executable.
3342 We recommend using the following renaming hack used in @code{gdb}:
3343 @example
3344 #define yymaxdepth c_maxdepth
3345 #define yyparse c_parse
3346 #define yylex   c_lex
3347 #define yyerror c_error
3348 #define yylval  c_lval
3349 #define yychar  c_char
3350 #define yydebug c_debug
3351 #define yypact  c_pact
3352 #define yyr1    c_r1
3353 #define yyr2    c_r2
3354 #define yydef   c_def
3355 #define yychk   c_chk
3356 #define yypgo   c_pgo
3357 #define yyact   c_act
3358 #define yyexca  c_exca
3359 #define yyerrflag c_errflag
3360 #define yynerrs c_nerrs
3361 #define yyps    c_ps
3362 #define yypv    c_pv
3363 #define yys     c_s
3364 #define yy_yys  c_yys
3365 #define yystate c_state
3366 #define yytmp   c_tmp
3367 #define yyv     c_v
3368 #define yy_yyv  c_yyv
3369 #define yyval   c_val
3370 #define yylloc  c_lloc
3371 #define yyreds  c_reds
3372 #define yytoks  c_toks
3373 #define yylhs   c_yylhs
3374 #define yylen   c_yylen
3375 #define yydefred c_yydefred
3376 #define yydgoto c_yydgoto
3377 #define yysindex c_yysindex
3378 #define yyrindex c_yyrindex
3379 #define yygindex c_yygindex
3380 #define yytable  c_yytable
3381 #define yycheck  c_yycheck
3382 #define yyname   c_yyname
3383 #define yyrule   c_yyrule
3384 @end example
3386 For each define, replace the @samp{c_} prefix with whatever you like.
3387 These defines work for @code{bison}, @code{byacc}, and traditional
3388 @code{yacc}s.  If you find a parser generator that uses a symbol not
3389 covered here, please report the new name so it can be added to the list.
3392 @node C++ Support
3393 @section C++ Support
3395 @cindex C++ support
3396 @cindex Support for C++
3398 Automake includes full support for C++.
3400 Any package including C++ code must define the output variable
3401 @samp{CXX} in @file{configure.in}; the simplest way to do this is to use
3402 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
3403 Program Checks, autoconf, The Autoconf Manual}).
3405 A few additional variables are defined when a C++ source file is seen:
3407 @vtable @code
3408 @item CXX
3409 The name of the C++ compiler.
3411 @item CXXFLAGS
3412 Any flags to pass to the C++ compiler.
3414 @item AM_CXXFLAGS
3415 The maintainer's variant of @code{CXXFLAGS}.
3417 @item CXXCOMPILE
3418 The command used to actually compile a C++ source file.  The file name
3419 is appended to form the complete command line.
3421 @item CXXLINK
3422 The command used to actually link a C++ program.
3423 @end vtable
3426 @node Assembly Support
3427 @section Assembly Support
3429 Automake includes some support for assembly code.
3431 The variable @code{CCAS} holds the name of the compiler used to build
3432 assembly code.  This compiler must work a bit like a C compiler; in
3433 particular it must accept @samp{-c} and @samp{-o}.  The value of
3434 @code{CCASFLAGS} is passed to the compilation.
3435 @vindex CCAS
3436 @vindex CCASFLAGS
3438 You are required to set @code{CCAS} and @code{CCASFLAGS} via
3439 @file{configure.in}.  The autoconf macro @code{AM_PROG_AS} will do this
3440 for you.  Unless they are already set, it simply sets @code{CCAS} to the
3441 C compiler and @code{CCASFLAGS} to the C compiler flags.
3443 Only the suffixes @samp{.s} and @samp{.S} are recognized by
3444 @code{automake} as being files containing assembly code.
3447 @node Fortran 77 Support
3448 @comment  node-name,  next,  previous,  up
3449 @section Fortran 77 Support
3451 @cindex Fortran 77 support
3452 @cindex Support for Fortran 77
3454 Automake includes full support for Fortran 77.
3456 Any package including Fortran 77 code must define the output variable
3457 @samp{F77} in @file{configure.in}; the simplest way to do this is to use
3458 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
3459 Program Checks, autoconf, The Autoconf Manual}).  @xref{Fortran 77 and
3460 Autoconf}.
3462 A few additional variables are defined when a Fortran 77 source file is
3463 seen:
3465 @vtable @code
3467 @item F77
3468 The name of the Fortran 77 compiler.
3470 @item FFLAGS
3471 Any flags to pass to the Fortran 77 compiler.
3473 @item AM_FFLAGS
3474 The maintainer's variant of @code{FFLAGS}.
3476 @item RFLAGS
3477 Any flags to pass to the Ratfor compiler.
3479 @item AM_RFLAGS
3480 The maintainer's variant of @code{RFLAGS}.
3482 @item F77COMPILE
3483 The command used to actually compile a Fortran 77 source file.  The file
3484 name is appended to form the complete command line.
3486 @item FLINK
3487 The command used to actually link a pure Fortran 77 program or shared
3488 library.
3490 @end vtable
3492 Automake can handle preprocessing Fortran 77 and Ratfor source files in
3493 addition to compiling them@footnote{Much, if not most, of the
3494 information in the following sections pertaining to preprocessing
3495 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
3496 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
3497 also contains some support for creating programs and shared libraries
3498 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
3499 Fortran 77 With C and C++}).
3501 These issues are covered in the following sections.
3503 @menu
3504 * Preprocessing Fortran 77::
3505 * Compiling Fortran 77 Files::
3506 * Mixing Fortran 77 With C and C++::
3507 * Fortran 77 and Autoconf::
3508 @end menu
3511 @node Preprocessing Fortran 77
3512 @comment  node-name,  next,  previous,  up
3513 @subsection Preprocessing Fortran 77
3515 @cindex Preprocessing Fortran 77
3516 @cindex Fortran 77, Preprocessing
3517 @cindex Ratfor programs
3519 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
3520 rule runs just the preprocessor to convert a preprocessable Fortran 77
3521 or Ratfor source file into a strict Fortran 77 source file.  The precise
3522 command used is as follows:
3524 @table @file
3526 @item .F
3527 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)}
3529 @item .r
3530 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
3532 @end table
3535 @node Compiling Fortran 77 Files
3536 @comment  node-name,  next,  previous,  up
3537 @subsection Compiling Fortran 77 Files
3539 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
3540 @file{N.r} by running the Fortran 77 compiler.  The precise command used
3541 is as follows:
3543 @table @file
3545 @item .f
3546 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
3548 @item .F
3549 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)}
3551 @item .r
3552 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
3554 @end table
3557 @node Mixing Fortran 77 With C and C++
3558 @comment  node-name,  next,  previous,  up
3559 @subsection Mixing Fortran 77 With C and C++
3561 @cindex Fortran 77, mixing with C and C++
3562 @cindex Mixing Fortran 77 with C and C++
3563 @cindex Linking Fortran 77 with C and C++
3564 @cindex cfortran
3565 @cindex Mixing Fortran 77 with C and/or C++
3567 Automake currently provides @emph{limited} support for creating programs
3568 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
3569 However, there are many other issues related to mixing Fortran 77 with
3570 other languages that are @emph{not} (currently) handled by Automake, but
3571 that are handled by other packages@footnote{For example,
3572 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
3573 addresses all of these inter-language issues, and runs under nearly all
3574 Fortran 77, C and C++ compilers on nearly all platforms.  However,
3575 @code{cfortran} is not yet Free Software, but it will be in the next
3576 major release.}.
3578 @page
3579 Automake can help in two ways:
3581 @enumerate
3582 @item
3583 Automatic selection of the linker depending on which combinations of
3584 source code.
3586 @item
3587 Automatic selection of the appropriate linker flags (e.g. @samp{-L} and
3588 @samp{-l}) to pass to the automatically selected linker in order to link
3589 in the appropriate Fortran 77 intrinsic and run-time libraries.
3591 @cindex FLIBS, defined
3592 These extra Fortran 77 linker flags are supplied in the output variable
3593 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro
3594 supplied with newer versions of Autoconf (Autoconf version 2.13 and
3595 later).  @xref{Fortran 77 Compiler Characteristics, , , autoconf, The
3596 Autoconf}.
3597 @end enumerate
3599 If Automake detects that a program or shared library (as mentioned in
3600 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
3601 code that is a mixture of Fortran 77 and C and/or C++, then it requires
3602 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
3603 @file{configure.in}, and that either @code{$(FLIBS)}
3604 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
3605 (for shared libraries) variables.  It is the responsibility of the
3606 person writing the @file{Makefile.am} to make sure that @code{$(FLIBS)}
3607 appears in the appropriate @code{_LDADD} or
3608 @code{_LIBADD} variable.
3610 @cindex Mixed language example
3611 @cindex Example, mixed language
3613 For example, consider the following @file{Makefile.am}:
3615 @example
3616 bin_PROGRAMS = foo
3617 foo_SOURCES  = main.cc foo.f
3618 foo_LDADD    = libfoo.la $(FLIBS)
3620 pkglib_LTLIBRARIES = libfoo.la
3621 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
3622 libfoo_la_LIBADD   = $(FLIBS)
3623 @end example
3625 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
3626 is mentioned in @file{configure.in}.  Also, if @code{$(FLIBS)} hadn't
3627 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
3628 Automake would have issued a warning.
3631 @page
3632 @menu
3633 * How the Linker is Chosen::
3634 @end menu
3636 @node How the Linker is Chosen
3637 @comment  node-name,  next,  previous,  up
3638 @subsubsection How the Linker is Chosen
3640 @cindex Automatic linker selection
3641 @cindex Selecting the linker automatically
3643 The following diagram demonstrates under what conditions a particular
3644 linker is chosen by Automake.
3646 For example, if Fortran 77, C and C++ source code were to be compiled
3647 into a program, then the C++ linker will be used.  In this case, if the
3648 C or Fortran 77 linkers required any special libraries that weren't
3649 included by the C++ linker, then they must be manually added to an
3650 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
3651 @file{Makefile.am}.
3653 @example
3654                      \              Linker
3655           source      \
3656            code        \     C        C++     Fortran
3657      -----------------  +---------+---------+---------+
3658                         |         |         |         |
3659      C                  |    x    |         |         |
3660                         |         |         |         |
3661                         +---------+---------+---------+
3662                         |         |         |         |
3663          C++            |         |    x    |         |
3664                         |         |         |         |
3665                         +---------+---------+---------+
3666                         |         |         |         |
3667                Fortran  |         |         |    x    |
3668                         |         |         |         |
3669                         +---------+---------+---------+
3670                         |         |         |         |
3671      C + C++            |         |    x    |         |
3672                         |         |         |         |
3673                         +---------+---------+---------+
3674                         |         |         |         |
3675      C +       Fortran  |         |         |    x    |
3676                         |         |         |         |
3677                         +---------+---------+---------+
3678                         |         |         |         |
3679          C++ + Fortran  |         |    x    |         |
3680                         |         |         |         |
3681                         +---------+---------+---------+
3682                         |         |         |         |
3683      C + C++ + Fortran  |         |    x    |         |
3684                         |         |         |         |
3685                         +---------+---------+---------+
3686 @end example
3689 @node Fortran 77 and Autoconf
3690 @comment  node-name,  next,  previous,  up
3691 @subsection Fortran 77 and Autoconf
3693 The current Automake support for Fortran 77 requires a recent enough
3694 version of Autoconf that also includes support for Fortran 77.  Full
3695 Fortran 77 support was added to Autoconf 2.13, so you will want to use
3696 that version of Autoconf or later.
3699 @node Java Support
3700 @comment  node-name,  next,  previous,  up
3701 @section Java Support
3703 @cindex Java support
3704 @cindex Support for Java
3706 Automake includes support for compiled Java, using @code{gcj}, the Java
3707 front end to the GNU Compiler Collection.
3709 Any package including Java code to be compiled must define the output
3710 variable @samp{GCJ} in @file{configure.in}; the variable @samp{GCJFLAGS}
3711 must also be defined somehow (either in @file{configure.in} or
3712 @file{Makefile.am}).  The simplest way to do this is to use the
3713 @code{AM_PROG_GCJ} macro.
3715 @vindex GCJFLAGS
3717 By default, programs including Java source files are linked with
3718 @code{gcj}.
3720 As always, the contents of @samp{AM_GCJFLAGS} are passed to every
3721 compilation invoking @code{gcj} (in its role as an ahead-of-time
3722 compiler -- when invoking it to create @file{.class} files,
3723 @samp{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
3724 options to @code{gcj} from @file{Makefile.am}, this variable, and not
3725 the user variable @samp{GCJFLAGS}, should be used.
3727 @vindex AM_GCJFLAGS
3729 @code{gcj} can be used to compile @file{.java}, @file{.class},
3730 @file{.zip}, or @file{.jar} files.
3732 When linking, @code{gcj} requires that the main class be specified
3733 using the @samp{--main=} option.  The easiest way to do this is to use
3734 the @code{_LDFLAGS} variable for the program.
3737 @node Support for Other Languages
3738 @comment  node-name,  next,  previous,  up
3739 @section Support for Other Languages
3741 Automake currently only includes full support for C, C++ (@pxref{C++
3742 Support}), Fortran 77 (@pxref{Fortran 77 Support}), and Java
3743 (@pxref{Java Support}).  There is only rudimentary support for other
3744 languages, support for which will be improved based on user demand.
3746 Some limited support for adding your own languages is available via the
3747 suffix rule handling; see @ref{Suffixes}.
3750 @node ANSI
3751 @section Automatic de-ANSI-fication
3753 @cindex de-ANSI-fication, defined
3755 Although the GNU standards allow the use of ANSI C, this can have the
3756 effect of limiting portability of a package to some older compilers
3757 (notably the SunOS C compiler).
3759 Automake allows you to work around this problem on such machines by
3760 @dfn{de-ANSI-fying} each source file before the actual compilation takes
3761 place.
3763 @vindex AUTOMAKE_OPTIONS
3764 @opindex ansi2knr
3766 If the @file{Makefile.am} variable @code{AUTOMAKE_OPTIONS}
3767 (@pxref{Options}) contains the option @code{ansi2knr} then code to
3768 handle de-ANSI-fication is inserted into the generated
3769 @file{Makefile.in}.
3771 This causes each C source file in the directory to be treated as ANSI C@.
3772 If an ANSI C compiler is available, it is used.  If no ANSI C compiler
3773 is available, the @code{ansi2knr} program is used to convert the source
3774 files into K&R C, which is then compiled.
3776 The @code{ansi2knr} program is simple-minded.  It assumes the source
3777 code will be formatted in a particular way; see the @code{ansi2knr} man
3778 page for details.
3780 Support for de-ANSI-fication requires the source files @file{ansi2knr.c}
3781 and @file{ansi2knr.1} to be in the same package as the ANSI C source;
3782 these files are distributed with Automake.  Also, the package
3783 @file{configure.in} must call the macro @code{AM_C_PROTOTYPES}
3784 (@pxref{Macros}).
3785 @cvindex AM_C_PROTOTYPES
3787 Automake also handles finding the @code{ansi2knr} support files in some
3788 other directory in the current package.  This is done by prepending the
3789 relative path to the appropriate directory to the @code{ansi2knr}
3790 option.  For instance, suppose the package has ANSI C code in the
3791 @file{src} and @file{lib} subdirectories.  The files @file{ansi2knr.c} and
3792 @file{ansi2knr.1} appear in @file{lib}.  Then this could appear in
3793 @file{src/Makefile.am}:
3795 @example
3796 AUTOMAKE_OPTIONS = ../lib/ansi2knr
3797 @end example
3799 If no directory prefix is given, the files are assumed to be in the
3800 current directory.
3802 Note that automatic de-ANSI-fication will not work when the package is
3803 being built for a different host architecture.  That is because automake
3804 currently has no way to build @code{ansi2knr} for the build machine.
3806 @c FIXME: this paragraph might be better moved to an `upgrading' section.
3807 @cindex @code{LTLIBOBJS} and @code{ansi2knr}
3808 @cindex @code{LIBOBJS} and @code{ansi2knr}
3809 @cindex @code{ansi2knr} and @code{LTLIBOBJS}
3810 @cindex @code{ansi2knr} and @code{LIBOBJS}
3811 Using @code{LIBOBJS} with source de-ANSI-fication used to require
3812 hand-crafted code in @file{configure} to append @code{$U} to basenames
3813 in @code{LIBOBJS}.  This is no longer true today.  Starting with version
3814 2.54, Autoconf takes care of rewriting @code{LIBOBJS} and
3815 @code{LTLIBOBJS}.  (@pxref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ}
3816 vs. @code{LIBOBJS}, autoconf, The Autoconf Manual})
3818 @node Dependencies
3819 @section Automatic dependency tracking
3821 As a developer it is often painful to continually update the
3822 @file{Makefile.in} whenever the include-file dependencies change in a
3823 project.  Automake supplies a way to automatically track dependency
3824 changes.
3826 @cindex Dependency tracking
3827 @cindex Automatic dependency tracking
3829 Automake always uses complete dependencies for a compilation, including
3830 system headers.  Automake's model is that dependency computation should
3831 be a side effect of the build.  To this end, dependencies are computed
3832 by running all compilations through a special wrapper program called
3833 @code{depcomp}.  @code{depcomp} understands how to coax many different C
3834 and C++ compilers into generating dependency information in the format
3835 it requires.  @code{automake -a} will install @code{depcomp} into your
3836 source tree for you.  If @code{depcomp} can't figure out how to properly
3837 invoke your compiler, dependency tracking will simply be disabled for
3838 your build.
3840 @cindex depcomp
3842 Experience with earlier versions of Automake @footnote{See
3843 @uref{http://sources.redhat.com/automake/dependencies.html} for more
3844 information on the history and experiences with automatic dependency
3845 tracking in Automake} taught us that it is not reliable to generate
3846 dependencies only on the maintainer's system, as configurations vary too
3847 much.  So instead Automake implements dependency tracking at build time.
3849 Automatic dependency tracking can be suppressed by putting
3850 @code{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
3851 passing @code{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
3852 (this should be the preferred way).  Or, you can invoke @code{automake}
3853 with the @code{-i} option.  Dependency tracking is enabled by default.
3855 @vindex AUTOMAKE_OPTIONS
3856 @opindex no-dependencies
3858 The person building your package also can choose to disable dependency
3859 tracking by configuring with @code{--disable-dependency-tracking}.
3861 @cindex Disabling dependency tracking
3862 @cindex Dependency tracking, disabling
3865 @node EXEEXT
3866 @section Support for executable extensions
3868 @cindex Executable extension
3869 @cindex Extension, executable
3870 @cindex Windows
3872 On some platforms, such as Windows, executables are expected to have an
3873 extension such as @samp{.exe}.  On these platforms, some compilers (GCC
3874 among them) will automatically generate @file{foo.exe} when asked to
3875 generate @file{foo}.
3877 Automake provides mostly-transparent support for this.  Unfortunately
3878 @emph{mostly} doesn't yet mean @emph{fully}.  Until the English
3879 dictionary is revised, you will have to assist Automake if your package
3880 must support those platforms.
3882 One thing you must be aware of is that, internally, Automake rewrites
3883 something like this:
3885 @example
3886 bin_PROGRAMS = liver
3887 @end example
3889 to this:
3891 @example
3892 bin_PROGRAMS = liver$(EXEEXT)
3893 @end example
3895 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
3896 extension.  @code{EXEEXT}
3898 However, Automake cannot apply this rewriting to @code{configure}
3899 substitutions.  This means that if you are conditionally building a
3900 program using such a substitution, then your @file{configure.in} must
3901 take care to add @samp{$(EXEEXT)} when constructing the output variable.
3903 With Autoconf 2.13 and earlier, you must explicitly use @code{AC_EXEEXT}
3904 to get this support.  With Autoconf 2.50, @code{AC_EXEEXT} is run
3905 automatically if you configure a compiler (say, through
3906 @code{AC_PROG_CC}).
3908 Sometimes maintainers like to write an explicit link rule for their
3909 program.  Without executable extension support, this is easy---you
3910 simply write a target with the same name as the program.  However, when
3911 executable extension support is enabled, you must instead add the
3912 @samp{$(EXEEXT)} suffix.
3914 Unfortunately, due to the change in Autoconf 2.50, this means you must
3915 always add this extension.  However, this is a problem for maintainers
3916 who know their package will never run on a platform that has executable
3917 extensions.  For those maintainers, the @code{no-exeext} option
3918 (@pxref{Options}) will disable this feature.  This works in a fairly
3919 ugly way; if @code{no-exeext} is seen, then the presence of a target
3920 named @code{foo} in @file{Makefile.am} will override an
3921 automake-generated target of the form @code{foo$(EXEEXT)}.  Without the
3922 @code{no-exeext} option, this use will give an error.
3925 @node Other objects
3926 @chapter Other Derived Objects
3928 Automake can handle derived objects which are not C programs.  Sometimes
3929 the support for actually building such objects must be explicitly
3930 supplied, but Automake will still automatically handle installation and
3931 distribution.
3933 @menu
3934 * Scripts::                     Executable scripts
3935 * Headers::                     Header files
3936 * Data::                        Architecture-independent data files
3937 * Sources::                     Derived sources
3938 @end menu
3941 @node Scripts
3942 @section Executable Scripts
3944 @cindex _SCRIPTS primary, defined
3945 @cindex SCRIPTS primary, defined
3946 @cindex Primary variable, SCRIPTS
3948 It is possible to define and install programs which are scripts.  Such
3949 programs are listed using the @samp{SCRIPTS} primary name.  Automake
3950 doesn't define any dependencies for scripts; the @file{Makefile.am}
3951 should include the appropriate rules.
3952 @vindex SCRIPTS
3954 Automake does not assume that scripts are derived objects; such objects
3955 must be deleted by hand (@pxref{Clean}).
3957 The @code{automake} program itself is a Perl script that is generated at
3958 configure time from @file{automake.in}.  Here is how this is handled:
3960 @example
3961 bin_SCRIPTS = automake
3962 @end example
3964 Since @code{automake} appears in the @code{AC_OUTPUT} macro, a target
3965 for it is automatically generated, and it is also automatically cleaned
3966 (despite the fact it's a script).
3968 @cindex SCRIPTS, installation directories
3969 @cindex Installing scripts
3971 @vindex bin_SCRIPTS
3972 @vindex sbin_SCRIPTS
3973 @vindex libexec_SCRIPTS
3974 @vindex pkgdata_SCRIPTS
3975 @vindex noinst_SCRIPTS
3976 @vindex check_SCRIPTS
3978 Script objects can be installed in @code{bindir}, @code{sbindir},
3979 @code{libexecdir}, or @code{pkgdatadir}.
3981 Scripts that need not being installed can be listed in
3982 @code{noinst_SCRIPTS}, and among them, those which are needed only by
3983 @code{make check} should go in @code{check_SCRIPTS}.
3986 @node Headers
3987 @section Header files
3989 @cindex _HEADERS primary, defined
3990 @cindex HEADERS primary, defined
3991 @cindex Primary variable, HEADERS
3993 @vindex noinst_HEADERS
3995 Header files are specified by the @samp{HEADERS} family of variables.
3996 Generally header files are not installed, so the @code{noinst_HEADERS}
3997 variable will be the most used.  @footnote{However, for the case of a
3998 non-installed header file that is actually used by a particular program,
3999 we recommend listing it in the program's @samp{_SOURCES} variable
4000 instead of in @code{noinst_HEADERS}.  We believe this is more clear.}
4001 @vindex HEADERS
4003 All header files must be listed somewhere; missing ones will not appear
4004 in the distribution.  Often it is clearest to list uninstalled headers
4005 with the rest of the sources for a program.  @xref{A Program}.  Headers
4006 listed in a @samp{_SOURCES} variable need not be listed in any
4007 @samp{_HEADERS} variable.
4009 @cindex HEADERS, installation directories
4010 @cindex Installing headers
4012 @vindex include_HEADERS
4013 @vindex oldinclude_HEADERS
4014 @vindex pkginclude_HEADERS
4016 Headers can be installed in @code{includedir}, @code{oldincludedir}, or
4017 @code{pkgincludedir}.
4020 @node Data
4021 @section Architecture-independent data files
4023 @cindex _DATA primary, defined
4024 @cindex DATA primary, defined
4025 @cindex Primary variable, DATA
4027 Automake supports the installation of miscellaneous data files using the
4028 @samp{DATA} family of variables.
4029 @vindex DATA
4031 @vindex data_DATA
4032 @vindex sysconf_DATA
4033 @vindex sharedstate_DATA
4034 @vindex localstate_DATA
4035 @vindex pkgdata_DATA
4037 Such data can be installed in the directories @code{datadir},
4038 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
4039 @code{pkgdatadir}.
4041 By default, data files are @emph{not} included in a distribution.  Of
4042 course, you can use the @samp{dist_} prefix to change this on a
4043 per-variable basis.
4045 Here is how Automake declares its auxiliary data files:
4047 @example
4048 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
4049 @end example
4052 @node Sources
4053 @section Built sources
4055 Because Automake's automatic dependency tracking works as a side-effect
4056 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
4057 target should not be compiled before its dependencies are made, but
4058 these dependencies are unknown until the target is first compiled.
4060 Ordinarily this is not a problem, because dependencies are distributed
4061 sources: they preexist and do not need to be built.  Suppose that
4062 @file{foo.c} includes @file{foo.h}.  When it first compiles
4063 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
4064 @file{foo.c}.  As a side-effect of this compilation @code{depcomp}
4065 records the @file{foo.h} dependency so that following invocations of
4066 @command{make} will honor it.  In these conditions, it's clear there is
4067 no problem: either @file{foo.o} doesn't exist and has to be built
4068 (regardless of the dependencies), either accurate dependencies exist and
4069 they can be used to decide whether @file{foo.o} should be rebuilt.
4071 It's a different story if @file{foo.h} doesn't exist by the first
4072 @command{make} run.  For instance there might be a rule to build
4073 @file{foo.h}.  This time @file{file.o}'s build will fail because the
4074 compiler can't find @file{foo.h}. @command{make} failed to trigger the
4075 rule to build @file{foo.h} first by lack of dependency information.
4077 @vindex BUILT_SOURCES
4078 @cindex BUILT_SOURCES, defined
4080 The @code{BUILT_SOURCES} variable is a workaround for this problem.  A
4081 source file listed in @code{BUILT_SOURCES} is made on @code{make all}
4082 or @code{make check} (or even @code{make install}) before other
4083 targets are processed.  However, such a source file is not
4084 @emph{compiled} unless explicitly requested by mentioning it in some
4085 other @samp{_SOURCES} variable.
4087 So, to conclude our introductory example, we could use
4088 @code{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
4089 any other target (including @file{foo.o}) during @code{make all} or
4090 @code{make check}.
4092 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
4093 must be created early in the build process can be listed in this
4094 variable.  Moreover, all built sources do not necessarily have to be
4095 listed in @code{BUILT_SOURCES}.  For instance a generated @file{.c} file
4096 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
4097 another source), because it's a known dependency of the associated
4098 object.
4100 It might be important to emphasize that @code{BUILT_SOURCES} is
4101 honored only by @code{make all}, @code{make check} and @code{make
4102 install}.  This means you cannot build a specific target (e.g.,
4103 @code{make foo}) in a clean tree if it depends on a built source.
4104 However it will succeed if you have run @code{make all} earlier,
4105 because accurate dependencies are already available.
4107 The next section illustrates and discusses the handling of built sources
4108 on a toy example.
4110 @menu
4111 * Built sources example::       Several ways to handle built sources.
4112 @end menu
4114 @node Built sources example
4115 @subsection Built sources example
4117 Suppose that @file{foo.c} includes @file{bindir.h}, which is
4118 installation-dependent and not distributed: it needs to be built.  Here
4119 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
4120 value of the @command{make} variable @code{bindir} (inherited from
4121 @file{configure}).
4123 We suggest several implementations below.  It's not meant to be an
4124 exhaustive listing of all ways to handle built sources, but it will give
4125 you a few ideas if you encounter this issue.
4127 @unnumberedsubsec First try
4129 This first implementation will illustrate the bootstrap issue mentioned
4130 in the previous section (@pxref{Sources}).
4132 Here is a tentative @file{Makefile.am}.
4134 @example
4135 # This won't work.
4136 bin_PROGRAMS = foo
4137 foo_SOURCES = foo.c
4138 nodist_foo_SOURCES = bindir.h
4139 CLEANFILES = bindir.h
4140 bindir.h: Makefile
4141         echo '#define bindir "$(bindir)"' >$@@
4142 @end example
4144 This setup doesn't work, because Automake doesn't know that @file{foo.c}
4145 includes @file{bindir.h}.  Remember, automatic dependency tracking works
4146 as a side-effect of compilation, so the dependencies of @file{foo.o} will
4147 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
4148 The symptom is as follows.
4150 @example
4151 % make
4152 source='foo.c' object='foo.o' libtool=no \
4153 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
4154 depmode=gcc /bin/sh ./depcomp \
4155 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
4156 foo.c:2: bindir.h: No such file or directory
4157 make: *** [foo.o] Error 1
4158 @end example
4160 @unnumberedsubsec Using @code{BUILT_SOURCES}
4162 A solution is to require @file{bindir.h} to be built before anything
4163 else.  This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
4165 @example
4166 bin_PROGRAMS = foo
4167 foo_SOURCES = foo.c
4168 BUILT_SOURCES = bindir.h
4169 CLEANFILES = bindir.h
4170 bindir.h: Makefile
4171         echo '#define bindir "$(bindir)"' >$@@
4172 @end example
4174 See how @file{bindir.h} get built first:
4176 @example
4177 % make
4178 echo '#define bindir "/usr/local/bin"' >bindir.h
4179 make  all-am
4180 make[1]: Entering directory `/home/adl/tmp'
4181 source='foo.c' object='foo.o' libtool=no \
4182 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
4183 depmode=gcc /bin/sh ./depcomp \
4184 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
4185 gcc  -g -O2   -o foo  foo.o
4186 make[1]: Leaving directory `/home/adl/tmp'
4187 @end example
4189 However, as said earlier, @code{BUILT_SOURCES} applies only to the
4190 @code{all}, @code{check}, and @code{install} targets.  It still fails
4191 if you try to run @code{make foo} explicitly:
4193 @example
4194 % make clean
4195 test -z "bindir.h" || rm -f bindir.h
4196 test -z "foo" || rm -f foo
4197 rm -f *.o
4198 % : > .deps/foo.Po # Suppress previously recorded dependencies
4199 % make foo
4200 source='foo.c' object='foo.o' libtool=no \
4201 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
4202 depmode=gcc /bin/sh ./depcomp \
4203 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
4204 foo.c:2: bindir.h: No such file or directory
4205 make: *** [foo.o] Error 1
4206 @end example
4208 @unnumberedsubsec Recording dependencies manually
4210 Usually people are happy enough with @code{BUILT_SOURCES} because they
4211 never run targets such as @code{make foo} before @code{make all}, as in
4212 the previous example.  However if this matters to you, you can avoid
4213 @code{BUILT_SOURCES} and record such dependencies explicitly in the
4214 @file{Makefile.am}.
4216 @example
4217 bin_PROGRAMS = foo
4218 foo_SOURCES = foo.c
4219 foo.$(OBJEXT): bindir.h
4220 CLEANFILES = bindir.h
4221 bindir.h: Makefile
4222         echo '#define bindir "$(bindir)"' >$@@
4223 @end example
4225 You don't have to list @emph{all} the dependencies of @code{foo.o}
4226 explicitly, only those which might need to be built.  If a dependency
4227 already exists, it will not hinder the first compilation and will be
4228 recorded by the normal dependency tracking code.  (Note that after this
4229 first compilation the dependency tracking code will also have recorded
4230 the dependency between @code{foo.o} and @code{bindir.h}; so our explicit
4231 dependency is really useful to the first build only.)
4233 Adding explicit dependencies like this can be a bit dangerous if you are
4234 not careful enough.  This is due to the way Automake tries not to
4235 overwrite your rules (it assumes you know better than it).
4236 @code{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
4237 output to build @code{foo.$(OBJEXT)}.  It happens to work in this case
4238 because Automake doesn't have to output any @code{foo.$(OBJEXT):}
4239 target: it relies on a suffix rule instead (i.e., @code{.c.$(OBJEXT):}).
4240 Always check the generated @file{Makefile.in} if you do this.
4242 @unnumberedsubsec Build @file{bindir.h} from @file{configure}
4244 It's possible to define this preprocessor macro from @file{configure},
4245 either in @file{config.h} (@pxref{Defining Directories, , Defining
4246 Directories, autoconf, The Autoconf Manual}), or by processing a
4247 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
4248 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
4249 Autoconf Manual}).
4251 At this point it should be clear that building @file{bindir.h} from
4252 @file{configure} work well for this example.  @file{bindir.h} will exist
4253 before you build any target, hence will not cause any dependency issue.
4255 The Makefile can be shrunk as follows.  We do not even have to mention
4256 @file{bindir.h}.
4258 @example
4259 bin_PROGRAMS = foo
4260 foo_SOURCES = foo.c
4261 @end example
4263 However, it's not always possible to build sources from
4264 @file{configure}, especially when these sources are generated by a tool
4265 that needs to be built first...
4267 @unnumberedsubsec Build @file{bindir.c}, not @file{bindir.h}.
4269 Another attractive idea is to define @code{bindir} as a variable or
4270 function exported from @file{bindir.o}, and build @file{bindir.c}
4271 instead of @file{bindir.h}.
4273 @example
4274 noinst_PROGRAMS = foo
4275 foo_SOURCES = foo.c bindir.h
4276 nodist_foo_SOURCES = bindir.c
4277 CLEANFILES = bindir.c
4278 bindir.c: Makefile
4279         echo 'const char bindir[] = "$(bindir)";' >$@
4280 @end example
4282 @file{bindir.h} contains just the variable's declaration and doesn't
4283 need to be built, so it won't cause any trouble.  @file{bindir.o} is
4284 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
4285 first.
4287 @unnumberedsubsec Which is best?
4289 There is no panacea, of course.  Each solution has its merits and
4290 drawbacks.
4292 You cannot use @code{BUILT_SOURCES} if the ability to run @code{make
4293 foo} on a clean tree is important to you.
4295 You won't add explicit dependencies if you are leery of overriding
4296 an Automake target by mistake.
4298 Building files from @file{./configure} is not always possible, neither
4299 is converting @file{.h} files into @file{.c} files.
4302 @node Other GNU Tools
4303 @chapter Other GNU Tools
4305 Since Automake is primarily intended to generate @file{Makefile.in}s for
4306 use in GNU programs, it tries hard to interoperate with other GNU tools.
4308 @menu
4309 * Emacs Lisp::                  Emacs Lisp
4310 * gettext::                     Gettext
4311 * Libtool::                     Libtool
4312 * Java::                        Java
4313 * Python::                      Python
4314 @end menu
4317 @node Emacs Lisp
4318 @section Emacs Lisp
4320 @cindex _LISP primary, defined
4321 @cindex LISP primary, defined
4322 @cindex Primary variable, LISP
4324 @vindex LISP
4325 @vindex lisp_LISP
4326 @vindex noinst_LISP
4328 Automake provides some support for Emacs Lisp.  The @samp{LISP} primary
4329 is used to hold a list of @file{.el} files.  Possible prefixes for this
4330 primary are @samp{lisp_} and @samp{noinst_}.  Note that if
4331 @code{lisp_LISP} is defined, then @file{configure.in} must run
4332 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
4334 Automake will byte-compile all Emacs Lisp source files using the Emacs
4335 found by @code{AM_PATH_LISPDIR}, if any was found.  If you wish to
4336 avoid byte-compiling, use @code{lisp_DATA} instead of
4337 @code{lisp_LISP}.
4339 Byte-compiled Emacs Lisp files are not portable among all versions of
4340 Emacs, so it makes sense to turn this off if you expect sites to have
4341 more than one version of Emacs installed.  Furthermore, many packages
4342 don't actually benefit from byte-compilation.  Still, we recommend
4343 that you byte-compile your Emacs Lisp sources.  It is probably better
4344 for sites with strange setups to cope for themselves than to make the
4345 installation less nice for everybody else.
4347 @node gettext
4348 @section Gettext
4350 @cindex GNU Gettext support
4351 @cindex Gettext support
4352 @cindex Support for GNU Gettext
4354 If @code{AM_GNU_GETTEXT} is seen in @file{configure.in}, then Automake
4355 turns on support for GNU gettext, a message catalog system for
4356 internationalization
4357 (@pxref{GNU Gettext, , , gettext, GNU gettext utilities}).
4359 The @code{gettext} support in Automake requires the addition of two
4360 subdirectories to the package, @file{intl} and @file{po}.  Automake
4361 insures that these directories exist and are mentioned in
4362 @code{SUBDIRS}.
4364 @vindex dist_lisp_LISP
4365 @vindex dist_noinst_LISP
4366 Lisp sources are not distributed by default.  You can prefix the
4367 @code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
4368 @code{dist_noinst_LISP}, to indicate that these files should be
4369 distributed.
4371 @node Libtool
4372 @section Libtool
4374 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
4375 libtool, The Libtool Manual}) with the @samp{LTLIBRARIES} primary.
4376 @xref{A Shared Library}.
4379 @node Java
4380 @section Java
4382 @cindex _JAVA primary, defined
4383 @cindex JAVA primary, defined
4384 @cindex Primary variable, JAVA
4386 Automake provides some minimal support for Java compilation with the
4387 @samp{JAVA} primary.
4389 Any @file{.java} files listed in a @samp{_JAVA} variable will be
4390 compiled with @code{JAVAC} at build time.  By default, @file{.class}
4391 files are not included in the distribution.
4393 @cindex JAVA restrictions
4394 @cindex Restrictions for JAVA
4396 Currently Automake enforces the restriction that only one @samp{_JAVA}
4397 primary can be used in a given @file{Makefile.am}.  The reason for this
4398 restriction is that, in general, it isn't possible to know which
4399 @file{.class} files were generated from which @file{.java} files -- so
4400 it would be impossible to know which files to install where.  For
4401 instance, a @file{.java} file can define multiple classes; the resulting
4402 @file{.class} file names cannot be predicted without parsing the
4403 @file{.java} file.
4405 There are a few variables which are used when compiling Java sources:
4407 @vtable @code
4408 @item JAVAC
4409 The name of the Java compiler.  This defaults to @samp{javac}.
4411 @item JAVACFLAGS
4412 The flags to pass to the compiler.  This is considered to be a user
4413 variable (@pxref{User Variables}).
4415 @item AM_JAVACFLAGS
4416 More flags to pass to the Java compiler.  This, and not
4417 @code{JAVACFLAGS}, should be used when it is necessary to put Java
4418 compiler flags into @file{Makefile.am}.
4420 @item JAVAROOT
4421 The value of this variable is passed to the @samp{-d} option to
4422 @code{javac}.  It defaults to @samp{$(top_builddir)}.
4424 @item CLASSPATH_ENV
4425 This variable is an @code{sh} expression which is used to set the
4426 @code{CLASSPATH} environment variable on the @code{javac} command line.
4427 (In the future we will probably handle class path setting differently.)
4428 @end vtable
4431 @node Python
4432 @section Python
4434 @cindex _PYTHON primary, defined
4435 @cindex PYTHON primary, defined
4436 @cindex Primary variable, PYTHON
4439 Automake provides support for Python compilation with the @samp{PYTHON}
4440 primary.
4442 Any files listed in a @samp{_PYTHON} variable will be byte-compiled with
4443 @code{py-compile} at install time.  @code{py-compile} actually creates
4444 both standard (@file{.pyc}) and byte-compiled (@file{.pyo}) versions of
4445 the source files.  Note that because byte-compilation occurs at install
4446 time, any files listed in @samp{noinst_PYTHON} will not be compiled.
4447 Python source files are included in the distribution by default.
4449 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON} which
4450 will determine some Python-related directory variables (see below).  If
4451 you have called @code{AM_PATH_PYTHON} from @file{configure.in}, then you
4452 may use the following variables to list you Python source files in your
4453 variables: @samp{python_PYTHON}, @samp{pkgpython_PYTHON},
4454 @samp{pyexecdir_PYTHON}, @samp{pkgpyexecdir_PYTHON}, depending where you
4455 want your files installed.
4457 @code{AM_PATH_PYTHON([@var{VERSION}], [@var{ACTION-IF-FOUND}],
4458 [@var{ACTION-IF-NOT-FOUND}])} takes three optional arguments.  It will
4459 search a Python interpreter on the system.  The first argument, if
4460 present, is the minimum version of Python required for this package:
4461 @code{AM_PATH_PYTHON} will skip any Python interpreter which is older
4462 than @var{VERSION}.  If an interpreter is found and satisfies
4463 @var{VERSION}, then @var{ACTION-IF-FOUND} is run.  Otherwise,
4464 @var{ACTION-IF-NOT-FOUND} is run.
4466 If @var{ACTION-IF-NOT-FOUND} is not specified, the default is to abort
4467 configure.  This is fine when Python is an absolute requirement for the
4468 package.  Therefore if Python >= 2.2 is only @emph{optional} to the
4469 package, @code{AM_PATH_PYTHON} could be called as follows.
4471 @example
4472   AM_PATH_PYTHON(2.2,, :)
4473 @end example
4475 @code{AM_PATH_PYTHON} creates several output variables based on the
4476 Python installation found during configuration.
4478 @vtable @code
4479 @item PYTHON
4480 The name of the Python executable, or @code{:} if no suitable
4481 interpreter could be found.
4483 Assuming @var{ACTION-IF-NOT-FOUND} is used (otherwise @file{./configure}
4484 will abort if Python is absent), the value of @code{PYTHON} can be used
4485 to setup a conditional in order to disable the relevant part of a build
4486 as follows.
4488 @example
4489   AM_PATH_PYTHON(,, :)
4490   AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
4491 @end example
4494 If the @var{ACTION-IF-NOT-FOUND}
4495 is specified
4497 @item PYTHON_VERSION
4498 The Python version number, in the form @var{major}.@var{minor}
4499 (e.g. @samp{1.5}).  This is currently the value of
4500 @code{sys.version[:3]}.
4502 @item PYTHON_PREFIX
4503 The string @code{$@{prefix@}}.  This term may be used in future work
4504 which needs the contents of Python's @code{sys.prefix}, but general
4505 consensus is to always use the value from configure.
4507 @item PYTHON_EXEC_PREFIX
4508 The string @code{$@{exec_prefix@}}.  This term may be used in future work
4509 which needs the contents of Python's @code{sys.exec_prefix}, but general
4510 consensus is to always use the value from configure.
4512 @item PYTHON_PLATFORM
4513 The canonical name used by Python to describe the operating system, as
4514 given by @code{sys.platform}.  This value is sometimes needed when
4515 building Python extensions.
4517 @item pythondir
4518 The directory name for the @file{site-packages} subdirectory of the
4519 standard Python install tree.
4521 @item pkgpythondir
4522 This is is the directory under @code{pythondir} which is named after the
4523 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
4524 as a convenience.
4526 @item pyexecdir
4527 This is the directory where Python extension modules (shared libraries)
4528 should be installed.
4530 @item pkgpyexecdir
4531 This is a convenience variable which is defined as
4532 @samp{$(pyexecdir)/$(PACKAGE)}.
4533 @end vtable
4535 All these directory variables have values that start with either
4536 @code{$@{prefix@}} or @code{$@{exec_prefix@}} unexpanded.  This works
4537 fine in @file{Makefiles}, but it makes these variables hard to use in
4538 @file{configure}.  This is mandated by the GNU coding standards, so
4539 that the user can run @code{make prefix=/foo install}.  The Autoconf
4540 manual has a section with more details on this topic
4541 (@pxref{Installation Directory Variables, , Installation Directory
4542 Variables, autoconf, The Autoconf Manual}).
4545 @node Documentation
4546 @chapter Building documentation
4548 Currently Automake provides support for Texinfo and man pages.
4550 @menu
4551 * Texinfo::                     Texinfo
4552 * Man pages::                   Man pages
4553 @end menu
4556 @node Texinfo
4557 @section Texinfo
4559 @cindex _TEXINFOS primary, defined
4560 @cindex TEXINFOS primary, defined
4561 @cindex Primary variable, TEXINFOS
4563 If the current directory contains Texinfo source, you must declare it
4564 with the @samp{TEXINFOS} primary.  Generally Texinfo files are converted
4565 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
4566 here.  Any Texinfo source file must end in the @file{.texi},
4567 @file{.txi}, or @file{.texinfo} extension.  We recommend @file{.texi}
4568 for new manuals.
4569 @vindex TEXINFOS
4570 @vindex info_TEXINFOS
4572 Automake generates rules to build @file{.info}, @file{.dvi}, @file{.ps},
4573 @file{.pdf} and @file{.html} files from your Texinfo sources.
4574 The @file{.info} files are built by @code{make all} and installed
4575 by @code{make install} (unless you use @code{no-installinfo}, see below).
4576 The other files can be built on request by @code{make dvi}, @code{make ps},
4577 @code{make pdf} and @code{make html}.
4579 @cindex Texinfo flag, VERSION
4580 @cindex Texinfo flag, UPDATED
4581 @cindex Texinfo flag, EDITION
4582 @cindex Texinfo flag, UPDATED-MONTH
4584 @cindex VERSION Texinfo flag
4585 @cindex UPDATED Texinfo flag
4586 @cindex EDITION Texinfo flag
4587 @cindex UPDATED-MONTH Texinfo flag
4589 @cindex mdate-sh
4591 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
4592 that file will be automatically generated.  The file @file{version.texi}
4593 defines four Texinfo flag you can reference using
4594 @code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
4595 @code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
4597 @table @code
4598 @item EDITION
4599 @itemx VERSION
4600 Both of these flags hold the version number of your program.  They are
4601 kept separate for clarity.
4603 @item UPDATED
4604 This holds the date the primary @file{.texi} file was last modified.
4606 @item UPDATED-MONTH
4607 This holds the name of the month in which the primary @file{.texi} file
4608 was last modified.
4609 @end table
4611 The @file{version.texi} support requires the @code{mdate-sh} program;
4612 this program is supplied with Automake and automatically included when
4613 @code{automake} is invoked with the @code{--add-missing} option.
4615 If you have multiple Texinfo files, and you want to use the
4616 @file{version.texi} feature, then you have to have a separate version
4617 file for each Texinfo file.  Automake will treat any include in a
4618 Texinfo file that matches @samp{vers*.texi} just as an automatically
4619 generated version file.
4621 When an info file is rebuilt, the program named by the @code{MAKEINFO}
4622 variable is used to invoke it.  If the @code{makeinfo} program is found
4623 on the system then it will be used by default; otherwise @code{missing}
4624 will be used instead.  The flags in the variables @code{MAKEINFOFLAGS}
4625 and @code{AM_MAKEINFOFLAGS} will be passed to the @code{makeinfo}
4626 invocation; the first of these is intended for use by the user
4627 (@pxref{User Variables}) and the second by the @file{Makefile.am}
4628 writer.
4629 @vindex MAKEINFO
4630 @vindex MAKEINFOFLAGS
4631 @vindex AM_MAKEINFOFLAGS
4633 Sometimes an info file actually depends on more than one @file{.texi}
4634 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
4635 @file{gpl.texi}.  You can tell Automake about these dependencies using
4636 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
4637 @vindex TEXINFOS
4638 @vindex _TEXINFOS
4640 @example
4641 info_TEXINFOS = hello.texi
4642 hello_TEXINFOS = gpl.texi
4643 @end example
4645 @cindex texinfo.tex
4647 By default, Automake requires the file @file{texinfo.tex} to appear in
4648 the same directory as the Texinfo source.  However, if you used
4649 @code{AC_CONFIG_AUX_DIR} in @file{configure.in} (@pxref{Input, , Finding
4650 `configure' Input, autoconf, The Autoconf Manual}), then
4651 @file{texinfo.tex} is looked for there.  Automake supplies
4652 @file{texinfo.tex} if @samp{--add-missing} is given.
4654 @vindex TEXINFO_TEX
4656 If your package has Texinfo files in many directories, you can use the
4657 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
4658 @file{texinfo.tex} for your package.  The value of this variable should
4659 be the relative path from the current @file{Makefile.am} to
4660 @file{texinfo.tex}:
4662 @example
4663 TEXINFO_TEX = ../doc/texinfo.tex
4664 @end example
4666 @opindex no-texinfo.tex
4668 The option @samp{no-texinfo.tex} can be used to eliminate the
4669 requirement for @file{texinfo.tex}.  Use of the variable
4670 @code{TEXINFO_TEX} is preferable, however, because that allows the
4671 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
4673 @cindex Target, install-info
4674 @cindex Target, noinstall-info
4675 @cindex install-info target
4676 @cindex noinstall-info target
4678 @opindex no-installinfo
4679 @trindex install-info
4681 Automake generates an @code{install-info} target; some people apparently
4682 use this.  By default, info pages are installed by @samp{make install}.
4683 This can be prevented via the @code{no-installinfo} option.
4686 @node Man pages
4687 @section Man pages
4689 @cindex _MANS primary, defined
4690 @cindex MANS primary, defined
4691 @cindex Primary variable, MANS
4693 A package can also include man pages (but see the GNU standards on this
4694 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
4695 pages are declared using the @samp{MANS} primary.  Generally the
4696 @code{man_MANS} variable is used.  Man pages are automatically installed in
4697 the correct subdirectory of @code{mandir}, based on the file extension.
4698 @vindex MANS
4699 @vindex man_MANS
4701 File extensions such as @samp{.1c} are handled by looking for the valid
4702 part of the extension and using that to determine the correct
4703 subdirectory of @code{mandir}.  Valid section names are the digits
4704 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
4706 Sometimes developers prefer to name a man page something like
4707 @file{foo.man} in the source, and then rename it to have the correct
4708 suffix, e.g. @file{foo.1}, when installing the file.  Automake also
4709 supports this mode.  For a valid section named @var{SECTION}, there is a
4710 corresponding directory named @samp{man@var{SECTION}dir}, and a
4711 corresponding @samp{_MANS} variable.  Files listed in such a variable
4712 are installed in the indicated section.  If the file already has a
4713 valid suffix, then it is installed as-is; otherwise the file suffix is
4714 changed to match the section.
4716 For instance, consider this example:
4717 @example
4718 man1_MANS = rename.man thesame.1 alsothesame.1c
4719 @end example
4721 In this case, @file{rename.man} will be renamed to @file{rename.1} when
4722 installed, but the other files will keep their names.
4724 @cindex Target, install-man
4725 @cindex Target, noinstall-man
4726 @cindex install-man target
4727 @cindex noinstall-man target
4729 @c Use @samp{make install} per documentation: (texi)code.
4730 By default, man pages are installed by @samp{make install}.  However,
4731 since the GNU project does not require man pages, many maintainers do
4732 not expend effort to keep the man pages up to date.  In these cases, the
4733 @code{no-installman} option will prevent the man pages from being
4734 installed by default.  The user can still explicitly install them via
4735 @samp{make install-man}.
4736 @opindex no-installman
4737 @trindex install-man
4739 Here is how the man pages are handled in GNU @code{cpio} (which includes
4740 both Texinfo documentation and man pages):
4742 @example
4743 man_MANS = cpio.1 mt.1
4744 EXTRA_DIST = $(man_MANS)
4745 @end example
4747 Man pages are not currently considered to be source, because it is not
4748 uncommon for man pages to be automatically generated.  Therefore they
4749 are not automatically included in the distribution.  However, this can
4750 be changed by use of the @samp{dist_} prefix.
4752 The @samp{nobase_} prefix is meaningless for man pages and is
4753 disallowed.
4756 @node Install
4757 @chapter What Gets Installed
4759 @cindex Installation support
4760 @cindex make install support
4762 @section Basics of installation
4764 Naturally, Automake handles the details of actually installing your
4765 program once it has been built.  All files named by the various
4766 primaries are automatically installed in the appropriate places when the
4767 user runs @code{make install}.
4769 A file named in a primary is installed by copying the built file into
4770 the appropriate directory.  The base name of the file is used when
4771 installing.
4773 @example
4774 bin_PROGRAMS = hello subdir/goodbye
4775 @end example
4777 In this example, both @samp{hello} and @samp{goodbye} will be installed
4778 in @code{$(bindir)}.
4780 Sometimes it is useful to avoid the basename step at install time.  For
4781 instance, you might have a number of header files in subdirectories of
4782 the source tree which are laid out precisely how you want to install
4783 them.  In this situation you can use the @samp{nobase_} prefix to
4784 suppress the base name step.  For example:
4786 @example
4787 nobase_include_HEADERS = stdio.h sys/types.h
4788 @end example
4790 Will install @file{stdio.h} in @code{$(includedir)} and @file{types.h}
4791 in @code{$(includedir)/sys}.
4793 @section The two parts of install
4795 Automake generates separate @code{install-data} and @code{install-exec}
4796 targets, in case the installer is installing on multiple machines which
4797 share directory structure---these targets allow the machine-independent
4798 parts to be installed only once.  @code{install-exec} installs
4799 platform-dependent files, and @code{install-data} installs
4800 platform-independent files.  The @code{install} target depends on both
4801 of these targets.  While Automake tries to automatically segregate
4802 objects into the correct category, the @file{Makefile.am} author is, in
4803 the end, responsible for making sure this is done correctly.
4804 @trindex install-data
4805 @trindex install-exec
4806 @trindex install
4807 @cindex Install, two parts of
4809 Variables using the standard directory prefixes @samp{data},
4810 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
4811 @samp{pkgdata}, or @samp{pkginclude} (e.g. @samp{data_DATA}) are
4812 installed by @samp{install-data}.
4814 Variables using the standard directory prefixes @samp{bin}, @samp{sbin},
4815 @samp{libexec}, @samp{sysconf}, @samp{localstate}, @samp{lib}, or
4816 @samp{pkglib} (e.g. @samp{bin_PROGRAMS}) are installed by
4817 @samp{install-exec}.
4819 Any variable using a user-defined directory prefix with @samp{exec} in
4820 the name (e.g. @samp{myexecbin_PROGRAMS} is installed by
4821 @samp{install-exec}.  All other user-defined prefixes are installed by
4822 @samp{install-data}.
4824 @section Extending installation
4826 It is possible to extend this mechanism by defining an
4827 @code{install-exec-local} or @code{install-data-local} target.  If these
4828 targets exist, they will be run at @samp{make install} time.  These
4829 rules can do almost anything; care is required.
4830 @trindex install-exec-local
4831 @trindex install-data-local
4833 Automake also supports two install hooks, @code{install-exec-hook} and
4834 @code{install-data-hook}.  These hooks are run after all other install
4835 rules of the appropriate type, exec or data, have completed.  So, for
4836 instance, it is possible to perform post-installation modifications
4837 using an install hook.
4838 @cindex Install hook
4840 @section Staged installs
4842 @vindex DESTDIR
4843 Automake generates support for the @samp{DESTDIR} variable in all
4844 install rules.  @samp{DESTDIR} is used during the @samp{make install}
4845 step to relocate install objects into a staging area.  Each object and
4846 path is prefixed with the value of @samp{DESTDIR} before being copied
4847 into the install area.  Here is an example of typical DESTDIR usage:
4849 @example
4850 make DESTDIR=/tmp/staging install
4851 @end example
4853 This places install objects in a directory tree built under
4854 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
4855 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
4856 would install @file{/tmp/staging/gnu/bin/foo} and
4857 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
4859 This feature is commonly used to build install images and packages.  For
4860 more information, see @ref{Makefile Conventions, , , standards, The GNU
4861 Coding Standards}.
4863 Support for @samp{DESTDIR} is implemented by coding it directly into the
4864 install rules.  If your @file{Makefile.am} uses a local install rule
4865 (e.g., @code{install-exec-local}) or an install hook, then you must
4866 write that code to respect @samp{DESTDIR}.
4868 @section Rules for the user
4870 Automake also generates an @code{uninstall} target, an
4871 @code{installdirs} target, and an @code{install-strip} target.
4872 @trindex uninstall
4873 @trindex installdirs
4874 @trindex install-strip
4876 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
4877 There is no notion of separate uninstalls for ``exec'' and ``data'', as
4878 these features would not provide additional functionality.
4880 Note that @code{uninstall} is not meant as a replacement for a real
4881 packaging tool.
4884 @node Clean
4885 @chapter What Gets Cleaned
4887 @cindex make clean support
4889 The GNU Makefile Standards specify a number of different clean rules.
4890 See @xref{Standard Targets, , Standard Targets for Users, standards,
4891 The GNU Coding Standards}.
4893 Generally the files that can be cleaned are determined automatically by
4894 Automake.  Of course, Automake also recognizes some variables that can
4895 be defined to specify additional files to clean.  These variables are
4896 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
4897 @code{MAINTAINERCLEANFILES}.
4898 @vindex MOSTLYCLEANFILES
4899 @vindex CLEANFILES
4900 @vindex DISTCLEANFILES
4901 @vindex MAINTAINERCLEANFILES
4903 As the GNU Standards aren't always explicit as to which files should be
4904 removed by which target, we've adopted a heuristic which we believe was
4905 first formulated by Fran@,{c}ois Pinard:
4907 @itemize @bullet
4908 @item
4909 If @code{make} built it, and it is commonly something that one would
4910 want to rebuild (for instance, a @file{.o} file), then
4911 @code{mostlyclean} should delete it.
4913 @item
4914 Otherwise, if @code{make} built it, then @code{clean} should delete it.
4916 @item
4917 If @code{configure} built it, then @code{distclean} should delete it.
4919 @item
4920 If the maintainer built it (for instance, a @file{.info} file), then
4921 @code{maintainer-clean} should delete it.  However
4922 @code{maintainer-clean} should not delete anything that needs to exist
4923 in order to run @code{./configure && make}.
4924 @end itemize
4926 We recommend that you follow this same set of heuristics in your
4927 @file{Makefile.am}.
4930 @node Dist
4931 @chapter What Goes in a Distribution
4933 @section Basics of distribution
4935 @cindex make dist
4937 The @code{dist} target in the generated @file{Makefile.in} can be used
4938 to generate a gzip'd @code{tar} file and other flavors of archive for
4939 distribution.  The files is named based on the @samp{PACKAGE} and
4940 @samp{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
4941 (@pxref{Macros}); more precisely the gzip'd @code{tar} file is named
4942 @samp{@var{package}-@var{version}.tar.gz}.
4943 @cvindex PACKAGE
4944 @cvindex VERSION
4945 @trindex dist
4946 You can use the @code{make} variable @samp{GZIP_ENV} to control how gzip
4947 is run.  The default setting is @samp{--best}.
4949 For the most part, the files to distribute are automatically found by
4950 Automake: all source files are automatically included in a distribution,
4951 as are all @file{Makefile.am}s and @file{Makefile.in}s.  Automake also
4952 has a built-in list of commonly used files which are automatically
4953 included if they are found in the current directory (either physically,
4954 or as the target of a @file{Makefile.am} rule).  This list is printed by
4955 @samp{automake --help}.  Also, files which are read by @code{configure}
4956 (i.e. the source files corresponding to the files specified in various
4957 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
4958 automatically distributed.  Files included in @file{Makefile.am}s (using
4959 @code{include}) or in @file{configure.in} (using @code{m4_include}), and
4960 helper scripts installed with @samp{automake --add-missing} are also
4961 distributed.
4963 @cvindex m4_include, distribution
4965 Still, sometimes there are files which must be distributed, but which
4966 are not covered in the automatic rules.  These files should be listed in
4967 the @code{EXTRA_DIST} variable.  You can mention files from
4968 subdirectories in @code{EXTRA_DIST}.
4970 You can also mention a directory in @code{EXTRA_DIST}; in this case the
4971 entire directory will be recursively copied into the distribution.
4972 Please note that this will also copy @emph{everything} in the directory,
4973 including CVS/RCS version control files.  We recommend against using
4974 this feature.
4975 @vindex EXTRA_DIST
4977 If you define @code{SUBDIRS}, Automake will recursively include the
4978 subdirectories in the distribution.  If @code{SUBDIRS} is defined
4979 conditionally (@pxref{Conditionals}), Automake will normally include all
4980 directories that could possibly appear in @code{SUBDIRS} in the
4981 distribution.  If you need to specify the set of directories
4982 conditionally, you can set the variable @code{DIST_SUBDIRS} to the exact
4983 list of subdirectories to include in the distribution (@pxref{Top level}).
4984 @vindex DIST_SUBDIRS
4987 @section Fine-grained distribution control
4989 Sometimes you need tighter control over what does @emph{not} go into the
4990 distribution; for instance you might have source files which are
4991 generated and which you do not want to distribute.  In this case
4992 Automake gives fine-grained control using the @samp{dist} and
4993 @samp{nodist} prefixes.  Any primary or @samp{_SOURCES} variable can be
4994 prefixed with @samp{dist_} to add the listed files to the distribution.
4995 Similarly, @samp{nodist_} can be used to omit the files from the
4996 distribution.
4997 @vindex dist_
4998 @vindex nodist_
5000 As an example, here is how you would cause some data to be distributed
5001 while leaving some source code out of the distribution:
5003 @example
5004 dist_data_DATA = distribute-this
5005 bin_PROGRAMS = foo
5006 nodist_foo_SOURCES = do-not-distribute.c
5007 @end example
5009 @section The dist hook
5011 @trindex dist-hook
5013 Occasionally it is useful to be able to change the distribution before
5014 it is packaged up.  If the @code{dist-hook} target exists, it is run
5015 after the distribution directory is filled, but before the actual tar
5016 (or shar) file is created.  One way to use this is for distributing
5017 files in subdirectories for which a new @file{Makefile.am} is overkill:
5019 @example
5020 dist-hook:
5021         mkdir $(distdir)/random
5022         cp -p $(srcdir)/random/a1 $(srcdir)/random/a2 $(distdir)/random
5023 @end example
5025 Another way to to use this is for removing unnecessary files that get
5026 recursively included by specifying a directory in EXTRA_DIST:
5028 @example
5029 EXTRA_DIST = doc
5031 dist-hook:
5032         rm -rf `find $(distdir)/doc -name CVS`
5033 @end example
5035 @vindex distdir
5036 @vindex top_distdir
5037 Two variables that come handy when writing @code{dist-hook} targets are
5038 @code{$(distdir)} and @code{$(top_distdir)}.
5040 @code{$(distdir)} points to the directory where the @code{dist} target
5041 will copy files from the current directory before creating the
5042 tarball.  If you are at the top-level directory, then @code{distdir =
5043 $(PACKAGE)-$(VERSION)}.  When used from subdirectory named
5044 @file{foo/}, then @code{distdir = ../$(PACKAGE)-$(VERSION)/foo}.
5046 @code{$(top_distdir)} always points to the root directory of the
5047 distributed tree.  At the top-level it's equal to @code{$(distdir)}.
5048 In the @file{foo/} subdirectory
5049 @code{top_distdir = ../$(PACKAGE)-$(VERSION)}.
5051 Note that when packages are nested using @code{AC_CONFIG_SUBDIRS}
5052 (@pxref{Subdirectories, AC_CONFIG_SUBDIRS, Configuring Other Packages
5053 in Subdirectories, autoconf, The Autoconf Manual}), then
5054 @code{$(distdir)} and @code{$(top_distdir)} are relative to the
5055 package where @code{make dist} was run, not to any sub-packages
5056 involved.
5058 @section Checking the distribution
5060 @cindex make distcheck
5061 @cindex make distcleancheck
5062 @vindex distcleancheck_listfiles
5063 @cindex make distuninstallcheck
5064 @vindex distuninstallcheck_listfiles
5066 Automake also generates a @code{distcheck} target which can be of help
5067 to ensure that a given distribution will actually work.
5068 @code{distcheck} makes a distribution, then tries to do a @code{VPATH}
5069 build, run the test suite, and finally make another tarfile to ensure the
5070 distribution is self-contained.
5071 @trindex distcheck
5073 Building the package involves running @code{./configure}.  If you need
5074 to supply additional flags to @code{configure}, define them in the
5075 @code{DISTCHECK_CONFIGURE_FLAGS} variable, either in your top-level
5076 @file{Makefile.am}, or on the command line when invoking @code{make}.
5077 @vindex DISTCHECK_CONFIGURE_FLAGS
5079 If the target @code{distcheck-hook} is defined in your
5080 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
5081 the new distribution has been unpacked, but before the unpacked copy is
5082 configured and built.  Your @code{distcheck-hook} can do almost
5083 anything, though as always caution is advised.  Generally this hook is
5084 used to check for potential distribution errors not caught by the
5085 standard mechanism.
5087 Speaking about potential distribution errors, @code{distcheck} will also
5088 ensure that the @code{distclean} target actually removes all built
5089 files.  This is done by running @code{make distcleancheck} at the end of
5090 the @code{VPATH} build.  By default, @code{distcleancheck} will run
5091 @code{distclean} and then make sure the build tree has been emptied by
5092 running @code{$(distcleancheck_listfiles)}.  Usually this check will
5093 find generated files that you forgot to add to the @code{DISTCLEANFILES}
5094 variable (@pxref{Clean}).
5095 @trindex distcleancheck
5097 The @code{distcleancheck} behavior should be OK for most packages,
5098 otherwise you have the possibility to override the definition of
5099 either the @code{distcleancheck} target, or the
5100 @code{$(distcleancheck_listfiles)} variable.  For instance to disable
5101 @code{distcleancheck} completely, add the following rule to your
5102 top-level @file{Makefile.am}:
5103 @vindex distcleancheck_listfiles
5105 @example
5106 distcleancheck:
5107         @@:
5108 @end example
5110 If you want @code{distcleancheck} to ignore built files which have not
5111 been cleaned because they are also part of the distribution, add the
5112 following definition instead:
5114 @example
5115 distcleancheck_listfiles = \
5116   find -type f -exec sh -c 'test -f $(srcdir)/@{@} || echo @{@}' ';'
5117 @end example
5119 The above definition is not the default because it's usually an error if
5120 your Makefiles cause some distributed files to be rebuilt when the user
5121 build the package.  (Think about the user missing the tool required to
5122 build the file; or if the required tool is built by your package,
5123 consider the cross-compilation case where it can't be run.)  There is
5124 a FAQ entry about this (@pxref{distcleancheck}), make sure you read it
5125 before playing with @code{distcleancheck_listfiles}.
5127 @code{distcheck} also checks that the @code{uninstall} target works
5128 properly, both for ordinary and @samp{DESTDIR} builds.  It does this
5129 by invoking @code{make uninstall}, and then it checks the install tree
5130 to see if any files are left over.  This check will make sure that you
5131 correctly coded your @code{uninstall}-related targets.
5133 By default, the checking is done by the @code{distuninstallcheck} target,
5134 and the list of files in the install tree is generated by
5135 @code{$(distuninstallcheck_listfiles}) (this is a variable whose value is
5136 a shell command to run that prints the list of files to stdout).
5138 Either of these can be overridden to modify the behavior of
5139 @code{distcheck}.  For instance, to disable this check completely, you
5140 would write:
5142 @example
5143 distuninstallcheck:
5144         @@:
5145 @end example
5147 @section The types of distributions
5149 Automake generates targets to provide archives of the project for
5150 distributions in various formats.  These targets are:
5152 @table @asis
5153 @item @code{dist-bzip2}
5154 Generate a bzip2 tar archive of the distribution.  bzip2 archives are
5155 frequently smaller than gzipped archives.
5156 @trindex dist-bzip2
5158 @item @code{dist-gzip}
5159 Generate a gzip tar archive of the distribution.
5160 @trindex dist-gzip
5162 @item @code{dist-shar}
5163 Generate a shar archive of the distribution.
5164 @trindex dist-shar
5166 @item @code{dist-zip}
5167 Generate a zip archive of the distribution.
5168 @trindex dist-zip
5170 @item @code{dist-tarZ}
5171 Generate a compressed tar archive of
5172 the distribution.
5173 @trindex dist-tarZ
5174 @end table
5176 The targets @code{dist} and its synonym @code{dist-all} will create
5177 archives in all the enabled formats, @ref{Options}.  By default, only
5178 the @code{dist-gzip} target is hooked to @code{dist}.
5181 @node Tests
5182 @chapter Support for test suites
5184 @cindex Test suites
5185 @cindex make check
5187 Automake supports two forms of test suites.
5189 @section Simple Tests
5191 If the variable @code{TESTS} is defined, its value is taken to be a list
5192 of programs to run in order to do the testing.  The programs can either
5193 be derived objects or source objects; the generated rule will look both
5194 in @code{srcdir} and @file{.}.  Programs needing data files should look
5195 for them in @code{srcdir} (which is both an environment variable and a
5196 make variable) so they work when building in a separate directory
5197 (@pxref{Build Directories, , Build Directories , autoconf, The Autoconf
5198 Manual}), and in particular for the @code{distcheck} target
5199 (@pxref{Dist}).
5201 @cindex Exit status 77, special interpretation
5203 The number of failures will be printed at the end of the run.  If a
5204 given test program exits with a status of 77, then its result is ignored
5205 in the final count.  This feature allows non-portable tests to be
5206 ignored in environments where they don't make sense.
5208 The variable @code{TESTS_ENVIRONMENT} can be used to set environment
5209 variables for the test run; the environment variable @code{srcdir} is
5210 set in the rule.  If all your test programs are scripts, you can also
5211 set @code{TESTS_ENVIRONMENT} to an invocation of the shell (e.g.
5212 @samp{$(SHELL) -x}); this can be useful for debugging the tests.
5213 @vindex TESTS
5214 @vindex TESTS_ENVIRONMENT
5216 @cindex Tests, expected failure
5217 @cindex Expected test failure
5219 You may define the variable @code{XFAIL_TESTS} to a list of tests
5220 (usually a subset of @code{TESTS}) that are expected to fail.  This will
5221 reverse the result of those tests.
5222 @vindex XFAIL_TESTS
5224 Automake ensures that each program listed in @code{TESTS} is built
5225 before any tests are run; you can list both source and derived programs
5226 in @code{TESTS}.  For instance, you might want to run a C program as a
5227 test.  To do this you would list its name in @code{TESTS} and also in
5228 @code{check_PROGRAMS}, and then specify it as you would any other
5229 program.
5231 @section DejaGnu Tests
5233 If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @samp{dejagnu}} appears in
5234 @code{AUTOMAKE_OPTIONS}, then a @code{dejagnu}-based test suite is
5235 assumed.  The variable @code{DEJATOOL} is a list of names which are
5236 passed, one at a time, as the @code{--tool} argument to @code{runtest}
5237 invocations; it defaults to the name of the package.
5239 The variable @code{RUNTESTDEFAULTFLAGS} holds the @code{--tool} and
5240 @code{--srcdir} flags that are passed to dejagnu by default; this can be
5241 overridden if necessary.
5242 @vindex RUNTESTDEFAULTFLAGS
5244 The variables @code{EXPECT} and @code{RUNTEST} can
5245 also be overridden to provide project-specific values.  For instance,
5246 you will need to do this if you are testing a compiler toolchain,
5247 because the default values do not take into account host and target
5248 names.
5249 @opindex dejagnu
5250 @vindex DEJATOOL
5251 @vindex EXPECT
5252 @vindex RUNTEST
5254 The contents of the variable @code{RUNTESTFLAGS} are passed to the
5255 @code{runtest} invocation.  This is considered a ``user variable''
5256 (@pxref{User Variables}).  If you need to set @code{runtest} flags in
5257 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
5258 @vindex RUNTESTFLAGS
5259 @vindex AM_RUNTESTFLAGS
5261 @cindex @file{site.exp}
5262 Automake will generate rules to create a local @file{site.exp} file,
5263 defining various variables detected by @code{./configure}.  This file
5264 is automatically read by DejaGnu.  It is OK for the user of a package
5265 to edit this file in order to tune the test suite.  However this is
5266 not the place where the test suite author should define new variables:
5267 this should be done elsewhere in the real test suite code.
5268 Especially, @file{site.exp} should not be distributed.
5270 For more information regarding DejaGnu test suites, see @xref{Top, , ,
5271 dejagnu, The DejaGnu Manual}.
5273 In either case, the testing is done via @samp{make check}.
5275 @section Install Tests
5277 The @code{installcheck} target is available to the user as a way to run
5278 any tests after the package has been installed.  You can add tests to
5279 this by writing an @code{installcheck-local} target.
5282 @node Options
5283 @chapter Changing Automake's Behavior
5285 Various features of Automake can be controlled by options in the
5286 @file{Makefile.am}.  Such options are applied on a per-@file{Makefile}
5287 basis when listed in a special @file{Makefile} variable named
5288 @code{AUTOMAKE_OPTIONS}.  They are applied globally to all processed
5289 @file{Makefiles} when listed in the first argument of
5290 @code{AM_INIT_AUTOMAKE} in @file{configure.in}.  Currently understood
5291 options are:
5292 @vindex AUTOMAKE_OPTIONS
5294 @table @asis
5295 @item @code{gnits}
5296 @itemx @code{gnu}
5297 @itemx @code{foreign}
5298 @itemx @code{cygnus}
5299 @cindex Option, gnits
5300 @cindex Option, gnu
5301 @cindex Option, foreign
5302 @cindex Option, cygnus
5304 Set the strictness as appropriate.  The @code{gnits} option also implies
5305 @code{readme-alpha} and @code{check-news}.
5307 @item @code{ansi2knr}
5308 @itemx @code{@var{path}/ansi2knr}
5309 @cindex Option, ansi2knr
5310 Turn on automatic de-ANSI-fication.  @xref{ANSI}.  If preceded by a
5311 path, the generated @file{Makefile.in} will look in the specified
5312 directory to find the @file{ansi2knr} program.  The path should be a
5313 relative path to another directory in the same distribution (Automake
5314 currently does not check this).
5316 @item @code{check-news}
5317 @cindex Option, check-news
5318 Cause @code{make dist} to fail unless the current version number appears
5319 in the first few lines of the @file{NEWS} file.
5321 @item @code{dejagnu}
5322 @cindex Option, dejagnu
5323 Cause @code{dejagnu}-specific rules to be generated.  @xref{Tests}.
5325 @item @code{dist-bzip2}
5326 @cindex Option, dist-bzip2
5327 Hook @code{dist-bzip2} to @code{dist}.
5328 @trindex dist-bzip2
5330 @item @code{dist-shar}
5331 @cindex Option, dist-shar
5332 Hook @code{dist-shar} to @code{dist}.
5333 @trindex dist-shar
5335 @item @code{dist-zip}
5336 @cindex Option, dist-zip
5337 Hook @code{dist-zip} to @code{dist}.
5338 @trindex dist-zip
5340 @item @code{dist-tarZ}
5341 @cindex Option, dist-tarZ
5342 Hook @code{dist-tarZ} to @code{dist}.
5343 @trindex dist-tarZ
5345 @item @code{no-define}
5346 @cindex Option, no-define
5347 This options is meaningful only when passed as an argument to
5348 @code{AM_INIT_AUTOMAKE}.  It will prevent the @code{PACKAGE} and
5349 @code{VERSION} variables to be @code{AC_DEFINE}d.
5351 @item @code{no-dependencies}
5352 @cindex Option, no-dependencies
5353 This is similar to using @samp{--include-deps} on the command line, but
5354 is useful for those situations where you don't have the necessary bits
5355 to make automatic dependency tracking work @xref{Dependencies}.  In this
5356 case the effect is to effectively disable automatic dependency tracking.
5358 @item @code{no-dist-gzip}
5359 @cindex Option, no-dist-gzip
5360 Do not hook @code{dist-gzip} to @code{dist}.
5361 @trindex no-dist-gzip
5363 @item @code{no-exeext}
5364 @cindex Option, no-exeext
5365 If your @file{Makefile.am} defines a target @samp{foo}, it will override
5366 a target named @samp{foo$(EXEEXT)}.  This is necessary when
5367 @code{EXEEXT} is found to be empty.  However, by default automake will
5368 generate an error for this use.  The @code{no-exeext} option will
5369 disable this error.  This is intended for use only where it is known in
5370 advance that the package will not be ported to Windows, or any other
5371 operating system using extensions on executables.
5373 @item @code{no-installinfo}
5374 @cindex Option, no-installinfo
5375 The generated @file{Makefile.in} will not cause info pages to be built
5376 or installed by default.  However, @code{info} and @code{install-info}
5377 targets will still be available.  This option is disallowed at
5378 @samp{GNU} strictness and above.
5379 @trindex info
5380 @trindex install-info
5382 @item @code{no-installman}
5383 @cindex Option, no-installman
5384 The generated @file{Makefile.in} will not cause man pages to be
5385 installed by default.  However, an @code{install-man} target will still
5386 be available for optional installation.  This option is disallowed at
5387 @samp{GNU} strictness and above.
5388 @trindex install-man
5390 @item @code{nostdinc}
5391 @cindex Option, nostdinc
5392 This option can be used to disable the standard @samp{-I} options which
5393 are ordinarily automatically provided by Automake.
5395 @item @code{no-texinfo.tex}
5396 @cindex Option, no-texinfo
5397 Don't require @file{texinfo.tex}, even if there are texinfo files in
5398 this directory.
5400 @item @code{readme-alpha}
5401 @cindex Option, readme-alpha
5402 If this release is an alpha release, and the file @file{README-alpha}
5403 exists, then it will be added to the distribution.  If this option is
5404 given, version numbers are expected to follow one of two forms.  The
5405 first form is @samp{@var{MAJOR}.@var{MINOR}.@var{ALPHA}}, where each
5406 element is a number; the final period and number should be left off for
5407 non-alpha releases.  The second form is
5408 @samp{@var{MAJOR}.@var{MINOR}@var{ALPHA}}, where @var{ALPHA} is a
5409 letter; it should be omitted for non-alpha releases.
5411 @item @code{std-options}
5412 @cindex Options, std-options
5413 @cindex make installcheck
5414 Make the @code{installcheck} target check that installed scripts and
5415 programs support the @code{--help} and @code{--version} options.
5416 This also provides a basic check that the program's
5417 run-time dependencies are satisfied after installation.
5419 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
5420 In a few situations, programs (or scripts) have to be exempted from this
5421 test.  For instance @command{false} (from GNU sh-utils) is never
5422 successful, even for @code{--help} or @code{--version}.  You can list
5423 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
5424 Programs (not scripts) listed in this variable should be suffixed by
5425 @code{$(EXEEXT)} for the sake of Win32 or OS/2.  For instance suppose we
5426 build @code{false} as a program but @code{true.sh} as a script, and that
5427 neither of them support @code{--help} or @code{--version}:
5429 @example
5430 AUTOMAKE_OPTIONS = std-options
5431 bin_PROGRAMS = false ...
5432 bin_SCRIPTS = true.sh ...
5433 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
5434 @end example
5436 @item @code{subdir-objects}
5437 If this option is specified, then objects are placed into the
5438 subdirectory of the build directory corresponding to the subdirectory of
5439 the source file.  For instance if the source file is
5440 @file{subdir/file.cxx}, then the output file would be
5441 @file{subdir/file.o}.
5443 @item @var{version}
5444 @cindex Option, version
5445 A version number (e.g. @samp{0.30}) can be specified.  If Automake is not
5446 newer than the version specified, creation of the @file{Makefile.in}
5447 will be suppressed.
5449 @item @code{-W@var{category}} or @code{--warnings=@var{category}}
5450 @cindex Option, warnings
5451 These options behave exactly like their command-line counterpart
5452 (@pxref{Invoking Automake}).  This allows you to enable or disable some
5453 warning categories on a per-file basis.  You can also setup some warnings
5454 for your entire project; for instance try @code{AM_INIT_AUTOMAKE([-Wall])}
5455 in your @file{configure.in}.
5457 @end table
5459 Unrecognized options are diagnosed by @code{automake}.
5461 If you want an option to apply to all the files in the tree, you can use
5462 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.in}.
5463 @xref{Macros}.
5466 @node Miscellaneous
5467 @chapter Miscellaneous Rules
5469 There are a few rules and variables that didn't fit anywhere else.
5471 @menu
5472 * Tags::                        Interfacing to etags and mkid
5473 * Suffixes::                    Handling new file extensions
5474 * Multilibs::                   Support for multilibs.
5475 @end menu
5478 @node Tags
5479 @section Interfacing to @code{etags}
5481 @cindex TAGS support
5483 Automake will generate rules to generate @file{TAGS} files for use with
5484 GNU Emacs under some circumstances.
5486 If any C, C++ or Fortran 77 source code or headers are present, then
5487 @code{tags} and @code{TAGS} targets will be generated for the directory.
5488 @trindex tags
5490 At the topmost directory of a multi-directory package, a @code{tags}
5491 target file will be generated which, when run, will generate a
5492 @file{TAGS} file that includes by reference all @file{TAGS} files from
5493 subdirectories.
5495 The @code{tags} target will also be generated if the variable
5496 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
5497 directories which contain taggable source that @code{etags} does not
5498 understand.  The user can use the @code{ETAGSFLAGS} to pass additional
5499 flags to @code{etags}; @code{AM_ETAGSFLAGS} is also available for use in
5500 @file{Makefile.am}.
5501 @vindex ETAGS_ARGS
5502 @vindex ETAGSFLAGS
5503 @vindex AM_ETAGSFLAGS
5505 Here is how Automake generates tags for its source, and for nodes in its
5506 Texinfo file:
5508 @example
5509 ETAGS_ARGS = automake.in --lang=none \
5510  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
5511 @end example
5513 If you add filenames to @samp{ETAGS_ARGS}, you will probably also
5514 want to set @samp{TAGS_DEPENDENCIES}.  The contents of this variable
5515 are added directly to the dependencies for the @code{tags} target.
5516 @vindex TAGS_DEPENDENCIES
5518 Automake also generates a @code{ctags} target which can be used to
5519 build @command{vi}-style @file{tags} files.  The variable @code{CTAGS}
5520 is the name of the program to invoke (by default @samp{ctags});
5521 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
5522 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
5524 Automake will also generate an @code{ID} target which will run
5525 @code{mkid} on the source.  This is only supported on a
5526 directory-by-directory basis.
5527 @trindex id
5529 Automake also supports the @uref{http://www.gnu.org/software/global/,
5530 GNU Global Tags program}.  The @code{GTAGS} target runs Global Tags
5531 automatically and puts the result in the top build directory.  The
5532 variable @code{GTAGS_ARGS} holds arguments which are passed to
5533 @code{gtags}.
5534 @vindex GTAGS_ARGS
5537 @node Suffixes
5538 @section Handling new file extensions
5540 @cindex Adding new SUFFIXES
5541 @cindex SUFFIXES, adding
5542 @vindex SUFFIXES
5544 It is sometimes useful to introduce a new implicit rule to handle a file
5545 type that Automake does not know about.
5547 For instance, suppose you had a compiler which could compile @samp{.foo}
5548 files to @samp{.o} files.  You would simply define an suffix rule for
5549 your language:
5551 @example
5552 .foo.o:
5553         foocc -c -o $@@ $<
5554 @end example
5556 Then you could directly use a @samp{.foo} file in a @samp{_SOURCES}
5557 variable and expect the correct results:
5559 @example
5560 bin_PROGRAMS = doit
5561 doit_SOURCES = doit.foo
5562 @end example
5564 This was the simpler and more common case.  In other cases, you will
5565 have to help Automake to figure which extensions you are defining your
5566 suffix rule for.  This usually happens when your extensions does not
5567 start with a dot.  Then, all you have to do is to put a list of new
5568 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
5569 implicit rule.
5571 For instance the following definition prevents Automake to misinterpret
5572 @samp{.idlC.cpp:} as an attempt to transform @samp{.idlC} into
5573 @samp{.cpp}.
5575 @example
5576 SUFFIXES = .idl C.cpp
5577 .idlC.cpp:
5578         # whatever
5579 @end example
5581 As you may have noted, the @code{SUFFIXES} variable behaves like the
5582 @code{.SUFFIXES} special target of @code{make}.  You should not touch
5583 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
5584 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
5585 @code{SUFFIXES} go at the start of the generated suffixes list, followed
5586 by Automake generated suffixes not already in the list.
5588 @node Multilibs
5589 @section Support for Multilibs
5591 Automake has support for an obscure feature called multilibs.  A
5592 @dfn{multilib} is a library which is built for multiple different ABIs
5593 at a single time; each time the library is built with a different target
5594 flag combination.  This is only useful when the library is intended to
5595 be cross-compiled, and it is almost exclusively used for compiler
5596 support libraries.
5598 The multilib support is still experimental.  Only use it if you are
5599 familiar with multilibs and can debug problems you might encounter.
5602 @node Include
5603 @chapter Include
5605 @cmindex include
5606 @cindex Including Makefile fragment
5607 @cindex Makefile fragment, including
5609 Automake supports an @code{include} directive which can be used to
5610 include other @file{Makefile} fragments when @code{automake} is run.
5611 Note that these fragments are read and interpreted by @code{automake},
5612 not by @code{make}.  As with conditionals, @code{make} has no idea that
5613 @code{include} is in use.
5615 There are two forms of @code{include}:
5617 @table @code
5618 @item include $(srcdir)/file
5619 Include a fragment which is found relative to the current source
5620 directory.
5622 @item include $(top_srcdir)/file
5623 Include a fragment which is found relative to the top source directory.
5624 @end table
5626 Note that if a fragment is included inside a conditional, then the
5627 condition applies to the entire contents of that fragment.
5629 Makefile fragments included this way are always distributed because
5630 there are needed to rebuild @file{Makefile.in}.
5632 @node Conditionals
5633 @chapter Conditionals
5635 @cindex Conditionals
5637 Automake supports a simple type of conditionals.
5639 @cvindex AM_CONDITIONAL
5640 Before using a conditional, you must define it by using
5641 @code{AM_CONDITIONAL} in the @code{configure.in} file (@pxref{Macros}).
5643 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
5644 The conditional name, @var{conditional}, should be a simple string
5645 starting with a letter and containing only letters, digits, and
5646 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
5647 which are reserved by Automake.
5649 The shell @var{condition} (suitable for use in a shell @code{if}
5650 statement) is evaluated when @code{configure} is run.  Note that you
5651 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
5652 time @code{configure} is run -- if @code{AM_CONDITIONAL} is run
5653 conditionally (e.g., in a shell @code{if} statement), then the result
5654 will confuse automake.
5655 @end defmac
5657 @cindex --enable-debug, example
5658 @cindex Example conditional --enable-debug
5659 @cindex Conditional example,  --enable-debug
5661 Conditionals typically depend upon options which the user provides to
5662 the @code{configure} script.  Here is an example of how to write a
5663 conditional which is true if the user uses the @samp{--enable-debug}
5664 option.
5666 @example
5667 AC_ARG_ENABLE(debug,
5668 [  --enable-debug    Turn on debugging],
5669 [case "$@{enableval@}" in
5670   yes) debug=true ;;
5671   no)  debug=false ;;
5672   *) AC_MSG_ERROR(bad value $@{enableval@} for --enable-debug) ;;
5673 esac],[debug=false])
5674 AM_CONDITIONAL(DEBUG, test x$debug = xtrue)
5675 @end example
5677 Here is an example of how to use that conditional in @file{Makefile.am}:
5679 @cmindex if
5680 @cmindex endif
5681 @cmindex else
5683 @example
5684 if DEBUG
5685 DBG = debug
5686 else
5687 DBG =
5688 endif
5689 noinst_PROGRAMS = $(DBG)
5690 @end example
5692 This trivial example could also be handled using EXTRA_PROGRAMS
5693 (@pxref{Conditional Programs}).
5695 You may only test a single variable in an @code{if} statement, possibly
5696 negated using @samp{!}.  The @code{else} statement may be omitted.
5697 Conditionals may be nested to any depth.  You may specify an argument to
5698 @code{else} in which case it must be the negation of the condition used
5699 for the current @code{if}.  Similarly you may specify the condition
5700 which is closed by an @code{end}:
5702 @example
5703 if DEBUG
5704 DBG = debug
5705 else !DEBUG
5706 DBG =
5707 endif !DEBUG
5708 @end example
5710 @noindent
5711 Unbalanced conditions are errors.
5713 Note that conditionals in Automake are not the same as conditionals in
5714 GNU Make.  Automake conditionals are checked at configure time by the
5715 @file{configure} script, and affect the translation from
5716 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
5717 to @file{configure} and on results that @file{configure} has discovered
5718 about the host system.  GNU Make conditionals are checked at @code{make}
5719 time, and are based on variables passed to the make program or defined
5720 in the @file{Makefile}.
5722 Automake conditionals will work with any make program.
5725 @node Gnits
5726 @chapter The effect of @code{--gnu} and @code{--gnits}
5728 @cindex --gnu, required files
5729 @cindex --gnu, complete description
5731 The @samp{--gnu} option (or @samp{gnu} in the @samp{AUTOMAKE_OPTIONS}
5732 variable) causes @code{automake} to check the following:
5734 @itemize @bullet
5735 @item
5736 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
5737 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
5738 or @file{COPYING}, are required at the topmost directory of the package.
5740 @item
5741 The options @samp{no-installman} and @samp{no-installinfo} are
5742 prohibited.
5743 @end itemize
5745 Note that this option will be extended in the future to do even more
5746 checking; it is advisable to be familiar with the precise requirements
5747 of the GNU standards.  Also, @samp{--gnu} can require certain
5748 non-standard GNU programs to exist for use by various maintainer-only
5749 targets; for instance in the future @code{pathchk} might be required for
5750 @samp{make dist}.
5752 @cindex --gnits, complete description
5754 The @samp{--gnits} option does everything that @samp{--gnu} does, and
5755 checks the following as well:
5757 @itemize @bullet
5758 @item
5759 @samp{make installcheck} will check to make sure that the @code{--help}
5760 and @code{--version} really print a usage message and a version string,
5761 respectively.  This is the @code{std-options} option (@pxref{Options}).
5763 @item
5764 @samp{make dist} will check to make sure the @file{NEWS} file has been
5765 updated to the current version.
5767 @item
5768 @samp{VERSION} is checked to make sure its format complies with Gnits
5769 standards.
5770 @c FIXME xref when standards are finished
5772 @item
5773 @cindex README-alpha
5774 If @samp{VERSION} indicates that this is an alpha release, and the file
5775 @file{README-alpha} appears in the topmost directory of a package, then
5776 it is included in the distribution.  This is done in @samp{--gnits}
5777 mode, and no other, because this mode is the only one where version
5778 number formats are constrained, and hence the only mode where Automake
5779 can automatically determine whether @file{README-alpha} should be
5780 included.
5782 @item
5783 The file @file{THANKS} is required.
5784 @end itemize
5787 @node Cygnus
5788 @chapter The effect of @code{--cygnus}
5790 @cindex Cygnus strictness
5792 Some packages, notably GNU GCC and GNU gdb, have a build environment
5793 originally written at Cygnus Support (subsequently renamed Cygnus
5794 Solutions, and then later purchased by Red Hat).  Packages with this
5795 ancestry are sometimes referred to as ``Cygnus'' trees.
5797 A Cygnus tree has slightly different rules for how a @file{Makefile.in}
5798 is to be constructed.  Passing @samp{--cygnus} to @code{automake} will
5799 cause any generated @file{Makefile.in} to comply with Cygnus rules.
5801 Here are the precise effects of @samp{--cygnus}:
5803 @itemize @bullet
5804 @item
5805 Info files are always created in the build directory, and not in the
5806 source directory.
5808 @item
5809 @file{texinfo.tex} is not required if a Texinfo source file is
5810 specified.  The assumption is that the file will be supplied, but in a
5811 place that Automake cannot find.  This assumption is an artifact of how
5812 Cygnus packages are typically bundled.
5814 @item
5815 @samp{make dist} is not supported, and the rules for it are not
5816 generated.  Cygnus-style trees use their own distribution mechanism.
5818 @item
5819 Certain tools will be searched for in the build tree as well as in the
5820 user's @samp{PATH}.  These tools are @code{runtest}, @code{expect},
5821 @code{makeinfo} and @code{texi2dvi}.
5823 @item
5824 @code{--foreign} is implied.
5826 @item
5827 The options @samp{no-installinfo} and @samp{no-dependencies} are
5828 implied.
5830 @item
5831 The macros @samp{AM_MAINTAINER_MODE} and @samp{AM_CYGWIN32} are
5832 required.
5834 @item
5835 The @code{check} target doesn't depend on @code{all}.
5836 @end itemize
5838 GNU maintainers are advised to use @samp{gnu} strictness in preference
5839 to the special Cygnus mode.  Some day, perhaps, the differences between
5840 Cygnus trees and GNU trees will disappear (for instance, as GCC is made
5841 more standards compliant).  At that time the special Cygnus mode will be
5842 removed.
5845 @node Extending
5846 @chapter When Automake Isn't Enough
5848 Automake's implicit copying semantics means that many problems can be
5849 worked around by simply adding some @code{make} targets and rules to
5850 @file{Makefile.in}.  Automake will ignore these additions.
5852 @cindex -local targets
5853 @cindex local targets
5855 There are some caveats to doing this.  Although you can overload a
5856 target already used by Automake, it is often inadvisable, particularly
5857 in the topmost directory of a package with subdirectories.  However,
5858 various useful targets have a @samp{-local} version you can specify in
5859 your @file{Makefile.in}.  Automake will supplement the standard target
5860 with these user-supplied targets.
5862 @trindex  all
5863 @trindex  all-local
5864 @trindex  info
5865 @trindex  info-local
5866 @trindex  dvi
5867 @trindex  dvi-local
5868 @trindex  ps
5869 @trindex  ps-local
5870 @trindex  pdf
5871 @trindex  pdf-local
5872 @trindex  html
5873 @trindex  html-local
5874 @trindex  check
5875 @trindex  check-local
5876 @trindex  install
5877 @trindex  install-data-local
5878 @trindex  install-exec
5879 @trindex  install-exec-local
5880 @trindex  uninstall
5881 @trindex  uninstall-local
5882 @trindex  mostlyclean
5883 @trindex  mostlyclean-local
5884 @trindex  clean
5885 @trindex  clean-local
5886 @trindex  distclean
5887 @trindex  distclean-local
5888 @trindex  installdirs
5889 @trindex  installdirs-local
5890 @trindex  installcheck
5891 @trindex  installcheck-local
5893 The targets that support a local version are @code{all}, @code{info},
5894 @code{dvi}, @code{ps}, @code{pdf}, @code{html}, @code{check},
5895 @code{install-data}, @code{install-exec}, @code{uninstall},
5896 @code{installdirs}, @code{installcheck} and the various @code{clean} targets
5897 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
5898 @code{maintainer-clean}).  Note that there are no
5899 @code{uninstall-exec-local} or @code{uninstall-data-local} targets; just
5900 use @code{uninstall-local}.  It doesn't make sense to uninstall just
5901 data or just executables.
5903 For instance, here is one way to install a file in @file{/etc}:
5905 @example
5906 install-data-local:
5907         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
5908 @end example
5910 @cindex -hook targets
5911 @cindex hook targets
5913 Some targets also have a way to run another target, called a @dfn{hook},
5914 after their work is done.  The hook is named after the principal target,
5915 with @samp{-hook} appended.  The targets allowing hooks are
5916 @code{install-data}, @code{install-exec}, @code{uninstall}, @code{dist},
5917 and @code{distcheck}.
5918 @trindex install-data-hook
5919 @trindex install-exec-hook
5920 @trindex uninstall-hook
5921 @trindex dist-hook
5923 For instance, here is how to create a hard link to an installed program:
5925 @example
5926 install-exec-hook:
5927         ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
5928            $(DESTDIR)$(bindir)/proglink$(EXEEXT)
5929 @end example
5931 Although cheaper and more portable than symbolic links, hard links
5932 will not work everywhere (for instance OS/2 does not have
5933 @command{ln}).  Ideally you should fall back to @code{cp -p} when
5934 @code{ln} does not work.  An easy way, if symbolic links are
5935 acceptable to you, is to add @code{AC_PROG_LN_S} to
5936 @file{configure.in} (@pxref{Particular Programs, , Particular Program
5937 Checks, autoconf, The Autoconf Manual}) and use @code{$(LN_S)} in
5938 @file{Makefile.am}.
5940 @cindex versioned binaries, installing
5941 @cindex installing versioned binaries
5942 @cindex LN_S example
5943 For instance, here is how you could install a versioned copy of a
5944 program using @code{$(LN_S)}:
5946 @example
5947 install-exec-hook:
5948         cd $(DESTDIR)$(bindir) && \
5949           mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
5950           $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
5951 @end example
5953 Note that we rename the program so that a new version will erase the
5954 symbolic link, not the real binary.  Also we @code{cd} into the
5955 destination directory in order to create relative links.
5957 @c FIXME should include discussion of variables you can use in these
5958 @c rules
5960 @node Distributing
5961 @chapter Distributing @file{Makefile.in}s
5963 Automake places no restrictions on the distribution of the resulting
5964 @file{Makefile.in}s.  We still encourage software authors to distribute
5965 their work under terms like those of the GPL, but doing so is not
5966 required to use Automake.
5968 Some of the files that can be automatically installed via the
5969 @code{--add-missing} switch do fall under the GPL@.  However, these also
5970 have a special exception allowing you to distribute them with your
5971 package, regardless of the licensing you choose.
5974 @node API versioning
5975 @chapter Automake API versioning
5977 New Automake releases usually include bug fixes and new features.
5978 Unfortunately they may also introduce new bugs and incompatibilities.
5979 This makes four reasons why a package may require a particular Automake
5980 version.
5982 Things get worse when maintaining a large tree of packages, each one
5983 requiring a different version of Automake.  In the past, this meant that
5984 any developer (and sometime users) had to install several versions of
5985 Automake in different places, and switch @samp{$PATH} appropriately for
5986 each package.
5988 Starting with version 1.6, Automake installs versioned binaries.  This
5989 means you can install several versions of Automake in the same
5990 @samp{$prefix}, and can select an arbitrary Automake version by running
5991 @samp{automake-1.6} or @samp{automake-1.7} without juggling with
5992 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
5993 will use @samp{automake-1.6} explicitly in their rebuild rules.
5995 Note that @samp{1.6} in @samp{automake-1.6} is Automake's API version,
5996 not Automake's version.  If a bug fix release is made, for instance
5997 Automake 1.6.1, the API version will remain 1.6.  This means that a
5998 package which work with Automake 1.6 should also work with 1.6.1; after
5999 all, this is what people expect from bug fix releases.
6001 Note that if your package relies on a feature or a bug fix introduced in
6002 a release, you can pass this version as an option to Automake to ensure
6003 older releases will not be used.  For instance, use this in your
6004 @file{configure.in}:
6006 @example
6007   AM_INIT_AUTOMAKE(1.6.1)    dnl Require Automake 1.6.1 or better.
6008 @end example
6009 @noindent
6010 or, in a particular @file{Makefile.am}:
6012 @example
6013   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
6014 @end example
6015 @noindent
6016 Automake will print an error message if its version is
6017 older than the requested version.
6020 @heading What is in the API
6022 Automake's programming interface is not easy to define.  Basically it
6023 should include at least all @strong{documented} variables and targets
6024 that a @samp{Makefile.am} author can use, any behavior associated with
6025 them (e.g. the places where @samp{-hook}'s are run), the command line
6026 interface of @samp{automake} and @samp{aclocal}, @dots{}
6028 @heading What is not in the API
6030 Every undocumented variable, target, or command line option, is not part
6031 of the API@.  You should avoid using them, as they could change from one
6032 version to the other (even in bug fix releases, if this helps to fix a
6033 bug).
6035 If it turns out you need to use such a undocumented feature, contact
6036 @email{automake@@gnu.org} and try to get it documented and exercised by
6037 the test-suite.
6039 @node FAQ
6040 @chapter Frequently Asked Questions about Automake
6042 This chapter covers some questions that often come up on the mailing
6043 lists.
6045 @menu
6046 * CVS::                         CVS and generated files
6047 * maintainer-mode::             missing and AM_MAINTAINER_MODE
6048 * wildcards::                   Why doesn't Automake support wildcards?
6049 * distcleancheck::              Files left in build directory after distclean
6050 * renamed objects::             Why are object files sometimes renamed?
6051 @end menu
6053 @node CVS
6054 @section CVS and generated files
6056 @subsection Background: distributed generated files
6057 @cindex generated files, distributed
6058 @cindex rebuild rules
6060 Packages made with Autoconf and Automake ship with some generated
6061 files like @file{configure} or @file{Makefile.in}.  These files were
6062 generated on the developer's host and are distributed so that
6063 end-users do not have to install the maintainer tools required to
6064 rebuild them.  Other generated files like Lex scanners, Yacc parsers,
6065 or Info documentation, are usually distributed on similar grounds.
6067 Automake outputs rules in @file{Makefile}s to rebuild these files.  For
6068 instance @command{make} will run @command{autoconf} to rebuild
6069 @file{configure} whenever @file{configure.in} is changed.  This makes
6070 development safer by ensuring a @file{configure} is never out-of-date
6071 with respect to @file{configure.in}.
6073 As generated files shipped in packages are up-to-date, and because
6074 @command{tar} preserves times-tamps, these rebuild rules are not
6075 triggered when a user unpacks and builds a package.
6077 @subsection Background: CVS and timestamps
6078 @cindex timestamps and CVS
6079 @cindex CVS and timestamps
6081 Unless you use CVS keywords (in which case files must be updated at
6082 commit time), CVS preserves timestamp during @code{cvs commit} and
6083 @code{cvs import -d} operations.
6085 When you check out a file using @code{cvs checkout} its timestamp is
6086 set to that of the revision which is being checked out.
6088 However, during @command{cvs update}, files will have the date of the
6089 update, not the original timestamp of this revision.  This is meant to
6090 make sure that @command{make} notices sources files have been updated.
6092 This times tamp shift is troublesome when both sources and generated
6093 files are kept under CVS.  Because CVS processes files in alphabetical
6094 order, @file{configure.in} will appear older than @file{configure}
6095 after a @command{cvs update} that updates both files, even if
6096 @file{configure} was newer than @file{configure.in} when it was
6097 checked in.  Calling @code{make} will then trigger a spurious rebuild
6098 of @file{configure}.
6100 @subsection Living with CVS in Autoconfiscated projects
6101 @cindex CVS and generated files
6102 @cindex generated files and CVS
6104 There are basically two clans amongst maintainers: those who keep all
6105 distributed files under CVS, including generated files, and those who
6106 keep generated files @emph{out} of CVS.
6108 @subsubheading All files in CVS
6110 @itemize @bullet
6111 @item
6112 The CVS repository contains all distributed files so you know exactly
6113 what is distributed, and you can checkout any prior version entirely.
6115 @item
6116 Maintainers can see how generated files evolve (for instance you can
6117 see what happens to your @file{Makefile.in}s when you upgrade Automake
6118 and make sure they look OK).
6120 @item
6121 Users do not need the autotools to build a checkout of the project, it
6122 works just like a released tarball.
6124 @item
6125 If users use @command{cvs update} to update their copy, instead of
6126 @command{cvs checkout} to fetch a fresh one, timestamps will be
6127 inaccurate.  Some rebuild rules will be triggered and attempt to
6128 run developer tools such as @command{autoconf} or @command{automake}.
6130 Actually, calls to such tools are all wrapped into a call to the
6131 @command{missing} script discussed later (@pxref{maintainer-mode}).
6132 @command{missing} will take care of fixing the timestamps when these
6133 tools are not installed, so that the build can continue.
6135 @item
6136 In distributed development, developers are likely to have different
6137 version of the maintainer tools installed.  In this case rebuilds
6138 triggered by timestamp lossage will lead to spurious changes
6139 to generated files.  There are several solutions to this:
6141 @itemize
6142 @item
6143 All developers should use the same versions, so that the rebuilt files
6144 are identical to files in CVS.  (This starts to be difficult when each
6145 project you work on uses different versions.)
6146 @item
6147 Or people use a script to fix the timestamp after a checkout (the GCC
6148 folks have such a script).
6149 @item
6150 Or @file{configure.in} uses @code{AM_MAINTAINER_MODE}, which will
6151 disable all these rebuild rules by default.  This is further discussed
6152 in @ref{maintainer-mode}.
6153 @end itemize
6155 @item
6156 Although we focused on spurious rebuilds, the converse can also
6157 happen.  CVS's timestamp handling can also let you think an
6158 out-of-date file is up-to-date.
6160 For instance, suppose a developer has modified @file{Makefile.am} and
6161 rebuilt @file{Makefile.in}, and then decide to do a last-minute change
6162 to @file{Makefile.am} right before checking in both files (without
6163 rebuilding @file{Makefile.in} to account for the change).
6165 This last change to @file{Makefile.am} make the copy of
6166 @file{Makefile.in} out-of-date.  Since CVS processes files
6167 alphabetically, when another developer @code{cvs update} his or her
6168 tree, @file{Makefile.in} will happen to be newer than
6169 @file{Makefile.am}.  This other developer will not see
6170 @file{Makefile.in} is out-of-date.
6172 @end itemize
6174 @subsubheading Generated files out of CVS
6176 One way to get CVS and @code{make} working peacefully is to never
6177 store generated files in CVS, i.e., do not CVS-control files which are
6178 @code{Makefile} targets (or @emph{derived} files in Make terminology).
6180 This way developers are not annoyed by changes to generated files.  It
6181 does not matter if they all have different versions (assuming they are
6182 compatible, of course).  And finally, timestamps are not lost, changes
6183 to sources files can't be missed as in the
6184 @file{Makefile.am}/@file{Makefile.in} example discussed earlier.
6186 The drawback is that the CVS repository is not an exact copy of what
6187 is distributed and that users now need to install various development
6188 tools (maybe even specific versions) before they can build a checkout.
6189 But, after all, CVS's job is versioning, not distribution.
6191 Allowing developers to use different versions of their tools can also
6192 hide bugs during distributed development.  Indeed, developers will be
6193 using (hence testing) their own generated files, instead of the
6194 generated files that will be released actually.  The developer who
6195 prepares the tarball might be using a version of the tool that
6196 produces bogus output (for instance a non-portable C file), something
6197 other developers could have noticed if they weren't using their own
6198 versions of this tool.
6200 @subsection Third-party files
6201 @cindex CVS and third-party files
6202 @cindex third-party files and CVS
6204 Another class of files not discussed here (because they do not cause
6205 timestamp issues) are files which are shipped with a package, but
6206 maintained elsewhere.  For instance tools like @command{gettextize}
6207 and @command{autopoint} (from Gettext) or @command{libtoolize} (from
6208 Libtool), will install or update files in your package.
6210 These files, whether they are kept under CVS or not, raise similar
6211 concerns about version mismatch between developers' tools.  The
6212 Gettext manual has a section about this, see @ref{CVS Issues, CVS
6213 Issues, Integrating with CVS, gettext, GNU gettext tools}.
6215 @node maintainer-mode
6216 @section @command{missing} and @code{AM_MAINTAINER_MODE}
6218 @subsection @command{missing}
6219 @cindex missing, purpose
6221 The @command{missing} script is a wrapper around several maintainer
6222 tools, designed to warn users if a maintainer tool is required but
6223 missing.  Typical maintainer tools are @command{autoconf},
6224 @command{automake}, @command{bison}, etc.  Because file generated by
6225 these tools are shipped with the other sources of a package, these
6226 tools shouldn't be required during a user build and they are not
6227 checked for in @file{configure}.
6229 However, if for some reason a rebuild rule is triggered and involves a
6230 missing tool, @command{missing} will notice it and warn the user.
6231 Besides the warning, when a tool is missing, @command{missing} will
6232 attempt to fix timestamps in a way which allow the build to continue.
6233 For instance @command{missing} will touch @file{configure} if
6234 @command{autoconf} is not installed.  When all distributed files are
6235 kept under CVS, this feature of @command{missing} allows user
6236 @emph{with no maintainer tools} to build a package off CVS, bypassing
6237 any timestamp inconsistency implied by @code{cvs update}.
6239 If the required tool is installed, @command{missing} will run it and
6240 won't attempt to continue after failures.  This is correct during
6241 development: developers love fixing failures.  However, users with
6242 wrong versions of maintainer tools may get an error when the rebuild
6243 rule is spuriously triggered, halting the build.  This failure to let
6244 the build continue is one of the arguments of the
6245 @code{AM_MAINTAINER_MODE} advocates.
6247 @subsection @code{AM_MAINTAINER_MODE}
6248 @cindex AM_MAINTAINER_MODE, purpose
6249 @cvindex AM_MAINTAINER_MODE
6251 @code{AM_MAINTAINER_MODE} disables the so called "rebuild rules" by
6252 default.  If you have @code{AM_MAINTAINER_MODE} in
6253 @file{configure.ac}, and run @code{./configure && make}, then
6254 @command{make} will *never* attempt to rebuilt @file{configure},
6255 @file{Makefile.in}s, Lex or Yacc outputs, etc.  I.e., this disables
6256 build rules for files which are usually distributed and that users
6257 should normally not have to update.
6259 If you run @code{./configure --enable-maintainer-mode}, then these
6260 rebuild rules will be active.
6262 People use @code{AM_MAINTAINER_MODE} either because they do want their
6263 users (or themselves) annoyed by timestamps lossage (@pxref{CVS}), or
6264 because they simply can't stand the rebuild rules and prefer running
6265 maintainer tools explicitly.
6267 @code{AM_MAINTAINER_MODE} also allows you to disable some custom build
6268 rules conditionally.  Some developers use this feature to disable
6269 rules that need exotic tools that users may not have available.
6271 Several years ago Fran@,{c}ois Pinard pointed out several arguments
6272 against @code{AM_MAINTAINER_MODE}.  Most of them relate to insecurity.
6273 By removing dependencies you get non-dependable builds: change to
6274 sources files can have no effect on generated files and this can be
6275 very confusing when unnoticed.  He adds that security shouldn't be
6276 reserved to maintainers (what @code{--enable-maintainer-mode}
6277 suggests), on the contrary.  If one user has to modify a
6278 @file{Makefile.am}, then either @file{Makefile.in} should be updated
6279 or a warning should be output (this is what Automake uses
6280 @code{missing} for) but the last thing you want is that nothing
6281 happens and the user doesn't notice it (this is what happens when
6282 rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
6284 Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro was
6285 swayed by Fran@,{c}ois's arguments, and got rid of
6286 @code{AM_MAINTAINER_MODE} in all of his packages.
6288 Still many people continue to use @code{AM_MAINTAINER_MODE}, because
6289 it helps them working on projects where all files are kept under CVS,
6290 and because @command{missing} isn't enough if you have the wrong
6291 version of the tools.
6294 @node wildcards
6295 @section Why doesn't Automake support wildcards?
6296 @cindex wildcards
6298 Developers are lazy.  They often would like to use wildcards in
6299 @file{Makefile.am}s, so they don't need to remember they have to
6300 update @file{Makefile.am}s every time they add, delete, or rename a
6301 file.
6303 There are several objections to this:
6304 @itemize
6305 @item
6306 When using CVS (or similar) developers need to remember they have to
6307 run @code{cvs add} or @code{cvs rm} anyway.  Updating
6308 @file{Makefile.am} accordingly quickly becomes a reflex.
6310 Conversely, if your application doesn't compile
6311 because you forgot to add a file in @file{Makefile.am}, it will help
6312 you remember to @code{cvs add} it.
6314 @item
6315 Using wildcards makes easy to distribute files by mistake.  For
6316 instance some code a developer is experimenting with (a test case,
6317 say) but which should not be part of the distribution.
6319 @item
6320 Using wildcards it's easy to omit some files by mistake.  For
6321 instance one developer creates a new file, uses it at many places,
6322 but forget to commit it.  Another developer then checkout the
6323 incomplete project and is able to run `make dist' successfully,
6324 even though a file is missing.
6326 @item
6327 Listing files, you control *exactly* what you distribute.
6328 If some file that should be distributed is missing from your
6329 tree, @code{make dist} will complain.  Besides, you don't distribute
6330 more than what you listed.
6332 @item
6333 Finally it's really hard to @file{forget} adding a file to
6334 @file{Makefile.am}, because if you don't add it, it doesn't get
6335 compiled nor installed, so you can't even test it.
6336 @end itemize
6338 Still, these are philosophical objections, and as such you may disagree,
6339 or find enough value in wildcards to dismiss all of them.  Before you
6340 start writing a patch against Automake to teach it about wildcards,
6341 let's see the main technical issue: portability.
6343 Although @code{$(wildcard ...)} works with GNU @command{make}, it is
6344 not portable to other @command{make} implementations.
6346 The only way Automake could support @command{$(wildcard ...)} is by
6347 expending @command{$(wildcard ...)} when @command{automake} is run.
6348 Resulting @file{Makefile.in}s would be portable since they would
6349 list all files and not use @code{$(wildcard ...)}.  However that
6350 means developers need to remember they must run @code{automake} each
6351 time they add, delete, or rename files.
6353 Compared to editing @file{Makefile.am}, this is really little win.  Sure,
6354 it's easier and faster to type @code{automake; make} than to type
6355 @code{emacs Makefile.am; make}.  But nobody bothered enough to write a
6356 patch add support for this syntax.  Some people use scripts to
6357 generated file lists in @file{Makefile.am} or in separate
6358 @file{Makefile} fragments.
6360 Even if you don't care about portability, and are tempted to use
6361 @code{$(wildcard ...)} anyway because you target only GNU Make, you
6362 should know there are many places where Automake need to know exactly
6363 which files should be processed.  As Automake doesn't know how to
6364 expand @code{$(wildcard ...)}, you cannot use it in these places.
6365 @code{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
6366 variables as far Automake is concerned.
6368 You can get warnings about @code{$(wildcard ...}) constructs using the
6369 @code{-Wportability} flag.
6371 @node distcleancheck
6372 @section Files left in build directory after distclean
6373 @cindex distclean, diagnostic
6374 @cindex dependencies and distributed files
6375 @trindex distclean
6376 @trindex distcleancheck
6378 This is a diagnostic you might encounter while running @code{make
6379 distcheck}.
6381 As explained in @ref{Dist}, @code{make distcheck} attempts to build
6382 and check your package for errors like this one.
6384 @code{make distcheck} will perform a @code{VPATH} build of your
6385 package, and then call @code{make distclean}.  Files left in the build
6386 directory after @code{make distclean} has run are listed after this
6387 error.
6389 This diagnostic really covers two kinds of errors:
6391 @itemize @bullet
6392 @item
6393 files that are forgotten by distclean;
6394 @item
6395 distributed files that are erroneously rebuilt.
6396 @end itemize
6398 The former left-over files are not distributed, so the fix is to mark
6399 them for cleaning (@pxref{Clean}), this is obvious and doesn't deserve
6400 more explanations.
6402 The latter bug is not always easy to understand and fix, so let's
6403 proceed with an example.  Suppose our package contains a program for
6404 which we want to build a man page using @command{help2man}.  GNU
6405 @command{help2man} produces simple manual pages from the @code{--help}
6406 and @code{--version} output of other commands (@pxref{Top, , Overview,
6407 help2man, The Help2man Manual}).  Because we don't to force want our
6408 users to install @command{help2man}, we decide to distribute the
6409 generated man page using the following setup.
6411 @example
6412 # This Makefile.am is bogus.
6413 bin_PROGRAMS = foo
6414 foo_SOURCES = foo.c
6415 dist_man_MANS = foo.1
6417 foo.1: foo$(EXEEXT)
6418         help2man --output=foo.1 ./foo$(EXEEXT)
6419 @end example
6421 This will effectively distribute the man page.  However,
6422 @code{make distcheck} will fail with:
6424 @example
6425 ERROR: files left in build directory after distclean:
6426 ./foo.1
6427 @end example
6429 Why was @file{foo.1} rebuilt?  Because although distributed,
6430 @file{foo.1} depends on a non-distributed built file:
6431 @file{foo$(EXEEXT)}.  @file{foo$(EXEEXT)} is built by the user, so it
6432 will always appear to be newer than the distributed @file{foo.1}.
6434 @code{make distcheck} caught an inconsistency in our package.  Our
6435 intent was to distribute @file{foo.1} so users do not need installing
6436 @command{help2man}, however since this our rule causes this file to be
6437 always rebuilt, users @emph{do} need @command{help2man}.  Either we
6438 should ensure that @file{foo.1} is not rebuilt by users, or there is
6439 no point in distributing @file{foo.1}.
6441 More generally, the rule is that distributed files should never depend
6442 on non-distributed built files.  If you distribute something
6443 generated, distribute its sources.
6445 One way to fix the above example, while still distributing
6446 @file{foo.1} is to not depend on @file{foo$(EXEEXT)}.  For instance,
6447 assuming @command{foo --version} and @command{foo --help} do not
6448 change unless @file{foo.c} or @file{configure.ac} change, we could
6449 write the following @file{Makefile.am}:
6451 @example
6452 bin_PROGRAMS = foo
6453 foo_SOURCES = foo.c
6454 dist_man_MANS = foo.1
6456 foo.1: foo.c $(top_srcdir)/configure.ac
6457         $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
6458         help2man --output=foo.1 ./foo$(EXEEXT)
6459 @end example
6461 This way, @file{foo.1} will not get rebuilt every time
6462 @file{foo$(EXEEXT)} changes.  The @command{make} call makes sure
6463 @file{foo$(EXEEXT)} is up-to-date before @command{help2man}.  Another
6464 way to ensure this would be to use separate directories for binaries
6465 and man pages, and set @code{SUBDIRS} so that binaries are built
6466 before man pages.
6468 We could also decide not to distribute @file{foo.1}.  In
6469 this case it's fine to have @file{foo.1} dependent upon
6470 @file{foo$(EXEEXT)}, since both will have to be rebuilt.
6471 However it would be impossible to build the package in a
6472 cross-compilation, because building @file{foo.1} involves
6473 an @emph{execution} of @file{foo$(EXEEXT)}.
6475 Another context where such errors are common is when distributed files
6476 are built by tools which are built by the package.  The pattern is similar:
6478 @example
6479 distributed-file: built-tools distributed-sources
6480         build-command
6481 @end example
6483 @noindent
6484 should be changed to
6486 @example
6487 distributed-file: distributed-sources
6488         $(MAKE) $(AM_MAKEFLAGS) built-tools
6489         build-command
6490 @end example
6492 @noindent
6493 or you could choose not to distribute @file{distributed-file}, if
6494 cross-compilation does not matter.
6496 The points made through these examples are worth a summary:
6498 @cartouche
6499 @itemize
6500 @item
6501 Distributed files should never depend upon non-distributed built
6502 files.
6503 @item
6504 Distributed files should be distributed will all their dependencies.
6505 @item
6506 If a file is @emph{intended} be rebuilt by users, there is no point in
6507 distributing it.
6508 @end itemize
6509 @end cartouche
6511 @vrindex distcleancheck_listfiles
6512 For desperate cases, it's always possible to disable this check by
6513 setting @code{distcleancheck_listfiles} as documented in @ref{Dist}.
6514 Make sure you do understand the reason why @code{make distcheck}
6515 complains before you do this.  @code{distcleancheck_listfiles} is a
6516 way to @emph{hide} errors, not to fix them.  You can always do better.
6518 @node renamed objects
6519 @section Why are object files sometimes renamed?
6521 This happens when per-target compilation flags are used.  Object
6522 files need to be renamed just in case they would clash with object
6523 files compiled from the same sources, but with different flags.
6524 Consider the following example.
6526 @example
6527 bin_PROGRAMS = true false
6528 true_SOURCES = generic.c
6529 true_CPPFLAGS = -DEXIT_CODE=0
6530 false_SOURCES = generic.c
6531 false_CPPFLAGS = -DEXIT_CODE=1
6532 @end example
6533 @noindent
6534 Obviously the two programs are built from the same source, but it
6535 would be bad if they shared the same object, because @file{generic.o}
6536 cannot be built with both @code{-DEXIT_CODE=0} *and*
6537 @code{-DEXIT_CODE=1}.  Therefore @command{automake} outputs rules to
6538 build two different objects: @file{true-generic.o} and
6539 @file{false-generic.o}.
6541 @command{automake} doesn't actually look whether sources files are
6542 shared to decide if it must rename objects.  It will just rename all
6543 objects of a target as soon as it sees per-target compilation flags
6544 are used.
6546 It's OK to share object files when per-target compilation flags are not
6547 used.  For instance @file{true} and @file{false} will both use
6548 @file{version.o} in the following example.
6550 @example
6551 AM_CPPFLAGS = -DVERSION=1.0
6552 bin_PROGRAMS = true false
6553 true_SOURCES = true.c version.c
6554 false_SOURCES = false.c version.c
6555 @end example
6557 Note that the renaming of objects is also affected by the
6558 @code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
6560 @page
6561 @node Macro and Variable Index
6562 @unnumbered Macro and Variable Index
6564 @printindex vr
6567 @page
6568 @node General Index
6569 @unnumbered General Index
6571 @printindex cp
6574 @page
6575 @contents
6576 @bye
6578 @c  LocalWords:  texinfo setfilename settitle setchapternewpage texi direntry
6579 @c  LocalWords:  dircategory in's aclocal ifinfo titlepage Tromey vskip pt sp
6580 @c  LocalWords:  filll defcodeindex ov cv op tr syncodeindex fn cp vr ifnottex
6581 @c  LocalWords:  dir Automake's ac Dist Gnits gnits cygnus dfn Autoconf's pxref
6582 @c  LocalWords:  cindex Autoconf autoconf perl samp cvs dist trindex SUBST foo
6583 @c  LocalWords:  xs emph FIXME ref vindex pkglibdir pkgincludedir pkgdatadir mt
6584 @c  LocalWords:  pkg libdir cvindex cpio bindir sbindir rmt pax sbin zar zardir
6585 @c  LocalWords:  HTML htmldir html noinst TEXINFOS nodist nobase strudel CFLAGS
6586 @c  LocalWords:  libmumble CC YFLAGS ansi knr itemx de fication config url comp
6587 @c  LocalWords:  depcomp elisp sh mdate mkinstalldirs mkdir py tex dvi ps pdf
6588 @c  LocalWords:  ylwrap zardoz INIT gettext acinclude mv FUNCS LIBOBJS LDADD fr
6589 @c  LocalWords:  uref featureful dnl src LINGUAS es ko nl pl sl sv PROG ISC doc
6590 @c  LocalWords:  POSIX STDC fcntl FUNC ALLOCA blksize struct stat intl po chmod
6591 @c  LocalWords:  ChangeLog SUBDIRS gettextize gpl testdata getopt INTLLIBS cpp
6592 @c  LocalWords:  localedir datadir DLOCALEDIR DEXIT CPPFLAGS autoreconf opindex
6593 @c  LocalWords:  AUX var symlink deps Wno Wnone package's aclocal's distclean
6594 @c  LocalWords:  ltmain xref LIBSOURCE LIBSOURCES LIBOBJ MEMCMP vs RANLIB CXX
6595 @c  LocalWords:  LDFLAGS LIBTOOL libtool XTRA LIBS gettext's acdir APIVERSION
6596 @c  LocalWords:  dirlist noindent usr MULTILIB multilib Multilibs TIOCGWINSZ sc
6597 @c  LocalWords:  GWINSZ termios SRCDIR tarball bzip LISPDIR lispdir XEmacs CCAS
6598 @c  LocalWords:  emacsen MicroEmacs CCASFLAGS UX GCJ gcj GCJFLAGS posix DMALLOC
6599 @c  LocalWords:  dmalloc ldmalloc REGEX regex rx DEPDIR DEP DEFUN aclocaldir fi
6600 @c  LocalWords:  mymacro myothermacro AMFLAGS autopoint autogen libtoolize yum
6601 @c  LocalWords:  autoheader README MAKEFLAGS subdir Inetutils sync COND endif
6602 @c  LocalWords:  Miller's installable includedir inc pkgdata EXEEXT libexec bsd
6603 @c  LocalWords:  pkglib libexecdir prog libcpio cpio's dlopen dlpreopen linux
6604 @c  LocalWords:  subsubsection OBJEXT esac lib LTLIBRARIES liblob LIBADD AR ar
6605 @c  LocalWords:  ARFLAGS cru ing maude libgettext lo LTLIBOBJS rpath SGI PRE yy
6606 @c  LocalWords:  libmaude CCLD CXXFLAGS FFLAGS LFLAGS OBJCFLAGS RFLAGS DEFS cc
6607 @c  LocalWords:  SHORTNAME vtable srcdir nostdinc basename yxx cxx ll lxx gdb
6608 @c  LocalWords:  lexers yymaxdepth maxdepth yyparse yylex yyerror yylval lval
6609 @c  LocalWords:  yychar yydebug yypact yyr yydef def yychk chk yypgo pgo yyact
6610 @c  LocalWords:  yyexca exca yyerrflag errflag yynerrs nerrs yyps yypv pv yys
6611 @c  LocalWords:  yystate yytmp tmp yyv yyval val yylloc lloc yyreds yytoks toks
6612 @c  LocalWords:  yylhs yylen yydefred yydgoto yysindex yyrindex yygindex yyname
6613 @c  LocalWords:  yytable yycheck yyrule byacc CXXCOMPILE CXXLINK FLINK cfortran
6614 @c  LocalWords:  Catalogue preprocessable FLIBS libfoo baz JAVACFLAGS java exe
6615 @c  LocalWords:  SunOS fying basenames exeext uninstalled oldinclude kr FSF's
6616 @c  LocalWords:  pkginclude oldincludedir sysconf sharedstate localstate gcc rm
6617 @c  LocalWords:  sysconfdir sharedstatedir localstatedir preexist CLEANFILES gz
6618 @c  LocalWords:  unnumberedsubsec depfile tmpdepfile depmode const interoperate
6619 @c  LocalWords:  JAVAC javac JAVAROOT builddir CLASSPATH ENV pyc pyo pkgpython
6620 @c  LocalWords:  pyexecdir pkgpyexecdir Python's pythondir pkgpythondir txi ois
6621 @c  LocalWords:  installinfo vers MAKEINFO makeinfo MAKEINFOFLAGS noinstall rf
6622 @c  LocalWords:  mandir thesame alsothesame installman myexecbin DESTDIR Pinard
6623 @c  LocalWords:  uninstall installdirs uninstalls MOSTLYCLEANFILES mostlyclean
6624 @c  LocalWords:  DISTCLEANFILES MAINTAINERCLEANFILES gzip'd GZIP gzip shar exp
6625 @c  LocalWords:  distdir distcheck distcleancheck listfiles distuninstallcheck
6626 @c  LocalWords:  VPATH tarfile stdout XFAIL DejaGnu dejagnu DEJATOOL runtest ln
6627 @c  LocalWords:  RUNTESTDEFAULTFLAGS toolchain RUNTESTFLAGS asis readme
6628 @c  LocalWords:  installcheck gzipped tarZ std utils etags mkid multilibbing cd
6629 @c  LocalWords:  ARGS taggable ETAGSFLAGS lang ctags CTAGSFLAGS GTAGS gtags idl
6630 @c  LocalWords:  foocc doit idlC multilibs ABIs cmindex defmac ARG enableval
6631 @c  LocalWords:  MSG xtrue DBG pathchk CYGWIN afile proglink versioned CVS's
6632 @c  LocalWords:  wildcards Autoconfiscated subsubheading autotools Meyering API
6633 @c  LocalWords:  ois's wildcard Wportability cartouche vrindex printindex Duret
6634 @c  LocalWords:  DSOMEFLAG DVERSION automake Lutz insertcopying versioning FAQ
6635 @c  LocalWords:  LTLIBOBJ Libtool's libtool's libltdl dlopening itutions libbar
6636 @c  LocalWords:  WANTEDLIBS libhello sublibraries libtop libsub dlopened Ratfor
6637 @c  LocalWords:  mymodule timestamps timestamp underquoted