Fixlet
[automake.git] / automake.texi
blob0c03b345fe0085625330cc859cdb62bf0e65820e
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
8 @include version.texi
10 @c Yes, this appears in many Texinfo files.  He's just a likeable guy.
11 @ifinfo
12 @set Francois Franc,ois
13 @end ifinfo
14 @tex
15 @set Francois Fran\noexpand\ptexc cois
16 @end tex
18 @ifinfo
19 @format
20 START-INFO-DIR-ENTRY
21 * automake: (automake).         Making Makefile.in's
22 END-INFO-DIR-ENTRY
23 @end format
24 @end ifinfo
26 @ifinfo
27 This file documents GNU automake @value{VERSION}
29 Copyright (C) 1995 Free Software Foundation, Inc.
31 Permission is granted to make and distribute verbatim copies of
32 this manual provided the copyright notice and this permission notice
33 are preserved on all copies.
35 @ignore
36 Permission is granted to process this file through TeX and print the
37 results, provided the printed document carries copying permission
38 notice identical to this one except for the removal of this paragraph
41 @end ignore
42 Permission is granted to copy and distribute modified versions of this
43 manual under the conditions for verbatim copying, provided that the entire
44 resulting derived work is distributed under the terms of a permission
45 notice identical to this one.
47 Permission is granted to copy and distribute translations of this manual
48 into another language, under the above conditions for modified versions,
49 except that this permission notice may be stated in a translation approved
50 by the Foundation.
51 @end ifinfo
54 @titlepage
55 @title GNU Automake
56 @subtitle For version @value{VERSION}, @value{UPDATED}
57 @c copyright page
58 @page
59 @vskip 0pt plus 1filll
60 Copyright @copyright{} 1995 Free Software Foundation, Inc.
61 @sp 2
62 This is the first edition of the GNU Automake documentation,@*
63 and is consistent with GNU Automake @value{VERSION}.@*
64 @sp 2
65 Published by the Free Software Foundation @*
66 59 Template Place - Suite 330, @*
67 Boston, MA 02111-1307 USA @*
69 Permission is granted to make and distribute verbatim copies of
70 this manual provided the copyright notice and this permission notice
71 are preserved on all copies.
73 Permission is granted to copy and distribute modified versions of this
74 manual under the conditions for verbatim copying, provided that the entire
75 resulting derived work is distributed under the terms of a permission
76 notice identical to this one.
78 Permission is granted to copy and distribute translations of this manual
79 into another language, under the above conditions for modified versions,
80 except that this permission notice may be stated in a translation
81 approved by the Free Software Foundation.
82 @end titlepage
84 @c Define an index of configure variables.
85 @defcodeindex cv
86 @c Define an index of options.
87 @defcodeindex op
88 @c Define an index of targets.
89 @defcodeindex tr
91 @ifinfo
92 @node Top, Introduction, (dir), (dir)
93 @comment  node-name,  next,  previous,  up
94 @top GNU Automake
96 This file documents the GNU Automake package for creating GNU
97 Standards-compliant Makefiles from template files.  This edition
98 documents version @value{VERSION}.
100 @menu
101 * Introduction::                Automake's purpose
102 * Invoking Automake::           Creating a Makefile.in
103 * Generalities::                General ideas
104 * configure::                   Scanning configure.in
105 * Top level::                   The top-level Makefile.am
106 * Programs::                    Building programs and libraries
107 * Other objects::               Other derived objects
108 * Emacs Lisp::                  Emacs Lisp support
109 * Documentation::               Building documentation
110 * Install::                     What gets installed
111 * Clean::                       What gets cleaned
112 * Dist::                        What goes in a distribution
113 * Tests::                       Support for test suites
114 * Options::                     Changing Automake's behavior
115 * Miscellaneous::               Miscellaneous rules
116 * Extending::                   Extending Automake
117 * Distributing::                Distributing the Makefile.in
118 * Examples::                    Some example packages
119 * Future::                      Some ideas for the future
120 * Variables::                   Index of variables
121 * Configure variables::         Index of configure variables and macros
122 * Targets::                     Index of targets
123 @end menu
125 @end ifinfo
127 @node Introduction
128 @chapter Introduction
130 Automake is a tool for automatically generating
131 @file{Makefile.in}s from files called @file{Makefile.am}.  The
132 @file{Makefile.am} is basically a series of @code{make} macro
133 definitions (with rules being thrown in occasionally).  The generated
134 @file{Makefile.in}s are compliant with the GNU Makefile standards.
136 The GNU Makefile Standards Document
137 (@pxref{Makefile Conventions, , , standards.info, The GNU Coding Standards})
138 is long, complicated, and subject to change.  The goal of Automake is to
139 remove the burden of Makefile maintenance from the back of the
140 individual GNU maintainer (and put it on the back of the Automake
141 maintainer).
143 The typical Automake input files is simply a series of macro
144 definitions.  Each such file is processed to create a
145 @file{Makefile.in}.  There should generally be one @file{Makefile.am}
146 per directory of a project.
148 Automake does constrain a project in certain ways; for instance it
149 assumes that the project uses Autoconf
150 (@pxref{Top, , The Autoconf Manual, autoconf.info, The Autoconf Manual}),
151 and enforces certain restrictions on the @file{configure.in} contents.
153 @code{Automake} requires @code{perl} in order to generate the
154 @file{Makefile.in}s.  However, the distributions created by Automake are
155 fully GNU standards-compliant, and do not require @code{perl} in order
156 to be built.
158 Mail suggestions and bug reports for Automake to tromey@@cygnus.com.
161 @node Invoking Automake
162 @chapter Creating a @file{Makefile.in}
164 To create all the @file{Makefile.in}s for a package, run the
165 @code{automake} program in the top level directory, with no arguments.
166 @code{automake} will automatically find each appropriate
167 @file{Makefile.am} (by scanning @file{configure.in}; @pxref{configure})
168 and generate the corresponding @file{Makefile.in}.
170 You can optionally give @code{automake} an argument; @samp{.am} is
171 appended to the argument and the result is used as the name of the input
172 file.  This feature is generally only used to automatically rebuild an
173 out-of-date @file{Makefile.in}.  Note that @code{automake} must always
174 be run from the topmost directory of a project, even if being used to
175 regenerate the @file{Makefile.in} in some subdirectory.  This is
176 necessary because @code{automake} must scan @file{configure.in}, and
177 because @code{automake} uses the knowledge that a @file{Makefile.in} is
178 in a subdirectory to change its behavior in some cases.
180 @code{automake} accepts the following options:
182 @table @code
183 @item --amdir=@var{dir}
184 Look for Automake data files in directory @var{dir} instead of in the
185 installation directory.  This is typically used for debugging.
187 @item --foreign
188 An alias for @samp{--strictness=foreign}.
190 @item --gnits
191 An alias for @samp{--strictness=gnits}.
193 @item --gnu
194 An alias for @samp{--strictness=gnu}.
196 @item --help
197 Print a summary of the command line options and exit.
199 @item --include-deps
200 Include all automatically generated dependency information
201 (@pxref{Dependencies}) in the generated
202 @file{Makefile.in}.  This is generally done when making a distribution;
203 see @ref{Dist}.
205 @item --add-missing
206 Automake requires certain common files to exist in certain situations;
207 for instance @file{config.guess} is required if @file{configure.in} runs
208 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
209 files; this option will cause the missing ones to be automatically added
210 to the package, whenever possible.
212 @item --output-dir=@var{dir}
213 Put the generated @file{Makefile.in} in the directory @var{dir}.
214 Ordinarily each @file{Makefile.in} is created in the directory of the
215 corresponding @file{Makefile.am}.  This option is used when making
216 distributions.
218 @item --strictness=@var{level}
219 Set the global strictness to @var{level}; this can be overridden in each
220 @file{Makefile.am} if required.  @xref{Generalities} for more
221 information.
223 @item --verbose
224 Cause Automake to print information about which files are being read or
225 created.
227 @item --version
228 Print the version number of Automake and exit.
229 @end table
232 @node Generalities
233 @chapter General ideas
235 @section Depth
236 @code{automake} supports three kinds of directory hierarchy: ``flat'',
237 ``shallow'', and ``deep''.
239 A @dfn{flat} package is one in which all the files are in a single
240 directory.  The @file{Makefile.am} for such a package by definition
241 lacks a @code{SUBDIRS} macro.  An example of such a package is
242 @code{termutils}.
243 @vindex SUBDIRS
245 A @dfn{deep} package is one in which all the source lies in
246 subdirectories; the top level directory contains mainly configuration
247 information.  GNU cpio is a good example of such a package, as is GNU
248 @code{tar}.  The top level @file{Makefile.am} for a deep package will
249 contain a @code{SUBDIRS} macro, but no other macros to define objects
250 which are built.
252 A @dfn{shallow} package is one in which the primary source resides in
253 the top-level directory, while various parts (typically libraries)
254 reside in subdirectories.  @code{automake} is one such package (as is
255 GNU @code{make}, which does not currently use @code{automake}).
258 @section Strictness
259 While Automake is intended to be used by maintainers of GNU packages, it
260 does make some effort to accommodate those who wish to use it, but do
261 not want to use all the GNU conventions.
263 To this end, Automake supports three levels of @dfn{strictness} -- the
264 strictness indicating how stringently Automake should check standards
265 conformance.
267 The valid strictness levels are:
269 @table @samp
270 @item foreign
271 Automake will check for only those things which are absolutely
272 required for proper operations.  For instance, whereas GNU standards
273 dictate the existence of a @file{NEWS} file, it will not be required in
274 this mode.  The name comes from the fact that Automake is intended to be
275 used for GNU programs; these relaxed rules are not the standard mode of
276 operation.
278 @item gnu
279 Automake will check -- as much as possible -- for compliance to the GNU
280 standards for packages.  This is the default.
282 @item gnits
283 Automake will check for compliance to the as-yet-unwritten GNITS
284 standards.  These are based on the GNU standards, but are even more
285 detailed.  Unless you are a GNITS standards contributor, it is
286 recommended that you avoid this option until such time as the GNITS
287 standard is actually published.
288 @end table
291 @section The Uniform Naming Scheme
292 Automake variables generally follow a uniform naming scheme that makes
293 it easy to decide how programs (and other derived objects) are built,
294 and how they are installed.  This scheme also supports @code{configure}
295 time determination of what should be built.
297 At @code{make} time, certain variables are used to determine which
298 objects are to be built.  These variables are called @dfn{primary}
299 variables.  For instance, the primary variable @code{PROGRAMS} holds a
300 list of programs which are to be compiled and linked.
301 @vindex PROGRAMS
303 A different set of variables is used to decide where the built objects
304 should be installed.  These variables are named after the primary
305 variables, but have a prefix indicating which standard directory should
306 be used as the installation directory.  The standard directory names are
307 given in the GNU standards
308 (@pxref{Directory Variables, , , standards.info, The GNU Coding
309 Standards}).
310 @code{automake} extends this list with @code{pkglibdir},
311 @code{pkgincludedir}, and @code{pkgdatadir}; these are the same as the
312 non-@samp{pkg} versions, but with @samp{@@PACKAGE@@} appended.
313 @cvindex PACKAGE
315 For each primary, there is one additional variable named by prepending
316 @samp{EXTRA_} to the primary name.  This variable is used to list
317 objects which may or may not be built, depending on what
318 @code{configure} decides.  This variable is required because Automake
319 must know the entire list of objects to be built in order to generate a
320 @file{Makefile.in} that will work in all cases.
322 For instance, @code{cpio} decides at configure time which programs are
323 built.  Some of the programs are installed in @code{bindir}, and some
324 are installed in @code{sbindir}:
326 @example
327 EXTRA_PROGRAMS = mt rmt
328 bin_PROGRAMS = cpio pax
329 sbin_PROGRAMS = @@PROGRAMS@@
330 @end example
332 Defining a primary variable is an error.
334 Note that the common @samp{dir} suffix is left off when constructing the
335 variable names; thus one writes @samp{bin_PROGRAMS} and not
336 @samp{bindir_PROGRAMS}.
338 Not every sort of object can be installed in every directory.  Automake
339 will flag those attempts it finds in error.  Automake will also diagnose
340 obvious misspellings in directory names.
342 Sometimes the standard directories -- even as augmented by Automake --
343 are not enough.  In particular it is sometimes useful, for clarity, to
344 install objects in a subdirectory of some predefined directory.  To this
345 end, Automake allows you to extend the list of possible installation
346 directories.  A given prefix (eg @samp{zar}) is valid if a variable of
347 the same name with @samp{dir} appended is defined (eg @samp{zardir}).
349 For instance, until HTML support is part of Automake, you could use this
350 to install raw HTML documentation:
352 @example
353 htmldir = $(prefix)/html
354 html_DATA = automake.html
355 @end example
357 The special prefix @samp{noinst} indicates that the objects in question
358 should not be installed at all.
360 The special prefix @samp{check} indicates that the objects in question
361 should not be built until the @code{make check} command is run.
363 Possible primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
364 @samp{SCRIPTS}, @samp{DATA}, @samp{HEADERS}, @samp{MANS}, and
365 @samp{TEXINFOS}.
366 @vindex PROGRAMS
367 @vindex LIBRARIES
368 @vindex SCRIPTS
369 @vindex DATA
370 @vindex HEADERS
371 @vindex MANS
372 @vindex TEXINFOS
374 @section General Operation
375 Automake essentially works by reading a @file{Makefile.am} and
376 generating a @file{Makefile.in}.  The macro definitions and targets in
377 the @file{Makefile.am} are copied into the generated file.
379 Automake tries to group comments with adjoining targets (or variable
380 definitions) in an intelligent way.
382 A target defined in @file{Makefile.am} generally overrides any such
383 target of a similar name that would be automatically generated by
384 @code{automake}.  Although this is a supported feature, it is generally
385 best to avoid making use of it, as sometimes the generated rules are
386 very particular.
388 Automake also allows a form of comment which is @emph{not} copied into
389 the output; all lines beginning with @samp{##} are completely ignored by
390 Automake.
392 It is customary to make the first line of @file{Makefile.am} read:
394 @example
395 ## Process this file with automake to produce Makefile.in
396 @end example
398 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
399 @c I don't know quite what to say.
401 @c FIXME document customary ordering of Makefile.am here!
404 @node configure
405 @chapter Scanning @file{configure.in}
407 Automake requires certain variables to be defined and certain macros to
408 be used in the package @file{configure.in}.
410 One such requirement is that @file{configure.in} must define the
411 variables @code{PACKAGE} and @code{VERSION} with @code{AC_SUBST}.
412 @cvindex PACKAGE
413 @cvindex VERSION
414 @code{PACKAGE} should be the name of the package as it appears when
415 bundled for distribution.  For instance, Automake defines @code{PACKAGE}
416 to be @samp{automake}.  @code{VERSION} should be the version number of
417 the release that is being developed.  We recommend that you make
418 @file{configure.in} the only place in your package where the version
419 number is defined; this makes releases simpler.
421 Automake requires the use of the macro @code{AC_ARG_PROGRAM} if a
422 program or script is installed.
423 @cvindex AC_ARG_PROGRAM
425 If your package is not a flat distribution, Automake requires the use of
426 @code{AC_PROG_MAKE_SET}.
427 @cvindex AC_PROG_MAKE_SET
429 Automake will also recognize the use of certain macros and tailor the
430 generated @file{Makefile.in} appropriately.  Currently recognized macros
431 and their effects are:
433 @table @code
434 @item AC_CONFIG_HEADER
435 Automake will generate rules to automatically regenerate the config
436 header.  If you do use this macro, you must create the file
437 @file{stamp-h.in}.  It can be empty.  Also, the @code{AC_OUTPUT} command
438 in @file{configure.in} must create @file{stamp-h}, eg:
439 @example
440 AC_OUTPUT(Makefile,
441 [test -z "$CONFIG_HEADERS" || echo timestamp > stamp-h])
442 @end example
443 @cvindex AC_CONFIG_HEADER
445 @item AC_CONFIG_AUX_DIR
446 Automake will look for various helper scripts, such as
447 @file{mkinstalldirs}, in the directory named in this macro invocation.
448 If not seen, the scripts are looked for in their ``standard'' locations
449 (either the top source directory, or in the source directory
450 corresponding to the current @file{Makefile.am}, whichever is
451 appropriate).
452 @cvindex AC_CONFIG_AUX_DIR
454 @item AC_OUTPUT
455 Automake uses this to determine which files to create.
456 @cvindex AC_OUTPUT
458 @item AC_PATH_XTRA
459 Automake will insert definitions for the variables defined by
460 @code{AC_PATH_XTRA} into each @file{Makefile.in} that builds a C program
461 or library.
462 @cvindex AC_PATH_XTRA
464 @item AC_CANONICAL_HOST
465 @item AC_CANONICAL_SYSTEM
466 @item AC_CHECK_TOOL
467 Automake will ensure that @file{config.guess} and @file{config.sub}
468 exist.
469 @cvindex AC_CANONICAL_HOST
470 @cvindex AC_CANONICAL_SYSTEM
471 @cvindex AC_CHECK_TOOL
473 @item AC_FUNC_ALLOCA
474 @item AC_FUNC_GETLOADAVG
475 @item AC_FUNC_MEMCMP
476 @item AC_STRUCT_ST_BLOCKS
477 @item AM_FUNC_FNMATCH
478 @item AC_FUNC_FNMATCH
479 @item AM_FUNC_STRTOD
480 @item AC_REPLACE_FUNCS
481 @item AC_REPLACE_GNU_GETOPT
482 Automake will ensure that the appropriate source files are part of the
483 distribution, and will ensure that the appropriate dependencies are
484 generated for these objects.  @xref{A Library} for more
485 information.
486 @cvindex AC_FUNC_ALLOCA
487 @cvindex AC_FUNC_GETLOADAVG
488 @cvindex AC_FUNC_MEMCMP
489 @cvindex AC_STRUCT_ST_BLOCKS
490 @cvindex AM_FUNC_FNMATCH
491 @cvindex AC_FUNC_FNMATCH
492 @cvindex AC_REPLACE_FUNCS
493 @cvindex AC_REPLACE_GNU_GETOPT
494 @cvindex AM_FUNC_STRTOD
496 Automake will also detect statements which put @samp{.o} files into
497 @code{LIBOBJS}, and will treat these additional files in a similar way.
498 @cvindex LIBOBJS
500 @item AC_PROG_RANLIB
501 This is required if any libraries are built in the package.
502 @cvindex AC_PROG_RANLIB
504 @item AC_PROG_CXX
505 This is required if any C++ source is included.
506 @cvindex AC_PROG_CXX
508 @item AC_PROG_INSTALL
509 @item AM_PROG_INSTALL
510 @code{AM_PROG_INSTALL} is required if any scripts (@pxref{Scripts}) are
511 installed by the package.  Otherwise, @code{AC_PROG_INSTALL} is
512 required.  @code{AM_INIT_AUTOMAKE} automatically calls
513 @code{AM_PROG_INSTALL}.
514 @cvindex AC_PROG_INSTALL
515 @cvindex AM_PROG_INSTALL
516 @cvindex AM_INIT_AUTOMAKE
518 @item AM_PROG_LIBTOOL
519 Automake will turn on processing for @code{libtool} (@pxref{Top, , The
520 Libtool Manual, libtool.info, The Libtool Manual}).  This work is
521 still preliminary.
522 @cvindex AM_PROG_LIBTOOL
524 @item AC_PROG_YACC
525 If a Yacc source file is seen, then you must either use this macro or
526 declare the variable @samp{YACC} in @file{configure.in}.  The former is
527 preferred.
528 @cvindex AC_PROG_YACC
529 @cvindex YACC
531 @item AC_DECL_YYTEXT
532 This macro is required if there is Yacc source in the package.
533 @cvindex AC_DECL_YYTEXT
535 @item AC_PROG_LEX
536 If a Lex source file is seen, then this macro must be used.
537 @cvindex AC_PROG_LEX
539 @item ALL_LINGUAS
540 If Automake sees that this variable is set in @file{configure.in}, it
541 will check the @file{po} directory to ensure that all the named
542 @samp{.po} files exist, and that all the @samp{.po} files that exist are
543 named.
544 @cvindex ALL_LINGUAS
546 @item AM_C_PROTOTYPES
547 This is required when using automatic de-ANSI-fication, see @ref{ANSI}.
548 @cvindex AM_C_PROTOTYPES
550 @item ud_GNU_GETTEXT
551 This macro is required for packages which use GNU gettext (FIXME xref).
552 It is distributed with gettext.  Automake uses this macro to ensure that
553 the package meets some of gettext's requirements.
554 @cvindex ud_GNU_GETTEXT
556 @item jm_MAINTAINER_MODE
557 This macro adds a @samp{--enable-maintainer-mode} option to
558 @code{configure}.  If this is used, @code{automake} will cause
559 ``maintainer-only'' rules to be turned off by default in the generated
560 @file{Makefile.in}s.
561 @cvindex jm_MAINTAINER_MODE
562 @end table
565 @node Top level
566 @chapter The top-level @file{Makefile.am}
568 In non-flat packages, the top level @file{Makefile.am} must tell
569 Automake which subdirectories are to be built.  This is done via the
570 @code{SUBDIRS} variable.
571 @vindex SUBDIRS
573 The @code{SUBDIRS} macro holds a list of subdirectories in which
574 building of various sorts can occur.  Many targets (eg @code{all}) in
575 the generated @file{Makefile} will run both locally and in all specified
576 subdirectories.  Note that the directories listed in @code{SUBDIRS} are
577 not required to contain @file{Makefile.am}s; only @file{Makefile}s
578 (after configuration).  This allows inclusion of libraries from packages
579 which do not use Automake (such as @code{gettext}).
581 In a deep package, the top-level @file{Makefile.am} is often very short.
582 For instance, here is the @file{Makefile.am} from the textutils
583 distribution:
585 @example
586 SUBDIRS = lib src doc man
587 EXTRA_DIST = @@README_ALPHA@@
588 @end example
590 @code{SUBDIRS} can contain configure substitutions (eg @samp{@@DIRS@@});
591 Automake itself does not actually examine the contents of this variable.
593 If @code{SUBDIRS} is defined, then your @file{configure.in} must include
594 @code{AC_PROG_MAKE_SET}.
597 @node Programs
598 @chapter Building Programs and Libraries
600 A large part of Automake's functionality is dedicated to making it easy
601 to build C programs and libraries.
603 @menu
604 * A Program::                   Building a program
605 * A Library::                   Building a library
606 * Program variables::           Variables used when building a program
607 * Yacc and Lex::                Yacc and Lex support
608 * C++::                         C++ and other languages
609 * ANSI::                        Automatic de-ANSI-fication
610 * Dependencies::                Automatic dependency tracking
611 @end menu
614 @node A Program
615 @section Building a program
617 In a directory containing source that gets built into a program (as
618 opposed to a library), the @samp{PROGRAMS} primary is used.  Programs
619 can be installed in @code{bindir}, @code{sbindir}, @code{libexecdir},
620 @code{pkglibdir}, or not at all.
622 For instance:
624 @example
625 bin_PROGRAMS = hello
626 @end example
628 In this simple case, the resulting @file{Makefile.in} will contain code
629 to generate a program named @code{hello}.  The variable
630 @code{hello_SOURCES} is used to specify which source files get built
631 into an executable:
633 @example
634 hello_SOURCES = hello.c
635 @end example
637 This causes @file{hello.c} to be compiled into @file{hello.o}, and then
638 linked to produce @file{hello}.
640 If @samp{prog_SOURCES} is needed, but not specified, then it defaults to
641 the single file @file{prog.c}.  In the example above, the definition of
642 @code{hello_SOURCES} is actually redundant.
643 @vindex _SOURCES
644 @vindex SOURCES
646 Multiple programs can be built in a single directory.  Multiple programs
647 can share a single source file.  The source file must be listed in each
648 @samp{_SOURCES} definition.
650 Header files listed in a @samp{_SOURCES} definition will be ignored.
651 Lex (@samp{.l}) and yacc (@samp{.y}) files can also be listed; support
652 for these should work but is still preliminary.
653 @c lex & yacc should have a separate section
655 Sometimes it is useful to determine the programs that are to be built at
656 configure time.  For instance, GNU @code{cpio} only builds @code{mt} and
657 @code{rmt} under special circumstances.
659 In this case, you must notify @code{Automake} of all the programs that
660 can possibly be built, but at the same time cause the generated
661 @file{Makefile.in} to use the programs specified by @code{configure}.
662 This is done by having @code{configure} substitute values into each
663 @samp{_PROGRAMS} definition, while listing all optionally built programs in
664 @code{EXTRA_PROGRAMS}.
665 @vindex EXTRA_PROGRAMS
667 If you need to link against libraries that are not found by
668 @code{configure}, you can use @code{LDADD} to do so.  This variable
669 actually can be used to add any options to the linker command line.
670 @vindex LDADD
672 Sometimes, multiple programs are built in one directory but do not share
673 the same link-time requirements.  In this case, you can use the
674 @samp{@var{prog}_LDADD} variable (where @var{PROG} is the name of the
675 program as it appears in some @samp{_PROGRAMS} variable, and usually
676 written in lowercase) to override the global @code{LDADD}.  (If this
677 variable exists for a given program, then that program is not linked
678 using @code{LDADD}.)
679 @vindex _LDADD
681 For instance, in GNU cpio, @code{pax}, @code{cpio}, and @code{mt} are
682 linked against the library @file{libcpio.a}.  However, @code{rmt} is
683 built in the same directory, and has no such link requirement.  Also,
684 @code{mt} and @code{rmt} are only built on certain architectures.  Here
685 is what cpio's @file{src/Makefile.am} looks like (abridged):
687 @example
688 bin_PROGRAMS = cpio pax @@MT@@
689 libexec_PROGRAMS = @@RMT@@
690 EXTRA_PROGRAMS = mt rmt
692 LDADD = ../lib/libcpio.a @@INTLLIBS@@
693 rmt_LDADD =
695 cpio_SOURCES = @dots{}
696 pax_SOURCES = @dots{}
697 mt_SOURCES = @dots{}
698 rmt_SOURCES = @dots{}
699 @end example
701 It is also occasionally useful to have a program depend on some other
702 target which is not actually part of that program.  This can be done
703 using the @samp{prog_DEPENDENCIES} variable.  Each program depends on
704 the contents of such a variable, but no further interpretation is done.
706 Since program names are rewritten into Makefile macro names, program
707 names must follow Makefile macro syntax.  Sometimes it is useful to have
708 a program whose name does not follow such rules.  In these cases,
709 Automake canonicalizes the program name.  All characters in the name
710 except for letters, numbers, and the underscore are turned into
711 underscores when making macro references.  Eg, if your program is named
712 @code{sniff-glue}, you would use @code{sniff_glue_SOURCES}, not
713 @code{sniff-glue_SOURCES}.
716 @node A Library
717 @section Building a library
719 Building a library is much like building a program.  In this case, the
720 name of the primary is @samp{LIBRARIES}.  Libraries can be installed in
721 @code{libdir} or @code{pkglibdir}.
723 Each @samp{_LIBRARIES} variable is a list of the base names of
724 libraries to be built.  For instance to create a library named
725 @file{libcpio.a}, but not install it, you would write:
727 @example
728 noinst_LIBRARIES = cpio
729 @end example
731 The sources that go into a library are determined exactly as they are
732 for programs, via the @samp{_SOURCES} variables.  Note that programs and
733 libraries share a namespace, so one cannot have a program (@file{lob}) and
734 a library (@file{liblob.a}) with the same name in one directory.
736 Extra objects can be added to a library using the @samp{library_LIBADD}
737 variable.  This should be used for objects determined by
738 @code{configure}.  Again from cpio:
739 @vindex _LIBADD
740 @vindex LIBADD
742 @example
743 cpio_LIBADD = @@LIBOBJS@@ @@ALLOCA@@
744 @end example
746 Note that Automake explicitly recognizes the use of @code{@@LIBOBJS@@}
747 and @code{@@ALLOCA@@} in the above example, and uses this information,
748 plus the list of @code{LIBOBJS} files derived from @file{configure.in}
749 to automatically include the appropriate source files in the
750 distribution (@pxref{Dist}).  These source files are also automatically
751 handled in the dependency-tracking scheme, see @xref{Dependencies}.
754 @node Program variables
755 @section Variables used when building a program
757 Occasionally it is useful to know which @file{Makefile} variables
758 Automake uses for compilations; for instance you might need to do your
759 own compilation in some special cases.
761 Some variables are inherited from Autoconf; these are @code{CC},
762 @code{CFLAGS}, @code{CPPFLAGS}, @code{CXX}, @code{CXXFLAGS},
763 @code{DEFS}, @code{LDFLAGS}, and @code{LIBS}.
766 There are some additional variables which Automake itself defines:
768 @table @code
769 @item INCLUDES
770 A list of @samp{-I} options.  This can be set in your @file{Makefile.am}
771 if you have special directories you want to look in.
773 @item COMPILE
774 This is the command used to actually compile a C source file.  The
775 filename is appended to form the complete command line.
777 @item LINK
778 This is the command used to actually link a C program.
779 @end table
782 @node Yacc and Lex
783 @section Yacc and Lex support
785 Automake has somewhat idiosyncratic support for Yacc and Lex.
790 @node C++
791 @section C++ and other languages
793 Automake includes full support for C++, and rudimentary support for
794 other languages.  Support for other languages will be improved based on
795 demand.
797 Any package including C++ code must use @code{AC_PROG_CXX} in its
798 @file{configure.in}.
801 A few additional variables are defined when a C++ source file is seen.
804 @node ANSI
805 @section Automatic de-ANSI-fication
807 Although the GNU standards prohibit it, some GNU programs are written in
808 ANSI C; see FIXME.  This is possible because each source file can be
809 ``de-ANSI-fied'' before the actual compilation takes place.
811 If the @file{Makefile.am} variable @code{AUTOMAKE_OPTIONS}
812 @vindex AUTOMAKE_OPTIONS
813 (@ref{Options}) contains the option @code{ansi2knr}
814 @opindex ansi2knr
815 then code to handle de-ANSI-fication is inserted into the generated
816 @file{Makefile.in}.
818 This causes each source file to be treated as ANSI C.  If an ANSI C
819 compiler is available, it is used.
821 This support requires the source files @file{ansi2knr.c} and
822 @file{ansi2knr.1} to be in the same directory as the ANSI C source;
823 these files are distributed with Automake.
824 Also, the package @file{configure.in} must call the macro
825 @code{fp_C_PROTOTYPES}.
826 @cvindex fp_C_PROTOTYPES
829 @node Dependencies
830 @section Automatic dependency tracking
832 As a developer it is often painful to continually update the
833 @file{Makefile.in} whenever the include-file dependencies change in a
834 project.  @code{automake} supplies a way to automatically track
835 dependency changes, and distribute the dependencies in the generated
836 @file{Makefile.in}.
838 Currently this support requires the use of GNU @code{make} and
839 @code{gcc}.  It might become possible in the future to supply a
840 different dependency generating program, if there is enough demand.
842 This mode is enabled by default if any C program or library is defined
843 in the current directory.
845 When you decide to make a distribution, the @code{dist} target will
846 @trindex dist
847 re-run @code{automake} with the @samp{--include-deps} option.  This
848 @c FIXME XREF?
849 causes the previously generated dependencies to be inserted into the
850 generated @file{Makefile.in}, and thus into the distribution.
851 @samp{--include-deps} also turns off inclusion of the dependency
852 generation code.
854 This mode can be suppressed by putting @code{no-dependencies} in the
855 variable @code{AUTOMAKE_OPTIONS}.
856 @vindex AUTOMAKE_OPTIONS
857 @opindex no-dependencies
860 @node Other objects
861 @chapter Other Derived Objects
863 Automake can handle derived objects which are not C programs.  Sometimes
864 the support for actually building such objects must be explicitly
865 supplied, but Automake will still automatically handle installation and
866 distribution.
868 @menu
869 * Scripts::                     Executable scripts
870 * Headers::                     Header files
871 * Data::                        Architecture-independent data files
872 * Sources::                     Derived sources
873 @end menu
876 @node Scripts
877 @section Executable Scripts
879 It is possible to define and install programs which are scripts.  Such
880 programs are listed using the @samp{SCRIPTS} primary name.
881 @code{automake} doesn't define any dependencies for scripts; the
882 @file{Makefile.am} should include the appropriate rules.
883 @vindex SCRIPTS
885 @code{automake} does not assume that scripts are derived objects; such
886 objects are must be deleted by hand; see @ref{Clean} for more
887 information.
889 @code{automake} itself is a script that is generated at configure time
890 from @file{automake.in}.  Here is how this is handled:
892 @example
893 bin_SCRIPTS = automake
894 @end example
896 Since @code{automake} appears in the @code{AC_OUTPUT} macro,
897 dependencies for it are automatically generated.
899 Script objects can be installed in @code{bindir}, @code{sbindir},
900 @code{libexecdir}, or @code{pkgdatadir}.
903 @node Headers
904 @section Header files
906 Header files are specified by the @samp{HEADERS} family of variables.
907 Generally header files are not installed, so the @code{noinst_HEADERS}
908 variable will be the most used.
909 @vindex HEADERS
911 All header files must be listed somewhere; missing ones will not appear
912 in the distribution.  Often it is most convenient to list uninstalled
913 headers with the rest of the sources for a program.  @xref{A Program}.
914 Headers listed in a @samp{_SOURCES} variable need not be listed in any
915 @samp{_HEADERS} variable.
917 Headers can be installed in @code{includedir}, @code{oldincludedir}, or
918 @code{pkgincludedir}.
921 @node Data
922 @section Architecture-independent data files
924 Automake supports the installation of miscellaneous data files using the
925 @samp{DATA} family of variables.
926 @vindex DATA
928 Such data can be installed in the directories @code{datadir},
929 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
930 @code{pkgdatadir}.
932 All such data files are included in the distribution.
934 Here is how @code{automake} installs its auxiliary data files:
936 @example
937 pkgdata_DATA = clean-kr.am clean.am compile-kr.am compile-vars.am \
938 compile.am data.am depend.am dist-subd-top.am dist-subd-vars.am \
939 dist-subd.am dist-vars.am dist.am footer.am header-vars.am header.am \
940 libscripts.am libprograms.am libraries-vars.am libraries.am library.am \
941 mans-vars.am mans.am packagedata.am program.am programs.am remake-hdr.am \
942 remake-subd.am remake.am scripts.am subdirs.am tags.am tags-subd.am \
943 texinfos-vars.am texinfos.am hack-make.sed nl-remove.sed
944 @end example
947 @node Sources
948 @section Built sources
950 Occasionally a file which would otherwise be called ``source'' (eg a C
951 @samp{.h} file) is actually derived from some other file.  Such files
952 should be listed in the @code{BUILT_SOURCES} variable.
953 @vindex BUILT_SOURCES
955 Files listed in @code{BUILT_SOURCES} are built before any automatic
956 dependency tracking is done.  Built sources are included in a
957 distribution.
960 @node Emacs Lisp
961 @chapter Emacs Lisp
963 Automake provides some support for Emacs Lisp.  The @samp{LISP} primary
964 is used to hold a list of @samp{.el} files.  Possible prefixes for this
965 primary are @samp{lisp_} and @samp{noinst_}.  Note that if
966 @code{lisp_LISP} is defined, then @file{configure.in} must run
967 @code{AM_PATH_LISPDIR} (fixme xref).
968 @vindex LISP
969 @vindex lisp_LISP
970 @vindex noinst_LISP
972 By default Automake will byte-compile all Emacs Lisp source files using
973 the Emacs found by @code{AM_PATH_LISPDIR}.  If you wish to avoid
974 byte-compiling, simply define the variable @samp{ELCFILES} to be empty.
975 @vindex ELCFILES
977 @node Documentation
978 @chapter Building documentation
980 Currently Automake provides support for Texinfo and man pages.
982 @menu
983 * Texinfo::                     Texinfo
984 * Man pages::                   Man pages
985 @end menu
988 @node Texinfo
989 @section Texinfo
991 If the current directory contains Texinfo source, you must declare it
992 with the @samp{TEXINFOS} primary.  Generally Texinfo files are converted
993 into info, and thus the @code{info_TEXINFOS} macro is most commonly used
994 here.  Note that any Texinfo source file must end in the @samp{.texi}
995 extension (@samp{.texinfo} won't work).
996 @vindex TEXINFOS
997 @vindex info_TEXINFOS
999 If the @samp{.texi} file @code{@@include}s @file{version.texi}, then that
1000 file will be automatically generated.  @file{version.texi} defines three
1001 Texinfo macros you can reference: @code{EDITION}, @code{VERSION}, and
1002 @code{UPDATED}.  The first two hold the version number of your package
1003 (but are kept separate for clarity); the last is the date the primary
1004 file was last modified.  The @file{version.texi} support requires the
1005 @code{mdate-sh} program; this program is supplied with Automake.
1007 Sometimes an info file actually depends on more than one @samp{.texi}
1008 file.  For instance, in the @code{xdvik} distribution,
1009 @file{kpathsea.texi} includes the files @file{install.texi},
1010 @file{copying.texi}, and @file{freedom.texi}.  You can tell Automake
1011 about these dependencies using the @samp{texi_TEXINFOS} variable.  Here
1012 is how @code{xdvik} could do it:
1013 @vindex TEXINFOS
1014 @vindex _TEXINFOS
1016 @example
1017 info_TEXINFOS = kpathsea.texi
1018 kpathsea_TEXINFOS = install.texi copying.texi freedom.texi
1019 @end example
1021 Automake will warn if a directory containing Texinfo source does not
1022 also contain the file @file{texinfo.tex}.  This file is supplied with
1023 Automake.
1025 Automake generates an @code{install-info} target; some people apparently
1026 use this.  By default, info pages are installed by @samp{make install}.
1027 This can be prevented via the @code{no-installinfo} option.
1030 @node Man pages
1031 @section Man pages
1033 A package can also include man pages.  (Though see the GNU standards on
1034 this matter, @ref{Man Pages, , , standards.info, The GNU Coding
1035 Standards}.)  Man pages are declared using the @samp{MANS} primary.
1036 Generally the @code{man_MANS} macro is used.  Man pages are
1037 automatically installed in the correct subdirectory of @code{mandir},
1038 based on the file extension.
1039 @vindex MANS
1040 @vindex man_MANS
1042 @c Use @samp{make install} per documentation: (texi.info)code.
1043 By default, man pages are installed by @samp{make install}.  However,
1044 since the GNU project does not require man pages, many maintainers do
1045 not expend effort to keep the man pages up to date.  In these cases, the
1046 @code{no-installman} option will prevent the man pages from being
1047 installed by default.  The user can still explicitly install them via
1048 @samp{make install-man}.
1049 @opindex no-installman
1050 @trindex install-man
1052 Here is how the documentation is handled in GNU @code{cpio} (which
1053 includes both Texinfo documentation and man pages):
1055 @example
1056 info_TEXINFOS = cpio.texi
1057 man_MANS = cpio.1 mt.1
1058 @end example
1060 Texinfo source, info pages and man pages are all considered to be source
1061 for the purposes of making a distribution.
1064 @node Install
1065 @chapter What Gets Installed
1067 Naturally, Automake handles the details of actually installing your
1068 program once it has been built.  All @code{PROGRAMS}, @code{SCRIPTS},
1069 @code{LIBRARIES}, @code{DATA} and @code{HEADERS} are automatically
1070 installed in the appropriate places.
1072 Automake also handles installing any specified info and man pages.
1074 Automake generates separate @code{install-data} and @code{install-exec}
1075 targets, in case the installer is installing on multiple machines which
1076 share directory structure -- these targets allow the machine-independent
1077 parts to be installed only once.  The @code{install} target depends on
1078 both of these targets.
1079 @trindex install-data
1080 @trindex install-exec
1081 @trindex install
1083 Automake also generates an @code{uninstall} target, and an
1084 @code{installdirs} target.
1085 @trindex uninstall
1086 @trindex installdirs
1088 It is possible to extend this mechanism by defining an
1089 @code{install-exec-local} or @code{install-data-local} target.  If these
1090 targets exist, they will be run at @samp{make install} time.
1091 @trindex install-exec-local
1092 @trindex install-data-local
1095 @node Clean
1096 @chapter What Gets Cleaned
1098 The GNU Makefile Standards specify a number of different clean rules.
1099 @c FIXME xref
1100 Generally the files that can cleaned are determined automatically by
1101 Automake.  Of course, Automake also recognizes some variables that can
1102 be defined to specify additional files to clean.  These variables are
1103 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
1104 @code{MAINTAINERCLEANFILES}.
1105 @vindex MOSTLYCLEANFILES
1106 @vindex CLEANFILES
1107 @vindex DISTCLEANFILES
1108 @vindex MAINTAINERCLEANFILES
1110 In Automake, the @code{automake} program is not automatically removed,
1111 because it is an executable script.  So this code in @file{Makefile.am}
1112 causes it to be removed by @samp{make clean}:
1114 @example
1115 CLEANFILES = automake
1116 @end example
1119 @node Dist
1120 @chapter What Goes in a Distribution
1122 The @code{dist} target in the generated @file{Makefile.in} can be used
1123 to generate a gzip'd @code{tar} file for distribution.  The tar file is
1124 named based on the @var{PACKAGE} and @var{VERSION} variables.
1125 @cvindex PACKAGE
1126 @cvindex VERSION
1127 @trindex dist
1129 For the most part, the files to distribute are automatically found by
1130 Automake: all source files are automatically included in a distribution,
1131 as are all @file{Makefile.am}s and @file{Makefile.in}s.  Automake also
1132 has a built-in list of commonly used files which, if present in the
1133 current directory, are automatically included.  This list is printed by
1134 @samp{automake --help}.  Also, files which are read by @code{configure}
1135 (ie, the source files corresponding to the files specified in the
1136 @code{AC_OUTPUT} invocation) are automatically distributed.
1138 Still, sometimes there are files which must be distributed, but which
1139 are not covered in the automatic rules.  These files should be listed in
1140 the @code{EXTRA_DIST} variable.
1141 @vindex EXTRA_DIST
1143 Occasionally it is useful to be able to change the distribution before
1144 it is packaged up.  If the @code{dist-hook} target exists, it is run
1145 after the distribution directory is filled, but before the actual tar
1146 (or shar) file is created.  One way to use this is for distributing file
1147 in subdirectories for which a new @file{Makefile.am} is overkill:
1149 @example
1150 dist-hook:
1151         mkdir $(distdir)/random
1152         cp -p random/a1 random/a2 $(distdir)/random
1153 @end example
1155 Automake also generates a @code{distcheck} target which can be help to
1156 ensure that a given distribution will actually work.  @code{distcheck}
1157 makes a distribution, and then tries to do a @code{VPATH} build.
1158 @trindex distcheck
1161 @node Tests
1162 @chapter Support for test suites
1164 Automake supports a two forms of test suite.
1166 If the variable @code{TESTS} is defined, its value is taken to be a list
1167 of programs to run in order to do the testing.  The programs can either
1168 be derived objects or source objects; the generated rule will look both
1169 in @var{srcdir} and @file{.}.  The number of failures will be printed at
1170 the end of the run.  The variable @code{TESTS_ENVIRONMENT} can be used
1171 to set environment variables for the test run; the environment variable
1172 @code{srcdir} is set in the rule.
1173 @vindex TESTS
1174 @vindex TESTS_ENVIRONMENT
1176 If @samp{dejagnu} appears in @code{AUTOMAKE_OPTIONS}, then the a
1177 @code{dejagnu}-based test suite is assumed.  The value of the variable
1178 @code{DEJATOOL} is passed as the @code{--tool} argument to
1179 @code{runtest}; it defaults to the name of the package.  The variables
1180 @code{EXPECT}, @code{RUNTEST} and @code{RUNTESTFLAGS} can also be
1181 overridden to provide project-specific values.  For instance, you will
1182 need to do this if you are testing a compiler toolchain, because the
1183 default values do not take into account host and target names.
1184 @opindex dejagnu
1185 @vindex DEJATOOL
1186 @vindex EXPECT
1187 @vindex RUNTEST
1188 @vindex RUNTESTFLAGS
1189 @c FIXME xref dejagnu
1191 In either case, the testing is done via @samp{make check}.
1194 @node Options
1195 @chapter Changing Automake's Behavior
1197 Various features of Automake can be controlled by options in the
1198 @file{Makefile.am}.  Such options are listed in a special variable named
1199 @code{AUTOMAKE_OPTIONS}.  Currently understood options are:
1200 @vindex AUTOMAKE_OPTIONS
1202 @table @asis
1203 @item @code{gnits}
1204 @itemx @code{gnu}
1205 @itemx @code{foreign}
1206 The same as the corresponding @samp{--strictness} option.
1208 @item @code{no-installman}
1209 The generated @file{Makefile.in} will not cause man pages to be
1210 installed by default.  However, an @code{install-man} target will still
1211 be available for optional installation.  This option is disallowed at
1212 @samp{GNU} strictness and above.
1213 @trindex install-man
1215 @item @code{no-installinfo}
1216 The generated @file{Makefile.in} will not cause info pages to be built
1217 or installed by default.  However, @code{info} and @code{install-info}
1218 targets will still be available.  This option is disallowed at
1219 @samp{GNU} strictness and above.
1220 @trindex info
1221 @trindex install-info
1223 @item @code{ansi2knr}
1224 @item @code{path/ansi2knr}
1225 Turn on automatic de-ANSI-fication.  If preceeded by a path, the
1226 generated @file{Makefile.in} will look in the specified directory to
1227 find the @file{ansi2knr} program.  Generally the path should be a
1228 relative path to another directory in the same distribution (though
1229 Automake currently does not check this).  It is up to you to make sure
1230 that the specified directory is built before the current directory; if
1231 @file{ansi2knr} does not exist then the build will fail.
1233 @item @code{dejagnu}
1234 Cause @code{dejagnu}-specific rules to be generated.  @xref{Tests}.
1236 @item @code{dist-shar}
1237 Generate a @code{dist-shar} target as well as the ordinary @code{dist}
1238 target.  This new target will create a shar archive of the
1239 distribution.
1240 @trindex dist-shar
1242 @item @code{dist-zip}
1243 Generate a @code{dist-zip} target as well as the ordinary @code{dist}
1244 target.  This new target will create a zip archive of the distribution.
1245 @trindex dist-zip
1247 @item @code{dist-tarZ}
1248 Generate a @code{dist-tarZ} target as well as the ordinary @code{dist}
1249 target.  This new target will create a compressed tar archive of the
1250 distribution; a traditional @code{tar} and @code{compress} will be
1251 assumed.  Warning: if you are actually using @code{GNU tar}, then the
1252 generated archive might contain nonportable constructs.
1253 @trindex dist-tarZ
1255 @item @code{no-dependencies}
1256 This is similar to using @samp{--include-deps} on the command line, but
1257 is useful for those situations where you don't have the necessary bits
1258 to make automatic dependency tracking work @xref{Dependencies}.  In this
1259 case the effect is to effectively disable automatic dependency tracking.
1261 @item @var{version}
1262 A version number (eg @samp{0.30}) can be specified.  If Automake is not
1263 newer than the version specified, creation of the @file{Makefile.in}
1264 will be suppressed.
1265 @end table
1267 Unrecognized options are diagnosed by @code{automake}.
1270 @node Miscellaneous
1271 @chapter Miscellaneous Rules
1273 There are a few rules and variables that didn't fit anywhere else.
1275 @menu
1276 * Tags::                        Interfacing to etags and mkid
1277 * Suffixes::                    Handling new file extensions
1278 * Built::                       Built sources
1279 @end menu
1282 @node Tags
1283 @section Interfacing to @code{etags}
1285 @code{automake} will generate rules to generate @file{TAGS} files for
1286 use with GNU Emacs under some circumstances.
1288 If any C source code or headers are present, then a @code{tags} target
1289 will be generated for the directory.
1290 @trindex tags
1292 At the topmost directory of a multi-directory package, a @code{tags}
1293 target file will be generated which, when run, will generate a
1294 @file{TAGS} file that includes by reference all @file{TAGS} files from
1295 subdirectories.
1297 Also, if the variable @code{ETAGS_ARGS} is defined, a @code{tags} target
1298 will be generated.  This variable is intended for use in directories
1299 which contain taggable source that @code{etags} does not understand.
1300 @vindex ETAGS_ARGS
1302 Here is how Automake generates tags for its source, and for nodes in its
1303 Texinfo file:
1305 @example
1306 ETAGS_ARGS = automake.in --lang=none \
1307  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
1308 @end example
1310 If you add filenames to @var{ETAGS_ARGS}, you will probably also
1311 want to set @var{TAGS_DEPENDENCIES}.  The contents of this variable
1312 are added directly to the dependencies for the @code{tags} target.
1313 @vindex TAGS_DEPENDENCIES
1315 Automake will also generate an @code{ID} target which will run
1316 @code{mkid} on the source.  This is only supported on a
1317 directory-by-directory basis.
1318 @trindex id
1321 @node Suffixes
1322 @section Handling new file extensions
1324 It is sometimes useful to introduce a new implicit rule to handle a file
1325 type that Automake does not know about.  If this is done, you must
1326 notify GNU Make of the new suffixes.  This can be done by putting a list
1327 of new suffixes in the @code{SUFFIXES} variable.
1328 @vindex SUFFIXES
1331 @node Built
1332 @section Built sources
1334 FIXME write this
1337 @node Extending
1338 @chapter When Automake Isn't Enough
1340 Sometimes @code{automake} isn't enough.  Then you just lose.
1342 Actually, @code{automake}s implicit copying semantics means that many
1343 problems can be worked around by simply adding some @code{make} targets
1344 and rules to @file{Makefile.in}.  @code{automake} will ignore these
1345 additions.
1347 There are some caveats to doing this.  Although you can overload a
1348 target already used by @code{automake}, it is often inadvisable,
1349 particularly in the topmost directory of a non-flat package.  However,
1350 various useful targets have a @samp{-local} version you can specify in your
1351 @file{Makefile.in}.  Automake will supplement the standard target with
1352 these user-supplied targets.
1354 The targets that support a local version are @code{all}, @code{info},
1355 @code{dvi}, @code{check}, @code{install-data}, @code{install-exec}, and
1356 @code{uninstall}.  Note that there are no @code{uninstall-exec-local} or
1357 @code{uninstall-data-local} targets; just use @code{uninstall-local}.
1358 It doesn't make sense to uninstall just data or just executables.
1359 @trindex all
1360 @trindex info
1361 @trindex dvi
1362 @trindex check
1363 @trindex install-data
1364 @trindex install-exec
1365 @trindex uninstall
1367 For instance, here is how to install a file in @file{/etc}:
1369 @example
1370 install-data-local:
1371         $(INSTALL_DATA) $(srcdir)/afile /etc/afile
1372 @end example
1374 Some targets also have a way to run another target, called a @dfn{hook},
1375 after their work is done.  The hook is named after the principal target,
1376 with @samp{-hook} appended.  The targets allowing hooks are
1377 @code{install-data}, @code{install-exec}, and @code{dist}.
1378 @trindex install-data-hook
1379 @trindex install-exec-hook
1380 @trindex dist-hook
1382 For instance, here is how to create a hard link to an installed program:
1384 @example
1385 install-exec-hook:
1386         $(LN) $(bindir)/program $(bindir)/proglink
1387 @end example
1389 @c FIXME should include discussion of variables you can use in these
1390 @c rules
1393 @node Distributing
1394 @chapter Distributing @file{Makefile.in}s
1396 Automake places no restrictions on the distribution of the resulting
1397 @file{Makefile.in}s.  We still encourage software authors to distribute
1398 their work under terms like those of the GPL, but doing so is not
1399 required to use Automake.
1401 Some of the files that can be automatically installed via the
1402 @samp{--add-missing} switch do fall under the GPL; examine each file
1403 to see.
1406 @node Examples
1407 @chapter Some example packages
1409 Here are some examples of how Automake can be used.
1411 @menu
1412 * Hello::                       The simplest GNU program
1413 * Tricky::                      A trickier example
1414 * Automake::                    Automake's own use
1415 * Textutils::                   A deep hierarchy
1416 @end menu
1418 @node Hello
1419 @section The simplest GNU program
1421 @code{hello} is renowned for its classic simplicity and versatility.
1422 What better place to begin a tour?  The below shows what could be used
1423 as the Hello distribution's @file{Makefile.am}.
1425 @example
1426 bin_PROGRAMS = hello
1427 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h
1428 hello_LDADD = @@ALLOCA@@
1429 info_TEXINFOS = hello.texi
1430 hello_TEXINFOS = gpl.texi
1432 EXTRA_DIST = testdata
1434 check-local: hello
1435         @@echo expect no output from diff
1436         ./hello > test.out
1437         diff -c $(srcdir)/testdata test.out
1438         rm -f test.out
1439 @end example
1441 Of course, Automake also requires some minor changes to
1442 @file{configure.in}.  The new @file{configure.in} would read:
1444 @example
1445 dnl Process this file with autoconf to produce a configure script.
1446 AC_INIT(hello.c)
1447 VERSION=1.3
1448 AC_SUBST(VERSION)
1449 PACKAGE=hello
1450 AC_SUBST(PACKAGE)
1451 AC_PROG_CC
1452 AC_PROG_CPP
1453 AC_PROG_INSTALL
1454 AC_STDC_HEADERS
1455 AC_HAVE_HEADERS(string.h fcntl.h sys/file.h)
1456 AC_ALLOCA
1457 AC_OUTPUT(Makefile)
1458 @end example
1460 If Hello were really going to use Automake, the @file{version.c} file
1461 would probably be deleted, or changed so as to be automatically
1462 generated.
1465 @node Tricky
1466 @section A tricker example
1468 Here is another, trickier example.  It shows how to generate two
1469 programs (@code{ctags} and @code{etags}) from the same source file
1470 (@file{etags.c}).  The difficult part is that each compilation of
1471 @file{etags.c} requires different @code{cpp} flags.
1473 @example
1474 bin_PROGRAMS = etags ctags
1475 ctags_SOURCES =
1476 ctags_LDADD = ctags.o
1477 ctags_DEPENDENCIES = ctags.o
1479 etags.o:
1480         $(COMPILE) -DETAGS_REGEXPS etags.c
1482 ctags.o:
1483         $(COMPILE) -DCTAGS -o ctags.o etags.c
1484 @end example
1486 Note that @code{ctags_SOURCES} is defined to be empty -- that way no
1487 implicit value is substituted.  The implicit value, however, is used to
1488 generate @code{etags} from @file{etags.o}.
1490 @code{ctags_LDADD} is used to get @file{ctags.o} into the link line,
1491 while @code{ctags_DEPENDENCIES} exists to make sure that @file{ctags.o}
1492 gets built in the first place.
1494 This is a somewhat pathological example.
1497 @node Automake
1498 @section Automake uses itself
1500 Automake, of course, uses itself to generate its @file{Makefile.in}.
1501 Since Automake is a shallow package, it has more than one
1502 @file{Makefile.am}.  Here is the top-level @file{Makefile.am}:
1504 @example
1505 ## Process this file with automake to create Makefile.in
1507 AUTOMAKE_OPTIONS = gnits
1508 MAINT_CHARSET = latin1
1509 PERL = @@PERL@@
1511 SUBDIRS = tests
1513 bin_SCRIPTS = automake
1514 info_TEXINFOS = automake.texi
1516 pkgdata_DATA = clean-kr.am clean.am compile-kr.am compile-vars.am \
1517 compile.am data.am depend.am \
1518 dist-vars.am footer.am header.am header-vars.am \
1519 kr-vars.am libraries-vars.am \
1520 libraries.am library.am mans-vars.am \
1521 program.am programs.am remake-hdr.am \
1522 remake-subd.am remake.am scripts.am subdirs.am tags.am tags-subd.am \
1523 tags-clean.am \
1524 texi-version.am texinfos-vars.am texinfos.am \
1525 libraries-clean.am programs-clean.am data-clean.am \
1526 COPYING INSTALL texinfo.tex \
1527 ansi2knr.c ansi2knr.1 \
1528 aclocal.m4
1530 ## These must all be executable when installed.
1531 pkgdata_SCRIPTS = config.guess config.sub install-sh mdate-sh mkinstalldirs
1533 CLEANFILES = automake
1535 # The following requires a fixed version of the Emacs 19.30 etags.
1536 ETAGS_ARGS = automake.in --lang=none \
1537  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
1539 ## `test -x' is not portable.  So we use Perl instead.  If Perl
1540 ## doesn't exist, then this test is meaningless anyway.
1541 # Check to make sure some installed files are executable.
1542 installcheck-local:
1543         $(PERL) -e "exit ! -x '$(pkgdatadir)/config.guess';"
1544         $(PERL) -e "exit ! -x '$(pkgdatadir)/config.sub';"
1545         $(PERL) -e "exit ! -x '$(pkgdatadir)/install-sh';"
1546         $(PERL) -e "exit ! -x '$(pkgdatadir)/mdate-sh';"
1547         $(PERL) -e "exit ! -x '$(pkgdatadir)/mkinstalldirs';"
1549 # Some simple checks:
1550 # * syntax check with perl4 and perl5.
1551 # * make sure the scripts don't use 'true'
1552 # * expect no instances of '$@{...@}'
1553 # These are only really guaranteed to work on my machine.
1554 maintainer-check: automake check
1555         $(PERL) -c -w automake
1556         @@if grep '^[^#].*true' $(srcdir)/[a-z]*.am; then \
1557           echo "can't use 'true' in GNU Makefile" 1>&2; \
1558           exit 1;                               \
1559         else :; fi
1560         @@if test `fgrep '$$@{' $(srcdir)/[a-z]*.am | wc -l` -ne 0; then \
1561           echo "found too many uses of '\$$@{'" 1>&2; \
1562           exit 1;                               \
1563         fi
1564         if $(SHELL) -c 'perl4.036 -v' >/dev/null 2>&1; then \
1565           perl4.036 -c -w automake; \
1566         else :; fi
1568 # Tag before making distribution.  Also, don't make a distribution if
1569 # checks fail.  Also, make sure the NEWS file is up-to-date.
1570 cvs-dist: maintainer-check
1571         @@if sed 1q NEWS | grep -e "$(VERSION)" > /dev/null; then :; else \
1572           echo "NEWS not updated; not releasing" 1>&2; \
1573           exit 1;                               \
1574         fi
1575         cvs tag `echo "Release-$(VERSION)" | sed 's/\./-/g'`
1576         $(MAKE) dist
1577 @end example
1579 As you can see, Automake defines many of its own rules, to make the
1580 maintainer's job easier.  For instance the @code{cvs-dist} rule
1581 automatically tags the current version in the CVS repository, and then
1582 makes a standard distribution.
1584 Automake consists primarily of one program, @code{automake}, and a
1585 number of auxiliary scripts.  Automake also installs a number of
1586 programs which are possibly installed via the @samp{--add-missing}
1587 option; these scripts are listed in the @code{pkgdata_SCRIPTS} variable.
1589 Automake also has a @file{tests} subdirectory, as indicated in the
1590 @code{SUBDIRS} variable above.  Here is @file{tests/Makefile.am}:
1592 @example
1593 ## Process this file with automake to create Makefile.in
1595 AUTOMAKE_OPTIONS = gnits
1597 TESTS = mdate.test vtexi.test acoutput.test instexec.test checkall.test \
1598 acoutnoq.test acouttbs.test libobj.test proginst.test acoutqnl.test \
1599 confincl.test spelling.test prefix.test badprog.test depend.test
1601 EXTRA_DIST = defs
1602 @end example
1604 This is where all the tests are really run.  @file{defs} is an
1605 initialization file used by each test script; it is explicitly mentioned
1606 because @code{automake} has no way of automatically finding it.
1609 @node Textutils
1610 @section A deep hierarchy
1612 The GNU textutils are a collection of programs for manipulating text
1613 files.  They are distributed as a deep package.  The textutils have only
1614 recently been modified to use Automake; the examples come from a
1615 prerelease.
1617 Here is the top-level @file{Makefile.am}:
1619 @example
1620 SUBDIRS = lib src doc man
1621 @end example
1623 In the @file{lib} directory, a library is built which is used by each
1624 textutil.  Here is @file{lib/Makefile.am}:
1626 @example
1627 noinst_LIBRARIES = tu
1629 EXTRA_DIST = rx.c regex.c
1631 tu_SOURCES = error.h getline.h getopt.h linebuffer.h \
1632 long-options.h md5.h regex.h rx.h xstrtod.h xstrtol.h xstrtoul.h \
1633 error.c full-write.c getline.c getopt.c getopt1.c \
1634 linebuffer.c long-options.c md5.c memchr.c safe-read.c \
1635 xmalloc.c xstrtod.c xstrtol.c xstrtoul.c
1637 tu_LIBADD = @@REGEXOBJ@@ @@LIBOBJS@@ @@ALLOCA@@
1638 @end example
1640 The @file{src} directory contains the source for all the textutils -- 23
1641 programs in all.  The @file{Makefile.am} for this directory also
1642 includes some simple checking code, and constructs a @file{version.c}
1643 file on the fly:
1645 @example
1646 bin_PROGRAMS = cat cksum comm csplit cut expand fmt fold head join md5sum \
1647 nl od paste pr sort split sum tac tail tr unexpand uniq wc
1649 noinst_HEADERS = system.h version.h
1650 DISTCLEANFILES = stamp-v version.c
1652 INCLUDES = -I$(top_srcdir)/lib
1654 LDADD = version.o ../lib/libtu.a
1656 $(PROGRAMS): version.o ../lib/libtu.a
1658 AUTOMAKE_OPTIONS = ansi2knr
1660 version.c: stamp-v
1661 stamp-v: Makefile
1662         rm -f t-version.c
1663         echo '#include <config.h>' > t-version.c
1664         echo '#include "version.h"' >> t-version.c
1665         echo 'const char *version_string = "'GNU @@PACKAGE@@ @@VERSION@@'";' \
1666                 >> t-version.c
1667         if cmp -s version.c t-version.c; then   \
1668           rm t-version.c;                       \
1669         else                                    \
1670           mv t-version.c version.c;             \
1671         fi
1672         echo timestamp > $@@
1674 check: md5sum
1675         ./md5sum \
1676          --string="" \
1677          --string="a" \
1678          --string="abc" \
1679          --string="message digest" \
1680          --string="abcdefghijklmnopqrstuvwxyz" \
1681          --string="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" \
1682          --string="12345678901234567890123456789012345678901234567890123456789012345678901234567890" \
1683        | diff -c $(srcdir)/md5-test.rfc -
1684 @end example
1686 The @file{doc} directory builds the info documentation for the
1687 textutils:
1689 @example
1690 info_TEXINFOS = textutils.texi
1691 @end example
1693 And, last, the @file{man} directory installs the man pages for all the
1694 textutils:
1696 @example
1697 man_MANS = cat.1 cksum.1 comm.1 csplit.1 cut.1 expand.1 fmt.1 fold.1 head.1 \
1698 join.1 md5sum.1 nl.1 od.1 paste.1 pr.1 sort.1 split.1 sum.1 tac.1 tail.1 \
1699 tr.1 unexpand.1 uniq.1 wc.1
1700 @end example
1702 You can now see how easy it is to handle even a largish project using
1703 Automake.
1706 @node Future
1707 @chapter Some ideas for the future
1709 Here are some things that might happen in the future:
1711 @itemize @bullet
1712 @item
1713 HTML support.
1715 @item
1716 The output will be cleaned up.  For instance, only variables which are
1717 actually used will appear in the generated @file{Makefile.in}.
1719 @item
1720 There will be support for automatically recoding a distribution.  The
1721 intent is to allow a maintainer to use whatever character set is most
1722 convenient locally, but for all distributions to be Unicode or
1723 @w{ISO 10646} with the UTF-8 encoding.
1724 @end itemize
1727 @node Variables
1728 @unnumbered Index of Variables
1730 @printindex vr
1733 @node Configure variables
1734 @unnumbered Index of Configure Variables and Macros
1736 @printindex cv
1739 @node Targets
1740 @unnumbered Index of Targets
1742 @printindex tr
1745 @bye