* automake.texi (Canonicalization): The sources for libmumble++.a
[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 GNU programming tools
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
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 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 * Macro and Variable Index::
138 * General Index::
139 @end menu
140
141 @end ifnottex
142
143
144 @node Introduction, Generalities, Top, Top
145 @chapter Introduction
146
147 Automake is a tool for automatically generating @file{Makefile.in}s from
148 files called @file{Makefile.am}.  Each @file{Makefile.am} is basically a
149 series of @code{make} macro definitions (with rules being thrown in
150 occasionally).  The generated @file{Makefile.in}s are compliant with the
151 GNU Makefile standards.
152
153 @cindex GNU Makefile standards
154
155 The GNU Makefile Standards Document
156 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
157 is long, complicated, and subject to change.  The goal of Automake is to
158 remove the burden of Makefile maintenance from the back of the
159 individual GNU maintainer (and put it on the back of the Automake
160 maintainer).
161
162 The typical Automake input file is simply a series of macro definitions.
163 Each such file is processed to create a @file{Makefile.in}.  There
164 should generally be one @file{Makefile.am} per directory of a project.
165
166 @cindex Constraints of Automake
167 @cindex Automake constraints
168
169 Automake does constrain a project in certain ways; for instance it
170 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
171 autoconf, The Autoconf Manual}), and enforces certain restrictions on
172 the @file{configure.in} contents@footnote{Autoconf 2.50 promotes
173 @file{configure.ac} over @file{configure.in}.  The rest of this
174 documentation will refer to @file{configure.in} as this use is not yet
175 spread, but Automake supports @file{configure.ac} too.}.
176
177 @cindex Automake requirements
178 @cindex Requirements, Automake
179
180 Automake requires @code{perl} in order to generate the
181 @file{Makefile.in}s.  However, the distributions created by Automake are
182 fully GNU standards-compliant, and do not require @code{perl} in order
183 to be built.
184
185 @cindex BUGS, reporting
186 @cindex Reporting BUGS
187 @cindex E-mail, bug reports
188
189 Mail suggestions and bug reports for Automake to
190 @email{bug-automake@@gnu.org}.
191
192
193 @node Generalities, Examples, Introduction, Top
194 @chapter General ideas
195
196 The following sections cover a few basic ideas that will help you
197 understand how Automake works.
198
199 @menu
200 * General Operation::           General operation of Automake
201 * Strictness::                  Standards conformance checking
202 * Uniform::                     The Uniform Naming Scheme
203 * Canonicalization::            How derived variables are named
204 * User Variables::              Variables reserved for the user
205 * Auxiliary Programs::          Programs automake might require
206 @end menu
207
208
209 @node General Operation, Strictness, Generalities, Generalities
210 @section General Operation
211
212 Automake works by reading a @file{Makefile.am} and generating a
213 @file{Makefile.in}.  Certain macros and targets defined in the
214 @file{Makefile.am} instruct Automake to generate more specialized code;
215 for instance, a @samp{bin_PROGRAMS} macro definition will cause targets
216 for compiling and linking programs to be generated.
217
218 @cindex Non-standard targets
219 @cindex cvs-dist, non-standard example
220 @trindex cvs-dist
221
222 The macro definitions and targets in the @file{Makefile.am} are copied
223 verbatim into the generated file.  This allows you to add arbitrary code
224 into the generated @file{Makefile.in}.  For instance the Automake
225 distribution includes a non-standard @code{cvs-dist} target, which the
226 Automake maintainer uses to make distributions from his source control
227 system.
228
229 @cindex GNU make extensions
230
231 Note that most GNU make extensions are not recognized by Automake.  Using
232 such extensions in a @file{Makefile.am} will lead to errors or confusing
233 behavior.
234
235 @cindex Append operator
236 A special exception is that the GNU make append operator, @samp{+=}, is
237 supported.  This operator appends its right hand argument to the macro
238 specified on the left.  Automake will translate the operator into
239 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
240
241 Note that it is only valid to append to a macro in the same conditional
242 context as the macro was originally defined. @xref{Conditional Append}, for
243 more information.
244
245 Automake tries to group comments with adjoining targets and macro
246 definitions in an intelligent way.
247 @c FIXME: What does this imply practically?
248
249 @cindex Make targets, overriding
250 @cindex Overriding make targets
251
252 A target defined in @file{Makefile.am} generally overrides any such
253 target of a similar name that would be automatically generated by
254 @code{automake}.  Although this is a supported feature, it is generally
255 best to avoid making use of it, as sometimes the generated rules are
256 very particular.
257
258 @cindex Macros, overriding
259 @cindex Overriding make macros
260
261 Similarly, a macro defined in @file{Makefile.am} or @code{AC_SUBST}'ed
262 from @file{configure.in} will override any definition of the macro that
263 @code{automake} would ordinarily create.  This feature is more often
264 useful than the ability to override a target definition.  Be warned that
265 many of the macros generated by @code{automake} are considered to be for
266 internal use only, and their names might change in future releases.
267
268 @cindex Recursive operation of Automake
269 @cindex Automake, recursive operation
270 @cindex Example of recursive operation
271
272 When examining a macro definition, Automake will recursively examine
273 macros referenced in the definition.  For example, if Automake is
274 looking at the content of @code{foo_SOURCES} in this snippet
275
276 @example
277 xs = a.c b.c
278 foo_SOURCES = c.c $(xs)
279 @end example
280
281 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
282 contents of @code{foo_SOURCES}.
283
284 @cindex ## (special Automake comment)
285 @cindex Special Automake comment
286 @cindex Comment, special to Automake
287
288 Automake also allows a form of comment which is @emph{not} copied into
289 the output; all lines beginning with @samp{##} (leading spaces allowed)
290 are completely ignored by Automake.
291
292 It is customary to make the first line of @file{Makefile.am} read:
293
294 @cindex Makefile.am, first line
295 @cindex First line of Makefile.am
296
297 @example
298 ## Process this file with automake to produce Makefile.in
299 @end example
300
301 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
302 @c I don't know quite what to say.
303
304 @c FIXME document customary ordering of Makefile.am here!
305
306
307 @node Strictness, Uniform, General Operation, Generalities
308 @section Strictness
309
310 @cindex Non-GNU packages
311
312 While Automake is intended to be used by maintainers of GNU packages, it
313 does make some effort to accommodate those who wish to use it, but do
314 not want to use all the GNU conventions.
315
316 @cindex Strictness, defined
317 @cindex Strictness, foreign
318 @cindex foreign strictness
319 @cindex Strictness, gnu
320 @cindex gnu strictness
321 @cindex Strictness, gnits
322 @cindex gnits strictness
323
324 To this end, Automake supports three levels of @dfn{strictness}---the
325 strictness indicating how stringently Automake should check standards
326 conformance.
327
328 The valid strictness levels are:
329
330 @table @samp
331 @item foreign
332 Automake will check for only those things which are absolutely
333 required for proper operations.  For instance, whereas GNU standards
334 dictate the existence of a @file{NEWS} file, it will not be required in
335 this mode.  The name comes from the fact that Automake is intended to be
336 used for GNU programs; these relaxed rules are not the standard mode of
337 operation.
338
339 @item gnu
340 Automake will check---as much as possible---for compliance to the GNU
341 standards for packages.  This is the default.
342
343 @item gnits
344 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
345 standards}.  These are based on the GNU standards, but are even more
346 detailed.  Unless you are a Gnits standards contributor, it is
347 recommended that you avoid this option until such time as the Gnits
348 standard is actually published (which may never happen).
349 @end table
350
351 For more information on the precise implications of the strictness
352 level, see @ref{Gnits}.
353
354 Automake also has a special ``cygnus'' mode which is similar to
355 strictness but handled differently.  This mode is useful for packages
356 which are put into a ``Cygnus'' style tree (e.g., the GCC tree).  For
357 more information on this mode, see @ref{Cygnus}.
358
359
360 @node Uniform, Canonicalization, Strictness, Generalities
361 @section The Uniform Naming Scheme
362
363 @cindex Uniform naming scheme
364
365 Automake macros (from here on referred to as @emph{variables}) generally
366 follow a @dfn{uniform naming scheme} that makes it easy to decide how
367 programs (and other derived objects) are built, and how they are
368 installed.  This scheme also supports @code{configure} time
369 determination of what should be built.
370
371 @cindex _PROGRAMS primary variable
372 @cindex PROGRAMS primary variable
373 @cindex Primary variable, PROGRAMS
374 @cindex Primary variable, defined
375
376 At @code{make} time, certain variables are used to determine which
377 objects are to be built.  The variable names are made of several pieces
378 which are concatenated together.
379
380 The piece which tells automake what is being built is commonly called
381 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
382 list of programs which are to be compiled and linked.
383 @vindex PROGRAMS
384
385 @cindex pkglibdir, defined
386 @cindex pkgincludedir, defined
387 @cindex pkgdatadir, defined
388
389 @vindex pkglibdir
390 @vindex pkgincludedir
391 @vindex pkgdatadir
392
393 A different set of names is used to decide where the built objects
394 should be installed.  These names are prefixes to the primary which
395 indicate which standard directory should be used as the installation
396 directory.  The standard directory names are given in the GNU standards
397 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
398 Automake extends this list with @code{pkglibdir}, @code{pkgincludedir},
399 and @code{pkgdatadir}; these are the same as the non-@samp{pkg}
400 versions, but with @samp{@@PACKAGE@@} appended.  For instance,
401 @code{pkglibdir} is defined as @code{$(libdir)/@@PACKAGE@@}.
402 @cvindex PACKAGE, directory
403
404 @cindex EXTRA_, prepending
405
406 For each primary, there is one additional variable named by prepending
407 @samp{EXTRA_} to the primary name.  This variable is used to list
408 objects which may or may not be built, depending on what
409 @code{configure} decides.  This variable is required because Automake
410 must statically know the entire list of objects that may be built in
411 order to generate a @file{Makefile.in} that will work in all cases.
412
413 @cindex EXTRA_PROGRAMS, defined
414 @cindex Example, EXTRA_PROGRAMS
415 @cindex cpio example
416
417 For instance, @code{cpio} decides at configure time which programs are
418 built.  Some of the programs are installed in @code{bindir}, and some
419 are installed in @code{sbindir}:
420
421 @example
422 EXTRA_PROGRAMS = mt rmt
423 bin_PROGRAMS = cpio pax
424 sbin_PROGRAMS = @@MORE_PROGRAMS@@
425 @end example
426
427 Defining a primary without a prefix as a variable, e.g.,
428 @code{PROGRAMS}, is an error.
429
430 Note that the common @samp{dir} suffix is left off when constructing the
431 variable names; thus one writes @samp{bin_PROGRAMS} and not
432 @samp{bindir_PROGRAMS}.
433
434 Not every sort of object can be installed in every directory.  Automake
435 will flag those attempts it finds in error.
436 Automake will also diagnose obvious misspellings in directory names.
437
438 @cindex Extending list of installation directories
439 @cindex Installation directories, extending list
440
441 Sometimes the standard directories---even as augmented by Automake---
442 are not enough.  In particular it is sometimes useful, for clarity, to
443 install objects in a subdirectory of some predefined directory.  To this
444 end, Automake allows you to extend the list of possible installation
445 directories.  A given prefix (e.g. @samp{zar}) is valid if a variable of
446 the same name with @samp{dir} appended is defined (e.g. @code{zardir}).
447
448 @cindex HTML support, example
449
450 For instance, until HTML support is part of Automake, you could use this
451 to install raw HTML documentation:
452
453 @example
454 htmldir = $(prefix)/html
455 html_DATA = automake.html
456 @end example
457
458 @cindex noinst primary prefix, definition
459
460 The special prefix @samp{noinst} indicates that the objects in question
461 should be built but not installed at all.  This is usually used for
462 objects required to build the rest of your package, for instance static
463 libraries (@pxref{A Library}), or helper scripts.
464
465 @cindex check primary prefix, definition
466
467 The special prefix @samp{check} indicates that the objects in question
468 should not be built until the @code{make check} command is run.  Those
469 objects are not installed either.
470
471 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
472 @samp{LISP}, @samp{PYTHON}, @samp{JAVA}, @samp{SCRIPTS}, @samp{DATA},
473 @samp{HEADERS}, @samp{MANS}, and @samp{TEXINFOS}.
474 @vindex PROGRAMS
475 @vindex LIBRARIES
476 @vindex LISP
477 @vindex PYTHON
478 @vindex JAVA
479 @vindex SCRIPTS
480 @vindex DATA
481 @vindex HEADERS
482 @vindex MANS
483 @vindex TEXINFOS
484
485 Some primaries also allow additional prefixes which control other
486 aspects of @code{automake}'s behavior.  The currently defined prefixes
487 are @samp{dist_}, @samp{nodist_}, and @samp{nobase_}.  These prefixes
488 are explained later (@pxref{Program and Library Variables}).
489
490
491 @node Canonicalization, User Variables, Uniform, Generalities
492 @section How derived variables are named
493
494 @cindex canonicalizing Automake macros
495
496 Sometimes a Makefile variable name is derived from some text the
497 maintainer supplies.  For instance, a program name listed in
498 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
499 variable.  In cases like this, Automake canonicalizes the text, so that
500 program names and the like do not have to follow Makefile macro naming
501 rules.  All characters in the name except for letters, numbers, the
502 strudel (@@), and the underscore are turned into underscores when making
503 macro references.
504
505 For example, if your program is named @code{sniff-glue}, the derived
506 variable name would be @code{sniff_glue_SOURCES}, not
507 @code{sniff-glue_SOURCES}.  Similarly the sources for a library named
508 @code{libmumble++.a} should be listed in the
509 @code{libmumble___a_SOURCES} variable.
510
511 The strudel is an addition, to make the use of Autoconf substitutions in
512 macro names less obfuscating.
513
514
515 @node User Variables, Auxiliary Programs, Canonicalization, Generalities
516 @section Variables reserved for the user
517
518 @cindex variables, reserved for the user
519 @cindex user variables
520
521 Some @code{Makefile} variables are reserved by the GNU Coding Standards
522 for the use of the ``user'' -- the person building the package.  For
523 instance, @code{CFLAGS} is one such variable.
524
525 Sometimes package developers are tempted to set user variables such as
526 @code{CFLAGS} because it appears to make their job easier -- they don't
527 have to introduce a second variable into every target.
528
529 However, the package itself should never set a user variable,
530 particularly not to include switches which are required for proper
531 compilation of the package.  Since these variables are documented as
532 being for the package builder, that person rightfully expects to be able
533 to override any of these variables at build time.
534 @c FIXME: maybe Automake could bark if a developer forces a user variable
535 @c from Makefile.am.
536
537 To get around this problem, automake introduces an automake-specific
538 shadow variable for each user flag variable.  (Shadow variables are not
539 introduced for variables like @code{CC}, where they would make no
540 sense.)  The shadow variable is named by prepending @samp{AM_} to the
541 user variable's name.  For instance, the shadow variable for
542 @code{YFLAGS} is @code{AM_YFLAGS}.
543
544
545 @node Auxiliary Programs,  , User Variables, Generalities
546 @section Programs automake might require
547
548 @cindex Programs, auxiliary
549 @cindex Auxiliary programs
550
551 Automake sometimes requires helper programs so that the generated
552 @file{Makefile} can do its work properly.  There are a fairly large
553 number of them, and we list them here.
554
555 @table @code
556 @item ansi2knr.c
557 @itemx ansi2knr.1
558 These two files are used by the automatic de-ANSI-fication support
559 (@pxref{ANSI}).
560
561 @item compile
562 This is a wrapper for compilers which don't accept both @samp{-c} and
563 @samp{-o} at the same time.  It is only used when absolutely required.
564 Such compilers are rare.
565
566 @item config.guess
567 @itemx config.sub
568 These programs compute the canonical triplets for the given build, host,
569 or target architecture.  These programs are updated regulary to support
570 new architectures and fix probes broken by changes in new kernel
571 versions.  You are encouraged to fetch the latest versions of these
572 files from @url{ftp://ftp.gnu.org/gnu/config/} before making a release.
573
574 @item depcomp
575 This program understands how to run a compiler so that it will generate
576 not only the desired output but also dependency information which is
577 then used by the automatic dependency tracking feature.
578
579 @item elisp-comp
580 This program is used to byte-compile Emacs Lisp code.
581
582 @item install-sh
583 This is a replacement for the @code{install} program which works on
584 platforms where @code{install} is unavailable or unusable.
585
586 @item mdate-sh
587 This script is used to generate a @file{version.texi} file.  It examines
588 a file and prints some date information about it.
589
590 @item missing
591 This wraps a number of programs which are typically only required by
592 maintainers.  If the program in question doesn't exist, @code{missing}
593 prints an informative warning and attempts to fix things so that the
594 build can continue.
595
596 @item mkinstalldirs
597 This works around the fact that @code{mkdir -p} is not portable.
598
599 @item py-compile
600 This is used to byte-compile Python scripts.
601
602 @item texinfo.tex
603 Not a program, this file is required for @code{make dvi} to work when
604 Texinfo sources are in the package.
605
606 @item ylwrap
607 This program wraps @code{lex} and @code{yacc} and ensures that, for
608 instance, multiple @code{yacc} instances can be invoked in a single
609 directory in parallel.
610
611 @end table
612
613
614 @node Examples, Invoking Automake, Generalities, Top
615 @chapter Some example packages
616
617 @menu
618 * Complete::                    A simple example, start to finish
619 * Hello::                       A classic program
620 * etags::                       Building etags and ctags
621 @end menu
622
623
624 @node Complete, Hello, Examples, Examples
625 @section A simple example, start to finish
626
627 @cindex Complete example
628
629 Let's suppose you just finished writing @code{zardoz}, a program to make
630 your head float from vortex to vortex.  You've been using Autoconf to
631 provide a portability framework, but your @file{Makefile.in}s have been
632 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
633
634 @cindex AM_INIT_AUTOMAKE, example use
635
636 The first step is to update your @file{configure.in} to include the
637 commands that @code{automake} needs.  The way to do this is to add an
638 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
639
640 @example
641 AC_INIT(zardoz, 1.0)
642 AM_INIT_AUTOMAKE
643 ...
644 @end example
645
646 Since your program doesn't have any complicating factors (e.g., it
647 doesn't use @code{gettext}, it doesn't want to build a shared library),
648 you're done with this part.  That was easy!
649
650 @cindex aclocal program, introduction
651 @cindex aclocal.m4, preexisting
652 @cindex acinclude.m4, defined
653
654 Now you must regenerate @file{configure}.  But to do that, you'll need
655 to tell @code{autoconf} how to find the new macro you've used.  The
656 easiest way to do this is to use the @code{aclocal} program to generate
657 your @file{aclocal.m4} for you.  But wait... maybe you already have an
658 @file{aclocal.m4}, because you had to write some hairy macros for your
659 program.  The @code{aclocal} program lets you put your own macros into
660 @file{acinclude.m4}, so simply rename and then run:
661
662 @example
663 mv aclocal.m4 acinclude.m4
664 aclocal
665 autoconf
666 @end example
667
668 @cindex zardoz example
669
670 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
671 Since @code{zardoz} is a user program, you want to install it where the
672 rest of the user programs go: @code{bindir}.  Additionally,
673 @code{zardoz} has some Texinfo documentation.  Your @file{configure.in}
674 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
675 @samp{@@LIBOBJS@@}.  So here's what you'd write:
676
677 @example
678 bin_PROGRAMS = zardoz
679 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
680 zardoz_LDADD = @@LIBOBJS@@
681
682 info_TEXINFOS = zardoz.texi
683 @end example
684
685 Now you can run @code{automake --add-missing} to generate your
686 @file{Makefile.in} and grab any auxiliary files you might need, and
687 you're done!
688
689
690 @node Hello, etags, Complete, Examples
691 @section A classic program
692
693 @cindex Example, GNU Hello
694 @cindex Hello example
695 @cindex GNU Hello, example
696
697 @uref{ftp://prep.ai.mit.edu/pub/gnu/hello-1.3.tar.gz, GNU hello} is
698 renowned for its classic simplicity and versatility.  This section shows
699 how Automake could be used with the GNU Hello package.  The examples
700 below are from the latest beta version of GNU Hello, but with all of the
701 maintainer-only code stripped out, as well as all copyright comments.
702
703 Of course, GNU Hello is somewhat more featureful than your traditional
704 two-liner.  GNU Hello is internationalized, does option processing, and
705 has a manual and a test suite.
706
707 @cindex configure.in, from GNU Hello
708 @cindex GNU Hello, configure.in
709 @cindex Hello, configure.in
710
711 Here is the @file{configure.in} from GNU Hello:
712 @c FIXME: This definitively requires an update.
713
714 @example
715 dnl Process this file with autoconf to produce a configure script.
716 AC_INIT(src/hello.c)
717 AM_INIT_AUTOMAKE(hello, 1.3.11)
718 AM_CONFIG_HEADER(config.h)
719
720 dnl Set of available languages.
721 ALL_LINGUAS="de fr es ko nl no pl pt sl sv"
722
723 dnl Checks for programs.
724 AC_PROG_CC
725 AC_ISC_POSIX
726
727 dnl Checks for libraries.
728
729 dnl Checks for header files.
730 AC_STDC_HEADERS
731 AC_HAVE_HEADERS(string.h fcntl.h sys/file.h sys/param.h)
732
733 dnl Checks for library functions.
734 AC_FUNC_ALLOCA
735
736 dnl Check for st_blksize in struct stat
737 AC_ST_BLKSIZE
738
739 dnl internationalization macros
740 AM_GNU_GETTEXT
741 AC_OUTPUT([Makefile doc/Makefile intl/Makefile po/Makefile.in \
742            src/Makefile tests/Makefile tests/hello],
743    [chmod +x tests/hello])
744 @end example
745
746 The @samp{AM_} macros are provided by Automake (or the Gettext library);
747 the rest are standard Autoconf macros.
748
749
750 The top-level @file{Makefile.am}:
751
752 @example
753 EXTRA_DIST = BUGS ChangeLog.O
754 SUBDIRS = doc intl po src tests
755 @end example
756
757 As you can see, all the work here is really done in subdirectories.
758
759 The @file{po} and @file{intl} directories are automatically generated
760 using @code{gettextize}; they will not be discussed here.
761
762 @cindex Texinfo file handling example
763 @cindex Example, handling Texinfo files
764
765 In @file{doc/Makefile.am} we see:
766
767 @example
768 info_TEXINFOS = hello.texi
769 hello_TEXINFOS = gpl.texi
770 @end example
771
772 This is sufficient to build, install, and distribute the GNU Hello
773 manual.
774
775 @cindex Regression test example
776 @cindex Example, regression test
777
778 Here is @file{tests/Makefile.am}:
779
780 @example
781 TESTS = hello
782 EXTRA_DIST = hello.in testdata
783 @end example
784
785 The script @file{hello} is generated by @code{configure}, and is the
786 only test case.  @code{make check} will run this test.
787
788 @cindex INCLUDES, example usage
789
790 Last we have @file{src/Makefile.am}, where all the real work is done:
791 @c FIXME: As all the Hello World excerpts in this manual, this
792 @c shows deprecated features (here: $(INCLUDES)).
793
794 @example
795 bin_PROGRAMS = hello
796 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
797 hello_LDADD = @@INTLLIBS@@ @@ALLOCA@@
798 localedir = $(datadir)/locale
799 INCLUDES = -I../intl -DLOCALEDIR=\"$(localedir)\"
800 @end example
801
802
803 @node etags,  , Hello, Examples
804 @section Building etags and ctags
805
806 @cindex Example, ctags and etags
807 @cindex ctags Example
808 @cindex etags Example
809
810 Here is another, trickier example.  It shows how to generate two
811 programs (@code{ctags} and @code{etags}) from the same source file
812 (@file{etags.c}).  The difficult part is that each compilation of
813 @file{etags.c} requires different @code{cpp} flags.
814
815 @example
816 bin_PROGRAMS = etags ctags
817 ctags_SOURCES =
818 ctags_LDADD = ctags.o
819
820 etags.o: etags.c
821         $(COMPILE) -DETAGS_REGEXPS -c etags.c
822
823 ctags.o: etags.c
824         $(COMPILE) -DCTAGS -o ctags.o -c etags.c
825 @end example
826
827 Note that there is no @code{etags_SOURCES} definition.  Automake will
828 implicitly assume that there is a source file named @file{etags.c}, and
829 define rules to compile @file{etags.o} and link @file{etags}.  The
830 @code{etags.o: etags.c} rule supplied by the above @file{Makefile.am},
831 will override the Automake generated rule to build @file{etags.o}.
832
833 @code{ctags_SOURCES} is defined to be empty---that way no implicit value
834 is substituted.  Because we have not listed the source of
835 @file{ctags}, we have to tell Automake how to link the program.  This is
836 the purpose of the @code{ctags_LDADD} line.  A @code{ctags_DEPENDENCIES}
837 variable, holding the dependencies of the @file{ctags} target will be
838 automatically generated by Automake from the contant of
839 @code{ctags_LDADD}.
840
841 The above rules won't work if your compiler doesn't accept both
842 @samp{-c} and @samp{-o}.  The simplest fix for this is to introduce a
843 bogus dependency (to avoid problems with a parallel @code{make}):
844
845 @example
846 etags.o: etags.c ctags.o
847         $(COMPILE) -DETAGS_REGEXPS -c etags.c
848
849 ctags.o: etags.c
850         $(COMPILE) -DCTAGS -c etags.c && mv etags.o ctags.o
851 @end example
852
853 Also, these explicit rules do not work if the de-ANSI-fication feature
854 is used (@pxref{ANSI}).  Supporting de-ANSI-fication requires a little
855 more work:
856
857 @example
858 etags._o: etags._c ctags.o
859         $(COMPILE) -DETAGS_REGEXPS -c etags.c
860
861 ctags._o: etags._c
862         $(COMPILE) -DCTAGS -c etags.c && mv etags._o ctags.o
863 @end example
864
865 As it turns out, there is also a much easier way to do this same task.
866 Some of the above techniques are useful enough that we've kept the
867 example in the manual.  However if you were to build @code{etags} and
868 @code{ctags} in real life, you would probably use per-program
869 compilation flags, like so:
870
871 @example
872 bin_PROGRAMS = ctags etags
873
874 ctags_SOURCES = etags.c
875 ctags_CFLAGS = -DCTAGS
876
877 etags_SOURCES = etags.c
878 etags_CFLAGS = -DETAGS_REGEXPS
879 @end example
880
881 In this case Automake will cause @file{etags.c} to be compiled twice,
882 with different flags.  De-ANSI-fication will work automatically.  In
883 this instance, the names of the object files would be chosen by
884 automake; they would be @file{ctags-etags.o} and @file{etags-etags.o}.
885 (The name of the object files rarely matters.)
886
887
888 @node Invoking Automake, configure, Examples, Top
889 @chapter Creating a @file{Makefile.in}
890
891 @cindex Multiple configure.in files
892 @cindex Invoking Automake
893 @cindex Automake, invoking
894
895 To create all the @file{Makefile.in}s for a package, run the
896 @code{automake} program in the top level directory, with no arguments.
897 @code{automake} will automatically find each appropriate
898 @file{Makefile.am} (by scanning @file{configure.in}; @pxref{configure})
899 and generate the corresponding @file{Makefile.in}.  Note that
900 @code{automake} has a rather simplistic view of what constitutes a
901 package; it assumes that a package has only one @file{configure.in}, at
902 the top.  If your package has multiple @file{configure.in}s, then you
903 must run @code{automake} in each directory holding a
904 @file{configure.in}.  (Alteratively, you may rely on Autoconf's
905 @code{autoreconf}, which is able to recurse your package tree and run
906 @code{automake} where appropriate.)
907
908 You can optionally give @code{automake} an argument; @file{.am} is
909 appended to the argument and the result is used as the name of the input
910 file.  This feature is generally only used to automatically rebuild an
911 out-of-date @file{Makefile.in}.  Note that @code{automake} must always
912 be run from the topmost directory of a project, even if being used to
913 regenerate the @file{Makefile.in} in some subdirectory.  This is
914 necessary because @code{automake} must scan @file{configure.in}, and
915 because @code{automake} uses the knowledge that a @file{Makefile.in} is
916 in a subdirectory to change its behavior in some cases.
917
918 @cindex Automake options
919 @cindex Options, Automake
920 @cindex Strictness, command line
921
922 @code{automake} accepts the following options:
923
924 @cindex Extra files distributed with Automake
925 @cindex Files distributed with Automake
926 @cindex config.guess
927
928 @table @samp
929 @item -a
930 @itemx --add-missing
931 @opindex -a
932 @opindex --add-missing
933 Automake requires certain common files to exist in certain situations;
934 for instance @file{config.guess} is required if @file{configure.in} runs
935 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
936 files (@pxref{Auxiliary Programs}); this option will cause the missing
937 ones to be automatically added to the package, whenever possible.  In
938 general if Automake tells you a file is missing, try using this option.
939 By default Automake tries to make a symbolic link pointing to its own
940 copy of the missing file; this can be changed with @code{--copy}.
941
942 @item --libdir=@var{dir}
943 @opindex --libdir
944 Look for Automake data files in directory @var{dir} instead of in the
945 installation directory.  This is typically used for debugging.
946
947 @item -c
948 @opindex -c
949 @itemx --copy
950 @opindex --copy
951 When used with @code{--add-missing}, causes installed files to be
952 copied.  The default is to make a symbolic link.
953
954 @item --cygnus
955 @opindex --cygnus
956 Causes the generated @file{Makefile.in}s to follow Cygnus rules, instead
957 of GNU or Gnits rules.  For more information, see @ref{Cygnus}.
958
959 @item -f
960 @opindex -f
961 @itemx --force-missing
962 @opindex --force-missing
963 When used with @code{--add-missing}, causes standard files to be reinstalled
964 even if they already exist in the source tree.  This involves removing
965 the file from the source tree before creating the new symlink (or, with
966 @code{--copy}, copying the new file).
967
968 @item --foreign
969 @opindex --foreign
970 Set the global strictness to @samp{foreign}.  For more information, see
971 @ref{Strictness}.
972
973 @item --gnits
974 @opindex --gnits
975 Set the global strictness to @samp{gnits}.  For more information, see
976 @ref{Gnits}.
977
978 @item --gnu
979 @opindex --gnu
980 Set the global strictness to @samp{gnu}.  For more information, see
981 @ref{Gnits}.  This is the default strictness.
982
983 @item --help
984 @opindex --help
985 Print a summary of the command line options and exit.
986
987 @item -i
988 @itemx --ignore-deps
989 @opindex -i
990 This disables the dependency tracking feature in generated
991 @file{Makefile}s; see @ref{Dependencies}.
992
993 @item --include-deps
994 @opindex --include-deps
995 This enables the dependency tracking feature.  This feature is enabled
996 by default.  This option is provided for historical reasons only and
997 probably should not be used.
998
999 @item --no-force
1000 @opindex --no-force
1001 Ordinarily @code{automake} creates all @file{Makefile.in}s mentioned in
1002 @file{configure.in}.  This option causes it to only update those
1003 @file{Makefile.in}s which are out of date with respect to one of their
1004 dependents.
1005
1006 @item -o @var{dir}
1007 @itemx --output-dir=@var{dir}
1008 @opindex -o
1009 @opindex --output-dir
1010 Put the generated @file{Makefile.in} in the directory @var{dir}.
1011 Ordinarily each @file{Makefile.in} is created in the directory of the
1012 corresponding @file{Makefile.am}.  This option is deprecated and will be
1013 removed in a future release.
1014
1015 @item -v
1016 @itemx --verbose
1017 @opindex -v
1018 @opindex --verbose
1019 Cause Automake to print information about which files are being read or
1020 created.
1021
1022 @item --version
1023 @opindex --version
1024 Print the version number of Automake and exit.
1025
1026 @item --Werror
1027 @itemx --Wno-error
1028 @opindex --Werror
1029 @opindex --Wno-error
1030 @samp{--Werror} will cause all warnings issued by @code{automake} to
1031 become errors.  Errors affect the exit status of @code{automake}, while
1032 warnings do not.  @samp{--Wno-error}, the default, causes warnings to be
1033 treated as warnings only.
1034 @end table
1035
1036
1037 @node configure, Top level, Invoking Automake, Top
1038 @chapter Scanning @file{configure.in}
1039
1040 @cindex configure.in, scanning
1041 @cindex Scanning configure.in
1042
1043 Automake scans the package's @file{configure.in} to determine certain
1044 information about the package.  Some @code{autoconf} macros are required
1045 and some variables must be defined in @file{configure.in}.  Automake
1046 will also use information from @file{configure.in} to further tailor its
1047 output.
1048
1049 Automake also supplies some Autoconf macros to make the maintenance
1050 easier.  These macros can automatically be put into your
1051 @file{aclocal.m4} using the @code{aclocal} program.
1052
1053 @menu
1054 * Requirements::                Configuration requirements
1055 * Optional::                    Other things Automake recognizes
1056 * Invoking aclocal::            Auto-generating aclocal.m4
1057 * Macros::                      Autoconf macros supplied with Automake
1058 * Extending aclocal::           Writing your own aclocal macros
1059 @end menu
1060
1061
1062 @node Requirements, Optional, configure, configure
1063 @section Configuration requirements
1064
1065 @cindex Automake requirements
1066 @cindex Requirements of Automake
1067
1068 The one real requirement of Automake is that your @file{configure.in}
1069 call @code{AM_INIT_AUTOMAKE}.  This macro does several things which are
1070 required for proper Automake operation (@pxref{Macros}).
1071 @cvindex AM_INIT_AUTOMAKE
1072
1073 Here are the other macros which Automake requires but which are not run
1074 by @code{AM_INIT_AUTOMAKE}:
1075
1076 @cindex AC_OUTPUT, scanning
1077
1078 @table @code
1079 @item AC_CONFIG_FILES
1080 @itemx AC_OUTPUT
1081 Automake uses these to determine which files to create (@pxref{Output, ,
1082 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
1083 is considered to be an Automake generated @file{Makefile} if there
1084 exists a file with the same name and the @file{.am} extension appended.
1085 Typically, @code{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
1086 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
1087
1088 Other listed files are treated differently.  Currently the only
1089 difference is that an Automake @file{Makefile} is removed by @code{make
1090 distclean}, while other files are removed by @code{make clean}.
1091 @c FIXME: this is in violation of standards!
1092 @cvindex AC_OUTPUT
1093 @end table
1094
1095
1096 @node Optional, Invoking aclocal, Requirements, configure
1097 @section Other things Automake recognizes
1098
1099 @cindex Macros Automake recognizes
1100 @cindex Recognized macros by Automake
1101
1102 Automake will also recognize the use of certain macros and tailor the
1103 generated @file{Makefile.in} appropriately.  Currently recognized macros
1104 and their effects are:
1105
1106 @table @code
1107 @item AC_CONFIG_HEADER
1108 Automake requires the use of @code{AM_CONFIG_HEADER} (@pxref{Macros}),
1109 which is similar to @code{AC_CONFIG_HEADER} (@pxref{Configuration
1110 Headers, , Configuration Header Files, autoconf, The Autoconf Manual}),
1111 but does some useful Automake-specific work.
1112 @cvindex AC_CONFIG_HEADER
1113
1114 @item AC_CONFIG_AUX_DIR
1115 Automake will look for various helper scripts, such as
1116 @file{mkinstalldirs}, in the directory named in this macro invocation.
1117 If not seen, the scripts are looked for in their @samp{standard}
1118 locations (either the top source directory, or in the source directory
1119 corresponding to the current @file{Makefile.am}, whichever is
1120 appropriate).  @xref{Input, , Finding `configure' Input, autoconf, The
1121 Autoconf Manual}.
1122 @cvindex AC_CONFIG_AUX_DIR
1123 FIXME: give complete list of things looked for in this directory
1124
1125 @item AC_PATH_XTRA
1126 Automake will insert definitions for the variables defined by
1127 @code{AC_PATH_XTRA} into each @file{Makefile.in} that builds a C program
1128 or library.  @xref{System Services, , System Services, autoconf, The
1129 Autoconf Manual}.
1130 @cvindex AC_PATH_XTRA
1131
1132 @item AC_CANONICAL_HOST
1133 Automake will ensure that @file{config.guess} and @file{config.sub}
1134 exist.  Also, the @file{Makefile} variables @samp{host_alias} and
1135 @samp{host_triplet} are introduced.  See @ref{Canonicalizing, ,
1136 Getting the Canonical System Type, autoconf, The Autoconf Manual}.
1137 @cvindex AC_CANONICAL_HOST
1138 @vindex host_alias
1139 @vindex host_triplet
1140
1141 @item AC_CANONICAL_SYSTEM
1142 This is similar to @code{AC_CANONICAL_HOST}, but also defines the
1143 @file{Makefile} variables @samp{build_alias} and @samp{target_alias}.
1144 @xref{Canonicalizing, , Getting the Canonical System Type, autoconf, The
1145 Autoconf Manual}.
1146 @cvindex AC_CANONICAL_SYSTEM
1147 @vindex build_alias
1148 @vindex target_alias
1149
1150 @item  AC_FUNC_ALLOCA
1151 @itemx AC_FUNC_ERROR_AT_LINE
1152 @itemx AC_FUNC_FNMATCH
1153 @itemx AC_FUNC_GETLOADAVG
1154 @itemx AC_FUNC_MEMCMP
1155 @itemx AC_FUNC_MKTIME
1156 @itemx AC_FUNC_OBSTACK
1157 @itemx AC_FUNC_STRTOD
1158 @itemx AC_REPLACE_FUNCS
1159 @itemx AC_REPLACE_GNU_GETOPT
1160 @itemx AC_STRUCT_ST_BLOCKS
1161 @itemx AM_WITH_REGEX
1162 Automake will ensure that the appropriate dependencies are generated for
1163 the objects corresponding to these macros.  Also, Automake will verify
1164 that the appropriate source files are part of the distribution.  Note
1165 that Automake does not come with any of the C sources required to use
1166 these macros, so @code{automake -a} will not install the sources.
1167 @xref{A Library}, for more information.  Also, see @ref{Particular
1168 Functions, , Particular Function Checks, autoconf, The Autoconf Manual}.
1169 @cvindex AC_FUNC_ALLOCA
1170 @cvindex AC_FUNC_ERROR_AT_LINE
1171 @cvindex AC_FUNC_FNMATCH
1172 @cvindex AC_FUNC_GETLOADAVG
1173 @cvindex AC_FUNC_MEMCMP
1174 @cvindex AC_FUNC_MKTIME
1175 @cvindex AC_FUNC_OBSTACK
1176 @cvindex AC_FUNC_STRTOD
1177 @cvindex AC_REPLACE_FUNCS
1178 @cvindex AC_REPLACE_GNU_GETOPT
1179 @cvindex AC_STRUCT_ST_BLOCKS
1180 @cvindex AM_WITH_REGEX
1181
1182 @item AC_LIBOBJ
1183 @itemx LIBOBJS
1184 @itemx AC_LIBSOURCE
1185 @itemx AC_LIBSOURCES
1186 Automake will detect statements which put @file{.o} files into
1187 @code{LIBOBJS}, or pass @file{.o} files to @code{AC_LIBOBJ}, and will
1188 treat these additional files as if they were discovered via
1189 @code{AC_REPLACE_FUNCS}.  Similarly, Automake will also distribute file
1190 listed in @code{AC_LIBSOURCE} and @code{AC_LIBSOURCES}.
1191
1192 Note that assignments to @code{LIBOBJS} is a construct which is being
1193 phased out; they will be ignored in a future release of Automake.  You
1194 should call the @code{AC_LIBOBJ} macro instead.  @xref{Generic
1195 Functions, , Generic Function Checks, autoconf, The Autoconf Manual}.
1196
1197 @cvindex AC_LIBOBJ
1198 @cvindex AC_LIBSOURCE
1199 @cvindex AC_LIBSOURCES
1200 @cvindex LIBOBJS
1201
1202 @item AC_PROG_RANLIB
1203 This is required if any libraries are built in the package.
1204 @xref{Particular Programs, , Particular Program Checks, autoconf, The
1205 Autoconf Manual}.
1206 @cvindex AC_PROG_RANLIB
1207
1208 @item AC_PROG_CXX
1209 This is required if any C++ source is included.  @xref{Particular
1210 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
1211 @cvindex AC_PROG_CXX
1212
1213 @item AC_PROG_F77
1214 This is required if any Fortran 77 source is included.  This macro is
1215 distributed with Autoconf version 2.13 and later.  @xref{Particular
1216 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
1217 @cvindex AC_PROG_F77
1218
1219 @item AC_F77_LIBRARY_LDFLAGS
1220 This is required for programs and shared libraries that are a mixture of
1221 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
1222 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
1223 @cvindex AC_F77_LIBRARY_LDFLAGS
1224
1225 @item AC_PROG_LIBTOOL
1226 Automake will turn on processing for @code{libtool} (@pxref{Top, ,
1227 Introduction, libtool, The Libtool Manual}).
1228 @cvindex AC_PROG_LIBTOOL
1229
1230 @item AC_PROG_YACC
1231 If a Yacc source file is seen, then you must either use this macro or
1232 define the variable @samp{YACC} in @file{configure.in}.  The former is
1233 preferred (@pxref{Particular Programs, , Particular Program Checks,
1234 autoconf, The Autoconf Manual}).
1235 @cvindex AC_PROG_YACC
1236 @cvindex YACC
1237
1238 @item AC_PROG_LEX
1239 If a Lex source file is seen, then this macro must be used.
1240 @xref{Particular Programs, , Particular Program Checks, autoconf, The
1241 Autoconf Manual}.
1242 @cvindex AC_PROG_LEX
1243
1244 @item AM_C_PROTOTYPES
1245 This is required when using automatic de-ANSI-fication; see @ref{ANSI}.
1246 @cvindex AM_C_PROTOTYPES
1247
1248 @item AM_GNU_GETTEXT
1249 This macro is required for packages which use GNU gettext
1250 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
1251 this macro it ensures that the package meets some of gettext's
1252 requirements.
1253 @cvindex AM_GNU_GETTEXT
1254
1255 @item AM_MAINTAINER_MODE
1256 @opindex --enable-maintainer-mode
1257 This macro adds a @samp{--enable-maintainer-mode} option to
1258 @code{configure}.  If this is used, @code{automake} will cause
1259 @samp{maintainer-only} rules to be turned off by default in the
1260 generated @file{Makefile.in}s.  This macro is disallowed in @samp{Gnits}
1261 mode (@pxref{Gnits}).  This macro defines the @samp{MAINTAINER_MODE}
1262 conditional, which you can use in your own @file{Makefile.am}.
1263 @cvindex AM_MAINTAINER_MODE
1264
1265 @item AC_SUBST
1266 @itemx AC_CHECK_TOOL
1267 @itemx AC_CHECK_PROG
1268 @itemx AC_CHECK_PROGS
1269 @itemx AC_PATH_PROG
1270 @itemx AC_PATH_PROGS
1271 For each of these macros, the first argument is automatically defined as
1272 a variable in each generated @file{Makefile.in}.  @xref{Setting Output
1273 Variables, , Setting Output Variables, autoconf, The Autoconf Manual},
1274 and @ref{Generic Programs, , Generic Program Checks, autoconf, The
1275 Autoconf Manual}.
1276 @cvindex AC_SUBST
1277 @cvindex AC_CHECK_TOOL
1278 @cvindex AC_CHECK_PROG
1279 @cvindex AC_CHECK_PROGS
1280 @cvindex AC_PATH_PROG
1281 @cvindex AC_PATH_PROGS
1282
1283 @end table
1284
1285
1286 @node Invoking aclocal, Macros, Optional, configure
1287 @section Auto-generating aclocal.m4
1288
1289 @cindex Invoking aclocal
1290 @cindex aclocal, Invoking
1291
1292 Automake includes a number of Autoconf macros which can be used in your
1293 package; some of them are actually required by Automake in certain
1294 situations.  These macros must be defined in your @file{aclocal.m4};
1295 otherwise they will not be seen by @code{autoconf}.
1296
1297 The @code{aclocal} program will automatically generate @file{aclocal.m4}
1298 files based on the contents of @file{configure.in}.  This provides a
1299 convenient way to get Automake-provided macros, without having to
1300 search around.  Also, the @code{aclocal} mechanism allows other packages
1301 to supply their own macros.
1302
1303 At startup, @code{aclocal} scans all the @file{.m4} files it can find,
1304 looking for macro definitions.  Then it scans @file{configure.in}.  Any
1305 mention of one of the macros found in the first step causes that macro,
1306 and any macros it in turn requires, to be put into @file{aclocal.m4}.
1307
1308 The contents of @file{acinclude.m4}, if it exists, are also
1309 automatically included in @file{aclocal.m4}.  This is useful for
1310 incorporating local macros into @file{configure}.
1311
1312 @code{aclocal} tries to be smart about looking for new @code{AC_DEFUN}s
1313 in the files it scans.  It also
1314 tries to copy the full text of the scanned file into @file{aclocal.m4},
1315 including both @samp{#} and @samp{dnl} comments.  If you want to make a
1316 comment which will be completely ignored by @code{aclocal}, use
1317 @samp{##} as the comment leader.
1318
1319 @code{aclocal} accepts the following options:
1320
1321 @table @code
1322 @item --acdir=@var{dir}
1323 @opindex --acdir
1324 Look for the macro files in @var{dir} instead of the installation
1325 directory.  This is typically used for debugging.
1326
1327 @item --help
1328 @opindex --help
1329 Print a summary of the command line options and exit.
1330
1331 @item -I @var{dir}
1332 @opindex -I
1333 Add the directory @var{dir} to the list of directories searched for
1334 @file{.m4} files.
1335
1336 @item --output=@var{file}
1337 @opindex --output
1338 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
1339
1340 @item --print-ac-dir
1341 @opindex --print-ac-dir
1342 Prints the name of the directory which @code{aclocal} will search to
1343 find third-party @file{.m4} files.  When this option is given, normal
1344 processing is suppressed.  This option can be used by a package to
1345 determine where to install a macro file.
1346
1347 @item --verbose
1348 @opindex --verbose
1349 Print the names of the files it examines.
1350
1351 @item --version
1352 @opindex --version
1353 Print the version number of Automake and exit.
1354 @end table
1355
1356
1357 @node Macros, Extending aclocal, Invoking aclocal, configure
1358 @section Autoconf macros supplied with Automake
1359
1360 Automake ships with several Autoconf macros that you can use from your
1361 @file{configure.in}.  When you use one of them it will be included by
1362 @code{aclocal} in @file{aclocal.m4}.
1363
1364 @menu
1365 * Public macros::               Macros that you can use.
1366 * Private macros::              Macros that you should not use.
1367 @end menu
1368
1369 @c consider generating the following subsections automatically from m4 files.
1370
1371 @node Public macros, Private macros, Macros, Macros
1372 @subsection Public macros
1373
1374 @table @code
1375 @item AM_CONFIG_HEADER
1376 Automake will generate rules to automatically regenerate the config
1377 header.
1378 @cvindex AM_CONFIG_HEADER
1379
1380 @item AM_ENABLE_MULTILIB
1381 This is used when a ``multilib'' library is being built.  The first
1382 optional argument is the name of the @file{Makefile} being generated; it
1383 defaults to @samp{Makefile}.  The second option argument is used to find
1384 the top source directory; it defaults to the empty string (generally
1385 this should not be used unless you are familiar with the internals).
1386 @xref{Multilibs}.
1387
1388 @item AM_C_PROTOTYPES
1389 Check to see if function prototypes are understood by the compiler.  If
1390 so, define @samp{PROTOTYPES} and set the output variables @samp{U} and
1391 @samp{ANSI2KNR} to the empty string.  Otherwise, set @samp{U} to
1392 @samp{_} and @samp{ANSI2KNR} to @samp{./ansi2knr}.  Automake uses these
1393 values to implement automatic de-ANSI-fication.
1394 @cvindex AM_C_PROTOTYPES
1395
1396 @item AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
1397 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
1398 define @code{GWINSZ_IN_SYS_IOCTL}.  Otherwise @code{TIOCGWINSZ} can be
1399 found in @file{<termios.h>}.
1400 @cvindex AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
1401
1402 @item AM_INIT_AUTOMAKE([OPTIONS])
1403 @itemx AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
1404 Runs many macros required for proper operation of the generated Makefiles.
1405
1406 This macro has two forms, the second of which has two required
1407 arguments: the package and the version number.  This latter form is
1408 obsolete because the @var{package} and @var{version} can be obtained
1409 from Autoconf's @code{AC_INIT} macro (which itself has an old and a new
1410 form).
1411
1412 If your @file{configure.in} has:
1413 @example
1414 AC_INIT(src/foo.c)
1415 AM_INIT_AUTOMAKE(mumble, 1.5)
1416 @end example
1417 you can modernize it as follow:
1418 @example
1419 AC_INIT(mumble, 1.5)
1420 AC_CONFIG_SRCDIR(src/foo.c)
1421 AM_INIT_AUTOMAKE
1422 @end example
1423
1424 Note that if you're upgrading your @file{configure.in} from an earlier
1425 version of Automake, it is not always correct to simply move the package
1426 and version arguments from @code{AM_INIT_AUTOMAKE} directly to
1427 @code{AC_INIT}, as in the example above.  The first argument of
1428 @code{AC_INIT} is the name of your package (e.g. @samp{GNU Automake}),
1429 not the tarball name (e.g. @samp{automake}) you used to pass to
1430 @code{AM_INIT_AUTOMAKE}.  Autoconf's rule to derive a tarball name from
1431 the package name should work for most but not all packages.  Especially,
1432 if your tarball name is not all lower case, you will have to use the
1433 four-argument form of @code{AC_INIT} (supported in Autoconf versions
1434 greater than 2.52g).
1435
1436 When @code{AM_INIT_AUTOMAKE} is called with a single argument, it is
1437 interpreted as a space-separated list of Automake options which should
1438 be applied to every @file{Makefile.am} in the tree.  The effect is as if
1439 each option were listed in @code{AUTOMAKE_OPTIONS}.
1440
1441 By default this macro @code{AC_DEFINE}'s @samp{PACKAGE} and
1442 @samp{VERSION}.  This can be avoided by passing the @samp{no-define}
1443 option, as in:
1444 @example
1445 AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
1446 @end example
1447 or by passing a third non-empty argument to the obsolete form.
1448
1449 @cvindex PACKAGE, prevent definition
1450 @cvindex VERSION, prevent definition
1451
1452
1453 @item AM_PATH_LISPDIR
1454 Searches for the program @code{emacs}, and, if found, sets the output
1455 variable @code{lispdir} to the full path to Emacs' site-lisp directory.
1456
1457 Note that this test assumes the @code{emacs} found to be a version that
1458 supports Emacs Lisp (such as @sc{gnu} Emacs or XEmacs).  Other emacsen
1459 can cause this test to hang (some, like old versions of MicroEmacs,
1460 start up in interactive mode, requiring @samp{C-x C-c} to exit, which
1461 is hardly obvious for a non-emacs user).  In most cases, however, you
1462 should be able to use @samp{C-c} to kill the test.  In order to avoid
1463 problems, you can set @code{EMACS} to ``no'' in the environment, or
1464 use the @samp{--with-lispdir} option to @command{configure} to
1465 explictly set the correct path (if you're sure you have an @code{emacs}
1466 that supports Emacs Lisp.
1467 @cvindex AM_PATH_LISPDIR
1468
1469 @item AM_PROG_AS
1470 Use this macro when you have assembly code in your project.  This will
1471 choose the assembler for you (by default the C compiler) and set
1472 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
1473
1474 @item AM_PROG_CC_C_O
1475 This is like @code{AC_PROG_CC_C_O}, but it generates its results in the
1476 manner required by automake.  You must use this instead of
1477 @code{AC_PROG_CC_C_O} when you need this functionality.
1478
1479 @item AM_PROG_CC_STDC
1480 If the C compiler is not in ANSI C mode by default, try to add an option
1481 to output variable @code{CC} to make it so.  This macro tries various
1482 options that select ANSI C on some system or another.  It considers the
1483 compiler to be in ANSI C mode if it handles function prototypes correctly.
1484
1485 If you use this macro, you should check after calling it whether the C
1486 compiler has been set to accept ANSI C; if not, the shell variable
1487 @code{am_cv_prog_cc_stdc} is set to @samp{no}.  If you wrote your source
1488 code in ANSI C, you can make an un-ANSIfied copy of it by using the
1489 @code{ansi2knr} option (@pxref{ANSI}).
1490
1491 @item AM_PROG_LEX
1492 @cindex HP-UX 10, lex problems
1493 @cindex lex problems with HP-UX 10
1494 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
1495 Program Checks, autoconf, The Autoconf Manual}), but uses the
1496 @code{missing} script on systems that do not have @code{lex}.
1497 @samp{HP-UX 10} is one such system.
1498
1499 @item AM_PROG_GCJ
1500 This macro finds the @code{gcj} program or causes an error.  It sets
1501 @samp{GCJ} and @samp{GCJFLAGS}.  @code{gcj} is the Java front-end to the
1502 GNU Compiler Collection.
1503 @cvindex AM_PROG_GCJ
1504
1505 @item AM_SYS_POSIX_TERMIOS
1506 @cvindex am_cv_sys_posix_termios
1507 @cindex POSIX termios headers
1508 @cindex termios POSIX headers
1509 Check to see if POSIX termios headers and functions are available on the
1510 system.  If so, set the shell variable @code{am_cv_sys_posix_termios} to
1511 @samp{yes}.  If not, set the variable to @samp{no}.
1512
1513 @item AM_WITH_DMALLOC
1514 @cvindex WITH_DMALLOC
1515 @cindex dmalloc, support for
1516 @opindex --with-dmalloc
1517 Add support for the
1518 @uref{ftp://ftp.letters.com/src/dmalloc/dmalloc.tar.gz, dmalloc}
1519 package.  If the user configures with @samp{--with-dmalloc}, then define
1520 @code{WITH_DMALLOC} and add @samp{-ldmalloc} to @code{LIBS}.
1521
1522 @item AM_WITH_REGEX
1523 @cvindex WITH_REGEX
1524 @opindex --with-regex
1525 @cindex regex package
1526 @cindex rx package
1527 Adds @samp{--with-regex} to the @code{configure} command line.  If
1528 specified (the default), then the @samp{regex} regular expression
1529 library is used, @file{regex.o} is put into @samp{LIBOBJS}, and
1530 @samp{WITH_REGEX} is defined.  If @samp{--without-regex} is given, then
1531 the @samp{rx} regular expression library is used, and @file{rx.o} is put
1532 into @samp{LIBOBJS}.
1533
1534 @end table
1535
1536 @node Private macros,  , Public macros, Macros
1537 @subsection Private macros
1538
1539 The following macros are private macros you should not call directly.
1540 They are called by the other public macros when appropriate.  Do not
1541 rely on them, as they might be changed in a future version.  Consider
1542 them as implementation details; or better, do not consider them at all:
1543 skip this section!
1544
1545 @table @code
1546 @item _AM_DEPENDENCIES
1547 @itemx AM_SET_DEPDIR
1548 @itemx AM_DEP_TRACK
1549 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
1550 These macros are used to implement automake's automatic dependency
1551 tracking scheme.  They are called automatically by automake when
1552 required, and there should be no need to invoke them manually.
1553
1554 @item AM_MAKE_INCLUDE
1555 This macro is used to discover how the user's @code{make} handles
1556 @code{include} statements.  This macro is automatically invoked when
1557 needed; there should be no need to invoke it manually.
1558
1559 @item AM_PROG_INSTALL_STRIP
1560 This is used to find a version of @code{install} which can be used to
1561 @code{strip} a program at installation time.  This macro is
1562 automatically included when required.
1563
1564 @item AM_SANITY_CHECK
1565 This checks to make sure that a file created in the build directory is
1566 newer than a file in the source directory.  This can fail on systems
1567 where the clock is set incorrectly.  This macro is automatically run
1568 from @code{AM_INIT_AUTOMAKE}.
1569
1570 @end table
1571
1572
1573
1574 @node Extending aclocal,  , Macros, configure
1575 @section Writing your own aclocal macros
1576
1577 @cindex aclocal, extending
1578 @cindex Extending aclocal
1579
1580 The @code{aclocal} program doesn't have any built-in knowledge of any
1581 macros, so it is easy to extend it with your own macros.
1582
1583 This is mostly used for libraries which want to supply their own
1584 Autoconf macros for use by other programs.  For instance the
1585 @code{gettext} library supplies a macro @code{AM_GNU_GETTEXT} which
1586 should be used by any package using @code{gettext}.  When the library is
1587 installed, it installs this macro so that @code{aclocal} will find it.
1588
1589 A file of macros should be a series of @code{AC_DEFUN}'s.  The
1590 @code{aclocal} programs also understands @code{AC_REQUIRE}, so it is
1591 safe to put each macro in a separate file.  @xref{Prerequisite Macros, ,
1592 , autoconf, The Autoconf Manual}, and @ref{Macro Definitions, , ,
1593 autoconf, The Autoconf Manual}.
1594
1595 A macro file's name should end in @file{.m4}.  Such files should be
1596 installed in @code{`aclocal --print-ac-dir`} (which usually happens to
1597 be @file{$(datadir)/aclocal}).
1598
1599
1600 @node Top level, Alternative, configure, Top
1601 @chapter The top-level @file{Makefile.am}
1602
1603 @cindex SUBDIRS, explained
1604
1605 In packages with subdirectories, the top level @file{Makefile.am} must
1606 tell Automake which subdirectories are to be built.  This is done via
1607 the @code{SUBDIRS} variable.
1608 @vindex SUBDIRS
1609
1610 The @code{SUBDIRS} macro holds a list of subdirectories in which
1611 building of various sorts can occur.  Many targets (e.g. @code{all}) in
1612 the generated @file{Makefile} will run both locally and in all specified
1613 subdirectories.  Note that the directories listed in @code{SUBDIRS} are
1614 not required to contain @file{Makefile.am}s; only @file{Makefile}s
1615 (after configuration).  This allows inclusion of libraries from packages
1616 which do not use Automake (such as @code{gettext}).  The directories
1617 mentioned in @code{SUBDIRS} must be direct children of the current
1618 directory.  For instance, you cannot put @samp{src/subdir} into
1619 @code{SUBDIRS}.
1620
1621 In packages that use subdirectories, the top-level @file{Makefile.am} is
1622 often very short.  For instance, here is the @file{Makefile.am} from the
1623 GNU Hello distribution:
1624
1625 @example
1626 EXTRA_DIST = BUGS ChangeLog.O README-alpha
1627 SUBDIRS = doc intl po src tests
1628 @end example
1629
1630 @cindex SUBDIRS, overriding
1631 @cindex Overriding SUBDIRS
1632
1633 It is possible to override the @code{SUBDIRS} variable if, like in the
1634 case of GNU @code{Inetutils}, you want to only build a subset of the
1635 entire package.  In your @file{Makefile.am} include:
1636
1637 @example
1638 SUBDIRS = @@MY_SUBDIRS@@
1639 @end example
1640
1641 Then in your @file{configure.in} you can specify:
1642
1643 @example
1644 MY_SUBDIRS="src doc lib po"
1645 AC_SUBST(MY_SUBDIRS)
1646 @end example
1647
1648 (Note that we don't use the variable name @code{SUBDIRS} in our
1649 @file{configure.in}; that would cause Automake to believe that every
1650 @file{Makefile.in} should recurse into the listed subdirectories.)
1651
1652 The upshot of this is that Automake is tricked into building the package
1653 to take the subdirs, but doesn't actually bind that list until
1654 @code{configure} is run.
1655
1656 Although the @code{SUBDIRS} macro can contain configure substitutions
1657 (e.g. @samp{@@DIRS@@}); Automake itself does not actually examine the
1658 contents of this variable.
1659
1660 If @code{SUBDIRS} is defined, then your @file{configure.in} must include
1661 @code{AC_PROG_MAKE_SET}.  When Automake invokes @code{make} in a
1662 subdirectory, it uses the value of the @code{MAKE} variable.  It passes
1663 the value of the variable @code{AM_MAKEFLAGS} to the @code{make}
1664 invocation; this can be set in @file{Makefile.am} if there are flags you
1665 must always pass to @code{make}.
1666 @vindex MAKE
1667 @vindex MAKEFLAGS
1668
1669 The use of @code{SUBDIRS} is not restricted to just the top-level
1670 @file{Makefile.am}.  Automake can be used to construct packages of
1671 arbitrary depth.
1672
1673 By default, Automake generates @file{Makefiles} which work depth-first
1674 (@samp{postfix}).  However, it is possible to change this ordering.  You
1675 can do this by putting @samp{.} into @code{SUBDIRS}.  For instance,
1676 putting @samp{.}  first will cause a @samp{prefix} ordering of
1677 directories.  All @samp{clean} targets are run in reverse order of build
1678 targets.
1679
1680 Sometimes, such as when running @code{make dist}, you want all possible
1681 subdirectories to be examined.  In this case Automake will use
1682 @code{DIST_SUBDIRS}, instead of @code{SUBDIRS}, to determine where to
1683 recurse.  This variable will also be used when the user runs
1684 @code{distclean} or @code{maintainer-clean}.  It should be set to the
1685 full list of subdirectories in the project.  If this macro is not set,
1686 Automake will attempt to set it for you.
1687
1688
1689 @node Alternative, Rebuilding, Top level, Top
1690 @chapter An Alternative Approach to Subdirectories
1691
1692 If you've ever read Peter Miller's excellent paper,
1693 @uref{http://www.pcug.org.au/~millerp/rmch/recu-make-cons-harm.html,
1694 Recursive Make Considered Harmful}, the preceding section on the use of
1695 subdirectories will probably come as unwelcome advice.  For those who
1696 haven't read the paper, Miller's main thesis is that recursive
1697 @code{make} invocations are both slow and error-prone.
1698
1699 Automake provides sufficient cross-directory support @footnote{We
1700 believe.  This work is new and there are probably warts.
1701 @xref{Introduction}, for information on reporting bugs.} to enable you
1702 to write a single @file{Makefile.am} for a complex multi-directory
1703 package.
1704
1705
1706 By default an installable file specified in a subdirectory will have its
1707 directory name stripped before installation.  For instance, in this
1708 example, the header file will be installed as
1709 @file{$(includedir)/stdio.h}:
1710
1711 @example
1712 include_HEADERS = inc/stdio.h
1713 @end example
1714
1715 @cindex nobase_
1716 @cindex Path stripping, avoiding
1717 @cindex Avoiding path stripping
1718
1719 However, the @samp{nobase_} prefix can be used to circumvent this path
1720 stripping.  In this example, the header file will be installed as
1721 @file{$(includedir)/sys/types.h}:
1722
1723 @example
1724 nobase_include_HEADERS = sys/types.h
1725 @end example
1726
1727 @cindex nobase_ and dist_ or nodist_
1728 @cindex dist_ and nobase_
1729 @cindex nodist_ and nobase_
1730
1731 @samp{nobase_} should be specified first when used in conjonction with
1732 either @samp{dist_} or @samp{nodist_} (@pxref{Dist}).  For instance:
1733
1734 @example
1735 nobase_dist_pkgdata_DATA = images/vortex.pgm
1736 @end example
1737
1738 @node Rebuilding, Programs, Alternative, Top
1739 @chapter Rebuilding Makefiles
1740
1741 Automake generates rules to automatically rebuild @file{Makefile}s,
1742 @file{configure}, and other derived files like @file{Makefile.in}.
1743
1744 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.in}, then
1745 these automatic rebuilding rules are only enabled in maintainer mode.
1746
1747 Sometimes you need to run @code{aclocal} with an argument like @code{-I}
1748 to tell it where to find @file{.m4} files.  Since sometimes @code{make}
1749 will automatically run @code{aclocal}, you need a way to specify these
1750 arguments.  You can do this by defining @code{ACLOCAL_AMFLAGS}; this
1751 holds arguments which are passed verbatim to @code{aclocal}.  This macro
1752 is only useful in the top-level @file{Makefile.am}.
1753 @vindex ACLOCAL_AMFLAGS
1754
1755
1756 @node Programs, Other objects, Rebuilding, Top
1757 @chapter Building Programs and Libraries
1758
1759 A large part of Automake's functionality is dedicated to making it easy
1760 to build programs and libraries.
1761
1762 @menu
1763 * A Program::                   Building a program
1764 * A Library::                   Building a library
1765 * A Shared Library::            Building a Libtool library
1766 * Program and Library Variables::  Variables controlling program and
1767                                 library builds
1768 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
1769 * Program variables::           Variables used when building a program
1770 * Yacc and Lex::                Yacc and Lex support
1771 * C++ Support::
1772 * Assembly Support::
1773 * Fortran 77 Support::
1774 * Java Support::
1775 * Support for Other Languages::
1776 * ANSI::                        Automatic de-ANSI-fication
1777 * Dependencies::                Automatic dependency tracking
1778 * EXEEXT::                      Support for executable extensions
1779 @end menu
1780
1781
1782 @node A Program, A Library, Programs, Programs
1783 @section Building a program
1784
1785 @subsection Introductory blathering
1786
1787 @cindex PROGRAMS, bindir
1788 @vindex bin_PROGRAMS
1789 @vindex sbin_PROGRAMS
1790 @vindex libexec_PROGRAMS
1791 @vindex pkglib_PROGRAMS
1792 @vindex noinst_PROGRAMS
1793 @vindex check_PROGRAMS
1794
1795 In a directory containing source that gets built into a program (as
1796 opposed to a library or a script), the @samp{PROGRAMS} primary is used.
1797 Programs can be installed in @code{bindir}, @code{sbindir},
1798 @code{libexecdir}, @code{pkglibdir}, or not at all (@samp{noinst}).
1799 They can also be built only for @code{make check}, in which case the
1800 prefix is @samp{check}.
1801
1802 For instance:
1803
1804 @example
1805 bin_PROGRAMS = hello
1806 @end example
1807
1808 In this simple case, the resulting @file{Makefile.in} will contain code
1809 to generate a program named @code{hello}.
1810
1811 Associated with each program are several assisting variables which are
1812 named after the program.  These variables are all optional, and have
1813 reasonable defaults.  Each variable, its use, and default is spelled out
1814 below; we use the ``hello'' example throughout.
1815
1816 The variable @code{hello_SOURCES} is used to specify which source files
1817 get built into an executable:
1818
1819 @example
1820 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
1821 @end example
1822
1823 This causes each mentioned @samp{.c} file to be compiled into the
1824 corresponding @samp{.o}.  Then all are linked to produce @file{hello}.
1825
1826 @cindex _SOURCES primary, defined
1827 @cindex SOURCES primary, defined
1828 @cindex Primary variable, SOURCES
1829
1830 If @samp{hello_SOURCES} is not specified, then it defaults to the single
1831 file @file{hello.c}; that is, the default is to compile a single C file
1832 whose base name is the name of the program itself.  (This is a terrible
1833 default but we are stuck with it for historical reasons.)
1834 @vindex _SOURCES
1835 @vindex SOURCES
1836
1837 Multiple programs can be built in a single directory.  Multiple programs
1838 can share a single source file, which must be listed in each
1839 @samp{_SOURCES} definition.
1840
1841 @cindex Header files in _SOURCES
1842 @cindex _SOURCES and header files
1843
1844 Header files listed in a @samp{_SOURCES} definition will be included in
1845 the distribution but otherwise ignored.  In case it isn't obvious, you
1846 should not include the header file generated by @file{configure} in a
1847 @samp{_SOURCES} variable; this file should not be distributed.  Lex
1848 (@samp{.l}) and Yacc (@samp{.y}) files can also be listed; see @ref{Yacc
1849 and Lex}.
1850
1851 @subsection Conditional compilations
1852
1853 You can't put a configure substitution (e.g., @samp{@@FOO@@}) into a
1854 @samp{_SOURCES} variable.  The reason for this is a bit hard to explain,
1855 but suffice to say that it simply won't work.  Automake will give an
1856 error if you try to do this.
1857
1858 @cindex EXTRA_prog_SOURCES, defined
1859
1860 Automake must know all the source files that could possibly go into a
1861 program, even if not all the files are built in every circumstance.
1862 Any files which are only conditionally built should be listed in the
1863 appropriate @samp{EXTRA_} variable.  For instance, if
1864 @file{hello-linux.c} were conditionally included in @code{hello}, the
1865 @file{Makefile.am} would contain:
1866
1867 @example
1868 EXTRA_hello_SOURCES = hello-linux.c
1869 @end example
1870
1871 In this case, @file{hello-linux.o} would be added, via a
1872 @file{configure} substitution, to @code{hello_LDADD} in order to cause
1873 it to be built and linked in.
1874
1875 An often simpler way to compile source files conditionally is to use
1876 Automake conditionals.  For instance, you could use this construct to
1877 conditionally use @file{hello-linux.c} or @file{hello-generic.c} as the
1878 basis for your program @file{hello}:
1879
1880 @example
1881 if LINUX
1882 hello_SOURCES = hello-linux.c
1883 else
1884 hello_SOURCES = hello-generic.c
1885 endif
1886 @end example
1887
1888 When using conditionals like this you don't need to use the
1889 @samp{EXTRA_} variable, because Automake will examine the contents of
1890 each variable to construct the complete list of source files.
1891
1892 Sometimes it is useful to determine the programs that are to be built at
1893 configure time.  For instance, GNU @code{cpio} only builds @code{mt} and
1894 @code{rmt} under special circumstances.
1895
1896 @cindex EXTRA_PROGRAMS, defined
1897
1898 In this case, you must notify Automake of all the programs that can
1899 possibly be built, but at the same time cause the generated
1900 @file{Makefile.in} to use the programs specified by @code{configure}.
1901 This is done by having @code{configure} substitute values into each
1902 @samp{_PROGRAMS} definition, while listing all optionally built programs
1903 in @code{EXTRA_PROGRAMS}.
1904 @vindex EXTRA_PROGRAMS
1905
1906 Of course you can use Automake conditionals to determine the programs to
1907 be built.
1908
1909 @subsection Linking the program
1910
1911 If you need to link against libraries that are not found by
1912 @code{configure}, you can use @code{LDADD} to do so.  This variable is
1913 used to specify additional objects or libraries to link with; it is
1914 inappropriate for specifying specific linker flags, you should use
1915 @code{AM_LDFLAGS} for this purpose.
1916 @vindex LDADD
1917 @vindex AM_LDFLAGS
1918
1919 @cindex prog_LDADD, defined
1920
1921 Sometimes, multiple programs are built in one directory but do not share
1922 the same link-time requirements.  In this case, you can use the
1923 @samp{@var{prog}_LDADD} variable (where @var{prog} is the name of the
1924 program as it appears in some @samp{_PROGRAMS} variable, and usually
1925 written in lowercase) to override the global @code{LDADD}.  If this
1926 variable exists for a given program, then that program is not linked
1927 using @code{LDADD}.
1928 @vindex _LDADD
1929
1930 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
1931 linked against the library @file{libcpio.a}.  However, @code{rmt} is
1932 built in the same directory, and has no such link requirement.  Also,
1933 @code{mt} and @code{rmt} are only built on certain architectures.  Here
1934 is what cpio's @file{src/Makefile.am} looks like (abridged):
1935
1936 @example
1937 bin_PROGRAMS = cpio pax @@MT@@
1938 libexec_PROGRAMS = @@RMT@@
1939 EXTRA_PROGRAMS = mt rmt
1940
1941 LDADD = ../lib/libcpio.a @@INTLLIBS@@
1942 rmt_LDADD =
1943
1944 cpio_SOURCES = @dots{}
1945 pax_SOURCES = @dots{}
1946 mt_SOURCES = @dots{}
1947 rmt_SOURCES = @dots{}
1948 @end example
1949
1950 @cindex _LDFLAGS, defined
1951
1952 @samp{@var{prog}_LDADD} is inappropriate for passing program-specific
1953 linker flags (except for @samp{-l}, @samp{-L}, @samp{-dlopen} and
1954 @samp{-dlpreopen}).  So, use the @samp{@var{prog}_LDFLAGS} variable for
1955 this purpose.
1956 @vindex _LDFLAGS
1957
1958 @cindex _DEPENDENCIES, defined
1959
1960 It is also occasionally useful to have a program depend on some other
1961 target which is not actually part of that program.  This can be done
1962 using the @samp{@var{prog}_DEPENDENCIES} variable.  Each program depends
1963 on the contents of such a variable, but no further interpretation is
1964 done.
1965
1966 If @samp{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
1967 Automake.  The automatically-assigned value is the contents of
1968 @samp{@var{prog}_LDADD}, with most configure substitutions, @samp{-l},
1969 @samp{-L}, @samp{-dlopen} and @samp{-dlpreopen} options removed.  The
1970 configure substitutions that are left in are only @samp{@@LIBOBJS@@} and
1971 @samp{@@ALLOCA@@}; these are left because it is known that they will not
1972 cause an invalid value for @samp{@var{prog}_DEPENDENCIES} to be
1973 generated.
1974
1975
1976 @node A Library, A Shared Library, A Program, Programs
1977 @section Building a library
1978
1979 @cindex _LIBRARIES primary, defined
1980 @cindex LIBRARIES primary, defined
1981 @cindex Primary variable, LIBRARIES
1982
1983 @vindex lib_LIBRARIES
1984 @vindex pkglib_LIBRARIES
1985 @vindex noinst_LIBRARIES
1986
1987 Building a library is much like building a program.  In this case, the
1988 name of the primary is @samp{LIBRARIES}.  Libraries can be installed in
1989 @code{libdir} or @code{pkglibdir}.
1990
1991 @xref{A Shared Library}, for information on how to build shared
1992 libraries using Libtool and the @samp{LTLIBRARIES} primary.
1993
1994 Each @samp{_LIBRARIES} variable is a list of the libraries to be built.
1995 For instance to create a library named @file{libcpio.a}, but not install
1996 it, you would write:
1997
1998 @example
1999 noinst_LIBRARIES = libcpio.a
2000 @end example
2001
2002 The sources that go into a library are determined exactly as they are
2003 for programs, via the @samp{_SOURCES} variables.  Note that the library
2004 name is canonicalized (@pxref{Canonicalization}), so the @samp{_SOURCES}
2005 variable corresponding to @file{liblob.a} is @samp{liblob_a_SOURCES},
2006 not @samp{liblob.a_SOURCES}.
2007
2008 @cindex _LIBADD primary, defined
2009 @cindex LIBADD primary, defined
2010 @cindex Primary variable, LIBADD
2011
2012 Extra objects can be added to a library using the
2013 @samp{@var{library}_LIBADD} variable.  This should be used for objects
2014 determined by @code{configure}.  Again from @code{cpio}:
2015 @vindex _LIBADD
2016 @vindex LIBADD
2017
2018 @example
2019 libcpio_a_LIBADD = @@LIBOBJS@@ @@ALLOCA@@
2020 @end example
2021
2022 In addition, sources for extra objects that will not exist until
2023 configure-time must be added to the @code{BUILT_SOURCES} variable
2024 (@pxref{Sources}).
2025
2026
2027 @node A Shared Library, Program and Library Variables, A Library, Programs
2028 @section Building a Shared Library
2029
2030 @cindex Shared libraries, support for
2031
2032 Building shared libraries is a relatively complex matter.  For this
2033 reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
2034 Libtool Manual}) was created to help build shared libraries in a
2035 platform-independent way.
2036
2037 @cindex _LTLIBRARIES primary, defined
2038 @cindex LTLIBRARIES primary, defined
2039 @cindex Primary variable, LTLIBRARIES
2040 @cindex Example of shared libraries
2041
2042 @cindex suffix .la, defined
2043
2044 Automake uses Libtool to build libraries declared with the
2045 @samp{LTLIBRARIES} primary.  Each @samp{_LTLIBRARIES} variable is a list
2046 of shared libraries to build.  For instance, to create a library named
2047 @file{libgettext.a} and its corresponding shared libraries, and install
2048 them in @samp{libdir}, write:
2049
2050 @example
2051 lib_LTLIBRARIES = libgettext.la
2052 @end example
2053
2054 @vindex lib_LTLIBRARIES
2055 @vindex pkglib_LTLIBRARIES
2056 @vindex noinst_LTLIBRARIES
2057 @vindex check_LTLIBRARIES
2058
2059 @cindex check_LTLIBRARIES, not allowed
2060
2061 Note that shared libraries @emph{must} be installed in order to work
2062 properly, so @code{check_LTLIBRARIES} is not allowed.  However,
2063 @code{noinst_LTLIBRARIES} is allowed.  This feature should be used for
2064 libtool ``convenience libraries''.
2065
2066 @cindex suffix .lo, defined
2067
2068 For each library, the @samp{@var{library}_LIBADD} variable contains the
2069 names of extra libtool objects (@file{.lo} files) to add to the shared
2070 library.  The @samp{@var{library}_LDFLAGS} variable contains any
2071 additional libtool flags, such as @samp{-version-info} or
2072 @samp{-static}.
2073
2074 @cindex @@LTLIBOBJS@@, special handling
2075
2076 Where an ordinary library might include @code{@@LIBOBJS@@}, a libtool
2077 library must use @code{@@LTLIBOBJS@@}.  This is required because the
2078 object files that libtool operates on do not necessarily end in
2079 @file{.o}.  The libtool manual contains more details on this topic.
2080
2081 For libraries installed in some directory, Automake will automatically
2082 supply the appropriate @samp{-rpath} option.  However, for libraries
2083 determined at configure time (and thus mentioned in
2084 @code{EXTRA_LTLIBRARIES}), Automake does not know the eventual
2085 installation directory; for such libraries you must add the
2086 @samp{-rpath} option to the appropriate @samp{_LDFLAGS} variable by
2087 hand.
2088
2089 Ordinarily, Automake requires that a shared library's name start with
2090 @samp{lib}.  However, if you are building a dynamically loadable module
2091 then you might wish to use a "nonstandard" name.  In this case, put
2092 @code{-module} into the @samp{_LDFLAGS} variable.
2093
2094 @xref{Using Automake, Using Automake with Libtool, The Libtool Manual,
2095 libtool, The Libtool Manual}, for more information.
2096
2097
2098 @node Program and Library Variables, LIBOBJS, A Shared Library, Programs
2099 @section Program and Library Variables
2100
2101 Associated with each program are a collection of variables which can be
2102 used to modify how that program is built.  There is a similar list of
2103 such variables for each library.  The canonical name of the program (or
2104 library) is used as a base for naming these variables.
2105
2106 In the list below, we use the name ``maude'' to refer to the program or
2107 library.  In your @file{Makefile.am} you would replace this with the
2108 canonical name of your program.  This list also refers to ``maude'' as a
2109 program, but in general the same rules apply for both static and dynamic
2110 libraries; the documentation below notes situations where programs and
2111 libraries differ.
2112
2113 @table @samp
2114 @item maude_SOURCES
2115 This variable, if it exists, lists all the source files which are
2116 compiled to build the program.  These files are added to the
2117 distribution by default.  When building the program, Automake will cause
2118 each source file to be compiled to a single @file{.o} file (or
2119 @file{.lo} when using libtool).  Normally these object files are named
2120 after the source file, but other factors can change this.  If a file in
2121 the @samp{_SOURCES} variable has an unrecognized extension, Automake
2122 will do one of two things with it.  If a suffix rule exists for turning
2123 files with the unrecognized extension into @file{.o} files, then
2124 automake will treat this file as it will any other source file
2125 (@pxref{Support for Other Languages}).  Otherwise, the file will be
2126 ignored as though it were a header file.
2127
2128 The prefixes @samp{dist_} and @samp{nodist_} can be used to control
2129 whether files listed in a @samp{_SOURCES} variable are distributed.
2130 @samp{dist_} is redundant, as sources are distributed by default, but it
2131 can be specified for clarity if desired.
2132
2133 It is possible to have both @samp{dist_} and @samp{nodist_} variants of
2134 a given @samp{_SOURCES} variable at once; this lets you easily
2135 distribute some files and not others, for instance:
2136
2137 @example
2138 nodist_maude_SOURCES = nodist.c
2139 dist_maude_SOURCES = dist-me.c
2140 @end example
2141
2142 By default the output file (on Unix systems, the @file{.o} file) will be
2143 put into the current build directory.  However, if the option
2144 @code{subdir-objects} is in effect in the current directory then the
2145 @file{.o} file will be put into the subdirectory named after the source
2146 file.  For instance, with @code{subdir-objects} enabled,
2147 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
2148 people prefer this mode of operation.  You can specify
2149 @code{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
2150 @cindex Subdirectory, objects in
2151 @cindex Objects in subdirectory
2152
2153
2154 @item EXTRA_maude_SOURCES
2155 Automake needs to know the list of files you intend to compile
2156 @emph{statically}.  For one thing, this is the only way Automake has of
2157 knowing what sort of language support a given @file{Makefile.in}
2158 requires.  @footnote{There are other, more obscure reasons reasons for
2159 this limitation as well.}  This means that, for example, you can't put a
2160 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
2161 variable.  If you intend to conditionally compile source files and use
2162 @file{configure} to substitute the appropriate object names into, e.g.,
2163 @samp{_LDADD} (see below), then you should list the corresponding source
2164 files in the @samp{EXTRA_} variable.
2165
2166 This variable also supports @samp{dist_} and @samp{nodist_} prefixes,
2167 e.g., @samp{nodist_EXTRA_maude_SOURCES}.
2168
2169 @item maude_AR
2170 A static library is created by default by invoking @code{$(AR) cru}
2171 followed by the name of the library and then the objects being put into
2172 the library.  You can override this by setting the @samp{_AR} variable.
2173 This is usually used with C++; some C++ compilers require a special
2174 invocation in order to instantiate all the templates which should go
2175 into a library.  For instance, the SGI C++ compiler likes this macro set
2176 like so:
2177 @example
2178 libmaude_a_AR = $(CXX) -ar -o
2179 @end example
2180
2181 @item maude_LIBADD
2182 Extra objects can be added to a static library using the @samp{_LIBADD}
2183 variable.  This should be used for objects determined by
2184 @code{configure}.  Note that @samp{_LIBADD} is not used for shared
2185 libraries; there you must use @samp{_LDADD}.
2186
2187 @item maude_LDADD
2188 Extra objects can be added to a shared library or a program by listing
2189 them in the @samp{_LDADD} variable.  This should be used for objects
2190 determined by @code{configure}.
2191
2192 @samp{_LDADD} and @samp{_LIBADD} are inappropriate for passing
2193 program-specific linker flags (except for @samp{-l}, @samp{-L},
2194 @samp{-dlopen} and @samp{-dlpreopen}).  Use the @samp{_LDFLAGS} variable
2195 for this purpose.
2196
2197 For instance, if your @file{configure.in} uses @code{AC_PATH_XTRA}, you
2198 could link your program against the X libraries like so:
2199
2200 @example
2201 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
2202 @end example
2203
2204 @item maude_LDFLAGS
2205 This variable is used to pass extra flags to the link step of a program
2206 or a shared library.
2207
2208 @item maude_LINK
2209 You can override the linker on a per-program basis.  By default the
2210 linker is chosen according to the languages used by the program.  For
2211 instance, a program that includes C++ source code would use the C++
2212 compiler to link.  The @samp{_LINK} variable must hold the name of a
2213 command which can be passed all the @file{.o} file names as arguments.
2214 Note that the name of the underlying program is @emph{not} passed to
2215 @samp{_LINK}; typically one uses @samp{$@@}:
2216
2217 @example
2218 maude_LINK = $(CCLD) -magic -o $@@
2219 @end example
2220
2221 @item maude_CFLAGS
2222 Automake allows you to set compilation flags on a per-program (or
2223 per-library) basis.  A single source file can be included in several
2224 programs, and it will potentially be compiled with different flags for
2225 each program.  This works for any language directly supported by
2226 Automake.  The flags are @samp{_CFLAGS}, @samp{_CXXFLAGS},
2227 @samp{_OBJCFLAGS}, @samp{_YFLAGS}, @samp{_CCASFLAGS}, @samp{_FFLAGS},
2228 @samp{_RFLAGS}, and @samp{_GCJFLAGS}.
2229
2230 When using a per-program compilation flag, Automake will choose a
2231 different name for the intermediate object files.  Ordinarily a file
2232 like @file{sample.c} will be compiled to produce @file{sample.o}.
2233 However, if the program's @samp{_CFLAGS} variable is set, then the
2234 object file will be named, for instance, @file{maude-sample.o}.
2235
2236 In compilations with per-program flags, the ordinary @samp{AM_} form of
2237 the flags variable is @emph{not} automatically included in the
2238 compilation (however, the user form of the variable @emph{is} included).
2239 So for instance, if you want the hypothetical @file{maude} compilations
2240 to also use the value of @samp{AM_CFLAGS}, you would need to write:
2241
2242 @example
2243 maude_CFLAGS = ... your flags ... $(AM_CFLAGS)
2244 @end example
2245
2246 @item maude_DEPENDENCIES
2247 It is also occasionally useful to have a program depend on some other
2248 target which is not actually part of that program.  This can be done
2249 using the @samp{_DEPENDENCIES} variable.  Each program depends on the
2250 contents of such a variable, but no further interpretation is done.
2251
2252 If @samp{_DEPENDENCIES} is not supplied, it is computed by Automake.
2253 The automatically-assigned value is the contents of @samp{_LDADD} or
2254 @samp{_LIBADD}, with most configure substitutions, @samp{-l}, @samp{-L},
2255 @samp{-dlopen} and @samp{-dlpreopen} options removed.  The configure
2256 substitutions that are left in are only @samp{@@LIBOBJS@@} and
2257 @samp{@@ALLOCA@@}; these are left because it is known that they will not
2258 cause an invalid value for @samp{_DEPENDENCIES} to be generated.
2259
2260 @item maude_SHORTNAME
2261 On some platforms the allowable file names are very short.  In order to
2262 support these systems and per-program compilation flags at the same
2263 time, Automake allows you to set a ``short name'' which will influence
2264 how intermediate object files are named.  For instance, if you set
2265 @samp{maude_SHORTNAME} to @samp{m}, then in the above per-program
2266 compilation flag example the object file would be named
2267 @file{m-sample.o} rather than @file{maude-sample.o}.  This facility is
2268 rarely needed in practice, and we recommend avoiding it until you find
2269 it is required.
2270 @end table
2271
2272
2273 @node LIBOBJS, Program variables, Program and Library Variables, Programs
2274 @section Special handling for LIBOBJS and ALLOCA
2275
2276 @cindex @@LIBOBJS@@, special handling
2277 @cindex @@ALLOCA@@, special handling
2278
2279 Automake explicitly recognizes the use of @code{@@LIBOBJS@@} and
2280 @code{@@ALLOCA@@}, and uses this information, plus the list of
2281 @code{LIBOBJS} files derived from @file{configure.in} to automatically
2282 include the appropriate source files in the distribution (@pxref{Dist}).
2283 These source files are also automatically handled in the
2284 dependency-tracking scheme; see @xref{Dependencies}.
2285
2286 @code{@@LIBOBJS@@} and @code{@@ALLOCA@@} are specially recognized in any
2287 @samp{_LDADD} or @samp{_LIBADD} variable.
2288
2289
2290 @node Program variables, Yacc and Lex, LIBOBJS, Programs
2291 @section Variables used when building a program
2292
2293 Occasionally it is useful to know which @file{Makefile} variables
2294 Automake uses for compilations; for instance you might need to do your
2295 own compilation in some special cases.
2296
2297 Some variables are inherited from Autoconf; these are @code{CC},
2298 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
2299 @code{LIBS}.
2300 @vindex CC
2301 @vindex CFLAGS
2302 @vindex CPPFLAGS
2303 @vindex DEFS
2304 @vindex LDFLAGS
2305 @vindex LIBS
2306
2307 There are some additional variables which Automake itself defines:
2308
2309 @vtable @code
2310 @item AM_CPPFLAGS
2311 The contents of this macro are passed to every compilation which invokes
2312 the C preprocessor; it is a list of arguments to the preprocessor.  For
2313 instance, @samp{-I} and @samp{-D} options should be listed here.
2314
2315 Automake already provides some @samp{-I} options automatically.  In
2316 particular it generates @samp{-I$(srcdir)}, @samp{-I.}, and a @samp{-I}
2317 pointing to the directory holding @file{config.h} (if you've used
2318 @code{AC_CONFIG_HEADER} or @code{AM_CONFIG_HEADER}).  You can disable
2319 the default @samp{-I} options using the @samp{nostdinc} option.
2320
2321 @item INCLUDES
2322 This does the same job as @samp{AM_CPPFLAGS}.  It is an older name for
2323 the same functionality.  This macro is deprecated; we suggest using
2324 @samp{AM_CPPFLAGS} instead.
2325
2326 @item AM_CFLAGS
2327 This is the variable which the @file{Makefile.am} author can use to pass
2328 in additional C compiler flags.  It is more fully documented elsewhere.
2329 In some situations, this is not used, in preference to the
2330 per-executable (or per-library) @code{_CFLAGS}.
2331
2332 @item COMPILE
2333 This is the command used to actually compile a C source file.  The
2334 filename is appended to form the complete command line.
2335
2336 @item AM_LDFLAGS
2337 This is the variable which the @file{Makefile.am} author can use to pass
2338 in additional linker flags.  In some situations, this is not used, in
2339 preference to the per-executable (or per-library) @code{_LDFLAGS}.
2340
2341 @item LINK
2342 This is the command used to actually link a C program.  It already
2343 includes @samp{-o $@@} and the usual variable references (for instance,
2344 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
2345 and libraries to link in.
2346 @end vtable
2347
2348
2349 @node Yacc and Lex, C++ Support, Program variables, Programs
2350 @section Yacc and Lex support
2351
2352 Automake has somewhat idiosyncratic support for Yacc and Lex.
2353
2354 Automake assumes that the @file{.c} file generated by @code{yacc} (or
2355 @code{lex}) should be named using the basename of the input file.  That
2356 is, for a yacc source file @file{foo.y}, Automake will cause the
2357 intermediate file to be named @file{foo.c} (as opposed to
2358 @file{y.tab.c}, which is more traditional).
2359
2360 The extension of a yacc source file is used to determine the extension
2361 of the resulting @samp{C} or @samp{C++} file.  Files with the extension
2362 @samp{.y} will be turned into @samp{.c} files; likewise, @samp{.yy} will
2363 become @samp{.cc}; @samp{.y++}, @samp{c++}; and @samp{.yxx},
2364 @samp{.cxx}.
2365
2366 Likewise, lex source files can be used to generate @samp{C} or
2367 @samp{C++}; the extensions @samp{.l}, @samp{.ll}, @samp{.l++}, and
2368 @samp{.lxx} are recognized.
2369
2370 You should never explicitly mention the intermediate (@samp{C} or
2371 @samp{C++}) file in any @samp{SOURCES} variable; only list the source
2372 file.
2373
2374 The intermediate files generated by @code{yacc} (or @code{lex}) will be
2375 included in any distribution that is made.  That way the user doesn't
2376 need to have @code{yacc} or @code{lex}.
2377
2378 If a @code{yacc} source file is seen, then your @file{configure.in} must
2379 define the variable @samp{YACC}.  This is most easily done by invoking
2380 the macro @samp{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
2381 Program Checks, autoconf, The Autoconf Manual}).
2382
2383 When @code{yacc} is invoked, it is passed @samp{YFLAGS} and
2384 @samp{AM_YFLAGS}.  The former is a user variable and the latter is
2385 intended for the @file{Makefile.am} author.
2386
2387 Similarly, if a @code{lex} source file is seen, then your
2388 @file{configure.in} must define the variable @samp{LEX}.  You can use
2389 @samp{AC_PROG_LEX} to do this (@pxref{Particular Programs, , Particular
2390 Program Checks, autoconf, The Autoconf Manual}), but using
2391 @code{AM_PROG_LEX} macro (@pxref{Macros}) is recommended.
2392
2393 When @code{lex} is invoked, it is passed @samp{LFLAGS} and
2394 @samp{AM_LFLAGS}.  The former is a user variable and the latter is
2395 intended for the @file{Makefile.am} author.
2396
2397
2398
2399 @cindex ylwrap
2400 @cindex yacc, multiple parsers
2401 @cindex Multiple yacc parsers
2402 @cindex Multiple lex lexers
2403 @cindex lex, multiple lexers
2404
2405
2406 Automake makes it possible to include multiple @code{yacc} (or
2407 @code{lex}) source files in a single program.  Automake uses a small
2408 program called @code{ylwrap} to run @code{yacc} (or @code{lex}) in a
2409 subdirectory.  This is necessary because yacc's output filename is
2410 fixed, and a parallel make could conceivably invoke more than one
2411 instance of @code{yacc} simultaneously.  The @code{ylwrap} program is
2412 distributed with Automake.  It should appear in the directory specified
2413 by @samp{AC_CONFIG_AUX_DIR} (@pxref{Input, , Finding `configure' Input,
2414 autoconf, The Autoconf Manual}), or the current directory if that macro
2415 is not used in @file{configure.in}.
2416
2417 For @code{yacc}, simply managing locking is insufficient.  The output of
2418 @code{yacc} always uses the same symbol names internally, so it isn't
2419 possible to link two @code{yacc} parsers into the same executable.
2420
2421 We recommend using the following renaming hack used in @code{gdb}:
2422 @example
2423 #define yymaxdepth c_maxdepth
2424 #define yyparse c_parse
2425 #define yylex   c_lex
2426 #define yyerror c_error
2427 #define yylval  c_lval
2428 #define yychar  c_char
2429 #define yydebug c_debug
2430 #define yypact  c_pact
2431 #define yyr1    c_r1
2432 #define yyr2    c_r2
2433 #define yydef   c_def
2434 #define yychk   c_chk
2435 #define yypgo   c_pgo
2436 #define yyact   c_act
2437 #define yyexca  c_exca
2438 #define yyerrflag c_errflag
2439 #define yynerrs c_nerrs
2440 #define yyps    c_ps
2441 #define yypv    c_pv
2442 #define yys     c_s
2443 #define yy_yys  c_yys
2444 #define yystate c_state
2445 #define yytmp   c_tmp
2446 #define yyv     c_v
2447 #define yy_yyv  c_yyv
2448 #define yyval   c_val
2449 #define yylloc  c_lloc
2450 #define yyreds  c_reds
2451 #define yytoks  c_toks
2452 #define yylhs   c_yylhs
2453 #define yylen   c_yylen
2454 #define yydefred c_yydefred
2455 #define yydgoto c_yydgoto
2456 #define yysindex c_yysindex
2457 #define yyrindex c_yyrindex
2458 #define yygindex c_yygindex
2459 #define yytable  c_yytable
2460 #define yycheck  c_yycheck
2461 #define yyname   c_yyname
2462 #define yyrule   c_yyrule
2463 @end example
2464
2465 For each define, replace the @samp{c_} prefix with whatever you like.
2466 These defines work for @code{bison}, @code{byacc}, and traditional
2467 @code{yacc}s.  If you find a parser generator that uses a symbol not
2468 covered here, please report the new name so it can be added to the list.
2469
2470
2471 @node C++ Support, Assembly Support, Yacc and Lex, Programs
2472 @section C++ Support
2473
2474 @cindex C++ support
2475 @cindex Support for C++
2476
2477 Automake includes full support for C++.
2478
2479 Any package including C++ code must define the output variable
2480 @samp{CXX} in @file{configure.in}; the simplest way to do this is to use
2481 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
2482 Program Checks, autoconf, The Autoconf Manual}).
2483
2484 A few additional variables are defined when a C++ source file is seen:
2485
2486 @vtable @code
2487 @item CXX
2488 The name of the C++ compiler.
2489
2490 @item CXXFLAGS
2491 Any flags to pass to the C++ compiler.
2492
2493 @item AM_CXXFLAGS
2494 The maintainer's variant of @code{CXXFLAGS}.
2495
2496 @item CXXCOMPILE
2497 The command used to actually compile a C++ source file.  The file name
2498 is appended to form the complete command line.
2499
2500 @item CXXLINK
2501 The command used to actually link a C++ program.
2502 @end vtable
2503
2504
2505 @node Assembly Support, Fortran 77 Support, C++ Support, Programs
2506 @section Assembly Support
2507
2508 Automake includes some support for assembly code.
2509
2510 The variable @code{CCAS} holds the name of the compiler used to build
2511 assembly code.  This compiler must work a bit like a C compiler; in
2512 particular it must accept @samp{-c} and @samp{-o}.  The value of
2513 @code{CCASFLAGS} is passed to the compilation.
2514 @vindex CCAS
2515 @vindex CCASFLAGS
2516
2517 You are required to set @code{CCAS} and @code{CCASFLAGS} via
2518 @file{configure.in}.  The autoconf macro @code{AM_PROG_AS} will do this
2519 for you.  Unless they are already set, it simply sets @code{CCAS} to the
2520 C compiler and @code{CCASFLAGS} to the C compiler flags.
2521
2522 Only the suffixes @samp{.s} and @samp{.S} are recognized by
2523 @code{automake} as being files containing assembly code.
2524
2525
2526 @node Fortran 77 Support, Java Support, Assembly Support, Programs
2527 @comment  node-name,  next,  previous,  up
2528 @section Fortran 77 Support
2529
2530 @cindex Fortran 77 support
2531 @cindex Support for Fortran 77
2532
2533 Automake includes full support for Fortran 77.
2534
2535 Any package including Fortran 77 code must define the output variable
2536 @samp{F77} in @file{configure.in}; the simplest way to do this is to use
2537 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
2538 Program Checks, autoconf, The Autoconf Manual}).  @xref{Fortran 77 and
2539 Autoconf}.
2540
2541 A few additional variables are defined when a Fortran 77 source file is
2542 seen:
2543
2544 @vtable @code
2545
2546 @item F77
2547 The name of the Fortran 77 compiler.
2548
2549 @item FFLAGS
2550 Any flags to pass to the Fortran 77 compiler.
2551
2552 @item AM_FFLAGS
2553 The maintainer's variant of @code{FFLAGS}.
2554
2555 @item RFLAGS
2556 Any flags to pass to the Ratfor compiler.
2557
2558 @item AM_RFLAGS
2559 The maintainer's variant of @code{RFLAGS}.
2560
2561 @item F77COMPILE
2562 The command used to actually compile a Fortran 77 source file.  The file
2563 name is appended to form the complete command line.
2564
2565 @item FLINK
2566 The command used to actually link a pure Fortran 77 program or shared
2567 library.
2568
2569 @end vtable
2570
2571 Automake can handle preprocessing Fortran 77 and Ratfor source files in
2572 addition to compiling them@footnote{Much, if not most, of the
2573 information in the following sections pertaining to preprocessing
2574 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
2575 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
2576 also contains some support for creating programs and shared libraries
2577 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
2578 Fortran 77 With C and C++}).
2579
2580 These issues are covered in the following sections.
2581
2582 @menu
2583 * Preprocessing Fortran 77::
2584 * Compiling Fortran 77 Files::
2585 * Mixing Fortran 77 With C and C++::
2586 * Fortran 77 and Autoconf::
2587 @end menu
2588
2589
2590 @node Preprocessing Fortran 77, Compiling Fortran 77 Files, Fortran 77 Support, Fortran 77 Support
2591 @comment  node-name,  next,  previous,  up
2592 @subsection Preprocessing Fortran 77
2593
2594 @cindex Preprocessing Fortran 77
2595 @cindex Fortran 77, Preprocessing
2596 @cindex Ratfor programs
2597
2598 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
2599 rule runs just the preprocessor to convert a preprocessable Fortran 77
2600 or Ratfor source file into a strict Fortran 77 source file.  The precise
2601 command used is as follows:
2602
2603 @table @file
2604
2605 @item .F
2606 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)}
2607
2608 @item .r
2609 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
2610
2611 @end table
2612
2613
2614 @node Compiling Fortran 77 Files, Mixing Fortran 77 With C and C++, Preprocessing Fortran 77, Fortran 77 Support
2615 @comment  node-name,  next,  previous,  up
2616 @subsection Compiling Fortran 77 Files
2617
2618 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
2619 @file{N.r} by running the Fortran 77 compiler.  The precise command used
2620 is as follows:
2621
2622 @table @file
2623
2624 @item .f
2625 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
2626
2627 @item .F
2628 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)}
2629
2630 @item .r
2631 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
2632
2633 @end table
2634
2635
2636 @node Mixing Fortran 77 With C and C++, Fortran 77 and Autoconf, Compiling Fortran 77 Files, Fortran 77 Support
2637 @comment  node-name,  next,  previous,  up
2638 @subsection Mixing Fortran 77 With C and C++
2639
2640 @cindex Fortran 77, mixing with C and C++
2641 @cindex Mixing Fortran 77 with C and C++
2642 @cindex Linking Fortran 77 with C and C++
2643 @cindex cfortran
2644 @cindex Mixing Fortran 77 with C and/or C++
2645
2646 Automake currently provides @emph{limited} support for creating programs
2647 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
2648 However, there are many other issues related to mixing Fortran 77 with
2649 other languages that are @emph{not} (currently) handled by Automake, but
2650 that are handled by other packages@footnote{For example,
2651 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
2652 addresses all of these inter-language issues, and runs under nearly all
2653 Fortran 77, C and C++ compilers on nearly all platforms.  However,
2654 @code{cfortran} is not yet Free Software, but it will be in the next
2655 major release.}.
2656
2657 @page
2658 Automake can help in two ways:
2659
2660 @enumerate
2661 @item
2662 Automatic selection of the linker depending on which combinations of
2663 source code.
2664
2665 @item
2666 Automatic selection of the appropriate linker flags (e.g. @samp{-L} and
2667 @samp{-l}) to pass to the automatically selected linker in order to link
2668 in the appropriate Fortran 77 intrinsic and run-time libraries.
2669
2670 @cindex FLIBS, defined
2671 These extra Fortran 77 linker flags are supplied in the output variable
2672 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro
2673 supplied with newer versions of Autoconf (Autoconf version 2.13 and
2674 later).  @xref{Fortran 77 Compiler Characteristics, , , autoconf, The
2675 Autoconf}.
2676 @end enumerate
2677
2678 If Automake detects that a program or shared library (as mentioned in
2679 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
2680 code that is a mixture of Fortran 77 and C and/or C++, then it requires
2681 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
2682 @file{configure.in}, and that either @code{$(FLIBS)} or @code{@@FLIBS@@}
2683 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
2684 (for shared libraries) variables.  It is the responsibility of the
2685 person writing the @file{Makefile.am} to make sure that @code{$(FLIBS)}
2686 or @code{@@FLIBS@@} appears in the appropriate @code{_LDADD} or
2687 @code{_LIBADD} variable.
2688
2689 @cindex Mixed language example
2690 @cindex Example, mixed language
2691
2692 For example, consider the following @file{Makefile.am}:
2693
2694 @example
2695 bin_PROGRAMS = foo
2696 foo_SOURCES  = main.cc foo.f
2697 foo_LDADD    = libfoo.la @@FLIBS@@
2698
2699 pkglib_LTLIBRARIES = libfoo.la
2700 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
2701 libfoo_la_LIBADD   = $(FLIBS)
2702 @end example
2703
2704 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
2705 is mentioned in @file{configure.in}.  Also, if @code{@@FLIBS@@} hadn't
2706 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
2707 Automake would have issued a warning.
2708
2709
2710 @page
2711 @menu
2712 * How the Linker is Chosen::
2713 @end menu
2714
2715 @node How the Linker is Chosen,  , Mixing Fortran 77 With C and C++, Mixing Fortran 77 With C and C++
2716 @comment  node-name,  next,  previous,  up
2717 @subsubsection How the Linker is Chosen
2718
2719 @cindex Automatic linker selection
2720 @cindex Selecting the linker automatically
2721
2722 The following diagram demonstrates under what conditions a particular
2723 linker is chosen by Automake.
2724
2725 For example, if Fortran 77, C and C++ source code were to be compiled
2726 into a program, then the C++ linker will be used.  In this case, if the
2727 C or Fortran 77 linkers required any special libraries that weren't
2728 included by the C++ linker, then they must be manually added to an
2729 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
2730 @file{Makefile.am}.
2731
2732 @example
2733                      \              Linker
2734           source      \
2735            code        \     C        C++     Fortran
2736      -----------------  +---------+---------+---------+
2737                         |         |         |         |
2738      C                  |    x    |         |         |
2739                         |         |         |         |
2740                         +---------+---------+---------+
2741                         |         |         |         |
2742          C++            |         |    x    |         |
2743                         |         |         |         |
2744                         +---------+---------+---------+
2745                         |         |         |         |
2746                Fortran  |         |         |    x    |
2747                         |         |         |         |
2748                         +---------+---------+---------+
2749                         |         |         |         |
2750      C + C++            |         |    x    |         |
2751                         |         |         |         |
2752                         +---------+---------+---------+
2753                         |         |         |         |
2754      C +       Fortran  |         |         |    x    |
2755                         |         |         |         |
2756                         +---------+---------+---------+
2757                         |         |         |         |
2758          C++ + Fortran  |         |    x    |         |
2759                         |         |         |         |
2760                         +---------+---------+---------+
2761                         |         |         |         |
2762      C + C++ + Fortran  |         |    x    |         |
2763                         |         |         |         |
2764                         +---------+---------+---------+
2765 @end example
2766
2767
2768 @node Fortran 77 and Autoconf,  , Mixing Fortran 77 With C and C++, Fortran 77 Support
2769 @comment  node-name,  next,  previous,  up
2770 @subsection Fortran 77 and Autoconf
2771
2772 The current Automake support for Fortran 77 requires a recent enough
2773 version of Autoconf that also includes support for Fortran 77.  Full
2774 Fortran 77 support was added to Autoconf 2.13, so you will want to use
2775 that version of Autoconf or later.
2776
2777
2778 @node Java Support, Support for Other Languages, Fortran 77 Support, Programs
2779 @comment  node-name,  next,  previous,  up
2780 @section Java Support
2781
2782 @cindex Java support
2783 @cindex Support for Java
2784
2785 Automake includes support for compiled Java, using @code{gcj}, the Java
2786 front end to the GNU Compiler Collection.
2787
2788 Any package including Java code to be compiled must define the output
2789 variable @samp{GCJ} in @file{configure.in}; the variable @samp{GCJFLAGS}
2790 must also be defined somehow (either in @file{configure.in} or
2791 @file{Makefile.am}).  The simplest way to do this is to use the
2792 @code{AM_PROG_GCJ} macro.
2793
2794 @vindex GCJFLAGS
2795
2796 By default, programs including Java source files are linked with
2797 @code{gcj}.
2798
2799 As always, the contents of @samp{AM_GCJFLAGS} are passed to every
2800 compilation invoking @code{gcj} (in its role as an ahead-of-time
2801 compiler -- when invoking it to create @file{.class} files,
2802 @samp{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
2803 options to @code{gcj} from @file{Makefile.am}, this macro, and not the
2804 user macro @samp{GCJFLAGS}, should be used.
2805
2806 @vindex AM_GCJFLAGS
2807
2808 @code{gcj} can be used to compile @file{.java}, @file{.class},
2809 @file{.zip}, or @file{.jar} files.
2810
2811
2812 @node Support for Other Languages, ANSI, Java Support, Programs
2813 @comment  node-name,  next,  previous,  up
2814 @section Support for Other Languages
2815
2816 Automake currently only includes full support for C, C++ (@pxref{C++
2817 Support}), Fortran 77 (@pxref{Fortran 77 Support}), and Java
2818 (@pxref{Java Support}).  There is only rudimentary support for other
2819 languages, support for which will be improved based on user demand.
2820
2821 Some limited support for adding your own languages is available via the
2822 suffix rule handling; see @ref{Suffixes}.
2823
2824
2825 @node ANSI, Dependencies, Support for Other Languages, Programs
2826 @section Automatic de-ANSI-fication
2827
2828 @cindex de-ANSI-fication, defined
2829
2830 Although the GNU standards allow the use of ANSI C, this can have the
2831 effect of limiting portability of a package to some older compilers
2832 (notably the SunOS C compiler).
2833
2834 Automake allows you to work around this problem on such machines by
2835 @dfn{de-ANSI-fying} each source file before the actual compilation takes
2836 place.
2837
2838 @vindex AUTOMAKE_OPTIONS
2839 @opindex ansi2knr
2840
2841 If the @file{Makefile.am} variable @code{AUTOMAKE_OPTIONS}
2842 (@pxref{Options}) contains the option @code{ansi2knr} then code to
2843 handle de-ANSI-fication is inserted into the generated
2844 @file{Makefile.in}.
2845
2846 This causes each C source file in the directory to be treated as ANSI C.
2847 If an ANSI C compiler is available, it is used.  If no ANSI C compiler
2848 is available, the @code{ansi2knr} program is used to convert the source
2849 files into K&R C, which is then compiled.
2850
2851 The @code{ansi2knr} program is simple-minded.  It assumes the source
2852 code will be formatted in a particular way; see the @code{ansi2knr} man
2853 page for details.
2854
2855 Support for de-ANSI-fication requires the source files @file{ansi2knr.c}
2856 and @file{ansi2knr.1} to be in the same package as the ANSI C source;
2857 these files are distributed with Automake.  Also, the package
2858 @file{configure.in} must call the macro @code{AM_C_PROTOTYPES}
2859 (@pxref{Macros}).
2860 @cvindex AM_C_PROTOTYPES
2861
2862 Automake also handles finding the @code{ansi2knr} support files in some
2863 other directory in the current package.  This is done by prepending the
2864 relative path to the appropriate directory to the @code{ansi2knr}
2865 option.  For instance, suppose the package has ANSI C code in the
2866 @file{src} and @file{lib} subdirs.  The files @file{ansi2knr.c} and
2867 @file{ansi2knr.1} appear in @file{lib}.  Then this could appear in
2868 @file{src/Makefile.am}:
2869
2870 @example
2871 AUTOMAKE_OPTIONS = ../lib/ansi2knr
2872 @end example
2873
2874 If no directory prefix is given, the files are assumed to be in the
2875 current directory.
2876
2877 Files mentioned in @code{LIBOBJS} which need de-ANSI-fication will not
2878 be automatically handled.  That's because @code{configure} will generate
2879 an object name like @file{regex.o}, while @code{make} will be looking
2880 for @file{regex_.o} (when de-ANSI-fying).  Eventually this problem will
2881 be fixed via @code{autoconf} magic, but for now you must put this code
2882 into your @file{configure.in}, just before the @code{AC_OUTPUT} call:
2883
2884 @example
2885 # This is necessary so that .o files in LIBOBJS are also built via
2886 # the ANSI2KNR-filtering rules.
2887 LIBOBJS=`echo $LIBOBJS|sed 's/\.o /\$U.o /g;s/\.o$/\$U.o/'`
2888 @end example
2889 @c FIXME: Ask Akim how this should be handled in the upcoming Autoconf.
2890
2891 Note that automatic de-ANSI-fication will not work when the package is
2892 being built for a different host architecture.  That is because automake
2893 currently has no way to build @code{ansi2knr} for the build machine.
2894
2895
2896 @node Dependencies, EXEEXT, ANSI, Programs
2897 @section Automatic dependency tracking
2898
2899 As a developer it is often painful to continually update the
2900 @file{Makefile.in} whenever the include-file dependencies change in a
2901 project.  Automake supplies a way to automatically track dependency
2902 changes.
2903
2904 @cindex Dependency tracking
2905 @cindex Automatic dependency tracking
2906
2907 Automake always uses complete dependencies for a compilation, including
2908 system headers.  Automake's model is that dependency computation should
2909 be a side effect of the build.  To this end, dependencies are computed
2910 by running all compilations through a special wrapper program called
2911 @code{depcomp}.  @code{depcomp} understands how to coax many different C
2912 and C++ compilers into generating dependency information in the format
2913 it requires.  @code{automake -a} will install @code{depcomp} into your
2914 source tree for you.  If @code{depcomp} can't figure out how to properly
2915 invoke your compiler, dependency tracking will simply be disabled for
2916 your build.
2917
2918 @cindex depcomp
2919
2920 Experience with earlier versions of Automake @footnote{See
2921 @uref{http://sources.redhat.com/automake/dependencies.html} for more
2922 information on the history and experiences with automatic dependency
2923 tracking in Automake} taught us that it is not reliable to generate
2924 dependencies only on the maintainer's system, as configurations vary too
2925 much.  So instead Automake implements dependency tracking at build time.
2926
2927 Automatic dependency tracking can be suppressed by putting
2928 @code{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
2929 passing @code{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
2930 (this should be the prefered way).  Or, you can invoke @code{automake}
2931 with the @code{-i} option.  Dependency tracking is enabled by default.
2932
2933 @vindex AUTOMAKE_OPTIONS
2934 @opindex no-dependencies
2935
2936 The person building your package also can choose to disable dependency
2937 tracking by configuring with @code{--disable-dependency-tracking}.
2938
2939 @cindex Disabling dependency tracking
2940 @cindex Dependency tracking, disabling
2941
2942
2943 @node EXEEXT,  , Dependencies, Programs
2944 @section Support for executable extensions
2945
2946 @cindex Executable extension
2947 @cindex Extension, executable
2948 @cindex Windows
2949
2950 On some platforms, such as Windows, executables are expected to have an
2951 extension such as @samp{.exe}.  On these platforms, some compilers (GCC
2952 among them) will automatically generate @file{foo.exe} when asked to
2953 generate @file{foo}.
2954
2955 Automake provides mostly-transparent support for this.  Unfortunately
2956 @emph{mostly} doesn't yet mean @emph{fully}.  Until the English
2957 dictionary is revised, you will have to assist Automake if your package
2958 must support those platforms.
2959
2960 One thing you must be aware of is that, internally, Automake rewrites
2961 something like this:
2962
2963 @example
2964 bin_PROGRAMS = liver
2965 @end example
2966
2967 to this:
2968
2969 @example
2970 bin_PROGRAMS = liver$(EXEEXT)
2971 @end example
2972
2973 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
2974 extension.  @code{EXEEXT}
2975
2976 However, Automake cannot apply this rewriting to @code{configure}
2977 substitutions.  This means that if you are conditionally building a
2978 program using such a substitution, then your @file{configure.in} must
2979 take care to add @samp{$(EXEEXT)} when constructing the output variable.
2980
2981 With Autoconf 2.13 and earlier, you must explicitly use @code{AC_EXEEXT}
2982 to get this support.  With Autoconf 2.50, @code{AC_EXEEXT} is run
2983 automatically if you configure a compiler (say, through
2984 @code{AC_PROG_CC}).
2985
2986 Sometimes maintainers like to write an explicit link rule for their
2987 program.  Without executable extension support, this is easy---you
2988 simply write a target with the same name as the program.  However, when
2989 executable extension support is enabled, you must instead add the
2990 @samp{$(EXEEXT)} suffix.
2991
2992 Unfortunately, due to the change in Autoconf 2.50, this means you must
2993 always add this extension.  However, this is a problem for maintainers
2994 who know their package will never run on a platform that has executable
2995 extensions.  For those maintainers, the @code{no-exeext} option
2996 (@pxref{Options}) will disable this feature.  This works in a fairly
2997 ugly way; if @code{no-exeext} is seen, then the presence of a target
2998 named @code{foo} in @file{Makefile.am} will override an
2999 automake-generated target of the form @code{foo$(EXEEXT)}.  Without the
3000 @code{no-exeext} option, this use will give an error.
3001
3002
3003 @node Other objects, Other GNU Tools, Programs, Top
3004 @chapter Other Derived Objects
3005
3006 Automake can handle derived objects which are not C programs.  Sometimes
3007 the support for actually building such objects must be explicitly
3008 supplied, but Automake will still automatically handle installation and
3009 distribution.
3010
3011 @menu
3012 * Scripts::                     Executable scripts
3013 * Headers::                     Header files
3014 * Data::                        Architecture-independent data files
3015 * Sources::                     Derived sources
3016 @end menu
3017
3018
3019 @node Scripts, Headers, Other objects, Other objects
3020 @section Executable Scripts
3021
3022 @cindex _SCRIPTS primary, defined
3023 @cindex SCRIPTS primary, defined
3024 @cindex Primary variable, SCRIPTS
3025
3026 It is possible to define and install programs which are scripts.  Such
3027 programs are listed using the @samp{SCRIPTS} primary name.  Automake
3028 doesn't define any dependencies for scripts; the @file{Makefile.am}
3029 should include the appropriate rules.
3030 @vindex SCRIPTS
3031
3032 Automake does not assume that scripts are derived objects; such objects
3033 must be deleted by hand (@pxref{Clean}).
3034
3035 The @code{automake} program itself is a Perl script that is generated at
3036 configure time from @file{automake.in}.  Here is how this is handled:
3037
3038 @example
3039 bin_SCRIPTS = automake
3040 @end example
3041
3042 Since @code{automake} appears in the @code{AC_OUTPUT} macro, a target
3043 for it is automatically generated, and it is also automatically cleaned
3044 (despite the fact it's a script).
3045
3046 @cindex SCRIPTS, installation directories
3047 @cindex Installing scripts
3048
3049 @vindex bin_SCRIPTS
3050 @vindex sbin_SCRIPTS
3051 @vindex libexec_SCRIPTS
3052 @vindex pkgdata_SCRIPTS
3053 @vindex noinst_SCRIPTS
3054 @vindex check_SCRIPTS
3055
3056 Script objects can be installed in @code{bindir}, @code{sbindir},
3057 @code{libexecdir}, or @code{pkgdatadir}.
3058
3059 Scripts that need not being installed can be listed in
3060 @code{noinst_SCRIPTS}, and among them, those which are needed only by
3061 @code{make check} should go in @code{check_SCRIPTS}.
3062
3063
3064 @node Headers, Data, Scripts, Other objects
3065 @section Header files
3066
3067 @cindex _HEADERS primary, defined
3068 @cindex HEADERS primary, defined
3069 @cindex Primary variable, HEADERS
3070
3071 @vindex noinst_HEADERS
3072
3073 Header files are specified by the @samp{HEADERS} family of variables.
3074 Generally header files are not installed, so the @code{noinst_HEADERS}
3075 variable will be the most used.  @footnote{However, for the case of a
3076 non-installed header file that is actually used by a particular program,
3077 we recommend listing it in the program's @samp{_SOURCES} variable
3078 instead of in @code{noinst_HEADERS}.  We believe this is more clear.}
3079 @vindex HEADERS
3080
3081 All header files must be listed somewhere; missing ones will not appear
3082 in the distribution.  Often it is clearest to list uninstalled headers
3083 with the rest of the sources for a program.  @xref{A Program}.  Headers
3084 listed in a @samp{_SOURCES} variable need not be listed in any
3085 @samp{_HEADERS} variable.
3086
3087 @cindex HEADERS, installation directories
3088 @cindex Installing headers
3089
3090 @vindex include_HEADERS
3091 @vindex oldinclude_HEADERS
3092 @vindex pkginclude_HEADERS
3093
3094 Headers can be installed in @code{includedir}, @code{oldincludedir}, or
3095 @code{pkgincludedir}.
3096
3097
3098 @node Data, Sources, Headers, Other objects
3099 @section Architecture-independent data files
3100
3101 @cindex _DATA primary, defined
3102 @cindex DATA primary, defined
3103 @cindex Primary variable, DATA
3104
3105 Automake supports the installation of miscellaneous data files using the
3106 @samp{DATA} family of variables.
3107 @vindex DATA
3108
3109 @vindex data_DATA
3110 @vindex sysconf_DATA
3111 @vindex sharedstate_DATA
3112 @vindex localstate_DATA
3113 @vindex pkgdata_DATA
3114
3115 Such data can be installed in the directories @code{datadir},
3116 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
3117 @code{pkgdatadir}.
3118
3119 By default, data files are @emph{not} included in a distribution.  Of
3120 course, you can use the @samp{dist_} prefix to change this on a
3121 per-variable basis.
3122
3123 Here is how Automake declares its auxiliary data files:
3124
3125 @example
3126 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
3127 @end example
3128
3129
3130 @node Sources,  , Data, Other objects
3131 @section Built sources
3132
3133 @cindex BUILT_SOURCES, defined
3134
3135 Occasionally a file which would otherwise be called @samp{source}
3136 (e.g. a C @samp{.h} file) is actually derived from some other file.
3137 Such files should be listed in the @code{BUILT_SOURCES} variable.
3138 @vindex BUILT_SOURCES
3139
3140 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
3141 must be created early in the build process can be listed in this
3142 variable.
3143
3144 A source file listed in @code{BUILT_SOURCES} is created before the other
3145 @code{all} targets are made.  However, such a source file is not
3146 compiled unless explicitly requested by mentioning it in some other
3147 @samp{_SOURCES} variable.
3148
3149 So, for instance, if you had header files which were created by a script
3150 run at build time, then you would list these headers in
3151 @code{BUILT_SOURCES}, to ensure that they would be built before any
3152 other compilations (perhaps ones using these headers) were started.
3153
3154
3155 @node Other GNU Tools, Documentation, Other objects, Top
3156 @chapter Other GNU Tools
3157
3158 Since Automake is primarily intended to generate @file{Makefile.in}s for
3159 use in GNU programs, it tries hard to interoperate with other GNU tools.
3160
3161 @menu
3162 * Emacs Lisp::                  Emacs Lisp
3163 * gettext::                     Gettext
3164 * Libtool::                     Libtool
3165 * Java::                        Java
3166 * Python::                      Python
3167 @end menu
3168
3169
3170 @node Emacs Lisp, gettext, Other GNU Tools, Other GNU Tools
3171 @section Emacs Lisp
3172
3173 @cindex _LISP primary, defined
3174 @cindex LISP primary, defined
3175 @cindex Primary variable, LISP
3176
3177 @vindex LISP
3178 @vindex lisp_LISP
3179 @vindex noinst_LISP
3180
3181 Automake provides some support for Emacs Lisp.  The @samp{LISP} primary
3182 is used to hold a list of @file{.el} files.  Possible prefixes for this
3183 primary are @samp{lisp_} and @samp{noinst_}.  Note that if
3184 @code{lisp_LISP} is defined, then @file{configure.in} must run
3185 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
3186
3187 @vindex ELCFILES
3188
3189 By default Automake will byte-compile all Emacs Lisp source files using
3190 the Emacs found by @code{AM_PATH_LISPDIR}.  If you wish to avoid
3191 byte-compiling, simply define the variable @code{ELCFILES} to be empty.
3192 Byte-compiled Emacs Lisp files are not portable among all versions of
3193 Emacs, so it makes sense to turn this off if you expect sites to have
3194 more than one version of Emacs installed.  Furthermore, many packages
3195 don't actually benefit from byte-compilation.  Still, we recommend that
3196 you leave it enabled by default.  It is probably better for sites with
3197 strange setups to cope for themselves than to make the installation less
3198 nice for everybody else.
3199
3200
3201 @node gettext, Libtool, Emacs Lisp, Other GNU Tools
3202 @section Gettext
3203
3204 @cindex GNU Gettext support
3205 @cindex Gettext support
3206 @cindex Support for GNU Gettext
3207
3208 If @code{AM_GNU_GETTEXT} is seen in @file{configure.in}, then Automake
3209 turns on support for GNU gettext, a message catalog system for
3210 internationalization
3211 (@pxref{GNU Gettext, , , gettext, GNU gettext utilities}).
3212
3213 The @code{gettext} support in Automake requires the addition of two
3214 subdirectories to the package, @file{intl} and @file{po}.  Automake
3215 insures that these directories exist and are mentioned in
3216 @code{SUBDIRS}.
3217
3218
3219 @node Libtool, Java, gettext, Other GNU Tools
3220 @section Libtool
3221
3222 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
3223 libtool, The Libtool Manual}) with the @samp{LTLIBRARIES} primary.
3224 @xref{A Shared Library}.
3225
3226
3227 @node Java, Python, Libtool, Other GNU Tools
3228 @section Java
3229
3230 @cindex _JAVA primary, defined
3231 @cindex JAVA primary, defined
3232 @cindex Primary variable, JAVA
3233
3234 Automake provides some minimal support for Java compilation with the
3235 @samp{JAVA} primary.
3236
3237 Any @file{.java} files listed in a @samp{_JAVA} variable will be
3238 compiled with @code{JAVAC} at build time.  By default, @file{.class}
3239 files are not included in the distribution.
3240
3241 @cindex JAVA restrictions
3242 @cindex Restrictions for JAVA
3243
3244 Currently Automake enforces the restriction that only one @samp{_JAVA}
3245 primary can be used in a given @file{Makefile.am}.  The reason for this
3246 restriction is that, in general, it isn't possible to know which
3247 @file{.class} files were generated from which @file{.java} files -- so
3248 it would be impossible to know which files to install where.  For
3249 instance, a @file{.java} file can define multiple classes; the resulting
3250 @file{.class} file names cannot be predicted without parsing the
3251 @file{.java} file.
3252
3253 There are a few variables which are used when compiling Java sources:
3254
3255 @vtable @code
3256 @item JAVAC
3257 The name of the Java compiler.  This defaults to @samp{javac}.
3258
3259 @item JAVACFLAGS
3260 The flags to pass to the compiler.  This is considered to be a user
3261 variable (@pxref{User Variables}).
3262
3263 @item AM_JAVACFLAGS
3264 More flags to pass to the Java compiler.  This, and not
3265 @code{JAVACFLAGS}, should be used when it is necessary to put Java
3266 compiler flags into @file{Makefile.am}.
3267
3268 @item JAVAROOT
3269 The value of this variable is passed to the @samp{-d} option to
3270 @code{javac}.  It defaults to @samp{$(top_builddir)}.
3271
3272 @item CLASSPATH_ENV
3273 This variable is an @code{sh} expression which is used to set the
3274 @code{CLASSPATH} environment variable on the @code{javac} command line.
3275 (In the future we will probably handle class path setting differently.)
3276 @end vtable
3277
3278
3279 @node Python,  , Java, Other GNU Tools
3280 @section Python
3281
3282 @cindex _PYTHON primary, defined
3283 @cindex PYTHON primary, defined
3284 @cindex Primary variable, PYTHON
3285
3286
3287 Automake provides support for Python compilation with the @samp{PYTHON}
3288 primary.
3289
3290 Any files listed in a @samp{_PYTHON} variable will be byte-compiled with
3291 @code{py-compile} at install time.  @code{py-compile} actually creates
3292 both standard (@file{.pyc}) and byte-compiled (@file{.pyo}) versions of
3293 the source files.  Note that because byte-compilation occurs at install
3294 time, any files listed in @samp{noinst_PYTHON} will not be compiled.
3295 Python source files are included in the distribution by default.
3296
3297 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON} which
3298 will determine some Python-related directory variables (see below).  If
3299 have called @code{AM_PATH_PYTHON} from you @file{configure.in}, then you
3300 may use the following variables to list you Python source files in your
3301 variables: @samp{python_PYTHON}, @samp{pkgpython_PYTHON},
3302 @samp{pkgpython_PYTHON}, @samp{pyexecdir_PYTHON},
3303 @samp{pkgpyexecdir_PYTHON}, depending where you want your files
3304 installed.
3305
3306 @code{AM_PATH_PYTHON} takes a single optional argument.  This argument,
3307 if present, is the minimum version of Python which can be used for this
3308 package.  If the version of Python found on the system is older than the
3309 required version, then @code{AM_PATH_PYTHON} will cause an error.
3310
3311 @code{AM_PATH_PYTHON} creates several output variables based on the
3312 Python installation found during configuration.
3313
3314 @vtable @code
3315 @item PYTHON
3316 The name of the Python executable.
3317
3318 @item PYTHON_VERSION
3319 The Python version number, in the form @var{major}.@var{minor}
3320 (e.g. @samp{1.5}).  This is currently the value of
3321 @code{sys.version[:3]}.
3322
3323 @item PYTHON_PREFIX
3324 The string @code{$prefix}.  This term may be used in future work
3325 which needs the contents of Python's @code{sys.prefix}, but general
3326 consensus is to always use the value from configure.
3327
3328 @item PYTHON_EXEC_PREFIX
3329 The string @code{$exec_prefix}.  This term may be used in future work
3330 which needs the contents of Python's @code{sys.exec_prefix}, but general
3331 consensus is to always use the value from configure.
3332
3333 @item PYTHON_PLATFORM
3334 The canonical name used by Python to describe the operating system, as
3335 given by @code{sys.platform}.  This value is sometimes needed when
3336 building Python extensions.
3337
3338 @item pythondir
3339 The directory name for the @file{site-packages} subdirectory of the
3340 standard Python install tree.
3341
3342 @item pkgpythondir
3343 This is is the directory under @code{pythondir} which is named after the
3344 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
3345 as a convenience.
3346
3347 @item pyexecdir
3348 This is the directory where Python extension modules (shared libraries)
3349 should be installed.
3350
3351 @item pkgpyexecdir
3352 This is a convenience variable which is defined as
3353 @samp{$(pyexecdir)/$(PACKAGE)}.
3354 @end vtable
3355
3356
3357 @node Documentation, Install, Other GNU Tools, Top
3358 @chapter Building documentation
3359
3360 Currently Automake provides support for Texinfo and man pages.
3361
3362 @menu
3363 * Texinfo::                     Texinfo
3364 * Man pages::                   Man pages
3365 @end menu
3366
3367
3368 @node Texinfo, Man pages, Documentation, Documentation
3369 @section Texinfo
3370
3371 @cindex _TEXINFOS primary, defined
3372 @cindex TEXINFOS primary, defined
3373 @cindex Primary variable, TEXINFOS
3374
3375 If the current directory contains Texinfo source, you must declare it
3376 with the @samp{TEXINFOS} primary.  Generally Texinfo files are converted
3377 into info, and thus the @code{info_TEXINFOS} macro is most commonly used
3378 here.  Any Texinfo source file must end in the @file{.texi},
3379 @file{.txi}, or @file{.texinfo} extension.  We recommend @file{.texi}
3380 for new manuals.
3381 @vindex TEXINFOS
3382 @vindex info_TEXINFOS
3383
3384 @cindex Texinfo macro, VERSION
3385 @cindex Texinfo macro, UPDATED
3386 @cindex Texinfo macro, EDITION
3387 @cindex Texinfo macro, UPDATED-MONTH
3388
3389 @cindex VERSION Texinfo macro
3390 @cindex UPDATED Texinfo macro
3391 @cindex EDITION Texinfo macro
3392 @cindex UPDATED-MONTH Texinfo macro
3393
3394 @cindex mdate-sh
3395
3396 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
3397 that file will be automatically generated.  The file @file{version.texi}
3398 defines four Texinfo macros you can reference:
3399
3400 @table @code
3401 @item EDITION
3402 @itemx VERSION
3403 Both of these macros hold the version number of your program.  They are
3404 kept separate for clarity.
3405
3406 @item UPDATED
3407 This holds the date the primary @file{.texi} file was last modified.
3408
3409 @item UPDATED-MONTH
3410 This holds the name of the month in which the primary @file{.texi} file
3411 was last modified.
3412 @end table
3413
3414 The @file{version.texi} support requires the @code{mdate-sh} program;
3415 this program is supplied with Automake and automatically included when
3416 @code{automake} is invoked with the @code{--add-missing} option.
3417
3418 If you have multiple Texinfo files, and you want to use the
3419 @file{version.texi} feature, then you have to have a separate version
3420 file for each Texinfo file.  Automake will treat any include in a
3421 Texinfo file that matches @samp{vers*.texi} just as an automatically
3422 generated version file.
3423
3424 When an info file is rebuilt, the program named by the @code{MAKEINFO}
3425 variable is used to invoke it.  If the @code{makeinfo} program is found
3426 on the system then it will be used by default; otherwise @code{missing}
3427 will be used instead.  The flags in the variables @code{MAKEINFOFLAGS}
3428 and @code{AM_MAKEINFOFLAGS} will be passed to the @code{makeinfo}
3429 invocation; the first of these is intended for use by the user
3430 (@pxref{User Variables}) and the second by the @file{Makefile.am}
3431 writer.
3432 @vindex MAKEINFO
3433 @vindex MAKEINFOFLAGS
3434 @vindex AM_MAKEINFOFLAGS
3435
3436 Sometimes an info file actually depends on more than one @file{.texi}
3437 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
3438 @file{gpl.texi}.  You can tell Automake about these dependencies using
3439 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
3440 @vindex TEXINFOS
3441 @vindex _TEXINFOS
3442
3443 @example
3444 info_TEXINFOS = hello.texi
3445 hello_TEXINFOS = gpl.texi
3446 @end example
3447
3448 @cindex texinfo.tex
3449
3450 By default, Automake requires the file @file{texinfo.tex} to appear in
3451 the same directory as the Texinfo source.  However, if you used
3452 @code{AC_CONFIG_AUX_DIR} in @file{configure.in} (@pxref{Input, , Finding
3453 `configure' Input, autoconf, The Autoconf Manual}), then
3454 @file{texinfo.tex} is looked for there.  Automake supplies
3455 @file{texinfo.tex} if @samp{--add-missing} is given.
3456
3457 @vindex TEXINFO_TEX
3458
3459 If your package has Texinfo files in many directories, you can use the
3460 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
3461 @file{texinfo.tex} for your package.  The value of this variable should
3462 be the relative path from the current @file{Makefile.am} to
3463 @file{texinfo.tex}:
3464
3465 @example
3466 TEXINFO_TEX = ../doc/texinfo.tex
3467 @end example
3468
3469 @opindex no-texinfo.tex
3470
3471 The option @samp{no-texinfo.tex} can be used to eliminate the
3472 requirement for @file{texinfo.tex}.  Use of the variable
3473 @code{TEXINFO_TEX} is preferable, however, because that allows the
3474 @code{dvi} target to still work.
3475
3476 @cindex Target, install-info
3477 @cindex Target, noinstall-info
3478 @cindex install-info target
3479 @cindex noinstall-info target
3480
3481 @opindex no-installinfo
3482 @trindex install-info
3483
3484 Automake generates an @code{install-info} target; some people apparently
3485 use this.  By default, info pages are installed by @samp{make install}.
3486 This can be prevented via the @code{no-installinfo} option.
3487
3488
3489 @node Man pages,  , Texinfo, Documentation
3490 @section Man pages
3491
3492 @cindex _MANS primary, defined
3493 @cindex MANS primary, defined
3494 @cindex Primary variable, MANS
3495
3496 A package can also include man pages (but see the GNU standards on this
3497 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
3498 pages are declared using the @samp{MANS} primary.  Generally the
3499 @code{man_MANS} macro is used.  Man pages are automatically installed in
3500 the correct subdirectory of @code{mandir}, based on the file extension.
3501 @vindex MANS
3502 @vindex man_MANS
3503
3504 File extensions such as @samp{.1c} are handled by looking for the valid
3505 part of the extension and using that to determine the correct
3506 subdirectory of @code{mandir}.  Valid section names are the digits
3507 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
3508
3509 Sometimes developers prefer to name a man page something like
3510 @file{foo.man} in the source, and then rename it to have the correct
3511 suffix, e.g. @file{foo.1}, when installing the file.  Automake also
3512 supports this mode.  For a valid section named @var{SECTION}, there is a
3513 corresponding directory named @samp{man@var{SECTION}dir}, and a
3514 corresponding @samp{_MANS} variable.  Files listed in such a variable
3515 are installed in the indicated section.  If the file already has a
3516 valid suffix, then it is installed as-is; otherwise the file suffix is
3517 changed to match the section.
3518
3519 For instance, consider this example:
3520 @example
3521 man1_MANS = rename.man thesame.1 alsothesame.1c
3522 @end example
3523
3524 In this case, @file{rename.man} will be renamed to @file{rename.1} when
3525 installed, but the other files will keep their names.
3526
3527 @cindex Target, install-man
3528 @cindex Target, noinstall-man
3529 @cindex install-man target
3530 @cindex noinstall-man target
3531
3532 @c Use @samp{make install} per documentation: (texi)code.
3533 By default, man pages are installed by @samp{make install}.  However,
3534 since the GNU project does not require man pages, many maintainers do
3535 not expend effort to keep the man pages up to date.  In these cases, the
3536 @code{no-installman} option will prevent the man pages from being
3537 installed by default.  The user can still explicitly install them via
3538 @samp{make install-man}.
3539 @opindex no-installman
3540 @trindex install-man
3541
3542 Here is how the man pages are handled in GNU @code{cpio} (which includes
3543 both Texinfo documentation and man pages):
3544
3545 @example
3546 man_MANS = cpio.1 mt.1
3547 EXTRA_DIST = $(man_MANS)
3548 @end example
3549
3550 Man pages are not currently considered to be source, because it is not
3551 uncommon for man pages to be automatically generated.  Therefore they
3552 are not automatically included in the distribution.  However, this can
3553 be changed by use of the @samp{dist_} prefix.
3554
3555 The @samp{nobase_} prefix is meaningless for man pages and is
3556 disallowed.
3557
3558
3559 @node Install, Clean, Documentation, Top
3560 @chapter What Gets Installed
3561
3562 @cindex Installation support
3563 @cindex make install support
3564
3565 @section Basics of installation
3566
3567 Naturally, Automake handles the details of actually installing your
3568 program once it has been built.  All files named by the various
3569 primaries are automatically installed in the appropriate places when the
3570 user runs @code{make install}.
3571
3572 A file named in a primary is installed by copying the built file into
3573 the appropriate directory.  The base name of the file is used when
3574 installing.
3575
3576 @example
3577 bin_PROGRAMS = hello subdir/goodbye
3578 @end example
3579
3580 In this example, both @samp{hello} and @samp{goodbye} will be installed
3581 in @code{$(bindir)}.
3582
3583 Sometimes it is useful to avoid the basename step at install time.  For
3584 instance, you might have a number of header files in subdirectories of
3585 the source tree which are laid out precisely how you want to install
3586 them.  In this situation you can use the @samp{nobase_} prefix to
3587 suppress the base name step.  For example:
3588
3589 @example
3590 nobase_include_HEADERS = stdio.h sys/types.h
3591 @end example
3592
3593 Will install @file{stdio.h} in @code{$(includedir)} and @file{types.h}
3594 in @code{$(includedir)/sys}.
3595
3596 @section The two parts of install
3597
3598 Automake generates separate @code{install-data} and @code{install-exec}
3599 targets, in case the installer is installing on multiple machines which
3600 share directory structure---these targets allow the machine-independent
3601 parts to be installed only once.  @code{install-exec} installs
3602 platform-dependent files, and @code{install-data} installs
3603 platform-independent files.  The @code{install} target depends on both
3604 of these targets.  While Automake tries to automatically segregate
3605 objects into the correct category, the @file{Makefile.am} author is, in
3606 the end, responsible for making sure this is done correctly.
3607 @trindex install-data
3608 @trindex install-exec
3609 @trindex install
3610 @cindex Install, two parts of
3611
3612 Variables using the standard directory prefixes @samp{data},
3613 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
3614 @samp{pkgdata}, or @samp{pkginclude} (e.g. @samp{data_DATA}) are
3615 installed by @samp{install-data}.
3616
3617 Variables using the standard directory prefixes @samp{bin}, @samp{sbin},
3618 @samp{libexec}, @samp{sysconf}, @samp{localstate}, @samp{lib}, or
3619 @samp{pkglib} (e.g. @samp{bin_PROGRAMS}) are installed by
3620 @samp{install-exec}.
3621
3622 Any variable using a user-defined directory prefix with @samp{exec} in
3623 the name (e.g. @samp{myexecbin_PROGRAMS} is installed by
3624 @samp{install-exec}.  All other user-defined prefixes are installed by
3625 @samp{install-data}.
3626
3627 @section Extending installation
3628
3629 It is possible to extend this mechanism by defining an
3630 @code{install-exec-local} or @code{install-data-local} target.  If these
3631 targets exist, they will be run at @samp{make install} time.  These
3632 rules can do almost anything; care is required.
3633 @trindex install-exec-local
3634 @trindex install-data-local
3635
3636 Automake also supports two install hooks, @code{install-exec-hook} and
3637 @code{install-data-hook}.  These hooks are run after all other install
3638 rules of the appropriate type, exec or data, have completed.  So, for
3639 instance, it is possible to perform post-installation modifications
3640 using an install hook.
3641 @cindex Install hook
3642
3643 @section Staged installs
3644
3645 @vindex DESTDIR
3646 Automake generates support for the @samp{DESTDIR} variable in all
3647 install rules.  @samp{DESTDIR} is used during the @samp{make install}
3648 step to relocate install objects into a staging area.  Each object and
3649 path is prefixed with the value of @samp{DESTDIR} before being copied
3650 into the install area.  Here is an example of typical DESTDIR usage:
3651
3652 @example
3653 make DESTDIR=/tmp/staging install
3654 @end example
3655
3656 This places install objects in a directory tree built under
3657 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
3658 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
3659 would install @file{/tmp/staging/gnu/bin/foo} and
3660 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
3661
3662 This feature is commonly used to build install images and packages.  For
3663 more information, see @ref{Makefile Conventions, , , standards, The GNU
3664 Coding Standards}.
3665
3666 Support for @samp{DESTDIR} is implemented by coding it directly into the
3667 install rules.  If your @file{Makefile.am} uses a local install rule
3668 (e.g., @code{install-exec-local}) or an install hook, then you must
3669 write that code to respect @samp{DESTDIR}.
3670
3671 @section Rules for the user
3672
3673 Automake also generates an @code{uninstall} target, an
3674 @code{installdirs} target, and an @code{install-strip} target.
3675 @trindex uninstall
3676 @trindex installdirs
3677 @trindex install-strip
3678
3679 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
3680 There is no notion of separate uninstalls for ``exec'' and ``data'', as
3681 these features would not provide additional functionality.
3682
3683 Note that @code{uninstall} is not meant as a replacement for a real
3684 packaging tool.
3685
3686
3687 @node Clean, Dist, Install, Top
3688 @chapter What Gets Cleaned
3689
3690 @cindex make clean support
3691
3692 The GNU Makefile Standards specify a number of different clean rules.
3693 See @xref{Standard Targets, , Standard Targets for Users, standards,
3694 The GNU Coding Standards}.
3695
3696 Generally the files that can be cleaned are determined automatically by
3697 Automake.  Of course, Automake also recognizes some variables that can
3698 be defined to specify additional files to clean.  These variables are
3699 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
3700 @code{MAINTAINERCLEANFILES}.
3701 @vindex MOSTLYCLEANFILES
3702 @vindex CLEANFILES
3703 @vindex DISTCLEANFILES
3704 @vindex MAINTAINERCLEANFILES
3705
3706 As the GNU Standards aren't always explicit as to which files should be
3707 removed by which target, we've adopted a heuristic which we believe was
3708 first formulated by Fran@,{c}ois Pinard:
3709
3710 @itemize @bullet
3711 @item
3712 If @code{make} built it, and it is commonly something that one would
3713 want to rebuild (for instance, a @file{.o} file), then
3714 @code{mostlyclean} should delete it.
3715
3716 @item
3717 Otherwise, if @code{make} built it, then @code{clean} should delete it.
3718
3719 @item
3720 If @code{configure} built it, then @code{distclean} should delete it
3721
3722 @item
3723 If the maintainer built it, then @code{maintainer-clean} should
3724 delete it.
3725 @end itemize
3726
3727 We recommend that you follow this same set of heuristics in your
3728 @file{Makefile.am}.
3729
3730
3731 @node Dist, Tests, Clean, Top
3732 @chapter What Goes in a Distribution
3733
3734 @section Basics of distribution
3735
3736 @cindex make dist
3737
3738 The @code{dist} target in the generated @file{Makefile.in} can be used
3739 to generate a gzip'd @code{tar} file and other flavors of archive for
3740 distribution.  The files is named based on the @samp{PACKAGE} and
3741 @samp{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
3742 (@pxref{Macros}); more precisely the gzip'd @code{tar} file is named
3743 @samp{@var{package}-@var{version}.tar.gz}.
3744 @cvindex PACKAGE
3745 @cvindex VERSION
3746 @trindex dist
3747 You can use the @code{make} variable @samp{GZIP_ENV} to control how gzip
3748 is run.  The default setting is @samp{--best}.
3749
3750 For the most part, the files to distribute are automatically found by
3751 Automake: all source files are automatically included in a distribution,
3752 as are all @file{Makefile.am}s and @file{Makefile.in}s.  Automake also
3753 has a built-in list of commonly used files which are automatically
3754 included if they are found in the current directory (either physically,
3755 or as the target of a @file{Makefile.am} rule).  This list is printed by
3756 @samp{automake --help}.  Also, files which are read by @code{configure}
3757 (i.e. the source files corresponding to the files specified in various
3758 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
3759 automatically distributed.
3760
3761 Still, sometimes there are files which must be distributed, but which
3762 are not covered in the automatic rules.  These files should be listed in
3763 the @code{EXTRA_DIST} variable.  You can mention files from
3764 subdirectories in @code{EXTRA_DIST}.
3765
3766 You can also mention a directory in @code{EXTRA_DIST}; in this case the
3767 entire directory will be recursively copied into the distribution.
3768 Please note that this will also copy @emph{everything} in the directory,
3769 including CVS/RCS version control files.  We recommend against using
3770 this feature.
3771
3772 @vindex EXTRA_DIST
3773
3774 @section Fine-grained distribution control
3775
3776 Sometimes you need tighter control over what does @emph{not} go into the
3777 distribution; for instance you might have source files which are
3778 generated and which you do not want to distribute.  In this case
3779 Automake gives fine-grained control using the @samp{dist} and
3780 @samp{nodist} prefixes.  Any primary or @samp{_SOURCES} variable can be
3781 prefixed with @samp{dist_} to add the listed files to the distribution.
3782 Similarly, @samp{nodist_} can be used to omit the files from the
3783 distribution.
3784 @vindex dist_
3785 @vindex nodist_
3786
3787 As an example, here is how you would cause some data to be distributed
3788 while leaving some source code out of the distribution:
3789
3790 @example
3791 dist_data_DATA = distribute-this
3792 bin_PROGRAMS = foo
3793 nodist_foo_SOURCES = do-not-distribute.c
3794 @end example
3795
3796 @section The dist hook
3797
3798 Another way to to use this is for removing unnecessary files that get
3799 recursively included by specifying a directory in EXTRA_DIST:
3800
3801 @example
3802 EXTRA_DIST = doc
3803
3804 dist-hook:
3805         rm -rf `find $(distdir)/doc -name CVS`
3806 @end example
3807
3808 If you define @code{SUBDIRS}, Automake will recursively include the
3809 subdirectories in the distribution.  If @code{SUBDIRS} is defined
3810 conditionally (@pxref{Conditionals}), Automake will normally include all
3811 directories that could possibly appear in @code{SUBDIRS} in the
3812 distribution.  If you need to specify the set of directories
3813 conditionally, you can set the variable @code{DIST_SUBDIRS} to the exact
3814 list of subdirectories to include in the distribution.
3815 @vindex DIST_SUBDIRS
3816
3817 @trindex dist-hook
3818
3819 Occasionally it is useful to be able to change the distribution before
3820 it is packaged up.  If the @code{dist-hook} target exists, it is run
3821 after the distribution directory is filled, but before the actual tar
3822 (or shar) file is created.  One way to use this is for distributing
3823 files in subdirectories for which a new @file{Makefile.am} is overkill:
3824
3825 @example
3826 dist-hook:
3827         mkdir $(distdir)/random
3828         cp -p $(srcdir)/random/a1 $(srcdir)/random/a2 $(distdir)/random
3829 @end example
3830
3831 @section Checking the distribution
3832
3833 @cindex make distcheck
3834 @cindex make distcleancheck
3835 @vindex distcleancheck_listfiles
3836
3837 Automake also generates a @code{distcheck} target which can be of help
3838 to ensure that a given distribution will actually work.
3839 @code{distcheck} makes a distribution, then tries to do a @code{VPATH}
3840 build, run the testsuite, and finally make another tarfile to ensure the
3841 distribution is self-contained.
3842 @trindex distcheck
3843
3844 Building the package involves running @code{./configure}.  If you need
3845 to supply additional flags to @code{configure}, define them in the
3846 @code{DISTCHECK_CONFIGURE_FLAGS} variable, either in your top-level
3847 @file{Makefile.am}, or on the commande line when invoking @code{make}.
3848 @vindex DISTCHECK_CONFIGURE_FLAGS
3849
3850 If the target @code{distcheck-hook} is defined in your
3851 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
3852 the new distribution has been unpacked, but before the unpacked copy is
3853 configured and built.  Your @code{distcheck-hook} can do almost
3854 anything, though as always caution is advised.  Generally this hook is
3855 used to check for potential distribution errors not caught by the
3856 standard mechanism.
3857
3858 Speaking about potential distribution errors, @code{distcheck} will also
3859 ensure that the @code{distclean} target actually removes all built
3860 files.  This is done by running @code{make distcleancheck} at the end of
3861 the @code{VPATH} build.  By default, @code{distcleancheck} will run
3862 @code{distclean} and then make sure the build tree has been emptied by
3863 running @code{$(distcleancheck_listfiles)}.  Usually this check will
3864 find generated files that you forgot to add to the @code{DISTCLEANFILES}
3865 variable (@pxref{Clean}).
3866 @trindex distcleancheck
3867
3868 The @code{distcleancheck} behaviour should be ok for most packages,
3869 otherwise you have the possibility to override the definitition of
3870 either the @code{distcleancheck} target, or the
3871 @code{$(distcleancheck_listfiles)} variable.  For instance to disable
3872 @code{distcleancheck} completely, add the following rule to your
3873 top-level @file{Makefile.am}:
3874 @vindex distcleancheck_listfiles
3875
3876 @example
3877 distcleancheck:
3878         @@:
3879 @end example
3880
3881 If you want @code{distcleancheck} to ignore built files which have not
3882 been cleaned because they are also part of the distribution, add the
3883 following definition instead:
3884
3885 @example
3886 distcleancheck_listfiles = \
3887   find -type f -exec sh -c 'test -f $(scrdir)/@{@} || echo @{@}'
3888 @end example
3889
3890 The above definition is not the default because it's usually an error if
3891 your Makefiles cause some distributed files to be rebuilt when the user
3892 build the package.  (Think about the user missing the tool required to
3893 build the file; or if the required tool is built by your package,
3894 consider the cross-compilation case where it can't be run.)
3895
3896 @section The types of distributions
3897
3898 @trindex dist-gzip
3899 Automake generates a @samp{.tar.gz} file when asked to create a
3900 distribution and other archives formats, @ref{Options}.  The target
3901 @code{dist-gzip} generates the @samp{.tar.gz} file only.
3902
3903
3904 @node Tests, Options, Dist, Top
3905 @chapter Support for test suites
3906
3907 @cindex Test suites
3908 @cindex make check
3909
3910 Automake supports two forms of test suites.
3911
3912 @section Simple Tests
3913
3914 If the variable @code{TESTS} is defined, its value is taken to be a list
3915 of programs to run in order to do the testing.  The programs can either
3916 be derived objects or source objects; the generated rule will look both
3917 in @code{srcdir} and @file{.}.  Programs needing data files should look
3918 for them in @code{srcdir} (which is both an environment variable and a
3919 make variable) so they work when building in a separate directory
3920 (@pxref{Build Directories, , Build Directories , autoconf, The Autoconf
3921 Manual}), and in particular for the @code{distcheck} target
3922 (@pxref{Dist}).
3923
3924 @cindex Exit status 77, special interpretation
3925
3926 The number of failures will be printed at the end of the run.  If a
3927 given test program exits with a status of 77, then its result is ignored
3928 in the final count.  This feature allows non-portable tests to be
3929 ignored in environments where they don't make sense.
3930
3931 The variable @code{TESTS_ENVIRONMENT} can be used to set environment
3932 variables for the test run; the environment variable @code{srcdir} is
3933 set in the rule.  If all your test programs are scripts, you can also
3934 set @code{TESTS_ENVIRONMENT} to an invocation of the shell (e.g.
3935 @samp{$(SHELL) -x}); this can be useful for debugging the tests.
3936 @vindex TESTS
3937 @vindex TESTS_ENVIRONMENT
3938
3939 @cindex Tests, expected failure
3940 @cindex Expected test failure
3941
3942 You may define the variable @code{XFAIL_TESTS} to a list of tests
3943 (usually a subset of @code{TESTS}) that are expected to fail.  This will
3944 reverse the result of those tests.
3945 @vindex XFAIL_TESTS
3946
3947 Automake ensures that each program listed in @code{TESTS} is built
3948 before any tests are run; you can list both source and derived programs
3949 in @code{TESTS}.  For instance, you might want to run a C program as a
3950 test.  To do this you would list its name in @code{TESTS} and also in
3951 @code{check_PROGRAMS}, and then specify it as you would any other
3952 program.
3953
3954 @section DejaGNU Tests
3955
3956 If @uref{ftp://prep.ai.mit.edu/pub/gnu/dejagnu-1.3.tar.gz,
3957 @samp{dejagnu}} appears in @code{AUTOMAKE_OPTIONS}, then a
3958 @code{dejagnu}-based test suite is assumed.  The variable
3959 @code{DEJATOOL} is a list of names which are passed, one at a time, as
3960 the @code{--tool} argument to @code{runtest} invocations; it defaults to
3961 the name of the package.
3962
3963 The variable @code{RUNTESTDEFAULTFLAGS} holds the @code{--tool} and
3964 @code{--srcdir} flags that are passed to dejagnu by default; this can be
3965 overridden if necessary.
3966 @vindex RUNTESTDEFAULTFLAGS
3967
3968 The variables @code{EXPECT} and @code{RUNTEST} can
3969 also be overridden to provide project-specific values.  For instance,
3970 you will need to do this if you are testing a compiler toolchain,
3971 because the default values do not take into account host and target
3972 names.
3973 @opindex dejagnu
3974 @vindex DEJATOOL
3975 @vindex EXPECT
3976 @vindex RUNTEST
3977
3978 The contents of the variable @code{RUNTESTFLAGS} are passed to the
3979 @code{runtest} invocation.  This is considered a ``user variable''
3980 (@pxref{User Variables}).  If you need to set @code{runtest} flags in
3981 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
3982 @vindex RUNTESTFLAGS
3983 @vindex AM_RUNTESTFLAGS
3984 @c FIXME xref dejagnu
3985
3986 In either case, the testing is done via @samp{make check}.
3987
3988 @section Install Tests
3989
3990 The @code{installcheck} target is available to the user as a way to run
3991 any tests after the package has been installed.  You can add tests to
3992 this by writing an @code{installcheck-local} target.
3993
3994
3995 @node Options, Miscellaneous, Tests, Top
3996 @chapter Changing Automake's Behavior
3997
3998 Various features of Automake can be controlled by options in the
3999 @file{Makefile.am}.  Such options are applied on a per-@file{Makefile}
4000 basis when listed in a special @file{Makefile} variable named
4001 @code{AUTOMAKE_OPTIONS}.  They are applied globally to all processed
4002 @file{Makefiles} when listed in the first argument of
4003 @code{AM_INIT_AUTOMAKE} in @file{configure.in}.  Currently understood
4004 options are:
4005 @vindex AUTOMAKE_OPTIONS
4006
4007 @table @asis
4008 @item @code{gnits}
4009 @itemx @code{gnu}
4010 @itemx @code{foreign}
4011 @itemx @code{cygnus}
4012 @cindex Option, gnits
4013 @cindex Option, gnu
4014 @cindex Option, foreign
4015 @cindex Option, cygnus
4016
4017 Set the strictness as appropriate.  The @code{gnits} option also implies
4018 @code{readme-alpha} and @code{check-news}.
4019
4020 @item @code{ansi2knr}
4021 @itemx @code{@var{path}/ansi2knr}
4022 @cindex Option, ansi2knr
4023 Turn on automatic de-ANSI-fication.  @xref{ANSI}.  If preceded by a
4024 path, the generated @file{Makefile.in} will look in the specified
4025 directory to find the @file{ansi2knr} program.  The path should be a
4026 relative path to another directory in the same distribution (Automake
4027 currently does not check this).
4028
4029 @item @code{check-news}
4030 @cindex Option, check-news
4031 Cause @code{make dist} to fail unless the current version number appears
4032 in the first few lines of the @file{NEWS} file.
4033
4034 @item @code{dejagnu}
4035 @cindex Option, dejagnu
4036 Cause @code{dejagnu}-specific rules to be generated.  @xref{Tests}.
4037
4038 @item @code{dist-bzip2}
4039 @cindex Option, dist-bzip2
4040 Generate a @code{dist-bzip2} target, creating a bzip2 tar archive of the
4041 distribution.  @code{dist} will create it in addition to the other
4042 formats.  bzip2 archives are frequently smaller than gzipped archives.
4043 @trindex dist-bzip2
4044
4045 @item @code{dist-shar}
4046 @cindex Option, dist-shar
4047 Generate a @code{dist-shar} target, creating a shar archive of the
4048 distribution.  @code{dist} will create it in addition to the other
4049 formats.
4050 @trindex dist-shar
4051
4052 @item @code{dist-zip}
4053 @cindex Option, dist-zip
4054 Generate a @code{dist-zip} target, creating a zip archive of the
4055 distribution.  @code{dist} will create it in addition to the other
4056 formats.
4057 @trindex dist-zip
4058
4059 @item @code{dist-tarZ}
4060 @cindex Option, dist-tarZ
4061 Generate a @code{dist-tarZ} target, creating a compressed tar archive of
4062 the distribution.  @code{dist} will create it in addition to the other
4063 formats.
4064 @trindex dist-tarZ
4065
4066 @item @code{no-define}
4067 @cindex Option, no-define
4068 This options is meaningful only when passed as an argument to
4069 AM_INIT_AUTOMAKE.  It will prevent the @code{PACKAGE} and @code{VERSION}
4070 variable to be @code{AC_DEFINE}d.
4071
4072 @item @code{no-dependencies}
4073 @cindex Option, no-dependencies
4074 This is similar to using @samp{--include-deps} on the command line, but
4075 is useful for those situations where you don't have the necessary bits
4076 to make automatic dependency tracking work @xref{Dependencies}.  In this
4077 case the effect is to effectively disable automatic dependency tracking.
4078
4079 @item @code{no-exeext}
4080 @cindex Option, no-exeext
4081 If your @file{Makefile.am} defines a target @samp{foo}, it will override
4082 a target named @samp{foo$(EXEEXT)}.  This is necessary when
4083 @code{EXEEXT} is found to be empty.  However, by default automake will
4084 generate an error for this use.  The @code{no-exeext} option will
4085 disable this error.  This is intended for use only where it is known in
4086 advance that the package will not be ported to Windows, or any other
4087 operating system using extensions on executables.
4088
4089 @item @code{no-installinfo}
4090 @cindex Option, no-installinfo
4091 The generated @file{Makefile.in} will not cause info pages to be built
4092 or installed by default.  However, @code{info} and @code{install-info}
4093 targets will still be available.  This option is disallowed at
4094 @samp{GNU} strictness and above.
4095 @trindex info
4096 @trindex install-info
4097
4098 @item @code{no-installman}
4099 @cindex Option, no-installman
4100 The generated @file{Makefile.in} will not cause man pages to be
4101 installed by default.  However, an @code{install-man} target will still
4102 be available for optional installation.  This option is disallowed at
4103 @samp{GNU} strictness and above.
4104 @trindex install-man
4105
4106 @item @code{nostdinc}
4107 @cindex Option, nostdinc
4108 This option can be used to disable the standard @samp{-I} options which
4109 are ordinarily automatically provided by Automake.
4110
4111 @item @code{no-texinfo.tex}
4112 @cindex Option, no-texinfo
4113 Don't require @file{texinfo.tex}, even if there are texinfo files in
4114 this directory.
4115
4116 @item @code{readme-alpha}
4117 @cindex Option, readme-alpha
4118 If this release is an alpha release, and the file @file{README-alpha}
4119 exists, then it will be added to the distribution.  If this option is
4120 given, version numbers are expected to follow one of two forms.  The
4121 first form is @samp{@var{MAJOR}.@var{MINOR}.@var{ALPHA}}, where each
4122 element is a number; the final period and number should be left off for
4123 non-alpha releases.  The second form is
4124 @samp{@var{MAJOR}.@var{MINOR}@var{ALPHA}}, where @var{ALPHA} is a
4125 letter; it should be omitted for non-alpha releases.
4126
4127 @item @code{subdir-objects}
4128 If this option is specified, then objects are placed into the
4129 subdirectory of the build directory corresponding to the subdirectory of
4130 the source file.  For instance if the source file is
4131 @file{subdir/file.cxx}, then the output file would be
4132 @file{subdir/file.o}.
4133
4134 @item @var{version}
4135 @cindex Option, version
4136 A version number (e.g. @samp{0.30}) can be specified.  If Automake is not
4137 newer than the version specified, creation of the @file{Makefile.in}
4138 will be suppressed.
4139 @end table
4140
4141 Unrecognized options are diagnosed by @code{automake}.
4142
4143 If you want an option to apply to all the files in the tree, you can use
4144 the @code{AM_AUTOMAKE_OPTIONS} macro in @file{configure.in}.
4145 @xref{Macros}.
4146
4147
4148 @node Miscellaneous, Include, Options, Top
4149 @chapter Miscellaneous Rules
4150
4151 There are a few rules and variables that didn't fit anywhere else.
4152
4153 @menu
4154 * Tags::                        Interfacing to etags and mkid
4155 * Suffixes::                    Handling new file extensions
4156 * Multilibs::                   Support for multilibbing.
4157 @end menu
4158
4159
4160 @node Tags, Suffixes, Miscellaneous, Miscellaneous
4161 @section Interfacing to @code{etags}
4162
4163 @cindex TAGS support
4164
4165 Automake will generate rules to generate @file{TAGS} files for use with
4166 GNU Emacs under some circumstances.
4167
4168 If any C, C++ or Fortran 77 source code or headers are present, then
4169 @code{tags} and @code{TAGS} targets will be generated for the directory.
4170 @trindex tags
4171
4172 At the topmost directory of a multi-directory package, a @code{tags}
4173 target file will be generated which, when run, will generate a
4174 @file{TAGS} file that includes by reference all @file{TAGS} files from
4175 subdirectories.
4176
4177 The @code{tags} target will also be generated if the variable
4178 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
4179 directories which contain taggable source that @code{etags} does not
4180 understand.  The user can use the @code{ETAGSFLAGS} to pass additional
4181 flags to @code{etags}; @code{AM_ETAGSFLAGS} is also available for use in
4182 @file{Makefile.am}.
4183 @vindex ETAGS_ARGS
4184 @vindex ETAGSFLAGS
4185 @vindex AM_ETAGSFLAGS
4186
4187 Here is how Automake generates tags for its source, and for nodes in its
4188 Texinfo file:
4189
4190 @example
4191 ETAGS_ARGS = automake.in --lang=none \
4192  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
4193 @end example
4194
4195 If you add filenames to @samp{ETAGS_ARGS}, you will probably also
4196 want to set @samp{TAGS_DEPENDENCIES}.  The contents of this variable
4197 are added directly to the dependencies for the @code{tags} target.
4198 @vindex TAGS_DEPENDENCIES
4199
4200 Automake will also generate an @code{ID} target which will run
4201 @code{mkid} on the source.  This is only supported on a
4202 directory-by-directory basis.
4203 @trindex id
4204
4205 Automake also supports the @uref{http://www.gnu.org/software/global/,
4206 GNU Global Tags program}.  The @code{GTAGS} target runs Global Tags
4207 automatically and puts the result in the top build directory.  The
4208 variable @code{GTAGS_ARGS} holds arguments which are passed to
4209 @code{gtags}.
4210 @vindex GTAGS_ARGS
4211
4212
4213 @node Suffixes, Multilibs, Tags, Miscellaneous
4214 @section Handling new file extensions
4215
4216 @cindex Adding new SUFFIXES
4217 @cindex SUFFIXES, adding
4218 @vindex SUFFIXES
4219
4220 It is sometimes useful to introduce a new implicit rule to handle a file
4221 type that Automake does not know about.
4222
4223 For instance, suppose you had a compiler which could compile @samp{.foo}
4224 files to @samp{.o} files.  You would simply define an suffix rule for
4225 your language:
4226
4227 @example
4228 .foo.o:
4229         foocc -c -o $@@ $<
4230 @end example
4231
4232 Then you could directly use a @samp{.foo} file in a @samp{_SOURCES}
4233 variable and expect the correct results:
4234
4235 @example
4236 bin_PROGRAMS = doit
4237 doit_SOURCES = doit.foo
4238 @end example
4239
4240 This was the simpler and more common case.  In other cases, you will
4241 have to help Automake to figure which extensions you are defining your
4242 suffix rule for.  This usually happens when your extensions does not
4243 start with a dot.  Then, all you have to do is to put a list of new
4244 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
4245 implicit rule.
4246
4247 For instance the following definition prevents Automake to misinterpret
4248 @samp{.idlC.cpp:} as an attemp to transform @samp{.idlC} into
4249 @samp{.cpp}.
4250
4251 @example
4252 SUFFIXES = .idl C.cpp
4253 .idlC.cpp:
4254         # whatever
4255 @end example
4256
4257 As you may have noted, the @code{SUFFIXES} macro behaves like the
4258 @code{.SUFFIXES} special target of @code{make}.  You should not touch
4259 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
4260 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
4261 @code{SUFFIXES} go at the start of the generated suffixes list, followed
4262 by Automake generated suffixes not already in the list.
4263
4264 @node Multilibs,  , Suffixes, Miscellaneous
4265 @section Support for Multilibs
4266
4267 Automake has support for an obscure feature called multilibs.  A
4268 @dfn{multilib} is a library which is built for multiple different ABIs
4269 at a single time; each time the library is built with a different target
4270 flag combination.  This is only useful when the library is intended to
4271 be cross-compiled, and it is almost exclusively used for compiler
4272 support libraries.
4273
4274 The multilib support is still experimental.  Only use it if you are
4275 familiar with multilibs and can debug problems you might encounter.
4276
4277
4278 @node Include, Conditionals, Miscellaneous, Top
4279 @chapter Include
4280
4281 @cmindex include
4282 @cindex Including Makefile fragment
4283 @cindex Makefile fragment, including
4284
4285 Automake supports an @code{include} directive which can be used to
4286 include other @file{Makefile} fragments when @code{automake} is run.
4287 Note that these fragments are read and interpreted by @code{automake},
4288 not by @code{make}.  As with conditionals, @code{make} has no idea that
4289 @code{include} is in use.
4290
4291 There are two forms of @code{include}:
4292
4293 @table @code
4294 @item include $(srcdir)/file
4295 Include a fragment which is found relative to the current source
4296 directory.
4297
4298 @item include $(top_srcdir)/file
4299 Include a fragment which is found relative to the top source directory.
4300 @end table
4301
4302 Note that if a fragment is included inside a conditional, then the
4303 condition applies to the entire contents of that fragment.
4304
4305
4306 @node Conditionals, Gnits, Include, Top
4307 @chapter Conditionals
4308
4309 @cindex Conditionals
4310
4311 Automake supports a simple type of conditionals.
4312
4313 @cvindex AM_CONDITIONAL
4314 Before using a conditional, you must define it by using
4315 @code{AM_CONDITIONAL} in the @code{configure.in} file (@pxref{Macros}).
4316
4317 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
4318 The conditional name, @var{conditional}, should be a simple string
4319 starting with a letter and containing only letters, digits, and
4320 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
4321 which are reserved by Automake.
4322
4323 The shell @var{condition} (suitable for use in a shell @code{if}
4324 statement) is evaluated when @code{configure} is run.  Note that you
4325 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
4326 time @code{configure} is run -- if @code{AM_CONDITIONAL} is run
4327 conditionally (e.g., in a shell @code{if} statement), then the result
4328 will confuse automake.
4329 @end defmac
4330
4331 @cindex --enable-debug, example
4332 @cindex Example conditional --enable-debug
4333 @cindex Conditional example,  --enable-debug
4334
4335 Conditionals typically depend upon options which the user provides to
4336 the @code{configure} script.  Here is an example of how to write a
4337 conditional which is true if the user uses the @samp{--enable-debug}
4338 option.
4339
4340 @example
4341 AC_ARG_ENABLE(debug,
4342 [  --enable-debug    Turn on debugging],
4343 [case "$@{enableval@}" in
4344   yes) debug=true ;;
4345   no)  debug=false ;;
4346   *) AC_MSG_ERROR(bad value $@{enableval@} for --enable-debug) ;;
4347 esac],[debug=false])
4348 AM_CONDITIONAL(DEBUG, test x$debug = xtrue)
4349 @end example
4350
4351 Here is an example of how to use that conditional in @file{Makefile.am}:
4352
4353 @cmindex if
4354 @cmindex endif
4355 @cmindex else
4356
4357 @example
4358 if DEBUG
4359 DBG = debug
4360 else
4361 DBG =
4362 endif
4363 noinst_PROGRAMS = $(DBG)
4364 @end example
4365
4366 This trivial example could also be handled using EXTRA_PROGRAMS
4367 (@pxref{A Program}).
4368
4369 You may only test a single variable in an @code{if} statement, possibly
4370 negated using @samp{!}.  The @code{else} statement may be omitted.
4371 Conditionals may be nested to any depth.  You may specify an argument to
4372 @code{else} in which case it must be the negation of the condition used
4373 for the current @code{if}.  Similarly you may specify the condition
4374 which is closed by an @code{end}:
4375
4376 @example
4377 if DEBUG
4378 DBG = debug
4379 else !DEBUG
4380 DBG =
4381 endif !DEBUG
4382 @end example
4383
4384 @noindent
4385 Unbalanced conditions are errors.
4386
4387 @anchor{Conditional Append}
4388 Conditionals do not interact very smoothly with the append operator.
4389 In particular, an append must happen in the same conditional context as
4390 the original assignment.  This means that the following will not work:
4391
4392 @example
4393 DBG = foo
4394 if DEBUG
4395 DBG += bar
4396 endif DEBUG
4397 @end example
4398
4399 The behaviour which is probably desired in this situation can be obtained
4400 using a temporary variable:
4401
4402 @example
4403 if DEBUG
4404 TMP_DBG = bar
4405 endif DEBUG
4406 DBG = foo $(TMP_DBG)
4407 @end example
4408
4409 This restriction may be lifted in future versions of automake.
4410
4411 Note that conditionals in Automake are not the same as conditionals in
4412 GNU Make.  Automake conditionals are checked at configure time by the
4413 @file{configure} script, and affect the translation from
4414 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
4415 to @file{configure} and on results that @file{configure} has discovered
4416 about the host system.  GNU Make conditionals are checked at @code{make}
4417 time, and are based on variables passed to the make program or defined
4418 in the @file{Makefile}.
4419
4420 Automake conditionals will work with any make program.
4421
4422
4423 @node Gnits, Cygnus, Conditionals, Top
4424 @chapter The effect of @code{--gnu} and @code{--gnits}
4425
4426 @cindex --gnu, required files
4427 @cindex --gnu, complete description
4428
4429 The @samp{--gnu} option (or @samp{gnu} in the @samp{AUTOMAKE_OPTIONS}
4430 variable) causes @code{automake} to check the following:
4431
4432 @itemize @bullet
4433 @item
4434 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{COPYING},
4435 @file{AUTHORS}, and @file{ChangeLog} are required at the topmost
4436 directory of the package.
4437
4438 @item
4439 The options @samp{no-installman} and @samp{no-installinfo} are
4440 prohibited.
4441 @end itemize
4442
4443 Note that this option will be extended in the future to do even more
4444 checking; it is advisable to be familiar with the precise requirements
4445 of the GNU standards.  Also, @samp{--gnu} can require certain
4446 non-standard GNU programs to exist for use by various maintainer-only
4447 targets; for instance in the future @code{pathchk} might be required for
4448 @samp{make dist}.
4449
4450 @cindex --gnits, complete description
4451
4452 The @samp{--gnits} option does everything that @samp{--gnu} does, and
4453 checks the following as well:
4454
4455 @itemize @bullet
4456 @item
4457 @samp{make dist} will check to make sure the @file{NEWS} file has been
4458 updated to the current version.
4459
4460 @item
4461 @samp{VERSION} is checked to make sure its format complies with Gnits
4462 standards.
4463 @c FIXME xref when standards are finished
4464
4465 @item
4466 @cindex README-alpha
4467 If @samp{VERSION} indicates that this is an alpha release, and the file
4468 @file{README-alpha} appears in the topmost directory of a package, then
4469 it is included in the distribution.  This is done in @samp{--gnits}
4470 mode, and no other, because this mode is the only one where version
4471 number formats are constrained, and hence the only mode where Automake
4472 can automatically determine whether @file{README-alpha} should be
4473 included.
4474
4475 @item
4476 The file @file{THANKS} is required.
4477 @end itemize
4478
4479
4480 @node Cygnus, Extending, Gnits, Top
4481 @chapter The effect of @code{--cygnus}
4482
4483 @cindex Cygnus strictness
4484
4485 Some packages, notably GNU GCC and GNU gdb, have a build environment
4486 originally written at Cygnus Support (subsequently renamed Cygnus
4487 Solutions, and then later purchased by Red Hat).  Packages with this
4488 ancestry are sometimes referred to as ``Cygnus'' trees.
4489
4490 A Cygnus tree has slightly different rules for how a @file{Makefile.in}
4491 is to be constructed.  Passing @samp{--cygnus} to @code{automake} will
4492 cause any generated @file{Makefile.in} to comply with Cygnus rules.
4493
4494 Here are the precise effects of @samp{--cygnus}:
4495
4496 @itemize @bullet
4497 @item
4498 Info files are always created in the build directory, and not in the
4499 source directory.
4500
4501 @item
4502 @file{texinfo.tex} is not required if a Texinfo source file is
4503 specified.  The assumption is that the file will be supplied, but in a
4504 place that Automake cannot find.  This assumption is an artifact of how
4505 Cygnus packages are typically bundled.
4506
4507 @item
4508 @samp{make dist} is not supported, and the rules for it are not
4509 generated.  Cygnus-style trees use their own distribution mechanism.
4510
4511 @item
4512 Certain tools will be searched for in the build tree as well as in the
4513 user's @samp{PATH}.  These tools are @code{runtest}, @code{expect},
4514 @code{makeinfo} and @code{texi2dvi}.
4515
4516 @item
4517 @code{--foreign} is implied.
4518
4519 @item
4520 The options @samp{no-installinfo} and @samp{no-dependencies} are
4521 implied.
4522
4523 @item
4524 The macros @samp{AM_MAINTAINER_MODE} and @samp{AM_CYGWIN32} are
4525 required.
4526
4527 @item
4528 The @code{check} target doesn't depend on @code{all}.
4529 @end itemize
4530
4531 GNU maintainers are advised to use @samp{gnu} strictness in preference
4532 to the special Cygnus mode.  Some day, perhaps, the differences between
4533 Cygnus trees and GNU trees will disappear (for instance, as GCC is made
4534 more standards compliant).  At that time the special Cygnus mode will be
4535 removed.
4536
4537
4538 @node Extending, Distributing, Cygnus, Top
4539 @chapter When Automake Isn't Enough
4540
4541 Automake's implicit copying semantics means that many problems can be
4542 worked around by simply adding some @code{make} targets and rules to
4543 @file{Makefile.in}.  Automake will ignore these additions.
4544
4545 @cindex -local targets
4546 @cindex local targets
4547
4548 There are some caveats to doing this.  Although you can overload a
4549 target already used by Automake, it is often inadvisable, particularly
4550 in the topmost directory of a package with subdirectories.  However,
4551 various useful targets have a @samp{-local} version you can specify in
4552 your @file{Makefile.in}.  Automake will supplement the standard target
4553 with these user-supplied targets.
4554
4555 @trindex  all-local
4556 @trindex  info-local
4557 @trindex  dvi-local
4558 @trindex  check-local
4559 @trindex  install-data-local
4560 @trindex  install-exec-local
4561 @trindex  uninstall-local
4562 @trindex  mostlyclean-local
4563 @trindex  clean-local
4564 @trindex  distclean-local
4565 @trindex  installdirs-local
4566 @trindex  installcheck-local
4567
4568 The targets that support a local version are @code{all}, @code{info},
4569 @code{dvi}, @code{check}, @code{install-data}, @code{install-exec},
4570 @code{uninstall}, @code{installdirs}, @code{installcheck} and the
4571 various @code{clean} targets (@code{mostlyclean}, @code{clean},
4572 @code{distclean}, and @code{maintainer-clean}).  Note that there are no
4573 @code{uninstall-exec-local} or @code{uninstall-data-local} targets; just
4574 use @code{uninstall-local}.  It doesn't make sense to uninstall just
4575 data or just executables.
4576 @trindex all
4577 @trindex info
4578 @trindex dvi
4579 @trindex check
4580 @trindex install-data
4581 @trindex install-exec
4582 @trindex uninstall
4583
4584 For instance, here is one way to install a file in @file{/etc}:
4585
4586 @example
4587 install-data-local:
4588         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
4589 @end example
4590
4591 @cindex -hook targets
4592 @cindex hook targets
4593
4594 Some targets also have a way to run another target, called a @dfn{hook},
4595 after their work is done.  The hook is named after the principal target,
4596 with @samp{-hook} appended.  The targets allowing hooks are
4597 @code{install-data}, @code{install-exec}, @code{uninstall}, @code{dist},
4598 and @code{distcheck}.
4599 @trindex install-data-hook
4600 @trindex install-exec-hook
4601 @trindex uninstall-hook
4602 @trindex dist-hook
4603
4604 For instance, here is how to create a hard link to an installed program:
4605
4606 @example
4607 install-exec-hook:
4608         ln $(DESTDIR)$(bindir)/program $(DESTDIR)$(bindir)/proglink
4609 @end example
4610
4611 @c FIXME should include discussion of variables you can use in these
4612 @c rules
4613
4614 @node Distributing, API versioning, Extending, Top
4615 @chapter Distributing @file{Makefile.in}s
4616
4617 Automake places no restrictions on the distribution of the resulting
4618 @file{Makefile.in}s.  We still encourage software authors to distribute
4619 their work under terms like those of the GPL, but doing so is not
4620 required to use Automake.
4621
4622 Some of the files that can be automatically installed via the
4623 @code{--add-missing} switch do fall under the GPL.  However, these also
4624 have a special exception allowing you to distribute them with your
4625 package, regardless of the licensing you choose.
4626
4627
4628 @node API versioning, Macro and Variable Index, Distributing, Top
4629 @chapter Automake API versioning
4630
4631 New Automake releases usually include bug fixes and new features.
4632 Unfortunately they may also introduce new bugs and incompatibilities.
4633 This make four reasons why a package may require a particular Automake
4634 version.
4635
4636 Things get worse when maintaining a large tree of packages, each one
4637 requiring a different version of Automake.  In the past, this meant that
4638 any developer (and sometime users) had to install several versions of
4639 Automake in different places, and switch @samp{$PATH} appropriately for
4640 each package.
4641
4642 Starting with version 1.6, Automake installs versioned binaries.  This
4643 means you can install several versions of Automake in the same
4644 @samp{$prefix}, and can select an arbitrary Automake version by running
4645 @samp{automake-1.6} or @samp{automake-1.7} without juggling with
4646 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
4647 will use @samp{automake-1.6} explicitely in their rebuild rules.
4648
4649 Note that @samp{1.6} in @samp{automake-1.6} is Automake's API version,
4650 not Automake's version.  If a bug fix release is made, for instance
4651 Automake 1.6.1, the API version will remain 1.6.  This means that a
4652 package which work with Automake 1.6 should also work with 1.6.1; after
4653 all, this is what people expect from bug fix releases.
4654
4655 Note that if your package relies on a feature or a bug fix introduced in
4656 a release, you can pass this version as an option to Automake to ensure
4657 older releases will not be used.  For instance, use this in your
4658 @file{configure.in}:
4659
4660 @example
4661   AM_INIT_AUTOMAKE(1.6.1)    dnl Require Automake 1.6.1 or better.
4662 @end example
4663 @noindent
4664 or, in a particular @file{Makefile.am}:
4665
4666 @example
4667   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
4668 @end example
4669 @noindent
4670 Automake will print an error message if its version is
4671 older than the requested version.
4672
4673
4674 @heading What is in the API
4675
4676 Automake's programing interface is not easy to define.  Basically it
4677 should include at least all @strong{documented} variables and targets
4678 that a @samp{Makefile.am} authors can use, the behaviours associated to
4679 them (e.g. the places where @samp{-hook}'s are run), the command line
4680 interface of @samp{automake} and @samp{aclocal}, ...
4681
4682 @heading What is not in the API
4683
4684 Every undocumented variable, target, or command line option, is not part
4685 of the API.  You should avoid using them, as they could change from one
4686 version to the other (even in bug fix releases, if this helps to fix a
4687 bug).
4688
4689 If it turns out you need to use such a undocumented feature, contact
4690 @email{automake@@gnu.org} and try to get it documented and exercised by
4691 the test-suite.
4692
4693 @page
4694 @node Macro and Variable Index, General Index, API versioning, Top
4695 @unnumbered Macro and Variable Index
4696
4697 @printindex vr
4698
4699
4700 @page
4701 @node General Index,  , Macro and Variable Index, Top
4702 @unnumbered General Index
4703
4704 @printindex cp
4705
4706
4707 @page
4708 @contents
4709 @bye