* automake.texi (Program and Library Variables): Clarify that
[automake.git] / automake.texi
blobfdb118c3b8492e99a92b234afd06316b4f07751b
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 @dircategory GNU programming tools
11 @direntry
12 * automake: (automake).         Making Makefile.in's
13 @end direntry
15 @dircategory Individual utilities
16 @direntry
17 * aclocal: (automake)Invoking aclocal.          Generating aclocal.m4
18 @end direntry
20 @ifinfo
21 This file documents GNU automake @value{VERSION}
23 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
24 Free Software Foundation, Inc.
26 Permission is granted to make and distribute verbatim copies of
27 this manual provided the copyright notice and this permission notice
28 are preserved on all copies.
30 @ignore
31 Permission is granted to process this file through TeX and print the
32 results, provided the printed document carries copying permission
33 notice identical to this one except for the removal of this paragraph
36 @end ignore
37 Permission is granted to copy and distribute modified versions of this
38 manual under the conditions for verbatim copying, provided that the entire
39 resulting derived work is distributed under the terms of a permission
40 notice identical to this one.
42 Permission is granted to copy and distribute translations of this manual
43 into another language, under the above conditions for modified versions,
44 except that this permission notice may be stated in a translation approved
45 by the Foundation.
46 @end ifinfo
49 @titlepage
50 @title GNU Automake
51 @subtitle For version @value{VERSION}, @value{UPDATED}
52 @author David MacKenzie and Tom Tromey
54 @page
55 @vskip 0pt plus 1filll
56 Copyright @copyright{} 1995, 1996, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
57 @sp 2
58 This is the first edition of the GNU Automake documentation,@*
59 and is consistent with GNU Automake @value{VERSION}.@*
60 @sp 2
61 Published by the Free Software Foundation @*
62 59 Temple Place - Suite 330, @*
63 Boston, MA 02111-1307 USA @*
65 Permission is granted to make and distribute verbatim copies of
66 this manual provided the copyright notice and this permission notice
67 are preserved on all copies.
69 Permission is granted to copy and distribute modified versions of this
70 manual under the conditions for verbatim copying, provided that the entire
71 resulting derived work is distributed under the terms of a permission
72 notice identical to this one.
74 Permission is granted to copy and distribute translations of this manual
75 into another language, under the above conditions for modified versions,
76 except that this permission notice may be stated in a translation
77 approved by the Free Software Foundation.
78 @end titlepage
80 @c Define an index of configure output variables.
81 @defcodeindex ov
82 @c Define an index of configure variables.
83 @defcodeindex cv
84 @c Define an index of options.
85 @defcodeindex op
86 @c Define an index of targets.
87 @defcodeindex tr
88 @c Define an index of commands.
89 @defcodeindex cm
91 @c Put the macros and variables into their own index.
92 @c @syncodeindex fn cp
93 @syncodeindex ov vr
94 @syncodeindex cv vr
95 @syncodeindex fn vr
97 @c Put everything else into one index (arbitrarily chosen to be the concept index).
98 @syncodeindex op cp
99 @syncodeindex tr cp
100 @syncodeindex cm cp
102 @ifnottex
103 @node Top, Introduction, (dir), (dir)
104 @comment  node-name,  next,  previous,  up
105 @top GNU Automake
107 This file documents the GNU Automake package.  Automake is a program
108 which creates GNU standards-compliant Makefiles from template files.
109 This edition documents version @value{VERSION}.
111 @menu
112 * Introduction::                Automake's purpose
113 * Generalities::                General ideas
114 * Examples::                    Some example packages
115 * Invoking Automake::           Creating a Makefile.in
116 * configure::                   Scanning configure.ac or configure.in
117 * Top level::                   The top-level Makefile.am
118 * Alternative::                 An alternative approach to subdirectories
119 * Rebuilding::                  Automatic rebuilding of Makefile
120 * Programs::                    Building programs and libraries
121 * Other objects::               Other derived objects
122 * Other GNU Tools::             Other GNU Tools
123 * Documentation::               Building documentation
124 * Install::                     What gets installed
125 * Clean::                       What gets cleaned
126 * Dist::                        What goes in a distribution
127 * Tests::                       Support for test suites
128 * Options::                     Changing Automake's behavior
129 * Miscellaneous::               Miscellaneous rules
130 * Include::                     Including extra files in an Automake template.
131 * Conditionals::                Conditionals
132 * Gnits::                       The effect of @code{--gnu} and @code{--gnits}
133 * Cygnus::                      The effect of @code{--cygnus}
134 * Extending::                   Extending Automake
135 * Distributing::                Distributing the Makefile.in
136 * API versioning::              About compatibility between Automake versions
137 * Macro and Variable Index::
138 * General Index::
139 @end menu
141 @end ifnottex
144 @node Introduction, Generalities, Top, Top
145 @chapter Introduction
147 Automake is a tool for automatically generating @file{Makefile.in}s from
148 files called @file{Makefile.am}.  Each @file{Makefile.am} is basically a
149 series of @code{make} variable definitions@footnote{These variables are
150 also called @dfn{make macros} in Make terminology, however in this
151 manual we reserve the term @dfn{macro} for Autoconf's macros.}, with
152 rules being thrown in occasionally.  The generated @file{Makefile.in}s
153 are compliant with the GNU Makefile standards.
155 @cindex GNU Makefile standards
157 The GNU Makefile Standards Document
158 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
159 is long, complicated, and subject to change.  The goal of Automake is to
160 remove the burden of Makefile maintenance from the back of the
161 individual GNU maintainer (and put it on the back of the Automake
162 maintainer).
164 The typical Automake input file is simply a series of variable definitions.
165 Each such file is processed to create a @file{Makefile.in}.  There
166 should generally be one @file{Makefile.am} per directory of a project.
168 @cindex Constraints of Automake
169 @cindex Automake constraints
171 Automake does constrain a project in certain ways; for instance it
172 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
173 autoconf, The Autoconf Manual}), and enforces certain restrictions on
174 the @file{configure.in} contents@footnote{Autoconf 2.50 promotes
175 @file{configure.ac} over @file{configure.in}.  The rest of this
176 documentation will refer to @file{configure.in} as this use is not yet
177 spread, but Automake supports @file{configure.ac} too.}.
179 @cindex Automake requirements
180 @cindex Requirements, Automake
182 Automake requires @code{perl} in order to generate the
183 @file{Makefile.in}s.  However, the distributions created by Automake are
184 fully GNU standards-compliant, and do not require @code{perl} in order
185 to be built.
187 @cindex BUGS, reporting
188 @cindex Reporting BUGS
189 @cindex E-mail, bug reports
191 Mail suggestions and bug reports for Automake to
192 @email{bug-automake@@gnu.org}.
195 @node Generalities, Examples, Introduction, Top
196 @chapter General ideas
198 The following sections cover a few basic ideas that will help you
199 understand how Automake works.
201 @menu
202 * General Operation::           General operation of Automake
203 * Strictness::                  Standards conformance checking
204 * Uniform::                     The Uniform Naming Scheme
205 * Canonicalization::            How derived variables are named
206 * User Variables::              Variables reserved for the user
207 * Auxiliary Programs::          Programs automake might require
208 @end menu
211 @node General Operation, Strictness, Generalities, Generalities
212 @section General Operation
214 Automake works by reading a @file{Makefile.am} and generating a
215 @file{Makefile.in}.  Certain variables and targets defined in the
216 @file{Makefile.am} instruct Automake to generate more specialized code;
217 for instance, a @samp{bin_PROGRAMS} variable definition will cause targets
218 for compiling and linking programs to be generated.
220 @cindex Non-standard targets
221 @cindex cvs-dist, non-standard example
222 @trindex cvs-dist
224 The variable definitions and targets in the @file{Makefile.am} are copied
225 verbatim into the generated file.  This allows you to add arbitrary code
226 into the generated @file{Makefile.in}.  For instance the Automake
227 distribution includes a non-standard @code{cvs-dist} target, which the
228 Automake maintainer uses to make distributions from his source control
229 system.
231 @cindex GNU make extensions
233 Note that most GNU make extensions are not recognized by Automake.  Using
234 such extensions in a @file{Makefile.am} will lead to errors or confusing
235 behavior.
237 @cindex Append operator
238 A special exception is that the GNU make append operator, @samp{+=}, is
239 supported.  This operator appends its right hand argument to the variable
240 specified on the left.  Automake will translate the operator into
241 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
243 Automake tries to keep comments grouped with any adjoining targets or
244 variable definitions.
246 @cindex Make targets, overriding
247 @cindex Overriding make targets
249 A target defined in @file{Makefile.am} generally overrides any such
250 target of a similar name that would be automatically generated by
251 @code{automake}.  Although this is a supported feature, it is generally
252 best to avoid making use of it, as sometimes the generated rules are
253 very particular.
255 @cindex Variables, overriding
256 @cindex Overriding make variables
258 Similarly, a variable defined in @file{Makefile.am} or @code{AC_SUBST}'ed
259 from @file{configure.in} will override any definition of the variable that
260 @code{automake} would ordinarily create.  This feature is more often
261 useful than the ability to override a target definition.  Be warned that
262 many of the variables generated by @code{automake} are considered to be for
263 internal use only, and their names might change in future releases.
265 @cindex Recursive operation of Automake
266 @cindex Automake, recursive operation
267 @cindex Example of recursive operation
269 When examining a variable definition, Automake will recursively examine
270 variables referenced in the definition.  For example, if Automake is
271 looking at the content of @code{foo_SOURCES} in this snippet
273 @example
274 xs = a.c b.c
275 foo_SOURCES = c.c $(xs)
276 @end example
278 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
279 contents of @code{foo_SOURCES}.
281 @cindex ## (special Automake comment)
282 @cindex Special Automake comment
283 @cindex Comment, special to Automake
285 Automake also allows a form of comment which is @emph{not} copied into
286 the output; all lines beginning with @samp{##} (leading spaces allowed)
287 are completely ignored by Automake.
289 It is customary to make the first line of @file{Makefile.am} read:
291 @cindex Makefile.am, first line
292 @cindex First line of Makefile.am
294 @example
295 ## Process this file with automake to produce Makefile.in
296 @end example
298 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
299 @c I don't know quite what to say.
301 @c FIXME document customary ordering of Makefile.am here!
304 @node Strictness, Uniform, General Operation, Generalities
305 @section Strictness
307 @cindex Non-GNU packages
309 While Automake is intended to be used by maintainers of GNU packages, it
310 does make some effort to accommodate those who wish to use it, but do
311 not want to use all the GNU conventions.
313 @cindex Strictness, defined
314 @cindex Strictness, foreign
315 @cindex foreign strictness
316 @cindex Strictness, gnu
317 @cindex gnu strictness
318 @cindex Strictness, gnits
319 @cindex gnits strictness
321 To this end, Automake supports three levels of @dfn{strictness}---the
322 strictness indicating how stringently Automake should check standards
323 conformance.
325 The valid strictness levels are:
327 @table @samp
328 @item foreign
329 Automake will check for only those things which are absolutely
330 required for proper operations.  For instance, whereas GNU standards
331 dictate the existence of a @file{NEWS} file, it will not be required in
332 this mode.  The name comes from the fact that Automake is intended to be
333 used for GNU programs; these relaxed rules are not the standard mode of
334 operation.
336 @item gnu
337 Automake will check---as much as possible---for compliance to the GNU
338 standards for packages.  This is the default.
340 @item gnits
341 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
342 standards}.  These are based on the GNU standards, but are even more
343 detailed.  Unless you are a Gnits standards contributor, it is
344 recommended that you avoid this option until such time as the Gnits
345 standard is actually published (which may never happen).
346 @end table
348 For more information on the precise implications of the strictness
349 level, see @ref{Gnits}.
351 Automake also has a special ``cygnus'' mode which is similar to
352 strictness but handled differently.  This mode is useful for packages
353 which are put into a ``Cygnus'' style tree (e.g., the GCC tree).  For
354 more information on this mode, see @ref{Cygnus}.
357 @node Uniform, Canonicalization, Strictness, Generalities
358 @section The Uniform Naming Scheme
360 @cindex Uniform naming scheme
362 Automake variables generally follow a @dfn{uniform naming scheme} that
363 makes it easy to decide how programs (and other derived objects) are
364 built, and how they are installed.  This scheme also supports
365 @code{configure} time determination of what should be built.
367 @cindex _PROGRAMS primary variable
368 @cindex PROGRAMS primary variable
369 @cindex Primary variable, PROGRAMS
370 @cindex Primary variable, defined
372 At @code{make} time, certain variables are used to determine which
373 objects are to be built.  The variable names are made of several pieces
374 which are concatenated together.
376 The piece which tells automake what is being built is commonly called
377 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
378 list of programs which are to be compiled and linked.
379 @vindex PROGRAMS
381 @cindex pkglibdir, defined
382 @cindex pkgincludedir, defined
383 @cindex pkgdatadir, defined
385 @vindex pkglibdir
386 @vindex pkgincludedir
387 @vindex pkgdatadir
389 A different set of names is used to decide where the built objects
390 should be installed.  These names are prefixes to the primary which
391 indicate which standard directory should be used as the installation
392 directory.  The standard directory names are given in the GNU standards
393 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
394 Automake extends this list with @code{pkglibdir}, @code{pkgincludedir},
395 and @code{pkgdatadir}; these are the same as the non-@samp{pkg}
396 versions, but with @samp{@@PACKAGE@@} appended.  For instance,
397 @code{pkglibdir} is defined as @code{$(libdir)/@@PACKAGE@@}.
398 @cvindex PACKAGE, directory
400 @cindex EXTRA_, prepending
402 For each primary, there is one additional variable named by prepending
403 @samp{EXTRA_} to the primary name.  This variable is used to list
404 objects which may or may not be built, depending on what
405 @code{configure} decides.  This variable is required because Automake
406 must statically know the entire list of objects that may be built in
407 order to generate a @file{Makefile.in} that will work in all cases.
409 @cindex EXTRA_PROGRAMS, defined
410 @cindex Example, EXTRA_PROGRAMS
411 @cindex cpio example
413 For instance, @code{cpio} decides at configure time which programs are
414 built.  Some of the programs are installed in @code{bindir}, and some
415 are installed in @code{sbindir}:
417 @example
418 EXTRA_PROGRAMS = mt rmt
419 bin_PROGRAMS = cpio pax
420 sbin_PROGRAMS = @@MORE_PROGRAMS@@
421 @end example
423 Defining a primary without a prefix as a variable, e.g.,
424 @code{PROGRAMS}, is an error.
426 Note that the common @samp{dir} suffix is left off when constructing the
427 variable names; thus one writes @samp{bin_PROGRAMS} and not
428 @samp{bindir_PROGRAMS}.
430 Not every sort of object can be installed in every directory.  Automake
431 will flag those attempts it finds in error.
432 Automake will also diagnose obvious misspellings in directory names.
434 @cindex Extending list of installation directories
435 @cindex Installation directories, extending list
437 Sometimes the standard directories---even as augmented by Automake---
438 are not enough.  In particular it is sometimes useful, for clarity, to
439 install objects in a subdirectory of some predefined directory.  To this
440 end, Automake allows you to extend the list of possible installation
441 directories.  A given prefix (e.g. @samp{zar}) is valid if a variable of
442 the same name with @samp{dir} appended is defined (e.g. @code{zardir}).
444 @cindex HTML support, example
446 For instance, until HTML support is part of Automake, you could use this
447 to install raw HTML documentation:
449 @example
450 htmldir = $(prefix)/html
451 html_DATA = automake.html
452 @end example
454 @cindex noinst primary prefix, definition
456 The special prefix @samp{noinst} indicates that the objects in question
457 should be built but not installed at all.  This is usually used for
458 objects required to build the rest of your package, for instance static
459 libraries (@pxref{A Library}), or helper scripts.
461 @cindex check primary prefix, definition
463 The special prefix @samp{check} indicates that the objects in question
464 should not be built until the @code{make check} command is run.  Those
465 objects are not installed either.
467 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
468 @samp{LISP}, @samp{PYTHON}, @samp{JAVA}, @samp{SCRIPTS}, @samp{DATA},
469 @samp{HEADERS}, @samp{MANS}, and @samp{TEXINFOS}.
470 @vindex PROGRAMS
471 @vindex LIBRARIES
472 @vindex LISP
473 @vindex PYTHON
474 @vindex JAVA
475 @vindex SCRIPTS
476 @vindex DATA
477 @vindex HEADERS
478 @vindex MANS
479 @vindex TEXINFOS
481 Some primaries also allow additional prefixes which control other
482 aspects of @code{automake}'s behavior.  The currently defined prefixes
483 are @samp{dist_}, @samp{nodist_}, and @samp{nobase_}.  These prefixes
484 are explained later (@pxref{Program and Library Variables}).
487 @node Canonicalization, User Variables, Uniform, Generalities
488 @section How derived variables are named
490 @cindex canonicalizing Automake variables
492 Sometimes a Makefile variable name is derived from some text the
493 maintainer supplies.  For instance, a program name listed in
494 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
495 variable.  In cases like this, Automake canonicalizes the text, so that
496 program names and the like do not have to follow Makefile variable naming
497 rules.  All characters in the name except for letters, numbers, the
498 strudel (@@), and the underscore are turned into underscores when making
499 variable references.
501 For example, if your program is named @code{sniff-glue}, the derived
502 variable name would be @code{sniff_glue_SOURCES}, not
503 @code{sniff-glue_SOURCES}.  Similarly the sources for a library named
504 @code{libmumble++.a} should be listed in the
505 @code{libmumble___a_SOURCES} variable.
507 The strudel is an addition, to make the use of Autoconf substitutions in
508 variable names less obfuscating.
511 @node User Variables, Auxiliary Programs, Canonicalization, Generalities
512 @section Variables reserved for the user
514 @cindex variables, reserved for the user
515 @cindex user variables
517 Some @code{Makefile} variables are reserved by the GNU Coding Standards
518 for the use of the ``user'' -- the person building the package.  For
519 instance, @code{CFLAGS} is one such variable.
521 Sometimes package developers are tempted to set user variables such as
522 @code{CFLAGS} because it appears to make their job easier -- they don't
523 have to introduce a second variable into every target.
525 However, the package itself should never set a user variable,
526 particularly not to include switches which are required for proper
527 compilation of the package.  Since these variables are documented as
528 being for the package builder, that person rightfully expects to be able
529 to override any of these variables at build time.
531 To get around this problem, automake introduces an automake-specific
532 shadow variable for each user flag variable.  (Shadow variables are not
533 introduced for variables like @code{CC}, where they would make no
534 sense.)  The shadow variable is named by prepending @samp{AM_} to the
535 user variable's name.  For instance, the shadow variable for
536 @code{YFLAGS} is @code{AM_YFLAGS}.
539 @node Auxiliary Programs,  , User Variables, Generalities
540 @section Programs automake might require
542 @cindex Programs, auxiliary
543 @cindex Auxiliary programs
545 Automake sometimes requires helper programs so that the generated
546 @file{Makefile} can do its work properly.  There are a fairly large
547 number of them, and we list them here.
549 @table @code
550 @item ansi2knr.c
551 @itemx ansi2knr.1
552 These two files are used by the automatic de-ANSI-fication support
553 (@pxref{ANSI}).
555 @item compile
556 This is a wrapper for compilers which don't accept both @samp{-c} and
557 @samp{-o} at the same time.  It is only used when absolutely required.
558 Such compilers are rare.
560 @item config.guess
561 @itemx config.sub
562 These programs compute the canonical triplets for the given build, host,
563 or target architecture.  These programs are updated regularly to support
564 new architectures and fix probes broken by changes in new kernel
565 versions.  You are encouraged to fetch the latest versions of these
566 files from @url{ftp://ftp.gnu.org/gnu/config/} before making a release.
568 @item depcomp
569 This program understands how to run a compiler so that it will generate
570 not only the desired output but also dependency information which is
571 then used by the automatic dependency tracking feature.
573 @item elisp-comp
574 This program is used to byte-compile Emacs Lisp code.
576 @item install-sh
577 This is a replacement for the @code{install} program which works on
578 platforms where @code{install} is unavailable or unusable.
580 @item mdate-sh
581 This script is used to generate a @file{version.texi} file.  It examines
582 a file and prints some date information about it.
584 @item missing
585 This wraps a number of programs which are typically only required by
586 maintainers.  If the program in question doesn't exist, @code{missing}
587 prints an informative warning and attempts to fix things so that the
588 build can continue.
590 @item mkinstalldirs
591 This works around the fact that @code{mkdir -p} is not portable.
593 @item py-compile
594 This is used to byte-compile Python scripts.
596 @item texinfo.tex
597 Not a program, this file is required for @code{make dvi}, @code{make ps}
598 and @code{make pdf} to work when Texinfo sources are in the package.
600 @item ylwrap
601 This program wraps @code{lex} and @code{yacc} and ensures that, for
602 instance, multiple @code{yacc} instances can be invoked in a single
603 directory in parallel.
605 @end table
608 @node Examples, Invoking Automake, Generalities, Top
609 @chapter Some example packages
611 @menu
612 * Complete::                    A simple example, start to finish
613 * Hello::                       A classic program
614 * true::                        Building true and false
615 @end menu
618 @node Complete, Hello, Examples, Examples
619 @section A simple example, start to finish
621 @cindex Complete example
623 Let's suppose you just finished writing @code{zardoz}, a program to make
624 your head float from vortex to vortex.  You've been using Autoconf to
625 provide a portability framework, but your @file{Makefile.in}s have been
626 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
628 @cindex AM_INIT_AUTOMAKE, example use
630 The first step is to update your @file{configure.in} to include the
631 commands that @code{automake} needs.  The way to do this is to add an
632 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
634 @example
635 AC_INIT(zardoz, 1.0)
636 AM_INIT_AUTOMAKE
637 @dots{}
638 @end example
640 Since your program doesn't have any complicating factors (e.g., it
641 doesn't use @code{gettext}, it doesn't want to build a shared library),
642 you're done with this part.  That was easy!
644 @cindex aclocal program, introduction
645 @cindex aclocal.m4, preexisting
646 @cindex acinclude.m4, defined
648 Now you must regenerate @file{configure}.  But to do that, you'll need
649 to tell @code{autoconf} how to find the new macro you've used.  The
650 easiest way to do this is to use the @code{aclocal} program to generate
651 your @file{aclocal.m4} for you.  But wait@dots{} maybe you already have an
652 @file{aclocal.m4}, because you had to write some hairy macros for your
653 program.  The @code{aclocal} program lets you put your own macros into
654 @file{acinclude.m4}, so simply rename and then run:
656 @example
657 mv aclocal.m4 acinclude.m4
658 aclocal
659 autoconf
660 @end example
662 @cindex zardoz example
664 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
665 Since @code{zardoz} is a user program, you want to install it where the
666 rest of the user programs go: @code{bindir}.  Additionally,
667 @code{zardoz} has some Texinfo documentation.  Your @file{configure.in}
668 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
669 @samp{$(LIBOBJS)}.  So here's what you'd write:
671 @example
672 bin_PROGRAMS = zardoz
673 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
674 zardoz_LDADD = $(LIBOBJS)
676 info_TEXINFOS = zardoz.texi
677 @end example
679 Now you can run @code{automake --add-missing} to generate your
680 @file{Makefile.in} and grab any auxiliary files you might need, and
681 you're done!
684 @node Hello, true, Complete, Examples
685 @section A classic program
687 @cindex Example, GNU Hello
688 @cindex Hello example
689 @cindex GNU Hello, example
691 @uref{ftp://prep.ai.mit.edu/pub/gnu/hello-1.3.tar.gz, GNU hello} is
692 renowned for its classic simplicity and versatility.  This section shows
693 how Automake could be used with the GNU Hello package.  The examples
694 below are from the latest beta version of GNU Hello, but with all of the
695 maintainer-only code stripped out, as well as all copyright comments.
697 Of course, GNU Hello is somewhat more featureful than your traditional
698 two-liner.  GNU Hello is internationalized, does option processing, and
699 has a manual and a test suite.
701 @cindex configure.in, from GNU Hello
702 @cindex GNU Hello, configure.in
703 @cindex Hello, configure.in
705 Here is the @file{configure.in} from GNU Hello:
706 @c FIXME: This definitively requires an update.
708 @example
709 dnl Process this file with autoconf to produce a configure script.
710 AC_INIT(src/hello.c)
711 AM_INIT_AUTOMAKE(hello, 1.3.11)
712 AM_CONFIG_HEADER(config.h)
714 dnl Set of available languages.
715 ALL_LINGUAS="de fr es ko nl no pl pt sl sv"
717 dnl Checks for programs.
718 AC_PROG_CC
719 AC_ISC_POSIX
721 dnl Checks for libraries.
723 dnl Checks for header files.
724 AC_STDC_HEADERS
725 AC_HAVE_HEADERS(string.h fcntl.h sys/file.h sys/param.h)
727 dnl Checks for library functions.
728 AC_FUNC_ALLOCA
730 dnl Check for st_blksize in struct stat
731 AC_ST_BLKSIZE
733 dnl internationalization macros
734 AM_GNU_GETTEXT
735 AC_OUTPUT([Makefile doc/Makefile intl/Makefile po/Makefile.in \
736            src/Makefile tests/Makefile tests/hello],
737    [chmod +x tests/hello])
738 @end example
740 The @samp{AM_} macros are provided by Automake (or the Gettext library);
741 the rest are standard Autoconf macros.
744 The top-level @file{Makefile.am}:
746 @example
747 EXTRA_DIST = BUGS ChangeLog.O
748 SUBDIRS = doc intl po src tests
749 @end example
751 As you can see, all the work here is really done in subdirectories.
753 The @file{po} and @file{intl} directories are automatically generated
754 using @code{gettextize}; they will not be discussed here.
756 @cindex Texinfo file handling example
757 @cindex Example, handling Texinfo files
759 In @file{doc/Makefile.am} we see:
761 @example
762 info_TEXINFOS = hello.texi
763 hello_TEXINFOS = gpl.texi
764 @end example
766 This is sufficient to build, install, and distribute the GNU Hello
767 manual.
769 @cindex Regression test example
770 @cindex Example, regression test
772 Here is @file{tests/Makefile.am}:
774 @example
775 TESTS = hello
776 EXTRA_DIST = hello.in testdata
777 @end example
779 The script @file{hello} is generated by @code{configure}, and is the
780 only test case.  @code{make check} will run this test.
782 @cindex INCLUDES, example usage
784 Last we have @file{src/Makefile.am}, where all the real work is done:
785 @c FIXME: As all the Hello World excerpts in this manual, this
786 @c shows deprecated features (here: $(INCLUDES)).
788 @example
789 bin_PROGRAMS = hello
790 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
791 hello_LDADD = @@INTLLIBS@@ @@ALLOCA@@
792 localedir = $(datadir)/locale
793 INCLUDES = -I../intl -DLOCALEDIR=\"$(localedir)\"
794 @end example
797 @node true,  , Hello, Examples
798 @section Building true and false
800 @cindex Example, false and true
801 @cindex false Example
802 @cindex true Example
804 Here is another, trickier example.  It shows how to generate two
805 programs (@code{true} and @code{false}) from the same source file
806 (@file{true.c}).  The difficult part is that each compilation of
807 @file{true.c} requires different @code{cpp} flags.
809 @example
810 bin_PROGRAMS = true false
811 false_SOURCES =
812 false_LDADD = false.o
814 true.o: true.c
815         $(COMPILE) -DEXIT_CODE=0 -c true.c
817 false.o: true.c
818         $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
819 @end example
821 Note that there is no @code{true_SOURCES} definition.  Automake will
822 implicitly assume that there is a source file named @file{true.c}, and
823 define rules to compile @file{true.o} and link @file{true}.  The
824 @code{true.o: true.c} rule supplied by the above @file{Makefile.am},
825 will override the Automake generated rule to build @file{true.o}.
827 @code{false_SOURCES} is defined to be empty---that way no implicit value
828 is substituted.  Because we have not listed the source of
829 @file{false}, we have to tell Automake how to link the program.  This is
830 the purpose of the @code{false_LDADD} line.  A @code{false_DEPENDENCIES}
831 variable, holding the dependencies of the @file{false} target will be
832 automatically generated by Automake from the content of
833 @code{false_LDADD}.
835 The above rules won't work if your compiler doesn't accept both
836 @samp{-c} and @samp{-o}.  The simplest fix for this is to introduce a
837 bogus dependency (to avoid problems with a parallel @code{make}):
839 @example
840 true.o: true.c false.o
841         $(COMPILE) -DEXIT_CODE=0 -c true.c
843 false.o: true.c
844         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
845 @end example
847 Also, these explicit rules do not work if the de-ANSI-fication feature
848 is used (@pxref{ANSI}).  Supporting de-ANSI-fication requires a little
849 more work:
851 @example
852 true._o: true._c false.o
853         $(COMPILE) -DEXIT_CODE=0 -c true.c
855 false._o: true._c
856         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true._o false.o
857 @end example
859 As it turns out, there is also a much easier way to do this same task.
860 Some of the above techniques are useful enough that we've kept the
861 example in the manual.  However if you were to build @code{true} and
862 @code{false} in real life, you would probably use per-program
863 compilation flags, like so:
865 @example
866 bin_PROGRAMS = false true
868 false_SOURCES = true.c
869 false_CPPFLAGS = -DEXIT_CODE=1
871 true_SOURCES = true.c
872 true_CPPFLAGS = -DEXIT_CODE=0
873 @end example
875 In this case Automake will cause @file{true.c} to be compiled twice,
876 with different flags.  De-ANSI-fication will work automatically.  In
877 this instance, the names of the object files would be chosen by
878 automake; they would be @file{false-true.o} and @file{true-true.o}.
879 (The name of the object files rarely matters.)
882 @node Invoking Automake, configure, Examples, Top
883 @chapter Creating a @file{Makefile.in}
885 @cindex Multiple configure.in files
886 @cindex Invoking Automake
887 @cindex Automake, invoking
889 To create all the @file{Makefile.in}s for a package, run the
890 @code{automake} program in the top level directory, with no arguments.
891 @code{automake} will automatically find each appropriate
892 @file{Makefile.am} (by scanning @file{configure.in}; @pxref{configure})
893 and generate the corresponding @file{Makefile.in}.  Note that
894 @code{automake} has a rather simplistic view of what constitutes a
895 package; it assumes that a package has only one @file{configure.in}, at
896 the top.  If your package has multiple @file{configure.in}s, then you
897 must run @code{automake} in each directory holding a
898 @file{configure.in}.  (Alternatively, you may rely on Autoconf's
899 @code{autoreconf}, which is able to recurse your package tree and run
900 @code{automake} where appropriate.)
902 You can optionally give @code{automake} an argument; @file{.am} is
903 appended to the argument and the result is used as the name of the input
904 file.  This feature is generally only used to automatically rebuild an
905 out-of-date @file{Makefile.in}.  Note that @code{automake} must always
906 be run from the topmost directory of a project, even if being used to
907 regenerate the @file{Makefile.in} in some subdirectory.  This is
908 necessary because @code{automake} must scan @file{configure.in}, and
909 because @code{automake} uses the knowledge that a @file{Makefile.in} is
910 in a subdirectory to change its behavior in some cases.
912 @vindex AUTOCONF
913 Automake will run @code{autoconf} to scan @file{configure.in} and its
914 dependencies (@file{aclocal.m4}), therefore @code{autoconf} must be in
915 your @code{PATH}.  If there is an @code{AUTOCONF} variable in your
916 environment it will be used instead of @code{autoconf}, this allows you
917 to select a particular version of Autoconf.  By the way, don't
918 misunderstand this paragraph: Automake runs @code{autoconf} to
919 @strong{scan} your @file{configure.in}, this won't build
920 @file{configure} and you still have to run @code{autoconf} yourself for
921 this purpose.
923 @cindex Automake options
924 @cindex Options, Automake
925 @cindex Strictness, command line
927 @code{automake} accepts the following options:
929 @cindex Extra files distributed with Automake
930 @cindex Files distributed with Automake
931 @cindex config.guess
933 @table @samp
934 @item -a
935 @itemx --add-missing
936 @opindex -a
937 @opindex --add-missing
938 Automake requires certain common files to exist in certain situations;
939 for instance @file{config.guess} is required if @file{configure.in} runs
940 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
941 files (@pxref{Auxiliary Programs}); this option will cause the missing
942 ones to be automatically added to the package, whenever possible.  In
943 general if Automake tells you a file is missing, try using this option.
944 By default Automake tries to make a symbolic link pointing to its own
945 copy of the missing file; this can be changed with @code{--copy}.
947 @item --libdir=@var{dir}
948 @opindex --libdir
949 Look for Automake data files in directory @var{dir} instead of in the
950 installation directory.  This is typically used for debugging.
952 @item -c
953 @opindex -c
954 @itemx --copy
955 @opindex --copy
956 When used with @code{--add-missing}, causes installed files to be
957 copied.  The default is to make a symbolic link.
959 @item --cygnus
960 @opindex --cygnus
961 Causes the generated @file{Makefile.in}s to follow Cygnus rules, instead
962 of GNU or Gnits rules.  For more information, see @ref{Cygnus}.
964 @item -f
965 @opindex -f
966 @itemx --force-missing
967 @opindex --force-missing
968 When used with @code{--add-missing}, causes standard files to be reinstalled
969 even if they already exist in the source tree.  This involves removing
970 the file from the source tree before creating the new symlink (or, with
971 @code{--copy}, copying the new file).
973 @item --foreign
974 @opindex --foreign
975 Set the global strictness to @samp{foreign}.  For more information, see
976 @ref{Strictness}.
978 @item --gnits
979 @opindex --gnits
980 Set the global strictness to @samp{gnits}.  For more information, see
981 @ref{Gnits}.
983 @item --gnu
984 @opindex --gnu
985 Set the global strictness to @samp{gnu}.  For more information, see
986 @ref{Gnits}.  This is the default strictness.
988 @item --help
989 @opindex --help
990 Print a summary of the command line options and exit.
992 @item -i
993 @itemx --ignore-deps
994 @opindex -i
995 This disables the dependency tracking feature in generated
996 @file{Makefile}s; see @ref{Dependencies}.
998 @item --include-deps
999 @opindex --include-deps
1000 This enables the dependency tracking feature.  This feature is enabled
1001 by default.  This option is provided for historical reasons only and
1002 probably should not be used.
1004 @item --no-force
1005 @opindex --no-force
1006 Ordinarily @code{automake} creates all @file{Makefile.in}s mentioned in
1007 @file{configure.in}.  This option causes it to only update those
1008 @file{Makefile.in}s which are out of date with respect to one of their
1009 dependents.
1011 @item -o @var{dir}
1012 @itemx --output-dir=@var{dir}
1013 @opindex -o
1014 @opindex --output-dir
1015 Put the generated @file{Makefile.in} in the directory @var{dir}.
1016 Ordinarily each @file{Makefile.in} is created in the directory of the
1017 corresponding @file{Makefile.am}.  This option is deprecated and will be
1018 removed in a future release.
1020 @item -v
1021 @itemx --verbose
1022 @opindex -v
1023 @opindex --verbose
1024 Cause Automake to print information about which files are being read or
1025 created.
1027 @item --version
1028 @opindex --version
1029 Print the version number of Automake and exit.
1031 @item -W CATEGORY
1032 @item --warnings=@var{category}
1033 @opindex -W
1034 @opindex --warnings
1035 Output warnings falling in @var{category}.  @var{category} can be
1036 one of:
1037 @table @samp
1038 @item gnu
1039 warnings related to the GNU Coding Standards
1040 (@pxref{Top, , , standards, The GNU Coding Standards}).
1041 @item obsolete
1042 obsolete features or constructions
1043 @item portability
1044 portability issues (e.g., use of Make features which are known not portable)
1045 @item syntax
1046 weird syntax, unused variables, typos
1047 @item unsupported
1048 unsupported or incomplete features
1049 @item all
1050 all the warnings
1051 @item none
1052 turn off all the warnings
1053 @item error
1054 treat warnings as errors
1055 @end table
1057 A category can be turned off by prefixing its name with @samp{no-}.  For
1058 instance @samp{-Wno-syntax} will hide the warnings about unused
1059 variables.
1061 The categories output by default are @samp{syntax} and
1062 @samp{unsupported}.  Additionally, @samp{gnu} is enabled in @samp{--gnu} and
1063 @samp{--gnits} strictness.
1065 @samp{portability} warnings are currently disabled by default, but they
1066 will be enabled in @samp{--gnu} and @samp{--gnits} strictness in a
1067 future release.
1069 @vindex WARNINGS
1070 The environment variable @samp{WARNINGS} can contain a comma separated
1071 list of categories to enable.  It will be taken into account before the
1072 command-line switches, this way @samp{-Wnone} will also ignore any
1073 warning category enabled by @samp{WARNINGS}.  This variable is also used
1074 by other tools like @command{autoconf}; unknown categories are ignored
1075 for this reason.
1077 @end table
1080 @node configure, Top level, Invoking Automake, Top
1081 @chapter Scanning @file{configure.in}
1083 @cindex configure.in, scanning
1084 @cindex Scanning configure.in
1086 Automake scans the package's @file{configure.in} to determine certain
1087 information about the package.  Some @code{autoconf} macros are required
1088 and some variables must be defined in @file{configure.in}.  Automake
1089 will also use information from @file{configure.in} to further tailor its
1090 output.
1092 Automake also supplies some Autoconf macros to make the maintenance
1093 easier.  These macros can automatically be put into your
1094 @file{aclocal.m4} using the @code{aclocal} program.
1096 @menu
1097 * Requirements::                Configuration requirements
1098 * Optional::                    Other things Automake recognizes
1099 * Invoking aclocal::            Auto-generating aclocal.m4
1100 * aclocal options::             aclocal command line arguments
1101 * Macro search path::           Modifying aclocal's search path
1102 * Macros::                      Autoconf macros supplied with Automake
1103 * Extending aclocal::           Writing your own aclocal macros
1104 @end menu
1107 @node Requirements, Optional, configure, configure
1108 @section Configuration requirements
1110 @cindex Automake requirements
1111 @cindex Requirements of Automake
1113 The one real requirement of Automake is that your @file{configure.in}
1114 call @code{AM_INIT_AUTOMAKE}.  This macro does several things which are
1115 required for proper Automake operation (@pxref{Macros}).
1116 @cvindex AM_INIT_AUTOMAKE
1118 Here are the other macros which Automake requires but which are not run
1119 by @code{AM_INIT_AUTOMAKE}:
1121 @cindex AC_OUTPUT, scanning
1123 @table @code
1124 @item AC_CONFIG_FILES
1125 @itemx AC_OUTPUT
1126 Automake uses these to determine which files to create (@pxref{Output, ,
1127 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
1128 is considered to be an Automake generated @file{Makefile} if there
1129 exists a file with the same name and the @file{.am} extension appended.
1130 Typically, @code{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
1131 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
1133 Other listed files are treated differently.  Currently the only
1134 difference is that an Automake @file{Makefile} is removed by @code{make
1135 distclean}, while other files are removed by @code{make clean}.
1136 @c FIXME: this is in violation of standards!
1137 @cvindex AC_OUTPUT
1138 @end table
1141 @node Optional, Invoking aclocal, Requirements, configure
1142 @section Other things Automake recognizes
1144 @cindex Macros Automake recognizes
1145 @cindex Recognized macros by Automake
1147 Every time Automake is run it calls Autoconf to trace
1148 @file{configure.in}.  This way it can recognize the use of certain
1149 macros and tailor the generated @file{Makefile.in} appropriately.
1150 Currently recognized macros and their effects are:
1152 @table @code
1153 @item AC_CONFIG_HEADERS
1154 Automake will generate rules to rebuild these headers.  Older versions
1155 of Automake required the use of @code{AM_CONFIG_HEADER}
1156 (@pxref{Macros}); this is no longer the case today.
1157 @cvindex AC_CONFIG_HEADERS
1159 @item AC_CONFIG_AUX_DIR
1160 Automake will look for various helper scripts, such as
1161 @file{mkinstalldirs}, in the directory named in this macro invocation.
1162 If not seen, the scripts are looked for in their @samp{standard}
1163 locations (either the top source directory, or in the source directory
1164 corresponding to the current @file{Makefile.am}, whichever is
1165 appropriate).  @xref{Input, , Finding `configure' Input, autoconf, The
1166 Autoconf Manual}.
1167 @cvindex AC_CONFIG_AUX_DIR
1168 @c FIXME: give complete list of things looked for in this directory
1170 @item AC_CANONICAL_HOST
1171 Automake will ensure that @file{config.guess} and @file{config.sub}
1172 exist.  Also, the @file{Makefile} variables @samp{host_alias} and
1173 @samp{host_triplet} are introduced.  See @ref{Canonicalizing, ,
1174 Getting the Canonical System Type, autoconf, The Autoconf Manual}.
1175 @cvindex AC_CANONICAL_HOST
1176 @vindex host_alias
1177 @vindex host_triplet
1179 @item AC_CANONICAL_SYSTEM
1180 This is similar to @code{AC_CANONICAL_HOST}, but also defines the
1181 @file{Makefile} variables @samp{build_alias} and @samp{target_alias}.
1182 @xref{Canonicalizing, , Getting the Canonical System Type, autoconf, The
1183 Autoconf Manual}.
1184 @cvindex AC_CANONICAL_SYSTEM
1185 @vindex build_alias
1186 @vindex target_alias
1188 @item AC_LIBSOURCE
1189 @itemx AC_LIBSOURCES
1190 @itemx AC_LIBOBJ
1191 Automake will automatically distribute any file listed in
1192 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
1194 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}.  So if
1195 an Autoconf macro is documented to call @code{AC_LIBOBJ([file])}, then
1196 @file{file.c} will be distributed automatically by Automake.  This
1197 encompasses many macros like @code{AC_FUNC_ALLOCA},
1198 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
1199 @cvindex AC_LIBOBJ
1200 @cvindex AC_LIBSOURCE
1201 @cvindex AC_LIBSOURCES
1203 By the way, direct assignments to @code{LIBOBJS} are no longer
1204 supported.  You should always use @code{AC_LIBOBJ} for this purpose.
1205 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs. @code{LIBOBJS},
1206 autoconf, The Autoconf Manual}.
1207 @cvindex LIBOBJS
1209 @item AC_PROG_RANLIB
1210 This is required if any libraries are built in the package.
1211 @xref{Particular Programs, , Particular Program Checks, autoconf, The
1212 Autoconf Manual}.
1213 @cvindex AC_PROG_RANLIB
1215 @item AC_PROG_CXX
1216 This is required if any C++ source is included.  @xref{Particular
1217 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
1218 @cvindex AC_PROG_CXX
1220 @item AC_PROG_F77
1221 This is required if any Fortran 77 source is included.  This macro is
1222 distributed with Autoconf version 2.13 and later.  @xref{Particular
1223 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
1224 @cvindex AC_PROG_F77
1226 @item AC_F77_LIBRARY_LDFLAGS
1227 This is required for programs and shared libraries that are a mixture of
1228 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
1229 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
1230 @cvindex AC_F77_LIBRARY_LDFLAGS
1232 @item AC_PROG_LIBTOOL
1233 Automake will turn on processing for @code{libtool} (@pxref{Top, ,
1234 Introduction, libtool, The Libtool Manual}).
1235 @cvindex AC_PROG_LIBTOOL
1237 @item AC_PROG_YACC
1238 If a Yacc source file is seen, then you must either use this macro or
1239 define the variable @samp{YACC} in @file{configure.in}.  The former is
1240 preferred (@pxref{Particular Programs, , Particular Program Checks,
1241 autoconf, The Autoconf Manual}).
1242 @cvindex AC_PROG_YACC
1243 @cvindex YACC
1245 @item AC_PROG_LEX
1246 If a Lex source file is seen, then this macro must be used.
1247 @xref{Particular Programs, , Particular Program Checks, autoconf, The
1248 Autoconf Manual}.
1249 @cvindex AC_PROG_LEX
1251 @item AC_SUBST
1252 @cvindex AC_SUBST
1253 The first argument is automatically defined as a variable in each
1254 generated @file{Makefile.in}.  @xref{Setting Output Variables, , Setting
1255 Output Variables, autoconf, The Autoconf Manual}.
1257 If the Autoconf manual says that a macro calls @code{AC_SUBST} for
1258 @var{var}, or defined the output variable @var{var} then @var{var} will
1259 be defined in each generated @file{Makefile.in}.
1260 E.g. @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and @code{X_LIBS}, so
1261 you can use the variable in any @file{Makefile.am} if
1262 @code{AC_PATH_XTRA} is called.
1264 @item AM_C_PROTOTYPES
1265 This is required when using automatic de-ANSI-fication; see @ref{ANSI}.
1266 @cvindex AM_C_PROTOTYPES
1268 @item AM_GNU_GETTEXT
1269 This macro is required for packages which use GNU gettext
1270 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
1271 this macro it ensures that the package meets some of gettext's
1272 requirements.
1273 @cvindex AM_GNU_GETTEXT
1275 @item AM_MAINTAINER_MODE
1276 @opindex --enable-maintainer-mode
1277 This macro adds a @samp{--enable-maintainer-mode} option to
1278 @code{configure}.  If this is used, @code{automake} will cause
1279 @samp{maintainer-only} rules to be turned off by default in the
1280 generated @file{Makefile.in}s. This macro defines the
1281 @samp{MAINTAINER_MODE} conditional, which you can use in your own
1282 @file{Makefile.am}.
1283 @cvindex AM_MAINTAINER_MODE
1285 @end table
1288 @node Invoking aclocal, aclocal options, Optional, configure
1289 @section Auto-generating aclocal.m4
1291 @cindex Invoking aclocal
1292 @cindex aclocal, Invoking
1294 Automake includes a number of Autoconf macros which can be used in your
1295 package; some of them are actually required by Automake in certain
1296 situations.  These macros must be defined in your @file{aclocal.m4};
1297 otherwise they will not be seen by @code{autoconf}.
1299 The @code{aclocal} program will automatically generate @file{aclocal.m4}
1300 files based on the contents of @file{configure.in}.  This provides a
1301 convenient way to get Automake-provided macros, without having to
1302 search around.  Also, the @code{aclocal} mechanism allows other packages
1303 to supply their own macros.
1305 At startup, @code{aclocal} scans all the @file{.m4} files it can find,
1306 looking for macro definitions (@pxref{Macro search path}).  Then it
1307 scans @file{configure.in}.  Any
1308 mention of one of the macros found in the first step causes that macro,
1309 and any macros it in turn requires, to be put into @file{aclocal.m4}.
1311 The contents of @file{acinclude.m4}, if it exists, are also
1312 automatically included in @file{aclocal.m4}.  This is useful for
1313 incorporating local macros into @file{configure}.
1315 @code{aclocal} tries to be smart about looking for new @code{AC_DEFUN}s
1316 in the files it scans.  It also
1317 tries to copy the full text of the scanned file into @file{aclocal.m4},
1318 including both @samp{#} and @samp{dnl} comments.  If you want to make a
1319 comment which will be completely ignored by @code{aclocal}, use
1320 @samp{##} as the comment leader.
1322 @menu
1323 * aclocal options::             Options supported by aclocal
1324 * Macro search path::           How aclocal finds .m4 files
1325 @end menu
1327 @node aclocal options, Macro search path, Invoking aclocal, configure
1328 @section aclocal options
1330 @cindex aclocal, Options
1331 @cindex Options, aclocal
1333 @code{aclocal} accepts the following options:
1335 @table @code
1336 @item --acdir=@var{dir}
1337 @opindex --acdir
1338 Look for the macro files in @var{dir} instead of the installation
1339 directory.  This is typically used for debugging.
1341 @item --help
1342 @opindex --help
1343 Print a summary of the command line options and exit.
1345 @item -I @var{dir}
1346 @opindex -I
1347 Add the directory @var{dir} to the list of directories searched for
1348 @file{.m4} files.
1350 @item --output=@var{file}
1351 @opindex --output
1352 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
1354 @item --print-ac-dir
1355 @opindex --print-ac-dir
1356 Prints the name of the directory which @code{aclocal} will search to
1357 find third-party @file{.m4} files.  When this option is given, normal
1358 processing is suppressed.  This option can be used by a package to
1359 determine where to install a macro file.
1361 @item --verbose
1362 @opindex --verbose
1363 Print the names of the files it examines.
1365 @item --version
1366 @opindex --version
1367 Print the version number of Automake and exit.
1368 @end table
1370 @node Macro search path, Macros, aclocal options, configure
1371 @section Macro search path
1373 @cindex Macro search path
1374 @cindex aclocal search path
1376 By default, @command{aclocal} searches for @file{.m4} files in the following
1377 directories, in this order:
1379 @table @code
1380 @item @var{acdir-APIVERSION}
1381 This is where the @file{.m4} macros distributed with automake itself
1382 are stored.  @var{APIVERSION} depends on the automake release used;
1383 for automake 1.6.x, @var{APIVERSION} = @code{1.6}.
1385 @item @var{acdir}
1386 This directory is intended for third party @file{.m4} files, and is
1387 configured when @command{automake} itself is built.  This is
1388 @file{@@datadir@@/aclocal/}, which typically
1389 expands to @file{$@{prefix@}/share/aclocal/}.  To find the compiled-in
1390 value of @var{acdir}, use the @code{--print-ac-dir} option
1391 (@pxref{aclocal options}).
1392 @end table
1394 As an example, suppose that automake-1.6.2 was configured with
1395 @code{--prefix=/usr/local}.  Then, the search path would be:
1397 @enumerate
1398 @item @file{/usr/local/share/aclocal-1.6/}
1399 @item @file{/usr/local/share/aclocal/}
1400 @end enumerate
1402 As explained in (@pxref{aclocal options}), there are several options that
1403 can be used to change or extend this search path.
1405 @subsection Modifying the macro search path: @code{--acdir}
1407 The most obvious option to modify the search path is
1408 @code{--acdir=@var{dir}}, which changes default directory and
1409 drops the @var{APIVERSION} directory.  For example, if one specifies
1410 @code{--acdir=/opt/private/}, then the search path becomes:
1412 @enumerate
1413 @item @file{/opt/private/}
1414 @end enumerate
1416 Note that this option, @code{--acdir}, is intended for use
1417 by the internal automake test suite only; it is not ordinarily
1418 needed by end-users.
1420 @subsection Modifying the macro search path: @code{-I @var{dir}}
1422 Any extra directories specified using @code{-I} options
1423 (@pxref{aclocal options}) are @emph{prepended} to this search list.  Thus,
1424 @code{aclocal -I /foo -I /bar} results in the following search path:
1426 @enumerate
1427 @item @file{/foo}
1428 @item @file{/bar}
1429 @item @var{acdir}-@var{APIVERSION}
1430 @item @var{acdir}
1431 @end enumerate
1433 @subsection Modifying the macro search path: @file{dirlist}
1434 @cindex @file{dirlist}
1436 There is a third mechanism for customizing the search path.  If a
1437 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
1438 contain a list of directories, one per line, to be added to the search
1439 list.  These directories are searched @emph{after} all other
1440 directories.
1442 For example, suppose
1443 @file{@var{acdir}/dirlist} contains the following:
1445 @example
1446 /test1
1447 /test2
1448 @end example
1450 @noindent
1451 and that @code{aclocal} was called with the @code{-I /foo -I /bar} options.
1452 Then, the search path would be
1454 @enumerate
1455 @item @file{/foo}
1456 @item @file{/bar}
1457 @item @var{acdir}-@var{APIVERSION}
1458 @item @var{acdir}
1459 @item @file{/test1}
1460 @item @file{/test2}
1461 @end enumerate
1463 If the @code{--acdir=@var{dir}} option is used, then @command{aclocal}
1464 will search for the @file{dirlist} file in @var{dir}.  In the
1465 @code{--acdir=/opt/private/} example above, @command{aclocal} would look
1466 for @file{/opt/private/dirlist}.  Again, however, the @code{--acdir}
1467 option is intended for use by the internal automake test suite only;
1468 @code{--acdir} is not ordinarily needed by end-users.
1470 @file{dirlist} is useful in the following situation: suppose that
1471 @code{automake} version @code{1.6.2} is installed with
1472 $prefix=/usr by the system vendor. Thus, the default search
1473 directories are
1475 @enumerate
1476 @item @file{/usr/share/aclocal-1.6/}
1477 @item @file{/usr/share/aclocal/}
1478 @end enumerate
1480 However, suppose further that many packages have been manually
1481 installed on the system, with $prefix=/usr/local, as is typical.
1482 In that case, many of these ``extra'' @file{.m4} files are in
1483 @file{/usr/local/share/aclocal}.  The only way to force
1484 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files
1485 is to always call @code{aclocal -I /usr/local/share/aclocal}.
1486 This is inconvenient.  With @file{dirlist}, one may create the file
1488 @file{/usr/share/aclocal/dirlist}
1490 @noindent
1491 which contains only the single line
1493 @file{/usr/local/share/aclocal}
1495 Now, the ``default'' search path on the affected system is
1497 @enumerate
1498 @item @file{/usr/share/aclocal-1.6/}
1499 @item @file{/usr/share/aclocal/}
1500 @item @file{/usr/local/share/aclocal/}
1501 @end enumerate
1503 without the need for @code{-I} options; @code{-I} options can be reserved
1504 for project-specific needs (@file{my-source-dir/m4/}), rather than
1505 using it to work around local system-dependent tool installation
1506 directories.
1508 Similarly, @file{dirlist} can be handy if you have installed a local
1509 copy Automake on your account and want @command{aclocal} to look for
1510 macros installed at other places on the system.
1512 @node Macros, Extending aclocal, Macro search path, configure
1513 @section Autoconf macros supplied with Automake
1515 Automake ships with several Autoconf macros that you can use from your
1516 @file{configure.in}.  When you use one of them it will be included by
1517 @code{aclocal} in @file{aclocal.m4}.
1519 @menu
1520 * Public macros::               Macros that you can use.
1521 * Private macros::              Macros that you should not use.
1522 @end menu
1524 @c consider generating the following subsections automatically from m4 files.
1526 @node Public macros, Private macros, Macros, Macros
1527 @subsection Public macros
1529 @table @code
1530 @item AM_CONFIG_HEADER
1531 Automake will generate rules to automatically regenerate the config
1532 header.  This obsolete macro is a synonym of @code{AC_CONFIG_HEADERS}
1533 today (@pxref{Optional}).
1534 @cvindex AM_CONFIG_HEADER
1536 @item AM_ENABLE_MULTILIB
1537 This is used when a ``multilib'' library is being built.  The first
1538 optional argument is the name of the @file{Makefile} being generated; it
1539 defaults to @samp{Makefile}.  The second option argument is used to find
1540 the top source directory; it defaults to the empty string (generally
1541 this should not be used unless you are familiar with the internals).
1542 @xref{Multilibs}.
1544 @item AM_C_PROTOTYPES
1545 Check to see if function prototypes are understood by the compiler.  If
1546 so, define @samp{PROTOTYPES} and set the output variables @samp{U} and
1547 @samp{ANSI2KNR} to the empty string.  Otherwise, set @samp{U} to
1548 @samp{_} and @samp{ANSI2KNR} to @samp{./ansi2knr}.  Automake uses these
1549 values to implement automatic de-ANSI-fication.
1550 @cvindex AM_C_PROTOTYPES
1552 @item AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
1553 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
1554 define @code{GWINSZ_IN_SYS_IOCTL}.  Otherwise @code{TIOCGWINSZ} can be
1555 found in @file{<termios.h>}.
1556 @cvindex AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
1558 @item AM_INIT_AUTOMAKE([OPTIONS])
1559 @itemx AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
1560 Runs many macros required for proper operation of the generated Makefiles.
1562 This macro has two forms, the second of which has two required
1563 arguments: the package and the version number.  This latter form is
1564 obsolete because the @var{package} and @var{version} can be obtained
1565 from Autoconf's @code{AC_INIT} macro (which itself has an old and a new
1566 form).
1568 If your @file{configure.in} has:
1569 @example
1570 AC_INIT(src/foo.c)
1571 AM_INIT_AUTOMAKE(mumble, 1.5)
1572 @end example
1573 you can modernize it as follow:
1574 @example
1575 AC_INIT(mumble, 1.5)
1576 AC_CONFIG_SRCDIR(src/foo.c)
1577 AM_INIT_AUTOMAKE
1578 @end example
1580 Note that if you're upgrading your @file{configure.in} from an earlier
1581 version of Automake, it is not always correct to simply move the package
1582 and version arguments from @code{AM_INIT_AUTOMAKE} directly to
1583 @code{AC_INIT}, as in the example above.  The first argument of
1584 @code{AC_INIT} is the name of your package (e.g. @samp{GNU Automake}),
1585 not the tarball name (e.g. @samp{automake}) you used to pass to
1586 @code{AM_INIT_AUTOMAKE}.  Autoconf's rule to derive a tarball name from
1587 the package name should work for most but not all packages.  Especially,
1588 if your tarball name is not all lower case, you will have to use the
1589 four-argument form of @code{AC_INIT} (supported in Autoconf versions
1590 greater than 2.52g).
1592 When @code{AM_INIT_AUTOMAKE} is called with a single argument, it is
1593 interpreted as a space-separated list of Automake options which should
1594 be applied to every @file{Makefile.am} in the tree.  The effect is as if
1595 each option were listed in @code{AUTOMAKE_OPTIONS}.
1597 By default this macro @code{AC_DEFINE}'s @samp{PACKAGE} and
1598 @samp{VERSION}.  This can be avoided by passing the @samp{no-define}
1599 option, as in:
1600 @example
1601 AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
1602 @end example
1603 or by passing a third non-empty argument to the obsolete form.
1605 @cvindex PACKAGE, prevent definition
1606 @cvindex VERSION, prevent definition
1609 @item AM_PATH_LISPDIR
1610 Searches for the program @code{emacs}, and, if found, sets the output
1611 variable @code{lispdir} to the full path to Emacs' site-lisp directory.
1613 Note that this test assumes the @code{emacs} found to be a version that
1614 supports Emacs Lisp (such as @sc{gnu} Emacs or XEmacs).  Other emacsen
1615 can cause this test to hang (some, like old versions of MicroEmacs,
1616 start up in interactive mode, requiring @samp{C-x C-c} to exit, which
1617 is hardly obvious for a non-emacs user).  In most cases, however, you
1618 should be able to use @samp{C-c} to kill the test.  In order to avoid
1619 problems, you can set @code{EMACS} to ``no'' in the environment, or
1620 use the @samp{--with-lispdir} option to @command{configure} to
1621 explictly set the correct path (if you're sure you have an @code{emacs}
1622 that supports Emacs Lisp.
1623 @cvindex AM_PATH_LISPDIR
1625 @item AM_PROG_AS
1626 Use this macro when you have assembly code in your project.  This will
1627 choose the assembler for you (by default the C compiler) and set
1628 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
1630 @item AM_PROG_CC_C_O
1631 This is like @code{AC_PROG_CC_C_O}, but it generates its results in the
1632 manner required by automake.  You must use this instead of
1633 @code{AC_PROG_CC_C_O} when you need this functionality.
1635 @item AM_PROG_CC_STDC
1636 If the C compiler is not in ANSI C mode by default, try to add an option
1637 to output variable @code{CC} to make it so.  This macro tries various
1638 options that select ANSI C on some system or another.  It considers the
1639 compiler to be in ANSI C mode if it handles function prototypes correctly.
1641 If you use this macro, you should check after calling it whether the C
1642 compiler has been set to accept ANSI C; if not, the shell variable
1643 @code{am_cv_prog_cc_stdc} is set to @samp{no}.  If you wrote your source
1644 code in ANSI C, you can make an un-ANSIfied copy of it by using the
1645 @code{ansi2knr} option (@pxref{ANSI}).
1647 This macro is a relic from the time Autoconf didn't offer such a
1648 feature.  @code{AM_PROG_CC_STDC}'s logic has now been merged into
1649 Autoconf's @code{AC_PROG_CC} macro, therefore you should use the latter
1650 instead.  Chances are you are already using @code{AC_PROG_CC}, so you
1651 can simply remove the @code{AM_PROG_CC_STDC} call and turn all
1652 occurrences of @code{$am_cv_prog_cc_stdc} into
1653 @code{$ac_cv_prog_cc_stdc}.  @code{AM_PROG_CC_STDC} will be marked as
1654 obsolete (in the Autoconf sense) in Automake 1.8.
1656 @item AM_PROG_LEX
1657 @cindex HP-UX 10, lex problems
1658 @cindex lex problems with HP-UX 10
1659 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
1660 Program Checks, autoconf, The Autoconf Manual}), but uses the
1661 @code{missing} script on systems that do not have @code{lex}.
1662 @samp{HP-UX 10} is one such system.
1664 @item AM_PROG_GCJ
1665 This macro finds the @code{gcj} program or causes an error.  It sets
1666 @samp{GCJ} and @samp{GCJFLAGS}.  @code{gcj} is the Java front-end to the
1667 GNU Compiler Collection.
1668 @cvindex AM_PROG_GCJ
1670 @item AM_SYS_POSIX_TERMIOS
1671 @cvindex am_cv_sys_posix_termios
1672 @cindex POSIX termios headers
1673 @cindex termios POSIX headers
1674 Check to see if POSIX termios headers and functions are available on the
1675 system.  If so, set the shell variable @code{am_cv_sys_posix_termios} to
1676 @samp{yes}.  If not, set the variable to @samp{no}.
1678 @item AM_WITH_DMALLOC
1679 @cvindex WITH_DMALLOC
1680 @cindex dmalloc, support for
1681 @opindex --with-dmalloc
1682 Add support for the
1683 @uref{ftp://ftp.letters.com/src/dmalloc/dmalloc.tar.gz, dmalloc}
1684 package.  If the user configures with @samp{--with-dmalloc}, then define
1685 @code{WITH_DMALLOC} and add @samp{-ldmalloc} to @code{LIBS}.
1687 @item AM_WITH_REGEX
1688 @cvindex WITH_REGEX
1689 @opindex --with-regex
1690 @cindex regex package
1691 @cindex rx package
1692 Adds @samp{--with-regex} to the @code{configure} command line.  If
1693 specified (the default), then the @samp{regex} regular expression
1694 library is used, @file{regex.o} is put into @samp{LIBOBJS}, and
1695 @samp{WITH_REGEX} is defined.  If @samp{--without-regex} is given, then
1696 the @samp{rx} regular expression library is used, and @file{rx.o} is put
1697 into @samp{LIBOBJS}.
1699 @end table
1701 @node Private macros,  , Public macros, Macros
1702 @subsection Private macros
1704 The following macros are private macros you should not call directly.
1705 They are called by the other public macros when appropriate.  Do not
1706 rely on them, as they might be changed in a future version.  Consider
1707 them as implementation details; or better, do not consider them at all:
1708 skip this section!
1710 @table @code
1711 @item _AM_DEPENDENCIES
1712 @itemx AM_SET_DEPDIR
1713 @itemx AM_DEP_TRACK
1714 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
1715 These macros are used to implement automake's automatic dependency
1716 tracking scheme.  They are called automatically by automake when
1717 required, and there should be no need to invoke them manually.
1719 @item AM_MAKE_INCLUDE
1720 This macro is used to discover how the user's @code{make} handles
1721 @code{include} statements.  This macro is automatically invoked when
1722 needed; there should be no need to invoke it manually.
1724 @item AM_PROG_INSTALL_STRIP
1725 This is used to find a version of @code{install} which can be used to
1726 @code{strip} a program at installation time.  This macro is
1727 automatically included when required.
1729 @item AM_SANITY_CHECK
1730 This checks to make sure that a file created in the build directory is
1731 newer than a file in the source directory.  This can fail on systems
1732 where the clock is set incorrectly.  This macro is automatically run
1733 from @code{AM_INIT_AUTOMAKE}.
1735 @end table
1739 @node Extending aclocal,  , Macros, configure
1740 @section Writing your own aclocal macros
1742 @cindex aclocal, extending
1743 @cindex Extending aclocal
1745 The @code{aclocal} program doesn't have any built-in knowledge of any
1746 macros, so it is easy to extend it with your own macros.
1748 This is mostly used for libraries which want to supply their own
1749 Autoconf macros for use by other programs.  For instance the
1750 @code{gettext} library supplies a macro @code{AM_GNU_GETTEXT} which
1751 should be used by any package using @code{gettext}.  When the library is
1752 installed, it installs this macro so that @code{aclocal} will find it.
1754 A file of macros should be a series of @code{AC_DEFUN}'s.  The
1755 @code{aclocal} programs also understands @code{AC_REQUIRE}, so it is
1756 safe to put each macro in a separate file.  @xref{Prerequisite Macros, ,
1757 , autoconf, The Autoconf Manual}, and @ref{Macro Definitions, , ,
1758 autoconf, The Autoconf Manual}.
1760 A macro file's name should end in @file{.m4}.  Such files should be
1761 installed in @code{`aclocal --print-ac-dir`} (which usually happens to
1762 be @file{$(datadir)/aclocal}).
1765 @node Top level, Alternative, configure, Top
1766 @chapter The top-level @file{Makefile.am}
1768 @section Recursing subdirectories
1770 @cindex SUBDIRS, explained
1772 In packages with subdirectories, the top level @file{Makefile.am} must
1773 tell Automake which subdirectories are to be built.  This is done via
1774 the @code{SUBDIRS} variable.
1775 @vindex SUBDIRS
1777 The @code{SUBDIRS} variable holds a list of subdirectories in which
1778 building of various sorts can occur.  Many targets (e.g. @code{all}) in
1779 the generated @file{Makefile} will run both locally and in all specified
1780 subdirectories.  Note that the directories listed in @code{SUBDIRS} are
1781 not required to contain @file{Makefile.am}s; only @file{Makefile}s
1782 (after configuration).  This allows inclusion of libraries from packages
1783 which do not use Automake (such as @code{gettext}).
1785 In packages that use subdirectories, the top-level @file{Makefile.am} is
1786 often very short.  For instance, here is the @file{Makefile.am} from the
1787 GNU Hello distribution:
1789 @example
1790 EXTRA_DIST = BUGS ChangeLog.O README-alpha
1791 SUBDIRS = doc intl po src tests
1792 @end example
1794 When Automake invokes @code{make} in a subdirectory, it uses the value
1795 of the @code{MAKE} variable.  It passes the value of the variable
1796 @code{AM_MAKEFLAGS} to the @code{make} invocation; this can be set in
1797 @file{Makefile.am} if there are flags you must always pass to
1798 @code{make}.
1799 @vindex MAKE
1800 @vindex MAKEFLAGS
1802 The directories mentioned in @code{SUBDIRS} must be direct children of
1803 the current directory.  For instance, you cannot put @samp{src/subdir}
1804 into @code{SUBDIRS}.  Instead you should put @code{SUBDIRS = subdir}
1805 into @file{src/Makefile.am}.  Automake can be used to construct packages
1806 of arbitrary depth this way.
1808 By default, Automake generates @file{Makefiles} which work depth-first
1809 (@samp{postfix}).  However, it is possible to change this ordering.  You
1810 can do this by putting @samp{.} into @code{SUBDIRS}.  For instance,
1811 putting @samp{.}  first will cause a @samp{prefix} ordering of
1812 directories.  All @samp{clean} targets are run in reverse order of build
1813 targets.
1815 @section Conditional subdirectories
1816 @cindex Subdirectories, building conditionally
1817 @cindex Conditional subdirectories
1818 @cindex @code{SUBDIRS}, conditional
1819 @cindex Conditional @code{SUBDIRS}
1821 It is possible to define the @code{SUBDIRS} variable conditionally if,
1822 like in the case of GNU @code{Inetutils}, you want to only build a
1823 subset of the entire package.
1825 To illustrate how this works, let's assume we have two directories
1826 @file{src/} and @file{opt/}.  @file{src/} should always be built, but we
1827 want to decide in @code{./configure} whether @file{opt/} will be built
1828 or not.  (For this example we will assume that @file{opt/} should be
1829 built when the variable @code{$want_opt} was set to @code{yes}.)
1831 Running @code{make} should thus recurse into @file{src/} always, and
1832 then maybe in @file{opt/}.
1834 However @code{make dist} should always recurse into both @file{src/} and
1835 @file{opt/}.  Because @file{opt/} should be distributed even if it is
1836 not needed in the current configuration. This means @file{opt/Makefile}
1837 should be created unconditionally.  @footnote{Don't try seeking a
1838 solution where @file{opt/Makefile} is created conditionally, this is a
1839 lot trickier than the solutions presented here.}
1841 There are two ways to setup a project like this.  You can use Automake
1842 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
1843 variables (@pxref{Setting Output Variables, , Setting Output Variables,
1844 autoconf, The Autoconf Manual}).  Using Automake conditionals is the
1845 preferred solution.
1847 @subsection Conditional subdirectories with @code{AM_CONDITIONAL}
1848 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
1849 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
1851 @c The test case for the setup described here is
1852 @c     test/subdircond2.test
1853 @c Try to keep it in sync.
1855 @file{configure} should output the @file{Makefile} for each directory
1856 and define a condition into which @file{opt/} should be built.
1858 @example
1859 @dots{}
1860 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
1861 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
1862 @dots{}
1863 @end example
1865 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
1866 as follows.
1868 @example
1869 if COND_OPT
1870   MAYBE_OPT = opt
1871 endif
1872 SUBDIRS = src $(MAYBE_OPT)
1873 @end example
1875 As you can see, running @code{make} will rightly recurse into
1876 @file{src/} and maybe @file{opt/}.
1878 @vindex DIST_SUBDIRS
1879 As you can't see, running @code{make dist} will recurse into both
1880 @file{src/} and @file{opt/} directories because @code{make dist}, unlike
1881 @code{make all}, doesn't use the @code{SUBDIRS} variable.  It uses the
1882 @code{DIST_SUBDIRS} variable.
1884 In this case Automake will define @code{DIST_SUBDIRS = src opt}
1885 automatically because it knows that @code{MAYBE_OPT} can contain
1886 @code{opt} in some condition.
1888 @subsection Conditional subdirectories with @code{AC_SUBST}
1889 @cindex @code{SUBDIRS} and @code{AC_SUBST}
1890 @cindex @code{AC_SUBST} and @code{SUBDIRS}
1892 @c The test case for the setup described here is
1893 @c     test/subdircond3.test
1894 @c Try to keep it in sync.
1896 Another idea is to define @code{MAYBE_OPT} from @file{./configure} using
1897 @code{AC_SUBST}:
1899 @example
1900 @dots{}
1901 if test "$want_opt" = yes; then
1902   MAYBE_OPT=opt
1903 else
1904   MAYBE_OPT=
1906 AC_SUBST([MAYBE_OPT])
1907 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
1908 @dots{}
1909 @end example
1911 In this case the top-level @file{Makefile.am} should look as follows.
1913 @example
1914 SUBDIRS = src $(MAYBE_OPT)
1915 DIST_SUBDIRS = src opt
1916 @end example
1918 The drawback is that since Automake cannot guess what the possible
1919 values of @code{MAYBE_OPT} are, it is necessary to define
1920 @code{DIST_SUBDIRS}.
1922 @subsection How @code{DIST_SUBDIRS} is used
1923 @cindex @code{DIST_SUBDIRS}, explained
1925 As shown in the above examples, @code{DIST_SUBDIRS} is used by targets
1926 that need to recurse in all directories, even those which have been
1927 conditionally left out of the build.
1929 Precisely, @code{DIST_SUBDIRS} is used by @code{make dist}, @code{make
1930 distclean}, and @code{make maintainer-clean}.  All other recursive
1931 targets use @code{SUBDIRS}.
1933 Automake will define @code{DIST_SUBDIRS} automatically from the
1934 possibles values of @code{SUBDIRS} in all conditions.
1936 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
1937 @code{DIST_SUBDIRS} will not be defined correctly because Automake
1938 doesn't know the possible values of these variables.  In this case
1939 @code{DIST_SUBDIRS} needs to be defined manually.
1942 @node Alternative, Rebuilding, Top level, Top
1943 @chapter An Alternative Approach to Subdirectories
1945 If you've ever read Peter Miller's excellent paper,
1946 @uref{http://www.pcug.org.au/~millerp/rmch/recu-make-cons-harm.html,
1947 Recursive Make Considered Harmful}, the preceding section on the use of
1948 subdirectories will probably come as unwelcome advice.  For those who
1949 haven't read the paper, Miller's main thesis is that recursive
1950 @code{make} invocations are both slow and error-prone.
1952 Automake provides sufficient cross-directory support @footnote{We
1953 believe.  This work is new and there are probably warts.
1954 @xref{Introduction}, for information on reporting bugs.} to enable you
1955 to write a single @file{Makefile.am} for a complex multi-directory
1956 package.
1959 By default an installable file specified in a subdirectory will have its
1960 directory name stripped before installation.  For instance, in this
1961 example, the header file will be installed as
1962 @file{$(includedir)/stdio.h}:
1964 @example
1965 include_HEADERS = inc/stdio.h
1966 @end example
1968 @cindex nobase_
1969 @cindex Path stripping, avoiding
1970 @cindex Avoiding path stripping
1972 However, the @samp{nobase_} prefix can be used to circumvent this path
1973 stripping.  In this example, the header file will be installed as
1974 @file{$(includedir)/sys/types.h}:
1976 @example
1977 nobase_include_HEADERS = sys/types.h
1978 @end example
1980 @cindex nobase_ and dist_ or nodist_
1981 @cindex dist_ and nobase_
1982 @cindex nodist_ and nobase_
1984 @samp{nobase_} should be specified first when used in conjunction with
1985 either @samp{dist_} or @samp{nodist_} (@pxref{Dist}).  For instance:
1987 @example
1988 nobase_dist_pkgdata_DATA = images/vortex.pgm
1989 @end example
1991 @node Rebuilding, Programs, Alternative, Top
1992 @chapter Rebuilding Makefiles
1994 Automake generates rules to automatically rebuild @file{Makefile}s,
1995 @file{configure}, and other derived files like @file{Makefile.in}.
1997 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.in}, then
1998 these automatic rebuilding rules are only enabled in maintainer mode.
2000 Sometimes you need to run @code{aclocal} with an argument like @code{-I}
2001 to tell it where to find @file{.m4} files.  Since sometimes @code{make}
2002 will automatically run @code{aclocal}, you need a way to specify these
2003 arguments.  You can do this by defining @code{ACLOCAL_AMFLAGS}; this
2004 holds arguments which are passed verbatim to @code{aclocal}.  This variable
2005 is only useful in the top-level @file{Makefile.am}.
2006 @vindex ACLOCAL_AMFLAGS
2009 @node Programs, Other objects, Rebuilding, Top
2010 @chapter Building Programs and Libraries
2012 A large part of Automake's functionality is dedicated to making it easy
2013 to build programs and libraries.
2015 @menu
2016 * A Program::                   Building a program
2017 * A Library::                   Building a library
2018 * A Shared Library::            Building a Libtool library
2019 * Program and Library Variables::  Variables controlling program and
2020                                 library builds
2021 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
2022 * Program variables::           Variables used when building a program
2023 * Yacc and Lex::                Yacc and Lex support
2024 * C++ Support::
2025 * Assembly Support::
2026 * Fortran 77 Support::
2027 * Java Support::
2028 * Support for Other Languages::
2029 * ANSI::                        Automatic de-ANSI-fication
2030 * Dependencies::                Automatic dependency tracking
2031 * EXEEXT::                      Support for executable extensions
2032 @end menu
2035 @node A Program, A Library, Programs, Programs
2036 @section Building a program
2038 In order to build a program, you need to tell Automake which sources
2039 are part of it, and which libraries it should be linked with.
2041 This section also covers conditional compilation of sources or
2042 programs.  Most of the comments about these also apply to libraries
2043 (@pxref{A Library}) and Libtool libraries (@pxref{A Shared Library}).
2045 @menu
2046 * Program Sources::             Defining program sources
2047 * Linking::                     Linking with libraries or extra objects
2048 * Conditional Sources::         Handling conditional sources
2049 * Conditional Programs::        Building program conditionally
2050 @end menu
2052 @node Program Sources, Linking, A Program, A Program
2053 @subsection Defining program sources
2055 @cindex PROGRAMS, bindir
2056 @vindex bin_PROGRAMS
2057 @vindex sbin_PROGRAMS
2058 @vindex libexec_PROGRAMS
2059 @vindex pkglib_PROGRAMS
2060 @vindex noinst_PROGRAMS
2061 @vindex check_PROGRAMS
2063 In a directory containing source that gets built into a program (as
2064 opposed to a library or a script), the @samp{PROGRAMS} primary is used.
2065 Programs can be installed in @code{bindir}, @code{sbindir},
2066 @code{libexecdir}, @code{pkglibdir}, or not at all (@samp{noinst}).
2067 They can also be built only for @code{make check}, in which case the
2068 prefix is @samp{check}.
2070 For instance:
2072 @example
2073 bin_PROGRAMS = hello
2074 @end example
2076 In this simple case, the resulting @file{Makefile.in} will contain code
2077 to generate a program named @code{hello}.
2079 Associated with each program are several assisting variables which are
2080 named after the program.  These variables are all optional, and have
2081 reasonable defaults.  Each variable, its use, and default is spelled out
2082 below; we use the ``hello'' example throughout.
2084 The variable @code{hello_SOURCES} is used to specify which source files
2085 get built into an executable:
2087 @example
2088 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
2089 @end example
2091 This causes each mentioned @samp{.c} file to be compiled into the
2092 corresponding @samp{.o}.  Then all are linked to produce @file{hello}.
2094 @cindex _SOURCES primary, defined
2095 @cindex SOURCES primary, defined
2096 @cindex Primary variable, SOURCES
2098 If @samp{hello_SOURCES} is not specified, then it defaults to the single
2099 file @file{hello.c}; that is, the default is to compile a single C file
2100 whose base name is the name of the program itself.  (This is a terrible
2101 default but we are stuck with it for historical reasons.)
2102 @vindex _SOURCES
2103 @vindex SOURCES
2105 Multiple programs can be built in a single directory.  Multiple programs
2106 can share a single source file, which must be listed in each
2107 @samp{_SOURCES} definition.
2109 @cindex Header files in _SOURCES
2110 @cindex _SOURCES and header files
2112 Header files listed in a @samp{_SOURCES} definition will be included in
2113 the distribution but otherwise ignored.  In case it isn't obvious, you
2114 should not include the header file generated by @file{configure} in a
2115 @samp{_SOURCES} variable; this file should not be distributed.  Lex
2116 (@samp{.l}) and Yacc (@samp{.y}) files can also be listed; see @ref{Yacc
2117 and Lex}.
2120 @node Linking, Conditional Sources, Program Sources, A Program
2121 @subsection Linking the program
2123 If you need to link against libraries that are not found by
2124 @code{configure}, you can use @code{LDADD} to do so.  This variable is
2125 used to specify additional objects or libraries to link with; it is
2126 inappropriate for specifying specific linker flags, you should use
2127 @code{AM_LDFLAGS} for this purpose.
2128 @vindex LDADD
2129 @vindex AM_LDFLAGS
2131 @cindex prog_LDADD, defined
2133 Sometimes, multiple programs are built in one directory but do not share
2134 the same link-time requirements.  In this case, you can use the
2135 @samp{@var{prog}_LDADD} variable (where @var{prog} is the name of the
2136 program as it appears in some @samp{_PROGRAMS} variable, and usually
2137 written in lowercase) to override the global @code{LDADD}.  If this
2138 variable exists for a given program, then that program is not linked
2139 using @code{LDADD}.
2140 @vindex _LDADD
2142 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
2143 linked against the library @file{libcpio.a}.  However, @code{rmt} is
2144 built in the same directory, and has no such link requirement.  Also,
2145 @code{mt} and @code{rmt} are only built on certain architectures.  Here
2146 is what cpio's @file{src/Makefile.am} looks like (abridged):
2148 @example
2149 bin_PROGRAMS = cpio pax @@MT@@
2150 libexec_PROGRAMS = @@RMT@@
2151 EXTRA_PROGRAMS = mt rmt
2153 LDADD = ../lib/libcpio.a @@INTLLIBS@@
2154 rmt_LDADD =
2156 cpio_SOURCES = @dots{}
2157 pax_SOURCES = @dots{}
2158 mt_SOURCES = @dots{}
2159 rmt_SOURCES = @dots{}
2160 @end example
2162 @cindex _LDFLAGS, defined
2164 @samp{@var{prog}_LDADD} is inappropriate for passing program-specific
2165 linker flags (except for @samp{-l}, @samp{-L}, @samp{-dlopen} and
2166 @samp{-dlpreopen}).  So, use the @samp{@var{prog}_LDFLAGS} variable for
2167 this purpose.
2168 @vindex _LDFLAGS
2170 @cindex _DEPENDENCIES, defined
2172 It is also occasionally useful to have a program depend on some other
2173 target which is not actually part of that program.  This can be done
2174 using the @samp{@var{prog}_DEPENDENCIES} variable.  Each program depends
2175 on the contents of such a variable, but no further interpretation is
2176 done.
2178 If @samp{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
2179 Automake.  The automatically-assigned value is the contents of
2180 @samp{@var{prog}_LDADD}, with most configure substitutions, @samp{-l},
2181 @samp{-L}, @samp{-dlopen} and @samp{-dlpreopen} options removed.  The
2182 configure substitutions that are left in are only @samp{@@LIBOBJS@@} and
2183 @samp{@@ALLOCA@@}; these are left because it is known that they will not
2184 cause an invalid value for @samp{@var{prog}_DEPENDENCIES} to be
2185 generated.
2188 @node Conditional Sources, Conditional Programs, Linking, A Program
2189 @subsection Conditional compilation of sources
2191 You can't put a configure substitution (e.g., @samp{@@FOO@@}) into a
2192 @samp{_SOURCES} variable.  The reason for this is a bit hard to explain,
2193 but suffice to say that it simply won't work.  Automake will give an
2194 error if you try to do this.
2196 Fortunately there are two other ways to achieve the same result.  One is
2197 to use configure substitutions in @code{_LDADD} variables, the other is
2198 to use an Automake conditional.
2200 @subsubsection Conditional compilation using @code{_LDADD} substitutions
2202 @cindex EXTRA_prog_SOURCES, defined
2204 Automake must know all the source files that could possibly go into a
2205 program, even if not all the files are built in every circumstance.  Any
2206 files which are only conditionally built should be listed in the
2207 appropriate @samp{EXTRA_} variable.  For instance, if
2208 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
2209 in @code{hello}, the @file{Makefile.am} would contain:
2211 @example
2212 bin_PROGRAMS = hello
2213 hello_SOURCES = hello-common.c
2214 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
2215 hello_LDADD = @@HELLO_SYSTEM@@
2216 hello_DEPENDENCIES = @@HELLO_SYSTEM@@
2217 @end example
2219 @noindent
2220 You can then setup the @code{@@HELLO_SYSTEM@@} substitution from
2221 @file{configure.in}:
2223 @example
2224 @dots{}
2225 case $host in
2226   *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
2227   *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
2228 esac
2229 AC_SUBST([HELLO_SYSTEM])
2230 @dots{}
2231 @end example
2233 In this case, @code{HELLO_SYSTEM} should be replaced by
2234 @file{hello-linux.o} or @file{hello-bsd.o}, and added to
2235 @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be built
2236 and linked in.
2238 @subsubsection Conditional compilation using Automake conditionals
2240 An often simpler way to compile source files conditionally is to use
2241 Automake conditionals.  For instance, you could use this
2242 @file{Makefile.am} construct to build the same @file{hello} example:
2244 @example
2245 bin_PROGRAMS = hello
2246 if LINUX
2247 hello_SOURCES = hello-linux.c hello-common.c
2248 else
2249 hello_SOURCES = hello-generic.c hello-common.c
2250 endif
2251 @end example
2253 In this case, your @file{configure.in} should setup the @code{LINUX}
2254 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
2256 When using conditionals like this you don't need to use the
2257 @samp{EXTRA_} variable, because Automake will examine the contents of
2258 each variable to construct the complete list of source files.
2260 If your program uses a lot of files, you will probably prefer a
2261 conditional @code{+=}.
2263 @example
2264 bin_PROGRAMS = hello
2265 hello_SOURCES = hello-common.c
2266 if LINUX
2267 hello_SOURCES += hello-linux.c
2268 else
2269 hello_SOURCES += hello-generic.c
2270 endif
2271 @end example
2273 @node Conditional Programs,  , Conditional Sources, A Program
2274 @subsection Conditional compilation of programs
2275 @cindex Conditional programs
2276 @cindex Programs, conditional
2278 Sometimes it is useful to determine the programs that are to be built
2279 at configure time.  For instance, GNU @code{cpio} only builds
2280 @code{mt} and @code{rmt} under special circumstances.  The means to
2281 achieve conditional compilation of programs are the same you can use
2282 to compile source files conditionally: substitutions or conditionals.
2284 @subsubsection Conditional programs using @code{configure} substitutions
2286 In this case, you must notify Automake of all the programs that can
2287 possibly be built, but at the same time cause the generated
2288 @file{Makefile.in} to use the programs specified by @code{configure}.
2289 This is done by having @code{configure} substitute values into each
2290 @samp{_PROGRAMS} definition, while listing all optionally built programs
2291 in @code{EXTRA_PROGRAMS}.
2292 @vindex EXTRA_PROGRAMS
2293 @cindex EXTRA_PROGRAMS, defined
2295 @example
2296 bin_PROGRAMS = cpio pax $(MT)
2297 libexec_PROGRAMS = $(RMT)
2298 EXTRA_PROGRAMS = mt rmt
2299 @end example
2301 As explained in @ref{EXEEXT}, Automake will rewrite
2302 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
2303 @code{EXTRA_PROGRAMS}, appending @code{$(EXEEXT)} to each binary.
2304 Obviously it cannot rewrite values obtained at run-time through
2305 @code{configure} substitutions, therefore you should take care of
2306 appending @code{$(EXEEXT)} yourself, as in @code{AC_SUBST([MT],
2307 ['mt$@{EXEEXT@}'])}.
2309 @subsubsection Conditional programs using Automake conditionals
2311 You can also use Automake conditionals (@pxref{Conditionals}) to
2312 select programs to be built.  In this case you don't have to worry
2313 about @code{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
2315 @example
2316 bin_PROGRAMS = cpio pax
2317 if WANT_MT
2318   bin_PROGRAMS += mt
2319 endif
2320 if WANT_RMT
2321   libexec_PROGRAMS = rmt
2322 endif
2323 @end example
2326 @node A Library, A Shared Library, A Program, Programs
2327 @section Building a library
2329 @cindex _LIBRARIES primary, defined
2330 @cindex LIBRARIES primary, defined
2331 @cindex Primary variable, LIBRARIES
2333 @vindex lib_LIBRARIES
2334 @vindex pkglib_LIBRARIES
2335 @vindex noinst_LIBRARIES
2337 Building a library is much like building a program.  In this case, the
2338 name of the primary is @samp{LIBRARIES}.  Libraries can be installed in
2339 @code{libdir} or @code{pkglibdir}.
2341 @xref{A Shared Library}, for information on how to build shared
2342 libraries using Libtool and the @samp{LTLIBRARIES} primary.
2344 Each @samp{_LIBRARIES} variable is a list of the libraries to be built.
2345 For instance to create a library named @file{libcpio.a}, but not install
2346 it, you would write:
2348 @example
2349 noinst_LIBRARIES = libcpio.a
2350 @end example
2352 The sources that go into a library are determined exactly as they are
2353 for programs, via the @samp{_SOURCES} variables.  Note that the library
2354 name is canonicalized (@pxref{Canonicalization}), so the @samp{_SOURCES}
2355 variable corresponding to @file{liblob.a} is @samp{liblob_a_SOURCES},
2356 not @samp{liblob.a_SOURCES}.
2358 @cindex _LIBADD primary, defined
2359 @cindex LIBADD primary, defined
2360 @cindex Primary variable, LIBADD
2362 Extra objects can be added to a library using the
2363 @samp{@var{library}_LIBADD} variable.  This should be used for objects
2364 determined by @code{configure}.  Again from @code{cpio}:
2365 @vindex _LIBADD
2366 @vindex LIBADD
2368 @example
2369 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
2370 @end example
2372 In addition, sources for extra objects that will not exist until
2373 configure-time must be added to the @code{BUILT_SOURCES} variable
2374 (@pxref{Sources}).
2377 @node A Shared Library, Program and Library Variables, A Library, Programs
2378 @section Building a Shared Library
2380 @cindex Shared libraries, support for
2382 Building shared libraries is a relatively complex matter.  For this
2383 reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
2384 Libtool Manual}) was created to help build shared libraries in a
2385 platform-independent way.
2387 @cindex _LTLIBRARIES primary, defined
2388 @cindex LTLIBRARIES primary, defined
2389 @cindex Primary variable, LTLIBRARIES
2390 @cindex Example of shared libraries
2392 @cindex suffix .la, defined
2394 Automake uses Libtool to build libraries declared with the
2395 @samp{LTLIBRARIES} primary.  Each @samp{_LTLIBRARIES} variable is a list
2396 of shared libraries to build.  For instance, to create a library named
2397 @file{libgettext.a} and its corresponding shared libraries, and install
2398 them in @samp{libdir}, write:
2400 @example
2401 lib_LTLIBRARIES = libgettext.la
2402 @end example
2404 @vindex lib_LTLIBRARIES
2405 @vindex pkglib_LTLIBRARIES
2406 @vindex noinst_LTLIBRARIES
2407 @vindex check_LTLIBRARIES
2409 @cindex check_LTLIBRARIES, not allowed
2411 Note that shared libraries @emph{must} be installed in order to work
2412 properly, so @code{check_LTLIBRARIES} is not allowed.  However,
2413 @code{noinst_LTLIBRARIES} is allowed.  This feature should be used for
2414 libtool ``convenience libraries''.
2416 @cindex suffix .lo, defined
2418 For each library, the @samp{@var{library}_LIBADD} variable contains the
2419 names of extra libtool objects (@file{.lo} files) to add to the shared
2420 library.  The @samp{@var{library}_LDFLAGS} variable contains any
2421 additional libtool flags, such as @samp{-version-info} or
2422 @samp{-static}.
2424 @cindex @code{LTLIBOBJS}, special handling
2426 Where an ordinary library might include @code{$(LIBOBJS)}, a libtool
2427 library must use @code{$(LTLIBOBJS)}.  This is required because the
2428 object files that libtool operates on do not necessarily end in
2429 @file{.o}.  The libtool manual contains more details on this topic.
2431 For libraries installed in some directory, Automake will automatically
2432 supply the appropriate @samp{-rpath} option.  However, for libraries
2433 determined at configure time (and thus mentioned in
2434 @code{EXTRA_LTLIBRARIES}), Automake does not know the eventual
2435 installation directory; for such libraries you must add the
2436 @samp{-rpath} option to the appropriate @samp{_LDFLAGS} variable by
2437 hand.
2439 Ordinarily, Automake requires that a shared library's name start with
2440 @samp{lib}.  However, if you are building a dynamically loadable module
2441 then you might wish to use a "nonstandard" name.  In this case, put
2442 @code{-module} into the @samp{_LDFLAGS} variable.
2444 @xref{Using Automake, Using Automake with Libtool, The Libtool Manual,
2445 libtool, The Libtool Manual}, for more information.
2448 @node Program and Library Variables, LIBOBJS, A Shared Library, Programs
2449 @section Program and Library Variables
2451 Associated with each program are a collection of variables which can be
2452 used to modify how that program is built.  There is a similar list of
2453 such variables for each library.  The canonical name of the program (or
2454 library) is used as a base for naming these variables.
2456 In the list below, we use the name ``maude'' to refer to the program or
2457 library.  In your @file{Makefile.am} you would replace this with the
2458 canonical name of your program.  This list also refers to ``maude'' as a
2459 program, but in general the same rules apply for both static and dynamic
2460 libraries; the documentation below notes situations where programs and
2461 libraries differ.
2463 @table @samp
2464 @item maude_SOURCES
2465 This variable, if it exists, lists all the source files which are
2466 compiled to build the program.  These files are added to the
2467 distribution by default.  When building the program, Automake will cause
2468 each source file to be compiled to a single @file{.o} file (or
2469 @file{.lo} when using libtool).  Normally these object files are named
2470 after the source file, but other factors can change this.  If a file in
2471 the @samp{_SOURCES} variable has an unrecognized extension, Automake
2472 will do one of two things with it.  If a suffix rule exists for turning
2473 files with the unrecognized extension into @file{.o} files, then
2474 automake will treat this file as it will any other source file
2475 (@pxref{Support for Other Languages}).  Otherwise, the file will be
2476 ignored as though it were a header file.
2478 The prefixes @samp{dist_} and @samp{nodist_} can be used to control
2479 whether files listed in a @samp{_SOURCES} variable are distributed.
2480 @samp{dist_} is redundant, as sources are distributed by default, but it
2481 can be specified for clarity if desired.
2483 It is possible to have both @samp{dist_} and @samp{nodist_} variants of
2484 a given @samp{_SOURCES} variable at once; this lets you easily
2485 distribute some files and not others, for instance:
2487 @example
2488 nodist_maude_SOURCES = nodist.c
2489 dist_maude_SOURCES = dist-me.c
2490 @end example
2492 By default the output file (on Unix systems, the @file{.o} file) will be
2493 put into the current build directory.  However, if the option
2494 @code{subdir-objects} is in effect in the current directory then the
2495 @file{.o} file will be put into the subdirectory named after the source
2496 file.  For instance, with @code{subdir-objects} enabled,
2497 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
2498 people prefer this mode of operation.  You can specify
2499 @code{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
2500 @cindex Subdirectory, objects in
2501 @cindex Objects in subdirectory
2504 @item EXTRA_maude_SOURCES
2505 Automake needs to know the list of files you intend to compile
2506 @emph{statically}.  For one thing, this is the only way Automake has of
2507 knowing what sort of language support a given @file{Makefile.in}
2508 requires.  @footnote{There are other, more obscure reasons reasons for
2509 this limitation as well.}  This means that, for example, you can't put a
2510 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
2511 variable.  If you intend to conditionally compile source files and use
2512 @file{configure} to substitute the appropriate object names into, e.g.,
2513 @samp{_LDADD} (see below), then you should list the corresponding source
2514 files in the @samp{EXTRA_} variable.
2516 This variable also supports @samp{dist_} and @samp{nodist_} prefixes,
2517 e.g., @samp{nodist_EXTRA_maude_SOURCES}.
2519 @item maude_AR
2520 A static library is created by default by invoking @code{$(AR) cru}
2521 followed by the name of the library and then the objects being put into
2522 the library.  You can override this by setting the @samp{_AR} variable.
2523 This is usually used with C++; some C++ compilers require a special
2524 invocation in order to instantiate all the templates which should go
2525 into a library.  For instance, the SGI C++ compiler likes this variable set
2526 like so:
2527 @example
2528 libmaude_a_AR = $(CXX) -ar -o
2529 @end example
2531 @item maude_LIBADD
2532 Extra objects can be added to a @emph{library} using the @samp{_LIBADD}
2533 variable.  For instance this should be used for objects determined by
2534 @code{configure} (@pxref{A Library}).
2536 @item maude_LDADD
2537 Extra objects can be added to a @emph{program} by listing them in the
2538 @samp{_LDADD} variable.  For instance this should be used for objects
2539 determined by @code{configure} (@pxref{Linking}).
2541 @samp{_LDADD} and @samp{_LIBADD} are inappropriate for passing
2542 program-specific linker flags (except for @samp{-l}, @samp{-L},
2543 @samp{-dlopen} and @samp{-dlpreopen}).  Use the @samp{_LDFLAGS} variable
2544 for this purpose.
2546 For instance, if your @file{configure.in} uses @code{AC_PATH_XTRA}, you
2547 could link your program against the X libraries like so:
2549 @example
2550 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
2551 @end example
2553 @item maude_LDFLAGS
2554 This variable is used to pass extra flags to the link step of a program
2555 or a shared library.
2557 @item maude_LINK
2558 You can override the linker on a per-program basis.  By default the
2559 linker is chosen according to the languages used by the program.  For
2560 instance, a program that includes C++ source code would use the C++
2561 compiler to link.  The @samp{_LINK} variable must hold the name of a
2562 command which can be passed all the @file{.o} file names as arguments.
2563 Note that the name of the underlying program is @emph{not} passed to
2564 @samp{_LINK}; typically one uses @samp{$@@}:
2566 @example
2567 maude_LINK = $(CCLD) -magic -o $@@
2568 @end example
2570 @item maude_CCASFLAGS
2571 @itemx maude_CFLAGS
2572 @itemx maude_CPPFLAGS
2573 @itemx maude_CXXFLAGS
2574 @itemx maude_FFLAGS
2575 @itemx maude_GCJFLAGS
2576 @itemx maude_LFLAGS
2577 @itemx maude_OBJCFLAGS
2578 @itemx maude_RFLAGS
2579 @itemx maude_YFLAGS
2580 Automake allows you to set compilation flags on a per-program (or
2581 per-library) basis.  A single source file can be included in several
2582 programs, and it will potentially be compiled with different flags for
2583 each program.  This works for any language directly supported by
2584 Automake.  The flags are
2585 @samp{_CCASFLAGS},
2586 @samp{_CFLAGS},
2587 @samp{_CPPFLAGS},
2588 @samp{_CXXFLAGS},
2589 @samp{_FFLAGS},
2590 @samp{_GCJFLAGS},
2591 @samp{_LFLAGS},
2592 @samp{_OBJCFLAGS},
2593 @samp{_RFLAGS}, and
2594 @samp{_YFLAGS}.
2596 When using a per-program compilation flag, Automake will choose a
2597 different name for the intermediate object files.  Ordinarily a file
2598 like @file{sample.c} will be compiled to produce @file{sample.o}.
2599 However, if the program's @samp{_CFLAGS} variable is set, then the
2600 object file will be named, for instance, @file{maude-sample.o}.
2602 In compilations with per-program flags, the ordinary @samp{AM_} form of
2603 the flags variable is @emph{not} automatically included in the
2604 compilation (however, the user form of the variable @emph{is} included).
2605 So for instance, if you want the hypothetical @file{maude} compilations
2606 to also use the value of @samp{AM_CFLAGS}, you would need to write:
2608 @example
2609 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
2610 @end example
2613 @item maude_DEPENDENCIES
2614 It is also occasionally useful to have a program depend on some other
2615 target which is not actually part of that program.  This can be done
2616 using the @samp{_DEPENDENCIES} variable.  Each program depends on the
2617 contents of such a variable, but no further interpretation is done.
2619 If @samp{_DEPENDENCIES} is not supplied, it is computed by Automake.
2620 The automatically-assigned value is the contents of @samp{_LDADD} or
2621 @samp{_LIBADD}, with most configure substitutions, @samp{-l}, @samp{-L},
2622 @samp{-dlopen} and @samp{-dlpreopen} options removed.  The configure
2623 substitutions that are left in are only @samp{@@LIBOBJS@@} and
2624 @samp{@@ALLOCA@@}; these are left because it is known that they will not
2625 cause an invalid value for @samp{_DEPENDENCIES} to be generated.
2627 @item maude_SHORTNAME
2628 On some platforms the allowable file names are very short.  In order to
2629 support these systems and per-program compilation flags at the same
2630 time, Automake allows you to set a ``short name'' which will influence
2631 how intermediate object files are named.  For instance, if you set
2632 @samp{maude_SHORTNAME} to @samp{m}, then in the above per-program
2633 compilation flag example the object file would be named
2634 @file{m-sample.o} rather than @file{maude-sample.o}.  This facility is
2635 rarely needed in practice, and we recommend avoiding it until you find
2636 it is required.
2637 @end table
2640 @node LIBOBJS, Program variables, Program and Library Variables, Programs
2641 @section Special handling for LIBOBJS and ALLOCA
2643 @cindex @code{LIBOBJS}, special handling
2644 @cindex @code{ALLOCA}, special handling
2646 Automake explicitly recognizes the use of @code{$(LIBOBJS)} and
2647 @code{$(ALLOCA)}, and uses this information, plus the list of
2648 @code{LIBOBJS} files derived from @file{configure.in} to automatically
2649 include the appropriate source files in the distribution (@pxref{Dist}).
2650 These source files are also automatically handled in the
2651 dependency-tracking scheme; see @xref{Dependencies}.
2653 @code{$(LIBOBJS)} and @code{$(ALLOCA)} are specially recognized in any
2654 @samp{_LDADD} or @samp{_LIBADD} variable.
2657 @node Program variables, Yacc and Lex, LIBOBJS, Programs
2658 @section Variables used when building a program
2660 Occasionally it is useful to know which @file{Makefile} variables
2661 Automake uses for compilations; for instance you might need to do your
2662 own compilation in some special cases.
2664 Some variables are inherited from Autoconf; these are @code{CC},
2665 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
2666 @code{LIBS}.
2667 @vindex CC
2668 @vindex CFLAGS
2669 @vindex CPPFLAGS
2670 @vindex DEFS
2671 @vindex LDFLAGS
2672 @vindex LIBS
2674 There are some additional variables which Automake itself defines:
2676 @vtable @code
2677 @item AM_CPPFLAGS
2678 The contents of this variable are passed to every compilation which invokes
2679 the C preprocessor; it is a list of arguments to the preprocessor.  For
2680 instance, @samp{-I} and @samp{-D} options should be listed here.
2682 Automake already provides some @samp{-I} options automatically.  In
2683 particular it generates @samp{-I$(srcdir)}, @samp{-I.}, and a @samp{-I}
2684 pointing to the directory holding @file{config.h} (if you've used
2685 @code{AC_CONFIG_HEADERS} or @code{AM_CONFIG_HEADER}).  You can disable
2686 the default @samp{-I} options using the @samp{nostdinc} option.
2688 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
2689 per-library) @code{_CPPFLAGS} variable if it is defined.
2691 @item INCLUDES
2692 This does the same job as @samp{AM_CPPFLAGS}.  It is an older name for
2693 the same functionality.  This variable is deprecated; we suggest using
2694 @samp{AM_CPPFLAGS} instead.
2696 @item AM_CFLAGS
2697 This is the variable which the @file{Makefile.am} author can use to pass
2698 in additional C compiler flags.  It is more fully documented elsewhere.
2699 In some situations, this is not used, in preference to the
2700 per-executable (or per-library) @code{_CFLAGS}.
2702 @item COMPILE
2703 This is the command used to actually compile a C source file.  The
2704 filename is appended to form the complete command line.
2706 @item AM_LDFLAGS
2707 This is the variable which the @file{Makefile.am} author can use to pass
2708 in additional linker flags.  In some situations, this is not used, in
2709 preference to the per-executable (or per-library) @code{_LDFLAGS}.
2711 @item LINK
2712 This is the command used to actually link a C program.  It already
2713 includes @samp{-o $@@} and the usual variable references (for instance,
2714 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
2715 and libraries to link in.
2716 @end vtable
2719 @node Yacc and Lex, C++ Support, Program variables, Programs
2720 @section Yacc and Lex support
2722 Automake has somewhat idiosyncratic support for Yacc and Lex.
2724 Automake assumes that the @file{.c} file generated by @code{yacc} (or
2725 @code{lex}) should be named using the basename of the input file.  That
2726 is, for a yacc source file @file{foo.y}, Automake will cause the
2727 intermediate file to be named @file{foo.c} (as opposed to
2728 @file{y.tab.c}, which is more traditional).
2730 The extension of a yacc source file is used to determine the extension
2731 of the resulting @samp{C} or @samp{C++} file.  Files with the extension
2732 @samp{.y} will be turned into @samp{.c} files; likewise, @samp{.yy} will
2733 become @samp{.cc}; @samp{.y++}, @samp{c++}; and @samp{.yxx},
2734 @samp{.cxx}.
2736 Likewise, lex source files can be used to generate @samp{C} or
2737 @samp{C++}; the extensions @samp{.l}, @samp{.ll}, @samp{.l++}, and
2738 @samp{.lxx} are recognized.
2740 You should never explicitly mention the intermediate (@samp{C} or
2741 @samp{C++}) file in any @samp{SOURCES} variable; only list the source
2742 file.
2744 The intermediate files generated by @code{yacc} (or @code{lex}) will be
2745 included in any distribution that is made.  That way the user doesn't
2746 need to have @code{yacc} or @code{lex}.
2748 If a @code{yacc} source file is seen, then your @file{configure.in} must
2749 define the variable @samp{YACC}.  This is most easily done by invoking
2750 the macro @samp{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
2751 Program Checks, autoconf, The Autoconf Manual}).
2753 When @code{yacc} is invoked, it is passed @samp{YFLAGS} and
2754 @samp{AM_YFLAGS}.  The former is a user variable and the latter is
2755 intended for the @file{Makefile.am} author.
2757 @samp{AM_YFLAGS} is usually used to pass the @code{-d} option to
2758 @code{yacc}.  Automake knows what this means and will automatically
2759 adjust its rules to update and distribute the header file built by
2760 @code{yacc -d}.  What Automake cannot guess, though, is where this
2761 header will be used: it is up to you to ensure the header gets built
2762 before it is first used.  Typically this is necessary in order for
2763 dependency tracking to work when the header is included by another
2764 file.  The common solution is listing the header file in
2765 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
2767 @example
2768 BUILT_SOURCES = parser.h
2769 AM_YFLAGS = -d
2770 bin_PROGRAMS = foo
2771 foo_SOURCES = @dots{} parser.y @dots{}
2772 @end example
2774 If a @code{lex} source file is seen, then your @file{configure.in}
2775 must define the variable @samp{LEX}.  You can use @samp{AC_PROG_LEX}
2776 to do this (@pxref{Particular Programs, , Particular Program Checks,
2777 autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
2778 (@pxref{Macros}) is recommended.
2780 When @code{lex} is invoked, it is passed @samp{LFLAGS} and
2781 @samp{AM_LFLAGS}.  The former is a user variable and the latter is
2782 intended for the @file{Makefile.am} author.
2786 @cindex ylwrap
2787 @cindex yacc, multiple parsers
2788 @cindex Multiple yacc parsers
2789 @cindex Multiple lex lexers
2790 @cindex lex, multiple lexers
2793 Automake makes it possible to include multiple @code{yacc} (or
2794 @code{lex}) source files in a single program.  When there is more than
2795 one distinct @code{yacc} (or @code{lex}) source file in a directory,
2796 Automake uses a small program called @code{ylwrap} to run @code{yacc}
2797 (or @code{lex}) in a subdirectory.  This is necessary because yacc's
2798 output filename is fixed, and a parallel make could conceivably invoke
2799 more than one instance of @code{yacc} simultaneously.  The @code{ylwrap}
2800 program is distributed with Automake.  It should appear in the directory
2801 specified by @samp{AC_CONFIG_AUX_DIR} (@pxref{Input, , Finding
2802 `configure' Input, autoconf, The Autoconf Manual}), or the current
2803 directory if that macro is not used in @file{configure.in}.
2805 For @code{yacc}, simply managing locking is insufficient.  The output of
2806 @code{yacc} always uses the same symbol names internally, so it isn't
2807 possible to link two @code{yacc} parsers into the same executable.
2809 We recommend using the following renaming hack used in @code{gdb}:
2810 @example
2811 #define yymaxdepth c_maxdepth
2812 #define yyparse c_parse
2813 #define yylex   c_lex
2814 #define yyerror c_error
2815 #define yylval  c_lval
2816 #define yychar  c_char
2817 #define yydebug c_debug
2818 #define yypact  c_pact
2819 #define yyr1    c_r1
2820 #define yyr2    c_r2
2821 #define yydef   c_def
2822 #define yychk   c_chk
2823 #define yypgo   c_pgo
2824 #define yyact   c_act
2825 #define yyexca  c_exca
2826 #define yyerrflag c_errflag
2827 #define yynerrs c_nerrs
2828 #define yyps    c_ps
2829 #define yypv    c_pv
2830 #define yys     c_s
2831 #define yy_yys  c_yys
2832 #define yystate c_state
2833 #define yytmp   c_tmp
2834 #define yyv     c_v
2835 #define yy_yyv  c_yyv
2836 #define yyval   c_val
2837 #define yylloc  c_lloc
2838 #define yyreds  c_reds
2839 #define yytoks  c_toks
2840 #define yylhs   c_yylhs
2841 #define yylen   c_yylen
2842 #define yydefred c_yydefred
2843 #define yydgoto c_yydgoto
2844 #define yysindex c_yysindex
2845 #define yyrindex c_yyrindex
2846 #define yygindex c_yygindex
2847 #define yytable  c_yytable
2848 #define yycheck  c_yycheck
2849 #define yyname   c_yyname
2850 #define yyrule   c_yyrule
2851 @end example
2853 For each define, replace the @samp{c_} prefix with whatever you like.
2854 These defines work for @code{bison}, @code{byacc}, and traditional
2855 @code{yacc}s.  If you find a parser generator that uses a symbol not
2856 covered here, please report the new name so it can be added to the list.
2859 @node C++ Support, Assembly Support, Yacc and Lex, Programs
2860 @section C++ Support
2862 @cindex C++ support
2863 @cindex Support for C++
2865 Automake includes full support for C++.
2867 Any package including C++ code must define the output variable
2868 @samp{CXX} in @file{configure.in}; the simplest way to do this is to use
2869 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
2870 Program Checks, autoconf, The Autoconf Manual}).
2872 A few additional variables are defined when a C++ source file is seen:
2874 @vtable @code
2875 @item CXX
2876 The name of the C++ compiler.
2878 @item CXXFLAGS
2879 Any flags to pass to the C++ compiler.
2881 @item AM_CXXFLAGS
2882 The maintainer's variant of @code{CXXFLAGS}.
2884 @item CXXCOMPILE
2885 The command used to actually compile a C++ source file.  The file name
2886 is appended to form the complete command line.
2888 @item CXXLINK
2889 The command used to actually link a C++ program.
2890 @end vtable
2893 @node Assembly Support, Fortran 77 Support, C++ Support, Programs
2894 @section Assembly Support
2896 Automake includes some support for assembly code.
2898 The variable @code{CCAS} holds the name of the compiler used to build
2899 assembly code.  This compiler must work a bit like a C compiler; in
2900 particular it must accept @samp{-c} and @samp{-o}.  The value of
2901 @code{CCASFLAGS} is passed to the compilation.
2902 @vindex CCAS
2903 @vindex CCASFLAGS
2905 You are required to set @code{CCAS} and @code{CCASFLAGS} via
2906 @file{configure.in}.  The autoconf macro @code{AM_PROG_AS} will do this
2907 for you.  Unless they are already set, it simply sets @code{CCAS} to the
2908 C compiler and @code{CCASFLAGS} to the C compiler flags.
2910 Only the suffixes @samp{.s} and @samp{.S} are recognized by
2911 @code{automake} as being files containing assembly code.
2914 @node Fortran 77 Support, Java Support, Assembly Support, Programs
2915 @comment  node-name,  next,  previous,  up
2916 @section Fortran 77 Support
2918 @cindex Fortran 77 support
2919 @cindex Support for Fortran 77
2921 Automake includes full support for Fortran 77.
2923 Any package including Fortran 77 code must define the output variable
2924 @samp{F77} in @file{configure.in}; the simplest way to do this is to use
2925 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
2926 Program Checks, autoconf, The Autoconf Manual}).  @xref{Fortran 77 and
2927 Autoconf}.
2929 A few additional variables are defined when a Fortran 77 source file is
2930 seen:
2932 @vtable @code
2934 @item F77
2935 The name of the Fortran 77 compiler.
2937 @item FFLAGS
2938 Any flags to pass to the Fortran 77 compiler.
2940 @item AM_FFLAGS
2941 The maintainer's variant of @code{FFLAGS}.
2943 @item RFLAGS
2944 Any flags to pass to the Ratfor compiler.
2946 @item AM_RFLAGS
2947 The maintainer's variant of @code{RFLAGS}.
2949 @item F77COMPILE
2950 The command used to actually compile a Fortran 77 source file.  The file
2951 name is appended to form the complete command line.
2953 @item FLINK
2954 The command used to actually link a pure Fortran 77 program or shared
2955 library.
2957 @end vtable
2959 Automake can handle preprocessing Fortran 77 and Ratfor source files in
2960 addition to compiling them@footnote{Much, if not most, of the
2961 information in the following sections pertaining to preprocessing
2962 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
2963 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
2964 also contains some support for creating programs and shared libraries
2965 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
2966 Fortran 77 With C and C++}).
2968 These issues are covered in the following sections.
2970 @menu
2971 * Preprocessing Fortran 77::
2972 * Compiling Fortran 77 Files::
2973 * Mixing Fortran 77 With C and C++::
2974 * Fortran 77 and Autoconf::
2975 @end menu
2978 @node Preprocessing Fortran 77, Compiling Fortran 77 Files, Fortran 77 Support, Fortran 77 Support
2979 @comment  node-name,  next,  previous,  up
2980 @subsection Preprocessing Fortran 77
2982 @cindex Preprocessing Fortran 77
2983 @cindex Fortran 77, Preprocessing
2984 @cindex Ratfor programs
2986 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
2987 rule runs just the preprocessor to convert a preprocessable Fortran 77
2988 or Ratfor source file into a strict Fortran 77 source file.  The precise
2989 command used is as follows:
2991 @table @file
2993 @item .F
2994 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)}
2996 @item .r
2997 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
2999 @end table
3002 @node Compiling Fortran 77 Files, Mixing Fortran 77 With C and C++, Preprocessing Fortran 77, Fortran 77 Support
3003 @comment  node-name,  next,  previous,  up
3004 @subsection Compiling Fortran 77 Files
3006 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
3007 @file{N.r} by running the Fortran 77 compiler.  The precise command used
3008 is as follows:
3010 @table @file
3012 @item .f
3013 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
3015 @item .F
3016 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)}
3018 @item .r
3019 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
3021 @end table
3024 @node Mixing Fortran 77 With C and C++, Fortran 77 and Autoconf, Compiling Fortran 77 Files, Fortran 77 Support
3025 @comment  node-name,  next,  previous,  up
3026 @subsection Mixing Fortran 77 With C and C++
3028 @cindex Fortran 77, mixing with C and C++
3029 @cindex Mixing Fortran 77 with C and C++
3030 @cindex Linking Fortran 77 with C and C++
3031 @cindex cfortran
3032 @cindex Mixing Fortran 77 with C and/or C++
3034 Automake currently provides @emph{limited} support for creating programs
3035 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
3036 However, there are many other issues related to mixing Fortran 77 with
3037 other languages that are @emph{not} (currently) handled by Automake, but
3038 that are handled by other packages@footnote{For example,
3039 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
3040 addresses all of these inter-language issues, and runs under nearly all
3041 Fortran 77, C and C++ compilers on nearly all platforms.  However,
3042 @code{cfortran} is not yet Free Software, but it will be in the next
3043 major release.}.
3045 @page
3046 Automake can help in two ways:
3048 @enumerate
3049 @item
3050 Automatic selection of the linker depending on which combinations of
3051 source code.
3053 @item
3054 Automatic selection of the appropriate linker flags (e.g. @samp{-L} and
3055 @samp{-l}) to pass to the automatically selected linker in order to link
3056 in the appropriate Fortran 77 intrinsic and run-time libraries.
3058 @cindex FLIBS, defined
3059 These extra Fortran 77 linker flags are supplied in the output variable
3060 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro
3061 supplied with newer versions of Autoconf (Autoconf version 2.13 and
3062 later).  @xref{Fortran 77 Compiler Characteristics, , , autoconf, The
3063 Autoconf}.
3064 @end enumerate
3066 If Automake detects that a program or shared library (as mentioned in
3067 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
3068 code that is a mixture of Fortran 77 and C and/or C++, then it requires
3069 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
3070 @file{configure.in}, and that either @code{$(FLIBS)} or @code{@@FLIBS@@}
3071 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
3072 (for shared libraries) variables.  It is the responsibility of the
3073 person writing the @file{Makefile.am} to make sure that @code{$(FLIBS)}
3074 or @code{@@FLIBS@@} appears in the appropriate @code{_LDADD} or
3075 @code{_LIBADD} variable.
3077 @cindex Mixed language example
3078 @cindex Example, mixed language
3080 For example, consider the following @file{Makefile.am}:
3082 @example
3083 bin_PROGRAMS = foo
3084 foo_SOURCES  = main.cc foo.f
3085 foo_LDADD    = libfoo.la @@FLIBS@@
3087 pkglib_LTLIBRARIES = libfoo.la
3088 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
3089 libfoo_la_LIBADD   = $(FLIBS)
3090 @end example
3092 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
3093 is mentioned in @file{configure.in}.  Also, if @code{@@FLIBS@@} hadn't
3094 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
3095 Automake would have issued a warning.
3098 @page
3099 @menu
3100 * How the Linker is Chosen::
3101 @end menu
3103 @node How the Linker is Chosen,  , Mixing Fortran 77 With C and C++, Mixing Fortran 77 With C and C++
3104 @comment  node-name,  next,  previous,  up
3105 @subsubsection How the Linker is Chosen
3107 @cindex Automatic linker selection
3108 @cindex Selecting the linker automatically
3110 The following diagram demonstrates under what conditions a particular
3111 linker is chosen by Automake.
3113 For example, if Fortran 77, C and C++ source code were to be compiled
3114 into a program, then the C++ linker will be used.  In this case, if the
3115 C or Fortran 77 linkers required any special libraries that weren't
3116 included by the C++ linker, then they must be manually added to an
3117 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
3118 @file{Makefile.am}.
3120 @example
3121                      \              Linker
3122           source      \
3123            code        \     C        C++     Fortran
3124      -----------------  +---------+---------+---------+
3125                         |         |         |         |
3126      C                  |    x    |         |         |
3127                         |         |         |         |
3128                         +---------+---------+---------+
3129                         |         |         |         |
3130          C++            |         |    x    |         |
3131                         |         |         |         |
3132                         +---------+---------+---------+
3133                         |         |         |         |
3134                Fortran  |         |         |    x    |
3135                         |         |         |         |
3136                         +---------+---------+---------+
3137                         |         |         |         |
3138      C + C++            |         |    x    |         |
3139                         |         |         |         |
3140                         +---------+---------+---------+
3141                         |         |         |         |
3142      C +       Fortran  |         |         |    x    |
3143                         |         |         |         |
3144                         +---------+---------+---------+
3145                         |         |         |         |
3146          C++ + Fortran  |         |    x    |         |
3147                         |         |         |         |
3148                         +---------+---------+---------+
3149                         |         |         |         |
3150      C + C++ + Fortran  |         |    x    |         |
3151                         |         |         |         |
3152                         +---------+---------+---------+
3153 @end example
3156 @node Fortran 77 and Autoconf,  , Mixing Fortran 77 With C and C++, Fortran 77 Support
3157 @comment  node-name,  next,  previous,  up
3158 @subsection Fortran 77 and Autoconf
3160 The current Automake support for Fortran 77 requires a recent enough
3161 version of Autoconf that also includes support for Fortran 77.  Full
3162 Fortran 77 support was added to Autoconf 2.13, so you will want to use
3163 that version of Autoconf or later.
3166 @node Java Support, Support for Other Languages, Fortran 77 Support, Programs
3167 @comment  node-name,  next,  previous,  up
3168 @section Java Support
3170 @cindex Java support
3171 @cindex Support for Java
3173 Automake includes support for compiled Java, using @code{gcj}, the Java
3174 front end to the GNU Compiler Collection.
3176 Any package including Java code to be compiled must define the output
3177 variable @samp{GCJ} in @file{configure.in}; the variable @samp{GCJFLAGS}
3178 must also be defined somehow (either in @file{configure.in} or
3179 @file{Makefile.am}).  The simplest way to do this is to use the
3180 @code{AM_PROG_GCJ} macro.
3182 @vindex GCJFLAGS
3184 By default, programs including Java source files are linked with
3185 @code{gcj}.
3187 As always, the contents of @samp{AM_GCJFLAGS} are passed to every
3188 compilation invoking @code{gcj} (in its role as an ahead-of-time
3189 compiler -- when invoking it to create @file{.class} files,
3190 @samp{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
3191 options to @code{gcj} from @file{Makefile.am}, this variable, and not
3192 the user variable @samp{GCJFLAGS}, should be used.
3194 @vindex AM_GCJFLAGS
3196 @code{gcj} can be used to compile @file{.java}, @file{.class},
3197 @file{.zip}, or @file{.jar} files.
3199 When linking, @code{gcj} requires that the main class be specified
3200 using the @samp{--main=} option.  The easiest way to do this is to use
3201 the @code{_LDFLAGS} variable for the program.
3204 @node Support for Other Languages, ANSI, Java Support, Programs
3205 @comment  node-name,  next,  previous,  up
3206 @section Support for Other Languages
3208 Automake currently only includes full support for C, C++ (@pxref{C++
3209 Support}), Fortran 77 (@pxref{Fortran 77 Support}), and Java
3210 (@pxref{Java Support}).  There is only rudimentary support for other
3211 languages, support for which will be improved based on user demand.
3213 Some limited support for adding your own languages is available via the
3214 suffix rule handling; see @ref{Suffixes}.
3217 @node ANSI, Dependencies, Support for Other Languages, Programs
3218 @section Automatic de-ANSI-fication
3220 @cindex de-ANSI-fication, defined
3222 Although the GNU standards allow the use of ANSI C, this can have the
3223 effect of limiting portability of a package to some older compilers
3224 (notably the SunOS C compiler).
3226 Automake allows you to work around this problem on such machines by
3227 @dfn{de-ANSI-fying} each source file before the actual compilation takes
3228 place.
3230 @vindex AUTOMAKE_OPTIONS
3231 @opindex ansi2knr
3233 If the @file{Makefile.am} variable @code{AUTOMAKE_OPTIONS}
3234 (@pxref{Options}) contains the option @code{ansi2knr} then code to
3235 handle de-ANSI-fication is inserted into the generated
3236 @file{Makefile.in}.
3238 This causes each C source file in the directory to be treated as ANSI C@.
3239 If an ANSI C compiler is available, it is used.  If no ANSI C compiler
3240 is available, the @code{ansi2knr} program is used to convert the source
3241 files into K&R C, which is then compiled.
3243 The @code{ansi2knr} program is simple-minded.  It assumes the source
3244 code will be formatted in a particular way; see the @code{ansi2knr} man
3245 page for details.
3247 Support for de-ANSI-fication requires the source files @file{ansi2knr.c}
3248 and @file{ansi2knr.1} to be in the same package as the ANSI C source;
3249 these files are distributed with Automake.  Also, the package
3250 @file{configure.in} must call the macro @code{AM_C_PROTOTYPES}
3251 (@pxref{Macros}).
3252 @cvindex AM_C_PROTOTYPES
3254 Automake also handles finding the @code{ansi2knr} support files in some
3255 other directory in the current package.  This is done by prepending the
3256 relative path to the appropriate directory to the @code{ansi2knr}
3257 option.  For instance, suppose the package has ANSI C code in the
3258 @file{src} and @file{lib} subdirs.  The files @file{ansi2knr.c} and
3259 @file{ansi2knr.1} appear in @file{lib}.  Then this could appear in
3260 @file{src/Makefile.am}:
3262 @example
3263 AUTOMAKE_OPTIONS = ../lib/ansi2knr
3264 @end example
3266 If no directory prefix is given, the files are assumed to be in the
3267 current directory.
3269 Note that automatic de-ANSI-fication will not work when the package is
3270 being built for a different host architecture.  That is because automake
3271 currently has no way to build @code{ansi2knr} for the build machine.
3273 @c FIXME: this paragraph might be better moved to an `upgrading' section.
3274 @cindex @code{LTLIBOBJS} and @code{ansi2knr}
3275 @cindex @code{LIBOBJS} and @code{ansi2knr}
3276 @cindex @code{ansi2knr} and @code{LTLIBOBJS}
3277 @cindex @code{ansi2knr} and @code{LIBOBJS}
3278 Using @code{LIBOBJS} with source de-ANSI-fication used to require
3279 hand-crafted code in @file{configure} to append @code{$U} to basenames
3280 in @code{LIBOBJS}.  This is no longer true today.  Starting with version
3281 2.54, Autoconf takes care of rewriting @code{LIBOBJS} and
3282 @code{LTLIBOBJS}.  (@pxref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ}
3283 vs. @code{LIBOBJS}, autoconf, The Autoconf Manual})
3285 @node Dependencies, EXEEXT, ANSI, Programs
3286 @section Automatic dependency tracking
3288 As a developer it is often painful to continually update the
3289 @file{Makefile.in} whenever the include-file dependencies change in a
3290 project.  Automake supplies a way to automatically track dependency
3291 changes.
3293 @cindex Dependency tracking
3294 @cindex Automatic dependency tracking
3296 Automake always uses complete dependencies for a compilation, including
3297 system headers.  Automake's model is that dependency computation should
3298 be a side effect of the build.  To this end, dependencies are computed
3299 by running all compilations through a special wrapper program called
3300 @code{depcomp}.  @code{depcomp} understands how to coax many different C
3301 and C++ compilers into generating dependency information in the format
3302 it requires.  @code{automake -a} will install @code{depcomp} into your
3303 source tree for you.  If @code{depcomp} can't figure out how to properly
3304 invoke your compiler, dependency tracking will simply be disabled for
3305 your build.
3307 @cindex depcomp
3309 Experience with earlier versions of Automake @footnote{See
3310 @uref{http://sources.redhat.com/automake/dependencies.html} for more
3311 information on the history and experiences with automatic dependency
3312 tracking in Automake} taught us that it is not reliable to generate
3313 dependencies only on the maintainer's system, as configurations vary too
3314 much.  So instead Automake implements dependency tracking at build time.
3316 Automatic dependency tracking can be suppressed by putting
3317 @code{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
3318 passing @code{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
3319 (this should be the prefered way).  Or, you can invoke @code{automake}
3320 with the @code{-i} option.  Dependency tracking is enabled by default.
3322 @vindex AUTOMAKE_OPTIONS
3323 @opindex no-dependencies
3325 The person building your package also can choose to disable dependency
3326 tracking by configuring with @code{--disable-dependency-tracking}.
3328 @cindex Disabling dependency tracking
3329 @cindex Dependency tracking, disabling
3332 @node EXEEXT,  , Dependencies, Programs
3333 @section Support for executable extensions
3335 @cindex Executable extension
3336 @cindex Extension, executable
3337 @cindex Windows
3339 On some platforms, such as Windows, executables are expected to have an
3340 extension such as @samp{.exe}.  On these platforms, some compilers (GCC
3341 among them) will automatically generate @file{foo.exe} when asked to
3342 generate @file{foo}.
3344 Automake provides mostly-transparent support for this.  Unfortunately
3345 @emph{mostly} doesn't yet mean @emph{fully}.  Until the English
3346 dictionary is revised, you will have to assist Automake if your package
3347 must support those platforms.
3349 One thing you must be aware of is that, internally, Automake rewrites
3350 something like this:
3352 @example
3353 bin_PROGRAMS = liver
3354 @end example
3356 to this:
3358 @example
3359 bin_PROGRAMS = liver$(EXEEXT)
3360 @end example
3362 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
3363 extension.  @code{EXEEXT}
3365 However, Automake cannot apply this rewriting to @code{configure}
3366 substitutions.  This means that if you are conditionally building a
3367 program using such a substitution, then your @file{configure.in} must
3368 take care to add @samp{$(EXEEXT)} when constructing the output variable.
3370 With Autoconf 2.13 and earlier, you must explicitly use @code{AC_EXEEXT}
3371 to get this support.  With Autoconf 2.50, @code{AC_EXEEXT} is run
3372 automatically if you configure a compiler (say, through
3373 @code{AC_PROG_CC}).
3375 Sometimes maintainers like to write an explicit link rule for their
3376 program.  Without executable extension support, this is easy---you
3377 simply write a target with the same name as the program.  However, when
3378 executable extension support is enabled, you must instead add the
3379 @samp{$(EXEEXT)} suffix.
3381 Unfortunately, due to the change in Autoconf 2.50, this means you must
3382 always add this extension.  However, this is a problem for maintainers
3383 who know their package will never run on a platform that has executable
3384 extensions.  For those maintainers, the @code{no-exeext} option
3385 (@pxref{Options}) will disable this feature.  This works in a fairly
3386 ugly way; if @code{no-exeext} is seen, then the presence of a target
3387 named @code{foo} in @file{Makefile.am} will override an
3388 automake-generated target of the form @code{foo$(EXEEXT)}.  Without the
3389 @code{no-exeext} option, this use will give an error.
3392 @node Other objects, Other GNU Tools, Programs, Top
3393 @chapter Other Derived Objects
3395 Automake can handle derived objects which are not C programs.  Sometimes
3396 the support for actually building such objects must be explicitly
3397 supplied, but Automake will still automatically handle installation and
3398 distribution.
3400 @menu
3401 * Scripts::                     Executable scripts
3402 * Headers::                     Header files
3403 * Data::                        Architecture-independent data files
3404 * Sources::                     Derived sources
3405 @end menu
3408 @node Scripts, Headers, Other objects, Other objects
3409 @section Executable Scripts
3411 @cindex _SCRIPTS primary, defined
3412 @cindex SCRIPTS primary, defined
3413 @cindex Primary variable, SCRIPTS
3415 It is possible to define and install programs which are scripts.  Such
3416 programs are listed using the @samp{SCRIPTS} primary name.  Automake
3417 doesn't define any dependencies for scripts; the @file{Makefile.am}
3418 should include the appropriate rules.
3419 @vindex SCRIPTS
3421 Automake does not assume that scripts are derived objects; such objects
3422 must be deleted by hand (@pxref{Clean}).
3424 The @code{automake} program itself is a Perl script that is generated at
3425 configure time from @file{automake.in}.  Here is how this is handled:
3427 @example
3428 bin_SCRIPTS = automake
3429 @end example
3431 Since @code{automake} appears in the @code{AC_OUTPUT} macro, a target
3432 for it is automatically generated, and it is also automatically cleaned
3433 (despite the fact it's a script).
3435 @cindex SCRIPTS, installation directories
3436 @cindex Installing scripts
3438 @vindex bin_SCRIPTS
3439 @vindex sbin_SCRIPTS
3440 @vindex libexec_SCRIPTS
3441 @vindex pkgdata_SCRIPTS
3442 @vindex noinst_SCRIPTS
3443 @vindex check_SCRIPTS
3445 Script objects can be installed in @code{bindir}, @code{sbindir},
3446 @code{libexecdir}, or @code{pkgdatadir}.
3448 Scripts that need not being installed can be listed in
3449 @code{noinst_SCRIPTS}, and among them, those which are needed only by
3450 @code{make check} should go in @code{check_SCRIPTS}.
3453 @node Headers, Data, Scripts, Other objects
3454 @section Header files
3456 @cindex _HEADERS primary, defined
3457 @cindex HEADERS primary, defined
3458 @cindex Primary variable, HEADERS
3460 @vindex noinst_HEADERS
3462 Header files are specified by the @samp{HEADERS} family of variables.
3463 Generally header files are not installed, so the @code{noinst_HEADERS}
3464 variable will be the most used.  @footnote{However, for the case of a
3465 non-installed header file that is actually used by a particular program,
3466 we recommend listing it in the program's @samp{_SOURCES} variable
3467 instead of in @code{noinst_HEADERS}.  We believe this is more clear.}
3468 @vindex HEADERS
3470 All header files must be listed somewhere; missing ones will not appear
3471 in the distribution.  Often it is clearest to list uninstalled headers
3472 with the rest of the sources for a program.  @xref{A Program}.  Headers
3473 listed in a @samp{_SOURCES} variable need not be listed in any
3474 @samp{_HEADERS} variable.
3476 @cindex HEADERS, installation directories
3477 @cindex Installing headers
3479 @vindex include_HEADERS
3480 @vindex oldinclude_HEADERS
3481 @vindex pkginclude_HEADERS
3483 Headers can be installed in @code{includedir}, @code{oldincludedir}, or
3484 @code{pkgincludedir}.
3487 @node Data, Sources, Headers, Other objects
3488 @section Architecture-independent data files
3490 @cindex _DATA primary, defined
3491 @cindex DATA primary, defined
3492 @cindex Primary variable, DATA
3494 Automake supports the installation of miscellaneous data files using the
3495 @samp{DATA} family of variables.
3496 @vindex DATA
3498 @vindex data_DATA
3499 @vindex sysconf_DATA
3500 @vindex sharedstate_DATA
3501 @vindex localstate_DATA
3502 @vindex pkgdata_DATA
3504 Such data can be installed in the directories @code{datadir},
3505 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
3506 @code{pkgdatadir}.
3508 By default, data files are @emph{not} included in a distribution.  Of
3509 course, you can use the @samp{dist_} prefix to change this on a
3510 per-variable basis.
3512 Here is how Automake declares its auxiliary data files:
3514 @example
3515 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
3516 @end example
3519 @node Sources,  , Data, Other objects
3520 @section Built sources
3522 Because Automake's automatic dependency tracking works as a side-effect
3523 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
3524 target should not be compiled before its dependencies are made, but
3525 these dependencies are unknown until the target is first compiled.
3527 Ordinarily this is not a problem, because dependencies are distributed
3528 sources: they preexist and do not need to be built.  Suppose that
3529 @file{foo.c} includes @file{foo.h}.  When it first compiles
3530 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
3531 @file{foo.c}.  As a side-effect of this compilation @code{depcomp}
3532 records the @file{foo.h} dependency so that following invocations of
3533 @command{make} will honor it.  In these conditions, it's clear there is
3534 no problem: either @file{foo.o} doesn't exist and has to be built
3535 (regardless of the dependencies), either accurate dependencies exist and
3536 they can be used to decide whether @file{foo.o} should be rebuilt.
3538 It's a different story if @file{foo.h} doesn't exist by the first
3539 @command{make} run.  For instance there might be a rule to build
3540 @file{foo.h}.  This time @file{file.o}'s build will fail because the
3541 compiler can't find @file{foo.h}. @command{make} failed to trigger the
3542 rule to build @file{foo.h} first by lack of dependency information.
3544 @vindex BUILT_SOURCES
3545 @cindex BUILT_SOURCES, defined
3547 The @code{BUILT_SOURCES} variable is a workaround for this problem.  A
3548 source file listed in @code{BUILT_SOURCES} is made on @code{make all} or
3549 @code{make check} before other targets are processed.  However, such a
3550 source file is not @emph{compiled} unless explicitly requested by
3551 mentioning it in some other @samp{_SOURCES} variable.
3553 So, to conclude our introductory example, we could use
3554 @code{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
3555 any other target (including @file{foo.o}) during @code{make all} or
3556 @code{make check}.
3558 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
3559 must be created early in the build process can be listed in this
3560 variable.  Moreover, all built sources do not necessarily have to be
3561 listed in @code{BUILT_SOURCES}.  For instance a generated @file{.c} file
3562 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
3563 another source), because it's a known dependency of the associated
3564 object.
3566 It might be important to emphasize that @code{BUILT_SOURCES} is honored
3567 only by @code{make all} and @code{make check}.  This means you cannot
3568 build a specific target (e.g., @code{make foo}) in a clean tree if it
3569 depends on a built source.  However it will succeed if you have run
3570 @code{make all} earlier, because accurate dependencies are already
3571 available.
3573 The next section illustrates and discusses the handling of built sources
3574 on a toy example.
3576 @menu
3577 * Built sources example::       Several ways to handle built sources.
3578 @end menu
3580 @node Built sources example,  , Sources, Sources
3581 @subsection Built sources example
3583 Suppose that @file{foo.c} includes @file{bindir.h}, which is
3584 installation-dependent and not distributed: it needs to be built.  Here
3585 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
3586 value of the @command{make} variable @code{bindir} (inherited from
3587 @file{configure}).
3589 We suggest several implementations below.  It's not meant to be an
3590 exhaustive listing of all ways to handle built sources, but it will give
3591 you a few ideas if you encounter this issue.
3593 @unnumberedsubsec First try
3595 This first implementation will illustrate the bootstrap issue mentioned
3596 in the previous section (@pxref{Sources}).
3598 Here is a tentative @file{Makefile.am}.
3600 @example
3601 # This won't work.
3602 bin_PROGRAMS = foo
3603 foo_SOURCES = foo.c
3604 nodist_foo_SOURCES = bindir.h
3605 CLEANFILES = bindir.h
3606 bindir.h: Makefile
3607         echo '#define bindir "$(bindir)"' >$@@
3608 @end example
3610 This setup doesn't work, because Automake doesn't know that @file{foo.c}
3611 includes @file{bindir.h}.  Remember, automatic dependency tracking works
3612 as a side-effect of compilation, so the dependencies of @file{foo.o} will
3613 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
3614 The symptom is as follows.
3616 @example
3617 % make
3618 source='foo.c' object='foo.o' libtool=no \
3619 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
3620 depmode=gcc /bin/sh ./depcomp \
3621 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
3622 foo.c:2: bindir.h: No such file or directory
3623 make: *** [foo.o] Error 1
3624 @end example
3626 @unnumberedsubsec Using @code{BUILT_SOURCES}
3628 A solution is to require @file{bindir.h} to be built before anything
3629 else.  This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
3631 @example
3632 bin_PROGRAMS = foo
3633 foo_SOURCES = foo.c
3634 BUILT_SOURCES = bindir.h
3635 CLEANFILES = bindir.h
3636 bindir.h: Makefile
3637         echo '#define bindir "$(bindir)"' >$@@
3638 @end example
3640 See how @file{bindir.h} get built first:
3642 @example
3643 % make
3644 echo '#define bindir "/usr/local/bin"' >bindir.h
3645 make  all-am
3646 make[1]: Entering directory `/home/adl/tmp'
3647 source='foo.c' object='foo.o' libtool=no \
3648 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
3649 depmode=gcc /bin/sh ./depcomp \
3650 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
3651 gcc  -g -O2   -o foo  foo.o
3652 make[1]: Leaving directory `/home/adl/tmp'
3653 @end example
3655 However, as said earlier, @code{BUILT_SOURCES} applies only to the
3656 @code{all} and @code{check} targets.  It still fails if you try to run
3657 @code{make foo} explicitly:
3659 @example
3660 % make clean
3661 test -z "bindir.h" || rm -f bindir.h
3662 test -z "foo" || rm -f foo
3663 rm -f *.o core *.core
3664 % : > .deps/foo.Po # Suppress previously recorded dependencies
3665 % make foo
3666 source='foo.c' object='foo.o' libtool=no \
3667 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
3668 depmode=gcc /bin/sh ./depcomp \
3669 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
3670 foo.c:2: bindir.h: No such file or directory
3671 make: *** [foo.o] Error 1
3672 @end example
3674 @unnumberedsubsec Recording dependencies manually
3676 Usually people are happy enough with @code{BUILT_SOURCES} because they
3677 never run targets such as @code{make foo} before @code{make all}, as in
3678 the previous example.  However if this matters to you, you can avoid
3679 @code{BUILT_SOURCES} and record such dependencies explicitly in the
3680 @file{Makefile.am}.
3682 @example
3683 bin_PROGRAMS = foo
3684 foo_SOURCES = foo.c
3685 foo.$(OBJEXT): bindir.h
3686 CLEANFILES = bindir.h
3687 bindir.h: Makefile
3688         echo '#define bindir "$(bindir)"' >$@@
3689 @end example
3691 You don't have to list @emph{all} the dependencies of @code{foo.o}
3692 explicitly, only those which might need to be built.  If a dependency
3693 already exists, it will not hinder the first compilation and will be
3694 recorded by the normal dependency tracking code.  (Note that after this
3695 first compilation the dependency tracking code will also have recorded
3696 the dependency between @code{foo.o} and @code{bindir.h}; so our explicit
3697 dependency is really useful to the first build only.)
3699 Adding explicit dependencies like this can be a bit dangerous if you are
3700 not careful enough.  This is due to the way Automake tries not to
3701 overwrite your rules (it assumes you know better than it).
3702 @code{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
3703 output to build @code{foo.$(OBJEXT)}.  It happens to work in this case
3704 because Automake doesn't have to output any @code{foo.$(OBJEXT):}
3705 target: it relies on a suffix rule instead (i.e., @code{.c.$(OBJEXT):}).
3706 Always check the generated @file{Makefile.in} if you do this.
3708 @unnumberedsubsec Build @file{bindir.h} from @file{configure}
3710 It's possible to define this preprocessor macro from @file{configure},
3711 either in @file{config.h} (@pxref{Defining Directories, , Defining
3712 Directories, autoconf, The Autoconf Manual}), or by processing a
3713 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
3714 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
3715 Autoconf Manual}).
3717 At this point it should be clear that building @file{bindir.h} from
3718 @file{configure} work well for this example.  @file{bindir.h} will exist
3719 before you build any target, hence will not cause any dependency issue.
3721 The Makefile can be shrunk as follows.  We do not even have to mention
3722 @file{bindir.h}.
3724 @example
3725 bin_PROGRAMS = foo
3726 foo_SOURCES = foo.c
3727 @end example
3729 However, it's not always possible to build sources from
3730 @file{configure}, especially when these sources are generated by a tool
3731 that needs to be built first...
3733 @unnumberedsubsec Build @file{bindir.c}, not @file{bindir.h}.
3735 Another attractive idea is to define @code{bindir} as a variable or
3736 function exported from @file{bindir.o}, and build @file{bindir.c}
3737 instead of @file{bindir.h}.
3739 @example
3740 noinst_PROGRAMS = foo
3741 foo_SOURCES = foo.c bindir.h
3742 nodist_foo_SOURCES = bindir.c
3743 CLEANFILES = bindir.c
3744 bindir.c: Makefile
3745         echo 'const char bindir[] = "$(bindir)";' >$@
3746 @end example
3748 @file{bindir.h} contains just the variable's declaration and doesn't
3749 need to be built, so it won't cause any trouble.  @file{bindir.o} is
3750 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
3751 first.
3753 @unnumberedsubsec Which is best?
3755 There is no panacea, of course.  Each solution has its merits and
3756 drawbacks.
3758 You cannot use @code{BUILT_SOURCES} if the ability to run @code{make
3759 foo} on a clean tree is important to you.
3761 You won't add explicit dependencies if you are leery of overriding
3762 an Automake target by mistake.
3764 Building files from @file{./configure} is not always possible, neither
3765 is converting @file{.h} files into @file{.c} files.
3768 @node Other GNU Tools, Documentation, Other objects, Top
3769 @chapter Other GNU Tools
3771 Since Automake is primarily intended to generate @file{Makefile.in}s for
3772 use in GNU programs, it tries hard to interoperate with other GNU tools.
3774 @menu
3775 * Emacs Lisp::                  Emacs Lisp
3776 * gettext::                     Gettext
3777 * Libtool::                     Libtool
3778 * Java::                        Java
3779 * Python::                      Python
3780 @end menu
3783 @node Emacs Lisp, gettext, Other GNU Tools, Other GNU Tools
3784 @section Emacs Lisp
3786 @cindex _LISP primary, defined
3787 @cindex LISP primary, defined
3788 @cindex Primary variable, LISP
3790 @vindex LISP
3791 @vindex lisp_LISP
3792 @vindex noinst_LISP
3794 Automake provides some support for Emacs Lisp.  The @samp{LISP} primary
3795 is used to hold a list of @file{.el} files.  Possible prefixes for this
3796 primary are @samp{lisp_} and @samp{noinst_}.  Note that if
3797 @code{lisp_LISP} is defined, then @file{configure.in} must run
3798 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
3800 @vindex ELCFILES
3802 By default Automake will byte-compile all Emacs Lisp source files using
3803 the Emacs found by @code{AM_PATH_LISPDIR}.  If you wish to avoid
3804 byte-compiling, simply define the variable @code{ELCFILES} to be empty.
3805 Byte-compiled Emacs Lisp files are not portable among all versions of
3806 Emacs, so it makes sense to turn this off if you expect sites to have
3807 more than one version of Emacs installed.  Furthermore, many packages
3808 don't actually benefit from byte-compilation.  Still, we recommend that
3809 you leave it enabled by default.  It is probably better for sites with
3810 strange setups to cope for themselves than to make the installation less
3811 nice for everybody else.
3814 @node gettext, Libtool, Emacs Lisp, Other GNU Tools
3815 @section Gettext
3817 @cindex GNU Gettext support
3818 @cindex Gettext support
3819 @cindex Support for GNU Gettext
3821 If @code{AM_GNU_GETTEXT} is seen in @file{configure.in}, then Automake
3822 turns on support for GNU gettext, a message catalog system for
3823 internationalization
3824 (@pxref{GNU Gettext, , , gettext, GNU gettext utilities}).
3826 The @code{gettext} support in Automake requires the addition of two
3827 subdirectories to the package, @file{intl} and @file{po}.  Automake
3828 insures that these directories exist and are mentioned in
3829 @code{SUBDIRS}.
3832 @node Libtool, Java, gettext, Other GNU Tools
3833 @section Libtool
3835 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
3836 libtool, The Libtool Manual}) with the @samp{LTLIBRARIES} primary.
3837 @xref{A Shared Library}.
3840 @node Java, Python, Libtool, Other GNU Tools
3841 @section Java
3843 @cindex _JAVA primary, defined
3844 @cindex JAVA primary, defined
3845 @cindex Primary variable, JAVA
3847 Automake provides some minimal support for Java compilation with the
3848 @samp{JAVA} primary.
3850 Any @file{.java} files listed in a @samp{_JAVA} variable will be
3851 compiled with @code{JAVAC} at build time.  By default, @file{.class}
3852 files are not included in the distribution.
3854 @cindex JAVA restrictions
3855 @cindex Restrictions for JAVA
3857 Currently Automake enforces the restriction that only one @samp{_JAVA}
3858 primary can be used in a given @file{Makefile.am}.  The reason for this
3859 restriction is that, in general, it isn't possible to know which
3860 @file{.class} files were generated from which @file{.java} files -- so
3861 it would be impossible to know which files to install where.  For
3862 instance, a @file{.java} file can define multiple classes; the resulting
3863 @file{.class} file names cannot be predicted without parsing the
3864 @file{.java} file.
3866 There are a few variables which are used when compiling Java sources:
3868 @vtable @code
3869 @item JAVAC
3870 The name of the Java compiler.  This defaults to @samp{javac}.
3872 @item JAVACFLAGS
3873 The flags to pass to the compiler.  This is considered to be a user
3874 variable (@pxref{User Variables}).
3876 @item AM_JAVACFLAGS
3877 More flags to pass to the Java compiler.  This, and not
3878 @code{JAVACFLAGS}, should be used when it is necessary to put Java
3879 compiler flags into @file{Makefile.am}.
3881 @item JAVAROOT
3882 The value of this variable is passed to the @samp{-d} option to
3883 @code{javac}.  It defaults to @samp{$(top_builddir)}.
3885 @item CLASSPATH_ENV
3886 This variable is an @code{sh} expression which is used to set the
3887 @code{CLASSPATH} environment variable on the @code{javac} command line.
3888 (In the future we will probably handle class path setting differently.)
3889 @end vtable
3892 @node Python,  , Java, Other GNU Tools
3893 @section Python
3895 @cindex _PYTHON primary, defined
3896 @cindex PYTHON primary, defined
3897 @cindex Primary variable, PYTHON
3900 Automake provides support for Python compilation with the @samp{PYTHON}
3901 primary.
3903 Any files listed in a @samp{_PYTHON} variable will be byte-compiled with
3904 @code{py-compile} at install time.  @code{py-compile} actually creates
3905 both standard (@file{.pyc}) and byte-compiled (@file{.pyo}) versions of
3906 the source files.  Note that because byte-compilation occurs at install
3907 time, any files listed in @samp{noinst_PYTHON} will not be compiled.
3908 Python source files are included in the distribution by default.
3910 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON} which
3911 will determine some Python-related directory variables (see below).  If
3912 you have called @code{AM_PATH_PYTHON} from @file{configure.in}, then you
3913 may use the following variables to list you Python source files in your
3914 variables: @samp{python_PYTHON}, @samp{pkgpython_PYTHON},
3915 @samp{pyexecdir_PYTHON}, @samp{pkgpyexecdir_PYTHON}, depending where you
3916 want your files installed.
3918 @code{AM_PATH_PYTHON} takes a single optional argument.  This argument,
3919 if present, is the minimum version of Python which can be used for this
3920 package.  If the version of Python found on the system is older than the
3921 required version, then @code{AM_PATH_PYTHON} will cause an error.
3923 @code{AM_PATH_PYTHON} creates several output variables based on the
3924 Python installation found during configuration.
3926 @vtable @code
3927 @item PYTHON
3928 The name of the Python executable.
3930 @item PYTHON_VERSION
3931 The Python version number, in the form @var{major}.@var{minor}
3932 (e.g. @samp{1.5}).  This is currently the value of
3933 @code{sys.version[:3]}.
3935 @item PYTHON_PREFIX
3936 The string @code{$@{prefix@}}.  This term may be used in future work
3937 which needs the contents of Python's @code{sys.prefix}, but general
3938 consensus is to always use the value from configure.
3940 @item PYTHON_EXEC_PREFIX
3941 The string @code{$@{exec_prefix@}}.  This term may be used in future work
3942 which needs the contents of Python's @code{sys.exec_prefix}, but general
3943 consensus is to always use the value from configure.
3945 @item PYTHON_PLATFORM
3946 The canonical name used by Python to describe the operating system, as
3947 given by @code{sys.platform}.  This value is sometimes needed when
3948 building Python extensions.
3950 @item pythondir
3951 The directory name for the @file{site-packages} subdirectory of the
3952 standard Python install tree.
3954 @item pkgpythondir
3955 This is is the directory under @code{pythondir} which is named after the
3956 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
3957 as a convenience.
3959 @item pyexecdir
3960 This is the directory where Python extension modules (shared libraries)
3961 should be installed.
3963 @item pkgpyexecdir
3964 This is a convenience variable which is defined as
3965 @samp{$(pyexecdir)/$(PACKAGE)}.
3966 @end vtable
3968 All these directory variables have values that start with either
3969 @code{$@{prefix@}} or @code{$@{exec_prefix@}} unexpanded.  This works
3970 fine in @file{Makefiles}, but it makes these variables hard to use in
3971 @file{configure}.  This is mandated by the GNU conding standard, so
3972 that the user can run @code{make prefix=/foo install}.  The Autoconf
3973 manual has a section with more details on this topic
3974 (@pxref{Installation Directory Variables, , Installation Directory
3975 Variables, autoconf, The Autoconf Manual}).
3978 @node Documentation, Install, Other GNU Tools, Top
3979 @chapter Building documentation
3981 Currently Automake provides support for Texinfo and man pages.
3983 @menu
3984 * Texinfo::                     Texinfo
3985 * Man pages::                   Man pages
3986 @end menu
3989 @node Texinfo, Man pages, Documentation, Documentation
3990 @section Texinfo
3992 @cindex _TEXINFOS primary, defined
3993 @cindex TEXINFOS primary, defined
3994 @cindex Primary variable, TEXINFOS
3996 If the current directory contains Texinfo source, you must declare it
3997 with the @samp{TEXINFOS} primary.  Generally Texinfo files are converted
3998 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
3999 here.  Any Texinfo source file must end in the @file{.texi},
4000 @file{.txi}, or @file{.texinfo} extension.  We recommend @file{.texi}
4001 for new manuals.
4002 @vindex TEXINFOS
4003 @vindex info_TEXINFOS
4005 Automake generates rules to build @file{.info}, @file{.dvi}, @file{.ps},
4006 and @file{.pdf} files from your Texinfo sources.  The @file{.info} files
4007 are built by @code{make all} and installed by @code{make install}
4008 (unless you use @code{no-installinfo}, see below).  The other files can
4009 be built on request by @code{make dvi}, @code{make ps}, and @code{make
4010 pdf}.
4012 @cindex Texinfo flag, VERSION
4013 @cindex Texinfo flag, UPDATED
4014 @cindex Texinfo flag, EDITION
4015 @cindex Texinfo flag, UPDATED-MONTH
4017 @cindex VERSION Texinfo flag
4018 @cindex UPDATED Texinfo flag
4019 @cindex EDITION Texinfo flag
4020 @cindex UPDATED-MONTH Texinfo flag
4022 @cindex mdate-sh
4024 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
4025 that file will be automatically generated.  The file @file{version.texi}
4026 defines four Texinfo flag you can reference using
4027 @code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
4028 @code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
4030 @table @code
4031 @item EDITION
4032 @itemx VERSION
4033 Both of these flags hold the version number of your program.  They are
4034 kept separate for clarity.
4036 @item UPDATED
4037 This holds the date the primary @file{.texi} file was last modified.
4039 @item UPDATED-MONTH
4040 This holds the name of the month in which the primary @file{.texi} file
4041 was last modified.
4042 @end table
4044 The @file{version.texi} support requires the @code{mdate-sh} program;
4045 this program is supplied with Automake and automatically included when
4046 @code{automake} is invoked with the @code{--add-missing} option.
4048 If you have multiple Texinfo files, and you want to use the
4049 @file{version.texi} feature, then you have to have a separate version
4050 file for each Texinfo file.  Automake will treat any include in a
4051 Texinfo file that matches @samp{vers*.texi} just as an automatically
4052 generated version file.
4054 When an info file is rebuilt, the program named by the @code{MAKEINFO}
4055 variable is used to invoke it.  If the @code{makeinfo} program is found
4056 on the system then it will be used by default; otherwise @code{missing}
4057 will be used instead.  The flags in the variables @code{MAKEINFOFLAGS}
4058 and @code{AM_MAKEINFOFLAGS} will be passed to the @code{makeinfo}
4059 invocation; the first of these is intended for use by the user
4060 (@pxref{User Variables}) and the second by the @file{Makefile.am}
4061 writer.
4062 @vindex MAKEINFO
4063 @vindex MAKEINFOFLAGS
4064 @vindex AM_MAKEINFOFLAGS
4066 Sometimes an info file actually depends on more than one @file{.texi}
4067 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
4068 @file{gpl.texi}.  You can tell Automake about these dependencies using
4069 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
4070 @vindex TEXINFOS
4071 @vindex _TEXINFOS
4073 @example
4074 info_TEXINFOS = hello.texi
4075 hello_TEXINFOS = gpl.texi
4076 @end example
4078 @cindex texinfo.tex
4080 By default, Automake requires the file @file{texinfo.tex} to appear in
4081 the same directory as the Texinfo source.  However, if you used
4082 @code{AC_CONFIG_AUX_DIR} in @file{configure.in} (@pxref{Input, , Finding
4083 `configure' Input, autoconf, The Autoconf Manual}), then
4084 @file{texinfo.tex} is looked for there.  Automake supplies
4085 @file{texinfo.tex} if @samp{--add-missing} is given.
4087 @vindex TEXINFO_TEX
4089 If your package has Texinfo files in many directories, you can use the
4090 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
4091 @file{texinfo.tex} for your package.  The value of this variable should
4092 be the relative path from the current @file{Makefile.am} to
4093 @file{texinfo.tex}:
4095 @example
4096 TEXINFO_TEX = ../doc/texinfo.tex
4097 @end example
4099 @opindex no-texinfo.tex
4101 The option @samp{no-texinfo.tex} can be used to eliminate the
4102 requirement for @file{texinfo.tex}.  Use of the variable
4103 @code{TEXINFO_TEX} is preferable, however, because that allows the
4104 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
4106 @cindex Target, install-info
4107 @cindex Target, noinstall-info
4108 @cindex install-info target
4109 @cindex noinstall-info target
4111 @opindex no-installinfo
4112 @trindex install-info
4114 Automake generates an @code{install-info} target; some people apparently
4115 use this.  By default, info pages are installed by @samp{make install}.
4116 This can be prevented via the @code{no-installinfo} option.
4119 @node Man pages,  , Texinfo, Documentation
4120 @section Man pages
4122 @cindex _MANS primary, defined
4123 @cindex MANS primary, defined
4124 @cindex Primary variable, MANS
4126 A package can also include man pages (but see the GNU standards on this
4127 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
4128 pages are declared using the @samp{MANS} primary.  Generally the
4129 @code{man_MANS} variable is used.  Man pages are automatically installed in
4130 the correct subdirectory of @code{mandir}, based on the file extension.
4131 @vindex MANS
4132 @vindex man_MANS
4134 File extensions such as @samp{.1c} are handled by looking for the valid
4135 part of the extension and using that to determine the correct
4136 subdirectory of @code{mandir}.  Valid section names are the digits
4137 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
4139 Sometimes developers prefer to name a man page something like
4140 @file{foo.man} in the source, and then rename it to have the correct
4141 suffix, e.g. @file{foo.1}, when installing the file.  Automake also
4142 supports this mode.  For a valid section named @var{SECTION}, there is a
4143 corresponding directory named @samp{man@var{SECTION}dir}, and a
4144 corresponding @samp{_MANS} variable.  Files listed in such a variable
4145 are installed in the indicated section.  If the file already has a
4146 valid suffix, then it is installed as-is; otherwise the file suffix is
4147 changed to match the section.
4149 For instance, consider this example:
4150 @example
4151 man1_MANS = rename.man thesame.1 alsothesame.1c
4152 @end example
4154 In this case, @file{rename.man} will be renamed to @file{rename.1} when
4155 installed, but the other files will keep their names.
4157 @cindex Target, install-man
4158 @cindex Target, noinstall-man
4159 @cindex install-man target
4160 @cindex noinstall-man target
4162 @c Use @samp{make install} per documentation: (texi)code.
4163 By default, man pages are installed by @samp{make install}.  However,
4164 since the GNU project does not require man pages, many maintainers do
4165 not expend effort to keep the man pages up to date.  In these cases, the
4166 @code{no-installman} option will prevent the man pages from being
4167 installed by default.  The user can still explicitly install them via
4168 @samp{make install-man}.
4169 @opindex no-installman
4170 @trindex install-man
4172 Here is how the man pages are handled in GNU @code{cpio} (which includes
4173 both Texinfo documentation and man pages):
4175 @example
4176 man_MANS = cpio.1 mt.1
4177 EXTRA_DIST = $(man_MANS)
4178 @end example
4180 Man pages are not currently considered to be source, because it is not
4181 uncommon for man pages to be automatically generated.  Therefore they
4182 are not automatically included in the distribution.  However, this can
4183 be changed by use of the @samp{dist_} prefix.
4185 The @samp{nobase_} prefix is meaningless for man pages and is
4186 disallowed.
4189 @node Install, Clean, Documentation, Top
4190 @chapter What Gets Installed
4192 @cindex Installation support
4193 @cindex make install support
4195 @section Basics of installation
4197 Naturally, Automake handles the details of actually installing your
4198 program once it has been built.  All files named by the various
4199 primaries are automatically installed in the appropriate places when the
4200 user runs @code{make install}.
4202 A file named in a primary is installed by copying the built file into
4203 the appropriate directory.  The base name of the file is used when
4204 installing.
4206 @example
4207 bin_PROGRAMS = hello subdir/goodbye
4208 @end example
4210 In this example, both @samp{hello} and @samp{goodbye} will be installed
4211 in @code{$(bindir)}.
4213 Sometimes it is useful to avoid the basename step at install time.  For
4214 instance, you might have a number of header files in subdirectories of
4215 the source tree which are laid out precisely how you want to install
4216 them.  In this situation you can use the @samp{nobase_} prefix to
4217 suppress the base name step.  For example:
4219 @example
4220 nobase_include_HEADERS = stdio.h sys/types.h
4221 @end example
4223 Will install @file{stdio.h} in @code{$(includedir)} and @file{types.h}
4224 in @code{$(includedir)/sys}.
4226 @section The two parts of install
4228 Automake generates separate @code{install-data} and @code{install-exec}
4229 targets, in case the installer is installing on multiple machines which
4230 share directory structure---these targets allow the machine-independent
4231 parts to be installed only once.  @code{install-exec} installs
4232 platform-dependent files, and @code{install-data} installs
4233 platform-independent files.  The @code{install} target depends on both
4234 of these targets.  While Automake tries to automatically segregate
4235 objects into the correct category, the @file{Makefile.am} author is, in
4236 the end, responsible for making sure this is done correctly.
4237 @trindex install-data
4238 @trindex install-exec
4239 @trindex install
4240 @cindex Install, two parts of
4242 Variables using the standard directory prefixes @samp{data},
4243 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
4244 @samp{pkgdata}, or @samp{pkginclude} (e.g. @samp{data_DATA}) are
4245 installed by @samp{install-data}.
4247 Variables using the standard directory prefixes @samp{bin}, @samp{sbin},
4248 @samp{libexec}, @samp{sysconf}, @samp{localstate}, @samp{lib}, or
4249 @samp{pkglib} (e.g. @samp{bin_PROGRAMS}) are installed by
4250 @samp{install-exec}.
4252 Any variable using a user-defined directory prefix with @samp{exec} in
4253 the name (e.g. @samp{myexecbin_PROGRAMS} is installed by
4254 @samp{install-exec}.  All other user-defined prefixes are installed by
4255 @samp{install-data}.
4257 @section Extending installation
4259 It is possible to extend this mechanism by defining an
4260 @code{install-exec-local} or @code{install-data-local} target.  If these
4261 targets exist, they will be run at @samp{make install} time.  These
4262 rules can do almost anything; care is required.
4263 @trindex install-exec-local
4264 @trindex install-data-local
4266 Automake also supports two install hooks, @code{install-exec-hook} and
4267 @code{install-data-hook}.  These hooks are run after all other install
4268 rules of the appropriate type, exec or data, have completed.  So, for
4269 instance, it is possible to perform post-installation modifications
4270 using an install hook.
4271 @cindex Install hook
4273 @section Staged installs
4275 @vindex DESTDIR
4276 Automake generates support for the @samp{DESTDIR} variable in all
4277 install rules.  @samp{DESTDIR} is used during the @samp{make install}
4278 step to relocate install objects into a staging area.  Each object and
4279 path is prefixed with the value of @samp{DESTDIR} before being copied
4280 into the install area.  Here is an example of typical DESTDIR usage:
4282 @example
4283 make DESTDIR=/tmp/staging install
4284 @end example
4286 This places install objects in a directory tree built under
4287 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
4288 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
4289 would install @file{/tmp/staging/gnu/bin/foo} and
4290 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
4292 This feature is commonly used to build install images and packages.  For
4293 more information, see @ref{Makefile Conventions, , , standards, The GNU
4294 Coding Standards}.
4296 Support for @samp{DESTDIR} is implemented by coding it directly into the
4297 install rules.  If your @file{Makefile.am} uses a local install rule
4298 (e.g., @code{install-exec-local}) or an install hook, then you must
4299 write that code to respect @samp{DESTDIR}.
4301 @section Rules for the user
4303 Automake also generates an @code{uninstall} target, an
4304 @code{installdirs} target, and an @code{install-strip} target.
4305 @trindex uninstall
4306 @trindex installdirs
4307 @trindex install-strip
4309 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
4310 There is no notion of separate uninstalls for ``exec'' and ``data'', as
4311 these features would not provide additional functionality.
4313 Note that @code{uninstall} is not meant as a replacement for a real
4314 packaging tool.
4317 @node Clean, Dist, Install, Top
4318 @chapter What Gets Cleaned
4320 @cindex make clean support
4322 The GNU Makefile Standards specify a number of different clean rules.
4323 See @xref{Standard Targets, , Standard Targets for Users, standards,
4324 The GNU Coding Standards}.
4326 Generally the files that can be cleaned are determined automatically by
4327 Automake.  Of course, Automake also recognizes some variables that can
4328 be defined to specify additional files to clean.  These variables are
4329 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
4330 @code{MAINTAINERCLEANFILES}.
4331 @vindex MOSTLYCLEANFILES
4332 @vindex CLEANFILES
4333 @vindex DISTCLEANFILES
4334 @vindex MAINTAINERCLEANFILES
4336 As the GNU Standards aren't always explicit as to which files should be
4337 removed by which target, we've adopted a heuristic which we believe was
4338 first formulated by Fran@,{c}ois Pinard:
4340 @itemize @bullet
4341 @item
4342 If @code{make} built it, and it is commonly something that one would
4343 want to rebuild (for instance, a @file{.o} file), then
4344 @code{mostlyclean} should delete it.
4346 @item
4347 Otherwise, if @code{make} built it, then @code{clean} should delete it.
4349 @item
4350 If @code{configure} built it, then @code{distclean} should delete it
4352 @item
4353 If the maintainer built it, then @code{maintainer-clean} should
4354 delete it.
4355 @end itemize
4357 We recommend that you follow this same set of heuristics in your
4358 @file{Makefile.am}.
4361 @node Dist, Tests, Clean, Top
4362 @chapter What Goes in a Distribution
4364 @section Basics of distribution
4366 @cindex make dist
4368 The @code{dist} target in the generated @file{Makefile.in} can be used
4369 to generate a gzip'd @code{tar} file and other flavors of archive for
4370 distribution.  The files is named based on the @samp{PACKAGE} and
4371 @samp{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
4372 (@pxref{Macros}); more precisely the gzip'd @code{tar} file is named
4373 @samp{@var{package}-@var{version}.tar.gz}.
4374 @cvindex PACKAGE
4375 @cvindex VERSION
4376 @trindex dist
4377 You can use the @code{make} variable @samp{GZIP_ENV} to control how gzip
4378 is run.  The default setting is @samp{--best}.
4380 For the most part, the files to distribute are automatically found by
4381 Automake: all source files are automatically included in a distribution,
4382 as are all @file{Makefile.am}s and @file{Makefile.in}s.  Automake also
4383 has a built-in list of commonly used files which are automatically
4384 included if they are found in the current directory (either physically,
4385 or as the target of a @file{Makefile.am} rule).  This list is printed by
4386 @samp{automake --help}.  Also, files which are read by @code{configure}
4387 (i.e. the source files corresponding to the files specified in various
4388 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
4389 automatically distributed.
4391 Still, sometimes there are files which must be distributed, but which
4392 are not covered in the automatic rules.  These files should be listed in
4393 the @code{EXTRA_DIST} variable.  You can mention files from
4394 subdirectories in @code{EXTRA_DIST}.
4396 You can also mention a directory in @code{EXTRA_DIST}; in this case the
4397 entire directory will be recursively copied into the distribution.
4398 Please note that this will also copy @emph{everything} in the directory,
4399 including CVS/RCS version control files.  We recommend against using
4400 this feature.
4401 @vindex EXTRA_DIST
4403 If you define @code{SUBDIRS}, Automake will recursively include the
4404 subdirectories in the distribution.  If @code{SUBDIRS} is defined
4405 conditionally (@pxref{Conditionals}), Automake will normally include all
4406 directories that could possibly appear in @code{SUBDIRS} in the
4407 distribution.  If you need to specify the set of directories
4408 conditionally, you can set the variable @code{DIST_SUBDIRS} to the exact
4409 list of subdirectories to include in the distribution (@pxref{Top level}).
4410 @vindex DIST_SUBDIRS
4412 @section Fine-grained distribution control
4414 Sometimes you need tighter control over what does @emph{not} go into the
4415 distribution; for instance you might have source files which are
4416 generated and which you do not want to distribute.  In this case
4417 Automake gives fine-grained control using the @samp{dist} and
4418 @samp{nodist} prefixes.  Any primary or @samp{_SOURCES} variable can be
4419 prefixed with @samp{dist_} to add the listed files to the distribution.
4420 Similarly, @samp{nodist_} can be used to omit the files from the
4421 distribution.
4422 @vindex dist_
4423 @vindex nodist_
4425 As an example, here is how you would cause some data to be distributed
4426 while leaving some source code out of the distribution:
4428 @example
4429 dist_data_DATA = distribute-this
4430 bin_PROGRAMS = foo
4431 nodist_foo_SOURCES = do-not-distribute.c
4432 @end example
4434 @section The dist hook
4436 @trindex dist-hook
4437 Occasionally it is useful to be able to change the distribution before
4438 it is packaged up.  If the @code{dist-hook} target exists, it is run
4439 after the distribution directory is filled, but before the actual tar
4440 (or shar) file is created.  One way to use this is for distributing
4441 files in subdirectories for which a new @file{Makefile.am} is overkill:
4443 @example
4444 dist-hook:
4445         mkdir $(distdir)/random
4446         cp -p $(srcdir)/random/a1 $(srcdir)/random/a2 $(distdir)/random
4447 @end example
4449 Another way to to use this is for removing unnecessary files that get
4450 recursively included by specifying a directory in EXTRA_DIST:
4452 @example
4453 EXTRA_DIST = doc
4455 dist-hook:
4456         rm -rf `find $(distdir)/doc -name CVS`
4457 @end example
4459 @section Checking the distribution
4461 @cindex make distcheck
4462 @cindex make distcleancheck
4463 @vindex distcleancheck_listfiles
4464 @cindex make distuninstallcheck
4465 @vindex distuninstallcheck_listfiles
4467 Automake also generates a @code{distcheck} target which can be of help
4468 to ensure that a given distribution will actually work.
4469 @code{distcheck} makes a distribution, then tries to do a @code{VPATH}
4470 build, run the testsuite, and finally make another tarfile to ensure the
4471 distribution is self-contained.
4472 @trindex distcheck
4474 Building the package involves running @code{./configure}.  If you need
4475 to supply additional flags to @code{configure}, define them in the
4476 @code{DISTCHECK_CONFIGURE_FLAGS} variable, either in your top-level
4477 @file{Makefile.am}, or on the command line when invoking @code{make}.
4478 @vindex DISTCHECK_CONFIGURE_FLAGS
4480 If the target @code{distcheck-hook} is defined in your
4481 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
4482 the new distribution has been unpacked, but before the unpacked copy is
4483 configured and built.  Your @code{distcheck-hook} can do almost
4484 anything, though as always caution is advised.  Generally this hook is
4485 used to check for potential distribution errors not caught by the
4486 standard mechanism.
4488 Speaking about potential distribution errors, @code{distcheck} will also
4489 ensure that the @code{distclean} target actually removes all built
4490 files.  This is done by running @code{make distcleancheck} at the end of
4491 the @code{VPATH} build.  By default, @code{distcleancheck} will run
4492 @code{distclean} and then make sure the build tree has been emptied by
4493 running @code{$(distcleancheck_listfiles)}.  Usually this check will
4494 find generated files that you forgot to add to the @code{DISTCLEANFILES}
4495 variable (@pxref{Clean}).
4496 @trindex distcleancheck
4498 The @code{distcleancheck} behaviour should be ok for most packages,
4499 otherwise you have the possibility to override the definitition of
4500 either the @code{distcleancheck} target, or the
4501 @code{$(distcleancheck_listfiles)} variable.  For instance to disable
4502 @code{distcleancheck} completely, add the following rule to your
4503 top-level @file{Makefile.am}:
4504 @vindex distcleancheck_listfiles
4506 @example
4507 distcleancheck:
4508         @@:
4509 @end example
4511 If you want @code{distcleancheck} to ignore built files which have not
4512 been cleaned because they are also part of the distribution, add the
4513 following definition instead:
4515 @example
4516 distcleancheck_listfiles = \
4517   find -type f -exec sh -c 'test -f $(srcdir)/@{@} || echo @{@}' ';'
4518 @end example
4520 The above definition is not the default because it's usually an error if
4521 your Makefiles cause some distributed files to be rebuilt when the user
4522 build the package.  (Think about the user missing the tool required to
4523 build the file; or if the required tool is built by your package,
4524 consider the cross-compilation case where it can't be run.)
4526 @code{distcheck} also checks that the @code{uninstall} target works
4527 properly, both for ordinary and @samp{DESTDIR} builds.  It does this
4528 by invoking @code{make uninstall}, and then it checks the install tree
4529 to see if any files are left over.  This check will make sure that you
4530 correctly coded your @code{uninstall}-related targets.
4532 By default, the checking is done by the @code{distuninstallcheck} target,
4533 and the list of files in the install tree is generated by
4534 @code{$(distuninstallcheck_listfiles}) (this is a variable whose value is
4535 a shell command to run that prints the list of files to stdout).
4537 Either of these can be overridden to modify the behavior of
4538 @code{distcheck}.  For instance, to disable this check completely, you
4539 would write:
4541 @example
4542 distuninstallcheck:
4543         @@:
4544 @end example
4546 @section The types of distributions
4548 @trindex dist-gzip
4549 Automake generates a @samp{.tar.gz} file when asked to create a
4550 distribution and other archives formats, @ref{Options}.  The target
4551 @code{dist-gzip} generates the @samp{.tar.gz} file only.
4554 @node Tests, Options, Dist, Top
4555 @chapter Support for test suites
4557 @cindex Test suites
4558 @cindex make check
4560 Automake supports two forms of test suites.
4562 @section Simple Tests
4564 If the variable @code{TESTS} is defined, its value is taken to be a list
4565 of programs to run in order to do the testing.  The programs can either
4566 be derived objects or source objects; the generated rule will look both
4567 in @code{srcdir} and @file{.}.  Programs needing data files should look
4568 for them in @code{srcdir} (which is both an environment variable and a
4569 make variable) so they work when building in a separate directory
4570 (@pxref{Build Directories, , Build Directories , autoconf, The Autoconf
4571 Manual}), and in particular for the @code{distcheck} target
4572 (@pxref{Dist}).
4574 @cindex Exit status 77, special interpretation
4576 The number of failures will be printed at the end of the run.  If a
4577 given test program exits with a status of 77, then its result is ignored
4578 in the final count.  This feature allows non-portable tests to be
4579 ignored in environments where they don't make sense.
4581 The variable @code{TESTS_ENVIRONMENT} can be used to set environment
4582 variables for the test run; the environment variable @code{srcdir} is
4583 set in the rule.  If all your test programs are scripts, you can also
4584 set @code{TESTS_ENVIRONMENT} to an invocation of the shell (e.g.
4585 @samp{$(SHELL) -x}); this can be useful for debugging the tests.
4586 @vindex TESTS
4587 @vindex TESTS_ENVIRONMENT
4589 @cindex Tests, expected failure
4590 @cindex Expected test failure
4592 You may define the variable @code{XFAIL_TESTS} to a list of tests
4593 (usually a subset of @code{TESTS}) that are expected to fail.  This will
4594 reverse the result of those tests.
4595 @vindex XFAIL_TESTS
4597 Automake ensures that each program listed in @code{TESTS} is built
4598 before any tests are run; you can list both source and derived programs
4599 in @code{TESTS}.  For instance, you might want to run a C program as a
4600 test.  To do this you would list its name in @code{TESTS} and also in
4601 @code{check_PROGRAMS}, and then specify it as you would any other
4602 program.
4604 @section DejaGNU Tests
4606 If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @samp{dejagnu}} appears in
4607 @code{AUTOMAKE_OPTIONS}, then a @code{dejagnu}-based test suite is
4608 assumed.  The variable @code{DEJATOOL} is a list of names which are
4609 passed, one at a time, as the @code{--tool} argument to @code{runtest}
4610 invocations; it defaults to the name of the package.
4612 The variable @code{RUNTESTDEFAULTFLAGS} holds the @code{--tool} and
4613 @code{--srcdir} flags that are passed to dejagnu by default; this can be
4614 overridden if necessary.
4615 @vindex RUNTESTDEFAULTFLAGS
4617 The variables @code{EXPECT} and @code{RUNTEST} can
4618 also be overridden to provide project-specific values.  For instance,
4619 you will need to do this if you are testing a compiler toolchain,
4620 because the default values do not take into account host and target
4621 names.
4622 @opindex dejagnu
4623 @vindex DEJATOOL
4624 @vindex EXPECT
4625 @vindex RUNTEST
4627 The contents of the variable @code{RUNTESTFLAGS} are passed to the
4628 @code{runtest} invocation.  This is considered a ``user variable''
4629 (@pxref{User Variables}).  If you need to set @code{runtest} flags in
4630 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
4631 @vindex RUNTESTFLAGS
4632 @vindex AM_RUNTESTFLAGS
4634 @cindex @file{site.exp}
4635 Automake will generate rules to create a local @file{site.exp} file,
4636 defining various variables detected by @code{./configure}.  This file
4637 is automatically read by DejaGnu.  It is ok for the user of a package
4638 to edit this file in order to tune the test suite.  However this is
4639 not the place where the test suite author should define new variables:
4640 this should be done elsewhere in the real test suite code.
4641 Especially, @file{site.exp} should not be distributed.
4643 For more information regarding DejaGnu test suites, see @xref{Top, , ,
4644 dejagnu, The DejaGnu Manual}.
4646 In either case, the testing is done via @samp{make check}.
4648 @section Install Tests
4650 The @code{installcheck} target is available to the user as a way to run
4651 any tests after the package has been installed.  You can add tests to
4652 this by writing an @code{installcheck-local} target.
4655 @node Options, Miscellaneous, Tests, Top
4656 @chapter Changing Automake's Behavior
4658 Various features of Automake can be controlled by options in the
4659 @file{Makefile.am}.  Such options are applied on a per-@file{Makefile}
4660 basis when listed in a special @file{Makefile} variable named
4661 @code{AUTOMAKE_OPTIONS}.  They are applied globally to all processed
4662 @file{Makefiles} when listed in the first argument of
4663 @code{AM_INIT_AUTOMAKE} in @file{configure.in}.  Currently understood
4664 options are:
4665 @vindex AUTOMAKE_OPTIONS
4667 @table @asis
4668 @item @code{gnits}
4669 @itemx @code{gnu}
4670 @itemx @code{foreign}
4671 @itemx @code{cygnus}
4672 @cindex Option, gnits
4673 @cindex Option, gnu
4674 @cindex Option, foreign
4675 @cindex Option, cygnus
4677 Set the strictness as appropriate.  The @code{gnits} option also implies
4678 @code{readme-alpha} and @code{check-news}.
4680 @item @code{ansi2knr}
4681 @itemx @code{@var{path}/ansi2knr}
4682 @cindex Option, ansi2knr
4683 Turn on automatic de-ANSI-fication.  @xref{ANSI}.  If preceded by a
4684 path, the generated @file{Makefile.in} will look in the specified
4685 directory to find the @file{ansi2knr} program.  The path should be a
4686 relative path to another directory in the same distribution (Automake
4687 currently does not check this).
4689 @item @code{check-news}
4690 @cindex Option, check-news
4691 Cause @code{make dist} to fail unless the current version number appears
4692 in the first few lines of the @file{NEWS} file.
4694 @item @code{dejagnu}
4695 @cindex Option, dejagnu
4696 Cause @code{dejagnu}-specific rules to be generated.  @xref{Tests}.
4698 @item @code{dist-bzip2}
4699 @cindex Option, dist-bzip2
4700 Generate a @code{dist-bzip2} target, creating a bzip2 tar archive of the
4701 distribution.  @code{dist} will create it in addition to the other
4702 formats.  bzip2 archives are frequently smaller than gzipped archives.
4703 @trindex dist-bzip2
4705 @item @code{dist-shar}
4706 @cindex Option, dist-shar
4707 Generate a @code{dist-shar} target, creating a shar archive of the
4708 distribution.  @code{dist} will create it in addition to the other
4709 formats.
4710 @trindex dist-shar
4712 @item @code{dist-zip}
4713 @cindex Option, dist-zip
4714 Generate a @code{dist-zip} target, creating a zip archive of the
4715 distribution.  @code{dist} will create it in addition to the other
4716 formats.
4717 @trindex dist-zip
4719 @item @code{dist-tarZ}
4720 @cindex Option, dist-tarZ
4721 Generate a @code{dist-tarZ} target, creating a compressed tar archive of
4722 the distribution.  @code{dist} will create it in addition to the other
4723 formats.
4724 @trindex dist-tarZ
4726 @item @code{no-define}
4727 @cindex Option, no-define
4728 This options is meaningful only when passed as an argument to
4729 @code{AM_INIT_AUTOMAKE}.  It will prevent the @code{PACKAGE} and
4730 @code{VERSION} variables to be @code{AC_DEFINE}d.
4732 @item @code{no-dependencies}
4733 @cindex Option, no-dependencies
4734 This is similar to using @samp{--include-deps} on the command line, but
4735 is useful for those situations where you don't have the necessary bits
4736 to make automatic dependency tracking work @xref{Dependencies}.  In this
4737 case the effect is to effectively disable automatic dependency tracking.
4739 @item @code{no-exeext}
4740 @cindex Option, no-exeext
4741 If your @file{Makefile.am} defines a target @samp{foo}, it will override
4742 a target named @samp{foo$(EXEEXT)}.  This is necessary when
4743 @code{EXEEXT} is found to be empty.  However, by default automake will
4744 generate an error for this use.  The @code{no-exeext} option will
4745 disable this error.  This is intended for use only where it is known in
4746 advance that the package will not be ported to Windows, or any other
4747 operating system using extensions on executables.
4749 @item @code{no-installinfo}
4750 @cindex Option, no-installinfo
4751 The generated @file{Makefile.in} will not cause info pages to be built
4752 or installed by default.  However, @code{info} and @code{install-info}
4753 targets will still be available.  This option is disallowed at
4754 @samp{GNU} strictness and above.
4755 @trindex info
4756 @trindex install-info
4758 @item @code{no-installman}
4759 @cindex Option, no-installman
4760 The generated @file{Makefile.in} will not cause man pages to be
4761 installed by default.  However, an @code{install-man} target will still
4762 be available for optional installation.  This option is disallowed at
4763 @samp{GNU} strictness and above.
4764 @trindex install-man
4766 @item @code{nostdinc}
4767 @cindex Option, nostdinc
4768 This option can be used to disable the standard @samp{-I} options which
4769 are ordinarily automatically provided by Automake.
4771 @item @code{no-texinfo.tex}
4772 @cindex Option, no-texinfo
4773 Don't require @file{texinfo.tex}, even if there are texinfo files in
4774 this directory.
4776 @item @code{readme-alpha}
4777 @cindex Option, readme-alpha
4778 If this release is an alpha release, and the file @file{README-alpha}
4779 exists, then it will be added to the distribution.  If this option is
4780 given, version numbers are expected to follow one of two forms.  The
4781 first form is @samp{@var{MAJOR}.@var{MINOR}.@var{ALPHA}}, where each
4782 element is a number; the final period and number should be left off for
4783 non-alpha releases.  The second form is
4784 @samp{@var{MAJOR}.@var{MINOR}@var{ALPHA}}, where @var{ALPHA} is a
4785 letter; it should be omitted for non-alpha releases.
4787 @item @code{std-options}
4788 @cindex Options, std-options
4789 @cindex make installcheck
4790 Make the @code{installcheck} target check that installed scripts and
4791 programs support the @code{--help} and @code{--version} options.
4792 This also provides a basic check that the program's
4793 run-time dependencies are satisfied after installation.
4795 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
4796 In a few situations, programs (or scripts) have to be exempted from this
4797 test.  For instance @command{false} (from GNU sh-utils) is never
4798 successful, even for @code{--help} or @code{--version}.  You can list
4799 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
4800 Programs (not scripts) listed in this variable should be suffixed by
4801 @code{$(EXEEXT)} for the sake of Win32 or OS/2.  For instance suppose we
4802 build @code{false} as a program but @code{true.sh} as a script, and that
4803 neither of them support @code{--help} or @code{--version}:
4805 @example
4806 AUTOMAKE_OPTIONS = std-options
4807 bin_PROGRAMS = false ...
4808 bin_SCRIPTS = true.sh ...
4809 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
4810 @end example
4812 @item @code{subdir-objects}
4813 If this option is specified, then objects are placed into the
4814 subdirectory of the build directory corresponding to the subdirectory of
4815 the source file.  For instance if the source file is
4816 @file{subdir/file.cxx}, then the output file would be
4817 @file{subdir/file.o}.
4819 @item @var{version}
4820 @cindex Option, version
4821 A version number (e.g. @samp{0.30}) can be specified.  If Automake is not
4822 newer than the version specified, creation of the @file{Makefile.in}
4823 will be suppressed.
4825 @item @code{-W@var{category}} or @code{--warnings=@var{category}}
4826 @cindex Option, warnings
4827 These options behave exactly like their command-line counterpart
4828 (@pxref{Invoking Automake}).  This allows you to enable or disable some
4829 warning categories on a per-file basis.  You can also setup some warnings
4830 for your entire project; for instance try @code{AM_INIT_AUTOMAKE([-Wall])}
4831 in your @file{configure.in}.
4833 @end table
4835 Unrecognized options are diagnosed by @code{automake}.
4837 If you want an option to apply to all the files in the tree, you can use
4838 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.in}.
4839 @xref{Macros}.
4842 @node Miscellaneous, Include, Options, Top
4843 @chapter Miscellaneous Rules
4845 There are a few rules and variables that didn't fit anywhere else.
4847 @menu
4848 * Tags::                        Interfacing to etags and mkid
4849 * Suffixes::                    Handling new file extensions
4850 * Multilibs::                   Support for multilibbing.
4851 @end menu
4854 @node Tags, Suffixes, Miscellaneous, Miscellaneous
4855 @section Interfacing to @code{etags}
4857 @cindex TAGS support
4859 Automake will generate rules to generate @file{TAGS} files for use with
4860 GNU Emacs under some circumstances.
4862 If any C, C++ or Fortran 77 source code or headers are present, then
4863 @code{tags} and @code{TAGS} targets will be generated for the directory.
4864 @trindex tags
4866 At the topmost directory of a multi-directory package, a @code{tags}
4867 target file will be generated which, when run, will generate a
4868 @file{TAGS} file that includes by reference all @file{TAGS} files from
4869 subdirectories.
4871 The @code{tags} target will also be generated if the variable
4872 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
4873 directories which contain taggable source that @code{etags} does not
4874 understand.  The user can use the @code{ETAGSFLAGS} to pass additional
4875 flags to @code{etags}; @code{AM_ETAGSFLAGS} is also available for use in
4876 @file{Makefile.am}.
4877 @vindex ETAGS_ARGS
4878 @vindex ETAGSFLAGS
4879 @vindex AM_ETAGSFLAGS
4881 Here is how Automake generates tags for its source, and for nodes in its
4882 Texinfo file:
4884 @example
4885 ETAGS_ARGS = automake.in --lang=none \
4886  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
4887 @end example
4889 If you add filenames to @samp{ETAGS_ARGS}, you will probably also
4890 want to set @samp{TAGS_DEPENDENCIES}.  The contents of this variable
4891 are added directly to the dependencies for the @code{tags} target.
4892 @vindex TAGS_DEPENDENCIES
4894 Automake also generates a @code{ctags} target which can be used to
4895 build @command{vi}-style @file{tags} files.  The variable @code{CTAGS}
4896 is the name of the program to invoke (by default @samp{ctags});
4897 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
4898 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
4900 Automake will also generate an @code{ID} target which will run
4901 @code{mkid} on the source.  This is only supported on a
4902 directory-by-directory basis.
4903 @trindex id
4905 Automake also supports the @uref{http://www.gnu.org/software/global/,
4906 GNU Global Tags program}.  The @code{GTAGS} target runs Global Tags
4907 automatically and puts the result in the top build directory.  The
4908 variable @code{GTAGS_ARGS} holds arguments which are passed to
4909 @code{gtags}.
4910 @vindex GTAGS_ARGS
4913 @node Suffixes, Multilibs, Tags, Miscellaneous
4914 @section Handling new file extensions
4916 @cindex Adding new SUFFIXES
4917 @cindex SUFFIXES, adding
4918 @vindex SUFFIXES
4920 It is sometimes useful to introduce a new implicit rule to handle a file
4921 type that Automake does not know about.
4923 For instance, suppose you had a compiler which could compile @samp{.foo}
4924 files to @samp{.o} files.  You would simply define an suffix rule for
4925 your language:
4927 @example
4928 .foo.o:
4929         foocc -c -o $@@ $<
4930 @end example
4932 Then you could directly use a @samp{.foo} file in a @samp{_SOURCES}
4933 variable and expect the correct results:
4935 @example
4936 bin_PROGRAMS = doit
4937 doit_SOURCES = doit.foo
4938 @end example
4940 This was the simpler and more common case.  In other cases, you will
4941 have to help Automake to figure which extensions you are defining your
4942 suffix rule for.  This usually happens when your extensions does not
4943 start with a dot.  Then, all you have to do is to put a list of new
4944 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
4945 implicit rule.
4947 For instance the following definition prevents Automake to misinterpret
4948 @samp{.idlC.cpp:} as an attempt to transform @samp{.idlC} into
4949 @samp{.cpp}.
4951 @example
4952 SUFFIXES = .idl C.cpp
4953 .idlC.cpp:
4954         # whatever
4955 @end example
4957 As you may have noted, the @code{SUFFIXES} variable behaves like the
4958 @code{.SUFFIXES} special target of @code{make}.  You should not touch
4959 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
4960 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
4961 @code{SUFFIXES} go at the start of the generated suffixes list, followed
4962 by Automake generated suffixes not already in the list.
4964 @node Multilibs,  , Suffixes, Miscellaneous
4965 @section Support for Multilibs
4967 Automake has support for an obscure feature called multilibs.  A
4968 @dfn{multilib} is a library which is built for multiple different ABIs
4969 at a single time; each time the library is built with a different target
4970 flag combination.  This is only useful when the library is intended to
4971 be cross-compiled, and it is almost exclusively used for compiler
4972 support libraries.
4974 The multilib support is still experimental.  Only use it if you are
4975 familiar with multilibs and can debug problems you might encounter.
4978 @node Include, Conditionals, Miscellaneous, Top
4979 @chapter Include
4981 @cmindex include
4982 @cindex Including Makefile fragment
4983 @cindex Makefile fragment, including
4985 Automake supports an @code{include} directive which can be used to
4986 include other @file{Makefile} fragments when @code{automake} is run.
4987 Note that these fragments are read and interpreted by @code{automake},
4988 not by @code{make}.  As with conditionals, @code{make} has no idea that
4989 @code{include} is in use.
4991 There are two forms of @code{include}:
4993 @table @code
4994 @item include $(srcdir)/file
4995 Include a fragment which is found relative to the current source
4996 directory.
4998 @item include $(top_srcdir)/file
4999 Include a fragment which is found relative to the top source directory.
5000 @end table
5002 Note that if a fragment is included inside a conditional, then the
5003 condition applies to the entire contents of that fragment.
5005 Makefile fragments included this way are always distributed because
5006 there are needed to rebuild @file{Makefile.in}.
5008 @node Conditionals, Gnits, Include, Top
5009 @chapter Conditionals
5011 @cindex Conditionals
5013 Automake supports a simple type of conditionals.
5015 @cvindex AM_CONDITIONAL
5016 Before using a conditional, you must define it by using
5017 @code{AM_CONDITIONAL} in the @code{configure.in} file (@pxref{Macros}).
5019 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
5020 The conditional name, @var{conditional}, should be a simple string
5021 starting with a letter and containing only letters, digits, and
5022 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
5023 which are reserved by Automake.
5025 The shell @var{condition} (suitable for use in a shell @code{if}
5026 statement) is evaluated when @code{configure} is run.  Note that you
5027 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
5028 time @code{configure} is run -- if @code{AM_CONDITIONAL} is run
5029 conditionally (e.g., in a shell @code{if} statement), then the result
5030 will confuse automake.
5031 @end defmac
5033 @cindex --enable-debug, example
5034 @cindex Example conditional --enable-debug
5035 @cindex Conditional example,  --enable-debug
5037 Conditionals typically depend upon options which the user provides to
5038 the @code{configure} script.  Here is an example of how to write a
5039 conditional which is true if the user uses the @samp{--enable-debug}
5040 option.
5042 @example
5043 AC_ARG_ENABLE(debug,
5044 [  --enable-debug    Turn on debugging],
5045 [case "$@{enableval@}" in
5046   yes) debug=true ;;
5047   no)  debug=false ;;
5048   *) AC_MSG_ERROR(bad value $@{enableval@} for --enable-debug) ;;
5049 esac],[debug=false])
5050 AM_CONDITIONAL(DEBUG, test x$debug = xtrue)
5051 @end example
5053 Here is an example of how to use that conditional in @file{Makefile.am}:
5055 @cmindex if
5056 @cmindex endif
5057 @cmindex else
5059 @example
5060 if DEBUG
5061 DBG = debug
5062 else
5063 DBG =
5064 endif
5065 noinst_PROGRAMS = $(DBG)
5066 @end example
5068 This trivial example could also be handled using EXTRA_PROGRAMS
5069 (@pxref{Conditional Programs}).
5071 You may only test a single variable in an @code{if} statement, possibly
5072 negated using @samp{!}.  The @code{else} statement may be omitted.
5073 Conditionals may be nested to any depth.  You may specify an argument to
5074 @code{else} in which case it must be the negation of the condition used
5075 for the current @code{if}.  Similarly you may specify the condition
5076 which is closed by an @code{end}:
5078 @example
5079 if DEBUG
5080 DBG = debug
5081 else !DEBUG
5082 DBG =
5083 endif !DEBUG
5084 @end example
5086 @noindent
5087 Unbalanced conditions are errors.
5089 Note that conditionals in Automake are not the same as conditionals in
5090 GNU Make.  Automake conditionals are checked at configure time by the
5091 @file{configure} script, and affect the translation from
5092 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
5093 to @file{configure} and on results that @file{configure} has discovered
5094 about the host system.  GNU Make conditionals are checked at @code{make}
5095 time, and are based on variables passed to the make program or defined
5096 in the @file{Makefile}.
5098 Automake conditionals will work with any make program.
5101 @node Gnits, Cygnus, Conditionals, Top
5102 @chapter The effect of @code{--gnu} and @code{--gnits}
5104 @cindex --gnu, required files
5105 @cindex --gnu, complete description
5107 The @samp{--gnu} option (or @samp{gnu} in the @samp{AUTOMAKE_OPTIONS}
5108 variable) causes @code{automake} to check the following:
5110 @itemize @bullet
5111 @item
5112 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
5113 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
5114 or @file{COPYING}, are required at the topmost directory of the package.
5116 @item
5117 The options @samp{no-installman} and @samp{no-installinfo} are
5118 prohibited.
5119 @end itemize
5121 Note that this option will be extended in the future to do even more
5122 checking; it is advisable to be familiar with the precise requirements
5123 of the GNU standards.  Also, @samp{--gnu} can require certain
5124 non-standard GNU programs to exist for use by various maintainer-only
5125 targets; for instance in the future @code{pathchk} might be required for
5126 @samp{make dist}.
5128 @cindex --gnits, complete description
5130 The @samp{--gnits} option does everything that @samp{--gnu} does, and
5131 checks the following as well:
5133 @itemize @bullet
5134 @item
5135 @samp{make installcheck} will check to make sure that the @code{--help}
5136 and @code{--version} really print a usage message and a version string,
5137 respectively.  This is the @code{std-options} option (@pxref{Options}).
5139 @item
5140 @samp{make dist} will check to make sure the @file{NEWS} file has been
5141 updated to the current version.
5143 @item
5144 @samp{VERSION} is checked to make sure its format complies with Gnits
5145 standards.
5146 @c FIXME xref when standards are finished
5148 @item
5149 @cindex README-alpha
5150 If @samp{VERSION} indicates that this is an alpha release, and the file
5151 @file{README-alpha} appears in the topmost directory of a package, then
5152 it is included in the distribution.  This is done in @samp{--gnits}
5153 mode, and no other, because this mode is the only one where version
5154 number formats are constrained, and hence the only mode where Automake
5155 can automatically determine whether @file{README-alpha} should be
5156 included.
5158 @item
5159 The file @file{THANKS} is required.
5160 @end itemize
5163 @node Cygnus, Extending, Gnits, Top
5164 @chapter The effect of @code{--cygnus}
5166 @cindex Cygnus strictness
5168 Some packages, notably GNU GCC and GNU gdb, have a build environment
5169 originally written at Cygnus Support (subsequently renamed Cygnus
5170 Solutions, and then later purchased by Red Hat).  Packages with this
5171 ancestry are sometimes referred to as ``Cygnus'' trees.
5173 A Cygnus tree has slightly different rules for how a @file{Makefile.in}
5174 is to be constructed.  Passing @samp{--cygnus} to @code{automake} will
5175 cause any generated @file{Makefile.in} to comply with Cygnus rules.
5177 Here are the precise effects of @samp{--cygnus}:
5179 @itemize @bullet
5180 @item
5181 Info files are always created in the build directory, and not in the
5182 source directory.
5184 @item
5185 @file{texinfo.tex} is not required if a Texinfo source file is
5186 specified.  The assumption is that the file will be supplied, but in a
5187 place that Automake cannot find.  This assumption is an artifact of how
5188 Cygnus packages are typically bundled.
5190 @item
5191 @samp{make dist} is not supported, and the rules for it are not
5192 generated.  Cygnus-style trees use their own distribution mechanism.
5194 @item
5195 Certain tools will be searched for in the build tree as well as in the
5196 user's @samp{PATH}.  These tools are @code{runtest}, @code{expect},
5197 @code{makeinfo} and @code{texi2dvi}.
5199 @item
5200 @code{--foreign} is implied.
5202 @item
5203 The options @samp{no-installinfo} and @samp{no-dependencies} are
5204 implied.
5206 @item
5207 The macros @samp{AM_MAINTAINER_MODE} and @samp{AM_CYGWIN32} are
5208 required.
5210 @item
5211 The @code{check} target doesn't depend on @code{all}.
5212 @end itemize
5214 GNU maintainers are advised to use @samp{gnu} strictness in preference
5215 to the special Cygnus mode.  Some day, perhaps, the differences between
5216 Cygnus trees and GNU trees will disappear (for instance, as GCC is made
5217 more standards compliant).  At that time the special Cygnus mode will be
5218 removed.
5221 @node Extending, Distributing, Cygnus, Top
5222 @chapter When Automake Isn't Enough
5224 Automake's implicit copying semantics means that many problems can be
5225 worked around by simply adding some @code{make} targets and rules to
5226 @file{Makefile.in}.  Automake will ignore these additions.
5228 @cindex -local targets
5229 @cindex local targets
5231 There are some caveats to doing this.  Although you can overload a
5232 target already used by Automake, it is often inadvisable, particularly
5233 in the topmost directory of a package with subdirectories.  However,
5234 various useful targets have a @samp{-local} version you can specify in
5235 your @file{Makefile.in}.  Automake will supplement the standard target
5236 with these user-supplied targets.
5238 @trindex  all
5239 @trindex  all-local
5240 @trindex  info
5241 @trindex  info-local
5242 @trindex  dvi
5243 @trindex  dvi-local
5244 @trindex  ps
5245 @trindex  ps-local
5246 @trindex  pdf
5247 @trindex  pdf-local
5248 @trindex  check
5249 @trindex  check-local
5250 @trindex  install
5251 @trindex  install-data-local
5252 @trindex  install-exec
5253 @trindex  install-exec-local
5254 @trindex  uninstall
5255 @trindex  uninstall-local
5256 @trindex  mostlyclean
5257 @trindex  mostlyclean-local
5258 @trindex  clean
5259 @trindex  clean-local
5260 @trindex  distclean
5261 @trindex  distclean-local
5262 @trindex  installdirs
5263 @trindex  installdirs-local
5264 @trindex  installcheck
5265 @trindex  installcheck-local
5267 The targets that support a local version are @code{all}, @code{info},
5268 @code{dvi}, @code{ps}, @code{pdf}, @code{check}, @code{install-data},
5269 @code{install-exec}, @code{uninstall}, @code{installdirs},
5270 @code{installcheck} and the various @code{clean} targets
5271 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
5272 @code{maintainer-clean}).  Note that there are no
5273 @code{uninstall-exec-local} or @code{uninstall-data-local} targets; just
5274 use @code{uninstall-local}.  It doesn't make sense to uninstall just
5275 data or just executables.
5277 For instance, here is one way to install a file in @file{/etc}:
5279 @example
5280 install-data-local:
5281         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
5282 @end example
5284 @cindex -hook targets
5285 @cindex hook targets
5287 Some targets also have a way to run another target, called a @dfn{hook},
5288 after their work is done.  The hook is named after the principal target,
5289 with @samp{-hook} appended.  The targets allowing hooks are
5290 @code{install-data}, @code{install-exec}, @code{uninstall}, @code{dist},
5291 and @code{distcheck}.
5292 @trindex install-data-hook
5293 @trindex install-exec-hook
5294 @trindex uninstall-hook
5295 @trindex dist-hook
5297 For instance, here is how to create a hard link to an installed program:
5299 @example
5300 install-exec-hook:
5301         ln $(DESTDIR)$(bindir)/program $(DESTDIR)$(bindir)/proglink
5302 @end example
5304 @c FIXME should include discussion of variables you can use in these
5305 @c rules
5307 @node Distributing, API versioning, Extending, Top
5308 @chapter Distributing @file{Makefile.in}s
5310 Automake places no restrictions on the distribution of the resulting
5311 @file{Makefile.in}s.  We still encourage software authors to distribute
5312 their work under terms like those of the GPL, but doing so is not
5313 required to use Automake.
5315 Some of the files that can be automatically installed via the
5316 @code{--add-missing} switch do fall under the GPL@.  However, these also
5317 have a special exception allowing you to distribute them with your
5318 package, regardless of the licensing you choose.
5321 @node API versioning, Macro and Variable Index, Distributing, Top
5322 @chapter Automake API versioning
5324 New Automake releases usually include bug fixes and new features.
5325 Unfortunately they may also introduce new bugs and incompatibilities.
5326 This makes four reasons why a package may require a particular Automake
5327 version.
5329 Things get worse when maintaining a large tree of packages, each one
5330 requiring a different version of Automake.  In the past, this meant that
5331 any developer (and sometime users) had to install several versions of
5332 Automake in different places, and switch @samp{$PATH} appropriately for
5333 each package.
5335 Starting with version 1.6, Automake installs versioned binaries.  This
5336 means you can install several versions of Automake in the same
5337 @samp{$prefix}, and can select an arbitrary Automake version by running
5338 @samp{automake-1.6} or @samp{automake-1.7} without juggling with
5339 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
5340 will use @samp{automake-1.6} explicitly in their rebuild rules.
5342 Note that @samp{1.6} in @samp{automake-1.6} is Automake's API version,
5343 not Automake's version.  If a bug fix release is made, for instance
5344 Automake 1.6.1, the API version will remain 1.6.  This means that a
5345 package which work with Automake 1.6 should also work with 1.6.1; after
5346 all, this is what people expect from bug fix releases.
5348 Note that if your package relies on a feature or a bug fix introduced in
5349 a release, you can pass this version as an option to Automake to ensure
5350 older releases will not be used.  For instance, use this in your
5351 @file{configure.in}:
5353 @example
5354   AM_INIT_AUTOMAKE(1.6.1)    dnl Require Automake 1.6.1 or better.
5355 @end example
5356 @noindent
5357 or, in a particular @file{Makefile.am}:
5359 @example
5360   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
5361 @end example
5362 @noindent
5363 Automake will print an error message if its version is
5364 older than the requested version.
5367 @heading What is in the API
5369 Automake's programming interface is not easy to define.  Basically it
5370 should include at least all @strong{documented} variables and targets
5371 that a @samp{Makefile.am} author can use, any behavior associated with
5372 them (e.g. the places where @samp{-hook}'s are run), the command line
5373 interface of @samp{automake} and @samp{aclocal}, @dots{}
5375 @heading What is not in the API
5377 Every undocumented variable, target, or command line option, is not part
5378 of the API@.  You should avoid using them, as they could change from one
5379 version to the other (even in bug fix releases, if this helps to fix a
5380 bug).
5382 If it turns out you need to use such a undocumented feature, contact
5383 @email{automake@@gnu.org} and try to get it documented and exercised by
5384 the test-suite.
5386 @page
5387 @node Macro and Variable Index, General Index, API versioning, Top
5388 @unnumbered Macro and Variable Index
5390 @printindex vr
5393 @page
5394 @node General Index,  , Macro and Variable Index, Top
5395 @unnumbered General Index
5397 @printindex cp
5400 @page
5401 @contents
5402 @bye