1 \input texinfo @c -*-texinfo-*-
3 @setfilename automake.info
5 @documentencoding UTF-8
12 @c @ovar(ARG, DEFAULT)
13 @c -------------------
14 @c The ARG is an optional argument. To be used for macro arguments in
15 @c their documentation (@defmac).
17 @r{[}@var{\varname\}@r{]}
20 @set PACKAGE_BUGREPORT bug-automake@@gnu.org
24 This manual is for GNU Automake (version @value{VERSION},
25 @value{UPDATED}), a program that creates GNU standards-compliant
26 Makefiles from template files.
28 Copyright @copyright{} 1995--2024 Free Software Foundation, Inc.
31 Permission is granted to copy, distribute and/or modify this document
32 under the terms of the GNU Free Documentation License,
33 Version 1.3 or any later version published by the Free Software
34 Foundation; with no Invariant Sections, with no Front-Cover texts,
35 and with no Back-Cover Texts. A copy of the license is included in the
36 section entitled ``GNU Free Documentation License.''
41 @dircategory Software development
43 * Automake: (automake). Making GNU standards-compliant Makefiles.
46 @dircategory Individual utilities
48 * aclocal-invocation: (automake)aclocal Invocation. Generating aclocal.m4.
49 * automake-invocation: (automake)automake Invocation. Generating Makefile.in.
54 @subtitle For version @value{VERSION}, @value{UPDATED}
55 @author David MacKenzie
57 @author Alexandre Duret-Lutz
58 @author Ralf Wildenhues
59 @author Stefano Lattarini
61 @vskip 0pt plus 1filll
68 @c We use the following macros to define indices:
69 @c @cindex concepts, and anything that does not fit elsewhere
70 @c @vindex Makefile variables
72 @c @acindex Autoconf/Automake/Libtool/M4/... macros
73 @c @opindex tool options
75 @c Define an index of configure macros.
77 @c Define an index of options.
79 @c Define an index of targets.
81 @c Define an index of commands.
84 @c Put the macros in the function index.
87 @c Put everything else into one index (arbitrarily chosen to be the
95 @comment node-name, next, previous, up
101 * Introduction:: Automake's purpose
102 * Autotools Introduction:: An Introduction to the Autotools
103 * Generalities:: General ideas
104 * Examples:: Some example packages
105 * automake Invocation:: Creating a Makefile.in
106 * configure:: Scanning configure.ac, using aclocal
107 * Directories:: Declaring subdirectories
108 * Programs:: Building programs and libraries
109 * Other Objects:: Other derived objects
110 * Other GNU Tools:: Other GNU Tools
111 * Documentation:: Building documentation
112 * Install:: What gets installed
113 * Clean:: What gets cleaned
114 * Dist:: What goes in a distribution
115 * Tests:: Support for test suites
116 * Rebuilding:: Automatic rebuilding of Makefile
117 * Options:: Changing Automake's behavior
118 * Miscellaneous:: Miscellaneous rules
119 * Include:: Including extra files in an Automake template
120 * Conditionals:: Conditionals
121 * Silencing Make:: Obtain less verbose output from @command{make}
122 * Not Enough:: When Automake is not Enough
123 * Distributing:: Distributing the Makefile.in
124 * API Versioning:: About compatibility between Automake versions
125 * Upgrading:: Upgrading to a Newer Automake Version
126 * FAQ:: Frequently Asked Questions
127 * Copying This Manual:: How to make copies of this manual
128 * Indices:: Indices of variables, macros, and concepts
131 --- The Detailed Node Listing ---
133 An Introduction to the Autotools
135 * GNU Build System:: Introducing the GNU Build System
136 * Use Cases:: Use Cases for the GNU Build System
137 * Why Autotools:: How Autotools Help
138 * Hello World:: A Small Hello World Package
140 Use Cases for the GNU Build System
142 * Basic Installation:: Common installation procedure
143 * Standard Targets:: A list of standard Makefile targets
144 * Standard Directory Variables:: A list of standard directory variables
145 * Standard Configuration Variables:: Using configuration variables
146 * config.site:: Using a config.site file
147 * VPATH Builds:: Parallel build trees
148 * Two-Part Install:: Installing data and programs separately
149 * Cross-Compilation:: Building for other architectures
150 * Renaming:: Renaming programs at install time
151 * DESTDIR:: Building binary packages with DESTDIR
152 * Preparing Distributions:: Rolling out tarballs
153 * Dependency Tracking:: Automatic dependency tracking
154 * Nested Packages:: The GNU Build Systems can be nested
158 * Creating amhello:: Create @file{amhello-1.0.tar.gz} from scratch
159 * amhello's configure.ac Setup Explained::
160 * amhello's Makefile.am Setup Explained::
164 * General Operation:: General operation of Automake
165 * Strictness:: Standards conformance checking
166 * Uniform:: The Uniform Naming Scheme
167 * Length Limitations:: Staying below the command line length limit
168 * Canonicalization:: How derived variables are named
169 * User Variables:: Variables reserved for the user
170 * Auxiliary Programs:: Programs automake might require
172 Some example packages
174 * Complete:: A simple example, start to finish
175 * true:: Building true and false
177 Scanning @file{configure.ac}, using @command{aclocal}
179 * Requirements:: Configuration requirements
180 * Optional:: Other things Automake recognizes
181 * aclocal Invocation:: Auto-generating aclocal.m4
182 * Macros:: Autoconf macros supplied with Automake
184 Auto-generating aclocal.m4
186 * aclocal Options:: Options supported by aclocal
187 * Macro Search Path:: How aclocal finds .m4 files
188 * Extending aclocal:: Writing your own aclocal macros
189 * Local Macros:: Organizing local macros
190 * Serials:: Serial lines in Autoconf macros
191 * Future of aclocal:: aclocal's scheduled death
193 Autoconf macros supplied with Automake
195 * Public Macros:: Macros that you can use.
196 * Obsolete Macros:: Macros that will soon be removed.
197 * Private Macros:: Macros that you should not use.
201 * Subdirectories:: Building subdirectories recursively
202 * Conditional Subdirectories:: Conditionally not building directories
203 * Alternative:: Subdirectories without recursion
204 * Subpackages:: Nesting packages
206 Conditional Subdirectories
208 * SUBDIRS vs DIST_SUBDIRS:: Two sets of directories
209 * Subdirectories with AM_CONDITIONAL:: Specifying conditional subdirectories
210 * Subdirectories with AC_SUBST:: Another way for conditional recursion
211 * Unconfigured Subdirectories:: Not even creating a @samp{Makefile}
213 Building Programs and Libraries
215 * A Program:: Building a program
216 * A Library:: Building a library
217 * A Shared Library:: Building a Libtool library
218 * Program and Library Variables:: Variables controlling program and
220 * Default _SOURCES:: Default source files
221 * LIBOBJS:: Special handling for LIBOBJS and ALLOCA
222 * Program Variables:: Variables used when building a program
223 * Yacc and Lex:: Yacc and Lex support
224 * C++ Support:: Compiling C++ sources
225 * Objective C Support:: Compiling Objective C sources
226 * Objective C++ Support:: Compiling Objective C++ sources
227 * Unified Parallel C Support:: Compiling Unified Parallel C sources
228 * Assembly Support:: Compiling assembly sources
229 * Fortran 77 Support:: Compiling Fortran 77 sources
230 * Fortran 9x Support:: Compiling Fortran 9x sources
231 * Java Support with gcj:: Compiling Java sources using gcj
232 * Vala Support:: Compiling Vala sources
233 * Support for Other Languages:: Compiling other languages
234 * Dependencies:: Automatic dependency tracking
235 * EXEEXT:: Support for executable extensions
239 * Program Sources:: Defining program sources
240 * Linking:: Linking with libraries or extra objects
241 * Conditional Sources:: Handling conditional sources
242 * Conditional Programs:: Building a program conditionally
244 Building a Shared Library
246 * Libtool Concept:: Introducing Libtool
247 * Libtool Libraries:: Declaring Libtool Libraries
248 * Conditional Libtool Libraries:: Building Libtool Libraries Conditionally
249 * Conditional Libtool Sources:: Choosing Library Sources Conditionally
250 * Libtool Convenience Libraries:: Building Convenience Libtool Libraries
251 * Libtool Modules:: Building Libtool Modules
252 * Libtool Flags:: Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
253 * LTLIBOBJS:: Using $(LTLIBOBJS) and $(LTALLOCA)
254 * Libtool Issues:: Common Issues Related to Libtool's Use
256 Common Issues Related to Libtool's Use
258 * Error required file ltmain.sh not found:: The need to run libtoolize
259 * Objects created both with libtool and without:: Avoid a specific build race
263 * Linking Multiple Yacc Parsers::
267 * Preprocessing Fortran 77:: Preprocessing Fortran 77 sources
268 * Compiling Fortran 77 Files:: Compiling Fortran 77 sources
269 * Mixing Fortran 77 With C and C++:: Mixing Fortran 77 With C and C++
271 Mixing Fortran 77 With C and C++
273 * How the Linker is Chosen:: Automatic linker selection
277 * Compiling Fortran 9x Files:: Compiling Fortran 9x sources
279 Other Derived Objects
281 * Scripts:: Executable scripts
282 * Headers:: Header files
283 * Data:: Architecture-independent data files
284 * Sources:: Derived sources
288 * Built Sources Example:: Several ways to handle built sources.
292 * Emacs Lisp:: Emacs Lisp
295 * Java:: Java bytecode compilation (deprecated)
300 * Supported Python versions::
302 Building documentation
305 * Man Pages:: Man pages
309 * Basics of Installation:: What gets installed where
310 * The Two Parts of Install:: Installing data and programs separately
311 * Extending Installation:: Adding your own rules for installation
312 * Staged Installs:: Installation in a temporary location
313 * Install Rules for the User:: Useful additional rules
315 What Goes in a Distribution
317 * Basics of Distribution:: Files distributed by default
318 * Fine-grained Distribution Control:: @code{dist_} and @code{nodist_} prefixes
319 * The dist Hook:: A target for last-minute distribution changes
320 * Checking the Distribution:: @samp{make distcheck} explained
321 * The Types of Distributions:: A variety of formats and compression methods
323 Checking the Distribution
325 * DISTCHECK_CONFIGURE_FLAGS:: Overriding configure flags in distcheck.
326 * distcheck-hook:: Running commands after distcheck.
327 * dvi and distcheck:: Overriding the distcheck doc target.
328 * distcleancheck:: Handling files not cleaned.
329 * distuninstallcheck:: Overriding the uninstall check.
330 * Errors with distclean::
332 Support for test suites
334 * Generalities about Testing:: Concepts and terminology about testing
335 * Simple Tests:: Listing test scripts in @code{TESTS}
336 * Custom Test Drivers:: Writing and using custom test drivers
337 * Using the TAP test protocol:: Integrating test scripts that use the TAP protocol
338 * DejaGnu Tests:: Interfacing with the @command{dejagnu} testing framework
339 * Install Tests:: Running tests on installed packages
343 * Scripts-based Testsuites:: Automake-specific concepts and terminology
344 * Serial Test Harness:: Older (and discouraged) serial test harness
345 * Parallel Test Harness:: Generic concurrent test harness
347 Scripts-based Testsuites
349 * Testsuite Environment Overrides::
353 * Overview of Custom Test Drivers Support::
354 * Declaring Custom Test Drivers::
355 * API for Custom Test Drivers::
357 API for Custom Test Drivers
359 * Command-line arguments for test drivers::
360 * Log files generation and test results recording::
361 * Testsuite progress output::
363 Using the TAP test protocol
365 * Introduction to TAP::
366 * Use TAP with the Automake test harness::
367 * Incompatibility with other TAP parsers and drivers::
368 * Links and external resources on TAP::
370 Changing Automake's Behavior
372 * Options generalities:: Semantics of Automake option
373 * List of Automake options:: A comprehensive list of Automake options
377 * Tags:: Interfacing to cscope, etags and mkid
378 * Suffixes:: Handling new file extensions
382 * Usage of Conditionals:: Declaring conditional content
383 * Limits of Conditionals:: Enclosing complete statements
385 Silencing @command{make}
387 * Make verbosity:: Make is verbose by default
388 * Tricks For Silencing Make:: Standard and generic ways to silence make
389 * Automake Silent Rules:: How Automake can help in silencing make
390 * Unsilencing Automake:: Showing commands.
392 When Automake Isn't Enough
394 * Extending:: Adding new rules or overriding existing ones.
395 * Third-Party Makefiles:: Integrating Non-Automake @file{Makefile}s.
397 Frequently Asked Questions about Automake
399 * Version Control:: Version control and generated files
400 * maintainer-mode:: missing and AM_MAINTAINER_MODE
401 * Wildcards:: Why doesn't Automake support wildcards?
402 * Limitations on File Names:: Limitations on source and installed file names
403 * Flag Variables Ordering:: CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
404 * Renamed Objects:: Why are object files sometimes renamed?
405 * Per-Object Flags:: How to simulate per-object flags?
406 * Multiple Outputs:: Writing rules for tools with many output files
407 * Hard-Coded Install Paths:: Installing to hard-coded locations
408 * Debugging Make Rules:: Strategies when things don't work as expected
409 * Reporting Bugs:: Feedback on bugs and feature requests
413 * GNU Free Documentation License:: License for copying this manual
417 * Macro Index:: Index of Autoconf macros
418 * Variable Index:: Index of Makefile variables
419 * General Index:: General index
428 @chapter Introduction
430 Automake is a tool for automatically generating @file{Makefile.in}s
431 from files called @file{Makefile.am}. Each @file{Makefile.am} is
432 basically a series of @command{make} variable
433 definitions@footnote{These variables are also called @dfn{make macros}
434 in Make terminology, however in this manual we reserve the term
435 @dfn{macro} for Autoconf's macros.}, with rules being thrown in
436 occasionally. The generated @file{Makefile.in}s are compliant with
437 the GNU Makefile standards.
439 @cindex GNU Makefile standards
441 The GNU Makefile Standards Document
442 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
443 is long, complicated, and subject to change. The goal of Automake is to
444 remove the burden of Makefile maintenance from the back of the
445 individual GNU maintainer (and put it on the back of the Automake
448 The typical Automake input file is simply a series of variable definitions.
449 Each such file is processed to create a @file{Makefile.in}.
451 @cindex Constraints of Automake
452 @cindex Automake constraints
454 Automake does constrain a project in certain ways; for instance, it
455 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
456 autoconf, The Autoconf Manual}), and enforces certain restrictions on
457 the @file{configure.ac} contents.
459 @cindex Automake requirements
460 @cindex Requirements, Automake
462 Automake requires @command{perl} in order to generate the
463 @file{Makefile.in}s. However, the distributions created by Automake are
464 fully GNU standards-compliant, and do not require @command{perl} in order
467 For more information on bug reports, @xref{Reporting Bugs}.
469 @node Autotools Introduction
470 @chapter An Introduction to the Autotools
472 If you are new to Automake, maybe you know that it is part of a set of
473 tools called @emph{The Autotools}. Maybe you've already delved into a
474 package full of files named @file{configure}, @file{configure.ac},
475 @file{Makefile.in}, @file{Makefile.am}, @file{aclocal.m4}, @dots{},
476 some of them claiming to be @emph{generated by} Autoconf or Automake.
477 But the exact purpose of these files and their relations is probably
478 fuzzy. The goal of this chapter is to introduce you to this machinery,
479 to show you how it works and how powerful it is. If you've never
480 installed or seen such a package, do not worry: this chapter will walk
483 If you need some teaching material, more illustrations, or a less
484 @command{automake}-centered continuation, some slides for this
485 introduction are available in Alexandre Duret-Lutz's
486 @uref{https://www.lrde.epita.fr/@/~adl/@/autotools.html,
488 This chapter is the written version of the first part of his tutorial.
491 * GNU Build System:: Introducing the GNU Build System
492 * Use Cases:: Use Cases for the GNU Build System
493 * Why Autotools:: How Autotools Help
494 * Hello World:: A Small Hello World Package
497 @node GNU Build System
498 @section Introducing the GNU Build System
499 @cindex GNU Build System, introduction
501 It is a truth universally acknowledged, that as a developer in
502 possession of a new package, you must be in want of a build system.
504 In the Unix world, such a build system is traditionally achieved using
505 the command @command{make} (@pxref{Top, , Overview, make, The GNU Make
506 Manual}). You express the recipe to build your package in a
507 @file{Makefile}. This file is a set of rules to build the files in
508 the package. For instance the program @file{prog} may be built by
509 running the linker on the files @file{main.o}, @file{foo.o}, and
510 @file{bar.o}; the file @file{main.o} may be built by running the
511 compiler on @file{main.c}; etc. Each time @command{make} is run, it
512 reads @file{Makefile}, checks the existence and modification time of
513 the files mentioned, decides what files need to be built (or rebuilt),
514 and runs the associated commands.
516 When a package needs to be built on a different platform than the one
517 it was developed on, its @file{Makefile} usually needs to be adjusted.
518 For instance the compiler may have another name or require more
519 options. In 1991, David J. MacKenzie got tired of customizing
520 @file{Makefile} for the 20 platforms he had to deal with. Instead, he
521 handcrafted a little shell script called @file{configure} to
522 automatically adjust the @file{Makefile} (@pxref{Genesis, , Genesis,
523 autoconf, The Autoconf Manual}). Compiling his package was now
524 as simple as running @code{./configure && make}.
526 @cindex GNU Coding Standards
528 Today this process has been standardized in the GNU project. The GNU
529 Coding Standards (@pxref{Managing Releases, The Release Process, ,
530 standards, The GNU Coding Standards}) explains how each package of the
531 GNU project should have a @file{configure} script, and the minimal
532 interface it should have. The @file{Makefile} too should follow some
533 established conventions. The result? A unified build system that
534 makes all packages almost indistinguishable by the installer. In its
535 simplest scenario, all the installer has to do is to unpack the
536 package, run @code{./configure && make && make install}, and repeat
537 with the next package to install.
539 We call this build system the @dfn{GNU Build System}, since it was
540 grown out of the GNU project. However it is used by a vast number of
541 other packages: following any existing convention has its advantages.
543 @cindex Autotools, introduction
545 The Autotools are tools that will create a GNU Build System for your
546 package. Autoconf mostly focuses on @file{configure} and Automake on
547 @file{Makefile}s. It is entirely possible to create a GNU Build
548 System without the help of these tools. However it is rather
549 burdensome and error-prone. We will discuss this again after some
550 illustration of the GNU Build System in action.
553 @section Use Cases for the GNU Build System
554 @cindex GNU Build System, use cases
555 @cindex GNU Build System, features
556 @cindex Features of the GNU Build System
557 @cindex Use Cases for the GNU Build System
558 @cindex @file{amhello-1.0.tar.gz}, location
559 @cindex @file{amhello-1.0.tar.gz}, use cases
561 In this section we explore several use cases for the GNU Build System.
562 You can replay all of these examples on the @file{amhello-1.0.tar.gz}
563 package distributed with Automake. If Automake is installed on your
564 system, you should find a copy of this file in
565 @file{@var{prefix}/share/doc/automake/amhello-1.0.tar.gz}, where
566 @var{prefix} is the installation prefix specified during configuration
567 (@var{prefix} defaults to @file{/usr/local}, however if Automake was
568 installed by some GNU/Linux distribution it most likely has been set
569 to @file{/usr}). If you do not have a copy of Automake installed,
570 you can find a copy of this file inside the @file{doc/} directory of
571 the Automake package.
573 Some of the following use cases present features that are in fact
574 extensions to the GNU Build System. Read: they are not specified by
575 the GNU Coding Standards, but they are nonetheless part of the build
576 system created by the Autotools. To keep things simple, we do not
577 point out the difference. Our objective is to show you many of the
578 features that the build system created by the Autotools will offer to
582 * Basic Installation:: Common installation procedure
583 * Standard Targets:: A list of standard Makefile targets
584 * Standard Directory Variables:: A list of standard directory variables
585 * Standard Configuration Variables:: Using configuration variables
586 * config.site:: Using a config.site file
587 * VPATH Builds:: Parallel build trees
588 * Two-Part Install:: Installing data and programs separately
589 * Cross-Compilation:: Building for other architectures
590 * Renaming:: Renaming programs at install time
591 * DESTDIR:: Building binary packages with DESTDIR
592 * Preparing Distributions:: Rolling out tarballs
593 * Dependency Tracking:: Automatic dependency tracking
594 * Nested Packages:: The GNU Build Systems can be nested
597 @node Basic Installation
598 @subsection Basic Installation
599 @cindex Configuration, basics
600 @cindex Installation, basics
601 @cindex GNU Build System, basics
603 The most common installation procedure looks as follows.
606 ~ % @kbd{tar zxf amhello-1.0.tar.gz}
607 ~ % @kbd{cd amhello-1.0}
608 ~/amhello-1.0 % @kbd{./configure}
610 config.status: creating Makefile
611 config.status: creating src/Makefile
613 ~/amhello-1.0 % @kbd{make}
615 ~/amhello-1.0 % @kbd{make check}
617 ~/amhello-1.0 % @kbd{su}
619 /home/adl/amhello-1.0 # @kbd{make install}
621 /home/adl/amhello-1.0 # @kbd{exit}
622 ~/amhello-1.0 % @kbd{make installcheck}
628 The user first unpacks the package. Here, and in the following
629 examples, we will use the non-portable @code{tar zxf} command for
630 simplicity. On a system without GNU @command{tar} installed, this
631 command should read @code{gunzip -c amhello-1.0.tar.gz | tar xf -}.
633 The user then enters the newly created directory to run the
634 @file{configure} script. This script probes the system for various
635 features, and finally creates the @file{Makefile}s. In this toy
636 example there are only two @file{Makefile}s, but in real-world projects,
637 there may be many more, usually one @file{Makefile} per directory.
639 It is now possible to run @code{make}. This will construct all the
640 programs, libraries, and scripts that need to be constructed for the
641 package. In our example, this compiles the @file{hello} program.
642 All files are constructed in place, in the source tree; we will see
643 later how this can be changed.
645 @code{make check} causes the package's tests to be run. This step is
646 not mandatory, but it is often good to make sure the programs that
647 have been built behave as they should, before you decide to install
648 them. Our example does not contain any tests, so running @code{make
651 @cindex su, before @code{make install}
652 After everything has been built, and maybe tested, it is time to
653 install it on the system. That means copying the programs,
654 libraries, header files, scripts, and other data files from the
655 source directory to their final destination on the system. The
656 command @code{make install} will do that. However, by default
657 everything will be installed in subdirectories of @file{/usr/local}:
658 binaries will go into @file{/usr/local/bin}, libraries will end up in
659 @file{/usr/local/lib}, etc. This destination is usually not writable
660 by any user, so we assume that we have to become root before we can
661 run @code{make install}. In our example, running @code{make install}
662 will copy the program @file{hello} into @file{/usr/local/bin}
663 and @file{README} into @file{/usr/local/share/doc/amhello}.
665 A last and optional step is to run @code{make installcheck}. This
666 command may run tests on the installed files. @code{make check} tests
667 the files in the source tree, while @code{make installcheck} tests
668 their installed copies. The tests run by the latter can be different
669 from those run by the former. For instance, there are tests that
670 cannot be run in the source tree. Conversely, some packages are set
671 up so that @code{make installcheck} will run the very same tests as
672 @code{make check}, only on different files (non-installed
673 vs.@: installed). It can make a difference, for instance when the
674 source tree's layout is different from that of the installation.
675 Furthermore it may help to diagnose an incomplete installation.
677 Presently most packages do not have any @code{installcheck} tests
678 because the existence of @code{installcheck} is little known, and its
679 usefulness is neglected. Our little toy package is no better: @code{make
680 installcheck} does nothing.
682 @node Standard Targets
683 @subsection Standard @file{Makefile} Targets
685 So far we have come across four ways to run @command{make} in the GNU
686 Build System: @code{make}, @code{make check}, @code{make install}, and
687 @code{make installcheck}. The words @code{check}, @code{install}, and
688 @code{installcheck}, passed as arguments to @command{make}, are called
689 @dfn{targets}. @code{make} is a shorthand for @code{make all},
690 @code{all} being the default target in the GNU Build System.
692 Here is a list of the most useful targets that the GNU Coding Standards
698 Build programs, libraries, documentation, etc.@: (same as @code{make}).
701 Install what needs to be installed, copying the files from the
702 package's tree to system-wide directories.
703 @item make install-strip
704 @trindex install-strip
705 Same as @code{make install}, then strip debugging symbols. Some
706 users like to trade space for useful bug reports@enddots{}
709 The opposite of @code{make install}: erase the installed files.
710 (This needs to be run from the same build tree that was installed.)
713 Erase from the build tree the files built by @code{make all}.
716 Additionally erase anything @code{./configure} created.
719 Run the test suite, if any.
720 @item make installcheck
721 @trindex installcheck
722 Check the installed programs or libraries, if supported.
725 Recreate @file{@var{package}-@var{version}.tar.gz} from all the source
729 @node Standard Directory Variables
730 @subsection Standard Directory Variables
731 @cindex directory variables
733 The GNU Coding Standards also specify a hierarchy of variables to
734 denote installation directories. Some of these are:
736 @multitable {Directory variable} {@code{$@{datarootdir@}/doc/$@{PACKAGE@}}}
737 @headitem Directory variable @tab Default value
738 @item @code{prefix} @tab @code{/usr/local}
739 @item @w{@ @ @code{exec_prefix}} @tab @code{$@{prefix@}}
740 @item @w{@ @ @ @ @code{bindir}} @tab @code{$@{exec_prefix@}/bin}
741 @item @w{@ @ @ @ @code{libdir}} @tab @code{$@{exec_prefix@}/lib}
742 @item @w{@ @ @ @ @dots{}}
743 @item @w{@ @ @code{includedir}} @tab @code{$@{prefix@}/include}
744 @item @w{@ @ @code{datarootdir}} @tab @code{$@{prefix@}/share}
745 @item @w{@ @ @ @ @code{datadir}} @tab @code{$@{datarootdir@}}
746 @item @w{@ @ @ @ @code{mandir}} @tab @code{$@{datarootdir@}/man}
747 @item @w{@ @ @ @ @code{infodir}} @tab @code{$@{datarootdir@}/info}
748 @item @w{@ @ @ @ @code{docdir}} @tab @code{$@{datarootdir@}/doc/$@{PACKAGE@}}
749 @item @w{@ @ @dots{}}
752 @c We should provide a complete table somewhere, but not here. The
753 @c complete list of directory variables it too confusing as-is. It
754 @c requires some explanations that are too complicated for this
755 @c introduction. Besides listing directories like localstatedir
756 @c would make the explanations in ``Two-Part Install'' harder.
758 Each of these directories has a role which is often obvious from its
759 name. In a package, any installable file will be installed in one of
760 these directories. For instance in @code{amhello-1.0}, the program
761 @file{hello} is to be installed in @var{bindir}, the directory for
762 binaries. The default value for this directory is
763 @file{/usr/local/bin}, but the user can supply a different value when
764 calling @command{configure}. Also the file @file{README} will be
765 installed into @var{docdir}, which defaults to
766 @file{/usr/local/share/doc/amhello}.
770 As a user, if you wish to install a package on your own account, you
771 could proceed as follows:
774 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
776 ~/amhello-1.0 % @kbd{make}
778 ~/amhello-1.0 % @kbd{make install}
782 This would install @file{~/usr/bin/hello} and
783 @file{~/usr/share/doc/amhello/README}.
785 The list of all such directory options is shown by
786 @code{./configure --help}.
788 @node Standard Configuration Variables
789 @subsection Standard Configuration Variables
790 @cindex configuration variables, overriding
792 The GNU Coding Standards also define a set of standard configuration
793 variables used during the build. Here are some:
802 @item @code{CXXFLAGS}
806 @item @code{CPPFLAGS}
807 C/C++ preprocessor flags
811 @command{configure} usually does a good job at setting appropriate
812 values for these variables, but there are cases where you may want to
813 override them. For instance you may have several versions of a
814 compiler installed and would like to use another one, you may have
815 header files installed outside the default search path of the
816 compiler, or even libraries out of the way of the linker.
818 Here is how one would call @command{configure} to force it to use
819 @command{gcc-3} as C compiler, use header files from
820 @file{~/usr/include} when compiling, and libraries from
821 @file{~/usr/lib} when linking.
824 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
825 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
828 Again, a full list of these variables appears in the output of
829 @code{./configure --help}.
832 @subsection Overriding Default Configuration Setting with @file{config.site}
833 @cindex @file{config.site} example
835 When installing several packages using the same setup, it can be
836 convenient to create a file to capture common settings.
837 If a file named @file{@var{prefix}/share/config.site} exists,
838 @command{configure} will source it at the beginning of its execution.
840 Recall the command from the previous section:
843 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
844 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
847 Assuming we are installing many package in @file{~/usr}, and will
848 always want to use these definitions of @code{CC}, @code{CPPFLAGS}, and
849 @code{LDFLAGS}, we can automate this by creating the following
850 @file{~/usr/share/config.site} file:
853 test -z "$CC" && CC=gcc-3
854 test -z "$CPPFLAGS" && CPPFLAGS=-I$HOME/usr/include
855 test -z "$LDFLAGS" && LDFLAGS=-L$HOME/usr/lib
858 Now, any time a @file{configure} script is using the @file{~/usr}
859 prefix, it will execute the above @file{config.site} and define
860 these three variables.
863 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
864 configure: loading site script /home/adl/usr/share/config.site
868 @xref{Site Defaults, , Setting Site Defaults, autoconf, The Autoconf
869 Manual}, for more information about this feature.
873 @subsection Parallel Build Trees (a.k.a.@: VPATH Builds)
874 @cindex Parallel build trees
876 @cindex source tree and build tree
877 @cindex build tree and source tree
878 @cindex trees, source vs.@: build
880 The GNU Build System distinguishes two trees: the source tree, and
881 the build tree. These are two directories that may be the same, or
884 The source tree is rooted in the directory containing the
885 @file{configure} script. It contains all the source files (those that are
886 distributed), and may be arranged using several subdirectories.
888 The build tree is rooted in the current directory at the time @file{configure}
889 was run, and is populated with all object files, programs, libraries,
890 and other derived files built from the sources (and hence not
891 distributed). The build tree usually has the same subdirectory layout
892 as the source tree; its subdirectories are created automatically by
895 If @file{configure} is executed in its own directory, the source and
896 build trees are combined: derived files are constructed in the same
897 directories as their sources. This was the case in our first
898 installation example (@pxref{Basic Installation}).
900 A common request from users is that they want to confine all derived
901 files to a single directory, to keep their source directories
902 uncluttered. Here is how we could run @file{configure} to create
903 everything in a build tree (that is, subdirectory) called @file{build/}.
906 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
907 ~ % @kbd{cd amhello-1.0}
908 ~/amhello-1.0 % @kbd{mkdir build && cd build}
909 ~/amhello-1.0/build % @kbd{../configure}
911 ~/amhello-1.0/build % @kbd{make}
915 These setups, where source and build trees are different, are often
916 called @dfn{parallel builds} or @dfn{VPATH builds}. The expression
917 @emph{parallel build} is misleading: the word @emph{parallel} is a
918 reference to the way the build tree shadows the source tree, it is not
919 about some concurrency in the way build commands are run. For this
920 reason we refer to such setups using the name @emph{VPATH builds} in
921 the following. @emph{VPATH} is the name of the @command{make} feature
922 used by the @file{Makefile}s to allow these builds (@pxref{General
923 Search, , @code{VPATH} Search Path for All Prerequisites, make, The
926 @cindex multiple configurations, example
927 @cindex debug build, example
928 @cindex optimized build, example
930 VPATH builds have other interesting uses. One is to build the same
931 sources with multiple configurations. For instance:
933 @c Keep in sync with amhello-cflags.sh
935 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
936 ~ % @kbd{cd amhello-1.0}
937 ~/amhello-1.0 % @kbd{mkdir debug optim && cd debug}
938 ~/amhello-1.0/debug % @kbd{../configure CFLAGS='-g -O0'}
940 ~/amhello-1.0/debug % @kbd{make}
942 ~/amhello-1.0/debug % cd ../optim
943 ~/amhello-1.0/optim % @kbd{../configure CFLAGS='-O3 -fomit-frame-pointer'}
945 ~/amhello-1.0/optim % @kbd{make}
949 With network file systems, a similar approach can be used to build the
950 same sources on different machines. For instance, suppose that the
951 sources are installed on a directory shared by two hosts: @code{HOST1}
952 and @code{HOST2}, which may be different platforms.
955 ~ % @kbd{cd /nfs/src}
956 /nfs/src % @kbd{tar zxf ~/amhello-1.0.tar.gz}
959 On the first host, you could create a local build directory:
961 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
962 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
964 [HOST1] /tmp/amh % @kbd{make && sudo make install}
969 (Here we assume that the installer has configured @command{sudo} so it
970 can execute @code{make install} with root privileges; it is more convenient
971 than using @command{su} like in @ref{Basic Installation}).
973 On the second host, you would do exactly the same, possibly at
976 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
977 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
979 [HOST2] /tmp/amh % @kbd{make && sudo make install}
983 @cindex read-only source tree
984 @cindex source tree, read-only
986 In this scenario, nothing forbids the @file{/nfs/src/amhello-1.0}
987 directory from being read-only. In fact VPATH builds are also a means
988 of building packages from a read-only medium such as a CD-ROM. (The
989 FSF used to sell CD-ROMs with unpacked source code, before the GNU
990 project grew so big.)
992 @node Two-Part Install
993 @subsection Two-Part Installation
995 In our last example (@pxref{VPATH Builds}), a source tree was shared
996 by two hosts, but compilation and installation were done separately on
999 The GNU Build System also supports networked setups where part of the
1000 installed files should be shared among multiple hosts. It does so
1001 by distinguishing architecture-dependent files from
1002 architecture-independent files, and providing two @file{Makefile}
1003 targets to install each of these classes of files.
1005 @trindex install-exec
1006 @trindex install-data
1008 These targets are @code{install-exec} for architecture-dependent files
1009 and @code{install-data} for architecture-independent files.
1010 The command we used up to now, @code{make install}, can be thought of
1011 as a shorthand for @code{make install-exec install-data}.
1013 From the GNU Build System point of view, the distinction between
1014 architecture-dependent files and architecture-independent files is
1015 based exclusively on the directory variable used to specify their
1016 installation destination. In the list of directory variables we
1017 provided earlier (@pxref{Standard Directory Variables}), all the
1018 variables based on @var{exec-prefix} designate architecture-dependent
1019 directories whose files will be installed by @code{make install-exec}.
1020 The others designate architecture-independent directories and will
1021 serve files installed by @code{make install-data}. @xref{The Two Parts
1022 of Install}, for more details.
1024 Here is how we could revisit our two-host installation example,
1025 assuming that (1) we want to install the package directly in
1026 @file{/usr}, and (2) the directory @file{/usr/share} is shared by the
1029 On the first host we would run
1031 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1032 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1034 [HOST1] /tmp/amh % @kbd{make && sudo make install}
1038 On the second host, however, we need only install the
1039 architecture-specific files.
1041 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1042 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1044 [HOST2] /tmp/amh % @kbd{make && sudo make install-exec}
1048 In packages that have installation checks, it would make sense to run
1049 @code{make installcheck} (@pxref{Basic Installation}) to verify that
1050 the package works correctly despite the apparent partial installation.
1052 @node Cross-Compilation
1053 @subsection Cross-Compilation
1054 @cindex cross-compilation
1056 To @dfn{cross-compile} is to build on one platform a binary that will
1057 run on another platform. When speaking of cross-compilation, it is
1058 important to distinguish between the @dfn{build platform} on which
1059 the compilation is performed, and the @dfn{host platform} on which the
1060 resulting executable is expected to run. The following
1061 @command{configure} options are used to specify each of them:
1064 @item --build=@var{build}
1065 @opindex --build=@var{build}
1066 The system on which the package is built.
1067 @item --host=@var{host}
1068 @opindex --host=@var{host}
1069 The system where built programs and libraries will run.
1072 When the @option{--host} is used, @command{configure} will search for
1073 the cross-compiling suite for this platform. Cross-compilation tools
1074 commonly have their target architecture as prefix of their name. For
1075 instance my cross-compiler for MinGW32 has its binaries called
1076 @code{i586-mingw32msvc-gcc}, @code{i586-mingw32msvc-ld},
1077 @code{i586-mingw32msvc-as}, etc.
1079 @cindex MinGW cross-compilation example
1080 @cindex cross-compilation example
1082 Here is how we could build @code{amhello-1.0} for
1083 @code{i586-mingw32msvc} on a GNU/Linux PC.
1085 @c Keep in sync with amhello-cross-compile.sh
1087 ~/amhello-1.0 % @kbd{./configure --build i686-pc-linux-gnu --host i586-mingw32msvc}
1088 checking for a BSD-compatible install... /usr/bin/install -c
1089 checking whether build environment is sane... yes
1090 checking for gawk... gawk
1091 checking whether make sets $(MAKE)... yes
1092 checking for i586-mingw32msvc-strip... i586-mingw32msvc-strip
1093 checking for i586-mingw32msvc-gcc... i586-mingw32msvc-gcc
1094 checking for C compiler default output file name... a.exe
1095 checking whether the C compiler works... yes
1096 checking whether we are cross compiling... yes
1097 checking for suffix of executables... .exe
1098 checking for suffix of object files... o
1099 checking whether we are using the GNU C compiler... yes
1100 checking whether i586-mingw32msvc-gcc accepts -g... yes
1101 checking for i586-mingw32msvc-gcc option to accept ANSI C...
1103 ~/amhello-1.0 % @kbd{make}
1105 ~/amhello-1.0 % @kbd{cd src; file hello.exe}
1106 hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable
1109 The @option{--host} and @option{--build} options are usually all we
1110 need for cross-compiling. The only exception is if the package being
1111 built is itself a cross-compiler: we need a third option to specify
1112 its target architecture.
1115 @item --target=@var{target}
1116 @opindex --target=@var{target}
1117 When building compiler tools: the system for which the tools will
1121 For instance when installing GCC, the GNU Compiler Collection, we can
1122 use @option{--target=@/@var{target}} to specify that we want to build
1123 GCC as a cross-compiler for @var{target}. Mixing @option{--build} and
1124 @option{--target}, we can cross-compile a cross-compiler; such a
1125 three-way cross-compilation is known as a @dfn{Canadian cross}.
1127 @xref{Specifying Names, , Specifying the System Type, autoconf, The
1128 Autoconf Manual}, for more information about these @command{configure}
1132 @subsection Renaming Programs at Install Time
1133 @cindex Renaming programs
1134 @cindex Transforming program names
1135 @cindex Programs, renaming during installation
1137 The GNU Build System provides means to automatically rename
1138 executables and manpages before they are installed (@pxref{Man Pages}).
1139 This is especially convenient
1140 when installing a GNU package on a system that already has a
1141 proprietary implementation you do not want to overwrite. For instance,
1142 you may want to install GNU @command{tar} as @command{gtar} so you can
1143 distinguish it from your vendor's @command{tar}.
1145 This can be done using one of these three @command{configure} options.
1148 @item --program-prefix=@var{prefix}
1149 @opindex --program-prefix=@var{prefix}
1150 Prepend @var{prefix} to installed program names.
1151 @item --program-suffix=@var{suffix}
1152 @opindex --program-suffix=@var{suffix}
1153 Append @var{suffix} to installed program names.
1154 @item --program-transform-name=@var{program}
1155 @opindex --program-transform-name=@var{program}
1156 Run @code{sed @var{program}} on installed program names.
1159 The following commands would install @file{hello}
1160 as @file{/usr/local/bin/test-hello}, for instance.
1163 ~/amhello-1.0 % @kbd{./configure --program-prefix test-}
1165 ~/amhello-1.0 % @kbd{make}
1167 ~/amhello-1.0 % @kbd{sudo make install}
1172 @subsection Building Binary Packages Using DESTDIR
1175 The GNU Build System's @code{make install} and @code{make uninstall}
1176 interface does not exactly fit the needs of a system administrator
1177 who has to deploy and upgrade packages on lots of hosts. In other
1178 words, the GNU Build System does not replace a package manager.
1180 Such package managers usually need to know which files have been
1181 installed by a package, so a mere @code{make install} is
1184 @cindex Staged installation
1186 The @code{DESTDIR} variable can be used to perform a staged
1187 installation. The package should be configured as if it was going to
1188 be installed in its final location (e.g., @code{--prefix /usr}), but
1189 when running @code{make install}, the @code{DESTDIR} should be set to
1190 the absolute name of a directory into which the installation will be
1191 diverted. From this directory it is easy to review which files are
1192 being installed where, and finally copy them to their final location
1195 @cindex Binary package
1197 For instance here is how we could create a binary package containing a
1198 snapshot of all the files to be installed.
1200 @c Keep in sync with amhello-binpkg.sh
1202 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1204 ~/amhello-1.0 % @kbd{make}
1206 ~/amhello-1.0 % @kbd{make DESTDIR=$HOME/inst install}
1208 ~/amhello-1.0 % @kbd{cd ~/inst}
1209 ~/inst % @kbd{find . -type f -print > ../files.lst}
1210 ~/inst % @kbd{tar zcvf ~/amhello-1.0-i686.tar.gz `cat ../files.lst`}
1212 ./usr/share/doc/amhello/README
1215 After this example, @code{amhello-1.0-i686.tar.gz} is ready to be
1216 decompressed in @file{/} on many hosts. (Using @code{`cat ../files.lst`}
1217 instead of @samp{.} as argument for @command{tar} avoids entries for
1218 each subdirectory in the archive: we would not like @command{tar} to
1219 restore the modification time of @file{/}, @file{/usr/}, etc.)
1221 Note that when building packages for several architectures, it might
1222 be convenient to use @code{make install-data} and @code{make
1223 install-exec} (@pxref{Two-Part Install}) to gather
1224 architecture-independent files in a single package.
1226 @xref{Install}, for more information.
1228 @c We should document PRE_INSTALL/POST_INSTALL/NORMAL_INSTALL and their
1229 @c UNINSTALL counterparts.
1231 @node Preparing Distributions
1232 @subsection Preparing Distributions
1233 @cindex Preparing distributions
1234 @cindex Packages, preparation
1235 @cindex Distributions, preparation
1237 We have already mentioned @code{make dist}. This target collects all
1238 your source files and the necessary parts of the build system to
1239 create a tarball named @file{@var{package}-@var{version}.tar.gz}.
1241 @cindex @code{distcheck} better than @code{dist}
1243 Another, more useful command is @code{make distcheck}. The
1244 @code{distcheck} target constructs
1245 @file{@var{package}-@var{version}.tar.gz} just as well as @code{dist},
1246 but it additionally ensures most of the use cases presented so far
1251 It attempts a full compilation of the package (@pxref{Basic
1252 Installation}): unpacking the newly constructed tarball, running
1253 @code{make}, @code{make dvi}, @code{make check}, @code{make install},
1254 as well as @code{make installcheck}, and even @code{make dist},
1256 it tests VPATH builds with read-only source tree (@pxref{VPATH Builds}),
1258 it makes sure @code{make clean}, @code{make distclean}, and @code{make
1259 uninstall} do not omit any file (@pxref{Standard Targets}),
1261 and it checks that @code{DESTDIR} installations work (@pxref{DESTDIR}).
1264 All of these actions are performed in a temporary directory, so that
1265 no root privileges are required. The exact location and the exact
1266 structure of such a subdirectory (where the extracted sources are
1267 placed, how the temporary build and install directories are named and
1268 how deeply they are nested, etc.) is to be considered an
1269 implementation detail, which can change at any time; so do not rely on
1272 Releasing a package that fails @code{make distcheck} means that one of
1273 the scenarios we presented will not work and some users will be
1274 disappointed. Therefore it is a good practice to release a package
1275 only after a successful @code{make distcheck}. This of course does
1276 not imply that the package will be flawless, but at least it will
1277 prevent some of the embarrassing errors you may find in packages
1278 released by people who have never heard about @code{distcheck} (like
1279 @code{DESTDIR} not working because of a typo, or a distributed file
1280 being erased by @code{make clean}, or even @code{VPATH} builds not
1283 @xref{Creating amhello}, to recreate @file{amhello-1.0.tar.gz} using
1284 @code{make distcheck}. @xref{Checking the Distribution}, for more
1285 information about @code{distcheck}.
1287 @node Dependency Tracking
1288 @subsection Automatic Dependency Tracking
1289 @cindex Dependency tracking
1291 Dependency tracking is performed as a side-effect of compilation.
1292 Each time the build system compiles a source file, it computes its
1293 list of dependencies (in C these are the header files included by the
1294 source being compiled). Later, any time @command{make} is run and a
1295 dependency appears to have changed, the dependent files will be
1298 Automake generates code for automatic dependency tracking by default,
1299 unless the developer chooses to override it; for more information,
1300 @pxref{Dependencies}.
1302 When @command{configure} is executed, you can see it probing each
1303 compiler for the dependency mechanism it supports (several mechanisms
1307 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1309 checking dependency style of gcc... gcc3
1313 Because dependencies are only computed as a side-effect of the
1314 compilation, no dependency information exists the first time a package
1315 is built. This is OK because all the files need to be built anyway:
1316 @code{make} does not have to decide which files need to be rebuilt.
1317 In fact, dependency tracking is completely useless for one-time builds
1318 and there is a @command{configure} option to disable this:
1321 @item --disable-dependency-tracking
1322 @opindex --disable-dependency-tracking
1323 Speed up one-time builds.
1326 Some compilers do not offer any practical way to derive the list of
1327 dependencies as a side-effect of the compilation, requiring a separate
1328 run (maybe of another tool) to compute these dependencies. The
1329 performance penalty implied by these methods is important enough to
1330 disable them by default. The option @option{--enable-dependency-tracking}
1331 must be passed to @command{configure} to activate them.
1334 @item --enable-dependency-tracking
1335 @opindex --enable-dependency-tracking
1336 Do not reject slow dependency extractors.
1339 @xref{Dependency Tracking Evolution, , Dependency Tracking Evolution,
1340 automake-history, Brief History of Automake}, for some discussion about
1341 the different dependency tracking schemes used by Automake over the years.
1343 @node Nested Packages
1344 @subsection Nested Packages
1345 @cindex Nested packages
1346 @cindex Packages, nested
1349 Although nesting packages isn't something we would recommend to
1350 someone who is discovering the Autotools, it is a nice feature worthy
1351 of mention in this small advertising tour.
1353 Autoconfiscated packages (that means packages whose build system have
1354 been created by Autoconf and friends) can be nested to arbitrary
1357 A typical setup is that package A will distribute one of the libraries
1358 it needs in a subdirectory. This library B is a complete package with
1359 its own GNU Build System. The @command{configure} script of A will
1360 run the @command{configure} script of B as part of its execution;
1361 building and installing A will also build and install B. Generating a
1362 distribution for A will also include B.
1364 It is possible to gather several packages like this. GCC is a heavy
1365 user of this feature. This gives installers a single package to
1366 configure, build and install, while it allows developers to work on
1367 subpackages independently.
1369 When configuring nested packages, the @command{configure} options
1370 given to the top-level @command{configure} are passed recursively to
1371 nested @command{configure}s. A package that does not understand an
1372 option will ignore it, assuming it is meaningful to some other
1375 @opindex --help=recursive
1377 The command @code{configure --help=recursive} can be used to display
1378 the options supported by all the included packages.
1380 @xref{Subpackages}, for an example setup.
1383 @section How Autotools Help
1384 @cindex Autotools, purpose
1386 There are several reasons why you may not want to implement the GNU
1387 Build System yourself (read: write a @file{configure} script and
1388 @file{Makefile}s yourself).
1392 As we have seen, the GNU Build System has a lot of
1393 features (@pxref{Use Cases}).
1394 Some users may expect features you have not implemented because
1395 you did not need them.
1397 Implementing these features portably is difficult and exhausting.
1398 Think of writing portable shell scripts, and portable
1399 @file{Makefile}s, for systems you may not have handy. @xref{Portable
1400 Shell, , Portable Shell Programming, autoconf, The Autoconf Manual}, to
1403 You will have to upgrade your setup to follow changes to the GNU
1407 The GNU Autotools take all this burden off your back and provide:
1411 Tools to create a portable, complete, and self-contained GNU Build
1412 System, from simple instructions.
1413 @emph{Self-contained} meaning the resulting build system does not
1414 require the GNU Autotools.
1416 A central place where fixes and improvements are made:
1417 a bug-fix for a portability issue will benefit every package.
1420 Yet there also exist reasons why you may want NOT to use the
1421 Autotools@enddots{} For instance you may be already using (or used to)
1422 another incompatible build system. Autotools will only be useful if
1423 you do accept the concepts of the GNU Build System. People who have their
1424 own idea of how a build system should work will feel frustrated by the
1428 @section A Small Hello World
1429 @cindex Example Hello World
1430 @cindex Hello World example
1431 @cindex @file{amhello-1.0.tar.gz}, creation
1433 In this section we recreate the @file{amhello-1.0} package from
1434 scratch. The first subsection shows how to call the Autotools to
1435 instantiate the GNU Build System, while the second explains the
1436 meaning of the @file{configure.ac} and @file{Makefile.am} files read
1439 @anchor{amhello Explained}
1441 * Creating amhello:: Create @file{amhello-1.0.tar.gz} from scratch
1442 * amhello's configure.ac Setup Explained::
1443 * amhello's Makefile.am Setup Explained::
1446 @node Creating amhello
1447 @subsection Creating @file{amhello-1.0.tar.gz}
1449 Here is how we can recreate @file{amhello-1.0.tar.gz} from scratch.
1450 The package is simple enough so that we will only need to write 5
1451 files. (You may copy them from the final @file{amhello-1.0.tar.gz}
1452 that is distributed with Automake if you do not want to write them.)
1454 Create the following files in an empty directory.
1459 @file{src/main.c} is the source file for the @file{hello} program. We
1460 store it in the @file{src/} subdirectory, because later, when the package
1461 evolves, it will ease the addition of a @file{man/} directory for man
1462 pages, a @file{data/} directory for data files, etc.
1464 ~/amhello % @kbd{cat src/main.c}
1471 puts ("Hello World!");
1472 puts ("This is " PACKAGE_STRING ".");
1478 @file{README} contains some very limited documentation for our little
1481 ~/amhello % @kbd{cat README}
1482 This is a demonstration package for GNU Automake.
1483 Type 'info Automake' to read the Automake manual.
1487 @file{Makefile.am} and @file{src/Makefile.am} contain Automake
1488 instructions for these two directories.
1491 ~/amhello % @kbd{cat src/Makefile.am}
1492 bin_PROGRAMS = hello
1493 hello_SOURCES = main.c
1494 ~/amhello % @kbd{cat Makefile.am}
1496 dist_doc_DATA = README
1500 Finally, @file{configure.ac} contains Autoconf instructions to
1501 create the @command{configure} script.
1504 ~/amhello % @kbd{cat configure.ac}
1505 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1506 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1508 AC_CONFIG_HEADERS([config.h])
1517 @cindex @command{autoreconf}, example
1519 Once you have these five files, it is time to run the Autotools to
1520 instantiate the build system. Do this using the @command{autoreconf}
1524 ~/amhello % @kbd{autoreconf --install}
1525 configure.ac: installing './install-sh'
1526 configure.ac: installing './missing'
1527 configure.ac: installing './compile'
1528 src/Makefile.am: installing './depcomp'
1531 At this point the build system is complete.
1533 In addition to the three scripts mentioned in its output, you can see
1534 that @command{autoreconf} created four other files: @file{configure},
1535 @file{config.h.in}, @file{Makefile.in}, and @file{src/Makefile.in}.
1536 The latter three files are templates that will be adapted to the
1537 system by @command{configure} under the names @file{config.h},
1538 @file{Makefile}, and @file{src/Makefile}. Let's do this:
1541 ~/amhello % @kbd{./configure}
1542 checking for a BSD-compatible install... /usr/bin/install -c
1543 checking whether build environment is sane... yes
1544 checking for gawk... no
1545 checking for mawk... mawk
1546 checking whether make sets $(MAKE)... yes
1547 checking for gcc... gcc
1548 checking for C compiler default output file name... a.out
1549 checking whether the C compiler works... yes
1550 checking whether we are cross compiling... no
1551 checking for suffix of executables...
1552 checking for suffix of object files... o
1553 checking whether we are using the GNU C compiler... yes
1554 checking whether gcc accepts -g... yes
1555 checking for gcc option to accept ISO C89... none needed
1556 checking for style of include used by make... GNU
1557 checking dependency style of gcc... gcc3
1558 configure: creating ./config.status
1559 config.status: creating Makefile
1560 config.status: creating src/Makefile
1561 config.status: creating config.h
1562 config.status: executing depfiles commands
1566 @cindex @code{distcheck} example
1568 You can see @file{Makefile}, @file{src/Makefile}, and @file{config.h}
1569 being created at the end after @command{configure} has probed the
1570 system. It is now possible to run all the targets we wish
1571 (@pxref{Standard Targets}). For instance:
1574 ~/amhello % @kbd{make}
1576 ~/amhello % @kbd{src/hello}
1578 This is amhello 1.0.
1579 ~/amhello % @kbd{make distcheck}
1581 =============================================
1582 amhello-1.0 archives ready for distribution:
1584 =============================================
1587 Running @command{autoreconf} is only needed initially, when
1588 the GNU Build System does not exist. When you later change some
1589 instructions in a @file{Makefile.am} or @file{configure.ac}, the
1590 relevant part of the build system will be regenerated automatically
1591 when you execute @command{make}.
1593 @command{autoreconf} is a script that calls @command{autoconf},
1594 @command{automake}, and related commands in the right order. If you
1595 are beginning with these tools, it is not important to figure out in
1596 which order all of these tools should be invoked and why. (But for the
1597 curious: the basic idea is to run:
1600 @item @command{aclocal} (@pxref{aclocal Invocation}),
1601 @item @command{autoconf} (@pxref{,,,autoconf, The Autoconf Manual}),
1602 @item (if needed) @command{autoheader} (part of the
1603 Autoconf distribution), and
1604 @item @command{automake} (@pxref{automake Invocation}).
1608 If needed, tools related to Gettext (@pxref{,,,gettext, GNU gettext
1609 utilities}) and Libtool (@pxref{,,,libtool, GNU libtool}) are also
1610 invoked at different points. Thus, as you can see, using
1611 @command{autoreconf} is quite a bit more convenient.
1613 Nevertheless, because Autoconf and Automake have separate manuals, an
1614 essential idea to understand is that Autoconf is in charge of creating
1615 @file{configure} from @file{configure.ac}, while Automake is in charge
1616 of creating @file{Makefile.in}s from @file{Makefile.am}s and
1617 @file{configure.ac}. This should at least direct you to the right
1618 manual when seeking answers.
1620 @node amhello's configure.ac Setup Explained
1621 @subsection @code{amhello}'s @file{configure.ac} Setup Explained
1623 @cindex @file{configure.ac}, Hello World
1625 Let us begin with the contents of @file{configure.ac}.
1628 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1629 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1631 AC_CONFIG_HEADERS([config.h])
1639 This file is read by both @command{autoconf} (to create
1640 @file{configure}) and @command{automake} (to create the various
1641 @file{Makefile.in}s). It contains a series of M4 macros that will be
1642 expanded as shell code to finally form the @file{configure} script.
1643 We will not elaborate on the syntax of this file, because the Autoconf
1644 manual has a whole section about it (@pxref{Writing Autoconf Input, ,
1645 Writing @file{configure.ac}, autoconf, The Autoconf Manual}).
1647 The macros prefixed with @code{AC_} are Autoconf macros, documented
1648 in the Autoconf manual (@pxref{Autoconf Macro Index, , Autoconf Macro
1649 Index, autoconf, The Autoconf Manual}). The macros that start with
1650 @code{AM_} are Automake macros, documented later in this manual
1651 (@pxref{Macro Index}).
1653 The first two lines of @file{configure.ac} initialize Autoconf and
1654 Automake. @code{AC_INIT} takes in as parameters the name of the package,
1655 its version number, and a contact address for bug-reports about the
1656 package (this address is output at the end of @code{./configure
1657 --help}, for instance). When adapting this setup to your own package,
1658 by all means please do not blindly copy Automake's address: use the
1659 mailing list of your package, or your own mail address.
1665 The argument to @code{AM_INIT_AUTOMAKE} is a list of options for
1666 @command{automake} (@pxref{Options}). @option{-Wall} and
1667 @option{-Werror} ask @command{automake} to turn on all warnings and
1668 report them as errors. We are speaking of @strong{Automake} warnings
1669 here, such as dubious instructions in @file{Makefile.am}. This has
1670 absolutely nothing to do with how the compiler will be called, even
1671 though it may support options with similar names. Using @option{-Wall
1672 -Werror} is a safe setting when starting to work on a package: you do
1673 not want to miss any issues. Later you may decide to relax things a
1674 bit. The @option{foreign} option tells Automake that this package
1675 will not follow the GNU Standards. GNU packages should always
1676 distribute additional files such as @file{ChangeLog}, @file{AUTHORS},
1677 etc. We do not want @command{automake} to complain about these
1678 missing files in our small example.
1680 The @code{AC_PROG_CC} line causes the @command{configure} script to
1681 search for a C compiler and define the variable @code{CC} with its
1682 name. The @file{src/Makefile.in} file generated by Automake uses the
1683 variable @code{CC} to build @file{hello}, so when @command{configure}
1684 creates @file{src/Makefile} from @file{src/Makefile.in}, it will define
1685 @code{CC} with the value it has found. If Automake is asked to create
1686 a @file{Makefile.in} that uses @code{CC} but @file{configure.ac} does
1687 not define it, it will suggest you add a call to @code{AC_PROG_CC}.
1689 The @code{AC_CONFIG_HEADERS([config.h])} invocation causes the
1690 @command{configure} script to create a @file{config.h} file gathering
1691 @samp{#define}s defined by other macros in @file{configure.ac}. In our
1692 case, the @code{AC_INIT} macro already defined a few of them. Here
1693 is an excerpt of @file{config.h} after @command{configure} has run:
1697 /* Define to the address where bug reports for this package should be sent. */
1698 #define PACKAGE_BUGREPORT "@value{PACKAGE_BUGREPORT}"
1700 /* Define to the full name and version of this package. */
1701 #define PACKAGE_STRING "amhello 1.0"
1705 As you probably noticed, @file{src/main.c} includes @file{config.h} so
1706 it can use @code{PACKAGE_STRING}. In a real-world project,
1707 @file{config.h} can grow quite large, with one @samp{#define} per
1708 feature probed on the system.
1710 The @code{AC_CONFIG_FILES} macro declares the list of files that
1711 @command{configure} should create from their @file{*.in} templates.
1712 Automake also scans this list to find the @file{Makefile.am} files it must
1713 process. (This is important to remember: when adding a new directory
1714 to your project, you should add its @file{Makefile} to this list,
1715 otherwise Automake will never process the new @file{Makefile.am} you
1716 wrote in that directory.)
1718 Finally, the @code{AC_OUTPUT} line is a closing command that actually
1719 produces the part of the script in charge of creating the files
1720 registered with @code{AC_CONFIG_HEADERS} and @code{AC_CONFIG_FILES}.
1722 @cindex @command{autoscan}
1724 When starting a new project, we suggest you start with such a simple
1725 @file{configure.ac}, and gradually add the other tests it requires.
1726 The command @command{autoscan} can also suggest a few of the tests
1727 your package may need (@pxref{autoscan Invocation, , Using
1728 @command{autoscan} to Create @file{configure.ac}, autoconf, The
1732 @node amhello's Makefile.am Setup Explained
1733 @subsection @code{amhello}'s @file{Makefile.am} Setup Explained
1735 @cindex @file{Makefile.am}, Hello World
1737 We now turn to @file{src/Makefile.am}. This file contains
1738 Automake instructions to build and install @file{hello}.
1741 bin_PROGRAMS = hello
1742 hello_SOURCES = main.c
1745 A @file{Makefile.am} has the same syntax as an ordinary
1746 @file{Makefile}. When @command{automake} processes a
1747 @file{Makefile.am} it copies the entire file into the output
1748 @file{Makefile.in} (that will be later turned into @file{Makefile} by
1749 @command{configure}) but will react to certain variable definitions
1750 by generating some build rules and other variables.
1751 Often @file{Makefile.am}s contain only a list of variable definitions as
1752 above, but they can also contain other variable and rule definitions that
1753 @command{automake} will pass along without interpretation.
1755 Variables that end with @code{_PROGRAMS} are special variables
1756 that list programs that the resulting @file{Makefile} should build.
1757 In Automake speak, this @code{_PROGRAMS} suffix is called a
1758 @dfn{primary}; Automake recognizes other primaries such as
1759 @code{_SCRIPTS}, @code{_DATA}, @code{_LIBRARIES}, etc.@: corresponding
1760 to different types of files.
1762 The @samp{bin} part of the @code{bin_PROGRAMS} tells
1763 @command{automake} that the resulting programs should be installed in
1764 @var{bindir}. Recall that the GNU Build System uses a set of variables
1765 to denote destination directories and allow users to customize these
1766 locations (@pxref{Standard Directory Variables}). Any such directory
1767 variable can be put in front of a primary (omitting the @code{dir}
1768 suffix) to tell @command{automake} where to install the listed files.
1770 Programs need to be built from source files, so for each program
1771 @code{@var{prog}} listed in a @code{@w{_PROGRAMS}} variable,
1772 @command{automake} will look for another variable named
1773 @code{@var{prog}_SOURCES} listing its source files. There may be more
1774 than one source file: they will all be compiled and linked together.
1776 Automake also knows that source files need to be distributed when
1777 creating a tarball (unlike built programs). So a side-effect of this
1778 @code{hello_SOURCES} declaration is that @file{main.c} will be
1779 part of the tarball created by @code{make dist}.
1781 Finally here are some explanations regarding the top-level
1786 dist_doc_DATA = README
1789 @code{SUBDIRS} is a special variable listing all directories that
1790 @command{make} should recurse into before processing the current
1791 directory. So this line is responsible for @command{make} building
1792 @file{src/hello} even though we run it from the top-level. This line
1793 also causes @code{make install} to install @file{src/hello} before
1794 installing @file{README} (not that this order matters).
1796 The line @code{dist_doc_DATA = README} causes @file{README} to be
1797 distributed and installed in @var{docdir}. Files listed with the
1798 @code{_DATA} primary are not automatically part of the tarball built
1799 with @code{make dist}, so we add the @code{dist_} prefix so they get
1800 distributed. However, for @file{README} it would not have been
1801 necessary: @command{automake} automatically distributes any
1802 @file{README} file it encounters (the list of other files
1803 automatically distributed is presented by @code{automake --help}).
1804 The only important effect of this second line is therefore to install
1805 @file{README} during @code{make install}.
1807 One thing not covered in this example is accessing the installation
1808 directory values (@pxref{Standard Directory Variables}) from your
1809 program code, that is, converting them into defined macros. For this,
1810 @pxref{Defining Directories,,, autoconf, The Autoconf Manual}.
1814 @chapter General ideas
1816 The following sections cover a few basic ideas that will help you
1817 understand how Automake works.
1820 * General Operation:: General operation of Automake
1821 * Strictness:: Standards conformance checking
1822 * Uniform:: The Uniform Naming Scheme
1823 * Length Limitations:: Staying below the command line length limit
1824 * Canonicalization:: How derived variables are named
1825 * User Variables:: Variables reserved for the user
1826 * Auxiliary Programs:: Programs automake might require
1830 @node General Operation
1831 @section General Operation
1833 Automake works by reading a @file{Makefile.am} and generating a
1834 @file{Makefile.in}. Certain variables and rules defined in the
1835 @file{Makefile.am} instruct Automake to generate more specialized code;
1836 for instance, a @code{bin_PROGRAMS} variable definition will cause rules
1837 for compiling and linking programs to be generated.
1839 @cindex Non-standard targets
1840 @cindex @code{git-dist}, non-standard example
1843 The variable definitions and rules in the @file{Makefile.am} are
1844 copied mostly verbatim into the generated file, with all variable
1845 definitions preceding all rules. This allows you to add almost
1846 arbitrary code into the generated @file{Makefile.in}. For instance,
1847 the Automake distribution includes a non-standard rule for the
1848 @code{git-dist} target, which the Automake maintainer uses to make
1849 distributions from the source control system.
1851 @cindex GNU Make extensions
1853 Note that most GNU Make extensions are not recognized by Automake. Using
1854 such extensions in a @file{Makefile.am} will lead to errors or confusing
1857 @cindex Append operator
1859 A special exception is that the GNU Make append operator, @samp{+=}, is
1860 supported. This operator appends its right hand argument to the variable
1861 specified on the left. Automake will translate the operator into
1862 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
1864 Automake tries to keep comments grouped with any adjoining rules or
1865 variable definitions.
1867 @cindex Limitations of automake parser
1868 @cindex Automake parser, limitations of
1869 @cindex indentation in Makefile.am
1870 Generally, Automake is not particularly smart in the parsing of unusual
1871 @file{Makefile} constructs, so you're advised to avoid fancy constructs or
1872 ``creative'' use of whitespace.
1873 @c Keep this in sync with doc-parsing-buglets-tabs.sh
1874 For example, @key{TAB} characters cannot be used between a target name
1875 and the following ``@code{:}'' character, and variable assignments
1876 shouldn't be indented with @key{TAB} characters.
1877 @c Keep this in sync with doc-parsing-buglets-colneq-subst.sh
1878 Also, using more complex macros in target names can cause trouble:
1881 % @kbd{cat Makefile.am}
1884 Makefile.am:1: bad characters in variable name '$(FOO'
1885 Makefile.am:1: ':='-style assignments are not portable
1888 @cindex Make targets, overriding
1889 @cindex Make rules, overriding
1890 @cindex Overriding make rules
1891 @cindex Overriding make targets
1893 A rule defined in @file{Makefile.am} generally overrides any such
1894 rule of a similar name that would be automatically generated by
1895 @command{automake}. Although this is a supported feature, it is generally
1896 best to avoid making use of it, as sometimes the generated rules are
1899 @cindex Variables, overriding
1900 @cindex Overriding make variables
1902 Similarly, a variable defined in @file{Makefile.am} or
1903 @code{AC_SUBST}ed from @file{configure.ac} will override any
1904 definition of the variable that @command{automake} would ordinarily
1905 create. This feature is often more useful than the ability to
1906 override a rule. Be warned that many of the variables generated by
1907 @command{automake} are considered to be for internal use only, and their
1908 names might change in future releases.
1910 @cindex Recursive operation of Automake
1911 @cindex Automake, recursive operation
1912 @cindex Example of recursive operation
1914 When examining a variable definition, Automake will recursively examine
1915 variables referenced in the definition. For example, if Automake is
1916 looking at the content of @code{foo_SOURCES} in this snippet
1918 @c Keep in sync with interp.sh
1921 foo_SOURCES = c.c $(xs)
1924 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
1925 contents of @code{foo_SOURCES}.
1927 @cindex @code{##} (special Automake comment)
1928 @cindex Special Automake comment
1929 @cindex Comment, special to Automake
1931 Automake also allows a form of comment that is @emph{not} copied into
1932 the output; all lines beginning with @samp{##} (leading spaces allowed)
1933 are completely ignored by Automake.
1935 It is customary to make the first line of @file{Makefile.am} read:
1937 @cindex Makefile.am, first line
1938 @cindex First line of Makefile.am
1941 ## Process this file with automake to produce Makefile.in
1944 @c FIXME document customary ordering of Makefile.am here!
1949 @c "Gnits" used to be a separate section.
1950 @c This @anchor allows old links to still work.
1952 @cindex Non-GNU packages
1954 While Automake is intended to be used by maintainers of GNU packages, it
1955 does make some effort to accommodate those who wish to use it, but do
1956 not want to use all the GNU conventions.
1958 @cindex Strictness, defined
1959 To this end, Automake supports three levels of @dfn{strictness}---how
1960 stringently Automake should enforce conformance with GNU conventions.
1961 Each strictness level can be selected using an option of the same name;
1964 The strictness levels are:
1968 @cindex Strictness, @option{gnu}
1969 @cindex @option{gnu} strictness
1971 This is the default level of strictness. Automake will check for
1972 basic compliance with the GNU standards for software packaging.
1973 @xref{Top,,, standards, The GNU Coding Standards}, for full details
1974 of these standards. Currently the following checks are made:
1978 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
1979 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
1980 or @file{COPYING}, are required at the topmost directory of the package.
1982 If the @option{--add-missing} option is given, @command{automake} will
1983 add a generic version of the @file{INSTALL} file as well as the
1984 @file{COPYING} file containing the text of the current version of the
1985 GNU General Public License existing at the time of this Automake release
1986 (version 3 as this is written,
1987 @uref{https://www.gnu.org/@/copyleft/@/gpl.html}).
1988 However, an existing @file{COPYING} file will never be overwritten by
1992 The options @option{no-installman} and @option{no-installinfo} are
1996 Future versions of Automake will add more checks at this level of
1997 strictness; it is advisable to be familiar with the precise requirements
1998 of the GNU standards.
2000 Future versions of Automake may, at this level of strictness, require
2001 certain non-standard GNU tools to be available to maintainer-only
2002 @file{Makefile} rules. For instance, in the future @command{pathchk}
2003 (@pxref{pathchk invocation,,, coreutils, GNU Coreutils})
2004 may be required to run @samp{make dist}.
2007 @cindex Strictness, @option{foreign}
2008 @cindex @option{foreign} strictness
2010 Automake will check for only those things that are absolutely
2011 required for proper operation. For instance, whereas GNU standards
2012 dictate the existence of a @file{NEWS} file, it will not be required in
2013 this mode. This strictness will also turn off some warnings by default
2014 (among them, portability warnings).
2017 @cindex Strictness, @option{gnits}
2018 @cindex @option{gnits} strictness
2020 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
2021 standards}. These are based on the GNU standards, but are even more
2022 detailed. Unless you are a Gnits standards contributor, it is
2023 recommended that you avoid this option until such time as the Gnits
2024 standard is published (which is unlikely to ever happen).
2026 Currently, @option{--gnits} does all the checks that
2027 @option{--gnu} does, and checks the following as well:
2031 @samp{make installcheck} will check to make sure that the
2032 @option{--help} and @option{--version} print a usage message and a
2033 version string, respectively. This is the @option{std-options} option
2037 @samp{make dist} will check to make sure the @file{NEWS} file has been
2038 updated to the current version.
2041 @code{VERSION} is checked to make sure its format complies with Gnits
2043 @c FIXME xref when standards are finished
2046 @cindex @file{README-alpha}
2047 If @code{VERSION} indicates that this is an alpha release, and the file
2048 @file{README-alpha} appears in the topmost directory of a package, then
2049 it is included in the distribution. This is done in @option{--gnits}
2050 mode, and no other, because this mode is the only one where version
2051 number formats are constrained, and hence the only mode where Automake
2052 can automatically determine whether @file{README-alpha} should be
2056 The file @file{THANKS} is required.
2064 @section The Uniform Naming Scheme
2066 @cindex Uniform naming scheme
2068 Automake variables generally follow a @dfn{uniform naming scheme} that
2069 makes it easy to decide how programs (and other derived objects) are
2070 built, and how they are installed. This scheme also supports
2071 @command{configure} time determination of what should be built.
2073 @cindex @code{_PROGRAMS} primary variable
2074 @cindex @code{PROGRAMS} primary variable
2075 @cindex Primary variable, @code{PROGRAMS}
2076 @cindex Primary variable, defined
2079 At @command{make} time, certain variables are used to determine which
2080 objects are to be built. The variable names are made of several pieces
2081 that are concatenated together.
2083 The piece that tells @command{automake} what is being built is commonly called
2084 the @dfn{primary}. For instance, the primary @code{PROGRAMS} holds a
2085 list of programs that are to be compiled and linked.
2088 @cindex @code{pkgdatadir}, defined
2089 @cindex @code{pkgincludedir}, defined
2090 @cindex @code{pkglibdir}, defined
2091 @cindex @code{pkglibexecdir}, defined
2094 @vindex pkgincludedir
2096 @vindex pkglibexecdir
2098 @cindex @code{PACKAGE}, directory
2099 A different set of names is used to decide where the built objects
2100 should be installed. These names are prefixes to the primary, and they
2101 indicate which standard directory should be used as the installation
2102 directory. The standard directory names are given in the GNU standards
2103 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
2104 Automake extends this list with @code{pkgdatadir}, @code{pkgincludedir},
2105 @code{pkglibdir}, and @code{pkglibexecdir}; these are the same as the
2106 non-@samp{pkg} versions, but with @samp{$(PACKAGE)} appended. For instance,
2107 @code{pkglibdir} is defined as @samp{$(libdir)/$(PACKAGE)}.
2109 @cindex @code{EXTRA_}, prepending
2110 For each primary, there is one additional variable named by prepending
2111 @samp{EXTRA_} to the primary name. This variable is used to list
2112 objects that may or may not be built, depending on what
2113 @command{configure} decides. This variable is required because Automake
2114 must statically know the entire list of objects that may be built in
2115 order to generate a @file{Makefile.in} that will work in all cases.
2117 @cindex @code{EXTRA_PROGRAMS}, defined
2118 @cindex Example, @code{EXTRA_PROGRAMS}
2119 @cindex @command{cpio} example
2121 For instance, @command{cpio} decides at configure time which programs
2122 should be built. Some of the programs are installed in @code{bindir},
2123 and some are installed in @code{sbindir}:
2126 EXTRA_PROGRAMS = mt rmt
2127 bin_PROGRAMS = cpio pax
2128 sbin_PROGRAMS = $(MORE_PROGRAMS)
2131 Defining a primary without a prefix as a variable, e.g.,
2132 @samp{PROGRAMS}, is an error.
2134 Note that the common @samp{dir} suffix is left off when constructing the
2135 variable names; thus one writes @samp{bin_PROGRAMS} and not
2136 @samp{bindir_PROGRAMS}.
2138 Not every sort of object can be installed in every directory.
2139 Automake will flag those attempts it finds in error (but see below how
2140 to override the check if you need to). Automake will also diagnose
2141 obvious misspellings in directory names.
2143 @cindex Extending list of installation directories
2144 @cindex Installation directories, extending list
2146 Sometimes the standard directories---even as augmented by
2147 Automake---are not enough. In particular it is sometimes useful, for
2148 clarity, to install objects in a subdirectory of some predefined
2149 directory. To this end, Automake allows you to extend the list of
2150 possible installation directories. A given prefix (e.g., @samp{zar})
2151 is valid if a variable of the same name with @samp{dir} appended is
2152 defined (e.g., @samp{zardir}).
2154 For instance, the following snippet will install @file{file.xml} into
2155 @samp{$(datadir)/xml}.
2157 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2159 xmldir = $(datadir)/xml
2163 This feature can also be used to override the sanity checks Automake
2164 performs to diagnose suspicious directory/primary couples (in the
2165 unlikely case that you need to omit these checks). For example,
2166 Automake would error out on this input:
2168 @c Should be tested in primary-prefix-invalid-couples.sh
2170 # Forbidden directory combinations, automake will error out on this.
2171 pkglib_PROGRAMS = foo
2172 doc_LIBRARIES = libquux.a
2176 but it will succeed with this:
2178 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2180 # Work around forbidden directory combinations. Do not use this
2181 # without a very good reason!
2182 my_execbindir = $(pkglibdir)
2183 my_doclibdir = $(docdir)
2184 my_execbin_PROGRAMS = foo
2185 my_doclib_LIBRARIES = libquux.a
2188 The @samp{exec} substring of the @samp{my_execbindir} variable lets
2189 the files be installed at the right time (@pxref{The Two Parts of
2192 @cindex @samp{noinst_} primary prefix, definition
2195 The special prefix @samp{noinst_} indicates that the objects in question
2196 should be built but not installed at all. This is usually used for
2197 objects required to build the rest of your package, for instance static
2198 libraries (@pxref{A Library}), or helper scripts.
2200 @cindex @samp{check_} primary prefix, definition
2203 The special prefix @samp{check_} indicates that the objects in question
2204 should not be built until the @samp{make check} command is run. Those
2205 objects are not installed either.
2207 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
2208 @samp{LTLIBRARIES}, @samp{LISP}, @samp{PYTHON}, @samp{JAVA},
2209 @samp{SCRIPTS}, @samp{DATA}, @samp{HEADERS}, @samp{MANS}, and
2223 Some primaries also allow additional prefixes that control other
2224 aspects of @command{automake}'s behavior. The currently defined prefixes
2225 are @samp{dist_}, @samp{nodist_}, @samp{nobase_}, and @samp{notrans_}.
2226 These prefixes are explained later (@pxref{Program and Library Variables})
2227 (@pxref{Man Pages}).
2230 @node Length Limitations
2231 @section Staying below the command line length limit
2233 @cindex command line length limit
2236 Traditionally, most unix-like systems have a length limitation for the
2237 command line arguments and environment contents when creating new
2238 processes (see for example
2239 @uref{https://www.in-ulm.de/@/~mascheck/@/various/@/argmax/} for an
2240 overview on this issue),
2241 which of course also applies to commands spawned by @command{make}.
2242 POSIX requires this limit to be at least 4096 bytes, and most modern
2243 systems have quite high limits (or are unlimited).
2245 In order to create portable Makefiles that do not trip over these
2246 limits, it is necessary to keep the length of file lists bounded.
2247 Unfortunately, it is not possible to do so fully transparently within
2248 Automake, so your help may be needed. Typically, you can split long
2249 file lists manually and use different installation directory names for
2250 each list. For example,
2253 data_DATA = file1 @dots{} file@var{N} file@var{N+1} @dots{} file@var{2N}
2257 may also be written as
2259 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2261 data_DATA = file1 @dots{} file@var{N}
2262 data2dir = $(datadir)
2263 data2_DATA = file@var{N+1} @dots{} file@var{2N}
2267 and will cause Automake to treat the two lists separately during
2268 @code{make install}. See @ref{The Two Parts of Install} for choosing
2269 directory names that will keep the ordering of the two parts of
2270 installation Note that @code{make dist} may still only work on a host
2271 with a higher length limit in this example.
2273 Automake itself employs a couple of strategies to avoid long command
2274 lines. For example, when @samp{$@{srcdir@}/} is prepended to file
2275 names, as can happen with above @code{$(data_DATA)} lists, it limits
2276 the amount of arguments passed to external commands.
2278 Unfortunately, some systems' @command{make} commands may prepend
2279 @code{VPATH} prefixes like @samp{$@{srcdir@}/} to file names from the
2280 source tree automatically (@pxref{Automatic Rule Rewriting, , Automatic
2281 Rule Rewriting, autoconf, The Autoconf Manual}). In this case, the user
2282 may have to switch to use GNU Make, or refrain from using VPATH builds,
2283 in order to stay below the length limit.
2285 For libraries and programs built from many sources, convenience archives
2286 may be used as intermediates in order to limit the object list length
2287 (@pxref{Libtool Convenience Libraries}).
2290 @node Canonicalization
2291 @section How derived variables are named
2293 @cindex canonicalizing Automake variables
2295 Sometimes a Makefile variable name is derived from some text the
2296 maintainer supplies. For instance, a program name listed in
2297 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
2298 variable. In cases like this, Automake canonicalizes the text, so that
2299 program names and the like do not have to follow Makefile variable naming
2300 rules. All characters in the name except for letters, numbers, the
2301 strudel (@@), and the underscore are turned into underscores when making
2302 variable references.
2304 For example, if your program is named @file{sniff-glue}, the derived
2305 variable name would be @samp{sniff_glue_SOURCES}, not
2306 @samp{sniff-glue_SOURCES}. Similarly the sources for a library named
2307 @file{libmumble++.a} should be listed in the
2308 @samp{libmumble___a_SOURCES} variable.
2310 The strudel is an addition, to make the use of Autoconf substitutions in
2311 variable names less obfuscating.
2314 @node User Variables
2315 @section Variables reserved for the user
2317 @cindex variables, reserved for the user
2318 @cindex user variables
2320 Some @file{Makefile} variables are reserved by the GNU Coding Standards
2321 for the use of the ``user''---the person building the package. For
2322 instance, @code{CFLAGS} is one such variable.
2324 Sometimes package developers are tempted to set user variables such as
2325 @code{CFLAGS} because it appears to make their job easier. However,
2326 the package itself should never set a user variable, particularly not
2327 to include switches that are required for proper compilation of the
2328 package. Since these variables are documented as being for the
2329 package builder, that person rightfully expects to be able to override
2330 any of these variables at build time.
2332 To get around this problem, Automake introduces an automake-specific
2333 shadow variable for each user flag variable. (Shadow variables are
2334 not introduced for variables like @code{CC}, where they would make no
2335 sense.) The shadow variable is named by prepending @samp{AM_} to the
2336 user variable's name. For instance, the shadow variable for
2337 @code{YFLAGS} is @code{AM_YFLAGS}. The package maintainer---that is,
2338 the author(s) of the @file{Makefile.am} and @file{configure.ac}
2339 files---may adjust these shadow variables however necessary.
2341 @xref{Flag Variables Ordering}, for more discussion about these
2342 variables and how they interact with per-target variables.
2344 @node Auxiliary Programs
2345 @section Programs automake might require
2347 @cindex Programs, auxiliary
2348 @cindex Auxiliary programs
2350 Automake sometimes requires helper programs so that the generated
2351 @file{Makefile} can do its work properly. There are a fairly large
2352 number of them, and we list them here.
2354 Although all of these files are distributed and installed with
2355 Automake, a couple of them are maintained separately. The Automake
2356 copies are updated before each release, but we mention the original
2357 source in case you need more recent versions.
2362 This is a wrapper primarily for the Microsoft lib archiver, to make
2367 This is a wrapper for compilers that do not accept options @option{-c}
2368 and @option{-o} at the same time. It is only used when absolutely
2369 required. Such compilers are rare, with the Microsoft C/C++ Compiler
2370 as the most notable exception. This wrapper also makes the following
2371 common options available for that compiler, while performing file name
2372 translation where needed: @option{-I}, @option{-L}, @option{-l},
2373 @option{-Wl,} and @option{-Xlinker}.
2377 @cmindex config.guess
2379 These two programs compute the canonical triplets for the given build,
2380 host, or target architecture. These programs are updated regularly to
2381 support new architectures and fix probes broken by changes in new
2382 kernel versions. Each new release of Automake comes with up-to-date
2383 copies of these programs. If your copy of Automake is getting old,
2384 you are encouraged to fetch the latest versions of these files from
2385 @url{https://savannah.gnu.org/git/?group=config} before making a
2390 This program understands how to run a compiler so that it will
2391 generate not only the desired output but also dependency information
2392 that is then used by the automatic dependency tracking feature
2393 (@pxref{Dependencies}).
2397 This is a replacement for the @command{install} program that works on
2398 platforms where @command{install} is unavailable or unusable.
2402 This script is used to generate a @file{version.texi} file. It examines
2403 a file and prints some date information about it.
2406 @cmindex missing @r{program}
2407 This wraps a number of programs that are typically only required by
2408 maintainers. If the program in question doesn't exist, or seems too old,
2409 @command{missing} will print an informative warning before failing out,
2410 to provide the user with more context and information.
2413 @cmindex mkinstalldirs
2414 This script used to be a wrapper around @samp{mkdir -p}, which is not
2415 portable. Now we prefer to use @samp{install-sh -d} when @command{configure}
2416 finds that @samp{mkdir -p} does not work, this makes one less script to
2419 For backward compatibility @file{mkinstalldirs} is still used and
2420 distributed when @command{automake} finds it in a package. But it is no
2421 longer installed automatically, and it should be safe to remove it.
2425 This is used to byte-compile Python scripts.
2428 @cmindex test-driver
2429 This implements the default test driver offered by the parallel
2433 @cmindex texinfo.tex
2434 When Texinfo sources are in the package, this file is required for
2435 @samp{make dvi}, @samp{make ps} and @samp{make pdf}. The latest
2436 version can be downloaded from
2437 @url{https://www.gnu.org/software/texinfo/}. A working @TeX{}
2438 distribution, or at least a @file{tex} program, is also required.
2439 Furthermore, @samp{make dist} invokes @samp{make dvi}, so these become
2440 requirements for making a distribution with Texinfo sources.
2444 This program wraps @command{lex} and @command{yacc} to rename their
2445 output files. It also ensures that, for instance, multiple
2446 @command{yacc} instances can be invoked in a single directory in
2453 @chapter Some example packages
2455 This section contains two small examples.
2457 The first example (@pxref{Complete}) assumes you have an existing
2458 project already using Autoconf, with handcrafted @file{Makefile}s, and
2459 that you want to convert it to using Automake. If you are discovering
2460 both tools, it is probably better that you look at the Hello World
2461 example presented earlier (@pxref{Hello World}).
2463 The second example (@pxref{true}) shows how two programs can be built
2464 from the same file, using different compilation parameters. It
2465 contains some technical digressions that are probably best skipped on
2469 * Complete:: A simple example, start to finish
2470 * true:: Building true and false
2475 @section A simple example, start to finish
2477 @cindex Complete example
2479 Let's suppose you just finished writing @code{zardoz}, a program to make
2480 your head float from vortex to vortex. You've been using Autoconf to
2481 provide a portability framework, but your @file{Makefile.in}s have been
2482 ad-hoc. You want to make them bulletproof, so you turn to Automake.
2484 @cindex @code{AM_INIT_AUTOMAKE}, example use
2486 The first step is to update your @file{configure.ac} to include the
2487 commands that @command{automake} needs. The way to do this is to add an
2488 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
2491 AC_INIT([zardoz], [1.0])
2496 Since your program doesn't have any complicating factors (e.g., it
2497 doesn't use @code{gettext}, it doesn't want to build a shared library),
2498 you're done with this part. That was easy!
2500 @cindex @command{aclocal} program, introduction
2501 @cindex @file{aclocal.m4}, preexisting
2502 @cindex @file{acinclude.m4}, defined
2504 Now you must regenerate @file{configure}. But to do that, you'll need
2505 to tell @command{autoconf} how to find the new macro you've used. The
2506 easiest way to do this is to use the @command{aclocal} program to
2507 generate your @file{aclocal.m4} for you. But wait@dots{} maybe you
2508 already have an @file{aclocal.m4}, because you had to write some hairy
2509 macros for your program. The @command{aclocal} program lets you put
2510 your own macros into @file{acinclude.m4}, so simply rename and then
2514 mv aclocal.m4 acinclude.m4
2519 @cindex @command{zardoz} example
2521 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
2522 Since @code{zardoz} is a user program, you want to install it where the
2523 rest of the user programs go: @code{bindir}. Additionally,
2524 @code{zardoz} has some Texinfo documentation. Your @file{configure.ac}
2525 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
2526 @samp{$(LIBOBJS)}. So here's what you'd write:
2529 bin_PROGRAMS = zardoz
2530 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
2531 zardoz_LDADD = $(LIBOBJS)
2533 info_TEXINFOS = zardoz.texi
2536 Now you can run @samp{automake --add-missing} to generate your
2537 @file{Makefile.in} and grab any auxiliary files you might need, and
2542 @section Building true and false
2544 @cindex Example, @command{false} and @command{true}
2545 @cindex @command{false} Example
2546 @cindex @command{true} Example
2548 Here is another, trickier example. It shows how to generate two
2549 programs (@code{true} and @code{false}) from the same source file
2550 (@file{true.c}). The difficult part is that each compilation of
2551 @file{true.c} requires different @code{cpp} flags.
2554 bin_PROGRAMS = true false
2556 false_LDADD = false.o
2559 $(COMPILE) -DEXIT_CODE=0 -c true.c
2562 $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
2565 Note that there is no @code{true_SOURCES} definition. Automake will
2566 implicitly assume that there is a source file named @file{true.c}
2567 (@pxref{Default _SOURCES}), and
2568 define rules to compile @file{true.o} and link @file{true}. The
2569 @samp{true.o: true.c} rule supplied by the above @file{Makefile.am},
2570 will override the Automake generated rule to build @file{true.o}.
2572 @code{false_SOURCES} is defined to be empty---that way no implicit value
2573 is substituted. Because we have not listed the source of
2574 @file{false}, we have to tell Automake how to link the program. This is
2575 the purpose of the @code{false_LDADD} line. A @code{false_DEPENDENCIES}
2576 variable, holding the dependencies of the @file{false} target will be
2577 automatically generated by Automake from the content of
2580 The above rules won't work if your compiler doesn't accept both
2581 @option{-c} and @option{-o}. The simplest fix for this is to introduce a
2582 bogus dependency (to avoid problems with a parallel @command{make}):
2585 true.o: true.c false.o
2586 $(COMPILE) -DEXIT_CODE=0 -c true.c
2589 $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
2592 As it turns out, there is also a much easier way to do this same task.
2593 Some of the above technique is useful enough that we've kept the
2594 example in the manual. However if you were to build @code{true} and
2595 @code{false} in real life, you would probably use per-program
2596 compilation flags, like so:
2598 @c Keep in sync with specflg7.sh and specflg8.sh
2600 bin_PROGRAMS = false true
2602 false_SOURCES = true.c
2603 false_CPPFLAGS = -DEXIT_CODE=1
2605 true_SOURCES = true.c
2606 true_CPPFLAGS = -DEXIT_CODE=0
2609 In this case Automake will cause @file{true.c} to be compiled twice,
2610 with different flags. In this instance, the names of the object files
2611 would be chosen by automake; they would be @file{false-true.o} and
2612 @file{true-true.o}. (The name of the object files rarely matters.)
2614 @node automake Invocation
2615 @chapter Creating a @file{Makefile.in}
2616 @c This node used to be named "Invoking automake". This @anchor
2617 @c allows old links to still work.
2618 @anchor{Invoking automake}
2620 @cindex Multiple @file{configure.ac} files
2621 @cindex Invoking @command{automake}
2622 @cindex @command{automake}, invoking
2623 @cindex Invocation of @command{automake}
2624 @cindex @command{automake}, invocation
2626 To create all the @file{Makefile.in}s for a package, run the
2627 @command{automake} program in the top level directory, with no
2628 arguments. @command{automake} will automatically find each
2629 appropriate @file{Makefile.am} (by scanning @file{configure.ac};
2630 @pxref{configure}) and generate the corresponding @file{Makefile.in}.
2631 Note that @command{automake} has a rather simplistic view of what
2632 constitutes a package; it assumes that a package has only one
2633 @file{configure.ac}, at the top. If your package has multiple
2634 @file{configure.ac}s, then you must run @command{automake} in each
2635 directory holding a @file{configure.ac}. (Alternatively, you may rely
2636 on Autoconf's @command{autoreconf}, which is able to recurse your
2637 package tree and run @command{automake} where appropriate.)
2639 You can optionally give @command{automake} an argument; @file{.am} is
2640 appended to the argument and the result is used as the name of the
2641 input file. This feature is generally only used to automatically
2642 rebuild an out-of-date @file{Makefile.in}. Note that
2643 @command{automake} must always be run from the topmost directory of a
2644 project, even if being used to regenerate the @file{Makefile.in} in
2645 some subdirectory. This is necessary because @command{automake} must
2646 scan @file{configure.ac}, and because @command{automake} uses the
2647 knowledge that a @file{Makefile.in} is in a subdirectory to change its
2648 behavior in some cases.
2651 Automake will run @command{autoconf} to scan @file{configure.ac} and
2652 its dependencies (i.e., @file{aclocal.m4} and any included file),
2653 therefore @command{autoconf} must be in your @env{PATH}. If there is
2654 an @env{AUTOCONF} variable in your environment it will be used
2655 instead of @command{autoconf}; this allows you to select a particular
2656 version of Autoconf. By the way, don't misunderstand this paragraph:
2657 @command{automake} runs @command{autoconf} to @strong{scan} your
2658 @file{configure.ac}; this won't build @file{configure} and you still
2659 have to run @command{autoconf} yourself for this purpose.
2661 @cindex @command{automake} options
2662 @cindex Options, @command{automake}
2663 @cindex Strictness, command line
2665 @command{automake} accepts the following options:
2667 @cindex Extra files distributed with Automake
2668 @cindex Files distributed with Automake
2669 @cindex @file{config.guess}
2673 @itemx --add-missing
2675 @opindex --add-missing
2676 Automake requires certain common files to exist in certain situations;
2677 for instance, @file{config.guess} is required if @file{configure.ac} invokes
2678 @code{AC_CANONICAL_HOST}. Automake is distributed with several of these
2679 files (@pxref{Auxiliary Programs}); this option will cause the missing
2680 ones to be automatically added to the package, whenever possible. In
2681 general if Automake tells you a file is missing, try using this option.
2682 By default Automake tries to make a symbolic link pointing to its own
2683 copy of the missing file; this can be changed with @option{--copy}.
2685 Many of the potentially-missing files are common scripts whose
2686 location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
2687 Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
2688 file is considered missing, and where the missing file is added
2691 In some strictness modes, additional files are installed, see @ref{Gnits}
2692 for more information.
2694 @item --libdir=@var{dir}
2696 Look for Automake data files in directory @var{dir} instead of in the
2697 installation directory. This is typically used for debugging.
2699 @vindex AUTOMAKE_LIBDIR
2700 The environment variable @env{AUTOMAKE_LIBDIR} provides another way to
2701 set the directory containing Automake data files. The
2702 @option{--libdir} option takes precedence over it.
2704 @item --print-libdir
2705 @opindex --print-libdir
2706 Print the path of the installation directory containing Automake-provided
2707 scripts and data files (e.g., @file{texinfo.texi} and
2714 When used with @option{--add-missing}, causes installed files to be
2715 copied. The default is to make a symbolic link.
2719 @itemx --force-missing
2720 @opindex --force-missing
2721 When used with @option{--add-missing}, causes standard files to be reinstalled
2722 even if they already exist in the source tree. This involves removing
2723 the file from the source tree before creating the new symlink (or, with
2724 @option{--copy}, copying the new file).
2728 Set the global strictness to @option{foreign}. For more information, see
2733 Set the global strictness to @option{gnits}. For more information, see
2738 Set the global strictness to @option{gnu}. For more information, see
2739 @ref{Strictness}. This is the default strictness.
2743 Print a summary of the command line options and exit.
2746 @itemx --ignore-deps
2748 This disables the dependency tracking feature in generated
2749 @file{Makefile}s; see @ref{Dependencies}.
2751 @item --include-deps
2752 @opindex --include-deps
2753 This enables the dependency tracking feature. This feature is enabled
2754 by default. This option is provided for historical reasons only and
2755 probably should not be used.
2759 Ordinarily @command{automake} creates all @file{Makefile.in}s mentioned in
2760 @file{configure.ac}. This option causes it to only update those
2761 @file{Makefile.in}s that are out of date with respect to one of their
2765 @itemx --output-dir=@var{dir}
2767 @opindex --output-dir
2768 Put the generated @file{Makefile.in} in the directory @var{dir}.
2769 Ordinarily each @file{Makefile.in} is created in the directory of the
2770 corresponding @file{Makefile.am}. This option is deprecated and will be
2771 removed in a future release.
2777 Cause Automake to print information about which files are being read or
2782 Print the version number of Automake and exit.
2784 @item -W @var{category}[,@var{category}...]
2785 @itemx --warnings=@var{category}[,@var{category}...]
2788 Output warnings about a @var{category} of potential problems with the
2789 package. @var{category} can be any of:
2793 Constructs compromising the ability to cross-compile the package.
2795 Minor deviations from the GNU Coding Standards
2796 (@pxref{Top, , , standards, The GNU Coding Standards}).
2798 Obsolete features or constructions.
2800 Redefinitions of Automake rules or variables.
2802 Portability issues (e.g., use of @command{make} features that are
2803 known to be not portable).
2804 @item portability-recursive
2805 Recursive, or nested, Make variable expansions (@code{$(foo$(x))}).
2806 These are not universally supported, but are more portable than the
2807 other non-portable constructs diagnosed by @option{-Wportability}.
2808 These warnings are turned on by @option{-Wportability} but can then be
2809 turned off specifically by @option{-Wno-portability-recursive}.
2810 @item extra-portability
2811 Extra portability issues, related to rarely-used tools such as
2812 the Microsoft @command{lib} archiver.
2814 Questionable syntax, unused variables, typos, etc.
2816 Unsupported or incomplete features.
2818 Turn on all the above categories of warnings.
2820 Turn off all the above categories of warnings.
2822 Treat warnings as errors.
2825 A category can be turned off by prefixing its name with @samp{no-}. For
2826 instance, @option{-Wno-syntax} will hide the warnings about unused
2829 Warnings in the @samp{gnu}, @samp{obsolete}, @samp{portability},
2830 @samp{syntax}, and @samp{unsupported} categories are turned on by
2831 default. The @samp{gnu} and @samp{portability} categories are turned
2832 off in @option{--foreign} strictness.
2834 @c Checked by extra-portability.sh
2835 Turning off @samp{portability} will also turn off @samp{extra-portability},
2836 and similarly turning on @samp{extra-portability} will also turn on
2837 @samp{portability}. However, turning on @samp{portability} or turning
2838 off @samp{extra-portability} will not affect the other category.
2840 Unknown warning categories supplied as an argument to @option{-W} will
2841 themselves produce a warning, in the @samp{unsupported} category. This
2842 warning is never treated as an error.
2845 The environment variable @env{WARNINGS} can contain a comma separated
2846 list of categories to enable. @option{-W} settings on the command line
2847 take precedence; for instance, @option{-Wnone} also turns off any
2848 warning categories enabled by @env{WARNINGS}.
2850 Unknown warning categories named in @env{WARNINGS} are silently ignored.
2854 @vindex AUTOMAKE_JOBS
2855 If the environment variable @env{AUTOMAKE_JOBS} contains a positive
2856 number, it is taken as the maximum number of Perl threads to use in
2857 @command{automake} for generating multiple @file{Makefile.in} files
2858 concurrently. This is an experimental feature.
2862 @chapter Scanning @file{configure.ac}, using @command{aclocal}
2864 @cindex @file{configure.ac}, scanning
2865 @cindex Scanning @file{configure.ac}
2866 @cindex Using @command{aclocal}
2867 @cindex @command{aclocal}, using
2869 Automake scans the package's @file{configure.ac} to determine certain
2870 information about the package. Some @command{autoconf} macros are required
2871 and some variables must be defined in @file{configure.ac}. Automake
2872 will also use information from @file{configure.ac} to further tailor its
2875 Automake also supplies some Autoconf macros to make the maintenance
2876 easier. These macros can automatically be put into your
2877 @file{aclocal.m4} using the @command{aclocal} program.
2880 * Requirements:: Configuration requirements
2881 * Optional:: Other things Automake recognizes
2882 * aclocal Invocation:: Auto-generating aclocal.m4
2883 * Macros:: Autoconf macros supplied with Automake
2888 @section Configuration requirements
2890 @cindex Automake requirements
2891 @cindex Requirements of Automake
2893 @acindex AM_INIT_AUTOMAKE
2894 The one real requirement of Automake is that your @file{configure.ac}
2895 call @code{AM_INIT_AUTOMAKE}. This macro does several things that are
2896 required for proper Automake operation (@pxref{Macros}).
2898 Here are the other macros that Automake requires but which are not run
2899 by @code{AM_INIT_AUTOMAKE}:
2902 @item AC_CONFIG_FILES
2904 @acindex AC_CONFIG_FILES
2906 These two macros are usually invoked as follows near the end of
2907 @file{configure.ac}.
2921 Automake uses these to determine which files to create (@pxref{Output, ,
2922 Creating Output Files, autoconf, The Autoconf Manual}). A listed file
2923 is considered to be an Automake generated @file{Makefile} if there
2924 exists a file with the same name and the @file{.am} extension appended.
2925 Typically, @samp{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
2926 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
2928 When using @code{AC_CONFIG_FILES} with multiple input files, as in
2931 AC_CONFIG_FILES([Makefile:top.in:Makefile.in:bot.in])
2935 @command{automake} will generate the first @file{.in} input file for
2936 which a @file{.am} file exists. If no such file exists the output
2937 file is not considered to be generated by Automake.
2939 Files created by @code{AC_CONFIG_FILES}, be they Automake
2940 @file{Makefile}s or not, are all removed by @samp{make distclean}.
2941 Their inputs are automatically distributed, unless they
2942 are the output of prior @code{AC_CONFIG_FILES} commands.
2943 Finally, rebuild rules are generated in the Automake @file{Makefile}
2944 existing in the subdirectory of the output file, if there is one, or
2945 in the top-level @file{Makefile} otherwise.
2947 The above machinery (cleaning, distributing, and rebuilding) works
2948 fine if the @code{AC_CONFIG_FILES} specifications contain only
2949 literals. If part of the specification uses shell variables,
2950 @command{automake} will not be able to fulfill this setup, and you will
2951 have to complete the missing bits by hand. For instance, on
2953 @c Keep in sync with output11.sh
2957 AC_CONFIG_FILES([output:$file],, [file=$file])
2961 @command{automake} will output rules to clean @file{output}, and
2962 rebuild it. However the rebuild rule will not depend on @file{input},
2963 and this file will not be distributed either. (You must add
2964 @samp{EXTRA_DIST = input} to your @file{Makefile.am} if @file{input} is a
2969 @c Keep in sync with output11.sh
2974 AC_CONFIG_FILES([$file:input],, [file=$file])
2975 AC_CONFIG_FILES([$file2],, [file2=$file2])
2979 will only cause @file{input} to be distributed. No file will be
2980 cleaned automatically (add @samp{DISTCLEANFILES = output out}
2981 yourself), and no rebuild rule will be output.
2983 Obviously @command{automake} cannot guess what value @samp{$file} is
2984 going to hold later when @file{configure} is run, and it cannot use
2985 the shell variable @samp{$file} in a @file{Makefile}. However, if you
2986 make reference to @samp{$file} as @samp{$@{file@}} (i.e., in a way
2987 that is compatible with @command{make}'s syntax) and furthermore use
2988 @code{AC_SUBST} to ensure that @samp{$@{file@}} is meaningful in a
2989 @file{Makefile}, then @command{automake} will be able to use
2990 @samp{$@{file@}} to generate all of these rules. For instance, here is
2991 how the Automake package itself generates versioned scripts for its
2995 AC_SUBST([APIVERSION], @dots{})
2998 [tests/aclocal-$@{APIVERSION@}:tests/aclocal.in],
2999 [chmod +x tests/aclocal-$@{APIVERSION@}],
3000 [APIVERSION=$APIVERSION])
3002 [tests/automake-$@{APIVERSION@}:tests/automake.in],
3003 [chmod +x tests/automake-$@{APIVERSION@}])
3007 Here cleaning, distributing, and rebuilding are done automatically,
3008 because @samp{$@{APIVERSION@}} is known at @command{make}-time.
3010 Note that you should not use shell variables to declare
3011 @file{Makefile} files for which @command{automake} must create
3012 @file{Makefile.in}. Even @code{AC_SUBST} does not help here, because
3013 @command{automake} needs to know the file name when it runs in order
3014 to check whether @file{Makefile.am} exists. (In the very hairy case
3015 that your setup requires such use of variables, you will have to tell
3016 Automake which @file{Makefile.in}s to generate on the command-line.)
3018 It is possible to let @command{automake} emit conditional rules for
3019 @code{AC_CONFIG_FILES} with the help of @code{AM_COND_IF}
3025 Use literals for @file{Makefile}s, and for other files whenever possible.
3027 Use @samp{$file} (or @samp{$@{file@}} without @samp{AC_SUBST([file])})
3028 for files that @command{automake} should ignore.
3030 Use @samp{$@{file@}} and @samp{AC_SUBST([file])} for files
3031 that @command{automake} should not ignore.
3038 @section Other things Automake recognizes
3040 @cindex Macros Automake recognizes
3041 @cindex Recognized macros by Automake
3043 Every time Automake is run it calls Autoconf to trace
3044 @file{configure.ac}. This way it can recognize the use of certain
3045 macros and tailor the generated @file{Makefile.in} appropriately.
3046 Currently recognized macros and their effects are:
3049 @item AC_CANONICAL_BUILD
3050 @itemx AC_CANONICAL_HOST
3051 @itemx AC_CANONICAL_TARGET
3052 @vindex build_triplet
3053 @vindex host_triplet
3054 @vindex target_triplet
3055 Automake will ensure that @file{config.guess} and @file{config.sub}
3056 exist. Also, the @file{Makefile} variables @code{build_triplet},
3057 @code{host_triplet} and @code{target_triplet} are introduced. See
3058 @ref{Canonicalizing, , Getting the Canonical System Type, autoconf,
3059 The Autoconf Manual}.
3061 @item AC_CONFIG_AUX_DIR
3062 Automake will look for various helper scripts, such as
3063 @file{install-sh}, in the directory named in this macro invocation.
3064 @c This list is accurate relative to version 1.11
3065 (The full list of scripts is:
3067 @file{config.guess},
3075 @file{mkinstalldirs},
3080 Not all scripts are always searched for; some scripts
3081 will only be sought if the generated @file{Makefile.in} requires them.
3083 If @code{AC_CONFIG_AUX_DIR} is used, it must be given before the call
3084 to @code{AM_INIT_AUTOMAKE}; Automake will warn about this if it is not
3085 so. All other @code{AC_CONFIG_...} macros are conventionally called
3086 after @code{AM_INIT_AUTOMAKE}, though they may or may not work in
3087 other locations, with or without warnings.
3089 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
3090 their standard locations. For @file{mdate-sh},
3091 @file{texinfo.tex}, and @file{ylwrap}, the standard location is the
3092 source directory corresponding to the current @file{Makefile.am}. For
3093 the rest, the standard location is the first one of @file{.}, @file{..},
3094 or @file{../..} (relative to the top source directory) that provides any
3095 one of the helper scripts. @xref{Input, , Finding `configure' Input,
3096 autoconf, The Autoconf Manual}.
3098 Required files from @code{AC_CONFIG_AUX_DIR} are automatically
3099 distributed, even if there is no @file{Makefile.am} in this directory.
3101 @item AC_CONFIG_LIBOBJ_DIR
3102 Automake will require the sources file declared with
3103 @code{AC_LIBSOURCE} (see below) in the directory specified by this
3106 @item AC_CONFIG_HEADERS
3107 Automake will generate rules to rebuild these headers from the
3108 corresponding templates (usually, the template for a @file{foo.h}
3109 header being @file{foo.h.in}).
3111 As with @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
3112 specification using shell variables will be ignored as far as
3113 cleaning, distributing, and rebuilding is concerned.
3115 Older versions of Automake required the use of
3116 @code{AM_CONFIG_HEADER}; this is no longer the case, and that macro
3117 has indeed been removed.
3119 @item AC_CONFIG_LINKS
3120 Automake will generate rules to remove @file{configure} generated
3121 links on @samp{make distclean} and to distribute named source files as
3122 part of @samp{make dist}.
3124 As with @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
3125 specification using shell variables will be ignored as far as cleaning
3126 and distributing is concerned. (There are no rebuild rules for links.)
3130 @itemx AC_LIBSOURCES
3132 Automake will automatically distribute any file listed in
3133 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
3135 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}. So if
3136 an Autoconf macro is documented to call @samp{AC_LIBOBJ([file])}, then
3137 @file{file.c} will be distributed automatically by Automake. This
3138 encompasses many macros like @code{AC_FUNC_ALLOCA},
3139 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
3141 By the way, direct assignments to @code{LIBOBJS} are no longer
3142 supported. You should always use @code{AC_LIBOBJ} for this purpose.
3143 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
3144 autoconf, The Autoconf Manual}.
3146 @item AC_PROG_RANLIB
3147 This is required if any libraries are built in the package.
3148 @xref{Particular Programs, , Particular Program Checks, autoconf, The
3152 This is required if any C++ source is included. @xref{Particular
3153 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3156 This is required if any Objective C source is included. @xref{Particular
3157 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3159 @item AC_PROG_OBJCXX
3160 This is required if any Objective C++ source is included. @xref{Particular
3161 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3164 This is required if any Fortran 77 source is included. @xref{Particular
3165 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3167 @item AC_F77_LIBRARY_LDFLAGS
3168 This is required for programs and shared libraries that are a mixture of
3169 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
3170 C++}). @xref{Macros, , Autoconf macros supplied with Automake}.
3173 Automake will add the flags computed by @code{AC_FC_SRCEXT} to compilation
3174 of files with the respective source extension (@pxref{Fortran Compiler, ,
3175 Fortran Compiler Characteristics, autoconf, The Autoconf Manual}).
3178 This is required if any Fortran 90/95 source is included. This macro is
3179 distributed with Autoconf version 2.58 and later. @xref{Particular
3180 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3182 @item AC_PROG_LIBTOOL
3184 Automake will turn on processing for @command{libtool} (@pxref{Top, ,
3185 Introduction, libtool, The Libtool Manual}).
3189 If a Yacc source file is seen, then you must either use this macro or
3190 define the variable @code{YACC} in @file{configure.ac}. The former is
3191 preferred (@pxref{Particular Programs, , Particular Program Checks,
3192 autoconf, The Autoconf Manual}).
3195 If a Lex source file is seen, then this macro must be used.
3196 @xref{Particular Programs, , Particular Program Checks, autoconf, The
3199 @item AC_REQUIRE_AUX_FILE
3200 For each @code{AC_REQUIRE_AUX_FILE([@var{file}])},
3201 @command{automake} will ensure that @file{@var{file}} exists in the
3202 aux directory, and will complain otherwise. It
3203 will also automatically distribute the file. This macro should be
3204 used by third-party Autoconf macros that require some supporting
3205 files in the aux directory specified with @code{AC_CONFIG_AUX_DIR}
3206 above. @xref{Input, , Finding @command{configure} Input, autoconf,
3207 The Autoconf Manual}.
3210 The first argument is automatically defined as a variable in each
3211 generated @file{Makefile.in}, unless @code{AM_SUBST_NOTMAKE} is also
3212 used for this variable. @xref{Setting Output Variables, , Setting
3213 Output Variables, autoconf, The Autoconf Manual}.
3215 For every substituted variable @var{var}, @command{automake} will add
3216 a line @code{@var{var} = @var{value}} to each @file{Makefile.in} file.
3217 Many Autoconf macros invoke @code{AC_SUBST} to set output variables
3218 this way, e.g., @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and
3219 @code{X_LIBS}. Thus, you can access these variables as
3220 @code{$(X_CFLAGS)} and @code{$(X_LIBS)} in any @file{Makefile.am}
3221 if @code{AC_PATH_XTRA} is called.
3223 @item AM_CONDITIONAL
3224 This introduces an Automake conditional (@pxref{Conditionals}).
3227 This macro allows @code{automake} to detect subsequent access within
3228 @file{configure.ac} to a conditional previously introduced with
3229 @code{AM_CONDITIONAL}, thus enabling conditional @code{AC_CONFIG_FILES}
3230 (@pxref{Usage of Conditionals}).
3232 @item AM_GNU_GETTEXT
3233 This macro is required for packages that use GNU gettext
3234 (@pxref{gettext}). It is distributed with gettext. If Automake sees
3235 this macro it ensures that the package meets some of gettext's
3238 @item AM_GNU_GETTEXT_INTL_SUBDIR
3239 This macro specifies that the @file{intl/} subdirectory is to be built,
3240 even if the @code{AM_GNU_GETTEXT} macro was invoked with a first argument
3243 @item AM_MAINTAINER_MODE(@ovar{default-mode})
3244 @opindex --enable-maintainer-mode
3245 @opindex --disable-maintainer-mode
3246 This macro adds an @option{--enable-maintainer-mode} option to
3247 @command{configure}. If this is used, @command{automake} will cause
3248 ``maintainer-only'' rules to be turned off by default in the
3249 generated @file{Makefile.in}s, unless @var{default-mode} is
3250 @samp{enable}. This macro defines the @code{MAINTAINER_MODE}
3251 conditional, which you can use in your own @file{Makefile.am}.
3252 @xref{maintainer-mode}.
3254 @item AM_SUBST_NOTMAKE(@var{var})
3255 Prevent Automake from defining a variable @var{var}, even if it is
3256 substituted by @command{config.status}. Normally, Automake defines a
3257 @command{make} variable for each @command{configure} substitution,
3258 i.e., for each @code{AC_SUBST([@var{var}])}. This macro prevents that
3259 definition from Automake. If @code{AC_SUBST} has not been called
3260 for this variable, then @code{AM_SUBST_NOTMAKE} has no effects.
3261 Preventing variable definitions may be useful for substitution of
3262 multi-line values, where @code{@var{var} = @@@var{value}@@} might yield
3266 Files included by @file{configure.ac} using this macro will be
3267 detected by Automake and automatically distributed. They will also
3268 appear as dependencies in @file{Makefile} rules.
3270 @code{m4_include} is seldom used by @file{configure.ac} authors, but
3271 can appear in @file{aclocal.m4} when @command{aclocal} detects that
3272 some required macros come from files local to your package (as opposed to
3273 macros installed in a system-wide directory; @pxref{aclocal Invocation}).
3277 @node aclocal Invocation
3278 @section Auto-generating aclocal.m4
3279 @c This node used to be named "Invoking aclocal". This @anchor
3280 @c allows old links to still work.
3281 @anchor{Invoking aclocal}
3283 @cindex Invocation of @command{aclocal}
3284 @cindex @command{aclocal}, Invocation
3285 @cindex Invoking @command{aclocal}
3286 @cindex @command{aclocal}, Invoking
3288 Automake includes a number of Autoconf macros that can be used in your
3289 package (@pxref{Macros}); some of them are required by Automake in
3290 certain situations. These macros must be defined in your
3291 @file{aclocal.m4}; otherwise they will not be seen by
3294 The @command{aclocal} program will automatically generate
3295 @file{aclocal.m4} files based on the contents of @file{configure.ac}.
3296 This provides a convenient way to get Automake-provided macros,
3297 without having to search around. The @command{aclocal} mechanism
3298 allows other packages to supply their own macros (@pxref{Extending
3299 aclocal}). You can also use it to maintain your own set of custom
3300 macros (@pxref{Local Macros}).
3302 At startup, @command{aclocal} scans all the @file{.m4} files it can
3303 find, looking for macro definitions (@pxref{Macro Search Path}). Then
3304 it scans @file{configure.ac}. Any mention of one of the macros found
3305 in the first step causes that macro, and any macros it in turn
3306 requires, to be put into @file{aclocal.m4}.
3308 @emph{Putting} the file that contains the macro definition into
3309 @file{aclocal.m4} is usually done by copying the entire text of this
3310 file, including unused macro definitions as well as both @samp{#} and
3311 @samp{dnl} comments. If you want to make a comment that will be
3312 completely ignored by @command{aclocal}, use @samp{##} as the comment
3315 When a file selected by @command{aclocal} is located in a subdirectory
3316 specified as a relative search path with @command{aclocal}'s @option{-I}
3317 argument, @command{aclocal} assumes the file belongs to the package
3318 and uses @code{m4_include} instead of copying it into
3319 @file{aclocal.m4}. This makes the package smaller, eases dependency
3320 tracking, and cause the file to be distributed automatically.
3321 (@xref{Local Macros}, for an example.) Any macro that is found in a
3322 system-wide directory or via an absolute search path will be copied.
3323 So use @samp{-I `pwd`/reldir} instead of @samp{-I reldir} whenever
3324 some relative directory should be considered outside the package.
3326 The contents of @file{acinclude.m4}, if this file exists, are also
3327 automatically included in @file{aclocal.m4}. We recommend against
3328 using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
3332 While computing @file{aclocal.m4}, @command{aclocal} runs
3333 @command{autom4te} (@pxref{Using autom4te, , Using @command{Autom4te},
3334 autoconf, The Autoconf Manual}) in order to trace the macros that are
3335 used, and omit from @file{aclocal.m4} all macros that are mentioned
3336 but otherwise unexpanded (this can happen when a macro is called
3337 conditionally). @command{autom4te} is expected to be in the
3338 @env{PATH}, just like @command{autoconf}. Its location can be
3339 overridden using the @env{AUTOM4TE} environment variable.
3341 Although this section explains the details of @command{aclocal}, in
3342 practice it is usually simpler to run @command{autoreconf}, instead of
3343 worrying about the required order of the various tools
3344 (@pxref{autoreconf Invocation, , Using @command{autoreconf},
3345 autoconf, The Autoconf Manual}).
3348 * aclocal Options:: Options supported by aclocal
3349 * Macro Search Path:: How aclocal finds .m4 files
3350 * Extending aclocal:: Writing your own aclocal macros
3351 * Local Macros:: Organizing local macros
3352 * Serials:: Serial lines in Autoconf macros
3353 * Future of aclocal:: aclocal's scheduled death
3356 @node aclocal Options
3357 @subsection aclocal Options
3359 @cindex @command{aclocal}, Options
3360 @cindex Options, @command{aclocal}
3362 @command{aclocal} accepts the following options:
3365 @item --automake-acdir=@var{dir}
3366 @opindex --automake-acdir
3367 Look for the automake-provided macro files in @var{dir} instead of
3368 in the installation directory. This is typically used for debugging.
3370 @vindex ACLOCAL_AUTOMAKE_DIR
3371 The environment variable @env{ACLOCAL_AUTOMAKE_DIR} provides another
3372 way to set the directory containing automake-provided macro files.
3373 However @option{--automake-acdir} takes precedence over it.
3375 @item --aclocal-path=@var{path}
3376 @opindex --aclocal-path
3377 Look for local third-party macro files (and the special @file{dirlist}
3378 file, @pxref{dirlist}) along @var{path} (a colon-separated list of
3379 directories) instead of in the installation directory. (This can be
3380 used for building against alternative system roots (``sysroots'') for
3381 finding headers and libraries.)
3383 @vindex ACLOCAL_PATH
3384 The environment variable @env{ACLOCAL_PATH} provides another way to
3385 set the search path containing local third-party macro files. This
3386 variable is ignored if the @option{--aclocal-path} option is specified.
3388 @item --system-acdir=@var{dir}
3389 @opindex --system-acdir
3390 Look for the system-wide third-party macro files (and the special
3391 @file{dirlist} file) in @var{dir} instead of in the installation
3392 directory. This is typically used for debugging.
3394 @item --diff[=@var{command}]
3396 Run @var{command} on the M4 file that would be installed or overwritten
3397 by @option{--install}. The default @var{command} is @samp{diff -u}.
3398 This option implies @option{--install} and @option{--dry-run}.
3402 Do not overwrite (or create) @file{aclocal.m4} and M4 files installed
3403 by @option{--install}.
3407 Print a summary of the command line options and exit.
3411 Add the directory @var{dir} to the list of directories searched for
3416 Install system-wide third-party macros into the first directory
3417 specified with @samp{-I @var{dir}} instead of copying them in the
3419 @c Keep in sync with aclocal-install-absdir.sh
3420 Note that this will happen also if @var{dir} is an absolute path.
3422 @cindex serial number and @option{--install}
3423 When this option is used, and only when this option is used,
3424 @command{aclocal} will also honor @samp{#serial @var{number}} lines
3425 that appear in macros: an M4 file is ignored if there exists another
3426 M4 file with the same basename and a greater serial number in the
3427 search path (@pxref{Serials}).
3431 Always overwrite the output file. The default is to overwrite the
3432 output file only when needed, i.e., when its contents change or if one
3433 of its dependencies is younger.
3435 This option forces the update of @file{aclocal.m4} (or the file
3436 specified with @file{--output} below) and only this file, it has
3437 absolutely no influence on files that may need to be installed by
3440 @item --output=@var{file}
3442 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
3444 @item --print-ac-dir
3445 @opindex --print-ac-dir
3446 Prints the name of the directory that @command{aclocal} will search to
3447 find third-party @file{.m4} files. When this option is given, normal
3448 processing is suppressed. This option was used @emph{in the past} by
3449 third-party packages to determine where to install @file{.m4} macro
3450 files, but @emph{this usage is today discouraged}, since it causes
3451 @samp{$(prefix)} not to be thoroughly honored (which violates the
3452 GNU Coding Standards), and similar semantics can be better obtained
3453 with the @env{ACLOCAL_PATH} environment variable; @pxref{Extending aclocal}.
3457 Print the names of the files it examines.
3461 Print the version number of Automake and exit.
3464 @item --warnings=@var{category}
3467 Output warnings falling in @var{category}. @var{category} can be
3471 dubious syntactic constructs, underquoted macros, unused macros, etc.
3475 all the warnings, this is the default
3477 turn off all the warnings
3479 treat warnings as errors
3482 All warnings are output by default.
3485 The environment variable @env{WARNINGS} is honored in the same
3486 way as it is for @command{automake} (@pxref{automake Invocation}).
3490 @node Macro Search Path
3491 @subsection Macro Search Path
3493 @cindex Macro search path
3494 @cindex @command{aclocal} search path
3496 By default, @command{aclocal} searches for @file{.m4} files in the following
3497 directories, in this order:
3500 @item @var{acdir-APIVERSION}
3501 This is where the @file{.m4} macros distributed with Automake itself
3502 are stored. @var{APIVERSION} depends on the Automake release used;
3503 for example, for Automake 1.11.x, @var{APIVERSION} = @code{1.11}.
3506 This directory is intended for third party @file{.m4} files, and is
3507 configured when @command{automake} itself is built. This is
3508 @file{@@datadir@@/aclocal/}, which typically
3509 expands to @file{$@{prefix@}/share/aclocal/}. To find the compiled-in
3510 value of @var{acdir}, use the @option{--print-ac-dir} option
3511 (@pxref{aclocal Options}).
3514 As an example, suppose that @command{automake-1.11.2} was configured with
3515 @option{--prefix=@-/usr/local}. Then, the search path would be:
3518 @item @file{/usr/local/share/aclocal-1.11.2/}
3519 @item @file{/usr/local/share/aclocal/}
3522 The paths for the @var{acdir} and @var{acdir-APIVERSION} directories can
3523 be changed respectively through aclocal options @option{--system-acdir}
3524 and @option{--automake-acdir} (@pxref{aclocal Options}). Note however
3525 that these options are only intended for use by the internal Automake
3526 test suite, or for debugging under highly unusual situations; they are
3527 not ordinarily needed by end-users.
3529 As explained in (@pxref{aclocal Options}), there are several options that
3530 can be used to change or extend this search path.
3532 @subsubheading Modifying the Macro Search Path: @samp{-I @var{dir}}
3534 Any extra directories specified using @option{-I} options
3535 (@pxref{aclocal Options}) are @emph{prepended} to this search list. Thus,
3536 @samp{aclocal -I /foo -I /bar} results in the following search path:
3541 @item @var{acdir}-@var{APIVERSION}
3546 @subsubheading Modifying the Macro Search Path: @file{dirlist}
3547 @cindex @file{dirlist}
3549 There is a third mechanism for customizing the search path. If a
3550 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
3551 contain a list of directory patterns, one per line. @command{aclocal}
3552 expands these patterns to directory names, and adds them to the search
3553 list @emph{after} all other directories. @file{dirlist} entries may
3554 use shell wildcards such as @samp{*}, @samp{?}, or @code{[...]}.
3556 For example, suppose
3557 @file{@var{acdir}/dirlist} contains the following:
3566 and that @command{aclocal} was called with the @samp{-I /foo -I /bar} options.
3567 Then, the search path would be
3569 @c @code looks better than @file here
3573 @item @var{acdir}-@var{APIVERSION}
3580 and all directories with path names starting with @code{/test3}.
3582 If the @option{--system-acdir=@var{dir}} option is used, then
3583 @command{aclocal} will search for the @file{dirlist} file in
3584 @var{dir}; but remember the warnings above against the use of
3585 @option{--system-acdir}.
3587 @file{dirlist} is useful in the following situation: suppose that
3588 @command{automake} version @code{1.11.2} is installed with
3589 @samp{--prefix=/usr} by the system vendor. Thus, the default search
3592 @c @code looks better than @file here
3594 @item @code{/usr/share/aclocal-1.11/}
3595 @item @code{/usr/share/aclocal/}
3598 However, suppose further that many packages have been manually
3599 installed on the system, with $prefix=/usr/local, as is typical. In
3600 that case, many of these ``extra'' @file{.m4} files are in
3601 @file{/usr/local/share/aclocal}. The only way to force
3602 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files is to
3603 always call @samp{aclocal -I /usr/local/share/aclocal}. This is
3604 inconvenient. With @file{dirlist}, one may create a file
3605 @file{/usr/share/aclocal/dirlist} containing only the single line
3608 /usr/local/share/aclocal
3611 Now, the ``default'' search path on the affected system is
3613 @c @code looks better than @file here
3615 @item @code{/usr/share/aclocal-1.11/}
3616 @item @code{/usr/share/aclocal/}
3617 @item @code{/usr/local/share/aclocal/}
3621 without the need for @option{-I} options; @option{-I} options can be reserved
3622 for project-specific needs (@file{my-source-dir/m4/}), rather than
3623 using them to work around local system-dependent tool installation
3626 Similarly, @file{dirlist} can be handy if you have installed a local
3627 copy of Automake in your account and want @command{aclocal} to look for
3628 macros installed at other places on the system.
3630 @anchor{ACLOCAL_PATH}
3631 @subsubheading Modifying the Macro Search Path: @option{--aclocal-path}/@file{ACLOCAL_PATH}
3632 @opindex @option{--aclocal-path}
3633 @cindex @env{ACLOCAL_PATH}
3635 The fourth and last mechanism to customize the macro search path is
3636 also the simplest. Any directory included in the colon-separated path
3637 given to the @option{--aclocal-path} command-line option or in the
3638 @env{ACLOCAL_PATH} environment variable is added to the search path.
3639 @c Keep in sync with aclocal-path-precedence.sh
3640 These directories take precedence over system directories (including
3641 those found via @file{dirlist}), with the exception of the versioned
3642 directory @var{acdir-APIVERSION} (@pxref{Macro Search Path}).
3643 However, directories passed via @option{-I} will take precedence over
3644 directories in @option{--aclocal-path}/@env{ACLOCAL_PATH}.
3646 @c Keep in sync with aclocal-path-install.sh
3647 If the @option{--install} option is used, any @file{.m4} file
3648 containing a required macro that is found in a directory listed in
3649 @option{--aclocal-path}/@env{ACLOCAL_PATH} will be installed locally.
3650 @c Keep in sync with aclocal-path-install-serial.sh
3651 In this case, serial numbers in @file{.m4} are honored too
3654 Conversely to @file{dirlist},
3655 @option{--aclocal-path}/@env{ACLOCAL_PATH} is useful if you are using
3656 a global copy of Automake and want @command{aclocal} to look for
3657 macros somewhere under your home directory.
3659 @subsubheading Possible future incompatibility
3661 The order in which the directories in the macro search path are
3662 currently looked up is confusing and/or suboptimal in various aspects.
3663 In particular, directories in
3664 @option{--aclocal-path}/@env{ACLOCAL_PATH} and @file{@var{acdir}}
3665 might end up taking precedence over @file{@var{acdir-APIVERSION}}, and
3666 directories in @file{@var{acdir}/dirlist} might end up taking
3667 precedence over @file{@var{acdir}}. Although there are no plans to
3668 change the current behavior, if it causes problems, the default might
3669 need to be changed, and the current behavior retained as an
3672 @node Extending aclocal
3673 @subsection Writing your own aclocal macros
3675 @cindex @command{aclocal}, extending
3676 @cindex Extending @command{aclocal}
3678 The @command{aclocal} program doesn't have any built-in knowledge of any
3679 macros, so it is easy to extend it with your own macros.
3681 This can be used by libraries that want to supply their own Autoconf
3682 macros for use by other programs. For instance, the @command{gettext}
3683 library supplies a macro @code{AM_GNU_GETTEXT} that should be used by
3684 any package using @command{gettext}. When the library is installed, it
3685 installs this macro so that @command{aclocal} will find it.
3687 A macro file's name should end in @file{.m4}. Such files should be
3688 installed in @file{$(datadir)/aclocal}. This is as simple as writing:
3690 @c Keep in sync with primary-prefix-couples-documented-valid.sh
3692 aclocaldir = $(datadir)/aclocal
3693 aclocal_DATA = mymacro.m4 myothermacro.m4
3697 Please do use @file{$(datadir)/aclocal}, and not something based on
3698 the result of @samp{aclocal --print-ac-dir} (@pxref{Hard-Coded Install
3699 Paths}, for arguments). It might also be helpful to suggest to
3700 the user to add the @file{$(datadir)/aclocal} directory to his
3701 @env{ACLOCAL_PATH} variable (@pxref{ACLOCAL_PATH}) so that
3702 @command{aclocal} will find the @file{.m4} files installed by your
3703 package automatically.
3705 A file of macros should be a series of properly quoted
3706 @code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
3707 Autoconf Manual}). The @command{aclocal} programs also understands
3708 @code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
3709 Autoconf Manual}), so it is safe to put each macro in a separate file.
3710 Each file should have no side effects but macro definitions.
3711 Especially, any call to @code{AC_PREREQ} should be done inside the
3712 defined macro, not at the beginning of the file.
3714 @cindex underquoted @code{AC_DEFUN}
3718 Starting with Automake 1.8, @command{aclocal} warns about all
3719 underquoted calls to @code{AC_DEFUN}. We realize this annoys some
3720 people, because @command{aclocal} was not so strict in the past and
3721 many third party macros are underquoted; and we have to apologize for
3722 this temporary inconvenience. The reason we have to be stricter is
3723 that a future implementation of @command{aclocal} (@pxref{Future of
3724 aclocal}) will have to temporarily include all of these third party
3725 @file{.m4} files, maybe several times, even including files that end
3726 up not being needed. Doing so should alleviate many problems of the
3727 current implementation; however, it requires a stricter style from
3728 macro authors. Hopefully it is easy to revise the existing macros.
3735 [AC_REQUIRE([AX_SOMETHING])dnl
3742 should be rewritten as
3745 AC_DEFUN([AX_FOOBAR],
3746 [AC_PREREQ([2.68])dnl
3747 AC_REQUIRE([AX_SOMETHING])dnl
3753 Wrapping the @code{AC_PREREQ} call inside the macro ensures that
3754 Autoconf 2.68 will not be required if @code{AX_FOOBAR} is not used.
3755 Most importantly, quoting the first argument of @code{AC_DEFUN} allows
3756 the macro to be redefined or included twice (otherwise this first
3757 argument would be expanded during the second definition). For
3758 consistency we like to quote even arguments such as @code{2.68} that
3761 If you have been directed here by the @command{aclocal} diagnostic but
3762 are not the maintainer of the implicated macro, you will want to
3763 contact the maintainer of that macro. Please make sure you have the
3764 latest version of the macro and that the problem hasn't already been
3765 reported before doing so: people tend to work faster when they aren't
3768 Another situation where @command{aclocal} is commonly used is to
3769 manage macros that are used locally by the package; @ref{Local
3773 @subsection Handling Local Macros
3775 Feature tests offered by Autoconf do not cover all needs. People
3776 often have to supplement existing tests with their own macros, or
3777 with third-party macros.
3779 There are two ways to organize custom macros in a package.
3781 The first possibility (the historical practice) is to list all your
3782 macros in @file{acinclude.m4}. This file will be included in
3783 @file{aclocal.m4} when you run @command{aclocal}, and its macro(s) will
3784 henceforth be visible to @command{autoconf}. However, if it contains
3785 numerous macros, it will rapidly become difficult to maintain, and it
3786 will be almost impossible to share macros between packages.
3788 The second possibility, which we do recommend, is to write each macro
3789 in its own file and gather all these files in a directory. This
3790 directory is usually called @file{m4/}. Then it's enough to update
3791 @file{configure.ac} by adding a proper call to @code{AC_CONFIG_MACRO_DIRS}:
3794 AC_CONFIG_MACRO_DIRS([m4])
3797 @command{aclocal} will then take care of automatically adding @file{m4/}
3798 to its search path for m4 files.
3800 When @samp{aclocal} is run, it will build an @file{aclocal.m4}
3801 that @code{m4_include}s any file from @file{m4/} that defines a
3802 required macro. Macros not found locally will still be searched in
3803 system-wide directories, as explained in @ref{Macro Search Path}.
3805 Custom macros should be distributed for the same reason that
3806 @file{configure.ac} is: so that other people have all the sources of
3807 your package if they want to work on it. In fact, this distribution
3808 happens automatically because all @code{m4_include}d files are
3811 However there is no consensus on the distribution of third-party
3812 macros that your package may use. Many libraries install their own
3813 macro in the system-wide @command{aclocal} directory (@pxref{Extending
3814 aclocal}). For instance, Guile ships with a file called
3815 @file{guile.m4} that contains the macro @code{GUILE_FLAGS} that can
3816 be used to define setup compiler and linker flags appropriate for
3817 using Guile. Using @code{GUILE_FLAGS} in @file{configure.ac} will
3818 cause @command{aclocal} to copy @file{guile.m4} into
3819 @file{aclocal.m4}, but as @file{guile.m4} is not part of the project,
3820 it will not be distributed. Technically, that means a user who
3821 needs to rebuild @file{aclocal.m4} will have to install Guile first.
3822 This is probably OK, if Guile already is a requirement to build the
3823 package. However, if Guile is only an optional feature, or if your
3824 package might run on architectures where Guile cannot be installed,
3825 this requirement will hinder development. An easy solution is to copy
3826 such third-party macros in your local @file{m4/} directory so they get
3829 Since Automake 1.10, @command{aclocal} offers the option @code{--install}
3830 to copy these system-wide third-party macros in your local macro directory,
3831 helping to solve the above problem.
3833 With this setup, system-wide macros will be copied to @file{m4/}
3834 the first time you run @command{aclocal}. Then the locally installed
3835 macros will have precedence over the system-wide installed macros
3836 each time @command{aclocal} is run again.
3838 One reason why you should keep @option{--install} in the flags even
3839 after the first run is that when you later edit @file{configure.ac}
3840 and depend on a new macro, this macro will be installed in your
3841 @file{m4/} automatically. Another one is that serial numbers
3842 (@pxref{Serials}) can be used to update the macros in your source tree
3843 automatically when new system-wide versions are installed. A serial
3844 number should be a single line of the form
3851 where @var{nnn} contains only digits and dots. It should appear in
3852 the M4 file before any macro definition. It is a good practice to
3853 maintain a serial number for each macro you distribute, even if you do
3854 not use the @option{--install} option of @command{aclocal}: this allows
3855 other people to use it.
3859 @subsection Serial Numbers
3860 @cindex serial numbers in macros
3861 @cindex macro serial numbers
3862 @cindex @code{#serial} syntax
3863 @cindex @command{aclocal} and serial numbers
3865 Because third-party macros defined in @file{*.m4} files are naturally
3866 shared between multiple projects, some people like to version them.
3867 This makes it easier to tell which of two M4 files is newer. Since at
3868 least 1996, the tradition is to use a @samp{#serial} line for this.
3870 A serial number should be a single line of the form
3873 # serial @var{version}
3877 where @var{version} is a version number containing only digits and
3878 dots. Usually people use a single integer, and they increment it each
3879 time they change the macro (hence the name of ``serial''). Such a
3880 line should appear in the M4 file before any macro definition.
3882 The @samp{#} must be the first character on the line,
3883 and it is OK to have extra words after the version, as in
3886 #serial @var{version} @var{garbage}
3889 Normally these serial numbers are completely ignored by
3890 @command{aclocal} and @command{autoconf}, like any genuine comment.
3891 However when using @command{aclocal}'s @option{--install} feature, these
3892 serial numbers will modify the way @command{aclocal} selects the
3893 macros to install in the package: if two files with the same basename
3894 exist in your search path, and if at least one of them uses a
3895 @samp{#serial} line, @command{aclocal} will ignore the file that has
3896 the older @samp{#serial} line (or the file that has none).
3898 Note that a serial number applies to a whole M4 file, not to any macro
3899 it contains. A file can contain multiple macros, but only one
3902 Here is a use case that illustrates the use of @option{--install} and
3903 its interaction with serial numbers. Let's assume we maintain a
3904 package called MyPackage, the @file{configure.ac} of which requires a
3905 third-party macro @code{AX_THIRD_PARTY} defined in
3906 @file{/usr/share/aclocal/thirdparty.m4} as follows:
3910 AC_DEFUN([AX_THIRD_PARTY], [...])
3913 MyPackage uses an @file{m4/} directory to store local macros as
3914 explained in @ref{Local Macros}, and has
3917 AC_CONFIG_MACRO_DIRS([m4])
3921 in its @file{configure.ac}.
3923 Initially the @file{m4/} directory is empty. The first time we run
3924 @command{aclocal --install}, it will notice that
3928 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3930 No local macros define @code{AX_THIRD_PARTY}
3932 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3933 with serial @w{number 1}.
3937 Because @file{/usr/share/aclocal/thirdparty.m4} is a system-wide macro
3938 and @command{aclocal} was given the @option{--install} option, it will
3939 copy this file in @file{m4/thirdparty.m4}, and output an
3940 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3942 The next time @samp{aclocal --install} is run, something different
3943 happens. @command{aclocal} notices that
3947 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3949 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3950 with serial @w{number 1}.
3952 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3953 with serial @w{number 1}.
3957 Because both files have the same serial number, @command{aclocal} uses
3958 the first it found in its search path order (@pxref{Macro Search
3959 Path}). @command{aclocal} therefore ignores
3960 @file{/usr/share/aclocal/thirdparty.m4} and outputs an
3961 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3963 Local directories specified with @option{-I} are always searched before
3964 system-wide directories, so a local file will always be preferred to
3965 the system-wide file in case of equal serial numbers.
3967 Now suppose the system-wide third-party macro is changed. This can
3968 happen if the package installing this macro is updated. Let's suppose
3969 the new macro has serial @w{number 2}. The next time @samp{aclocal --install}
3970 is run the situation is the following:
3974 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3976 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3977 with serial @w{number 1}.
3979 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3984 When @command{aclocal} sees a greater serial number, it immediately
3985 forgets anything it knows from files that have the same basename and a
3986 smaller serial number. So after it has found
3987 @file{/usr/share/aclocal/thirdparty.m4} with serial 2,
3988 @command{aclocal} will proceed as if it had never seen
3989 @file{m4/thirdparty.m4}. This brings us back to a situation similar
3990 to that at the beginning of our example, where no local file defined
3991 the macro. @command{aclocal} will install the new version of the
3992 macro in @file{m4/thirdparty.m4}, in this case overriding the old
3993 version. MyPackage just had its macro updated as a side effect of
3994 running @command{aclocal}.
3996 If you are leery of letting @command{aclocal} update your local
3997 macro, you can run @samp{aclocal --diff} to review the changes
3998 @samp{aclocal --install} would perform on these macros.
4000 Finally, note that the @option{--force} option of @command{aclocal} has
4001 absolutely no effect on the files installed by @option{--install}. For
4002 instance, if you have modified your local macros, do not expect
4003 @option{--install --force} to replace the local macros by their
4004 system-wide versions. If you want to do so, simply erase the local
4005 macros you want to revert, and run @samp{aclocal --install}.
4008 @node Future of aclocal
4009 @subsection The Future of @command{aclocal}
4010 @cindex @command{aclocal}'s scheduled death
4012 Ideally, @command{aclocal} should not be part of Automake. Automake
4013 should focus on generating @file{Makefile}s; dealing with M4 macros is
4014 more Autoconf's job. The fact that some people install Automake just
4015 to use @command{aclocal}, but do not use @command{automake} otherwise
4016 is an indication of how that feature is misplaced.
4018 The new implementation will probably be done slightly differently.
4019 For instance, it could enforce the @file{m4/}-style layout discussed in
4022 We do not know when or whether this will happen. This has been
4023 discussed several times in the past, but someone still has to commit
4024 to that non-trivial task.
4026 From the user point of view, @command{aclocal}'s removal might turn
4027 out to be painful. There is a simple precaution that you may take to
4028 make that switch more seamless: never call @command{aclocal} yourself.
4029 Keep its invocation under the exclusive control of @command{autoreconf} and
4030 Automake's rebuild rules. Hopefully you won't need to worry about
4031 things breaking; when @command{aclocal} disappears, because everything
4032 will have been taken care of. If otherwise you used to call
4033 @command{aclocal} directly yourself or from some script, you will
4034 quickly notice the change.
4036 Many packages come with a script called @file{bootstrap} or
4037 @file{autogen.sh}, that will just call @command{aclocal},
4038 @command{libtoolize}, @command{gettextize} or @command{autopoint},
4039 @command{autoconf}, @command{autoheader}, and @command{automake} in
4040 the right order. In fact, this is precisely what @command{autoreconf}
4041 can do for you. If your package has such a @file{bootstrap} or
4042 @file{autogen.sh} script, consider using @command{autoreconf}. That
4043 should simplify its logic a lot (less things to maintain, all to the
4044 good), it's even likely you will not need the script anymore, and more
4045 to the point you will not call @command{aclocal} directly anymore.
4047 For the time being, third-party packages should continue to install
4048 public macros into @file{/usr/share/aclocal/}. If @command{aclocal}
4049 is replaced by another tool it might make sense to rename the
4050 directory, but supporting @file{/usr/share/aclocal/} for backward
4051 compatibility should be easy provided all macros are properly written
4052 (@pxref{Extending aclocal}).
4057 @section Autoconf macros supplied with Automake
4059 Automake ships with several Autoconf macros that you can use from your
4060 @file{configure.ac}. When you use one of them it will be included by
4061 @command{aclocal} in @file{aclocal.m4}.
4064 * Public Macros:: Macros that you can use.
4065 * Obsolete Macros:: Macros that will soon be removed.
4066 * Private Macros:: Macros that you should not use.
4069 @c consider generating the following subsections automatically from m4 files.
4072 @subsection Public Macros
4076 @item AM_INIT_AUTOMAKE([@var{options}])
4077 @acindex AM_INIT_AUTOMAKE
4078 Runs many macros required for proper operation of the generated Makefiles.
4080 @vindex AUTOMAKE_OPTIONS
4081 Today, @code{AM_INIT_AUTOMAKE} is called with a single argument: a
4082 space-separated list of Automake options that should be applied to
4083 every @file{Makefile.am} in the tree. The effect is as if
4084 each option were listed in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
4087 This macro can also be called in another, @emph{deprecated} form:
4088 @code{AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])}. In this form,
4089 there are two required arguments: the package and the version number.
4090 This usage is mostly obsolete because the @var{package} and @var{version}
4091 can be obtained from Autoconf's @code{AC_INIT} macro. However,
4092 differently from what happens for @code{AC_INIT} invocations, this
4093 @code{AM_INIT_AUTOMAKE} invocation supports shell variables' expansions
4094 in the @code{PACKAGE} and @code{VERSION} arguments (which otherwise
4095 defaults, respectively, to the @code{PACKAGE_TARNAME} and
4096 @code{PACKAGE_VERSION} defined via the @code{AC_INIT} invocation;
4097 @pxref{AC_INIT, , The @code{AC_INIT} macro, autoconf, The Autoconf Manual});
4098 and this can still be useful in some selected situations.
4099 Our hope is that future Autoconf versions will improve their support
4100 for package versions defined dynamically at configure runtime; when
4101 (and if) this happens, support for the two-args @code{AM_INIT_AUTOMAKE}
4102 invocation will likely be removed from Automake.
4104 @anchor{Modernize AM_INIT_AUTOMAKE invocation}
4105 If your @file{configure.ac} has:
4108 AC_INIT([src/foo.c])
4109 AM_INIT_AUTOMAKE([mumble], [1.5])
4113 you should modernize it as follows:
4116 AC_INIT([mumble], [1.5])
4117 AC_CONFIG_SRCDIR([src/foo.c])
4121 Note that if you're upgrading your @file{configure.ac} from an earlier
4122 version of Automake, it is not always correct to simply move the
4123 package and version arguments from @code{AM_INIT_AUTOMAKE} directly to
4124 @code{AC_INIT}, as in the example above. The first argument to
4125 @code{AC_INIT} should be the name of your package (e.g., @samp{GNU
4126 Automake}), not the tarball name (e.g., @samp{automake}) that you used
4127 to pass to @code{AM_INIT_AUTOMAKE}. Autoconf tries to derive a
4128 tarball name from the package name, which should work for most but not
4129 all package names. (If it doesn't work for yours, you can use the
4130 four-argument form of @code{AC_INIT} to provide the tarball name
4133 @cindex @code{PACKAGE}, prevent definition
4134 @cindex @code{VERSION}, prevent definition
4136 By default this macro @code{AC_DEFINE}'s @code{PACKAGE} and
4137 @code{VERSION}. This can be avoided by passing the @option{no-define}
4138 option (@pxref{List of Automake options}):
4140 AM_INIT_AUTOMAKE([no-define ...])
4143 @item AM_PATH_LISPDIR
4144 @acindex AM_PATH_LISPDIR
4147 Searches for the program @command{emacs}, and, if found, sets the
4148 output variable @code{lispdir} to the full path to Emacs' site-lisp
4151 Note that this test assumes the @command{emacs} found to be a version
4152 that supports Emacs Lisp (such as GNU Emacs or XEmacs). Other
4153 emacsen can cause this test to hang (some, like old versions of
4154 MicroEmacs, start up in interactive mode, requiring @kbd{C-x C-c} to
4155 exit, which is hardly obvious for a non-emacs user). In most cases,
4156 however, you should be able to use @kbd{C-c} to kill the test. In
4157 order to avoid problems, you can set @env{EMACS} to ``no'' in the
4158 environment, or use the @option{--with-lispdir} option to
4159 @command{configure} to explicitly set the correct path (if you're sure
4160 you have an @command{emacs} that supports Emacs Lisp).
4162 @item AM_PROG_AR(@ovar{act-if-fail})
4165 You must use this macro when you use the archiver in your project, if
4166 you want support for unusual archivers such as Microsoft @command{lib}.
4167 The content of the optional argument is executed if the archiver
4168 interface is not recognized; the default action is to abort configure
4169 with an error message.
4175 Use this macro when you have assembly code in your project. This will
4176 choose the assembler for you (by default the C compiler) and set
4177 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
4179 @item AM_PROG_CC_C_O
4180 @acindex AM_PROG_CC_C_O
4181 This is an obsolescent macro that checks that the C compiler supports
4182 the @option{-c} and @option{-o} options together. Note that, since
4183 Automake 1.14, the @code{AC_PROG_CC} is rewritten to implement such
4184 checks itself, and thus the explicit use of @code{AM_PROG_CC_C_O}
4185 should no longer be required.
4187 @item AM_PROG_LEX([@var{options}])
4188 @acindex AM_PROG_LEX
4189 @acindex AC_PROG_LEX
4190 @cindex HP-UX 10, @command{lex} problems
4191 @cindex @command{lex} problems with HP-UX 10
4192 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
4193 Program Checks, autoconf, The Autoconf Manual}), but uses the
4194 @command{missing} script on systems that do not have @command{lex}.
4195 HP-UX 10 is one such system. @var{options} are passed directly to
4199 @acindex AM_PROG_GCJ
4202 This macro finds the @command{gcj} program or causes an error. It sets
4203 @code{GCJ} and @code{GCJFLAGS}. @command{gcj} is the Java front-end to the
4204 GNU Compiler Collection.
4206 @item AM_PROG_UPC([@var{compiler-search-list}])
4207 @acindex AM_PROG_UPC
4209 Find a compiler for Unified Parallel C and define the @code{UPC}
4210 variable. The default @var{compiler-search-list} is @samp{upcc upc}.
4211 This macro will abort @command{configure} if no Unified Parallel C
4214 @item AM_MISSING_PROG(@var{name}, @var{program})
4215 @acindex AM_MISSING_PROG
4217 Find a maintainer tool @var{program} and define the @var{name}
4218 environment variable with its location. If @var{program} is not
4219 detected, then @var{name} will instead invoke the @command{missing}
4220 script, in order to give useful advice to the user about the missing
4221 maintainer tool. @xref{maintainer-mode}, for more information on when
4222 the @command{missing} script is appropriate.
4224 @item AM_SILENT_RULES
4225 @acindex AM_SILENT_RULES
4226 Control the machinery for less verbose build output
4227 (@pxref{Automake Silent Rules}).
4229 @item AM_WITH_DMALLOC
4230 @acindex AM_WITH_DMALLOC
4231 @cindex @command{dmalloc}, support for
4232 @vindex WITH_DMALLOC
4233 @opindex --with-dmalloc
4234 Add support for the @uref{https://dmalloc.com/, Dmalloc package}. If
4235 the user runs @command{configure} with @option{--with-dmalloc}, then
4236 define @code{WITH_DMALLOC} and add @option{-ldmalloc} to @code{LIBS}.
4241 @node Obsolete Macros
4242 @subsection Obsolete Macros
4243 @cindex obsolete macros
4246 Although using some of the following macros was required in past
4247 releases, you should not use any of them in new code. @emph{All
4248 these macros will be removed in the next major Automake version};
4249 if you are still using them, running @command{autoupdate} should
4250 adjust your @file{configure.ac} automatically (@pxref{autoupdate
4251 Invocation, , Using @command{autoupdate} to Modernize
4252 @file{configure.ac}, autoconf, The Autoconf Manual}).
4257 @item AM_PROG_MKDIR_P
4258 @acindex AM_PROG_MKDIR_P
4259 @cindex @code{mkdir -p}, macro check
4263 From Automake 1.8 to 1.9.6 this macro used to define the output
4264 variable @code{mkdir_p} to one of @code{mkdir -p}, @code{install-sh
4265 -d}, or @code{mkinstalldirs}.
4267 Nowadays Autoconf provides a similar functionality with
4268 @code{AC_PROG_MKDIR_P} (@pxref{Particular Programs, , Particular
4269 Program Checks, autoconf, The Autoconf Manual}), however this defines
4270 the output variable @code{MKDIR_P} instead. In case you are still
4271 using the @code{AM_PROG_MKDIR_P} macro in your @file{configure.ac},
4272 or its provided variable @code{$(mkdir_p)} in your @file{Makefile.am},
4273 you are advised to switch ASAP to the more modern Autoconf-provided
4274 interface instead; both the macro and the variable might be removed
4275 in a future major Automake release.
4280 @node Private Macros
4281 @subsection Private Macros
4283 The following macros are private macros you should not call directly.
4284 They are called by the other public macros when appropriate. Do not
4285 rely on them, as they might be changed in a future version. Consider
4286 them as implementation details; or better, do not consider them at all:
4290 @item _AM_DEPENDENCIES
4291 @itemx AM_SET_DEPDIR
4293 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
4294 These macros are used to implement Automake's automatic dependency
4295 tracking scheme. They are called automatically by Automake when
4296 required, and there should be no need to invoke them manually.
4298 @item AM_MAKE_INCLUDE
4299 This macro is used to discover how the user's @command{make} handles
4300 @code{include} statements. This macro is automatically invoked when
4301 needed; there should be no need to invoke it manually.
4303 @item AM_PROG_INSTALL_STRIP
4304 This is used to find a version of @code{install} that can be used to
4305 strip a program at installation time. This macro is automatically
4306 included when required.
4308 @item AM_SANITY_CHECK
4309 This checks to make sure that a file created in the build directory is
4310 newer than a file in the source directory. This can fail on systems
4311 where the clock is set incorrectly. This macro is automatically run
4312 from @code{AM_INIT_AUTOMAKE}.
4318 @chapter Directories
4320 For simple projects that distribute all files in the same directory
4321 it is enough to have a single @file{Makefile.am} that builds
4322 everything in place.
4324 In larger projects, it is common to organize files in different
4325 directories, in a tree. For example, there could be a directory
4326 for the program's source, one for the testsuite, and one for the
4327 documentation; or, for very large projects, there could be one
4328 directory per program, per library or per module.
4330 The traditional approach is to build these subdirectories recursively,
4331 employing @emph{make recursion}: each directory contains its
4332 own @file{Makefile}, and when @command{make} is run from the top-level
4333 directory, it enters each subdirectory in turn, and invokes there a
4334 new @command{make} instance to build the directory's contents.
4336 Because this approach is very widespread, Automake offers built-in
4337 support for it. However, it is worth noting that the use of make
4338 recursion has its own serious issues and drawbacks, and that it's
4339 well possible to have packages with a multi directory layout that
4340 make little or no use of such recursion (examples of such packages
4341 are GNU Bison and GNU Automake itself); see also the @ref{Alternative}
4345 * Subdirectories:: Building subdirectories recursively
4346 * Conditional Subdirectories:: Conditionally not building directories
4347 * Alternative:: Subdirectories without recursion
4348 * Subpackages:: Nesting packages
4351 @node Subdirectories
4352 @section Recursing subdirectories
4354 @cindex @code{SUBDIRS}, explained
4356 In packages using make recursion, the top level @file{Makefile.am} must
4357 tell Automake which subdirectories are to be built. This is done via
4358 the @code{SUBDIRS} variable.
4361 The @code{SUBDIRS} variable holds a list of subdirectories in which
4362 building of various sorts can occur. The rules for many targets
4363 (e.g., @code{all}) in the generated @file{Makefile} will run commands
4364 both locally and in all specified subdirectories. Note that the
4365 directories listed in @code{SUBDIRS} are not required to contain
4366 @file{Makefile.am}s; only @file{Makefile}s (after configuration).
4367 This allows inclusion of libraries from packages that do not use
4368 Automake (such as @code{gettext}; see also @ref{Third-Party
4371 In packages that use subdirectories, the top-level @file{Makefile.am} is
4372 often very short. For instance, here is the @file{Makefile.am} from the
4373 GNU Hello distribution:
4376 EXTRA_DIST = BUGS ChangeLog.O README-alpha
4377 SUBDIRS = doc intl po src tests
4380 When Automake invokes @command{make} in a subdirectory, it uses the value
4381 of the @code{MAKE} variable. It passes the value of the variable
4382 @code{AM_MAKEFLAGS} to the @command{make} invocation; this can be set in
4383 @file{Makefile.am} if there are flags you must always pass to
4386 @vindex AM_MAKEFLAGS
4388 The directories mentioned in @code{SUBDIRS} are usually direct
4389 children of the current directory, each subdirectory containing its
4390 own @file{Makefile.am} with a @code{SUBDIRS} pointing to deeper
4391 subdirectories. Automake can be used to construct packages of
4392 arbitrary depth this way.
4394 By default, Automake generates @file{Makefiles} that work depth-first
4395 in postfix order: the subdirectories are built before the current
4396 directory. However, it is possible to change this ordering. You can
4397 do this by putting @samp{.} into @code{SUBDIRS}. For instance,
4398 putting @samp{.} first will cause a prefix ordering of
4404 SUBDIRS = lib src . test
4408 will cause @file{lib/} to be built before @file{src/}, then the
4409 current directory will be built, finally the @file{test/} directory
4410 will be built. It is customary to arrange test directories to be
4411 built after everything else since they are meant to test what has
4414 In addition to the built-in recursive targets defined by Automake
4415 (@code{all}, @code{check}, etc.), the developer can also define his
4416 own recursive targets. That is done by passing the names of such
4417 targets as arguments to the m4 macro @code{AM_EXTRA_RECURSIVE_TARGETS}
4418 in @file{configure.ac}. Automake generates rules to handle the
4419 recursion for such targets; and the developer can define real actions
4420 for them by defining corresponding @code{-local} targets.
4423 % @kbd{cat configure.ac}
4424 AC_INIT([pkg-name], [1.0])
4426 AM_EXTRA_RECURSIVE_TARGETS([foo])
4427 AC_CONFIG_FILES([Makefile sub/Makefile sub/src/Makefile])
4429 % @kbd{cat Makefile.am}
4432 @@echo This will be run by "make foo".
4433 % @kbd{cat sub/Makefile.am}
4435 % @kbd{cat sub/src/Makefile.am}
4437 @@echo This too will be run by a "make foo" issued either in
4438 @@echo the 'sub/src/' directory, the 'sub/' directory, or the
4439 @@echo top-level directory.
4442 @node Conditional Subdirectories
4443 @section Conditional Subdirectories
4444 @cindex Subdirectories, building conditionally
4445 @cindex Conditional subdirectories
4446 @cindex @code{SUBDIRS}, conditional
4447 @cindex Conditional @code{SUBDIRS}
4449 It is possible to define the @code{SUBDIRS} variable conditionally if,
4450 like in the case of GNU Inetutils, you want to only build a subset of
4453 To illustrate how this works, let's assume we have two directories,
4454 @file{src/} and @file{opt/}. @file{src/} should always be built, but we
4455 want to decide in @command{configure} whether @file{opt/} will be built
4456 or not. (For this example we will assume that @file{opt/} should be
4457 built when the variable @samp{$want_opt} was set to @samp{yes}.)
4459 Running @command{make} should thus recurse into @file{src/} always, and
4460 then maybe in @file{opt/}.
4462 However @samp{make dist} should always recurse into both @file{src/}
4463 and @file{opt/}, because @file{opt/} should be distributed even if it
4464 is not needed in the current configuration. This means
4465 @file{opt/Makefile} should be created @emph{unconditionally}.
4467 There are two ways to set up a project like this. You can use Automake
4468 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
4469 variables (@pxref{Setting Output Variables, , Setting Output
4470 Variables, autoconf, The Autoconf Manual}). Using Automake
4471 conditionals is the preferred solution. Before we illustrate these
4472 two possibilities, let's introduce @code{DIST_SUBDIRS}.
4475 * SUBDIRS vs DIST_SUBDIRS:: Two sets of directories
4476 * Subdirectories with AM_CONDITIONAL:: Specifying conditional subdirectories
4477 * Subdirectories with AC_SUBST:: Another way for conditional recursion
4478 * Unconfigured Subdirectories:: Not even creating a @samp{Makefile}
4481 @node SUBDIRS vs DIST_SUBDIRS
4482 @subsection @code{SUBDIRS} vs.@: @code{DIST_SUBDIRS}
4483 @cindex @code{DIST_SUBDIRS}, explained
4485 Automake considers two sets of directories, defined by the variables
4486 @code{SUBDIRS} and @code{DIST_SUBDIRS}.
4488 @code{SUBDIRS} contains the subdirectories of the current directory
4489 that must be built (@pxref{Subdirectories}). It must be defined
4490 manually; Automake will never guess a directory is to be built. As we
4491 will see in the next two sections, it is possible to define it
4492 conditionally so that some directory will be omitted from the build.
4494 @code{DIST_SUBDIRS} is used in rules that need to recurse in all
4495 directories, even those that have been conditionally left out of the
4496 build. Recall our example where we may not want to build subdirectory
4497 @file{opt/}, but yet we want to distribute it? This is where
4498 @code{DIST_SUBDIRS} comes into play: @samp{opt} may not appear in
4499 @code{SUBDIRS}, but it must appear in @code{DIST_SUBDIRS}.
4501 Precisely, @code{DIST_SUBDIRS} is used by @samp{make
4502 maintainer-clean}, @samp{make distclean} and @samp{make dist}. All
4503 other recursive rules use @code{SUBDIRS}.
4505 If @code{SUBDIRS} is defined conditionally using Automake
4506 conditionals, Automake will define @code{DIST_SUBDIRS} automatically
4507 from the possible values of @code{SUBDIRS} in all conditions.
4509 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
4510 @code{DIST_SUBDIRS} will not be defined correctly because Automake
4511 does not know the possible values of these variables. In this case
4512 @code{DIST_SUBDIRS} needs to be defined manually.
4514 @node Subdirectories with AM_CONDITIONAL
4515 @subsection Subdirectories with @code{AM_CONDITIONAL}
4516 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
4517 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
4519 @c Keep in sync with subdir-am-cond.sh
4521 @file{configure} should output the @file{Makefile} for each directory
4522 and define a condition into which @file{opt/} should be built.
4526 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
4527 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4531 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
4538 SUBDIRS = src $(MAYBE_OPT)
4541 As you can see, running @command{make} will rightly recurse into
4542 @file{src/} and maybe @file{opt/}.
4544 @vindex DIST_SUBDIRS
4545 As you can't see, running @samp{make dist} will recurse into both
4546 @file{src/} and @file{opt/} directories because @samp{make dist}, unlike
4547 @samp{make all}, doesn't use the @code{SUBDIRS} variable. It uses the
4548 @code{DIST_SUBDIRS} variable.
4550 In this case Automake will define @samp{DIST_SUBDIRS = src opt}
4551 automatically because it knows that @code{MAYBE_OPT} can contain
4552 @samp{opt} in some condition.
4554 @node Subdirectories with AC_SUBST
4555 @subsection Subdirectories with @code{AC_SUBST}
4556 @cindex @code{SUBDIRS} and @code{AC_SUBST}
4557 @cindex @code{AC_SUBST} and @code{SUBDIRS}
4559 @c Keep in sync with subdir-ac-subst.sh
4561 Another possibility is to define @code{MAYBE_OPT} from
4562 @file{./configure} using @code{AC_SUBST}:
4566 if test "$want_opt" = yes; then
4571 AC_SUBST([MAYBE_OPT])
4572 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4576 In this case the top-level @file{Makefile.am} should look as follows.
4579 SUBDIRS = src $(MAYBE_OPT)
4580 DIST_SUBDIRS = src opt
4583 The drawback is that since Automake cannot guess what the possible
4584 values of @code{MAYBE_OPT} are, it is necessary to define
4585 @code{DIST_SUBDIRS}.
4587 @node Unconfigured Subdirectories
4588 @subsection Unconfigured Subdirectories
4589 @cindex Subdirectories, configured conditionally
4591 The semantics of @code{DIST_SUBDIRS} are often misunderstood by some
4592 users that try to @emph{configure and build} subdirectories
4593 conditionally. Here by configuring we mean creating the
4594 @file{Makefile} (it might also involve running a nested
4595 @command{configure} script: this is a costly operation that explains
4596 why people want to do it conditionally, but only the @file{Makefile}
4597 is relevant to the discussion).
4599 The above examples all assume that every @file{Makefile} is created,
4600 even in directories that are not going to be built. The simple reason
4601 is that we want @samp{make dist} to distribute even the directories
4602 that are not being built (e.g., platform-dependent code), hence
4603 @file{make dist} must recurse into the subdirectory, hence this
4604 directory must be configured and appear in @code{DIST_SUBDIRS}.
4606 Building packages that do not configure every subdirectory is a tricky
4607 business, and we do not recommend it to the novice as it is easy to
4608 produce an incomplete tarball by mistake. We will not discuss this
4609 topic in depth here, yet for the adventurous here are a few rules to
4614 @item @code{SUBDIRS} should always be a subset of @code{DIST_SUBDIRS}.
4616 It makes little sense to have a directory in @code{SUBDIRS} that
4617 is not in @code{DIST_SUBDIRS}. Think of the former as a way to tell
4618 which directories listed in the latter should be built.
4619 @item Any directory listed in @code{DIST_SUBDIRS} and @code{SUBDIRS}
4622 That is, the @file{Makefile} must exist or the recursive @command{make}
4623 rules will not be able to process the directory.
4624 @item Any configured directory must be listed in @code{DIST_SUBDIRS}.
4626 This is so the cleaning rules remove the generated @file{Makefile}s.
4627 It would be correct to see @code{DIST_SUBDIRS} as a variable that
4628 lists all the directories that have been configured.
4632 In order to prevent recursion in some unconfigured directory you
4633 must therefore ensure that this directory does not appear in
4634 @code{DIST_SUBDIRS} (and @code{SUBDIRS}). For instance, if you define
4635 @code{SUBDIRS} conditionally using @code{AC_SUBST} and do not define
4636 @code{DIST_SUBDIRS} explicitly, it will be default to
4637 @samp{$(SUBDIRS)}; another possibility is to force @code{DIST_SUBDIRS
4640 Of course, directories that are omitted from @code{DIST_SUBDIRS} will
4641 not be distributed unless you make other arrangements for this to
4642 happen (for instance, always running @samp{make dist} in a
4643 configuration where all directories are known to appear in
4644 @code{DIST_SUBDIRS}; or writing a @code{dist-hook} target to
4645 distribute these directories).
4647 @cindex Subdirectories, not distributed
4648 In a few packages, unconfigured directories are not even expected to
4649 be distributed. Although these packages do not require the
4650 aforementioned extra arrangements, there is another pitfall. If the
4651 name of a directory appears in @code{SUBDIRS} or @code{DIST_SUBDIRS},
4652 @command{automake} will make sure the directory exists. Consequently
4653 @command{automake} cannot be run on such a distribution when one
4654 directory has been omitted. One way to avoid this check is to use the
4655 @code{AC_SUBST} method to declare conditional directories; since
4656 @command{automake} does not know the values of @code{AC_SUBST}
4657 variables it cannot ensure the corresponding directory exists.
4660 @section An Alternative Approach to Subdirectories
4662 If you've ever read Peter Miller's excellent paper, @cite{Recursive
4663 Make Considered Harmful}, the preceding sections on the use of make
4664 recursion will probably come as unwelcome advice. For those who
4665 haven't read the paper, Miller's main thesis is that recursive
4666 @command{make} invocations are both slow and error-prone.
4668 Automake is intended to have sufficient cross-directory support to
4669 enable you to write a single @file{Makefile.am} for a complex
4670 multi-directory package. (If it seems to be lacking, please report
4671 the issue as usual.)
4673 By default an installable file specified in a subdirectory will have its
4674 directory name stripped before installation. For instance, in this
4675 example, the header file will be installed as
4676 @file{$(includedir)/stdio.h}:
4679 include_HEADERS = inc/stdio.h
4683 @cindex @code{nobase_} prefix
4684 @cindex Path stripping, avoiding
4685 @cindex Avoiding path stripping
4687 However, the @samp{nobase_} prefix can be used to circumvent this path
4688 stripping. In this example, the header file will be installed as
4689 @file{$(includedir)/sys/types.h}:
4692 nobase_include_HEADERS = sys/types.h
4695 @cindex @code{nobase_} and @code{dist_} or @code{nodist_}
4696 @cindex @code{dist_} and @code{nobase_}
4697 @cindex @code{nodist_} and @code{nobase_}
4701 @samp{nobase_} should be specified first when used in conjunction with
4702 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
4703 Control}). For instance:
4706 nobase_dist_pkgdata_DATA = images/vortex.pgm sounds/whirl.ogg
4709 Finally, note that a variable using the @samp{nobase_} prefix can
4710 often be replaced by several variables, one for each destination
4711 directory (@pxref{Uniform}). For instance, the last example could be
4712 rewritten as follows:
4714 @c Keep in sync with primary-prefix-couples-documented-valid.sh
4716 imagesdir = $(pkgdatadir)/images
4717 soundsdir = $(pkgdatadir)/sounds
4718 dist_images_DATA = images/vortex.pgm
4719 dist_sounds_DATA = sounds/whirl.ogg
4723 This latter syntax makes it possible to change one destination
4724 directory without changing the layout of the source tree.
4726 Currently, @samp{nobase_*_LTLIBRARIES} are the only exception to this
4727 rule, in that there is no particular installation order guarantee for
4728 an otherwise equivalent set of variables without @samp{nobase_} prefix.
4731 @section Nesting Packages
4732 @cindex Nesting packages
4734 @acindex AC_CONFIG_SUBDIRS
4735 @acindex AC_CONFIG_AUX_DIR
4737 In the GNU Build System, packages can be nested to arbitrary depth.
4738 This means that a package can embed other packages with their own
4739 @file{configure}, @file{Makefile}s, etc.
4741 These other packages should just appear as subdirectories of their
4742 parent package. They must be listed in @code{SUBDIRS} like other
4743 ordinary directories. However the subpackage's @file{Makefile}s
4744 should be output by its own @file{configure} script, not by the
4745 parent's @file{configure}. This is achieved using the
4746 @code{AC_CONFIG_SUBDIRS} Autoconf macro (@pxref{Subdirectories,
4747 AC_CONFIG_SUBDIRS, Configuring Other Packages in Subdirectories,
4748 autoconf, The Autoconf Manual}).
4750 Here is an example package for an @code{arm} program that links with
4751 a @code{hand} library that is a nested package in subdirectory
4754 @code{arm}'s @file{configure.ac}:
4757 AC_INIT([arm], [1.0])
4758 AC_CONFIG_AUX_DIR([.])
4761 AC_CONFIG_FILES([Makefile])
4762 # Call hand's ./configure script recursively.
4763 AC_CONFIG_SUBDIRS([hand])
4767 @code{arm}'s @file{Makefile.am}:
4770 # Build the library in the hand subdirectory first.
4773 # Include hand's header when compiling this directory.
4774 AM_CPPFLAGS = -I$(srcdir)/hand
4778 # link with the hand library.
4779 arm_LDADD = hand/libhand.a
4782 Now here is @code{hand}'s @file{hand/configure.ac}:
4785 AC_INIT([hand], [1.2])
4786 AC_CONFIG_AUX_DIR([.])
4791 AC_CONFIG_FILES([Makefile])
4796 and its @file{hand/Makefile.am}:
4799 lib_LIBRARIES = libhand.a
4800 libhand_a_SOURCES = hand.c
4803 When @samp{make dist} is run from the top-level directory it will
4804 create an archive @file{arm-1.0.tar.gz} that contains the @code{arm}
4805 code as well as the @file{hand} subdirectory. This package can be
4806 built and installed like any ordinary package, with the usual
4807 @samp{./configure && make && make install} sequence (the @code{hand}
4808 subpackage will be built and installed by the process).
4810 When @samp{make dist} is run from the hand directory, it will create a
4811 self-contained @file{hand-1.2.tar.gz} archive. So although it appears
4812 to be embedded in another package, it can still be used separately.
4814 The purpose of the @samp{AC_CONFIG_AUX_DIR([.])} instruction is to
4815 force Automake and Autoconf to search for auxiliary scripts in the
4816 current directory. For instance, this means that there will be two
4817 copies of @file{install-sh}: one in the top-level of the @code{arm}
4818 package, and another one in the @file{hand/} subdirectory for the
4819 @code{hand} package.
4821 The historical default is to search for these auxiliary scripts in the
4822 parent directory and the grandparent directory. So if the
4823 @samp{AC_CONFIG_AUX_DIR([.])} line was removed from
4824 @file{hand/configure.ac}, that subpackage would share the auxiliary
4825 script of the @code{arm} package. This may look like a gain in size
4826 (a few kilobytes), but more importantly, it is a loss of modularity as
4827 the @code{hand} subpackage is no longer self-contained (@samp{make
4828 dist} in the subdirectory will not work anymore).
4830 Packages that do not use Automake need more work to be integrated this
4831 way. @xref{Third-Party Makefiles}.
4834 @chapter Building Programs and Libraries
4836 A large part of Automake's functionality is dedicated to making it easy
4837 to build programs and libraries.
4840 * A Program:: Building a program
4841 * A Library:: Building a library
4842 * A Shared Library:: Building a Libtool library
4843 * Program and Library Variables:: Variables controlling program and
4845 * Default _SOURCES:: Default source files
4846 * LIBOBJS:: Special handling for LIBOBJS and ALLOCA
4847 * Program Variables:: Variables used when building a program
4848 * Yacc and Lex:: Yacc and Lex support
4849 * C++ Support:: Compiling C++ sources
4850 * Objective C Support:: Compiling Objective C sources
4851 * Objective C++ Support:: Compiling Objective C++ sources
4852 * Unified Parallel C Support:: Compiling Unified Parallel C sources
4853 * Assembly Support:: Compiling assembly sources
4854 * Fortran 77 Support:: Compiling Fortran 77 sources
4855 * Fortran 9x Support:: Compiling Fortran 9x sources
4856 * Java Support with gcj:: Compiling Java sources using gcj
4857 * Vala Support:: Compiling Vala sources
4858 * Support for Other Languages:: Compiling other languages
4859 * Dependencies:: Automatic dependency tracking
4860 * EXEEXT:: Support for executable extensions
4865 @section Building a program
4867 In order to build a program, you need to tell Automake which sources
4868 are part of it, and which libraries it should be linked with.
4870 This section also covers conditional compilation of sources or
4871 programs. Most of the comments about these also apply to libraries
4872 (@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
4875 * Program Sources:: Defining program sources
4876 * Linking:: Linking with libraries or extra objects
4877 * Conditional Sources:: Handling conditional sources
4878 * Conditional Programs:: Building a program conditionally
4881 @node Program Sources
4882 @subsection Defining program sources
4884 @cindex @code{PROGRAMS}, @code{bindir}
4886 @vindex bin_PROGRAMS
4887 @vindex sbin_PROGRAMS
4888 @vindex libexec_PROGRAMS
4889 @vindex pkglibexec_PROGRAMS
4890 @vindex noinst_PROGRAMS
4891 @vindex check_PROGRAMS
4893 In a directory containing source that gets built into a program (as
4894 opposed to a library or a script), the @code{PROGRAMS} primary is used.
4895 Programs can be installed in @code{bindir}, @code{sbindir},
4896 @code{libexecdir}, @code{pkglibexecdir}, or not at all
4897 (@code{noinst_}). They can also be built only for @samp{make check}, in
4898 which case the prefix is @samp{check_}.
4903 bin_PROGRAMS = hello
4906 In this simple case, the resulting @file{Makefile.in} will contain code
4907 to generate a program named @code{hello}.
4909 Associated with each program are several assisting variables that are
4910 named after the program. These variables are all optional, and have
4911 reasonable defaults. Each variable, its use, and default is spelled out
4912 below; we use the ``hello'' example throughout.
4914 The variable @code{hello_SOURCES} is used to specify which source files
4915 get built into an executable:
4918 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
4921 This causes each mentioned @file{.c} file to be compiled into the
4922 corresponding @file{.o}. Then all are linked to produce @file{hello}.
4924 @cindex @code{_SOURCES} primary, defined
4925 @cindex @code{SOURCES} primary, defined
4926 @cindex Primary variable, @code{SOURCES}
4929 If @code{hello_SOURCES} is not specified, then it defaults to the single
4930 file @file{hello.c} (@pxref{Default _SOURCES}).
4934 Multiple programs can be built in a single directory. Multiple programs
4935 can share a single source file, which must be listed in each
4936 @code{_SOURCES} definition.
4938 @cindex Header files in @code{_SOURCES}
4939 @cindex @code{_SOURCES} and header files
4941 Header files listed in a @code{_SOURCES} definition will be included in
4942 the distribution but otherwise ignored. In case it isn't obvious, you
4943 should not include the header file generated by @file{configure} in a
4944 @code{_SOURCES} variable; this file should not be distributed. Lex
4945 (@file{.l}) and Yacc (@file{.y}) files can also be listed; see @ref{Yacc
4950 @subsection Linking the program
4952 If you need to link against libraries that are not found by
4953 @command{configure}, you can use @code{LDADD} to do so. This variable is
4954 used to specify additional objects or libraries to link with; it is
4955 inappropriate for specifying specific linker flags; you should use
4956 @code{AM_LDFLAGS} for this purpose.
4960 @cindex @code{prog_LDADD}, defined
4962 Sometimes, multiple programs are built in one directory but do not share
4963 the same link-time requirements. In this case, you can use the
4964 @code{@var{prog}_LDADD} variable (where @var{prog} is the name of the
4965 program as it appears in some @code{_PROGRAMS} variable, and usually
4966 written in lowercase) to override @code{LDADD}. If this variable exists
4967 for a given program, then that program is not linked using @code{LDADD}.
4970 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
4971 linked against the library @file{libcpio.a}. However, @code{rmt} is
4972 built in the same directory, and has no such link requirement. Also,
4973 @code{mt} and @code{rmt} are only built on certain architectures. Here
4974 is what cpio's @file{src/Makefile.am} looks like (abridged):
4977 bin_PROGRAMS = cpio pax $(MT)
4978 libexec_PROGRAMS = $(RMT)
4979 EXTRA_PROGRAMS = mt rmt
4981 LDADD = ../lib/libcpio.a $(INTLLIBS)
4984 cpio_SOURCES = @dots{}
4985 pax_SOURCES = @dots{}
4986 mt_SOURCES = @dots{}
4987 rmt_SOURCES = @dots{}
4990 @cindex @code{_LDFLAGS}, defined
4991 @vindex maude_LDFLAGS
4992 @code{@var{prog}_LDADD} is inappropriate for passing program-specific
4993 linker flags (except for @option{-l}, @option{-L}, @option{-dlopen} and
4994 @option{-dlpreopen}). So, use the @code{@var{prog}_LDFLAGS} variable for
4997 @cindex @code{_DEPENDENCIES}, defined
4998 @vindex maude_DEPENDENCIES
4999 @vindex EXTRA_maude_DEPENDENCIES
5000 It is also occasionally useful to have a program depend on some other
5001 target that is not in fact part of that program. This can be done
5002 using either the @code{@var{prog}_DEPENDENCIES} or the
5003 @code{EXTRA_@var{prog}_DEPENDENCIES} variable. Each program depends on
5004 the contents both variables, but no further interpretation is done.
5006 Since these dependencies are associated to the link rule used to
5007 create the programs they should normally list files used by the link
5008 command. That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la}
5009 files. In rare cases you may need to add other kinds of files such as
5010 linker scripts, but @emph{listing a source file in
5011 @code{_DEPENDENCIES} is wrong}. If some source file needs to be built
5012 before all the components of a program are built, consider using the
5013 @code{BUILT_SOURCES} variable instead (@pxref{Sources}).
5015 If @code{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
5016 Automake. The automatically-assigned value is the contents of
5017 @code{@var{prog}_LDADD}, with most configure substitutions, @option{-l},
5018 @option{-L}, @option{-dlopen} and @option{-dlpreopen} options removed. The
5019 configure substitutions that are left in are only @samp{$(LIBOBJS)} and
5020 @samp{$(ALLOCA)}; these are left because it is known that they will not
5021 cause an invalid value for @code{@var{prog}_DEPENDENCIES} to be
5024 @ref{Conditional Sources} shows a situation where @code{_DEPENDENCIES}
5027 The @code{EXTRA_@var{prog}_DEPENDENCIES} may be useful for cases where
5028 you merely want to augment the @command{automake}-generated
5029 @code{@var{prog}_DEPENDENCIES} rather than replacing it.
5031 @cindex @code{LDADD} and @option{-l}
5032 @cindex @option{-l} and @code{LDADD}
5033 We recommend that you avoid using @option{-l} options in @code{LDADD}
5034 or @code{@var{prog}_LDADD} when referring to libraries built by your
5035 package. Instead, write the file name of the library explicitly as in
5036 the above @code{cpio} example. Use @option{-l} only to list
5037 third-party libraries. If you follow this rule, the default value of
5038 @code{@var{prog}_DEPENDENCIES} will list all your local libraries and
5039 omit the other ones.
5042 @node Conditional Sources
5043 @subsection Conditional compilation of sources
5045 You can't put a configure substitution (e.g., @samp{@@FOO@@} or
5046 @samp{$(FOO)} where @code{FOO} is defined via @code{AC_SUBST}) into a
5047 @code{_SOURCES} variable. The reason for this is a bit hard to
5048 explain, but suffice to say that it simply won't work. Automake will
5049 give an error if you try to do this.
5051 Fortunately there are two other ways to achieve the same result. One is
5052 to use configure substitutions in @code{_LDADD} variables, the other is
5053 to use an Automake conditional.
5055 @subsubheading Conditional Compilation using @code{_LDADD} Substitutions
5057 @cindex @code{EXTRA_prog_SOURCES}, defined
5059 Automake must know all the source files that could possibly go into a
5060 program, even if not all the files are built in every circumstance. Any
5061 files that are only conditionally built should be listed in the
5062 appropriate @code{EXTRA_} variable. For instance, if
5063 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
5064 in @code{hello}, the @file{Makefile.am} would contain:
5067 bin_PROGRAMS = hello
5068 hello_SOURCES = hello-common.c
5069 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
5070 hello_LDADD = $(HELLO_SYSTEM)
5071 hello_DEPENDENCIES = $(HELLO_SYSTEM)
5075 You can then set up the @samp{$(HELLO_SYSTEM)} substitution from
5076 @file{configure.ac}:
5081 *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
5082 *) HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
5084 AC_SUBST([HELLO_SYSTEM])
5088 In this case, the variable @code{HELLO_SYSTEM} should be replaced by
5089 either @file{hello-linux.o} or @file{hello-generic.o}, and added to
5090 both @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be
5091 built and linked in.
5093 @subsubheading Conditional Compilation using Automake Conditionals
5095 An often simpler way to compile source files conditionally is to use
5096 Automake conditionals. For instance, you could use this
5097 @file{Makefile.am} construct to build the same @file{hello} example:
5100 bin_PROGRAMS = hello
5102 hello_SOURCES = hello-linux.c hello-common.c
5104 hello_SOURCES = hello-generic.c hello-common.c
5108 In this case, @file{configure.ac} should set up the @code{LINUX}
5109 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
5111 When using conditionals like this you don't need to use the
5112 @code{EXTRA_} variable, because Automake will examine the contents of
5113 each variable to construct the complete list of source files.
5115 If your program uses a lot of files, you will probably prefer a
5116 conditional @samp{+=}.
5119 bin_PROGRAMS = hello
5120 hello_SOURCES = hello-common.c
5122 hello_SOURCES += hello-linux.c
5124 hello_SOURCES += hello-generic.c
5128 @node Conditional Programs
5129 @subsection Conditional compilation of programs
5130 @cindex Conditional programs
5131 @cindex Programs, conditional
5133 Sometimes it is useful to determine the programs that are to be built
5134 at configure time. For instance, GNU @code{cpio} only builds
5135 @code{mt} and @code{rmt} under special circumstances. The means to
5136 achieve conditional compilation of programs are the same you can use
5137 to compile source files conditionally: substitutions or conditionals.
5139 @subsubheading Conditional Programs using @command{configure} Substitutions
5141 @vindex EXTRA_PROGRAMS
5142 @cindex @code{EXTRA_PROGRAMS}, defined
5143 In this case, you must notify Automake of all the programs that can
5144 possibly be built, but at the same time cause the generated
5145 @file{Makefile.in} to use the programs specified by @command{configure}.
5146 This is done by having @command{configure} substitute values into each
5147 @code{_PROGRAMS} definition, while listing all optionally built programs
5148 in @code{EXTRA_PROGRAMS}.
5151 bin_PROGRAMS = cpio pax $(MT)
5152 libexec_PROGRAMS = $(RMT)
5153 EXTRA_PROGRAMS = mt rmt
5156 As explained in @ref{EXEEXT}, Automake will rewrite
5157 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
5158 @code{EXTRA_PROGRAMS}, appending @samp{$(EXEEXT)} to each binary.
5159 Obviously it cannot rewrite values obtained at run-time through
5160 @command{configure} substitutions, therefore you should take care of
5161 appending @samp{$(EXEEXT)} yourself, as in @samp{AC_SUBST([MT],
5162 ['mt$@{EXEEXT@}'])}.
5164 @subsubheading Conditional Programs using Automake Conditionals
5166 You can also use Automake conditionals (@pxref{Conditionals}) to
5167 select programs to be built. In this case you don't have to worry
5168 about @samp{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
5170 @c Keep in sync with exeext.sh
5172 bin_PROGRAMS = cpio pax
5177 libexec_PROGRAMS = rmt
5183 @section Building a library
5185 @cindex @code{_LIBRARIES} primary, defined
5186 @cindex @code{LIBRARIES} primary, defined
5187 @cindex Primary variable, @code{LIBRARIES}
5190 @vindex lib_LIBRARIES
5191 @vindex pkglib_LIBRARIES
5192 @vindex noinst_LIBRARIES
5194 Building a library is much like building a program. In this case, the
5195 name of the primary is @code{LIBRARIES}. Libraries can be installed in
5196 @code{libdir} or @code{pkglibdir}.
5198 @xref{A Shared Library}, for information on how to build shared
5199 libraries using libtool and the @code{LTLIBRARIES} primary.
5201 Each @code{_LIBRARIES} variable is a list of the libraries to be built.
5202 For instance, to create a library named @file{libcpio.a}, but not install
5203 it, you would write:
5206 noinst_LIBRARIES = libcpio.a
5207 libcpio_a_SOURCES = @dots{}
5210 The sources that go into a library are determined exactly as they are
5211 for programs, via the @code{_SOURCES} variables. Note that the library
5212 name is canonicalized (@pxref{Canonicalization}), so the @code{_SOURCES}
5213 variable corresponding to @file{libcpio.a} is @samp{libcpio_a_SOURCES},
5214 not @samp{libcpio.a_SOURCES}.
5216 @vindex maude_LIBADD
5217 Extra objects can be added to a library using the
5218 @code{@var{library}_LIBADD} variable. This should be used for objects
5219 determined by @command{configure}. Again from @code{cpio}:
5221 @c Keep in sync with pr401c.sh
5223 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
5226 In addition, sources for extra objects that will not exist until
5227 configure-time must be added to the @code{BUILT_SOURCES} variable
5230 Building a static library is done by compiling all object files, then
5231 by invoking @samp{$(AR) $(ARFLAGS)} followed by the name of the
5232 library and the list of objects, and finally by calling
5233 @samp{$(RANLIB)} on that library. You should call
5234 @code{AC_PROG_RANLIB} from your @file{configure.ac} to define
5235 @code{RANLIB} (Automake will complain otherwise). You should also
5236 call @code{AM_PROG_AR} to define @code{AR}, in order to support unusual
5237 archivers such as Microsoft lib. @code{ARFLAGS} will default to
5238 @code{cr}; you can override this variable by setting it in your
5239 @file{Makefile.am} or by @code{AC_SUBST}ing it from your
5240 @file{configure.ac}. You can override the @code{AR} variable by
5241 defining a per-library @code{maude_AR} variable (@pxref{Program and
5242 Library Variables}).
5244 @cindex Empty libraries
5245 Be careful when selecting library components conditionally. Because
5246 building an empty library is not portable, you should ensure that any
5247 library always contains at least one object.
5249 To use a static library when building a program, add it to
5250 @code{LDADD} for this program. In the following example, the program
5251 @file{cpio} is statically linked with the library @file{libcpio.a}.
5254 noinst_LIBRARIES = libcpio.a
5255 libcpio_a_SOURCES = @dots{}
5258 cpio_SOURCES = cpio.c @dots{}
5259 cpio_LDADD = libcpio.a
5263 @node A Shared Library
5264 @section Building a Shared Library
5266 @cindex Shared libraries, support for
5268 Building shared libraries portably is a relatively complex matter.
5269 For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
5270 Libtool Manual}) was created to help build shared libraries in a
5271 platform-independent way.
5274 * Libtool Concept:: Introducing Libtool
5275 * Libtool Libraries:: Declaring Libtool Libraries
5276 * Conditional Libtool Libraries:: Building Libtool Libraries Conditionally
5277 * Conditional Libtool Sources:: Choosing Library Sources Conditionally
5278 * Libtool Convenience Libraries:: Building Convenience Libtool Libraries
5279 * Libtool Modules:: Building Libtool Modules
5280 * Libtool Flags:: Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
5281 * LTLIBOBJS:: Using $(LTLIBOBJS) and $(LTALLOCA)
5282 * Libtool Issues:: Common Issues Related to Libtool's Use
5285 @node Libtool Concept
5286 @subsection The Libtool Concept
5288 @cindex @command{libtool}, introduction
5289 @cindex libtool library, definition
5290 @cindex suffix @file{.la}, defined
5291 @cindex @file{.la} suffix, defined
5293 Libtool abstracts shared and static libraries into a unified concept
5294 henceforth called @dfn{libtool libraries}. Libtool libraries are
5295 files using the @file{.la} suffix, and can designate a static library,
5296 a shared library, or maybe both. Their exact nature cannot be
5297 determined until @file{./configure} is run: not all platforms support
5298 all kinds of libraries, and users can explicitly select which
5299 libraries should be built. (However the package's maintainers can
5300 tune the default; @pxref{LT_INIT, , The @code{LT_INIT}
5301 macro, libtool, The Libtool Manual}.)
5303 @cindex suffix @file{.lo}, defined
5304 Because object files for shared and static libraries must be compiled
5305 differently, libtool is also used during compilation. Object files
5306 built by libtool are called @dfn{libtool objects}: these are files
5307 using the @file{.lo} suffix. Libtool libraries are built from these
5310 You should not assume anything about the structure of @file{.la} or
5311 @file{.lo} files and how libtool constructs them: this is libtool's
5312 concern, and the last thing one wants is to learn about libtool's
5313 guts. However the existence of these files matters, because they are
5314 used as targets and dependencies in @file{Makefile}s' rules when
5315 building libtool libraries. There are situations where you may have
5316 to refer to these, for instance when expressing dependencies for
5317 building source files conditionally (@pxref{Conditional Libtool
5320 @cindex @file{libltdl}, introduction
5322 People considering writing a plug-in system, with dynamically loaded
5323 modules, should look into @file{libltdl}: libtool's dlopening library
5324 (@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
5325 This offers a portable dlopening facility to load libtool libraries
5326 dynamically, and can also achieve static linking where unavoidable.
5328 Before we discuss how to use libtool with Automake in detail, it
5329 should be noted that the libtool manual also has a section about how
5330 to use Automake with libtool (@pxref{Using Automake, , Using Automake
5331 with Libtool, libtool, The Libtool Manual}).
5333 @node Libtool Libraries
5334 @subsection Building Libtool Libraries
5336 @cindex @code{_LTLIBRARIES} primary, defined
5337 @cindex @code{LTLIBRARIES} primary, defined
5338 @cindex Primary variable, @code{LTLIBRARIES}
5339 @cindex Example of shared libraries
5340 @vindex lib_LTLIBRARIES
5341 @vindex pkglib_LTLIBRARIES
5342 @vindex _LTLIBRARIES
5344 Automake uses libtool to build libraries declared with the
5345 @code{LTLIBRARIES} primary. Each @code{_LTLIBRARIES} variable is a
5346 list of libtool libraries to build. For instance, to create a libtool
5347 library named @file{libgettext.la}, and install it in @code{libdir},
5351 lib_LTLIBRARIES = libgettext.la
5352 libgettext_la_SOURCES = gettext.c gettext.h @dots{}
5355 Automake predefines the variable @code{pkglibdir}, so you can use
5356 @code{pkglib_LTLIBRARIES} to install libraries in
5357 @samp{$(libdir)/@@PACKAGE@@/}.
5359 If @file{gettext.h} is a public header file that needs to be installed
5360 in order for people to use the library, it should be declared using a
5361 @code{_HEADERS} variable, not in @code{libgettext_la_SOURCES}.
5362 Headers listed in the latter should be internal headers that are not
5363 part of the public interface.
5366 lib_LTLIBRARIES = libgettext.la
5367 libgettext_la_SOURCES = gettext.c @dots{}
5368 include_HEADERS = gettext.h @dots{}
5371 A package can build and install such a library along with other
5372 programs that use it. This dependency should be specified using
5373 @code{LDADD}. The following example builds a program named
5374 @file{hello} that is linked with @file{libgettext.la}.
5377 lib_LTLIBRARIES = libgettext.la
5378 libgettext_la_SOURCES = gettext.c @dots{}
5380 bin_PROGRAMS = hello
5381 hello_SOURCES = hello.c @dots{}
5382 hello_LDADD = libgettext.la
5386 Whether @file{hello} is statically or dynamically linked with
5387 @file{libgettext.la} is not yet known: this will depend on the
5388 configuration of libtool and the capabilities of the host.
5391 @node Conditional Libtool Libraries
5392 @subsection Building Libtool Libraries Conditionally
5393 @cindex libtool libraries, conditional
5394 @cindex conditional libtool libraries
5396 Like conditional programs (@pxref{Conditional Programs}), there are
5397 two main ways to build conditional libraries: using Automake
5398 conditionals or using Autoconf @code{AC_SUBST}itutions.
5400 The important implementation detail you have to be aware of is that
5401 the place where a library will be installed matters to libtool: it
5402 needs to be indicated @emph{at link-time} using the @option{-rpath}
5405 For libraries whose destination directory is known when Automake runs,
5406 Automake will automatically supply the appropriate @option{-rpath}
5407 option to libtool. This is the case for libraries listed explicitly in
5408 some installable @code{_LTLIBRARIES} variables such as
5409 @code{lib_LTLIBRARIES}.
5411 However, for libraries determined at configure time (and thus
5412 mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
5413 final installation directory. For such libraries you must add the
5414 @option{-rpath} option to the appropriate @code{_LDFLAGS} variable by
5417 The examples below illustrate the differences between these two methods.
5419 Here is an example where @code{WANTEDLIBS} is an @code{AC_SUBST}ed
5420 variable set at @file{./configure}-time to either @file{libfoo.la},
5421 @file{libbar.la}, both, or none. Although @samp{$(WANTEDLIBS)}
5422 appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
5423 relates to @file{libfoo.la} or @file{libbar.la} at the time it creates
5424 the link rule for these two libraries. Therefore the @option{-rpath}
5425 argument must be explicitly supplied.
5427 @c Keep in sync with ltcond.sh
5429 EXTRA_LTLIBRARIES = libfoo.la libbar.la
5430 lib_LTLIBRARIES = $(WANTEDLIBS)
5431 libfoo_la_SOURCES = foo.c @dots{}
5432 libfoo_la_LDFLAGS = -rpath '$(libdir)'
5433 libbar_la_SOURCES = bar.c @dots{}
5434 libbar_la_LDFLAGS = -rpath '$(libdir)'
5437 Here is how the same @file{Makefile.am} would look using Automake
5438 conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}. Now
5439 Automake is able to compute the @option{-rpath} setting itself, because
5440 it's clear that both libraries will end up in @samp{$(libdir)} if they
5443 @c Keep in sync with ltcond.sh
5447 lib_LTLIBRARIES += libfoo.la
5450 lib_LTLIBRARIES += libbar.la
5452 libfoo_la_SOURCES = foo.c @dots{}
5453 libbar_la_SOURCES = bar.c @dots{}
5456 @node Conditional Libtool Sources
5457 @subsection Libtool Libraries with Conditional Sources
5459 Conditional compilation of sources in a library can be achieved in the
5460 same way as conditional compilation of sources in a program
5461 (@pxref{Conditional Sources}). The only difference is that
5462 @code{_LIBADD} should be used instead of @code{_LDADD} and that it
5463 should mention libtool objects (@file{.lo} files).
5465 So, to mimic the @file{hello} example from @ref{Conditional Sources},
5466 we could build a @file{libhello.la} library using either
5467 @file{hello-linux.c} or @file{hello-generic.c} with the following
5470 @c Keep in sync with ltcond2.sh
5472 lib_LTLIBRARIES = libhello.la
5473 libhello_la_SOURCES = hello-common.c
5474 EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
5475 libhello_la_LIBADD = $(HELLO_SYSTEM)
5476 libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
5480 And make sure @command{configure} defines @code{HELLO_SYSTEM} as
5481 either @file{hello-linux.lo} or @file{hello-@-generic.lo}.
5483 Or we could simply use an Automake conditional as follows.
5485 @c Keep in sync with ltcond2.sh
5487 lib_LTLIBRARIES = libhello.la
5488 libhello_la_SOURCES = hello-common.c
5490 libhello_la_SOURCES += hello-linux.c
5492 libhello_la_SOURCES += hello-generic.c
5496 @node Libtool Convenience Libraries
5497 @subsection Libtool Convenience Libraries
5498 @cindex convenience libraries, libtool
5499 @cindex libtool convenience libraries
5500 @vindex noinst_LTLIBRARIES
5501 @vindex check_LTLIBRARIES
5503 Sometimes you want to build libtool libraries that should not be
5504 installed. These are called @dfn{libtool convenience libraries} and
5505 are typically used to encapsulate many sublibraries, later gathered
5506 into one big installed library.
5508 Libtool convenience libraries are declared by directory-less variables
5509 such as @code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
5510 @code{EXTRA_LTLIBRARIES}. Unlike installed libtool libraries they do
5511 not need an @option{-rpath} flag at link time (this is in fact the only
5514 Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
5515 built. Those listed in @code{check_LTLIBRARIES} are built only upon
5516 @samp{make check}. Finally, libraries listed in
5517 @code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
5518 rules to build them, but if the library does not appear as a @file{Makefile}
5519 dependency anywhere it won't be built (this is why
5520 @code{EXTRA_LTLIBRARIES} is used for conditional compilation).
5522 Here is a sample setup merging libtool convenience libraries from
5523 subdirectories into one main @file{libtop.la} library.
5525 @c Keep in sync with ltconv.sh
5527 # -- Top-level Makefile.am --
5528 SUBDIRS = sub1 sub2 @dots{}
5529 lib_LTLIBRARIES = libtop.la
5531 libtop_la_LIBADD = \
5536 # -- sub1/Makefile.am --
5537 noinst_LTLIBRARIES = libsub1.la
5538 libsub1_la_SOURCES = @dots{}
5540 # -- sub2/Makefile.am --
5541 # showing nested convenience libraries
5542 SUBDIRS = sub2.1 sub2.2 @dots{}
5543 noinst_LTLIBRARIES = libsub2.la
5544 libsub2_la_SOURCES =
5545 libsub2_la_LIBADD = \
5551 When using such a setup, beware that @command{automake} will assume
5552 @file{libtop.la} is to be linked with the C linker. This is because
5553 @code{libtop_la_SOURCES} is empty, so @command{automake} picks C as
5554 default language. If @code{libtop_la_SOURCES} was not empty,
5555 @command{automake} would select the linker as explained in @ref{How
5556 the Linker is Chosen}.
5558 If one of the sublibraries contains non-C source, it is important that
5559 the appropriate linker be chosen. One way to achieve this is to
5560 pretend that there is such a non-C file among the sources of the
5561 library, thus forcing @command{automake} to select the appropriate
5562 linker. Here is the top-level @file{Makefile} of our example updated
5563 to force C++ linking.
5566 SUBDIRS = sub1 sub2 @dots{}
5567 lib_LTLIBRARIES = libtop.la
5569 # Dummy C++ source to cause C++ linking.
5570 nodist_EXTRA_libtop_la_SOURCES = dummy.cxx
5571 libtop_la_LIBADD = \
5577 @samp{EXTRA_*_SOURCES} variables are used to keep track of source
5578 files that might be compiled (this is mostly useful when doing
5579 conditional compilation using @code{AC_SUBST}; @pxref{Conditional
5580 Libtool Sources}), and the @code{nodist_} prefix means the listed
5581 sources are not to be distributed (@pxref{Program and Library
5582 Variables}). In effect the file @file{dummy.cxx} does not need to
5583 exist in the source tree. Of course if you have some real source file
5584 to list in @code{libtop_la_SOURCES} there is no point in cheating with
5585 @code{nodist_EXTRA_libtop_la_SOURCES}.
5588 @node Libtool Modules
5589 @subsection Libtool Modules
5590 @cindex modules, libtool
5591 @cindex libtool modules
5592 @cindex @option{-module}, libtool
5594 These are libtool libraries meant to be dlopened. They are
5595 indicated to libtool by passing @option{-module} at link-time.
5598 pkglib_LTLIBRARIES = mymodule.la
5599 mymodule_la_SOURCES = doit.c
5600 mymodule_la_LDFLAGS = -module
5603 Ordinarily, Automake requires that a library's name start with
5604 @code{lib}. However, when building a dynamically loadable module you
5605 might wish to use a "nonstandard" name. Automake will not complain
5606 about such nonstandard names if it knows the library being built is a
5607 libtool module, i.e., if @option{-module} explicitly appears in the
5608 library's @code{_LDFLAGS} variable (or in the common @code{AM_LDFLAGS}
5609 variable when no per-library @code{_LDFLAGS} variable is defined).
5611 As always, @code{AC_SUBST} variables are black boxes to Automake since
5612 their values are not yet known when @command{automake} is run.
5613 Therefore if @option{-module} is set via such a variable, Automake
5614 cannot notice it and will proceed as if the library was an ordinary
5615 libtool library, with strict naming.
5617 If @code{mymodule_la_SOURCES} is not specified, then it defaults to
5618 the single file @file{mymodule.c} (@pxref{Default _SOURCES}).
5621 @subsection @code{_LIBADD}, @code{_LDFLAGS}, and @code{_LIBTOOLFLAGS}
5622 @cindex @code{_LIBADD}, libtool
5623 @cindex @code{_LDFLAGS}, libtool
5624 @cindex @code{_LIBTOOLFLAGS}, libtool
5625 @vindex AM_LIBTOOLFLAGS
5626 @vindex LIBTOOLFLAGS
5627 @vindex maude_LIBTOOLFLAGS
5629 As shown in previous sections, the @samp{@var{library}_LIBADD}
5630 variable should be used to list extra libtool objects (@file{.lo}
5631 files) or libtool libraries (@file{.la}) to add to @var{library}.
5633 The @samp{@var{library}_LDFLAGS} variable is the place to list
5634 additional libtool linking flags, such as @option{-version-info},
5635 @option{-static}, and a lot more. @xref{Link mode, , Link mode,
5636 libtool, The Libtool Manual}.
5638 The @command{libtool} command has two kinds of options: mode-specific
5639 options and generic options. Mode-specific options such as the
5640 aforementioned linking flags should be lumped with the other flags
5641 passed to the tool invoked by @command{libtool} (hence the use of
5642 @samp{@var{library}_LDFLAGS} for libtool linking flags). Generic
5643 options include @option{--tag=@var{tag}} and @option{--silent}
5644 (@pxref{Invoking libtool, , Invoking @command{libtool}, libtool, The
5645 Libtool Manual} for more options). They should appear before the mode
5646 selection on the command line; in @file{Makefile.am}s they should
5647 be listed in the @samp{@var{library}_LIBTOOLFLAGS} variable.
5649 If @samp{@var{library}_LIBTOOLFLAGS} is not defined, then the variable
5650 @code{AM_LIBTOOLFLAGS} is used instead.
5652 These flags are passed to libtool after the @option{--tag=@var{tag}}
5653 option computed by Automake (if any), so
5654 @samp{@var{library}_LIBTOOLFLAGS} (or @code{AM_LIBTOOLFLAGS}) is a
5655 good place to override or supplement the @option{--tag=@var{tag}}
5658 The libtool rules also use a @code{LIBTOOLFLAGS} variable that should
5659 not be set in @file{Makefile.am}: this is a user variable (@pxref{Flag
5660 Variables Ordering}). It allows users to run @samp{make
5661 LIBTOOLFLAGS=--silent}, for instance. Note that the verbosity of
5662 @command{libtool} can also be influenced by the Automake support
5663 for silent rules (@pxref{Automake Silent Rules}).
5665 @node LTLIBOBJS, Libtool Issues, Libtool Flags, A Shared Library
5666 @subsection @code{LTLIBOBJS} and @code{LTALLOCA}
5667 @cindex @code{LTLIBOBJS}, special handling
5668 @cindex @code{LIBOBJS}, and Libtool
5669 @cindex @code{LTALLOCA}, special handling
5670 @cindex @code{ALLOCA}, and Libtool
5677 Where an ordinary library might include @samp{$(LIBOBJS)} or
5678 @samp{$(ALLOCA)} (@pxref{LIBOBJS}), a libtool library must use
5679 @samp{$(LTLIBOBJS)} or @samp{$(LTALLOCA)}. This is required because
5680 the object files that libtool operates on do not necessarily end in
5683 Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
5684 performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
5685 @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual}).
5687 @node Libtool Issues
5688 @subsection Common Issues Related to Libtool's Use
5691 * Error required file ltmain.sh not found:: The need to run libtoolize
5692 * Objects created both with libtool and without:: Avoid a specific build race
5695 @node Error required file ltmain.sh not found
5696 @subsubsection Error: @samp{required file `./ltmain.sh' not found}
5697 @cindex @file{ltmain.sh} not found
5698 @cindex @command{libtoolize}, no longer run by @command{automake}
5699 @cindex @command{libtoolize} and @command{autoreconf}
5700 @cindex @command{autoreconf} and @command{libtoolize}
5701 @cindex @file{bootstrap} and @command{autoreconf}
5702 @cindex @file{autogen.sh} and @command{autoreconf}
5704 Libtool comes with a tool called @command{libtoolize} that will
5705 install libtool's supporting files into a package. Running this
5706 command will install @file{ltmain.sh}. You should execute it before
5707 @command{aclocal} and @command{automake}.
5709 People upgrading old packages to newer autotools are likely to face
5710 this issue because older Automake versions used to call
5711 @command{libtoolize}. Therefore old build scripts do not call
5712 @command{libtoolize}.
5714 Since Automake 1.6, it has been decided that running
5715 @command{libtoolize} was not Automake's business. Instead, that
5716 functionality has been moved into the @command{autoreconf} command
5717 (@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
5718 The Autoconf Manual}). If you do not want to remember what to run and
5719 when, just remember the @command{autoreconf} command. Hopefully,
5720 replacing existing @file{bootstrap} or @file{autogen.sh} scripts by a
5721 call to @command{autoreconf} should also free you from any similar
5722 incompatible change in the future.
5724 @node Objects created both with libtool and without
5725 @subsubsection Objects @samp{created with both libtool and without}
5727 Sometimes, the same source file is used both to build a libtool
5728 library and to build another non-libtool target (be it a program or
5731 Let's consider the following @file{Makefile.am}.
5735 prog_SOURCES = prog.c foo.c @dots{}
5737 lib_LTLIBRARIES = libfoo.la
5738 libfoo_la_SOURCES = foo.c @dots{}
5742 (In this trivial case the issue could be avoided by linking
5743 @file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
5744 @code{prog_SOURCES}. But let's assume we want to keep @file{prog} and
5745 @file{libfoo.la} separate.)
5747 Technically, it means that we should build @file{foo.$(OBJEXT)} for
5748 @file{prog}, and @file{foo.lo} for @file{libfoo.la}. The problem is
5749 that in the course of creating @file{foo.lo}, libtool may erase (or
5750 replace) @file{foo.$(OBJEXT)}, and this cannot be avoided.
5752 Therefore, when Automake detects this situation it will complain
5753 with a message such as
5755 object 'foo.$(OBJEXT)' created both with libtool and without
5758 A workaround for this issue is to ensure that these two objects get
5759 different basenames. As explained in @ref{Renamed Objects}, this
5760 happens automatically when per-target flags are used.
5764 prog_SOURCES = prog.c foo.c @dots{}
5765 prog_CFLAGS = $(AM_CFLAGS)
5767 lib_LTLIBRARIES = libfoo.la
5768 libfoo_la_SOURCES = foo.c @dots{}
5772 Adding @samp{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
5773 when the @code{prog_CFLAGS} is defined, it is used instead of
5774 @code{AM_CFLAGS}. However as a side effect it will cause
5775 @file{prog.c} and @file{foo.c} to be compiled as
5776 @file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)}, which solves
5779 @node Program and Library Variables
5780 @section Program and Library Variables
5782 Associated with each program is a collection of variables that can be
5783 used to modify how that program is built. There is a similar list of
5784 such variables for each library. The canonical name of the program (or
5785 library) is used as a base for naming these variables.
5787 In the list below, we use the name ``maude'' to refer to the program or
5788 library. In your @file{Makefile.am} you would replace this with the
5789 canonical name of your program. This list also refers to ``maude'' as a
5790 program, but in general the same rules apply for both static and dynamic
5791 libraries; the documentation below notes situations where programs and
5796 This variable, if it exists, lists all the source files that are
5797 compiled to build the program. These files are added to the
5798 distribution by default. When building the program, Automake will cause
5799 each source file to be compiled to a single @file{.o} file (or
5800 @file{.lo} when using libtool). Normally these object files are named
5801 after the source file, but other factors can change this. If a file in
5802 the @code{_SOURCES} variable has an unrecognized extension, Automake
5803 will do one of two things with it. If a suffix rule exists for turning
5804 files with the unrecognized extension into @file{.o} files, then
5805 @command{automake} will treat this file as it will any other source file
5806 (@pxref{Support for Other Languages}). Otherwise, the file will be
5807 ignored as though it were a header file.
5809 The prefixes @code{dist_} and @code{nodist_} can be used to control
5810 whether files listed in a @code{_SOURCES} variable are distributed.
5811 @code{dist_} is redundant, as sources are distributed by default, but it
5812 can be specified for clarity if desired.
5814 It is possible to have both @code{dist_} and @code{nodist_} variants of
5815 a given @code{_SOURCES} variable at once; this lets you easily
5816 distribute some files and not others, for instance:
5819 nodist_maude_SOURCES = nodist.c
5820 dist_maude_SOURCES = dist-me.c
5823 By default the output file (on Unix systems, the @file{.o} file) will
5824 be put into the current build directory. However, if the option
5825 @option{subdir-objects} is in effect in the current directory then the
5826 @file{.o} file will be put into the subdirectory named after the
5827 source file. For instance, with @option{subdir-objects} enabled,
5828 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}. Some
5829 projects prefer or require this mode of operation. You can specify
5830 @option{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
5831 @cindex Subdirectory, objects in
5832 @cindex Objects in subdirectory
5834 @c https://bugs.gnu.org/20699
5835 When @option{subdir-objects} is specified, and source files which lie
5836 outside the current directory tree are nevertheless specified, as in
5837 @code{foo_SOURCES = ../lib/other.c}, Automake will still remove
5838 @file{../lib/other.o}, in fact, @file{../lib/*.o} (e.g., at @code{make
5839 clean}, even though it is arguably wrong for one subdirectory to
5840 clean in a sibling. This may or may not be changed in the future.
5842 @item EXTRA_maude_SOURCES
5843 Automake needs to know the list of files you intend to compile
5844 @emph{statically}. For one thing, this is the only way Automake has of
5845 knowing what sort of language support a given @file{Makefile.in}
5846 requires. (There are other, more obscure reasons for
5847 this limitation as well.) This means that, for example, you can't put a
5848 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
5849 variable. If you intend to conditionally compile source files and use
5850 @file{configure} to substitute the appropriate object names into, e.g.,
5851 @code{_LDADD} (see below), then you should list the corresponding source
5852 files in the @code{EXTRA_} variable.
5854 This variable also supports @code{dist_} and @code{nodist_} prefixes.
5855 For instance, @code{nodist_EXTRA_maude_SOURCES} would list extra
5856 sources that may need to be built, but should not be distributed.
5859 A static library is created by default by invoking @samp{$(AR)
5860 $(ARFLAGS)} followed by the name of the library and then the objects
5861 being put into the library. You can override this by setting the
5862 @code{_AR} variable. This is usually used with C++; some C++
5863 compilers require a special invocation in order to instantiate all the
5864 templates that should go into a library. For instance, the SGI C++
5865 compiler likes this variable set like so:
5867 libmaude_a_AR = $(CXX) -ar -o
5871 A static library's index is updated by default by invoking @samp{$(RANLIB)}
5872 followed by the name of the library. You can override this by setting the
5873 @code{_RANLIB} variable.
5876 Extra objects can be added to a @emph{library} using the @code{_LIBADD}
5877 variable. For instance, this should be used for objects determined by
5878 @command{configure} (@pxref{A Library}).
5880 In the case of libtool libraries, @code{maude_LIBADD} can also refer
5881 to other libtool libraries.
5884 Extra objects (@file{*.$(OBJEXT)}) and libraries (@file{*.a},
5885 @file{*.la}) can be added to a @emph{program} by listing them in the
5886 @code{_LDADD} variable. For instance, this should be used for objects
5887 determined by @command{configure} (@pxref{Linking}).
5889 @code{_LDADD} and @code{_LIBADD} are inappropriate for passing
5890 program-specific linker flags (except for @option{-l}, @option{-L},
5891 @option{-dlopen} and @option{-dlpreopen}). Use the @code{_LDFLAGS} variable
5894 For instance, if your @file{configure.ac} uses @code{AC_PATH_XTRA}, you
5895 could link your program against the X libraries like so:
5898 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
5901 We recommend that you use @option{-l} and @option{-L} only when
5902 referring to third-party libraries, and give the explicit file names
5903 of any library built by your package. Doing so will ensure that
5904 @code{maude_DEPENDENCIES} (see below) is correctly defined by default.
5907 This variable is used to pass extra flags to the link step of a program
5908 or a shared library. It overrides the @code{AM_LDFLAGS} variable,
5909 even if it is defined only in a false branch of a conditional; in
5910 other words, if @code{@var{prog}_LDFLAGS} is defined at all,
5911 @code{AM_LDFLAGS} will not be used.
5912 @c https://bugs.gnu.org/34925
5914 @item maude_LIBTOOLFLAGS
5915 This variable is used to pass extra options to @command{libtool}.
5916 It overrides the @code{AM_LIBTOOLFLAGS} variable.
5917 These options are output before @command{libtool}'s @option{--mode=@var{mode}}
5918 option, so they should not be mode-specific options (those belong to
5919 the compiler or linker flags). @xref{Libtool Flags}.
5921 @item maude_DEPENDENCIES
5922 @itemx EXTRA_maude_DEPENDENCIES
5923 It is also occasionally useful to have a target (program or library)
5924 depend on some other file that is not in fact part of that target.
5925 This can be done using the @code{_DEPENDENCIES} variable. Each
5926 target depends on the contents of such a variable, but no further
5927 interpretation is done.
5929 Since these dependencies are associated with the link rule used to
5930 create the programs they should normally list files used by the link
5931 command. That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la} files
5932 for programs; @file{*.lo} and @file{*.la} files for Libtool libraries;
5933 and @file{*.$(OBJEXT)} files for static libraries. In rare cases you
5934 may need to add other kinds of files such as linker scripts, but
5935 @emph{listing a source file in @code{_DEPENDENCIES} is wrong}. If
5936 some source file needs to be built before all the components of a
5937 program are built, consider using the @code{BUILT_SOURCES} variable
5940 If @code{_DEPENDENCIES} is not supplied, it is computed by Automake.
5941 The automatically-assigned value is the contents of @code{_LDADD} or
5942 @code{_LIBADD}, with most configure substitutions, @option{-l}, @option{-L},
5943 @option{-dlopen} and @option{-dlpreopen} options removed. The configure
5944 substitutions that are left in are only @samp{$(LIBOBJS)} and
5945 @samp{$(ALLOCA)}; these are left because it is known that they will not
5946 cause an invalid value for @code{_DEPENDENCIES} to be generated.
5948 @code{_DEPENDENCIES} is more likely used to perform conditional
5949 compilation using an @code{AC_SUBST} variable that contains a list of
5950 objects. @xref{Conditional Sources}, and @ref{Conditional Libtool
5953 The @code{EXTRA_*_DEPENDENCIES} variable may be useful for cases where
5954 you merely want to augment the @command{automake}-generated
5955 @code{_DEPENDENCIES} variable rather than replacing it.
5958 You can override the linker on a per-program basis. By default the
5959 linker is chosen according to the languages used by the program. For
5960 instance, a program that includes C++ source code would use the C++
5961 compiler to link. The @code{_LINK} variable must hold the name of a
5962 command that can be passed all the @file{.o} file names and libraries
5963 to link against as arguments. Note that the name of the underlying
5964 program is @emph{not} passed to @code{_LINK}; typically one uses
5968 maude_LINK = $(CCLD) -magic -o $@@
5971 If a @code{_LINK} variable is not supplied, it may still be generated
5972 and used by Automake due to the use of per-target link flags such as
5973 @code{_CFLAGS}, @code{_LDFLAGS} or @code{_LIBTOOLFLAGS}, in cases where
5976 If the variable @code{AM_V_*_LINK} exists, it is used to output a
5977 status line in silent mode; otherwise, @code{AM_V_GEN} is used.
5979 @item maude_CCASFLAGS
5981 @itemx maude_CPPFLAGS
5982 @itemx maude_CXXFLAGS
5984 @itemx maude_GCJFLAGS
5986 @itemx maude_OBJCFLAGS
5987 @itemx maude_OBJCXXFLAGS
5989 @itemx maude_UPCFLAGS
5991 @cindex per-target compilation flags, defined
5992 Automake allows you to set compilation flags on a per-program (or
5993 per-library) basis. A single source file can be included in several
5994 programs, and it will potentially be compiled with different flags for
5995 each program. This works for any language directly supported by
5996 Automake. These @dfn{per-target compilation flags} are
6005 @samp{_OBJCXXFLAGS},
6007 @samp{_UPCFLAGS}, and
6010 When using a per-target compilation flag, Automake will choose a
6011 different name for the intermediate object files. Ordinarily a file
6012 like @file{sample.c} will be compiled to produce @file{sample.o}.
6013 However, if the program's @code{_CFLAGS} variable is set, then the
6014 object file will be named, for instance, @file{maude-sample.o}. (See
6015 also @ref{Renamed Objects}.)
6017 In compilations with per-target flags, the ordinary @samp{AM_} form of
6018 the flags variable is @emph{not} automatically included in the
6019 compilation (however, the user form of the variable @emph{is} included).
6020 So for instance, if you want the hypothetical @file{maude} compilations
6021 to also use the value of @code{AM_CFLAGS}, you would need to write:
6024 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
6027 @xref{Flag Variables Ordering}, for more discussion about the
6028 interaction between user variables, @samp{AM_} shadow variables, and
6029 per-target variables.
6031 @item maude_SHORTNAME
6032 On some platforms the allowable file names are very short. In order to
6033 support these systems and per-target compilation flags at the same
6034 time, Automake allows you to set a ``short name'' that will influence
6035 how intermediate object files are named. For instance, in the following
6039 bin_PROGRAMS = maude
6040 maude_CPPFLAGS = -DSOMEFLAG
6042 maude_SOURCES = sample.c @dots{}
6046 the object file would be named @file{m-sample.o} rather than
6047 @file{maude-sample.o}.
6049 This facility is rarely needed in practice,
6050 and we recommend avoiding it until you find it is required.
6053 @node Default _SOURCES
6054 @section Default @code{_SOURCES}
6058 @cindex @code{_SOURCES}, default
6059 @cindex default @code{_SOURCES}
6060 @vindex AM_DEFAULT_SOURCE_EXT
6062 @code{_SOURCES} variables are used to specify source files of programs
6063 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
6064 libraries (@pxref{A Shared Library}).
6066 When no such variable is specified for a target, Automake will define
6067 one itself. The default is to compile a single C file whose base name
6068 is the name of the target itself, with any extension replaced by
6069 @code{AM_DEFAULT_SOURCE_EXT}, which defaults to @file{.c}.
6071 For example if you have the following somewhere in your
6072 @file{Makefile.am} with no corresponding @code{libfoo_a_SOURCES}:
6075 lib_LIBRARIES = libfoo.a sub/libc++.a
6079 @file{libfoo.a} will be built using a default source file named
6080 @file{libfoo.c}, and @file{sub/libc++.a} will be built from
6081 @file{sub/libc++.c}. (In older versions @file{sub/libc++.a}
6082 would be built from @file{sub_libc___a.c}, i.e., the default source
6083 was the canonicalized name of the target, with @file{.c} appended.
6084 We believe the new behavior is more sensible, but for backward
6085 compatibility @command{automake} will use the old name if a file or a rule
6086 with that name exists and @code{AM_DEFAULT_SOURCE_EXT} is not used.)
6088 @cindex @code{check_PROGRAMS} example
6089 @vindex check_PROGRAMS
6090 Default sources are mainly useful in test suites, when building many
6091 test programs each from a single source. For instance, in
6094 check_PROGRAMS = test1 test2 test3
6095 AM_DEFAULT_SOURCE_EXT = .cpp
6099 @file{test1}, @file{test2}, and @file{test3} will be built
6100 from @file{test1.cpp}, @file{test2.cpp}, and @file{test3.cpp}.
6101 Without the last line, they will be built from @file{test1.c},
6102 @file{test2.c}, and @file{test3.c}.
6104 @cindex Libtool modules, default source example
6105 @cindex default source, Libtool modules example
6106 Another case where this is convenient is building many Libtool modules
6107 (@file{module@var{n}.la}), each defined in its own file
6108 (@file{module@var{n}.c}).
6111 AM_LDFLAGS = -module
6112 lib_LTLIBRARIES = module1.la module2.la module3.la
6115 @cindex empty @code{_SOURCES}
6116 @cindex @code{_SOURCES}, empty
6117 Finally, there is one situation where this default source computation
6118 needs to be avoided: when a target should not be built from sources.
6119 We already saw such an example in @ref{true}; this happens when all
6120 the constituents of a target have already been compiled and just need
6121 to be combined using a @code{_LDADD} variable. Then it is necessary
6122 to define an empty @code{_SOURCES} variable, so that @command{automake}
6123 does not compute a default.
6126 bin_PROGRAMS = target
6128 target_LDADD = libmain.a libmisc.a
6132 @section Special handling for @code{LIBOBJS} and @code{ALLOCA}
6134 @cindex @code{LIBOBJS}, example
6135 @cindex @code{ALLOCA}, example
6136 @cindex @code{LIBOBJS}, special handling
6137 @cindex @code{ALLOCA}, special handling
6143 The @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} variables list object
6144 files that should be compiled into the project to provide an
6145 implementation for functions that are missing or broken on the host
6146 system. They are substituted by @file{configure}.
6150 These variables are defined by Autoconf macros such as
6151 @code{AC_LIBOBJ}, @code{AC_REPLACE_FUNCS} (@pxref{Generic Functions, ,
6152 Generic Function Checks, autoconf, The Autoconf Manual}), or
6153 @code{AC_FUNC_ALLOCA} (@pxref{Particular Functions, , Particular
6154 Function Checks, autoconf, The Autoconf Manual}). Many other Autoconf
6155 macros call @code{AC_LIBOBJ} or @code{AC_REPLACE_FUNCS} to
6156 populate @samp{$(LIBOBJS)}.
6158 @acindex AC_LIBSOURCE
6160 Using these variables is very similar to doing conditional compilation
6161 using @code{AC_SUBST} variables, as described in @ref{Conditional
6162 Sources}. That is, when building a program, @samp{$(LIBOBJS)} and
6163 @samp{$(ALLOCA)} should be added to the associated @samp{*_LDADD}
6164 variable, or to the @samp{*_LIBADD} variable when building a library.
6165 However there is no need to list the corresponding sources in
6166 @samp{EXTRA_*_SOURCES} nor to define @samp{*_DEPENDENCIES}. Automake
6167 automatically adds @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} to the
6168 dependencies, and it will discover the list of corresponding source
6169 files automatically (by tracing the invocations of the
6170 @code{AC_LIBSOURCE} Autoconf macros). If you have already defined
6171 @samp{*_DEPENDENCIES} explicitly for an unrelated reason, then you
6172 either need to add these variables manually, or use
6173 @samp{EXTRA_*_DEPENDENCIES} instead of @samp{*_DEPENDENCIES}.
6175 These variables are usually used to build a portability library that
6176 is linked with all the programs of the project. We now review a
6177 sample setup. First, @file{configure.ac} contains some checks that
6178 affect either @code{LIBOBJS} or @code{ALLOCA}.
6183 AC_CONFIG_LIBOBJ_DIR([lib])
6185 AC_FUNC_MALLOC dnl May add malloc.$(OBJEXT) to LIBOBJS
6186 AC_FUNC_MEMCMP dnl May add memcmp.$(OBJEXT) to LIBOBJS
6187 AC_REPLACE_FUNCS([strdup]) dnl May add strdup.$(OBJEXT) to LIBOBJS
6188 AC_FUNC_ALLOCA dnl May add alloca.$(OBJEXT) to ALLOCA
6197 @acindex AC_CONFIG_LIBOBJ_DIR
6199 The @code{AC_CONFIG_LIBOBJ_DIR} tells Autoconf that the source files
6200 of these object files are to be found in the @file{lib/} directory.
6201 Automake can also use this information, otherwise it expects the
6202 source files are to be in the directory where the @samp{$(LIBOBJS)}
6203 and @samp{$(ALLOCA)} variables are used.
6205 The @file{lib/} directory should therefore contain @file{malloc.c},
6206 @file{memcmp.c}, @file{strdup.c}, @file{alloca.c}. Here is its
6212 noinst_LIBRARIES = libcompat.a
6213 libcompat_a_SOURCES =
6214 libcompat_a_LIBADD = $(LIBOBJS) $(ALLOCA)
6217 The library can have any name, of course, and anyway it is not going
6218 to be installed: it just holds the replacement versions of the missing
6219 or broken functions so we can later link them in. Many projects
6220 also include extra functions, specific to the project, in that
6221 library: they are simply added on the @code{_SOURCES} line.
6223 @cindex Empty libraries and @samp{$(LIBOBJS)}
6224 @cindex @samp{$(LIBOBJS)} and empty libraries
6225 There is a small trap here, though: @samp{$(LIBOBJS)} and
6226 @samp{$(ALLOCA)} might be empty, and building an empty library is not
6227 portable. You should ensure that there is always something to put in
6228 @file{libcompat.a}. Most projects will also add some utility
6229 functions in that directory, and list them in
6230 @code{libcompat_a_SOURCES}, so in practice @file{libcompat.a} cannot
6233 Finally here is how this library could be used from the @file{src/}
6239 # Link all programs in this directory with libcompat.a
6240 LDADD = ../lib/libcompat.a
6242 bin_PROGRAMS = tool1 tool2 @dots{}
6243 tool1_SOURCES = @dots{}
6244 tool2_SOURCES = @dots{}
6247 When option @option{subdir-objects} is not used, as in the above
6248 example, the variables @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} can only
6249 be used in the directory where their sources lie. E.g., here it would
6250 be wrong to use @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} in
6251 @file{src/Makefile.am}. However if both @option{subdir-objects} and
6252 @code{AC_CONFIG_LIBOBJ_DIR} are used, it is OK to use these variables
6253 in other directories. For instance @file{src/Makefile.am} could be
6259 AUTOMAKE_OPTIONS = subdir-objects
6260 LDADD = $(LIBOBJS) $(ALLOCA)
6262 bin_PROGRAMS = tool1 tool2 @dots{}
6263 tool1_SOURCES = @dots{}
6264 tool2_SOURCES = @dots{}
6267 Because @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} contain object
6268 file names that end with @samp{.$(OBJEXT)}, they are not suitable for
6269 Libtool libraries (where the expected object extension is @file{.lo}):
6270 @code{LTLIBOBJS} and @code{LTALLOCA} should be used instead.
6272 @code{LTLIBOBJS} is defined automatically by Autoconf and should not
6273 be defined by hand (as in the past), however at the time of writing
6274 @code{LTALLOCA} still needs to be defined from @code{ALLOCA} manually.
6275 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
6276 autoconf, The Autoconf Manual}.
6279 @node Program Variables
6280 @section Variables used when building a program
6282 Occasionally it is useful to know which @file{Makefile} variables
6283 Automake uses for compilations, and in which order (@pxref{Flag
6284 Variables Ordering}); for instance, you might need to do your own
6285 compilation in some special cases.
6287 Some variables are inherited from Autoconf; these are @code{CC},
6288 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
6297 There are some additional variables that Automake defines on its own:
6301 The contents of this variable are passed to every compilation that invokes
6302 the C preprocessor; it is a list of arguments to the preprocessor. For
6303 instance, @option{-I} and @option{-D} options should be listed here.
6305 Automake already provides some @option{-I} options automatically, in a
6306 separate variable that is also passed to every compilation that invokes
6307 the C preprocessor. In particular it generates @samp{-I.},
6308 @samp{-I$(srcdir)}, and a @option{-I} pointing to the directory holding
6309 @file{config.h} (if you've used @code{AC_CONFIG_HEADERS}). You can
6310 disable the default @option{-I} options using the @option{nostdinc}
6313 When a file to be included is generated during the build and not part
6314 of a distribution tarball, its location is under @code{$(builddir)},
6315 not under @code{$(srcdir)}. This matters especially for packages that
6316 use header files placed in sub-directories and want to allow builds
6317 outside the source tree (@pxref{VPATH Builds}). In that case we
6318 recommend using a pair of @option{-I} options, such as, e.g.,
6319 @samp{-Isome/subdir -I$(srcdir)/some/subdir} or
6320 @samp{-I$(top_builddir)/some/subdir -I$(top_srcdir)/some/subdir}.
6321 Note that the reference to the build tree should come before the
6322 reference to the source tree, so that accidentally leftover generated
6323 files in the source directory are ignored.
6325 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
6326 per-library) @code{_CPPFLAGS} variable if it is defined.
6329 This does the same job as @code{AM_CPPFLAGS} (or any per-target
6330 @code{_CPPFLAGS} variable if it is used). It is an older name for the
6331 same functionality. This variable is deprecated; we suggest using
6332 @code{AM_CPPFLAGS} and per-target @code{_CPPFLAGS} instead.
6335 This is the variable the @file{Makefile.am} author can use to pass
6336 in additional C compiler flags. In some situations, this is
6337 not used, in preference to the per-executable (or per-library)
6341 This is the command used to compile a C source file. The file name is
6342 appended to form the complete command line.
6345 This is the variable the @file{Makefile.am} author can use to pass
6346 in additional linker flags. In some situations, this is not used, in
6347 preference to the per-executable (or per-library) @code{_LDFLAGS}.
6350 This is the command used to link a C program. It already includes
6351 @samp{-o $@@} and the usual variable references (for instance,
6352 @code{CFLAGS}); it takes as ``arguments'' the names of the object
6353 files and libraries to link in. This variable is not used when the
6354 linker is overridden with a per-target @code{_LINK} variable or
6355 per-target flags cause Automake to define such a @code{_LINK}
6361 @section Yacc and Lex support
6363 Automake has somewhat idiosyncratic support for Yacc and Lex.
6365 Automake assumes that the @file{.c} file generated by @command{yacc}
6366 or @command{lex} should be named using the basename of the input
6367 file. That is, for a Yacc source file @file{foo.y}, Automake will
6368 cause the intermediate file to be named @file{foo.c} (as opposed to
6369 @file{y.tab.c}, which is more traditional).
6371 The extension of a Yacc source file is used to determine the extension
6372 of the resulting C or C++ source and header files. Be aware that header
6373 files are generated only when the option @option{-d} is given to Yacc; see
6374 below for more information about this flag, and how to specify it.
6375 Files with the extension @file{.y} will thus be turned into @file{.c}
6376 sources and @file{.h} headers; likewise, @file{.yy} will become
6377 @file{.cc} and @file{.hh}, @file{.y++} will become @file{c++} and
6378 @file{h++}, @file{.yxx} will become @file{.cxx} and @file{.hxx},
6379 and @file{.ypp} will become @file{.cpp} and @file{.hpp}.
6381 Similarly, Lex source files can be used to generate C or C++; the
6382 extensions @file{.l}, @file{.ll}, @file{.l++}, @file{.lxx}, and
6383 @file{.lpp} are recognized.
6385 You should never explicitly mention the intermediate (C or C++) file
6386 in any @code{SOURCES} variable (except @code{BUILT_SOURCES}, see below);
6387 only list the source file.
6389 The intermediate files generated by @command{yacc} (or @command{lex})
6390 will be included in any distribution that is made. That way the user
6391 doesn't need to have @command{yacc} or @command{lex}.
6393 If a Yacc source file is seen, then your @file{configure.ac} must
6394 define the variable @code{YACC}. This is most easily done by invoking
6395 the macro @code{AC_PROG_YACC} (@pxref{Particular Programs, ,
6396 Particular Program Checks, autoconf, The Autoconf Manual}).
6400 When @code{yacc} is invoked, it is passed @code{AM_YFLAGS} and
6401 @code{YFLAGS}. The latter is a user variable and the former is
6402 intended for the @file{Makefile.am} author.
6404 @code{AM_YFLAGS} is usually used to pass the @option{-d} option to
6405 @command{yacc}. Automake knows what this means and will automatically
6406 adjust its rules to update and distribute the header file built by
6407 @samp{yacc -d}. Caveat: @command{automake} recognizes @option{-d} in
6408 @code{AM_YFLAGS} only if it is not clustered with other options; for
6409 example, it won't be recognized if @code{AM_YFLAGS} is @option{-dt},
6410 but it will be if @code{AM_YFLAGS} is @option{-d -t} or @option{-t
6413 What Automake cannot guess, though, is where this header will be used:
6414 it is up to you to ensure the header gets built before it is first
6415 used. Typically this is necessary in order for dependency tracking to
6416 work when the header is included by another file. The common solution
6417 is listing the header file, and the corresponding C file, in
6418 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
6421 BUILT_SOURCES = parser.h parser.c
6424 foo_SOURCES = @dots{} parser.y @dots{}
6427 If a Lex source file is seen, then your @file{configure.ac} must
6428 define the variable @code{LEX}. You can use @code{AC_PROG_LEX} to do
6429 this (@pxref{Particular Programs, , Particular Program Checks,
6430 autoconf, The Autoconf Manual}), but using the @code{AM_PROG_LEX}
6431 macro (@pxref{Macros}) is recommended.
6435 When @command{lex} is invoked, it is passed @code{AM_LFLAGS} and
6436 @code{LFLAGS}. The latter is a user variable and the former is
6437 intended for the @file{Makefile.am} author.
6439 When @code{AM_MAINTAINER_MODE} (@pxref{maintainer-mode}) is in effect,
6440 the rebuild rules for distributed Yacc and Lex sources are only used
6441 when @code{maintainer-mode} is enabled, or when the files have been
6444 @cindex @command{ylwrap}
6445 @cindex @command{yacc}, multiple parsers
6446 @cindex Multiple @command{yacc} parsers
6447 @cindex Multiple @command{lex} lexers
6448 @cindex @command{lex}, multiple lexers
6450 When Yacc or Lex sources are used, @code{automake -a} automatically
6451 installs an auxiliary program called @command{ylwrap} in your package
6452 (@pxref{Auxiliary Programs}). This program is used by the build rules
6453 to rename the output of these tools, and makes it possible to include
6454 multiple @command{yacc} (or @command{lex}) source files in a single
6455 directory. This is necessary because Yacc's output file name is
6456 fixed, and a parallel make could invoke more than one instance of
6457 @command{yacc} simultaneously.
6460 * Linking Multiple Yacc Parsers::
6463 @node Linking Multiple Yacc Parsers
6464 @subsection Linking Multiple Yacc Parsers
6466 @cindex Linking multiple @command{yacc} parsers
6468 For @command{yacc}, simply managing locking as with @code{ylwrap} is
6469 insufficient. The output of @command{yacc} always uses the same
6470 symbol names internally, so it isn't possible to link two
6471 @command{yacc} parsers into the same executable.
6473 We recommend using the following renaming hack used in @command{gdb}:
6475 #define yymaxdepth c_maxdepth
6476 #define yyparse c_parse
6478 #define yyerror c_error
6479 #define yylval c_lval
6480 #define yychar c_char
6481 #define yydebug c_debug
6482 #define yypact c_pact
6489 #define yyexca c_exca
6490 #define yyerrflag c_errflag
6491 #define yynerrs c_nerrs
6495 #define yy_yys c_yys
6496 #define yystate c_state
6499 #define yy_yyv c_yyv
6501 #define yylloc c_lloc
6502 #define yyreds c_reds
6503 #define yytoks c_toks
6504 #define yylhs c_yylhs
6505 #define yylen c_yylen
6506 #define yydefred c_yydefred
6507 #define yydgoto c_yydgoto
6508 #define yysindex c_yysindex
6509 #define yyrindex c_yyrindex
6510 #define yygindex c_yygindex
6511 #define yytable c_yytable
6512 #define yycheck c_yycheck
6513 #define yyname c_yyname
6514 #define yyrule c_yyrule
6517 For each define, replace the @samp{c_} prefix with whatever you like.
6518 These defines work for @command{bison}, @command{byacc}, and
6519 traditional @code{yacc}s. If you find a parser generator that uses a
6520 symbol not covered here, please report the new name so it can be added
6525 @section C++ Support
6528 @cindex Support for C++
6530 Automake includes full support for C++.
6532 Any package including C++ code must define the output variable
6533 @code{CXX} in @file{configure.ac}; the simplest way to do this is to use
6534 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
6535 Program Checks, autoconf, The Autoconf Manual}).
6537 A few additional variables are defined when a C++ source file is seen:
6541 The name of the C++ compiler.
6544 Any flags to pass to the C++ compiler.
6547 The maintainer's variant of @code{CXXFLAGS}.
6550 The command used to compile a C++ source file. The file name is
6551 appended to form the complete command line.
6554 The command used to link a C++ program.
6558 @node Objective C Support
6559 @section Objective C Support
6561 @cindex Objective C support
6562 @cindex Support for Objective C
6564 Automake includes some support for Objective C.
6566 Any package including Objective C code must define the output variable
6567 @code{OBJC} in @file{configure.ac}; the simplest way to do this is to use
6568 the @code{AC_PROG_OBJC} macro (@pxref{Particular Programs, , Particular
6569 Program Checks, autoconf, The Autoconf Manual}).
6571 A few additional variables are defined when an Objective C source file
6576 The name of the Objective C compiler.
6579 Any flags to pass to the Objective C compiler.
6582 The maintainer's variant of @code{OBJCFLAGS}.
6585 The command used to compile an Objective C source file. The file name
6586 is appended to form the complete command line.
6589 The command used to link an Objective C program.
6593 @node Objective C++ Support
6594 @section Objective C++ Support
6596 @cindex Objective C++ support
6597 @cindex Support for Objective C++
6599 Automake includes some support for Objective C++.
6601 Any package including Objective C++ code must define the output variable
6602 @code{OBJCXX} in @file{configure.ac}; the simplest way to do this is to use
6603 the @code{AC_PROG_OBJCXX} macro (@pxref{Particular Programs, , Particular
6604 Program Checks, autoconf, The Autoconf Manual}).
6606 A few additional variables are defined when an Objective C++ source file
6611 The name of the Objective C++ compiler.
6614 Any flags to pass to the Objective C++ compiler.
6616 @item AM_OBJCXXFLAGS
6617 The maintainer's variant of @code{OBJCXXFLAGS}.
6620 The command used to compile an Objective C++ source file. The file
6621 name is appended to form the complete command line.
6624 The command used to link an Objective C++ program.
6628 @node Unified Parallel C Support
6629 @section Unified Parallel C Support
6631 @cindex Unified Parallel C support
6632 @cindex Support for Unified Parallel C
6634 Automake includes some support for Unified Parallel C.
6636 Any package including Unified Parallel C code must define the output
6637 variable @code{UPC} in @file{configure.ac}; the simplest way to do
6638 this is to use the @code{AM_PROG_UPC} macro (@pxref{Public Macros}).
6640 A few additional variables are defined when a Unified Parallel C
6641 source file is seen:
6645 The name of the Unified Parallel C compiler.
6648 Any flags to pass to the Unified Parallel C compiler.
6651 The maintainer's variant of @code{UPCFLAGS}.
6654 The command used to compile a Unified Parallel C source file. The
6655 file name is appended to form the complete command line.
6658 The command used to link a Unified Parallel C program.
6662 @node Assembly Support
6663 @section Assembly Support
6665 Automake includes some support for assembly code. There are two forms
6666 of assembler files: normal (@file{*.s}) and preprocessed by @code{CPP}
6667 (@file{*.S} or @file{*.sx}).
6672 @vindex AM_CCASFLAGS
6674 The variable @code{CCAS} holds the name of the compiler used to build
6675 assembly code. This compiler must work a bit like a C compiler; in
6676 particular it must accept @option{-c} and @option{-o}. The values of
6677 @code{CCASFLAGS} and @code{AM_CCASFLAGS} (or its per-target
6678 definition) is passed to the compilation. For preprocessed files,
6679 @code{DEFS}, @code{DEFAULT_INCLUDES}, @code{INCLUDES}, @code{CPPFLAGS}
6680 and @code{AM_CPPFLAGS} are also used.
6682 The autoconf macro @code{AM_PROG_AS} will define @code{CCAS} and
6683 @code{CCASFLAGS} for you (unless they are already set, it simply sets
6684 @code{CCAS} to the C compiler and @code{CCASFLAGS} to the C compiler
6685 flags), but you are free to define these variables by other means.
6687 Only the suffixes @file{.s}, @file{.S}, and @file{.sx} are recognized by
6688 @command{automake} as being files containing assembly code.
6691 @node Fortran 77 Support
6692 @comment node-name, next, previous, up
6693 @section Fortran 77 Support
6695 @cindex Fortran 77 support
6696 @cindex Support for Fortran 77
6698 Automake includes full support for Fortran 77.
6700 Any package including Fortran 77 code must define the output variable
6701 @code{F77} in @file{configure.ac}; the simplest way to do this is to use
6702 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
6703 Program Checks, autoconf, The Autoconf Manual}).
6705 A few additional variables are defined when a Fortran 77 source file is
6711 The name of the Fortran 77 compiler.
6714 Any flags to pass to the Fortran 77 compiler.
6717 The maintainer's variant of @code{FFLAGS}.
6720 Any flags to pass to the Ratfor compiler.
6723 The maintainer's variant of @code{RFLAGS}.
6726 The command used to compile a Fortran 77 source file. The file name
6727 is appended to form the complete command line.
6730 The command used to link a pure Fortran 77 program or shared library.
6733 Automake can handle preprocessing Fortran 77 and Ratfor source files in
6734 addition to compiling them@footnote{Much, if not most, of the
6735 information in the following sections pertaining to preprocessing
6736 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
6737 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}. Automake
6738 also contains some support for creating programs and shared libraries
6739 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
6740 Fortran 77 With C and C++}).
6742 These issues are covered in the following sections.
6745 * Preprocessing Fortran 77:: Preprocessing Fortran 77 sources
6746 * Compiling Fortran 77 Files:: Compiling Fortran 77 sources
6747 * Mixing Fortran 77 With C and C++:: Mixing Fortran 77 With C and C++
6751 @node Preprocessing Fortran 77
6752 @comment node-name, next, previous, up
6753 @subsection Preprocessing Fortran 77
6755 @cindex Preprocessing Fortran 77
6756 @cindex Fortran 77, Preprocessing
6757 @cindex Ratfor programs
6759 @file{N.f} is made automatically from @file{N.F} or @file{N.r}. This
6760 rule runs just the preprocessor to convert a preprocessable Fortran 77
6761 or Ratfor source file into a strict Fortran 77 source file. The precise
6762 command used is as follows:
6767 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6768 $(AM_FFLAGS) $(FFLAGS)}
6771 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6776 @node Compiling Fortran 77 Files
6777 @comment node-name, next, previous, up
6778 @subsection Compiling Fortran 77 Files
6780 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
6781 @file{N.r} by running the Fortran 77 compiler. The precise command used
6787 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
6790 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6791 $(AM_FFLAGS) $(FFLAGS)}
6794 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6799 @node Mixing Fortran 77 With C and C++
6800 @comment node-name, next, previous, up
6801 @subsection Mixing Fortran 77 With C and C++
6803 @cindex Fortran 77, mixing with C and C++
6804 @cindex Mixing Fortran 77 with C and C++
6805 @cindex Linking Fortran 77 with C and C++
6807 @cindex Mixing Fortran 77 with C and/or C++
6809 Automake currently provides @emph{limited} support for creating programs
6810 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
6811 However, there are many other issues related to mixing Fortran 77 with
6812 other languages that are @emph{not} (currently) handled by Automake, but
6813 that are handled by other packages@footnote{For example,
6814 @uref{https://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
6815 addresses all of these inter-language issues, and runs under nearly all
6816 Fortran 77, C and C++ compilers on nearly all platforms. However,
6817 @command{cfortran} is not yet Free Software, but it will be in the next
6820 Automake can help in two ways:
6824 Automatic selection of the linker depending on which combinations of
6828 Automatic selection of the appropriate linker flags (e.g., @option{-L} and
6829 @option{-l}) to pass to the automatically selected linker in order to link
6830 in the appropriate Fortran 77 intrinsic and run-time libraries.
6832 @cindex @code{FLIBS}, defined
6834 These extra Fortran 77 linker flags are supplied in the output variable
6835 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro.
6836 @xref{Fortran Compiler, , Fortran Compiler Characteristics, autoconf,
6837 The Autoconf Manual}.
6840 If Automake detects that a program or shared library (as mentioned in
6841 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
6842 code that is a mixture of Fortran 77 and C and/or C++, then it requires
6843 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
6844 @file{configure.ac}, and that either @code{$(FLIBS)}
6845 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
6846 (for shared libraries) variables. It is the responsibility of the
6847 person writing the @file{Makefile.am} to make sure that @samp{$(FLIBS)}
6848 appears in the appropriate @code{_LDADD} or
6849 @code{_LIBADD} variable.
6851 @cindex Mixed language example
6852 @cindex Example, mixed language
6854 For example, consider the following @file{Makefile.am}:
6858 foo_SOURCES = main.cc foo.f
6859 foo_LDADD = libfoo.la $(FLIBS)
6861 pkglib_LTLIBRARIES = libfoo.la
6862 libfoo_la_SOURCES = bar.f baz.c zardoz.cc
6863 libfoo_la_LIBADD = $(FLIBS)
6866 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
6867 is mentioned in @file{configure.ac}. Also, if @samp{$(FLIBS)} hadn't
6868 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
6869 Automake would have issued a warning.
6872 * How the Linker is Chosen:: Automatic linker selection
6875 @node How the Linker is Chosen
6876 @comment node-name, next, previous, up
6877 @subsubsection How the Linker is Chosen
6879 @cindex Automatic linker selection
6880 @cindex Selecting the linker automatically
6882 When a program or library mixes several languages, Automake chooses the
6883 linker according to the following priorities. (The names in
6884 parentheses are the variables containing the link command.)
6889 Native Java (@code{GCJLINK})
6892 Objective C++ (@code{OBJCXXLINK})
6895 C++ (@code{CXXLINK})
6898 Fortran 77 (@code{F77LINK})
6901 Fortran (@code{FCLINK})
6904 Objective C (@code{OBJCLINK})
6907 Unified Parallel C (@code{UPCLINK})
6913 For example, if Fortran 77, C and C++ source code is compiled
6914 into a program, then the C++ linker will be used. In this case, if the
6915 C or Fortran 77 linkers required any special libraries that weren't
6916 included by the C++ linker, then they must be manually added to an
6917 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
6920 Automake only looks at the file names listed in @file{_SOURCES}
6921 variables to choose the linker, and defaults to the C linker.
6922 Sometimes this is inconvenient because you are linking against a
6923 library written in another language and would like to set the linker
6924 more appropriately. @xref{Libtool Convenience Libraries}, for a
6925 trick with @code{nodist_EXTRA_@dots{}_SOURCES}.
6927 A per-target @code{_LINK} variable will override the above selection.
6928 Per-target link flags will cause Automake to write a per-target
6929 @code{_LINK} variable according to the language chosen as above.
6932 @node Fortran 9x Support
6933 @comment node-name, next, previous, up
6934 @section Fortran 9x Support
6936 @cindex Fortran 9x support
6937 @cindex Support for Fortran 9x
6939 Automake includes support for Fortran 9x.
6941 Any package including Fortran 9x code must define the output variable
6942 @code{FC} in @file{configure.ac}; the simplest way to do this is to use
6943 the @code{AC_PROG_FC} macro (@pxref{Particular Programs, , Particular
6944 Program Checks, autoconf, The Autoconf Manual}).
6946 A few additional variables are defined when a Fortran 9x source file is
6952 The name of the Fortran 9x compiler.
6955 Any flags to pass to the Fortran 9x compiler.
6958 The maintainer's variant of @code{FCFLAGS}.
6961 The command used to compile a Fortran 9x source file. The file name
6962 is appended to form the complete command line.
6965 The command used to link a pure Fortran 9x program or shared library.
6969 * Compiling Fortran 9x Files:: Compiling Fortran 9x sources
6972 @node Compiling Fortran 9x Files
6973 @comment node-name, next, previous, up
6974 @subsection Compiling Fortran 9x Files
6976 @file{@var{file}.o} is made automatically from @file{@var{file}.f90},
6977 @file{@var{file}.f95}, @file{@var{file}.f03}, or @file{@var{file}.f08}
6978 by running the Fortran 9x compiler. The precise command used
6984 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f90) $<}
6987 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f95) $<}
6990 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f03) $<}
6993 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f08) $<}
6997 @node Java Support with gcj
6998 @comment node-name, next, previous, up
6999 @section Compiling Java sources using gcj
7001 @cindex Java support with gcj
7002 @cindex Support for Java with gcj
7003 @cindex Java to native code, compilation
7004 @cindex Compilation of Java to native code
7006 Automake includes support for natively compiled Java, using @command{gcj},
7007 the Java front end to the GNU Compiler Collection (rudimentary support
7008 for compiling Java to bytecode using the @command{javac} compiler is
7009 also present, @emph{albeit deprecated}; @pxref{Java}).
7011 Any package including Java code to be compiled must define the output
7012 variable @code{GCJ} in @file{configure.ac}; the variable @code{GCJFLAGS}
7013 must also be defined somehow (either in @file{configure.ac} or
7014 @file{Makefile.am}). The simplest way to do this is to use the
7015 @code{AM_PROG_GCJ} macro.
7019 By default, programs including Java source files are linked with
7022 As always, the contents of @code{AM_GCJFLAGS} are passed to every
7023 compilation invoking @command{gcj} (in its role as an ahead-of-time
7024 compiler, when invoking it to create @file{.class} files,
7025 @code{AM_JAVACFLAGS} is used instead). If it is necessary to pass
7026 options to @command{gcj} from @file{Makefile.am}, this variable, and not
7027 the user variable @code{GCJFLAGS}, should be used.
7031 @command{gcj} can be used to compile @file{.java}, @file{.class},
7032 @file{.zip}, or @file{.jar} files.
7034 When linking, @command{gcj} requires that the main class be specified
7035 using the @option{--main=} option. The easiest way to do this is to use
7036 the @code{_LDFLAGS} variable for the program.
7040 @section Vala Support
7042 @cindex Vala support
7043 @cindex Support for Vala
7044 @cindex GNU Make, required by Vala
7046 Automake supports Vala (@uref{https://vala.dev/}).
7047 Vala support requires the user to use GNU @command{make}.
7050 foo_SOURCES = foo.vala bar.vala zardoz.c
7053 Any @file{.vala} file listed in a @code{_SOURCES} variable will be
7054 compiled into C code by the Vala compiler. The generated @file{.c}
7055 files are distributed. The end user does not need to have a Vala
7058 Because all C files must be generated, and the Vala compiler compiles
7059 all the @file{.vala} files for a target at once, it is not possible to
7060 add files to a @code{_SOURCES} variable that cannot be compiled
7061 together; for example, alternative platform-specific definitions of
7064 Automake ships with an Autoconf macro called @code{AM_PROG_VALAC}
7065 that will locate the Vala compiler and optionally check its version
7068 @defmac AM_PROG_VALAC (@ovar{minimum-version}, @ovar{action-if-found},
7069 @ovar{action-if-not-found})
7070 Search for a Vala compiler in @env{PATH}. If it is found, the variable
7071 @code{VALAC} is set to point to it (see below for more details). This
7072 macro takes three optional arguments. The first argument, if present,
7073 is the minimum version of the Vala API required to compile this package.
7074 For Vala releases, this is the same as the major and minor release
7075 number; e.g., when @code{valac --version} reports @code{0.48.7},
7076 @code{valac --api-version} reports @code{0.48}. If a compiler is found
7077 and satisfies @var{minimum-version}, then @var{action-if-found} is run
7078 (this defaults to do nothing). Otherwise, @var{action-if-not-found} is
7079 run. If @var{action-if-not-found} is not specified, the default value
7080 is to print a warning in case no compiler is found, or if a too-old
7081 version of the compiler is found.
7084 There are a few variables that are used when compiling Vala sources:
7088 Absolute path to the Vala compiler, or simply @samp{valac} if no
7089 suitable Vala compiler could be found at configure runtime.
7092 Additional arguments for the Vala compiler.
7095 The maintainer's variant of @code{VALAFLAGS}.
7098 lib_LTLIBRARIES = libfoo.la
7099 libfoo_la_SOURCES = foo.vala
7103 Note that currently, you cannot use per-target @code{*_VALAFLAGS}
7104 (@pxref{Renamed Objects}) to produce different C files from one Vala
7108 @node Support for Other Languages
7109 @comment node-name, next, previous, up
7110 @section Support for Other Languages
7112 Automake currently only includes full support for C, C++ (@pxref{C++
7113 Support}), Objective C (@pxref{Objective C Support}),
7114 Objective C++ (@pxref{Objective C++ Support}),
7116 (@pxref{Fortran 77 Support}), Fortran 9x (@pxref{Fortran 9x Support}),
7117 and Java (@pxref{Java Support with gcj}). There is only rudimentary
7118 support for other languages, support for which will be improved based
7121 Some limited support for adding your own languages is available via the
7122 suffix rule handling (@pxref{Suffixes}).
7125 @section Automatic dependency tracking
7127 As a developer it is often painful to continually update the
7128 @file{Makefile.am} whenever the include-file dependencies change in a
7129 project. Automake supplies a way to automatically track dependency
7130 changes (@pxref{Dependency Tracking}).
7132 @cindex Dependency tracking
7133 @cindex Automatic dependency tracking
7135 Automake always uses complete dependencies for a compilation,
7136 including system headers. Automake's model is that dependency
7137 computation should be a side effect of the build. To this end,
7138 dependencies are computed by running all compilations through a
7139 special wrapper program called @command{depcomp}. @command{depcomp}
7140 understands how to coax many different C and C++ compilers into
7141 generating dependency information in the format it requires.
7142 @samp{automake -a} will install @command{depcomp} into your source
7143 tree for you. If @command{depcomp} can't figure out how to properly
7144 invoke your compiler, dependency tracking will simply be disabled for
7147 @cindex @command{depcomp}
7149 Experience with earlier versions of Automake (@pxref{Dependency Tracking
7150 Evolution, , Dependency Tracking Evolution, automake-history, Brief History
7151 of Automake}) taught us that it is not reliable to generate dependencies
7152 only on the maintainer's system, as configurations vary too much. So
7153 instead Automake implements dependency tracking at build time.
7155 This automatic dependency tracking can be suppressed by putting
7156 @option{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
7157 passing @option{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
7158 (this should be the preferred way). Or, you can invoke @command{automake}
7159 with the @option{-i} option. Dependency tracking is enabled by default.
7161 @vindex AUTOMAKE_OPTIONS
7162 @opindex no-dependencies
7164 @cindex Disabling dependency tracking
7165 @cindex Dependency tracking, disabling
7166 The person building your package also can choose to disable dependency
7167 tracking by configuring with @option{--disable-dependency-tracking}.
7169 @cindex Conditional for dependency tracking
7170 If, as the package maintainer, you wish to conditionalize your
7171 @code{Makefile.am} according to whether dependency tracking is
7172 enabled, the best way is to define your own conditional in
7173 @code{configure.ac} according to the shell variable
7174 @code{$enable_dependency_tracking} (all
7175 @code{--enable}/@code{--disable} options are available as shell
7176 variables; @pxref{Package Options, , , autoconf, The Autoconf Manual}):
7179 AM_CONDITIONAL([NO_DEP_TRACKING],
7180 [test x"$enable_dependency_tracking" = x"no"])
7183 And then in your @code{Makefile.am}:
7187 # stuff to do when dependency tracking is disabled
7189 # stuff to do when it's enabled
7194 @section Support for executable extensions
7196 @cindex Executable extension
7197 @cindex Extension, executable
7200 On some platforms, such as Windows, executables are expected to have an
7201 extension such as @file{.exe}. On these platforms, some compilers (GCC
7202 among them) will automatically generate @file{foo.exe} when asked to
7203 generate @file{foo}.
7205 Automake provides mostly-transparent support for this. Unfortunately
7206 @emph{mostly} doesn't yet mean @emph{fully}. Until the English
7207 dictionary is revised, you will have to assist Automake if your package
7208 must support those platforms.
7210 One thing you must be aware of is that, internally, Automake rewrites
7211 something like this:
7214 bin_PROGRAMS = liver
7221 bin_PROGRAMS = liver$(EXEEXT)
7224 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
7227 The variables @code{TESTS} and @code{XFAIL_TESTS} (@pxref{Simple Tests})
7228 are also rewritten if they contain filenames that have been declared as
7229 programs in the same @file{Makefile}. (This is mostly useful when some
7230 programs from @code{check_PROGRAMS} are listed in @code{TESTS}.)
7232 However, Automake cannot apply this rewriting to @command{configure}
7233 substitutions. This means that if you are conditionally building a
7234 program using such a substitution, then your @file{configure.ac} must
7235 take care to add @samp{$(EXEEXT)} when constructing the output variable.
7237 Sometimes maintainers like to write an explicit link rule for their
7238 program. Without executable extension support, this is easy---you
7239 simply write a rule whose target is the name of the program. However,
7240 when executable extension support is enabled, you must instead add the
7241 @samp{$(EXEEXT)} suffix.
7243 This might be a nuisance for maintainers who know their package will
7244 never run on a platform that has
7245 executable extensions. For those maintainers, the @option{no-exeext}
7246 option (@pxref{Options}) will disable this feature. This works in a
7247 fairly ugly way; if @option{no-exeext} is seen, then the presence of a
7248 rule for a target named @code{foo} in @file{Makefile.am} will override
7249 an @command{automake}-generated rule for @samp{foo$(EXEEXT)}. Without
7250 the @option{no-exeext} option, this use will give a diagnostic.
7254 @chapter Other Derived Objects
7256 Automake can handle derived objects that are not C programs.
7257 Sometimes the support for building such objects must be explicitly
7258 supplied, but Automake can still automatically handle installation and
7262 * Scripts:: Executable scripts
7263 * Headers:: Header files
7264 * Data:: Architecture-independent data files
7265 * Sources:: Derived sources
7270 @section Executable Scripts
7272 @cindex @code{_SCRIPTS} primary, defined
7273 @cindex @code{SCRIPTS} primary, defined
7274 @cindex Primary variable, @code{SCRIPTS}
7276 @cindex Installing scripts
7278 It is possible to define and install programs that are scripts. Such
7279 programs are listed using the @code{SCRIPTS} primary name. When the
7280 script is distributed in its final, installable form, the
7281 @file{Makefile} usually looks as follows:
7285 # Install my_script in $(bindir) and distribute it.
7286 dist_bin_SCRIPTS = my_script
7289 Scripts are not distributed by default; as we have just seen, those
7290 that should be distributed can be specified using a @code{dist_}
7291 prefix as with other primaries.
7293 @cindex @code{SCRIPTS}, installation directories
7295 @vindex sbin_SCRIPTS
7296 @vindex libexec_SCRIPTS
7297 @vindex pkgdata_SCRIPTS
7298 @vindex pkglibexec_SCRIPTS
7299 @vindex noinst_SCRIPTS
7300 @vindex check_SCRIPTS
7302 Scripts can be installed in @code{bindir}, @code{sbindir},
7303 @code{libexecdir}, @code{pkglibexecdir}, or @code{pkgdatadir}.
7305 Scripts that need not be installed can be listed in
7306 @code{noinst_SCRIPTS}, and among them, those which are needed only by
7307 @samp{make check} should go in @code{check_SCRIPTS}.
7309 When a script needs to be built, the @file{Makefile.am} should include
7310 the appropriate rules. For instance the @command{automake} program
7311 itself is a Perl script that is generated from @file{automake.in}.
7312 Here is how this is handled:
7315 bin_SCRIPTS = automake
7316 CLEANFILES = $(bin_SCRIPTS)
7317 EXTRA_DIST = automake.in
7319 do_subst = sed -e 's,[@@]datadir[@@],$(datadir),g' \
7320 -e 's,[@@]PERL[@@],$(PERL),g' \
7321 -e 's,[@@]PACKAGE[@@],$(PACKAGE),g' \
7322 -e 's,[@@]VERSION[@@],$(VERSION),g' \
7325 automake: automake.in Makefile
7326 $(do_subst) < $(srcdir)/automake.in > automake
7330 Such scripts for which a build rule has been supplied need to be
7331 deleted explicitly using @code{CLEANFILES} (@pxref{Clean}), and their
7332 sources have to be distributed, usually with @code{EXTRA_DIST}
7333 (@pxref{Basics of Distribution}).
7335 Another common way to build scripts is to process them from
7336 @file{configure} with @code{AC_CONFIG_FILES}. In this situation
7337 Automake knows which files should be cleaned and distributed, and what
7338 the rebuild rules should look like.
7340 For instance if @file{configure.ac} contains
7343 AC_CONFIG_FILES([src/my_script], [chmod +x src/my_script])
7347 to build @file{src/my_script} from @file{src/my_script.in}, then a
7348 @file{src/Makefile.am} to install this script in @code{$(bindir)} can
7352 bin_SCRIPTS = my_script
7353 CLEANFILES = $(bin_SCRIPTS)
7357 There is no need for @code{EXTRA_DIST} or any build rule: Automake
7358 infers them from @code{AC_CONFIG_FILES} (@pxref{Requirements}).
7359 @code{CLEANFILES} is still useful, because by default Automake will
7360 clean targets of @code{AC_CONFIG_FILES} in @code{distclean}, not
7363 Although this looks simpler, building scripts this way has one
7364 drawback: directory variables such as @code{$(datadir)} are not fully
7365 expanded and may refer to other directory variables.
7368 @section Header files
7370 @cindex @code{_HEADERS} primary, defined
7371 @cindex @code{HEADERS} primary, defined
7372 @cindex Primary variable, @code{HEADERS}
7374 @vindex noinst_HEADERS
7375 @cindex @code{HEADERS}, installation directories
7376 @cindex Installing headers
7377 @vindex include_HEADERS
7378 @vindex oldinclude_HEADERS
7379 @vindex pkginclude_HEADERS
7382 Header files that must be installed are specified by the
7383 @code{HEADERS} family of variables. Headers can be installed in
7384 @code{includedir}, @code{oldincludedir}, @code{pkgincludedir} or any
7385 other directory you may have defined (@pxref{Uniform}). For instance,
7388 include_HEADERS = foo.h bar/bar.h
7392 will install the two files as @file{$(includedir)/foo.h} and
7393 @file{$(includedir)/bar.h}.
7395 The @code{nobase_} prefix is also supported:
7398 nobase_include_HEADERS = foo.h bar/bar.h
7402 will install the two files as @file{$(includedir)/foo.h} and
7403 @file{$(includedir)/bar/bar.h} (@pxref{Alternative}).
7405 @vindex noinst_HEADERS
7406 Usually, only header files that accompany installed libraries need to
7407 be installed. Headers used by programs or convenience libraries are
7408 not installed. The @code{noinst_HEADERS} variable can be used for
7409 such headers. However, when the header belongs to a single
7410 convenience library or program, we recommend listing it in the
7411 program's or library's @code{_SOURCES} variable (@pxref{Program
7412 Sources}) instead of in @code{noinst_HEADERS}. This is clearer for
7413 the @file{Makefile.am} reader. @code{noinst_HEADERS} would be the
7414 right variable to use in a directory containing only headers and no
7415 associated library or program.
7417 All header files must be listed somewhere; in a @code{_SOURCES}
7418 variable or in a @code{_HEADERS} variable. Missing ones will not
7419 appear in the distribution.
7421 For header files that are built and must not be distributed, use the
7422 @code{nodist_} prefix as in @code{nodist_include_HEADERS} or
7423 @code{nodist_prog_SOURCES}. If these generated headers are needed
7424 during the build, you must also ensure they exist before they are
7425 used (@pxref{Sources}).
7429 @section Architecture-independent data files
7431 @cindex @code{_DATA} primary, defined
7432 @cindex @code{DATA} primary, defined
7433 @cindex Primary variable, @code{DATA}
7436 Automake supports the installation of miscellaneous data files using the
7437 @code{DATA} family of variables.
7443 @vindex sysconf_DATA
7444 @vindex sharedstate_DATA
7445 @vindex localstate_DATA
7446 @vindex pkgdata_DATA
7448 Such data can be installed in the directories @code{datadir},
7449 @code{docdir}, @code{lispdir}, @code{sysconfdir}, @code{sharedstatedir},
7450 @code{localstatedir}, or @code{pkgdatadir}.
7452 By default, data files are @emph{not} included in a distribution. Of
7453 course, you can use the @code{dist_} prefix to change this on a
7456 Here is how Automake declares its auxiliary data files:
7459 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
7464 @section Built Sources
7466 Because Automake's automatic dependency tracking works as a side-effect
7467 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
7468 target should not be compiled before its dependencies are made, but
7469 these dependencies are unknown until the target is first compiled.
7471 Ordinarily this is not a problem, because dependencies are distributed
7472 sources: they preexist and do not need to be built. Suppose that
7473 @file{foo.c} includes @file{foo.h}. When it first compiles
7474 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
7475 @file{foo.c}. As a side-effect of this compilation @command{depcomp}
7476 records the @file{foo.h} dependency so that following invocations of
7477 @command{make} will honor it. In these conditions, it's clear there is
7478 no problem: either @file{foo.o} doesn't exist and has to be built
7479 (regardless of the dependencies), or accurate dependencies exist and
7480 they can be used to decide whether @file{foo.o} should be rebuilt.
7482 It's a different story if @file{foo.h} doesn't exist by the first
7483 @command{make} run. For instance, there might be a rule to build
7484 @file{foo.h}. This time @file{file.o}'s build will fail because the
7485 compiler can't find @file{foo.h}. @command{make} failed to trigger the
7486 rule to build @file{foo.h} first by lack of dependency information.
7488 @vindex BUILT_SOURCES
7489 @cindex @code{BUILT_SOURCES}, defined
7491 The @code{BUILT_SOURCES} variable is a workaround for this problem. A
7492 source file listed in @code{BUILT_SOURCES} is made when @samp{make
7493 all}, @samp{make check}, @samp{make install}, @samp{make install-exec}
7494 (or @code{make dist}) is run, before other targets are processed.
7495 However, such a source file is not @emph{compiled} unless explicitly
7496 requested by mentioning it in some other @code{_SOURCES} variable.
7498 So, to conclude our introductory example, we could use
7499 @samp{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
7500 any other target (including @file{foo.o}) during @samp{make all} or
7503 @code{BUILT_SOURCES} is a bit of a misnomer, as any file which must be
7504 created early in the build process can be listed in this variable.
7505 Moreover, all built sources do not necessarily have to be listed in
7506 @code{BUILT_SOURCES}. For instance, a generated @file{.c} file
7507 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included
7508 by another source), because it's a known dependency of the associated
7511 To emphasize, @code{BUILT_SOURCES} is honored only by @samp{make all},
7512 @samp{make check}, @samp{make install}, and @code{make install-exec}
7513 (and @samp{make dist}). This means you cannot build an arbitrary
7514 target (e.g., @samp{make foo}) in a clean tree if it depends on a
7515 built source. However it will succeed if you have run @samp{make all}
7516 earlier, because accurate dependencies are already available.
7518 The next section illustrates and discusses the handling of built sources
7522 * Built Sources Example:: Several ways to handle built sources.
7525 @node Built Sources Example
7526 @subsection Built Sources Example
7528 Suppose that @file{foo.c} includes @file{bindir.h}, which is
7529 installation-dependent and not distributed: it needs to be built. Here
7530 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
7531 value of the @command{make} variable @code{bindir} (inherited from
7534 We suggest several implementations below. It's not meant to be an
7535 exhaustive listing of all ways to handle built sources, but it will give
7536 you a few ideas if you encounter this issue.
7538 @subsubheading First Try
7540 This first implementation will illustrate the bootstrap issue mentioned
7541 in the previous section (@pxref{Sources}).
7543 Here is a tentative @file{Makefile.am}.
7549 nodist_foo_SOURCES = bindir.h
7550 CLEANFILES = bindir.h
7552 echo '#define bindir "$(bindir)"' >$@@
7555 This setup doesn't work, because Automake doesn't know that @file{foo.c}
7556 includes @file{bindir.h}. Remember, automatic dependency tracking works
7557 as a side-effect of compilation, so the dependencies of @file{foo.o} will
7558 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
7559 The symptom is as follows.
7563 source='foo.c' object='foo.o' libtool=no \
7564 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7565 depmode=gcc /bin/sh ./depcomp \
7566 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7567 foo.c:2: bindir.h: No such file or directory
7568 make: *** [foo.o] Error 1
7571 In this example @file{bindir.h} is not distributed nor installed, and
7572 it is not even being built on-time. One may wonder if the
7573 @samp{nodist_foo_SOURCES = bindir.h} line has any use at all. This
7574 line simply states that @file{bindir.h} is a source of @code{foo}, so
7575 for instance, it should be inspected while generating tags
7576 (@pxref{Tags}). In other words, it does not help our present problem,
7577 and the build would fail identically without it.
7579 @subsubheading Using @code{BUILT_SOURCES}
7581 A solution is to require @file{bindir.h} to be built before anything
7582 else. This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
7587 nodist_foo_SOURCES = bindir.h
7588 BUILT_SOURCES = bindir.h
7589 CLEANFILES = bindir.h
7591 echo '#define bindir "$(bindir)"' >$@@
7594 See how @file{bindir.h} gets built first:
7598 echo '#define bindir "/usr/local/bin"' >bindir.h
7600 make[1]: Entering directory `/home/adl/tmp'
7601 source='foo.c' object='foo.o' libtool=no \
7602 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7603 depmode=gcc /bin/sh ./depcomp \
7604 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7605 gcc -g -O2 -o foo foo.o
7606 make[1]: Leaving directory `/home/adl/tmp'
7609 However, as said earlier, @code{BUILT_SOURCES} applies only to the
7610 @code{all}, @code{check}, and @code{install} targets. It still fails
7611 if you try to run @samp{make foo} explicitly:
7615 test -z "bindir.h" || rm -f bindir.h
7616 test -z "foo" || rm -f foo
7618 % @kbd{: > .deps/foo.Po} # Suppress previously recorded dependencies
7620 source='foo.c' object='foo.o' libtool=no \
7621 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7622 depmode=gcc /bin/sh ./depcomp \
7623 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7624 foo.c:2: bindir.h: No such file or directory
7625 make: *** [foo.o] Error 1
7628 @subsubheading Recording Dependencies manually
7630 Usually people are happy enough with @code{BUILT_SOURCES} because they
7631 never build targets such as @samp{make foo} before @samp{make all}, as
7632 in the previous example. However if this matters to you, you can
7633 avoid @code{BUILT_SOURCES} and record such dependencies explicitly in
7634 the @file{Makefile.am}.
7639 nodist_foo_SOURCES = bindir.h
7640 foo.$(OBJEXT): bindir.h
7641 CLEANFILES = bindir.h
7643 echo '#define bindir "$(bindir)"' >$@@
7646 You don't have to list @emph{all} the dependencies of @file{foo.o}
7647 explicitly, only those that might need to be built. If a dependency
7648 already exists, it will not hinder the first compilation and will be
7649 recorded by the normal dependency tracking code. (After this first
7650 compilation, the dependency tracking code will also have recorded the
7651 dependency between @file{foo.o} and @file{bindir.h}, so our explicit
7652 dependency is only useful to the first build.)
7654 Adding explicit dependencies like this can be a bit dangerous if you are
7655 not careful enough. This is due to the way Automake tries not to
7656 overwrite your rules (it assumes you know better than it).
7657 @samp{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
7658 output to build @samp{foo.$(OBJEXT)}. It happens to work in this case
7659 because Automake doesn't have to output any @samp{foo.$(OBJEXT):}
7660 target: it relies on a suffix rule instead (i.e., @samp{.c.$(OBJEXT):}).
7661 Always check the generated @file{Makefile.in} if you do this.
7663 @subsubheading Build @file{bindir.h} from @file{configure}
7665 It's possible to define this preprocessor macro from @file{configure},
7666 either in @file{config.h} (@pxref{Defining Directories, , Defining
7667 Directories, autoconf, The Autoconf Manual}), or by processing a
7668 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
7669 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
7672 At this point it should be clear that building @file{bindir.h} from
7673 @file{configure} works well for this example. @file{bindir.h} will exist
7674 before you build any target, hence will not cause any dependency issue.
7676 The Makefile can be shrunk as follows. We do not even have to mention
7684 However, it's not always possible to build sources from
7685 @file{configure}, especially when these sources are generated by a tool
7686 that needs to be built first.
7688 @subsubheading Build @file{bindir.c}, not @file{bindir.h}.
7690 Another attractive idea is to define @code{bindir} as a variable or
7691 function exported from @file{bindir.o}, and build @file{bindir.c}
7692 instead of @file{bindir.h}.
7695 noinst_PROGRAMS = foo
7696 foo_SOURCES = foo.c bindir.h
7697 nodist_foo_SOURCES = bindir.c
7698 CLEANFILES = bindir.c
7700 echo 'const char bindir[] = "$(bindir)";' >$@@
7703 @file{bindir.h} contains just the variable's declaration and doesn't
7704 need to be built, so it won't cause any trouble. @file{bindir.o} is
7705 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
7708 @subsubheading Which is best?
7710 There is no panacea, of course. Each solution has its merits and
7713 You cannot use @code{BUILT_SOURCES} if the ability to run @samp{make
7714 foo} on a clean tree is important to you.
7716 You won't add explicit dependencies if you are leery of overriding
7717 an Automake rule by mistake.
7719 Building files from @file{./configure} is not always possible, neither
7720 is converting @file{.h} files into @file{.c} files.
7723 @node Other GNU Tools
7724 @chapter Other GNU Tools
7726 Since Automake is primarily intended to generate @file{Makefile.in}s for
7727 use in GNU programs, it tries hard to interoperate with other GNU tools.
7730 * Emacs Lisp:: Emacs Lisp
7733 * Java:: Java bytecode compilation (deprecated)
7741 @cindex @code{_LISP} primary, defined
7742 @cindex @code{LISP} primary, defined
7743 @cindex Primary variable, @code{LISP}
7749 Automake provides some support for Emacs Lisp. The @code{LISP} primary
7750 is used to hold a list of @file{.el} files. Possible prefixes for this
7751 primary are @code{lisp_} and @code{noinst_}. Note that if
7752 @code{lisp_LISP} is defined, then @file{configure.ac} must run
7753 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
7755 @vindex dist_lisp_LISP
7756 @vindex dist_noinst_LISP
7757 Lisp sources are not distributed by default. You can prefix the
7758 @code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
7759 @code{dist_noinst_LISP}, to indicate that these files should be
7762 Automake will byte-compile all Emacs Lisp source files using the Emacs
7763 found by @code{AM_PATH_LISPDIR}, if any was found. When performing such
7764 byte-compilation, the flags specified in the (developer-reserved)
7765 @code{AM_ELCFLAGS} and (user-reserved) @code{ELCFLAGS} make variables
7766 will be passed to the Emacs invocation.
7768 Byte-compiled Emacs Lisp files are not portable among all versions of
7769 Emacs, so it makes sense to turn this off if you expect sites to have
7770 more than one version of Emacs installed. Furthermore, many packages
7771 do not actually benefit from byte-compilation. Still, we recommend
7772 that you byte-compile your Emacs Lisp sources. It is probably better
7773 for sites with strange setups to cope for themselves than to make the
7774 installation less nice for everybody else.
7776 There are two ways to avoid byte-compiling. Historically, we have
7777 recommended the following construct.
7780 lisp_LISP = file1.el file2.el
7785 @code{ELCFILES} is an internal Automake variable that normally lists
7786 all @file{.elc} files that must be byte-compiled. Automake defines
7787 @code{ELCFILES} automatically from @code{lisp_LISP}. Emptying this
7788 variable explicitly prevents byte-compilation.
7790 Since Automake 1.8, we now recommend using @code{lisp_DATA} instead:
7792 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7794 lisp_DATA = file1.el file2.el
7797 Note that these two constructs are not equivalent. @code{_LISP} will
7798 not install a file if Emacs is not installed, while @code{_DATA} will
7799 always install its files.
7804 @cindex GNU Gettext support
7805 @cindex Gettext support
7806 @cindex Support for GNU Gettext
7808 If @code{AM_GNU_GETTEXT} is seen in @file{configure.ac}, then Automake
7809 turns on support for GNU gettext, a message catalog system for
7810 internationalization
7811 (@pxref{Top, , Introduction, gettext, GNU gettext utilities}).
7813 The @code{gettext} support in Automake requires the addition of one or
7814 two subdirectories to the package: @file{po} and possibly also @file{intl}.
7815 The latter is needed if @code{AM_GNU_GETTEXT} is not invoked with the
7816 @samp{external} argument, or if @code{AM_GNU_GETTEXT_INTL_SUBDIR} is used.
7817 Automake ensures that these directories exist and are mentioned in
7823 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
7824 libtool, The Libtool Manual}) with the @code{LTLIBRARIES} primary.
7825 @xref{A Shared Library}.
7829 @section Java bytecode compilation (deprecated)
7831 @cindex @code{_JAVA} primary, defined
7832 @cindex @code{JAVA} primary, defined
7833 @cindex Primary variable, @code{JAVA}
7834 @cindex Java to bytecode, compilation
7835 @cindex Compilation of Java to bytecode
7837 Automake provides some minimal support for Java bytecode compilation with
7838 the @code{JAVA} primary (in addition to the support for compiling Java to
7839 native machine code; @pxref{Java Support with gcj}). Note however that
7840 @emph{the interface and most features described here are deprecated}.
7841 Future Automake releases will strive to provide a better and cleaner
7842 interface, which however @emph{won't be backward-compatible}; the present
7843 interface will probably be removed altogether some time after the
7844 introduction of the new interface (if that ever materializes). In any
7845 case, the current @code{JAVA} primary features are frozen and will no
7846 longer be developed, not even to take bug fixes.
7848 Any @file{.java} files listed in a @code{_JAVA} variable will be
7849 compiled with @code{JAVAC} at build time. By default, @file{.java}
7850 files are not included in the distribution; you should use the
7851 @code{dist_} prefix to distribute them.
7853 Here is a typical setup for distributing @file{.java} files and
7854 installing the @file{.class} files resulting from their compilation.
7856 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7858 javadir = $(datadir)/java
7859 dist_java_JAVA = a.java b.java @dots{}
7862 @cindex @code{JAVA} restrictions
7863 @cindex Restrictions for @code{JAVA}
7865 Currently Automake enforces the restriction that only one @code{_JAVA}
7866 primary can be used in a given @file{Makefile.am}. The reason for this
7867 restriction is that, in general, it isn't possible to know which
7868 @file{.class} files were generated from which @file{.java} files, so
7869 it would be impossible to know which files to install where. For
7870 instance, a @file{.java} file can define multiple classes; the resulting
7871 @file{.class} file names cannot be predicted without parsing the
7874 There are a few variables that are used when compiling Java sources:
7878 The name of the Java compiler. This defaults to @samp{javac}.
7881 The flags to pass to the compiler. This is considered to be a user
7882 variable (@pxref{User Variables}).
7885 More flags to pass to the Java compiler. This, and not
7886 @code{JAVACFLAGS}, should be used when it is necessary to put Java
7887 compiler flags into @file{Makefile.am}.
7890 The value of this variable is passed to the @option{-d} option to
7891 @code{javac}. It defaults to @samp{$(top_builddir)}.
7894 This variable is a shell expression that is used to set the
7895 @env{CLASSPATH} environment variable on the @code{javac} command line.
7896 (In the future we will probably handle class path setting differently.)
7903 @cindex @code{_PYTHON} primary, defined
7904 @cindex @code{PYTHON} primary, defined
7905 @cindex Primary variable, @code{PYTHON}
7908 Automake provides support for Python compilation with the
7909 @code{PYTHON} primary. A typical setup is to call
7910 @code{AM_PATH_PYTHON} in @file{configure.ac} and use a line like this
7911 in @file{Makefile.am}:
7914 python_PYTHON = tree.py leave.py
7917 Python source files are included in the distribution by default;
7918 prepend @code{nodist_} (as in @code{nodist_python_PYTHON}) to omit
7921 @cindex @file{.pyc}, @file{.pyo} files
7922 At install time, any files listed in a @code{_PYTHON} variable will be
7923 byte-compiled with @command{py-compile}. @command{py-compile} creates
7924 both standard (@file{.pyc}) and optimized (@file{.pyo}) byte-compiled
7925 versions of the source files. Because byte-compilation occurs at
7926 install time, files listed in @code{noinst_PYTHON} will not be
7929 Automake ships with an Autoconf macro named @code{AM_PATH_PYTHON} that
7930 determines some Python-related directory variables (see below). If
7931 you have called @code{AM_PATH_PYTHON} from @file{configure.ac}, then
7932 you may use the variables
7933 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7934 @code{python_PYTHON} and @code{pkgpython_PYTHON} to list Python source
7935 files in your @file{Makefile.am}, depending on whether you want your
7936 files installed in @code{pythondir} or @code{pkgpythondir},
7939 @defmac AM_PATH_PYTHON (@ovar{version}, @ovar{action-if-found},
7940 @ovar{action-if-not-found})
7942 Search for a Python interpreter on the system. This macro takes three
7943 optional arguments. The first argument, if present, is the minimum
7944 version of Python required for this package: @code{AM_PATH_PYTHON}
7945 will skip any Python interpreter that is older than @var{version}.
7946 If an interpreter is found and satisfies @var{version}, then
7947 @var{action-if-found} is run. Otherwise, @var{action-if-not-found} is
7950 If @var{action-if-not-found} is not specified, as in the following
7951 example, the default is to abort @command{configure}:
7954 AM_PATH_PYTHON([2.5])
7958 This is fine when Python is an absolute requirement for the package.
7959 If Python @geq{} 2.5 was only @emph{optional} for the package,
7960 @code{AM_PATH_PYTHON} could be called as follows.
7963 AM_PATH_PYTHON([2.5],, [:])
7966 If the @env{PYTHON} variable is set when @code{AM_PATH_PYTHON} is
7967 called, then that will be the only Python interpreter that is tried.
7969 @code{AM_PATH_PYTHON} creates the following output variables based on
7970 the Python installation found during configuration:
7975 The name of the Python executable, or @samp{:} if no suitable
7976 interpreter could be found.
7978 Assuming @var{action-if-not-found} is used (otherwise @file{./configure}
7979 will abort if Python is absent), the value of @code{PYTHON} can be used
7980 to set up a conditional in order to disable the relevant part of a build
7984 AM_PATH_PYTHON(,, [:])
7985 AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
7988 @item PYTHON_VERSION
7989 @vindex sys.version_info @r{Python variable}
7990 The Python version number, in the form @var{major}.@var{minor}
7991 (e.g., @samp{2.5}). This is set to be the value of
7992 @samp{'%u.%u' % sys.version_info[:2]}.
7995 @itemx PYTHON_EXEC_PREFIX
7996 @opindex --with-python-sys-prefix
7997 @opindex --with-python_prefix
7998 @opindex --with-python_exec_prefix
7999 @vindex sys.prefix @r{Python variable}
8000 @vindex sys.exec_prefix @r{Python variable}
8001 With no special options given, these have values @samp{$@{prefix@}}
8002 and @samp{$@{exec_prefix@}}, respectively (unexpanded; see below).
8004 The @file{configure} options @option{--with-python_prefix}
8005 and @option{--with-python_exec_prefix} set them to an explicit value.
8007 The @file{configure} option @option{--with-python-sys-prefix} set them
8008 to the values of Python's @samp{sys.prefix} and @samp{sys.exec_prefix}
8009 variables. These often differ from @samp{$@{prefix@}} and
8010 @samp{$@{exec_prefix@}}, e.g., on platforms such as Mac@tie{}OS@tie{}x
8011 (where Python is usually installed as a Framework).
8013 @item PYTHON_PLATFORM
8014 @vindex sys.platform @r{Python variable}
8015 The canonical name used by Python to describe the operating system, as
8016 given by @samp{sys.platform}. This value is sometimes needed when
8017 building Python extensions.
8020 @cindex @file{site-packages} Python directory
8021 @cindex @file{dist-packages} Python directory
8022 The subdirectory of the Python install tree in which to install Python
8023 scripts. By default this is, on all systems,
8024 @file{$PYTHON_PREFIX/lib/python@var{version}/site-packages}, where
8025 @code{$PYTHON_PREFIX} is described above, and @var{version} is the
8026 Python version. (For those knowledgeable about Python installation
8027 details: systems generally have their own Python installation scheme,
8028 such as @code{posix_local} on Debian and related (as of
8029 Python@tie{}3.10), which ends up using a directory named
8030 @file{dist-packages}; Automake uses the @code{posix_prefix} scheme and
8031 @file{site-packages}.)
8032 @c https://bugs.gnu.org/54412 et al.
8035 This is the directory under @code{pythondir} that is named after the
8036 package. That is, it is @samp{$(pythondir)/$(PACKAGE)}. It is provided
8040 This is the directory where Python extension modules (shared libraries)
8041 should be installed. An extension module written in C could be declared
8042 as follows to Automake:
8044 @c Keep in sync with primary-prefix-couples-documented-valid.sh
8046 pyexec_LTLIBRARIES = quaternion.la
8047 quaternion_la_SOURCES = quaternion.c support.c support.h
8048 quaternion_la_LDFLAGS = -avoid-version -module
8052 This is a convenience variable that is defined as
8053 @samp{$(pyexecdir)/$(PACKAGE)}.
8056 All of these directory variables have values that can start with either
8057 @samp{$@{prefix@}} or @samp{$@{exec_prefix@}}, unexpanded. This works
8058 fine in @file{Makefile}s, but it makes these variables hard to use in
8059 @file{configure}. This is mandated by the GNU coding standards, so
8060 that the user can run @samp{make prefix=/foo install}. The Autoconf
8061 manual has a section with more details on this topic
8062 (@pxref{Installation Directory Variables, , Installation Directory
8063 Variables, autoconf, The Autoconf Manual}). See also @ref{Hard-Coded
8067 * Supported Python versions::
8070 @node Supported Python versions
8071 @subsection Supported versions
8073 Automake guarantees releases will support all Python versions that are still
8074 supported by the Python project at the time of the Automake release. Support
8075 for EOL versions of Python are not guaranteed, but will be considered as long
8076 as it is not onerous to do so, and there are large supported distros including
8077 them. If you need to support older Python versions, please use a previous
8080 Here are the current support plans.
8082 @multitable {2.0 -- 3.5} {Unsupported}
8083 @headitem Version @tab Status
8089 @tab Untested, but should work
8091 @c Debian Bullseye goes EOL in Apr 2026.
8092 @tab Supported (until Apr 2026)
8094 @tab Untested, but should work
8096 @c Ubuntu Trusty goes EOL in Apr 2022.
8097 @tab Supported (until Apr 2022)
8099 @c Ubuntu Xenial goes EOL in Apr 2024.
8100 @tab Supported (until Apr 2024)
8102 @c Ubuntu Bionic goes EOL in Apr 2028.
8103 @tab Supported (until Apr 2028)
8105 @c Debian Buster goes EOL in Apr 2024.
8106 @c But should support at least as long as previous Python version?
8107 @tab Supported (until Apr 2028)
8109 @c Ubuntu Focal goes EOL in Apr 2030
8110 @tab Supported (until Apr 2030)
8112 @c Debian Bullseye goes EOL in Apr 2026.
8113 @c But should support at least as long as previous Python version?
8114 @tab Supported (until Apr 2030)
8116 @c But should support at least as long as previous Python version?
8117 @tab Supported (until Apr 2030)
8121 @chapter Building documentation
8123 Currently Automake provides support for Texinfo and man pages.
8134 @cindex Texinfo support
8135 @cindex @code{_TEXINFOS} primary, defined
8136 @cindex @code{TEXINFOS} primary, defined
8137 @cindex Primary variable, @code{TEXINFOS}
8138 @cindex HTML output using Texinfo
8139 @cindex PDF output using Texinfo
8140 @cindex PS output using Texinfo
8141 @cindex DVI output using Texinfo
8143 @vindex info_TEXINFOS
8145 If the current directory contains Texinfo source, you must declare it
8146 with the @code{TEXINFOS} primary. Generally Texinfo files are converted
8147 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
8148 here. Any Texinfo source file should have the @file{.texi} extension.
8149 Automake also accepts @file{.txi} or @file{.texinfo} extensions, but their
8150 use is discouraged now, and will elicit runtime warnings.
8152 Automake generates rules to build @file{.info}, @file{.dvi},
8153 @file{.ps}, @file{.pdf} and @file{.html} files from your Texinfo
8154 sources. Following the GNU Coding Standards, only the @file{.info}
8155 files are built by @samp{make all} and installed by @samp{make
8156 install} (unless you use @option{no-installinfo}, see below).
8157 Furthermore, @file{.info} files are automatically distributed so that
8158 Texinfo is not a prerequisite for installing your package.
8160 It is worth noting that, contrary to what happens with the other formats,
8161 the generated @file{.info} files are by default placed in @code{srcdir}
8162 rather than in the @code{builddir}. This can be changed with the
8163 @option{info-in-builddir} option.
8165 If the Texinfo sources are in a subdirectory relative to the Makefile, then
8166 @code{-I} flags for the subdirectory, both in the source directory and in the
8167 build directory, will automatically be added. There is no need to specify
8168 these in @samp{$(MAKEINFO)}, @samp{$(MAKEINFOFLAGS)}, etc.
8170 @cindex @samp{@@setfilename} Texinfo directive
8171 If a Texinfo source file contains an @samp{@@setfilename} directive,
8172 and its argument has extension @samp{.info} (or no extension, but this
8173 is discouraged), that argument should be the same as the basename of
8174 the Texinfo file, extended with @samp{.info}. The Make rules
8175 generated by Automake assume this, and will not work if the
8176 @samp{@@setfilename} is for some other name.
8178 @cindex @file{.texi.in} file, read
8179 If a Texinfo source @samp{foo.texi} is not present, but
8180 @file{foo.texi.in} exists, Texinfo will read that @file{.texi.in} file
8181 for @code{@@setfilename} and @code{@@include version.texi} (described
8184 Texinfo source files need not be present at all, and if present, need
8185 not contain @code{@@setfilename}. Then the file name given in the
8186 Makefile.am will be used.
8192 @trindex install-dvi
8193 @trindex install-html
8194 @trindex install-pdf
8196 Other documentation formats can be built on request by @samp{make
8197 dvi}, @samp{make ps}, @samp{make pdf} and @samp{make html}, and they
8198 can be installed with @samp{make install-dvi}, @samp{make install-ps},
8199 @samp{make install-pdf} and @samp{make install-html} explicitly.
8200 @samp{make uninstall} will remove everything: the Texinfo
8201 documentation installed by default as well as all the above optional
8204 All of these targets can be extended using @samp{-local} rules
8205 (@pxref{Extending}).
8207 @cindex Texinfo flag, @code{VERSION}
8208 @cindex Texinfo flag, @code{UPDATED}
8209 @cindex Texinfo flag, @code{EDITION}
8210 @cindex Texinfo flag, @code{UPDATED-MONTH}
8212 @cindex @code{VERSION} Texinfo flag
8213 @cindex @code{UPDATED} Texinfo flag
8214 @cindex @code{EDITION} Texinfo flag
8215 @cindex @code{UPDATED-MONTH} Texinfo flag
8217 @cindex @file{mdate-sh}
8219 If a @file{.texi} file @code{@@include}s @file{version.texi} (actually
8220 any file named @file{vers...texi}, then that file will be
8221 automatically generated. The file @file{version.texi} defines four
8222 Texinfo flags you can reference using @code{@@value@{EDITION@}},
8223 @code{@@value@{VERSION@}}, @code{@@value@{UPDATED@}}, and
8224 @code{@@value@{UPDATED-MONTH@}}.
8229 Both of these flags hold the version number of your program. They are
8230 kept separate for clarity.
8233 This holds the date the primary @file{.texi} file was last modified.
8236 This holds the name of the month in which the primary @file{.texi} file
8240 The @file{version.texi} support requires the @command{mdate-sh}
8241 script; this script is supplied with Automake and automatically
8242 included when @command{automake} is invoked with the
8243 @option{--add-missing} option.
8245 If you have multiple Texinfo files, and you want to use the
8246 @file{version.texi} feature, then you have to have a separate version
8247 file for each Texinfo file. Automake will treat any include in a
8248 Texinfo file that matches @file{vers*.texi} just like an automatically
8249 generated version file.
8251 Often an Info file depends on more than one @file{.texi} file. For
8252 instance, in GNU Hello, @file{hello.texi} includes the file
8253 @file{fdl.texi}. You can tell Automake about these dependencies using
8254 the @code{@var{texi}_TEXINFOS} variable. Here is how GNU Hello does
8260 info_TEXINFOS = hello.texi
8261 hello_TEXINFOS = fdl.texi
8264 @cindex @file{texinfo.tex}
8266 By default, Automake requires the file @file{texinfo.tex} to appear in
8267 the same directory as the @file{Makefile.am} file that lists the
8268 @file{.texi} files. If you used @code{AC_CONFIG_AUX_DIR} in
8269 @file{configure.ac} (@pxref{Input, , Finding `configure' Input,
8270 autoconf, The Autoconf Manual}), then @file{texinfo.tex} is looked for
8271 there. In both cases, @command{automake} then supplies @file{texinfo.tex} if
8272 @option{--add-missing} is given, and takes care of its distribution.
8273 However, if you set the @code{TEXINFO_TEX} variable (see below),
8274 it overrides the location of the file and turns off its installation
8275 into the source as well as its distribution.
8277 The option @option{no-texinfo.tex} can be used to eliminate the
8278 requirement for the file @file{texinfo.tex}. Use of the variable
8279 @code{TEXINFO_TEX} is preferable, however, because that allows the
8280 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
8282 @cindex Option, @code{no-installinfo}
8283 @cindex Target, @code{install-info}
8284 @cindex @code{install-info} target
8285 @cindex @code{no-installinfo} option
8287 @opindex no-installinfo
8288 @trindex install-info
8290 Automake generates an @code{install-info} rule; some people apparently
8291 use this. By default, info pages are installed by @samp{make
8292 install}, so running @code{make install-info} is pointless. This can
8293 be prevented via the @code{no-installinfo} option. In this case,
8294 @file{.info} files are not installed by default, and user must
8295 request this explicitly using @samp{make install-info}.
8297 @vindex AM_UPDATE_INFO_DIR
8298 By default, @code{make install-info} and @code{make uninstall-info}
8299 will try to run the @command{install-info} program (if available) to
8300 update (or create/remove) the @file{@code{$@{infodir@}}/dir} index.
8301 If this is undesired, it can be prevented by exporting the
8302 @code{AM_UPDATE_INFO_DIR} variable to "@code{no}".
8304 The following variables are used by the Texinfo build rules.
8308 The name of the program invoked to build @file{.info} files. This
8309 variable is defined by Automake. If the @command{makeinfo} program is
8310 found on the system then it will be used by default; otherwise
8311 @command{missing} will be used instead.
8314 The command invoked to build @file{.html} files. Automake
8315 defines this to @samp{$(MAKEINFO) --html}.
8318 User flags passed to each invocation of @samp{$(MAKEINFO)} and
8319 @samp{$(MAKEINFOHTML)}. This user variable (@pxref{User Variables}) is
8320 not expected to be defined in any @file{Makefile}; it can be used by
8321 users to pass extra flags to suit their needs.
8323 @item AM_MAKEINFOFLAGS
8324 @itemx AM_MAKEINFOHTMLFLAGS
8325 @itemx AM_TEXI2FLAGS
8326 Maintainer flags passed to each @command{makeinfo} invocation. Unlike
8327 @code{MAKEINFOFLAGS}, these variables are meant to be defined by
8328 maintainers in @file{Makefile.am}. @samp{$(AM_MAKEINFOFLAGS)} is
8329 passed to @code{makeinfo} when building @file{.info} files;
8330 @samp{$(AM_MAKEINFOHTMLFLAGS)} is used when building @file{.html}
8331 files; and @samp{$(AM_TEXI2FLAGS)} is used when building @file{.dvi} and
8334 @c Keep in sync with txinfo-many-output-formats.sh
8335 For instance, the following setting can be used to obtain one single
8336 @file{.html} file per manual, without node separators.
8338 AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
8341 @code{AM_MAKEINFOHTMLFLAGS} defaults to @samp{$(AM_MAKEINFOFLAGS)}.
8342 This means that defining @code{AM_MAKEINFOFLAGS} without defining
8343 @code{AM_MAKEINFOHTMLFLAGS} will impact builds of both @file{.info}
8344 and @file{.html} files.
8347 The name of the command that converts a @file{.texi} file into a
8348 @file{.dvi} file. This defaults to @samp{texi2dvi}, a script that ships
8349 with the Texinfo package.
8352 The name of the command that translates a @file{.texi} file into a
8353 @file{.pdf} file. This defaults to @samp{$(TEXI2DVI) --pdf --batch}.
8356 The name of the command that builds a @file{.ps} file out of a
8357 @file{.dvi} file. This defaults to @samp{dvips}.
8360 If your package has Texinfo files in many directories, you can use the
8361 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
8362 @file{texinfo.tex} for your package. The value of this variable should
8363 be the relative path from the current @file{Makefile.am} to
8367 TEXINFO_TEX = ../doc/texinfo.tex
8375 @cindex @code{_MANS} primary, defined
8376 @cindex @code{MANS} primary, defined
8377 @cindex Primary variable, @code{MANS}
8381 A package can also include man pages (but see the GNU standards on this
8382 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.) Man
8383 pages are declared using the @code{MANS} primary. Generally the
8384 @code{man_MANS} variable is used. Man pages are automatically installed in
8385 the correct subdirectory of @code{mandir}, based on the file extension.
8387 File extensions such as @file{.1c} are handled by looking for the valid
8388 part of the extension and using that to determine the correct
8389 subdirectory of @code{mandir}. Valid section names are the digits
8390 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
8392 Sometimes developers prefer to name a man page something like
8393 @file{foo.man} in the source, and then rename it to have the correct
8394 suffix, for example @file{foo.1}, when installing the file. Automake
8395 also supports this mode. For a valid section named @var{section},
8396 there is a corresponding directory named @samp{man@var{section}dir},
8397 and a corresponding @code{_MANS} variable. Files listed in such a
8398 variable are installed in the indicated section. If the file already
8399 has a valid suffix, then it is installed as-is; otherwise the file
8400 suffix is changed to match the section.
8402 For instance, consider this example:
8404 man1_MANS = rename.man thesame.1 alsothesame.1c
8408 In this case, @file{rename.man} will be renamed to @file{rename.1} when
8409 installed, but the other files will keep their names.
8411 @cindex Target, @code{install-man}
8412 @cindex Option, @option{no-installman}
8413 @cindex @code{install-man} target
8414 @cindex @option{no-installman} option
8415 @opindex no-installman
8416 @trindex install-man
8418 By default, man pages are installed by @samp{make install}. However,
8419 since the GNU project does not require man pages, many maintainers do
8420 not expend effort to keep the man pages up to date. In these cases, the
8421 @option{no-installman} option will prevent the man pages from being
8422 installed by default. The user can still explicitly install them via
8423 @samp{make install-man}.
8425 For fast installation, with many files it is preferable to use
8426 @samp{man@var{section}_MANS} over @samp{man_MANS} as well as files that
8427 do not need to be renamed.
8429 Man pages are not currently considered to be source, because it is not
8430 uncommon for man pages to be automatically generated. Therefore they
8431 are not automatically included in the distribution. However, this can
8432 be changed by use of the @code{dist_} prefix. For instance here is
8433 how to distribute and install the two man pages of GNU @command{cpio}
8434 (which includes both Texinfo documentation and man pages):
8437 dist_man_MANS = cpio.1 mt.1
8440 The @code{nobase_} prefix is meaningless for man pages and is
8444 @cindex @code{notrans_} prefix
8445 @cindex Man page renaming, avoiding
8446 @cindex Avoiding man page renaming
8448 Executables and manpages may be renamed upon installation
8449 (@pxref{Renaming}). For manpages this can be avoided by use of the
8450 @code{notrans_} prefix. For instance, suppose an executable @samp{foo}
8451 allowing to access a library function @samp{foo} from the command line.
8452 The way to avoid renaming of the @file{foo.3} manpage is:
8456 notrans_man_MANS = foo.3
8459 @cindex @code{notrans_} and @code{dist_} or @code{nodist_}
8460 @cindex @code{dist_} and @code{notrans_}
8461 @cindex @code{nodist_} and @code{notrans_}
8463 @samp{notrans_} must be specified first when used in conjunction with
8464 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
8465 Control}). For instance:
8468 notrans_dist_man3_MANS = bar.3
8472 @chapter What Gets Installed
8474 @cindex Installation support
8475 @cindex @samp{make install} support
8477 Naturally, Automake handles the details of installing your program
8478 once it has been built. All files named by the various primaries are
8479 automatically installed in the appropriate places when the user runs
8480 @samp{make install}.
8483 * Basics of Installation:: What gets installed where
8484 * The Two Parts of Install:: Installing data and programs separately
8485 * Extending Installation:: Adding your own rules for installation
8486 * Staged Installs:: Installation in a temporary location
8487 * Install Rules for the User:: Useful additional rules
8490 @node Basics of Installation
8491 @section Basics of Installation
8493 A file named in a primary is installed by copying the built file into
8494 the appropriate directory. The base name of the file is used when
8498 bin_PROGRAMS = hello subdir/goodbye
8501 In this example, both @samp{hello} and @samp{goodbye} will be installed
8502 in @samp{$(bindir)}.
8504 Sometimes it is useful to avoid the basename step at install time. For
8505 instance, you might have a number of header files in subdirectories of
8506 the source tree that are laid out precisely how you want to install
8507 them. In this situation you can use the @code{nobase_} prefix to
8508 suppress the base name step. For example:
8511 nobase_include_HEADERS = stdio.h sys/types.h
8515 will install @file{stdio.h} in @samp{$(includedir)} and @file{types.h}
8516 in @samp{$(includedir)/sys}.
8518 For most file types, Automake will install multiple files at once, while
8519 avoiding command line length issues (@pxref{Length Limitations}). Since
8520 some @command{install} programs will not install the same file twice in
8521 one invocation, you may need to ensure that file lists are unique within
8522 one variable such as @samp{nobase_include_HEADERS} above.
8524 You should not rely on the order in which files listed in one variable
8525 are installed. Likewise, to cater for parallel make, you should not
8526 rely on any particular file installation order even among different
8527 file types (library dependencies are an exception here).
8530 @node The Two Parts of Install
8531 @section The Two Parts of Install
8533 Automake generates separate @code{install-data} and @code{install-exec}
8534 rules, in case the installer is installing on multiple machines that
8535 share directory structure---these targets allow the machine-independent
8536 parts to be installed only once. @code{install-exec} installs
8537 platform-dependent files, and @code{install-data} installs
8538 platform-independent files. The @code{install} target depends on both
8539 of these targets. While Automake tries to automatically segregate
8540 objects into the correct category, the @file{Makefile.am} author is, in
8541 the end, responsible for making sure this is done correctly.
8542 @trindex install-data
8543 @trindex install-exec
8545 @cindex Install, two parts of
8547 Variables using the standard directory prefixes @samp{data},
8548 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
8549 @samp{pkgdata}, or @samp{pkginclude} are installed by
8550 @code{install-data}.
8552 Variables using the standard directory prefixes @samp{bin},
8553 @samp{sbin}, @samp{libexec}, @samp{sysconf}, @samp{localstate},
8554 @samp{lib}, or @samp{pkglib} are installed by @code{install-exec}.
8556 For instance, @code{data_DATA} files are installed by @code{install-data},
8557 while @code{bin_PROGRAMS} files are installed by @code{install-exec}.
8559 Any variable using a user-defined directory prefix with
8560 @samp{exec} in the name (e.g.,
8561 @c Keep in sync with primary-prefix-couples-documented-valid.sh
8562 @code{myexecbin_PROGRAMS}) is installed by @code{install-exec}. All
8563 other user-defined prefixes are installed by @code{install-data}.
8565 @node Extending Installation
8566 @section Extending Installation
8568 It is possible to extend this mechanism by defining an
8569 @code{install-exec-local} or @code{install-data-local} rule. If these
8570 rules exist, they will be run at @samp{make install} time. These
8571 rules can do almost anything; care is required.
8572 @trindex install-exec-local
8573 @trindex install-data-local
8575 Automake also supports two install hooks, @code{install-exec-hook} and
8576 @code{install-data-hook}. These hooks are run after all other install
8577 rules of the appropriate type, exec or data, have completed. So, for
8578 instance, it is possible to perform post-installation modifications
8579 using an install hook. @xref{Extending}, for some examples.
8580 @cindex Install hook
8582 @node Staged Installs
8583 @section Staged Installs
8586 Automake generates support for the @code{DESTDIR} variable in all
8587 install rules. @code{DESTDIR} is used during the @samp{make install}
8588 step to relocate install objects into a staging area. Each object and
8589 path is prefixed with the value of @code{DESTDIR} before being copied
8590 into the install area. Here is an example of typical DESTDIR usage:
8593 mkdir /tmp/staging &&
8594 make DESTDIR=/tmp/staging install
8597 The @command{mkdir} command avoids a security problem if the attacker
8598 creates a symbolic link from @file{/tmp/staging} to a victim area;
8599 then @command{make} places install objects in a directory tree built under
8600 @file{/tmp/staging}. If @file{/gnu/bin/foo} and
8601 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
8602 would install @file{/tmp/staging/gnu/bin/foo} and
8603 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
8605 This feature is commonly used to build install images and packages
8608 Support for @code{DESTDIR} is implemented by coding it directly into
8609 the install rules. If your @file{Makefile.am} uses a local install
8610 rule (e.g., @code{install-exec-local}) or an install hook, then you
8611 must write that code to respect @code{DESTDIR}.
8613 @xref{Makefile Conventions, , , standards, The GNU Coding Standards},
8614 for another usage example.
8616 @node Install Rules for the User
8617 @section Install Rules for the User
8619 Automake also generates rules for targets @code{uninstall},
8620 @code{installdirs}, and @code{install-strip}.
8622 @trindex installdirs
8623 @trindex install-strip
8625 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
8626 There is no notion of separate uninstalls for ``exec'' and ``data'', as
8627 these features would not provide additional functionality.
8629 Note that @code{uninstall} is not meant as a replacement for a real
8634 @chapter What Gets Cleaned
8636 @cindex @samp{make clean} support
8638 The GNU Makefile Standards specify a number of different clean rules.
8639 @xref{Standard Targets, , Standard Targets for Users, standards,
8640 The GNU Coding Standards}.
8642 Generally the files that can be cleaned are determined automatically by
8643 Automake. Of course, Automake also recognizes some variables that can
8644 be defined to specify additional files to clean. These variables are
8645 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
8646 @code{MAINTAINERCLEANFILES}.
8647 @vindex MOSTLYCLEANFILES
8649 @vindex DISTCLEANFILES
8650 @vindex MAINTAINERCLEANFILES
8652 @trindex mostlyclean-local
8653 @trindex clean-local
8654 @trindex distclean-local
8655 @trindex maintainer-clean-local
8656 When cleaning involves more than deleting some hard-coded list of
8657 files, it is also possible to supplement the cleaning rules with your
8658 own commands. Simply define a rule for any of the
8659 @code{mostlyclean-local}, @code{clean-local}, @code{distclean-local},
8660 or @code{maintainer-clean-local} targets (@pxref{Extending}). A common
8661 case is deleting a directory, for instance, a directory created by the
8669 Since @command{make} allows only one set of rules for a given target,
8670 a more extensible way of writing this is to use a separate target
8671 listed as a dependency:
8674 clean-local: clean-local-check
8675 .PHONY: clean-local-check
8680 As the GNU Standards aren't always explicit as to which files should
8681 be removed by which rule, we've adopted a heuristic that we believe
8682 was first formulated by Fran@,{c}ois Pinard:
8686 If @command{make} built it, and it is commonly something that one would
8687 want to rebuild (for instance, a @file{.o} file), then
8688 @code{mostlyclean} should delete it.
8691 Otherwise, if @command{make} built it, then @code{clean} should delete it.
8694 If @command{configure} built it, then @code{distclean} should delete it.
8697 If the maintainer built it (for instance, a @file{.info} file), then
8698 @code{maintainer-clean} should delete it. However
8699 @code{maintainer-clean} should not delete anything that needs to exist
8700 in order to run @samp{./configure && make}.
8703 We recommend that you follow this same set of heuristics in your
8708 @chapter What Goes in a Distribution
8711 * Basics of Distribution:: Files distributed by default
8712 * Fine-grained Distribution Control:: @code{dist_} and @code{nodist_} prefixes
8713 * The dist Hook:: A target for last-minute distribution changes
8714 * Checking the Distribution:: @samp{make distcheck} explained
8715 * The Types of Distributions:: A variety of formats and compression methods
8718 @node Basics of Distribution
8719 @section Basics of Distribution
8721 @cindex @samp{make dist}
8726 The @code{dist} rule in the generated @file{Makefile.in} can be used
8727 to generate a gzipped @code{tar} file and/or other flavors of archives
8728 for distribution. The file is named based on the @code{PACKAGE} and
8729 @code{VERSION} variables automatically defined by either the
8730 @code{AC_INIT} invocation or by a @emph{deprecated} two-arguments
8731 invocation of the @code{AM_INIT_AUTOMAKE} macro (see @ref{Public
8732 Macros} for how these variables get their values, from either defaults
8733 or explicit values---it's slightly trickier than one would expect).
8734 More precisely, the gzipped @code{tar} file is named
8735 @samp{$@{PACKAGE@}-$@{VERSION@}.tar.gz}.
8737 @c See automake #9822.
8739 You can set the environment (or @code{Makefile.am}) variable @code{TAR}
8740 to override the tar program used; it defaults to @code{tar}.
8741 @xref{The Types of Distributions}, for how to generate other kinds of
8745 With GNU tar, you can also set the environment (or @code{Makefile.am})
8746 variable @code{TAR_OPTIONS} to pass options to @code{tar}. One common
8747 case for this is wanting to avoid using the local user's uid and gid
8748 in the tar file, or the uid being larger than is supported by the tar
8749 format (not uncommon nowadays). This can be done with, for example>
8752 TAR_OPTIONS = --owner=0 --group=0
8757 The @code{export} (a GNU make feature) is necessary to pass the
8758 variable in the environment to the @code{tar} invocation.
8759 (For more discussion, see @url{https://bugs.gnu.org/19615}.)
8761 For the most part, the files to distribute are automatically
8766 All source files are automatically included in a distribution, as are
8767 all @file{Makefile.am} and @file{Makefile.in} files.
8769 @acindex AC_CONFIG_FILES
8771 Files that are read by @command{configure} are automatically
8772 distributed. These are the source files as specified in various
8773 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings.
8775 @cindex @code{m4_include}, distribution
8776 @cindex @code{include}, distribution
8780 Files included in a @file{Makefile.am} (using @code{include}) or in
8781 @file{configure.ac} (using @code{m4_include}).
8784 Automake has a built-in list of commonly used files automatically
8785 included in the distribution if they are found in the current
8786 directory (either physically, or as the target of a @file{Makefile.am}
8787 rule). Some common examples: @file{ABOUT-GNU}, @file{COPYING},
8790 This list also includes helper scripts installed with @samp{automake
8791 --add-missing}. Some common examples: @file{compile},
8792 @file{config.guess}, @file{config.rpath}, @file{config.sub},
8796 Automake has another built-in list of files automatically distributed
8797 if they are found either with the plain name, or with extension
8798 @file{.md} (presumably MarkDown, though this not checked). They are
8799 checked for in that order, so the plain name is preferred. These are:
8800 @file{AUTHORS ChangeLog INSTALL NEWS README README-alpha THANKS}.
8803 A final built-in list of files are those distributed only if other
8804 certain conditions hold. For example,
8805 @c Keep in sync with autodist-config-headers.sh
8806 the files @file{config.h.top} and @file{config.h.bot} are
8807 automatically distributed only if, e.g.,
8808 @samp{AC_CONFIG_HEADERS([config.h])} is used in @file{configure.ac}).
8809 @file{README-alpha} is another such file, with @file{README-alpha.md}
8810 distributed if that is what is available; @pxref{Strictness}, for its
8811 conditions for distribution.
8816 These three lists of files are given in their entirety in the output
8817 from @code{automake --help}.
8820 Despite all this automatic inclusion, it is still common to have files
8821 to be distributed which are not found by the automatic rules. You
8822 should listed these files in the @code{EXTRA_DIST} variable. You can
8823 mention files in subdirectories in @code{EXTRA_DIST}.
8825 You can also mention a directory in @code{EXTRA_DIST}; in this case
8826 the entire directory will be recursively copied into the distribution.
8827 To emphasize, this copies @emph{everything} in the directory,
8828 including temporary editor files, intermediate build files, version
8829 control files, etc.; thus we recommend against using this feature
8830 as-is. However, you can use the @code{dist-hook} feature to
8831 ameliorate the problem; @pxref{The dist Hook}.
8834 @vindex DIST_SUBDIRS
8835 If you define @code{SUBDIRS}, Automake will recursively include the
8836 subdirectories in the distribution. If @code{SUBDIRS} is defined
8837 conditionally (@pxref{Conditionals}), Automake will normally include
8838 all directories that could possibly appear in @code{SUBDIRS} in the
8839 distribution. If you need to specify the set of directories
8840 conditionally, you can set the variable @code{DIST_SUBDIRS} to the
8841 exact list of subdirectories to include in the distribution
8842 (@pxref{Conditional Subdirectories}).
8845 @node Fine-grained Distribution Control
8846 @section Fine-grained Distribution Control
8850 Sometimes you need tighter control over what does @emph{not} go into the
8851 distribution; for instance, you might have source files that are
8852 generated and that you do not want to distribute. In this case
8853 Automake gives fine-grained control using the @code{dist} and
8854 @code{nodist} prefixes. Any primary or @code{_SOURCES} variable can be
8855 prefixed with @code{dist_} to add the listed files to the distribution.
8856 Similarly, @code{nodist_} can be used to omit the files from the
8859 As an example, here is how you would cause some data to be distributed
8860 while leaving some source code out of the distribution:
8863 dist_data_DATA = distribute-this
8865 nodist_foo_SOURCES = do-not-distribute.c
8869 @section The dist Hook
8873 Occasionally it is useful to be able to change the distribution before
8874 it is packaged up. If the @code{dist-hook} rule exists, it is run
8875 after the distribution directory is filled, but before the actual
8876 distribution archives are created. One way to use this is for
8877 removing unnecessary files that get recursively included by specifying
8878 a directory in @code{EXTRA_DIST}:
8883 chmod -R u+w $(distdir)/doc
8884 rm -rf `find $(distdir)/doc -type d -name RCS`
8887 @c The caveats described here should be documented in 'disthook.sh'.
8889 The @code{dist-hook} recipe should not assume that the regular files
8890 in the distribution directory are writable; this might not be the case
8891 if one is packaging from a read-only source tree, or when a @code{make
8892 distcheck} is being done. Similarly, the recipe should not assume
8893 that the subdirectories put into the distribution directory as a
8894 result of being listed in @code{EXTRA_DIST} are writable. So, if the
8895 @code{dist-hook} recipe wants to modify the content of an existing
8896 file (or @code{EXTRA_DIST} subdirectory) in the distribution
8897 directory, it should explicitly to make it writable first:
8900 EXTRA_DIST = README doc
8902 chmod u+w $(distdir)/README $(distdir)/doc
8903 echo "Distribution date: `date`" >> $(distdir)/README
8904 rm -f $(distdir)/doc/HACKING
8909 Two variables that come handy when writing @code{dist-hook} rules are
8910 @samp{$(distdir)} and @samp{$(top_distdir)}.
8912 @samp{$(distdir)} points to the directory where the @code{dist} rule
8913 will copy files from the current directory before creating the
8914 tarball. If you are at the top-level directory, then @samp{distdir =
8915 $(PACKAGE)-$(VERSION)}. When used from subdirectory named
8916 @file{foo/}, then @samp{distdir = ../$(PACKAGE)-$(VERSION)/foo}.
8917 @samp{$(distdir)} can be either a relative or absolute path; do not
8918 assume a particular form.
8920 @samp{$(top_distdir)} always points to the root directory of the
8921 distributed tree. At the top level it's equal to @samp{$(distdir)}.
8922 In the @file{foo/} subdirectory @samp{top_distdir =
8923 ../$(PACKAGE)-$(VERSION)}. @samp{$(top_distdir)} can also be either a
8924 relative or absolute path.
8926 @acindex AC_CONFIG_SUBDIRS
8927 When packages are nested using @code{AC_CONFIG_SUBDIRS}
8928 (@pxref{Subpackages}), then @samp{$(distdir)} and
8929 @samp{$(top_distdir)} are relative to the package where @samp{make
8930 dist} was run, not to any sub-packages involved.
8932 @node Checking the Distribution
8933 @section Checking the Distribution
8935 @cindex @samp{make distcheck}
8937 Automake also generates a @code{distcheck} rule that can be of help
8938 to ensure that a given distribution will actually work. Simplifying
8939 a bit, we can say this rule first makes a distribution, and then,
8940 @emph{operating from it}, takes the following steps (in this order):
8943 does a @code{VPATH} build (@pxref{VPATH Builds}), with the
8944 @code{srcdir} and all its content made @emph{read-only};
8946 makes the printable documentation (with @command{make dvi}), if any,
8948 runs the test suite (with @command{make check}) on this fresh build;
8950 installs the package in a temporary directory (with @command{make
8951 install}), and runs the test suite on the resulting installation
8952 (with @command{make installcheck});
8954 checks that the package can be correctly uninstalled (by @command{make
8955 uninstall}) and cleaned (by @code{make distclean});
8957 finally, makes another tarball to ensure the distribution is
8961 All of these actions are performed in a temporary directory. The
8962 exact location and the exact structure of such a directory (where the
8963 read-only sources are placed, how the temporary build and install
8964 directories are named and how deeply they are nested, etc.) is to be
8965 considered an implementation detail, which can change at any time, so
8966 please do not rely on it.
8969 * DISTCHECK_CONFIGURE_FLAGS:: Overriding configure flags in distcheck.
8970 * distcheck-hook:: Running commands after distcheck.
8971 * dvi and distcheck:: Overriding the distcheck doc target.
8972 * distcleancheck:: Handling files not cleaned.
8973 * distuninstallcheck:: Overriding the uninstall check.
8974 * Errors with distclean::
8977 @node DISTCHECK_CONFIGURE_FLAGS
8978 @subsection @code{DISTCHECK_CONFIGURE_FLAGS}
8979 @vindex AM_DISTCHECK_CONFIGURE_FLAGS
8980 @vindex DISTCHECK_CONFIGURE_FLAGS
8982 Building the package involves running @samp{./configure}. If you need
8983 to supply additional flags to @command{configure}, define them in the
8984 @code{AM_DISTCHECK_CONFIGURE_FLAGS} variable in your top-level
8985 @file{Makefile.am}. The user can still extend or override the flags
8986 provided there by defining the @code{DISTCHECK_CONFIGURE_FLAGS} variable,
8987 on the command line when invoking @command{make}.
8988 @c See automake bug#14991 for more details about how the following holds.
8989 It's worth noting that @command{make distcheck} needs complete control
8990 over the @command{configure} options @option{--srcdir} and
8991 @option{--prefix}, so those options cannot be overridden by
8992 @code{AM_DISTCHECK_CONFIGURE_FLAGS} nor by
8993 @code{DISTCHECK_CONFIGURE_FLAGS}.
8995 Developers are encouraged to strive to make their code buildable
8996 without requiring any special configure option; thus, in general, you
8997 shouldn't define @code{AM_DISTCHECK_CONFIGURE_FLAGS}. GNU
8998 @command{m4} offers an example of when its use is justified, however.
8999 GNU @command{m4} configures by default with its experimental and
9000 seldom used @samp{changeword} feature disabled; so in this case it is
9001 useful to have @command{make distcheck} run configure with the
9002 @option{--with-changeword} option, to ensure that the code for
9003 changeword support still compiles correctly. GNU @command{m4} also
9004 employs the @code{AM_DISTCHECK_CONFIGURE_FLAGS} variable to
9005 stress-test the use of @option{--program-prefix=g}, since at one point
9006 the @command{m4} build system had a bug where @command{make
9007 installcheck} was wrongly assuming it could blindly test @samp{m4},
9008 rather than the just-installed @samp{gm4}.
9010 @node distcheck-hook
9011 @subsection @code{distcheck-hook}
9012 @trindex distcheck-hook
9014 If the @code{distcheck-hook} rule is defined in your top-level
9015 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
9016 the new distribution has been unpacked, but before the unpacked copy
9017 is configured and built. Your @code{distcheck-hook} can do almost
9018 anything, though as always caution is advised. Generally this hook is
9019 used to check for potential distribution errors not caught by the
9022 @code{distcheck-hook}, as well as @code{AM_DISTCHECK_CONFIGURE_FLAGS}
9023 and @code{DISTCHECK_CONFIGURE_FLAGS}, are not honored in a subpackage
9024 @file{Makefile.am}, but the flags from
9025 @code{AM_DISTCHECK_CONFIGURE_FLAGS} and
9026 @code{DISTCHECK_CONFIGURE_FLAGS} are passed down to the
9027 @command{configure} script of the subpackage.
9029 @node dvi and distcheck
9030 @subsection @code{dvi} and @code{distcheck}
9033 Ordinarily, @command{make distcheck} runs @command{make dvi}. It does
9034 nothing if the distribution contains no Texinfo sources. If the
9035 distribution does contain a Texinfo manual, by default the @code{dvi}
9036 target will run @TeX{} to make sure it can be successfully processed
9039 @vindex AM_DISTCHECK_DVI_TARGET
9040 @cindex @code{eps} images, and @code{distcheck}
9041 However, you may wish to test the manual by producing @code{pdf}
9042 (e.g., if your manual uses images in formats other than @code{eps}),
9043 @code{html} (if you don't have @TeX{} at all), some other format, or
9044 just skip the test entirely (not recommended). You can change the
9045 target that is run by setting the variable
9046 @code{AM_DISTCHECK_DVI_TARGET} in your @code{Makefile.am}; for
9050 AM_DISTCHECK_DVI_TARGET = pdf
9053 To make @code{dvi} into a do-nothing target, see the example for
9054 @code{EMPTY_AUTOMAKE_TARGETS} in @ref{Third-Party Makefiles}.
9056 @node distcleancheck
9057 @subsection @code{distcleancheck}
9058 @cindex @samp{make distcleancheck}
9059 @trindex distcleancheck
9060 @vindex DISTCLEANFILES
9061 @vindex distcleancheck_listfiles
9063 @code{distcheck} ensures that the @code{distclean} rule actually
9064 removes all built files. This is done by running @samp{make
9065 distcleancheck} at the end of the @code{VPATH} build. By default,
9066 @code{distcleancheck} will run @code{distclean} and then make sure the
9067 build tree has been emptied by running the value of the variable
9068 @samp{$(distcleancheck_listfiles)}. Often this check will find
9069 generated files that you forgot to add to the @code{DISTCLEANFILES}
9070 variable (@pxref{Clean}).
9072 The @code{distcleancheck} behavior should be OK for most packages,
9073 otherwise you have the possibility to override the definition of
9074 either the @code{distcleancheck} rule, or the
9075 @samp{$(distcleancheck_listfiles)} variable. For instance, to disable
9076 @code{distcleancheck} completely (not recommended), add the following
9077 rule to your top-level @file{Makefile.am}:
9084 If you want @code{distcleancheck} to ignore built files that have not
9085 been cleaned because they are also part of the distribution, make the
9086 following definition:
9088 @c Keep in sync with t/distcleancheck.sh.
9090 distcleancheck_listfiles = \
9091 find . -type f -exec sh -c 'test -f $(srcdir)/$$1 || echo $$1' \
9095 The above definition is not the default because it's usually an error
9096 if your Makefiles cause some distributed files to be rebuilt when the
9097 user builds the package: consider the user missing the tool required
9098 to build the file; or if the required tool is built by your package,
9099 consider the cross-compilation case where it can't be run.
9101 Please see the (following) section @ref{Errors with distclean} before
9102 playing with @code{distcleancheck_listfiles}.
9104 @node distuninstallcheck
9105 @subsection @code{distuninstallcheck}
9106 @cindex @samp{make distuninstallcheck}
9107 @trindex distuninstallcheck
9108 @vindex distuninstallcheck_listfiles
9110 @code{distcheck} also checks that the @code{uninstall} rule works
9111 properly, both for ordinary and @code{DESTDIR} builds. It does this
9112 by invoking @samp{make uninstall}, and then it checks the install tree
9113 to see if any files are left over. This check will make sure that you
9114 correctly coded your @code{uninstall}-related rules.
9116 By default, the checking is done by the @code{distuninstallcheck}
9117 rule, and the list of files in the install tree is generated by
9118 @samp{$(distuninstallcheck_listfiles)}. The value of the latter
9119 variable is taken to be a shell command to run that prints the list of
9122 Either of these can be overridden to modify the behavior of
9123 @code{distcheck}. For instance, to disable this check completely (not
9124 recommended), you would write:
9131 @node Errors with distclean
9132 @subsection Errors with @code{distclean}
9133 @cindex @code{distclean}, diagnostic
9134 @cindex @samp{make distclean}, diagnostic
9135 @cindex dependencies and distributed files
9138 As explained in the section above (@pxref{Checking the Distribution}),
9139 @samp{make distcheck} attempts to build and check your package for
9140 errors. One such error you might see is:
9143 ERROR: files left in build directory after distclean:
9146 @noindent The file(s) left in the build directory after @samp{make distclean}
9147 has run are listed after this error message. This can happen in two
9151 @item files that were forgotten to be distclean-ed;
9152 @item distributed files that are erroneously rebuilt.
9155 In the first case of simple left-over files not intended to be
9156 distributed, the fix is to include them for cleaning (@pxref{Clean});
9157 this is straightforward and doesn't need more explanation.
9160 @cindex man pages, generating and distributing
9161 The second case, however, is not always easy to understand and fix, so
9162 let's proceed with an example. Suppose our package contains a program
9163 for which we want to build a man page using @command{help2man}. GNU
9164 @command{help2man} produces simple manual pages from the
9165 @option{--help} and @option{--version} output of other commands
9166 (@pxref{,,,help2man, The Help2man Manual}). Because we don't want to
9167 force our users to install @command{help2man}, we distribute the
9168 generated man page using the following setup.
9171 # This Makefile.am is bogus.
9174 dist_man_MANS = foo.1
9177 help2man --output=foo.1 ./foo$(EXEEXT)
9180 This will effectively distribute the man page. However,
9181 @samp{make distcheck} will fail with:
9184 ERROR: files left in build directory after distclean:
9188 Why was @file{foo.1} rebuilt? Because although distributed,
9189 @file{foo.1} depends on a non-distributed built file:
9190 @file{foo$(EXEEXT)}. @file{foo$(EXEEXT)} is built by the user, so it
9191 will always appear to be newer than the distributed @file{foo.1}.
9193 In other words, @samp{make distcheck} caught an inconsistency in our
9194 package. Our intent was to distribute @file{foo.1} so users do not
9195 need to install @command{help2man}, but since this rule causes this
9196 file to be always rebuilt, users @emph{do} need @command{help2man}.
9197 Either we should ensure that @file{foo.1} is not rebuilt by users, or
9198 there is no point in distributing @file{foo.1}.
9200 More generally, the rule is that distributed files should never depend
9201 on non-distributed built files. If you distribute something
9202 generated, distribute all its sources.
9204 One way to fix the above example, while still distributing
9205 @file{foo.1}, is to not depend on @file{foo$(EXEEXT)}, but instead on
9206 relevant source files. For instance, assuming @command{foo --version}
9207 and @command{foo --help} do not change unless @file{foo.c} or
9208 @file{configure.ac} change, we could write the following
9214 dist_man_MANS = foo.1
9216 foo.1: foo.c $(top_srcdir)/configure.ac
9217 $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
9218 help2man --output=foo.1 ./foo$(EXEEXT)
9221 This way, @file{foo.1} will not get rebuilt every time
9222 @file{foo$(EXEEXT)} changes. The @command{make} call makes sure
9223 @file{foo$(EXEEXT)} is up-to-date before @command{help2man}.
9225 Another step towards ensuring this would be to use separate
9226 directories for binaries and man pages, and set @code{SUBDIRS} so that
9227 binaries are built before man pages. Unfortunately, this alone is, in
9228 general, not sufficient. In order to avoid to avoid concurrency bugs,
9229 it may be necessary to include wrappers; this is done by GNU Autoconf,
9232 We could also decide not to distribute @file{foo.1}. In this case
9233 it's fine to have @file{foo.1} dependent upon @file{foo$(EXEEXT)},
9234 since both will have to be rebuilt. However, it might be impossible
9235 to build the package in a cross-compilation, because building
9236 @file{foo.1} involves an @emph{execution} of @file{foo$(EXEEXT)}. The
9237 exception would be if @file{foo} is a platform-independent script,
9238 such as @command{help2man}.
9240 Another context where such errors are common is when distributed files
9241 are built by tools that are built by the package. The pattern is
9245 distributed-file: built-tools distributed-sources
9250 should be changed to
9253 distributed-file: distributed-sources
9254 $(MAKE) $(AM_MAKEFLAGS) built-tools
9259 or you could choose not to distribute @file{distributed-file}, if
9260 cross-compilation does not matter.
9262 The points made through these examples are worth summarizing:
9266 @item Distributed files should never depend upon non-distributed built files.
9268 @item Distributed files should be distributed with all their dependencies.
9270 @item If a file is @emph{intended} to be rebuilt by users, then there
9271 is no point in distributing it.
9275 Real-world examples for @code{help2man}:
9279 Autoconf takes the approach described above, including man pages in
9280 its releases. A wrapper for each script is needed to avoid concurrency
9281 problems. See its source file @code{autoconf/man/local.mk}, which has
9282 a good discussion of the necessary additional details.
9285 Automake itself takes another approach: it does @emph{not} include man
9286 pages in distributions; thus, every user generates them when building
9287 from the release tarballs. This is ok (only) because Automake also
9288 includes a copy of the @command{help2man} script, which is plausible
9289 because @command{help2man} is small, self-contained, and
9290 platform-independent. See the source file
9291 @code{automake/doc/local.mk}.
9294 @vrindex distcleancheck_listfiles
9295 If you're desperate, it's possible to disable this check completely by
9296 setting @code{distcleancheck_listfiles} (@pxref{distcleancheck}).
9297 Make sure you understand the reason why @samp{make distcheck}
9298 complains first. @code{distcleancheck_listfiles} is a way to
9299 @emph{hide} errors, not to fix them. You can always do better.
9301 @node The Types of Distributions
9302 @section The Types of Distributions
9304 Automake generates rules to provide archives of the project for
9305 distributions in various formats. Their targets are:
9308 @item @code{dist-gzip}
9312 @c See https://bugs.gnu.org/68151 about using -9 instead of --best.
9313 Generate a @samp{gzip} tar archive of the distribution. This is the
9314 only format enabled by default. By default, this rule makes
9315 @command{gzip} use a compression option of @option{-9} (more widely
9316 supported than @option{--best}). To make
9317 it use a different one, set the @env{GZIP_ENV} environment variable.
9318 For example, @samp{make dist-gzip GZIP_ENV=-7}. @env{GZIP_ENV} is not
9319 used when decompressing.
9321 @item @code{dist-bzip2}
9325 Generate a @samp{bzip2} tar archive of the distribution. bzip2
9326 archives are usually smaller than gzipped archives. By default, this
9327 rule makes @samp{bzip2} use a compression option of @option{-9}. To
9328 make it use a different one, set the @env{BZIP2} environment variable.
9330 @item @code{dist-lzip}
9334 Generate an @samp{lzip} tar archive of the distribution.
9335 @command{lzip} archives are usually smaller than
9336 @command{bzip2}-compressed archives. By default, this rule makes
9337 @samp{lzip} use a compression option of @option{-9}. To make it use a
9338 different one, set the @env{LZIP_OPT} environment variable.
9340 @item @code{dist-xz}
9344 Generate an @samp{xz} tar archive of the distribution. @command{xz}
9345 archives are usually smaller than @command{bzip2}-compressed archives.
9346 By default, this rule makes @samp{xz} use a compression option of
9347 @option{-e}. To make it use a different one, set the @env{XZ_OPT}
9348 environment variable. For example, run this command to use the
9349 default compression ratio, but with a progress indicator: @samp{make
9350 dist-xz XZ_OPT=-ve}.
9354 @item @code{dist-zip}
9355 Generate a @samp{zip} archive of the distribution.
9357 @item @code{dist-zstd}
9362 Generate a @code{zstd} tar archive of the distribution. By default,
9363 this rule makes @command{zstd} use a compression option of
9364 @option{-19}. To use a different setting, set the @env{ZSTD_OPT}
9365 environment variable. For example, run this command to use the
9366 default compression ratio, but with a progress indicator: @samp{make
9367 dist-zstd ZSTD_OPT=-19v}. However, note that for compatibility with
9368 @command{zstd} itself, you may instead set the @env{ZSTD_CLEVEL}
9369 environment variable, in which case, any @env{ZSTD_OPT} setting is
9372 @item @code{dist-shar}
9375 Generate a @samp{shar} archive of the distribution. This format
9376 archive is obsolescent, and use of this option is deprecated.
9377 It and the corresponding functionality will be removed altogether
9380 @item @code{dist-tarZ}
9383 Generate a tar archive of the distribution, compressed with the
9384 historical (and obsolescent) program @command{compress}. This
9385 option is deprecated, and it and the corresponding functionality
9386 will be removed altogether in Automake 2.0.
9391 The rule @code{dist} (and its historical synonym @code{dist-all})
9392 will create archives in all the enabled formats (@pxref{List of
9393 Automake options} for how to change this list). By default, only
9394 the @code{dist-gzip} target is enabled by @code{dist}.
9398 @chapter Support for test suites
9401 @cindex @code{make check}
9404 Automake can generate code to handle two kinds of test suites. One is
9405 based on integration with the @command{dejagnu} framework. The other
9406 (and most used) form is based on the use of generic test scripts, and
9407 its activation is triggered by the definition of the special @code{TESTS}
9408 variable. This second form allows for various degrees of sophistication
9409 and customization; in particular, it allows for concurrent execution
9410 of test scripts, use of established test protocols such as TAP, and
9411 definition of custom test drivers and test runners.
9414 In either case, the testsuite is invoked via @samp{make check}.
9417 * Generalities about Testing:: Concepts and terminology about testing
9418 * Simple Tests:: Listing test scripts in @code{TESTS}
9419 * Custom Test Drivers:: Writing and using custom test drivers
9420 * Using the TAP test protocol:: Integrating test scripts that use the TAP protocol
9421 * DejaGnu Tests:: Interfacing with the @command{dejagnu} testing framework
9422 * Install Tests:: Running tests on installed packages
9425 @node Generalities about Testing
9426 @section Generalities about Testing
9428 The purpose of testing is to determine whether a program or system behaves
9429 as expected (e.g., known inputs produce the expected outputs, error
9430 conditions are correctly handled or reported, and older bugs do not
9434 The minimal unit of testing is usually called @emph{test case}, or simply
9435 @emph{test}. How a test case is defined or delimited, and even what
9436 exactly @emph{constitutes} a test case, depends heavily on the testing
9437 paradigm and/or framework in use, so we won't attempt any more precise
9438 definition. The set of the test cases for a given program or system
9439 constitutes its @emph{testsuite}.
9441 @cindex test harness
9442 @cindex testsuite harness
9443 A @emph{test harness} (also @emph{testsuite harness}) is a program or
9444 software component that executes all (or part of) the defined test cases,
9445 analyzes their outcomes, and reports or registers these outcomes
9446 appropriately. Again, the details of how this is accomplished (and how
9447 the developer and user can influence it or interface with it) varies
9448 wildly, and we'll attempt no precise definition.
9451 @cindex test failure
9452 A test is said to @emph{pass} when it can determine that the condition or
9453 behavior it means to verify holds, and is said to @emph{fail} when it can
9454 determine that such condition of behavior does @emph{not} hold.
9457 Sometimes, tests can rely on non-portable tools or prerequisites, or
9458 simply make no sense on a given system (for example, a test checking a
9459 Windows-specific feature makes no sense on a GNU/Linux system). In
9460 this case, accordingly to the definition above, the tests can neither
9461 be considered passed nor failed; instead, they are @emph{skipped},
9462 that is, they are not run, or their result is in any case ignored for
9463 what concerns the count of failures and successes. Skips are usually
9464 explicitly reported though, so that the user will be aware that not
9465 all of the testsuite has been run.
9468 @cindex expected failure
9469 @cindex expected test failure
9471 @cindex unexpected pass
9472 @cindex unexpected test pass
9473 It's not uncommon, especially during early development stages, that some
9474 tests fail for known reasons, and that the developer doesn't want to
9475 tackle these failures immediately (this is especially true when the
9476 failing tests deal with corner cases). In this situation, the better
9477 policy is to declare that each of those failures is an @emph{expected
9478 failure} (or @emph{xfail}). In case a test that is expected to fail ends
9479 up passing instead, many testing environments will flag the result as a
9480 special kind of failure called @emph{unexpected pass} (or @emph{xpass}).
9483 @cindex Distinction between errors and failures in testsuites
9484 Many testing environments and frameworks distinguish between test failures
9485 and hard errors. As we've seen, a test failure happens when some invariant
9486 or expected behavior of the software under test is not met. A @emph{hard
9487 error} happens when e.g., the set-up of a test case scenario fails, or when
9488 some other unexpected or highly undesirable condition is encountered (for
9489 example, the program under test experiences a segmentation fault).
9492 @section Simple Tests
9495 * Scripts-based Testsuites:: Automake-specific concepts and terminology
9496 * Serial Test Harness:: Older (and discouraged) serial test harness
9497 * Parallel Test Harness:: Generic concurrent test harness
9500 @node Scripts-based Testsuites
9501 @subsection Scripts-based Testsuites
9503 If the special variable @code{TESTS} is defined, its value is taken to be
9504 a list of programs or scripts to run in order to do the testing. Under
9505 the appropriate circumstances, it's possible for @code{TESTS} to list
9506 also data files to be passed to one or more test scripts defined by
9507 different means (the so-called ``log compilers'', @pxref{Parallel Test
9510 Test scripts can be executed serially or concurrently. Automake supports
9511 both these kinds of test execution, with the parallel test harness being
9512 the default. The concurrent test harness relies on the concurrence
9513 capabilities (if any) offered by the underlying @command{make}
9514 implementation, and can thus only be as good as those are.
9516 By default, only the exit statuses of the test scripts are considered when
9517 determining the testsuite outcome. But Automake allows also the use of
9518 more complex test protocols, either standard (@pxref{Using the TAP test
9519 protocol}) or custom (@pxref{Custom Test Drivers}). You can't
9520 enable such protocols when the serial harness is used, though.
9521 In the rest of this section we are going to concentrate mostly on
9522 protocol-less tests, since we cover test protocols in a later section
9523 (again, @pxref{Custom Test Drivers}).
9525 @cindex Exit status 77, special interpretation
9526 @cindex Exit status 99, special interpretation
9527 When no test protocol is in use, an exit status of 0 from a test script will
9528 denote a success, an exit status of 77 a skipped test, an exit status of 99
9529 a hard error, and any other exit status will denote a failure.
9531 @cindex Tests, expected failure
9532 @cindex Expected test failure
9534 @vindex DISABLE_HARD_ERRORS
9535 @cindex Disabling hard errors
9536 You may define the variable @code{XFAIL_TESTS} to a list of tests
9537 (usually a subset of @code{TESTS}) that are expected to fail; this will
9538 effectively reverse the result of those tests (with the provision that
9539 skips and hard errors remain untouched). You may also instruct the
9540 testsuite harness to treat hard errors like simple failures, by defining
9541 the @code{DISABLE_HARD_ERRORS} make variable to a nonempty value.
9543 Note however that, for tests based on more complex test protocols,
9544 the exact effects of @code{XFAIL_TESTS} and @code{DISABLE_HARD_ERRORS}
9545 might change, or they might even have no effect at all (for example,
9546 @c Keep this in sync with tap-no-disable-hard-errors.sh
9547 in tests using TAP, there is no way to disable hard errors, and the
9548 @code{DISABLE_HARD_ERRORS} variable has no effect on them).
9550 @anchor{Testsuite progress on console}
9551 @cindex Testsuite progress on console
9552 The result of each test case run by the scripts in @code{TESTS} will be
9553 printed on standard output, along with the test name. For test protocols
9554 that allow more test cases per test script (such as TAP), a number,
9555 identifier and/or brief description specific for the single test case is
9556 expected to be printed in addition to the name of the test script. The
9557 possible results (whose meanings should be clear from the previous
9558 @ref{Generalities about Testing}) are @code{PASS}, @code{FAIL},
9559 @code{SKIP}, @code{XFAIL}, @code{XPASS} and @code{ERROR}. Here is an
9560 example of output from a hypothetical testsuite that uses both plain
9562 @c Keep in sync with tap-doc.sh
9565 PASS: zardoz.tap 1 - Daemon started
9566 PASS: zardoz.tap 2 - Daemon responding
9567 SKIP: zardoz.tap 3 - Daemon uses /proc # SKIP /proc is not mounted
9568 PASS: zardoz.tap 4 - Daemon stopped
9571 XFAIL: mu.tap 2 # TODO frobnication not yet implemented
9575 A testsuite summary (expected to report at least the number of run,
9576 skipped and failed tests) will be printed at the end of the testsuite
9577 run. By default, the first line of the summary has the form:
9580 Testsuite summary for @var{package-string}
9583 @c See automake bug#11745.
9584 @vindex AM_TESTSUITE_SUMMARY_HEADER
9586 where @var{package-string} is the name and version of the package. If
9587 you have several independent test suites for different parts of the
9588 package, though, it can be misleading for each suite to imply it is
9589 for the whole package. Or, in complex projects, you may wish to add
9590 the current directory or other information to the testsuite header
9591 line. So you can override the @samp{ for @var{package-string}} suffix
9592 on that line by setting the @code{AM_TESTSUITE_SUMMARY_HEADER}
9593 variable. The value of this variable is used unquoted in a shell echo
9594 command, so you must include any necessary quotes. For example, the
9598 AM_TESTSUITE_SUMMARY_HEADER = ' for $(PACKAGE_STRING)'
9602 including the double quotes (interpreted by the shell) and the leading
9603 space (since the value is output directly after the @samp{Testsuite
9604 summary}). The @code{$(PACKAGE_STRING)} is substituted by @code{make}.
9606 @anchor{Simple tests and color-tests}
9607 @vindex AM_COLOR_TESTS
9608 @cindex Colorized testsuite output
9609 If the standard output is connected to a capable terminal, then the test
9610 results and the summary are colored appropriately. The developer and the
9611 user can disable colored output by setting the @command{make} variable
9612 @samp{AM_COLOR_TESTS=no}; the user can in addition force colored output
9613 even without a connecting terminal with @samp{AM_COLOR_TESTS=always}.
9614 It's also worth noting that some @command{make} implementations,
9615 when used in parallel mode, have slightly different semantics
9616 (@pxref{Parallel make,,, autoconf, The Autoconf Manual}), which can
9617 break the automatic detection of a connection to a capable terminal.
9618 If this is the case, the user will have to resort to the use of
9619 @samp{AM_COLOR_TESTS=always} in order to have the testsuite output
9622 Test programs that need data files should look for them in @code{srcdir}
9623 (which is both a make variable and an environment variable made available
9624 to the tests), so that they work when building in a separate directory
9625 (@pxref{Build Directories, , Build Directories , autoconf,
9626 The Autoconf Manual}), and in particular for the @code{distcheck} rule
9627 (@pxref{Checking the Distribution}).
9630 Automake ensures that each file listed in @code{TESTS} is built before
9631 it is run; you can list both source and derived programs (or scripts)
9632 in @code{TESTS}; the generated rule will look both in @code{srcdir} and
9633 `@file{..}'. For instance, you might want to run a C program as a test.
9634 To do this you would list its name in @code{TESTS} and also in
9635 @code{check_PROGRAMS}, and then specify it as you would any other
9638 @vindex check_PROGRAMS
9639 Programs listed in @code{check_PROGRAMS} (and @code{check_LIBRARIES},
9640 @code{check_LTLIBRARIES}, ...) are only built during @code{make
9641 check}, not during @code{make all}. You should list there any program
9642 needed by your tests that does not need to be built by @code{make
9643 all}. The programs in @code{check_PROGRAMS} are @emph{not}
9644 automatically added to @code{TESTS} because @code{check_PROGRAMS}
9645 usually lists programs used by the tests, not the tests themselves.
9646 If all your programs are in fact test cases, you can set @code{TESTS =
9650 * Testsuite Environment Overrides::
9653 @node Testsuite Environment Overrides
9654 @subsubsection Testsuite Environment Overrides
9656 @cindex Testsuite environment overrides
9657 @cindex Overriding testsuite environment
9659 @vindex TESTS_ENVIRONMENT
9660 @vindex AM_TESTS_ENVIRONMENT
9661 The @code{AM_TESTS_ENVIRONMENT} and @code{TESTS_ENVIRONMENT} variables can
9662 be used to run initialization code and set environment variables for the
9663 test scripts. The former variable is developer-reserved, and can be
9664 defined in the @file{Makefile.am}, while the latter is reserved for the
9665 user, which can employ it to extend or override the settings in the
9666 former; for this to work portably, however, the contents of a non-empty
9667 @code{AM_TESTS_ENVIRONMENT} @emph{must} be terminated by a semicolon.
9669 @vindex AM_TESTS_FD_REDIRECT
9670 The @code{AM_TESTS_FD_REDIRECT} variable can be used to define file
9671 descriptor redirections for the test scripts. One might think that
9672 @code{AM_TESTS_ENVIRONMENT} could be used for this purpose, but experience
9673 has shown that doing so portably is practically impossible. The main
9674 hurdle is constituted by Korn shells, which usually set the close-on-exec
9675 flag on file descriptors opened with the @command{exec} builtin, thus
9676 rendering an idiom like @code{AM_TESTS_ENVIRONMENT = exec 9>&2;}
9677 ineffectual. This issue also affects some Bourne shells, such as the
9678 HP-UX's @command{/bin/sh}.
9680 @c Keep in sync with tests-environment-backcompat.sh
9682 AM_TESTS_ENVIRONMENT = \
9683 ## Some environment initializations are kept in a separate shell
9684 ## file 'tests-env.sh', which can make it easier to also run tests
9685 ## from the command line.
9686 . $(srcdir)/tests-env.sh; \
9687 ## On Solaris, prefer more POSIX-compliant versions of the standard
9688 ## tools by default.
9689 if test -d /usr/xpg4/bin; then \
9690 PATH=/usr/xpg4/bin:$$PATH; export PATH; \
9693 @c $$ restore font-lock
9694 ## With this, the test scripts will be able to print diagnostic
9695 ## messages to the original standard error stream, even if the test
9696 ## driver redirects the stderr of the test scripts to a log file
9697 ## before executing them.
9698 AM_TESTS_FD_REDIRECT = 9>&2
9701 @c https://bugs.gnu.org/49309
9702 As another example, a notice that a test is starting can be emitted
9703 using @code{AM_TESTS_ENVIRONMENT} (for package maintainers) or
9704 @code{TESTS_ENVIRONMENT} by users:
9707 make -j12 ... TESTS_ENVIRONMENT='echo RUNNING: "$$f";' check
9711 The shell variable @code{$f} contains the test name. (Although
9712 technically this is not guaranteed, in practice it is extremely
9713 unlikely to ever change.) This can be helpful to see when trying to
9714 debug test failures.
9716 Notwithstanding these benefits, @code{AM_TESTS_ENVIRONMENT} is, for
9717 historical and implementation reasons, @emph{not} supported by the
9718 serial harness (@pxref{Serial Test Harness}).
9720 @node Serial Test Harness
9721 @subsection Older (and discouraged) Serial Test Harness
9722 @cindex @option{serial-tests}, Using
9724 First, note that today the use of this harness is strongly discouraged in
9725 favor of the parallel test harness (@pxref{Parallel Test Harness}).
9726 Still, there are a @emph{few} situations when the advantages offered by
9727 the parallel harness are irrelevant, and when test concurrency can
9728 even cause tricky problems. In those cases, it might make sense to
9729 still use the serial harness, for simplicity and reliability (we still
9730 suggest trying to give the parallel harness a shot though).
9732 The serial test harness is enabled by the Automake option
9733 @option{serial-tests}. It operates by simply running the tests serially,
9734 one at the time, without any I/O redirection. It's up to the user to
9735 implement logging of tests' output, if that's required or desired.
9737 For historical and implementation reasons, the @code{AM_TESTS_ENVIRONMENT}
9738 variable is @emph{not} supported by this harness (it will be silently
9739 ignored if defined); only @code{TESTS_ENVIRONMENT} is, and it is to be
9740 considered a developer-reserved variable. This is done so that, when
9741 using the serial harness, @code{TESTS_ENVIRONMENT} can be defined to an
9742 invocation of an interpreter through which the tests are to be run.
9743 For instance, the following setup may be used to run tests with Perl:
9746 TESTS_ENVIRONMENT = $(PERL) -Mstrict -w
9747 TESTS = foo.pl bar.pl baz.pl
9751 It's important to note that the use of @code{TESTS_ENVIRONMENT} endorsed
9752 here would be @emph{invalid} with the parallel harness. That harness
9753 provides a more elegant way to achieve the same effect, with the further
9754 benefit of freeing the @code{TESTS_ENVIRONMENT} variable for the user
9755 (@pxref{Parallel Test Harness}).
9757 Another, less serious limitation of the serial harness is that it
9758 doesn't distinguish between simple failures and hard errors; this is
9759 for historical reasons, and might be fixed in future Automake
9762 @node Parallel Test Harness
9763 @subsection Parallel Test Harness
9765 By default, Automake generates a parallel (concurrent) test harness. It
9766 features automatic collection of the test scripts output in @file{.log}
9767 files, concurrent execution of tests with @code{make -j}, specification
9768 of inter-test dependencies, lazy reruns of tests that have not completed
9769 in a prior run, and hard errors for exceptional failures.
9771 @anchor{Basics of test metadata}
9773 @cindex @file{.log} files
9774 @cindex @file{.trs} files
9775 @cindex test metadata
9776 The parallel test harness operates by defining a set of @command{make}
9777 rules that run the test scripts listed in @code{TESTS}, and, for each
9778 such script, save its output in a corresponding @file{.log} file and
9779 its results (and other ``metadata'', @pxref{API for Custom Test Drivers})
9780 in a corresponding @file{.trs} (as in @b{T}est @b{R}e@b{S}ults) file.
9781 @c We choose the '.trs' extension also because, at the time of writing,
9782 @c it isn't already used for other significant purposes; see e.g.:
9783 @c - http://filext.com/file-extension/trs
9784 @c - http://www.file-extensions.org/search/?searchstring=trs
9785 The @file{.log} file will contain all the output emitted by the test on
9786 its standard output and its standard error. The @file{.trs} file will
9787 contain, among the other things, the results of the test cases run by
9790 @vindex TEST_SUITE_LOG
9791 @vindex IGNORE_SKIPPED_LOGS
9792 The parallel test harness will also create a summary log file,
9793 @code{TEST_SUITE_LOG}, which defaults to @file{test-suite.log} and requires
9794 a @file{.log} suffix. This file depends upon all the @file{.log} and
9795 @file{.trs} files created for the test scripts listed in @code{TESTS}.
9796 It contains the output of all tests that failed, encountered a hard error,
9797 succeeded unexpectedly, or---unless the variable @code{IGNORE_SKIPPED_LOGS}
9798 is set to a non-empty value---were skipped.
9801 As with the serial harness above, by default one status line is printed
9802 per completed test, and a short summary after the suite has completed.
9803 However, standard output and standard error of the test are redirected
9804 to a per-test log file, so that parallel execution does not produce
9805 intermingled output. The output from failed tests is collected in the
9806 @file{test-suite.log} file. If the variable @samp{VERBOSE} is set, this
9807 file is output after the summary.
9809 @vindex TEST_EXTENSIONS
9811 Each couple of @file{.log} and @file{.trs} files is created when the
9812 corresponding test has completed. The set of log files is listed in
9813 the read-only variable @code{TEST_LOGS}, and defaults to @code{TESTS},
9814 with the executable extension if any (@pxref{EXEEXT}), as well as any
9815 suffix listed in @code{TEST_EXTENSIONS} removed, and @file{.log} appended.
9816 Results are undefined if a test file name ends in several concatenated
9817 suffixes. @code{TEST_EXTENSIONS} defaults to @file{.test}; it can be
9818 overridden by the user, in which case any extension listed in it must be
9819 constituted by a dot, followed by a non-digit alphabetic character,
9820 followed by any number of alphabetic characters.
9821 @c Keep in sync with test-extensions.sh
9822 For example, @samp{.sh}, @samp{.T} and @samp{.t1} are valid extensions,
9823 while @samp{.x-y}, @samp{.6c} and @samp{.t.1} are not.
9825 @cindex Configure substitutions in @code{TESTS}
9826 It is important to note that, due to current limitations (unlikely to be
9827 lifted), configure substitutions in the definition of @code{TESTS} can
9828 only work if they will expand to a list of tests that have a suffix listed
9829 in @code{TEST_EXTENSIONS}.
9831 @vindex _LOG_COMPILE
9832 @vindex _LOG_COMPILER
9835 @vindex LOG_COMPILER
9837 @vindex @var{ext}_LOG_COMPILE
9838 @vindex @var{ext}_LOG_COMPILER
9839 @vindex @var{ext}_LOG_FLAGS
9840 @vindex AM_@var{ext}_LOG_FLAGS
9841 @vindex AM_LOG_FLAGS
9842 For tests that match an extension @code{.@var{ext}} listed in
9843 @code{TEST_EXTENSIONS}, you can provide a custom ``test runner'' using
9844 the variable @code{@var{ext}_LOG_COMPILER} (note the upper-case
9845 extension) and pass options in @code{AM_@var{ext}_LOG_FLAGS} and allow
9846 the user to pass options in @code{@var{ext}_LOG_FLAGS}. It will cause
9847 all tests with this extension to be called with this runner. For all
9848 tests without a registered extension, the variables @code{LOG_COMPILER},
9849 @code{AM_LOG_FLAGS}, and @code{LOG_FLAGS} may be used. For example,
9851 @c Keep in sync with parallel-tests-log-compiler-example.sh
9853 TESTS = foo.pl bar.py baz
9854 TEST_EXTENSIONS = .pl .py
9855 PL_LOG_COMPILER = $(PERL)
9856 AM_PL_LOG_FLAGS = -w
9857 PY_LOG_COMPILER = $(PYTHON)
9858 AM_PY_LOG_FLAGS = -v
9859 LOG_COMPILER = ./wrapper-script
9864 will invoke @samp{$(PERL) -w foo.pl}, @samp{$(PYTHON) -v bar.py},
9865 and @samp{./wrapper-script -d baz} to produce @file{foo.log},
9866 @file{bar.log}, and @file{baz.log}, respectively. The @file{foo.trs},
9867 @file{bar.trs} and @file{baz.trs} files will be automatically produced
9870 It's important to note that, differently from what we've seen for the
9871 serial test harness (@pxref{Serial Test Harness}), the
9872 @code{AM_TESTS_ENVIRONMENT} and @code{TESTS_ENVIRONMENT} variables
9873 @emph{cannot} be used to define a custom test runner; the
9874 @code{LOG_COMPILER} and @code{LOG_FLAGS} (or their extension-specific
9875 counterparts) should be used instead:
9879 AM_TESTS_ENVIRONMENT = PERL5LIB='$(srcdir)/lib' $(PERL) -Mstrict -w
9884 AM_TESTS_ENVIRONMENT = PERL5LIB='$(srcdir)/lib'; export PERL5LIB;
9885 LOG_COMPILER = $(PERL)
9886 AM_LOG_FLAGS = -Mstrict -w
9889 By default, the test suite harness will run all tests, but there are
9890 several ways to limit the set of tests that are run:
9894 You can set the @code{TESTS} variable. For example, you can use a
9895 command like this to run only a subset of the tests:
9898 env TESTS="foo.test bar.test" make -e check
9901 @c https://bugs.gnu.org/42883
9902 If you're using a recursive make setup, you'll probably also need to
9903 override @code{SUBDIRS}:
9906 env TESTS="foo.test bar.test" make -e check SUBDIRS=
9909 Otherwise, the test harness will descend into all subdirectories,
9910 where the tests presumably do not exist, and thus fail. (Patch to
9911 provide better behavior would be welcome.)
9913 Another issue: the command above will unconditionally overwrite the
9914 @file{test-suite.log} file, thus clobbering the recorded results
9915 of any previous testsuite run. This might be undesirable for packages
9916 whose testsuite takes a long time to execute. Luckily, this problem can
9917 easily be avoided by also overriding @code{TEST_SUITE_LOG} at runtime;
9920 @c Keep in sync with parallel-tests-log-override-2.sh
9922 env TEST_SUITE_LOG=partial.log TESTS="..." make -e check
9925 will write the result of the partial testsuite runs to the
9926 @file{partial.log}, without touching @file{test-suite.log}.
9929 You can set the @code{TEST_LOGS} variable. By default, this variable is
9930 computed at @command{make} run time from the value of @code{TESTS} as
9931 described above. For example, you can use the following:
9934 set x subset*.log; shift
9935 env TEST_LOGS="foo.log $*" make -e check
9938 The comments made above about @code{TEST_SUITE_LOG} overriding applies
9942 @vindex RECHECK_LOGS
9943 @cindex lazy test execution
9944 By default, the test harness removes all old per-test @file{.log} and
9945 @file{.trs} files before it starts running tests to regenerate them. The
9946 variable @code{RECHECK_LOGS} contains the set of @file{.log} (and, by
9947 implication, @file{.trs}) files which are removed. @code{RECHECK_LOGS}
9948 defaults to @code{TEST_LOGS}, which means all tests need to be rechecked.
9949 By overriding this variable, you can choose which tests need to be
9950 reconsidered. For example, you can lazily rerun only those tests which
9951 are outdated, i.e., older than their prerequisite test files, by setting
9952 this variable to the empty value:
9955 env RECHECK_LOGS= make -e check
9960 You can ensure that all tests are rerun which have failed or passed
9961 unexpectedly, by running @code{make recheck} in the test directory.
9962 This convenience target will set @code{RECHECK_LOGS} appropriately
9963 before invoking the main test harness.
9967 In order to guarantee an ordering between tests even with @code{make
9968 -j@var{N}}, dependencies between the corresponding @file{.log} files
9969 may be specified through usual @command{make} dependencies. For example,
9970 the following snippet lets the test named @file{foo-execute.test} depend
9971 upon completion of the test @file{foo-compile.test}:
9974 TESTS = foo-compile.test foo-execute.test
9975 foo-execute.log: foo-compile.log
9979 Please note that this ordering ignores the @emph{results} of required
9980 tests, thus the test @file{foo-execute.test} is run even if the test
9981 @file{foo-compile.test} failed or was skipped beforehand. Further,
9982 please note that specifying such dependencies currently works only for
9983 tests that end in one of the suffixes listed in @code{TEST_EXTENSIONS}.
9985 Tests without such specified dependencies may be run concurrently with
9986 parallel @command{make -j@var{N}}, so be sure they are prepared for
9987 concurrent execution.
9990 @c Keep in sync with 'parallel-tests-extra-programs.sh'.
9991 The combination of lazy test execution and correct dependencies between
9992 tests and their sources may be exploited for efficient unit testing
9993 during development. To further speed up the edit-compile-test cycle, it
9994 may even be useful to specify compiled programs in @code{EXTRA_PROGRAMS}
9995 instead of with @code{check_PROGRAMS}, as the former allows intertwined
9996 compilation and test execution (but note that @code{EXTRA_PROGRAMS} are
9997 not cleaned automatically; @pxref{Uniform}).
9999 The variables @code{TESTS} and @code{XFAIL_TESTS} may contain
10000 conditional parts as well as configure substitutions. In the latter
10001 case, however, certain restrictions apply: substituted test names
10002 must end with a nonempty test suffix like @file{.test}, so that one of
10003 the inference rules generated by @command{automake} can apply. For
10004 literal test names, @command{automake} can generate per-target rules
10005 to avoid this limitation.
10007 Please note that it is currently not possible to use @code{$(srcdir)/}
10008 or @code{$(top_srcdir)/} in the @code{TESTS} variable. This technical
10009 limitation is necessary to avoid generating test logs in the source tree
10010 and has the unfortunate consequence that it is not possible to specify
10011 distributed tests that are themselves generated by means of explicit
10012 rules, in a way that is portable to all @command{make} implementations
10013 (@pxref{Make Target Lookup,,, autoconf, The Autoconf Manual}, the
10014 semantics of FreeBSD and OpenBSD @command{make} conflict with this).
10015 In case of doubt you may want to require to use GNU @command{make},
10016 or work around the issue with inference rules to generate the tests.
10018 @node Custom Test Drivers
10019 @section Custom Test Drivers
10022 * Overview of Custom Test Drivers Support::
10023 * Declaring Custom Test Drivers::
10024 * API for Custom Test Drivers::
10027 @node Overview of Custom Test Drivers Support
10028 @subsection Overview of Custom Test Drivers Support
10030 Starting from Automake version 1.12, the parallel test harness allows
10031 the package authors to use third-party custom test drivers, in case the
10032 default ones are inadequate for their purposes, or do not support their
10033 testing protocol of choice.
10035 A custom test driver is expected to properly run the test programs passed
10036 to it (including the command-line arguments passed to those programs, if
10037 any), to analyze their execution and outcome, to create the @file{.log}
10038 and @file{.trs} files associated to these test runs, and to display the test
10039 results on the console. It is responsibility of the author of the test
10040 driver to ensure that it implements all the above steps meaningfully and
10041 correctly; Automake isn't and can't be of any help here. On the other
10042 hand, the Automake-provided code for testsuite summary generation offers
10043 support for test drivers allowing several test results per test script,
10044 if they take care to register such results properly (@pxref{Log files
10045 generation and test results recording}).
10047 The exact details of how test scripts' results are to be determined and
10048 analyzed is left to the individual drivers. Some drivers might only
10049 consider the test script exit status (this is done for example by the
10050 default test driver used by the parallel test harness, described
10051 in the previous section). Other drivers might implement more complex and
10052 advanced test protocols, which might require them to parse and interpret
10053 the output emitted by the test script they're running (examples of such
10054 protocols are TAP and SubUnit).
10056 It's very important to note that, even when using custom test drivers,
10057 most of the infrastructure described in the previous section about the
10058 parallel harness remains in place; this includes:
10062 list of test scripts defined in @code{TESTS}, and overridable at
10063 runtime through the redefinition of @code{TESTS} or @code{TEST_LOGS};
10065 concurrency through the use of @command{make}'s option @option{-j};
10067 per-test @file{.log} and @file{.trs} files, and generation of a summary
10068 @file{.log} file from them;
10070 @code{recheck} target, @code{RECHECK_LOGS} variable, and lazy reruns
10073 inter-test dependencies;
10075 support for @code{check_*} variables (@code{check_PROGRAMS},
10076 @code{check_LIBRARIES}, ...);
10078 use of @code{VERBOSE} environment variable to get verbose output on
10079 testsuite failures;
10081 definition and honoring of @code{TESTS_ENVIRONMENT},
10082 @code{AM_TESTS_ENVIRONMENT} and @code{AM_TESTS_FD_REDIRECT}
10085 definition of generic and extension-specific @code{LOG_COMPILER} and
10086 @code{LOG_FLAGS} variables.
10090 On the other hand, the exact semantics of how (and if) testsuite output
10091 colorization, @code{XFAIL_TESTS}, and hard errors are supported and
10092 handled is left to the individual test drivers.
10094 @c TODO: We should add a working example in the doc/ directory,
10095 @c TODO: and reference it from here.
10097 @node Declaring Custom Test Drivers
10098 @subsection Declaring Custom Test Drivers
10100 @vindex _LOG_DRIVER
10101 @vindex _LOG_DRIVER_FLAGS
10103 @vindex LOG_DRIVER_FLAGS
10104 @vindex @var{ext}_LOG_DRIVER
10105 @vindex @var{ext}_LOG_DRIVER_FLAGS
10106 @vindex AM_@var{ext}_LOG_DRIVER_FLAGS
10107 @vindex AM_LOG_DRIVER_FLAGS
10108 Custom testsuite drivers are declared by defining the make variables
10109 @code{LOG_DRIVER} or @code{@var{ext}_LOG_DRIVER} (where @var{ext} must
10110 be declared in @code{TEST_EXTENSIONS}). They must be defined to
10111 programs or scripts that will be used to drive the execution, logging,
10112 and outcome report of the tests with corresponding extensions (or of
10113 those with no registered extension in the case of @code{LOG_DRIVER}).
10114 Clearly, multiple distinct test drivers can be declared in the same
10115 @file{Makefile.am}. Note moreover that the @code{LOG_DRIVER} variables
10116 are @emph{not} a substitute for the @code{LOG_COMPILER} variables: the
10117 two sets of variables can, and often do, usefully and legitimately
10120 @c TODO: We should point to a clarifying example here!
10122 The developer-reserved variable @code{AM_LOG_DRIVER_FLAGS} and the
10123 user-reserved variable @code{LOG_DRIVER_FLAGS} can be used to define
10124 flags that will be passed to each invocation of @code{LOG_DRIVER},
10125 with the user-defined flags obviously taking precedence over the
10126 developer-reserved ones. Similarly, for each extension @var{ext}
10127 declared in @code{TEST_EXTENSIONS}, flags listed in
10128 @code{AM_@var{ext}_LOG_DRIVER_FLAGS} and
10129 @code{@var{ext}_LOG_DRIVER_FLAGS} will be passed to
10130 invocations of @code{@var{ext}_LOG_DRIVER}.
10132 @node API for Custom Test Drivers
10133 @subsection API for Custom Test Drivers
10135 Note that @emph{the APIs described here are still highly
10136 experimental}, and will very likely undergo tightening and possibly
10137 extensive changes in the future, to accommodate for new features or to
10138 satisfy additional portability requirements.
10140 The main characteristic of these APIs is that they are designed to share
10141 as much infrastructure, semantics, and implementation detail as possible
10142 with the parallel test harness and its default driver.
10145 * Command-line arguments for test drivers::
10146 * Log files generation and test results recording::
10147 * Testsuite progress output::
10150 @node Command-line arguments for test drivers
10151 @subsubsection Command-line arguments for test drivers
10153 A custom driver can rely on various command-line options and arguments
10154 being passed to it automatically by the Automake-generated test
10155 harness. It is @emph{mandatory} that it understands all of them (even
10156 if the exact interpretation of the associated semantics can
10157 legitimately change between a test driver and another, and even be a
10158 no-op in some drivers). Options are separated from their arguments by
10159 whitespace.@footnote{Regrettably, older versions of this manual stated
10160 that option arguments should be joined to their options with a
10161 @code{=} character, rather than passed as in the following argument
10162 word as shown here. The syntax with @code{=} has never been accepted
10163 by the test drivers supplied with Automake, and has never been
10164 produced by @file{Makefile}s generated by Automake.}
10167 Here is the list of options:
10170 @item --test-name @var{NAME}
10171 The name of the test, with VPATH prefix (if any) removed. This can have a
10172 suffix and a directory component (as in e.g., @file{sub/foo.test}), and is
10173 mostly meant to be used in console reports about testsuite advancements and
10174 results (@pxref{Testsuite progress output}).
10175 @item --log-file @file{@var{PATH}.log}
10176 The @file{.log} file the test driver must create (@pxref{Basics of
10177 test metadata}). If it has a directory component (as in e.g.,
10178 @file{sub/foo.log}), the test harness will ensure that such directory
10179 exists @emph{before} the test driver is called.
10180 @item --trs-file @file{@var{PATH}.trs}
10181 The @file{.trs} file the test driver must create (@pxref{Basics of
10182 test metadata}). If it has a directory component (as in e.g.,
10183 @file{sub/foo.trs}), the test harness will ensure that such directory
10184 exists @emph{before} the test driver is called.
10185 @item --color-tests @{yes|no@}
10186 Whether the console output should be colorized or not (@pxref{Simple
10187 tests and color-tests}, to learn when this option gets activated and
10189 @item --collect-skipped-logs @{yes|no@}
10190 Whether to include the logs of skipped tests in the global
10191 @file{test-suite.log} file.
10192 @item --expect-failure @{yes|no@}
10193 Whether the tested program is expected to fail.
10194 @item --enable-hard-errors @{yes|no@}
10195 Whether ``hard errors'' in the tested program should be treated differently
10196 from normal failures or not (the default should be @code{yes}). The exact
10197 meaning of ``hard error'' is highly dependent from the test protocols or
10198 conventions in use.
10200 Explicitly terminate the list of options.
10204 The first non-option argument passed to the test driver is the program to
10205 be run, and all the following ones are command-line options and arguments
10208 Exact semantics attached to the @option{--color-tests},
10209 @option{--collect-skipped-logs}, @option{--expect-failure}, and
10210 @option{--enable-hard-errors} options are left up to the individual
10211 test drivers. Still, having a behavior compatible or at least similar
10212 to that provided by the default driver is advised, as that results
10213 in better consistency and thus a more pleasant user experience.
10215 @node Log files generation and test results recording
10216 @subsubsection Log files generation and test results recording
10218 The test driver must correctly generate the files specified by the
10219 @option{--log-file} and @option{--trs-file} option (even when the tested
10220 program fails or crashes).
10222 The @file{.log} file should ideally contain all the output produced by the
10223 tested program, plus optionally other information that might facilitate
10224 debugging or analysis of bug reports. Apart from that, its format is
10227 The @file{.trs} file is used to register some metadata through the use
10228 of custom reStructuredText fields. This metadata is expected to be
10229 employed in various ways by the parallel test harness; for example, to
10230 count the test results when printing the testsuite summary, or to decide
10231 which tests to rerun upon @command{make recheck}. Unrecognized metadata
10232 in a @file{.trs} file is currently ignored by the harness, but this might
10233 change in the future. The list of currently recognized metadata follows.
10237 @item :test-result:
10238 @cindex Register test result
10239 @cindex Register test case result
10240 @cindex Test result, registering
10241 @cindex Test case result, registering
10242 @cindex @code{:test-result:}
10243 @cindex reStructuredText field, @code{:test-result:}
10244 The test driver must use this field to register the results of @emph{each}
10245 test case run by a test script file. Several @code{:test-result:} fields
10246 can be present in the same @file{.trs} file; this is done in order to
10247 support test protocols that allow a single test script to run more test
10250 @c Keep this in sync with lib/am/check-am:$(TEST_SUITE_LOG).
10251 The only recognized test results are currently @code{PASS}, @code{XFAIL},
10252 @code{SKIP}, @code{FAIL}, @code{XPASS} and @code{ERROR}. These results,
10253 when declared with @code{:test-result:}, can be optionally followed by
10254 text holding the name and/or a brief description of the corresponding
10255 test; the harness will ignore such extra text when generating
10256 @file{test-suite.log} and preparing the testsuite summary.
10258 @c Keep in sync with 'test-metadata-recheck.sh'.
10259 @item @code{:recheck:}
10261 @cindex reStructuredText field, @code{:recheck:}
10262 If this field is present and defined to @code{no}, then the corresponding
10263 test script will @emph{not} be run upon a @command{make recheck}. What
10264 happens when two or more @code{:recheck:} fields are present in the same
10265 @file{.trs} file is undefined behavior.
10267 @c Keep in sync with 'test-metadata-global-log.sh'.
10268 @item @code{:copy-in-global-log:}
10269 @cindex :copy-in-global-log:
10270 @cindex reStructuredText field, @code{:copy-in-global-log:}
10271 If this field is present and defined to @code{no}, then the content
10272 of the @file{.log} file will @emph{not} be copied into the global
10273 @file{test-suite.log}. We allow to forsake such copying because, while
10274 it can be useful in debugging and analysis of bug report, it can also be
10275 just a waste of space in normal situations, e.g., when a test script is
10276 successful. What happens when two or more @code{:copy-in-global-log:}
10277 fields are present in the same @file{.trs} file is undefined behavior.
10279 @c Keep in sync with 'test-metadata-global-result.sh'.
10280 @item @code{:test-global-result:}
10281 @cindex :test-global-result:
10282 @cindex reStructuredText field, @code{:test-global-result:}
10283 This is used to declare the "global result" of the script. Currently,
10284 the value of this field is needed only to be reported (more or less
10285 verbatim) in the generated global log file @code{$(TEST_SUITE_LOG)},
10286 so it's quite free-form. For example, a test script which runs 10 test
10287 cases, 6 of which pass and 4 of which are skipped, could reasonably have
10288 a @code{PASS/SKIP} value for this field, while a test script which runs
10289 19 successful tests and one failed test could have an @code{ALMOST
10290 PASSED} value. What happens when two or more @code{:test-global-result:}
10291 fields are present in the same @file{.trs} file is undefined behavior.
10295 Let's see a small example. Assume a @file{.trs} file contains the
10299 :test-result: PASS server starts
10300 :global-log-copy: no
10301 :test-result: PASS HTTP/1.1 request
10302 :test-result: FAIL HTTP/1.0 request
10304 :test-result: SKIP HTTPS request (TLS library wasn't available)
10305 :test-result: PASS server stops
10309 Then the corresponding test script will be rerun by @command{make check},
10310 will contribute with @emph{five} test results to the testsuite summary
10311 (three of these tests being successful, one failed, and one skipped), and
10312 the content of the corresponding @file{.log} file will @emph{not} be
10313 copied into the global log file @file{test-suite.log}.
10315 @node Testsuite progress output
10316 @subsubsection Testsuite progress output
10318 A custom test driver also has the task of displaying, on the standard
10319 output, the test results as soon as they become available. Depending on
10320 the protocol in use, it can also display the reasons for failures and
10321 skips, and, more generally, any useful diagnostic output (but remember
10322 that each line on the screen is precious, so that cluttering the screen
10323 with overly verbose information is bad idea). The exact format of this
10324 progress output is left up to the test driver; in fact, a custom test
10325 driver might @emph{theoretically} even decide not to do any such report,
10326 leaving it all to the testsuite summary (that would be a very lousy idea,
10327 of course, and serves only to illustrate the flexibility that is
10330 Remember that consistency is good; so, if possible, try to be consistent
10331 with the output of the built-in Automake test drivers, providing a similar
10332 ``look & feel''. In particular, the testsuite progress output should be
10333 colorized when the @option{--color-tests} is passed to the driver. On the
10334 other end, if you are using a known and widespread test protocol with
10335 well-established implementations, being consistent with those
10336 implementations' output might be a good idea too.
10338 @node Using the TAP test protocol
10339 @section Using the TAP test protocol
10342 * Introduction to TAP::
10343 * Use TAP with the Automake test harness::
10344 * Incompatibility with other TAP parsers and drivers::
10345 * Links and external resources on TAP::
10348 @node Introduction to TAP
10349 @subsection Introduction to TAP
10351 TAP, the Test Anything Protocol, is a simple text-based interface between
10352 testing modules or programs and a test harness. The tests (also called
10353 ``TAP producers'' in this context) write test results in a simple format
10354 on standard output; a test harness (also called ``TAP consumer'') will
10355 parse and interpret these results, and properly present them to the user,
10356 and/or register them for later analysis. The exact details of how this
10357 is accomplished can vary among different test harnesses. The Automake
10358 harness will present the results on the console in the usual
10359 fashion (@pxref{Testsuite progress on console}), and will use the
10360 @file{.trs} files (@pxref{Basics of test metadata}) to store the test
10361 results and related metadata. Apart from that, it will try to remain
10362 as compatible as possible with pre-existing and widespread utilities,
10364 @uref{https://metacpan.org/pod/distribution/Test-Harness/bin/prove,
10365 @command{prove} utility}, at least for the simpler usages.
10367 TAP started its life as part of the test harness for Perl, but today
10368 it has been (mostly) standardized, and has various independent
10369 implementations in different languages; among them, C, C++, Perl,
10370 Python, PHP, and Java. For a semi-official specification of the
10371 TAP protocol, please refer to the documentation of
10372 @uref{https://metacpan.org/pod/Test::Harness, @samp{Test::Harness}}.
10374 The most relevant real-world usages of TAP are obviously in the testsuites
10375 of @command{perl} and of many Perl modules. Still, other important
10376 third-party packages, such as @uref{https://git-scm.com/, @command{git}},
10377 also use TAP in their testsuite.
10379 @node Use TAP with the Automake test harness
10380 @subsection Use TAP with the Automake test harness
10382 Currently, the TAP driver that comes with Automake requires some by-hand
10383 steps on the developer's part (this situation should hopefully be improved
10384 in future Automake versions). You'll have to grab the @file{tap-driver.sh}
10385 script from the Automake distribution by hand, copy it in your source tree,
10386 and use the Automake support for third-party test drivers to instruct the
10387 harness to use the @file{tap-driver.sh} script and the awk program found
10388 by @code{AM_INIT_AUTOMAKE} to run your TAP-producing tests. See the example
10389 below for clarification.
10391 Apart from the options common to all the Automake test drivers
10392 (@pxref{Command-line arguments for test drivers}), @file{tap-driver.sh}
10393 supports the following options, whose names are chosen for enhanced
10394 compatibility with the @command{prove} utility.
10397 @c Keep in sync with 'tap-exit.sh' and 'tap-signal.tap'.
10398 @item --ignore-exit
10399 Causes the test driver to ignore the exit status of the test scripts;
10400 by default, the driver will report an error if the script exits with a
10401 non-zero status. This option has effect also on non-zero exit statuses
10402 due to termination by a signal.
10404 Instruct the test driver to display TAP diagnostics (i.e., lines beginning
10405 with the @samp{#} character) in the testsuite progress output too; by
10406 default, TAP diagnostics are only copied to the @file{.log} file.
10407 @item --no-comments
10408 Revert the effects of @option{--comments}.
10410 Instruct the test driver to merge the test scripts' standard error into
10411 their standard output. This is necessary if you want to ensure that
10412 diagnostics from the test scripts are displayed in the correct order
10413 relative to test results; this can be of great help in debugging
10414 (especially if your test scripts are shell scripts run with shell
10415 tracing active). As a downside, this option might cause the test
10416 harness to get confused if anything that appears on standard error
10417 looks like a test result.
10419 Revert the effects of @option{--merge}.
10420 @item --diagnostic-string @var{STRING}
10421 Change the string that introduces TAP diagnostics from the default value
10422 of ``@code{#}'' to @code{@var{STRING}}. This can be useful if your
10423 TAP-based test scripts produce verbose output on which they have limited
10424 control (because, say, the output comes from other tools invoked in the
10425 scripts), and it might contain text that gets spuriously interpreted as
10426 TAP diagnostics: such an issue can be solved by redefining the string that
10427 activates TAP diagnostics to a value you know won't appear by chance in
10428 the tests' output. Note however that this feature is non-standard, as
10429 the ``official'' TAP protocol does not allow for such a customization; so
10430 don't use it if you can avoid it.
10434 Here is an example of how the TAP driver can be set up and used.
10436 @c Keep in sync with tap-doc2.sh
10438 % @kbd{cat configure.ac}
10439 AC_INIT([GNU Try Tap], [1.0], [bug-automake@@gnu.org])
10440 AC_CONFIG_AUX_DIR([build-aux])
10441 AM_INIT_AUTOMAKE([foreign -Wall -Werror])
10442 AC_CONFIG_FILES([Makefile])
10443 AC_REQUIRE_AUX_FILE([tap-driver.sh])
10446 % @kbd{cat Makefile.am}
10447 TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
10448 $(top_srcdir)/build-aux/tap-driver.sh
10449 TESTS = foo.test bar.test baz.test
10450 EXTRA_DIST = $(TESTS)
10452 % @kbd{cat foo.test}
10454 echo 1..4 # Number of tests to be executed.
10455 echo 'ok 1 - Swallows fly'
10456 echo 'not ok 2 - Caterpillars fly # TODO metamorphosis in progress'
10457 echo 'ok 3 - Pigs fly # SKIP not enough acid'
10458 echo '# I just love word plays ...'
10459 echo 'ok 4 - Flies fly too :-)'
10461 % @kbd{cat bar.test}
10464 echo 'not ok 1 - Bummer, this test has failed.'
10465 echo 'ok 2 - This passed though.'
10466 echo 'Bail out! Ennui kicking in, sorry...'
10467 echo 'ok 3 - This will not be seen.'
10469 % @kbd{cat baz.test}
10473 # Exit with error, even if all the tests have been successful.
10476 % @kbd{cp @var{PREFIX}/share/automake-@var{APIVERSION}/tap-driver.sh .}
10477 % @kbd{autoreconf -vi && ./configure && make check}
10479 PASS: foo.test 1 - Swallows fly
10480 XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
10481 SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
10482 PASS: foo.test 4 - Flies fly too :-)
10483 FAIL: bar.test 1 - Bummer, this test has failed.
10484 PASS: bar.test 2 - This passed though.
10485 ERROR: bar.test - Bail out! Ennui kicking in, sorry...
10487 ERROR: baz.test - exited with status 7
10489 Please report to bug-automake@@gnu.org
10491 % @kbd{echo exit status: $?}
10494 @c Keep the "skewed" indentation below, it produces pretty PDF output.
10495 % @kbd{env TEST_LOG_DRIVER_FLAGS='--comments --ignore-exit' \
10496 TESTS='foo.test baz.test' make -e check}
10498 PASS: foo.test 1 - Swallows fly
10499 XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
10500 SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
10501 # foo.test: I just love word plays...
10502 PASS: foo.test 4 - Flies fly too :-)
10505 % @kbd{echo exit status: $?}
10509 @node Incompatibility with other TAP parsers and drivers
10510 @subsection Incompatibility with other TAP parsers and drivers
10512 For implementation or historical reasons, the TAP driver and harness as
10513 implemented by Automake have some minor compatibility issues with the
10514 mainstream versions, which you should be aware of.
10518 A @code{Bail out!} directive doesn't stop the whole testsuite, but only
10519 the test script it occurs in. This doesn't follow TAP specifications,
10520 but on the other hand it maximizes compatibility (and code sharing) with
10521 the ``hard error'' concept of the default testsuite driver.
10523 The @code{version} and @code{pragma} directives are not supported.
10525 The @option{--diagnostic-string} option of our driver allows modification of
10526 the string that introduces TAP diagnostics from the default value
10527 of ``@code{#}''. The standard TAP protocol currently has no way to
10528 allow this, so if you use it your diagnostic will be lost to more
10529 compliant tools like @command{prove} and @code{Test::Harness}
10531 And there are probably some other small and yet undiscovered
10532 compatibility issues, especially in corner cases or with rare usages.
10535 @node Links and external resources on TAP
10536 @subsection Links and external resources on TAP
10539 Here are some links to more extensive official or third-party
10540 documentation and resources about the TAP protocol and related
10541 tools and libraries.
10544 @uref{https://metacpan.org/pod/Test::Harness, @samp{Test::Harness}},
10545 the (mostly) official documentation about the TAP format and protocol.
10547 @uref{https://metacpan.org/pod/distribution/Test-Harness/bin/prove,
10549 the most famous command-line TAP test driver, included in the distribution
10550 of @command{perl} and
10551 @uref{https://metacpan.org/pod/distribution/Test-Harness/lib/Test/Harness.pm,
10552 @samp{Test::Harness}}.
10554 The @uref{https://testanything.org/,TAP wiki}.
10556 A ``gentle introduction'' to testing for Perl coders:
10557 @uref{https://metacpan.org/pod/distribution/Test-Simple/lib/Test/Tutorial.pod,
10558 @samp{Test::Tutorial}}.
10560 @uref{https://metacpan.org/pod/distribution/Test-Simple/lib/Test/Simple.pm,
10561 @samp{Test::Simple}}
10563 @uref{https://metacpan.org/pod/distribution/Test-Simple/lib/Test/More.pm,
10564 @samp{Test::More}},
10565 the standard Perl testing libraries, which are based on TAP.
10567 @uref{https://www.eyrie.org/~eagle/software/c-tap-harness/,C TAP Harness},
10568 a C-based project implementing both a TAP producer and a TAP consumer.
10570 @uref{https://tap4j.org/,tap4j},
10571 a Java-based project implementing both a TAP producer and a TAP consumer.
10574 @node DejaGnu Tests
10575 @section DejaGnu Tests
10577 If @command{dejagnu} (@pxref{Top, , Introduction, dejagnu, DejaGnu})
10578 appears in @code{AUTOMAKE_OPTIONS}, then a @command{dejagnu}-based
10579 test suite is assumed. The variable @code{DEJATOOL} is a list of
10580 names that are passed, one at a time, as the @option{--tool} argument
10581 to @command{runtest} invocations; it defaults to the name of the
10584 The variable @code{RUNTESTDEFAULTFLAGS} holds the @option{--tool} and
10585 @option{--srcdir} flags that are passed to dejagnu by default; this can be
10586 overridden if necessary.
10587 @vindex RUNTESTDEFAULTFLAGS
10589 The variables @code{EXPECT} and @code{RUNTEST} can
10590 also be overridden to provide project-specific values. For instance,
10591 you will need to do this if you are testing a compiler toolchain,
10592 because the default values do not take into account host and target
10599 The contents of the variable @code{RUNTESTFLAGS} are passed to the
10600 @code{runtest} invocation. This is considered a ``user variable''
10601 (@pxref{User Variables}). If you need to set @command{runtest} flags in
10602 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
10603 @vindex RUNTESTFLAGS
10604 @vindex AM_RUNTESTFLAGS
10606 @cindex @file{site.exp}
10607 Automake will generate rules to create a local @file{site.exp} file,
10608 defining various variables detected by @command{configure}. This file
10609 is automatically read by DejaGnu. It is OK for the user of a package
10610 to edit this file in order to tune the test suite. However this is
10611 not the place where the test suite author should define new variables:
10612 this should be done elsewhere in the real test suite code.
10613 Especially, @file{site.exp} should not be distributed.
10615 Still, if the package author has legitimate reasons to extend
10616 @file{site.exp} at @command{make} time, he can do so by defining
10617 the variable @code{EXTRA_DEJAGNU_SITE_CONFIG}; the files listed
10618 there will be considered @file{site.exp} prerequisites, and their
10619 content will be appended to it (in the same order in which they
10620 appear in @code{EXTRA_DEJAGNU_SITE_CONFIG}). Note that files are
10621 @emph{not} distributed by default.
10623 For more information regarding DejaGnu test suites, see @ref{Top, , ,
10624 dejagnu, The DejaGnu Manual}.
10626 @node Install Tests
10627 @section Install Tests
10629 The @code{installcheck} target is available to the user as a way to
10630 run any tests after the package has been installed. You can add tests
10631 to this by writing an @code{installcheck-local} rule.
10635 @chapter Rebuilding Makefiles
10636 @cindex rebuild rules
10638 Automake generates rules to automatically rebuild @file{Makefile}s,
10639 @file{configure}, and other derived files like @file{Makefile.in}.
10641 @acindex AM_MAINTAINER_MODE
10642 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.ac}, then
10643 these automatic rebuilding rules are only enabled in maintainer mode.
10645 @vindex CONFIG_STATUS_DEPENDENCIES
10646 @vindex CONFIGURE_DEPENDENCIES
10647 @cindex @file{version.sh}, example
10648 @cindex @file{version.m4}, example
10650 Sometimes it is convenient to supplement the rebuild rules for
10651 @file{configure} or @file{config.status} with additional dependencies.
10652 The variables @code{CONFIGURE_DEPENDENCIES} and
10653 @code{CONFIG_STATUS_DEPENDENCIES} can be used to list these extra
10654 dependencies. These variables should be defined in all
10655 @file{Makefile}s of the tree (because these two rebuild rules are
10656 output in all of them), so it is safer and easier to @code{AC_SUBST} them
10657 from @file{configure.ac}. For instance, the following statement will
10658 cause @file{configure} to be rerun each time @file{version.sh} is
10661 @c Keep in sync with remake-config-status-dependencies.sh
10663 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh'])
10667 Note the @samp{$(top_srcdir)/} in the file name. Since this variable
10668 is to be used in all @file{Makefile}s, its value must be sensible at
10669 any level in the build hierarchy.
10671 Beware not to mistake @code{CONFIGURE_DEPENDENCIES} for
10672 @code{CONFIG_STATUS_DEPENDENCIES}.
10674 @c Keep in sync with remake-configure-dependencies.sh
10675 @code{CONFIGURE_DEPENDENCIES} adds dependencies to the
10676 @file{configure} rule, whose effect is to run @command{autoconf}. This
10677 variable should be seldom used, because @command{automake} already tracks
10678 @code{m4_include}d files. However it can be useful when playing
10679 tricky games with @code{m4_esyscmd} or similar non-recommendable
10680 macros with side effects. Be also aware that interactions of this
10681 variable with the @ref{Autom4te Cache, , autom4te cache, autoconf,
10682 The Autoconf Manual} are quite problematic and can cause subtle
10683 breakage, so you might want to disable the cache if you want to use
10684 @code{CONFIGURE_DEPENDENCIES}.
10686 @code{CONFIG_STATUS_DEPENDENCIES} adds dependencies to the
10687 @file{config.status} rule, whose effect is to run @file{configure}.
10688 This variable should therefore carry any non-standard source that may
10689 be read as a side effect of running @command{configure}, like @file{version.sh}
10690 in the example above.
10692 Speaking of @file{version.sh} scripts, we recommend against them
10693 today. They are mainly used when the version of a package is updated
10694 automatically by a script (e.g., in daily builds). Here is what some
10695 old-style @file{configure.ac}s may look like:
10699 . $srcdir/version.sh
10700 AM_INIT_AUTOMAKE([name], $VERSION_NUMBER)
10705 Here, @file{version.sh} is a shell fragment that sets
10706 @code{VERSION_NUMBER}. The problem with this example is that
10707 @command{automake} cannot track dependencies (listing @file{version.sh}
10708 in @command{CONFIG_STATUS_DEPENDENCIES}, and distributing this file is up
10709 to the user), and that it uses the obsolete form of @code{AC_INIT} and
10710 @code{AM_INIT_AUTOMAKE}. Upgrading to the new syntax is not
10711 straightforward, because shell variables are not allowed in
10712 @code{AC_INIT}'s arguments. We recommend that @file{version.sh} be
10713 replaced by an M4 file that is included by @file{configure.ac}:
10716 m4_include([version.m4])
10717 AC_INIT([name], VERSION_NUMBER)
10723 Here @file{version.m4} could contain something like
10724 @samp{m4_define([VERSION_NUMBER], [1.2])}. The advantage of this
10725 second form is that @command{automake} will take care of the
10726 dependencies when defining the rebuild rule, and will also distribute
10727 the file automatically. An inconvenience is that @command{autoconf}
10728 will now be rerun each time the version number is bumped, when only
10729 @file{configure} had to be rerun in the previous setup.
10731 @opindex --always-make @r{GNU Make option}
10732 GNU Make, at least, has an option @option{--always-make} which tells
10733 Make to consider that all targets are out of date. This interacts
10734 badly with Automake-generated Makefiles, which implement their own
10735 careful rules for when to regenerate Makefiles, as described above.
10736 The result is an endless loop, or other poor behavior. The only thing
10737 to do, as far as we know, is to refrain from using
10738 @option{--always-make}.
10742 @chapter Changing Automake's Behavior
10745 * Options generalities:: Semantics of Automake option
10746 * List of Automake options:: A comprehensive list of Automake options
10749 @node Options generalities
10750 @section Options generalities
10752 Various features of Automake can be controlled by options. Except where
10753 noted otherwise, options can be specified in one of several ways. Most
10754 options can be applied on a per-@file{Makefile} basis when listed in a
10755 special @file{Makefile} variable named @code{AUTOMAKE_OPTIONS}. Some
10756 of these options only make sense when specified in the toplevel
10757 @file{Makefile.am} file. Options are applied globally to all processed
10758 @file{Makefile} files when listed in the first argument of
10759 @code{AM_INIT_AUTOMAKE} in @file{configure.ac}, and some options which
10760 require changes to the @command{configure} script can only be specified
10761 there. These are annotated below.
10763 As a general rule, options specified in @code{AUTOMAKE_OPTIONS} take
10764 precedence over those specified in @code{AM_INIT_AUTOMAKE}, which in
10765 turn take precedence over those specified on the command line.
10767 Also, some care must be taken about the interactions among strictness
10768 level and warning categories. As a general rule, strictness-implied
10769 warnings are overridden by those specified by explicit options. For
10770 example, even if @samp{portability} warnings are disabled by default
10771 in @option{foreign} strictness, a usage like this will end up enabling
10775 AUTOMAKE_OPTIONS = -Wportability foreign
10778 However, a strictness level specified in a higher-priority context
10779 will override all the explicit warnings specified in a lower-priority
10780 context. For example, if @file{configure.ac} contains:
10783 AM_INIT_AUTOMAKE([-Wportability])
10787 and @file{Makefile.am} contains:
10790 AUTOMAKE_OPTIONS = foreign
10794 then @samp{portability} warnings will be @emph{disabled} in
10795 @file{Makefile.am}.
10797 @node List of Automake options
10798 @section List of Automake options
10800 @vindex AUTOMAKE_OPTIONS
10803 @item @option{gnits}
10804 @itemx @option{gnu}
10805 @itemx @option{foreign}
10806 @cindex Option, @option{gnits}
10807 @cindex Option, @option{gnu}
10808 @cindex Option, @option{foreign}
10813 Set the strictness as appropriate. @xref{Strictness}.
10814 The @option{gnits} option also implies options @option{readme-alpha} and
10815 @option{check-news}.
10817 @item @option{check-news}
10818 @cindex Option, @option{check-news}
10819 @opindex check-news
10820 Cause @samp{make dist} to fail unless the current version number appears
10821 in the first few lines of the @file{NEWS} file.
10823 @item @option{dejagnu}
10824 @cindex Option, @option{dejagnu}
10826 Cause @command{dejagnu}-specific rules to be generated. @xref{DejaGnu Tests}.
10828 @item @option{dist-bzip2}
10829 @cindex Option, @option{dist-bzip2}
10830 @opindex dist-bzip2
10831 Hook @code{dist-bzip2} to @code{dist}.
10832 @trindex dist-bzip2
10834 @item @option{dist-lzip}
10835 @cindex Option, @option{dist-lzip}
10837 Hook @code{dist-lzip} to @code{dist}.
10840 @item @option{dist-xz}
10841 @cindex Option, @option{dist-xz}
10843 Hook @code{dist-xz} to @code{dist}.
10846 @item @option{dist-zip}
10847 @cindex Option, @option{dist-zip}
10849 Hook @code{dist-zip} to @code{dist}.
10852 @item @option{dist-zstd}
10853 @cindex Option, @option{dist-zstd}
10855 Hook @code{dist-zstd} to @code{dist}.
10858 @item @option{dist-shar}
10859 @cindex Option, @option{dist-shar}
10861 Hook @code{dist-shar} to @code{dist}. Use of this option
10862 is deprecated, as the @samp{shar} format is obsolescent and
10863 problematic. Support for it will be removed altogether in
10867 @item @option{dist-tarZ}
10868 @cindex Option, @option{dist-tarZ}
10870 Hook @code{dist-tarZ} to @code{dist}. Use of this option
10871 is deprecated, as the @samp{compress} program is obsolete.
10872 Support for it will be removed altogether in Automake 2.0.
10875 @item @option{filename-length-max=99}
10876 @cindex Option, @option{filename-length-max=99}
10877 @opindex filename-length-max=99
10878 Abort if file names longer than 99 characters are found during
10879 @samp{make dist}. Such long file names are generally considered not to
10880 be portable in tarballs. See the @option{tar-v7} and @option{tar-ustar}
10881 options below. This option should be used in the top-level
10882 @file{Makefile.am} or as an argument of @code{AM_INIT_AUTOMAKE} in
10883 @file{configure.ac}; it will be ignored otherwise. It will also be
10884 ignored in sub-packages of nested packages (@pxref{Subpackages}).
10886 @item @option{info-in-builddir}
10887 @cindex Option, @option{info-in-builddir}
10888 @opindex info-in-builddir
10889 Instruct Automake to place the generated @file{.info} files in the
10890 @code{builddir} rather than in the @code{srcdir}. Note that this
10891 might make VPATH builds with some non-GNU make implementations more
10894 @item @option{no-define}
10895 @cindex Option, @option{no-define}
10897 This option is meaningful only when passed as an argument to
10898 @code{AM_INIT_AUTOMAKE}. It will prevent the @code{PACKAGE} and
10899 @code{VERSION} variables from being @code{AC_DEFINE}d. But notice
10900 that they will remain defined as shell variables in the generated
10901 @code{configure}, and as make variables in the generated
10902 @code{Makefile}; this is deliberate, and required for backward
10905 @item @option{no-dependencies}
10906 @cindex Option, @option{no-dependencies}
10907 @opindex no-dependencies
10908 This is similar to using @option{--ignore-deps} on the command line,
10909 but is useful for those situations where you don't have the necessary
10910 bits to make automatic dependency tracking work
10911 (@pxref{Dependencies}). In this case the effect is to effectively
10912 disable automatic dependency tracking.
10914 @item @option{no-dist}
10915 @cindex Option, @option{no-dist}
10917 Don't emit any code related to @code{dist} target. This is useful
10918 when a package has its own method for making distributions.
10920 @item @option{no-dist-built-sources}
10921 @cindex Option, @option{no-dist-built-sources}
10922 @opindex no-dist-built-sources
10923 @cindex @command{help2man}, and @samp{dist} target
10924 @vindex BUILT_SOURCES, and @samp{dist} target
10925 Don't build @code{BUILT_SOURCES} as part of @code{dist}. This option
10926 can be set if building the distribution only requires the source
10927 files, and doesn't compile anything as a side-effect. The default is
10928 for @samp{$(distdir)} to depend on @samp{$(BUILT_SOURCES)} because it
10929 is common, at least among GNU packages, to want to build the program
10930 to generate man pages with @code{help2man} (@pxref{Errors with
10931 distclean}). Admittedly the default behavior should perhaps be to
10932 omit the dependency, but to preserve compatibility, we don't want to
10935 @item @option{no-dist-gzip}
10936 @cindex Option, @option{no-dist-gzip}
10937 @opindex no-dist-gzip
10938 Do not hook @code{dist-gzip} to @code{dist}.
10939 @trindex no-dist-gzip
10941 @item @option{no-exeext}
10942 @cindex Option, @option{no-exeext}
10944 If your @file{Makefile.am} defines a rule for target @code{foo}, it
10945 will override a rule for a target named @samp{foo$(EXEEXT)}. This is
10946 necessary when @code{EXEEXT} is found to be empty. However, by
10947 default @command{automake} will generate an error for this use. The
10948 @option{no-exeext} option will disable this error. This is intended for
10949 use only where it is known in advance that the package will not be
10950 ported to Windows, or any other operating system using extensions on
10953 @item @option{no-installinfo}
10954 @cindex Option, @option{no-installinfo}
10955 @opindex no-installinfo
10956 The generated @file{Makefile.in} will not cause info pages to be built
10957 or installed by default. However, @code{info} and @code{install-info}
10958 targets will still be available. This option is disallowed at
10959 @option{gnu} strictness and above.
10961 @trindex install-info
10963 @item @option{no-installman}
10964 @cindex Option, @option{no-installman}
10965 @opindex no-installman
10966 The generated @file{Makefile.in} will not cause man pages to be
10967 installed by default. However, an @code{install-man} target will still
10968 be available for optional installation. This option is disallowed at
10969 @option{gnu} strictness and above.
10970 @trindex install-man
10972 @item @option{nostdinc}
10973 @cindex Option, @option{nostdinc}
10975 This option can be used to disable the standard @option{-I} options that
10976 are ordinarily automatically provided by Automake.
10978 @item @option{no-texinfo.tex}
10979 @cindex Option, @option{no-texinfo.tex}
10980 @opindex no-texinfo.tex
10981 Don't require @file{texinfo.tex}, even if there are texinfo files in
10984 @item @option{posix}
10985 @cindex Option, @option{posix}
10987 Generate the special target @code{.POSIX} as the first non-comment
10988 line in the @file{Makefile.in} files. This alters the behavior of the
10989 @code{make} program. @xref{Special targets,, make, The GNU Make
10992 @item @option{serial-tests}
10993 @cindex Option, @option{serial-tests}
10994 @opindex serial-tests
10995 Enable the older serial test suite harness for @code{TESTS} (@pxref{Serial
10996 Test Harness}, for more information).
10998 @item @option{parallel-tests}
10999 @cindex Option, @option{parallel-tests}
11000 @opindex parallel-tests
11001 Enable test suite harness for @code{TESTS} that can run tests in parallel
11002 (@pxref{Parallel Test Harness}, for more information). This option is
11003 only kept for backward-compatibility, since the parallel test harness is
11006 @item @option{readme-alpha}
11007 @cindex Option, @option{readme-alpha}
11008 @opindex readme-alpha
11009 If this release is an alpha release, and the file @file{README-alpha}
11010 exists, then it will be added to the distribution. If this option is
11011 given, version numbers are expected to follow one of two forms. The
11012 first form is @samp{@var{major}.@var{minor}.@var{alpha}}, where each
11013 element is a number; the final period and number should be left off for
11014 non-alpha releases. The second form is
11015 @samp{@var{major}.@var{minor}@var{alpha}}, where @var{alpha} is a
11016 letter; it should be omitted for non-alpha releases.
11018 @item @option{std-options}
11019 @cindex Options, @option{std-options}
11020 @cindex @samp{make installcheck}, testing @option{--help} and @option{--version}
11021 @cindex @option{--help} check
11022 @cindex @option{--version} check
11023 @opindex std-options
11025 Make the @code{installcheck} rule check that installed scripts and
11026 programs support the @option{--help} and @option{--version} options.
11027 This also provides a basic check that the program's
11028 run-time dependencies are satisfied after installation.
11030 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
11031 In a few situations, programs (or scripts) have to be exempted from this
11032 test. For instance, @command{false} (from GNU coreutils) is never
11033 successful, even for @option{--help} or @option{--version}. You can list
11034 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
11035 Programs (not scripts) listed in this variable should be suffixed by
11036 @samp{$(EXEEXT)} for the sake of Windows or OS/2. For instance, suppose we
11037 build @file{false} as a program but @file{true.sh} as a script, and that
11038 neither of them support @option{--help} or @option{--version}:
11041 AUTOMAKE_OPTIONS = std-options
11042 bin_PROGRAMS = false ...
11043 bin_SCRIPTS = true.sh ...
11044 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
11047 @item @option{subdir-objects}
11048 @cindex Options, @option{subdir-objects}
11049 @opindex subdir-objects
11050 If this option is specified, then objects are placed into the
11051 subdirectory of the build directory corresponding to the subdirectory of
11052 the source file. For instance, if the source file is
11053 @file{subdir/file.cxx}, then the output file would be
11054 @file{subdir/file.o}. @xref{Program and Library Variables}.
11056 @anchor{tar-formats}
11057 @item @option{tar-v7}
11058 @itemx @option{tar-ustar}
11059 @itemx @option{tar-pax}
11060 @cindex Option, @option{tar-v7}
11061 @cindex Option, @option{tar-ustar}
11062 @cindex Option, @option{tar-pax}
11063 @cindex @command{tar} formats
11064 @cindex v7 @command{tar} format
11065 @cindex ustar format
11071 These three mutually exclusive options select the tar format to use
11072 when generating tarballs with @samp{make dist}. (The tar file created
11073 is then compressed according to the set of @option{no-dist-gzip},
11074 @option{dist-bzip2}, @option{dist-lzip}, @option{dist-xz},
11075 @option{dist-zstd} and @option{dist-tarZ} options in use.)
11077 These options must be passed as arguments to @code{AM_INIT_AUTOMAKE}
11078 (@pxref{Macros}) because they can require additional configure checks.
11079 Automake will complain if it sees such options in an
11080 @code{AUTOMAKE_OPTIONS} variable.
11082 @option{tar-v7} selects the old V7 tar format. This is the historical
11083 default. This antiquated format is understood by all tar
11084 implementations and supports file names with up to 99 characters. When
11085 given longer file names some tar implementations will diagnose the
11086 problem while others will generate broken tarballs or use non-portable
11087 extensions. Furthermore, the V7 format cannot store empty
11088 directories. When using this format, consider using the
11089 @option{filename-length-max=99} option to catch file names too long.
11091 @option{tar-ustar} selects the ustar format defined by POSIX
11092 1003.1-1988. This format is old enough to be portable:
11093 As of 2018, it is supported by the native @code{tar} command on
11094 GNU, FreeBSD, NetBSD, OpenBSD, AIX, HP-UX, and Solaris, at least.
11095 It fully supports empty directories. It can store file names with up
11096 to 256 characters, provided that the file name can be split at
11097 directory separator in two parts, first of them being at most 155
11098 bytes long. So, in most cases the maximum file name length will be
11099 shorter than 256 characters.
11101 @option{tar-pax} selects the new pax interchange format defined by POSIX
11102 1003.1-2001. It does not limit the length of file names. However,
11103 this format is very young and should probably be restricted to
11104 packages that target only very modern platforms.
11105 As of 2018, this format is supported by the native @code{tar} command only
11106 on GNU, FreeBSD, and OpenBSD systems; it is not supported by the native
11107 @code{tar} command on NetBSD, AIX, HP-UX, or Solaris.
11109 change the pax format in an upward-compatible way, so this option may
11110 refer to a more recent version in the future.
11112 @xref{Formats, , Controlling the Archive Format, tar, GNU Tar}, for
11113 further discussion about tar formats.
11115 @command{configure} knows several ways to construct these formats. It
11116 will not abort if it cannot find a tool up to the task (so that the
11117 package can still be built), but @samp{make dist} will fail.
11119 @item @var{version}
11120 @cindex Option, @var{version}
11121 A version number (e.g., @samp{0.30}) can be specified. If Automake is not
11122 the same version or
11123 newer than the version specified, creation of the @file{Makefile.in}
11124 will be suppressed.
11126 @item @option{-W@var{category}} or @option{--warnings=@var{category}}
11127 @cindex Option, warnings
11128 @cindex Option, @option{-W@var{category}}
11129 @cindex Option, @option{--warnings=@var{category}}
11130 These options behave exactly like their command-line counterpart
11131 (@pxref{automake Invocation}). This allows you to enable or disable some
11132 warning categories on a per-file basis. You can also setup some warnings
11133 for your entire project; for instance, try @samp{AM_INIT_AUTOMAKE([-Wall])}
11134 in your @file{configure.ac}.
11138 Unrecognized options are diagnosed by @command{automake}.
11140 If you want an option to apply to all the files in the tree, you can use
11141 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.ac}.
11145 @node Miscellaneous
11146 @chapter Miscellaneous Rules
11148 There are a few rules and variables that didn't fit anywhere else.
11151 * Tags:: Interfacing to cscope, etags and mkid
11152 * Suffixes:: Handling new file extensions
11157 @section Interfacing to @command{etags}
11159 @cindex @file{TAGS} support
11161 Automake will generate rules to generate @file{TAGS} files for use with
11162 GNU Emacs under some circumstances.
11165 If any C, C++ or Fortran 77 source code or headers are present, then
11166 @code{tags} and @code{TAGS} rules will be generated for the directory.
11167 All files listed using the @code{_SOURCES}, @code{_HEADERS}, and
11168 @code{_LISP} primaries will be used to generate tags. Generated
11169 source files that are not distributed must be declared in variables
11170 like @code{nodist_noinst_HEADERS} or @code{nodist_@var{prog}_SOURCES}
11171 or they will be ignored.
11173 A @code{tags} rule will be output at the topmost directory of a
11174 multi-directory package. When run from this topmost directory,
11175 @samp{make tags} will generate a @file{TAGS} file that includes by
11176 reference all @file{TAGS} files from subdirectories.
11178 The @code{tags} rule will also be generated if the variable
11179 @code{ETAGS_ARGS} is defined. This variable is intended for use in
11180 directories that contain taggable source that @command{etags} does
11181 not understand. The user can use the @code{ETAGSFLAGS} to pass
11182 additional flags to @command{etags}; @code{AM_ETAGSFLAGS} is also
11183 available for use in @file{Makefile.am}. The variable @code{ETAGS}
11184 is the name of the program to invoke (by default @command{etags}).
11187 @vindex AM_ETAGSFLAGS
11190 Here is how Automake generates tags for its source, and for nodes in its
11194 ETAGS_ARGS = automake.in --lang=none \
11195 --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
11198 If you add file names to @code{ETAGS_ARGS}, you will probably also
11199 want to define @code{TAGS_DEPENDENCIES}. The contents of this variable
11200 are added directly to the dependencies for the @code{tags} rule.
11201 @vindex TAGS_DEPENDENCIES
11203 Automake also generates a @code{ctags} rule that can be used to
11204 build @command{vi}-style @file{tags} files. The variable @code{CTAGS}
11205 is the name of the program to invoke (by default @command{ctags});
11206 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
11207 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
11213 Automake will also generate an @code{ID} rule that will run
11214 @command{mkid} on the source. This is only supported on a
11215 directory-by-directory basis.
11217 Similarly, the @code{cscope} rule will create a list of all the source
11218 files in the tree and run @command{cscope} to build an inverted index
11219 database. The variable @code{CSCOPE} is the name of the program to invoke
11220 (by default @command{cscope}); @code{CSCOPEFLAGS} and
11221 @code{CSCOPE_ARGS} can be used by the user to pass additional flags and
11222 file names respectively, while @code{AM_CSCOPEFLAGS} can be used by the
11223 @file{Makefile.am}. Note that, currently, the Automake-provided
11224 @code{cscope} support, when used in a VPATH build, might not work well
11225 with non-GNU make implementations (especially with make implementations
11226 performing @ref{Automatic Rule Rewriting, , VPATH rewrites, autoconf,
11227 The Autoconf Manual}).
11228 @vindex CSCOPE_ARGS
11229 @vindex CSCOPEFLAGS
11232 Finally, Automake also emits rules to support the
11233 @uref{https://www.gnu.org/software/global/, GNU Global Tags program}.
11234 The @code{GTAGS} rule runs Global Tags and puts the
11235 result in the top build directory. The variable @code{GTAGS_ARGS}
11236 holds arguments that are passed to @command{gtags}.
11241 @section Handling new file extensions
11243 @cindex Adding new @code{SUFFIXES}
11244 @cindex @code{SUFFIXES}, adding
11247 It is sometimes useful to introduce a new implicit rule to handle a file
11248 type that Automake does not know about.
11250 For instance, suppose you had a compiler that could compile @file{.foo}
11251 files to @file{.o} files. You would simply define a suffix rule for
11259 Then you could directly use a @file{.foo} file in a @code{_SOURCES}
11260 variable and expect the correct results:
11263 bin_PROGRAMS = doit
11264 doit_SOURCES = doit.foo
11267 This was the simpler and more common case. In other cases, you will
11268 have to help Automake to figure out which extensions you are defining your
11269 suffix rule for. This usually happens when your extension does not
11270 start with a dot. Then, all you have to do is to put a list of new
11271 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
11274 For instance, the following definition prevents Automake from misinterpreting
11275 the @samp{.idlC.cpp:} rule as an attempt to transform @file{.idlC} files into
11278 @c Keep in sync with suffix7.sh
11280 SUFFIXES = .idl C.cpp
11285 As you may have noted, the @code{SUFFIXES} variable behaves like the
11286 @code{.SUFFIXES} special target of @command{make}. You should not touch
11287 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
11288 Automake generate the suffix list for @code{.SUFFIXES}. Any given
11289 @code{SUFFIXES} go at the start of the generated suffixes list, followed
11290 by Automake generated suffixes not already in the list.
11292 @c https://bugs.gnu.org/64743.
11293 @cindex built-in suffix and pattern rules, disabled
11294 @cindex suffix rules of Make, disabled
11295 @cindex pattern rules of GNU Make, disabled
11296 Automake disables the Make program's built-in rules with a
11297 @code{.SUFFIXES:} rule, and then adds whatever suffixes are
11298 necessary. Automake also disables GNU Make's built-in pattern rules.
11304 @cindex Including @file{Makefile} fragment
11305 @cindex @file{Makefile} fragment, including
11307 Automake supports an @code{include} directive that can be used to
11308 include other @file{Makefile} fragments when @command{automake} is run.
11309 Note that these fragments are read and interpreted by @command{automake},
11310 not by @command{make}. As with conditionals, @command{make} has no idea that
11311 @code{include} is in use.
11313 There are two forms of @code{include}:
11316 @item include $(srcdir)/file
11317 Include a fragment that is found relative to the current source
11320 @item include $(top_srcdir)/file
11321 Include a fragment that is found relative to the top source directory.
11324 Note that if a fragment is included inside a conditional, then the
11325 condition applies to the entire contents of that fragment.
11327 @file{Makefile} fragments included this way are always distributed because
11328 they are needed to rebuild @file{Makefile.in}.
11330 Inside a fragment, the construct @code{%reldir%} is replaced with the
11331 directory of the fragment relative to the base @file{Makefile.am}.
11332 Similarly, @code{%canon_reldir%} is replaced with the canonicalized
11333 (@pxref{Canonicalization}) form of @code{%reldir%}. As a convenience,
11334 @code{%D%} is a synonym for @code{%reldir%}, and @code{%C%}
11335 is a synonym for @code{%canon_reldir%}.
11337 A special feature is that if the fragment is in the same directory as
11338 the base @file{Makefile.am} (i.e., @code{%reldir%} is @code{.}), then:
11342 together with a following slash expands to the empty string, otherwise
11343 it expands to a dot;
11345 @item %canon_reldir%
11346 together with a following underscore expands to the empty string, otherwise
11347 it expands to an underscore.
11351 Thus, a @file{Makefile} fragment might look like this:
11354 bin_PROGRAMS += %reldir%/mumble
11355 %canon_reldir%_mumble_SOURCES = %reldir%/one.c
11359 @chapter Conditionals
11361 @cindex Conditionals
11363 Automake supports a simple type of conditional.
11365 These conditionals are not the same as conditionals in
11366 GNU Make. Automake conditionals are checked at configure time by the
11367 @file{configure} script, and affect the translation from
11368 @file{Makefile.in} to @file{Makefile}. They are based on options passed
11369 to @file{configure} and on results that @file{configure} has discovered
11370 about the host system. GNU Make conditionals are checked at @command{make}
11371 time, and are based on variables passed to the make program or defined
11372 in the @file{Makefile}.
11374 Automake conditionals will work with any make program.
11377 * Usage of Conditionals:: Declaring conditional content
11378 * Limits of Conditionals:: Enclosing complete statements
11381 @node Usage of Conditionals
11382 @section Usage of Conditionals
11384 @acindex AM_CONDITIONAL
11385 Before using a conditional, you must define it by using
11386 @code{AM_CONDITIONAL} in the @file{configure.ac} file (@pxref{Macros}).
11388 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
11389 The conditional name, @var{conditional}, should be a simple string
11390 starting with a letter and containing only letters, digits, and
11391 underscores. It must be different from @samp{TRUE} and @samp{FALSE},
11392 which are reserved by Automake.
11394 The shell @var{condition} (suitable for use in a shell @code{if}
11395 statement) is evaluated when @command{configure} is run. Note that you
11396 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
11397 time @command{configure} is run. If @code{AM_CONDITIONAL} is run
11398 conditionally (e.g., in a shell @code{if} statement), then the result
11399 will confuse @command{automake}.
11401 For portability, it is best to use shell operators @code{&&} and
11402 @code{||} and parentheses, when constructing a compound
11403 @var{condition} using the @command{test} command, and not the
11404 @code{-a} and @code{-o} options and parentheses as options to
11405 @command{test}, all of which have been marked obsolescent by POSIX
11406 (@url{https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html#tag_20_128_161}).
11407 The name @code{test} is also more portable than @code{[}.
11408 @xref{Limitations of Builtins, ,, autoconf, The Autoconf Manual}.
11412 @cindex @option{--enable-debug}, example
11413 @cindex Example conditional @option{--enable-debug}
11414 @cindex Conditional example, @option{--enable-debug}
11416 Conditionals typically depend upon options that the user provides to
11417 the @command{configure} script. Here is an example of how to write a
11418 conditional that is true if the user uses the @option{--enable-debug}
11422 AC_ARG_ENABLE([debug],
11423 [ --enable-debug Turn on debugging],
11424 [case "$@{enableval@}" in
11427 *) AC_MSG_ERROR([bad value $@{enableval@} for --enable-debug]) ;;
11428 esac],[debug=false])
11429 AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
11432 Here is an example of how to use that conditional in @file{Makefile.am}:
11444 noinst_PROGRAMS = $(DBG)
11447 This trivial example could also be handled using @code{EXTRA_PROGRAMS}
11448 (@pxref{Conditional Programs}).
11450 You may only test a single variable in an @code{if} statement, possibly
11451 negated using @samp{!}. The @code{else} statement may be omitted.
11452 Conditionals may be nested to any depth. You may specify an argument to
11453 @code{else} in which case it must be the negation of the condition used
11454 for the current @code{if}. Similarly you may specify the condition
11455 that is closed on the @code{endif} line:
11466 Unbalanced conditions are errors. The @code{if}, @code{else}, and
11467 @code{endif} statements should not be indented, i.e., start on column
11470 The @code{else} branch of the above two examples could be omitted,
11471 since assigning the empty string to an otherwise undefined variable
11472 makes no difference.
11474 @acindex AM_COND_IF
11475 In order to allow access to the condition registered by
11476 @code{AM_CONDITIONAL} inside @file{configure.ac}, and to allow
11477 conditional @code{AC_CONFIG_FILES}, @code{AM_COND_IF} may be used:
11479 @defmac AM_COND_IF (@var{conditional}, @ovar{if-true}, @ovar{if-false})
11480 If @var{conditional} is fulfilled, execute @var{if-true}, otherwise
11481 execute @var{if-false}. If either branch contains @code{AC_CONFIG_FILES},
11482 it will cause @command{automake} to output the rules for the respective
11483 files only for the given condition.
11486 @code{AM_COND_IF} macros may be nested when m4 quotation is used
11487 properly (@pxref{M4 Quotation, ,, autoconf, The Autoconf Manual}).
11489 @cindex Example conditional @code{AC_CONFIG_FILES}
11490 @cindex @code{AC_CONFIG_FILES}, conditional
11492 Here is an example of how to define a conditional config file:
11495 AM_CONDITIONAL([SHELL_WRAPPER], [test "x$with_wrapper" = xtrue])
11496 AM_COND_IF([SHELL_WRAPPER],
11497 [AC_CONFIG_FILES([wrapper:wrapper.in])])
11500 @node Limits of Conditionals
11501 @section Limits of Conditionals
11503 Conditionals should enclose complete statements like variables or
11504 rules definitions. Automake cannot deal with conditionals used inside
11505 a variable definition, for instance, and is not even able to diagnose
11506 this situation. The following example would not work:
11509 # This syntax is not understood by Automake
11518 However the intended definition of @code{AM_CPPFLAGS} can be achieved
11523 DEBUGFLAGS = -DDEBUG
11525 AM_CPPFLAGS = -DFEATURE_A $(DEBUGFLAGS) -DFEATURE_B
11532 AM_CPPFLAGS = -DFEATURE_A
11534 AM_CPPFLAGS += -DDEBUG
11536 AM_CPPFLAGS += -DFEATURE_B
11539 More details and examples of conditionals are described alongside
11540 various Automake features in this manual (@pxref{Conditional
11541 Subdirectories}, @pxref{Conditional Sources}, @pxref{Conditional
11542 Programs}, @pxref{Conditional Libtool Libraries}, @pxref{Conditional
11545 @node Silencing Make
11546 @chapter Silencing @command{make}
11548 @cindex Silent @command{make}
11549 @cindex Silencing @command{make}
11550 @cindex Silent rules
11551 @cindex Silent @command{make} rules
11554 * Make verbosity:: Make is verbose by default
11555 * Tricks For Silencing Make:: Standard and generic ways to silence make
11556 * Automake Silent Rules:: How Automake can help in silencing make
11557 * Unsilencing Automake:: Showing commands.
11560 @node Make verbosity
11561 @section Make is verbose by default
11563 Normally, when executing the set of rules associated with a target,
11564 @command{make} prints each rule before it is executed. This behavior,
11565 despite having been in place since the beginning of @command{make},
11566 and being mandated by the POSIX standard, starkly violates the
11567 ``silence is golden'' UNIX principle@footnote{See also
11568 @uref{http://catb.org/~esr/writings/taoup/html/ch11s09.html}.}:
11571 When a program has nothing interesting or surprising to say, it should
11572 say nothing. Well-behaved Unix programs do their jobs unobtrusively,
11573 with a minimum of fuss and bother. Silence is golden.
11576 The traditional verbosity of @command{make} is understandable, as it
11577 is useful, often necessary, in order to understand reasons of
11578 failures. However, it can also hide warning and error messages from
11579 @command{make}-invoked tools, drowning them in uninteresting and
11580 seldom useful messages, and thus allowing them to easily go
11583 This can be quite problematic, especially for developers, who usually
11584 know quite well what's going on behind the scenes, and for whom the
11585 verbose output from @command{make} ends up being mostly noise that
11586 hampers the easy detection of potentially important warning messages.
11588 So Automake provides some support for silencing @command{make}.
11590 @node Tricks For Silencing Make
11591 @section Standard and generic ways to silence Make
11593 Here we describe some common idioms/tricks to obtain a quieter
11594 @command{make} output, with their relative advantages and drawbacks.
11595 In the next section (@ref{Automake Silent Rules}) we'll see how
11596 Automake can help in this respect, providing more elaborate and
11601 @item @command{make -s}
11603 This simply causes @command{make} not to print @emph{any} rule before
11606 The @option{-s} flag is mandated by POSIX, universally supported, and
11607 its purpose and function are easy to understand.
11609 But it also has serious limitations. First of all, it embodies an
11610 ``all or nothing'' strategy, i.e., either everything is silenced, or
11611 nothing is; in practice, this lack of granularity makes it unsuitable
11612 as a general solution. When the @option{-s} flag is used, the
11613 @command{make} output might turn out to be too terse; in case of
11614 errors, the user won't be able to easily see what rule or command have
11615 caused them, or even, in case of tools with poor error reporting, what
11618 @item @command{make >/dev/null || make}
11620 Apparently, this perfectly obeys the ``silence is golden'' rule: warnings
11621 from stderr are passed through, output reporting is done only in case of
11622 error, and in that case it should provide a verbose-enough report to allow
11623 an easy determination of the error location and causes.
11625 However, calling @command{make} two times in a row might hide errors
11626 (especially intermittent ones), or subtly change the expected
11627 semantics of the @command{make} calls---these things can clearly make
11628 debugging and error assessment very difficult.
11630 @item @command{make --no-print-directory}
11632 This is GNU @command{make} specific. When called with the
11633 @option{--no-print-directory} option, GNU @command{make} will disable
11634 printing of the working directory by invoked sub-@command{make}s (the
11635 well-known ``@i{Entering/Leaving directory @dots{}}'' messages). This
11636 helps to decrease the verbosity of the output, but experience has
11637 shown that it can also often render debugging considerably harder in
11638 projects using deeply-nested @command{make} recursion.
11640 As an aside, the @option{--no-print-directory} option is automatically
11641 activated if the @option{-s} flag is used.
11643 @c TODO: Other tricks?
11644 @c TODO: Maybe speak about the @code{.SILENT} target?
11645 @c TODO: - Pros: More granularity on what to silence.
11646 @c TODO: - Cons: No easy way to temporarily override.
11650 @node Automake Silent Rules
11651 @section How Automake can help in silencing Make
11653 The tricks and idioms for silencing @command{make} described in the
11654 previous section can be useful from time to time, but we've seen that
11655 they all have their serious drawbacks and limitations. That's why
11656 automake provides support for a more advanced and flexible way of
11657 obtaining quieter output from @command{make} (for most rules at least).
11659 To give the gist of what Automake can do in this respect, here is a simple
11660 comparison between a typical @command{make} output (where silent rules
11661 are disabled) and one with silent rules enabled:
11664 % @kbd{cat Makefile.am}
11666 foo_SOURCES = main.c func.c
11668 int main (void) @{ return func (); @} /* func used undeclared */
11670 int func (void) @{ int i; return i; @} /* i used uninitialized */
11672 @i{The make output is by default very verbose. This causes warnings
11673 from the compiler to be somewhat hidden, and not immediate to spot.}
11674 % @kbd{make CFLAGS=-Wall}
11675 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
11676 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
11677 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT main.o
11678 -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
11679 main.c: In function ‘main’:
11680 main.c:3:3: warning: implicit declaration of function ‘func’
11681 mv -f .deps/main.Tpo .deps/main.Po
11682 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
11683 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
11684 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT func.o
11685 -MD -MP -MF .deps/func.Tpo -c -o func.o func.c
11686 func.c: In function ‘func’:
11687 func.c:4:3: warning: ‘i’ used uninitialized in this function
11688 mv -f .deps/func.Tpo .deps/func.Po
11689 gcc -Wall -o foo main.o func.o
11691 @i{Clean up, so that we can rebuild everything from scratch.}
11693 test -z "foo" || rm -f foo
11696 @i{Silent rules enabled: the output is minimal but informative.
11697 The warnings from the compiler stick out very clearly.}
11698 % @kbd{make V=0 CFLAGS=-Wall}
11700 main.c: In function ‘main’:
11701 main.c:3:3: warning: implicit declaration of function ‘func’
11703 func.c: In function ‘func’:
11704 func.c:4:3: warning: ‘i’ used uninitialized in this function
11708 @cindex silent rules and libtool
11709 Also, in projects using @command{libtool}, the use of silent rules can
11710 automatically enable the @command{libtool}'s @option{--silent} option:
11713 % @kbd{cat Makefile.am}
11714 lib_LTLIBRARIES = libx.la
11716 % @kbd{make # Both make and libtool are verbose by default.}
11718 libtool: compile: gcc -DPACKAGE_NAME=\"foo\" ... -DLT_OBJDIR=\".libs/\"
11719 -I. -g -O2 -MT libx.lo -MD -MP -MF .deps/libx.Tpo -c libx.c -fPIC
11720 -DPIC -o .libs/libx.o
11721 mv -f .deps/libx.Tpo .deps/libx.Plo
11722 /bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -o libx.la -rpath
11723 /usr/local/lib libx.lo
11724 libtool: link: gcc -shared .libs/libx.o -Wl,-soname -Wl,libx.so.0
11725 -o .libs/libx.so.0.0.0
11726 libtool: link: cd .libs && rm -f libx.so && ln -s libx.so.0.0.0 libx.so
11734 For Automake-generated @file{Makefile}s, the user may influence the
11735 verbosity at @command{configure} run time as well as at @command{make}
11740 @opindex --enable-silent-rules
11741 @opindex --disable-silent-rules
11742 Passing @option{--enable-silent-rules} to @command{configure} will cause
11743 build rules to be less verbose; the option @option{--disable-silent-rules}
11744 will cause normal verbose output.
11748 At @command{make} run time, the default chosen at @command{configure}
11749 time may be overridden: @code{make V=1} will produce verbose output,
11750 @code{make V=0} less verbose output.
11752 Unfortunately, if @code{V} is assigned a value other than 0 or 1,
11753 errors will result. This is problematic when a third-party program or
11754 library is built in the same tree and also uses the make variable
11755 @code{V}, with different values. The best workaround is probably to
11756 set @code{AM_V_P=true} (or similar), either on the make command line
11757 or in the @code{V}-using project's @code{Makefile.am}. (For more
11758 discussion, see @url{https://bugs.gnu.org/20077}.)
11761 @cindex default verbosity for silent rules
11762 Silent rules are @emph{disabled} by default; the user must enable them
11763 explicitly at either @command{configure} run time or at @command{make}
11764 run time. We think that this is a good policy, since it provides the
11765 casual user with enough information to prepare a good bug report in
11766 case anything breaks.
11768 Notwithstanding those rationales, developers who want to enable silent
11769 rules by default in their own packages can do so by calling
11770 @code{AM_SILENT_RULES([yes])} in @file{configure.ac}.
11772 @c Keep in sync with silent-configsite.sh
11773 Analogously, users who prefer to have silent rules enabled by default
11774 for everything on their system can edit their @file{config.site} file
11775 to make the variable @code{enable_silent_rules} default to @samp{yes}.
11776 This still allows disabling silent rules at @command{configure} time
11777 and at @command{make} time.
11779 To work best, the current implementation of this feature normally uses
11780 nested variable expansion @samp{$(@var{var1}$(V))}, a @file{Makefile}
11781 feature that is not required by POSIX 2008 but is widely supported in
11782 practice. On the rare @command{make} implementations that do not
11783 support nested variable expansion, whether rules are silent is always
11784 determined at configure time, and cannot be overridden at make time.
11785 Future versions of POSIX are likely to require nested variable
11786 expansion, so this minor limitation should go away with time.
11788 @vindex @code{AM_V_GEN}
11789 @vindex @code{AM_V_at}
11790 @vindex @code{AM_DEFAULT_VERBOSITY}
11791 @vindex @code{AM_V}
11792 @vindex @code{AM_DEFAULT_V}
11793 To extend the silent mode to your own rules, you have a few choices:
11797 You can use the predefined variable @code{AM_V_GEN} as a prefix to
11798 commands that should output a status line in silent mode, and
11799 @code{AM_V_at} as a prefix to commands that should not output anything
11800 in silent mode. When output is to be verbose, both of these variables
11801 will expand to the empty string.
11804 You can silence a recipe unconditionally with @code{@@}, and then use
11805 the predefined variable @code{AM_V_P} to know whether make is being run
11806 in silent or verbose mode; adjust the verbose information your recipe
11807 displays accordingly. For example:
11809 @c smallexample because text is too wide for normal example.
11813 ... [commands defining shell variable '$headers'] ...; \
11814 if $(AM_V_P); then set -x; else echo " GEN [headers]"; fi; \
11815 rm -f $$headers && generate-header --flags $$headers
11818 @code{AM_V_P} is (must be) always set to a simple command, not needing
11819 shell quoting, typically either @code{:} or @code{true} or
11823 You can add your own variables, so strings of your own choice are shown.
11824 The following snippet shows how you would define your own equivalent of
11825 @code{AM_V_GEN}, say a string @samp{PKG-GEN}:
11827 @c smallexample because regular example would look weird
11828 @c next to the smallexample above.
11830 pkg_verbose = $(pkg_verbose_@@AM_V@@)
11831 pkg_verbose_ = $(pkg_verbose_@@AM_DEFAULT_V@@)
11832 pkg_verbose_0 = @@echo PKG-GEN $@@;
11835 $(pkg_verbose)cp $(srcdir)/foo.in $@@
11840 Even when silent rules are enabled, the @option{--no-print-directory}
11841 option is still required with GNU @command{make} if the
11842 ``@i{Entering/Leaving directory @dots{}}'' messages are to be elided.
11844 @node Unsilencing Automake
11845 @section Unsilencing Automake
11847 @cindex unsilencing Automake
11848 @cindex verbose output from Automake
11850 With the @code{AM_SILENT_RULES} macro described in the previous
11851 section, Automake does a good job reducing @command{make} output to a
11852 bare minimum. Sometimes you want to see more than that. Let's
11853 summarize ways to get more information out of Automake packages:
11857 Running @code{make V=1} will produce generally verbose output.
11860 Adding @code{AM_V_GEN= AM_V_at=} will unsilence more rules. Thus, in all:
11861 @code{make V=1 AM_V_GEN= AM_V_at=}.
11863 @c VERBOSE=1 is (highly) relevant to the Automake test suite,
11864 @c but not in general, so shouldn't be mentioned here. See automake/HACKING.
11866 @c Adding @code{VERBOSE=1} can unsilence yet more. Thus, in all:
11867 @c ode{make V=1 AM_V_GEN= AM_V_at= VERBOSE=1}.
11870 Even this will not unsilence everything. To see the real truth of what
11871 gets executed, resort to GNU Make's debugging feature: @code{make
11872 --debug=p ... other args ...}. This reports every command being run,
11873 ignoring the @code{@@} prefix on rules (which silences them). In the
11874 case of Automake, these commands are generally complex shell
11875 constructs, and you'll want to track down the source files in Automake
11876 to actually understand them; but at least you'll have the text to
11877 search for. You may wish to include other debugging
11878 options. @xref{Options Summary,,,make, The GNU Make Manual}.
11883 @chapter When Automake Isn't Enough
11885 In some situations, where Automake is not up to one task, one has to
11886 resort to handwritten rules or even handwritten @file{Makefile}s.
11889 * Extending:: Adding new rules or overriding existing ones.
11890 * Third-Party Makefiles:: Integrating Non-Automake @file{Makefile}s.
11894 @section Extending Automake Rules
11896 With some minor exceptions (for example @code{_PROGRAMS} variables,
11897 @code{TESTS}, or @code{XFAIL_TESTS}) being rewritten to append
11898 @samp{$(EXEEXT)}), the contents of a @file{Makefile.am} is copied to
11899 @file{Makefile.in} verbatim.
11901 @cindex copying semantics
11903 These copying semantics mean that many problems can be worked around
11904 by simply adding some @command{make} variables and rules to
11905 @file{Makefile.am}. Automake will ignore these additions.
11907 @cindex conflicting definitions
11908 @cindex rules, conflicting
11909 @cindex variables, conflicting
11910 @cindex definitions, conflicts
11912 Since a @file{Makefile.in} is built from data gathered from three
11913 different places (@file{Makefile.am}, @file{configure.ac}, and
11914 @command{automake} itself), it is possible to have conflicting
11915 definitions of rules or variables. When building @file{Makefile.in}
11916 the following priorities are respected by @command{automake} to ensure
11917 the user always has the last word:
11921 User defined variables in @file{Makefile.am} have priority over
11922 variables @code{AC_SUBST}ed from @file{configure.ac}, and
11923 @code{AC_SUBST}ed variables have priority over
11924 @command{automake}-defined variables.
11926 As far as rules are concerned, a user-defined rule overrides any
11927 @command{automake}-defined rule for the same target.
11930 @cindex overriding rules
11931 @cindex overriding semantics
11932 @cindex rules, overriding
11934 These overriding semantics make it possible to fine tune some default
11935 settings of Automake, or replace some of its rules. Overriding
11936 Automake rules is often inadvisable, particularly in the topmost
11937 directory of a package with subdirectories. The @option{-Woverride}
11938 option (@pxref{automake Invocation}) comes in handy to catch overridden
11941 Note that Automake does not make any distinction between rules with
11942 commands and rules that only specify dependencies. So it is not
11943 possible to append new dependencies to an @command{automake}-defined
11944 target without redefining the entire rule.
11946 @cindex @option{-local} targets
11947 @cindex local targets
11949 However, various useful targets have a @samp{-local} version you can
11950 specify in your @file{Makefile.am}. Automake will supplement the
11951 standard target with these user-supplied targets.
11956 @trindex info-local
11964 @trindex html-local
11966 @trindex check-local
11968 @trindex install-data
11969 @trindex install-data-local
11970 @trindex install-dvi
11971 @trindex install-dvi-local
11972 @trindex install-exec
11973 @trindex install-exec-local
11974 @trindex install-html
11975 @trindex install-html-local
11976 @trindex install-info
11977 @trindex install-info-local
11978 @trindex install-pdf
11979 @trindex install-pdf-local
11980 @trindex install-ps
11981 @trindex install-ps-local
11983 @trindex uninstall-local
11984 @trindex mostlyclean
11985 @trindex mostlyclean-local
11987 @trindex clean-local
11989 @trindex distclean-local
11990 @trindex installdirs
11991 @trindex installdirs-local
11992 @trindex installcheck
11993 @trindex installcheck-local
11995 The targets that support a local version are @code{all}, @code{info},
11996 @code{dvi}, @code{ps}, @code{pdf}, @code{html}, @code{check},
11997 @code{install-data}, @code{install-dvi}, @code{install-exec},
11998 @code{install-html}, @code{install-info}, @code{install-pdf},
11999 @code{install-ps}, @code{uninstall}, @code{installdirs},
12000 @code{installcheck} and the various @code{clean} targets
12001 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
12002 @code{maintainer-clean}).
12004 Note that there are no @code{uninstall-exec-local} or
12005 @code{uninstall-data-local} targets; just use @code{uninstall-local}.
12006 It doesn't make sense to uninstall just data or just executables.
12008 For instance, here is one way to erase a subdirectory during
12009 @samp{make clean} (@pxref{Clean}).
12016 You may be tempted to use @code{install-data-local} to install a file
12017 to some hard-coded location, but you should avoid this
12018 (@pxref{Hard-Coded Install Paths}).
12020 With the @code{-local} targets, there is no particular guarantee of
12021 execution order; typically, they are run early, but with parallel
12022 make, there is no way to be sure of that.
12024 @cindex @option{-hook} targets
12025 @cindex hook targets
12026 @trindex install-data-hook
12027 @trindex install-exec-hook
12028 @trindex uninstall-hook
12031 In contrast, some rules also have a way to run another rule, called a
12032 @dfn{hook}; hooks are always executed after the main rule's work is done.
12033 The hook is named after the principal target, with @samp{-hook} appended.
12034 The targets allowing hooks are @code{install-data},
12035 @code{install-exec}, @code{uninstall}, @code{dist}, and
12038 For instance, here is how to create a hard link to an installed program:
12042 ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
12043 $(DESTDIR)$(bindir)/proglink$(EXEEXT)
12046 Although cheaper and more portable than symbolic links, hard links
12047 will not work everywhere (for instance, OS/2 does not have
12048 @command{ln}). Ideally you should fall back to @samp{cp -p} when
12049 @command{ln} does not work. An easy way, if symbolic links are
12050 acceptable to you, is to add @code{AC_PROG_LN_S} to
12051 @file{configure.ac} (@pxref{Particular Programs, , Particular Program
12052 Checks, autoconf, The Autoconf Manual}) and use @samp{$(LN_S)} in
12053 @file{Makefile.am}.
12055 @cindex versioned binaries, installing
12056 @cindex installing versioned binaries
12057 @cindex @code{LN_S} example
12058 For instance, here is how you could install a versioned copy of a
12059 program using @samp{$(LN_S)}:
12061 @c Keep in sync with insthook.sh
12064 cd $(DESTDIR)$(bindir) && \
12065 mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
12066 $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
12069 Note that we rename the program so that a new version will erase the
12070 symbolic link, not the real binary. Also we @command{cd} into the
12071 destination directory in order to create relative links.
12073 When writing @code{install-exec-hook} or @code{install-data-hook},
12074 please bear in mind that the exec/data distinction is based on the
12075 installation directory, not on the primary used (@pxref{The Two Parts of
12077 @c Keep in sync with primary-prefix-couples-documented-valid.sh
12078 So a @code{foo_SCRIPTS} will be installed by
12079 @code{install-data}, and a @code{barexec_SCRIPTS} will be installed by
12080 @code{install-exec}. You should define your hooks accordingly.
12082 @c FIXME should include discussion of variables you can use in these
12085 @node Third-Party Makefiles
12086 @section Third-Party @file{Makefile}s
12088 @cindex Third-party packages, interfacing with
12089 @cindex Interfacing with third-party packages
12091 In most projects all @file{Makefile}s are generated by Automake. In
12092 some cases, however, projects need to embed subdirectories with
12093 handwritten @file{Makefile}s. For instance, one subdirectory could be
12094 a third-party project with its own build system, not using Automake.
12096 It is possible to list arbitrary directories in @code{SUBDIRS} or
12097 @code{DIST_SUBDIRS} provided each of these directories has a
12098 @file{Makefile} that recognizes all the following recursive targets.
12100 @cindex recursive targets and third-party @file{Makefile}s
12101 When a user runs one of these targets, that target is run recursively
12102 in all subdirectories. This is why it is important that even
12103 third-party @file{Makefile}s support them.
12107 Compile the entire package. This is the default target in
12108 Automake-generated @file{Makefile}s, but it does not need to be the
12109 default in third-party @file{Makefile}s.
12114 @vindex top_distdir
12115 Copy files to distribute into @samp{$(distdir)}, before a tarball is
12116 constructed. Of course this target is not required if the
12117 @option{no-dist} option (@pxref{Options}) is used.
12119 The variables @samp{$(top_distdir)} and @samp{$(distdir)}
12120 (@pxref{The dist Hook}) will be passed from the outer package to the subpackage
12121 when the @code{distdir} target is invoked. These two variables have
12122 been adjusted for the directory that is being recursed into, so they
12126 @itemx install-data
12127 @itemx install-exec
12129 Install or uninstall files (@pxref{Install}).
12132 @itemx install-html
12133 @itemx install-info
12136 Install only some specific documentation format (@pxref{Texinfo}).
12139 Create install directories, but do not install any files.
12142 @itemx installcheck
12143 Check the package (@pxref{Tests}).
12148 @itemx maintainer-clean
12149 Cleaning rules (@pxref{Clean}).
12156 Build the documentation in various formats (@pxref{Texinfo}).
12160 Build @file{TAGS} and @file{CTAGS} (@pxref{Tags}).
12163 If you have ever used Gettext in a project, this is a good example of
12164 how third-party @file{Makefile}s can be used with Automake. The
12165 @file{Makefile}s that @command{gettextize} puts in the @file{po/} and
12166 @file{intl/} directories are handwritten @file{Makefile}s that
12167 implement all of these targets. That way they can be added to
12168 @code{SUBDIRS} in Automake packages.
12170 Directories that are only listed in @code{DIST_SUBDIRS} but not in
12171 @code{SUBDIRS} need only the @code{distclean},
12172 @code{maintainer-clean}, and @code{distdir} rules (@pxref{Conditional
12175 Usually, many of these rules are irrelevant to the third-party
12176 subproject, but they are required for the whole package to work. It's
12177 OK to have a rule that does nothing, so if you are integrating a
12178 third-party project with no documentation or tag support, you could
12179 augment its @file{Makefile} as follows:
12181 @vindex EMPTY_AUTOMAKE_TARGETS
12182 @cindex Automake targets, no-op
12183 @cindex do-nothing Automake targets
12184 @cindex empty Automake targets
12185 @cindex no-op Automake targets
12186 @cindex targets, making into no-op
12188 EMPTY_AUTOMAKE_TARGETS = dvi pdf ps info html tags ctags
12189 .PHONY: $(EMPTY_AUTOMAKE_TARGETS)
12190 $(EMPTY_AUTOMAKE_TARGETS):
12193 To be clear, there is nothing special about the variable name
12194 @code{EMPTY_AUTOMAKE_TARGETS}; the name could be anything.
12196 Another aspect of integrating third-party build systems is whether
12197 they support VPATH builds (@pxref{VPATH Builds}). Obviously if the
12198 subpackage does not support VPATH builds the whole package will not
12199 support VPATH builds. This in turns means that @samp{make distcheck}
12200 will not work, because it relies on VPATH builds. Some people can
12201 live without this (indeed, many Automake users have never heard of
12202 @samp{make distcheck}). Other people may prefer to revamp the
12203 existing @file{Makefile}s to support VPATH@. Doing so does not
12204 necessarily require Automake; only Autoconf is needed (@pxref{Build
12205 Directories, , Build Directories, autoconf, The Autoconf Manual}).
12206 The necessary substitutions: @samp{@@srcdir@@}, @samp{@@top_srcdir@@},
12207 and @samp{@@top_builddir@@} are defined by @file{configure} when it
12208 processes a @file{Makefile} (@pxref{Preset Output Variables, , Preset
12209 Output Variables, autoconf, The Autoconf Manual}); they are not
12210 computed by the @file{Makefile} like the aforementioned @samp{$(distdir)} and
12211 @samp{$(top_distdir)} variables.
12213 It is sometimes inconvenient to modify a third-party @file{Makefile}
12214 to introduce the above required targets. For instance, one may want to
12215 keep the third-party sources untouched to ease upgrades to new
12218 @cindex @file{GNUmakefile} including @file{Makefile}
12219 Here are two other ideas. If GNU Make is assumed, one possibility is
12220 to add to that subdirectory a @file{GNUmakefile} that defines the
12221 required targets and includes the third-party @file{Makefile}. For
12222 this to work in VPATH builds, @file{GNUmakefile} must lie in the build
12223 directory; the easiest way to do this is to write a
12224 @file{GNUmakefile.in} instead, and have it processed with
12225 @code{AC_CONFIG_FILES} from the outer package. For example, if we
12226 assume @file{Makefile} defines all targets except the documentation
12227 targets, and that the real @code{check} target is named @code{test},
12228 we could write @file{GNUmakefile} (or @file{GNUmakefile.in}) like
12232 # First, include the real Makefile
12234 # Then, define the other targets needed by Automake Makefiles.
12235 .PHONY: dvi pdf ps info html check
12236 dvi pdf ps info html:
12240 @cindex Proxy @file{Makefile} for third-party packages
12241 A similar idea that does not use @code{include} is to write a proxy
12242 @file{Makefile} that dispatches rules to the real @file{Makefile},
12243 either with @samp{$(MAKE) -f Makefile.real $(AM_MAKEFLAGS) target} (if
12244 it's OK to rename the original @file{Makefile}) or with @samp{cd
12245 subdir && $(MAKE) $(AM_MAKEFLAGS) target} (if it's OK to store the
12246 subdirectory project one directory deeper). The good news is that
12247 this proxy @file{Makefile} can be generated with Automake. All we
12248 need are @option{-local} targets (@pxref{Extending}) that perform the
12249 dispatch. Of course the other Automake features are available, so you
12250 could decide to let Automake perform distribution or installation.
12251 Here is a possible @file{Makefile.am}:
12255 cd subdir && $(MAKE) $(AM_MAKEFLAGS) all
12257 cd subdir && $(MAKE) $(AM_MAKEFLAGS) test
12259 cd subdir && $(MAKE) $(AM_MAKEFLAGS) clean
12261 # Assuming the package knows how to install itself
12262 install-data-local:
12263 cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-data
12264 install-exec-local:
12265 cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-exec
12267 cd subdir && $(MAKE) $(AM_MAKEFLAGS) uninstall
12269 # Distribute files from here.
12270 EXTRA_DIST = subdir/Makefile subdir/program.c ...
12273 Pushing this idea to the extreme, it is also possible to ignore the
12274 subproject build system and build everything from this proxy
12275 @file{Makefile.am}. This might well be sensible if you need VPATH
12276 builds but the subproject does not support them.
12279 @chapter Distributing @file{Makefile.in}s
12281 Automake places no restrictions on the distribution of the resulting
12282 @file{Makefile.in}s. We encourage software authors to distribute
12283 their work under terms like those of the GPL, but doing so is not
12284 required to use Automake.
12286 Some of the files that can be automatically installed via the
12287 @option{--add-missing} switch do fall under the GPL@. However, these also
12288 have a special exception allowing you to distribute them with your
12289 package, regardless of the licensing you choose.
12292 @node API Versioning
12293 @chapter Automake API Versioning
12295 New Automake releases usually include bug fixes and new features.
12296 Unfortunately they may also introduce new bugs and incompatibility.
12297 This makes four reasons why a package may require a particular Automake
12300 Things get worse when maintaining a large tree of packages, each one
12301 requiring a different version of Automake. In the past, this meant that
12302 any developer (and sometimes users) had to install several versions of
12303 Automake in different places, and switch @samp{$PATH} appropriately for
12306 Starting with version 1.6, Automake installs versioned binaries. This
12307 means you can install several versions of Automake in the same
12308 @samp{$prefix}, and can select an arbitrary Automake version by running
12309 @command{automake-1.6} or @command{automake-1.7} without juggling with
12310 @samp{$PATH}. Furthermore, @file{Makefile}s generated by Automake 1.6
12311 will use @command{automake-1.6} explicitly in their rebuild rules.
12313 The number @samp{1.6} in @command{automake-1.6} is Automake's API version,
12314 not Automake's version. If a bug fix release is made, for instance
12315 Automake 1.6.1, the API version will remain 1.6. This means that a
12316 package that works with Automake 1.6 should also work with 1.6.1; after
12317 all, this is what people expect from bug fix releases.
12319 If your package relies on a feature or a bug fix introduced in
12320 a release, you can pass this version as an option to Automake to ensure
12321 older releases will not be used. For instance, use this in your
12322 @file{configure.ac}:
12325 AM_INIT_AUTOMAKE([1.6.1]) dnl Require Automake 1.6.1 or better.
12329 or, in a particular @file{Makefile.am}:
12332 AUTOMAKE_OPTIONS = 1.6.1 # Require Automake 1.6.1 or better.
12336 Automake will print an error message if its version is
12337 older than the requested version.
12340 @heading What is in the API
12342 Automake's programming interface is not easy to define. Basically it
12343 should include at least all @strong{documented} variables and targets
12344 that a @file{Makefile.am} author can use, any behavior associated with
12345 them (e.g., the places where @samp{-hook}'s are run), the command line
12346 interface of @command{automake} and @command{aclocal}, @dots{}
12348 @heading What is not in the API
12350 Every undocumented variable, target, or command line option is not part
12351 of the API@. You should avoid using them, as they could change from one
12352 version to the other (even in bug fix releases, if this helps to fix a
12355 If it turns out you need to use such an undocumented feature, contact
12356 @email{automake@@gnu.org} and try to get it documented and exercised by
12360 @chapter Upgrading a Package to a Newer Automake Version
12362 Automake maintains three kinds of files in a package.
12365 @item @file{aclocal.m4}
12366 @item @file{Makefile.in}s
12367 @item auxiliary tools like @file{install-sh} or @file{py-compile}
12370 @file{aclocal.m4} is generated by @command{aclocal} and contains some
12371 Automake-supplied M4 macros. Auxiliary tools are installed by
12372 @samp{automake --add-missing} when needed. @file{Makefile.in}s are
12373 built from @file{Makefile.am} by @command{automake}, and rely on the
12374 definitions of the M4 macros put in @file{aclocal.m4} as well as the
12375 behavior of the auxiliary tools installed.
12377 Because all of these files are closely related, it is important to
12378 regenerate all of them when upgrading to a newer Automake release.
12379 The usual way to do that is
12382 aclocal # with any option needed (such as -I m4)
12384 automake --add-missing --force-missing
12388 or more conveniently:
12394 The use of @option{--force-missing} ensures that auxiliary tools will be
12395 overridden by new versions (@pxref{automake Invocation}).
12397 It is important to regenerate all of these files each time Automake is
12398 upgraded, even between bug fix releases. For instance, it is not
12399 unusual for a bug fix to involve changes to both the rules generated
12400 in @file{Makefile.in} and the supporting M4 macros copied to
12403 Presently @command{automake} is able to diagnose situations where
12404 @file{aclocal.m4} has been generated with another version of
12405 @command{aclocal}. However it never checks whether auxiliary scripts
12406 are up-to-date. In other words, @command{automake} will tell you when
12407 @command{aclocal} needs to be rerun, but it will never diagnose a
12408 missing @option{--force-missing}.
12410 Before upgrading to a new major release, it is a good idea to read the
12411 file @file{NEWS}. This file lists all changes between releases: new
12412 features, obsolete constructs, known incompatibility, and
12416 @chapter Frequently Asked Questions about Automake
12418 This chapter covers some questions that often come up on the mailing
12422 * Version Control:: Version control and generated files
12423 * maintainer-mode:: missing and AM_MAINTAINER_MODE
12424 * Wildcards:: Why doesn't Automake support wildcards?
12425 * Limitations on File Names:: Limitations on source and installed file names
12426 * Flag Variables Ordering:: CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
12427 * Renamed Objects:: Why are object files sometimes renamed?
12428 * Per-Object Flags:: How to simulate per-object flags?
12429 * Multiple Outputs:: Writing rules for tools with many output files
12430 * Hard-Coded Install Paths:: Installing to hard-coded locations
12431 * Debugging Make Rules:: Strategies when things don't work as expected
12432 * Reporting Bugs:: Feedback on bugs and feature requests
12435 @node Version Control
12436 @section Version control and generated files
12438 @anchor{CVS}@c old name of node, keep for compatibility
12439 @subheading Background: distributed generated Files
12440 @cindex generated files, distributed
12441 @cindex rebuild rules
12443 Packages made with Autoconf and Automake ship with some generated
12444 files like @file{configure} or @file{Makefile.in}. These files were
12445 generated on the developer's machine and are distributed so that
12446 end-users do not have to install the maintainer tools required to
12447 rebuild them. Other generated files like Lex scanners, Yacc parsers,
12448 or Info documentation are usually distributed on similar grounds.
12450 Automake output generates rules in @file{Makefile}s to rebuild these
12451 files. For instance, @command{make} will run @command{autoconf} to
12452 rebuild @file{configure} whenever @file{configure.ac} is changed.
12453 This makes development safer by ensuring a @file{configure} is never
12454 out-of-date with respect to @file{configure.ac}.
12456 As generated files shipped in packages are up-to-date, and because
12457 @command{tar} preserves timestamps, these rebuild rules are not
12458 triggered when a user unpacks and builds a package.
12460 @subheading Background: Version Control and Timestamps
12461 @cindex timestamps and version control
12462 @cindex version control and timestamps
12464 Typically when you update files with version control commands, working
12465 files will have the timestamp of your update, not the original
12466 timestamp of the commit. This is meant to make sure that
12467 @command{make} notices that source files have been updated.
12469 This timestamp shift is troublesome when both sources and generated
12470 files are kept under version control. Because version control
12471 commands often process files in lexical order, @file{configure.ac}
12472 will appear newer than @file{configure} after a version control
12473 command that updates both files, even if @file{configure} was newer
12474 than @file{configure.ac} when it was committed. Calling
12475 @command{make} will then trigger a spurious rebuild of
12478 @subheading Living with Version Control in Autoconfiscated Projects
12479 @cindex version control and generated files
12480 @cindex generated files and version control
12482 There are basically two clans among maintainers: those who keep all
12483 distributed files under version control, including generated files, and
12484 those who keep generated files @emph{out} of version control.
12486 @subsubheading All Files under Version Control
12490 The repository contains all distributed files so you know exactly
12491 what is distributed, and you can check out any prior version entirely.
12494 Maintainers can see how generated files evolve (for instance, you can
12495 see what happens to your @file{Makefile.in}s when you upgrade Automake
12496 and make sure they look OK).
12499 Users do not need Autotools to build a check-out of the project; it
12500 works just like a released tarball.
12503 If users use version control to update their copy, timestamps will likely be
12504 inaccurate. Some rebuild rules will be triggered and attempt to
12505 run developer tools such as @command{autoconf} or @command{automake}.
12507 Calls to such tools are all wrapped into a call to the @command{missing}
12508 script discussed later (@pxref{maintainer-mode}), so that the user will
12509 see more descriptive warnings about missing or out-of-date tools, and
12510 possible suggestions about how to obtain them, rather than just some
12511 ``command not found'' error, or (worse) some obscure message from some
12512 older version of the required tool they happen to have installed.
12514 Maintainers interested in keeping their package buildable from a
12515 checkout even for those users that lack maintainer-specific tools might
12516 want to provide a helper script (or to enhance their existing bootstrap
12517 script) to fix the timestamps after a checkout, to prevent spurious
12518 rebuilds. In case of a project committing the Autotools-generated
12519 files, as well as the generated @file{.info} files, such a script might
12520 look something like this:
12524 # fix-timestamp.sh: Prevent useless rebuilds after "git pull".
12526 # aclocal-generated aclocal.m4 depends on locally-installed
12527 # '.m4' macro files, as well as on 'configure.ac'.
12530 # autoconf-generated 'configure' and autoheader-generated
12531 # config.h.in both depend on aclocal.m4 and on configure.ac.
12532 touch configure config.h.in
12533 # Automake-generated Makefile.in files depend on Makefile.am,
12534 # and makeinfo-generated '.info' files depend on the
12535 # corresponding '.texi' files.
12536 touch $(git ls-files '*/Makefile.in' '*.info')
12540 In distributed development, developers are likely to have different
12541 versions of the maintainer tools installed. In this case rebuilds
12542 triggered by clock skew can lead to spurious changes to generated
12543 files. There are several solutions to this:
12547 All developers should use the same versions, so that the rebuilt files
12548 are identical to files in the repository. (This becomes difficult
12549 when different projects on which you are working use different versions.)
12551 Or people use a script to fix the timestamp after a checkout (the GCC
12552 folks have such a script).
12554 Or @file{configure.ac} uses @code{AM_MAINTAINER_MODE}, which disables
12555 all of these rebuild rules by default. This is further discussed in
12556 @ref{maintainer-mode}.
12560 Although we focused on spurious rebuilds, the converse can also
12561 happen. Version control timestamp handling can also let you think an
12562 out-of-date file is up-to-date.
12564 For instance, suppose a developer has modified @file{Makefile.am} and
12565 has rebuilt @file{Makefile.in}, and then decides to do a last-minute
12566 change to @file{Makefile.am} right before checking in both files
12567 (without rebuilding @file{Makefile.in} to account for the change).
12569 This last change to @file{Makefile.am} makes the copy of
12570 @file{Makefile.in} out-of-date. Assuming version control processes
12571 files alphabetically, when another developer updates their tree,
12572 @file{Makefile.in} will happen to be newer than @file{Makefile.am}.
12573 This other developer will not see that @file{Makefile.in} is
12578 @subsubheading Generated Files out of Version Control
12580 One way to get version control and @command{make} working peacefully
12581 is to never store generated files in version control, i.e., do not
12582 version-control files that are @file{Makefile} targets (also called
12583 @emph{derived} files).
12585 This way developers are not annoyed by changes to generated files. It
12586 does not matter if they all have different versions (assuming they are
12587 compatible, of course). And finally, timestamps are not lost; changes
12588 to source files can't be missed as in the
12589 @file{Makefile.am}/@file{Makefile.in} example discussed earlier.
12591 The drawback is that the repository does not contain some files that
12592 are is distributed, so builders now need to install various
12593 development tools (maybe even specific versions) before they can build
12594 a checkout. But, after all, the job of version control is versioning,
12597 Allowing developers to use different versions of their tools can also
12598 hide bugs during distributed development. Indeed, developers will be
12599 using (hence testing) their own generated files, instead of the
12600 generated files that will be released. The developer who prepares the
12601 tarball might be using a version of the tool that produces bogus
12602 output (for instance a non-portable C file), something other
12603 developers could have noticed if they weren't using their own versions
12606 @subheading Third-party Files
12607 @cindex version control and third-party files
12608 @cindex third-party files and version control
12610 Another class of files not discussed here (because they do not cause
12611 timestamp issues) are files that are shipped with a package, but
12612 maintained elsewhere. For instance, tools like @command{gettextize}
12613 and @command{autopoint} (from Gettext) or @command{libtoolize} (from
12614 Libtool), will install or update files in your package.
12616 These files, whether they are kept under version control or not, raise
12617 similar concerns about version mismatch between developers' tools.
12618 The Gettext manual has a section about this; see @ref{Version Control
12619 Issues,, Integrating with Version Control Systems, gettext, GNU
12622 @node maintainer-mode
12623 @section @command{missing} and @code{AM_MAINTAINER_MODE}
12625 @subheading @command{missing}
12626 @cindex @command{missing}, purpose
12628 The @command{missing} script is a wrapper around several maintainer
12629 tools, designed to warn users if a maintainer tool is required but
12630 missing. Typical maintainer tools are @command{autoconf},
12631 @command{automake}, @command{bison}, etc. Because files generated by
12632 these tools are shipped with the other sources of a package, these
12633 tools shouldn't be required during a user build and they are not
12634 checked for in @file{configure}.
12636 However, if for some reason a rebuild rule is triggered and involves a
12637 missing tool, @command{missing} will notice it and warn the user, even
12638 suggesting how to obtain such a tool (at least in case it is a well-known
12639 one, like @command{makeinfo} or @command{bison}). This is more helpful
12640 and user-friendly than just having the rebuild rules spewing out a terse
12641 error message like @samp{sh: @var{tool}: command not found}. Similarly,
12642 @command{missing} will warn the user if it detects that a maintainer
12643 tool it attempted to use seems too old (be warned that diagnosing this
12644 correctly is typically more difficult than detecting missing tools, and
12645 requires cooperation from the tool itself, so it won't always work).
12647 If the required tool is installed, @command{missing} will run it and
12648 won't attempt to continue after failures. This is correct behavior during
12649 development: developers love fixing failures. However, users with
12650 missing or too old maintainer tools may get an error when the rebuild
12651 rule is spuriously triggered, halting the build. This failure to let
12652 the build continue is one of the arguments of the
12653 @code{AM_MAINTAINER_MODE} advocates.
12655 @subheading @code{AM_MAINTAINER_MODE}
12656 @cindex @code{AM_MAINTAINER_MODE}, purpose
12657 @acindex AM_MAINTAINER_MODE
12659 @code{AM_MAINTAINER_MODE} allows you to choose whether the so called
12660 "rebuild rules" should be enabled or disabled. With
12661 @code{AM_MAINTAINER_MODE([enable])}, they are enabled by default;
12662 otherwise they are disabled by default. In the latter case, if you
12663 have @code{AM_MAINTAINER_MODE} in @file{configure.ac}, and run
12664 @samp{./configure && make}, then @command{make} will *never* attempt
12665 to rebuild @file{configure}, @file{Makefile.in}s, Lex or Yacc outputs,
12666 etc. That is, this disables build rules for files that are usually
12667 distributed and that users should normally not have to update.
12669 The user can override the default setting by passing either
12670 @samp{--enable-maintainer-mode} or @samp{--disable-maintainer-mode}
12671 to @command{configure}.
12673 People use @code{AM_MAINTAINER_MODE} either because they do not want their
12674 users (or themselves) annoyed by clock skew (@pxref{Version Control}), or
12675 because they simply can't stand the rebuild rules and prefer running
12676 maintainer tools explicitly.
12678 @code{AM_MAINTAINER_MODE} also allows you to disable some custom build
12679 rules conditionally. Some developers use this feature to disable
12680 rules that need exotic tools that users may not have available.
12682 Several years ago Fran@,{c}ois Pinard pointed out several arguments
12683 against this @code{AM_MAINTAINER_MODE} macro. Most of them relate to
12684 insecurity. By removing dependencies you get non-dependable builds:
12685 changes to source files can have no effect on generated files and this
12686 can be very confusing when unnoticed. He adds that security shouldn't
12687 be reserved to maintainers (what @option{--enable-maintainer-mode}
12688 suggests), on the contrary. If one user has to modify a
12689 @file{Makefile.am}, then either @file{Makefile.in} should be updated
12690 or a warning should be output (this is what Automake uses
12691 @command{missing} for) but the last thing you want is that nothing
12692 happens and the user doesn't notice it (this is what happens when
12693 rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
12695 Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro, was
12696 swayed by Fran@,{c}ois' arguments, and got rid of
12697 @code{AM_MAINTAINER_MODE} in all of his packages.
12699 Still many people continue to use @code{AM_MAINTAINER_MODE}, because
12700 it helps them working on projects where all files are kept under version
12701 control, and because @command{missing} isn't enough if you have the
12702 wrong version of the tools.
12706 @section Why doesn't Automake support wildcards?
12709 Developers are lazy. They would often like to use wildcards in
12710 @file{Makefile.am}s, so that they would not need to remember to
12711 update @file{Makefile.am}s every time they add, delete, or rename
12714 There are several objections to this:
12717 When using version control, developers need to remember they have to
12718 add or remove files from version control anyway. Updating
12719 @file{Makefile.am} accordingly quickly becomes a reflex.
12721 Conversely, if your application doesn't compile
12722 because you forgot to add a file in @file{Makefile.am}, it will help
12723 you remember to add the file to version control.
12726 Using wildcards makes it easy to distribute files by mistake. For
12727 instance, some code a developer is experimenting with (a test case,
12728 say) that should not be part of the distribution.
12731 Using wildcards it's easy to omit some files by mistake. For
12732 instance, one developer creates a new file, uses it in many places,
12733 but forgets to commit it. Another developer then checks out the
12734 incomplete project and is able to run @samp{make dist} successfully,
12735 even though a file is missing. By listing files, @samp{make dist}
12736 @emph{will} complain.
12739 Wildcards are not portable to some non-GNU @command{make} implementations,
12740 e.g., NetBSD @command{make} will not expand globs such as @samp{*} in
12741 prerequisites of a target.
12744 Finally, it's quite hard to @emph{forget} to add a file to
12745 @file{Makefile.am}: files that are not listed in @file{Makefile.am}
12746 are not compiled or installed, so you can't even test them.
12749 Still, these are philosophical objections, and as such you may disagree,
12750 or find enough value in wildcards to dismiss all of them. Before you
12751 start writing a patch against Automake to teach it about wildcards,
12752 let's see the main technical issue: portability.
12754 Although @samp{$(wildcard ...)} works with GNU @command{make}, it is
12755 not portable to other @command{make} implementations.
12757 The only way Automake could support @command{$(wildcard ...)} is by
12758 expanding @command{$(wildcard ...)} when @command{automake} is run.
12759 The resulting @file{Makefile.in}s would be portable since they would
12760 list all files and not use @samp{$(wildcard ...)}. However that
12761 means developers would need to remember to run @command{automake} each
12762 time they add, delete, or rename files.
12764 Compared to editing @file{Makefile.am}, this is a very small gain. Sure,
12765 it's easier and faster to type @samp{automake; make} than to type
12766 @samp{emacs Makefile.am; make}. But nobody bothered enough to write a
12767 patch to add support for this syntax. Some people use scripts to
12768 generate file lists in @file{Makefile.am} or in separate
12769 @file{Makefile} fragments.
12771 Even if you don't care about portability, and are tempted to use
12772 @samp{$(wildcard ...)} anyway because you target only GNU Make, you
12773 should know there are many places where Automake needs to know exactly
12774 which files should be processed. As Automake doesn't know how to
12775 expand @samp{$(wildcard ...)}, you cannot use it in these places.
12776 @samp{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
12777 variables as far Automake is concerned.
12779 You can get warnings about @samp{$(wildcard ...}) constructs using the
12780 @option{-Wportability} flag.
12782 @node Limitations on File Names
12783 @section Limitations on File Names
12784 @cindex file names, limitations on
12786 Automake attempts to support all kinds of file names, even those that
12787 contain unusual characters or are unusually long. However, some
12788 limitations are imposed by the underlying operating system and tools.
12790 Most operating systems prohibit the use of the null byte in file
12791 names, and reserve @samp{/} as a directory separator. Also, they
12792 require that file names are properly encoded for the user's locale.
12793 Automake is subject to these limits.
12795 Portable packages should limit themselves to POSIX file
12796 names. These can contain ASCII letters and digits,
12797 @samp{_}, @samp{.}, and @samp{-}. File names consist of components
12798 separated by @samp{/}. File name components cannot begin with
12801 Portable POSIX file names cannot contain components that exceed a
12802 14-byte limit, but nowadays it's normally safe to assume the
12803 more-generous XOPEN limit of 255 bytes. POSIX
12804 limits file names to 255 bytes (XOPEN allows 1023 bytes),
12805 but you may want to limit a source tarball to file names of 99 bytes
12806 to avoid interoperability problems with old versions of @command{tar}.
12808 If you depart from these rules (e.g., by using non-ASCII
12809 characters in file names, or by using lengthy file names), your
12810 installers may have problems for reasons unrelated to Automake.
12811 However, if this does not concern you, you should know about the
12812 limitations imposed by Automake itself. These limitations are
12813 undesirable, but some of them seem to be inherent to underlying tools
12814 like Autoconf, Make, M4, and the shell. They fall into three
12815 categories: install directories, build directories, and file names.
12817 The following characters:
12820 @r{newline} " # $ ' `
12823 should not appear in the names of install directories. For example,
12824 the operand of @command{configure}'s @option{--prefix} option should
12825 not contain these characters.
12827 Build directories suffer the same limitations as install directories,
12828 and in addition should not contain the following characters:
12834 For example, the full name of the directory containing the source
12835 files should not contain these characters.
12837 Source and installation file names like @file{main.c} are limited even
12838 further: they should conform to the POSIX/XOPEN
12839 rules described above. In addition, if you plan to port to
12840 non-POSIX environments, you should avoid file names that
12841 differ only in case (e.g., @file{makefile} and @file{Makefile}).
12842 Nowadays it is no longer worth worrying about the 8.3 limits of
12845 @node Flag Variables Ordering
12846 @section Flag Variables Ordering
12847 @cindex Ordering flag variables
12848 @cindex Flag variables, ordering
12851 What is the difference between @code{AM_CFLAGS}, @code{CFLAGS}, and
12852 @code{mumble_CFLAGS}?
12856 Why does @command{automake} output @code{CPPFLAGS} after
12857 @code{AM_CPPFLAGS} on compile lines? Shouldn't it be the converse?
12861 My @file{configure} adds some warning flags into @code{CXXFLAGS}. In
12862 one @file{Makefile.am} I would like to append a new flag, however if I
12863 put the flag into @code{AM_CXXFLAGS} it is prepended to the other
12864 flags, not appended.
12867 @subheading Compile Flag Variables
12868 @cindex Flag Variables, Ordering
12869 @cindex Compile Flag Variables
12870 @cindex @code{AM_CCASFLAGS} and @code{CCASFLAGS}
12871 @cindex @code{AM_CFLAGS} and @code{CFLAGS}
12872 @cindex @code{AM_CPPFLAGS} and @code{CPPFLAGS}
12873 @cindex @code{AM_CXXFLAGS} and @code{CXXFLAGS}
12874 @cindex @code{AM_FCFLAGS} and @code{FCFLAGS}
12875 @cindex @code{AM_FFLAGS} and @code{FFLAGS}
12876 @cindex @code{AM_GCJFLAGS} and @code{GCJFLAGS}
12877 @cindex @code{AM_LDFLAGS} and @code{LDFLAGS}
12878 @cindex @code{AM_LFLAGS} and @code{LFLAGS}
12879 @cindex @code{AM_LIBTOOLFLAGS} and @code{LIBTOOLFLAGS}
12880 @cindex @code{AM_OBJCFLAGS} and @code{OBJCFLAGS}
12881 @cindex @code{AM_OBJCXXFLAGS} and @code{OBJXXCFLAGS}
12882 @cindex @code{AM_RFLAGS} and @code{RFLAGS}
12883 @cindex @code{AM_UPCFLAGS} and @code{UPCFLAGS}
12884 @cindex @code{AM_YFLAGS} and @code{YFLAGS}
12885 @cindex @code{CCASFLAGS} and @code{AM_CCASFLAGS}
12886 @cindex @code{CFLAGS} and @code{AM_CFLAGS}
12887 @cindex @code{CPPFLAGS} and @code{AM_CPPFLAGS}
12888 @cindex @code{CXXFLAGS} and @code{AM_CXXFLAGS}
12889 @cindex @code{FCFLAGS} and @code{AM_FCFLAGS}
12890 @cindex @code{FFLAGS} and @code{AM_FFLAGS}
12891 @cindex @code{GCJFLAGS} and @code{AM_GCJFLAGS}
12892 @cindex @code{LDFLAGS} and @code{AM_LDFLAGS}
12893 @cindex @code{LFLAGS} and @code{AM_LFLAGS}
12894 @cindex @code{LIBTOOLFLAGS} and @code{AM_LIBTOOLFLAGS}
12895 @cindex @code{OBJCFLAGS} and @code{AM_OBJCFLAGS}
12896 @cindex @code{OBJCXXFLAGS} and @code{AM_OBJCXXFLAGS}
12897 @cindex @code{RFLAGS} and @code{AM_RFLAGS}
12898 @cindex @code{UPCFLAGS} and @code{AM_UPCFLAGS}
12899 @cindex @code{YFLAGS} and @code{AM_YFLAGS}
12901 This section attempts to answer all the above questions. We will
12902 mostly discuss @code{CPPFLAGS} in our examples, but the answer holds
12903 for all the compile flags used in Automake: @code{CCASFLAGS},
12904 @code{CFLAGS}, @code{CPPFLAGS}, @code{CXXFLAGS}, @code{FCFLAGS},
12905 @code{FFLAGS}, @code{GCJFLAGS}, @code{LDFLAGS}, @code{LFLAGS},
12906 @code{LIBTOOLFLAGS}, @code{OBJCFLAGS}, @code{OBJCXXFLAGS},
12907 @code{RFLAGS}, @code{UPCFLAGS}, and @code{YFLAGS}.
12909 @code{CPPFLAGS}, @code{AM_CPPFLAGS}, and @code{mumble_CPPFLAGS} are
12910 three variables that can be used to pass flags to the C preprocessor (
12911 these variables are also used for other languages like C++ or
12912 preprocessed Fortran). @code{CPPFLAGS} is the user variable
12913 (@pxref{User Variables}), @code{AM_CPPFLAGS} is the Automake variable,
12914 and @code{mumble_CPPFLAGS} is the variable specific to the
12915 @code{mumble} target (we call this a per-target variable,
12916 @pxref{Program and Library Variables}).
12918 Automake always uses two of these variables when compiling C sources
12919 files. When compiling an object file for the @code{mumble} target,
12920 the first variable will be @code{mumble_CPPFLAGS} if it is defined, or
12921 @code{AM_CPPFLAGS} otherwise. The second variable is always
12924 In the following example,
12927 bin_PROGRAMS = foo bar
12928 foo_SOURCES = xyz.c
12929 bar_SOURCES = main.c
12930 foo_CPPFLAGS = -DFOO
12931 AM_CPPFLAGS = -DBAZ
12935 @file{xyz.o} will be compiled with @samp{$(foo_CPPFLAGS) $(CPPFLAGS)},
12936 (because @file{xyz.o} is part of the @code{foo} target), while
12937 @file{main.o} will be compiled with @samp{$(AM_CPPFLAGS) $(CPPFLAGS)}
12938 (because there is no per-target variable for target @code{bar}).
12940 The difference between @code{mumble_CPPFLAGS} and @code{AM_CPPFLAGS}
12941 being clear enough, let's focus on @code{CPPFLAGS}. @code{CPPFLAGS}
12942 is a user variable, i.e., a variable that users are entitled to modify
12943 in order to compile the package. This variable, like many others,
12944 is documented at the end of the output of @samp{configure --help}.
12946 For instance, someone who needs to add @file{/home/my/usr/include} to
12947 the C compiler's search path would configure a package with
12950 ./configure CPPFLAGS='-I /home/my/usr/include'
12954 and this flag would be propagated to the compile rules of all
12957 It is also not uncommon to override a user variable at
12958 @command{make}-time. Many installers do this with @code{prefix}, but
12959 this can be useful with compiler flags too. For instance, while
12960 debugging a C++ project, if you need to disable optimization in one
12961 specific object file, you can run something like
12965 make CXXFLAGS=-O0 file.o
12969 The reason @samp{$(CPPFLAGS)} appears after @samp{$(AM_CPPFLAGS)} or
12970 @samp{$(mumble_CPPFLAGS)} in the compile command is that users should
12971 have the last say. In the example above, the desire is for the
12972 @samp{CXXFLAGS=-O0} to supersede any other switch from
12973 @code{AM_CXXFLAGS} or @code{mumble_CXXFLAGS}.
12975 @c https://bugs.gnu.org/35526
12976 It's true that not all options to all programs can be overridden. So
12977 in general, users could conceivably want to place options at arbitrary
12978 places in the command line, but Automake does not support this. It
12979 would be difficult to make such generality comprehensible. Being able
12980 to specify the final options commonly suffices.
12982 Thus, you should never redefine a user variable such as
12983 @code{CPPFLAGS} in @file{Makefile.am}. Use @samp{automake -Woverride}
12984 to diagnose such mistakes. Even something like
12987 CPPFLAGS = -DDATADIR=\"$(datadir)\" @@CPPFLAGS@@
12991 is erroneous. Although this preserves @file{configure}'s value of
12992 @code{CPPFLAGS}, the definition of @code{DATADIR} will disappear if a
12993 user attempts to override @code{CPPFLAGS} from the @command{make}
12997 AM_CPPFLAGS = -DDATADIR=\"$(datadir)\"
13001 is all that is needed here if no per-target flags are used.
13003 You should not add options to these user variables within
13004 @file{configure} either, for the same reason. Occasionally you need
13005 to modify these variables to perform a test, but you should reset
13006 their values afterwards. In contrast, it is OK to modify the
13007 @samp{AM_} variables within @file{configure} if you @code{AC_SUBST}
13008 them, but it is rather rare that you need to do this, unless you want
13009 to change the default definitions of the @samp{AM_} variables in all
13012 What we recommend is that you define extra flags in separate
13013 variables. For instance, you may write an Autoconf macro that computes
13014 a set of warning options for the C compiler, and @code{AC_SUBST} them
13015 in @code{WARNINGCFLAGS}; you may also have an Autoconf macro that
13016 determines which compiler and which linker flags should be used to
13017 link with library @file{libfoo}, and @code{AC_SUBST} these in
13018 @code{LIBFOOCFLAGS} and @code{LIBFOOLDFLAGS}. Then, a
13019 @file{Makefile.am} could use these variables as follows:
13022 AM_CFLAGS = $(WARNINGCFLAGS)
13023 bin_PROGRAMS = prog1 prog2
13024 prog1_SOURCES = @dots{}
13025 prog2_SOURCES = @dots{}
13026 prog2_CFLAGS = $(LIBFOOCFLAGS) $(AM_CFLAGS)
13027 prog2_LDFLAGS = $(LIBFOOLDFLAGS)
13030 In this example both programs will be compiled with the flags
13031 substituted into @samp{$(WARNINGCFLAGS)}, and @code{prog2} will
13032 additionally be compiled with the flags required to link with
13035 Note that listing @code{AM_CFLAGS} in a per-target @code{CFLAGS}
13036 variable is a common idiom to ensure that @code{AM_CFLAGS} applies to
13037 every target in a @file{Makefile.in}.
13039 Using variables like this gives you full control over the ordering of
13040 the flags. For instance, if there is a flag in $(WARNINGCFLAGS) that
13041 you want to negate for a particular target, you can use something like
13042 @samp{prog1_CFLAGS = $(AM_CFLAGS) -no-flag}. If all of these flags had
13043 been forcefully appended to @code{CFLAGS}, there would be no way to
13044 disable one flag. Yet another reason to leave user variables to
13047 Finally, we have avoided naming the variable of the example
13048 @code{LIBFOO_LDFLAGS} (with an underscore) because that would cause
13049 Automake to think that this is a per-target variable (like
13050 @code{mumble_LDFLAGS}) for some non-declared @code{LIBFOO} target.
13052 @subheading Other Variables
13054 There are other variables in Automake that follow similar principles
13055 to allow user options. For instance, Texinfo rules (@pxref{Texinfo})
13056 use @code{MAKEINFOFLAGS} and @code{AM_MAKEINFOFLAGS}. Similarly,
13057 DejaGnu tests (@pxref{DejaGnu Tests}) use @code{RUNTESTFLAGS} and
13058 @code{AM_RUNTESTFLAGS}. The tags and ctags rules
13059 (@pxref{Tags}) use @code{ETAGSFLAGS}, @code{AM_ETAGSFLAGS},
13060 @code{CTAGSFLAGS}, and @code{AM_CTAGSFLAGS}. Java rules
13061 (@pxref{Java}) use @code{JAVACFLAGS} and @code{AM_JAVACFLAGS}. None
13062 of these rules support per-target flags (yet).
13064 To some extent, even @code{AM_MAKEFLAGS} (@pxref{Subdirectories})
13065 obeys this naming scheme. The slight difference is that
13066 @code{MAKEFLAGS} is passed to sub-@command{make}s implicitly by
13067 @command{make} itself.
13069 @code{ARFLAGS} (@pxref{A Library}) is usually defined by Automake and
13070 has neither an @code{AM_} nor a per-target cousin.
13072 Finally you should not think that the existence of a per-target
13073 variable implies the existence of an @code{AM_} variable or of a user
13074 variable. For instance, the @code{mumble_LDADD} per-target variable
13075 overrides the makefile-wide @code{LDADD} variable (which is not a user
13076 variable), and @code{mumble_LIBADD} exists only as a per-target
13077 variable. @xref{Program and Library Variables}.
13080 @node Renamed Objects
13081 @section Why are object files sometimes renamed?
13083 This happens when per-target compilation flags are used. Object
13084 files need to be renamed just in case they would clash with object
13085 files compiled from the same sources, but with different flags.
13086 Consider the following example.
13089 bin_PROGRAMS = true false
13090 true_SOURCES = generic.c
13091 true_CPPFLAGS = -DEXIT_CODE=0
13092 false_SOURCES = generic.c
13093 false_CPPFLAGS = -DEXIT_CODE=1
13097 Obviously the two programs are built from the same source, but it
13098 would be bad if they shared the same object, because @file{generic.o}
13099 cannot be built with both @samp{-DEXIT_CODE=0} @emph{and}
13100 @samp{-DEXIT_CODE=1}. Therefore @command{automake} outputs rules to
13101 build two different objects: @file{true-generic.o} and
13102 @file{false-generic.o}.
13104 Automake doesn't actually determine whether source files are shared to
13105 decide if it must rename objects. It just renames all objects of a
13106 target as soon as it sees that per-target compilation flags are used.
13108 It's OK to share object files when per-target compilation flags are not
13109 used. For instance, @file{true} and @file{false} will both use
13110 @file{version.o} in the following example.
13113 AM_CPPFLAGS = -DVERSION=1.0
13114 bin_PROGRAMS = true false
13115 true_SOURCES = true.c version.c
13116 false_SOURCES = false.c version.c
13119 Note that the renaming of objects is also affected by the
13120 @code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
13123 @node Per-Object Flags
13124 @section Per-Object Flags Emulation
13125 @cindex Per-object flags, emulated
13128 One of my source files needs to be compiled with different flags. How
13132 Automake supports per-program and per-library compilation flags (see
13133 @ref{Program and Library Variables} and @ref{Flag Variables
13134 Ordering}). With this you can define compilation flags that apply to
13135 all files compiled for a target. For instance, in
13139 foo_SOURCES = foo.c foo.h bar.c bar.h main.c
13140 foo_CFLAGS = -some -flags
13144 @file{foo-foo.o}, @file{foo-bar.o}, and @file{foo-main.o} will all be
13145 compiled with @samp{-some -flags}. (If you wonder about the names of
13146 these object files, see @ref{Renamed Objects}.) Note that
13147 @code{foo_CFLAGS} gives the flags to use when compiling all the C
13148 sources of the @emph{program} @code{foo}; it has nothing to do with
13149 @file{foo.c} or @file{foo-foo.o} specifically.
13151 What if @file{foo.c} needs to be compiled into @file{foo.o} using some
13152 specific flags, that none of the other files requires? Obviously
13153 per-program flags are not directly applicable here. Something like
13154 per-object flags are expected, i.e., flags that would be used only
13155 when creating @file{foo-foo.o}. Automake does not support that;
13156 however this is easy to simulate using a library that contains only
13157 that object, and compiling this library with per-library flags.
13161 foo_SOURCES = bar.c bar.h main.c
13162 foo_CFLAGS = -some -flags
13163 foo_LDADD = libfoo.a
13164 noinst_LIBRARIES = libfoo.a
13165 libfoo_a_SOURCES = foo.c foo.h
13166 libfoo_a_CFLAGS = -some -other -flags
13169 Here @file{foo-bar.o} and @file{foo-main.o} will all be
13170 compiled with @samp{-some -flags}, while @file{libfoo_a-foo.o} will
13171 be compiled using @samp{-some -other -flags}. Eventually, all
13172 three objects will be linked to form @file{foo}.
13174 This trick can also be achieved using Libtool convenience libraries,
13175 for instance @samp{noinst_LTLIBRARIES = libfoo.la} (@pxref{Libtool
13176 Convenience Libraries}).
13178 Another tempting idea to implement per-object flags is to override the
13179 compile rules @command{automake} would output for these files.
13180 Automake will not define a rule for a target you have defined, so you
13181 could think about defining the @samp{foo-foo.o: foo.c} rule yourself.
13182 We recommend against this, because this is error prone. For instance,
13183 if you add such a rule to the first example, it will break the day you
13184 decide to remove @code{foo_CFLAGS} (because @file{foo.c} will then be
13185 compiled as @file{foo.o} instead of @file{foo-foo.o}, @pxref{Renamed
13186 Objects}). Also in order to support dependency tracking, the two
13187 @file{.o}/@file{.obj} extensions, and all the other flags variables
13188 involved in a compilation, you will end up modifying a copy of the
13189 rule previously output by @command{automake} for this file. If a new
13190 release of Automake generates a different rule, your copy will need to
13191 be updated by hand.
13193 @node Multiple Outputs
13194 @section Handling Tools that Produce Many Outputs
13195 @cindex multiple outputs, rules with
13196 @cindex many outputs, rules with
13197 @cindex rules with multiple outputs
13199 This section describes a @command{make} idiom that can be used when a
13200 tool produces multiple output files. It is not specific to Automake
13201 and can be used in ordinary @file{Makefile}s.
13203 First, however: GNU @command{make} is able to express rules with
13204 multiple output files using pattern rules (@pxref{Pattern Examples, ,
13205 Pattern Rule Examples, make, The GNU Make Manual}). We do not discuss
13206 pattern rules here because they are not portable, but if you're able
13207 to assume GNU @command{make}, they are typically more convenient than
13208 any of the below approaches.
13210 Suppose we have a program called @command{foo} that will read one file
13211 called @file{data.foo} and produce two files named @file{data.c} and
13212 @file{data.h}. We want to write a @file{Makefile} rule that captures
13213 this one-to-two dependency.
13215 The naive rule is incorrect:
13218 # This is incorrect.
13219 data.c data.h: data.foo
13224 What the above rule says is that @file{data.c} and @file{data.h} each
13225 depend on @file{data.foo}, and can each be built by running @samp{foo
13226 data.foo}. In other words it is equivalent to:
13229 # We do not want this.
13237 which means that @command{foo} can be run twice. Usually it will not
13238 be run twice, because @command{make} implementations are smart enough
13239 to check for the existence of the second file after the first one has
13240 been built; they will therefore detect that it already exists.
13241 However there are a few situations where it can run twice anyway:
13245 The most worrying case is when running a parallel @command{make}. If
13246 @file{data.c} and @file{data.h} are built in parallel, two @samp{foo
13247 data.foo} commands will run concurrently. This is harmful.
13249 Another case is when the dependency (here @file{data.foo}) is
13250 (or depends upon) a phony target.
13253 Ideally, we want a scheme that will support any number of output
13254 files, and that works with parallel @command{make} invocations, and
13255 that does nothing when @samp{make -n} is run. It is apparently not
13256 possible to achieve a perfect solution. Even an acceptable solution
13257 for the majority of cases gets complicated, so we will take it step by
13260 One idea is to write the following:
13263 # There is still a problem with this one.
13270 The idea is that @samp{foo data.foo} is run only when @file{data.c}
13271 needs to be updated, but we further state that @file{data.h} depends
13272 upon @file{data.c}. That way, if @file{data.h} is required and
13273 @file{data.foo} is out of date, the dependency on @file{data.c} will
13276 This is almost perfect, but suppose we have built @file{data.h} and
13277 @file{data.c}, and then we erase @file{data.h}. Then, running
13278 @samp{make data.h} will not rebuild @file{data.h}. The above rules
13279 just state that @file{data.c} must be up-to-date with respect to
13280 @file{data.foo}, and this is already the case.
13282 What we need is a rule that forces a rebuild when @file{data.h} is
13283 missing. Here it is:
13286 # More or less works, but not easy to generalize.
13290 ## Recover from the removal of $@@
13291 @@test -f $@@ || rm -f data.c
13292 @@test -f $@@ || $(MAKE) $(AM_MAKEFLAGS) data.c
13295 It is tempting to use a single test as follows:
13298 # This breaks make -n.
13300 ## Recover from the removal of $@@
13301 @@if test -f $@@; then :; else \
13303 $(MAKE) $(AM_MAKEFLAGS) data.c; \
13308 but that would break @samp{make -n}: at least GNU @command{make} and
13309 Solaris @command{make} execute recipes containing the @samp{$(MAKE)}
13310 string even when they are running in dry mode. So if we didn't break
13311 the recipe above in two invocations, the file @file{data.c} would be
13312 removed even upon @samp{make -n}. Not nice.
13315 The above scheme can be extended to handle more outputs and more
13316 inputs. One of the outputs is selected to serve as a witness to the
13317 successful completion of the command, it depends upon all inputs, and
13318 all other outputs depend upon it. For instance, if @command{foo}
13319 should additionally read @file{data.bar} and also produce
13320 @file{data.w} and @file{data.x}, we would write:
13323 data.c: data.foo data.bar
13324 foo data.foo data.bar
13325 data.h data.w data.x: data.c
13326 ## Recover from the removal of $@@
13327 @@test -f $@@ || rm -f data.c
13328 @@test -f $@@ || $(MAKE) $(AM_MAKEFLAGS) data.c
13331 However there are now three problems in this setup. One is related to
13332 the timestamp ordering of @file{data.h}, @file{data.w}, @file{data.x},
13333 and @file{data.c}. A second is a race condition if a parallel
13334 @command{make} attempts to run multiple instances of the recover block
13335 at once. Finally, the recursive rule breaks @samp{make -n} when run
13336 with GNU @command{make} (as well as some other @command{make}
13337 implementations), as it may remove @file{data.h} even when it should
13338 not (@pxref{MAKE Variable, , How the @code{MAKE} Variable Works, make,
13339 The GNU Make Manual}).
13341 Let us deal with the first problem. @command{foo} outputs four files,
13342 but we do not know in which order these files are created. Suppose
13343 that @file{data.h} is created before @file{data.c}. Then we have a
13344 weird situation. The next time @command{make} is run, @file{data.h}
13345 will appear older than @file{data.c}, the second rule will be
13346 triggered, a shell will be started to execute the @samp{if@dots{}fi}
13347 command, but it will just execute the @code{then} branch, that is:
13348 nothing. In other words, because the witness we selected is not the
13349 first file created by @command{foo}, @command{make} will start a shell
13350 to do nothing each time it is run.
13352 A simple riposte is to fix the timestamps when this happens.
13355 data.c: data.foo data.bar
13356 foo data.foo data.bar
13357 data.h data.w data.x: data.c
13358 @@test ! -f $@@ || touch $@@
13359 ## Recover from the removal of $@@
13360 @@test -f $@@ || rm -f data.c
13361 @@test -f $@@ || $(MAKE) $(AM_MAKEFLAGS) data.c
13364 Another solution is to use a different and dedicated file as witness,
13365 rather than using any of @command{foo}'s outputs.
13368 data.stamp: data.foo data.bar
13371 foo data.foo data.bar
13372 @@mv -f data.tmp $@@
13373 data.c data.h data.w data.x: data.stamp
13374 ## Recover from the removal of $@@
13375 @@test -f $@@ || rm -f data.stamp
13376 @@test -f $@@ || $(MAKE) $(AM_MAKEFLAGS) data.stamp
13379 @file{data.tmp} is created before @command{foo} is run, so it has a
13380 timestamp older than output files output by @command{foo}. It is then
13381 renamed to @file{data.stamp} after @command{foo} has run, because we
13382 do not want to update @file{data.stamp} if @command{foo} fails.
13384 This solution still suffers from the second problem: the race
13385 condition in the recover rule. If, after a successful build, a user
13386 erases @file{data.c} and @file{data.h}, and runs @samp{make -j}, then
13387 @command{make} may start both recover rules in parallel. If the two
13388 instances of the rule execute @samp{$(MAKE) $(AM_MAKEFLAGS)
13389 data.stamp} concurrently the build is likely to fail (for instance, the
13390 two rules will create @file{data.tmp}, but only one can rename it).
13392 Admittedly, such a weird situation does not arise during ordinary
13393 builds. It occurs only when the build tree is mutilated. Here
13394 @file{data.c} and @file{data.h} have been explicitly removed without
13395 also removing @file{data.stamp} and the other output files.
13396 @code{make clean; make} will always recover from these situations even
13397 with parallel makes, so you may decide that the recover rule is solely
13398 to help non-parallel make users and leave things as-is. Fixing this
13399 requires some locking mechanism to ensure only one instance of the
13400 recover rule rebuilds @file{data.stamp}. One could imagine something
13401 along the following lines.
13404 data.c data.h data.w data.x: data.stamp
13405 ## Recover from the removal of $@@
13406 @@if test -f $@@; then :; else \
13407 trap 'rm -rf data.lock data.stamp' 1 2 13 15; \
13408 ## mkdir is a portable test-and-set
13409 if mkdir data.lock 2>/dev/null; then \
13410 ## This code is being executed by the first process.
13411 rm -f data.stamp; \
13412 $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
13413 result=$$?; rm -rf data.lock; exit $$result; \
13415 ## This code is being executed by the follower processes.
13416 ## Wait until the first process is done.
13417 while test -d data.lock; do sleep 1; done; \
13418 ## Succeed if and only if the first process succeeded.
13419 test -f data.stamp; \
13424 Using a dedicated witness, like @file{data.stamp}, is very handy when
13425 the list of output files is not known beforehand. As an illustration,
13426 consider the following rules to compile many @file{*.el} files into
13427 @file{*.elc} files in a single command. It does not matter how
13428 @code{ELFILES} is defined (as long as it is not empty: empty targets
13429 are not accepted by POSIX).
13432 ELFILES = one.el two.el three.el @dots{}
13433 ELCFILES = $(ELFILES:=c)
13435 elc-stamp: $(ELFILES)
13438 $(elisp_comp) $(ELFILES)
13439 @@mv -f elc-temp $@@
13441 $(ELCFILES): elc-stamp
13442 @@if test -f $@@; then :; else \
13443 ## Recover from the removal of $@@
13444 trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
13445 if mkdir elc-lock 2>/dev/null; then \
13446 ## This code is being executed by the first process.
13448 $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
13451 ## This code is being executed by the follower processes.
13452 ## Wait until the first process is done.
13453 while test -d elc-lock; do sleep 1; done; \
13454 ## Succeed if and only if the first process succeeded.
13455 test -f elc-stamp; exit $$?; \
13461 These solutions all still suffer from the third problem, namely that
13462 they break the promise that @samp{make -n} should not cause any actual
13463 changes to the tree. For those solutions that do not create lock files,
13464 it is possible to split the recover rules into two separate recipe
13465 commands, one of which does all work but the recursion, and the
13466 other invokes the recursive @samp{$(MAKE)}. The solutions involving
13467 locking could act upon the contents of the @samp{MAKEFLAGS} variable,
13468 but parsing that portably is not easy (@pxref{The Make Macro MAKEFLAGS,,,
13469 autoconf, The Autoconf Manual}). Here is an example:
13472 ELFILES = one.el two.el three.el @dots{}
13473 ELCFILES = $(ELFILES:=c)
13475 elc-stamp: $(ELFILES)
13478 $(elisp_comp) $(ELFILES)
13479 @@mv -f elc-temp $@@
13481 $(ELCFILES): elc-stamp
13482 ## Recover from the removal of $@@
13483 @@dry=; for f in x $$MAKEFLAGS; do \
13489 if test -f $@@; then :; else \
13490 $$dry trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
13491 if $$dry mkdir elc-lock 2>/dev/null; then \
13492 ## This code is being executed by the first process.
13493 $$dry rm -f elc-stamp; \
13494 $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
13495 $$dry rmdir elc-lock; \
13497 ## This code is being executed by the follower processes.
13498 ## Wait until the first process is done.
13499 while test -d elc-lock && test -z "$$dry"; do \
13503 ## Succeed if and only if the first process succeeded.
13504 $$dry test -f elc-stamp; exit $$?; \
13510 @node Hard-Coded Install Paths
13511 @section Installing to Hard-Coded Locations
13514 My package needs to install some configuration file. I tried to use
13515 the following rule, but @samp{make distcheck} fails. Why?
13519 install-data-local:
13520 $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
13525 My package needs to populate the installation directory of another
13526 package at install-time. I can easily compute that installation
13527 directory in @file{configure}, but if I install files therein,
13528 @samp{make distcheck} fails. How else should I do it?
13531 These two setups share their symptoms: @samp{make distcheck} fails
13532 because they are installing files to hard-coded paths. In the latter
13533 case the path is not hard-coded in the package, but we can consider it
13534 to be hard-coded in the system (or in whichever tool that supplies the
13535 path). As long as the path does not use any of the standard directory
13536 variables (@samp{$(prefix)}, @samp{$(bindir)}, @samp{$(datadir)},
13537 etc.), the effect will be the same: user-installations are impossible.
13539 As a (non-root) user who wants to install a package, you usually have no
13540 right to install anything in @file{/usr} or @file{/usr/local}. So you
13541 do something like @samp{./configure --prefix ~/usr} to install a
13542 package in your own @file{~/usr} tree.
13544 If a package attempts to install something to some hard-coded path
13545 (e.g., @file{/etc/afile}), regardless of this @option{--prefix} setting,
13546 then the installation will fail. @samp{make distcheck} performs such
13547 a @option{--prefix} installation, hence it will fail too.
13549 Now, there are some easy solutions.
13551 The above @code{install-data-local} example for installing
13552 @file{/etc/afile} would be better replaced by
13555 sysconf_DATA = afile
13559 By default @code{sysconfdir} will be @samp{$(prefix)/etc}, because
13560 this is what the GNU Standards require. When such a package is
13561 installed on an FHS compliant system, the installer will have to set
13562 @samp{--sysconfdir=/etc}. As the maintainer of the package you
13563 should not be concerned by such site policies: use the appropriate
13564 standard directory variable to install your files so that the installer
13565 can easily redefine these variables to match their site conventions.
13567 Installing files that should be used by another package is slightly
13568 more involved. Let's take an example and assume you want to install
13569 a shared library that is a Python extension module. If you ask Python
13570 where to install the library, it will answer something like this:
13573 % @kbd{python -c 'from distutils import sysconfig;
13574 print sysconfig.get_python_lib(1,0)'}
13575 /usr/lib/python2.5/site-packages
13578 If you indeed use this absolute path to install your shared library,
13579 non-root users will not be able to install the package; hence
13582 Let's do better. The @samp{sysconfig.get_python_lib()} function
13583 accepts a third argument that will replace Python's installation
13587 % @kbd{python -c 'from distutils import sysconfig;
13588 print sysconfig.get_python_lib(1,0,"$@{exec_prefix@}")'}
13589 $@{exec_prefix@}/lib/python2.5/site-packages
13592 You can also use this new path. If you do
13595 root users can install your package with the same @option{--prefix}
13596 as Python (you get the behavior of the previous attempt)
13599 non-root users can install your package too; they will have the
13600 extension module in a place that is not searched by Python but they
13601 can work around this using environment variables (and if you installed
13602 scripts that use this shared library, it's easy to tell Python where to
13603 look in the beginning of your script, so the script works in both
13607 The @code{AM_PATH_PYTHON} macro uses similar commands to define
13608 @samp{$(pythondir)} and @samp{$(pyexecdir)} (@pxref{Python}).
13610 Of course not all tools are as advanced as Python regarding that
13611 substitution of @var{prefix}. So another strategy is to figure out the
13612 part of the installation directory that must be preserved. For
13613 instance, here is how @code{AM_PATH_LISPDIR} (@pxref{Emacs Lisp})
13614 computes @samp{$(lispdir)}:
13617 $EMACS -batch -no-site-file -eval '(while load-path
13618 (princ (concat (car load-path) "\n"))
13619 (setq load-path (cdr load-path)))' >conftest.out
13622 -e '/.*\/lib\/x*emacs\/site-lisp$/@{
13623 s,.*/lib/\(x*emacs/site-lisp\)$,$@{libdir@}/\1,;p;q;
13625 -e '/.*\/share\/x*emacs\/site-lisp$/@{
13626 s,.*/share/\(x*emacs/site-lisp\),$@{datarootdir@}/\1,;p;q;
13631 That is, it just picks the first directory that looks like
13632 @file{*/lib/*emacs/site-lisp} or @file{*/share/*emacs/site-lisp} in
13633 the search path of emacs, and then substitutes @samp{$@{libdir@}} or
13634 @samp{$@{datadir@}} appropriately.
13636 The emacs case looks complicated because it processes a list and
13637 expects two possible layouts; otherwise it's easy, and the benefits
13638 for non-root users are worth the extra @command{sed} invocation.
13641 @node Debugging Make Rules
13642 @section Debugging Make Rules
13643 @cindex debugging rules
13644 @cindex rules, debugging
13646 The rules and dependency trees generated by @command{automake} can get
13647 rather complex, and leave the developer head-scratching when things
13648 don't work as expected. Besides the debug options provided by the
13649 @command{make} command (@pxref{Options Summary,,, make, The GNU Make
13650 Manual}), here's a couple of further hints for debugging makefiles
13651 generated by @command{automake} effectively:
13655 If less verbose output has been enabled in the package with the use
13656 of silent rules (@pxref{Automake Silent Rules}), you can use
13657 @code{make V=1} to see the commands being executed.
13660 @code{make -n} can help show what would be done without actually doing
13661 it. However, this @emph{still executes} commands prefixed with
13662 @samp{+}, and, when using GNU @command{make}, commands that contain
13663 the strings @samp{$(MAKE)} or @samp{$@{MAKE@}} (@pxref{Instead of
13664 Execution,,, make, The GNU Make Manual}). Typically, this is helpful
13665 to show what recursive rules would do, but it means that, in your own
13666 rules, you should not mix such recursion with actions that change any
13667 files.@footnote{Automake's @samp{dist} and @samp{distcheck} rules had
13668 a bug in this regard in that they created directories even with
13669 @option{-n}, but this has been fixed in Automake 1.11.} Furthermore,
13670 note that GNU @command{make} will update prerequisites for the
13671 @file{Makefile} file itself even with @option{-n} (@pxref{Remaking
13672 Makefiles,,, make, The GNU Make Manual}).
13675 @code{make SHELL="/bin/bash -vx"} can help debug complex rules.
13676 @xref{The Make Macro SHELL,,, autoconf, The Autoconf Manual}, for some
13677 portability quirks associated with this construct.
13680 @code{echo 'print: ; @@echo "$(VAR)"' | make -f Makefile -f - print}
13681 can be handy to examine the expanded value of variables. You may need
13682 to use a target other than @samp{print} if that is already used or a
13683 file with that name exists.
13686 @url{http://bashdb.sourceforge.net/@/remake/} provides a modified
13687 GNU @command{make} command called @command{remake} that copes with
13688 complex GNU @command{make}-specific Makefiles and allows tracing
13689 execution, examining variables, and calling rules interactively, much like
13694 @node Reporting Bugs
13695 @section Reporting Bugs
13697 @cindex Bugs, reporting
13698 @cindex Reporting bugs
13700 Most nontrivial software has bugs. Automake is no exception. We
13701 cannot promise we can or will fix a bug, and we might not even agree
13702 that it is a bug, but we want to hear about problems you
13703 encounter. Often we agree they are bugs and want to fix them.
13705 So, to make it possible for us to fix a bug, please report it.
13706 If you can, though, it is helpful if you check if it is already known.
13707 You can look at the @uref{https://debbugs.gnu.org/, GNU Bug Tracker}
13708 and the @uref{https://lists.gnu.org/@/archive/@/html/@/bug-automake/,
13709 bug-automake mailing list archives} for previous bug reports. (We
13710 previously used a Gnats database for bug tracking, but it is no longer
13713 If the bug is not already known, it should be reported. To report
13714 bugs in a way that is useful and efficient, please read
13715 @uref{https://www.chiark.greenend.org.uk/@/~sgtatham/@/bugs.html, How
13716 to Report Bugs Effectively} and
13717 @uref{http://catb.org/@/~esr/@/faqs/@/smart-questions.html, How to Ask
13718 Questions the Smart Way}. Good bug reports save time for everyone.
13720 For a bug report, a feature request or other suggestions, please send
13721 email to @email{@value{PACKAGE_BUGREPORT}}. This will then open a new
13722 bug in the @uref{https://debbugs.gnu.org/@/automake, bug tracker}. Be
13723 sure to include the versions of Autoconf and Automake that you use and
13724 the kind of system you're on. Ideally, post a minimal
13725 @file{Makefile.am} and @file{configure.ac} that reproduces the problem
13726 you encounter. If you have encountered test suite failures, please
13727 attach the @file{test-suite.log} file.
13729 @c ========================================================== Appendices
13732 @node Copying This Manual
13733 @appendix Copying This Manual
13736 * GNU Free Documentation License:: License for copying this manual
13739 @node GNU Free Documentation License
13740 @appendixsec GNU Free Documentation License
13748 * Macro Index:: Index of Autoconf macros
13749 * Variable Index:: Index of Makefile variables
13750 * General Index:: General index
13754 @appendixsec Macro Index
13758 @node Variable Index
13759 @appendixsec Variable Index
13763 @node General Index
13764 @appendixsec General Index
13771 @c LocalWords: texinfo setfilename settitle setchapternewpage texi direntry
13772 @c LocalWords: dircategory in's aclocal ifinfo titlepage Tromey vskip pt sp
13773 @c LocalWords: filll defcodeindex ov cv op tr syncodeindex fn cp vr ifnottex
13774 @c LocalWords: dir Automake's ac Dist Gnits gnits dfn Autoconf's pxref
13775 @c LocalWords: cindex Autoconf autoconf perl samp dist trindex SUBST foo
13776 @c LocalWords: xs emph FIXME ref vindex pkglibdir pkgincludedir pkgdatadir mt
13777 @c LocalWords: pkg libdir cpio bindir sbindir rmt pax sbin zar zardir acindex
13778 @c LocalWords: HTML htmldir html noinst TEXINFOS nodist nobase strudel CFLAGS
13779 @c LocalWords: libmumble CC YFLAGS itemx de fication config url comp
13780 @c LocalWords: depcomp elisp sh mdate mkinstalldirs mkdir py tex dvi ps pdf
13781 @c LocalWords: ylwrap zardoz INIT gettext acinclude mv FUNCS LIBOBJS LDADD fr
13782 @c LocalWords: uref featureful dnl src LINGUAS es ko nl pl sl sv PROG ISC doc
13783 @c LocalWords: POSIX STDC fcntl FUNC ALLOCA blksize struct stat intl po chmod
13784 @c LocalWords: ChangeLog SUBDIRS gettextize gpl testdata getopt INTLLIBS cpp
13785 @c LocalWords: localedir datadir DLOCALEDIR DEXIT CPPFLAGS autoreconf opindex
13786 @c LocalWords: AUX var symlink deps Wno Wnone package's aclocal's distclean
13787 @c LocalWords: ltmain xref LIBSOURCE LIBSOURCES LIBOBJ MEMCMP vs RANLIB CXX
13788 @c LocalWords: LDFLAGS LIBTOOL libtool XTRA LIBS gettext's acdir APIVERSION
13789 @c LocalWords: dirlist noindent usr TIOCGWINSZ sc
13790 @c LocalWords: GWINSZ termios SRCDIR tarball bzip LISPDIR lispdir XEmacs CCAS
13791 @c LocalWords: emacsen MicroEmacs CCASFLAGS UX GCJ gcj GCJFLAGS posix DMALLOC
13792 @c LocalWords: dmalloc ldmalloc REGEX regex DEPDIR DEP DEFUN aclocaldir fi
13793 @c LocalWords: mymacro myothermacro AMFLAGS autopoint autogen libtoolize yum
13794 @c LocalWords: autoheader README MAKEFLAGS subdir Inetutils sync COND endif
13795 @c LocalWords: Miller's installable includedir inc pkgdata EXEEXT libexec bsd
13796 @c LocalWords: pkglib libexecdir prog libcpio cpio's dlopen dlpreopen linux
13797 @c LocalWords: subsubsection OBJEXT esac lib LTLIBRARIES liblob LIBADD AR ar
13798 @c LocalWords: ARFLAGS cr ing maude libgettext lo LTLIBOBJS rpath SGI PRE yy
13799 @c LocalWords: libmaude CCLD CXXFLAGS FFLAGS LFLAGS OBJCFLAGS RFLAGS DEFS cc
13800 @c LocalWords: OBJCXXFLAGS
13801 @c LocalWords: SHORTNAME vtable srcdir nostdinc basename yxx cxx ll lxx gdb
13802 @c LocalWords: lexers yymaxdepth maxdepth yyparse yylex yyerror yylval lval
13803 @c LocalWords: yychar yydebug yypact yyr yydef def yychk chk yypgo pgo yyact
13804 @c LocalWords: yyexca exca yyerrflag errflag yynerrs nerrs yyps yypv pv yys
13805 @c LocalWords: yystate yytmp tmp yyv yyval val yylloc lloc yyreds yytoks toks
13806 @c LocalWords: yylhs yylen yydefred yydgoto yysindex yyrindex yygindex yyname
13807 @c LocalWords: yytable yycheck yyrule byacc CXXCOMPILE CXXLINK FLINK cfortran
13808 @c LocalWords: Catalogue preprocessable FLIBS libfoo baz JAVACFLAGS java exe
13809 @c LocalWords: SunOS basenames exeext uninstalled oldinclude kr FSF's
13810 @c LocalWords: pkginclude oldincludedir sysconf sharedstate localstate gcc rm
13811 @c LocalWords: sysconfdir sharedstatedir localstatedir preexist CLEANFILES gz
13812 @c LocalWords: depfile tmpdepfile depmode const interoperate
13813 @c LocalWords: JAVAC javac JAVAROOT builddir CLASSPATH ENV pyc pyo pkgpython
13814 @c LocalWords: pyexecdir pkgpyexecdir Python's pythondir pkgpythondir txi ois
13815 @c LocalWords: installinfo vers MAKEINFO makeinfo MAKEINFOFLAGS noinstall rf
13816 @c LocalWords: mandir thesame alsothesame installman myexecbin DESTDIR Pinard
13817 @c LocalWords: uninstall installdirs uninstalls MOSTLYCLEANFILES mostlyclean
13818 @c LocalWords: DISTCLEANFILES MAINTAINERCLEANFILES GZIP gzip shar exp
13819 @c LocalWords: distdir distcheck distcleancheck listfiles distuninstallcheck
13820 @c LocalWords: VPATH tarfile stdout XFAIL DejaGnu dejagnu DEJATOOL runtest ln
13821 @c LocalWords: RUNTESTDEFAULTFLAGS toolchain RUNTESTFLAGS asis readme DVIPS
13822 @c LocalWords: installcheck gzipped tarZ std utils etags mkid cd
13823 @c LocalWords: ARGS taggable ETAGSFLAGS lang ctags CTAGSFLAGS GTAGS gtags idl
13824 @c LocalWords: foocc doit idlC multilibs ABIs cmindex defmac ARG enableval FC
13825 @c LocalWords: MSG xtrue DBG pathchk CYGWIN afile proglink versioned TE
13826 @c LocalWords: wildcards Autoconfiscated subsubheading autotools Meyering API
13827 @c LocalWords: ois's wildcard Wportability cartouche vrindex printindex Duret
13828 @c LocalWords: DSOMEFLAG DVERSION automake Lutz insertcopying versioning FAQ
13829 @c LocalWords: LTLIBOBJ Libtool's libtool's libltdl dlopening itutions libbar
13830 @c LocalWords: WANTEDLIBS libhello sublibraries libtop libsub dlopened Ratfor
13831 @c LocalWords: mymodule timestamps timestamp underquoted MAKEINFOHTMLFLAGS te
13832 @c LocalWords: GNUmakefile Subpackages subpackage's subpackages aux
13833 @c LocalWords: detailmenu Timeline pwd reldir AUTOM autom PREREQ FOOBAR libc
13834 @c LocalWords: libhand subpackage moduleN libmain libmisc FCFLAGS FCCOMPILE
13835 @c LocalWords: FCLINK subst sed ELCFILES elc MAKEINFOHTML dvips esyscmd ustar
13836 @c LocalWords: tarballs Woverride vfi ELFILES djm AutoMake honkin FSF
13837 @c LocalWords: fileutils precanned MacKenzie's reimplement termutils Tromey's
13838 @c LocalWords: cois gnitsians LIBPROGRAMS progs LIBLIBRARIES Textutils Ulrich
13839 @c LocalWords: Matzigkeit Drepper's Gord Matzigkeit's jm Dalley Debian org
13840 @c LocalWords: Administrivia ILU CORBA Sourceware Molenda sourceware Elliston
13841 @c LocalWords: dep Oliva Akim Demaille Aiieeee Demaillator Akim's sourcequake
13842 @c LocalWords: grep backported screenshots libgcj KB unnumberedsubsubsec pre
13843 @c LocalWords: precomputing hacky makedepend inline clearmake LD PRELOAD Rel
13844 @c LocalWords: syscalls perlhist acl pm multitable headitem fdl appendixsec
13845 @c LocalWords: LTALLOCA MALLOC malloc memcmp strdup alloca libcompat xyz DFOO
13846 @c LocalWords: unprefixed buildable preprocessed DBAZ DDATADIR WARNINGCFLAGS
13847 @c LocalWords: LIBFOOCFLAGS LIBFOOLDFLAGS ftable testSubDir obj LIBTOOLFLAGS
13848 @c LocalWords: barexec Pinard's automatize initialize lzip xz zstd cscope