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