1 \input texinfo @c -*-texinfo-*-
3 @setfilename automake.info
11 This file documents GNU automake @value{VERSION}
13 Copyright (C) 1995 Free Software Foundation, Inc.
15 Permission is granted to make and distribute verbatim copies of
16 this manual provided the copyright notice and this permission notice
17 are preserved on all copies.
20 Permission is granted to process this file through TeX and print the
21 results, provided the printed document carries copying permission
22 notice identical to this one except for the removal of this paragraph
26 Permission is granted to copy and distribute modified versions of this
27 manual under the conditions for verbatim copying, provided that the entire
28 resulting derived work is distributed under the terms of a permission
29 notice identical to this one.
31 Permission is granted to copy and distribute translations of this manual
32 into another language, under the above conditions for modified versions,
33 except that this permission notice may be stated in a translation approved
40 @subtitle For version @value{VERSION}, @value{UPDATED}
43 @vskip 0pt plus 1filll
44 Copyright @copyright{} 1995 Free Software Foundation, Inc.
46 This is the first edition of the GNU AutoMake documentation,@*
47 and is consistent with GNU AutoMake @value{VERSION}.@*
49 Published by the Free Software Foundation @*
50 675 Massachusetts Avenue, @*
51 Cambridge, MA 02139 USA @*
53 Permission is granted to make and distribute verbatim copies of
54 this manual provided the copyright notice and this permission notice
55 are preserved on all copies.
57 Permission is granted to copy and distribute modified versions of this
58 manual under the conditions for verbatim copying, provided that the entire
59 resulting derived work is distributed under the terms of a permission
60 notice identical to this one.
62 Permission is granted to copy and distribute translations of this manual
63 into another language, under the above conditions for modified versions,
64 except that this permission notice may be stated in a translation
65 approved by the Free Software Foundation.
69 @node Top, Introduction, (dir), (dir)
70 @comment node-name, next, previous, up
73 This file documents the GNU AutoMake package for creating GNU
74 Standards-compliant Makefiles from template files. This edition
75 documents version @value{VERSION}.
78 * Introduction:: AutoMake's purpose
79 * Details:: Creating an AutoMake template file
80 * Invoking automake:: Creating a Makefile.in
81 * Future:: Some ideas for the future.
82 * Some index:: Index of variables
90 The GNU Makefile Standards Document
91 (@pxref{Makefile Conventions, , Makefile Conventions, standards.info, The
92 GNU Coding Standards})
94 and subject to change. The goal of AutoMake is to remove the burden of
95 Makefile maintenance from back the individual GNU maintainer (and put it
96 on the back of the AutoMake maintainer)
98 Typical AutoMake input files are simply a series of macro definitions.
99 AutoMake processes these files to produce @file{Makefile.in}s which are
102 AutoMake does force some structure on the package maintainer. However,
103 it is felt that this (minor) inconvenience is more than offset by
104 AutoMake's convenience.
108 @chapter Making @code{automake} templates
111 * configure:: AutoMake and configure
112 * Depth:: Types of package hierarchy
113 * Programs:: What gets built
114 * Source:: Specifying source files
115 * Scripts:: Building scripts
116 * Libraries:: Building libraries
117 * Libstuff:: Programs that aren't user-visible
119 * Docs:: Specifying documentation files
120 * ANSI:: Automatic de-ANSI-fication
121 * Install:: What gets installed
122 * Clean:: What gets cleaned
123 * Distribution:: What gets distributed
125 * Dependencies:: Automatic dependency tracking
126 * Extending:: If the defaults aren't enough
130 @section How @code{automake} and @code{configure} interact
132 AutoMake enforces a certain amount of structure on the package
133 maintainer. One such item is its requirement that the
134 @file{configure.in} for the package define the variables @samp{PACKAGE}
137 @var{PACKAGE} should be the name of the package as it appears when
138 bundled for distribution. For instance, AutoMake defines @samp{PACKAGE}
141 @var{VERSION} should be the version number of the release being worked
142 on. We recommend that you make @file{configure.in} the only place you
143 define the version number for your package; this makes releases simpler.
145 Here is an example of what to put in @file{configure.in}:
150 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
151 AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
156 If your @file{configure.in} uses @samp{AC_CONFIG_HEADER}, then in each
157 directory you should define the @samp{CONFIG_HEADER} variable to hold
158 the name of the header.
160 For instance, in cpio's @file{src/Makefile.am}, we see:
163 CONFIG_HEADER = ../config.h
167 @code{automake} also assumes that your @file{configure} script will
168 define the variable @samp{INSTALL_SCRIPT}. Until this is incorporated
169 in @code{autoconf}'s @samp{AC_PROG_INSTALL} macro, you can use this
173 ## --------------------------------------------------------- ##
174 ## Use AC_PROG_INSTALL, supplementing it with INSTALL_SCRIPT ##
176 ## --------------------------------------------------------- ##
178 AC_DEFUN(fp_PROG_INSTALL,
180 test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='$@{INSTALL@} -m 755'
181 AC_SUBST(INSTALL_SCRIPT)dnl
186 @code{automake} also assumes your @file{configure.in} calls
187 @samp{AC_ARG_PROGRAM}.
191 @section Types of directory hierarchy
193 @code{automake} supports three kinds of directory hierarcy: ``flat'',
194 ``shallow'', and ``deep''.
196 A flat package is one in which all the files are in a single directory.
197 The @file{Makefile.am} for such a package by definition lacks a
198 @samp{SUBDIRS} macro. (There are not any @code{automake}-using packages
201 A deep package is one in which all the source lies in subdirectories;
202 the top level directory contains only configuration information. GNU
203 cpio is a good example of such a package (as is GNU tar, although it
204 does not presently use @code{automake}). The top level
205 @file{Makefile.am} for a deep package will contain a @samp{SUBDIRS}
206 macro, but no other macros to define objects which are built (eg
209 A shallow package is one in which the primary source resides in the
210 top-level directory, while various parts (typically libraries) reside in
211 subdirectories. @code{automake} is one such package (as is GNU make,
212 which does not currently use @code{automake}).
215 The @samp{SUBDIRS} macro holds a list of subdirectories in which
216 building of various sorts can occur. Many targets (eg @samp{all}) in
217 the generated @file{Makefile} will run both locally and in all specified
218 subdirectories. Note that the directories listed in @samp{SUBDIRS} are
219 not expected to contain @file{Makefile.am}s; only @file{Makefile}s
220 (after configuration). This allows inclusion of libraries from packages
221 which do not use @code{automake} (such as gettext).
223 If @samp{SUBDIRS} is defined, then your @file{configure.in} must include
224 @code{AC_PROG_MAKE_SET}.
226 FIXME supply complete list of recursive targets?
230 @section Which Programs Are Built
232 In a directory containing source that gets built into a program (as
233 opposed to a library), the @samp{PROGRAMS} variable is used:
239 In this simple case, the resulting @file{Makefile.in} will contain code
240 to generate a program named @code{hello}. The variable
241 @samp{@var{prog}_SOURCE} is used to specify which source files get built
245 hello_SOURCE = hello.c
248 This causes @file{hello.o} to be built from @code{hello.c} at compile
249 time, and then linked into @file{hello}.
251 Multiple programs can be built in a single directory -- simply list them
252 all in the @samp{PROGRAMS} definition. Multiple programs can share a
253 single source file. The source file must be listed in each ``_SOURCE''
256 Sometimes it is useful to determine the programs that are to be built at
257 configure time. For instance, GNU cpio only builts @code{mt} and
258 @code{rmt} under special circumstances.
260 In this case, you must notify AutoMake of all the programs that can
261 possibly be built, but at the same time cause the generated
262 @file{Makefile.in} to use the programs specified by @code{configure}.
263 You can do this using the @code{AM_PROGRAMS} variable. Here is the
264 relevant code from cpio:
268 AM_PROGRAMS = cpio pax mt rmt
272 If you need to link against libraries that are not found by
273 @code{configure}, you can use @samp{LDADD} to do so. This variable
274 actually can be used to add any options to the linker command line.
276 Sometimes, multiple programs are built in one directory but do not share
277 the same link-time requirements. In this case, you can use the
278 @samp{@var{prog}_LDADD} variable to override the global @samp{LDADD}.
279 (If this variable exists for a given program, then that program is not
280 linked using @samp{LDADD}).
282 For instance, in GNU cpio, @code{pax}, @code{cpio}, and @code{mt} are
283 linked against the library @file{libcpio.a}. However, @code{rmt} is
284 built in the same directory, and has no such link requirement. Thus:
287 LDADD = ../lib/libcpio.a @@INTLLIBS@@
293 @section Specifying Source Code
295 Any header files in your distribution must be listed in the
296 @samp{HEADERS} variable. This is used both for making distributions,
297 and for automatic de-ANSI-fication.
300 HEADERS = hello.h getopt.h rx.h
303 @samp{HEADERS} should also be used to list any sources files which are
304 conditionally built. FIXME probably should use @samp{SOURCES} for this;
305 that support might even work.
309 @section Programs Which are Scripts
311 It is possible to define and install programs which are scripts. Such
312 programs should be listed in the @samp{SCRIPTS} variable.
313 @code{automake} doesn't define any dependencies for scripts; if a script
314 is not to be installed as-is, the @file{Makefile.am} should include the
317 @code{automake} itself is a script that is generated at configure time
318 from @file{automake.in}. Here is how this is handled:
323 automake: automake.in
324 CONFIG_FILES=$@@ CONFIG_HEADERS= ./config.status
329 @section Building Libraries
331 The @samp{LIBRARIES} variable holds the names of libraries to be built
332 in the current directory. If the libraries to be built vary at
333 configure time, you may define @samp{AM_LIBRARIES} to supply
334 @code{automake} with the full static list of possible libraries.
336 For a given library @samp{zot}, the sources are taken to be in
337 @samp{@var{zot}_SOURCES}, just as for programs. Note that libraries and
338 programs share one namespace in @code{automake}: one directory cannot
339 contain both a library (``liblob.a'') and a program (``lob'') with the
342 Here is how the @file{libcpio.a} library is built in the GNU cpio
343 distribution's @file{lib} subdirectory:
347 cpio_SOURCES = dirname.c dstring.c error.c filemode.c \
348 getopt.c getopt1.c idcache.c makepath.c octal.c \
349 stpcpy.c stripslash.c userspec.c xmalloc.c xstrdup.c
354 @section Programs which are not User-Visible
356 @code{automake} allows for the automatic building and installation of
357 programs which are not actually used by the user, but are instead used
358 by other user-visible programs. Such programs are installed in a
359 separate directory from user-visible programs.
361 For programs of this sort which are build from C source, define the
362 names in @samp{LIBPROGRAMS}. For scripts, use @samp{LIBSCRIPTS}. In
363 other respects, these variables are similar to @samp{PROGRAMS} and
364 @samp{SCRIPTS}. Both of these variables have ``AM_'' override forms.
366 Here is how to generate a program named @code{goodbye}, a helper for
370 LIBPROGRAMS = goodbye
371 goodbye_SOURCES = goodbye.c
376 @section Architecture-independent data files
378 @code{automake} supports two different ways to install
379 architecture-independent data files.
381 The first variable that can be used is @samp{DATA}. This is intended to
382 be used for only a small number of data files. The files are installed
383 in @samp{$@{datadir@}}.
385 The second variable that can be used is @samp{PACKAGEDATA}. This is
386 intended for a larger number of data files. The files are installed in
387 @samp{$@{datadir@}/$@{PACKAGE@}}. This variable is what @code{automake}
391 PACKAGEDATA = clean-kr.am clean.am compile-kr.am compile-vars.am \
392 compile.am data.am depend.am dist-subd-top.am dist-subd-vars.am \
393 dist-subd.am dist-vars.am dist.am footer.am header-vars.am header.am \
394 libscripts.am libprograms.am libraries-vars.am libraries.am library.am \
395 mans-vars.am mans.am packagedata.am program.am programs.am remake-hdr.am \
396 remake-subd.am remake.am scripts.am subdirs.am tags.am tags-subd.am \
397 texinfos-vars.am texinfos.am hack-make.sed nl-remove.sed
400 All @samp{DATA} and @samp{PACKAGEDATA} files are included in a
405 @section Texinfo and Man Pages
408 If the current directory contains Texinfo source, you must declare it
409 with the @samp{TEXINFOS} macro.
410 Note that any Texinfo source file must end in the @file{.texi} extension
411 (@file{.texinfo} won't work).
413 If the @file{.texi} file ``@@include''s @file{version.texi}, then that
414 file will be automatically generated. @file{version.texi} defines three
415 Texinfo macros you can reference: @samp{EDITION}, @samp{VERSION}, and
416 @samp{UPDATED}. The first two hold the version number of your package
417 (but are kept separate for clarity); the last is the date the primary
418 file was last modified.
419 The @file{version.texi} support requires a version of @code{date} that
420 accepts the @samp{-r} (read time from a file) option.
422 Sometimes an info file actually depends on more than one @file{.texi}
423 file. For instance, in the @samp{xdvik} distribution,
424 @file{kpathsea.texi} includes the files @file{install.texi},
425 @file{copying.texi}, and @file{freedom.texi}. You can tell
426 @code{automake} about these dependencies using the @samp{texi_TEXINFOS}
427 variable. Here is how @samp{xdvik} could do it:
430 TEXINFOS = kpathsea.texi
431 kpathsea_TEXINFOS = install.texi copying.texi freedom.texi
434 @code{automake} might be modified to detect these dependencies
437 Currently @code{automake} can only handle one primary @file{.texi} file.
438 This restriction will be lifted if it proves too onerous.
440 @code{automake} will warn if a directory containing Texinfo source does
441 not also contain the file @file{texinfo.tex}. (I'm not sure if this is
442 a good rule or not. Comments?)
445 @subsection Man pages
446 A package can also include man pages. (Though see the GNU standards on
447 this matter. FIXME xref).
448 Man pages are declared using the @samp{MANS} macro.
451 Here is how the documentation is handled in GNU cpio (which includes
452 both Texinfo documentation and man pages):
459 Texinfo source, info pages and man pages are all considered to be
460 ``source'' for the purposes of making a distribution.
464 @section Automatic de-ANSI-fication of Source
466 If @file{Makefile.am} includes the text @samp{@@kr@@}, then code to
467 handle automatic de-ANSI-fication is included in the generated
470 This means that each C source file will be treated as ANSI C. If no
471 ANSI C compiler is available on the build system, then the code will be
472 turned into K&R C before compilation.
474 Each directory that uses automatic de-ANSI-fication must include the
475 source files @file{ansi2knr.c} and @file{ansi2knr.1}. Also, your
476 @file{configure} script must define the variables @samp{U} and
477 @samp{ANSI2KNR}. Here is a snippet you can add to @file{aclocal.m4} to
481 ## ------------------------------- ##
482 ## Check for function prototypes. ##
483 ## ------------------------------- ##
485 AC_DEFUN(fp_C_PROTOTYPES,
486 [AC_REQUIRE([fp_PROG_CC_STDC])
487 AC_MSG_CHECKING([for function prototypes])
488 if test "$ac_cv_prog_cc_stdc" != no; then
490 AC_DEFINE(PROTOTYPES)
494 U=_ ANSI2KNR=./ansi2knr
497 AC_SUBST(ANSI2KNR)dnl
501 ## ----------------------------------------- ##
502 ## ANSIfy the C compiler whenever possible. ##
503 ## ----------------------------------------- ##
505 # @@defmac AC_PROG_CC_STDC
506 # @@maindex PROG_CC_STDC
508 # If the C compiler in not in ANSI C mode by default, try to add an option
509 # to output variable @@code@{CC@} to make it so. This macro tries various
510 # options that select ANSI C on some system or another. It considers the
511 # compiler to be in ANSI C mode if it defines @@code@{__STDC__@} to 1 and
512 # handles function prototypes correctly.
514 # If you use this macro, you should check after calling it whether the C
515 # compiler has been set to accept ANSI C; if not, the shell variable
516 # @@code@{ac_cv_prog_cc_stdc@} is set to @@samp@{no@}. If you wrote your source
517 # code in ANSI C, you can make an un-ANSIfied copy of it by using the
518 # program @@code@{ansi2knr@}, which comes with Ghostscript.
521 AC_DEFUN(fp_PROG_CC_STDC,
522 [AC_MSG_CHECKING(for $@{CC-cc@} option to accept ANSI C)
523 AC_CACHE_VAL(ac_cv_prog_cc_stdc,
524 [ac_cv_prog_cc_stdc=no
525 ac_save_CFLAGS="$CFLAGS"
526 # Don't try gcc -ansi; that turns off useful extensions and
527 # breaks some systems' header files.
529 # Ultrix and OSF/1 -std1
530 # HP-UX -Aa -D_HPUX_SOURCE
532 for ac_arg in "" -qlanglvl=ansi -std1 "-Aa -D_HPUX_SOURCE" -Xc
534 CFLAGS="$ac_save_CFLAGS $ac_arg"
536 [#if !defined(__STDC__) || __STDC__ != 1
539 ], [int test (int i, double x);
540 struct s1 @{int (*f) (int a);@};
541 struct s2 @{int (*f) (double a);@};],
542 [ac_cv_prog_cc_stdc="$ac_arg"; break])
544 CFLAGS="$ac_save_CFLAGS"
546 AC_MSG_RESULT($ac_cv_prog_cc_stdc)
547 case "x$ac_cv_prog_cc_stdc" in
549 *) CC="$CC $ac_cv_prog_cc_stdc" ;;
556 @section What Gets Installed
558 Naturally, @code{automake} handles the details of actually installing
559 your program once it has been built. Any objects specified in
560 @samp{PROGRAMS}, @samp{LIBPROGRAMS}, @samp{SCRIPTS}, @samp{LIBSCRIPTS},
561 @samp{DATA}, and @samp{PACKAGEDATA} are automatically installed in the
564 @code{automake} also handles installing any specified info and man
567 FIXME xref to Extending node here; sometimes you need to install more.
569 @code{automake} generates separate @samp{install-data} and
570 @samp{install-exec} targets, in case the installer is installing on
571 multiple machines which share directory structure -- these targets allow
572 the machine-independent parts to be installed only once.
574 @code{automake} also generates an @samp{uninstall} target, and an
575 @samp{installdirs} target.
579 @section Clean targets
581 The GNU Makefile Standards specify a number of different clean rules.
582 Generally the files that can cleaned are determined automatically by
583 @code{automake}. Of course, @code{automake} also recognizes some
584 variables that can be defined to specify additional files to clean.
585 These variables are @samp{MOSTLYCLEANFILES}, @samp{CLEANFILES},
586 @samp{DISTCLEANFILES}, and @samp{MAINTAINERCLEANFILES}.
590 @section Building a Release
592 The @samp{dist} target in the generated @file{Makefile.in} can be used
593 to generate a gzip'd tar file for distribution. The tar file is named
594 based on the @var{PACKAGE} and @var{VERSION} variables.
596 For the most part, the files to distribute are automatically found by
597 @code{automake}: all source files are automatically included in a
598 distribution, as are all @file{Makefile.am}s and @file{Makefile.in}s.
599 @code{automake} also has a built-in list of commonly used files which,
600 if present in the current directory, are automatically included. This
601 list is printed by @code{automake --help}.
603 Still, sometimes there are files which must be distributed, but which
604 are not covered in the automatic rules. These files should be listed in
605 the @samp{DIST_OTHER} variable.
607 For instance, in the @code{automake} distribution,
608 @file{automake.in} (the source to
609 @code{automake}) is not found automatically. So in the
610 @file{Makefile.am}, we have:
613 DIST_OTHER = automake.in
616 FIXME mention files that are found automatically but not printed by
618 FIXME: describe DIST_SUBDIRS or not? It is a hack which might go away.
621 @section Interfacing to @code{etags}
623 @code{automake} will generate rules to generate @file{TAGS} files for
624 use with GNU Emacs under some circumstances.
626 If any C source code or headers are present, then a @file{TAGS} file
627 will be generated for the directory.
629 At the topmost directory of a multi-directory package, a @file{TAGS}
630 file will be generated that will include by reference all @file{TAGS}
631 files from subdirectories.
633 Also, if the variable @samp{ETAGS_ARGS} is defined, a @file{TAGS} file
634 will be generated. This variable is intended for use in directories
635 which contain taggable source that @code{etags} does not understand.
636 (For instance, it could be set to a regexp to recognize node names in
637 Texinfo documentation)
641 @section Automatic dependency tracking
643 As a developer it is often painful to continually update the
644 @file{Makefile.in} whenever the include-file dependencies change in a
645 project. @code{automake} supplies a way to automatically track
646 dependency changes, and distribute the dependencies in the generated
649 Currently this support requires the use of @code{GNU make} and
650 @code{gcc}. It might become possible in the future to supply a
651 different dependency generating program, if there is enough demand.
653 This mode is enabled by default if any C program or library is defined
654 in the current directory.
656 When you decide to make a distribution, the @samp{dist} target will
657 re-run @code{automake} with the @samp{--include-deps} option. This
658 causes the previously generated dependencies to be inserted into the
659 generated @file{Makefile.in}, and thus into the distribution.
660 @samp{--include-deps} also turns off inclusion of the dependency
663 There should probably be a way to suppress this mode.
667 @section When AutoMake Isn't Enough
669 Sometimes @code{automake} isn't enough. Then you just lose.
671 Actually, @code{automake}s implicit copying semantics means that many
672 problems can be worked around by simply adding some @code{make} targets
673 and rules to @file{Makefile.in}. @code{automake} will ignore these
676 There are some caveats to doing this. You can't overload a target
677 already used by @code{automake}. However, various useful targets have a
678 ``-local'' version you can specify in your @file{Makefile.in}.
680 The targets that support a local version are @samp{all}, @samp{info},
681 @samp{dvi}, @samp{check}, @samp{install-data}, @samp{install-exec}, and
682 @samp{uninstall}. (Currently @samp{install} is also supported, but this
685 For instance, here is how to install a file in @file{/etc}:
689 $(INSTALL_DATA) $(srcdir)/afile /etc/afile
693 @node Invoking automake
694 @chapter Using @code{automake} to Create @file{Makefile.in}
696 There are basically two modes in which @code{automake} can be run.
698 In the first, most common, mode, @code{automake} is simply run without
699 any arguments. It will determine which @file{Makefile.am}s exist by
700 looking in the current directory and immediate subdirectories, and will
701 automatically build @file{Makefile.in}s in these directories.
703 In the second mode, @code{automake} is run with the name of one or more
704 @file{Makefile}s as arguments. It then rebuilds the corresponding
705 @file{Makefile.in}s from the (also) corresponding @file{Makefile.am}s.
706 This second mode is most often used by @code{make} itself, when it
707 notices that a @code{Makefile.in} is out of date.
711 @chapter Some ideas for the future
713 Here are some things that might happen in the future:
717 Better error checking would be good.
727 * Need section on operation of automake: it reads Makefile.am and COPIES
728 the contents. This section should include info on SUFFIXES, because
729 that is usually only needed when copying in additional targets (?)