source: vendor/automake/1.7.9/automake.texi@ 3675

Last change on this file since 3675 was 3120, checked in by bird, 18 years ago

automake 1.7.9

File size: 231.6 KB
Line 
1\input texinfo @c -*-texinfo-*-
2@c %**start of header
3@setfilename automake.info
4@settitle automake
5@setchapternewpage off
6@c %**end of header
7
8@include version.texi
9
10@dircategory Software development
11@direntry
12* automake: (automake). Making Makefile.in's.
13@end direntry
14
15@dircategory Individual utilities
16@direntry
17* aclocal: (automake)Invoking aclocal. Generating aclocal.m4.
18@end direntry
19
20@ifinfo
21This file documents GNU automake @value{VERSION}
22
23Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
24Free Software Foundation, Inc.
25
26Permission is granted to make and distribute verbatim copies of
27this manual provided the copyright notice and this permission notice
28are preserved on all copies.
29
30@ignore
31Permission is granted to process this file through TeX and print the
32results, provided the printed document carries copying permission
33notice identical to this one except for the removal of this paragraph
34
35
36@end ignore
37Permission is granted to copy and distribute modified versions of this
38manual under the conditions for verbatim copying, provided that the entire
39resulting derived work is distributed under the terms of a permission
40notice identical to this one.
41
42Permission is granted to copy and distribute translations of this manual
43into another language, under the above conditions for modified versions,
44except that this permission notice may be stated in a translation approved
45by the Foundation.
46@end ifinfo
47
48
49@titlepage
50@title GNU Automake
51@subtitle For version @value{VERSION}, @value{UPDATED}
52@author David MacKenzie and Tom Tromey
53
54@page
55@vskip 0pt plus 1filll
56Copyright @copyright{} 1995, 1996, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
57@sp 2
58This is the first edition of the GNU Automake documentation,@*
59and is consistent with GNU Automake @value{VERSION}.@*
60@sp 2
61Published by the Free Software Foundation @*
6259 Temple Place - Suite 330, @*
63Boston, MA 02111-1307 USA @*
64
65Permission is granted to make and distribute verbatim copies of
66this manual provided the copyright notice and this permission notice
67are preserved on all copies.
68
69Permission is granted to copy and distribute modified versions of this
70manual under the conditions for verbatim copying, provided that the entire
71resulting derived work is distributed under the terms of a permission
72notice identical to this one.
73
74Permission is granted to copy and distribute translations of this manual
75into another language, under the above conditions for modified versions,
76except that this permission notice may be stated in a translation
77approved by the Free Software Foundation.
78@end titlepage
79
80@c Define an index of configure output variables.
81@defcodeindex ov
82@c Define an index of configure variables.
83@defcodeindex cv
84@c Define an index of options.
85@defcodeindex op
86@c Define an index of targets.
87@defcodeindex tr
88@c Define an index of commands.
89@defcodeindex cm
90
91@c Put the macros and variables into their own index.
92@c @syncodeindex fn cp
93@syncodeindex ov vr
94@syncodeindex cv vr
95@syncodeindex fn vr
96
97@c Put everything else into one index (arbitrarily chosen to be the concept index).
98@syncodeindex op cp
99@syncodeindex tr cp
100@syncodeindex cm cp
101
102@ifnottex
103@node Top, Introduction, (dir), (dir)
104@comment node-name, next, previous, up
105@top GNU Automake
106
107This file documents the GNU Automake package. Automake is a program
108which creates GNU standards-compliant Makefiles from template files.
109This edition documents version @value{VERSION}.
110
111@menu
112* Introduction:: Automake's purpose
113* Generalities:: General ideas
114* Examples:: Some example packages
115* Invoking Automake:: Creating a Makefile.in
116* configure:: Scanning configure.ac or configure.in
117* Top level:: The top-level Makefile.am
118* Alternative:: An alternative approach to subdirectories
119* Rebuilding:: Automatic rebuilding of Makefile
120* Programs:: Building programs and libraries
121* Other objects:: Other derived objects
122* Other GNU Tools:: Other GNU Tools
123* Documentation:: Building documentation
124* Install:: What gets installed
125* Clean:: What gets cleaned
126* Dist:: What goes in a distribution
127* Tests:: Support for test suites
128* Options:: Changing Automake's behavior
129* Miscellaneous:: Miscellaneous rules
130* Include:: Including extra files in an Automake template.
131* Conditionals:: Conditionals
132* Gnits:: The effect of @code{--gnu} and @code{--gnits}
133* Cygnus:: The effect of @code{--cygnus}
134* Extending:: Extending Automake
135* Distributing:: Distributing the Makefile.in
136* API versioning:: About compatibility between Automake versions
137* FAQ:: Frequently Asked Questions
138* Macro and Variable Index::
139* General Index::
140@end menu
141
142@end ifnottex
143
144
145@node Introduction, Generalities, Top, Top
146@chapter Introduction
147
148Automake is a tool for automatically generating @file{Makefile.in}s from
149files called @file{Makefile.am}. Each @file{Makefile.am} is basically a
150series of @code{make} variable definitions@footnote{These variables are
151also called @dfn{make macros} in Make terminology, however in this
152manual we reserve the term @dfn{macro} for Autoconf's macros.}, with
153rules being thrown in occasionally. The generated @file{Makefile.in}s
154are compliant with the GNU Makefile standards.
155
156@cindex GNU Makefile standards
157
158The GNU Makefile Standards Document
159(@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
160is long, complicated, and subject to change. The goal of Automake is to
161remove the burden of Makefile maintenance from the back of the
162individual GNU maintainer (and put it on the back of the Automake
163maintainer).
164
165The typical Automake input file is simply a series of variable definitions.
166Each such file is processed to create a @file{Makefile.in}. There
167should generally be one @file{Makefile.am} per directory of a project.
168
169@cindex Constraints of Automake
170@cindex Automake constraints
171
172Automake does constrain a project in certain ways; for instance it
173assumes that the project uses Autoconf (@pxref{Top, , Introduction,
174autoconf, The Autoconf Manual}), and enforces certain restrictions on
175the @file{configure.in} contents@footnote{Autoconf 2.50 promotes
176@file{configure.ac} over @file{configure.in}. The rest of this
177documentation will refer to @file{configure.in} as this use is not yet
178spread, but Automake supports @file{configure.ac} too.}.
179
180@cindex Automake requirements
181@cindex Requirements, Automake
182
183Automake requires @code{perl} in order to generate the
184@file{Makefile.in}s. However, the distributions created by Automake are
185fully GNU standards-compliant, and do not require @code{perl} in order
186to be built.
187
188@cindex BUGS, reporting
189@cindex Reporting BUGS
190@cindex E-mail, bug reports
191
192Mail suggestions and bug reports for Automake to
193@email{bug-automake@@gnu.org}.
194
195
196@node Generalities, Examples, Introduction, Top
197@chapter General ideas
198
199The following sections cover a few basic ideas that will help you
200understand how Automake works.
201
202@menu
203* General Operation:: General operation of Automake
204* Strictness:: Standards conformance checking
205* Uniform:: The Uniform Naming Scheme
206* Canonicalization:: How derived variables are named
207* User Variables:: Variables reserved for the user
208* Auxiliary Programs:: Programs automake might require
209@end menu
210
211
212@node General Operation, Strictness, Generalities, Generalities
213@section General Operation
214
215Automake works by reading a @file{Makefile.am} and generating a
216@file{Makefile.in}. Certain variables and targets defined in the
217@file{Makefile.am} instruct Automake to generate more specialized code;
218for instance, a @samp{bin_PROGRAMS} variable definition will cause targets
219for compiling and linking programs to be generated.
220
221@cindex Non-standard targets
222@cindex cvs-dist, non-standard example
223@trindex cvs-dist
224
225The variable definitions and targets in the @file{Makefile.am} are copied
226verbatim into the generated file. This allows you to add arbitrary code
227into the generated @file{Makefile.in}. For instance the Automake
228distribution includes a non-standard @code{cvs-dist} target, which the
229Automake maintainer uses to make distributions from his source control
230system.
231
232@cindex GNU make extensions
233
234Note that most GNU make extensions are not recognized by Automake. Using
235such extensions in a @file{Makefile.am} will lead to errors or confusing
236behavior.
237
238@cindex Append operator
239A special exception is that the GNU make append operator, @samp{+=}, is
240supported. This operator appends its right hand argument to the variable
241specified on the left. Automake will translate the operator into
242an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
243
244Automake tries to keep comments grouped with any adjoining targets or
245variable definitions.
246
247@cindex Make targets, overriding
248@cindex Overriding make targets
249
250A target defined in @file{Makefile.am} generally overrides any such
251target of a similar name that would be automatically generated by
252@code{automake}. Although this is a supported feature, it is generally
253best to avoid making use of it, as sometimes the generated rules are
254very particular.
255
256@cindex Variables, overriding
257@cindex Overriding make variables
258
259Similarly, a variable defined in @file{Makefile.am} or @code{AC_SUBST}'ed
260from @file{configure.in} will override any definition of the variable that
261@code{automake} would ordinarily create. This feature is more often
262useful than the ability to override a target definition. Be warned that
263many of the variables generated by @code{automake} are considered to be for
264internal use only, and their names might change in future releases.
265
266@cindex Recursive operation of Automake
267@cindex Automake, recursive operation
268@cindex Example of recursive operation
269
270When examining a variable definition, Automake will recursively examine
271variables referenced in the definition. For example, if Automake is
272looking at the content of @code{foo_SOURCES} in this snippet
273
274@example
275xs = a.c b.c
276foo_SOURCES = c.c $(xs)
277@end example
278
279it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
280contents of @code{foo_SOURCES}.
281
282@cindex ## (special Automake comment)
283@cindex Special Automake comment
284@cindex Comment, special to Automake
285
286Automake also allows a form of comment which is @emph{not} copied into
287the output; all lines beginning with @samp{##} (leading spaces allowed)
288are completely ignored by Automake.
289
290It is customary to make the first line of @file{Makefile.am} read:
291
292@cindex Makefile.am, first line
293@cindex First line of Makefile.am
294
295@example
296## Process this file with automake to produce Makefile.in
297@end example
298
299@c FIXME discuss putting a copyright into Makefile.am here? I would but
300@c I don't know quite what to say.
301
302@c FIXME document customary ordering of Makefile.am here!
303
304
305@node Strictness, Uniform, General Operation, Generalities
306@section Strictness
307
308@cindex Non-GNU packages
309
310While Automake is intended to be used by maintainers of GNU packages, it
311does make some effort to accommodate those who wish to use it, but do
312not want to use all the GNU conventions.
313
314@cindex Strictness, defined
315@cindex Strictness, foreign
316@cindex foreign strictness
317@cindex Strictness, gnu
318@cindex gnu strictness
319@cindex Strictness, gnits
320@cindex gnits strictness
321
322To this end, Automake supports three levels of @dfn{strictness}---the
323strictness indicating how stringently Automake should check standards
324conformance.
325
326The valid strictness levels are:
327
328@table @samp
329@item foreign
330Automake will check for only those things which are absolutely
331required for proper operations. For instance, whereas GNU standards
332dictate the existence of a @file{NEWS} file, it will not be required in
333this mode. The name comes from the fact that Automake is intended to be
334used for GNU programs; these relaxed rules are not the standard mode of
335operation.
336
337@item gnu
338Automake will check---as much as possible---for compliance to the GNU
339standards for packages. This is the default.
340
341@item gnits
342Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
343standards}. These are based on the GNU standards, but are even more
344detailed. Unless you are a Gnits standards contributor, it is
345recommended that you avoid this option until such time as the Gnits
346standard is actually published (which may never happen).
347@end table
348
349For more information on the precise implications of the strictness
350level, see @ref{Gnits}.
351
352Automake also has a special ``cygnus'' mode which is similar to
353strictness but handled differently. This mode is useful for packages
354which are put into a ``Cygnus'' style tree (e.g., the GCC tree). For
355more information on this mode, see @ref{Cygnus}.
356
357
358@node Uniform, Canonicalization, Strictness, Generalities
359@section The Uniform Naming Scheme
360
361@cindex Uniform naming scheme
362
363Automake variables generally follow a @dfn{uniform naming scheme} that
364makes it easy to decide how programs (and other derived objects) are
365built, and how they are installed. This scheme also supports
366@code{configure} time determination of what should be built.
367
368@cindex _PROGRAMS primary variable
369@cindex PROGRAMS primary variable
370@cindex Primary variable, PROGRAMS
371@cindex Primary variable, defined
372
373At @code{make} time, certain variables are used to determine which
374objects are to be built. The variable names are made of several pieces
375which are concatenated together.
376
377The piece which tells automake what is being built is commonly called
378the @dfn{primary}. For instance, the primary @code{PROGRAMS} holds a
379list of programs which are to be compiled and linked.
380@vindex PROGRAMS
381
382@cindex pkglibdir, defined
383@cindex pkgincludedir, defined
384@cindex pkgdatadir, defined
385
386@vindex pkglibdir
387@vindex pkgincludedir
388@vindex pkgdatadir
389
390A different set of names is used to decide where the built objects
391should be installed. These names are prefixes to the primary which
392indicate which standard directory should be used as the installation
393directory. The standard directory names are given in the GNU standards
394(@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
395Automake extends this list with @code{pkglibdir}, @code{pkgincludedir},
396and @code{pkgdatadir}; these are the same as the non-@samp{pkg}
397versions, but with @samp{@@PACKAGE@@} appended. For instance,
398@code{pkglibdir} is defined as @code{$(libdir)/@@PACKAGE@@}.
399@cvindex PACKAGE, directory
400
401@cindex EXTRA_, prepending
402
403For each primary, there is one additional variable named by prepending
404@samp{EXTRA_} to the primary name. This variable is used to list
405objects which may or may not be built, depending on what
406@code{configure} decides. This variable is required because Automake
407must statically know the entire list of objects that may be built in
408order to generate a @file{Makefile.in} that will work in all cases.
409
410@cindex EXTRA_PROGRAMS, defined
411@cindex Example, EXTRA_PROGRAMS
412@cindex cpio example
413
414For instance, @code{cpio} decides at configure time which programs are
415built. Some of the programs are installed in @code{bindir}, and some
416are installed in @code{sbindir}:
417
418@example
419EXTRA_PROGRAMS = mt rmt
420bin_PROGRAMS = cpio pax
421sbin_PROGRAMS = @@MORE_PROGRAMS@@
422@end example
423
424Defining a primary without a prefix as a variable, e.g.,
425@code{PROGRAMS}, is an error.
426
427Note that the common @samp{dir} suffix is left off when constructing the
428variable names; thus one writes @samp{bin_PROGRAMS} and not
429@samp{bindir_PROGRAMS}.
430
431Not every sort of object can be installed in every directory. Automake
432will flag those attempts it finds in error.
433Automake will also diagnose obvious misspellings in directory names.
434
435@cindex Extending list of installation directories
436@cindex Installation directories, extending list
437
438Sometimes the standard directories---even as augmented by Automake---
439are not enough. In particular it is sometimes useful, for clarity, to
440install objects in a subdirectory of some predefined directory. To this
441end, Automake allows you to extend the list of possible installation
442directories. A given prefix (e.g. @samp{zar}) is valid if a variable of
443the same name with @samp{dir} appended is defined (e.g. @code{zardir}).
444
445@cindex HTML support, example
446
447For instance, until HTML support is part of Automake, you could use this
448to install raw HTML documentation:
449
450@example
451htmldir = $(prefix)/html
452html_DATA = automake.html
453@end example
454
455@cindex noinst primary prefix, definition
456
457The special prefix @samp{noinst} indicates that the objects in question
458should be built but not installed at all. This is usually used for
459objects required to build the rest of your package, for instance static
460libraries (@pxref{A Library}), or helper scripts.
461
462@cindex check primary prefix, definition
463
464The special prefix @samp{check} indicates that the objects in question
465should not be built until the @code{make check} command is run. Those
466objects are not installed either.
467
468The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
469@samp{LISP}, @samp{PYTHON}, @samp{JAVA}, @samp{SCRIPTS}, @samp{DATA},
470@samp{HEADERS}, @samp{MANS}, and @samp{TEXINFOS}.
471@vindex PROGRAMS
472@vindex LIBRARIES
473@vindex LISP
474@vindex PYTHON
475@vindex JAVA
476@vindex SCRIPTS
477@vindex DATA
478@vindex HEADERS
479@vindex MANS
480@vindex TEXINFOS
481
482Some primaries also allow additional prefixes which control other
483aspects of @code{automake}'s behavior. The currently defined prefixes
484are @samp{dist_}, @samp{nodist_}, and @samp{nobase_}. These prefixes
485are explained later (@pxref{Program and Library Variables}).
486
487
488@node Canonicalization, User Variables, Uniform, Generalities
489@section How derived variables are named
490
491@cindex canonicalizing Automake variables
492
493Sometimes a Makefile variable name is derived from some text the
494maintainer supplies. For instance, a program name listed in
495@samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
496variable. In cases like this, Automake canonicalizes the text, so that
497program names and the like do not have to follow Makefile variable naming
498rules. All characters in the name except for letters, numbers, the
499strudel (@@), and the underscore are turned into underscores when making
500variable references.
501
502For example, if your program is named @code{sniff-glue}, the derived
503variable name would be @code{sniff_glue_SOURCES}, not
504@code{sniff-glue_SOURCES}. Similarly the sources for a library named
505@code{libmumble++.a} should be listed in the
506@code{libmumble___a_SOURCES} variable.
507
508The strudel is an addition, to make the use of Autoconf substitutions in
509variable names less obfuscating.
510
511
512@node User Variables, Auxiliary Programs, Canonicalization, Generalities
513@section Variables reserved for the user
514
515@cindex variables, reserved for the user
516@cindex user variables
517
518Some @code{Makefile} variables are reserved by the GNU Coding Standards
519for the use of the ``user'' -- the person building the package. For
520instance, @code{CFLAGS} is one such variable.
521
522Sometimes package developers are tempted to set user variables such as
523@code{CFLAGS} because it appears to make their job easier -- they don't
524have to introduce a second variable into every target.
525
526However, the package itself should never set a user variable,
527particularly not to include switches which are required for proper
528compilation of the package. Since these variables are documented as
529being for the package builder, that person rightfully expects to be able
530to override any of these variables at build time.
531
532To get around this problem, automake introduces an automake-specific
533shadow variable for each user flag variable. (Shadow variables are not
534introduced for variables like @code{CC}, where they would make no
535sense.) The shadow variable is named by prepending @samp{AM_} to the
536user variable's name. For instance, the shadow variable for
537@code{YFLAGS} is @code{AM_YFLAGS}.
538
539
540@node Auxiliary Programs, , User Variables, Generalities
541@section Programs automake might require
542
543@cindex Programs, auxiliary
544@cindex Auxiliary programs
545
546Automake sometimes requires helper programs so that the generated
547@file{Makefile} can do its work properly. There are a fairly large
548number of them, and we list them here.
549
550@table @code
551@item ansi2knr.c
552@itemx ansi2knr.1
553These two files are used by the automatic de-ANSI-fication support
554(@pxref{ANSI}).
555
556@item compile
557This is a wrapper for compilers which don't accept both @samp{-c} and
558@samp{-o} at the same time. It is only used when absolutely required.
559Such compilers are rare.
560
561@item config.guess
562@itemx config.sub
563These programs compute the canonical triplets for the given build, host,
564or target architecture. These programs are updated regularly to support
565new architectures and fix probes broken by changes in new kernel
566versions. You are encouraged to fetch the latest versions of these
567files from @url{ftp://ftp.gnu.org/gnu/config/} before making a release.
568
569@item depcomp
570This program understands how to run a compiler so that it will generate
571not only the desired output but also dependency information which is
572then used by the automatic dependency tracking feature.
573
574@item elisp-comp
575This program is used to byte-compile Emacs Lisp code.
576
577@item install-sh
578This is a replacement for the @code{install} program which works on
579platforms where @code{install} is unavailable or unusable.
580
581@item mdate-sh
582This script is used to generate a @file{version.texi} file. It examines
583a file and prints some date information about it.
584
585@item missing
586This wraps a number of programs which are typically only required by
587maintainers. If the program in question doesn't exist, @code{missing}
588prints an informative warning and attempts to fix things so that the
589build can continue.
590
591@item mkinstalldirs
592This works around the fact that @code{mkdir -p} is not portable.
593
594@item py-compile
595This is used to byte-compile Python scripts.
596
597@item texinfo.tex
598Not a program, this file is required for @code{make dvi}, @code{make ps}
599and @code{make pdf} to work when Texinfo sources are in the package.
600
601@item ylwrap
602This program wraps @code{lex} and @code{yacc} and ensures that, for
603instance, multiple @code{yacc} instances can be invoked in a single
604directory in parallel.
605
606@end table
607
608
609@node Examples, Invoking Automake, Generalities, Top
610@chapter Some example packages
611
612@menu
613* Complete:: A simple example, start to finish
614* Hello:: A classic program
615* true:: Building true and false
616@end menu
617
618
619@node Complete, Hello, Examples, Examples
620@section A simple example, start to finish
621
622@cindex Complete example
623
624Let's suppose you just finished writing @code{zardoz}, a program to make
625your head float from vortex to vortex. You've been using Autoconf to
626provide a portability framework, but your @file{Makefile.in}s have been
627ad-hoc. You want to make them bulletproof, so you turn to Automake.
628
629@cindex AM_INIT_AUTOMAKE, example use
630
631The first step is to update your @file{configure.in} to include the
632commands that @code{automake} needs. The way to do this is to add an
633@code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
634
635@example
636AC_INIT(zardoz, 1.0)
637AM_INIT_AUTOMAKE
638@dots{}
639@end example
640
641Since your program doesn't have any complicating factors (e.g., it
642doesn't use @code{gettext}, it doesn't want to build a shared library),
643you're done with this part. That was easy!
644
645@cindex aclocal program, introduction
646@cindex aclocal.m4, preexisting
647@cindex acinclude.m4, defined
648
649Now you must regenerate @file{configure}. But to do that, you'll need
650to tell @code{autoconf} how to find the new macro you've used. The
651easiest way to do this is to use the @code{aclocal} program to generate
652your @file{aclocal.m4} for you. But wait@dots{} maybe you already have an
653@file{aclocal.m4}, because you had to write some hairy macros for your
654program. The @code{aclocal} program lets you put your own macros into
655@file{acinclude.m4}, so simply rename and then run:
656
657@example
658mv aclocal.m4 acinclude.m4
659aclocal
660autoconf
661@end example
662
663@cindex zardoz example
664
665Now it is time to write your @file{Makefile.am} for @code{zardoz}.
666Since @code{zardoz} is a user program, you want to install it where the
667rest of the user programs go: @code{bindir}. Additionally,
668@code{zardoz} has some Texinfo documentation. Your @file{configure.in}
669script uses @code{AC_REPLACE_FUNCS}, so you need to link against
670@samp{$(LIBOBJS)}. So here's what you'd write:
671
672@example
673bin_PROGRAMS = zardoz
674zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
675zardoz_LDADD = $(LIBOBJS)
676
677info_TEXINFOS = zardoz.texi
678@end example
679
680Now you can run @code{automake --add-missing} to generate your
681@file{Makefile.in} and grab any auxiliary files you might need, and
682you're done!
683
684
685@node Hello, true, Complete, Examples
686@section A classic program
687
688@cindex Example, GNU Hello
689@cindex Hello example
690@cindex GNU Hello, example
691
692@uref{ftp://prep.ai.mit.edu/pub/gnu/hello-1.3.tar.gz, GNU hello} is
693renowned for its classic simplicity and versatility. This section shows
694how Automake could be used with the GNU Hello package. The examples
695below are from the latest beta version of GNU Hello, but with all of the
696maintainer-only code stripped out, as well as all copyright comments.
697
698Of course, GNU Hello is somewhat more featureful than your traditional
699two-liner. GNU Hello is internationalized, does option processing, and
700has a manual and a test suite.
701
702@cindex configure.in, from GNU Hello
703@cindex GNU Hello, configure.in
704@cindex Hello, configure.in
705
706Here is the @file{configure.in} from GNU Hello.
707@strong{Please note:} The calls to @code{AC_INIT} and @code{AM_INIT_AUTOMAKE}
708in this example use a deprecated syntax. For the current approach,
709see the description of @code{AM_INIT_AUTOMAKE} in @ref{Public macros}.
710
711@c FIXME: This definitely requires an update, e.g. to GNU Hello 2.1.1.
712
713@example
714dnl Process this file with autoconf to produce a configure script.
715AC_INIT(src/hello.c)
716AM_INIT_AUTOMAKE(hello, 1.3.11)
717AM_CONFIG_HEADER(config.h)
718
719dnl Set of available languages.
720ALL_LINGUAS="de fr es ko nl no pl pt sl sv"
721
722dnl Checks for programs.
723AC_PROG_CC
724AC_ISC_POSIX
725
726dnl Checks for libraries.
727
728dnl Checks for header files.
729AC_STDC_HEADERS
730AC_HAVE_HEADERS(string.h fcntl.h sys/file.h sys/param.h)
731
732dnl Checks for library functions.
733AC_FUNC_ALLOCA
734
735dnl Check for st_blksize in struct stat
736AC_ST_BLKSIZE
737
738dnl internationalization macros
739AM_GNU_GETTEXT
740AC_OUTPUT([Makefile doc/Makefile intl/Makefile po/Makefile.in \
741 src/Makefile tests/Makefile tests/hello],
742 [chmod +x tests/hello])
743@end example
744
745The @samp{AM_} macros are provided by Automake (or the Gettext library);
746the rest are standard Autoconf macros.
747
748
749The top-level @file{Makefile.am}:
750
751@example
752EXTRA_DIST = BUGS ChangeLog.O
753SUBDIRS = doc intl po src tests
754@end example
755
756As you can see, all the work here is really done in subdirectories.
757
758The @file{po} and @file{intl} directories are automatically generated
759using @code{gettextize}; they will not be discussed here.
760
761@cindex Texinfo file handling example
762@cindex Example, handling Texinfo files
763
764In @file{doc/Makefile.am} we see:
765
766@example
767info_TEXINFOS = hello.texi
768hello_TEXINFOS = gpl.texi
769@end example
770
771This is sufficient to build, install, and distribute the GNU Hello
772manual.
773
774@cindex Regression test example
775@cindex Example, regression test
776
777Here is @file{tests/Makefile.am}:
778
779@example
780TESTS = hello
781EXTRA_DIST = hello.in testdata
782@end example
783
784The script @file{hello} is generated by @code{configure}, and is the
785only test case. @code{make check} will run this test.
786
787@cindex INCLUDES, example usage
788
789Last we have @file{src/Makefile.am}, where all the real work is done:
790@c FIXME: As all the Hello World excerpts in this manual, this
791@c shows deprecated features (here: $(INCLUDES)).
792
793@example
794bin_PROGRAMS = hello
795hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
796hello_LDADD = @@INTLLIBS@@ @@ALLOCA@@
797localedir = $(datadir)/locale
798INCLUDES = -I../intl -DLOCALEDIR=\"$(localedir)\"
799@end example
800
801
802@node true, , Hello, Examples
803@section Building true and false
804
805@cindex Example, false and true
806@cindex false Example
807@cindex true Example
808
809Here is another, trickier example. It shows how to generate two
810programs (@code{true} and @code{false}) from the same source file
811(@file{true.c}). The difficult part is that each compilation of
812@file{true.c} requires different @code{cpp} flags.
813
814@example
815bin_PROGRAMS = true false
816false_SOURCES =
817false_LDADD = false.o
818
819true.o: true.c
820 $(COMPILE) -DEXIT_CODE=0 -c true.c
821
822false.o: true.c
823 $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
824@end example
825
826Note that there is no @code{true_SOURCES} definition. Automake will
827implicitly assume that there is a source file named @file{true.c}, and
828define rules to compile @file{true.o} and link @file{true}. The
829@code{true.o: true.c} rule supplied by the above @file{Makefile.am},
830will override the Automake generated rule to build @file{true.o}.
831
832@code{false_SOURCES} is defined to be empty---that way no implicit value
833is substituted. Because we have not listed the source of
834@file{false}, we have to tell Automake how to link the program. This is
835the purpose of the @code{false_LDADD} line. A @code{false_DEPENDENCIES}
836variable, holding the dependencies of the @file{false} target will be
837automatically generated by Automake from the content of
838@code{false_LDADD}.
839
840The above rules won't work if your compiler doesn't accept both
841@samp{-c} and @samp{-o}. The simplest fix for this is to introduce a
842bogus dependency (to avoid problems with a parallel @code{make}):
843
844@example
845true.o: true.c false.o
846 $(COMPILE) -DEXIT_CODE=0 -c true.c
847
848false.o: true.c
849 $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
850@end example
851
852Also, these explicit rules do not work if the de-ANSI-fication feature
853is used (@pxref{ANSI}). Supporting de-ANSI-fication requires a little
854more work:
855
856@example
857true._o: true._c false.o
858 $(COMPILE) -DEXIT_CODE=0 -c true.c
859
860false._o: true._c
861 $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true._o false.o
862@end example
863
864As it turns out, there is also a much easier way to do this same task.
865Some of the above techniques are useful enough that we've kept the
866example in the manual. However if you were to build @code{true} and
867@code{false} in real life, you would probably use per-program
868compilation flags, like so:
869
870@example
871bin_PROGRAMS = false true
872
873false_SOURCES = true.c
874false_CPPFLAGS = -DEXIT_CODE=1
875
876true_SOURCES = true.c
877true_CPPFLAGS = -DEXIT_CODE=0
878@end example
879
880In this case Automake will cause @file{true.c} to be compiled twice,
881with different flags. De-ANSI-fication will work automatically. In
882this instance, the names of the object files would be chosen by
883automake; they would be @file{false-true.o} and @file{true-true.o}.
884(The name of the object files rarely matters.)
885
886
887@node Invoking Automake, configure, Examples, Top
888@chapter Creating a @file{Makefile.in}
889
890@cindex Multiple configure.in files
891@cindex Invoking Automake
892@cindex Automake, invoking
893
894To create all the @file{Makefile.in}s for a package, run the
895@code{automake} program in the top level directory, with no arguments.
896@code{automake} will automatically find each appropriate
897@file{Makefile.am} (by scanning @file{configure.in}; @pxref{configure})
898and generate the corresponding @file{Makefile.in}. Note that
899@code{automake} has a rather simplistic view of what constitutes a
900package; it assumes that a package has only one @file{configure.in}, at
901the top. If your package has multiple @file{configure.in}s, then you
902must run @code{automake} in each directory holding a
903@file{configure.in}. (Alternatively, you may rely on Autoconf's
904@code{autoreconf}, which is able to recurse your package tree and run
905@code{automake} where appropriate.)
906
907You can optionally give @code{automake} an argument; @file{.am} is
908appended to the argument and the result is used as the name of the input
909file. This feature is generally only used to automatically rebuild an
910out-of-date @file{Makefile.in}. Note that @code{automake} must always
911be run from the topmost directory of a project, even if being used to
912regenerate the @file{Makefile.in} in some subdirectory. This is
913necessary because @code{automake} must scan @file{configure.in}, and
914because @code{automake} uses the knowledge that a @file{Makefile.in} is
915in a subdirectory to change its behavior in some cases.
916
917@vindex AUTOCONF
918Automake will run @code{autoconf} to scan @file{configure.in} and its
919dependencies (@file{aclocal.m4}), therefore @code{autoconf} must be in
920your @code{PATH}. If there is an @code{AUTOCONF} variable in your
921environment it will be used instead of @code{autoconf}, this allows you
922to select a particular version of Autoconf. By the way, don't
923misunderstand this paragraph: Automake runs @code{autoconf} to
924@strong{scan} your @file{configure.in}, this won't build
925@file{configure} and you still have to run @code{autoconf} yourself for
926this purpose.
927
928@cindex Automake options
929@cindex Options, Automake
930@cindex Strictness, command line
931
932@code{automake} accepts the following options:
933
934@cindex Extra files distributed with Automake
935@cindex Files distributed with Automake
936@cindex config.guess
937
938@table @samp
939@item -a
940@itemx --add-missing
941@opindex -a
942@opindex --add-missing
943Automake requires certain common files to exist in certain situations;
944for instance @file{config.guess} is required if @file{configure.in} runs
945@code{AC_CANONICAL_HOST}. Automake is distributed with several of these
946files (@pxref{Auxiliary Programs}); this option will cause the missing
947ones to be automatically added to the package, whenever possible. In
948general if Automake tells you a file is missing, try using this option.
949By default Automake tries to make a symbolic link pointing to its own
950copy of the missing file; this can be changed with @code{--copy}.
951
952Many of the potentially-missing files are common scripts whose
953location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
954Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
955file is considered missing, and where the missing file is added
956(@pxref{Optional}).
957
958@item --libdir=@var{dir}
959@opindex --libdir
960Look for Automake data files in directory @var{dir} instead of in the
961installation directory. This is typically used for debugging.
962
963@item -c
964@opindex -c
965@itemx --copy
966@opindex --copy
967When used with @code{--add-missing}, causes installed files to be
968copied. The default is to make a symbolic link.
969
970@item --cygnus
971@opindex --cygnus
972Causes the generated @file{Makefile.in}s to follow Cygnus rules, instead
973of GNU or Gnits rules. For more information, see @ref{Cygnus}.
974
975@item -f
976@opindex -f
977@itemx --force-missing
978@opindex --force-missing
979When used with @code{--add-missing}, causes standard files to be reinstalled
980even if they already exist in the source tree. This involves removing
981the file from the source tree before creating the new symlink (or, with
982@code{--copy}, copying the new file).
983
984@item --foreign
985@opindex --foreign
986Set the global strictness to @samp{foreign}. For more information, see
987@ref{Strictness}.
988
989@item --gnits
990@opindex --gnits
991Set the global strictness to @samp{gnits}. For more information, see
992@ref{Gnits}.
993
994@item --gnu
995@opindex --gnu
996Set the global strictness to @samp{gnu}. For more information, see
997@ref{Gnits}. This is the default strictness.
998
999@item --help
1000@opindex --help
1001Print a summary of the command line options and exit.
1002
1003@item -i
1004@itemx --ignore-deps
1005@opindex -i
1006This disables the dependency tracking feature in generated
1007@file{Makefile}s; see @ref{Dependencies}.
1008
1009@item --include-deps
1010@opindex --include-deps
1011This enables the dependency tracking feature. This feature is enabled
1012by default. This option is provided for historical reasons only and
1013probably should not be used.
1014
1015@item --no-force
1016@opindex --no-force
1017Ordinarily @code{automake} creates all @file{Makefile.in}s mentioned in
1018@file{configure.in}. This option causes it to only update those
1019@file{Makefile.in}s which are out of date with respect to one of their
1020dependents.
1021
1022Due to a bug in its implementation, this option is currently ignored.
1023It will be fixed in Automake 1.8.
1024
1025@item -o @var{dir}
1026@itemx --output-dir=@var{dir}
1027@opindex -o
1028@opindex --output-dir
1029Put the generated @file{Makefile.in} in the directory @var{dir}.
1030Ordinarily each @file{Makefile.in} is created in the directory of the
1031corresponding @file{Makefile.am}. This option is deprecated and will be
1032removed in a future release.
1033
1034@item -v
1035@itemx --verbose
1036@opindex -v
1037@opindex --verbose
1038Cause Automake to print information about which files are being read or
1039created.
1040
1041@item --version
1042@opindex --version
1043Print the version number of Automake and exit.
1044
1045@item -W CATEGORY
1046@item --warnings=@var{category}
1047@opindex -W
1048@opindex --warnings
1049Output warnings falling in @var{category}. @var{category} can be
1050one of:
1051@table @samp
1052@item gnu
1053warnings related to the GNU Coding Standards
1054(@pxref{Top, , , standards, The GNU Coding Standards}).
1055@item obsolete
1056obsolete features or constructions
1057@item portability
1058portability issues (e.g., use of Make features which are known not portable)
1059@item syntax
1060weird syntax, unused variables, typos
1061@item unsupported
1062unsupported or incomplete features
1063@item all
1064all the warnings
1065@item none
1066turn off all the warnings
1067@item error
1068treat warnings as errors
1069@end table
1070
1071A category can be turned off by prefixing its name with @samp{no-}. For
1072instance @samp{-Wno-syntax} will hide the warnings about unused
1073variables.
1074
1075The categories output by default are @samp{syntax} and
1076@samp{unsupported}. Additionally, @samp{gnu} is enabled in @samp{--gnu} and
1077@samp{--gnits} strictness.
1078
1079@samp{portability} warnings are currently disabled by default, but they
1080will be enabled in @samp{--gnu} and @samp{--gnits} strictness in a
1081future release.
1082
1083@vindex WARNINGS
1084The environment variable @samp{WARNINGS} can contain a comma separated
1085list of categories to enable. It will be taken into account before the
1086command-line switches, this way @samp{-Wnone} will also ignore any
1087warning category enabled by @samp{WARNINGS}. This variable is also used
1088by other tools like @command{autoconf}; unknown categories are ignored
1089for this reason.
1090
1091@end table
1092
1093
1094@node configure, Top level, Invoking Automake, Top
1095@chapter Scanning @file{configure.in}
1096
1097@cindex configure.in, scanning
1098@cindex Scanning configure.in
1099
1100Automake scans the package's @file{configure.in} to determine certain
1101information about the package. Some @code{autoconf} macros are required
1102and some variables must be defined in @file{configure.in}. Automake
1103will also use information from @file{configure.in} to further tailor its
1104output.
1105
1106Automake also supplies some Autoconf macros to make the maintenance
1107easier. These macros can automatically be put into your
1108@file{aclocal.m4} using the @code{aclocal} program.
1109
1110@menu
1111* Requirements:: Configuration requirements
1112* Optional:: Other things Automake recognizes
1113* Invoking aclocal:: Auto-generating aclocal.m4
1114* aclocal options:: aclocal command line arguments
1115* Macro search path:: Modifying aclocal's search path
1116* Macros:: Autoconf macros supplied with Automake
1117* Extending aclocal:: Writing your own aclocal macros
1118@end menu
1119
1120
1121@node Requirements, Optional, configure, configure
1122@section Configuration requirements
1123
1124@cindex Automake requirements
1125@cindex Requirements of Automake
1126
1127The one real requirement of Automake is that your @file{configure.in}
1128call @code{AM_INIT_AUTOMAKE}. This macro does several things which are
1129required for proper Automake operation (@pxref{Macros}).
1130@cvindex AM_INIT_AUTOMAKE
1131
1132Here are the other macros which Automake requires but which are not run
1133by @code{AM_INIT_AUTOMAKE}:
1134
1135@table @code
1136@item AC_CONFIG_FILES
1137@itemx AC_OUTPUT
1138Automake uses these to determine which files to create (@pxref{Output, ,
1139Creating Output Files, autoconf, The Autoconf Manual}). A listed file
1140is considered to be an Automake generated @file{Makefile} if there
1141exists a file with the same name and the @file{.am} extension appended.
1142Typically, @code{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
1143generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
1144
1145These files are all removed by @code{make distclean}.
1146@cvindex AC_CONFIG_FILES
1147@cvindex AC_OUTPUT
1148@end table
1149
1150
1151@node Optional, Invoking aclocal, Requirements, configure
1152@section Other things Automake recognizes
1153
1154@cindex Macros Automake recognizes
1155@cindex Recognized macros by Automake
1156
1157Every time Automake is run it calls Autoconf to trace
1158@file{configure.in}. This way it can recognize the use of certain
1159macros and tailor the generated @file{Makefile.in} appropriately.
1160Currently recognized macros and their effects are:
1161
1162@table @code
1163@item AC_CONFIG_HEADERS
1164Automake will generate rules to rebuild these headers. Older versions
1165of Automake required the use of @code{AM_CONFIG_HEADER}
1166(@pxref{Macros}); this is no longer the case today.
1167@cvindex AC_CONFIG_HEADERS
1168
1169@item AC_CONFIG_AUX_DIR
1170Automake will look for various helper scripts, such as
1171@file{mkinstalldirs}, in the directory named in this macro invocation.
1172@c This list is accurate relative to version 1.7.2
1173(The full list of scripts is: @file{config.guess}, @file{config.sub},
1174@file{depcomp}, @file{elisp-comp}, @file{compile}, @file{install-sh},
1175@file{ltmain.sh}, @file{mdate-sh}, @file{missing}, @file{mkinstalldirs},
1176@file{py-compile}, @file{texinfo.tex}, and @file{ylwrap}.) Not all
1177scripts are always searched for; some scripts will only be sought if the
1178generated @file{Makefile.in} requires them.
1179@cvindex AC_CONFIG_AUX_DIR
1180
1181If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
1182their @samp{standard} locations. For @file{mdate-sh},
1183@file{texinfo.tex}, and @file{ylwrap}, the standard location is the
1184source directory corresponding to the current @file{Makefile.am}. For
1185the rest, the standard location is the first one of @file{.}, @file{..},
1186or @file{../..} (relative to the top source directory) that provides any
1187one of the helper scripts. @xref{Input, , Finding `configure' Input,
1188autoconf, The Autoconf Manual}.
1189
1190Required files from @code{AC_CONFIG_AUX_DIR} are automatically
1191distributed, even if there is no @file{Makefile.am} in this directory.
1192
1193@item AC_CANONICAL_HOST
1194Automake will ensure that @file{config.guess} and @file{config.sub}
1195exist. Also, the @file{Makefile} variables @samp{host_alias} and
1196@samp{host_triplet} are introduced. See @ref{Canonicalizing, ,
1197Getting the Canonical System Type, autoconf, The Autoconf Manual}.
1198@cvindex AC_CANONICAL_HOST
1199@vindex host_alias
1200@vindex host_triplet
1201
1202@item AC_CANONICAL_SYSTEM
1203This is similar to @code{AC_CANONICAL_HOST}, but also defines the
1204@file{Makefile} variables @samp{build_alias} and @samp{target_alias}.
1205@xref{Canonicalizing, , Getting the Canonical System Type, autoconf, The
1206Autoconf Manual}.
1207@cvindex AC_CANONICAL_SYSTEM
1208@vindex build_alias
1209@vindex target_alias
1210
1211@item AC_LIBSOURCE
1212@itemx AC_LIBSOURCES
1213@itemx AC_LIBOBJ
1214Automake will automatically distribute any file listed in
1215@code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
1216
1217Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}. So if
1218an Autoconf macro is documented to call @code{AC_LIBOBJ([file])}, then
1219@file{file.c} will be distributed automatically by Automake. This
1220encompasses many macros like @code{AC_FUNC_ALLOCA},
1221@code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
1222@cvindex AC_LIBOBJ
1223@cvindex AC_LIBSOURCE
1224@cvindex AC_LIBSOURCES
1225
1226By the way, direct assignments to @code{LIBOBJS} are no longer
1227supported. You should always use @code{AC_LIBOBJ} for this purpose.
1228@xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs. @code{LIBOBJS},
1229autoconf, The Autoconf Manual}.
1230@cvindex LIBOBJS
1231
1232@item AC_PROG_RANLIB
1233This is required if any libraries are built in the package.
1234@xref{Particular Programs, , Particular Program Checks, autoconf, The
1235Autoconf Manual}.
1236@cvindex AC_PROG_RANLIB
1237
1238@item AC_PROG_CXX
1239This is required if any C++ source is included. @xref{Particular
1240Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
1241@cvindex AC_PROG_CXX
1242
1243@item AC_PROG_F77
1244This is required if any Fortran 77 source is included. This macro is
1245distributed with Autoconf version 2.13 and later. @xref{Particular
1246Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
1247@cvindex AC_PROG_F77
1248
1249@item AC_F77_LIBRARY_LDFLAGS
1250This is required for programs and shared libraries that are a mixture of
1251languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
1252C++}). @xref{Macros, , Autoconf macros supplied with Automake}.
1253@cvindex AC_F77_LIBRARY_LDFLAGS
1254
1255@item AC_PROG_LIBTOOL
1256Automake will turn on processing for @code{libtool} (@pxref{Top, ,
1257Introduction, libtool, The Libtool Manual}).
1258@cvindex AC_PROG_LIBTOOL
1259
1260@item AC_PROG_YACC
1261If a Yacc source file is seen, then you must either use this macro or
1262define the variable @samp{YACC} in @file{configure.in}. The former is
1263preferred (@pxref{Particular Programs, , Particular Program Checks,
1264autoconf, The Autoconf Manual}).
1265@cvindex AC_PROG_YACC
1266@cvindex YACC
1267
1268@item AC_PROG_LEX
1269If a Lex source file is seen, then this macro must be used.
1270@xref{Particular Programs, , Particular Program Checks, autoconf, The
1271Autoconf Manual}.
1272@cvindex AC_PROG_LEX
1273
1274@item AC_SUBST
1275@cvindex AC_SUBST
1276The first argument is automatically defined as a variable in each
1277generated @file{Makefile.in}. @xref{Setting Output Variables, , Setting
1278Output Variables, autoconf, The Autoconf Manual}.
1279
1280If the Autoconf manual says that a macro calls @code{AC_SUBST} for
1281@var{var}, or defines the output variable @var{var} then @var{var} will
1282be defined in each @file{Makefile.in} generated by Automake.
1283E.g. @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and @code{X_LIBS}, so
1284you can use these variables in any @file{Makefile.am} if
1285@code{AC_PATH_XTRA} is called.
1286
1287@item AM_C_PROTOTYPES
1288This is required when using automatic de-ANSI-fication; see @ref{ANSI}.
1289@cvindex AM_C_PROTOTYPES
1290
1291@item AM_GNU_GETTEXT
1292This macro is required for packages which use GNU gettext
1293(@pxref{gettext}). It is distributed with gettext. If Automake sees
1294this macro it ensures that the package meets some of gettext's
1295requirements.
1296@cvindex AM_GNU_GETTEXT
1297
1298@item AM_MAINTAINER_MODE
1299@opindex --enable-maintainer-mode
1300This macro adds a @samp{--enable-maintainer-mode} option to
1301@code{configure}. If this is used, @code{automake} will cause
1302@samp{maintainer-only} rules to be turned off by default in the
1303generated @file{Makefile.in}s. This macro defines the
1304@samp{MAINTAINER_MODE} conditional, which you can use in your own
1305@file{Makefile.am}.
1306@cvindex AM_MAINTAINER_MODE
1307
1308@end table
1309
1310
1311@node Invoking aclocal, aclocal options, Optional, configure
1312@section Auto-generating aclocal.m4
1313
1314@cindex Invoking aclocal
1315@cindex aclocal, Invoking
1316
1317Automake includes a number of Autoconf macros which can be used in your
1318package; some of them are actually required by Automake in certain
1319situations. These macros must be defined in your @file{aclocal.m4};
1320otherwise they will not be seen by @code{autoconf}.
1321
1322The @code{aclocal} program will automatically generate @file{aclocal.m4}
1323files based on the contents of @file{configure.in}. This provides a
1324convenient way to get Automake-provided macros, without having to
1325search around. Also, the @code{aclocal} mechanism allows other packages
1326to supply their own macros.
1327
1328At startup, @code{aclocal} scans all the @file{.m4} files it can find,
1329looking for macro definitions (@pxref{Macro search path}). Then it
1330scans @file{configure.in}. Any
1331mention of one of the macros found in the first step causes that macro,
1332and any macros it in turn requires, to be put into @file{aclocal.m4}.
1333
1334The contents of @file{acinclude.m4}, if it exists, are also
1335automatically included in @file{aclocal.m4}. This is useful for
1336incorporating local macros into @file{configure}.
1337
1338@code{aclocal} tries to be smart about looking for new @code{AC_DEFUN}s
1339in the files it scans. It also
1340tries to copy the full text of the scanned file into @file{aclocal.m4},
1341including both @samp{#} and @samp{dnl} comments. If you want to make a
1342comment which will be completely ignored by @code{aclocal}, use
1343@samp{##} as the comment leader.
1344
1345@menu
1346* aclocal options:: Options supported by aclocal
1347* Macro search path:: How aclocal finds .m4 files
1348@end menu
1349
1350@node aclocal options, Macro search path, Invoking aclocal, configure
1351@section aclocal options
1352
1353@cindex aclocal, Options
1354@cindex Options, aclocal
1355
1356@code{aclocal} accepts the following options:
1357
1358@table @code
1359@item --acdir=@var{dir}
1360@opindex --acdir
1361Look for the macro files in @var{dir} instead of the installation
1362directory. This is typically used for debugging.
1363
1364@item --help
1365@opindex --help
1366Print a summary of the command line options and exit.
1367
1368@item -I @var{dir}
1369@opindex -I
1370Add the directory @var{dir} to the list of directories searched for
1371@file{.m4} files.
1372
1373@item --output=@var{file}
1374@opindex --output
1375Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
1376
1377@item --print-ac-dir
1378@opindex --print-ac-dir
1379Prints the name of the directory which @code{aclocal} will search to
1380find third-party @file{.m4} files. When this option is given, normal
1381processing is suppressed. This option can be used by a package to
1382determine where to install a macro file.
1383
1384@item --verbose
1385@opindex --verbose
1386Print the names of the files it examines.
1387
1388@item --version
1389@opindex --version
1390Print the version number of Automake and exit.
1391@end table
1392
1393@node Macro search path, Macros, aclocal options, configure
1394@section Macro search path
1395
1396@cindex Macro search path
1397@cindex aclocal search path
1398
1399By default, @command{aclocal} searches for @file{.m4} files in the following
1400directories, in this order:
1401
1402@table @code
1403@item @var{acdir-APIVERSION}
1404This is where the @file{.m4} macros distributed with automake itself
1405are stored. @var{APIVERSION} depends on the automake release used;
1406for automake 1.6.x, @var{APIVERSION} = @code{1.6}.
1407
1408@item @var{acdir}
1409This directory is intended for third party @file{.m4} files, and is
1410configured when @command{automake} itself is built. This is
1411@file{@@datadir@@/aclocal/}, which typically
1412expands to @file{$@{prefix@}/share/aclocal/}. To find the compiled-in
1413value of @var{acdir}, use the @code{--print-ac-dir} option
1414(@pxref{aclocal options}).
1415@end table
1416
1417As an example, suppose that automake-1.6.2 was configured with
1418@code{--prefix=/usr/local}. Then, the search path would be:
1419
1420@enumerate
1421@item @file{/usr/local/share/aclocal-1.6/}
1422@item @file{/usr/local/share/aclocal/}
1423@end enumerate
1424
1425As explained in (@pxref{aclocal options}), there are several options that
1426can be used to change or extend this search path.
1427
1428@subsection Modifying the macro search path: @code{--acdir}
1429
1430The most obvious option to modify the search path is
1431@code{--acdir=@var{dir}}, which changes default directory and
1432drops the @var{APIVERSION} directory. For example, if one specifies
1433@code{--acdir=/opt/private/}, then the search path becomes:
1434
1435@enumerate
1436@item @file{/opt/private/}
1437@end enumerate
1438
1439Note that this option, @code{--acdir}, is intended for use
1440by the internal automake test suite only; it is not ordinarily
1441needed by end-users.
1442
1443@subsection Modifying the macro search path: @code{-I @var{dir}}
1444
1445Any extra directories specified using @code{-I} options
1446(@pxref{aclocal options}) are @emph{prepended} to this search list. Thus,
1447@code{aclocal -I /foo -I /bar} results in the following search path:
1448
1449@enumerate
1450@item @file{/foo}
1451@item @file{/bar}
1452@item @var{acdir}-@var{APIVERSION}
1453@item @var{acdir}
1454@end enumerate
1455
1456@subsection Modifying the macro search path: @file{dirlist}
1457@cindex @file{dirlist}
1458
1459There is a third mechanism for customizing the search path. If a
1460@file{dirlist} file exists in @var{acdir}, then that file is assumed to
1461contain a list of directories, one per line, to be added to the search
1462list. These directories are searched @emph{after} all other
1463directories.
1464
1465For example, suppose
1466@file{@var{acdir}/dirlist} contains the following:
1467
1468@example
1469/test1
1470/test2
1471@end example
1472
1473@noindent
1474and that @code{aclocal} was called with the @code{-I /foo -I /bar} options.
1475Then, the search path would be
1476
1477@enumerate
1478@item @file{/foo}
1479@item @file{/bar}
1480@item @var{acdir}-@var{APIVERSION}
1481@item @var{acdir}
1482@item @file{/test1}
1483@item @file{/test2}
1484@end enumerate
1485
1486If the @code{--acdir=@var{dir}} option is used, then @command{aclocal}
1487will search for the @file{dirlist} file in @var{dir}. In the
1488@code{--acdir=/opt/private/} example above, @command{aclocal} would look
1489for @file{/opt/private/dirlist}. Again, however, the @code{--acdir}
1490option is intended for use by the internal automake test suite only;
1491@code{--acdir} is not ordinarily needed by end-users.
1492
1493@file{dirlist} is useful in the following situation: suppose that
1494@code{automake} version @code{1.6.2} is installed with
1495$prefix=/usr by the system vendor. Thus, the default search
1496directories are
1497
1498@enumerate
1499@item @file{/usr/share/aclocal-1.6/}
1500@item @file{/usr/share/aclocal/}
1501@end enumerate
1502
1503However, suppose further that many packages have been manually
1504installed on the system, with $prefix=/usr/local, as is typical.
1505In that case, many of these ``extra'' @file{.m4} files are in
1506@file{/usr/local/share/aclocal}. The only way to force
1507@file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files
1508is to always call @code{aclocal -I /usr/local/share/aclocal}.
1509This is inconvenient. With @file{dirlist}, one may create the file
1510
1511@file{/usr/share/aclocal/dirlist}
1512
1513@noindent
1514which contains only the single line
1515
1516@file{/usr/local/share/aclocal}
1517
1518Now, the ``default'' search path on the affected system is
1519
1520@enumerate
1521@item @file{/usr/share/aclocal-1.6/}
1522@item @file{/usr/share/aclocal/}
1523@item @file{/usr/local/share/aclocal/}
1524@end enumerate
1525
1526without the need for @code{-I} options; @code{-I} options can be reserved
1527for project-specific needs (@file{my-source-dir/m4/}), rather than
1528using it to work around local system-dependent tool installation
1529directories.
1530
1531Similarly, @file{dirlist} can be handy if you have installed a local
1532copy Automake on your account and want @command{aclocal} to look for
1533macros installed at other places on the system.
1534
1535@node Macros, Extending aclocal, Macro search path, configure
1536@section Autoconf macros supplied with Automake
1537
1538Automake ships with several Autoconf macros that you can use from your
1539@file{configure.in}. When you use one of them it will be included by
1540@code{aclocal} in @file{aclocal.m4}.
1541
1542@menu
1543* Public macros:: Macros that you can use.
1544* Private macros:: Macros that you should not use.
1545@end menu
1546
1547@c consider generating the following subsections automatically from m4 files.
1548
1549@node Public macros, Private macros, Macros, Macros
1550@subsection Public macros
1551
1552@table @code
1553@item AM_CONFIG_HEADER
1554Automake will generate rules to automatically regenerate the config
1555header. This obsolete macro is a synonym of @code{AC_CONFIG_HEADERS}
1556today (@pxref{Optional}).
1557@cvindex AM_CONFIG_HEADER
1558
1559@item AM_ENABLE_MULTILIB
1560This is used when a ``multilib'' library is being built. The first
1561optional argument is the name of the @file{Makefile} being generated; it
1562defaults to @samp{Makefile}. The second option argument is used to find
1563the top source directory; it defaults to the empty string (generally
1564this should not be used unless you are familiar with the internals).
1565@xref{Multilibs}.
1566
1567@item AM_C_PROTOTYPES
1568Check to see if function prototypes are understood by the compiler. If
1569so, define @samp{PROTOTYPES} and set the output variables @samp{U} and
1570@samp{ANSI2KNR} to the empty string. Otherwise, set @samp{U} to
1571@samp{_} and @samp{ANSI2KNR} to @samp{./ansi2knr}. Automake uses these
1572values to implement automatic de-ANSI-fication.
1573@cvindex AM_C_PROTOTYPES
1574
1575@item AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
1576If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
1577define @code{GWINSZ_IN_SYS_IOCTL}. Otherwise @code{TIOCGWINSZ} can be
1578found in @file{<termios.h>}.
1579@cvindex AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
1580
1581@item AM_INIT_AUTOMAKE([OPTIONS])
1582@itemx AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
1583Runs many macros required for proper operation of the generated Makefiles.
1584
1585This macro has two forms, the first of which is preferred.
1586In this form, @code{AM_INIT_AUTOMAKE} is called with a
1587single argument --- a space-separated list of Automake options which should
1588be applied to every @file{Makefile.am} in the tree. The effect is as if
1589each option were listed in @code{AUTOMAKE_OPTIONS}.
1590
1591The second, deprecated, form of @code{AM_INIT_AUTOMAKE} has two required
1592arguments: the package and the version number. This form is
1593obsolete because the @var{package} and @var{version} can be obtained
1594from Autoconf's @code{AC_INIT} macro (which itself has an old and a new
1595form).
1596
1597If your @file{configure.in} has:
1598@example
1599AC_INIT(src/foo.c)
1600AM_INIT_AUTOMAKE(mumble, 1.5)
1601@end example
1602you can modernize it as follows:
1603@example
1604AC_INIT(mumble, 1.5)
1605AC_CONFIG_SRCDIR(src/foo.c)
1606AM_INIT_AUTOMAKE
1607@end example
1608
1609Note that if you're upgrading your @file{configure.in} from an earlier
1610version of Automake, it is not always correct to simply move the package
1611and version arguments from @code{AM_INIT_AUTOMAKE} directly to
1612@code{AC_INIT}, as in the example above. The first argument to
1613@code{AC_INIT} should be the name of your package (e.g. @samp{GNU Automake}),
1614not the tarball name (e.g. @samp{automake}) that you used to pass to
1615@code{AM_INIT_AUTOMAKE}. Autoconf tries to derive a tarball name from
1616the package name, which should work for most but not all package names.
1617(If it doesn't work for yours, you can use the
1618four-argument form of @code{AC_INIT} --- supported in Autoconf versions
1619greater than 2.52g --- to provide the tarball name explicitly).
1620
1621By default this macro @code{AC_DEFINE}'s @samp{PACKAGE} and
1622@samp{VERSION}. This can be avoided by passing the @samp{no-define}
1623option, as in:
1624@example
1625AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
1626@end example
1627or by passing a third non-empty argument to the obsolete form.
1628
1629@cvindex PACKAGE, prevent definition
1630@cvindex VERSION, prevent definition
1631
1632
1633@item AM_PATH_LISPDIR
1634Searches for the program @code{emacs}, and, if found, sets the output
1635variable @code{lispdir} to the full path to Emacs' site-lisp directory.
1636
1637Note that this test assumes the @code{emacs} found to be a version that
1638supports Emacs Lisp (such as @sc{gnu} Emacs or XEmacs). Other emacsen
1639can cause this test to hang (some, like old versions of MicroEmacs,
1640start up in interactive mode, requiring @samp{C-x C-c} to exit, which
1641is hardly obvious for a non-emacs user). In most cases, however, you
1642should be able to use @samp{C-c} to kill the test. In order to avoid
1643problems, you can set @code{EMACS} to ``no'' in the environment, or
1644use the @samp{--with-lispdir} option to @command{configure} to
1645explicitly set the correct path (if you're sure you have an @code{emacs}
1646that supports Emacs Lisp.
1647@cvindex AM_PATH_LISPDIR
1648
1649@item AM_PROG_AS
1650Use this macro when you have assembly code in your project. This will
1651choose the assembler for you (by default the C compiler) and set
1652@code{CCAS}, and will also set @code{CCASFLAGS} if required.
1653
1654@item AM_PROG_CC_C_O
1655This is like @code{AC_PROG_CC_C_O}, but it generates its results in the
1656manner required by automake. You must use this instead of
1657@code{AC_PROG_CC_C_O} when you need this functionality.
1658
1659@item AM_PROG_CC_STDC
1660If the C compiler is not in ANSI C mode by default, try to add an option
1661to output variable @code{CC} to make it so. This macro tries various
1662options that select ANSI C on some system or another. It considers the
1663compiler to be in ANSI C mode if it handles function prototypes correctly.
1664
1665If you use this macro, you should check after calling it whether the C
1666compiler has been set to accept ANSI C; if not, the shell variable
1667@code{am_cv_prog_cc_stdc} is set to @samp{no}. If you wrote your source
1668code in ANSI C, you can make an un-ANSIfied copy of it by using the
1669@code{ansi2knr} option (@pxref{ANSI}).
1670
1671This macro is a relic from the time Autoconf didn't offer such a
1672feature. @code{AM_PROG_CC_STDC}'s logic has now been merged into
1673Autoconf's @code{AC_PROG_CC} macro, therefore you should use the latter
1674instead. Chances are you are already using @code{AC_PROG_CC}, so you
1675can simply remove the @code{AM_PROG_CC_STDC} call and turn all
1676occurrences of @code{$am_cv_prog_cc_stdc} into
1677@code{$ac_cv_prog_cc_stdc}. @code{AM_PROG_CC_STDC} will be marked as
1678obsolete (in the Autoconf sense) in Automake 1.8.
1679
1680@item AM_PROG_LEX
1681@cindex HP-UX 10, lex problems
1682@cindex lex problems with HP-UX 10
1683Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
1684Program Checks, autoconf, The Autoconf Manual}), but uses the
1685@code{missing} script on systems that do not have @code{lex}.
1686@samp{HP-UX 10} is one such system.
1687
1688@item AM_PROG_GCJ
1689This macro finds the @code{gcj} program or causes an error. It sets
1690@samp{GCJ} and @samp{GCJFLAGS}. @code{gcj} is the Java front-end to the
1691GNU Compiler Collection.
1692@cvindex AM_PROG_GCJ
1693
1694@item AM_SYS_POSIX_TERMIOS
1695@cvindex am_cv_sys_posix_termios
1696@cindex POSIX termios headers
1697@cindex termios POSIX headers
1698Check to see if POSIX termios headers and functions are available on the
1699system. If so, set the shell variable @code{am_cv_sys_posix_termios} to
1700@samp{yes}. If not, set the variable to @samp{no}.
1701
1702@item AM_WITH_DMALLOC
1703@cvindex WITH_DMALLOC
1704@cindex dmalloc, support for
1705@opindex --with-dmalloc
1706Add support for the
1707@uref{ftp://ftp.letters.com/src/dmalloc/dmalloc.tar.gz, dmalloc}
1708package. If the user configures with @samp{--with-dmalloc}, then define
1709@code{WITH_DMALLOC} and add @samp{-ldmalloc} to @code{LIBS}.
1710
1711@item AM_WITH_REGEX
1712@cvindex WITH_REGEX
1713@opindex --with-regex
1714@cindex regex package
1715@cindex rx package
1716Adds @samp{--with-regex} to the @code{configure} command line. If
1717specified (the default), then the @samp{regex} regular expression
1718library is used, @file{regex.o} is put into @samp{LIBOBJS}, and
1719@samp{WITH_REGEX} is defined. If @samp{--without-regex} is given, then
1720the @samp{rx} regular expression library is used, and @file{rx.o} is put
1721into @samp{LIBOBJS}.
1722
1723@end table
1724
1725@node Private macros, , Public macros, Macros
1726@subsection Private macros
1727
1728The following macros are private macros you should not call directly.
1729They are called by the other public macros when appropriate. Do not
1730rely on them, as they might be changed in a future version. Consider
1731them as implementation details; or better, do not consider them at all:
1732skip this section!
1733
1734@table @code
1735@item _AM_DEPENDENCIES
1736@itemx AM_SET_DEPDIR
1737@itemx AM_DEP_TRACK
1738@itemx AM_OUTPUT_DEPENDENCY_COMMANDS
1739These macros are used to implement Automake's automatic dependency
1740tracking scheme. They are called automatically by automake when
1741required, and there should be no need to invoke them manually.
1742
1743@item AM_MAKE_INCLUDE
1744This macro is used to discover how the user's @code{make} handles
1745@code{include} statements. This macro is automatically invoked when
1746needed; there should be no need to invoke it manually.
1747
1748@item AM_PROG_INSTALL_STRIP
1749This is used to find a version of @code{install} which can be used to
1750@code{strip} a program at installation time. This macro is
1751automatically included when required.
1752
1753@item AM_SANITY_CHECK
1754This checks to make sure that a file created in the build directory is
1755newer than a file in the source directory. This can fail on systems
1756where the clock is set incorrectly. This macro is automatically run
1757from @code{AM_INIT_AUTOMAKE}.
1758
1759@end table
1760
1761
1762
1763@node Extending aclocal, , Macros, configure
1764@section Writing your own aclocal macros
1765
1766@cindex aclocal, extending
1767@cindex Extending aclocal
1768
1769The @command{aclocal} program doesn't have any built-in knowledge of any
1770macros, so it is easy to extend it with your own macros.
1771
1772This can be used by libraries which want to supply their own Autoconf
1773macros for use by other programs. For instance the @command{gettext}
1774library supplies a macro @code{AM_GNU_GETTEXT} which should be used by
1775any package using @command{gettext}. When the library is installed, it
1776installs this macro so that @command{aclocal} will find it.
1777
1778A macro file's name should end in @file{.m4}. Such files should be
1779installed in @file{$(datadir)/aclocal}. This is as simple as writing:
1780
1781@example
1782aclocaldir = $(datadir)/aclocal
1783aclocal_DATA = mymacro.m4 myothermacro.m4
1784@end example
1785
1786A file of macros should be a series of properly quoted
1787@code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
1788Autoconf Manual}). The @command{aclocal} programs also understands
1789@code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
1790Autoconf Manual}), so it is safe to put each macro in a separate file.
1791Each file should have no side effects but macro definitions.
1792Especially, any call to @code{AC_PREREQ} should be done inside the
1793defined macro, not at the beginning of the file.
1794
1795@cindex underquoted AC_DEFUN
1796@cvindex AC_DEFUN
1797@cvindex AC_PREREQ
1798
1799Starting with Automake 1.8, @command{aclocal} will warn about all
1800underquoted calls to @code{AC_DEFUN}. We realize this will annoy a
1801lot of people, because @command{aclocal} was not so strict in the past
1802and many third party macros are underquoted; and we have to apologize
1803for this temporary inconvenience. The reason we have to be stricter
1804is that a future implementation of @command{aclocal} will have to
1805temporary include all these third party @file{.m4} files, maybe
1806several times, even those which are not actually needed. Doing so
1807should alleviate many problem of the current implementation, however
1808it requires a stricter style from the macro authors. Hopefully it is
1809easy to revise the existing macros. For instance
1810@example
1811# bad style
1812AC_PREREQ(2.57)
1813AC_DEFUN(AX_FOOBAR,
1814[AC_REQUIRE([AX_SOMETHING])dnl
1815AX_FOO
1816AX_BAR
1817])
1818@end example
1819@noindent
1820should be rewritten as
1821@example
1822AC_DEFUN([AX_FOOBAR],
1823[AC_PREREQ(2.57)dnl
1824AC_REQUIRE([AX_SOMETHING])dnl
1825AX_FOO
1826AX_BAR
1827])
1828@end example
1829
1830Wrapping the @code{AC_PREREQ} call inside the macro ensures that
1831Autoconf 2.57 will not be required if @code{AX_FOOBAR} is not actually
1832used. Most importantly, quoting the first argument of @code{AC_DEFUN}
1833allows the macro to be redefined or included twice (otherwise this
1834first argument would be expansed during the second definition).
1835
1836If you have been directed here by the @command{aclocal} diagnostic but
1837are not the maintainer of the implicated macro, you will want to
1838contact the maintainer of that macro. Please make sure you have the
1839last version of the macro and that the problem already hasn't been
1840reported before doing so: people tend to work faster when they aren't
1841flooded by mails.
1842
1843
1844@node Top level, Alternative, configure, Top
1845@chapter The top-level @file{Makefile.am}
1846
1847@section Recursing subdirectories
1848
1849@cindex SUBDIRS, explained
1850
1851In packages with subdirectories, the top level @file{Makefile.am} must
1852tell Automake which subdirectories are to be built. This is done via
1853the @code{SUBDIRS} variable.
1854@vindex SUBDIRS
1855
1856The @code{SUBDIRS} variable holds a list of subdirectories in which
1857building of various sorts can occur. Many targets (e.g. @code{all}) in
1858the generated @file{Makefile} will run both locally and in all specified
1859subdirectories. Note that the directories listed in @code{SUBDIRS} are
1860not required to contain @file{Makefile.am}s; only @file{Makefile}s
1861(after configuration). This allows inclusion of libraries from packages
1862which do not use Automake (such as @code{gettext}).
1863
1864In packages that use subdirectories, the top-level @file{Makefile.am} is
1865often very short. For instance, here is the @file{Makefile.am} from the
1866GNU Hello distribution:
1867
1868@example
1869EXTRA_DIST = BUGS ChangeLog.O README-alpha
1870SUBDIRS = doc intl po src tests
1871@end example
1872
1873When Automake invokes @code{make} in a subdirectory, it uses the value
1874of the @code{MAKE} variable. It passes the value of the variable
1875@code{AM_MAKEFLAGS} to the @code{make} invocation; this can be set in
1876@file{Makefile.am} if there are flags you must always pass to
1877@code{make}.
1878@vindex MAKE
1879@vindex MAKEFLAGS
1880
1881The directories mentioned in @code{SUBDIRS} must be direct children of
1882the current directory. For instance, you cannot put @samp{src/subdir}
1883into @code{SUBDIRS}. Instead you should put @code{SUBDIRS = subdir}
1884into @file{src/Makefile.am}. Automake can be used to construct packages
1885of arbitrary depth this way.
1886
1887By default, Automake generates @file{Makefiles} which work depth-first
1888(@samp{postfix}). However, it is possible to change this ordering. You
1889can do this by putting @samp{.} into @code{SUBDIRS}. For instance,
1890putting @samp{.} first will cause a @samp{prefix} ordering of
1891directories. All @samp{clean} targets are run in reverse order of build
1892targets.
1893
1894@section Conditional subdirectories
1895@cindex Subdirectories, building conditionally
1896@cindex Conditional subdirectories
1897@cindex @code{SUBDIRS}, conditional
1898@cindex Conditional @code{SUBDIRS}
1899
1900It is possible to define the @code{SUBDIRS} variable conditionally if,
1901like in the case of GNU @code{Inetutils}, you want to only build a
1902subset of the entire package.
1903
1904To illustrate how this works, let's assume we have two directories
1905@file{src/} and @file{opt/}. @file{src/} should always be built, but we
1906want to decide in @code{./configure} whether @file{opt/} will be built
1907or not. (For this example we will assume that @file{opt/} should be
1908built when the variable @code{$want_opt} was set to @code{yes}.)
1909
1910Running @code{make} should thus recurse into @file{src/} always, and
1911then maybe in @file{opt/}.
1912
1913However @code{make dist} should always recurse into both @file{src/} and
1914@file{opt/}. Because @file{opt/} should be distributed even if it is
1915not needed in the current configuration. This means @file{opt/Makefile}
1916should be created unconditionally. @footnote{Don't try seeking a
1917solution where @file{opt/Makefile} is created conditionally, this is a
1918lot trickier than the solutions presented here.}
1919
1920There are two ways to setup a project like this. You can use Automake
1921conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
1922variables (@pxref{Setting Output Variables, , Setting Output Variables,
1923autoconf, The Autoconf Manual}). Using Automake conditionals is the
1924preferred solution.
1925
1926@subsection Conditional subdirectories with @code{AM_CONDITIONAL}
1927@cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
1928@cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
1929
1930@c The test case for the setup described here is
1931@c test/subdircond2.test
1932@c Try to keep it in sync.
1933
1934@file{configure} should output the @file{Makefile} for each directory
1935and define a condition into which @file{opt/} should be built.
1936
1937@example
1938@dots{}
1939AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
1940AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
1941@dots{}
1942@end example
1943
1944Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
1945as follows.
1946
1947@example
1948if COND_OPT
1949 MAYBE_OPT = opt
1950endif
1951SUBDIRS = src $(MAYBE_OPT)
1952@end example
1953
1954As you can see, running @code{make} will rightly recurse into
1955@file{src/} and maybe @file{opt/}.
1956
1957@vindex DIST_SUBDIRS
1958As you can't see, running @code{make dist} will recurse into both
1959@file{src/} and @file{opt/} directories because @code{make dist}, unlike
1960@code{make all}, doesn't use the @code{SUBDIRS} variable. It uses the
1961@code{DIST_SUBDIRS} variable.
1962
1963In this case Automake will define @code{DIST_SUBDIRS = src opt}
1964automatically because it knows that @code{MAYBE_OPT} can contain
1965@code{opt} in some condition.
1966
1967@subsection Conditional subdirectories with @code{AC_SUBST}
1968@cindex @code{SUBDIRS} and @code{AC_SUBST}
1969@cindex @code{AC_SUBST} and @code{SUBDIRS}
1970
1971@c The test case for the setup described here is
1972@c test/subdircond3.test
1973@c Try to keep it in sync.
1974
1975Another idea is to define @code{MAYBE_OPT} from @file{./configure} using
1976@code{AC_SUBST}:
1977
1978@example
1979@dots{}
1980if test "$want_opt" = yes; then
1981 MAYBE_OPT=opt
1982else
1983 MAYBE_OPT=
1984fi
1985AC_SUBST([MAYBE_OPT])
1986AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
1987@dots{}
1988@end example
1989
1990In this case the top-level @file{Makefile.am} should look as follows.
1991
1992@example
1993SUBDIRS = src $(MAYBE_OPT)
1994DIST_SUBDIRS = src opt
1995@end example
1996
1997The drawback is that since Automake cannot guess what the possible
1998values of @code{MAYBE_OPT} are, it is necessary to define
1999@code{DIST_SUBDIRS}.
2000
2001@subsection How @code{DIST_SUBDIRS} is used
2002@cindex @code{DIST_SUBDIRS}, explained
2003
2004As shown in the above examples, @code{DIST_SUBDIRS} is used by targets
2005that need to recurse in all directories, even those which have been
2006conditionally left out of the build.
2007
2008Precisely, @code{DIST_SUBDIRS} is used by @code{make dist}, @code{make
2009distclean}, and @code{make maintainer-clean}. All other recursive
2010targets use @code{SUBDIRS}.
2011
2012Automake will define @code{DIST_SUBDIRS} automatically from the
2013possibles values of @code{SUBDIRS} in all conditions.
2014
2015If @code{SUBDIRS} contains @code{AC_SUBST} variables,
2016@code{DIST_SUBDIRS} will not be defined correctly because Automake
2017doesn't know the possible values of these variables. In this case
2018@code{DIST_SUBDIRS} needs to be defined manually.
2019
2020
2021@node Alternative, Rebuilding, Top level, Top
2022@chapter An Alternative Approach to Subdirectories
2023
2024If you've ever read Peter Miller's excellent paper,
2025@uref{http://www.pcug.org.au/~millerp/rmch/recu-make-cons-harm.html,
2026Recursive Make Considered Harmful}, the preceding section on the use of
2027subdirectories will probably come as unwelcome advice. For those who
2028haven't read the paper, Miller's main thesis is that recursive
2029@code{make} invocations are both slow and error-prone.
2030
2031Automake provides sufficient cross-directory support @footnote{We
2032believe. This work is new and there are probably warts.
2033@xref{Introduction}, for information on reporting bugs.} to enable you
2034to write a single @file{Makefile.am} for a complex multi-directory
2035package.
2036
2037
2038By default an installable file specified in a subdirectory will have its
2039directory name stripped before installation. For instance, in this
2040example, the header file will be installed as
2041@file{$(includedir)/stdio.h}:
2042
2043@example
2044include_HEADERS = inc/stdio.h
2045@end example
2046
2047@cindex nobase_
2048@cindex Path stripping, avoiding
2049@cindex Avoiding path stripping
2050
2051However, the @samp{nobase_} prefix can be used to circumvent this path
2052stripping. In this example, the header file will be installed as
2053@file{$(includedir)/sys/types.h}:
2054
2055@example
2056nobase_include_HEADERS = sys/types.h
2057@end example
2058
2059@cindex nobase_ and dist_ or nodist_
2060@cindex dist_ and nobase_
2061@cindex nodist_ and nobase_
2062
2063@samp{nobase_} should be specified first when used in conjunction with
2064either @samp{dist_} or @samp{nodist_} (@pxref{Dist}). For instance:
2065
2066@example
2067nobase_dist_pkgdata_DATA = images/vortex.pgm
2068@end example
2069
2070@node Rebuilding, Programs, Alternative, Top
2071@chapter Rebuilding Makefiles
2072
2073Automake generates rules to automatically rebuild @file{Makefile}s,
2074@file{configure}, and other derived files like @file{Makefile.in}.
2075
2076If you are using @code{AM_MAINTAINER_MODE} in @file{configure.in}, then
2077these automatic rebuilding rules are only enabled in maintainer mode.
2078
2079Sometimes you need to run @code{aclocal} with an argument like @code{-I}
2080to tell it where to find @file{.m4} files. Since sometimes @code{make}
2081will automatically run @code{aclocal}, you need a way to specify these
2082arguments. You can do this by defining @code{ACLOCAL_AMFLAGS}; this
2083holds arguments which are passed verbatim to @code{aclocal}. This variable
2084is only useful in the top-level @file{Makefile.am}.
2085@vindex ACLOCAL_AMFLAGS
2086
2087
2088@node Programs, Other objects, Rebuilding, Top
2089@chapter Building Programs and Libraries
2090
2091A large part of Automake's functionality is dedicated to making it easy
2092to build programs and libraries.
2093
2094@menu
2095* A Program:: Building a program
2096* A Library:: Building a library
2097* A Shared Library:: Building a Libtool library
2098* Program and Library Variables:: Variables controlling program and
2099 library builds
2100* LIBOBJS:: Special handling for LIBOBJS and ALLOCA
2101* Program variables:: Variables used when building a program
2102* Yacc and Lex:: Yacc and Lex support
2103* C++ Support::
2104* Assembly Support::
2105* Fortran 77 Support::
2106* Java Support::
2107* Support for Other Languages::
2108* ANSI:: Automatic de-ANSI-fication
2109* Dependencies:: Automatic dependency tracking
2110* EXEEXT:: Support for executable extensions
2111@end menu
2112
2113
2114@node A Program, A Library, Programs, Programs
2115@section Building a program
2116
2117In order to build a program, you need to tell Automake which sources
2118are part of it, and which libraries it should be linked with.
2119
2120This section also covers conditional compilation of sources or
2121programs. Most of the comments about these also apply to libraries
2122(@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
2123
2124@menu
2125* Program Sources:: Defining program sources
2126* Linking:: Linking with libraries or extra objects
2127* Conditional Sources:: Handling conditional sources
2128* Conditional Programs:: Building program conditionally
2129@end menu
2130
2131@node Program Sources, Linking, A Program, A Program
2132@subsection Defining program sources
2133
2134@cindex PROGRAMS, bindir
2135@vindex bin_PROGRAMS
2136@vindex sbin_PROGRAMS
2137@vindex libexec_PROGRAMS
2138@vindex pkglib_PROGRAMS
2139@vindex noinst_PROGRAMS
2140@vindex check_PROGRAMS
2141
2142In a directory containing source that gets built into a program (as
2143opposed to a library or a script), the @samp{PROGRAMS} primary is used.
2144Programs can be installed in @code{bindir}, @code{sbindir},
2145@code{libexecdir}, @code{pkglibdir}, or not at all (@samp{noinst}).
2146They can also be built only for @code{make check}, in which case the
2147prefix is @samp{check}.
2148
2149For instance:
2150
2151@example
2152bin_PROGRAMS = hello
2153@end example
2154
2155In this simple case, the resulting @file{Makefile.in} will contain code
2156to generate a program named @code{hello}.
2157
2158Associated with each program are several assisting variables which are
2159named after the program. These variables are all optional, and have
2160reasonable defaults. Each variable, its use, and default is spelled out
2161below; we use the ``hello'' example throughout.
2162
2163The variable @code{hello_SOURCES} is used to specify which source files
2164get built into an executable:
2165
2166@example
2167hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
2168@end example
2169
2170This causes each mentioned @samp{.c} file to be compiled into the
2171corresponding @samp{.o}. Then all are linked to produce @file{hello}.
2172
2173@cindex _SOURCES primary, defined
2174@cindex SOURCES primary, defined
2175@cindex Primary variable, SOURCES
2176
2177If @samp{hello_SOURCES} is not specified, then it defaults to the single
2178file @file{hello.c}; that is, the default is to compile a single C file
2179whose base name is the name of the program itself. (This is a terrible
2180default but we are stuck with it for historical reasons.)
2181@vindex _SOURCES
2182@vindex SOURCES
2183
2184Multiple programs can be built in a single directory. Multiple programs
2185can share a single source file, which must be listed in each
2186@samp{_SOURCES} definition.
2187
2188@cindex Header files in _SOURCES
2189@cindex _SOURCES and header files
2190
2191Header files listed in a @samp{_SOURCES} definition will be included in
2192the distribution but otherwise ignored. In case it isn't obvious, you
2193should not include the header file generated by @file{configure} in a
2194@samp{_SOURCES} variable; this file should not be distributed. Lex
2195(@samp{.l}) and Yacc (@samp{.y}) files can also be listed; see @ref{Yacc
2196and Lex}.
2197
2198
2199@node Linking, Conditional Sources, Program Sources, A Program
2200@subsection Linking the program
2201
2202If you need to link against libraries that are not found by
2203@code{configure}, you can use @code{LDADD} to do so. This variable is
2204used to specify additional objects or libraries to link with; it is
2205inappropriate for specifying specific linker flags, you should use
2206@code{AM_LDFLAGS} for this purpose.
2207@vindex LDADD
2208@vindex AM_LDFLAGS
2209
2210@cindex prog_LDADD, defined
2211
2212Sometimes, multiple programs are built in one directory but do not share
2213the same link-time requirements. In this case, you can use the
2214@samp{@var{prog}_LDADD} variable (where @var{prog} is the name of the
2215program as it appears in some @samp{_PROGRAMS} variable, and usually
2216written in lowercase) to override the global @code{LDADD}. If this
2217variable exists for a given program, then that program is not linked
2218using @code{LDADD}.
2219@vindex _LDADD
2220
2221For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
2222linked against the library @file{libcpio.a}. However, @code{rmt} is
2223built in the same directory, and has no such link requirement. Also,
2224@code{mt} and @code{rmt} are only built on certain architectures. Here
2225is what cpio's @file{src/Makefile.am} looks like (abridged):
2226
2227@example
2228bin_PROGRAMS = cpio pax @@MT@@
2229libexec_PROGRAMS = @@RMT@@
2230EXTRA_PROGRAMS = mt rmt
2231
2232LDADD = ../lib/libcpio.a @@INTLLIBS@@
2233rmt_LDADD =
2234
2235cpio_SOURCES = @dots{}
2236pax_SOURCES = @dots{}
2237mt_SOURCES = @dots{}
2238rmt_SOURCES = @dots{}
2239@end example
2240
2241@cindex _LDFLAGS, defined
2242
2243@samp{@var{prog}_LDADD} is inappropriate for passing program-specific
2244linker flags (except for @samp{-l}, @samp{-L}, @samp{-dlopen} and
2245@samp{-dlpreopen}). So, use the @samp{@var{prog}_LDFLAGS} variable for
2246this purpose.
2247@vindex _LDFLAGS
2248
2249@cindex _DEPENDENCIES, defined
2250
2251It is also occasionally useful to have a program depend on some other
2252target which is not actually part of that program. This can be done
2253using the @samp{@var{prog}_DEPENDENCIES} variable. Each program depends
2254on the contents of such a variable, but no further interpretation is
2255done.
2256
2257If @samp{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
2258Automake. The automatically-assigned value is the contents of
2259@samp{@var{prog}_LDADD}, with most configure substitutions, @samp{-l},
2260@samp{-L}, @samp{-dlopen} and @samp{-dlpreopen} options removed. The
2261configure substitutions that are left in are only @samp{@@LIBOBJS@@} and
2262@samp{@@ALLOCA@@}; these are left because it is known that they will not
2263cause an invalid value for @samp{@var{prog}_DEPENDENCIES} to be
2264generated.
2265
2266
2267@node Conditional Sources, Conditional Programs, Linking, A Program
2268@subsection Conditional compilation of sources
2269
2270You can't put a configure substitution (e.g., @samp{@@FOO@@}) into a
2271@samp{_SOURCES} variable. The reason for this is a bit hard to explain,
2272but suffice to say that it simply won't work. Automake will give an
2273error if you try to do this.
2274
2275Fortunately there are two other ways to achieve the same result. One is
2276to use configure substitutions in @code{_LDADD} variables, the other is
2277to use an Automake conditional.
2278
2279@subsubsection Conditional compilation using @code{_LDADD} substitutions
2280
2281@cindex EXTRA_prog_SOURCES, defined
2282
2283Automake must know all the source files that could possibly go into a
2284program, even if not all the files are built in every circumstance. Any
2285files which are only conditionally built should be listed in the
2286appropriate @samp{EXTRA_} variable. For instance, if
2287@file{hello-linux.c} or @file{hello-generic.c} were conditionally included
2288in @code{hello}, the @file{Makefile.am} would contain:
2289
2290@example
2291bin_PROGRAMS = hello
2292hello_SOURCES = hello-common.c
2293EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
2294hello_LDADD = @@HELLO_SYSTEM@@
2295hello_DEPENDENCIES = @@HELLO_SYSTEM@@
2296@end example
2297
2298@noindent
2299You can then setup the @code{@@HELLO_SYSTEM@@} substitution from
2300@file{configure.in}:
2301
2302@example
2303@dots{}
2304case $host in
2305 *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
2306 *) HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
2307esac
2308AC_SUBST([HELLO_SYSTEM])
2309@dots{}
2310@end example
2311
2312In this case, @code{HELLO_SYSTEM} should be replaced by
2313@file{hello-linux.o} or @file{hello-bsd.o}, and added to
2314@code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be built
2315and linked in.
2316
2317@subsubsection Conditional compilation using Automake conditionals
2318
2319An often simpler way to compile source files conditionally is to use
2320Automake conditionals. For instance, you could use this
2321@file{Makefile.am} construct to build the same @file{hello} example:
2322
2323@example
2324bin_PROGRAMS = hello
2325if LINUX
2326hello_SOURCES = hello-linux.c hello-common.c
2327else
2328hello_SOURCES = hello-generic.c hello-common.c
2329endif
2330@end example
2331
2332In this case, your @file{configure.in} should setup the @code{LINUX}
2333conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
2334
2335When using conditionals like this you don't need to use the
2336@samp{EXTRA_} variable, because Automake will examine the contents of
2337each variable to construct the complete list of source files.
2338
2339If your program uses a lot of files, you will probably prefer a
2340conditional @code{+=}.
2341
2342@example
2343bin_PROGRAMS = hello
2344hello_SOURCES = hello-common.c
2345if LINUX
2346hello_SOURCES += hello-linux.c
2347else
2348hello_SOURCES += hello-generic.c
2349endif
2350@end example
2351
2352@node Conditional Programs, , Conditional Sources, A Program
2353@subsection Conditional compilation of programs
2354@cindex Conditional programs
2355@cindex Programs, conditional
2356
2357Sometimes it is useful to determine the programs that are to be built
2358at configure time. For instance, GNU @code{cpio} only builds
2359@code{mt} and @code{rmt} under special circumstances. The means to
2360achieve conditional compilation of programs are the same you can use
2361to compile source files conditionally: substitutions or conditionals.
2362
2363@subsubsection Conditional programs using @code{configure} substitutions
2364
2365In this case, you must notify Automake of all the programs that can
2366possibly be built, but at the same time cause the generated
2367@file{Makefile.in} to use the programs specified by @code{configure}.
2368This is done by having @code{configure} substitute values into each
2369@samp{_PROGRAMS} definition, while listing all optionally built programs
2370in @code{EXTRA_PROGRAMS}.
2371@vindex EXTRA_PROGRAMS
2372@cindex EXTRA_PROGRAMS, defined
2373
2374@example
2375bin_PROGRAMS = cpio pax $(MT)
2376libexec_PROGRAMS = $(RMT)
2377EXTRA_PROGRAMS = mt rmt
2378@end example
2379
2380As explained in @ref{EXEEXT}, Automake will rewrite
2381@code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
2382@code{EXTRA_PROGRAMS}, appending @code{$(EXEEXT)} to each binary.
2383Obviously it cannot rewrite values obtained at run-time through
2384@code{configure} substitutions, therefore you should take care of
2385appending @code{$(EXEEXT)} yourself, as in @code{AC_SUBST([MT],
2386['mt$@{EXEEXT@}'])}.
2387
2388@subsubsection Conditional programs using Automake conditionals
2389
2390You can also use Automake conditionals (@pxref{Conditionals}) to
2391select programs to be built. In this case you don't have to worry
2392about @code{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
2393
2394@example
2395bin_PROGRAMS = cpio pax
2396if WANT_MT
2397 bin_PROGRAMS += mt
2398endif
2399if WANT_RMT
2400 libexec_PROGRAMS = rmt
2401endif
2402@end example
2403
2404
2405@node A Library, A Shared Library, A Program, Programs
2406@section Building a library
2407
2408@cindex _LIBRARIES primary, defined
2409@cindex LIBRARIES primary, defined
2410@cindex Primary variable, LIBRARIES
2411
2412@vindex lib_LIBRARIES
2413@vindex pkglib_LIBRARIES
2414@vindex noinst_LIBRARIES
2415
2416Building a library is much like building a program. In this case, the
2417name of the primary is @samp{LIBRARIES}. Libraries can be installed in
2418@code{libdir} or @code{pkglibdir}.
2419
2420@xref{A Shared Library}, for information on how to build shared
2421libraries using libtool and the @samp{LTLIBRARIES} primary.
2422
2423Each @samp{_LIBRARIES} variable is a list of the libraries to be built.
2424For instance to create a library named @file{libcpio.a}, but not install
2425it, you would write:
2426
2427@example
2428noinst_LIBRARIES = libcpio.a
2429@end example
2430
2431The sources that go into a library are determined exactly as they are
2432for programs, via the @samp{_SOURCES} variables. Note that the library
2433name is canonicalized (@pxref{Canonicalization}), so the @samp{_SOURCES}
2434variable corresponding to @file{liblob.a} is @samp{liblob_a_SOURCES},
2435not @samp{liblob.a_SOURCES}.
2436
2437@cindex _LIBADD primary, defined
2438@cindex LIBADD primary, defined
2439@cindex Primary variable, LIBADD
2440
2441Extra objects can be added to a library using the
2442@samp{@var{library}_LIBADD} variable. This should be used for objects
2443determined by @code{configure}. Again from @code{cpio}:
2444@vindex _LIBADD
2445@vindex LIBADD
2446
2447@example
2448libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
2449@end example
2450
2451In addition, sources for extra objects that will not exist until
2452configure-time must be added to the @code{BUILT_SOURCES} variable
2453(@pxref{Sources}).
2454
2455
2456@node A Shared Library, Program and Library Variables, A Library, Programs
2457@section Building a Shared Library
2458
2459@cindex Shared libraries, support for
2460
2461Building shared libraries portably is a relatively complex matter.
2462For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
2463Libtool Manual}) was created to help build shared libraries in a
2464platform-independent way.
2465
2466@menu
2467* Libtool Concept:: Introducing Libtool
2468* Libtool Libraries:: Declaring Libtool Libraries
2469* Conditional Libtool Libraries:: Building Libtool Libraries Conditionally
2470* Conditional Libtool Sources:: Choosing Library Sources Conditionally
2471* Libtool Convenience Libraries:: Building Convenience Libtool Libraries
2472* Libtool Modules:: Building Libtool Modules
2473* Libtool Flags:: Using _LIBADD and _LDFLAGS
2474* LTLIBOBJ:: Using $(LTLIBOBJ)
2475* Libtool Issues:: Common Issues Related to Libtool's Use
2476@end menu
2477
2478@node Libtool Concept, Libtool Libraries, A Shared Library, A Shared Library
2479@subsection The Libtool Concept
2480
2481@cindex libtool, introduction
2482@cindex libtool library, definition
2483@cindex suffix .la, defined
2484@cindex .la suffix, defined
2485
2486Libtool abstracts shared and static libraries into a unified
2487concept henceforth called @dfn{libtool libraries}. Libtool libraries
2488are files using the @file{.la} suffix, and can designate a static
2489library, a shared library, or maybe both. Their exact nature cannot
2490be determined until @file{./configure} is run: not all platforms
2491support all kinds of libraries, and users can explicitly select which
2492libraries should be built. (However the package's maintainers can
2493tune the default, @xref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
2494macro, libtool, The Libtool Manual}.)
2495
2496@cindex suffix .lo, defined
2497Because object files for shared and static libraries must be compiled
2498differently, libtool is also used during compilation. Object files
2499built by libtool are called @dfn{libtool objects}: these are files
2500using the @file{.lo} suffix. Libtool libraries are built from these
2501libtool objects.
2502
2503You should not assume anything about the structure of @file{.la} or
2504@file{.lo} files and how libtool constructs them: this is libtool's
2505concern, and the last thing one wants is to learn about libtool's
2506guts. However the existence of these files matters, because they are
2507used as targets and dependencies in @file{Makefile}s when building
2508libtool libraries. There are situations where you may have to refer
2509to these, for instance when expressing dependencies for building
2510source files conditionally (@pxref{Conditional Libtool Sources}).
2511
2512@cindex libltdl, introduction
2513
2514People considering writing a plug-in system, with dynamically loaded
2515modules, should look into @file{libltdl}: libtool's dlopening library
2516(@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
2517This offers a portable dlopening facility to load libtool libraries
2518dynamically, and can also achieve static linking where unavoidable.
2519
2520Before we discuss how to use libtool with Automake in details, it
2521should be noted that the libtool manual also has a section about how
2522to use Automake with libtool (@pxref{Using Automake, , Using Automake
2523with Libtool, libtool, The Libtool Manual}).
2524
2525@node Libtool Libraries, Conditional Libtool Libraries, Libtool Concept, A Shared Library
2526@subsection Building Libtool Libraries
2527
2528@cindex _LTLIBRARIES primary, defined
2529@cindex LTLIBRARIES primary, defined
2530@cindex Primary variable, LTLIBRARIES
2531@cindex Example of shared libraries
2532@vindex lib_LTLIBRARIES
2533@vindex pkglib_LTLIBRARIES
2534
2535Automake uses libtool to build libraries declared with the
2536@samp{LTLIBRARIES} primary. Each @samp{_LTLIBRARIES} variable is a
2537list of libtool libraries to build. For instance, to create a libtool
2538library named @file{libgettext.la}, and install it in @samp{libdir},
2539write:
2540
2541@example
2542lib_LTLIBRARIES = libgettext.la
2543libgettext_la_SOURCES = gettext.c gettext.h @dots{}
2544@end example
2545
2546Automake predefines the variable @samp{pkglibdir}, so you can use
2547@code{pkglib_LTLIBRARIES} to install libraries in
2548@code{$(libdir)/@@PACKAGE@@/}.
2549
2550@node Conditional Libtool Libraries, Conditional Libtool Sources, Libtool Libraries, A Shared Library
2551@subsection Building Libtool Libraries Conditionally
2552@cindex libtool libraries, conditional
2553@cindex conditional libtool libraries
2554
2555Like conditional programs (@pxref{Conditional Programs}), there are
2556two main ways to build conditional libraries: using Automake
2557conditionals or using Autoconf @code{AC_SUBST}itutions.
2558
2559The important implementation detail you have to be aware of is that
2560the place where a library will be installed matters to libtool: it
2561needs to be indicated @emph{at link-time} using the @code{-rpath}
2562option.
2563
2564For libraries whose destination directory is known when Automake runs,
2565Automake will automatically supply the appropriate @samp{-rpath}
2566option to libtool. This is the case for libraries listed explicitly in
2567some installable @code{_LTLIBRARIES} variables such as
2568@code{lib_LTLIBRARIES}.
2569
2570However, for libraries determined at configure time (and thus
2571mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
2572final installation directory. For such libraries you must add the
2573@samp{-rpath} option to the appropriate @samp{_LDFLAGS} variable by
2574hand.
2575
2576The examples below illustrate the differences between these two methods.
2577
2578Here is an example where @code{$(WANTEDLIBS)} is an @code{AC_SUBST}ed
2579variable set at @file{./configure}-time to either @file{libfoo.la},
2580@file{libbar.la}, both, or none. Although @code{$(WANTEDLIBS)}
2581appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
2582relates to @file{libfoo.la} or @file{libbar.la} by the time it creates
2583the link rule for these two libraries. Therefore the @code{-rpath}
2584argument must be explicitly supplied.
2585
2586@example
2587EXTRA_LTLIBRARIES = libfoo.la libbar.la
2588lib_LTLIBRARIES = $(WANTEDLIBS)
2589libfoo_la_SOURCES = foo.c @dots{}
2590libfoo_la_LDFLAGS = -rpath '$(libdir)'
2591libbar_la_SOURCES = bar.c @dots{}
2592libbar_la_LDFLAGS = -rpath '$(libdir)'
2593@end example
2594
2595Here is how the same @file{Makefile.am} would look using Automake
2596conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}. Now
2597Automake is able to compute the @code{-rpath} setting itself, because
2598it's clear that both libraries will end up in @code{$(libdir)} if they
2599are installed.
2600
2601@example
2602lib_LTLIBRARIES =
2603if WANT_LIBFOO
2604lib_LTLIBRARIES += libfoo.la
2605endif
2606if WANT_LIBBAR
2607lib_LTLIBRARIES += libbar.la
2608endif
2609libfoo_la_SOURCES = foo.c @dots{}
2610libbar_la_SOURCES = bar.c @dots{}
2611@end example
2612
2613@node Conditional Libtool Sources, Libtool Convenience Libraries, Conditional Libtool Libraries, A Shared Library
2614@subsection Libtool Libraries with Conditional Sources
2615
2616Conditional compilation of sources in a library can be achieved in the
2617same way as conditional compilation of sources in a program
2618(@pxref{Conditional Sources}). The only difference is that
2619@code{_LIBADD} should be used instead of @code{_LDADD} and that it
2620should mention libtool objects (@file{.lo} files).
2621
2622So, to mimic the @file{hello} example from @ref{Conditional Sources},
2623we could build a @file{libhello.la} library using either
2624@file{hello-linux.c} or @file{hello-generic.c} with the following
2625@file{Makefile.am}.
2626
2627@example
2628lib_LTLIBRARIES = libhello.la
2629libhello_la_SOURCES = hello-common.c
2630EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
2631libhello_la_LIBADD = $(HELLO_SYSTEM)
2632libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
2633@end example
2634
2635@noindent
2636And make sure @code{$(HELLO_SYSTEM)} is set to either
2637@file{hello-linux.lo} or @file{hello-generic.lo} in
2638@file{./configure}.
2639
2640Or we could simply use an Automake conditional as follows.
2641
2642@example
2643lib_LTLIBRARIES = libhello.la
2644libhello_la_SOURCES = hello-common.c
2645if LINUX
2646libhello_la_SOURCES += hello-linux.c
2647else
2648libhello_la_SOURCES += hello-generic.c
2649endif
2650@end example
2651
2652@node Libtool Convenience Libraries, Libtool Modules, Conditional Libtool Sources, A Shared Library
2653@subsection Libtool Convenience Libraries
2654@cindex convenience libraries, libtool
2655@cindex libtool convenience libraries
2656@vindex noinst_LTLIBRARIES
2657@vindex check_LTLIBRARIES
2658
2659Sometimes you want to build libtool libraries which should not be
2660installed. These are called @dfn{libtool convenience libraries} and
2661are typically used to encapsulate many sublibraries, later gathered
2662into one big installed library.
2663
2664Libtool convenience libraries are declared by
2665@code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
2666@code{EXTRA_LTLIBRARIES}. Unlike installed libtool libraries they do
2667not need an @code{-rpath} flag at link time (actually this is the only
2668difference).
2669
2670Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
2671built. Those listed in @code{check_LTLIBRARIES} are built only upon
2672@code{make check}. Finally, libraries listed in
2673@code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
2674rules to build them, but if the library does not appear as a Makefile
2675dependency anywhere it won't be built (this is why
2676@code{EXTRA_LTLIBRARIES} is used for conditional compilation).
2677
2678Here is a sample setup merging libtool convenience libraries from
2679subdirectories into one main @file{libtop.la} library.
2680
2681@example
2682# -- Top-level Makefile.am --
2683SUBDIRS = sub1 sub2 @dots{}
2684lib_LTLIBRARIES = libtop.la
2685libtop_la_SOURCES =
2686libtop_la_LIBADD = \
2687 sub1/libsub1.la \
2688 sub2/libsub2.la \
2689 @dots{}
2690
2691# -- sub1/Makefile.am --
2692noinst_LTLIBRARIES = libsub1.la
2693libsub1_la_SOURCES = @dots{}
2694
2695# -- sub2/Makefile.am --
2696# showing nested convenience libraries
2697SUBDIRS = sub2.1 sub2.2 @dots{}
2698noinst_LTLIBRARIES = libsub2.la
2699libsub2_la_SOURCES =
2700libsub2_la_LIBADD = \
2701 sub21/libsub21.la \
2702 sub22/libsub22.la \
2703 @dots{}
2704@end example
2705
2706@node Libtool Modules, Libtool Flags, Libtool Convenience Libraries, A Shared Library
2707@subsection Libtool Modules
2708@cindex modules, libtool
2709@cindex libtool modules
2710@cindex -module, libtool
2711
2712These are libtool libraries meant to be dlopened. They are
2713indicated to libtool by passing @code{-module} at link-time.
2714
2715@example
2716pkglib_LTLIBRARIES = mymodule.la
2717mymodule_la_SOURCES = doit.c
2718mymodule_LDFLAGS = -module
2719@end example
2720
2721Ordinarily, Automake requires that a Library's name starts with
2722@samp{lib}. However, when building a dynamically loadable module you
2723might wish to use a "nonstandard" name.
2724
2725@node Libtool Flags, LTLIBOBJ, Libtool Modules, A Shared Library
2726@subsection _LIBADD and _LDFLAGS
2727@cindex _LIBADD, libtool
2728@cindex _LDFLAGS, libtool
2729
2730As shown in previous sections, the @samp{@var{library}_LIBADD}
2731variable should be used to list extra libtool objects (@file{.lo}
2732files) or libtool libraries (@file{.la}) to add to @var{library}.
2733
2734The @samp{@var{library}_LDFLAGS} variable is the place to list
2735additional libtool flags, such as @samp{-version-info},
2736@samp{-static}, and a lot more. See @xref{Link mode, , Using libltdl,
2737libtool, The Libtool Manual}.
2738
2739@node LTLIBOBJ, Libtool Issues, Libtool Flags, A Shared Library
2740@subsection @code{LTLIBOBJS}
2741@cindex @code{LTLIBOBJS}, special handling
2742@vindex LTLIBOBJS
2743@vindex LIBOBJS
2744@cvindex AC_LIBOBJ
2745
2746Where an ordinary library might include @code{$(LIBOBJS)}, a libtool
2747library must use @code{$(LTLIBOBJS)}. This is required because the
2748object files that libtool operates on do not necessarily end in
2749@file{.o}.
2750
2751Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
2752performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
2753@code{AC_LIBOBJ} vs. @code{LIBOBJS}, autoconf, The Autoconf Manual}).
2754
2755@node Libtool Issues, , LTLIBOBJ, A Shared Library
2756@subsection Common Issues Related to Libtool's Use
2757
2758@subsubsection @code{required file `./ltmain.sh' not found}
2759@cindex ltmain.sh not found
2760@cindex libtoolize, no longer run by Automake
2761@cindex libtoolize and autoreconf
2762@cindex autoreconf and libtoolize
2763@cindex bootstrap.sh and autoreconf
2764@cindex autogen.sh and autoreconf
2765
2766Libtool comes with a tool called @command{libtoolize} that will
2767install libtool's supporting files into a package. Running this
2768command will install @file{ltmain.sh}. You should execute it before
2769@command{aclocal} and @command{automake}.
2770
2771People upgrading old packages to newer autotools are likely to face
2772this issue because older Automake versions used to call
2773@command{libtoolize}. Therefore old build scripts do not call
2774@command{libtoolize}.
2775
2776Since Automake 1.6, it has been decided that running
2777@command{libtoolize} was none of Automake's business. Instead, that
2778functionality has been moved into the @command{autoreconf} command
2779(@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
2780The Autoconf Manual}). If you do not want to remember what to run and
2781when, just learn the @command{autoreconf} command. Hopefully,
2782replacing existing @file{bootstrap.sh} or @file{autogen.sh} scripts by
2783a call to @command{autoreconf} should also free you from any similar
2784incompatible change in the future.
2785
2786@subsubsection Objects @code{created with both libtool and without}
2787
2788Sometimes, the same source file is used both to build a libtool
2789library and to build another non-libtool target (be it a program or
2790another library).
2791
2792Let's consider the following @file{Makefile.am}.
2793
2794@example
2795bin_PROGRAMS = prog
2796prog_SOURCES = prog.c foo.c @dots{}
2797
2798lib_LTLIBRARIES = libfoo.la
2799libfoo_la_SOURCES = foo.c @dots{}
2800@end example
2801
2802@noindent
2803(In this trivial case the issue could be avoided by linking
2804@file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
2805@code{prog_SOURCES}. But let's assume we really want to keep
2806@file{prog} and @file{libfoo.la} separate.)
2807
2808Technically, it means that we should build @file{foo.$(OBJEXT)} for
2809@file{prog}, and @file{foo.lo} for @file{libfoo.la}. The problem is
2810that in the course of creating @file{foo.lo}, libtool may erase (or
2811replace) @file{foo.$(OBJEXT)} -- and this cannot be avoided.
2812
2813Therefore, when Automake detects this situation it will complain
2814with a message such as
2815@example
2816object `foo.$(OBJEXT)' created both with libtool and without
2817@end example
2818
2819A workaround for this issue is to ensure that these two objects get
2820different basenames. As explained in @ref{renamed objects}, this
2821happens automatically when per-targets flags are used.
2822
2823@example
2824bin_PROGRAMS = prog
2825prog_SOURCES = prog.c foo.c @dots{}
2826prog_CFLAGS = $(AM_CFLAGS)
2827
2828lib_LTLIBRARIES = libfoo.la
2829libfoo_la_SOURCES = foo.c @dots{}
2830@end example
2831
2832@noindent
2833Adding @code{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
2834when the @code{prog_CFLAGS} is defined, it is used instead of
2835@code{AM_CFLAGS}. However as a side effect it will cause
2836@file{prog.c} and @file{foo.c} to be compiled as
2837@file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)} which solves
2838the issue.
2839
2840@node Program and Library Variables, LIBOBJS, A Shared Library, Programs
2841@section Program and Library Variables
2842
2843Associated with each program are a collection of variables which can be
2844used to modify how that program is built. There is a similar list of
2845such variables for each library. The canonical name of the program (or
2846library) is used as a base for naming these variables.
2847
2848In the list below, we use the name ``maude'' to refer to the program or
2849library. In your @file{Makefile.am} you would replace this with the
2850canonical name of your program. This list also refers to ``maude'' as a
2851program, but in general the same rules apply for both static and dynamic
2852libraries; the documentation below notes situations where programs and
2853libraries differ.
2854
2855@table @samp
2856@item maude_SOURCES
2857This variable, if it exists, lists all the source files which are
2858compiled to build the program. These files are added to the
2859distribution by default. When building the program, Automake will cause
2860each source file to be compiled to a single @file{.o} file (or
2861@file{.lo} when using libtool). Normally these object files are named
2862after the source file, but other factors can change this. If a file in
2863the @samp{_SOURCES} variable has an unrecognized extension, Automake
2864will do one of two things with it. If a suffix rule exists for turning
2865files with the unrecognized extension into @file{.o} files, then
2866automake will treat this file as it will any other source file
2867(@pxref{Support for Other Languages}). Otherwise, the file will be
2868ignored as though it were a header file.
2869
2870The prefixes @samp{dist_} and @samp{nodist_} can be used to control
2871whether files listed in a @samp{_SOURCES} variable are distributed.
2872@samp{dist_} is redundant, as sources are distributed by default, but it
2873can be specified for clarity if desired.
2874
2875It is possible to have both @samp{dist_} and @samp{nodist_} variants of
2876a given @samp{_SOURCES} variable at once; this lets you easily
2877distribute some files and not others, for instance:
2878
2879@example
2880nodist_maude_SOURCES = nodist.c
2881dist_maude_SOURCES = dist-me.c
2882@end example
2883
2884By default the output file (on Unix systems, the @file{.o} file) will be
2885put into the current build directory. However, if the option
2886@code{subdir-objects} is in effect in the current directory then the
2887@file{.o} file will be put into the subdirectory named after the source
2888file. For instance, with @code{subdir-objects} enabled,
2889@file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}. Some
2890people prefer this mode of operation. You can specify
2891@code{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
2892@cindex Subdirectory, objects in
2893@cindex Objects in subdirectory
2894
2895
2896@item EXTRA_maude_SOURCES
2897Automake needs to know the list of files you intend to compile
2898@emph{statically}. For one thing, this is the only way Automake has of
2899knowing what sort of language support a given @file{Makefile.in}
2900requires. @footnote{There are other, more obscure reasons reasons for
2901this limitation as well.} This means that, for example, you can't put a
2902configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
2903variable. If you intend to conditionally compile source files and use
2904@file{configure} to substitute the appropriate object names into, e.g.,
2905@samp{_LDADD} (see below), then you should list the corresponding source
2906files in the @samp{EXTRA_} variable.
2907
2908This variable also supports @samp{dist_} and @samp{nodist_} prefixes,
2909e.g., @samp{nodist_EXTRA_maude_SOURCES}.
2910
2911@item maude_AR
2912A static library is created by default by invoking @code{$(AR) cru}
2913followed by the name of the library and then the objects being put into
2914the library. You can override this by setting the @samp{_AR} variable.
2915This is usually used with C++; some C++ compilers require a special
2916invocation in order to instantiate all the templates which should go
2917into a library. For instance, the SGI C++ compiler likes this variable set
2918like so:
2919@example
2920libmaude_a_AR = $(CXX) -ar -o
2921@end example
2922
2923@item maude_LIBADD
2924Extra objects can be added to a @emph{library} using the @samp{_LIBADD}
2925variable. For instance this should be used for objects determined by
2926@code{configure} (@pxref{A Library}).
2927
2928@item maude_LDADD
2929Extra objects can be added to a @emph{program} by listing them in the
2930@samp{_LDADD} variable. For instance this should be used for objects
2931determined by @code{configure} (@pxref{Linking}).
2932
2933@samp{_LDADD} and @samp{_LIBADD} are inappropriate for passing
2934program-specific linker flags (except for @samp{-l}, @samp{-L},
2935@samp{-dlopen} and @samp{-dlpreopen}). Use the @samp{_LDFLAGS} variable
2936for this purpose.
2937
2938For instance, if your @file{configure.in} uses @code{AC_PATH_XTRA}, you
2939could link your program against the X libraries like so:
2940
2941@example
2942maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
2943@end example
2944
2945@item maude_LDFLAGS
2946This variable is used to pass extra flags to the link step of a program
2947or a shared library.
2948
2949@item maude_DEPENDENCIES
2950It is also occasionally useful to have a program depend on some other
2951target which is not actually part of that program. This can be done
2952using the @samp{_DEPENDENCIES} variable. Each program depends on the
2953contents of such a variable, but no further interpretation is done.
2954
2955If @samp{_DEPENDENCIES} is not supplied, it is computed by Automake.
2956The automatically-assigned value is the contents of @samp{_LDADD} or
2957@samp{_LIBADD}, with most configure substitutions, @samp{-l}, @samp{-L},
2958@samp{-dlopen} and @samp{-dlpreopen} options removed. The configure
2959substitutions that are left in are only @samp{$(LIBOBJS)} and
2960@samp{$(ALLOCA)}; these are left because it is known that they will not
2961cause an invalid value for @samp{_DEPENDENCIES} to be generated.
2962
2963@item maude_LINK
2964You can override the linker on a per-program basis. By default the
2965linker is chosen according to the languages used by the program. For
2966instance, a program that includes C++ source code would use the C++
2967compiler to link. The @samp{_LINK} variable must hold the name of a
2968command which can be passed all the @file{.o} file names as arguments.
2969Note that the name of the underlying program is @emph{not} passed to
2970@samp{_LINK}; typically one uses @samp{$@@}:
2971
2972@example
2973maude_LINK = $(CCLD) -magic -o $@@
2974@end example
2975
2976@item maude_CCASFLAGS
2977@itemx maude_CFLAGS
2978@itemx maude_CPPFLAGS
2979@itemx maude_CXXFLAGS
2980@itemx maude_FFLAGS
2981@itemx maude_GCJFLAGS
2982@itemx maude_LFLAGS
2983@itemx maude_OBJCFLAGS
2984@itemx maude_RFLAGS
2985@itemx maude_YFLAGS
2986@cindex per-target compilation flags, defined
2987Automake allows you to set compilation flags on a per-program (or
2988per-library) basis. A single source file can be included in several
2989programs, and it will potentially be compiled with different flags for
2990each program. This works for any language directly supported by
2991Automake. These @dfn{per-target compilation flags} are
2992@samp{_CCASFLAGS},
2993@samp{_CFLAGS},
2994@samp{_CPPFLAGS},
2995@samp{_CXXFLAGS},
2996@samp{_FFLAGS},
2997@samp{_GCJFLAGS},
2998@samp{_LFLAGS},
2999@samp{_OBJCFLAGS},
3000@samp{_RFLAGS}, and
3001@samp{_YFLAGS}.
3002
3003When using a per-target compilation flag, Automake will choose a
3004different name for the intermediate object files. Ordinarily a file
3005like @file{sample.c} will be compiled to produce @file{sample.o}.
3006However, if the program's @samp{_CFLAGS} variable is set, then the
3007object file will be named, for instance, @file{maude-sample.o}.
3008(See also @ref{renamed objects}.)
3009
3010In compilations with per-target flags, the ordinary @samp{AM_} form of
3011the flags variable is @emph{not} automatically included in the
3012compilation (however, the user form of the variable @emph{is} included).
3013So for instance, if you want the hypothetical @file{maude} compilations
3014to also use the value of @samp{AM_CFLAGS}, you would need to write:
3015
3016@example
3017maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
3018@end example
3019
3020
3021@item maude_DEPENDENCIES
3022It is also occasionally useful to have a program depend on some other
3023target which is not actually part of that program. This can be done
3024using the @samp{_DEPENDENCIES} variable. Each program depends on the
3025contents of such a variable, but no further interpretation is done.
3026
3027If @samp{_DEPENDENCIES} is not supplied, it is computed by Automake.
3028The automatically-assigned value is the contents of @samp{_LDADD} or
3029@samp{_LIBADD}, with most configure substitutions, @samp{-l}, @samp{-L},
3030@samp{-dlopen} and @samp{-dlpreopen} options removed. The configure
3031substitutions that are left in are only @samp{@@LIBOBJS@@} and
3032@samp{@@ALLOCA@@}; these are left because it is known that they will not
3033cause an invalid value for @samp{_DEPENDENCIES} to be generated.
3034
3035@item maude_SHORTNAME
3036On some platforms the allowable file names are very short. In order to
3037support these systems and per-program compilation flags at the same
3038time, Automake allows you to set a ``short name'' which will influence
3039how intermediate object files are named. For instance, if you set
3040@samp{maude_SHORTNAME} to @samp{m}, then in the above per-program
3041compilation flag example the object file would be named
3042@file{m-sample.o} rather than @file{maude-sample.o}. This facility is
3043rarely needed in practice, and we recommend avoiding it until you find
3044it is required.
3045@end table
3046
3047
3048@node LIBOBJS, Program variables, Program and Library Variables, Programs
3049@section Special handling for LIBOBJS and ALLOCA
3050
3051@cindex @code{LIBOBJS}, special handling
3052@cindex @code{ALLOCA}, special handling
3053
3054Automake explicitly recognizes the use of @code{$(LIBOBJS)} and
3055@code{$(ALLOCA)}, and uses this information, plus the list of
3056@code{LIBOBJS} files derived from @file{configure.in} to automatically
3057include the appropriate source files in the distribution (@pxref{Dist}).
3058These source files are also automatically handled in the
3059dependency-tracking scheme; see @xref{Dependencies}.
3060
3061@code{$(LIBOBJS)} and @code{$(ALLOCA)} are specially recognized in any
3062@samp{_LDADD} or @samp{_LIBADD} variable.
3063
3064
3065@node Program variables, Yacc and Lex, LIBOBJS, Programs
3066@section Variables used when building a program
3067
3068Occasionally it is useful to know which @file{Makefile} variables
3069Automake uses for compilations; for instance you might need to do your
3070own compilation in some special cases.
3071
3072Some variables are inherited from Autoconf; these are @code{CC},
3073@code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
3074@code{LIBS}.
3075@vindex CC
3076@vindex CFLAGS
3077@vindex CPPFLAGS
3078@vindex DEFS
3079@vindex LDFLAGS
3080@vindex LIBS
3081
3082There are some additional variables which Automake itself defines:
3083
3084@vtable @code
3085@item AM_CPPFLAGS
3086The contents of this variable are passed to every compilation which invokes
3087the C preprocessor; it is a list of arguments to the preprocessor. For
3088instance, @samp{-I} and @samp{-D} options should be listed here.
3089
3090Automake already provides some @samp{-I} options automatically. In
3091particular it generates @samp{-I$(srcdir)}, @samp{-I.}, and a @samp{-I}
3092pointing to the directory holding @file{config.h} (if you've used
3093@code{AC_CONFIG_HEADERS} or @code{AM_CONFIG_HEADER}). You can disable
3094the default @samp{-I} options using the @samp{nostdinc} option.
3095
3096@code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
3097per-library) @code{_CPPFLAGS} variable if it is defined.
3098
3099@item INCLUDES
3100This does the same job as @samp{AM_CPPFLAGS}. It is an older name for
3101the same functionality. This variable is deprecated; we suggest using
3102@samp{AM_CPPFLAGS} instead.
3103
3104@item AM_CFLAGS
3105This is the variable which the @file{Makefile.am} author can use to pass
3106in additional C compiler flags. It is more fully documented elsewhere.
3107In some situations, this is not used, in preference to the
3108per-executable (or per-library) @code{_CFLAGS}.
3109
3110@item COMPILE
3111This is the command used to actually compile a C source file. The
3112filename is appended to form the complete command line.
3113
3114@item AM_LDFLAGS
3115This is the variable which the @file{Makefile.am} author can use to pass
3116in additional linker flags. In some situations, this is not used, in
3117preference to the per-executable (or per-library) @code{_LDFLAGS}.
3118
3119@item LINK
3120This is the command used to actually link a C program. It already
3121includes @samp{-o $@@} and the usual variable references (for instance,
3122@code{CFLAGS}); it takes as ``arguments'' the names of the object files
3123and libraries to link in.
3124@end vtable
3125
3126
3127@node Yacc and Lex, C++ Support, Program variables, Programs
3128@section Yacc and Lex support
3129
3130Automake has somewhat idiosyncratic support for Yacc and Lex.
3131
3132Automake assumes that the @file{.c} file generated by @code{yacc} (or
3133@code{lex}) should be named using the basename of the input file. That
3134is, for a yacc source file @file{foo.y}, Automake will cause the
3135intermediate file to be named @file{foo.c} (as opposed to
3136@file{y.tab.c}, which is more traditional).
3137
3138The extension of a yacc source file is used to determine the extension
3139of the resulting @samp{C} or @samp{C++} file. Files with the extension
3140@samp{.y} will be turned into @samp{.c} files; likewise, @samp{.yy} will
3141become @samp{.cc}; @samp{.y++}, @samp{c++}; and @samp{.yxx},
3142@samp{.cxx}.
3143
3144Likewise, lex source files can be used to generate @samp{C} or
3145@samp{C++}; the extensions @samp{.l}, @samp{.ll}, @samp{.l++}, and
3146@samp{.lxx} are recognized.
3147
3148You should never explicitly mention the intermediate (@samp{C} or
3149@samp{C++}) file in any @samp{SOURCES} variable; only list the source
3150file.
3151
3152The intermediate files generated by @code{yacc} (or @code{lex}) will be
3153included in any distribution that is made. That way the user doesn't
3154need to have @code{yacc} or @code{lex}.
3155
3156If a @code{yacc} source file is seen, then your @file{configure.in} must
3157define the variable @samp{YACC}. This is most easily done by invoking
3158the macro @samp{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
3159Program Checks, autoconf, The Autoconf Manual}).
3160
3161When @code{yacc} is invoked, it is passed @samp{YFLAGS} and
3162@samp{AM_YFLAGS}. The former is a user variable and the latter is
3163intended for the @file{Makefile.am} author.
3164
3165@samp{AM_YFLAGS} is usually used to pass the @code{-d} option to
3166@code{yacc}. Automake knows what this means and will automatically
3167adjust its rules to update and distribute the header file built by
3168@code{yacc -d}. What Automake cannot guess, though, is where this
3169header will be used: it is up to you to ensure the header gets built
3170before it is first used. Typically this is necessary in order for
3171dependency tracking to work when the header is included by another
3172file. The common solution is listing the header file in
3173@code{BUILT_SOURCES} (@pxref{Sources}) as follows.
3174
3175@example
3176BUILT_SOURCES = parser.h
3177AM_YFLAGS = -d
3178bin_PROGRAMS = foo
3179foo_SOURCES = @dots{} parser.y @dots{}
3180@end example
3181
3182If a @code{lex} source file is seen, then your @file{configure.in}
3183must define the variable @samp{LEX}. You can use @samp{AC_PROG_LEX}
3184to do this (@pxref{Particular Programs, , Particular Program Checks,
3185autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
3186(@pxref{Macros}) is recommended.
3187
3188When @code{lex} is invoked, it is passed @samp{LFLAGS} and
3189@samp{AM_LFLAGS}. The former is a user variable and the latter is
3190intended for the @file{Makefile.am} author.
3191
3192
3193
3194@cindex ylwrap
3195@cindex yacc, multiple parsers
3196@cindex Multiple yacc parsers
3197@cindex Multiple lex lexers
3198@cindex lex, multiple lexers
3199
3200
3201Automake makes it possible to include multiple @code{yacc} (or
3202@code{lex}) source files in a single program. When there is more than
3203one distinct @code{yacc} (or @code{lex}) source file in a directory,
3204Automake uses a small program called @code{ylwrap} to run @code{yacc}
3205(or @code{lex}) in a subdirectory. This is necessary because yacc's
3206output filename is fixed, and a parallel make could conceivably invoke
3207more than one instance of @code{yacc} simultaneously. The @code{ylwrap}
3208program is distributed with Automake. It should appear in the directory
3209specified by @samp{AC_CONFIG_AUX_DIR} (@pxref{Input, , Finding
3210`configure' Input, autoconf, The Autoconf Manual}), or the current
3211directory if that macro is not used in @file{configure.in}.
3212
3213For @code{yacc}, simply managing locking is insufficient. The output of
3214@code{yacc} always uses the same symbol names internally, so it isn't
3215possible to link two @code{yacc} parsers into the same executable.
3216
3217We recommend using the following renaming hack used in @code{gdb}:
3218@example
3219#define yymaxdepth c_maxdepth
3220#define yyparse c_parse
3221#define yylex c_lex
3222#define yyerror c_error
3223#define yylval c_lval
3224#define yychar c_char
3225#define yydebug c_debug
3226#define yypact c_pact
3227#define yyr1 c_r1
3228#define yyr2 c_r2
3229#define yydef c_def
3230#define yychk c_chk
3231#define yypgo c_pgo
3232#define yyact c_act
3233#define yyexca c_exca
3234#define yyerrflag c_errflag
3235#define yynerrs c_nerrs
3236#define yyps c_ps
3237#define yypv c_pv
3238#define yys c_s
3239#define yy_yys c_yys
3240#define yystate c_state
3241#define yytmp c_tmp
3242#define yyv c_v
3243#define yy_yyv c_yyv
3244#define yyval c_val
3245#define yylloc c_lloc
3246#define yyreds c_reds
3247#define yytoks c_toks
3248#define yylhs c_yylhs
3249#define yylen c_yylen
3250#define yydefred c_yydefred
3251#define yydgoto c_yydgoto
3252#define yysindex c_yysindex
3253#define yyrindex c_yyrindex
3254#define yygindex c_yygindex
3255#define yytable c_yytable
3256#define yycheck c_yycheck
3257#define yyname c_yyname
3258#define yyrule c_yyrule
3259@end example
3260
3261For each define, replace the @samp{c_} prefix with whatever you like.
3262These defines work for @code{bison}, @code{byacc}, and traditional
3263@code{yacc}s. If you find a parser generator that uses a symbol not
3264covered here, please report the new name so it can be added to the list.
3265
3266
3267@node C++ Support, Assembly Support, Yacc and Lex, Programs
3268@section C++ Support
3269
3270@cindex C++ support
3271@cindex Support for C++
3272
3273Automake includes full support for C++.
3274
3275Any package including C++ code must define the output variable
3276@samp{CXX} in @file{configure.in}; the simplest way to do this is to use
3277the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
3278Program Checks, autoconf, The Autoconf Manual}).
3279
3280A few additional variables are defined when a C++ source file is seen:
3281
3282@vtable @code
3283@item CXX
3284The name of the C++ compiler.
3285
3286@item CXXFLAGS
3287Any flags to pass to the C++ compiler.
3288
3289@item AM_CXXFLAGS
3290The maintainer's variant of @code{CXXFLAGS}.
3291
3292@item CXXCOMPILE
3293The command used to actually compile a C++ source file. The file name
3294is appended to form the complete command line.
3295
3296@item CXXLINK
3297The command used to actually link a C++ program.
3298@end vtable
3299
3300
3301@node Assembly Support, Fortran 77 Support, C++ Support, Programs
3302@section Assembly Support
3303
3304Automake includes some support for assembly code.
3305
3306The variable @code{CCAS} holds the name of the compiler used to build
3307assembly code. This compiler must work a bit like a C compiler; in
3308particular it must accept @samp{-c} and @samp{-o}. The value of
3309@code{CCASFLAGS} is passed to the compilation.
3310@vindex CCAS
3311@vindex CCASFLAGS
3312
3313You are required to set @code{CCAS} and @code{CCASFLAGS} via
3314@file{configure.in}. The autoconf macro @code{AM_PROG_AS} will do this
3315for you. Unless they are already set, it simply sets @code{CCAS} to the
3316C compiler and @code{CCASFLAGS} to the C compiler flags.
3317
3318Only the suffixes @samp{.s} and @samp{.S} are recognized by
3319@code{automake} as being files containing assembly code.
3320
3321
3322@node Fortran 77 Support, Java Support, Assembly Support, Programs
3323@comment node-name, next, previous, up
3324@section Fortran 77 Support
3325
3326@cindex Fortran 77 support
3327@cindex Support for Fortran 77
3328
3329Automake includes full support for Fortran 77.
3330
3331Any package including Fortran 77 code must define the output variable
3332@samp{F77} in @file{configure.in}; the simplest way to do this is to use
3333the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
3334Program Checks, autoconf, The Autoconf Manual}). @xref{Fortran 77 and
3335Autoconf}.
3336
3337A few additional variables are defined when a Fortran 77 source file is
3338seen:
3339
3340@vtable @code
3341
3342@item F77
3343The name of the Fortran 77 compiler.
3344
3345@item FFLAGS
3346Any flags to pass to the Fortran 77 compiler.
3347
3348@item AM_FFLAGS
3349The maintainer's variant of @code{FFLAGS}.
3350
3351@item RFLAGS
3352Any flags to pass to the Ratfor compiler.
3353
3354@item AM_RFLAGS
3355The maintainer's variant of @code{RFLAGS}.
3356
3357@item F77COMPILE
3358The command used to actually compile a Fortran 77 source file. The file
3359name is appended to form the complete command line.
3360
3361@item FLINK
3362The command used to actually link a pure Fortran 77 program or shared
3363library.
3364
3365@end vtable
3366
3367Automake can handle preprocessing Fortran 77 and Ratfor source files in
3368addition to compiling them@footnote{Much, if not most, of the
3369information in the following sections pertaining to preprocessing
3370Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
3371Rules, , Catalogue of Rules, make, The GNU Make Manual}.}. Automake
3372also contains some support for creating programs and shared libraries
3373that are a mixture of Fortran 77 and other languages (@pxref{Mixing
3374Fortran 77 With C and C++}).
3375
3376These issues are covered in the following sections.
3377
3378@menu
3379* Preprocessing Fortran 77::
3380* Compiling Fortran 77 Files::
3381* Mixing Fortran 77 With C and C++::
3382* Fortran 77 and Autoconf::
3383@end menu
3384
3385
3386@node Preprocessing Fortran 77, Compiling Fortran 77 Files, Fortran 77 Support, Fortran 77 Support
3387@comment node-name, next, previous, up
3388@subsection Preprocessing Fortran 77
3389
3390@cindex Preprocessing Fortran 77
3391@cindex Fortran 77, Preprocessing
3392@cindex Ratfor programs
3393
3394@file{N.f} is made automatically from @file{N.F} or @file{N.r}. This
3395rule runs just the preprocessor to convert a preprocessable Fortran 77
3396or Ratfor source file into a strict Fortran 77 source file. The precise
3397command used is as follows:
3398
3399@table @file
3400
3401@item .F
3402@code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)}
3403
3404@item .r
3405@code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
3406
3407@end table
3408
3409
3410@node Compiling Fortran 77 Files, Mixing Fortran 77 With C and C++, Preprocessing Fortran 77, Fortran 77 Support
3411@comment node-name, next, previous, up
3412@subsection Compiling Fortran 77 Files
3413
3414@file{N.o} is made automatically from @file{N.f}, @file{N.F} or
3415@file{N.r} by running the Fortran 77 compiler. The precise command used
3416is as follows:
3417
3418@table @file
3419
3420@item .f
3421@code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
3422
3423@item .F
3424@code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)}
3425
3426@item .r
3427@code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
3428
3429@end table
3430
3431
3432@node Mixing Fortran 77 With C and C++, Fortran 77 and Autoconf, Compiling Fortran 77 Files, Fortran 77 Support
3433@comment node-name, next, previous, up
3434@subsection Mixing Fortran 77 With C and C++
3435
3436@cindex Fortran 77, mixing with C and C++
3437@cindex Mixing Fortran 77 with C and C++
3438@cindex Linking Fortran 77 with C and C++
3439@cindex cfortran
3440@cindex Mixing Fortran 77 with C and/or C++
3441
3442Automake currently provides @emph{limited} support for creating programs
3443and shared libraries that are a mixture of Fortran 77 and C and/or C++.
3444However, there are many other issues related to mixing Fortran 77 with
3445other languages that are @emph{not} (currently) handled by Automake, but
3446that are handled by other packages@footnote{For example,
3447@uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
3448addresses all of these inter-language issues, and runs under nearly all
3449Fortran 77, C and C++ compilers on nearly all platforms. However,
3450@code{cfortran} is not yet Free Software, but it will be in the next
3451major release.}.
3452
3453@page
3454Automake can help in two ways:
3455
3456@enumerate
3457@item
3458Automatic selection of the linker depending on which combinations of
3459source code.
3460
3461@item
3462Automatic selection of the appropriate linker flags (e.g. @samp{-L} and
3463@samp{-l}) to pass to the automatically selected linker in order to link
3464in the appropriate Fortran 77 intrinsic and run-time libraries.
3465
3466@cindex FLIBS, defined
3467These extra Fortran 77 linker flags are supplied in the output variable
3468@code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro
3469supplied with newer versions of Autoconf (Autoconf version 2.13 and
3470later). @xref{Fortran 77 Compiler Characteristics, , , autoconf, The
3471Autoconf}.
3472@end enumerate
3473
3474If Automake detects that a program or shared library (as mentioned in
3475some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
3476code that is a mixture of Fortran 77 and C and/or C++, then it requires
3477that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
3478@file{configure.in}, and that either @code{$(FLIBS)} or @code{@@FLIBS@@}
3479appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
3480(for shared libraries) variables. It is the responsibility of the
3481person writing the @file{Makefile.am} to make sure that @code{$(FLIBS)}
3482or @code{@@FLIBS@@} appears in the appropriate @code{_LDADD} or
3483@code{_LIBADD} variable.
3484
3485@cindex Mixed language example
3486@cindex Example, mixed language
3487
3488For example, consider the following @file{Makefile.am}:
3489
3490@example
3491bin_PROGRAMS = foo
3492foo_SOURCES = main.cc foo.f
3493foo_LDADD = libfoo.la @@FLIBS@@
3494
3495pkglib_LTLIBRARIES = libfoo.la
3496libfoo_la_SOURCES = bar.f baz.c zardoz.cc
3497libfoo_la_LIBADD = $(FLIBS)
3498@end example
3499
3500In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
3501is mentioned in @file{configure.in}. Also, if @code{@@FLIBS@@} hadn't
3502been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
3503Automake would have issued a warning.
3504
3505
3506@page
3507@menu
3508* How the Linker is Chosen::
3509@end menu
3510
3511@node How the Linker is Chosen, , Mixing Fortran 77 With C and C++, Mixing Fortran 77 With C and C++
3512@comment node-name, next, previous, up
3513@subsubsection How the Linker is Chosen
3514
3515@cindex Automatic linker selection
3516@cindex Selecting the linker automatically
3517
3518The following diagram demonstrates under what conditions a particular
3519linker is chosen by Automake.
3520
3521For example, if Fortran 77, C and C++ source code were to be compiled
3522into a program, then the C++ linker will be used. In this case, if the
3523C or Fortran 77 linkers required any special libraries that weren't
3524included by the C++ linker, then they must be manually added to an
3525@code{_LDADD} or @code{_LIBADD} variable by the user writing the
3526@file{Makefile.am}.
3527
3528@example
3529 \ Linker
3530 source \
3531 code \ C C++ Fortran
3532 ----------------- +---------+---------+---------+
3533 | | | |
3534 C | x | | |
3535 | | | |
3536 +---------+---------+---------+
3537 | | | |
3538 C++ | | x | |
3539 | | | |
3540 +---------+---------+---------+
3541 | | | |
3542 Fortran | | | x |
3543 | | | |
3544 +---------+---------+---------+
3545 | | | |
3546 C + C++ | | x | |
3547 | | | |
3548 +---------+---------+---------+
3549 | | | |
3550 C + Fortran | | | x |
3551 | | | |
3552 +---------+---------+---------+
3553 | | | |
3554 C++ + Fortran | | x | |
3555 | | | |
3556 +---------+---------+---------+
3557 | | | |
3558 C + C++ + Fortran | | x | |
3559 | | | |
3560 +---------+---------+---------+
3561@end example
3562
3563
3564@node Fortran 77 and Autoconf, , Mixing Fortran 77 With C and C++, Fortran 77 Support
3565@comment node-name, next, previous, up
3566@subsection Fortran 77 and Autoconf
3567
3568The current Automake support for Fortran 77 requires a recent enough
3569version of Autoconf that also includes support for Fortran 77. Full
3570Fortran 77 support was added to Autoconf 2.13, so you will want to use
3571that version of Autoconf or later.
3572
3573
3574@node Java Support, Support for Other Languages, Fortran 77 Support, Programs
3575@comment node-name, next, previous, up
3576@section Java Support
3577
3578@cindex Java support
3579@cindex Support for Java
3580
3581Automake includes support for compiled Java, using @code{gcj}, the Java
3582front end to the GNU Compiler Collection.
3583
3584Any package including Java code to be compiled must define the output
3585variable @samp{GCJ} in @file{configure.in}; the variable @samp{GCJFLAGS}
3586must also be defined somehow (either in @file{configure.in} or
3587@file{Makefile.am}). The simplest way to do this is to use the
3588@code{AM_PROG_GCJ} macro.
3589
3590@vindex GCJFLAGS
3591
3592By default, programs including Java source files are linked with
3593@code{gcj}.
3594
3595As always, the contents of @samp{AM_GCJFLAGS} are passed to every
3596compilation invoking @code{gcj} (in its role as an ahead-of-time
3597compiler -- when invoking it to create @file{.class} files,
3598@samp{AM_JAVACFLAGS} is used instead). If it is necessary to pass
3599options to @code{gcj} from @file{Makefile.am}, this variable, and not
3600the user variable @samp{GCJFLAGS}, should be used.
3601
3602@vindex AM_GCJFLAGS
3603
3604@code{gcj} can be used to compile @file{.java}, @file{.class},
3605@file{.zip}, or @file{.jar} files.
3606
3607When linking, @code{gcj} requires that the main class be specified
3608using the @samp{--main=} option. The easiest way to do this is to use
3609the @code{_LDFLAGS} variable for the program.
3610
3611
3612@node Support for Other Languages, ANSI, Java Support, Programs
3613@comment node-name, next, previous, up
3614@section Support for Other Languages
3615
3616Automake currently only includes full support for C, C++ (@pxref{C++
3617Support}), Fortran 77 (@pxref{Fortran 77 Support}), and Java
3618(@pxref{Java Support}). There is only rudimentary support for other
3619languages, support for which will be improved based on user demand.
3620
3621Some limited support for adding your own languages is available via the
3622suffix rule handling; see @ref{Suffixes}.
3623
3624
3625@node ANSI, Dependencies, Support for Other Languages, Programs
3626@section Automatic de-ANSI-fication
3627
3628@cindex de-ANSI-fication, defined
3629
3630Although the GNU standards allow the use of ANSI C, this can have the
3631effect of limiting portability of a package to some older compilers
3632(notably the SunOS C compiler).
3633
3634Automake allows you to work around this problem on such machines by
3635@dfn{de-ANSI-fying} each source file before the actual compilation takes
3636place.
3637
3638@vindex AUTOMAKE_OPTIONS
3639@opindex ansi2knr
3640
3641If the @file{Makefile.am} variable @code{AUTOMAKE_OPTIONS}
3642(@pxref{Options}) contains the option @code{ansi2knr} then code to
3643handle de-ANSI-fication is inserted into the generated
3644@file{Makefile.in}.
3645
3646This causes each C source file in the directory to be treated as ANSI C@.
3647If an ANSI C compiler is available, it is used. If no ANSI C compiler
3648is available, the @code{ansi2knr} program is used to convert the source
3649files into K&R C, which is then compiled.
3650
3651The @code{ansi2knr} program is simple-minded. It assumes the source
3652code will be formatted in a particular way; see the @code{ansi2knr} man
3653page for details.
3654
3655Support for de-ANSI-fication requires the source files @file{ansi2knr.c}
3656and @file{ansi2knr.1} to be in the same package as the ANSI C source;
3657these files are distributed with Automake. Also, the package
3658@file{configure.in} must call the macro @code{AM_C_PROTOTYPES}
3659(@pxref{Macros}).
3660@cvindex AM_C_PROTOTYPES
3661
3662Automake also handles finding the @code{ansi2knr} support files in some
3663other directory in the current package. This is done by prepending the
3664relative path to the appropriate directory to the @code{ansi2knr}
3665option. For instance, suppose the package has ANSI C code in the
3666@file{src} and @file{lib} subdirectories. The files @file{ansi2knr.c} and
3667@file{ansi2knr.1} appear in @file{lib}. Then this could appear in
3668@file{src/Makefile.am}:
3669
3670@example
3671AUTOMAKE_OPTIONS = ../lib/ansi2knr
3672@end example
3673
3674If no directory prefix is given, the files are assumed to be in the
3675current directory.
3676
3677Note that automatic de-ANSI-fication will not work when the package is
3678being built for a different host architecture. That is because automake
3679currently has no way to build @code{ansi2knr} for the build machine.
3680
3681@c FIXME: this paragraph might be better moved to an `upgrading' section.
3682@cindex @code{LTLIBOBJS} and @code{ansi2knr}
3683@cindex @code{LIBOBJS} and @code{ansi2knr}
3684@cindex @code{ansi2knr} and @code{LTLIBOBJS}
3685@cindex @code{ansi2knr} and @code{LIBOBJS}
3686Using @code{LIBOBJS} with source de-ANSI-fication used to require
3687hand-crafted code in @file{configure} to append @code{$U} to basenames
3688in @code{LIBOBJS}. This is no longer true today. Starting with version
36892.54, Autoconf takes care of rewriting @code{LIBOBJS} and
3690@code{LTLIBOBJS}. (@pxref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ}
3691vs. @code{LIBOBJS}, autoconf, The Autoconf Manual})
3692
3693@node Dependencies, EXEEXT, ANSI, Programs
3694@section Automatic dependency tracking
3695
3696As a developer it is often painful to continually update the
3697@file{Makefile.in} whenever the include-file dependencies change in a
3698project. Automake supplies a way to automatically track dependency
3699changes.
3700
3701@cindex Dependency tracking
3702@cindex Automatic dependency tracking
3703
3704Automake always uses complete dependencies for a compilation, including
3705system headers. Automake's model is that dependency computation should
3706be a side effect of the build. To this end, dependencies are computed
3707by running all compilations through a special wrapper program called
3708@code{depcomp}. @code{depcomp} understands how to coax many different C
3709and C++ compilers into generating dependency information in the format
3710it requires. @code{automake -a} will install @code{depcomp} into your
3711source tree for you. If @code{depcomp} can't figure out how to properly
3712invoke your compiler, dependency tracking will simply be disabled for
3713your build.
3714
3715@cindex depcomp
3716
3717Experience with earlier versions of Automake @footnote{See
3718@uref{http://sources.redhat.com/automake/dependencies.html} for more
3719information on the history and experiences with automatic dependency
3720tracking in Automake} taught us that it is not reliable to generate
3721dependencies only on the maintainer's system, as configurations vary too
3722much. So instead Automake implements dependency tracking at build time.
3723
3724Automatic dependency tracking can be suppressed by putting
3725@code{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
3726passing @code{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
3727(this should be the preferred way). Or, you can invoke @code{automake}
3728with the @code{-i} option. Dependency tracking is enabled by default.
3729
3730@vindex AUTOMAKE_OPTIONS
3731@opindex no-dependencies
3732
3733The person building your package also can choose to disable dependency
3734tracking by configuring with @code{--disable-dependency-tracking}.
3735
3736@cindex Disabling dependency tracking
3737@cindex Dependency tracking, disabling
3738
3739
3740@node EXEEXT, , Dependencies, Programs
3741@section Support for executable extensions
3742
3743@cindex Executable extension
3744@cindex Extension, executable
3745@cindex Windows
3746
3747On some platforms, such as Windows, executables are expected to have an
3748extension such as @samp{.exe}. On these platforms, some compilers (GCC
3749among them) will automatically generate @file{foo.exe} when asked to
3750generate @file{foo}.
3751
3752Automake provides mostly-transparent support for this. Unfortunately
3753@emph{mostly} doesn't yet mean @emph{fully}. Until the English
3754dictionary is revised, you will have to assist Automake if your package
3755must support those platforms.
3756
3757One thing you must be aware of is that, internally, Automake rewrites
3758something like this:
3759
3760@example
3761bin_PROGRAMS = liver
3762@end example
3763
3764to this:
3765
3766@example
3767bin_PROGRAMS = liver$(EXEEXT)
3768@end example
3769
3770The targets Automake generates are likewise given the @samp{$(EXEEXT)}
3771extension. @code{EXEEXT}
3772
3773However, Automake cannot apply this rewriting to @code{configure}
3774substitutions. This means that if you are conditionally building a
3775program using such a substitution, then your @file{configure.in} must
3776take care to add @samp{$(EXEEXT)} when constructing the output variable.
3777
3778With Autoconf 2.13 and earlier, you must explicitly use @code{AC_EXEEXT}
3779to get this support. With Autoconf 2.50, @code{AC_EXEEXT} is run
3780automatically if you configure a compiler (say, through
3781@code{AC_PROG_CC}).
3782
3783Sometimes maintainers like to write an explicit link rule for their
3784program. Without executable extension support, this is easy---you
3785simply write a target with the same name as the program. However, when
3786executable extension support is enabled, you must instead add the
3787@samp{$(EXEEXT)} suffix.
3788
3789Unfortunately, due to the change in Autoconf 2.50, this means you must
3790always add this extension. However, this is a problem for maintainers
3791who know their package will never run on a platform that has executable
3792extensions. For those maintainers, the @code{no-exeext} option
3793(@pxref{Options}) will disable this feature. This works in a fairly
3794ugly way; if @code{no-exeext} is seen, then the presence of a target
3795named @code{foo} in @file{Makefile.am} will override an
3796automake-generated target of the form @code{foo$(EXEEXT)}. Without the
3797@code{no-exeext} option, this use will give an error.
3798
3799
3800@node Other objects, Other GNU Tools, Programs, Top
3801@chapter Other Derived Objects
3802
3803Automake can handle derived objects which are not C programs. Sometimes
3804the support for actually building such objects must be explicitly
3805supplied, but Automake will still automatically handle installation and
3806distribution.
3807
3808@menu
3809* Scripts:: Executable scripts
3810* Headers:: Header files
3811* Data:: Architecture-independent data files
3812* Sources:: Derived sources
3813@end menu
3814
3815
3816@node Scripts, Headers, Other objects, Other objects
3817@section Executable Scripts
3818
3819@cindex _SCRIPTS primary, defined
3820@cindex SCRIPTS primary, defined
3821@cindex Primary variable, SCRIPTS
3822
3823It is possible to define and install programs which are scripts. Such
3824programs are listed using the @samp{SCRIPTS} primary name. Automake
3825doesn't define any dependencies for scripts; the @file{Makefile.am}
3826should include the appropriate rules.
3827@vindex SCRIPTS
3828
3829Automake does not assume that scripts are derived objects; such objects
3830must be deleted by hand (@pxref{Clean}).
3831
3832The @code{automake} program itself is a Perl script that is generated at
3833configure time from @file{automake.in}. Here is how this is handled:
3834
3835@example
3836bin_SCRIPTS = automake
3837@end example
3838
3839Since @code{automake} appears in the @code{AC_OUTPUT} macro, a target
3840for it is automatically generated, and it is also automatically cleaned
3841(despite the fact it's a script).
3842
3843@cindex SCRIPTS, installation directories
3844@cindex Installing scripts
3845
3846@vindex bin_SCRIPTS
3847@vindex sbin_SCRIPTS
3848@vindex libexec_SCRIPTS
3849@vindex pkgdata_SCRIPTS
3850@vindex noinst_SCRIPTS
3851@vindex check_SCRIPTS
3852
3853Script objects can be installed in @code{bindir}, @code{sbindir},
3854@code{libexecdir}, or @code{pkgdatadir}.
3855
3856Scripts that need not being installed can be listed in
3857@code{noinst_SCRIPTS}, and among them, those which are needed only by
3858@code{make check} should go in @code{check_SCRIPTS}.
3859
3860
3861@node Headers, Data, Scripts, Other objects
3862@section Header files
3863
3864@cindex _HEADERS primary, defined
3865@cindex HEADERS primary, defined
3866@cindex Primary variable, HEADERS
3867
3868@vindex noinst_HEADERS
3869
3870Header files are specified by the @samp{HEADERS} family of variables.
3871Generally header files are not installed, so the @code{noinst_HEADERS}
3872variable will be the most used. @footnote{However, for the case of a
3873non-installed header file that is actually used by a particular program,
3874we recommend listing it in the program's @samp{_SOURCES} variable
3875instead of in @code{noinst_HEADERS}. We believe this is more clear.}
3876@vindex HEADERS
3877
3878All header files must be listed somewhere; missing ones will not appear
3879in the distribution. Often it is clearest to list uninstalled headers
3880with the rest of the sources for a program. @xref{A Program}. Headers
3881listed in a @samp{_SOURCES} variable need not be listed in any
3882@samp{_HEADERS} variable.
3883
3884@cindex HEADERS, installation directories
3885@cindex Installing headers
3886
3887@vindex include_HEADERS
3888@vindex oldinclude_HEADERS
3889@vindex pkginclude_HEADERS
3890
3891Headers can be installed in @code{includedir}, @code{oldincludedir}, or
3892@code{pkgincludedir}.
3893
3894
3895@node Data, Sources, Headers, Other objects
3896@section Architecture-independent data files
3897
3898@cindex _DATA primary, defined
3899@cindex DATA primary, defined
3900@cindex Primary variable, DATA
3901
3902Automake supports the installation of miscellaneous data files using the
3903@samp{DATA} family of variables.
3904@vindex DATA
3905
3906@vindex data_DATA
3907@vindex sysconf_DATA
3908@vindex sharedstate_DATA
3909@vindex localstate_DATA
3910@vindex pkgdata_DATA
3911
3912Such data can be installed in the directories @code{datadir},
3913@code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
3914@code{pkgdatadir}.
3915
3916By default, data files are @emph{not} included in a distribution. Of
3917course, you can use the @samp{dist_} prefix to change this on a
3918per-variable basis.
3919
3920Here is how Automake declares its auxiliary data files:
3921
3922@example
3923dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
3924@end example
3925
3926
3927@node Sources, , Data, Other objects
3928@section Built sources
3929
3930Because Automake's automatic dependency tracking works as a side-effect
3931of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
3932target should not be compiled before its dependencies are made, but
3933these dependencies are unknown until the target is first compiled.
3934
3935Ordinarily this is not a problem, because dependencies are distributed
3936sources: they preexist and do not need to be built. Suppose that
3937@file{foo.c} includes @file{foo.h}. When it first compiles
3938@file{foo.o}, @command{make} only knows that @file{foo.o} depends on
3939@file{foo.c}. As a side-effect of this compilation @code{depcomp}
3940records the @file{foo.h} dependency so that following invocations of
3941@command{make} will honor it. In these conditions, it's clear there is
3942no problem: either @file{foo.o} doesn't exist and has to be built
3943(regardless of the dependencies), either accurate dependencies exist and
3944they can be used to decide whether @file{foo.o} should be rebuilt.
3945
3946It's a different story if @file{foo.h} doesn't exist by the first
3947@command{make} run. For instance there might be a rule to build
3948@file{foo.h}. This time @file{file.o}'s build will fail because the
3949compiler can't find @file{foo.h}. @command{make} failed to trigger the
3950rule to build @file{foo.h} first by lack of dependency information.
3951
3952@vindex BUILT_SOURCES
3953@cindex BUILT_SOURCES, defined
3954
3955The @code{BUILT_SOURCES} variable is a workaround for this problem. A
3956source file listed in @code{BUILT_SOURCES} is made on @code{make all}
3957or @code{make check} (or even @code{make install}) before other
3958targets are processed. However, such a source file is not
3959@emph{compiled} unless explicitly requested by mentioning it in some
3960other @samp{_SOURCES} variable.
3961
3962So, to conclude our introductory example, we could use
3963@code{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
3964any other target (including @file{foo.o}) during @code{make all} or
3965@code{make check}.
3966
3967@code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
3968must be created early in the build process can be listed in this
3969variable. Moreover, all built sources do not necessarily have to be
3970listed in @code{BUILT_SOURCES}. For instance a generated @file{.c} file
3971doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
3972another source), because it's a known dependency of the associated
3973object.
3974
3975It might be important to emphasize that @code{BUILT_SOURCES} is
3976honored only by @code{make all}, @code{make check} and @code{make
3977install}. This means you cannot build a specific target (e.g.,
3978@code{make foo}) in a clean tree if it depends on a built source.
3979However it will succeed if you have run @code{make all} earlier,
3980because accurate dependencies are already available.
3981
3982The next section illustrates and discusses the handling of built sources
3983on a toy example.
3984
3985@menu
3986* Built sources example:: Several ways to handle built sources.
3987@end menu
3988
3989@node Built sources example, , Sources, Sources
3990@subsection Built sources example
3991
3992Suppose that @file{foo.c} includes @file{bindir.h}, which is
3993installation-dependent and not distributed: it needs to be built. Here
3994@file{bindir.h} defines the preprocessor macro @code{bindir} to the
3995value of the @command{make} variable @code{bindir} (inherited from
3996@file{configure}).
3997
3998We suggest several implementations below. It's not meant to be an
3999exhaustive listing of all ways to handle built sources, but it will give
4000you a few ideas if you encounter this issue.
4001
4002@unnumberedsubsec First try
4003
4004This first implementation will illustrate the bootstrap issue mentioned
4005in the previous section (@pxref{Sources}).
4006
4007Here is a tentative @file{Makefile.am}.
4008
4009@example
4010# This won't work.
4011bin_PROGRAMS = foo
4012foo_SOURCES = foo.c
4013nodist_foo_SOURCES = bindir.h
4014CLEANFILES = bindir.h
4015bindir.h: Makefile
4016 echo '#define bindir "$(bindir)"' >$@@
4017@end example
4018
4019This setup doesn't work, because Automake doesn't know that @file{foo.c}
4020includes @file{bindir.h}. Remember, automatic dependency tracking works
4021as a side-effect of compilation, so the dependencies of @file{foo.o} will
4022be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
4023The symptom is as follows.
4024
4025@example
4026% make
4027source='foo.c' object='foo.o' libtool=no \
4028depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
4029depmode=gcc /bin/sh ./depcomp \
4030gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
4031foo.c:2: bindir.h: No such file or directory
4032make: *** [foo.o] Error 1
4033@end example
4034
4035@unnumberedsubsec Using @code{BUILT_SOURCES}
4036
4037A solution is to require @file{bindir.h} to be built before anything
4038else. This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
4039
4040@example
4041bin_PROGRAMS = foo
4042foo_SOURCES = foo.c
4043BUILT_SOURCES = bindir.h
4044CLEANFILES = bindir.h
4045bindir.h: Makefile
4046 echo '#define bindir "$(bindir)"' >$@@
4047@end example
4048
4049See how @file{bindir.h} get built first:
4050
4051@example
4052% make
4053echo '#define bindir "/usr/local/bin"' >bindir.h
4054make all-am
4055make[1]: Entering directory `/home/adl/tmp'
4056source='foo.c' object='foo.o' libtool=no \
4057depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
4058depmode=gcc /bin/sh ./depcomp \
4059gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
4060gcc -g -O2 -o foo foo.o
4061make[1]: Leaving directory `/home/adl/tmp'
4062@end example
4063
4064However, as said earlier, @code{BUILT_SOURCES} applies only to the
4065@code{all}, @code{check}, and @code{install} targets. It still fails
4066if you try to run @code{make foo} explicitly:
4067
4068@example
4069% make clean
4070test -z "bindir.h" || rm -f bindir.h
4071test -z "foo" || rm -f foo
4072rm -f *.o core *.core
4073% : > .deps/foo.Po # Suppress previously recorded dependencies
4074% make foo
4075source='foo.c' object='foo.o' libtool=no \
4076depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
4077depmode=gcc /bin/sh ./depcomp \
4078gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
4079foo.c:2: bindir.h: No such file or directory
4080make: *** [foo.o] Error 1
4081@end example
4082
4083@unnumberedsubsec Recording dependencies manually
4084
4085Usually people are happy enough with @code{BUILT_SOURCES} because they
4086never run targets such as @code{make foo} before @code{make all}, as in
4087the previous example. However if this matters to you, you can avoid
4088@code{BUILT_SOURCES} and record such dependencies explicitly in the
4089@file{Makefile.am}.
4090
4091@example
4092bin_PROGRAMS = foo
4093foo_SOURCES = foo.c
4094foo.$(OBJEXT): bindir.h
4095CLEANFILES = bindir.h
4096bindir.h: Makefile
4097 echo '#define bindir "$(bindir)"' >$@@
4098@end example
4099
4100You don't have to list @emph{all} the dependencies of @code{foo.o}
4101explicitly, only those which might need to be built. If a dependency
4102already exists, it will not hinder the first compilation and will be
4103recorded by the normal dependency tracking code. (Note that after this
4104first compilation the dependency tracking code will also have recorded
4105the dependency between @code{foo.o} and @code{bindir.h}; so our explicit
4106dependency is really useful to the first build only.)
4107
4108Adding explicit dependencies like this can be a bit dangerous if you are
4109not careful enough. This is due to the way Automake tries not to
4110overwrite your rules (it assumes you know better than it).
4111@code{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
4112output to build @code{foo.$(OBJEXT)}. It happens to work in this case
4113because Automake doesn't have to output any @code{foo.$(OBJEXT):}
4114target: it relies on a suffix rule instead (i.e., @code{.c.$(OBJEXT):}).
4115Always check the generated @file{Makefile.in} if you do this.
4116
4117@unnumberedsubsec Build @file{bindir.h} from @file{configure}
4118
4119It's possible to define this preprocessor macro from @file{configure},
4120either in @file{config.h} (@pxref{Defining Directories, , Defining
4121Directories, autoconf, The Autoconf Manual}), or by processing a
4122@file{bindir.h.in} file using @code{AC_CONFIG_FILES}
4123(@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
4124Autoconf Manual}).
4125
4126At this point it should be clear that building @file{bindir.h} from
4127@file{configure} work well for this example. @file{bindir.h} will exist
4128before you build any target, hence will not cause any dependency issue.
4129
4130The Makefile can be shrunk as follows. We do not even have to mention
4131@file{bindir.h}.
4132
4133@example
4134bin_PROGRAMS = foo
4135foo_SOURCES = foo.c
4136@end example
4137
4138However, it's not always possible to build sources from
4139@file{configure}, especially when these sources are generated by a tool
4140that needs to be built first...
4141
4142@unnumberedsubsec Build @file{bindir.c}, not @file{bindir.h}.
4143
4144Another attractive idea is to define @code{bindir} as a variable or
4145function exported from @file{bindir.o}, and build @file{bindir.c}
4146instead of @file{bindir.h}.
4147
4148@example
4149noinst_PROGRAMS = foo
4150foo_SOURCES = foo.c bindir.h
4151nodist_foo_SOURCES = bindir.c
4152CLEANFILES = bindir.c
4153bindir.c: Makefile
4154 echo 'const char bindir[] = "$(bindir)";' >$@
4155@end example
4156
4157@file{bindir.h} contains just the variable's declaration and doesn't
4158need to be built, so it won't cause any trouble. @file{bindir.o} is
4159always dependent on @file{bindir.c}, so @file{bindir.c} will get built
4160first.
4161
4162@unnumberedsubsec Which is best?
4163
4164There is no panacea, of course. Each solution has its merits and
4165drawbacks.
4166
4167You cannot use @code{BUILT_SOURCES} if the ability to run @code{make
4168foo} on a clean tree is important to you.
4169
4170You won't add explicit dependencies if you are leery of overriding
4171an Automake target by mistake.
4172
4173Building files from @file{./configure} is not always possible, neither
4174is converting @file{.h} files into @file{.c} files.
4175
4176
4177@node Other GNU Tools, Documentation, Other objects, Top
4178@chapter Other GNU Tools
4179
4180Since Automake is primarily intended to generate @file{Makefile.in}s for
4181use in GNU programs, it tries hard to interoperate with other GNU tools.
4182
4183@menu
4184* Emacs Lisp:: Emacs Lisp
4185* gettext:: Gettext
4186* Libtool:: Libtool
4187* Java:: Java
4188* Python:: Python
4189@end menu
4190
4191
4192@node Emacs Lisp, gettext, Other GNU Tools, Other GNU Tools
4193@section Emacs Lisp
4194
4195@cindex _LISP primary, defined
4196@cindex LISP primary, defined
4197@cindex Primary variable, LISP
4198
4199@vindex LISP
4200@vindex lisp_LISP
4201@vindex noinst_LISP
4202
4203Automake provides some support for Emacs Lisp. The @samp{LISP} primary
4204is used to hold a list of @file{.el} files. Possible prefixes for this
4205primary are @samp{lisp_} and @samp{noinst_}. Note that if
4206@code{lisp_LISP} is defined, then @file{configure.in} must run
4207@code{AM_PATH_LISPDIR} (@pxref{Macros}).
4208
4209@vindex ELCFILES
4210
4211By default Automake will byte-compile all Emacs Lisp source files using
4212the Emacs found by @code{AM_PATH_LISPDIR}. If you wish to avoid
4213byte-compiling, simply define the variable @code{ELCFILES} to be empty.
4214Byte-compiled Emacs Lisp files are not portable among all versions of
4215Emacs, so it makes sense to turn this off if you expect sites to have
4216more than one version of Emacs installed. Furthermore, many packages
4217don't actually benefit from byte-compilation. Still, we recommend that
4218you leave it enabled by default. It is probably better for sites with
4219strange setups to cope for themselves than to make the installation less
4220nice for everybody else.
4221
4222@vindex dist_lisp_LISP
4223@vindex dist_noinst_LISP
4224Lisp sources are not distributed by default. You can prefix the
4225@code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
4226@code{dist_noinst_LISP}, to indicate that these files should be
4227distributed.
4228
4229@node gettext, Libtool, Emacs Lisp, Other GNU Tools
4230@section Gettext
4231
4232@cindex GNU Gettext support
4233@cindex Gettext support
4234@cindex Support for GNU Gettext
4235
4236If @code{AM_GNU_GETTEXT} is seen in @file{configure.in}, then Automake
4237turns on support for GNU gettext, a message catalog system for
4238internationalization
4239(@pxref{GNU Gettext, , , gettext, GNU gettext utilities}).
4240
4241The @code{gettext} support in Automake requires the addition of two
4242subdirectories to the package, @file{intl} and @file{po}. Automake
4243insures that these directories exist and are mentioned in
4244@code{SUBDIRS}.
4245
4246
4247@node Libtool, Java, gettext, Other GNU Tools
4248@section Libtool
4249
4250Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
4251libtool, The Libtool Manual}) with the @samp{LTLIBRARIES} primary.
4252@xref{A Shared Library}.
4253
4254
4255@node Java, Python, Libtool, Other GNU Tools
4256@section Java
4257
4258@cindex _JAVA primary, defined
4259@cindex JAVA primary, defined
4260@cindex Primary variable, JAVA
4261
4262Automake provides some minimal support for Java compilation with the
4263@samp{JAVA} primary.
4264
4265Any @file{.java} files listed in a @samp{_JAVA} variable will be
4266compiled with @code{JAVAC} at build time. By default, @file{.class}
4267files are not included in the distribution.
4268
4269@cindex JAVA restrictions
4270@cindex Restrictions for JAVA
4271
4272Currently Automake enforces the restriction that only one @samp{_JAVA}
4273primary can be used in a given @file{Makefile.am}. The reason for this
4274restriction is that, in general, it isn't possible to know which
4275@file{.class} files were generated from which @file{.java} files -- so
4276it would be impossible to know which files to install where. For
4277instance, a @file{.java} file can define multiple classes; the resulting
4278@file{.class} file names cannot be predicted without parsing the
4279@file{.java} file.
4280
4281There are a few variables which are used when compiling Java sources:
4282
4283@vtable @code
4284@item JAVAC
4285The name of the Java compiler. This defaults to @samp{javac}.
4286
4287@item JAVACFLAGS
4288The flags to pass to the compiler. This is considered to be a user
4289variable (@pxref{User Variables}).
4290
4291@item AM_JAVACFLAGS
4292More flags to pass to the Java compiler. This, and not
4293@code{JAVACFLAGS}, should be used when it is necessary to put Java
4294compiler flags into @file{Makefile.am}.
4295
4296@item JAVAROOT
4297The value of this variable is passed to the @samp{-d} option to
4298@code{javac}. It defaults to @samp{$(top_builddir)}.
4299
4300@item CLASSPATH_ENV
4301This variable is an @code{sh} expression which is used to set the
4302@code{CLASSPATH} environment variable on the @code{javac} command line.
4303(In the future we will probably handle class path setting differently.)
4304@end vtable
4305
4306
4307@node Python, , Java, Other GNU Tools
4308@section Python
4309
4310@cindex _PYTHON primary, defined
4311@cindex PYTHON primary, defined
4312@cindex Primary variable, PYTHON
4313
4314
4315Automake provides support for Python compilation with the @samp{PYTHON}
4316primary.
4317
4318Any files listed in a @samp{_PYTHON} variable will be byte-compiled with
4319@code{py-compile} at install time. @code{py-compile} actually creates
4320both standard (@file{.pyc}) and byte-compiled (@file{.pyo}) versions of
4321the source files. Note that because byte-compilation occurs at install
4322time, any files listed in @samp{noinst_PYTHON} will not be compiled.
4323Python source files are included in the distribution by default.
4324
4325Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON} which
4326will determine some Python-related directory variables (see below). If
4327you have called @code{AM_PATH_PYTHON} from @file{configure.in}, then you
4328may use the following variables to list you Python source files in your
4329variables: @samp{python_PYTHON}, @samp{pkgpython_PYTHON},
4330@samp{pyexecdir_PYTHON}, @samp{pkgpyexecdir_PYTHON}, depending where you
4331want your files installed.
4332
4333@code{AM_PATH_PYTHON} takes a single optional argument. This argument,
4334if present, is the minimum version of Python which can be used for this
4335package. If the version of Python found on the system is older than the
4336required version, then @code{AM_PATH_PYTHON} will cause an error.
4337
4338@code{AM_PATH_PYTHON} creates several output variables based on the
4339Python installation found during configuration.
4340
4341@vtable @code
4342@item PYTHON
4343The name of the Python executable.
4344
4345@item PYTHON_VERSION
4346The Python version number, in the form @var{major}.@var{minor}
4347(e.g. @samp{1.5}). This is currently the value of
4348@code{sys.version[:3]}.
4349
4350@item PYTHON_PREFIX
4351The string @code{$@{prefix@}}. This term may be used in future work
4352which needs the contents of Python's @code{sys.prefix}, but general
4353consensus is to always use the value from configure.
4354
4355@item PYTHON_EXEC_PREFIX
4356The string @code{$@{exec_prefix@}}. This term may be used in future work
4357which needs the contents of Python's @code{sys.exec_prefix}, but general
4358consensus is to always use the value from configure.
4359
4360@item PYTHON_PLATFORM
4361The canonical name used by Python to describe the operating system, as
4362given by @code{sys.platform}. This value is sometimes needed when
4363building Python extensions.
4364
4365@item pythondir
4366The directory name for the @file{site-packages} subdirectory of the
4367standard Python install tree.
4368
4369@item pkgpythondir
4370This is is the directory under @code{pythondir} which is named after the
4371package. That is, it is @samp{$(pythondir)/$(PACKAGE)}. It is provided
4372as a convenience.
4373
4374@item pyexecdir
4375This is the directory where Python extension modules (shared libraries)
4376should be installed.
4377
4378@item pkgpyexecdir
4379This is a convenience variable which is defined as
4380@samp{$(pyexecdir)/$(PACKAGE)}.
4381@end vtable
4382
4383All these directory variables have values that start with either
4384@code{$@{prefix@}} or @code{$@{exec_prefix@}} unexpanded. This works
4385fine in @file{Makefiles}, but it makes these variables hard to use in
4386@file{configure}. This is mandated by the GNU coding standards, so
4387that the user can run @code{make prefix=/foo install}. The Autoconf
4388manual has a section with more details on this topic
4389(@pxref{Installation Directory Variables, , Installation Directory
4390Variables, autoconf, The Autoconf Manual}).
4391
4392
4393@node Documentation, Install, Other GNU Tools, Top
4394@chapter Building documentation
4395
4396Currently Automake provides support for Texinfo and man pages.
4397
4398@menu
4399* Texinfo:: Texinfo
4400* Man pages:: Man pages
4401@end menu
4402
4403
4404@node Texinfo, Man pages, Documentation, Documentation
4405@section Texinfo
4406
4407@cindex _TEXINFOS primary, defined
4408@cindex TEXINFOS primary, defined
4409@cindex Primary variable, TEXINFOS
4410
4411If the current directory contains Texinfo source, you must declare it
4412with the @samp{TEXINFOS} primary. Generally Texinfo files are converted
4413into info, and thus the @code{info_TEXINFOS} variable is most commonly used
4414here. Any Texinfo source file must end in the @file{.texi},
4415@file{.txi}, or @file{.texinfo} extension. We recommend @file{.texi}
4416for new manuals.
4417@vindex TEXINFOS
4418@vindex info_TEXINFOS
4419
4420Automake generates rules to build @file{.info}, @file{.dvi}, @file{.ps},
4421and @file{.pdf} files from your Texinfo sources. The @file{.info} files
4422are built by @code{make all} and installed by @code{make install}
4423(unless you use @code{no-installinfo}, see below). The other files can
4424be built on request by @code{make dvi}, @code{make ps}, and @code{make
4425pdf}.
4426
4427@cindex Texinfo flag, VERSION
4428@cindex Texinfo flag, UPDATED
4429@cindex Texinfo flag, EDITION
4430@cindex Texinfo flag, UPDATED-MONTH
4431
4432@cindex VERSION Texinfo flag
4433@cindex UPDATED Texinfo flag
4434@cindex EDITION Texinfo flag
4435@cindex UPDATED-MONTH Texinfo flag
4436
4437@cindex mdate-sh
4438
4439If the @file{.texi} file @code{@@include}s @file{version.texi}, then
4440that file will be automatically generated. The file @file{version.texi}
4441defines four Texinfo flag you can reference using
4442@code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
4443@code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
4444
4445@table @code
4446@item EDITION
4447@itemx VERSION
4448Both of these flags hold the version number of your program. They are
4449kept separate for clarity.
4450
4451@item UPDATED
4452This holds the date the primary @file{.texi} file was last modified.
4453
4454@item UPDATED-MONTH
4455This holds the name of the month in which the primary @file{.texi} file
4456was last modified.
4457@end table
4458
4459The @file{version.texi} support requires the @code{mdate-sh} program;
4460this program is supplied with Automake and automatically included when
4461@code{automake} is invoked with the @code{--add-missing} option.
4462
4463If you have multiple Texinfo files, and you want to use the
4464@file{version.texi} feature, then you have to have a separate version
4465file for each Texinfo file. Automake will treat any include in a
4466Texinfo file that matches @samp{vers*.texi} just as an automatically
4467generated version file.
4468
4469When an info file is rebuilt, the program named by the @code{MAKEINFO}
4470variable is used to invoke it. If the @code{makeinfo} program is found
4471on the system then it will be used by default; otherwise @code{missing}
4472will be used instead. The flags in the variables @code{MAKEINFOFLAGS}
4473and @code{AM_MAKEINFOFLAGS} will be passed to the @code{makeinfo}
4474invocation; the first of these is intended for use by the user
4475(@pxref{User Variables}) and the second by the @file{Makefile.am}
4476writer.
4477@vindex MAKEINFO
4478@vindex MAKEINFOFLAGS
4479@vindex AM_MAKEINFOFLAGS
4480
4481Sometimes an info file actually depends on more than one @file{.texi}
4482file. For instance, in GNU Hello, @file{hello.texi} includes the file
4483@file{gpl.texi}. You can tell Automake about these dependencies using
4484the @code{@var{texi}_TEXINFOS} variable. Here is how GNU Hello does it:
4485@vindex TEXINFOS
4486@vindex _TEXINFOS
4487
4488@example
4489info_TEXINFOS = hello.texi
4490hello_TEXINFOS = gpl.texi
4491@end example
4492
4493@cindex texinfo.tex
4494
4495By default, Automake requires the file @file{texinfo.tex} to appear in
4496the same directory as the Texinfo source. However, if you used
4497@code{AC_CONFIG_AUX_DIR} in @file{configure.in} (@pxref{Input, , Finding
4498`configure' Input, autoconf, The Autoconf Manual}), then
4499@file{texinfo.tex} is looked for there. Automake supplies
4500@file{texinfo.tex} if @samp{--add-missing} is given.
4501
4502@vindex TEXINFO_TEX
4503
4504If your package has Texinfo files in many directories, you can use the
4505variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
4506@file{texinfo.tex} for your package. The value of this variable should
4507be the relative path from the current @file{Makefile.am} to
4508@file{texinfo.tex}:
4509
4510@example
4511TEXINFO_TEX = ../doc/texinfo.tex
4512@end example
4513
4514@opindex no-texinfo.tex
4515
4516The option @samp{no-texinfo.tex} can be used to eliminate the
4517requirement for @file{texinfo.tex}. Use of the variable
4518@code{TEXINFO_TEX} is preferable, however, because that allows the
4519@code{dvi}, @code{ps}, and @code{pdf} targets to still work.
4520
4521@cindex Target, install-info
4522@cindex Target, noinstall-info
4523@cindex install-info target
4524@cindex noinstall-info target
4525
4526@opindex no-installinfo
4527@trindex install-info
4528
4529Automake generates an @code{install-info} target; some people apparently
4530use this. By default, info pages are installed by @samp{make install}.
4531This can be prevented via the @code{no-installinfo} option.
4532
4533
4534@node Man pages, , Texinfo, Documentation
4535@section Man pages
4536
4537@cindex _MANS primary, defined
4538@cindex MANS primary, defined
4539@cindex Primary variable, MANS
4540
4541A package can also include man pages (but see the GNU standards on this
4542matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.) Man
4543pages are declared using the @samp{MANS} primary. Generally the
4544@code{man_MANS} variable is used. Man pages are automatically installed in
4545the correct subdirectory of @code{mandir}, based on the file extension.
4546@vindex MANS
4547@vindex man_MANS
4548
4549File extensions such as @samp{.1c} are handled by looking for the valid
4550part of the extension and using that to determine the correct
4551subdirectory of @code{mandir}. Valid section names are the digits
4552@samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
4553
4554Sometimes developers prefer to name a man page something like
4555@file{foo.man} in the source, and then rename it to have the correct
4556suffix, e.g. @file{foo.1}, when installing the file. Automake also
4557supports this mode. For a valid section named @var{SECTION}, there is a
4558corresponding directory named @samp{man@var{SECTION}dir}, and a
4559corresponding @samp{_MANS} variable. Files listed in such a variable
4560are installed in the indicated section. If the file already has a
4561valid suffix, then it is installed as-is; otherwise the file suffix is
4562changed to match the section.
4563
4564For instance, consider this example:
4565@example
4566man1_MANS = rename.man thesame.1 alsothesame.1c
4567@end example
4568
4569In this case, @file{rename.man} will be renamed to @file{rename.1} when
4570installed, but the other files will keep their names.
4571
4572@cindex Target, install-man
4573@cindex Target, noinstall-man
4574@cindex install-man target
4575@cindex noinstall-man target
4576
4577@c Use @samp{make install} per documentation: (texi)code.
4578By default, man pages are installed by @samp{make install}. However,
4579since the GNU project does not require man pages, many maintainers do
4580not expend effort to keep the man pages up to date. In these cases, the
4581@code{no-installman} option will prevent the man pages from being
4582installed by default. The user can still explicitly install them via
4583@samp{make install-man}.
4584@opindex no-installman
4585@trindex install-man
4586
4587Here is how the man pages are handled in GNU @code{cpio} (which includes
4588both Texinfo documentation and man pages):
4589
4590@example
4591man_MANS = cpio.1 mt.1
4592EXTRA_DIST = $(man_MANS)
4593@end example
4594
4595Man pages are not currently considered to be source, because it is not
4596uncommon for man pages to be automatically generated. Therefore they
4597are not automatically included in the distribution. However, this can
4598be changed by use of the @samp{dist_} prefix.
4599
4600The @samp{nobase_} prefix is meaningless for man pages and is
4601disallowed.
4602
4603
4604@node Install, Clean, Documentation, Top
4605@chapter What Gets Installed
4606
4607@cindex Installation support
4608@cindex make install support
4609
4610@section Basics of installation
4611
4612Naturally, Automake handles the details of actually installing your
4613program once it has been built. All files named by the various
4614primaries are automatically installed in the appropriate places when the
4615user runs @code{make install}.
4616
4617A file named in a primary is installed by copying the built file into
4618the appropriate directory. The base name of the file is used when
4619installing.
4620
4621@example
4622bin_PROGRAMS = hello subdir/goodbye
4623@end example
4624
4625In this example, both @samp{hello} and @samp{goodbye} will be installed
4626in @code{$(bindir)}.
4627
4628Sometimes it is useful to avoid the basename step at install time. For
4629instance, you might have a number of header files in subdirectories of
4630the source tree which are laid out precisely how you want to install
4631them. In this situation you can use the @samp{nobase_} prefix to
4632suppress the base name step. For example:
4633
4634@example
4635nobase_include_HEADERS = stdio.h sys/types.h
4636@end example
4637
4638Will install @file{stdio.h} in @code{$(includedir)} and @file{types.h}
4639in @code{$(includedir)/sys}.
4640
4641@section The two parts of install
4642
4643Automake generates separate @code{install-data} and @code{install-exec}
4644targets, in case the installer is installing on multiple machines which
4645share directory structure---these targets allow the machine-independent
4646parts to be installed only once. @code{install-exec} installs
4647platform-dependent files, and @code{install-data} installs
4648platform-independent files. The @code{install} target depends on both
4649of these targets. While Automake tries to automatically segregate
4650objects into the correct category, the @file{Makefile.am} author is, in
4651the end, responsible for making sure this is done correctly.
4652@trindex install-data
4653@trindex install-exec
4654@trindex install
4655@cindex Install, two parts of
4656
4657Variables using the standard directory prefixes @samp{data},
4658@samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
4659@samp{pkgdata}, or @samp{pkginclude} (e.g. @samp{data_DATA}) are
4660installed by @samp{install-data}.
4661
4662Variables using the standard directory prefixes @samp{bin}, @samp{sbin},
4663@samp{libexec}, @samp{sysconf}, @samp{localstate}, @samp{lib}, or
4664@samp{pkglib} (e.g. @samp{bin_PROGRAMS}) are installed by
4665@samp{install-exec}.
4666
4667Any variable using a user-defined directory prefix with @samp{exec} in
4668the name (e.g. @samp{myexecbin_PROGRAMS} is installed by
4669@samp{install-exec}. All other user-defined prefixes are installed by
4670@samp{install-data}.
4671
4672@section Extending installation
4673
4674It is possible to extend this mechanism by defining an
4675@code{install-exec-local} or @code{install-data-local} target. If these
4676targets exist, they will be run at @samp{make install} time. These
4677rules can do almost anything; care is required.
4678@trindex install-exec-local
4679@trindex install-data-local
4680
4681Automake also supports two install hooks, @code{install-exec-hook} and
4682@code{install-data-hook}. These hooks are run after all other install
4683rules of the appropriate type, exec or data, have completed. So, for
4684instance, it is possible to perform post-installation modifications
4685using an install hook.
4686@cindex Install hook
4687
4688@section Staged installs
4689
4690@vindex DESTDIR
4691Automake generates support for the @samp{DESTDIR} variable in all
4692install rules. @samp{DESTDIR} is used during the @samp{make install}
4693step to relocate install objects into a staging area. Each object and
4694path is prefixed with the value of @samp{DESTDIR} before being copied
4695into the install area. Here is an example of typical DESTDIR usage:
4696
4697@example
4698make DESTDIR=/tmp/staging install
4699@end example
4700
4701This places install objects in a directory tree built under
4702@file{/tmp/staging}. If @file{/gnu/bin/foo} and
4703@file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
4704would install @file{/tmp/staging/gnu/bin/foo} and
4705@file{/tmp/staging/gnu/share/aclocal/foo.m4}.
4706
4707This feature is commonly used to build install images and packages. For
4708more information, see @ref{Makefile Conventions, , , standards, The GNU
4709Coding Standards}.
4710
4711Support for @samp{DESTDIR} is implemented by coding it directly into the
4712install rules. If your @file{Makefile.am} uses a local install rule
4713(e.g., @code{install-exec-local}) or an install hook, then you must
4714write that code to respect @samp{DESTDIR}.
4715
4716@section Rules for the user
4717
4718Automake also generates an @code{uninstall} target, an
4719@code{installdirs} target, and an @code{install-strip} target.
4720@trindex uninstall
4721@trindex installdirs
4722@trindex install-strip
4723
4724Automake supports @code{uninstall-local} and @code{uninstall-hook}.
4725There is no notion of separate uninstalls for ``exec'' and ``data'', as
4726these features would not provide additional functionality.
4727
4728Note that @code{uninstall} is not meant as a replacement for a real
4729packaging tool.
4730
4731
4732@node Clean, Dist, Install, Top
4733@chapter What Gets Cleaned
4734
4735@cindex make clean support
4736
4737The GNU Makefile Standards specify a number of different clean rules.
4738See @xref{Standard Targets, , Standard Targets for Users, standards,
4739The GNU Coding Standards}.
4740
4741Generally the files that can be cleaned are determined automatically by
4742Automake. Of course, Automake also recognizes some variables that can
4743be defined to specify additional files to clean. These variables are
4744@code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
4745@code{MAINTAINERCLEANFILES}.
4746@vindex MOSTLYCLEANFILES
4747@vindex CLEANFILES
4748@vindex DISTCLEANFILES
4749@vindex MAINTAINERCLEANFILES
4750
4751As the GNU Standards aren't always explicit as to which files should be
4752removed by which target, we've adopted a heuristic which we believe was
4753first formulated by Fran@,{c}ois Pinard:
4754
4755@itemize @bullet
4756@item
4757If @code{make} built it, and it is commonly something that one would
4758want to rebuild (for instance, a @file{.o} file), then
4759@code{mostlyclean} should delete it.
4760
4761@item
4762Otherwise, if @code{make} built it, then @code{clean} should delete it.
4763
4764@item
4765If @code{configure} built it, then @code{distclean} should delete it.
4766
4767@item
4768If the maintainer built it (for instance, a @file{.info} file), then
4769@code{maintainer-clean} should delete it. However
4770@code{maintainer-clean} should not delete anything that needs to exist
4771in order to run @code{./configure && make}.
4772@end itemize
4773
4774We recommend that you follow this same set of heuristics in your
4775@file{Makefile.am}.
4776
4777
4778@node Dist, Tests, Clean, Top
4779@chapter What Goes in a Distribution
4780
4781@section Basics of distribution
4782
4783@cindex make dist
4784
4785The @code{dist} target in the generated @file{Makefile.in} can be used
4786to generate a gzip'd @code{tar} file and other flavors of archive for
4787distribution. The files is named based on the @samp{PACKAGE} and
4788@samp{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
4789(@pxref{Macros}); more precisely the gzip'd @code{tar} file is named
4790@samp{@var{package}-@var{version}.tar.gz}.
4791@cvindex PACKAGE
4792@cvindex VERSION
4793@trindex dist
4794You can use the @code{make} variable @samp{GZIP_ENV} to control how gzip
4795is run. The default setting is @samp{--best}.
4796
4797For the most part, the files to distribute are automatically found by
4798Automake: all source files are automatically included in a distribution,
4799as are all @file{Makefile.am}s and @file{Makefile.in}s. Automake also
4800has a built-in list of commonly used files which are automatically
4801included if they are found in the current directory (either physically,
4802or as the target of a @file{Makefile.am} rule). This list is printed by
4803@samp{automake --help}. Also, files which are read by @code{configure}
4804(i.e. the source files corresponding to the files specified in various
4805Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
4806automatically distributed. Helper scripts installed with
4807@samp{automake --add-missing} are also distributed.
4808
4809Still, sometimes there are files which must be distributed, but which
4810are not covered in the automatic rules. These files should be listed in
4811the @code{EXTRA_DIST} variable. You can mention files from
4812subdirectories in @code{EXTRA_DIST}.
4813
4814You can also mention a directory in @code{EXTRA_DIST}; in this case the
4815entire directory will be recursively copied into the distribution.
4816Please note that this will also copy @emph{everything} in the directory,
4817including CVS/RCS version control files. We recommend against using
4818this feature.
4819@vindex EXTRA_DIST
4820
4821If you define @code{SUBDIRS}, Automake will recursively include the
4822subdirectories in the distribution. If @code{SUBDIRS} is defined
4823conditionally (@pxref{Conditionals}), Automake will normally include all
4824directories that could possibly appear in @code{SUBDIRS} in the
4825distribution. If you need to specify the set of directories
4826conditionally, you can set the variable @code{DIST_SUBDIRS} to the exact
4827list of subdirectories to include in the distribution (@pxref{Top level}).
4828@vindex DIST_SUBDIRS
4829
4830@section Fine-grained distribution control
4831
4832Sometimes you need tighter control over what does @emph{not} go into the
4833distribution; for instance you might have source files which are
4834generated and which you do not want to distribute. In this case
4835Automake gives fine-grained control using the @samp{dist} and
4836@samp{nodist} prefixes. Any primary or @samp{_SOURCES} variable can be
4837prefixed with @samp{dist_} to add the listed files to the distribution.
4838Similarly, @samp{nodist_} can be used to omit the files from the
4839distribution.
4840@vindex dist_
4841@vindex nodist_
4842
4843As an example, here is how you would cause some data to be distributed
4844while leaving some source code out of the distribution:
4845
4846@example
4847dist_data_DATA = distribute-this
4848bin_PROGRAMS = foo
4849nodist_foo_SOURCES = do-not-distribute.c
4850@end example
4851
4852@section The dist hook
4853
4854@trindex dist-hook
4855Occasionally it is useful to be able to change the distribution before
4856it is packaged up. If the @code{dist-hook} target exists, it is run
4857after the distribution directory is filled, but before the actual tar
4858(or shar) file is created. One way to use this is for distributing
4859files in subdirectories for which a new @file{Makefile.am} is overkill:
4860
4861@example
4862dist-hook:
4863 mkdir $(distdir)/random
4864 cp -p $(srcdir)/random/a1 $(srcdir)/random/a2 $(distdir)/random
4865@end example
4866
4867Another way to to use this is for removing unnecessary files that get
4868recursively included by specifying a directory in EXTRA_DIST:
4869
4870@example
4871EXTRA_DIST = doc
4872
4873dist-hook:
4874 rm -rf `find $(distdir)/doc -name CVS`
4875@end example
4876
4877@section Checking the distribution
4878
4879@cindex make distcheck
4880@cindex make distcleancheck
4881@vindex distcleancheck_listfiles
4882@cindex make distuninstallcheck
4883@vindex distuninstallcheck_listfiles
4884
4885Automake also generates a @code{distcheck} target which can be of help
4886to ensure that a given distribution will actually work.
4887@code{distcheck} makes a distribution, then tries to do a @code{VPATH}
4888build, run the test suite, and finally make another tarfile to ensure the
4889distribution is self-contained.
4890@trindex distcheck
4891
4892Building the package involves running @code{./configure}. If you need
4893to supply additional flags to @code{configure}, define them in the
4894@code{DISTCHECK_CONFIGURE_FLAGS} variable, either in your top-level
4895@file{Makefile.am}, or on the command line when invoking @code{make}.
4896@vindex DISTCHECK_CONFIGURE_FLAGS
4897
4898If the target @code{distcheck-hook} is defined in your
4899@file{Makefile.am}, then it will be invoked by @code{distcheck} after
4900the new distribution has been unpacked, but before the unpacked copy is
4901configured and built. Your @code{distcheck-hook} can do almost
4902anything, though as always caution is advised. Generally this hook is
4903used to check for potential distribution errors not caught by the
4904standard mechanism.
4905
4906Speaking about potential distribution errors, @code{distcheck} will also
4907ensure that the @code{distclean} target actually removes all built
4908files. This is done by running @code{make distcleancheck} at the end of
4909the @code{VPATH} build. By default, @code{distcleancheck} will run
4910@code{distclean} and then make sure the build tree has been emptied by
4911running @code{$(distcleancheck_listfiles)}. Usually this check will
4912find generated files that you forgot to add to the @code{DISTCLEANFILES}
4913variable (@pxref{Clean}).
4914@trindex distcleancheck
4915
4916The @code{distcleancheck} behavior should be OK for most packages,
4917otherwise you have the possibility to override the definition of
4918either the @code{distcleancheck} target, or the
4919@code{$(distcleancheck_listfiles)} variable. For instance to disable
4920@code{distcleancheck} completely, add the following rule to your
4921top-level @file{Makefile.am}:
4922@vindex distcleancheck_listfiles
4923
4924@example
4925distcleancheck:
4926 @@:
4927@end example
4928
4929If you want @code{distcleancheck} to ignore built files which have not
4930been cleaned because they are also part of the distribution, add the
4931following definition instead:
4932
4933@example
4934distcleancheck_listfiles = \
4935 find -type f -exec sh -c 'test -f $(srcdir)/@{@} || echo @{@}' ';'
4936@end example
4937
4938The above definition is not the default because it's usually an error if
4939your Makefiles cause some distributed files to be rebuilt when the user
4940build the package. (Think about the user missing the tool required to
4941build the file; or if the required tool is built by your package,
4942consider the cross-compilation case where it can't be run.) There is
4943a FAQ entry about this (@pxref{distcleancheck}), make sure you read it
4944before playing with @code{distcleancheck_listfiles}.
4945
4946@code{distcheck} also checks that the @code{uninstall} target works
4947properly, both for ordinary and @samp{DESTDIR} builds. It does this
4948by invoking @code{make uninstall}, and then it checks the install tree
4949to see if any files are left over. This check will make sure that you
4950correctly coded your @code{uninstall}-related targets.
4951
4952By default, the checking is done by the @code{distuninstallcheck} target,
4953and the list of files in the install tree is generated by
4954@code{$(distuninstallcheck_listfiles}) (this is a variable whose value is
4955a shell command to run that prints the list of files to stdout).
4956
4957Either of these can be overridden to modify the behavior of
4958@code{distcheck}. For instance, to disable this check completely, you
4959would write:
4960
4961@example
4962distuninstallcheck:
4963 @@:
4964@end example
4965
4966@section The types of distributions
4967
4968@trindex dist-gzip
4969Automake generates a @samp{.tar.gz} file when asked to create a
4970distribution and other archives formats, @ref{Options}. The target
4971@code{dist-gzip} generates the @samp{.tar.gz} file only.
4972
4973
4974@node Tests, Options, Dist, Top
4975@chapter Support for test suites
4976
4977@cindex Test suites
4978@cindex make check
4979
4980Automake supports two forms of test suites.
4981
4982@section Simple Tests
4983
4984If the variable @code{TESTS} is defined, its value is taken to be a list
4985of programs to run in order to do the testing. The programs can either
4986be derived objects or source objects; the generated rule will look both
4987in @code{srcdir} and @file{.}. Programs needing data files should look
4988for them in @code{srcdir} (which is both an environment variable and a
4989make variable) so they work when building in a separate directory
4990(@pxref{Build Directories, , Build Directories , autoconf, The Autoconf
4991Manual}), and in particular for the @code{distcheck} target
4992(@pxref{Dist}).
4993
4994@cindex Exit status 77, special interpretation
4995
4996The number of failures will be printed at the end of the run. If a
4997given test program exits with a status of 77, then its result is ignored
4998in the final count. This feature allows non-portable tests to be
4999ignored in environments where they don't make sense.
5000
5001The variable @code{TESTS_ENVIRONMENT} can be used to set environment
5002variables for the test run; the environment variable @code{srcdir} is
5003set in the rule. If all your test programs are scripts, you can also
5004set @code{TESTS_ENVIRONMENT} to an invocation of the shell (e.g.
5005@samp{$(SHELL) -x}); this can be useful for debugging the tests.
5006@vindex TESTS
5007@vindex TESTS_ENVIRONMENT
5008
5009@cindex Tests, expected failure
5010@cindex Expected test failure
5011
5012You may define the variable @code{XFAIL_TESTS} to a list of tests
5013(usually a subset of @code{TESTS}) that are expected to fail. This will
5014reverse the result of those tests.
5015@vindex XFAIL_TESTS
5016
5017Automake ensures that each program listed in @code{TESTS} is built
5018before any tests are run; you can list both source and derived programs
5019in @code{TESTS}. For instance, you might want to run a C program as a
5020test. To do this you would list its name in @code{TESTS} and also in
5021@code{check_PROGRAMS}, and then specify it as you would any other
5022program.
5023
5024@section DejaGnu Tests
5025
5026If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @samp{dejagnu}} appears in
5027@code{AUTOMAKE_OPTIONS}, then a @code{dejagnu}-based test suite is
5028assumed. The variable @code{DEJATOOL} is a list of names which are
5029passed, one at a time, as the @code{--tool} argument to @code{runtest}
5030invocations; it defaults to the name of the package.
5031
5032The variable @code{RUNTESTDEFAULTFLAGS} holds the @code{--tool} and
5033@code{--srcdir} flags that are passed to dejagnu by default; this can be
5034overridden if necessary.
5035@vindex RUNTESTDEFAULTFLAGS
5036
5037The variables @code{EXPECT} and @code{RUNTEST} can
5038also be overridden to provide project-specific values. For instance,
5039you will need to do this if you are testing a compiler toolchain,
5040because the default values do not take into account host and target
5041names.
5042@opindex dejagnu
5043@vindex DEJATOOL
5044@vindex EXPECT
5045@vindex RUNTEST
5046
5047The contents of the variable @code{RUNTESTFLAGS} are passed to the
5048@code{runtest} invocation. This is considered a ``user variable''
5049(@pxref{User Variables}). If you need to set @code{runtest} flags in
5050@file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
5051@vindex RUNTESTFLAGS
5052@vindex AM_RUNTESTFLAGS
5053
5054@cindex @file{site.exp}
5055Automake will generate rules to create a local @file{site.exp} file,
5056defining various variables detected by @code{./configure}. This file
5057is automatically read by DejaGnu. It is OK for the user of a package
5058to edit this file in order to tune the test suite. However this is
5059not the place where the test suite author should define new variables:
5060this should be done elsewhere in the real test suite code.
5061Especially, @file{site.exp} should not be distributed.
5062
5063For more information regarding DejaGnu test suites, see @xref{Top, , ,
5064dejagnu, The DejaGnu Manual}.
5065
5066In either case, the testing is done via @samp{make check}.
5067
5068@section Install Tests
5069
5070The @code{installcheck} target is available to the user as a way to run
5071any tests after the package has been installed. You can add tests to
5072this by writing an @code{installcheck-local} target.
5073
5074
5075@node Options, Miscellaneous, Tests, Top
5076@chapter Changing Automake's Behavior
5077
5078Various features of Automake can be controlled by options in the
5079@file{Makefile.am}. Such options are applied on a per-@file{Makefile}
5080basis when listed in a special @file{Makefile} variable named
5081@code{AUTOMAKE_OPTIONS}. They are applied globally to all processed
5082@file{Makefiles} when listed in the first argument of
5083@code{AM_INIT_AUTOMAKE} in @file{configure.in}. Currently understood
5084options are:
5085@vindex AUTOMAKE_OPTIONS
5086
5087@table @asis
5088@item @code{gnits}
5089@itemx @code{gnu}
5090@itemx @code{foreign}
5091@itemx @code{cygnus}
5092@cindex Option, gnits
5093@cindex Option, gnu
5094@cindex Option, foreign
5095@cindex Option, cygnus
5096
5097Set the strictness as appropriate. The @code{gnits} option also implies
5098@code{readme-alpha} and @code{check-news}.
5099
5100@item @code{ansi2knr}
5101@itemx @code{@var{path}/ansi2knr}
5102@cindex Option, ansi2knr
5103Turn on automatic de-ANSI-fication. @xref{ANSI}. If preceded by a
5104path, the generated @file{Makefile.in} will look in the specified
5105directory to find the @file{ansi2knr} program. The path should be a
5106relative path to another directory in the same distribution (Automake
5107currently does not check this).
5108
5109@item @code{check-news}
5110@cindex Option, check-news
5111Cause @code{make dist} to fail unless the current version number appears
5112in the first few lines of the @file{NEWS} file.
5113
5114@item @code{dejagnu}
5115@cindex Option, dejagnu
5116Cause @code{dejagnu}-specific rules to be generated. @xref{Tests}.
5117
5118@item @code{dist-bzip2}
5119@cindex Option, dist-bzip2
5120Generate a @code{dist-bzip2} target, creating a bzip2 tar archive of the
5121distribution. @code{dist} will create it in addition to the other
5122formats. bzip2 archives are frequently smaller than gzipped archives.
5123@trindex dist-bzip2
5124
5125@item @code{dist-shar}
5126@cindex Option, dist-shar
5127Generate a @code{dist-shar} target, creating a shar archive of the
5128distribution. @code{dist} will create it in addition to the other
5129formats.
5130@trindex dist-shar
5131
5132@item @code{dist-zip}
5133@cindex Option, dist-zip
5134Generate a @code{dist-zip} target, creating a zip archive of the
5135distribution. @code{dist} will create it in addition to the other
5136formats.
5137@trindex dist-zip
5138
5139@item @code{dist-tarZ}
5140@cindex Option, dist-tarZ
5141Generate a @code{dist-tarZ} target, creating a compressed tar archive of
5142the distribution. @code{dist} will create it in addition to the other
5143formats.
5144@trindex dist-tarZ
5145
5146@item @code{no-define}
5147@cindex Option, no-define
5148This options is meaningful only when passed as an argument to
5149@code{AM_INIT_AUTOMAKE}. It will prevent the @code{PACKAGE} and
5150@code{VERSION} variables to be @code{AC_DEFINE}d.
5151
5152@item @code{no-dependencies}
5153@cindex Option, no-dependencies
5154This is similar to using @samp{--include-deps} on the command line, but
5155is useful for those situations where you don't have the necessary bits
5156to make automatic dependency tracking work @xref{Dependencies}. In this
5157case the effect is to effectively disable automatic dependency tracking.
5158
5159@item @code{no-exeext}
5160@cindex Option, no-exeext
5161If your @file{Makefile.am} defines a target @samp{foo}, it will override
5162a target named @samp{foo$(EXEEXT)}. This is necessary when
5163@code{EXEEXT} is found to be empty. However, by default automake will
5164generate an error for this use. The @code{no-exeext} option will
5165disable this error. This is intended for use only where it is known in
5166advance that the package will not be ported to Windows, or any other
5167operating system using extensions on executables.
5168
5169@item @code{no-installinfo}
5170@cindex Option, no-installinfo
5171The generated @file{Makefile.in} will not cause info pages to be built
5172or installed by default. However, @code{info} and @code{install-info}
5173targets will still be available. This option is disallowed at
5174@samp{GNU} strictness and above.
5175@trindex info
5176@trindex install-info
5177
5178@item @code{no-installman}
5179@cindex Option, no-installman
5180The generated @file{Makefile.in} will not cause man pages to be
5181installed by default. However, an @code{install-man} target will still
5182be available for optional installation. This option is disallowed at
5183@samp{GNU} strictness and above.
5184@trindex install-man
5185
5186@item @code{nostdinc}
5187@cindex Option, nostdinc
5188This option can be used to disable the standard @samp{-I} options which
5189are ordinarily automatically provided by Automake.
5190
5191@item @code{no-texinfo.tex}
5192@cindex Option, no-texinfo
5193Don't require @file{texinfo.tex}, even if there are texinfo files in
5194this directory.
5195
5196@item @code{readme-alpha}
5197@cindex Option, readme-alpha
5198If this release is an alpha release, and the file @file{README-alpha}
5199exists, then it will be added to the distribution. If this option is
5200given, version numbers are expected to follow one of two forms. The
5201first form is @samp{@var{MAJOR}.@var{MINOR}.@var{ALPHA}}, where each
5202element is a number; the final period and number should be left off for
5203non-alpha releases. The second form is
5204@samp{@var{MAJOR}.@var{MINOR}@var{ALPHA}}, where @var{ALPHA} is a
5205letter; it should be omitted for non-alpha releases.
5206
5207@item @code{std-options}
5208@cindex Options, std-options
5209@cindex make installcheck
5210Make the @code{installcheck} target check that installed scripts and
5211programs support the @code{--help} and @code{--version} options.
5212This also provides a basic check that the program's
5213run-time dependencies are satisfied after installation.
5214
5215@vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
5216In a few situations, programs (or scripts) have to be exempted from this
5217test. For instance @command{false} (from GNU sh-utils) is never
5218successful, even for @code{--help} or @code{--version}. You can list
5219such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
5220Programs (not scripts) listed in this variable should be suffixed by
5221@code{$(EXEEXT)} for the sake of Win32 or OS/2. For instance suppose we
5222build @code{false} as a program but @code{true.sh} as a script, and that
5223neither of them support @code{--help} or @code{--version}:
5224
5225@example
5226AUTOMAKE_OPTIONS = std-options
5227bin_PROGRAMS = false ...
5228bin_SCRIPTS = true.sh ...
5229AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
5230@end example
5231
5232@item @code{subdir-objects}
5233If this option is specified, then objects are placed into the
5234subdirectory of the build directory corresponding to the subdirectory of
5235the source file. For instance if the source file is
5236@file{subdir/file.cxx}, then the output file would be
5237@file{subdir/file.o}.
5238
5239@item @var{version}
5240@cindex Option, version
5241A version number (e.g. @samp{0.30}) can be specified. If Automake is not
5242newer than the version specified, creation of the @file{Makefile.in}
5243will be suppressed.
5244
5245@item @code{-W@var{category}} or @code{--warnings=@var{category}}
5246@cindex Option, warnings
5247These options behave exactly like their command-line counterpart
5248(@pxref{Invoking Automake}). This allows you to enable or disable some
5249warning categories on a per-file basis. You can also setup some warnings
5250for your entire project; for instance try @code{AM_INIT_AUTOMAKE([-Wall])}
5251in your @file{configure.in}.
5252
5253@end table
5254
5255Unrecognized options are diagnosed by @code{automake}.
5256
5257If you want an option to apply to all the files in the tree, you can use
5258the @code{AM_INIT_AUTOMAKE} macro in @file{configure.in}.
5259@xref{Macros}.
5260
5261
5262@node Miscellaneous, Include, Options, Top
5263@chapter Miscellaneous Rules
5264
5265There are a few rules and variables that didn't fit anywhere else.
5266
5267@menu
5268* Tags:: Interfacing to etags and mkid
5269* Suffixes:: Handling new file extensions
5270* Multilibs:: Support for multilibs.
5271@end menu
5272
5273
5274@node Tags, Suffixes, Miscellaneous, Miscellaneous
5275@section Interfacing to @code{etags}
5276
5277@cindex TAGS support
5278
5279Automake will generate rules to generate @file{TAGS} files for use with
5280GNU Emacs under some circumstances.
5281
5282If any C, C++ or Fortran 77 source code or headers are present, then
5283@code{tags} and @code{TAGS} targets will be generated for the directory.
5284@trindex tags
5285
5286At the topmost directory of a multi-directory package, a @code{tags}
5287target file will be generated which, when run, will generate a
5288@file{TAGS} file that includes by reference all @file{TAGS} files from
5289subdirectories.
5290
5291The @code{tags} target will also be generated if the variable
5292@code{ETAGS_ARGS} is defined. This variable is intended for use in
5293directories which contain taggable source that @code{etags} does not
5294understand. The user can use the @code{ETAGSFLAGS} to pass additional
5295flags to @code{etags}; @code{AM_ETAGSFLAGS} is also available for use in
5296@file{Makefile.am}.
5297@vindex ETAGS_ARGS
5298@vindex ETAGSFLAGS
5299@vindex AM_ETAGSFLAGS
5300
5301Here is how Automake generates tags for its source, and for nodes in its
5302Texinfo file:
5303
5304@example
5305ETAGS_ARGS = automake.in --lang=none \
5306 --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
5307@end example
5308
5309If you add filenames to @samp{ETAGS_ARGS}, you will probably also
5310want to set @samp{TAGS_DEPENDENCIES}. The contents of this variable
5311are added directly to the dependencies for the @code{tags} target.
5312@vindex TAGS_DEPENDENCIES
5313
5314Automake also generates a @code{ctags} target which can be used to
5315build @command{vi}-style @file{tags} files. The variable @code{CTAGS}
5316is the name of the program to invoke (by default @samp{ctags});
5317@code{CTAGSFLAGS} can be used by the user to pass additional flags,
5318and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
5319
5320Automake will also generate an @code{ID} target which will run
5321@code{mkid} on the source. This is only supported on a
5322directory-by-directory basis.
5323@trindex id
5324
5325Automake also supports the @uref{http://www.gnu.org/software/global/,
5326GNU Global Tags program}. The @code{GTAGS} target runs Global Tags
5327automatically and puts the result in the top build directory. The
5328variable @code{GTAGS_ARGS} holds arguments which are passed to
5329@code{gtags}.
5330@vindex GTAGS_ARGS
5331
5332
5333@node Suffixes, Multilibs, Tags, Miscellaneous
5334@section Handling new file extensions
5335
5336@cindex Adding new SUFFIXES
5337@cindex SUFFIXES, adding
5338@vindex SUFFIXES
5339
5340It is sometimes useful to introduce a new implicit rule to handle a file
5341type that Automake does not know about.
5342
5343For instance, suppose you had a compiler which could compile @samp{.foo}
5344files to @samp{.o} files. You would simply define an suffix rule for
5345your language:
5346
5347@example
5348.foo.o:
5349 foocc -c -o $@@ $<
5350@end example
5351
5352Then you could directly use a @samp{.foo} file in a @samp{_SOURCES}
5353variable and expect the correct results:
5354
5355@example
5356bin_PROGRAMS = doit
5357doit_SOURCES = doit.foo
5358@end example
5359
5360This was the simpler and more common case. In other cases, you will
5361have to help Automake to figure which extensions you are defining your
5362suffix rule for. This usually happens when your extensions does not
5363start with a dot. Then, all you have to do is to put a list of new
5364suffixes in the @code{SUFFIXES} variable @strong{before} you define your
5365implicit rule.
5366
5367For instance the following definition prevents Automake to misinterpret
5368@samp{.idlC.cpp:} as an attempt to transform @samp{.idlC} into
5369@samp{.cpp}.
5370
5371@example
5372SUFFIXES = .idl C.cpp
5373.idlC.cpp:
5374 # whatever
5375@end example
5376
5377As you may have noted, the @code{SUFFIXES} variable behaves like the
5378@code{.SUFFIXES} special target of @code{make}. You should not touch
5379@code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
5380Automake generate the suffix list for @code{.SUFFIXES}. Any given
5381@code{SUFFIXES} go at the start of the generated suffixes list, followed
5382by Automake generated suffixes not already in the list.
5383
5384@node Multilibs, , Suffixes, Miscellaneous
5385@section Support for Multilibs
5386
5387Automake has support for an obscure feature called multilibs. A
5388@dfn{multilib} is a library which is built for multiple different ABIs
5389at a single time; each time the library is built with a different target
5390flag combination. This is only useful when the library is intended to
5391be cross-compiled, and it is almost exclusively used for compiler
5392support libraries.
5393
5394The multilib support is still experimental. Only use it if you are
5395familiar with multilibs and can debug problems you might encounter.
5396
5397
5398@node Include, Conditionals, Miscellaneous, Top
5399@chapter Include
5400
5401@cmindex include
5402@cindex Including Makefile fragment
5403@cindex Makefile fragment, including
5404
5405Automake supports an @code{include} directive which can be used to
5406include other @file{Makefile} fragments when @code{automake} is run.
5407Note that these fragments are read and interpreted by @code{automake},
5408not by @code{make}. As with conditionals, @code{make} has no idea that
5409@code{include} is in use.
5410
5411There are two forms of @code{include}:
5412
5413@table @code
5414@item include $(srcdir)/file
5415Include a fragment which is found relative to the current source
5416directory.
5417
5418@item include $(top_srcdir)/file
5419Include a fragment which is found relative to the top source directory.
5420@end table
5421
5422Note that if a fragment is included inside a conditional, then the
5423condition applies to the entire contents of that fragment.
5424
5425Makefile fragments included this way are always distributed because
5426there are needed to rebuild @file{Makefile.in}.
5427
5428@node Conditionals, Gnits, Include, Top
5429@chapter Conditionals
5430
5431@cindex Conditionals
5432
5433Automake supports a simple type of conditionals.
5434
5435@cvindex AM_CONDITIONAL
5436Before using a conditional, you must define it by using
5437@code{AM_CONDITIONAL} in the @code{configure.in} file (@pxref{Macros}).
5438
5439@defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
5440The conditional name, @var{conditional}, should be a simple string
5441starting with a letter and containing only letters, digits, and
5442underscores. It must be different from @samp{TRUE} and @samp{FALSE}
5443which are reserved by Automake.
5444
5445The shell @var{condition} (suitable for use in a shell @code{if}
5446statement) is evaluated when @code{configure} is run. Note that you
5447must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
5448time @code{configure} is run -- if @code{AM_CONDITIONAL} is run
5449conditionally (e.g., in a shell @code{if} statement), then the result
5450will confuse automake.
5451@end defmac
5452
5453@cindex --enable-debug, example
5454@cindex Example conditional --enable-debug
5455@cindex Conditional example, --enable-debug
5456
5457Conditionals typically depend upon options which the user provides to
5458the @code{configure} script. Here is an example of how to write a
5459conditional which is true if the user uses the @samp{--enable-debug}
5460option.
5461
5462@example
5463AC_ARG_ENABLE(debug,
5464[ --enable-debug Turn on debugging],
5465[case "$@{enableval@}" in
5466 yes) debug=true ;;
5467 no) debug=false ;;
5468 *) AC_MSG_ERROR(bad value $@{enableval@} for --enable-debug) ;;
5469esac],[debug=false])
5470AM_CONDITIONAL(DEBUG, test x$debug = xtrue)
5471@end example
5472
5473Here is an example of how to use that conditional in @file{Makefile.am}:
5474
5475@cmindex if
5476@cmindex endif
5477@cmindex else
5478
5479@example
5480if DEBUG
5481DBG = debug
5482else
5483DBG =
5484endif
5485noinst_PROGRAMS = $(DBG)
5486@end example
5487
5488This trivial example could also be handled using EXTRA_PROGRAMS
5489(@pxref{Conditional Programs}).
5490
5491You may only test a single variable in an @code{if} statement, possibly
5492negated using @samp{!}. The @code{else} statement may be omitted.
5493Conditionals may be nested to any depth. You may specify an argument to
5494@code{else} in which case it must be the negation of the condition used
5495for the current @code{if}. Similarly you may specify the condition
5496which is closed by an @code{end}:
5497
5498@example
5499if DEBUG
5500DBG = debug
5501else !DEBUG
5502DBG =
5503endif !DEBUG
5504@end example
5505
5506@noindent
5507Unbalanced conditions are errors.
5508
5509Note that conditionals in Automake are not the same as conditionals in
5510GNU Make. Automake conditionals are checked at configure time by the
5511@file{configure} script, and affect the translation from
5512@file{Makefile.in} to @file{Makefile}. They are based on options passed
5513to @file{configure} and on results that @file{configure} has discovered
5514about the host system. GNU Make conditionals are checked at @code{make}
5515time, and are based on variables passed to the make program or defined
5516in the @file{Makefile}.
5517
5518Automake conditionals will work with any make program.
5519
5520
5521@node Gnits, Cygnus, Conditionals, Top
5522@chapter The effect of @code{--gnu} and @code{--gnits}
5523
5524@cindex --gnu, required files
5525@cindex --gnu, complete description
5526
5527The @samp{--gnu} option (or @samp{gnu} in the @samp{AUTOMAKE_OPTIONS}
5528variable) causes @code{automake} to check the following:
5529
5530@itemize @bullet
5531@item
5532The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
5533and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
5534or @file{COPYING}, are required at the topmost directory of the package.
5535
5536@item
5537The options @samp{no-installman} and @samp{no-installinfo} are
5538prohibited.
5539@end itemize
5540
5541Note that this option will be extended in the future to do even more
5542checking; it is advisable to be familiar with the precise requirements
5543of the GNU standards. Also, @samp{--gnu} can require certain
5544non-standard GNU programs to exist for use by various maintainer-only
5545targets; for instance in the future @code{pathchk} might be required for
5546@samp{make dist}.
5547
5548@cindex --gnits, complete description
5549
5550The @samp{--gnits} option does everything that @samp{--gnu} does, and
5551checks the following as well:
5552
5553@itemize @bullet
5554@item
5555@samp{make installcheck} will check to make sure that the @code{--help}
5556and @code{--version} really print a usage message and a version string,
5557respectively. This is the @code{std-options} option (@pxref{Options}).
5558
5559@item
5560@samp{make dist} will check to make sure the @file{NEWS} file has been
5561updated to the current version.
5562
5563@item
5564@samp{VERSION} is checked to make sure its format complies with Gnits
5565standards.
5566@c FIXME xref when standards are finished
5567
5568@item
5569@cindex README-alpha
5570If @samp{VERSION} indicates that this is an alpha release, and the file
5571@file{README-alpha} appears in the topmost directory of a package, then
5572it is included in the distribution. This is done in @samp{--gnits}
5573mode, and no other, because this mode is the only one where version
5574number formats are constrained, and hence the only mode where Automake
5575can automatically determine whether @file{README-alpha} should be
5576included.
5577
5578@item
5579The file @file{THANKS} is required.
5580@end itemize
5581
5582
5583@node Cygnus, Extending, Gnits, Top
5584@chapter The effect of @code{--cygnus}
5585
5586@cindex Cygnus strictness
5587
5588Some packages, notably GNU GCC and GNU gdb, have a build environment
5589originally written at Cygnus Support (subsequently renamed Cygnus
5590Solutions, and then later purchased by Red Hat). Packages with this
5591ancestry are sometimes referred to as ``Cygnus'' trees.
5592
5593A Cygnus tree has slightly different rules for how a @file{Makefile.in}
5594is to be constructed. Passing @samp{--cygnus} to @code{automake} will
5595cause any generated @file{Makefile.in} to comply with Cygnus rules.
5596
5597Here are the precise effects of @samp{--cygnus}:
5598
5599@itemize @bullet
5600@item
5601Info files are always created in the build directory, and not in the
5602source directory.
5603
5604@item
5605@file{texinfo.tex} is not required if a Texinfo source file is
5606specified. The assumption is that the file will be supplied, but in a
5607place that Automake cannot find. This assumption is an artifact of how
5608Cygnus packages are typically bundled.
5609
5610@item
5611@samp{make dist} is not supported, and the rules for it are not
5612generated. Cygnus-style trees use their own distribution mechanism.
5613
5614@item
5615Certain tools will be searched for in the build tree as well as in the
5616user's @samp{PATH}. These tools are @code{runtest}, @code{expect},
5617@code{makeinfo} and @code{texi2dvi}.
5618
5619@item
5620@code{--foreign} is implied.
5621
5622@item
5623The options @samp{no-installinfo} and @samp{no-dependencies} are
5624implied.
5625
5626@item
5627The macros @samp{AM_MAINTAINER_MODE} and @samp{AM_CYGWIN32} are
5628required.
5629
5630@item
5631The @code{check} target doesn't depend on @code{all}.
5632@end itemize
5633
5634GNU maintainers are advised to use @samp{gnu} strictness in preference
5635to the special Cygnus mode. Some day, perhaps, the differences between
5636Cygnus trees and GNU trees will disappear (for instance, as GCC is made
5637more standards compliant). At that time the special Cygnus mode will be
5638removed.
5639
5640
5641@node Extending, Distributing, Cygnus, Top
5642@chapter When Automake Isn't Enough
5643
5644Automake's implicit copying semantics means that many problems can be
5645worked around by simply adding some @code{make} targets and rules to
5646@file{Makefile.in}. Automake will ignore these additions.
5647
5648@cindex -local targets
5649@cindex local targets
5650
5651There are some caveats to doing this. Although you can overload a
5652target already used by Automake, it is often inadvisable, particularly
5653in the topmost directory of a package with subdirectories. However,
5654various useful targets have a @samp{-local} version you can specify in
5655your @file{Makefile.in}. Automake will supplement the standard target
5656with these user-supplied targets.
5657
5658@trindex all
5659@trindex all-local
5660@trindex info
5661@trindex info-local
5662@trindex dvi
5663@trindex dvi-local
5664@trindex ps
5665@trindex ps-local
5666@trindex pdf
5667@trindex pdf-local
5668@trindex check
5669@trindex check-local
5670@trindex install
5671@trindex install-data-local
5672@trindex install-exec
5673@trindex install-exec-local
5674@trindex uninstall
5675@trindex uninstall-local
5676@trindex mostlyclean
5677@trindex mostlyclean-local
5678@trindex clean
5679@trindex clean-local
5680@trindex distclean
5681@trindex distclean-local
5682@trindex installdirs
5683@trindex installdirs-local
5684@trindex installcheck
5685@trindex installcheck-local
5686
5687The targets that support a local version are @code{all}, @code{info},
5688@code{dvi}, @code{ps}, @code{pdf}, @code{check}, @code{install-data},
5689@code{install-exec}, @code{uninstall}, @code{installdirs},
5690@code{installcheck} and the various @code{clean} targets
5691(@code{mostlyclean}, @code{clean}, @code{distclean}, and
5692@code{maintainer-clean}). Note that there are no
5693@code{uninstall-exec-local} or @code{uninstall-data-local} targets; just
5694use @code{uninstall-local}. It doesn't make sense to uninstall just
5695data or just executables.
5696
5697For instance, here is one way to install a file in @file{/etc}:
5698
5699@example
5700install-data-local:
5701 $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
5702@end example
5703
5704@cindex -hook targets
5705@cindex hook targets
5706
5707Some targets also have a way to run another target, called a @dfn{hook},
5708after their work is done. The hook is named after the principal target,
5709with @samp{-hook} appended. The targets allowing hooks are
5710@code{install-data}, @code{install-exec}, @code{uninstall}, @code{dist},
5711and @code{distcheck}.
5712@trindex install-data-hook
5713@trindex install-exec-hook
5714@trindex uninstall-hook
5715@trindex dist-hook
5716
5717For instance, here is how to create a hard link to an installed program:
5718
5719@example
5720install-exec-hook:
5721 ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
5722 $(DESTDIR)$(bindir)/proglink$(EXEEXT)
5723@end example
5724
5725Although cheaper and more portable than symbolic links, hard links
5726will not work everywhere (for instance OS/2 does not have
5727@command{ln}). Ideally you should fall back to @code{cp -p} when
5728@code{ln} does not work. An easy way, if symbolic links are
5729acceptable to you, is to add @code{AC_PROG_LN_S} to
5730@file{configure.in} (@pxref{Particular Programs, , Particular Program
5731Checks, autoconf, The Autoconf Manual}) and use @code{$(LN_S)} in
5732@file{Makefile.am}.
5733
5734@cindex versioned binaries, installing
5735@cindex installing versioned binaries
5736@cindex LN_S example
5737For instance, here is how you could install a versioned copy of a
5738program using @code{$(LN_S)}:
5739
5740@example
5741install-exec-hook:
5742 cd $(DESTDIR)$(bindir) && \
5743 mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
5744 $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
5745@end example
5746
5747Note that we rename the program so that a new version will erase the
5748symbolic link, not the real binary. Also we @code{cd} into the
5749destination directory in order to create relative links.
5750
5751@c FIXME should include discussion of variables you can use in these
5752@c rules
5753
5754@node Distributing, API versioning, Extending, Top
5755@chapter Distributing @file{Makefile.in}s
5756
5757Automake places no restrictions on the distribution of the resulting
5758@file{Makefile.in}s. We still encourage software authors to distribute
5759their work under terms like those of the GPL, but doing so is not
5760required to use Automake.
5761
5762Some of the files that can be automatically installed via the
5763@code{--add-missing} switch do fall under the GPL@. However, these also
5764have a special exception allowing you to distribute them with your
5765package, regardless of the licensing you choose.
5766
5767
5768@node API versioning, FAQ, Distributing, Top
5769@chapter Automake API versioning
5770
5771New Automake releases usually include bug fixes and new features.
5772Unfortunately they may also introduce new bugs and incompatibilities.
5773This makes four reasons why a package may require a particular Automake
5774version.
5775
5776Things get worse when maintaining a large tree of packages, each one
5777requiring a different version of Automake. In the past, this meant that
5778any developer (and sometime users) had to install several versions of
5779Automake in different places, and switch @samp{$PATH} appropriately for
5780each package.
5781
5782Starting with version 1.6, Automake installs versioned binaries. This
5783means you can install several versions of Automake in the same
5784@samp{$prefix}, and can select an arbitrary Automake version by running
5785@samp{automake-1.6} or @samp{automake-1.7} without juggling with
5786@samp{$PATH}. Furthermore, @file{Makefile}'s generated by Automake 1.6
5787will use @samp{automake-1.6} explicitly in their rebuild rules.
5788
5789Note that @samp{1.6} in @samp{automake-1.6} is Automake's API version,
5790not Automake's version. If a bug fix release is made, for instance
5791Automake 1.6.1, the API version will remain 1.6. This means that a
5792package which work with Automake 1.6 should also work with 1.6.1; after
5793all, this is what people expect from bug fix releases.
5794
5795Note that if your package relies on a feature or a bug fix introduced in
5796a release, you can pass this version as an option to Automake to ensure
5797older releases will not be used. For instance, use this in your
5798@file{configure.in}:
5799
5800@example
5801 AM_INIT_AUTOMAKE(1.6.1) dnl Require Automake 1.6.1 or better.
5802@end example
5803@noindent
5804or, in a particular @file{Makefile.am}:
5805
5806@example
5807 AUTOMAKE_OPTIONS = 1.6.1 # Require Automake 1.6.1 or better.
5808@end example
5809@noindent
5810Automake will print an error message if its version is
5811older than the requested version.
5812
5813
5814@heading What is in the API
5815
5816Automake's programming interface is not easy to define. Basically it
5817should include at least all @strong{documented} variables and targets
5818that a @samp{Makefile.am} author can use, any behavior associated with
5819them (e.g. the places where @samp{-hook}'s are run), the command line
5820interface of @samp{automake} and @samp{aclocal}, @dots{}
5821
5822@heading What is not in the API
5823
5824Every undocumented variable, target, or command line option, is not part
5825of the API@. You should avoid using them, as they could change from one
5826version to the other (even in bug fix releases, if this helps to fix a
5827bug).
5828
5829If it turns out you need to use such a undocumented feature, contact
5830@email{automake@@gnu.org} and try to get it documented and exercised by
5831the test-suite.
5832
5833@node FAQ, Macro and Variable Index, API versioning, Top
5834@chapter Frequently Asked Questions about Automake
5835
5836This chapter covers some questions that often come up on the mailing
5837lists.
5838
5839@menu
5840* CVS:: CVS and generated files
5841* maintainer-mode:: missing and AM_MAINTAINER_MODE
5842* wildcards:: Why doesn't Automake support wildcards?
5843* distcleancheck:: Files left in build directory after distclean
5844* renamed objects:: Why are object files sometimes renamed?
5845@end menu
5846
5847@node CVS, maintainer-mode, FAQ, FAQ
5848@section CVS and generated files
5849
5850@subsection Background: distributed generated files
5851@cindex generated files, distributed
5852@cindex rebuild rules
5853
5854Packages made with Autoconf and Automake ship with some generated
5855files like @file{configure} or @file{Makefile.in}. These files were
5856generated on the developer's host and are distributed so that
5857end-users do not have to install the maintainer tools required to
5858rebuild them. Other generated files like Lex scanners, Yacc parsers,
5859or Info documentation, are usually distributed on similar grounds.
5860
5861Automake outputs rules in @file{Makefile}s to rebuild these files. For
5862instance @command{make} will run @command{autoconf} to rebuild
5863@file{configure} whenever @file{configure.in} is changed. This makes
5864development safer by ensuring a @file{configure} is never out-of-date
5865with respect to @file{configure.in}.
5866
5867As generated files shipped in packages are up-to-date, and because
5868@command{tar} preserves timestamps, these rebuild rules are not
5869triggered when a user unpacks and builds a package.
5870
5871@subsection Background: CVS and timestamps
5872@cindex timestamps and CVS
5873@cindex CVS and timestamps
5874
5875Unless you use CVS keywords (in which case files must be updated at
5876commit time), CVS preserves timestamps during @code{cvs commit} and
5877@code{cvs import -d} operations.
5878
5879When you check out a file using @code{cvs checkout} its timestamp is
5880set to that of the revision which is being checked out.
5881
5882However, during @command{cvs update}, files will have the date of the
5883update, not the original timestamp of this revision. This is meant to
5884make sure that @command{make} notices sources files have been updated.
5885
5886This timestamp shift is troublesome when both sources and generated
5887files are kept under CVS. Because CVS processes files in alphabetical
5888order, @file{configure.in} will appear older than @file{configure}
5889after a @command{cvs update} that updates both files, even if
5890@file{configure} was newer than @file{configure.in} when it was
5891checked in. Calling @code{make} will then trigger a spurious rebuild
5892of @file{configure}.
5893
5894@subsection Living with CVS in Autoconfiscated projects
5895@cindex CVS and generated files
5896@cindex generated files and CVS
5897
5898There are basically two clans amongst maintainers: those who keep all
5899distributed files under CVS, including generated files, and those who
5900keep generated files @emph{out} of CVS.
5901
5902@subsubheading All files in CVS
5903
5904@itemize @bullet
5905@item
5906The CVS repository contains all distributed files so you know exactly
5907what is distributed, and you can checkout any prior version entirely.
5908
5909@item
5910Maintainers can see how generated files evolve (for instance you can
5911see what happens to your @file{Makefile.in}s when you upgrade Automake
5912and make sure they look OK).
5913
5914@item
5915Users do not need the autotools to build a checkout of the project, it
5916works just like a released tarball.
5917
5918@item
5919If users use @command{cvs update} to update their copy, instead of
5920@command{cvs checkout} to fetch a fresh one, timestamps will be
5921inaccurate. Some rebuild rules will be triggered and attempt to
5922run developer tools such as @command{autoconf} or @command{automake}.
5923
5924Actually, calls to such tools are all wrapped into a call to the
5925@command{missing} script discussed later (@pxref{maintainer-mode}).
5926@command{missing} will take care of fixing the timestamps when these
5927tools are not installed, so that the build can continue.
5928
5929@item
5930In distributed development, developers are likely to have different
5931version of the maintainer tools installed. In this case rebuilds
5932triggered by timestamp lossage will lead to spurious changes
5933to generated files. There are several solutions to this:
5934
5935@itemize
5936@item
5937All developers should use the same versions, so that the rebuilt files
5938are identical to files in CVS. (This starts to be difficult when each
5939project you work on uses different versions.)
5940@item
5941Or people use a script to fix the timestamp after a checkout (the GCC
5942folks have such a script).
5943@item
5944Or @file{configure.in} uses @code{AM_MAINTAINER_MODE}, which will
5945disable all these rebuild rules by default. This is further discussed
5946in @ref{maintainer-mode}.
5947@end itemize
5948
5949@item
5950Although we focused on spurious rebuilds, the converse can also
5951happen. CVS's timestamp handling can also let you think an
5952out-of-date file is up-to-date.
5953
5954For instance, suppose a developer has modified @file{Makefile.am} and
5955rebuilt @file{Makefile.in}, and then decide to do a last-minute change
5956to @file{Makefile.am} right before checking in both files (without
5957rebuilding @file{Makefile.in} to account for the change).
5958
5959This last change to @file{Makefile.am} make the copy of
5960@file{Makefile.in} out-of-date. Since CVS processes files
5961alphabetically, when another developer @code{cvs update} his or her
5962tree, @file{Makefile.in} will happen to be newer than
5963@file{Makefile.am}. This other developer will not see
5964@file{Makefile.in} is out-of-date.
5965
5966@end itemize
5967
5968@subsubheading Generated files out of CVS
5969
5970One way to get CVS and @code{make} working peacefully is to never
5971store generated files in CVS, i.e., do not CVS-control files which are
5972@code{Makefile} targets (or @emph{derived} files in Make terminology).
5973
5974This way developers are not annoyed by changes to generated files. It
5975does not matter if they all have different versions (assuming they are
5976compatible, of course). And finally, timestamps are not lost, changes
5977to sources files can't be missed as in the
5978@file{Makefile.am}/@file{Makefile.in} example discussed earlier.
5979
5980The drawback is that the CVS repository is not an exact copy of what
5981is distributed and that users now need to install various development
5982tools (maybe even specific versions) before they can build a checkout.
5983But, after all, CVS's job is versioning, not distribution.
5984
5985Allowing developers to use different versions of their tools can also
5986hide bugs during distributed development. Indeed, developers will be
5987using (hence testing) their own generated files, instead of the
5988generated files that will be released actually. The developer who
5989prepares the tarball might be using a version of the tool that
5990produces bogus output (for instance a non-portable C file), something
5991other developers could have noticed if they weren't using their own
5992versions of this tool.
5993
5994@subsection Third-party files
5995@cindex CVS and third-party files
5996@cindex third-party files and CVS
5997
5998Another class of files not discussed here (because they do not cause
5999timestamp issues) are files which are shipped with a package, but
6000maintained elsewhere. For instance tools like @command{gettextize}
6001and @command{autopoint} (from Gettext) or @command{libtoolize} (from
6002Libtool), will install or update files in your package.
6003
6004These files, whether they are kept under CVS or not, raise similar
6005concerns about version mismatch between developers' tools. The
6006Gettext manual has a section about this, see @ref{CVS Issues, CVS
6007Issues, Integrating with CVS, gettext, GNU gettext tools}.
6008
6009@node maintainer-mode, wildcards, CVS, FAQ
6010@section @command{missing} and @code{AM_MAINTAINER_MODE}
6011
6012@subsection @command{missing}
6013@cindex missing, purpose
6014
6015The @command{missing} script is a wrapper around several maintainer
6016tools, designed to warn users if a maintainer tool is required but
6017missing. Typical maintainer tools are @command{autoconf},
6018@command{automake}, @command{bison}, etc. Because file generated by
6019these tools are shipped with the other sources of a package, these
6020tools shouldn't be required during a user build and they are not
6021checked for in @file{configure}.
6022
6023However, if for some reason a rebuild rule is triggered and involves a
6024missing tool, @command{missing} will notice it and warn the user.
6025Besides the warning, when a tool is missing, @command{missing} will
6026attempt to fix timestamps in a way which allow the build to continue.
6027For instance @command{missing} will touch @file{configure} if
6028@command{autoconf} is not installed. When all distributed files are
6029kept under CVS, this feature of @command{missing} allows user
6030@emph{with no maintainer tools} to build a package off CVS, bypassing
6031any timestamp inconsistency implied by @code{cvs update}.
6032
6033If the required tool is installed, @command{missing} will run it and
6034won't attempt to continue after failures. This is correct during
6035development: developers love fixing failures. However, users with
6036wrong versions of maintainer tools may get an error when the rebuild
6037rule is spuriously triggered, halting the build. This failure to let
6038the build continue is one of the arguments of the
6039@code{AM_MAINTAINER_MODE} advocates.
6040
6041@subsection @code{AM_MAINTAINER_MODE}
6042@cindex AM_MAINTAINER_MODE, purpose
6043@cvindex AM_MAINTAINER_MODE
6044
6045@code{AM_MAINTAINER_MODE} disables the so called "rebuild rules" by
6046default. If you have @code{AM_MAINTAINER_MODE} in
6047@file{configure.ac}, and run @code{./configure && make}, then
6048@command{make} will *never* attempt to rebuilt @file{configure},
6049@file{Makefile.in}s, Lex or Yacc outputs, etc. I.e., this disables
6050build rules for files which are usually distributed and that users
6051should normally not have to update.
6052
6053If you run @code{./configure --enable-maintainer-mode}, then these
6054rebuild rules will be active.
6055
6056People use @code{AM_MAINTAINER_MODE} either because they do want their
6057users (or themselves) annoyed by timestamps lossage (@pxref{CVS}), or
6058because they simply can't stand the rebuild rules and prefer running
6059maintainer tools explicitly.
6060
6061@code{AM_MAINTAINER_MODE} also allows you to disable some custom build
6062rules conditionally. Some developers use this feature to disable
6063rules that need exotic tools that users may not have available.
6064
6065Several years ago Fran@,{c}ois Pinard pointed out several arguments
6066against @code{AM_MAINTAINER_MODE}. Most of them relate to insecurity.
6067By removing dependencies you get non-dependable builds: change to
6068sources files can have no effect on generated files and this can be
6069very confusing when unnoticed. He adds that security shouldn't be
6070reserved to maintainers (what @code{--enable-maintainer-mode}
6071suggests), on the contrary. If one user has to modify a
6072@file{Makefile.am}, then either @file{Makefile.in} should be updated
6073or a warning should be output (this is what Automake uses
6074@code{missing} for) but the last thing you want is that nothing
6075happens and the user doesn't notice it (this is what happens when
6076rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
6077
6078Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro was
6079swayed by Fran@,{c}ois's arguments, and got rid of
6080@code{AM_MAINTAINER_MODE} in all of his packages.
6081
6082Still many people continue to use @code{AM_MAINTAINER_MODE}, because
6083it helps them working on projects where all files are kept under CVS,
6084and because @command{missing} isn't enough if you have the wrong
6085version of the tools.
6086
6087
6088@node wildcards, distcleancheck, maintainer-mode, FAQ
6089@section Why doesn't Automake support wildcards?
6090@cindex wildcards
6091
6092Developers are lazy. They often would like to use wildcards in
6093@file{Makefile.am}s, so they don't need to remember they have to
6094update @file{Makefile.am}s every time they add, delete, or rename a
6095file.
6096
6097There are several objections to this:
6098@itemize
6099@item
6100When using CVS (or similar) developers need to remember they have to
6101run @code{cvs add} or @code{cvs rm} anyway. Updating
6102@file{Makefile.am} accordingly quickly becomes a reflex.
6103
6104Conversely, if your application doesn't compile
6105because you forgot to add a file in @file{Makefile.am}, it will help
6106you remember to @code{cvs add} it.
6107
6108@item
6109Using wildcards makes easy to distribute files by mistake. For
6110instance some code a developer is experimenting with (a test case,
6111say) but which should not be part of the distribution.
6112
6113@item
6114Using wildcards it's easy to omit some files by mistake. For
6115instance one developer creates a new file, uses it at many places,
6116but forget to commit it. Another developer then checkout the
6117incomplete project and is able to run `make dist' successfully,
6118even though a file is missing.
6119
6120@item
6121Listing files, you control *exactly* what you distribute.
6122If some file that should be distributed is missing from your
6123tree, @code{make dist} will complain. Besides, you don't distribute
6124more than what you listed.
6125
6126@item
6127Finally it's really hard to @file{forget} adding a file to
6128@file{Makefile.am}, because if you don't add it, it doesn't get
6129compiled nor installed, so you can't even test it.
6130@end itemize
6131
6132Still, these are philosophical objections, and as such you may disagree,
6133or find enough value in wildcards to dismiss all of them. Before you
6134start writing a patch against Automake to teach it about wildcards,
6135let's see the main technical issue: portability.
6136
6137Although @code{$(wildcard ...)} works with GNU @command{make}, it is
6138not portable to other @command{make} implementations.
6139
6140The only way Automake could support @command{$(wildcard ...)} is by
6141expending @command{$(wildcard ...)} when @command{automake} is run.
6142Resulting @file{Makefile.in}s would be portable since they would
6143list all files and not use @code{$(wildcard ...)}. However that
6144means developers need to remember they must run @code{automake} each
6145time they add, delete, or rename files.
6146
6147Compared to editing @file{Makefile.am}, this is really little win. Sure,
6148it's easier and faster to type @code{automake; make} than to type
6149@code{emacs Makefile.am; make}. But nobody bothered enough to write a
6150patch add support for this syntax. Some people use scripts to
6151generated file lists in @file{Makefile.am} or in separate
6152@file{Makefile} fragments.
6153
6154Even if you don't care about portability, and are tempted to use
6155@code{$(wildcard ...)} anyway because you target only GNU Make, you
6156should know there are many places where Automake need to know exactly
6157which files should be processed. As Automake doesn't know how to
6158expand @code{$(wildcard ...)}, you cannot use it in these places.
6159@code{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
6160variables as far Automake is concerned.
6161
6162You can get warnings about @code{$(wildcard ...}) constructs using the
6163@code{-Wportability} flag.
6164
6165@node distcleancheck, renamed objects, wildcards, FAQ
6166@section Files left in build directory after distclean
6167@cindex distclean, diagnostic
6168@cindex dependencies and distributed files
6169@trindex distclean
6170@trindex distcleancheck
6171
6172This is a diagnostic you might encounter while running @code{make
6173distcheck}.
6174
6175As explained in @ref{Dist}, @code{make distcheck} attempts to build
6176and check your package for errors like this one.
6177
6178@code{make distcheck} will perform a @code{VPATH} build of your
6179package, and then call @code{make distclean}. Files left in the build
6180directory after @code{make distclean} has run are listed after this
6181error.
6182
6183This diagnostic really covers two kinds of errors:
6184
6185@itemize @bullet
6186@item
6187files that are forgotten by distclean;
6188@item
6189distributed files that are erroneously rebuilt.
6190@end itemize
6191
6192The former left-over files are not distributed, so the fix is to mark
6193them for cleaning (@pxref{Clean}), this is obvious and doesn't deserve
6194more explanations.
6195
6196The latter bug is not always easy to understand and fix, so let's
6197proceed with an example. Suppose our package contains a program for
6198which we want to build a man page using @command{help2man}. GNU
6199@command{help2man} produces simple manual pages from the @code{--help}
6200and @code{--version} output of other commands (@pxref{Top, , Overview,
6201help2man, The Help2man Manual}). Because we don't to force want our
6202users to install @command{help2man}, we decide to distribute the
6203generated man page using the following setup.
6204
6205@example
6206# This Makefile.am is bogus.
6207bin_PROGRAMS = foo
6208foo_SOURCES = foo.c
6209dist_man_MANS = foo.1
6210
6211foo.1: foo$(EXEEXT)
6212 help2man --output=foo.1 ./foo$(EXEEXT)
6213@end example
6214
6215This will effectively distribute the man page. However,
6216@code{make distcheck} will fail with:
6217
6218@example
6219ERROR: files left in build directory after distclean:
6220./foo.1
6221@end example
6222
6223Why was @file{foo.1} rebuilt? Because although distributed,
6224@file{foo.1} depends on a non-distributed built file:
6225@file{foo$(EXEEXT)}. @file{foo$(EXEEXT)} is built by the user, so it
6226will always appear to be newer than the distributed @file{foo.1}.
6227
6228@code{make distcheck} caught an inconsistency in our package. Our
6229intent was to distribute @file{foo.1} so users do not need installing
6230@command{help2man}, however since this our rule causes this file to be
6231always rebuilt, users @emph{do} need @command{help2man}. Either we
6232should ensure that @file{foo.1} is not rebuilt by users, or there is
6233no point in distributing @file{foo.1}.
6234
6235More generally, the rule is that distributed files should never depend
6236on non-distributed built files. If you distribute something
6237generated, distribute its sources.
6238
6239One way to fix the above example, while still distributing
6240@file{foo.1} is to not depend on @file{foo$(EXEEXT)}. For instance,
6241assuming @command{foo --version} and @command{foo --help} do not
6242change unless @file{foo.c} or @file{configure.ac} change, we could
6243write the following @file{Makefile.am}:
6244
6245@example
6246bin_PROGRAMS = foo
6247foo_SOURCES = foo.c
6248dist_man_MANS = foo.1
6249
6250foo.1: foo.c $(top_srcdir)/configure.ac
6251 $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
6252 help2man --output=foo.1 ./foo$(EXEEXT)
6253@end example
6254
6255This way, @file{foo.1} will not get rebuilt every time
6256@file{foo$(EXEEXT)} changes. The @command{make} call makes sure
6257@file{foo$(EXEEXT)} is up-to-date before @command{help2man}. Another
6258way to ensure this would be to use separate directories for binaries
6259and man pages, and set @code{SUBDIRS} so that binaries are built
6260before man pages.
6261
6262We could also decide not to distribute @file{foo.1}. In
6263this case it's fine to have @file{foo.1} dependent upon
6264@file{foo$(EXEEXT)}, since both will have to be rebuilt.
6265However it would be impossible to build the package in a
6266cross-compilation, because building @file{foo.1} involves
6267an @emph{execution} of @file{foo$(EXEEXT)}.
6268
6269Another context where such errors are common is when distributed files
6270are built by tools which are built by the package. The pattern is similar:
6271
6272@example
6273distributed-file: built-tools distributed-sources
6274 build-command
6275@end example
6276
6277@noindent
6278should be changed to
6279
6280@example
6281distributed-file: distributed-sources
6282 $(MAKE) $(AM_MAKEFLAGS) built-tools
6283 build-command
6284@end example
6285
6286@noindent
6287or you could choose not to distribute @file{distributed-file}, if
6288cross-compilation does not matter.
6289
6290The points made through these examples are worth a summary:
6291
6292@cartouche
6293@itemize
6294@item
6295Distributed files should never depend upon non-distributed built
6296files.
6297@item
6298Distributed files should be distributed will all their dependencies.
6299@item
6300If a file is @emph{intended} be rebuilt by users, there is no point in
6301distributing it.
6302@end itemize
6303@end cartouche
6304
6305@vrindex distcleancheck_listfiles
6306For desperate cases, it's always possible to disable this check by
6307setting @code{distcleancheck_listfiles} as documented in @ref{Dist}.
6308Make sure you do understand the reason why @code{make distcheck}
6309complains before you do this. @code{distcleancheck_listfiles} is a
6310way to @emph{hide} errors, not to fix them. You can always do better.
6311
6312@node renamed objects, , distcleancheck, FAQ
6313@section Why are object files sometimes renamed?
6314
6315This happens when per-target compilation flags are used. Object
6316files need to be renamed just in case they would clash with object
6317files compiled from the same sources, but with different flags.
6318Consider the following example.
6319
6320@example
6321bin_PROGRAMS = true false
6322true_SOURCES = generic.c
6323true_CPPFLAGS = -DEXIT_CODE=0
6324false_SOURCES = generic.c
6325false_CPPFLAGS = -DEXIT_CODE=1
6326@end example
6327@noindent
6328Obviously the two programs are built from the same source, but it
6329would be bad if they shared the same object, because @file{generic.o}
6330cannot be built with both @code{-DEXIT_CODE=0} *and*
6331@code{-DEXIT_CODE=1}. Therefore @command{automake} outputs rules to
6332build two different objects: @file{true-generic.o} and
6333@file{false-generic.o}.
6334
6335@command{automake} doesn't actually look whether sources files are
6336shared to decide if it must rename objects. It will just rename all
6337objects of a target as soon as it sees per-target compilation flags
6338are used.
6339
6340It's OK to share object files when per-target compilation flags are not
6341used. For instance @file{true} and @file{false} will both use
6342@file{version.o} in the following example.
6343
6344@example
6345AM_CPPFLAGS = -DVERSION=1.0
6346bin_PROGRAMS = true false
6347true_SOURCES = true.c version.c
6348false_SOURCES = false.c version.c
6349@end example
6350
6351Note that the renaming of objects is also affected by the
6352@code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
6353
6354@page
6355@node Macro and Variable Index, General Index, FAQ, Top
6356@unnumbered Macro and Variable Index
6357
6358@printindex vr
6359
6360
6361@page
6362@node General Index, , Macro and Variable Index, Top
6363@unnumbered General Index
6364
6365@printindex cp
6366
6367
6368@page
6369@contents
6370@bye
Note: See TracBrowser for help on using the repository browser.