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