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