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