* lib/autoconf/general.m4 (_AC_LIBOBJS_NORMALIZE): Prepend each
[autoconf.git] / doc / autoconf.texi
blobe0d945bfef68bfd4df842256247b49d5ce6b3a21
1 \input texinfo @c -*-texinfo-*-
2 @comment ========================================================
3 @comment %**start of header
4 @setfilename autoconf.info
5 @include version.texi
6 @settitle Autoconf
7 @setchapternewpage odd
8 @setcontentsaftertitlepage
9 @finalout
11 @c @ovar(ARG, DEFAULT)
12 @c -------------------
13 @c The ARG is an optional argument.  To be used for macro arguments in
14 @c their documentation (@defmac).
15 @macro ovar{varname}
16 @r{[}@var{\varname\}@r{]}
17 @end macro
19 @c @dvar(ARG, DEFAULT)
20 @c -------------------
21 @c The ARG is an optional argument, defaulting to DEFAULT.  To be used
22 @c for macro arguments in their documentation (@defmac).
23 @macro dvar{varname, default}
24 @r{[}@var{\varname\} = @samp{\default\}@r{]}
25 @end macro
27 @c Handling the indexes with Texinfo yields several different problems.
29 @c Because we want to drop out the AC_ part of the macro names in the
30 @c printed manual, but not in the other outputs, we need a layer above
31 @c the usual @acindex{} etc.  That's why we first define indexes such as
32 @c acx meant to become the macro @acindex.  First of all, using ``ac_''
33 @c does not work with makeinfo, and using ``ac1'' doesn't work with TeX.
34 @c So use something more regular ``acx''.  Then you finish with a printed
35 @c index saying ``index is not existent''.  Of course: you ought to use
36 @c two letters :(  So you use capitals.
38 @c Second, when defining a macro in the TeX world, following spaces are
39 @c eaten.  But then, since we embed @acxindex commands that use the end
40 @c of line as an end marker, the whole things wrecks itself.  So make
41 @c sure you do *force* an additional end of line, add a ``@c''.
43 @c Finally, you might want to get rid of TeX expansion, using --expand
44 @c with texi2dvi.  But then you wake up an old problem: we use macros
45 @c in @defmac etc. where TeX does perform the expansion, but not makeinfo.
47 @c Define an environment variable index.
48 @defcodeindex ev
49 @c Define an output variable index.
50 @defcodeindex ov
51 @c Define a CPP variable index.
52 @defcodeindex cv
53 @c Define an Autoconf macro index that @defmac doesn't write to.
54 @defcodeindex AC
55 @c Define an Autotest macro index that @defmac doesn't write to.
56 @defcodeindex AT
57 @c Define an M4sugar macro index that @defmac doesn't write to.
58 @defcodeindex MS
59 @c Define an index for *foreign* programs: `mv' etc.  Used for the
60 @c portability sections and so on.
61 @defindex pr
63 @c shortindexflag
64 @c --------------
65 @c Shall we factor AC_ out of the Autoconf macro index etc.?
66 @iftex
67 @set shortindexflag
68 @end iftex
70 @c @acindex{MACRO}
71 @c ---------------
72 @c Registering an AC_\MACRO\.
73 @ifset shortindexflag
74 @macro acindex{macro}
75 @ACindex \macro\
77 @end macro
78 @end ifset
79 @ifclear shortindexflag
80 @macro acindex{macro}
81 @ACindex AC_\macro\
82 @end macro
83 @end ifclear
85 @c @ahindex{MACRO}
86 @c ---------------
87 @c Registering an AH_\MACRO\.
88 @macro ahindex{macro}
89 @ACindex AH_\macro\
91 @end macro
93 @c @asindex{MACRO}
94 @c ---------------
95 @c Registering an AS_\MACRO\.
96 @ifset shortindexflag
97 @macro asindex{macro}
98 @MSindex \macro\
100 @end macro
101 @end ifset
102 @ifclear shortindexflag
103 @macro asindex{macro}
104 @MSindex AS_\macro\
105 @end macro
106 @end ifclear
108 @c @atindex{MACRO}
109 @c ---------------
110 @c Registering an AT_\MACRO\.
111 @ifset shortindexflag
112 @macro atindex{macro}
113 @ATindex \macro\
115 @end macro
116 @end ifset
117 @ifclear shortindexflag
118 @macro atindex{macro}
119 @ATindex AT_\macro\
120 @end macro
121 @end ifclear
123 @c @auindex{MACRO}
124 @c ---------------
125 @c Registering an AU_\MACRO\.
126 @macro auindex{macro}
127 @ACindex AU_\macro\
129 @end macro
131 @c @hdrindex{MACRO}
132 @c ----------------
133 @c Indexing a header.
134 @macro hdrindex{macro}
135 @prindex @file{\macro\}
137 @end macro
139 @c @msindex{MACRO}
140 @c ---------------
141 @c Registering an m4_\MACRO\.
142 @ifset shortindexflag
143 @macro msindex{macro}
144 @MSindex \macro\
146 @end macro
147 @end ifset
148 @ifclear shortindexflag
149 @macro msindex{macro}
150 @MSindex m4_\macro\
151 @end macro
152 @end ifclear
155 @c Define an index for functions: `alloca' etc.  Used for the
156 @c portability sections and so on.  We can't use `fn' (aka `fnindex),
157 @c since `@defmac' goes into it => we'd get all the macros too.
159 @c   FIXME: Aaarg!  It seems there are too many indices for TeX :(
161 @c   ! No room for a new @write .
162 @c   l.112 @defcodeindex fu
164 @c   so don't define yet another one :(  Just put some tags before each
165 @c   @prindex which is actually a @funindex.
167 @c   @defcodeindex fu
170 @c   @c Put the programs and functions into their own index.
171 @c   @syncodeindex fu pr
173 @comment %**end of header
174 @comment ========================================================
176 @copying
178 This manual is for @acronym{GNU} Autoconf
179 (version @value{VERSION}, @value{UPDATED}),
180 a package for creating scripts to configure source code packages using
181 templates and an M4 macro package.
183 Copyright @copyright{} 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000,
184 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
186 @quotation
187 Permission is granted to copy, distribute and/or modify this document
188 under the terms of the @acronym{GNU} Free Documentation License,
189 Version 1.2 or any later version published by the Free Software
190 Foundation; with no Invariant Sections, with the Front-Cover texts
191 being ``A @acronym{GNU} Manual,'' and with the Back-Cover Texts as in
192 (a) below.  A copy of the license is included in the section entitled
193 ``@acronym{GNU} Free Documentation License.''
195 (a) The FSF's Back-Cover Text is: ``You have freedom to copy and
196 modify this @acronym{GNU} Manual, like @acronym{GNU} software.  Copies
197 published by the Free Software Foundation raise funds for
198 @acronym{GNU} development.''
199 @end quotation
200 @end copying
204 @dircategory Software development
205 @direntry
206 * Autoconf: (autoconf).         Create source code configuration scripts.
207 @end direntry
209 @dircategory Individual utilities
210 @direntry
211 * autoscan: (autoconf)autoscan Invocation.
212                                 Semi-automatic @file{configure.ac} writing
213 * ifnames: (autoconf)ifnames Invocation.        Listing conditionals in source.
214 * autoconf: (autoconf)autoconf Invocation.
215                                 How to create configuration scripts
216 * autoreconf: (autoconf)autoreconf Invocation.
217                                 Remaking multiple @command{configure} scripts
218 * autoheader: (autoconf)autoheader Invocation.
219                                 How to create configuration templates
220 * autom4te: (autoconf)autom4te Invocation.
221                                 The Autoconf executables backbone
222 * configure: (autoconf)configure Invocation.    Configuring a package.
223 * autoupdate: (autoconf)autoupdate Invocation.
224                                 Automatic update of @file{configure.ac}
225 * config.status: (autoconf)config.status Invocation. Recreating configurations.
226 * testsuite: (autoconf)testsuite Invocation.    Running an Autotest test suite.
227 @end direntry
229 @titlepage
230 @title Autoconf
231 @subtitle Creating Automatic Configuration Scripts
232 @subtitle for version @value{VERSION}, @value{UPDATED}
233 @author David MacKenzie
234 @author Ben Elliston
235 @author Akim Demaille
236 @page
237 @vskip 0pt plus 1filll
238 @insertcopying
239 @end titlepage
241 @contents
244 @ifnottex
245 @node Top
246 @top Autoconf
247 @insertcopying
248 @end ifnottex
250 @c The master menu, created with texinfo-master-menu, goes here.
252 @menu
253 * Introduction::                Autoconf's purpose, strengths, and weaknesses
254 * The GNU Build System::        A set of tools for portable software packages
255 * Making configure Scripts::    How to organize and produce Autoconf scripts
256 * Setup::                       Initialization and output
257 * Existing Tests::              Macros that check for particular features
258 * Writing Tests::               How to write new feature checks
259 * Results::                     What to do with results from feature checks
260 * Programming in M4::           Layers on top of which Autoconf is written
261 * Writing Autoconf Macros::     Adding new macros to Autoconf
262 * Portable Shell::              Shell script portability pitfalls
263 * Manual Configuration::        Selecting features that can't be guessed
264 * Site Configuration::          Local defaults for @command{configure}
265 * Running configure Scripts::   How to use the Autoconf output
266 * config.status Invocation::    Recreating a configuration
267 * Obsolete Constructs::         Kept for backward compatibility
268 * Using Autotest::              Creating portable test suites
269 * FAQ::                         Frequent Autoconf Questions, with answers
270 * History::                     History of Autoconf
271 * Copying This Manual::         How to make copies of this manual
272 * Indices::                     Indices of symbols, concepts, etc.
274 @detailmenu
275  --- The Detailed Node Listing ---
277 The @acronym{GNU} Build System
279 * Automake::                    Escaping Makefile hell
280 * Libtool::                     Building libraries portably
281 * Pointers::                    More info on the @acronym{GNU} build system
283 Making @command{configure} Scripts
285 * Writing configure.ac::        What to put in an Autoconf input file
286 * autoscan Invocation::         Semi-automatic @file{configure.ac} writing
287 * ifnames Invocation::          Listing the conditionals in source code
288 * autoconf Invocation::         How to create configuration scripts
289 * autoreconf Invocation::       Remaking multiple @command{configure} scripts
291 Writing @file{configure.ac}
293 * Shell Script Compiler::       Autoconf as solution of a problem
294 * Autoconf Language::           Programming in Autoconf
295 * configure.ac Layout::         Standard organization of @file{configure.ac}
297 Initialization and Output Files
299 * Initializing configure::      Option processing etc.
300 * Notices::                     Copyright, version numbers in @command{configure}
301 * Input::                       Where Autoconf should find files
302 * Output::                      Outputting results from the configuration
303 * Configuration Actions::       Preparing the output based on results
304 * Configuration Files::         Creating output files
305 * Makefile Substitutions::      Using output variables in @file{Makefile}s
306 * Configuration Headers::       Creating a configuration header file
307 * Configuration Commands::      Running arbitrary instantiation commands
308 * Configuration Links::         Links depending on the configuration
309 * Subdirectories::              Configuring independent packages together
310 * Default Prefix::              Changing the default installation prefix
312 Substitutions in Makefiles
314 * Preset Output Variables::     Output variables that are always set
315 * Installation Directory Variables::  Other preset output variables
316 * Build Directories::           Supporting multiple concurrent compiles
317 * Automatic Remaking::          Makefile rules for configuring
319 Configuration Header Files
321 * Header Templates::            Input for the configuration headers
322 * autoheader Invocation::       How to create configuration templates
323 * Autoheader Macros::           How to specify CPP templates
325 Existing Tests
327 * Common Behavior::             Macros' standard schemes
328 * Alternative Programs::        Selecting between alternative programs
329 * Files::                       Checking for the existence of files
330 * Libraries::                   Library archives that might be missing
331 * Library Functions::           C library functions that might be missing
332 * Header Files::                Header files that might be missing
333 * Declarations::                Declarations that may be missing
334 * Structures::                  Structures or members that might be missing
335 * Types::                       Types that might be missing
336 * Compilers and Preprocessors::  Checking for compiling programs
337 * System Services::             Operating system services
338 * Posix Variants::              Special kludges for specific Posix variants
340 Common Behavior
342 * Standard Symbols::            Symbols defined by the macros
343 * Default Includes::            Includes used by the generic macros
345 Alternative Programs
347 * Particular Programs::         Special handling to find certain programs
348 * Generic Programs::            How to find other programs
350 Library Functions
352 * Function Portability::        Pitfalls with usual functions
353 * Particular Functions::        Special handling to find certain functions
354 * Generic Functions::           How to find other functions
356 Header Files
358 * Header Portability::          Collected knowledge on common headers
359 * Particular Headers::          Special handling to find certain headers
360 * Generic Headers::             How to find other headers
362 Declarations
364 * Particular Declarations::     Macros to check for certain declarations
365 * Generic Declarations::        How to find other declarations
367 Structures
369 * Particular Structures::       Macros to check for certain structure members
370 * Generic Structures::          How to find other structure members
372 Types
374 * Particular Types::            Special handling to find certain types
375 * Generic Types::               How to find other types
377 Compilers and Preprocessors
379 * Specific Compiler Characteristics::  Some portability issues
380 * Generic Compiler Characteristics::  Language independent tests and features
381 * C Compiler::                  Checking its characteristics
382 * C++ Compiler::                Likewise
383 * Fortran Compiler::            Likewise
385 Writing Tests
387 * Language Choice::             Selecting which language to use for testing
388 * Writing Test Programs::       Forging source files for compilers
389 * Running the Preprocessor::    Detecting preprocessor symbols
390 * Running the Compiler::        Detecting language or header features
391 * Running the Linker::          Detecting library features
392 * Run Time::                    Testing for run-time features
393 * Systemology::                 A zoology of operating systems
394 * Multiple Cases::              Tests for several possible values
396 Writing Test Programs
398 * Guidelines::                  General rules for writing test programs
399 * Test Functions::              Avoiding pitfalls in test programs
400 * Generating Sources::          Source program boilerplate
402 Results of Tests
404 * Defining Symbols::            Defining C preprocessor symbols
405 * Setting Output Variables::    Replacing variables in output files
406 * Caching Results::             Speeding up subsequent @command{configure} runs
407 * Printing Messages::           Notifying @command{configure} users
409 Caching Results
411 * Cache Variable Names::        Shell variables used in caches
412 * Cache Files::                 Files @command{configure} uses for caching
413 * Cache Checkpointing::         Loading and saving the cache file
415 Programming in M4
417 * M4 Quotation::                Protecting macros from unwanted expansion
418 * Using autom4te::              The Autoconf executables backbone
419 * Programming in M4sugar::      Convenient pure M4 macros
420 * Programming in M4sh::         Common shell Constructs
421 * File Descriptor Macros::      File descriptor macros for input and output
423 M4 Quotation
425 * Active Characters::           Characters that change the behavior of M4
426 * One Macro Call::              Quotation and one macro call
427 * Quotation and Nested Macros::  Macros calling macros
428 * Changequote is Evil::         Worse than INTERCAL: M4 + changequote
429 * Quadrigraphs::                Another way to escape special characters
430 * Quotation Rule Of Thumb::     One parenthesis, one quote
432 Using @command{autom4te}
434 * autom4te Invocation::         A @acronym{GNU} M4 wrapper
435 * Customizing autom4te::        Customizing the Autoconf package
437 Programming in M4sugar
439 * Redefined M4 Macros::         M4 builtins changed in M4sugar
440 * Evaluation Macros::           More quotation and evaluation control
441 * Forbidden Patterns::          Catching unexpanded macros
443 Writing Autoconf Macros
445 * Macro Definitions::           Basic format of an Autoconf macro
446 * Macro Names::                 What to call your new macros
447 * Reporting Messages::          Notifying @command{autoconf} users
448 * Dependencies Between Macros::  What to do when macros depend on other macros
449 * Obsoleting Macros::           Warning about old ways of doing things
450 * Coding Style::                Writing Autoconf macros @`a la Autoconf
452 Dependencies Between Macros
454 * Prerequisite Macros::         Ensuring required information
455 * Suggested Ordering::          Warning about possible ordering problems
456 * One-Shot Macros::             Ensuring a macro is called only once
458 Portable Shell Programming
460 * Shellology::                  A zoology of shells
461 * Here-Documents::              Quirks and tricks
462 * File Descriptors::            FDs and redirections
463 * File System Conventions::     File names
464 * Shell Substitutions::         Variable and command expansions
465 * Assignments::                 Varying side effects of assignments
466 * Parentheses::                 Parentheses in shell scripts
467 * Slashes::                     Slashes in shell scripts
468 * Special Shell Variables::     Variables you should not change
469 * Limitations of Builtins::     Portable use of not so portable /bin/sh
470 * Limitations of Usual Tools::  Portable use of portable tools
471 * Limitations of Make::         Portable Makefiles
473 Manual Configuration
475 * Specifying Names::            Specifying the system type
476 * Canonicalizing::              Getting the canonical system type
477 * Using System Type::           What to do with the system type
479 Site Configuration
481 * External Software::           Working with other optional software
482 * Package Options::             Selecting optional features
483 * Pretty Help Strings::         Formatting help string
484 * Site Details::                Configuring site details
485 * Transforming Names::          Changing program names when installing
486 * Site Defaults::               Giving @command{configure} local defaults
488 Transforming Program Names When Installing
490 * Transformation Options::      @command{configure} options to transform names
491 * Transformation Examples::     Sample uses of transforming names
492 * Transformation Rules::        @file{Makefile} uses of transforming names
494 Running @command{configure} Scripts
496 * Basic Installation::          Instructions for typical cases
497 * Compilers and Options::       Selecting compilers and optimization
498 * Multiple Architectures::      Compiling for multiple architectures at once
499 * Installation Names::          Installing in different directories
500 * Optional Features::           Selecting optional features
501 * System Type::                 Specifying the system type
502 * Sharing Defaults::            Setting site-wide defaults for @command{configure}
503 * Defining Variables::          Specifying the compiler etc.
504 * configure Invocation::        Changing how @command{configure} runs
506 Obsolete Constructs
508 * Obsolete config.status Use::  Different calling convention
509 * acconfig.h::                  Additional entries in @file{config.h.in}
510 * autoupdate Invocation::       Automatic update of @file{configure.ac}
511 * Obsolete Macros::             Backward compatibility macros
512 * Autoconf 1::                  Tips for upgrading your files
513 * Autoconf 2.13::               Some fresher tips
515 Upgrading From Version 1
517 * Changed File Names::          Files you might rename
518 * Changed Makefiles::           New things to put in @file{Makefile.in}
519 * Changed Macros::              Macro calls you might replace
520 * Changed Results::             Changes in how to check test results
521 * Changed Macro Writing::       Better ways to write your own macros
523 Upgrading From Version 2.13
525 * Changed Quotation::           Broken code which used to work
526 * New Macros::                  Interaction with foreign macros
527 * Hosts and Cross-Compilation::  Bugward compatibility kludges
528 * AC_LIBOBJ vs LIBOBJS::        LIBOBJS is a forbidden token
529 * AC_FOO_IFELSE vs AC_TRY_FOO::  A more generic scheme for testing sources
531 Generating Test Suites with Autotest
533 * Using an Autotest Test Suite::  Autotest and the user
534 * Writing testsuite.at::        Autotest macros
535 * testsuite Invocation::        Running @command{testsuite} scripts
536 * Making testsuite Scripts::    Using autom4te to create @command{testsuite}
538 Using an Autotest Test Suite
540 * testsuite Scripts::           The concepts of Autotest
541 * Autotest Logs::               Their contents
543 Frequent Autoconf Questions, with answers
545 * Distributing::                Distributing @command{configure} scripts
546 * Why GNU m4::                  Why not use the standard M4?
547 * Bootstrapping::               Autoconf and @acronym{GNU} M4 require each other?
548 * Why Not Imake::               Why @acronym{GNU} uses @command{configure} instead of Imake
549 * Defining Directories::        Passing @code{datadir} to program
550 * autom4te.cache::              What is it?  Can I remove it?
551 * Present But Cannot Be Compiled::  Compiler and Preprocessor Disagree
553 History of Autoconf
555 * Genesis::                     Prehistory and naming of @command{configure}
556 * Exodus::                      The plagues of M4 and Perl
557 * Leviticus::                   The priestly code of portability arrives
558 * Numbers::                     Growth and contributors
559 * Deuteronomy::                 Approaching the promises of easy configuration
561 Copying This Manual
563 * GNU Free Documentation License::  License for copying this manual
565 Indices
567 * Environment Variable Index::  Index of environment variables used
568 * Output Variable Index::       Index of variables set in output files
569 * Preprocessor Symbol Index::   Index of C preprocessor symbols defined
570 * Autoconf Macro Index::        Index of Autoconf macros
571 * M4 Macro Index::              Index of M4, M4sugar, and M4sh macros
572 * Autotest Macro Index::        Index of Autotest macros
573 * Program & Function Index::    Index of those with portability problems
574 * Concept Index::               General index
576 @end detailmenu
577 @end menu
579 @c ============================================================= Introduction.
581 @node Introduction
582 @chapter Introduction
583 @cindex Introduction
585 @flushright
586 A physicist, an engineer, and a computer scientist were discussing the
587 nature of God.  ``Surely a Physicist,'' said the physicist, ``because
588 early in the Creation, God made Light; and you know, Maxwell's
589 equations, the dual nature of electromagnetic waves, the relativistic
590 consequences@dots{}'' ``An Engineer!,'' said the engineer, ``because
591 before making Light, God split the Chaos into Land and Water; it takes a
592 hell of an engineer to handle that big amount of mud, and orderly
593 separation of solids from liquids@dots{}'' The computer scientist
594 shouted: ``And the Chaos, where do you think it was coming from, hmm?''
596 ---Anonymous
597 @end flushright
598 @c (via Franc,ois Pinard)
600 Autoconf is a tool for producing shell scripts that automatically
601 configure software source code packages to adapt to many kinds of
602 Posix-like systems.  The configuration scripts produced by Autoconf
603 are independent of Autoconf when they are run, so their users do not
604 need to have Autoconf.
606 The configuration scripts produced by Autoconf require no manual user
607 intervention when run; they do not normally even need an argument
608 specifying the system type.  Instead, they individually test for the
609 presence of each feature that the software package they are for might need.
610 (Before each check, they print a one-line message stating what they are
611 checking for, so the user doesn't get too bored while waiting for the
612 script to finish.)  As a result, they deal well with systems that are
613 hybrids or customized from the more common Posix variants.  There is
614 no need to maintain files that list the features supported by each
615 release of each variant of Posix.
617 For each software package that Autoconf is used with, it creates a
618 configuration script from a template file that lists the system features
619 that the package needs or can use.  After the shell code to recognize
620 and respond to a system feature has been written, Autoconf allows it to
621 be shared by many software packages that can use (or need) that feature.
622 If it later turns out that the shell code needs adjustment for some
623 reason, it needs to be changed in only one place; all of the
624 configuration scripts can be regenerated automatically to take advantage
625 of the updated code.
627 The Metaconfig package is similar in purpose to Autoconf, but the
628 scripts it produces require manual user intervention, which is quite
629 inconvenient when configuring large source trees.  Unlike Metaconfig
630 scripts, Autoconf scripts can support cross-compiling, if some care is
631 taken in writing them.
633 Autoconf does not solve all problems related to making portable
634 software packages---for a more complete solution, it should be used in
635 concert with other @acronym{GNU} build tools like Automake and
636 Libtool.  These other tools take on jobs like the creation of a
637 portable, recursive @file{Makefile} with all of the standard targets,
638 linking of shared libraries, and so on.  @xref{The GNU Build System},
639 for more information.
641 Autoconf imposes some restrictions on the names of macros used with
642 @code{#if} in C programs (@pxref{Preprocessor Symbol Index}).
644 Autoconf requires @acronym{GNU} M4 in order to generate the scripts.  It uses
645 features that some versions of M4, including @acronym{GNU} M4 1.3,
646 do not have.  You must use version 1.4 or later of @acronym{GNU} M4.
648 @xref{Autoconf 1}, for information about upgrading from version 1.
649 @xref{History}, for the story of Autoconf's development.  @xref{FAQ},
650 for answers to some common questions about Autoconf.
652 See the @uref{http://www.gnu.org/software/autoconf/,
653 Autoconf web page} for up-to-date information, details on the mailing
654 lists, pointers to a list of known bugs, etc.
656 Mail suggestions to @email{autoconf@@gnu.org, the Autoconf mailing
657 list}.
659 Bug reports should be emailed to @email{bug-autoconf@@gnu.org, the
660 Autoconf Bugs mailing list}.  If possible, first check that your bug is
661 not already solved in current development versions, and that it has not
662 been reported yet.  Be sure to include all the needed information and a
663 short @file{configure.ac} that demonstrates the problem.
665 Autoconf's development tree is accessible via @acronym{CVS}; see the
666 @uref{http://savannah.gnu.org/projects/autoconf/, Autoconf
667 Summary} for details.  Patches relative to the
668 current @acronym{CVS} version can be sent for review to the
669 @email{autoconf-patches@@gnu.org, Autoconf Patches mailing list}.
671 Archives of @email{bug-autoconf@@gnu.org} can be
672 found in @uref{http://lists.gnu.org/archive/html/bug-autoconf/}, and
673 similarly for the other mailing lists.
675 Because of its mission, Autoconf includes only a set of often-used
676 macros that have already demonstrated their usefulness.  Nevertheless,
677 if you wish to share your macros, or find existing ones, see the
678 @uref{http://www.gnu.org/software/ac-archive/, @acronym{GNU} Autoconf Macro
679 Archive}, which is kindly run by @email{simons@@cryp.to,
680 Peter Simons}.
683 @c ================================================= The GNU Build System
685 @node The GNU Build System
686 @chapter The @acronym{GNU} Build System
687 @cindex GNU build system
689 Autoconf solves an important problem---reliable discovery of
690 system-specific build and run-time information---but this is only one
691 piece of the puzzle for the development of portable software.  To this
692 end, the @acronym{GNU} project has developed a suite of integrated
693 utilities to finish the job Autoconf started: the @acronym{GNU} build
694 system, whose most important components are Autoconf, Automake, and
695 Libtool.  In this chapter, we introduce you to those tools, point you
696 to sources of more information, and try to convince you to use the
697 entire @acronym{GNU} build system for your software.
699 @menu
700 * Automake::                    Escaping Makefile hell
701 * Libtool::                     Building libraries portably
702 * Pointers::                    More info on the @acronym{GNU} build system
703 @end menu
705 @node Automake
706 @section Automake
708 The ubiquity of @command{make} means that a @file{Makefile} is almost the
709 only viable way to distribute automatic build rules for software, but
710 one quickly runs into @command{make}'s numerous limitations.  Its lack of
711 support for automatic dependency tracking, recursive builds in
712 subdirectories, reliable timestamps (e.g., for network filesystems), and
713 so on, mean that developers must painfully (and often incorrectly)
714 reinvent the wheel for each project.  Portability is non-trivial, thanks
715 to the quirks of @command{make} on many systems.  On top of all this is the
716 manual labor required to implement the many standard targets that users
717 have come to expect (@code{make install}, @code{make distclean},
718 @code{make uninstall}, etc.).  Since you are, of course, using Autoconf,
719 you also have to insert repetitive code in your @code{Makefile.in} to
720 recognize @code{@@CC@@}, @code{@@CFLAGS@@}, and other substitutions
721 provided by @command{configure}.  Into this mess steps @dfn{Automake}.
722 @cindex Automake
724 Automake allows you to specify your build needs in a @code{Makefile.am}
725 file with a vastly simpler and more powerful syntax than that of a plain
726 @code{Makefile}, and then generates a portable @code{Makefile.in} for
727 use with Autoconf.  For example, the @code{Makefile.am} to build and
728 install a simple ``Hello world'' program might look like:
730 @example
731 bin_PROGRAMS = hello
732 hello_SOURCES = hello.c
733 @end example
735 @noindent
736 The resulting @code{Makefile.in} (~400 lines) automatically supports all
737 the standard targets, the substitutions provided by Autoconf, automatic
738 dependency tracking, @code{VPATH} building, and so on.  @command{make} will
739 build the @code{hello} program, and @code{make install} will install it
740 in @file{/usr/local/bin} (or whatever prefix was given to
741 @command{configure}, if not @file{/usr/local}).
743 The benefits of Automake increase for larger packages (especially ones
744 with subdirectories), but even for small programs the added convenience
745 and portability can be substantial.  And that's not all@enddots{}
747 @node Libtool
748 @section Libtool
750 Very often, one wants to build not only programs, but libraries, so that
751 other programs can benefit from the fruits of your labor.  Ideally, one
752 would like to produce @emph{shared} (dynamically linked) libraries,
753 which can be used by multiple programs without duplication on disk or in
754 memory and can be updated independently of the linked programs.
755 Producing shared libraries portably, however, is the stuff of
756 nightmares---each system has its own incompatible tools, compiler flags,
757 and magic incantations.  Fortunately, @acronym{GNU} provides a solution:
758 @dfn{Libtool}.
759 @cindex Libtool
761 Libtool handles all the requirements of building shared libraries for
762 you, and at this time seems to be the @emph{only} way to do so with any
763 portability.  It also handles many other headaches, such as: the
764 interaction of @code{Makefile} rules with the variable suffixes of
765 shared libraries, linking reliably with shared libraries before they are
766 installed by the superuser, and supplying a consistent versioning system
767 (so that different versions of a library can be installed or upgraded
768 without breaking binary compatibility).  Although Libtool, like
769 Autoconf, can be used without Automake, it is most simply utilized in
770 conjunction with Automake---there, Libtool is used automatically
771 whenever shared libraries are needed, and you need not know its syntax.
773 @node Pointers
774 @section Pointers
776 Developers who are used to the simplicity of @command{make} for small
777 projects on a single system might be daunted at the prospect of
778 learning to use Automake and Autoconf.  As your software is
779 distributed to more and more users, however, you will otherwise
780 quickly find yourself putting lots of effort into reinventing the
781 services that the @acronym{GNU} build tools provide, and making the
782 same mistakes that they once made and overcame.  (Besides, since
783 you're already learning Autoconf, Automake will be a piece of cake.)
785 There are a number of places that you can go to for more information on
786 the @acronym{GNU} build tools.
788 @itemize @minus
790 @item Web
792 The home pages for
793 @uref{http://www.gnu.org/software/autoconf/, Autoconf},
794 @uref{http://www.gnu.org/software/automake/, Automake}, and
795 @uref{http://www.gnu.org/software/libtool/, Libtool}.
797 @item Automake Manual
799 @xref{Top,,Automake,automake,@acronym{GNU} Automake}, for more
800 information on Automake.
802 @item Books
804 The book @cite{@acronym{GNU} Autoconf, Automake and
805 Libtool}@footnote{@cite{@acronym{GNU} Autoconf, Automake and Libtool},
806 by G. V. Vaughan, B. Elliston, T. Tromey, and I. L. Taylor.  SAMS (originally
807 New Riders), 2000, ISBN 1578701902.}  describes the complete @acronym{GNU}
808 build environment.  You can also find
809 @uref{http://sources.redhat.com/autobook/, the entire book on-line}.
811 @end itemize
813 @c ================================================= Making configure Scripts.
815 @node Making configure Scripts
816 @chapter Making @command{configure} Scripts
817 @cindex @file{aclocal.m4}
818 @cindex @command{configure}
820 The configuration scripts that Autoconf produces are by convention
821 called @command{configure}.  When run, @command{configure} creates several
822 files, replacing configuration parameters in them with appropriate
823 values.  The files that @command{configure} creates are:
825 @itemize @minus
826 @item
827 one or more @file{Makefile} files, usually one in each subdirectory of the
828 package (@pxref{Makefile Substitutions});
830 @item
831 optionally, a C header file, the name of which is configurable,
832 containing @code{#define} directives (@pxref{Configuration Headers});
834 @item
835 a shell script called @file{config.status} that, when run, will recreate
836 the files listed above (@pxref{config.status Invocation});
838 @item
839 an optional shell script normally called @file{config.cache}
840 (created when using @samp{configure --config-cache}) that
841 saves the results of running many of the tests (@pxref{Cache Files});
843 @item
844 a file called @file{config.log} containing any messages produced by
845 compilers, to help debugging if @command{configure} makes a mistake.
846 @end itemize
848 @cindex @file{configure.in}
849 @cindex @file{configure.ac}
850 To create a @command{configure} script with Autoconf, you need to write an
851 Autoconf input file @file{configure.ac} (or @file{configure.in}) and run
852 @command{autoconf} on it.  If you write your own feature tests to
853 supplement those that come with Autoconf, you might also write files
854 called @file{aclocal.m4} and @file{acsite.m4}.  If you use a C header
855 file to contain @code{#define} directives, you might also run
856 @command{autoheader}, and you will distribute the generated file
857 @file{config.h.in} with the package.
859 Here is a diagram showing how the files that can be used in
860 configuration are produced.  Programs that are executed are suffixed by
861 @samp{*}.  Optional files are enclosed in square brackets (@samp{[]}).
862 @command{autoconf} and @command{autoheader} also read the installed Autoconf
863 macro files (by reading @file{autoconf.m4}).
865 @noindent
866 Files used in preparing a software package for distribution:
867 @example
868 your source files --> [autoscan*] --> [configure.scan] --> configure.ac
870 @group
871 configure.ac --.
872                |   .------> autoconf* -----> configure
873 [aclocal.m4] --+---+
874                |   `-----> [autoheader*] --> [config.h.in]
875 [acsite.m4] ---'
876 @end group
878 Makefile.in -------------------------------> Makefile.in
879 @end example
881 @noindent
882 Files used in configuring a software package:
883 @example
884 @group
885                        .-------------> [config.cache]
886 configure* ------------+-------------> config.log
887                        |
888 [config.h.in] -.       v            .-> [config.h] -.
889                +--> config.status* -+               +--> make*
890 Makefile.in ---'                    `-> Makefile ---'
891 @end group
892 @end example
894 @menu
895 * Writing configure.ac::        What to put in an Autoconf input file
896 * autoscan Invocation::         Semi-automatic @file{configure.ac} writing
897 * ifnames Invocation::          Listing the conditionals in source code
898 * autoconf Invocation::         How to create configuration scripts
899 * autoreconf Invocation::       Remaking multiple @command{configure} scripts
900 @end menu
902 @node Writing configure.ac
903 @section Writing @file{configure.ac}
905 To produce a @command{configure} script for a software package, create a
906 file called @file{configure.ac} that contains invocations of the
907 Autoconf macros that test the system features your package needs or can
908 use.  Autoconf macros already exist to check for many features; see
909 @ref{Existing Tests}, for their descriptions.  For most other features,
910 you can use Autoconf template macros to produce custom checks; see
911 @ref{Writing Tests}, for information about them.  For especially tricky
912 or specialized features, @file{configure.ac} might need to contain some
913 hand-crafted shell commands; see @ref{Portable Shell}.  The
914 @command{autoscan} program can give you a good start in writing
915 @file{configure.ac} (@pxref{autoscan Invocation}, for more information).
917 Previous versions of Autoconf promoted the name @file{configure.in},
918 which is somewhat ambiguous (the tool needed to process this file is not
919 described by its extension), and introduces a slight confusion with
920 @file{config.h.in} and so on (for which @samp{.in} means ``to be
921 processed by @command{configure}'').  Using @file{configure.ac} is now
922 preferred.
924 @menu
925 * Shell Script Compiler::       Autoconf as solution of a problem
926 * Autoconf Language::           Programming in Autoconf
927 * configure.ac Layout::         Standard organization of @file{configure.ac}
928 @end menu
930 @node Shell Script Compiler
931 @subsection A Shell Script Compiler
933 Just as for any other computer language, in order to properly program
934 @file{configure.ac} in Autoconf you must understand @emph{what} problem
935 the language tries to address and @emph{how} it does so.
937 The problem Autoconf addresses is that the world is a mess.  After all,
938 you are using Autoconf in order to have your package compile easily on
939 all sorts of different systems, some of them being extremely hostile.
940 Autoconf itself bears the price for these differences: @command{configure}
941 must run on all those systems, and thus @command{configure} must limit itself
942 to their lowest common denominator of features.
944 Naturally, you might then think of shell scripts; who needs
945 @command{autoconf}?  A set of properly written shell functions is enough to
946 make it easy to write @command{configure} scripts by hand.  Sigh!
947 Unfortunately, shell functions do not belong to the least common
948 denominator; therefore, where you would like to define a function and
949 use it ten times, you would instead need to copy its body ten times.
951 So, what is really needed is some kind of compiler, @command{autoconf},
952 that takes an Autoconf program, @file{configure.ac}, and transforms it
953 into a portable shell script, @command{configure}.
955 How does @command{autoconf} perform this task?
957 There are two obvious possibilities: creating a brand new language or
958 extending an existing one.  The former option is very attractive: all
959 sorts of optimizations could easily be implemented in the compiler and
960 many rigorous checks could be performed on the Autoconf program
961 (e.g., rejecting any non-portable construct).  Alternatively, you can
962 extend an existing language, such as the @code{sh} (Bourne shell)
963 language.
965 Autoconf does the latter: it is a layer on top of @code{sh}.  It was
966 therefore most convenient to implement @command{autoconf} as a macro
967 expander: a program that repeatedly performs @dfn{macro expansions} on
968 text input, replacing macro calls with macro bodies and producing a pure
969 @code{sh} script in the end.  Instead of implementing a dedicated
970 Autoconf macro expander, it is natural to use an existing
971 general-purpose macro language, such as M4, and implement the extensions
972 as a set of M4 macros.
975 @node Autoconf Language
976 @subsection The Autoconf Language
977 @cindex quotation
979 The Autoconf language is very different from many other computer
980 languages because it treats actual code the same as plain text.  Whereas
981 in C, for instance, data and instructions have very different syntactic
982 status, in Autoconf their status is rigorously the same.  Therefore, we
983 need a means to distinguish literal strings from text to be expanded:
984 quotation.
986 When calling macros that take arguments, there must not be any blank
987 space between the macro name and the open parenthesis.  Arguments should
988 be enclosed within the M4 quote characters @samp{[} and @samp{]}, and be
989 separated by commas.  Any leading spaces in arguments are ignored,
990 unless they are quoted.  You may safely leave out the quotes when the
991 argument cannot contain any macro calls, but @emph{always} quote arguments
992 that might contain macro calls.  This rule applies recursively for every macro
993 call, including macros called from other macros.
995 For instance:
997 @example
998 AC_CHECK_HEADER([stdio.h],
999                 [AC_DEFINE([HAVE_STDIO_H], [1],
1000                    [Define to 1 if you have <stdio.h>.])],
1001                 [AC_MSG_ERROR([Sorry, can't do anything for you])])
1002 @end example
1004 @noindent
1005 is quoted properly.  You may safely simplify its quotation to:
1007 @example
1008 AC_CHECK_HEADER([stdio.h],
1009                 [AC_DEFINE([HAVE_STDIO_H], 1,
1010                    [Define to 1 if you have <stdio.h>.])],
1011                 [AC_MSG_ERROR([Sorry, can't do anything for you])])
1012 @end example
1014 @noindent
1015 because @samp{1} cannot contain a macro call.  Here, the argument of
1016 @code{AC_MSG_ERROR} must be quoted; otherwise, its comma would be
1017 interpreted as an argument separator.  Also, @samp{AC_CHECK_HEADER}'s
1018 second and third arguments must be quoted, since those arguments contain
1019 macro calls.  The three arguments @samp{HAVE_STDIO_H}, @samp{stdio.h},
1020 and @samp{Define to 1 if you have <stdio.h>.} do not need quoting, but
1021 if you unwisely defined a macro with a name like @samp{Define} or
1022 @samp{stdio} then they would need quoting.  Cautious Autoconf users
1023 would keep the quotes, but many Autoconf users find such precautions
1024 annoying, and would rewrite the example as follows:
1026 @example
1027 AC_CHECK_HEADER(stdio.h,
1028                 [AC_DEFINE(HAVE_STDIO_H, 1,
1029                    [Define to 1 if you have <stdio.h>.])],
1030                 [AC_MSG_ERROR([Sorry, can't do anything for you])])
1031 @end example
1033 @noindent
1034 This is safe, so long as you adopt good naming conventions and do not
1035 define macros with names like @samp{HAVE_STDIO_H}, @samp{stdio}, or
1036 @samp{h}.  Though it is also safe here to omit the quotes around
1037 @samp{Define to 1 if you have <stdio.h>.} this is not recommended, as
1038 message strings are more likely to inadvertently contain commas.
1040 The following example is wrong and dangerous, as it is underquoted:
1042 @example
1043 AC_CHECK_HEADER(stdio.h,
1044                 AC_DEFINE(HAVE_STDIO_H, 1,
1045                    Define to 1 if you have <stdio.h>.),
1046                 AC_MSG_ERROR([Sorry, can't do anything for you]))
1047 @end example
1049 In other cases, you may have to use text that also resembles a macro
1050 call.  You must quote that text even when it is not passed as a macro
1051 argument:
1053 @example
1054 echo "Hard rock was here!  --[AC_DC]"
1055 @end example
1057 @noindent
1058 which will result in
1060 @example
1061 echo "Hard rock was here!  --AC_DC"
1062 @end example
1064 @noindent
1065 When you use the same text in a macro argument, you must therefore have
1066 an extra quotation level (since one is stripped away by the macro
1067 substitution).  In general, then, it is a good idea to @emph{use double
1068 quoting for all literal string arguments}:
1070 @example
1071 AC_MSG_WARN([[AC_DC stinks  --Iron Maiden]])
1072 @end example
1074 You are now able to understand one of the constructs of Autoconf that
1075 has been continually misunderstood@dots{}  The rule of thumb is that
1076 @emph{whenever you expect macro expansion, expect quote expansion};
1077 i.e., expect one level of quotes to be lost.  For instance:
1079 @example
1080 AC_COMPILE_IFELSE([char b[10];],, [AC_MSG_ERROR([you lose])])
1081 @end example
1083 @noindent
1084 is incorrect: here, the first argument of @code{AC_COMPILE_IFELSE} is
1085 @samp{char b[10];} and will be expanded once, which results in
1086 @samp{char b10;}.  (There was an idiom common in Autoconf's past to
1087 address this issue via the M4 @code{changequote} primitive, but do not
1088 use it!)  Let's take a closer look: the author meant the first argument
1089 to be understood as a literal, and therefore it must be quoted twice:
1091 @example
1092 AC_COMPILE_IFELSE([[char b[10];]],, [AC_MSG_ERROR([you lose])])
1093 @end example
1095 @noindent
1096 Voil@`a, you actually produce @samp{char b[10];} this time!
1098 On the other hand, descriptions (e.g., the last parameter of
1099 @code{AC_DEFINE} or @code{AS_HELP_STRING}) are not literals---they
1100 are subject to line breaking, for example---and should not be double quoted.
1101 Even if these descriptions are short and are not actually broken, double
1102 quoting them yields weird results.
1104 Some macros take optional arguments, which this documentation represents
1105 as @ovar{arg} (not to be confused with the quote characters).  You may
1106 just leave them empty, or use @samp{[]} to make the emptiness of the
1107 argument explicit, or you may simply omit the trailing commas.  The
1108 three lines below are equivalent:
1110 @example
1111 AC_CHECK_HEADERS(stdio.h, [], [], [])
1112 AC_CHECK_HEADERS(stdio.h,,,)
1113 AC_CHECK_HEADERS(stdio.h)
1114 @end example
1116 It is best to put each macro call on its own line in
1117 @file{configure.ac}.  Most of the macros don't add extra newlines; they
1118 rely on the newline after the macro call to terminate the commands.
1119 This approach makes the generated @command{configure} script a little
1120 easier to read by not inserting lots of blank lines.  It is generally
1121 safe to set shell variables on the same line as a macro call, because
1122 the shell allows assignments without intervening newlines.
1124 You can include comments in @file{configure.ac} files by starting them
1125 with the @samp{#}.  For example, it is helpful to begin
1126 @file{configure.ac} files with a line like this:
1128 @example
1129 # Process this file with autoconf to produce a configure script.
1130 @end example
1132 @node configure.ac Layout
1133 @subsection Standard @file{configure.ac} Layout
1135 The order in which @file{configure.ac} calls the Autoconf macros is not
1136 important, with a few exceptions.  Every @file{configure.ac} must
1137 contain a call to @code{AC_INIT} before the checks, and a call to
1138 @code{AC_OUTPUT} at the end (@pxref{Output}).  Additionally, some macros
1139 rely on other macros having been called first, because they check
1140 previously set values of some variables to decide what to do.  These
1141 macros are noted in the individual descriptions (@pxref{Existing
1142 Tests}), and they also warn you when @command{configure} is created if they
1143 are called out of order.
1145 To encourage consistency, here is a suggested order for calling the
1146 Autoconf macros.  Generally speaking, the things near the end of this
1147 list are those that could depend on things earlier in it.  For example,
1148 library functions could be affected by types and libraries.
1150 @display
1151 @group
1152 Autoconf requirements
1153 @code{AC_INIT(@var{package}, @var{version}, @var{bug-report-address})}
1154 information on the package
1155 checks for programs
1156 checks for libraries
1157 checks for header files
1158 checks for types
1159 checks for structures
1160 checks for compiler characteristics
1161 checks for library functions
1162 checks for system services
1163 @code{AC_CONFIG_FILES(@r{[}@var{file@dots{}}@r{]})}
1164 @code{AC_OUTPUT}
1165 @end group
1166 @end display
1169 @node autoscan Invocation
1170 @section Using @command{autoscan} to Create @file{configure.ac}
1171 @cindex @command{autoscan}
1173 The @command{autoscan} program can help you create and/or maintain a
1174 @file{configure.ac} file for a software package.  @command{autoscan}
1175 examines source files in the directory tree rooted at a directory given
1176 as a command line argument, or the current directory if none is given.
1177 It searches the source files for common portability problems and creates
1178 a file @file{configure.scan} which is a preliminary @file{configure.ac}
1179 for that package, and checks a possibly existing @file{configure.ac} for
1180 completeness.
1182 When using @command{autoscan} to create a @file{configure.ac}, you
1183 should manually examine @file{configure.scan} before renaming it to
1184 @file{configure.ac}; it will probably need some adjustments.
1185 Occasionally, @command{autoscan} outputs a macro in the wrong order
1186 relative to another macro, so that @command{autoconf} produces a warning;
1187 you need to move such macros manually.  Also, if you want the package to
1188 use a configuration header file, you must add a call to
1189 @code{AC_CONFIG_HEADERS} (@pxref{Configuration Headers}).  You might
1190 also have to change or add some @code{#if} directives to your program in
1191 order to make it work with Autoconf (@pxref{ifnames Invocation}, for
1192 information about a program that can help with that job).
1194 When using @command{autoscan} to maintain a @file{configure.ac}, simply
1195 consider adding its suggestions.  The file @file{autoscan.log} will
1196 contain detailed information on why a macro is requested.
1198 @command{autoscan} uses several data files (installed along with Autoconf)
1199 to determine which macros to output when it finds particular symbols in
1200 a package's source files.  These data files all have the same format:
1201 each line consists of a symbol, whitespace, and the Autoconf macro to
1202 output if that symbol is encountered.  Lines starting with @samp{#} are
1203 comments.
1205 @command{autoscan} accepts the following options:
1207 @table @option
1208 @item --help
1209 @itemx -h
1210 Print a summary of the command line options and exit.
1212 @item --version
1213 @itemx -V
1214 Print the version number of Autoconf and exit.
1216 @item --verbose
1217 @itemx -v
1218 Print the names of the files it examines and the potentially interesting
1219 symbols it finds in them.  This output can be voluminous.
1221 @item --include=@var{dir}
1222 @itemx -I @var{dir}
1223 Append @var{dir} to the include path.  Multiple invocations accumulate.
1225 @item --prepend-include=@var{dir}
1226 @item -B @var{dir}
1227 Prepend @var{dir} to the include path.  Multiple invocations accumulate.
1228 @end table
1230 @node ifnames Invocation
1231 @section Using @command{ifnames} to List Conditionals
1232 @cindex @command{ifnames}
1234 @command{ifnames} can help you write @file{configure.ac} for a software
1235 package.  It prints the identifiers that the package already uses in C
1236 preprocessor conditionals.  If a package has already been set up to have
1237 some portability, @command{ifnames} can thus help you figure out what its
1238 @command{configure} needs to check for.  It may help fill in some gaps in a
1239 @file{configure.ac} generated by @command{autoscan} (@pxref{autoscan
1240 Invocation}).
1242 @command{ifnames} scans all of the C source files named on the command line
1243 (or the standard input, if none are given) and writes to the standard
1244 output a sorted list of all the identifiers that appear in those files
1245 in @code{#if}, @code{#elif}, @code{#ifdef}, or @code{#ifndef}
1246 directives.  It prints each identifier on a line, followed by a
1247 space-separated list of the files in which that identifier occurs.
1249 @noindent
1250 @command{ifnames} accepts the following options:
1252 @table @option
1253 @item --help
1254 @itemx -h
1255 Print a summary of the command line options and exit.
1257 @item --version
1258 @itemx -V
1259 Print the version number of Autoconf and exit.
1260 @end table
1262 @node autoconf Invocation
1263 @section Using @command{autoconf} to Create @command{configure}
1264 @cindex @command{autoconf}
1266 To create @command{configure} from @file{configure.ac}, run the
1267 @command{autoconf} program with no arguments.  @command{autoconf} processes
1268 @file{configure.ac} with the M4 macro processor, using the
1269 Autoconf macros.  If you give @command{autoconf} an argument, it reads that
1270 file instead of @file{configure.ac} and writes the configuration script
1271 to the standard output instead of to @command{configure}.  If you give
1272 @command{autoconf} the argument @option{-}, it reads from the standard
1273 input instead of @file{configure.ac} and writes the configuration script
1274 to the standard output.
1276 The Autoconf macros are defined in several files.  Some of the files are
1277 distributed with Autoconf; @command{autoconf} reads them first.  Then it
1278 looks for the optional file @file{acsite.m4} in the directory that
1279 contains the distributed Autoconf macro files, and for the optional file
1280 @file{aclocal.m4} in the current directory.  Those files can contain
1281 your site's or the package's own Autoconf macro definitions
1282 (@pxref{Writing Autoconf Macros}, for more information).  If a macro is
1283 defined in more than one of the files that @command{autoconf} reads, the
1284 last definition it reads overrides the earlier ones.
1286 @command{autoconf} accepts the following options:
1288 @table @option
1289 @item --help
1290 @itemx -h
1291 Print a summary of the command line options and exit.
1293 @item --version
1294 @itemx -V
1295 Print the version number of Autoconf and exit.
1297 @item --verbose
1298 @itemx -v
1299 Report processing steps.
1301 @item --debug
1302 @itemx -d
1303 Don't remove the temporary files.
1305 @item --force
1306 @itemx -f
1307 Remake @file{configure} even if newer than its input files.
1309 @item --include=@var{dir}
1310 @itemx -I @var{dir}
1311 Append @var{dir} to the include path.  Multiple invocations accumulate.
1313 @item --prepend-include=@var{dir}
1314 @item -B @var{dir}
1315 Prepend @var{dir} to the include path.  Multiple invocations accumulate.
1317 @item --output=@var{file}
1318 @itemx -o @var{file}
1319 Save output (script or trace) to @var{file}.  The file @option{-} stands
1320 for the standard output.
1322 @item --warnings=@var{category}
1323 @itemx -W @var{category}
1324 @evindex WARNINGS
1325 Report the warnings related to @var{category} (which can actually be a
1326 comma separated list).  @xref{Reporting Messages}, macro
1327 @code{AC_DIAGNOSE}, for a comprehensive list of categories.  Special
1328 values include:
1330 @table @samp
1331 @item all
1332 report all the warnings
1334 @item none
1335 report none
1337 @item error
1338 treats warnings as errors
1340 @item no-@var{category}
1341 disable warnings falling into @var{category}
1342 @end table
1344 Warnings about @samp{syntax} are enabled by default, and the environment
1345 variable @env{WARNINGS}, a comma separated list of categories, is
1346 honored.  Passing @samp{-W @var{category}} will actually behave as if
1347 you had passed @samp{--warnings=syntax,$WARNINGS,@var{category}}.  If
1348 you want to disable the defaults and @env{WARNINGS}, but (for example)
1349 enable the warnings about obsolete constructs, you would use @option{-W
1350 none,obsolete}.
1352 @cindex Back trace
1353 @cindex Macro invocation stack
1354 Because @command{autoconf} uses @command{autom4te} behind the scenes, it
1355 displays a back trace for errors, but not for warnings; if you want
1356 them, just pass @option{-W error}.  @xref{autom4te Invocation}, for some
1357 examples.
1359 @item --trace=@var{macro}[:@var{format}]
1360 @itemx -t @var{macro}[:@var{format}]
1361 Do not create the @command{configure} script, but list the calls to
1362 @var{macro} according to the @var{format}.  Multiple @option{--trace}
1363 arguments can be used to list several macros.  Multiple @option{--trace}
1364 arguments for a single macro are not cumulative; instead, you should
1365 just make @var{format} as long as needed.
1367 The @var{format} is a regular string, with newlines if desired, and
1368 several special escape codes.  It defaults to @samp{$f:$l:$n:$%}; see
1369 @ref{autom4te Invocation}, for details on the @var{format}.
1371 @item --initialization
1372 @itemx -i
1373 By default, @option{--trace} does not trace the initialization of the
1374 Autoconf macros (typically the @code{AC_DEFUN} definitions).  This
1375 results in a noticeable speedup, but can be disabled by this option.
1376 @end table
1379 It is often necessary to check the content of a @file{configure.ac}
1380 file, but parsing it yourself is extremely fragile and error-prone.  It
1381 is suggested that you rely upon @option{--trace} to scan
1382 @file{configure.ac}.  For instance, to find the list of variables that
1383 are substituted, use:
1385 @example
1386 @group
1387 $ @kbd{autoconf -t AC_SUBST}
1388 configure.ac:2:AC_SUBST:ECHO_C
1389 configure.ac:2:AC_SUBST:ECHO_N
1390 configure.ac:2:AC_SUBST:ECHO_T
1391 @i{More traces deleted}
1392 @end group
1393 @end example
1395 @noindent
1396 The example below highlights the difference between @samp{$@@},
1397 @samp{$*}, and @strong{$%}.
1399 @example
1400 @group
1401 $ @kbd{cat configure.ac}
1402 AC_DEFINE(This, is, [an
1403 [example]])
1404 $ @kbd{autoconf -t 'AC_DEFINE:@@: $@@}
1405 *: $*
1406 $: $%'
1407 @@: [This],[is],[an
1408 [example]]
1409 *: This,is,an
1410 [example]
1411 $: This:is:an [example]
1412 @end group
1413 @end example
1415 @noindent
1416 The @var{format} gives you a lot of freedom:
1418 @example
1419 @group
1420 $ @kbd{autoconf -t 'AC_SUBST:$$ac_subst@{"$1"@} = "$f:$l";'}
1421 $ac_subst@{"ECHO_C"@} = "configure.ac:2";
1422 $ac_subst@{"ECHO_N"@} = "configure.ac:2";
1423 $ac_subst@{"ECHO_T"@} = "configure.ac:2";
1424 @i{More traces deleted}
1425 @end group
1426 @end example
1428 @noindent
1429 A long @var{separator} can be used to improve the readability of complex
1430 structures, and to ease their parsing (for instance when no single
1431 character is suitable as a separator):
1433 @example
1434 @group
1435 $ @kbd{autoconf -t 'AM_MISSING_PROG:$@{|:::::|@}*'}
1436 ACLOCAL|:::::|aclocal|:::::|$missing_dir
1437 AUTOCONF|:::::|autoconf|:::::|$missing_dir
1438 AUTOMAKE|:::::|automake|:::::|$missing_dir
1439 @i{More traces deleted}
1440 @end group
1441 @end example
1443 @node autoreconf Invocation
1444 @section Using @command{autoreconf} to Update @command{configure} Scripts
1445 @cindex @command{autoreconf}
1447 Installing the various components of the @acronym{GNU} Build System can be
1448 tedious: running @command{autopoint} for Gettext, @command{automake} for
1449 @file{Makefile.in} etc.@: in each directory.  It may be needed either
1450 because some tools such as @command{automake} have been updated on your
1451 system, or because some of the sources such as @file{configure.ac} have
1452 been updated, or finally, simply in order to install the @acronym{GNU} Build
1453 System in a fresh tree.
1455 @command{autoreconf} runs @command{autoconf}, @command{autoheader},
1456 @command{aclocal}, @command{automake}, @command{libtoolize}, and
1457 @command{autopoint} (when appropriate) repeatedly to update the
1458 @acronym{GNU} Build System in the specified directories and their
1459 subdirectories (@pxref{Subdirectories}).  By default, it only remakes
1460 those files that are older than their sources.
1462 If you install a new version of some tool, you can make
1463 @command{autoreconf} remake @emph{all} of the files by giving it the
1464 @option{--force} option.
1466 @xref{Automatic Remaking}, for @file{Makefile} rules to automatically
1467 remake @command{configure} scripts when their source files change.  That
1468 method handles the timestamps of configuration header templates
1469 properly, but does not pass @option{--autoconf-dir=@var{dir}} or
1470 @option{--localdir=@var{dir}}.
1472 @cindex Gettext
1473 @cindex @command{autopoint}
1474 Gettext supplies the @command{autopoint} command to add translation
1475 infrastructure to a source package.  If you use @command{autopoint},
1476 your @file{configure.ac} should invoke both @code{AM_GNU_GETTEXT} and
1477 @code{AM_GNU_GETTEXT_VERSION(@var{gettext-version})}.  @xref{autopoint
1478 Invocation,, Invoking the @code{autopoint} Program, gettext, GNU
1479 @code{gettext} utilities}, for further details.
1481 @noindent
1482 @command{autoreconf} accepts the following options:
1484 @table @option
1485 @item --help
1486 @itemx -h
1487 Print a summary of the command line options and exit.
1489 @item --version
1490 @itemx -V
1491 Print the version number of Autoconf and exit.
1493 @item --verbose
1494 Print the name of each directory where @command{autoreconf} runs
1495 @command{autoconf} (and @command{autoheader}, if appropriate).
1497 @item --debug
1498 @itemx -d
1499 Don't remove the temporary files.
1501 @item --force
1502 @itemx -f
1503 Remake even @file{configure} scripts and configuration headers that are
1504 newer than their input files (@file{configure.ac} and, if present,
1505 @file{aclocal.m4}).
1507 @item --install
1508 @itemx -i
1509 Install the missing auxiliary files in the package.  By default, files
1510 are copied; this can be changed with @option{--symlink}.
1512 This option triggers calls to @samp{automake --add-missing},
1513 @samp{libtoolize}, @samp{autopoint}, etc.
1515 @item --symlink
1516 @itemx -s
1517 When used with @option{--install}, install symbolic links to the missing
1518 auxiliary files instead of copying them.
1520 @item --make
1521 @itemx -m
1522 When the directories were configured, update the configuration by
1523 running @samp{./config.status --recheck && ./config.status}, and then
1524 run @samp{make}.
1526 @item --include=@var{dir}
1527 @itemx -I @var{dir}
1528 Append @var{dir} to the include path.  Multiple invocations accumulate.
1530 @item --prepend-include=@var{dir}
1531 @item -B @var{dir}
1532 Prepend @var{dir} to the include path.  Multiple invocations accumulate.
1534 @item --warnings=@var{category}
1535 @itemx -W @var{category}
1536 @evindex WARNINGS
1537 Report the warnings related to @var{category} (which can actually be a
1538 comma separated list).
1540 @table @samp
1541 @item cross
1542 related to cross compilation issues.
1544 @item obsolete
1545 report the uses of obsolete constructs.
1547 @item portability
1548 portability issues
1550 @item syntax
1551 dubious syntactic constructs.
1553 @item all
1554 report all the warnings
1556 @item none
1557 report none
1559 @item error
1560 treats warnings as errors
1562 @item no-@var{category}
1563 disable warnings falling into @var{category}
1564 @end table
1566 Warnings about @samp{syntax} are enabled by default, and the environment
1567 variable @env{WARNINGS}, a comma separated list of categories, is
1568 honored.  Passing @samp{-W @var{category}} will actually behave as if
1569 you had passed @samp{--warnings=syntax,$WARNINGS,@var{category}}.  If
1570 you want to disable the defaults and @env{WARNINGS}, but (for example)
1571 enable the warnings about obsolete constructs, you would use @option{-W
1572 none,obsolete}.
1573 @end table
1576 @c ========================================= Initialization and Output Files.
1578 @node Setup
1579 @chapter Initialization and Output Files
1581 Autoconf-generated @command{configure} scripts need some information about
1582 how to initialize, such as how to find the package's source files and
1583 about the output files to produce.  The following sections describe the
1584 initialization and the creation of output files.
1586 @menu
1587 * Initializing configure::      Option processing etc.
1588 * Notices::                     Copyright, version numbers in @command{configure}
1589 * Input::                       Where Autoconf should find files
1590 * Output::                      Outputting results from the configuration
1591 * Configuration Actions::       Preparing the output based on results
1592 * Configuration Files::         Creating output files
1593 * Makefile Substitutions::      Using output variables in @file{Makefile}s
1594 * Configuration Headers::       Creating a configuration header file
1595 * Configuration Commands::      Running arbitrary instantiation commands
1596 * Configuration Links::         Links depending on the configuration
1597 * Subdirectories::              Configuring independent packages together
1598 * Default Prefix::              Changing the default installation prefix
1599 @end menu
1601 @node Initializing configure
1602 @section Initializing @command{configure}
1604 Every @command{configure} script must call @code{AC_INIT} before doing
1605 anything else.  The only other required macro is @code{AC_OUTPUT}
1606 (@pxref{Output}).
1608 @defmac AC_INIT (@var{package}, @var{version}, @ovar{bug-report}, @ovar{tarname})
1609 @acindex{INIT}
1610 Process any command-line arguments and perform various initializations
1611 and verifications.
1613 Set the name of the @var{package} and its @var{version}.  These are
1614 typically used in @option{--version} support, including that of
1615 @command{configure}.  The optional argument @var{bug-report} should be
1616 the email to which users should send bug reports.  The package
1617 @var{tarname} differs from @var{package}: the latter designates the full
1618 package name (e.g., @samp{GNU Autoconf}), while the former is meant for
1619 distribution tar ball names (e.g., @samp{autoconf}).  It defaults to
1620 @var{package} with @samp{GNU } stripped, lower-cased, and all characters
1621 other than alphanumerics and underscores are changed to @samp{-}.
1623 It is preferable that the arguments of @code{AC_INIT} be static, i.e.,
1624 there should not be any shell computation, but they can be computed by
1627 The following M4 macros (e.g., @code{AC_PACKAGE_NAME}), output variables
1628 (e.g., @code{PACKAGE_NAME}), and preprocessor symbols (e.g.,
1629 @code{PACKAGE_NAME}) are defined by @code{AC_INIT}:
1631 @table @asis
1632 @item @code{AC_PACKAGE_NAME}, @code{PACKAGE_NAME}
1633 @acindex{PACKAGE_NAME}
1634 @ovindex PACKAGE_NAME
1635 @cvindex PACKAGE_NAME
1636 Exactly @var{package}.
1638 @item @code{AC_PACKAGE_TARNAME}, @code{PACKAGE_TARNAME}
1639 @acindex{PACKAGE_TARNAME}
1640 @ovindex PACKAGE_TARNAME
1641 @cvindex PACKAGE_TARNAME
1642 Exactly @var{tarname}.
1644 @item @code{AC_PACKAGE_VERSION}, @code{PACKAGE_VERSION}
1645 @acindex{PACKAGE_VERSION}
1646 @ovindex PACKAGE_VERSION
1647 @cvindex PACKAGE_VERSION
1648 Exactly @var{version}.
1650 @item @code{AC_PACKAGE_STRING}, @code{PACKAGE_STRING}
1651 @acindex{PACKAGE_STRING}
1652 @ovindex PACKAGE_STRING
1653 @cvindex PACKAGE_STRING
1654 Exactly @samp{@var{package} @var{version}}.
1656 @item @code{AC_PACKAGE_BUGREPORT}, @code{PACKAGE_BUGREPORT}
1657 @acindex{PACKAGE_BUGREPORT}
1658 @ovindex PACKAGE_BUGREPORT
1659 @cvindex PACKAGE_BUGREPORT
1660 Exactly @var{bug-report}.
1661 @end table
1662 @end defmac
1665 @node Notices
1666 @section Notices in @command{configure}
1667 @cindex Notices in @command{configure}
1669 The following macros manage version numbers for @command{configure}
1670 scripts.  Using them is optional.
1672 @c FIXME: AC_PREREQ should not be here
1673 @defmac AC_PREREQ (@var{version})
1674 @acindex{PREREQ}
1675 @cindex Version
1676 Ensure that a recent enough version of Autoconf is being used.  If the
1677 version of Autoconf being used to create @command{configure} is
1678 earlier than @var{version}, print an error message to the standard
1679 error output and exit with failure (exit status is 63).  For example:
1681 @example
1682 AC_PREREQ(@value{VERSION})
1683 @end example
1685 This macro is the only macro that may be used before @code{AC_INIT}, but
1686 for consistency, you are invited not to do so.
1687 @end defmac
1689 @defmac AC_COPYRIGHT (@var{copyright-notice})
1690 @acindex{COPYRIGHT}
1691 @cindex Copyright Notice
1692 State that, in addition to the Free Software Foundation's copyright on
1693 the Autoconf macros, parts of your @command{configure} are covered by the
1694 @var{copyright-notice}.
1696 The @var{copyright-notice} will show up in both the head of
1697 @command{configure} and in @samp{configure --version}.
1698 @end defmac
1701 @defmac AC_REVISION (@var{revision-info})
1702 @acindex{REVISION}
1703 @cindex Revision
1704 Copy revision stamp @var{revision-info} into the @command{configure}
1705 script, with any dollar signs or double-quotes removed.  This macro lets
1706 you put a revision stamp from @file{configure.ac} into @command{configure}
1707 without @acronym{RCS} or @acronym{CVS} changing it when you check in
1708 @command{configure}.  That way, you can determine easily which revision of
1709 @file{configure.ac} a particular @command{configure} corresponds to.
1711 For example, this line in @file{configure.ac}:
1713 @c The asis prevents RCS from changing the example in the manual.
1714 @example
1715 AC_REVISION($@asis{Revision: 1.30 }$)
1716 @end example
1718 @noindent
1719 produces this in @command{configure}:
1721 @example
1722 #! /bin/sh
1723 # From configure.ac Revision: 1.30
1724 @end example
1725 @end defmac
1728 @node Input
1729 @section Finding @command{configure} Input
1732 @defmac AC_CONFIG_SRCDIR (@var{unique-file-in-source-dir})
1733 @acindex{CONFIG_SRCDIR}
1734 @var{unique-file-in-source-dir} is some file that is in the package's
1735 source directory; @command{configure} checks for this file's existence to
1736 make sure that the directory that it is told contains the source code in
1737 fact does.  Occasionally people accidentally specify the wrong directory
1738 with @option{--srcdir}; this is a safety check.  @xref{configure
1739 Invocation}, for more information.
1740 @end defmac
1743 @c FIXME: Remove definitively once --install explained.
1745 @c Small packages may store all their macros in @code{aclocal.m4}.  As the
1746 @c set of macros grows, or for maintenance reasons, a maintainer may prefer
1747 @c to split the macros in several files.  In this case, Autoconf must be
1748 @c told which files to load, and in which order.
1750 @c @defmac AC_INCLUDE (@var{file}@dots{})
1751 @c @acindex{INCLUDE}
1752 @c @c FIXME: There is no longer shell globbing.
1753 @c Read the macro definitions that appear in the listed files.  A list of
1754 @c space-separated file names or shell globbing patterns is expected.  The
1755 @c files will be read in the order they're listed.
1757 @c Because the order of definition of macros is important (only the last
1758 @c definition of a macro is used), beware that it is @code{AC_INIT} that
1759 @c loads @file{acsite.m4} and @file{aclocal.m4}.  Note that
1760 @c @code{AC_INCLUDE}ing a file before @code{AC_INIT} or within
1761 @c @file{aclocal.m4} is different from doing so after @code{AC_INIT}: in
1762 @c the latter case, non-macro lines from included files may end up in the
1763 @c @file{configure} script, whereas in the former case, they'd be discarded
1764 @c just like any text that appear before @code{AC_INIT}.
1765 @c @end defmac
1767 Packages that do manual configuration or use the @code{install} program
1768 might need to tell @command{configure} where to find some other shell
1769 scripts by calling @code{AC_CONFIG_AUX_DIR}, though the default places
1770 it looks are correct for most cases.
1772 @defmac AC_CONFIG_AUX_DIR (@var{dir})
1773 @acindex{CONFIG_AUX_DIR}
1774 Use the auxiliary build tools (e.g., @file{install-sh},
1775 @file{config.sub}, @file{config.guess}, Cygnus @command{configure},
1776 Automake and Libtool scripts, etc.)@: that are in directory @var{dir}.
1777 These are auxiliary files used in configuration.  @var{dir} can be
1778 either absolute or relative to @file{@var{srcdir}}.  The default is
1779 @file{@var{srcdir}} or @file{@var{srcdir}/..} or
1780 @file{@var{srcdir}/../..}, whichever is the first that contains
1781 @file{install-sh}.  The other files are not checked for, so that using
1782 @code{AC_PROG_INSTALL} does not automatically require distributing the
1783 other auxiliary files.  It checks for @file{install.sh} also, but that
1784 name is obsolete because some @code{make} have a rule that creates
1785 @file{install} from it if there is no @file{Makefile}.
1787 The auxiliary directory is commonly named @file{build-aux}.
1788 If you need portability to @acronym{DOS} variants, do not name the
1789 auxiliary directory @file{aux}.  @xref{File System Conventions}.
1790 @end defmac
1792 @defmac AC_REQUIRE_AUX_FILE (@var{file})
1793 @acindex{REQUIRE_AUX_FILE}
1794 Declares that @var{file} is expected in the directory defined above.  In
1795 Autoconf proper, this macro does nothing: its sole purpose is to be
1796 traced by third-party tools to produce a list of expected auxiliary
1797 files.  For instance it is called by macros like @code{AC_PROG_INSTALL}
1798 (@pxref{Particular Programs}) or @code{AC_CANONICAL_BUILD}
1799 (@pxref{Canonicalizing}) to register the auxiliary files they need.
1800 @end defmac
1802 Similarly, packages that use @command{aclocal} should declare where
1803 local macros can be found using @code{AC_CONFIG_MACRO_DIR}.
1805 @defmac AC_CONFIG_MACRO_DIR (@var{dir})
1806 @acindex{CONFIG_MACRO_DIR}
1807 Future versions of @command{autopoint}, @command{libtoolize},
1808 @command{aclocal} and @command{autoreconf} will use directory
1809 @var{dir} as the location of additional local Autoconf macros.  Be
1810 sure to call this macro directly from @file{configure.ac} so that
1811 tools that install macros for @command{aclocal} can find the
1812 declaration before @option{--trace} can be called safely.
1813 @end defmac
1816 @node Output
1817 @section Outputting Files
1818 @cindex Outputting files
1820 Every Autoconf script, e.g., @file{configure.ac}, should finish by
1821 calling @code{AC_OUTPUT}.  That is the macro that generates and runs
1822 @file{config.status}, which will create the @file{Makefile}s and any
1823 other files resulting from configuration.  This is the only required
1824 macro besides @code{AC_INIT} (@pxref{Input}).
1826 @defmac AC_OUTPUT
1827 @acindex{OUTPUT}
1828 @cindex Instantiation
1829 Generate @file{config.status} and launch it.  Call this macro once, at
1830 the end of @file{configure.ac}.
1832 @file{config.status} will perform all the configuration actions: all the
1833 output files (see @ref{Configuration Files}, macro
1834 @code{AC_CONFIG_FILES}), header files (see @ref{Configuration Headers},
1835 macro @code{AC_CONFIG_HEADERS}), commands (see @ref{Configuration
1836 Commands}, macro @code{AC_CONFIG_COMMANDS}), links (see
1837 @ref{Configuration Links}, macro @code{AC_CONFIG_LINKS}), subdirectories
1838 to configure (see @ref{Subdirectories}, macro @code{AC_CONFIG_SUBDIRS})
1839 are honored.
1841 The location of your @code{AC_OUTPUT} invocation is the exact point
1842 where configuration actions are taken: any code afterwards will be
1843 executed by @code{configure} once @command{config.status} was run.  If
1844 you want to bind actions to @command{config.status} itself
1845 (independently of whether @command{configure} is being run), see
1846 @ref{Configuration Commands, , Running Arbitrary Configuration
1847 Commands}.
1848 @end defmac
1850 Historically, the usage of @code{AC_OUTPUT} was somewhat different.
1851 @xref{Obsolete Macros}, for a description of the arguments that
1852 @code{AC_OUTPUT} used to support.
1855 If you run @command{make} in subdirectories, you should run it using the
1856 @code{make} variable @code{MAKE}.  Most versions of @command{make} set
1857 @code{MAKE} to the name of the @command{make} program plus any options it
1858 was given.  (But many do not include in it the values of any variables
1859 set on the command line, so those are not passed on automatically.)
1860 Some old versions of @command{make} do not set this variable.  The
1861 following macro allows you to use it even with those versions.
1863 @defmac AC_PROG_MAKE_SET
1864 @acindex{PROG_MAKE_SET}
1865 @ovindex SET_MAKE
1866 If the Make command, @code{$MAKE} if set or else @samp{make}, predefines
1867 @code{$(MAKE)}, define output variable @code{SET_MAKE} to be empty.
1868 Otherwise, define @code{SET_MAKE} to a macro definition that sets
1869 @code{$(MAKE)}, such as @samp{MAKE=make}.  Calls @code{AC_SUBST} for
1870 @code{SET_MAKE}.
1871 @end defmac
1873 If you use this macro, place a line like this in each @file{Makefile.in}
1874 that runs @code{MAKE} on other directories:
1876 @example
1877 @@SET_MAKE@@
1878 @end example
1882 @node Configuration Actions
1883 @section Performing Configuration Actions
1884 @cindex Configuration actions
1886 @file{configure} is designed so that it appears to do everything itself,
1887 but there is actually a hidden slave: @file{config.status}.
1888 @file{configure} is in charge of examining your system, but it is
1889 @file{config.status} that actually takes the proper actions based on the
1890 results of @file{configure}.  The most typical task of
1891 @file{config.status} is to @emph{instantiate} files.
1893 This section describes the common behavior of the four standard
1894 instantiating macros: @code{AC_CONFIG_FILES}, @code{AC_CONFIG_HEADERS},
1895 @code{AC_CONFIG_COMMANDS} and @code{AC_CONFIG_LINKS}.  They all
1896 have this prototype:
1898 @c FIXME: Can't use @ovar here, Texinfo 4.0 goes lunatic and emits something
1899 @c awful.
1900 @example
1901 AC_CONFIG_FOOS(@var{tag}@dots{}, [@var{commands}], [@var{init-cmds}])
1902 @end example
1904 @noindent
1905 where the arguments are:
1907 @table @var
1908 @item @var{tag}@dots{}
1909 A whitespace-separated list of tags, which are typically the names of
1910 the files to instantiate.
1912 You are encouraged to use literals as @var{tags}.  In particular, you
1913 should avoid
1915 @example
1916 @dots{} && my_foos="$my_foos fooo"
1917 @dots{} && my_foos="$my_foos foooo"
1918 AC_CONFIG_FOOS($my_foos)
1919 @end example
1921 @noindent
1922 and use this instead:
1924 @example
1925 @dots{} && AC_CONFIG_FOOS(fooo)
1926 @dots{} && AC_CONFIG_FOOS(foooo)
1927 @end example
1929 The macros @code{AC_CONFIG_FILES} and @code{AC_CONFIG_HEADERS} use
1930 special @var{tag}s: they may have the form @samp{@var{output}} or
1931 @samp{@var{output}:@var{inputs}}.  The file @var{output} is instantiated
1932 from its templates, @var{inputs} (defaulting to @samp{@var{output}.in}).
1934 For instance
1935 @samp{AC_CONFIG_FILES(Makefile:boiler/top.mk:boiler/bot.mk)} asks for
1936 the creation of @file{Makefile} that will be the expansion of the
1937 output variables in the concatenation of @file{boiler/top.mk} and
1938 @file{boiler/bot.mk}.
1940 The special value @samp{-} might be used to denote the standard output
1941 when used in @var{output}, or the standard input when used in the
1942 @var{inputs}.  You most probably don't need to use this in
1943 @file{configure.ac}, but it is convenient when using the command line
1944 interface of @file{./config.status}, see @ref{config.status Invocation},
1945 for more details.
1947 The @var{inputs} may be absolute or relative file names.  In the latter
1948 case they are first looked for in the build tree, and then in the source
1949 tree.
1951 @item commands
1952 Shell commands output literally into @file{config.status}, and
1953 associated with a tag that the user can use to tell @file{config.status}
1954 which the commands to run.  The commands are run each time a @var{tag}
1955 request is given to @file{config.status}, typically each time the file
1956 @file{@var{tag}} is created.
1958 The variables set during the execution of @command{configure} are
1959 @emph{not} available here: you first need to set them via the
1960 @var{init-cmds}.  Nonetheless the following variables are precomputed:
1962 @table @code
1963 @item srcdir
1964 The name of the top source directory, assuming that the working
1965 directory is the top build directory.  This
1966 is what @command{configure}'s option @option{--srcdir} sets.
1968 @item ac_top_srcdir
1969 The name of the top source directory, assuming that the working
1970 directory is the current build directory.
1973 @item ac_top_builddir
1974 The name of the top build directory, assuming that the working
1975 directory is the current build directory.
1976 It can be empty, or else ends with a slash, so that you may concatenate
1979 @item ac_srcdir
1980 The name of the corresponding source directory, assuming that the
1981 working directory is the current build directory.
1982 @end table
1984 @noindent
1985 The @dfn{current} directory refers to the directory (or
1986 pseudo-directory) containing the input part of @var{tags}.  For
1987 instance, running
1989 @example
1990 AC_CONFIG_COMMANDS([deep/dir/out:in/in.in], [@dots{}], [@dots{}])
1991 @end example
1993 @noindent
1994  with @option{--srcdir=../package} produces the following values:
1996 @example
1997 # Argument of --srcdir
1998 srcdir='../package'
1999 # Reversing deep/dir
2000 ac_top_builddir='../../'
2001 # Concatenation of $ac_top_builddir and srcdir
2002 ac_top_srcdir='../../../package'
2003 # Concatenation of $ac_top_srcdir and deep/dir
2004 ac_srcdir='../../../package/deep/dir'
2005 @end example
2007 @noindent
2008 independently of @samp{in/in.in}.
2010 @item init-cmds
2011 Shell commands output @emph{unquoted} near the beginning of
2012 @file{config.status}, and executed each time @file{config.status} runs
2013 (regardless of the tag).  Because they are unquoted, for example,
2014 @samp{$var} will be output as the value of @code{var}.  @var{init-cmds}
2015 is typically used by @file{configure} to give @file{config.status} some
2016 variables it needs to run the @var{commands}.
2018 You should be extremely cautious in your variable names: all the
2019 @var{init-cmds} share the same name space and may overwrite each other
2020 in unpredictable ways.  Sorry@enddots{}
2021 @end table
2023 All these macros can be called multiple times, with different
2024 @var{tag}s, of course!
2027 @node Configuration Files
2028 @section Creating Configuration Files
2029 @cindex Creating configuration files
2030 @cindex Configuration file creation
2032 Be sure to read the previous section, @ref{Configuration Actions}.
2034 @defmac AC_CONFIG_FILES (@var{file}@dots{}, @ovar{cmds}, @ovar{init-cmds})
2035 @acindex{CONFIG_FILES}
2036 Make @code{AC_OUTPUT} create each @file{@var{file}} by copying an input
2037 file (by default @file{@var{file}.in}), substituting the output variable
2038 values.
2039 @c Before we used to have this feature, which was later rejected
2040 @c because it complicates the write of Makefiles:
2041 @c If the file would be unchanged, it is left untouched, to preserve
2042 @c timestamp.
2043 This macro is one of the instantiating macros; see @ref{Configuration
2044 Actions}.  @xref{Makefile Substitutions}, for more information on using
2045 output variables.  @xref{Setting Output Variables}, for more information
2046 on creating them.  This macro creates the directory that the file is in
2047 if it doesn't exist.  Usually, @file{Makefile}s are created this way,
2048 but other files, such as @file{.gdbinit}, can be specified as well.
2050 Typical calls to @code{AC_CONFIG_FILES} look like this:
2052 @example
2053 AC_CONFIG_FILES([Makefile src/Makefile man/Makefile X/Imakefile])
2054 AC_CONFIG_FILES([autoconf], [chmod +x autoconf])
2055 @end example
2057 You can override an input file name by appending to @var{file} a
2058 colon-separated list of input files.  Examples:
2060 @example
2061 AC_CONFIG_FILES([Makefile:boiler/top.mk:boiler/bot.mk]
2062                 [lib/Makefile:boiler/lib.mk])
2063 @end example
2065 @noindent
2066 Doing this allows you to keep your file names acceptable to
2067 @acronym{DOS} variants, or
2068 to prepend and/or append boilerplate to the file.
2069 @end defmac
2073 @node Makefile Substitutions
2074 @section Substitutions in Makefiles
2075 @cindex Substitutions in makefiles
2076 @cindex Makefile substitutions
2078 Each subdirectory in a distribution that contains something to be
2079 compiled or installed should come with a file @file{Makefile.in}, from
2080 which @command{configure} will create a @file{Makefile} in that directory.
2081 To create a @file{Makefile}, @command{configure} performs a simple variable
2082 substitution, replacing occurrences of @samp{@@@var{variable}@@} in
2083 @file{Makefile.in} with the value that @command{configure} has determined
2084 for that variable.  Variables that are substituted into output files in
2085 this way are called @dfn{output variables}.  They are ordinary shell
2086 variables that are set in @command{configure}.  To make @command{configure}
2087 substitute a particular variable into the output files, the macro
2088 @code{AC_SUBST} must be called with that variable name as an argument.
2089 Any occurrences of @samp{@@@var{variable}@@} for other variables are
2090 left unchanged.  @xref{Setting Output Variables}, for more information
2091 on creating output variables with @code{AC_SUBST}.
2093 A software package that uses a @command{configure} script should be
2094 distributed with a file @file{Makefile.in}, but no @file{Makefile}; that
2095 way, the user has to properly configure the package for the local system
2096 before compiling it.
2098 @xref{Makefile Conventions,, Makefile Conventions, standards, The
2099 @acronym{GNU} Coding Standards}, for more information on what to put in
2100 @file{Makefile}s.
2102 @menu
2103 * Preset Output Variables::     Output variables that are always set
2104 * Installation Directory Variables::  Other preset output variables
2105 * Build Directories::           Supporting multiple concurrent compiles
2106 * Automatic Remaking::          Makefile rules for configuring
2107 @end menu
2109 @node Preset Output Variables
2110 @subsection Preset Output Variables
2111 @cindex Output variables
2113 Some output variables are preset by the Autoconf macros.  Some of the
2114 Autoconf macros set additional output variables, which are mentioned in
2115 the descriptions for those macros.  @xref{Output Variable Index}, for a
2116 complete list of output variables.  @xref{Installation Directory
2117 Variables}, for the list of the preset ones related to installation
2118 directories.  Below are listed the other preset ones.  They all are
2119 precious variables (@pxref{Setting Output Variables},
2120 @code{AC_ARG_VAR}).
2122 @c Just say no to ASCII sorting!  We're humans, not computers.
2123 @c These variables are listed as they would be in a dictionary:
2124 @c actor
2125 @c Actress
2126 @c actress
2128 @defvar CFLAGS
2129 @ovindex CFLAGS
2130 Debugging and optimization options for the C compiler.  If it is not set
2131 in the environment when @command{configure} runs, the default value is set
2132 when you call @code{AC_PROG_CC} (or empty if you don't).  @command{configure}
2133 uses this variable when compiling programs to test for C features.
2134 @end defvar
2136 @defvar configure_input
2137 @ovindex configure_input
2138 A comment saying that the file was generated automatically by
2139 @command{configure} and giving the name of the input file.
2140 @code{AC_OUTPUT} adds a comment line containing this variable to the top
2141 of every @file{Makefile} it creates.  For other files, you should
2142 reference this variable in a comment at the top of each input file.  For
2143 example, an input shell script should begin like this:
2145 @example
2146 #! /bin/sh
2147 # @@configure_input@@
2148 @end example
2150 @noindent
2151 The presence of that line also reminds people editing the file that it
2152 needs to be processed by @command{configure} in order to be used.
2153 @end defvar
2155 @defvar CPPFLAGS
2156 @ovindex CPPFLAGS
2157 Header file search directory (@option{-I@var{dir}}) and any other
2158 miscellaneous options for the C and C++ preprocessors and compilers.  If
2159 it is not set in the environment when @command{configure} runs, the default
2160 value is empty.  @command{configure} uses this variable when compiling or
2161 preprocessing programs to test for C and C++ features.
2162 @end defvar
2164 @defvar CXXFLAGS
2165 @ovindex CXXFLAGS
2166 Debugging and optimization options for the C++ compiler.  If it is not
2167 set in the environment when @command{configure} runs, the default value is
2168 set when you call @code{AC_PROG_CXX} (or empty if you don't).
2169 @command{configure} uses this variable when compiling programs to test for
2170 C++ features.
2171 @end defvar
2173 @defvar DEFS
2174 @ovindex DEFS
2175 @option{-D} options to pass to the C compiler.  If @code{AC_CONFIG_HEADERS}
2176 is called, @command{configure} replaces @samp{@@DEFS@@} with
2177 @option{-DHAVE_CONFIG_H} instead (@pxref{Configuration Headers}).  This
2178 variable is not defined while @command{configure} is performing its tests,
2179 only when creating the output files.  @xref{Setting Output Variables}, for
2180 how to check the results of previous tests.
2181 @end defvar
2183 @defvar ECHO_C
2184 @defvarx ECHO_N
2185 @defvarx ECHO_T
2186 @ovindex ECHO_C
2187 @ovindex ECHO_N
2188 @ovindex ECHO_T
2189 How does one suppress the trailing newline from @command{echo} for
2190 question-answer message pairs?  These variables provide a way:
2192 @example
2193 echo $ECHO_N "And the winner is... $ECHO_C"
2194 sleep 100000000000
2195 echo "$@{ECHO_T@}dead."
2196 @end example
2198 @noindent
2199 Some old and uncommon @command{echo} implementations offer no means to
2200 achieve this, in which case @code{ECHO_T} is set to tab.  You might not
2201 want to use it.
2202 @end defvar
2204 @defvar FCFLAGS
2205 @ovindex FCFLAGS
2206 Debugging and optimization options for the Fortran compiler.  If it
2207 is not set in the environment when @command{configure} runs, the default
2208 value is set when you call @code{AC_PROG_FC} (or empty if you don't).
2209 @command{configure} uses this variable when compiling programs to test for
2210 Fortran features.
2211 @end defvar
2213 @defvar FFLAGS
2214 @ovindex FFLAGS
2215 Debugging and optimization options for the Fortran 77 compiler.  If it
2216 is not set in the environment when @command{configure} runs, the default
2217 value is set when you call @code{AC_PROG_F77} (or empty if you don't).
2218 @command{configure} uses this variable when compiling programs to test for
2219 Fortran 77 features.
2220 @end defvar
2222 @defvar LDFLAGS
2223 @ovindex LDFLAGS
2224 Stripping (@option{-s}), path (@option{-L}), and any other miscellaneous
2225 options for the linker.  Don't use this variable to pass library names
2226 (@option{-l}) to the linker, use @code{LIBS} instead.  If it is not set
2227 in the environment when @command{configure} runs, the default value is empty.
2228 @command{configure} uses this variable when linking programs to test for
2229 C, C++, and Fortran features.
2230 @end defvar
2232 @defvar LIBS
2233 @ovindex LIBS
2234 @option{-l} options to pass to the linker.  The default value is empty,
2235 but some Autoconf macros may prepend extra libraries to this variable if
2236 those libraries are found and provide necessary functions, see
2237 @ref{Libraries}.  @command{configure} uses this variable when linking
2238 programs to test for C, C++, and Fortran features.
2239 @end defvar
2241 @defvar builddir
2242 @ovindex builddir
2243 Rigorously equal to @samp{.}.  Added for symmetry only.
2244 @end defvar
2246 @defvar abs_builddir
2247 @ovindex abs_builddir
2248 Absolute name of @code{builddir}.
2249 @end defvar
2251 @defvar top_builddir
2252 @ovindex top_builddir
2253 The relative name of the top level of the current build tree.  In the
2254 top-level directory, this is the same as @code{builddir}.
2255 @end defvar
2257 @defvar abs_top_builddir
2258 @ovindex abs_top_builddir
2259 Absolute name of @code{top_builddir}.
2260 @end defvar
2262 @defvar srcdir
2263 @ovindex srcdir
2264 The relative name of the directory that contains the source code for
2265 that @file{Makefile}.
2266 @end defvar
2268 @defvar abs_srcdir
2269 @ovindex abs_srcdir
2270 Absolute name of @code{srcdir}.
2271 @end defvar
2273 @defvar top_srcdir
2274 @ovindex top_srcdir
2275 The relative name of the top-level source code directory for the
2276 package.  In the top-level directory, this is the same as @code{srcdir}.
2277 @end defvar
2279 @defvar abs_top_srcdir
2280 @ovindex abs_top_srcdir
2281 Absolute name of @code{top_srcdir}.
2282 @end defvar
2284 @node Installation Directory Variables
2285 @subsection Installation Directory Variables
2286 @cindex Installation directories
2287 @cindex Directories, installation
2289 The following variables specify the directories where the package will
2290 be installed, see @ref{Directory Variables,, Variables for
2291 Installation Directories, standards, The @acronym{GNU} Coding
2292 Standards}, for more information.  See the end of this section for
2293 details on when and how to use these variables.
2295 @defvar bindir
2296 @ovindex bindir
2297 The directory for installing executables that users run.
2298 @end defvar
2300 @defvar datadir
2301 @ovindex datadir
2302 The directory for installing ideosyncratic read-only
2303 architecture-independent data.
2304 @end defvar
2306 @defvar datarootdir
2307 @ovindex datarootdir
2308 The root of the directory tree for read-only architecture-independent
2309 data files.
2310 @end defvar
2312 @defvar docdir
2313 @ovindex docdir
2314 The directory for installing documentation files (other than Info and
2315 man).
2316 @end defvar
2318 @defvar dvidir
2319 @ovindex dvidir
2320 The directory for installing documentation files in DVI format.
2321 @end defvar
2323 @defvar exec_prefix
2324 @ovindex exec_prefix
2325 The installation prefix for architecture-dependent files.  By default
2326 it's the same as @var{prefix}.  You should avoid installing anything
2327 directly to @var{exec_prefix}.  However, the default value for
2328 directories containing architecture-dependent files should be relative
2329 to @var{exec_prefix}.
2330 @end defvar
2332 @defvar htmldir
2333 @ovindex htmldir
2334 The directory for installing HTML documentation.
2335 @end defvar
2337 @defvar includedir
2338 @ovindex includedir
2339 The directory for installing C header files.
2340 @end defvar
2342 @defvar infodir
2343 @ovindex infodir
2344 The directory for installing documentation in Info format.
2345 @end defvar
2347 @defvar libdir
2348 @ovindex libdir
2349 The directory for installing object code libraries.
2350 @end defvar
2352 @defvar libexecdir
2353 @ovindex libexecdir
2354 The directory for installing executables that other programs run.
2355 @end defvar
2357 @defvar localedir
2358 @ovindex localedir
2359 The directory for installing locale-dependent but
2360 architecture-independent data, such as message catalogs.  This directory
2361 usually has a subdirectory per locale.
2362 @end defvar
2364 @defvar localstatedir
2365 @ovindex localstatedir
2366 The directory for installing modifiable single-machine data.
2367 @end defvar
2369 @defvar mandir
2370 @ovindex mandir
2371 The top-level directory for installing documentation in man format.
2372 @end defvar
2374 @defvar oldincludedir
2375 @ovindex oldincludedir
2376 The directory for installing C header files for non-GCC compilers.
2377 @end defvar
2379 @defvar pdfdir
2380 @ovindex pdfdir
2381 The directory for installing PDF documentation.
2382 @end defvar
2384 @defvar prefix
2385 @ovindex prefix
2386 The common installation prefix for all files.  If @var{exec_prefix}
2387 is defined to a different value, @var{prefix} is used only for
2388 architecture-independent files.
2389 @end defvar
2391 @defvar psdir
2392 @ovindex psdir
2393 The directory for installing PostScript documentation.
2394 @end defvar
2396 @defvar sbindir
2397 @ovindex sbindir
2398 The directory for installing executables that system
2399 administrators run.
2400 @end defvar
2402 @defvar sharedstatedir
2403 @ovindex sharedstatedir
2404 The directory for installing modifiable architecture-independent data.
2405 @end defvar
2407 @defvar sysconfdir
2408 @ovindex sysconfdir
2409 The directory for installing read-only single-machine data.
2410 @end defvar
2413 Most of these variables have values that rely on @code{prefix} or
2414 @code{exec_prefix}.  It is deliberate that the directory output
2415 variables keep them unexpanded: typically @samp{@@datarootdir@@} will be
2416 replaced by @samp{$@{prefix@}/share}, not @samp{/usr/local/share}, and
2417 @samp{@@datadir@@} will be replaced by @samp{$@{datarootdir@}}.
2419 This behavior is mandated by the @acronym{GNU} coding standards, so that when
2420 the user runs:
2422 @table @samp
2423 @item make
2424 she can still specify a different prefix from the one specified to
2425 @command{configure}, in which case, if needed, the package shall hard
2426 code dependencies corresponding to the make-specified prefix.
2428 @item make install
2429 she can specify a different installation location, in which case the
2430 package @emph{must} still depend on the location which was compiled in
2431 (i.e., never recompile when @samp{make install} is run).  This is an
2432 extremely important feature, as many people may decide to install all
2433 the files of a package grouped together, and then install links from
2434 the final locations to there.
2435 @end table
2437 In order to support these features, it is essential that
2438 @code{datarootdir} remains being defined as @samp{$@{prefix@}/share} to
2439 depend upon the current value of @code{prefix}.
2441 A corollary is that you should not use these variables except in
2442 Makefiles.  For instance, instead of trying to evaluate @code{datadir}
2443 in @file{configure} and hard-coding it in Makefiles using
2444 e.g., @samp{AC_DEFINE_UNQUOTED(DATADIR, "$datadir", [Data directory.])},
2445 you should add
2446 @samp{-DDATADIR="$(datadir)"} to your @code{CPPFLAGS}.
2448 Similarly, you should not rely on @code{AC_CONFIG_FILES} to replace
2449 @code{datadir} and friends in your shell scripts and other files, rather
2450 let @command{make} manage their replacement.  For instance Autoconf
2451 ships templates of its shell scripts ending with @samp{.in}, and uses a
2452 Makefile snippet similar to:
2454 @example
2455 @group
2456 edit = sed \
2457         -e 's|@@datadir[@@]|$(pkgdatadir)|g' \
2458         -e 's|@@prefix[@@]|$(prefix)|g'
2459 @end group
2461 @group
2462 autoconf: Makefile $(srcdir)/autoconf.in
2463         rm -f autoconf autoconf.tmp
2464         $(edit) $(srcdir)/autoconf.in >autoconf.tmp
2465         chmod +x autoconf.tmp
2466         mv autoconf.tmp autoconf
2467 @end group
2469 @group
2470 autoheader: Makefile $(srcdir)/autoheader.in
2471         rm -f autoheader autoheader.tmp
2472         $(edit) $(srcdir)/autoconf.in >autoheader.tmp
2473         chmod +x autoheader.tmp
2474         mv autoheader.tmp autoheader
2475 @end group
2476 @end example
2478 Some details are noteworthy:
2480 @table @samp
2481 @item @@datadir[@@]
2482 The brackets prevent @command{configure} from replacing
2483 @samp{@@datadir@@} in the sed expression itself.
2484 Brackets are preferable to a backslash here, since
2485 Posix says @samp{\@@} is not portable.
2487 @item $(pkgdatadir)
2488 Don't use @samp{@@pkgdatadir@@}!  Use the matching makefile variable
2489 instead.
2491 @item ,
2492 Don't use @samp{/} in the sed expression(s) since most likely the
2493 variables you use, such as @samp{$(pkgdatadir)}, will contain
2494 some.
2496 @item Dependency on @file{Makefile}
2497 Since @code{edit} uses values that depend on the configuration specific
2498 values (@code{prefix}, etc.)@: and not only on @code{VERSION} and so forth,
2499 the output depends on @file{Makefile}, not @file{configure.ac}.
2501 @item Separated dependencies and Single Suffix Rules
2502 You can't use them!  The above snippet cannot be (portably) rewritten
2505 @example
2506 autoconf autoheader: Makefile
2507 @group
2508 .in:
2509         rm -f $@@ $@@.tmp
2510         $(edit) $< >$@@.tmp
2511         chmod +x $@@.tmp
2512         mv $@@.tmp $@@
2513 @end group
2514 @end example
2516 @xref{Limitations of Make}, for details.
2518 @item @samp{$(srcdir)}
2519 Be sure to specify the name of the source directory,
2520 otherwise the package won't support separated builds.
2521 @end table
2524 @node Build Directories
2525 @subsection Build Directories
2526 @cindex Build directories
2527 @cindex Directories, build
2529 You can support compiling a software package for several architectures
2530 simultaneously from the same copy of the source code.  The object files
2531 for each architecture are kept in their own directory.
2533 To support doing this, @command{make} uses the @code{VPATH} variable to
2534 find the files that are in the source directory.  @acronym{GNU} Make
2535 and most other recent @command{make} programs can do this.  Older
2536 @command{make} programs do not support @code{VPATH}; when using them, the
2537 source code must be in the same directory as the object files.
2539 To support @code{VPATH}, each @file{Makefile.in} should contain two
2540 lines that look like:
2542 @example
2543 srcdir = @@srcdir@@
2544 VPATH = @@srcdir@@
2545 @end example
2547 Do not set @code{VPATH} to the value of another variable, for example
2548 @samp{VPATH = $(srcdir)}, because some versions of @command{make} do not do
2549 variable substitutions on the value of @code{VPATH}.
2551 @command{configure} substitutes the correct value for @code{srcdir} when
2552 it produces @file{Makefile}.
2554 Do not use the @code{make} variable @code{$<}, which expands to the
2555 file name of the file in the source directory (found with @code{VPATH}),
2556 except in implicit rules.  (An implicit rule is one such as @samp{.c.o},
2557 which tells how to create a @file{.o} file from a @file{.c} file.)  Some
2558 versions of @command{make} do not set @code{$<} in explicit rules; they
2559 expand it to an empty value.
2561 Instead, @file{Makefile} command lines should always refer to source
2562 files by prefixing them with @samp{$(srcdir)/}.  For example:
2564 @example
2565 time.info: time.texinfo
2566         $(MAKEINFO) $(srcdir)/time.texinfo
2567 @end example
2569 @node Automatic Remaking
2570 @subsection Automatic Remaking
2571 @cindex Automatic remaking
2572 @cindex Remaking automatically
2574 You can put rules like the following in the top-level @file{Makefile.in}
2575 for a package to automatically update the configuration information when
2576 you change the configuration files.  This example includes all of the
2577 optional files, such as @file{aclocal.m4} and those related to
2578 configuration header files.  Omit from the @file{Makefile.in} rules for
2579 any of these files that your package does not use.
2581 The @samp{$(srcdir)/} prefix is included because of limitations in the
2582 @code{VPATH} mechanism.
2584 The @file{stamp-} files are necessary because the timestamps of
2585 @file{config.h.in} and @file{config.h} will not be changed if remaking
2586 them does not change their contents.  This feature avoids unnecessary
2587 recompilation.  You should include the file @file{stamp-h.in} your
2588 package's distribution, so @command{make} will consider
2589 @file{config.h.in} up to date.  Don't use @command{touch}
2590 (@pxref{Limitations of Usual Tools}), rather use @command{echo} (using
2591 @command{date} would cause needless differences, hence @acronym{CVS}
2592 conflicts, etc.).
2594 @example
2595 @group
2596 $(srcdir)/configure: configure.ac aclocal.m4
2597         cd $(srcdir) && autoconf
2599 # autoheader might not change config.h.in, so touch a stamp file.
2600 $(srcdir)/config.h.in: stamp-h.in
2601 $(srcdir)/stamp-h.in: configure.ac aclocal.m4
2602         cd $(srcdir) && autoheader
2603         echo timestamp > $(srcdir)/stamp-h.in
2605 config.h: stamp-h
2606 stamp-h: config.h.in config.status
2607         ./config.status
2609 Makefile: Makefile.in config.status
2610         ./config.status
2612 config.status: configure
2613         ./config.status --recheck
2614 @end group
2615 @end example
2617 @noindent
2618 (Be careful if you copy these lines directly into your Makefile, as you
2619 will need to convert the indented lines to start with the tab character.)
2621 In addition, you should use @samp{AC_CONFIG_FILES([stamp-h], [echo
2622 timestamp > stamp-h])} so @file{config.status} will ensure that
2623 @file{config.h} is considered up to date.  @xref{Output}, for more
2624 information about @code{AC_OUTPUT}.
2626 @xref{config.status Invocation}, for more examples of handling
2627 configuration-related dependencies.
2629 @node Configuration Headers
2630 @section Configuration Header Files
2631 @cindex Configuration Header
2632 @cindex @file{config.h}
2634 When a package contains more than a few tests that define C preprocessor
2635 symbols, the command lines to pass @option{-D} options to the compiler
2636 can get quite long.  This causes two problems.  One is that the
2637 @command{make} output is hard to visually scan for errors.  More
2638 seriously, the command lines can exceed the length limits of some
2639 operating systems.  As an alternative to passing @option{-D} options to
2640 the compiler, @command{configure} scripts can create a C header file
2641 containing @samp{#define} directives.  The @code{AC_CONFIG_HEADERS}
2642 macro selects this kind of output.  It should be called right after
2643 @code{AC_INIT}.
2645 The package should @samp{#include} the configuration header file before
2646 any other header files, to prevent inconsistencies in declarations (for
2647 example, if it redefines @code{const}).  Use @samp{#include <config.h>}
2648 instead of @samp{#include "config.h"}, and pass the C compiler a
2649 @option{-I.} option (or @option{-I..}; whichever directory contains
2650 @file{config.h}).  That way, even if the source directory is configured
2651 itself (perhaps to make a distribution), other build directories can
2652 also be configured without finding the @file{config.h} from the source
2653 directory.
2655 @defmac AC_CONFIG_HEADERS (@var{header} @dots{}, @ovar{cmds}, @ovar{init-cmds})
2656 @acindex{CONFIG_HEADERS}
2657 @cvindex HAVE_CONFIG_H
2658 This macro is one of the instantiating macros; see @ref{Configuration
2659 Actions}.  Make @code{AC_OUTPUT} create the file(s) in the
2660 whitespace-separated list @var{header} containing C preprocessor
2661 @code{#define} statements, and replace @samp{@@DEFS@@} in generated
2662 files with @option{-DHAVE_CONFIG_H} instead of the value of @code{DEFS}.
2663 The usual name for @var{header} is @file{config.h}.
2665 If @var{header} already exists and its contents are identical to what
2666 @code{AC_OUTPUT} would put in it, it is left alone.  Doing this allows
2667 making some changes in the configuration without needlessly causing
2668 object files that depend on the header file to be recompiled.
2670 Usually the input file is named @file{@var{header}.in}; however, you can
2671 override the input file name by appending to @var{header} a
2672 colon-separated list of input files.  Examples:
2674 @example
2675 AC_CONFIG_HEADERS([config.h:config.hin])
2676 AC_CONFIG_HEADERS([defines.h:defs.pre:defines.h.in:defs.post])
2677 @end example
2679 @noindent
2680 Doing this allows you to keep your file names acceptable to
2681 @acronym{DOS} variants, or
2682 to prepend and/or append boilerplate to the file.
2683 @end defmac
2685 @xref{Configuration Actions}, for more details on @var{header}.
2687 @menu
2688 * Header Templates::            Input for the configuration headers
2689 * autoheader Invocation::       How to create configuration templates
2690 * Autoheader Macros::           How to specify CPP templates
2691 @end menu
2693 @node Header Templates
2694 @subsection Configuration Header Templates
2695 @cindex Configuration Header Template
2696 @cindex Header templates
2697 @cindex @file{config.h.in}
2699 Your distribution should contain a template file that looks as you want
2700 the final header file to look, including comments, with @code{#undef}
2701 statements which are used as hooks.  For example, suppose your
2702 @file{configure.ac} makes these calls:
2704 @example
2705 AC_CONFIG_HEADERS([conf.h])
2706 AC_CHECK_HEADERS([unistd.h])
2707 @end example
2709 @noindent
2710 Then you could have code like the following in @file{conf.h.in}.  On
2711 systems that have @file{unistd.h}, @command{configure} will @samp{#define}
2712 @samp{HAVE_UNISTD_H} to 1.  On other systems, the whole line will be
2713 commented out (in case the system predefines that symbol).
2715 @example
2716 @group
2717 /* Define as 1 if you have unistd.h.  */
2718 #undef HAVE_UNISTD_H
2719 @end group
2720 @end example
2722 Pay attention that @samp{#undef} is in the first column, and there is
2723 nothing behind @samp{HAVE_UNISTD_H}, not even white spaces.  You can
2724 then decode the configuration header using the preprocessor directives:
2726 @example
2727 @group
2728 #include <conf.h>
2730 #if HAVE_UNISTD_H
2731 # include <unistd.h>
2732 #else
2733 /* We are in trouble.  */
2734 #endif
2735 @end group
2736 @end example
2738 The use of old form templates, with @samp{#define} instead of
2739 @samp{#undef} is strongly discouraged.  Similarly with old templates
2740 with comments on the same line as the @samp{#undef}.  Anyway, putting
2741 comments in preprocessor macros has never been a good idea.
2743 Since it is a tedious task to keep a template header up to date, you may
2744 use @command{autoheader} to generate it, see @ref{autoheader Invocation}.
2747 @node autoheader Invocation
2748 @subsection Using @command{autoheader} to Create @file{config.h.in}
2749 @cindex @command{autoheader}
2751 The @command{autoheader} program can create a template file of C
2752 @samp{#define} statements for @command{configure} to use.  If
2753 @file{configure.ac} invokes @code{AC_CONFIG_HEADERS(@var{file})},
2754 @command{autoheader} creates @file{@var{file}.in}; if multiple file
2755 arguments are given, the first one is used.  Otherwise,
2756 @command{autoheader} creates @file{config.h.in}.
2758 In order to do its job, @command{autoheader} needs you to document all
2759 of the symbols that you might use; i.e., there must be at least one
2760 @code{AC_DEFINE} or one @code{AC_DEFINE_UNQUOTED} call with a third
2761 argument for each symbol (@pxref{Defining Symbols}).  An additional
2762 constraint is that the first argument of @code{AC_DEFINE} must be a
2763 literal.  Note that all symbols defined by Autoconf's builtin tests are
2764 already documented properly; you only need to document those that you
2765 define yourself.
2767 You might wonder why @command{autoheader} is needed: after all, why
2768 would @command{configure} need to ``patch'' a @file{config.h.in} to
2769 produce a @file{config.h} instead of just creating @file{config.h} from
2770 scratch?  Well, when everything rocks, the answer is just that we are
2771 wasting our time maintaining @command{autoheader}: generating
2772 @file{config.h} directly is all that is needed.  When things go wrong,
2773 however, you'll be thankful for the existence of @command{autoheader}.
2775 The fact that the symbols are documented is important in order to
2776 @emph{check} that @file{config.h} makes sense.  The fact that there is a
2777 well-defined list of symbols that should be @code{#define}'d (or not) is
2778 also important for people who are porting packages to environments where
2779 @command{configure} cannot be run: they just have to @emph{fill in the
2780 blanks}.
2782 But let's come back to the point: @command{autoheader}'s invocation@dots{}
2784 If you give @command{autoheader} an argument, it uses that file instead
2785 of @file{configure.ac} and writes the header file to the standard output
2786 instead of to @file{config.h.in}.  If you give @command{autoheader} an
2787 argument of @option{-}, it reads the standard input instead of
2788 @file{configure.ac} and writes the header file to the standard output.
2790 @command{autoheader} accepts the following options:
2792 @table @option
2793 @item --help
2794 @itemx -h
2795 Print a summary of the command line options and exit.
2797 @item --version
2798 @itemx -V
2799 Print the version number of Autoconf and exit.
2801 @item --verbose
2802 @itemx -v
2803 Report processing steps.
2805 @item --debug
2806 @itemx -d
2807 Don't remove the temporary files.
2809 @item --force
2810 @itemx -f
2811 Remake the template file even if newer than its input files.
2813 @item --include=@var{dir}
2814 @itemx -I @var{dir}
2815 Append @var{dir} to the include path.  Multiple invocations accumulate.
2817 @item --prepend-include=@var{dir}
2818 @item -B @var{dir}
2819 Prepend @var{dir} to the include path.  Multiple invocations accumulate.
2821 @item --warnings=@var{category}
2822 @itemx -W @var{category}
2823 @evindex WARNINGS
2824 Report the warnings related to @var{category} (which can actually be a
2825 comma separated list).  Current categories include:
2827 @table @samp
2828 @item obsolete
2829 report the uses of obsolete constructs
2831 @item all
2832 report all the warnings
2834 @item none
2835 report none
2837 @item error
2838 treats warnings as errors
2840 @item no-@var{category}
2841 disable warnings falling into @var{category}
2842 @end table
2844 @end table
2848 @node Autoheader Macros
2849 @subsection Autoheader Macros
2850 @cindex Autoheader macros
2852 @command{autoheader} scans @file{configure.ac} and figures out which C
2853 preprocessor symbols it might define.  It knows how to generate
2854 templates for symbols defined by @code{AC_CHECK_HEADERS},
2855 @code{AC_CHECK_FUNCS} etc., but if you @code{AC_DEFINE} any additional
2856 symbol, you must define a template for it.  If there are missing
2857 templates, @command{autoheader} fails with an error message.
2859 The simplest way to create a template for a @var{symbol} is to supply
2860 the @var{description} argument to an @samp{AC_DEFINE(@var{symbol})}; see
2861 @ref{Defining Symbols}.  You may also use one of the following macros.
2863 @defmac AH_VERBATIM (@var{key}, @var{template})
2864 @ahindex{VERBATIM}
2865 Tell @command{autoheader} to include the @var{template} as-is in the header
2866 template file.  This @var{template} is associated with the @var{key},
2867 which is used to sort all the different templates and guarantee their
2868 uniqueness.  It should be a symbol that can be @code{AC_DEFINE}'d.
2870 For example:
2872 @example
2873 AH_VERBATIM([_GNU_SOURCE],
2874 [/* Enable GNU extensions on systems that have them.  */
2875 #ifndef _GNU_SOURCE
2876 # define _GNU_SOURCE
2877 #endif])
2878 @end example
2879 @end defmac
2882 @defmac AH_TEMPLATE (@var{key}, @var{description})
2883 @ahindex{TEMPLATE}
2884 Tell @command{autoheader} to generate a template for @var{key}.  This macro
2885 generates standard templates just like @code{AC_DEFINE} when a
2886 @var{description} is given.
2888 For example:
2890 @example
2891 AH_TEMPLATE([CRAY_STACKSEG_END],
2892             [Define to one of _getb67, GETB67, getb67
2893              for Cray-2 and Cray-YMP systems.  This
2894              function is required for alloca.c support
2895              on those systems.])
2896 @end example
2898 @noindent
2899 will generate the following template, with the description properly
2900 justified.
2902 @example
2903 /* Define to one of _getb67, GETB67, getb67 for Cray-2 and
2904    Cray-YMP systems.  This function is required for alloca.c
2905    support on those systems.  */
2906 #undef CRAY_STACKSEG_END
2907 @end example
2908 @end defmac
2911 @defmac AH_TOP (@var{text})
2912 @ahindex{TOP}
2913 Include @var{text} at the top of the header template file.
2914 @end defmac
2917 @defmac AH_BOTTOM (@var{text})
2918 @ahindex{BOTTOM}
2919 Include @var{text} at the bottom of the header template file.
2920 @end defmac
2923 @node Configuration Commands
2924 @section Running Arbitrary Configuration Commands
2925 @cindex Configuration commands
2926 @cindex Commands for configuration
2928 You can execute arbitrary commands before, during, and after
2929 @file{config.status} is run.  The three following macros accumulate the
2930 commands to run when they are called multiple times.
2931 @code{AC_CONFIG_COMMANDS} replaces the obsolete macro
2932 @code{AC_OUTPUT_COMMANDS}; see @ref{Obsolete Macros}, for details.
2934 @defmac AC_CONFIG_COMMANDS (@var{tag}@dots{}, @ovar{cmds}, @ovar{init-cmds})
2935 @acindex{CONFIG_COMMANDS}
2936 Specify additional shell commands to run at the end of
2937 @file{config.status}, and shell commands to initialize any variables
2938 from @command{configure}.  Associate the commands with @var{tag}.
2939 Since typically the @var{cmds} create a file, @var{tag} should
2940 naturally be the name of that file.  If needed, the directory hosting
2941 @var{tag} is created.  This macro is one of the instantiating macros;
2942 see @ref{Configuration Actions}.
2944 Here is an unrealistic example:
2945 @example
2946 fubar=42
2947 AC_CONFIG_COMMANDS([fubar],
2948                    [echo this is extra $fubar, and so on.],
2949                    [fubar=$fubar])
2950 @end example
2952 Here is a better one:
2953 @example
2954 AC_CONFIG_COMMANDS([time-stamp], [date >time-stamp])
2955 @end example
2956 @end defmac
2958 @defmac AC_CONFIG_COMMANDS_PRE (@var{cmds})
2959 @acindex{OUTPUT_COMMANDS_PRE}
2960 Execute the @var{cmds} right before creating @file{config.status}.
2961 @end defmac
2963 @defmac AC_CONFIG_COMMANDS_POST (@var{cmds})
2964 @acindex{OUTPUT_COMMANDS_POST}
2965 Execute the @var{cmds} right after creating @file{config.status}.
2966 @end defmac
2971 @node Configuration Links
2972 @section Creating Configuration Links
2973 @cindex Configuration links
2974 @cindex Links for configuration
2976 You may find it convenient to create links whose destinations depend upon
2977 results of tests.  One can use @code{AC_CONFIG_COMMANDS} but the
2978 creation of relative symbolic links can be delicate when the package is
2979 built in a directory different from the source directory.
2981 @defmac AC_CONFIG_LINKS (@var{dest}:@var{source}@dots{}, @ovar{cmds}, @ovar{init-cmds})
2982 @acindex{CONFIG_LINKS}
2983 @cindex Links
2984 Make @code{AC_OUTPUT} link each of the existing files @var{source} to
2985 the corresponding link name @var{dest}.  Makes a symbolic link if
2986 possible, otherwise a hard link if possible, otherwise a copy.  The
2987 @var{dest} and @var{source} names should be relative to the top level
2988 source or build directory.  This macro is one of the instantiating
2989 macros; see @ref{Configuration Actions}.
2991 For example, this call:
2993 @example
2994 AC_CONFIG_LINKS(host.h:config/$machine.h
2995                 object.h:config/$obj_format.h)
2996 @end example
2998 @noindent
2999 creates in the current directory @file{host.h} as a link to
3000 @file{@var{srcdir}/config/$machine.h}, and @file{object.h} as a
3001 link to @file{@var{srcdir}/config/$obj_format.h}.
3003 The tempting value @samp{.} for @var{dest} is invalid: it makes it
3004 impossible for @samp{config.status} to guess the links to establish.
3006 One can then run:
3007 @example
3008 ./config.status host.h object.h
3009 @end example
3010 @noindent
3011 to create the links.
3012 @end defmac
3016 @node Subdirectories
3017 @section Configuring Other Packages in Subdirectories
3018 @section Configure subdirectories
3019 @section Subdirectory configure
3021 In most situations, calling @code{AC_OUTPUT} is sufficient to produce
3022 @file{Makefile}s in subdirectories.  However, @command{configure} scripts
3023 that control more than one independent package can use
3024 @code{AC_CONFIG_SUBDIRS} to run @command{configure} scripts for other
3025 packages in subdirectories.
3027 @defmac AC_CONFIG_SUBDIRS (@var{dir} @dots{})
3028 @acindex{CONFIG_SUBDIRS}
3029 @ovindex subdirs
3030 Make @code{AC_OUTPUT} run @command{configure} in each subdirectory
3031 @var{dir} in the given whitespace-separated list.  Each @var{dir} should
3032 be a literal, i.e., please do not use:
3034 @example
3035 if test "$package_foo_enabled" = yes; then
3036   $my_subdirs="$my_subdirs foo"
3038 AC_CONFIG_SUBDIRS($my_subdirs)
3039 @end example
3041 @noindent
3042 because this prevents @samp{./configure --help=recursive} from
3043 displaying the options of the package @code{foo}.  Rather, you should
3044 write:
3046 @example
3047 if test "$package_foo_enabled" = yes; then
3048   AC_CONFIG_SUBDIRS(foo)
3050 @end example
3052 If a given @var{dir} is not found, an error is reported: if the
3053 subdirectory is optional, write:
3055 @example
3056 if test -d $srcdir/foo; then
3057   AC_CONFIG_SUBDIRS(foo)
3059 @end example
3061 @c NB: Yes, below we mean configure.in, not configure.ac.
3062 If a given @var{dir} contains @command{configure.gnu}, it is run instead
3063 of @command{configure}.  This is for packages that might use a
3064 non-Autoconf script @command{Configure}, which can't be called through a
3065 wrapper @command{configure} since it would be the same file on
3066 case-insensitive filesystems.  Likewise, if a @var{dir} contains
3067 @file{configure.in} but no @command{configure}, the Cygnus
3068 @command{configure} script found by @code{AC_CONFIG_AUX_DIR} is used.
3070 The subdirectory @command{configure} scripts are given the same command
3071 line options that were given to this @command{configure} script, with minor
3072 changes if needed, which include:
3074 @itemize @minus
3075 @item
3076 adjusting a relative name for the cache file;
3078 @item
3079 adjusting a relative name for the source directory;
3081 @item
3082 propagating the current value of @code{$prefix}, including if it was
3083 defaulted, and if the default values of the top level and of the subdirectory
3084 @file{configure} differ.
3085 @end itemize
3087 This macro also sets the output variable @code{subdirs} to the list of
3088 directories @samp{@var{dir} @dots{}}.  @file{Makefile} rules can use
3089 this variable to determine which subdirectories to recurse into.
3091 This macro may be called multiple times.
3092 @end defmac
3094 @node Default Prefix
3095 @section Default Prefix
3096 @cindex Install prefix
3097 @cindex Prefix for install
3099 By default, @command{configure} sets the prefix for files it installs to
3100 @file{/usr/local}.  The user of @command{configure} can select a different
3101 prefix using the @option{--prefix} and @option{--exec-prefix} options.
3102 There are two ways to change the default: when creating
3103 @command{configure}, and when running it.
3105 Some software packages might want to install in a directory other than
3106 @file{/usr/local} by default.  To accomplish that, use the
3107 @code{AC_PREFIX_DEFAULT} macro.
3109 @defmac AC_PREFIX_DEFAULT (@var{prefix})
3110 @acindex{PREFIX_DEFAULT}
3111 Set the default installation prefix to @var{prefix} instead of
3112 @file{/usr/local}.
3113 @end defmac
3115 It may be convenient for users to have @command{configure} guess the
3116 installation prefix from the location of a related program that they
3117 have already installed.  If you wish to do that, you can call
3118 @code{AC_PREFIX_PROGRAM}.
3120 @defmac AC_PREFIX_PROGRAM (@var{program})
3121 @acindex{PREFIX_PROGRAM}
3122 If the user did not specify an installation prefix (using the
3123 @option{--prefix} option), guess a value for it by looking for
3124 @var{program} in @env{PATH}, the way the shell does.  If @var{program}
3125 is found, set the prefix to the parent of the directory containing
3126 @var{program}, else default the prefix as described above
3127 (@file{/usr/local} or @code{AC_PREFIX_DEFAULT}).  For example, if
3128 @var{program} is @code{gcc} and the @env{PATH} contains
3129 @file{/usr/local/gnu/bin/gcc}, set the prefix to @file{/usr/local/gnu}.
3130 @end defmac
3134 @c ======================================================== Existing tests
3136 @node Existing Tests
3137 @chapter Existing Tests
3139 These macros test for particular system features that packages might
3140 need or want to use.  If you need to test for a kind of feature that
3141 none of these macros check for, you can probably do it by calling
3142 primitive test macros with appropriate arguments (@pxref{Writing
3143 Tests}).
3145 These tests print messages telling the user which feature they're
3146 checking for, and what they find.  They cache their results for future
3147 @command{configure} runs (@pxref{Caching Results}).
3149 Some of these macros set output variables.  @xref{Makefile
3150 Substitutions}, for how to get their values.  The phrase ``define
3151 @var{name}'' is used below as a shorthand to mean ``define C
3152 preprocessor symbol @var{name} to the value 1''.  @xref{Defining
3153 Symbols}, for how to get those symbol definitions into your program.
3155 @menu
3156 * Common Behavior::             Macros' standard schemes
3157 * Alternative Programs::        Selecting between alternative programs
3158 * Files::                       Checking for the existence of files
3159 * Libraries::                   Library archives that might be missing
3160 * Library Functions::           C library functions that might be missing
3161 * Header Files::                Header files that might be missing
3162 * Declarations::                Declarations that may be missing
3163 * Structures::                  Structures or members that might be missing
3164 * Types::                       Types that might be missing
3165 * Compilers and Preprocessors::  Checking for compiling programs
3166 * System Services::             Operating system services
3167 * Posix Variants::              Special kludges for specific Posix variants
3168 @end menu
3170 @node Common Behavior
3171 @section Common Behavior
3172 @cindex Common autoconf behavior
3174 Much effort has been expended to make Autoconf easy to learn.  The most
3175 obvious way to reach this goal is simply to enforce standard interfaces
3176 and behaviors, avoiding exceptions as much as possible.  Because of
3177 history and inertia, unfortunately, there are still too many exceptions
3178 in Autoconf; nevertheless, this section describes some of the common
3179 rules.
3181 @menu
3182 * Standard Symbols::            Symbols defined by the macros
3183 * Default Includes::            Includes used by the generic macros
3184 @end menu
3186 @node Standard Symbols
3187 @subsection Standard Symbols
3188 @cindex Standard symbols
3190 All the generic macros that @code{AC_DEFINE} a symbol as a result of
3191 their test transform their @var{argument}s to a standard alphabet.
3192 First, @var{argument} is converted to upper case and any asterisks
3193 (@samp{*}) are each converted to @samp{P}.  Any remaining characters
3194 that are not alphanumeric are converted to underscores.
3196 For instance,
3198 @example
3199 AC_CHECK_TYPES(struct $Expensive*)
3200 @end example
3202 @noindent
3203 will define the symbol @samp{HAVE_STRUCT__EXPENSIVEP} if the check
3204 succeeds.
3207 @node Default Includes
3208 @subsection Default Includes
3209 @cindex Default includes
3210 @cindex Includes, default
3212 Several tests depend upon a set of header files.  Since these headers
3213 are not universally available, tests actually have to provide a set of
3214 protected includes, such as:
3216 @example
3217 @group
3218 #if TIME_WITH_SYS_TIME
3219 # include <sys/time.h>
3220 # include <time.h>
3221 #else
3222 # if HAVE_SYS_TIME_H
3223 #  include <sys/time.h>
3224 # else
3225 #  include <time.h>
3226 # endif
3227 #endif
3228 @end group
3229 @end example
3231 @noindent
3232 Unless you know exactly what you are doing, you should avoid using
3233 unconditional includes, and check the existence of the headers you
3234 include beforehand (@pxref{Header Files}).
3236 Most generic macros use the following macro to provide the default set
3237 of includes:
3239 @defmac AC_INCLUDES_DEFAULT (@ovar{include-directives})
3240 @acindex{INCLUDES_DEFAULT}
3241 Expand to @var{include-directives} if defined, otherwise to:
3243 @example
3244 @group
3245 #include <stdio.h>
3246 #if HAVE_SYS_TYPES_H
3247 # include <sys/types.h>
3248 #endif
3249 #if HAVE_SYS_STAT_H
3250 # include <sys/stat.h>
3251 #endif
3252 #if STDC_HEADERS
3253 # include <stdlib.h>
3254 # include <stddef.h>
3255 #else
3256 # if HAVE_STDLIB_H
3257 #  include <stdlib.h>
3258 # endif
3259 #endif
3260 #if HAVE_STRING_H
3261 # if !STDC_HEADERS && HAVE_MEMORY_H
3262 #  include <memory.h>
3263 # endif
3264 # include <string.h>
3265 #endif
3266 #if HAVE_STRINGS_H
3267 # include <strings.h>
3268 #endif
3269 #if HAVE_INTTYPES_H
3270 # include <inttypes.h>
3271 #endif
3272 #if HAVE_STDINT_H
3273 # include <stdint.h>
3274 #endif
3275 #if HAVE_UNISTD_H
3276 # include <unistd.h>
3277 #endif
3278 @end group
3279 @end example
3281 If the default includes are used, then check for the presence of these
3282 headers and their compatibility, i.e., you don't need to run
3283 @code{AC_HEADERS_STDC}, nor check for @file{stdlib.h} etc.
3285 These headers are checked for in the same order as they are included.
3286 For instance, on some systems @file{string.h} and @file{strings.h} both
3287 exist, but conflict.  Then @code{HAVE_STRING_H} will be defined, but
3288 @code{HAVE_STRINGS_H} won't.
3289 @end defmac
3291 @node Alternative Programs
3292 @section Alternative Programs
3293 @cindex Programs, checking
3295 These macros check for the presence or behavior of particular programs.
3296 They are used to choose between several alternative programs and to
3297 decide what to do once one has been chosen.  If there is no macro
3298 specifically defined to check for a program you need, and you don't need
3299 to check for any special properties of it, then you can use one of the
3300 general program-check macros.
3302 @menu
3303 * Particular Programs::         Special handling to find certain programs
3304 * Generic Programs::            How to find other programs
3305 @end menu
3307 @node Particular Programs
3308 @subsection Particular Program Checks
3310 These macros check for particular programs---whether they exist, and
3311 in some cases whether they support certain features.
3313 @defmac AC_PROG_AWK
3314 @acindex{PROG_AWK}
3315 @ovindex AWK
3316 Check for @code{gawk}, @code{mawk}, @code{nawk}, and @code{awk}, in that
3317 order, and set output variable @code{AWK} to the first one that is found.
3318 It tries @code{gawk} first because that is reported to be the
3319 best implementation.
3320 @end defmac
3322 @defmac AC_PROG_GREP
3323 @acindex{PROG_GREP}
3324 @ovindex GREP
3325 On AIX the default @code{grep} silently truncates long lines on the
3326 input before matching.  On Solaris 9 @code{/usr/bin/grep} does not
3327 understand the @option{-e} option.  On NeXT, @code{grep} understands only a
3328 single @option{-e} option.  This macro looks for @sc{gnu} Grep or
3329 else the best available @code{grep} or @code{ggrep} in the user's
3330 @env{PATH} which accepts the longest input lines possible, and which
3331 accepts and respects multiple @option{-e} options.  Set the
3332 output variable @code{GREP} to whatever is chosen.
3333 @end defmac
3335 @defmac AC_PROG_EGREP
3336 @acindex{PROG_EGREP}
3337 @ovindex EGREP
3338 Check whether @code{$GREP -E} works, or else search the user's
3339 @env{PATH} for @code{egrep}, and @code{gegrep}, in that order, and set
3340 output variable @code{EGREP} to the one that accepts the longest input
3341 lines.
3342 @end defmac
3344 @defmac AC_PROG_FGREP
3345 @acindex{PROG_FGREP}
3346 @ovindex FGREP
3347 Check whether @code{$GREP -F} works, or else search the user's
3348 @env{PATH} for @code{fgrep}, and @code{gfgrep}, in that order, and set
3349 output variable @code{FGREP} to the one that accepts the longest input
3350 lines.
3351 @end defmac
3353 @defmac AC_PROG_INSTALL
3354 @acindex{PROG_INSTALL}
3355 @ovindex INSTALL
3356 @ovindex INSTALL_PROGRAM
3357 @ovindex INSTALL_DATA
3358 @ovindex INSTALL_SCRIPT
3359 Set output variable @code{INSTALL} to the name of a @acronym{BSD}-compatible
3360 @code{install} program, if one is found in the current @env{PATH}.
3361 Otherwise, set @code{INSTALL} to @samp{@var{dir}/install-sh -c},
3362 checking the directories specified to @code{AC_CONFIG_AUX_DIR} (or its
3363 default directories) to determine @var{dir} (@pxref{Output}).  Also set
3364 the variables @code{INSTALL_PROGRAM} and @code{INSTALL_SCRIPT} to
3365 @samp{$@{INSTALL@}} and @code{INSTALL_DATA} to @samp{$@{INSTALL@} -m 644}.
3367 This macro screens out various instances of @code{install} known not to
3368 work.  It prefers to find a C program rather than a shell script, for
3369 speed.  Instead of @file{install-sh}, it can also use @file{install.sh},
3370 but that name is obsolete because some @command{make} programs have a rule
3371 that creates @file{install} from it if there is no @file{Makefile}.
3373 Autoconf comes with a copy of @file{install-sh} that you can use.  If
3374 you use @code{AC_PROG_INSTALL}, you must include either
3375 @file{install-sh} or @file{install.sh} in your distribution, or
3376 @command{configure} will produce an error message saying it can't find
3377 them---even if the system you're on has a good @code{install} program.
3378 This check is a safety measure to prevent you from accidentally leaving
3379 that file out, which would prevent your package from installing on
3380 systems that don't have a @acronym{BSD}-compatible @code{install} program.
3382 If you need to use your own installation program because it has features
3383 not found in standard @code{install} programs, there is no reason to use
3384 @code{AC_PROG_INSTALL}; just put the file name of your program into your
3385 @file{Makefile.in} files.
3386 @end defmac
3388 @defmac AC_PROG_LEX
3389 @acindex{PROG_LEX}
3390 @ovindex LEX
3391 @ovindex LEXLIB
3392 @cvindex YYTEXT_POINTER
3393 @ovindex LEX_OUTPUT_ROOT
3394 If @code{flex} is found, set output variable @code{LEX} to @samp{flex}
3395 and @code{LEXLIB} to @option{-lfl}, if that library is in a standard
3396 place.  Otherwise set @code{LEX} to @samp{lex} and @code{LEXLIB} to
3397 @option{-ll}.
3399 Define @code{YYTEXT_POINTER} if @code{yytext} is a @samp{char *} instead
3400 of a @samp{char []}.  Also set output variable @code{LEX_OUTPUT_ROOT} to
3401 the base of the file name that the lexer generates; usually
3402 @file{lex.yy}, but sometimes something else.  These results vary
3403 according to whether @code{lex} or @code{flex} is being used.
3405 You are encouraged to use Flex in your sources, since it is both more
3406 pleasant to use than plain Lex and the C source it produces is portable.
3407 In order to ensure portability, however, you must either provide a
3408 function @code{yywrap} or, if you don't use it (e.g., your scanner has
3409 no @samp{#include}-like feature), simply include a @samp{%noyywrap}
3410 statement in the scanner's source.  Once this done, the scanner is
3411 portable (unless @emph{you} felt free to use nonportable constructs) and
3412 does not depend on any library.  In this case, and in this case only, it
3413 is suggested that you use this Autoconf snippet:
3415 @example
3416 AC_PROG_LEX
3417 if test "$LEX" != flex; then
3418   LEX="$SHELL $missing_dir/missing flex"
3419   AC_SUBST(LEX_OUTPUT_ROOT, lex.yy)
3420   AC_SUBST(LEXLIB, '')
3422 @end example
3424 The shell script @command{missing} can be found in the Automake
3425 distribution.
3427 To ensure backward compatibility, Automake's @code{AM_PROG_LEX} invokes
3428 (indirectly) this macro twice, which will cause an annoying but benign
3429 ``@code{AC_PROG_LEX} invoked multiple times'' warning.  Future versions
3430 of Automake will fix this issue; meanwhile, just ignore this message.
3432 As part of running the test, this macro may delete any file in the
3433 configuration directory named @file{lex.yy.c} or @file{lexyy.c}.
3434 @end defmac
3436 @defmac AC_PROG_LN_S
3437 @acindex{PROG_LN_S}
3438 @ovindex LN_S
3439 If @samp{ln -s} works on the current file system (the operating system
3440 and file system support symbolic links), set the output variable
3441 @code{LN_S} to @samp{ln -s}; otherwise, if @samp{ln} works, set
3442 @code{LN_S} to @samp{ln}, and otherwise set it to @samp{cp -p}.
3444 If you make a link in a directory other than the current directory, its
3445 meaning depends on whether @samp{ln} or @samp{ln -s} is used.  To safely
3446 create links using @samp{$(LN_S)}, either find out which form is used
3447 and adjust the arguments, or always invoke @code{ln} in the directory
3448 where the link is to be created.
3450 In other words, it does not work to do:
3451 @example
3452 $(LN_S) foo /x/bar
3453 @end example
3455 Instead, do:
3457 @example
3458 (cd /x && $(LN_S) foo bar)
3459 @end example
3460 @end defmac
3462 @defmac AC_PROG_RANLIB
3463 @acindex{PROG_RANLIB}
3464 @ovindex RANLIB
3465 Set output variable @code{RANLIB} to @samp{ranlib} if @code{ranlib}
3466 is found, and otherwise to @samp{:} (do nothing).
3467 @end defmac
3469 @defmac AC_PROG_SED
3470 @acindex{PROG_SED}
3471 @ovindex SED
3472 Set output variable @code{SED} to a @code{sed} on @env{PATH} that
3473 truncates as few characters as possible.  If @sc{gnu} Sed is found,
3474 use that instead.
3475 @end defmac
3477 @defmac AC_PROG_YACC
3478 @acindex{PROG_YACC}
3479 @ovindex YACC
3480 If @code{bison} is found, set output variable @code{YACC} to @samp{bison
3481 -y}.  Otherwise, if @code{byacc} is found, set @code{YACC} to
3482 @samp{byacc}.  Otherwise set @code{YACC} to @samp{yacc}.
3483 @end defmac
3485 @node Generic Programs
3486 @subsection Generic Program and File Checks
3488 These macros are used to find programs not covered by the ``particular''
3489 test macros.  If you need to check the behavior of a program as well as
3490 find out whether it is present, you have to write your own test for it
3491 (@pxref{Writing Tests}).  By default, these macros use the environment
3492 variable @env{PATH}.  If you need to check for a program that might not
3493 be in the user's @env{PATH}, you can pass a modified path to use
3494 instead, like this:
3496 @example
3497 AC_PATH_PROG([INETD], [inetd], [/usr/libexec/inetd],
3498              [$PATH:/usr/libexec:/usr/sbin:/usr/etc:/etc])
3499 @end example
3501 You are strongly encouraged to declare the @var{variable} passed to
3502 @code{AC_CHECK_PROG} etc.@: as precious, @xref{Setting Output Variables},
3503 @code{AC_ARG_VAR}, for more details.
3505 @defmac AC_CHECK_PROG (@var{variable}, @var{prog-to-check-for}, @var{value-if-found}, @ovar{value-if-not-found}, @ovar{path},  @ovar{reject})
3506 @acindex{CHECK_PROG}
3507 Check whether program @var{prog-to-check-for} exists in @env{PATH}.  If
3508 it is found, set @var{variable} to @var{value-if-found}, otherwise to
3509 @var{value-if-not-found}, if given.  Always pass over @var{reject} (an
3510 absolute file name) even if it is the first found in the search path; in
3511 that case, set @var{variable} using the absolute file name of the
3512 @var{prog-to-check-for} found that is not @var{reject}.  If
3513 @var{variable} was already set, do nothing.  Calls @code{AC_SUBST} for
3514 @var{variable}.
3515 @end defmac
3517 @defmac AC_CHECK_PROGS (@var{variable}, @var{progs-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3518 @acindex{CHECK_PROGS}
3519 Check for each program in the whitespace-separated list
3520 @var{progs-to-check-for} existing in the @env{PATH}.  If one is found, set
3521 @var{variable} to the name of that program.  Otherwise, continue
3522 checking the next program in the list.  If none of the programs in the
3523 list are found, set @var{variable} to @var{value-if-not-found}; if
3524 @var{value-if-not-found} is not specified, the value of @var{variable}
3525 is not changed.  Calls @code{AC_SUBST} for @var{variable}.
3526 @end defmac
3528 @defmac AC_CHECK_TARGET_TOOL (@var{variable}, @var{prog-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3529 @acindex{CHECK_TARGET_TOOL}
3530 Like @code{AC_CHECK_PROG}, but first looks for @var{prog-to-check-for}
3531 with a prefix of the target type as determined by
3532 @code{AC_CANONICAL_TARGET}, followed by a dash (@pxref{Canonicalizing}).
3533 If the tool cannot be found with a prefix, and if the build and target
3534 types are equal, then it is also searched for without a prefix.
3536 As noted in @ref{Specifying Names, , Specifying the system type}, the
3537 target is rarely specified, because most of the time it is the same
3538 as the host: it is the type of system for which any compiler tools in
3539 the package will produce code.  What this macro will look for is,
3540 for example, @emph{a tool @r{(assembler, linker, etc.)}@: that the
3541 compiler driver @r{(@command{gcc} for the @acronym{GNU} C Compiler)}
3542 will use to produce objects, archives or executables}.
3543 @end defmac
3545 @defmac AC_CHECK_TOOL (@var{variable}, @var{prog-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3546 @acindex{CHECK_TOOL}
3547 Like @code{AC_CHECK_PROG}, but first looks for @var{prog-to-check-for}
3548 with a prefix of the host type as determined by
3549 @code{AC_CANONICAL_HOST}, followed by a dash (@pxref{Canonicalizing}).
3550 For example, if the user runs @samp{configure --host=i386-gnu}, then
3551 this call:
3552 @example
3553 AC_CHECK_TOOL(RANLIB, ranlib, :)
3554 @end example
3555 @noindent
3556 sets @code{RANLIB} to @file{i386-gnu-ranlib} if that program exists in
3557 @env{PATH}, or otherwise to @samp{ranlib} if that program exists in
3558 @env{PATH}, or to @samp{:} if neither program exists.
3560 In the future, when cross-compiling this macro will @emph{only}
3561 accept program names that are prefixed with the host type.
3562 For more information, see @ref{Specifying Names, , Specifying the
3563 system type}.
3564 @end defmac
3566 @defmac AC_CHECK_TARGET_TOOLS (@var{variable}, @var{progs-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3567 @acindex{CHECK_TARGET_TOOLS}
3568 Like @code{AC_CHECK_TARGET_TOOL}, each of the tools in the list
3569 @var{progs-to-check-for} are checked with a prefix of the target type as
3570 determined by @code{AC_CANONICAL_TARGET}, followed by a dash
3571 (@pxref{Canonicalizing}).  If none of the tools can be found with a
3572 prefix, and if the build and target types are equal, then the first one
3573 without a prefix is used.  If a tool is found, set @var{variable} to
3574 the name of that program.  If none of the tools in the list are found,
3575 set @var{variable} to @var{value-if-not-found}; if @var{value-if-not-found}
3576 is not specified, the value of @var{variable} is not changed.  Calls
3577 @code{AC_SUBST} for @var{variable}.
3578 @end defmac
3580 @defmac AC_CHECK_TOOLS (@var{variable}, @var{progs-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3581 @acindex{CHECK_TOOLS}
3582 Like @code{AC_CHECK_TOOL}, each of the tools in the list
3583 @var{progs-to-check-for} are checked with a prefix of the host type as
3584 determined by @code{AC_CANONICAL_HOST}, followed by a dash
3585 (@pxref{Canonicalizing}).  If none of the tools can be found with a
3586 prefix, then the first one without a prefix is used.  If a tool is found,
3587 set @var{variable} to the name of that program.  If none of the tools in
3588 the list are found, set @var{variable} to @var{value-if-not-found}; if
3589 @var{value-if-not-found} is not specified, the value of @var{variable}
3590 is not changed.  Calls @code{AC_SUBST} for @var{variable}.
3592 In the future, when cross-compiling this macro will @emph{not}
3593 accept program names that are not prefixed with the host type.
3594 @end defmac
3596 @defmac AC_PATH_PROG (@var{variable}, @var{prog-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3597 @acindex{PATH_PROG}
3598 Like @code{AC_CHECK_PROG}, but set @var{variable} to the absolute
3599 name of @var{prog-to-check-for} if found.
3600 @end defmac
3602 @defmac AC_PATH_PROGS (@var{variable}, @var{progs-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3603 @acindex{PATH_PROGS}
3604 Like @code{AC_CHECK_PROGS}, but if any of @var{progs-to-check-for}
3605 are found, set @var{variable} to the absolute name of the program
3606 found.
3607 @end defmac
3609 @defmac AC_PATH_TARGET_TOOL (@var{variable}, @var{prog-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3610 @acindex{PATH_TARGET_TOOL}
3611 Like @code{AC_CHECK_TARGET_TOOL}, but set @var{variable} to the absolute
3612 name of the program if it is found.
3613 @end defmac
3615 @defmac AC_PATH_TOOL (@var{variable}, @var{prog-to-check-for}, @ovar{value-if-not-found}, @ovar{path})
3616 @acindex{PATH_TOOL}
3617 Like @code{AC_CHECK_TOOL}, but set @var{variable} to the absolute
3618 name of the program if it is found.
3620 In the future, when cross-compiling this macro will @emph{not}
3621 accept program names that are not prefixed with the host type.
3622 @end defmac
3625 @node Files
3626 @section Files
3627 @cindex File, checking
3629 You might also need to check for the existence of files.  Before using
3630 these macros, ask yourself whether a run-time test might not be a better
3631 solution.  Be aware that, like most Autoconf macros, they test a feature
3632 of the host machine, and therefore, they die when cross-compiling.
3634 @defmac AC_CHECK_FILE (@var{file}, @ovar{action-if-found}, @ovar{action-if-not-found})
3635 @acindex{CHECK_FILE}
3636 Check whether file @var{file} exists on the native system.  If it is
3637 found, execute @var{action-if-found}, otherwise do
3638 @var{action-if-not-found}, if given.
3639 @end defmac
3641 @defmac AC_CHECK_FILES (@var{files}, @ovar{action-if-found}, @ovar{action-if-not-found})
3642 @acindex{CHECK_FILES}
3643 Executes @code{AC_CHECK_FILE} once for each file listed in @var{files}.
3644 Additionally, defines @samp{HAVE_@var{file}} (@pxref{Standard Symbols})
3645 for each file found.
3646 @end defmac
3649 @node Libraries
3650 @section Library Files
3651 @cindex Library, checking
3653 The following macros check for the presence of certain C, C++, or Fortran
3654 library archive files.
3656 @defmac AC_CHECK_LIB (@var{library}, @var{function}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{other-libraries})
3657 @acindex{CHECK_LIB}
3658 Test whether the library @var{library} is available by trying to link
3659 a test program that calls function @var{function} with the library.
3660 @var{function} should be a function provided by the library.
3661 Use the base
3662 name of the library; e.g., to check for @option{-lmp}, use @samp{mp} as
3663 the @var{library} argument.
3665 @var{action-if-found} is a list of shell commands to run if the link
3666 with the library succeeds; @var{action-if-not-found} is a list of shell
3667 commands to run if the link fails.  If @var{action-if-found} is not
3668 specified, the default action will prepend @option{-l@var{library}} to
3669 @code{LIBS} and define @samp{HAVE_LIB@var{library}} (in all
3670 capitals).  This macro is intended to support building @code{LIBS} in
3671 a right-to-left (least-dependent to most-dependent) fashion such that
3672 library dependencies are satisfied as a natural side-effect of
3673 consecutive tests.  Some linkers are very sensitive to library ordering
3674 so the order in which @code{LIBS} is generated is important to reliable
3675 detection of libraries.
3677 If linking with @var{library} results in unresolved symbols that would
3678 be resolved by linking with additional libraries, give those libraries
3679 as the @var{other-libraries} argument, separated by spaces:
3680 e.g., @option{-lXt -lX11}.  Otherwise, this macro will fail to detect
3681 that @var{library} is present, because linking the test program will
3682 always fail with unresolved symbols.  The @var{other-libraries} argument
3683 should be limited to cases where it is desirable to test for one library
3684 in the presence of another that is not already in @code{LIBS}.
3686 @code{AC_CHECK_LIB} requires some care in usage, and should be avoided
3687 in some common cases.  Many standard functions like @code{gethostbyname}
3688 appear the standard C library on some hosts, and in special libraries
3689 like @code{nsl} on other hosts.  On some hosts the special libraries
3690 contain variant implementations that you may not want to use.  These
3691 days it is normally better to use @code{AC_SEARCH_LIBS(gethostbyname,
3692 nsl)} instead of @code{AC_CHECK_LIB(nsl, gethostbyname)}.
3693 @end defmac
3696 @defmac AC_SEARCH_LIBS (@var{function}, @var{search-libs}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{other-libraries})
3697 @acindex{SEARCH_LIBS}
3698 Search for a library defining @var{function} if it's not already
3699 available.  This equates to calling
3700 @samp{AC_LINK_IFELSE([AC_LANG_CALL([], [@var{function}])])} first with
3701 no libraries, then for each library listed in @var{search-libs}.
3703 Add @option{-l@var{library}} to @code{LIBS} for the first library found
3704 to contain @var{function}, and run @var{action-if-found}.  If the
3705 function is not found, run @var{action-if-not-found}.
3707 If linking with @var{library} results in unresolved symbols that would
3708 be resolved by linking with additional libraries, give those libraries
3709 as the @var{other-libraries} argument, separated by spaces:
3710 e.g., @option{-lXt -lX11}.  Otherwise, this macro will fail to detect
3711 that @var{function} is present, because linking the test program will
3712 always fail with unresolved symbols.
3713 @end defmac
3717 @node Library Functions
3718 @section Library Functions
3720 The following macros check for particular C library functions.
3721 If there is no macro specifically defined to check for a function you need,
3722 and you don't need to check for any special properties of
3723 it, then you can use one of the general function-check macros.
3725 @menu
3726 * Function Portability::        Pitfalls with usual functions
3727 * Particular Functions::        Special handling to find certain functions
3728 * Generic Functions::           How to find other functions
3729 @end menu
3731 @node Function Portability
3732 @subsection Portability of C Functions
3733 @cindex Portability of C functions
3734 @cindex C function portability
3736 Most usual functions can either be missing, or be buggy, or be limited
3737 on some architectures.  This section tries to make an inventory of these
3738 portability issues.  By definition, this list will always require
3739 additions.  Please help us keeping it as complete as possible.
3741 @table @asis
3742 @item @code{exit}
3743 @c @fuindex exit
3744 @prindex @code{exit}
3745 Did you know that, on some older hosts, @code{exit} returns @code{int}?
3746 This is because @code{exit} predates @code{void}, and there was a long
3747 tradition of it returning @code{int}.
3749 @item @code{free}
3750 @c @fuindex free
3751 @prindex @code{free}
3752 The ISO C99 standard says a call @code{free(NULL)} does nothing, but
3753 some old systems don't support this (e.g., NextStep).
3755 @item @code{isinf}
3756 @itemx @code{isnan}
3757 @c @fuindex isinf
3758 @c @fuindex isnan
3759 @prindex @code{isinf}
3760 @prindex @code{isnan}
3761 The ISO C99 standard specifies that @code{isinf} and @code{isnan} are
3762 macros.  On some systems just macros are available (e.g., HP-UX), on
3763 some systems both macros and functions (e.g., glibc 2.3.2), and on some
3764 systems only functions (e.g., IRIX 6 and Solaris 9).  In some cases
3765 these functions are declared in nonstandard headers like
3766 @code{<sunmath.h>} and defined in non-default libraries like
3767 @option{-lm} or @option{-lsunmath}.
3769 The C99 @code{isinf} and @code{isnan} macros work correctly with
3770 @code{long double} arguments, but pre-C99 systems that use functions
3771 typically assume @code{double} arguments.  On such a system,
3772 @code{isinf} incorrectly returns true for a finite @code{long double}
3773 argument that is outside the range of @code{double}.
3775 To work around this porting mess, you can use code like the following.
3777 @example
3778 #include <math.h>
3780 #ifndef isnan
3781 # define isnan(x) \
3782     (sizeof (x) == sizeof (long double) ? isnan_ld (x) \
3783      : sizeof (x) == sizeof (double) ? isnan_d (x) \
3784      : isnan_f (x))
3785 static inline int isnan_f  (float       x) @{ return x != x; @}
3786 static inline int isnan_d  (double      x) @{ return x != x; @}
3787 static inline int isnan_ld (long double x) @{ return x != x; @}
3788 #endif
3790 #ifndef isinf
3791 # define isinf(x) \
3792     (sizeof (x) == sizeof (long double) ? isinf_ld (x) \
3793      : sizeof (x) == sizeof (double) ? isinf_d (x) \
3794      : isinf_f (x))
3795 static inline int isinf_f  (float       x) @{ return isnan (x - x); @}
3796 static inline int isinf_d  (double      x) @{ return isnan (x - x); @}
3797 static inline int isinf_ld (long double x) @{ return isnan (x - x); @}
3798 #endif
3799 @end example
3801 Use @code{AC_C_INLINE} (@pxref{C Compiler}) so that this code works on
3802 compilers that lack the @code{inline} keyword.  Some optimizing
3803 compilers mishandle these definitions, but systems with that bug
3804 typically have missing or broken @code{isnan} functions anyway, so it's
3805 probably not worth worrying about.
3807 @item @code{malloc}
3808 @c @fuindex malloc
3809 @prindex @code{malloc}
3810 The ISO C99 standard says a call @code{malloc(0)} is implementation
3811 dependent, it may either return @code{NULL} (e.g., OSF 4) or
3812 non-@code{NULL} (e.g., @acronym{GNU} C Library).  @code{AC_FUNC_MALLOC}
3813 can be used to insist on non-@code{NULL} (@pxref{Particular Functions}).
3815 @item @code{putenv}
3816 @c @fuindex putenv
3817 @prindex @code{putenv}
3818 Posix prefers @code{setenv} to @code{putenv}; among other things,
3819 @code{putenv} is not required of all Posix implementations, but
3820 @code{setenv} is.
3822 Posix specifies that @code{putenv} puts the given string directly in
3823 @code{environ}, but some systems make a copy of it instead (e.g.,
3824 glibc 2.0, or BSD).  And when a copy is made, @code{unsetenv} might
3825 not free it, causing a memory leak (e.g., FreeBSD 4).
3827 On some systems @code{putenv("FOO")} removes @samp{FOO} from the
3828 environment, but this is not standard usage and it dumps core
3829 on some systems (e.g., AIX).
3831 On MINGW, a call @code{putenv("FOO=")} removes @samp{FOO} from the
3832 environment, rather than inserting it with an empty value.
3834 @item @code{realloc}
3835 @c @fuindex realloc
3836 @prindex @code{realloc}
3837 The ISO C99 standard says a call @code{realloc(NULL,size)} is equivalent
3838 to a @code{malloc(size)}, but some old systems don't support this (e.g.,
3839 NextStep).
3841 @item @code{signal} handler
3842 @c @fuindex signal
3843 @prindex @code{signal}
3844 Normally @code{signal} takes a handler function with a return type of
3845 @code{void}, but some old systems required @code{int} instead.  Any
3846 actual @code{int} value returned is not used, this is only a
3847 difference in the function prototype demanded.
3849 All systems we know of in current use take @code{void}.  Presumably
3850 @code{int} was to support K&R C, where of course @code{void} is not
3851 available.  @code{AC_TYPE_SIGNAL} (@pxref{Particular Types}) can be
3852 used to establish the correct type in all cases.
3854 @item @code{snprintf}
3855 @c @fuindex snprintf
3856 @prindex @code{snprintf}
3857 @c @fuindex vsnprintf
3858 @prindex @code{vsnprintf}
3859 The ISO C99 standard says that if the output array isn't big enough
3860 and if no other errors occur, @code{snprintf} and @code{vsnprintf}
3861 truncate the output and return the number of bytes that ought to have
3862 been produced.  Some older systems return the truncated length (e.g.,
3863 @acronym{GNU} C Library 2.0.x or @sc{irix} 6.5), some a negative value
3864 (e.g., earlier @acronym{GNU} C Library versions), and some the buffer
3865 length without truncation (e.g., 32-bit Solaris 7).  Also, some buggy
3866 older systems ignore the length and overrun the buffer (e.g., 64-bit
3867 Solaris 7).
3869 @item @code{sprintf}
3870 @c @fuindex sprintf
3871 @prindex @code{sprintf}
3872 @c @fuindex vsprintf
3873 @prindex @code{vsprintf}
3874 The ISO C standard says @code{sprintf} and @code{vsprintf} return the
3875 number of bytes written, but on some old systems (SunOS 4 for
3876 instance) they return the buffer pointer instead.
3878 @item @code{sscanf}
3879 @c @fuindex sscanf
3880 @prindex @code{sscanf}
3881 On various old systems, e.g., HP-UX 9, @code{sscanf} requires that its
3882 input string be writable (though it doesn't actually change it).  This
3883 can be a problem when using @command{gcc} since it normally puts
3884 constant strings in read-only memory
3885 (@pxref{Incompatibilities,Incompatibilities of GCC,,gcc,Using and
3886 Porting the @acronym{GNU} Compiler Collection}).  Apparently in some cases even
3887 having format strings read-only can be a problem.
3889 @item @code{strerror_r}
3890 @c @fuindex strerror_r
3891 @prindex @code{strerror_r}
3892 Posix specifies that @code{strerror_r} returns an @code{int}, but many
3893 systems (e.g., @acronym{GNU} C Library version 2.2.4) provide a
3894 different version returning a @code{char *}.  @code{AC_FUNC_STRERROR_R}
3895 can detect which is in use (@pxref{Particular Functions}).
3897 @item @code{strnlen}
3898 @c @fuindex strnlen
3899 @prindex @code{strnlen}
3900 @acronym{AIX} 4.3 provides a broken version which produces the
3901 following results:
3903 @example
3904 strnlen ("foobar", 0) = 0
3905 strnlen ("foobar", 1) = 3
3906 strnlen ("foobar", 2) = 2
3907 strnlen ("foobar", 3) = 1
3908 strnlen ("foobar", 4) = 0
3909 strnlen ("foobar", 5) = 6
3910 strnlen ("foobar", 6) = 6
3911 strnlen ("foobar", 7) = 6
3912 strnlen ("foobar", 8) = 6
3913 strnlen ("foobar", 9) = 6
3914 @end example
3916 @item @code{sysconf}
3917 @c @fuindex sysconf
3918 @prindex @code{sysconf}
3919 @code{_SC_PAGESIZE} is standard, but some older systems (e.g., HP-UX
3920 9) have @code{_SC_PAGE_SIZE} instead.  This can be tested with
3921 @code{#ifdef}.
3923 @item @code{unlink}
3924 @c @fuindex unlink
3925 @prindex @code{unlink}
3926 The Posix spec says that @code{unlink} causes the given file to be
3927 removed only after there are no more open file handles for it.  Some
3928 non-Posix hosts have trouble with this requirement, though,
3929 and some @acronym{DOS} variants even corrupt the file system.
3931 @item @code{unsetenv}
3932 @c @fuindex unsetenv
3933 @prindex @code{unsetenv}
3934 On MINGW, @code{unsetenv} is not available, but a variable @samp{FOO}
3935 can be removed with a call @code{putenv("FOO=")}, as described under
3936 @code{putenv} above.
3938 @item @code{va_copy}
3939 @c @fuindex va_copy
3940 @prindex @code{va_copy}
3941 The ISO C99 standard provides @code{va_copy} for copying
3942 @code{va_list} variables.  It may be available in older environments
3943 too, though possibly as @code{__va_copy} (e.g., @command{gcc} in strict
3944 C89 mode).  These can be tested with @code{#ifdef}.  A fallback to
3945 @code{memcpy (&dst, &src, sizeof(va_list))} will give maximum
3946 portability.
3948 @item @code{va_list}
3949 @c @fuindex va_list
3950 @prindex @code{va_list}
3951 @code{va_list} is not necessarily just a pointer.  It can be a
3952 @code{struct} (e.g., @command{gcc} on Alpha), which means @code{NULL} is
3953 not portable.  Or it can be an array (e.g., @command{gcc} in some
3954 PowerPC configurations), which means as a function parameter it can be
3955 effectively call-by-reference and library routines might modify the
3956 value back in the caller (e.g., @code{vsnprintf} in the @acronym{GNU} C Library
3957 2.1).
3959 @item Signed @code{>>}
3960 Normally the C @code{>>} right shift of a signed type replicates the
3961 high bit, giving a so-called ``arithmetic'' shift.  But care should be
3962 taken since the ISO C standard doesn't require that behavior.  On those
3963 few processors without a native arithmetic shift (for instance Cray
3964 vector systems) zero bits may be shifted in, the same as a shift of an
3965 unsigned type.
3966 @end table
3969 @node Particular Functions
3970 @subsection Particular Function Checks
3971 @cindex Function, checking
3973 These macros check for particular C functions---whether they exist, and
3974 in some cases how they respond when given certain arguments.
3976 @defmac AC_FUNC_ALLOCA
3977 @acindex{FUNC_ALLOCA}
3978 @cvindex C_ALLOCA
3979 @cvindex HAVE_ALLOCA_H
3980 @ovindex ALLOCA
3981 @c @fuindex alloca
3982 @prindex @code{alloca}
3983 @hdrindex{alloca.h}
3984 Check how to get @code{alloca}.  Tries to get a builtin version by
3985 checking for @file{alloca.h} or the predefined C preprocessor macros
3986 @code{__GNUC__} and @code{_AIX}.  If this macro finds @file{alloca.h},
3987 it defines @code{HAVE_ALLOCA_H}.
3989 If those attempts fail, it looks for the function in the standard C
3990 library.  If any of those methods succeed, it defines
3991 @code{HAVE_ALLOCA}.  Otherwise, it sets the output variable
3992 @code{ALLOCA} to @samp{alloca.o} and defines @code{C_ALLOCA} (so
3993 programs can periodically call @samp{alloca(0)} to garbage collect).
3994 This variable is separate from @code{LIBOBJS} so multiple programs can
3995 share the value of @code{ALLOCA} without needing to create an actual
3996 library, in case only some of them use the code in @code{LIBOBJS}.
3998 This macro does not try to get @code{alloca} from the System V R3
3999 @file{libPW} or the System V R4 @file{libucb} because those libraries
4000 contain some incompatible functions that cause trouble.  Some versions
4001 do not even contain @code{alloca} or contain a buggy version.  If you
4002 still want to use their @code{alloca}, use @code{ar} to extract
4003 @file{alloca.o} from them instead of compiling @file{alloca.c}.
4005 Source files that use @code{alloca} should start with a piece of code
4006 like the following, to declare it properly.
4008 @example
4009 @group
4010 #if HAVE_ALLOCA_H
4011 # include <alloca.h>
4012 #elif defined __GNUC__
4013 # define alloca __builtin_alloca
4014 #elif defined _AIX
4015 # define alloca __alloca
4016 #elif defined _MSC_VER
4017 # include <malloc.h>
4018 # define alloca _alloca
4019 #else
4020 # include <stddef.h>
4021 # ifdef  __cplusplus
4022 extern "C"
4023 # endif
4024 void *alloca (size_t);
4025 #endif
4026 @end group
4027 @end example
4028 @end defmac
4030 @defmac AC_FUNC_CHOWN
4031 @acindex{FUNC_CHOWN}
4032 @c @fuindex chown
4033 @prindex @code{chown}
4034 If the @code{chown} function is available and works (in particular, it
4035 should accept @option{-1} for @code{uid} and @code{gid}), define
4036 @code{HAVE_CHOWN}.
4037 @end defmac
4040 @defmac AC_FUNC_CLOSEDIR_VOID
4041 @acindex{FUNC_CLOSEDIR_VOID}
4042 @cvindex CLOSEDIR_VOID
4043 @c @fuindex closedir
4044 @prindex @code{closedir}
4045 If the @code{closedir} function does not return a meaningful value,
4046 define @code{CLOSEDIR_VOID}.  Otherwise, callers ought to check its
4047 return value for an error indicator.
4049 Currently this test is implemented by running a test program.  When
4050 cross compiling the pessimistic assumption that @code{closedir} does not
4051 return a meaningful value is made.
4052 @end defmac
4054 @defmac AC_FUNC_ERROR_AT_LINE
4055 @acindex{FUNC_ERROR_AT_LINE}
4056 @c @fuindex error_at_line
4057 @prindex @code{error_at_line}
4058 If the @code{error_at_line} function is not found, require an
4059 @code{AC_LIBOBJ} replacement of @samp{error}.
4060 @end defmac
4062 @defmac AC_FUNC_FNMATCH
4063 @acindex{FUNC_FNMATCH}
4064 @c @fuindex fnmatch
4065 @prindex @code{fnmatch}
4066 If the @code{fnmatch} function conforms to Posix, define
4067 @code{HAVE_FNMATCH}.  Detect common implementation bugs, for example,
4068 the bugs in Solaris 2.4.
4070 Note that for historical reasons, contrary to the other specific
4071 @code{AC_FUNC} macros, @code{AC_FUNC_FNMATCH} does not replace a
4072 broken/missing @code{fnmatch}.  See @code{AC_REPLACE_FNMATCH} below.
4073 @end defmac
4075 @defmac AC_FUNC_FNMATCH_GNU
4076 @acindex{FUNC_FNMATCH_GNU}
4077 @c @fuindex fnmatch
4078 @prindex @code{fnmatch}
4079 Behave like @code{AC_REPLACE_FNMATCH} (@emph{replace}) but also test
4080 whether @code{fnmatch} supports @acronym{GNU} extensions.  Detect common
4081 implementation bugs, for example, the bugs in the @acronym{GNU} C
4082 Library 2.1.
4083 @end defmac
4085 @defmac AC_FUNC_FORK
4086 @acindex{FUNC_FORK}
4087 @cvindex HAVE_VFORK_H
4088 @cvindex HAVE_WORKING_FORK
4089 @cvindex HAVE_WORKING_VFORK
4090 @cvindex vfork
4091 @c @fuindex fork
4092 @prindex @code{fork}
4093 @c @fuindex vfork
4094 @prindex @code{vfork}
4095 @hdrindex{vfork.h}
4096 This macro checks for the @code{fork} and @code{vfork} functions.  If a
4097 working @code{fork} is found, define @code{HAVE_WORKING_FORK}.  This macro
4098 checks whether @code{fork} is just a stub by trying to run it.
4100 If @file{vfork.h} is found, define @code{HAVE_VFORK_H}.  If a working
4101 @code{vfork} is found, define @code{HAVE_WORKING_VFORK}.  Otherwise,
4102 define @code{vfork} to be @code{fork} for backward compatibility with
4103 previous versions of @command{autoconf}.  This macro checks for several known
4104 errors in implementations of @code{vfork} and considers the system to not
4105 have a working @code{vfork} if it detects any of them.  It is not considered
4106 to be an implementation error if a child's invocation of @code{signal}
4107 modifies the parent's signal handler, since child processes rarely change
4108 their signal handlers.
4110 Since this macro defines @code{vfork} only for backward compatibility with
4111 previous versions of @command{autoconf} you're encouraged to define it
4112 yourself in new code:
4113 @example
4114 @group
4115 #if !HAVE_WORKING_VFORK
4116 # define vfork fork
4117 #endif
4118 @end group
4119 @end example
4120 @end defmac
4122 @defmac AC_FUNC_FSEEKO
4123 @acindex{FUNC_FSEEKO}
4124 @cvindex _LARGEFILE_SOURCE
4125 @c @fuindex fseeko
4126 @prindex @code{fseeko}
4127 If the @code{fseeko} function is available, define @code{HAVE_FSEEKO}.
4128 Define @code{_LARGEFILE_SOURCE} if necessary to make the prototype
4129 visible on some systems (e.g., glibc 2.2).  Otherwise linkage problems
4130 may occur when compiling with @code{AC_SYS_LARGEFILE} on
4131 largefile-sensitive systems where @code{off_t} does not default to a
4132 64bit entity.
4133 @end defmac
4135 @defmac AC_FUNC_GETGROUPS
4136 @acindex{FUNC_GETGROUPS}
4137 @ovindex GETGROUPS_LIBS
4138 @c @fuindex getgroups
4139 @prindex @code{getgroups}
4140 If the @code{getgroups} function is available and works (unlike on
4141 Ultrix 4.3, where @samp{getgroups (0, 0)} always fails), define
4142 @code{HAVE_GETGROUPS}.  Set @code{GETGROUPS_LIBS} to any libraries
4143 needed to get that function.  This macro runs @code{AC_TYPE_GETGROUPS}.
4144 @end defmac
4146 @defmac AC_FUNC_GETLOADAVG
4147 @acindex{FUNC_GETLOADAVG}
4148 @cvindex SVR4
4149 @cvindex DGUX
4150 @cvindex UMAX
4151 @cvindex UMAX4_3
4152 @cvindex HAVE_NLIST_H
4153 @cvindex NLIST_NAME_UNION
4154 @cvindex GETLODAVG_PRIVILEGED
4155 @cvindex NEED_SETGID
4156 @cvindex C_GETLOADAVG
4157 @ovindex LIBOBJS
4158 @ovindex NEED_SETGID
4159 @ovindex KMEM_GROUP
4160 @ovindex GETLOADAVG_LIBS
4161 @c @fuindex getloadavg
4162 @prindex @code{getloadavg}
4163 Check how to get the system load averages.  To perform its tests
4164 properly, this macro needs the file @file{getloadavg.c}; therefore, be
4165 sure to set the @code{AC_LIBOBJ} replacement directory properly (see
4166 @ref{Generic Functions}, @code{AC_CONFIG_LIBOBJ_DIR}).
4168 If the system has the @code{getloadavg} function, define
4169 @code{HAVE_GETLOADAVG}, and set @code{GETLOADAVG_LIBS} to any libraries
4170 needed to get that function.  Also add @code{GETLOADAVG_LIBS} to
4171 @code{LIBS}.  Otherwise, require an @code{AC_LIBOBJ} replacement for
4172 @samp{getloadavg} with source code in @file{@var{dir}/getloadavg.c}, and
4173 possibly define several other C preprocessor macros and output
4174 variables:
4176 @enumerate
4177 @item
4178 Define @code{C_GETLOADAVG}.
4180 @item
4181 Define @code{SVR4}, @code{DGUX}, @code{UMAX}, or @code{UMAX4_3} if on
4182 those systems.
4184 @item
4185 @hdrindex{nlist.h}
4186 If @file{nlist.h} is found, define @code{HAVE_NLIST_H}.
4188 @item
4189 If @samp{struct nlist} has an @samp{n_un.n_name} member, define
4190 @code{HAVE_STRUCT_NLIST_N_UN_N_NAME}.  The obsolete symbol
4191 @code{NLIST_NAME_UNION} is still defined, but do not depend upon it.
4193 @item
4194 Programs may need to be installed setgid (or setuid) for
4195 @code{getloadavg} to work.  In this case, define
4196 @code{GETLOADAVG_PRIVILEGED}, set the output variable @code{NEED_SETGID}
4197 to @samp{true} (and otherwise to @samp{false}), and set
4198 @code{KMEM_GROUP} to the name of the group that should own the installed
4199 program.
4200 @end enumerate
4201 @end defmac
4203 @defmac AC_FUNC_GETMNTENT
4204 @acindex{FUNC_GETMNTENT}
4205 @cvindex HAVE_GETMNTENT
4206 @c @fuindex getmntent
4207 @prindex @code{getmntent}
4208 Check for @code{getmntent} in the standard C library, and then in the
4209 @file{sun}, @file{seq}, and @file{gen} libraries, for @sc{unicos},
4210 @sc{irix} 4, @sc{ptx}, and UnixWare, respectively.  Then, if
4211 @code{getmntent} is available, define @code{HAVE_GETMNTENT}.
4212 @end defmac
4214 @defmac AC_FUNC_GETPGRP
4215 @acindex{FUNC_GETPGRP}
4216 @cvindex GETPGRP_VOID
4217 @c @fuindex getpgid
4218 @c @fuindex getpgrp
4219 @prindex @code{getpgid}
4220 @prindex @code{getpgrp}
4221 Define @code{GETPGRP_VOID} if it is an error to pass 0 to
4222 @code{getpgrp}; this is the Posix behavior.  On older BSD
4223 systems, you must pass 0 to @code{getpgrp}, as it takes an argument and
4224 behaves like Posix's @code{getpgid}.
4226 @example
4227 #if GETPGRP_VOID
4228   pid = getpgrp ();
4229 #else
4230   pid = getpgrp (0);
4231 #endif
4232 @end example
4234 This macro does not check whether
4235 @code{getpgrp} exists at all; if you need to work in that situation,
4236 first call @code{AC_CHECK_FUNC} for @code{getpgrp}.
4237 @end defmac
4239 @defmac AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
4240 @acindex{FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK}
4241 @cvindex LSTAT_FOLLOWS_SLASHED_SYMLINK
4242 @c @fuindex lstat
4243 @prindex @code{lstat}
4244 If @file{link} is a symbolic link, then @code{lstat} should treat
4245 @file{link/} the same as @file{link/.}.  However, many older
4246 @code{lstat} implementations incorrectly ignore trailing slashes.
4248 It is safe to assume that if @code{lstat} incorrectly ignores
4249 trailing slashes, then other symbolic-link-aware functions like
4250 @code{unlink} also incorrectly ignore trailing slashes.
4252 If @code{lstat} behaves properly, define
4253 @code{LSTAT_FOLLOWS_SLASHED_SYMLINK}, otherwise require an
4254 @code{AC_LIBOBJ} replacement of @code{lstat}.
4255 @end defmac
4257 @defmac AC_FUNC_MALLOC
4258 @acindex{FUNC_MALLOC}
4259 @cvindex HAVE_MALLOC
4260 @cvindex malloc
4261 @c @fuindex malloc
4262 @prindex @code{malloc}
4263 If the @code{malloc} function is compatible with the @acronym{GNU} C
4264 library @code{malloc} (i.e., @samp{malloc (0)} returns a valid
4265 pointer), define @code{HAVE_MALLOC} to 1.  Otherwise define
4266 @code{HAVE_MALLOC} to 0, ask for an @code{AC_LIBOBJ} replacement for
4267 @samp{malloc}, and define @code{malloc} to @code{rpl_malloc} so that the
4268 native @code{malloc} is not used in the main project.
4270 Typically, the replacement file @file{malloc.c} should look like (note
4271 the @samp{#undef malloc}):
4273 @verbatim
4274 #if HAVE_CONFIG_H
4275 # include <config.h>
4276 #endif
4277 #undef malloc
4279 #include <sys/types.h>
4281 void *malloc ();
4283 /* Allocate an N-byte block of memory from the heap.
4284    If N is zero, allocate a 1-byte block.  */
4286 void *
4287 rpl_malloc (size_t n)
4289   if (n == 0)
4290     n = 1;
4291   return malloc (n);
4293 @end verbatim
4294 @end defmac
4296 @defmac AC_FUNC_MEMCMP
4297 @acindex{FUNC_MEMCMP}
4298 @ovindex LIBOBJS
4299 @c @fuindex memcmp
4300 @prindex @code{memcmp}
4301 If the @code{memcmp} function is not available, or does not work on
4302 8-bit data (like the one on SunOS 4.1.3), or fails when comparing 16
4303 bytes or more and with at least one buffer not starting on a 4-byte
4304 boundary (such as the one on NeXT x86 OpenStep), require an
4305 @code{AC_LIBOBJ} replacement for @samp{memcmp}.
4306 @end defmac
4308 @defmac AC_FUNC_MBRTOWC
4309 @acindex{FUNC_MBRTOWC}
4310 @cvindex HAVE_MBRTOWC
4311 @c @fuindex mbrtowc
4312 @prindex @code{mbrtowc}
4313 Define @code{HAVE_MBRTOWC} to 1 if the function @code{mbrtowc} and the
4314 type @code{mbstate_t} are properly declared.
4315 @end defmac
4317 @defmac AC_FUNC_MKTIME
4318 @acindex{FUNC_MKTIME}
4319 @ovindex LIBOBJS
4320 @c @fuindex mktime
4321 @prindex @code{mktime}
4322 If the @code{mktime} function is not available, or does not work
4323 correctly, require an @code{AC_LIBOBJ} replacement for @samp{mktime}.
4324 For the purposes of this test, @code{mktime} should conform to the
4325 Posix standard and should be the inverse of
4326 @code{localtime}.
4327 @end defmac
4329 @defmac AC_FUNC_MMAP
4330 @acindex{FUNC_MMAP}
4331 @cvindex HAVE_MMAP
4332 @c @fuindex mmap
4333 @prindex @code{mmap}
4334 If the @code{mmap} function exists and works correctly, define
4335 @code{HAVE_MMAP}.  Only checks private fixed mapping of already-mapped
4336 memory.
4337 @end defmac
4339 @defmac AC_FUNC_OBSTACK
4340 @acindex{FUNC_OBSTACK}
4341 @cvindex HAVE_OBSTACK
4342 @cindex obstack
4343 If the obstacks are found, define @code{HAVE_OBSTACK}, else require an
4344 @code{AC_LIBOBJ} replacement for @samp{obstack}.
4345 @end defmac
4347 @defmac AC_FUNC_REALLOC
4348 @acindex{FUNC_REALLOC}
4349 @cvindex HAVE_REALLOC
4350 @cvindex realloc
4351 @c @fuindex realloc
4352 @prindex @code{realloc}
4353 If the @code{realloc} function is compatible with the @acronym{GNU} C
4354 library @code{realloc} (i.e., @samp{realloc (0, 0)} returns a
4355 valid pointer), define @code{HAVE_REALLOC} to 1.  Otherwise define
4356 @code{HAVE_REALLOC} to 0, ask for an @code{AC_LIBOBJ} replacement for
4357 @samp{realloc}, and define @code{realloc} to @code{rpl_realloc} so that
4358 the native @code{realloc} is not used in the main project.  See
4359 @code{AC_FUNC_MALLOC} for details.
4360 @end defmac
4362 @defmac AC_FUNC_SELECT_ARGTYPES
4363 @acindex{FUNC_SELECT_ARGTYPES}
4364 @cvindex SELECT_TYPE_ARG1
4365 @cvindex SELECT_TYPE_ARG234
4366 @cvindex SELECT_TYPE_ARG5
4367 @c @fuindex select
4368 @prindex @code{select}
4369 Determines the correct type to be passed for each of the
4370 @code{select} function's arguments, and defines those types
4371 in @code{SELECT_TYPE_ARG1}, @code{SELECT_TYPE_ARG234}, and
4372 @code{SELECT_TYPE_ARG5} respectively.  @code{SELECT_TYPE_ARG1} defaults
4373 to @samp{int}, @code{SELECT_TYPE_ARG234} defaults to @samp{int *},
4374 and @code{SELECT_TYPE_ARG5} defaults to @samp{struct timeval *}.
4375 @end defmac
4377 @defmac AC_FUNC_SETPGRP
4378 @acindex{FUNC_SETPGRP}
4379 @cvindex SETPGRP_VOID
4380 @c @fuindex setpgrp
4381 @prindex @code{setpgrp}
4382 If @code{setpgrp} takes no argument (the Posix version), define
4383 @code{SETPGRP_VOID}.  Otherwise, it is the @acronym{BSD} version, which takes
4384 two process IDs as arguments.  This macro does not check whether
4385 @code{setpgrp} exists at all; if you need to work in that situation,
4386 first call @code{AC_CHECK_FUNC} for @code{setpgrp}.
4387 @end defmac
4389 @defmac AC_FUNC_STAT
4390 @defmacx AC_FUNC_LSTAT
4391 @acindex{FUNC_STAT}
4392 @acindex{FUNC_LSTAT}
4393 @cvindex HAVE_STAT_EMPTY_STRING_BUG
4394 @cvindex HAVE_LSTAT_EMPTY_STRING_BUG
4395 @c @fuindex stat
4396 @prindex @code{stat}
4397 @c @fuindex lstat
4398 @prindex @code{lstat}
4399 Determine whether @code{stat} or @code{lstat} have the bug that it
4400 succeeds when given the zero-length file name as argument.  The @code{stat}
4401 and @code{lstat} from SunOS 4.1.4 and the Hurd (as of 1998-11-01) do
4402 this.
4404 If it does, then define @code{HAVE_STAT_EMPTY_STRING_BUG} (or
4405 @code{HAVE_LSTAT_EMPTY_STRING_BUG}) and ask for an @code{AC_LIBOBJ}
4406 replacement of it.
4407 @end defmac
4409 @defmac AC_FUNC_SETVBUF_REVERSED
4410 @acindex{FUNC_SETVBUF_REVERSED}
4411 @cvindex SETVBUF_REVERSED
4412 @c @fuindex setvbuf
4413 @prindex @code{setvbuf}
4414 If @code{setvbuf} takes the buffering type as its second argument and
4415 the buffer pointer as the third, instead of the other way around, define
4416 @code{SETVBUF_REVERSED}.
4417 @end defmac
4419 @defmac AC_FUNC_STRCOLL
4420 @acindex{FUNC_STRCOLL}
4421 @cvindex HAVE_STRCOLL
4422 @c @fuindex strcoll
4423 @prindex @code{strcoll}
4424 If the @code{strcoll} function exists and works correctly, define
4425 @code{HAVE_STRCOLL}.  This does a bit more than
4426 @samp{AC_CHECK_FUNCS(strcoll)}, because some systems have incorrect
4427 definitions of @code{strcoll} that should not be used.
4428 @end defmac
4430 @defmac AC_FUNC_STRTOD
4431 @acindex{FUNC_STRTOD}
4432 @ovindex POW_LIB
4433 @c @fuindex strtod
4434 @prindex @code{strtod}
4435 If the @code{strtod} function does not exist or doesn't work correctly,
4436 ask for an @code{AC_LIBOBJ} replacement of @samp{strtod}.  In this case,
4437 because @file{strtod.c} is likely to need @samp{pow}, set the output
4438 variable @code{POW_LIB} to the extra library needed.
4439 @end defmac
4441 @defmac AC_FUNC_STRERROR_R
4442 @acindex{FUNC_STRERROR_R}
4443 @cvindex HAVE_STRERROR_R
4444 @cvindex HAVE_DECL_STRERROR_R
4445 @cvindex STRERROR_R_CHAR_P
4446 @c @fuindex strerror_r
4447 @prindex @code{strerror_r}
4448 If @code{strerror_r} is available, define @code{HAVE_STRERROR_R}, and if
4449 it is declared, define @code{HAVE_DECL_STRERROR_R}.  If it returns a
4450 @code{char *} message, define @code{STRERROR_R_CHAR_P}; otherwise it
4451 returns an @code{int} error number.  The Thread-Safe Functions option of
4452 Posix requires @code{strerror_r} to return @code{int}, but
4453 many systems (including, for example, version 2.2.4 of the @acronym{GNU} C
4454 Library) return a @code{char *} value that is not necessarily equal to
4455 the buffer argument.
4456 @end defmac
4458 @defmac AC_FUNC_STRFTIME
4459 @acindex{FUNC_STRFTIME}
4460 @cvindex HAVE_STRFTIME
4461 @c @fuindex strftime
4462 @prindex @code{strftime}
4463 Check for @code{strftime} in the @file{intl} library, for SCO Unix.
4464 Then, if @code{strftime} is available, define @code{HAVE_STRFTIME}.
4465 @end defmac
4467 @defmac AC_FUNC_STRNLEN
4468 @acindex{FUNC_STRNLEN}
4469 @cvindex HAVE_STRNLEN
4470 @c @fuindex strnlen
4471 @prindex @code{strnlen}
4472 If the @code{strnlen} function is not available, or is buggy (like the one
4473 from @acronym{AIX} 4.3), require an @code{AC_LIBOBJ} replacement for it.
4474 @end defmac
4476 @defmac AC_FUNC_UTIME_NULL
4477 @acindex{FUNC_UTIME_NULL}
4478 @cvindex HAVE_UTIME_NULL
4479 @c @fuindex utime
4480 @prindex @code{utime}
4481 If @samp{utime(@var{file}, NULL)} sets @var{file}'s timestamp to
4482 the present, define @code{HAVE_UTIME_NULL}.
4483 @end defmac
4485 @defmac AC_FUNC_VPRINTF
4486 @acindex{FUNC_VPRINTF}
4487 @cvindex HAVE_VPRINTF
4488 @cvindex HAVE_DOPRNT
4489 @c @fuindex vprintf
4490 @prindex @code{vprintf}
4491 If @code{vprintf} is found, define @code{HAVE_VPRINTF}.  Otherwise, if
4492 @code{_doprnt} is found, define @code{HAVE_DOPRNT}.  (If @code{vprintf}
4493 is available, you may assume that @code{vfprintf} and @code{vsprintf}
4494 are also available.)
4495 @end defmac
4497 @defmac AC_REPLACE_FNMATCH
4498 @acindex{REPLACE_FNMATCH}
4499 @c @fuindex fnmatch
4500 @prindex @code{fnmatch}
4501 @hdrindex{fnmatch.h}
4502 If the @code{fnmatch} function does not conform to Posix (see
4503 @code{AC_FUNC_FNMATCH}), ask for its @code{AC_LIBOBJ} replacement.
4505 The files @file{fnmatch.c}, @file{fnmatch_loop.c}, and @file{fnmatch_.h}
4506 in the @code{AC_LIBOBJ} replacement directory are assumed to contain a
4507 copy of the source code of @acronym{GNU} @code{fnmatch}.  If necessary,
4508 this source code is compiled as an @code{AC_LIBOBJ} replacement, and the
4509 @file{fnmatch_.h} file is linked to @file{fnmatch.h} so that it can be
4510 included in place of the system @code{<fnmatch.h>}.
4511 @end defmac
4515 @node Generic Functions
4516 @subsection Generic Function Checks
4518 These macros are used to find functions not covered by the ``particular''
4519 test macros.  If the functions might be in libraries other than the
4520 default C library, first call @code{AC_CHECK_LIB} for those libraries.
4521 If you need to check the behavior of a function as well as find out
4522 whether it is present, you have to write your own test for
4523 it (@pxref{Writing Tests}).
4525 @defmac AC_CHECK_FUNC (@var{function}, @ovar{action-if-found}, @ovar{action-if-not-found})
4526 @acindex{CHECK_FUNC}
4527 If C function @var{function} is available, run shell commands
4528 @var{action-if-found}, otherwise @var{action-if-not-found}.  If you just
4529 want to define a symbol if the function is available, consider using
4530 @code{AC_CHECK_FUNCS} instead.  This macro checks for functions with C
4531 linkage even when @code{AC_LANG(C++)} has been called, since C is more
4532 standardized than C++.  (@pxref{Language Choice}, for more information
4533 about selecting the language for checks.)
4534 @end defmac
4536 @defmac AC_CHECK_FUNCS (@var{function}@dots{}, @ovar{action-if-found}, @ovar{action-if-not-found})
4537 @acindex{CHECK_FUNCS}
4538 @cvindex HAVE_@var{function}
4539 For each @var{function} in the whitespace-separated argument list,
4540 define @code{HAVE_@var{function}} (in all capitals) if it is available.
4541 If @var{action-if-found} is given, it is additional shell code to
4542 execute when one of the functions is found.  You can give it a value of
4543 @samp{break} to break out of the loop on the first match.  If
4544 @var{action-if-not-found} is given, it is executed when one of the
4545 functions is not found.
4546 @end defmac
4548 @sp 1
4550 Autoconf follows a philosophy that was formed over the years by those
4551 who have struggled for portability: isolate the portability issues in
4552 specific files, and then program as if you were in a Posix
4553 environment.  Some functions may be missing or unfixable, and your
4554 package must be ready to replace them.
4556 @defmac AC_LIBOBJ (@var{function})
4557 @acindex{LIBOBJ}
4558 @ovindex LIBOBJS
4559 Specify that @samp{@var{function}.c} must be included in the executables
4560 to replace a missing or broken implementation of @var{function}.
4562 Technically, it adds @samp{@var{function}.$ac_objext} to the output
4563 variable @code{LIBOBJS} if it is not already in, and calls
4564 @code{AC_LIBSOURCE} for @samp{@var{function}.c}.  You should not
4565 directly change @code{LIBOBJS}, since this is not traceable.
4566 @end defmac
4568 @defmac AC_LIBSOURCE (@var{file})
4569 @acindex{LIBSOURCE}
4570 Specify that @var{file} might be needed to compile the project.  If you
4571 need to know what files might be needed by a @file{configure.ac}, you
4572 should trace @code{AC_LIBSOURCE}.  @var{file} must be a literal.
4574 This macro is called automatically from @code{AC_LIBOBJ}, but you must
4575 call it explicitly if you pass a shell variable to @code{AC_LIBOBJ}.  In
4576 that case, since shell variables cannot be traced statically, you must
4577 pass to @code{AC_LIBSOURCE} any possible files that the shell variable
4578 might cause @code{AC_LIBOBJ} to need.  For example, if you want to pass
4579 a variable @code{$foo_or_bar} to @code{AC_LIBOBJ} that holds either
4580 @code{"foo"} or @code{"bar"}, you should do:
4582 @example
4583 AC_LIBSOURCE(foo.c)
4584 AC_LIBSOURCE(bar.c)
4585 AC_LIBOBJ($foo_or_bar)
4586 @end example
4588 @noindent
4589 There is usually a way to avoid this, however, and you are encouraged to
4590 simply call @code{AC_LIBOBJ} with literal arguments.
4592 Note that this macro replaces the obsolete @code{AC_LIBOBJ_DECL}, with
4593 slightly different semantics: the old macro took the function name,
4594 e.g., @code{foo}, as its argument rather than the file name.
4595 @end defmac
4597 @defmac AC_LIBSOURCES (@var{files})
4598 @acindex{LIBSOURCES}
4599 Like @code{AC_LIBSOURCE}, but accepts one or more @var{files} in a
4600 comma-separated M4 list.  Thus, the above example might be rewritten:
4602 @example
4603 AC_LIBSOURCES([foo.c, bar.c])
4604 AC_LIBOBJ($foo_or_bar)
4605 @end example
4606 @end defmac
4608 @defmac AC_CONFIG_LIBOBJ_DIR (@var{directory})
4609 @acindex{CONFIG_LIBOBJ_DIR}
4610 Specify that @code{AC_LIBOBJ} replacement files are to be found in
4611 @var{directory}, a name relative to the top level of the
4612 source tree.  The replacement directory defaults to @file{.}, the top
4613 level directory, and the most typical value is @file{lib}, corresponding
4614 to @samp{AC_CONFIG_LIBOBJ_DIR(lib)}.
4616 @command{configure} might need to know the replacement directory for the
4617 following reasons: (i) some checks use the replacement files, (ii) some
4618 macros bypass broken system headers by installing links to the
4619 replacement headers (iii) when used in conjunction with Automake,
4620 within each @file{Makefile}, @var{directory} is used as a relative path
4621 from @code{$(top_srcdir)} to each object named in @code(LIBOBJS) and
4622 @code(LTLIBOBJS), etc.
4623 @end defmac
4625 @sp 1
4627 It is common to merely check for the existence of a function, and ask
4628 for its @code{AC_LIBOBJ} replacement if missing.  The following macro is
4629 a convenient shorthand.
4631 @defmac AC_REPLACE_FUNCS (@var{function}@dots{})
4632 @acindex{REPLACE_FUNCS}
4633 @ovindex LIBOBJS
4634 Like @code{AC_CHECK_FUNCS}, but uses @samp{AC_LIBOBJ(@var{function})} as
4635 @var{action-if-not-found}.  You can declare your replacement function by
4636 enclosing the prototype in @samp{#if !HAVE_@var{function}}.  If the
4637 system has the function, it probably declares it in a header file you
4638 should be including, so you shouldn't redeclare it lest your declaration
4639 conflict.
4640 @end defmac
4642 @node Header Files
4643 @section Header Files
4644 @cindex Header, checking
4646 The following macros check for the presence of certain C header files.
4647 If there is no macro specifically defined to check for a header file you need,
4648 and you don't need to check for any special properties of
4649 it, then you can use one of the general header-file check macros.
4651 @menu
4652 * Header Portability::          Collected knowledge on common headers
4653 * Particular Headers::          Special handling to find certain headers
4654 * Generic Headers::             How to find other headers
4655 @end menu
4657 @node Header Portability
4658 @subsection Portability of Headers
4659 @cindex Portability of headers
4660 @cindex Header portability
4662 This section tries to collect knowledge about common headers, and the
4663 problems they cause.  By definition, this list will always require
4664 additions.  Please help us keeping it as complete as possible.
4666 @table @asis
4667 @item @file{inttypes.h} vs.@: @file{stdint.h}
4668 @hdrindex{inttypes.h}
4669 @hdrindex{stdint.h}
4670 Paul Eggert notes that: ISO C 1999 says that @file{inttypes.h} includes
4671 @file{stdint.h}, so there's no need to include @file{stdint.h}
4672 separately in a standard environment.  Many implementations have
4673 @file{inttypes.h} but not @file{stdint.h} (e.g., Solaris 7), but I don't
4674 know of any implementation that has @file{stdint.h} but not
4675 @file{inttypes.h}.  Nor do I know of any free software that includes
4676 @file{stdint.h}; @file{stdint.h} seems to be a creation of the committee.
4678 @item @file{linux/irda.h}
4679 @hdrindex{linux/irda.h}
4680 It requires @file{linux/types.h} and @file{sys/socket.h}.
4682 @item @file{linux/random.h}
4683 @hdrindex{linux/random.h}
4684 It requires @file{linux/types.h}.
4686 @item @file{net/if.h}
4687 @hdrindex{net/if.h}
4688 On Darwin, this file requires that @file{sys/socket.h} be included
4689 beforehand.  One should run:
4691 @example
4692 AC_CHECK_HEADERS([sys/socket.h])
4693 AC_CHECK_HEADERS([net/if.h], [], [],
4694 [#include <stdio.h>
4695 #if STDC_HEADERS
4696 # include <stdlib.h>
4697 # include <stddef.h>
4698 #else
4699 # if HAVE_STDLIB_H
4700 #  include <stdlib.h>
4701 # endif
4702 #endif
4703 #if HAVE_SYS_SOCKET_H
4704 # include <sys/socket.h>
4705 #endif
4707 @end example
4709 @item @file{netinet/if_ether.h}
4710 @hdrindex{netinet/if_ether.h}
4711 On Darwin, this file requires that @file{stdio.h} and
4712 @file{sys/socket.h} be included beforehand.  One should run:
4714 @example
4715 AC_CHECK_HEADERS([sys/socket.h])
4716 AC_CHECK_HEADERS([netinet/if_ether.h], [], [],
4717 [#include <stdio.h>
4718 #if STDC_HEADERS
4719 # include <stdlib.h>
4720 # include <stddef.h>
4721 #else
4722 # if HAVE_STDLIB_H
4723 #  include <stdlib.h>
4724 # endif
4725 #endif
4726 #if HAVE_SYS_SOCKET_H
4727 # include <sys/socket.h>
4728 #endif
4730 @end example
4732 @item @file{stdint.h}
4733 See above, item @file{inttypes.h} vs.@: @file{stdint.h}.
4735 @item @file{stdlib.h}
4736 @hdrindex{stdlib.h}
4737 On many systems (e.g., Darwin), @file{stdio.h} is a prerequisite.
4739 @item @file{sys/mount.h}
4740 @hdrindex{sys/mount.h}
4741 On FreeBSD 4.8 on ia32 and using gcc version 2.95.4,
4742 @file{sys/params.h} is a prerequisite.
4744 @item @file{sys/socket.h}
4745 @hdrindex{sys/socket.h}
4746 On Darwin, @file{stdlib.h} is a prerequisite.
4748 @item @file{sys/ucred.h}
4749 @hdrindex{sys/ucred.h}
4750 On HP Tru64 5.1, @file{sys/types.h} is a prerequisite.
4752 @item @file{X11/extensions/scrnsaver.h}
4753 @hdrindex{X11/extensions/scrnsaver.h}
4754 Using XFree86, this header requires @file{X11/Xlib.h}, which is probably
4755 so required that you might not even consider looking for it.
4757 @example
4758 AC_CHECK_HEADERS([X11/extensions/scrnsaver.h], [], [],
4759 [[#include <X11/Xlib.h>
4761 @end example
4762 @end table
4765 @node Particular Headers
4766 @subsection Particular Header Checks
4768 These macros check for particular system header files---whether they
4769 exist, and in some cases whether they declare certain symbols.
4771 @defmac AC_HEADER_DIRENT
4772 @acindex{HEADER_DIRENT}
4773 @cvindex HAVE_DIRENT_H
4774 @cvindex HAVE_NDIR_H
4775 @cvindex HAVE_SYS_DIR_H
4776 @cvindex HAVE_SYS_NDIR_H
4777 @hdrindex{dirent.h}
4778 @hdrindex{sys/ndir.h}
4779 @hdrindex{sys/dir.h}
4780 @hdrindex{ndir.h}
4781 Check for the following header files.  For the first one that is
4782 found and defines @samp{DIR}, define the listed C preprocessor macro:
4784 @multitable {@file{sys/ndir.h}} {@code{HAVE_SYS_NDIR_H}}
4785 @item @file{dirent.h}   @tab @code{HAVE_DIRENT_H}
4786 @item @file{sys/ndir.h} @tab @code{HAVE_SYS_NDIR_H}
4787 @item @file{sys/dir.h}  @tab @code{HAVE_SYS_DIR_H}
4788 @item @file{ndir.h}     @tab @code{HAVE_NDIR_H}
4789 @end multitable
4791 The directory-library declarations in your source code should look
4792 something like the following:
4794 @example
4795 @group
4796 #if HAVE_DIRENT_H
4797 # include <dirent.h>
4798 # define NAMLEN(dirent) strlen((dirent)->d_name)
4799 #else
4800 # define dirent direct
4801 # define NAMLEN(dirent) (dirent)->d_namlen
4802 # if HAVE_SYS_NDIR_H
4803 #  include <sys/ndir.h>
4804 # endif
4805 # if HAVE_SYS_DIR_H
4806 #  include <sys/dir.h>
4807 # endif
4808 # if HAVE_NDIR_H
4809 #  include <ndir.h>
4810 # endif
4811 #endif
4812 @end group
4813 @end example
4815 Using the above declarations, the program would declare variables to be
4816 of type @code{struct dirent}, not @code{struct direct}, and would access
4817 the length of a directory entry name by passing a pointer to a
4818 @code{struct dirent} to the @code{NAMLEN} macro.
4820 This macro also checks for the SCO Xenix @file{dir} and @file{x} libraries.
4821 @end defmac
4823 @defmac AC_HEADER_MAJOR
4824 @acindex{HEADER_MAJOR}
4825 @cvindex MAJOR_IN_MKDEV
4826 @cvindex MAJOR_IN_SYSMACROS
4827 @hdrindex{sys/mkdev.h}
4828 @hdrindex{sys/sysmacros.h}
4829 If @file{sys/types.h} does not define @code{major}, @code{minor}, and
4830 @code{makedev}, but @file{sys/mkdev.h} does, define
4831 @code{MAJOR_IN_MKDEV}; otherwise, if @file{sys/sysmacros.h} does, define
4832 @code{MAJOR_IN_SYSMACROS}.
4833 @end defmac
4835 @defmac AC_HEADER_RESOLV
4836 @acindex{HEADER_RESOLV}
4837 @cvindex HAVE_RESOLV_H
4838 @hdrindex{resolv.h}
4839 Checks for header @file{resolv.h}, checking for prerequisities first.
4840 To properly use @file{resolv.h}, your code should contain something like
4841 the following:
4843 @verbatim
4844 #if HAVE_SYS_TYPES_H
4845 #  include <sys/types.h>
4846 #endif
4847 #ifdef HAVE_NETINET_IN_H
4848 #  include <netinet/in.h>   /* inet_ functions / structs */
4849 #endif
4850 #ifdef HAVE_ARPA_NAMESER_H
4851 #  include <arpa/nameser.h> /* DNS HEADER struct */
4852 #endif
4853 #ifdef HAVE_NETDB_H
4854 #  include <netdb.h>
4855 #endif
4856 #include <resolv.h>
4857 @end verbatim
4858 @end defmac
4860 @defmac AC_HEADER_STAT
4861 @acindex{HEADER_STAT}
4862 @cvindex STAT_MACROS_BROKEN
4863 @hdrindex{sys/stat.h}
4864 If the macros @code{S_ISDIR}, @code{S_ISREG}, etc.@: defined in
4865 @file{sys/stat.h} do not work properly (returning false positives),
4866 define @code{STAT_MACROS_BROKEN}.  This is the case on Tektronix UTekV,
4867 Amdahl UTS and Motorola System V/88.
4868 @end defmac
4870 @defmac AC_HEADER_STDBOOL
4871 @acindex{HEADER_STDBOOL}
4872 @cvindex HAVE_STDBOOL_H
4873 @cvindex HAVE__BOOL
4874 @hdrindex{stdbool.h}
4875 @hdrindex{system.h}
4876 If @file{stdbool.h} exists and is conformant to C99, define
4877 @code{HAVE_STDBOOL_H} to 1; if the type @code{_Bool} is defined, define
4878 @code{HAVE__BOOL} to 1.  To fulfill the C99 requirements, your
4879 @file{system.h} should contain the following code:
4881 @verbatim
4882 #if HAVE_STDBOOL_H
4883 # include <stdbool.h>
4884 #else
4885 # if ! HAVE__BOOL
4886 #  ifdef __cplusplus
4887 typedef bool _Bool;
4888 #  else
4889 typedef unsigned char _Bool;
4890 #  endif
4891 # endif
4892 # define bool _Bool
4893 # define false 0
4894 # define true 1
4895 # define __bool_true_false_are_defined 1
4896 #endif
4897 @end verbatim
4898 @end defmac
4901 @defmac AC_HEADER_STDC
4902 @acindex{HEADER_STDC}
4903 @cvindex STDC_HEADERS
4904 @hdrindex{stdlib.h}
4905 @hdrindex{stdarg.h}
4906 @hdrindex{string.h}
4907 @hdrindex{float.h}
4908 @hdrindex{ctype.h}
4909 Define @code{STDC_HEADERS} if the system has @acronym{ANSI} C header files.
4910 Specifically, this macro checks for @file{stdlib.h}, @file{stdarg.h},
4911 @file{string.h}, and @file{float.h}; if the system has those, it
4912 probably has the rest of the @acronym{ANSI} C header files.  This macro also
4913 checks whether @file{string.h} declares @code{memchr} (and thus
4914 presumably the other @code{mem} functions), whether @file{stdlib.h}
4915 declare @code{free} (and thus presumably @code{malloc} and other related
4916 functions), and whether the @file{ctype.h} macros work on characters
4917 with the high bit set, as @acronym{ANSI} C requires.
4919 Use @code{STDC_HEADERS} instead of @code{__STDC__} to determine whether
4920 the system has @acronym{ANSI}-compliant header files (and probably C library
4921 functions) because many systems that have GCC do not have @acronym{ANSI} C
4922 header files.
4924 @hdrindex{string.h}
4925 @hdrindex{strings.h}
4926 On systems without @acronym{ANSI} C headers, there is so much variation
4927 that it is probably easier to declare the functions you use than to
4928 figure out exactly what the system header files declare.  Some systems
4929 contain a mix of functions from @acronym{ANSI} and @acronym{BSD}; some are
4930 mostly @acronym{ANSI} but lack @samp{memmove}; some define the
4931 @acronym{BSD} functions as macros in @file{string.h} or
4932 @file{strings.h}; some have only the @acronym{BSD} functions but
4933 @file{string.h}; some declare the memory functions in @file{memory.h},
4934 some in @file{string.h}; etc.  It is probably sufficient to check for
4935 one string function and one memory function; if the library has the
4936 @acronym{ANSI} versions of those then it probably has most of the others.
4937 If you put the following in @file{configure.ac}:
4939 @example
4940 AC_HEADER_STDC
4941 AC_CHECK_FUNCS(strchr memcpy)
4942 @end example
4944 @noindent
4945 then, in your code, you can use declarations like this:
4947 @example
4948 @group
4949 #if STDC_HEADERS
4950 # include <string.h>
4951 #else
4952 # if !HAVE_STRCHR
4953 #  define strchr index
4954 #  define strrchr rindex
4955 # endif
4956 char *strchr (), *strrchr ();
4957 # if !HAVE_MEMCPY
4958 #  define memcpy(d, s, n) bcopy ((s), (d), (n))
4959 #  define memmove(d, s, n) bcopy ((s), (d), (n))
4960 # endif
4961 #endif
4962 @end group
4963 @end example
4965 @noindent
4966 If you use a function like @code{memchr}, @code{memset}, @code{strtok},
4967 or @code{strspn}, which have no @acronym{BSD} equivalent, then macros won't
4968 suffice; you must provide an implementation of each function.  An easy
4969 way to incorporate your implementations only when needed (since the ones
4970 in system C libraries may be hand optimized) is to, taking @code{memchr}
4971 for example, put it in @file{memchr.c} and use
4972 @samp{AC_REPLACE_FUNCS(memchr)}.
4973 @end defmac
4975 @defmac AC_HEADER_SYS_WAIT
4976 @acindex{HEADER_SYS_WAIT}
4977 @cvindex HAVE_SYS_WAIT_H
4978 @hdrindex{sys/wait.h}
4979 If @file{sys/wait.h} exists and is compatible with Posix, define
4980 @code{HAVE_SYS_WAIT_H}.  Incompatibility can occur if @file{sys/wait.h}
4981 does not exist, or if it uses the old @acronym{BSD} @code{union wait} instead
4982 of @code{int} to store a status value.  If @file{sys/wait.h} is not
4983 Posix compatible, then instead of including it, define the
4984 Posix macros with their usual interpretations.  Here is an
4985 example:
4987 @example
4988 @group
4989 #include <sys/types.h>
4990 #if HAVE_SYS_WAIT_H
4991 # include <sys/wait.h>
4992 #endif
4993 #ifndef WEXITSTATUS
4994 # define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
4995 #endif
4996 #ifndef WIFEXITED
4997 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
4998 #endif
4999 @end group
5000 @end example
5001 @end defmac
5003 @cvindex _POSIX_VERSION
5004 @hdrindex{unistd.h}
5005 @code{_POSIX_VERSION} is defined when @file{unistd.h} is included on
5006 Posix systems.  If there is no @file{unistd.h}, it is definitely
5007 not a Posix system.  However, some non-Posix systems do
5008 have @file{unistd.h}.
5010 The way to check whether the system supports Posix is:
5012 @example
5013 @group
5014 #if HAVE_UNISTD_H
5015 # include <sys/types.h>
5016 # include <unistd.h>
5017 #endif
5019 #ifdef _POSIX_VERSION
5020 /* Code for Posix systems.  */
5021 #endif
5022 @end group
5023 @end example
5025 @defmac AC_HEADER_TIME
5026 @acindex{HEADER_TIME}
5027 @cvindex TIME_WITH_SYS_TIME
5028 @hdrindex{time.h}
5029 @hdrindex{sys/time.h}
5030 If a program may include both @file{time.h} and @file{sys/time.h},
5031 define @code{TIME_WITH_SYS_TIME}.  On some older systems,
5032 @file{sys/time.h} includes @file{time.h}, but @file{time.h} is not
5033 protected against multiple inclusion, so programs should not explicitly
5034 include both files.  This macro is useful in programs that use, for
5035 example, @code{struct timeval} as well as
5036 @code{struct tm}.  It is best used in conjunction with
5037 @code{HAVE_SYS_TIME_H}, which can be checked for using
5038 @code{AC_CHECK_HEADERS(sys/time.h)}.
5040 @example
5041 @group
5042 #if TIME_WITH_SYS_TIME
5043 # include <sys/time.h>
5044 # include <time.h>
5045 #else
5046 # if HAVE_SYS_TIME_H
5047 #  include <sys/time.h>
5048 # else
5049 #  include <time.h>
5050 # endif
5051 #endif
5052 @end group
5053 @end example
5054 @end defmac
5057 @defmac AC_HEADER_TIOCGWINSZ
5058 @acindex{HEADER_TIOCGWINSZ}
5059 @cvindex GWINSZ_IN_SYS_IOCTL
5060 @hdrindex{sys/ioctl.h}
5061 @hdrindex{termios.h}
5062 @c FIXME: I need clarifications from Jim.
5063 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
5064 define @code{GWINSZ_IN_SYS_IOCTL}.  Otherwise @code{TIOCGWINSZ} can be
5065 found in @file{<termios.h>}.
5067 Use:
5069 @example
5070 @group
5071 #if HAVE_TERMIOS_H
5072 # include <termios.h>
5073 #endif
5075 #if GWINSZ_IN_SYS_IOCTL
5076 # include <sys/ioctl.h>
5077 #endif
5078 @end group
5079 @end example
5080 @end defmac
5082 @node Generic Headers
5083 @subsection Generic Header Checks
5085 These macros are used to find system header files not covered by the
5086 ``particular'' test macros.  If you need to check the contents of a header
5087 as well as find out whether it is present, you have to write your own
5088 test for it (@pxref{Writing Tests}).
5090 @defmac AC_CHECK_HEADER (@var{header-file}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5091 @acindex{CHECK_HEADER}
5092 If the system header file @var{header-file} is compilable, execute shell
5093 commands @var{action-if-found}, otherwise execute
5094 @var{action-if-not-found}.  If you just want to define a symbol if the
5095 header file is available, consider using @code{AC_CHECK_HEADERS}
5096 instead.
5098 For compatibility issues with older versions of Autoconf, please read
5099 below.
5100 @end defmac
5102 @defmac AC_CHECK_HEADERS (@var{header-file}@dots{}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5103 @acindex{CHECK_HEADERS}
5104 @cvindex HAVE_@var{header}
5105 For each given system header file @var{header-file} in the
5106 whitespace-separated argument list that exists, define
5107 @code{HAVE_@var{header-file}} (in all capitals).  If @var{action-if-found}
5108 is given, it is additional shell code to execute when one of the header
5109 files is found.  You can give it a value of @samp{break} to break out of
5110 the loop on the first match.  If @var{action-if-not-found} is given, it
5111 is executed when one of the header files is not found.
5113 For compatibility issues with older versions of Autoconf, please read
5114 below.
5115 @end defmac
5117 Previous versions of Autoconf merely checked whether the header was
5118 accepted by the preprocessor.  This was changed because the old test was
5119 inappropriate for typical uses.  Headers are typically used to compile,
5120 not merely to preprocess, and the old behavior sometimes accepted
5121 headers that clashed at compile-time.  If you need to check whether a
5122 header is preprocessable, you can use @code{AC_PREPROC_IFELSE}
5123 (@pxref{Running the Preprocessor}).
5125 This scheme, which improves the robustness of the test, also requires
5126 that you make sure that headers that must be included before the
5127 @var{header-file} be part of the @var{includes}, (@pxref{Default
5128 Includes}).  If looking for @file{bar.h}, which requires that
5129 @file{foo.h} be included before if it exists, we suggest the following
5130 scheme:
5132 @verbatim
5133 AC_CHECK_HEADERS([foo.h])
5134 AC_CHECK_HEADERS([bar.h], [], [],
5135 [#if HAVE_FOO_H
5136 # include <foo.h>
5137 # endif
5139 @end verbatim
5141 @node Declarations
5142 @section Declarations
5143 @cindex Declaration, checking
5145 The following macros check for the declaration of variables and
5146 functions.  If there is no macro specifically defined to check for a
5147 symbol you need, then you can use the general macros (@pxref{Generic
5148 Declarations}) or, for more complex tests, you may use
5149 @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}).
5151 @menu
5152 * Particular Declarations::     Macros to check for certain declarations
5153 * Generic Declarations::        How to find other declarations
5154 @end menu
5156 @node Particular Declarations
5157 @subsection Particular Declaration Checks
5159 There are no specific macros for declarations.
5161 @node Generic Declarations
5162 @subsection Generic Declaration Checks
5164 These macros are used to find declarations not covered by the ``particular''
5165 test macros.
5167 @defmac AC_CHECK_DECL (@var{symbol}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5168 @acindex{CHECK_DECL}
5169 If @var{symbol} (a function or a variable) is not declared in
5170 @var{includes} and a declaration is needed, run the shell commands
5171 @var{action-if-not-found}, otherwise @var{action-if-found}.  If no
5172 @var{includes} are specified, the default includes are used
5173 (@pxref{Default Includes}).
5175 This macro actually tests whether it is valid to use @var{symbol} as an
5176 r-value, not if it is really declared, because it is much safer to avoid
5177 introducing extra declarations when they are not needed.
5178 @end defmac
5180 @defmac AC_CHECK_DECLS (@var{symbols}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5181 @acindex{CHECK_DECLS}
5182 @cvindex HAVE_DECL_@var{symbol}
5183 For each of the @var{symbols} (@emph{comma}-separated list), define
5184 @code{HAVE_DECL_@var{symbol}} (in all capitals) to @samp{1} if
5185 @var{symbol} is declared, otherwise to @samp{0}.  If
5186 @var{action-if-not-found} is given, it is additional shell code to
5187 execute when one of the function declarations is needed, otherwise
5188 @var{action-if-found} is executed.
5190 This macro uses an m4 list as first argument:
5191 @example
5192 AC_CHECK_DECLS(strdup)
5193 AC_CHECK_DECLS([strlen])
5194 AC_CHECK_DECLS([malloc, realloc, calloc, free])
5195 @end example
5197 Unlike the other @samp{AC_CHECK_*S} macros, when a @var{symbol} is not
5198 declared, @code{HAVE_DECL_@var{symbol}} is defined to @samp{0} instead
5199 of leaving @code{HAVE_DECL_@var{symbol}} undeclared.  When you are
5200 @emph{sure} that the check was performed, use
5201 @code{HAVE_DECL_@var{symbol}} just like any other result of Autoconf:
5203 @example
5204 #if !HAVE_DECL_SYMBOL
5205 extern char *symbol;
5206 #endif
5207 @end example
5209 @noindent
5210 If the test may have not been performed, however, because it is safer
5211 @emph{not} to declare a symbol than to use a declaration that conflicts
5212 with the system's one, you should use:
5214 @example
5215 #if defined HAVE_DECL_MALLOC && !HAVE_DECL_MALLOC
5216 void *malloc (size_t *s);
5217 #endif
5218 @end example
5220 @noindent
5221 You fall into the second category only in extreme situations: either
5222 your files may be used without being configured, or they are used during
5223 the configuration.  In most cases the traditional approach is enough.
5224 @end defmac
5227 @node Structures
5228 @section Structures
5229 @cindex Structure, checking
5231 The following macros check for the presence of certain members in C
5232 structures.  If there is no macro specifically defined to check for a
5233 member you need, then you can use the general structure-member macros
5234 (@pxref{Generic Structures}) or, for more complex tests, you may use
5235 @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}).
5237 @menu
5238 * Particular Structures::       Macros to check for certain structure members
5239 * Generic Structures::          How to find other structure members
5240 @end menu
5242 @node Particular Structures
5243 @subsection Particular Structure Checks
5245 The following macros check for certain structures or structure members.
5247 @defmac AC_STRUCT_ST_BLKSIZE
5248 @acindex{STRUCT_ST_BLKSIZE}
5249 @cvindex HAVE_STRUCT_STAT_ST_BLKSIZE
5250 @cvindex HAVE_ST_BLKSIZE
5251 If @code{struct stat} contains an @code{st_blksize} member, define
5252 @code{HAVE_STRUCT_STAT_ST_BLKSIZE}.  The former name,
5253 @code{HAVE_ST_BLKSIZE} is to be avoided, as its support will cease in
5254 the future.  This macro is obsoleted, and should be replaced by
5256 @example
5257 AC_CHECK_MEMBERS([struct stat.st_blksize])
5258 @end example
5259 @end defmac
5261 @defmac AC_STRUCT_ST_BLOCKS
5262 @acindex{STRUCT_ST_BLOCKS}
5263 @cvindex HAVE_STRUCT_STAT_ST_BLOCKS
5264 @cvindex HAVE_ST_BLOCKS
5265 @ovindex LIBOBJS
5266 If @code{struct stat} contains an @code{st_blocks} member, define
5267 @code{HAVE_STRUCT_STAT_ST_BLOCKS}.  Otherwise, require an
5268 @code{AC_LIBOBJ} replacement of @samp{fileblocks}.  The former name,
5269 @code{HAVE_ST_BLOCKS} is to be avoided, as its support will cease in the
5270 future.
5271 @end defmac
5273 @defmac AC_STRUCT_ST_RDEV
5274 @acindex{STRUCT_ST_RDEV}
5275 @cvindex HAVE_ST_RDEV
5276 @cvindex HAVE_STRUCT_STAT_ST_RDEV
5277 If @code{struct stat} contains an @code{st_rdev} member, define
5278 @code{HAVE_STRUCT_STAT_ST_RDEV}.  The former name for this macro,
5279 @code{HAVE_ST_RDEV}, is to be avoided as it will cease to be supported
5280 in the future.  Actually, even the new macro is obsolete and should be
5281 replaced by:
5282 @example
5283 AC_CHECK_MEMBERS([struct stat.st_rdev])
5284 @end example
5285 @end defmac
5287 @defmac AC_STRUCT_TM
5288 @acindex{STRUCT_TM}
5289 @cvindex TM_IN_SYS_TIME
5290 @hdrindex{time.h}
5291 @hdrindex{sys/time.h}
5292 If @file{time.h} does not define @code{struct tm}, define
5293 @code{TM_IN_SYS_TIME}, which means that including @file{sys/time.h}
5294 had better define @code{struct tm}.
5295 @end defmac
5297 @defmac AC_STRUCT_TIMEZONE
5298 @acindex{STRUCT_TIMEZONE}
5299 @cvindex HAVE_TM_ZONE
5300 @cvindex HAVE_TZNAME
5301 Figure out how to get the current timezone.  If @code{struct tm} has a
5302 @code{tm_zone} member, define @code{HAVE_STRUCT_TM_TM_ZONE} (and the
5303 obsoleted @code{HAVE_TM_ZONE}).  Otherwise, if the external array
5304 @code{tzname} is found, define @code{HAVE_TZNAME}; if it is declared,
5305 define @code{HAVE_DECL_TZNAME}.
5306 @end defmac
5308 @node Generic Structures
5309 @subsection Generic Structure Checks
5311 These macros are used to find structure members not covered by the
5312 ``particular'' test macros.
5314 @defmac AC_CHECK_MEMBER (@var{aggregate}.@var{member}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5315 @acindex{CHECK_MEMBER}
5316 Check whether @var{member} is a member of the aggregate @var{aggregate}.
5317 If no @var{includes} are specified, the default includes are used
5318 (@pxref{Default Includes}).
5320 @example
5321 AC_CHECK_MEMBER(struct passwd.pw_gecos,,
5322                 [AC_MSG_ERROR([We need `passwd.pw_gecos'!])],
5323                 [#include <pwd.h>])
5324 @end example
5326 You can use this macro for sub-members:
5328 @example
5329 AC_CHECK_MEMBER(struct top.middle.bot)
5330 @end example
5331 @end defmac
5333 @defmac AC_CHECK_MEMBERS (@var{members}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5334 @acindex{CHECK_MEMBERS}
5335 Check for the existence of each @samp{@var{aggregate}.@var{member}} of
5336 @var{members} using the previous macro.  When @var{member} belongs to
5337 @var{aggregate}, define @code{HAVE_@var{aggregate}_@var{member}} (in all
5338 capitals, with spaces and dots replaced by underscores).  If
5339 @var{action-if-found} is given, it is executed for each of the found
5340 members.  If @var{action-if-not-found} is given, it is executed for each
5341 of the members that could not be found.
5343 This macro uses m4 lists:
5344 @example
5345 AC_CHECK_MEMBERS([struct stat.st_rdev, struct stat.st_blksize])
5346 @end example
5347 @end defmac
5350 @node Types
5351 @section Types
5352 @cindex Types
5353 @cindex C types
5355 The following macros check for C types, either builtin or typedefs.  If
5356 there is no macro specifically defined to check for a type you need, and
5357 you don't need to check for any special properties of it, then you can
5358 use a general type-check macro.
5360 @menu
5361 * Particular Types::            Special handling to find certain types
5362 * Generic Types::               How to find other types
5363 @end menu
5365 @node Particular Types
5366 @subsection Particular Type Checks
5368 @hdrindex{sys/types.h}
5369 @hdrindex{stdlib.h}
5370 These macros check for particular C types in @file{sys/types.h},
5371 @file{stdlib.h} and others, if they exist.
5373 @defmac AC_TYPE_GETGROUPS
5374 @acindex{TYPE_GETGROUPS}
5375 @cvindex GETGROUPS_T
5376 Define @code{GETGROUPS_T} to be whichever of @code{gid_t} or @code{int}
5377 is the base type of the array argument to @code{getgroups}.
5378 @end defmac
5380 @defmac AC_TYPE_MBSTATE_T
5381 @acindex{TYPE_MBSTATE_T}
5382 @cvindex mbstate_t
5383 @hdrindex{wchar.h}
5384 Define @code{HAVE_MBSTATE_T} if @code{<wchar.h>} declares the
5385 @code{mbstate_t} type.  Also, define @code{mbstate_t} to be a type if
5386 @code{<wchar.h>} does not declare it.
5387 @end defmac
5389 @defmac AC_TYPE_MODE_T
5390 @acindex{TYPE_MODE_T}
5391 @cvindex mode_t
5392 Equivalent to @samp{AC_CHECK_TYPE(mode_t, int)}.
5393 @end defmac
5395 @defmac AC_TYPE_OFF_T
5396 @acindex{TYPE_OFF_T}
5397 @cvindex off_t
5398 Equivalent to @samp{AC_CHECK_TYPE(off_t, long int)}.
5399 @end defmac
5401 @defmac AC_TYPE_PID_T
5402 @acindex{TYPE_PID_T}
5403 @cvindex pid_t
5404 Equivalent to @samp{AC_CHECK_TYPE(pid_t, int)}.
5405 @end defmac
5407 @defmac AC_TYPE_SIGNAL
5408 @acindex{TYPE_SIGNAL}
5409 @cvindex RETSIGTYPE
5410 @hdrindex{signal.h}
5411 If @file{signal.h} declares @code{signal} as returning a pointer to a
5412 function returning @code{void}, define @code{RETSIGTYPE} to be
5413 @code{void}; otherwise, define it to be @code{int}.
5415 Define signal handlers as returning type @code{RETSIGTYPE}:
5417 @example
5418 @group
5419 RETSIGTYPE
5420 hup_handler ()
5422 @dots{}
5424 @end group
5425 @end example
5426 @end defmac
5428 @defmac AC_TYPE_SIZE_T
5429 @acindex{TYPE_SIZE_T}
5430 @cvindex size_t
5431 Equivalent to @samp{AC_CHECK_TYPE(size_t, unsigned int)}.
5432 @end defmac
5434 @defmac AC_TYPE_UID_T
5435 @acindex{TYPE_UID_T}
5436 @cvindex uid_t
5437 @cvindex gid_t
5438 If @code{uid_t} is not defined, define @code{uid_t} to be @code{int} and
5439 @code{gid_t} to be @code{int}.
5440 @end defmac
5442 @node Generic Types
5443 @subsection Generic Type Checks
5445 These macros are used to check for types not covered by the ``particular''
5446 test macros.
5448 @defmac AC_CHECK_TYPE (@var{type}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5449 @acindex{CHECK_TYPE}
5450 Check whether @var{type} is defined.  It may be a compiler builtin type
5451 or defined by the @var{includes} (@pxref{Default Includes}).
5452 @end defmac
5455 @defmac AC_CHECK_TYPES (@var{types}, @ovar{action-if-found}, @ovar{action-if-not-found}, @dvar{includes, default-includes})
5456 @acindex{CHECK_TYPES}
5457 For each @var{type} of the @var{types} that is defined, define
5458 @code{HAVE_@var{type}} (in all capitals).  If no @var{includes} are
5459 specified, the default includes are used (@pxref{Default Includes}).  If
5460 @var{action-if-found} is given, it is additional shell code to execute
5461 when one of the types is found.  If @var{action-if-not-found} is given,
5462 it is executed when one of the types is not found.
5464 This macro uses m4 lists:
5465 @example
5466 AC_CHECK_TYPES(ptrdiff_t)
5467 AC_CHECK_TYPES([unsigned long long int, uintmax_t])
5468 @end example
5470 @end defmac
5472 Autoconf, up to 2.13, used to provide to another version of
5473 @code{AC_CHECK_TYPE}, broken by design.  In order to keep backward
5474 compatibility, a simple heuristics, quite safe but not totally, is
5475 implemented.  In case of doubt, read the documentation of the former
5476 @code{AC_CHECK_TYPE}, see @ref{Obsolete Macros}.
5479 @node Compilers and Preprocessors
5480 @section Compilers and Preprocessors
5481 @cindex Compilers
5482 @cindex Preprocessors
5484 @ovindex EXEEXT
5485 All the tests for compilers (@code{AC_PROG_CC}, @code{AC_PROG_CXX},
5486 @code{AC_PROG_F77}) define the output variable @code{EXEEXT} based on
5487 the output of the compiler, typically to the empty string if
5488 Posix and @samp{.exe} if a @acronym{DOS} variant.
5490 @ovindex OBJEXT
5491 They also define the output variable @code{OBJEXT} based on the
5492 output of the compiler, after @file{.c} files have been excluded, typically
5493 to @samp{o} if Posix, @samp{obj} if a @acronym{DOS} variant.
5495 If the compiler being used does not produce executables, the tests fail.  If
5496 the executables can't be run, and cross-compilation is not enabled, they
5497 fail too.  @xref{Manual Configuration}, for more on support for cross
5498 compiling.
5500 @menu
5501 * Specific Compiler Characteristics::  Some portability issues
5502 * Generic Compiler Characteristics::  Language independent tests and features
5503 * C Compiler::                  Checking its characteristics
5504 * C++ Compiler::                Likewise
5505 * Fortran Compiler::            Likewise
5506 @end menu
5508 @node Specific Compiler Characteristics
5509 @subsection Specific Compiler Characteristics
5511 Some compilers exhibit different behaviors.
5513 @table @asis
5514 @item Static/Dynamic Expressions
5515 Autoconf relies on a trick to extract one bit of information from the C
5516 compiler: using negative array sizes.  For instance the following
5517 excerpt of a C source demonstrates how to test whether @samp{int}s are 4
5518 bytes wide:
5520 @example
5522 main (void)
5524   static int test_array [sizeof (int) == 4 ? 1 : -1];
5525   test_array [0] = 0;
5526   return 0;
5528 @end example
5530 @noindent
5531 To our knowledge, there is a single compiler that does not support this
5532 trick: the HP C compilers (the real one, not only the ``bundled'') on
5533 HP-UX 11.00:
5535 @example
5536 $ @kbd{cc -c -Ae +O2 +Onolimit conftest.c}
5537 cc: "conftest.c": error 1879: Variable-length arrays cannot \
5538     have static storage.
5539 @end example
5541 Autoconf works around this problem by casting @code{sizeof (int)} to
5542 @code{long int} before comparing it.
5543 @end table
5545 @node Generic Compiler Characteristics
5546 @subsection Generic Compiler Characteristics
5548 @defmac AC_CHECK_SIZEOF (@var{type}, @ovar{unused}, @dvar{includes, default-includes})
5549 @acindex{CHECK_SIZEOF}
5550 Define @code{SIZEOF_@var{type}} (@pxref{Standard Symbols}) to be the
5551 size in bytes of @var{type}.  If @samp{type} is unknown, it gets a size
5552 of 0.  If no @var{includes} are specified, the default includes are used
5553 (@pxref{Default Includes}).  If you provide @var{include}, be sure to
5554 include @file{stdio.h} which is required for this macro to run.
5556 This macro now works even when cross-compiling.  The @var{unused}
5557 argument was used when cross-compiling.
5559 For example, the call
5561 @example
5562 AC_CHECK_SIZEOF(int *)
5563 @end example
5565 @noindent
5566 defines @code{SIZEOF_INT_P} to be 8 on DEC Alpha AXP systems.
5567 @end defmac
5569 @defmac AC_CHECK_ALIGNOF (@var{type}, @dvar{includes, default-includes})
5570 @acindex{CHECK_ALIGNOF}
5571 Define @code{ALIGNOF_@var{type}} (@pxref{Standard Symbols}) to be the
5572 alignment in bytes of @var{type}.  If @samp{type} is unknown, it gets a size
5573 of 0.  If no @var{includes} are specified, the default includes are used
5574 (@pxref{Default Includes}).  If you provide @var{include}, be sure to
5575 include @file{stddef.h} and @file{stdio.h} which are required for this
5576 macro to work correctly.
5577 @end defmac
5579 @defmac AC_LANG_WERROR
5580 @acindex{LANG_WERROR}
5581 Normally Autoconf ignores warnings generated by the compiler, linker, and
5582 preprocessor.  If this macro is used, warnings will be treated as fatal
5583 errors instead for the current language.  This macro is useful when the
5584 results of configuration will be used where warnings are unacceptable; for
5585 instance, if parts of a program are built with the GCC @samp{-Werror}
5586 option.  If the whole program will be built using @samp{-Werror} it is
5587 often simpler to put @samp{-Werror} in the compiler flags (@code{CFLAGS},
5588 etc.).
5589 @end defmac
5591 @node C Compiler
5592 @subsection C Compiler Characteristics
5594 The following macros provide ways to find and exercise a C Compiler.
5595 There are a few constructs that ought to be avoided, but do not deserve
5596 being checked for, since they can easily be worked around.
5598 @table @asis
5599 @item Don't use lines containing solitary backslashes
5600 They tickle a bug in the HP-UX C compiler (checked on HP-UX 10.20,
5601 11.00, and 11i).  Running the compiler on the following source,
5603 @example
5604 #ifdef __STDC__
5606 * A comment with backslash-newlines in it.  %@{ %@} *\
5609 char str[] = "\\
5610 " A string with backslash-newlines in it %@{ %@} \\
5612 char apostrophe = '\\
5616 #endif
5617 @end example
5619 @noindent
5620 yields
5622 @example
5623 @error{}cpp: "foo.c", line 13: error 4048: Non-terminating comment at end of file.
5624 @error{}cpp: "foo.c", line 13: error 4033: Missing #endif at end of file.
5625 @end example
5627 @noindent
5628 Removing the lines with solitary backslashes solves the problem.
5630 @item Don't compile several files at once if output matters to you
5631 Some compilers, such as the HP's, reports the name of the file it is
5632 compiling @emph{when} they are several.  For instance:
5634 @example
5635 $ @kbd{cc a.c b.c}
5636 a.c:
5637 b.c:
5638 @end example
5640 @noindent
5641 This can cause problems if you observe the output of the compiler to
5642 detect failures.  Invoking @samp{cc -c a.c && cc -c b.c && cc -o c a.o
5643 b.o} solves the issue.
5645 @item Don't rely on correct @code{#line} support
5646 On Solaris 8, @command{c89} (Sun WorkShop 6 update 2 C 5.3 Patch
5647 111679-08 2002/05/09)) rejects @code{#line} directives whose line
5648 numbers are greater than 32767.  In addition, nothing in @sc{posix}
5649 makes this invalid.  That is the reason why Autoconf stopped issuing
5650 @code{#line} directives.
5651 @end table
5653 @defmac AC_PROG_CC (@ovar{compiler-search-list})
5654 @acindex{PROG_CC}
5655 @ovindex CC
5656 @ovindex CFLAGS
5657 Determine a C compiler to use.  If @code{CC} is not already set in the
5658 environment, check for @code{gcc} and @code{cc}, then for other C
5659 compilers.  Set output variable @code{CC} to the name of the compiler
5660 found.
5662 This macro may, however, be invoked with an optional first argument
5663 which, if specified, must be a space separated list of C compilers to
5664 search for.  This just gives the user an opportunity to specify an
5665 alternative search list for the C compiler.  For example, if you didn't
5666 like the default order, then you could invoke @code{AC_PROG_CC} like
5667 this:
5669 @example
5670 AC_PROG_CC(cl egcs gcc cc)
5671 @end example
5673 If the C compiler is not in @acronym{ANSI} mode by default, try to add an
5674 option to output variable @code{CC} to make it so.  This macro tries
5675 various options that select @acronym{ANSI} C on some system or another.  It
5676 considers the compiler to be in @acronym{ANSI} mode if it handles function
5677 prototypes correctly.
5679 After calling this macro you can check whether the C compiler has been
5680 set to accept @acronym{ANSI} C; if not, the shell variable
5681 @code{ac_cv_prog_cc_c89} is set to @samp{no}.  If you wrote your source
5682 code in @acronym{ANSI} C, you can make an un-@acronym{ANSI}fied copy of it by
5683 using the program @code{ansi2knr}, which comes with Automake.  See also
5684 under @code{AC_C_PROTOTYPES} below.
5686 If using the @acronym{GNU} C compiler, set shell variable @code{GCC} to
5687 @samp{yes}.  If output variable @code{CFLAGS} was not already set, set
5688 it to @option{-g -O2} for the @acronym{GNU} C compiler (@option{-O2} on systems
5689 where GCC does not accept @option{-g}), or @option{-g} for other compilers.
5690 @end defmac
5692 @defmac AC_PROG_CC_C_O
5693 @acindex{PROG_CC_C_O}
5694 @cvindex NO_MINUS_C_MINUS_O
5695 If the C compiler does not accept the @option{-c} and @option{-o} options
5696 simultaneously, define @code{NO_MINUS_C_MINUS_O}.  This macro actually
5697 tests both the compiler found by @code{AC_PROG_CC}, and, if different,
5698 the first @code{cc} in the path.  The test fails if one fails.  This
5699 macro was created for @acronym{GNU} Make to choose the default C compilation
5700 rule.
5701 @end defmac
5704 @defmac AC_PROG_CPP
5705 @acindex{PROG_CPP}
5706 @ovindex CPP
5707 Set output variable @code{CPP} to a command that runs the
5708 C preprocessor.  If @samp{$CC -E} doesn't work, @file{/lib/cpp} is used.
5709 It is only portable to run @code{CPP} on files with a @file{.c}
5710 extension.
5712 Some preprocessors don't indicate missing include files by the error
5713 status.  For such preprocessors an internal variable is set that causes
5714 other macros to check the standard error from the preprocessor and
5715 consider the test failed if any warnings have been reported.
5716 For most preprocessors, though, warnings do not cause include-file
5717 tests to fail unless @code{AC_PROG_CPP_WERROR} is also specified.
5718 @end defmac
5720 @defmac AC_PROG_CPP_WERROR
5721 @acindex{PROG_CPP_WERROR}
5722 @ovindex CPP
5723 This acts like @code{AC_PROG_CPP}, except it treats warnings from the
5724 preprocessor as errors even if the preprocessor exit status indicates
5725 success.  This is useful for avoiding headers that generate mandatory
5726 warnings, such as deprecation notices.
5727 @end defmac
5730 The following macros check for C compiler or machine architecture
5731 features.  To check for characteristics not listed here, use
5732 @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}) or
5733 @code{AC_RUN_IFELSE} (@pxref{Run Time}).
5735 @defmac AC_PROG_CC_STDC
5736 @acindex{PROG_CC_STDC}
5737 If the C compiler is not able to compile ISO Standard C (currently ISO
5738 C99), try to add an option to output variable @code{CC} to make it so.
5739 If the compiler does not support ISO C99, fall back to supporting
5740 @acronym{ANSI} C89 (ISO C90).
5742 After calling this macro you can check whether the C compiler has been
5743 set to accept ISO Standard C; if not, the shell variable
5744 @code{ac_cv_prog_cc_stdc} is set to @samp{no}.
5745 @end defmac
5747 @defmac AC_PROG_CC_C89
5748 @acindex{PROG_CC_C89}
5749 If the C compiler is not in @acronym{ANSI} C89 (ISO C90) mode by
5750 default, try to add an option to output variable @code{CC} to make it
5751 so.  This macro tries various options that select @acronym{ANSI} C89 on
5752 some system or another.  It considers the compiler to be in
5753 @acronym{ANSI} C89 mode if it handles function prototypes correctly.
5755 After calling this macro you can check whether the C compiler has been
5756 set to accept @acronym{ANSI} C89; if not, the shell variable
5757 @code{ac_cv_prog_cc_c89} is set to @samp{no}.
5759 This macro is called automatically by @code{AC_PROG_CC}.
5760 @end defmac
5762 @defmac AC_PROG_CC_C99
5763 @acindex{PROG_CC_C99}
5764 If the C compiler is not in ISO C99 mode by default, try to add an
5765 option to output variable @code{CC} to make it so.  This macro tries
5766 various options that select ISO C99 on some system or another.  It
5767 considers the compiler to be in ISO C99 mode if it handles @code{_Bool},
5768 flexible arrays, @code{inline}, @code{long long}, mixed code and
5769 declarations, named initialization of structs, @code{restrict}, varargs
5770 macros, variable declarations in @code{for} loops and variable length
5771 arrays.
5773 After calling this macro you can check whether the C compiler has been
5774 set to accept ISO C99; if not, the shell variable
5775 @code{ac_cv_prog_cc_c99} is set to @samp{no}.
5776 @end defmac
5778 @defmac AC_C_BACKSLASH_A
5779 @acindex{HAVE_C_BACKSLASH_A}
5780 Define @samp{HAVE_C_BACKSLASH_A} to 1 if the C compiler understands
5781 @samp{\a}.
5782 @end defmac
5784 @defmac AC_C_BIGENDIAN (@ovar{action-if-true}, @ovar{action-if-false}, @ovar{action-if-unknown})
5785 @acindex{C_BIGENDIAN}
5786 @cvindex WORDS_BIGENDIAN
5787 @cindex Endianness
5788 If words are stored with the most significant byte first (like Motorola
5789 and SPARC CPUs), execute @var{action-if-true}.  If words are stored with
5790 the least significant byte first (like Intel and VAX CPUs), execute
5791 @var{action-if-false}.
5793 This macro runs a test-case if endianness cannot be determined from the
5794 system header files.  When cross-compiling, the test-case is not run but
5795 grep'ed for some magic values.  @var{action-if-unknown} is executed if
5796 the latter case fails to determine the byte sex of the host system.
5798 The default for @var{action-if-true} is to define
5799 @samp{WORDS_BIGENDIAN}.  The default for @var{action-if-false} is to do
5800 nothing.  And finally, the default for @var{action-if-unknown} is to
5801 abort configure and tell the installer which variable he should preset
5802 to bypass this test.
5803 @end defmac
5805 @defmac AC_C_CONST
5806 @acindex{C_CONST}
5807 @cvindex const
5808 If the C compiler does not fully support the @acronym{ANSI} C qualifier
5809 @code{const}, define @code{const} to be empty.  Some C compilers that do
5810 not define @code{__STDC__} do support @code{const}; some compilers that
5811 define @code{__STDC__} do not completely support @code{const}.  Programs
5812 can simply use @code{const} as if every C compiler supported it; for
5813 those that don't, the @file{Makefile} or configuration header file will
5814 define it as empty.
5816 Occasionally installers use a C++ compiler to compile C code, typically
5817 because they lack a C compiler.  This causes problems with @code{const},
5818 because C and C++ treat @code{const} differently.  For example:
5820 @example
5821 const int foo;
5822 @end example
5824 @noindent
5825 is valid in C but not in C++.  These differences unfortunately cannot be
5826 papered over by defining @code{const} to be empty.
5828 If @command{autoconf} detects this situation, it leaves @code{const} alone,
5829 as this generally yields better results in practice.  However, using a
5830 C++ compiler to compile C code is not recommended or supported, and
5831 installers who run into trouble in this area should get a C compiler
5832 like GCC to compile their C code.
5833 @end defmac
5835 @defmac AC_C_RESTRICT
5836 @acindex{C_RESTRICT}
5837 @cvindex restrict
5838 If the C compiler recognizes the @code{restrict} keyword, don't do anything.
5839 If it recognizes only a variant spelling (@code{__restrict},
5840 @code{__restrict__}, or @code{_Restrict}), then define
5841 @code{restrict} to that.
5842 Otherwise, define @code{restrict} to be empty.
5843 Thus, programs may simply use @code{restrict} as if every C compiler
5844 supported it; for those that do not, the @file{Makefile}
5845 or configuration header defines it away.
5847 Although support in C++ for the @code{restrict} keyword is not
5848 required, several C++ compilers do accept the keyword.
5849 This macro works for them, too.
5850 @end defmac
5852 @defmac AC_C_VOLATILE
5853 @acindex{C_VOLATILE}
5854 @cvindex volatile
5855 If the C compiler does not understand the keyword @code{volatile},
5856 define @code{volatile} to be empty.  Programs can simply use
5857 @code{volatile} as if every C compiler supported it; for those that do
5858 not, the @file{Makefile} or configuration header will define it as
5859 empty.
5861 If the correctness of your program depends on the semantics of
5862 @code{volatile}, simply defining it to be empty does, in a sense, break
5863 your code.  However, given that the compiler does not support
5864 @code{volatile}, you are at its mercy anyway.  At least your
5865 program will compile, when it wouldn't before.
5867 In general, the @code{volatile} keyword is a feature of @acronym{ANSI} C, so
5868 you might expect that @code{volatile} is available only when
5869 @code{__STDC__} is defined.  However, Ultrix 4.3's native compiler does
5870 support volatile, but does not define @code{__STDC__}.
5871 @end defmac
5873 @defmac AC_C_INLINE
5874 @acindex{C_INLINE}
5875 @cvindex inline
5876 If the C compiler supports the keyword @code{inline}, do nothing.
5877 Otherwise define @code{inline} to @code{__inline__} or @code{__inline}
5878 if it accepts one of those, otherwise define @code{inline} to be empty.
5879 @end defmac
5881 @defmac AC_C_CHAR_UNSIGNED
5882 @acindex{C_CHAR_UNSIGNED}
5883 @cvindex __CHAR_UNSIGNED__
5884 If the C type @code{char} is unsigned, define @code{__CHAR_UNSIGNED__},
5885 unless the C compiler predefines it.
5886 @end defmac
5888 @defmac AC_C_LONG_DOUBLE
5889 @acindex{C_LONG_DOUBLE}
5890 @cvindex HAVE_LONG_DOUBLE
5891 If the C compiler supports a working @code{long double} type with more
5892 range or precision than the @code{double} type, define
5893 @code{HAVE_LONG_DOUBLE}.
5894 @end defmac
5896 @defmac AC_C_STRINGIZE
5897 @acindex{C_STRINGIZE}
5898 @cvindex HAVE_STRINGIZE
5899 If the C preprocessor supports the stringizing operator, define
5900 @code{HAVE_STRINGIZE}.  The stringizing operator is @samp{#} and is
5901 found in macros such as this:
5903 @example
5904 #define x(y) #y
5905 @end example
5906 @end defmac
5908 @defmac AC_C_PROTOTYPES
5909 @acindex{C_PROTOTYPES}
5910 @cvindex PROTOTYPES
5911 @cvindex __PROTOTYPES
5912 @cvindex PARAMS
5913 If function prototypes are understood by the compiler (as determined by
5914 @code{AC_PROG_CC}), define @code{PROTOTYPES} and @code{__PROTOTYPES}.
5915 In the case the compiler does not handle
5916 prototypes, you should use @code{ansi2knr}, which comes with the
5917 Automake distribution, to unprotoize function definitions.  For
5918 function prototypes, you should first define @code{PARAMS}:
5920 @example
5921 #ifndef PARAMS
5922 # if PROTOTYPES
5923 #  define PARAMS(protos) protos
5924 # else /* no PROTOTYPES */
5925 #  define PARAMS(protos) ()
5926 # endif /* no PROTOTYPES */
5927 #endif
5928 @end example
5930 @noindent
5931 then use it this way:
5933 @example
5934 size_t my_strlen PARAMS ((const char *));
5935 @end example
5936 @end defmac
5938 This macro also defines @code{__PROTOTYPES}; this is for the benefit of
5939 header files that cannot use macros that infringe on user name space.
5941 @defmac AC_PROG_GCC_TRADITIONAL
5942 @acindex{PROG_GCC_TRADITIONAL}
5943 @ovindex CC
5944 Add @option{-traditional} to output variable @code{CC} if using the
5945 @acronym{GNU} C compiler and @code{ioctl} does not work properly without
5946 @option{-traditional}.  That usually happens when the fixed header files
5947 have not been installed on an old system.  Since recent versions of the
5948 @acronym{GNU} C compiler fix the header files automatically when installed,
5949 this is becoming a less prevalent problem.
5950 @end defmac
5953 @node C++ Compiler
5954 @subsection C++ Compiler Characteristics
5957 @defmac AC_PROG_CXX (@ovar{compiler-search-list})
5958 @acindex{PROG_CXX}
5959 @ovindex CXX
5960 @ovindex CXXFLAGS
5961 Determine a C++ compiler to use.  Check whether the environment variable
5962 @code{CXX} or @code{CCC} (in that order) is set; if so, then set output
5963 variable @code{CXX} to its value.
5965 Otherwise, if the macro is invoked without an argument, then search for
5966 a C++ compiler under the likely names (first @code{g++} and @code{c++}
5967 then other names).  If none of those checks succeed, then as a last
5968 resort set @code{CXX} to @code{g++}.
5970 This macro may, however, be invoked with an optional first argument
5971 which, if specified, must be a space separated list of C++ compilers to
5972 search for.  This just gives the user an opportunity to specify an
5973 alternative search list for the C++ compiler.  For example, if you
5974 didn't like the default order, then you could invoke @code{AC_PROG_CXX}
5975 like this:
5977 @example
5978 AC_PROG_CXX(cl KCC CC cxx cc++ xlC aCC c++ g++ egcs gcc)
5979 @end example
5981 If using the @acronym{GNU} C++ compiler, set shell variable @code{GXX} to
5982 @samp{yes}.  If output variable @code{CXXFLAGS} was not already set, set
5983 it to @option{-g -O2} for the @acronym{GNU} C++ compiler (@option{-O2} on
5984 systems where G++ does not accept @option{-g}), or @option{-g} for other
5985 compilers.
5986 @end defmac
5988 @defmac AC_PROG_CXXCPP
5989 @acindex{PROG_CXXCPP}
5990 @ovindex CXXCPP
5991 Set output variable @code{CXXCPP} to a command that runs the C++
5992 preprocessor.  If @samp{$CXX -E} doesn't work, @file{/lib/cpp} is used.
5993 It is only portable to run @code{CXXCPP} on files with a @file{.c},
5994 @file{.C}, or @file{.cc} extension.
5996 Some preprocessors don't indicate missing include files by the error
5997 status.  For such preprocessors an internal variable is set that causes
5998 other macros to check the standard error from the preprocessor and
5999 consider the test failed if any warnings have been reported.  However,
6000 it is not known whether such broken preprocessors exist for C++.
6001 @end defmac
6005 @node Fortran Compiler
6006 @subsection Fortran Compiler Characteristics
6007 @cindex Fortran
6008 @cindex F77
6010 The Autoconf Fortran support is divided into two categories: legacy
6011 Fortran 77 macros (@code{F77}), and modern Fortran macros (@code{FC}).
6012 The former are intended for traditional Fortran 77 code, and have output
6013 variables like @code{F77}, @code{FFLAGS}, and @code{FLIBS}.  The latter
6014 are for newer programs that can (or must) compile under the newer
6015 Fortran standards, and have output variables like @code{FC},
6016 @code{FCFLAGS}, and @code{FCLIBS}.
6018 Except for two new macros @code{AC_FC_SRCEXT} and
6019 @code{AC_FC_FREEFORM} (see below), the @code{FC} and @code{F77} macros
6020 behave almost identically, and so they are documented together in this
6021 section.
6024 @defmac AC_PROG_F77 (@ovar{compiler-search-list})
6025 @acindex{PROG_F77}
6026 @ovindex F77
6027 @ovindex FFLAGS
6028 Determine a Fortran 77 compiler to use.  If @code{F77} is not already
6029 set in the environment, then check for @code{g77} and @code{f77}, and
6030 then some other names.  Set the output variable @code{F77} to the name
6031 of the compiler found.
6033 This macro may, however, be invoked with an optional first argument
6034 which, if specified, must be a space separated list of Fortran 77
6035 compilers to search for.  This just gives the user an opportunity to
6036 specify an alternative search list for the Fortran 77 compiler.  For
6037 example, if you didn't like the default order, then you could invoke
6038 @code{AC_PROG_F77} like this:
6040 @example
6041 AC_PROG_F77(fl32 f77 fort77 xlf g77 f90 xlf90)
6042 @end example
6044 If using @code{g77} (the @acronym{GNU} Fortran 77 compiler), then
6045 @code{AC_PROG_F77} will set the shell variable @code{G77} to @samp{yes}.
6046 If the output variable @code{FFLAGS} was not already set in the
6047 environment, then set it to @option{-g -02} for @code{g77} (or @option{-O2}
6048 where @code{g77} does not accept @option{-g}).  Otherwise, set
6049 @code{FFLAGS} to @option{-g} for all other Fortran 77 compilers.
6050 @end defmac
6052 @defmac AC_PROG_FC (@ovar{compiler-search-list}, @ovar{dialect})
6053 @acindex{PROG_FC}
6054 @ovindex FC
6055 @ovindex FCFLAGS
6056 Determine a Fortran compiler to use.  If @code{FC} is not already set in
6057 the environment, then @code{dialect} is a hint to indicate what Fortran
6058 dialect to search for; the default is to search for the newest available
6059 dialect.  Set the output variable @code{FC} to the name of the compiler
6060 found.
6062 By default, newer dialects are preferred over older dialects, but if
6063 @code{dialect} is specified then older dialects are preferred starting
6064 with the specified dialect.  @code{dialect} can currently be one of
6065 Fortran 77, Fortran 90, or Fortran 95.  However, this is only a hint of
6066 which compiler @emph{name} to prefer (e.g., @code{f90} or @code{f95}),
6067 and no attempt is made to guarantee that a particular language standard
6068 is actually supported.  Thus, it is preferable that you avoid the
6069 @code{dialect} option, and use AC_PROG_FC only for code compatible with
6070 the latest Fortran standard.
6072 This macro may, alternatively, be invoked with an optional first argument
6073 which, if specified, must be a space separated list of Fortran
6074 compilers to search for, just as in @code{AC_PROG_F77}.
6076 If the output variable @code{FCFLAGS} was not already set in the
6077 environment, then set it to @option{-g -02} for GNU @code{g77} (or
6078 @option{-O2} where @code{g77} does not accept @option{-g}).  Otherwise,
6079 set @code{FCFLAGS} to @option{-g} for all other Fortran compilers.
6080 @end defmac
6082 @defmac AC_PROG_F77_C_O
6083 @defmacx AC_PROG_FC_C_O
6084 @acindex{PROG_F77_C_O}
6085 @acindex{PROG_FC_C_O}
6086 @cvindex F77_NO_MINUS_C_MINUS_O
6087 @cvindex FC_NO_MINUS_C_MINUS_O
6088 Test whether the Fortran compiler accepts the options @option{-c} and
6089 @option{-o} simultaneously, and define @code{F77_NO_MINUS_C_MINUS_O} or
6090 @code{FC_NO_MINUS_C_MINUS_O}, respectively, if it does not.
6091 @end defmac
6093 The following macros check for Fortran compiler characteristics.
6094 To check for characteristics not listed here, use
6095 @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}) or
6096 @code{AC_RUN_IFELSE} (@pxref{Run Time}), making sure to first set the
6097 current language to Fortran 77 or Fortran via @code{AC_LANG(Fortran 77)}
6098 or @code{AC_LANG(Fortran)} (@pxref{Language Choice}).
6101 @defmac AC_F77_LIBRARY_LDFLAGS
6102 @defmacx AC_FC_LIBRARY_LDFLAGS
6103 @acindex{F77_LIBRARY_LDFLAGS}
6104 @ovindex FLIBS
6105 @acindex{FC_LIBRARY_LDFLAGS}
6106 @ovindex FCLIBS
6107 Determine the linker flags (e.g., @option{-L} and @option{-l}) for the
6108 @dfn{Fortran intrinsic and run-time libraries} that are required to
6109 successfully link a Fortran program or shared library.  The output
6110 variable @code{FLIBS} or @code{FCLIBS} is set to these flags (which
6111 should be include after @code{LIBS} when linking).
6113 This macro is intended to be used in those situations when it is
6114 necessary to mix, e.g., C++ and Fortran source code in a single
6115 program or shared library (@pxref{Mixing Fortran 77 With C and C++,,,
6116 automake, @acronym{GNU} Automake}).
6118 For example, if object files from a C++ and Fortran compiler must be
6119 linked together, then the C++ compiler/linker must be used for linking
6120 (since special C++-ish things need to happen at link time like calling
6121 global constructors, instantiating templates, enabling exception
6122 support, etc.).
6124 However, the Fortran intrinsic and run-time libraries must be linked in
6125 as well, but the C++ compiler/linker doesn't know by default how to add
6126 these Fortran 77 libraries.  Hence, this macro was created to determine
6127 these Fortran libraries.
6129 The macros @code{AC_F77_DUMMY_MAIN}/@code{AC_FC_DUMMY_MAIN} or
6130 @code{AC_F77_MAIN}/@code{AC_FC_MAIN} will probably also be necessary to
6131 link C/C++ with Fortran; see below.
6132 @end defmac
6134 @defmac AC_F77_DUMMY_MAIN (@ovar{action-if-found}, @ovar{action-if-not-found})
6135 @defmacx AC_FC_DUMMY_MAIN (@ovar{action-if-found}, @ovar{action-if-not-found})
6136 @acindex{F77_DUMMY_MAIN}
6137 @cvindex F77_DUMMY_MAIN
6138 With many compilers, the Fortran libraries detected by
6139 @code{AC_F77_LIBRARY_LDFLAGS} or @code{AC_FC_LIBRARY_LDFLAGS} provide
6140 their own @code{main} entry function that initializes things like
6141 Fortran I/O, and which then calls a user-provided entry function named
6142 (say) @code{MAIN__} to run the user's program.  The
6143 @code{AC_F77_DUMMY_MAIN}/@code{AC_FC_DUMMY_MAIN} or
6144 @code{AC_F77_MAIN}/@code{AC_FC_MAIN} macro figures out how to deal with
6145 this interaction.
6147 When using Fortran for purely numerical functions (no I/O, etc.)@: often
6148 one prefers to provide one's own @code{main} and skip the Fortran
6149 library initializations.  In this case, however, one may still need to
6150 provide a dummy @code{MAIN__} routine in order to prevent linking errors
6151 on some systems.  @code{AC_F77_DUMMY_MAIN} or @code{AC_FC_DUMMY_MAIN}
6152 detects whether any such routine is @emph{required} for linking, and
6153 what its name is; the shell variable @code{F77_DUMMY_MAIN} or
6154 @code{FC_DUMMY_MAIN} holds this name, @code{unknown} when no solution
6155 was found, and @code{none} when no such dummy main is needed.
6157 By default, @var{action-if-found} defines @code{F77_DUMMY_MAIN} or
6158 @code{FC_DUMMY_MAIN} to the name of this routine (e.g., @code{MAIN__})
6159 @emph{if} it is required.  @ovar{action-if-not-found} defaults to
6160 exiting with an error.
6162 In order to link with Fortran routines, the user's C/C++ program should
6163 then include the following code to define the dummy main if it is
6164 needed:
6166 @example
6167 #ifdef F77_DUMMY_MAIN
6168 #  ifdef __cplusplus
6169      extern "C"
6170 #  endif
6171    int F77_DUMMY_MAIN() @{ return 1; @}
6172 #endif
6173 @end example
6175 (Replace @code{F77} with @code{FC} for Fortran instead of Fortran 77.)
6177 Note that this macro is called automatically from @code{AC_F77_WRAPPERS}
6178 or @code{AC_FC_WRAPPERS}; there is generally no need to call it
6179 explicitly unless one wants to change the default actions.
6180 @end defmac
6182 @defmac AC_F77_MAIN
6183 @defmacx AC_FC_MAIN
6184 @acindex{F77_MAIN}
6185 @cvindex F77_MAIN
6186 @acindex{FC_MAIN}
6187 @cvindex FC_MAIN
6188 As discussed above, many Fortran libraries allow you to provide an entry
6189 point called (say) @code{MAIN__} instead of the usual @code{main}, which
6190 is then called by a @code{main} function in the Fortran libraries that
6191 initializes things like Fortran I/O@.  The
6192 @code{AC_F77_MAIN}/@code{AC_FC_MAIN} macro detects whether it is
6193 @emph{possible} to utilize such an alternate main function, and defines
6194 @code{F77_MAIN}/@code{FC_MAIN} to the name of the function.  (If no
6195 alternate main function name is found, @code{F77_MAIN}/@code{FC_MAIN} is
6196 simply defined to @code{main}.)
6198 Thus, when calling Fortran routines from C that perform things like I/O,
6199 one should use this macro and name the "main" function
6200 @code{F77_MAIN}/@code{FC_MAIN} instead of @code{main}.
6201 @end defmac
6203 @defmac AC_F77_WRAPPERS
6204 @defmacx AC_FC_WRAPPERS
6205 @acindex{F77_WRAPPERS}
6206 @cvindex F77_FUNC
6207 @cvindex F77_FUNC_
6208 @acindex{FC_WRAPPERS}
6209 @cvindex FC_FUNC
6210 @cvindex FC_FUNC_
6211 Defines C macros @code{F77_FUNC(name,NAME)}/@code{FC_FUNC(name,NAME)}
6212 and @code{F77_FUNC_(name,NAME)}/@code{FC_FUNC_(name,NAME)} to properly
6213 mangle the names of C/C++ identifiers, and identifiers with underscores,
6214 respectively, so that they match the name-mangling scheme used by the
6215 Fortran compiler.
6217 Fortran is case-insensitive, and in order to achieve this the Fortran
6218 compiler converts all identifiers into a canonical case and format.  To
6219 call a Fortran subroutine from C or to write a C function that is
6220 callable from Fortran, the C program must explicitly use identifiers in
6221 the format expected by the Fortran compiler.  In order to do this, one
6222 simply wraps all C identifiers in one of the macros provided by
6223 @code{AC_F77_WRAPPERS} or @code{AC_FC_WRAPPERS}.  For example, suppose
6224 you have the following Fortran 77 subroutine:
6226 @example
6227       subroutine foobar(x,y)
6228       double precision x, y
6229       y = 3.14159 * x
6230       return
6231       end
6232 @end example
6234 You would then declare its prototype in C or C++ as:
6236 @example
6237 #define FOOBAR_F77 F77_FUNC(foobar,FOOBAR)
6238 #ifdef __cplusplus
6239 extern "C"  /* prevent C++ name mangling */
6240 #endif
6241 void FOOBAR_F77(double *x, double *y);
6242 @end example
6244 Note that we pass both the lowercase and uppercase versions of the
6245 function name to @code{F77_FUNC} so that it can select the right one.
6246 Note also that all parameters to Fortran 77 routines are passed as
6247 pointers (@pxref{Mixing Fortran 77 With C and C++,,, automake, @acronym{GNU}
6248 Automake}).
6250 (Replace @code{F77} with @code{FC} for Fortran instead of Fortran 77.)
6252 Although Autoconf tries to be intelligent about detecting the
6253 name-mangling scheme of the Fortran compiler, there may be Fortran
6254 compilers that it doesn't support yet.  In this case, the above code
6255 will generate a compile-time error, but some other behavior
6256 (e.g., disabling Fortran-related features) can be induced by checking
6257 whether the @code{F77_FUNC}/@code{FC_FUNC} macro is defined.
6259 Now, to call that routine from a C program, we would do something like:
6261 @example
6263     double x = 2.7183, y;
6264     FOOBAR_F77(&x, &y);
6266 @end example
6268 If the Fortran identifier contains an underscore (e.g., @code{foo_bar}),
6269 you should use @code{F77_FUNC_}/@code{FC_FUNC_} instead of
6270 @code{F77_FUNC}/@code{FC_FUNC} (with the same arguments).  This is
6271 because some Fortran compilers mangle names differently if they contain
6272 an underscore.
6273 @end defmac
6275 @defmac AC_F77_FUNC (@var{name}, @ovar{shellvar})
6276 @defmacx AC_FC_FUNC (@var{name}, @ovar{shellvar})
6277 @acindex{F77_FUNC}
6278 @acindex{FC_FUNC}
6279 Given an identifier @var{name}, set the shell variable @var{shellvar} to
6280 hold the mangled version @var{name} according to the rules of the
6281 Fortran linker (see also @code{AC_F77_WRAPPERS} or
6282 @code{AC_FC_WRAPPERS}).  @var{shellvar} is optional; if it is not
6283 supplied, the shell variable will be simply @var{name}.  The purpose of
6284 this macro is to give the caller a way to access the name-mangling
6285 information other than through the C preprocessor as above, for example,
6286 to call Fortran routines from some language other than C/C++.
6287 @end defmac
6289 @defmac AC_FC_SRCEXT (@var{ext}, @ovar{action-if-success}, @ovar{action-if-failure})
6290 @acindex{FC_SRCEXT}
6291 By default, the @code{FC} macros perform their tests using a @file{.f}
6292 extension for source-code files.  Some compilers, however, only enable
6293 newer language features for appropriately named files, e.g., Fortran 90
6294 features only for @file{.f90} files.  On the other hand, some other
6295 compilers expect all source files to end in @file{.f} and require
6296 special flags to support other file name extensions.  The
6297 @code{AC_FC_SRCEXT} macro deals with both of these issues.
6299 The @code{AC_FC_SRCEXT} tries to get the @code{FC} compiler to accept files
6300 ending with the extension .@var{ext} (i.e., @var{ext} does @emph{not}
6301 contain the dot).  If any special compiler flags are needed for this, it
6302 stores them in the output variable @code{FCFLAGS_}@var{ext}.  This
6303 extension and these flags are then used for all subsequent @code{FC} tests
6304 (until @code{AC_FC_SRCEXT} is called again).
6306 For example, you would use @code{AC_FC_SRCEXT(f90)} to employ the
6307 @file{.f90} extension in future tests, and it would set a
6308 @code{FCFLAGS_f90} output variable with any extra flags that are needed
6309 to compile such files.
6311 The @code{FCFLAGS_}@var{ext} can @emph{not} be simply absorbed into
6312 @code{FCFLAGS}, for two reasons based on the limitations of some
6313 compilers.  First, only one @code{FCFLAGS_}@var{ext} can be used at a
6314 time, so files with different extensions must be compiled separately.
6315 Second, @code{FCFLAGS_}@var{ext} must appear @emph{immediately} before
6316 the source-code file name when compiling.  So, continuing the example
6317 above, you might compile a @file{foo.f90} file in your Makefile with the
6318 command:
6320 @example
6321 foo.o: foo.f90
6322      $(FC) -c $(FCFLAGS) $(FCFLAGS_f90) foo.f90
6323 @end example
6325 If @code{AC_FC_SRCEXT} succeeds in compiling files with the @var{ext}
6326 extension, it calls @ovar{action-if-success} (defaults to nothing).  If
6327 it fails, and cannot find a way to make the @code{FC} compiler accept such
6328 files, it calls @ovar{action-if-failure} (defaults to exiting with an
6329 error message).
6331 @end defmac
6333 @defmac AC_FC_FREEFORM (@ovar{action-if-success}, @ovar{action-if-failure})
6334 @acindex{FC_FREEFORM}
6336 The @code{AC_FC_FREEFORM} tries to ensure that the Fortran compiler
6337 (@code{$FC}) allows free-format source code (as opposed to the older
6338 fixed-format style from Fortran 77).  If necessary, it may add some
6339 additional flags to @code{FCFLAGS}.
6341 This macro is most important if you are using the default @file{.f}
6342 extension, since many compilers interpret this extension as indicating
6343 fixed-format source unless an additional flag is supplied.  If you
6344 specify a different extension with @code{AC_FC_SRCEXT}, such as
6345 @file{.f90} or @file{.f95}, then @code{AC_FC_FREEFORM} will ordinarily
6346 succeed without modifying @code{FCFLAGS}.
6348 If @code{AC_FC_FREEFORM} succeeds in compiling free-form source, it
6349 calls @ovar{action-if-success} (defaults to nothing).  If it fails, it
6350 calls @ovar{action-if-failure} (defaults to exiting with an error
6351 message).
6352 @end defmac
6354 @node System Services
6355 @section System Services
6357 The following macros check for operating system services or capabilities.
6359 @defmac AC_PATH_X
6360 @acindex{PATH_X}
6361 @cindex X Window System
6362 Try to locate the X Window System include files and libraries.  If the
6363 user gave the command line options @option{--x-includes=@var{dir}} and
6364 @option{--x-libraries=@var{dir}}, use those directories.  If either or
6365 both were not given, get the missing values by running @code{xmkmf} on a
6366 trivial @file{Imakefile} and examining the @file{Makefile} that it
6367 produces.  If that fails (such as if @code{xmkmf} is not present), look
6368 for the files in several directories where they often reside.  If either
6369 method is successful, set the shell variables @code{x_includes} and
6370 @code{x_libraries} to their locations, unless they are in directories
6371 the compiler searches by default.
6373 If both methods fail, or the user gave the command line option
6374 @option{--without-x}, set the shell variable @code{no_x} to @samp{yes};
6375 otherwise set it to the empty string.
6376 @end defmac
6378 @defmac AC_PATH_XTRA
6379 @acindex{PATH_XTRA}
6380 @ovindex X_CFLAGS
6381 @ovindex X_LIBS
6382 @ovindex X_EXTRA_LIBS
6383 @ovindex X_PRE_LIBS
6384 @cvindex X_DISPLAY_MISSING
6385 An enhanced version of @code{AC_PATH_X}.  It adds the C compiler flags
6386 that X needs to output variable @code{X_CFLAGS}, and the X linker flags
6387 to @code{X_LIBS}.  Define @code{X_DISPLAY_MISSING} if X is not
6388 available.
6390 This macro also checks for special libraries that some systems need in
6391 order to compile X programs.  It adds any that the system needs to
6392 output variable @code{X_EXTRA_LIBS}.  And it checks for special X11R6
6393 libraries that need to be linked with before @option{-lX11}, and adds
6394 any found to the output variable @code{X_PRE_LIBS}.
6396 @c This is an incomplete kludge.  Make a real way to do it.
6397 @c If you need to check for other X functions or libraries yourself, then
6398 @c after calling this macro, add the contents of @code{X_EXTRA_LIBS} to
6399 @c @code{LIBS} temporarily, like this: (FIXME - add example)
6400 @end defmac
6402 @defmac AC_SYS_INTERPRETER
6403 @acindex{SYS_INTERPRETER}
6404 Check whether the system supports starting scripts with a line of the
6405 form @samp{#! /bin/csh} to select the interpreter to use for the script.
6406 After running this macro, shell code in @file{configure.ac} can check
6407 the shell variable @code{interpval}; it will be set to @samp{yes}
6408 if the system supports @samp{#!}, @samp{no} if not.
6409 @end defmac
6411 @defmac AC_SYS_LARGEFILE
6412 @acindex{SYS_LARGEFILE}
6413 @cvindex _FILE_OFFSET_BITS
6414 @cvindex _LARGE_FILES
6415 @ovindex CC
6416 @cindex Large file support
6417 @cindex LFS
6418 Arrange for
6419 @uref{http://www.unix-systems.org/version2/whatsnew/lfs20mar.html,
6420 large-file support}.  On some hosts, one must use special compiler
6421 options to build programs that can access large files.  Append any such
6422 options to the output variable @code{CC}.  Define
6423 @code{_FILE_OFFSET_BITS} and @code{_LARGE_FILES} if necessary.
6425 Large-file support can be disabled by configuring with the
6426 @option{--disable-largefile} option.
6428 If you use this macro, check that your program works even when
6429 @code{off_t} is wider than @code{long int}, since this is common when
6430 large-file support is enabled.  For example, it is not correct to print
6431 an arbitrary @code{off_t} value @code{X} with @code{printf ("%ld",
6432 (long int) X)}.
6434 The LFS introduced the @code{fseeko} and @code{ftello} functions to
6435 replace their C counterparts @code{fseek} and @code{ftell} that do not
6436 use @code{off_t}.  Take care to use @code{AC_FUNC_FSEEKO} to make their
6437 prototypes available when using them and large-file support is
6438 enabled.
6439 @end defmac
6441 @defmac AC_SYS_LONG_FILE_NAMES
6442 @acindex{SYS_LONG_FILE_NAMES}
6443 @cvindex HAVE_LONG_FILE_NAMES
6444 If the system supports file names longer than 14 characters, define
6445 @code{HAVE_LONG_FILE_NAMES}.
6446 @end defmac
6448 @defmac AC_SYS_POSIX_TERMIOS
6449 @acindex{SYS_POSIX_TERMIOS}
6450 @cindex Posix termios headers
6451 @cindex termios Posix headers
6452 Check to see if the Posix termios headers and functions are available on the
6453 system.  If so, set the shell variable @code{ac_cv_sys_posix_termios} to
6454 @samp{yes}.  If not, set the variable to @samp{no}.
6455 @end defmac
6457 @node Posix Variants
6458 @section Posix Variants
6460 The following macros check for certain operating systems that need
6461 special treatment for some programs, due to exceptional oddities in
6462 their header files or libraries.  These macros are warts; they will be
6463 replaced by a more systematic approach, based on the functions they make
6464 available or the environments they provide.
6466 @defmac AC_AIX
6467 @acindex{AIX}
6468 @cvindex _ALL_SOURCE
6469 If on @acronym{AIX}, define @code{_ALL_SOURCE}.  Allows the use of some @acronym{BSD}
6470 functions.  Should be called before any macros that run the C compiler.
6471 @end defmac
6473 @defmac AC_GNU_SOURCE
6474 @acindex{GNU_SOURCE}
6475 @cvindex _GNU_SOURCE
6476 If using the @acronym{GNU} C library, define @code{_GNU_SOURCE}.
6477 Allows the use of some @acronym{GNU} functions.  Should be called
6478 before any macros that run the C compiler.
6479 @end defmac
6481 @defmac AC_ISC_POSIX
6482 @acindex{ISC_POSIX}
6483 @ovindex LIBS
6484 For @sc{interactive} Systems Corporation Unix, add @option{-lcposix} to output
6485 variable @code{LIBS} if necessary for Posix facilities.  Call this
6486 after @code{AC_PROG_CC} and before any other macros that use Posix
6487 interfaces.  @sc{interactive} Unix is no longer sold, and Sun says that
6488 they will drop support for it on 2006-07-23, so this macro is becoming
6489 obsolescent.
6490 @end defmac
6492 @defmac AC_MINIX
6493 @acindex{MINIX}
6494 @cvindex _MINIX
6495 @cvindex _POSIX_SOURCE
6496 @cvindex _POSIX_1_SOURCE
6497 If on Minix, define @code{_MINIX} and @code{_POSIX_SOURCE} and define
6498 @code{_POSIX_1_SOURCE} to be 2.  This allows the use of Posix
6499 facilities.  Should be called before any macros that run the C compiler.
6500 @end defmac
6505 @c ========================================================= Writing Tests
6507 @node Writing Tests
6508 @chapter Writing Tests
6510 If the existing feature tests don't do something you need, you have to
6511 write new ones.  These macros are the building blocks.  They provide
6512 ways for other macros to check whether various kinds of features are
6513 available and report the results.
6515 This chapter contains some suggestions and some of the reasons why the
6516 existing tests are written the way they are.  You can also learn a lot
6517 about how to write Autoconf tests by looking at the existing ones.  If
6518 something goes wrong in one or more of the Autoconf tests, this
6519 information can help you understand the assumptions behind them, which
6520 might help you figure out how to best solve the problem.
6522 These macros check the output of the compiler system of the current
6523 language (@pxref{Language Choice}).  They do not cache the results of
6524 their tests for future use (@pxref{Caching Results}), because they don't
6525 know enough about the information they are checking for to generate a
6526 cache variable name.  They also do not print any messages, for the same
6527 reason.  The checks for particular kinds of features call these macros
6528 and do cache their results and print messages about what they're
6529 checking for.
6531 When you write a feature test that could be applicable to more than one
6532 software package, the best thing to do is encapsulate it in a new macro.
6533 @xref{Writing Autoconf Macros}, for how to do that.
6535 @menu
6536 * Language Choice::             Selecting which language to use for testing
6537 * Writing Test Programs::       Forging source files for compilers
6538 * Running the Preprocessor::    Detecting preprocessor symbols
6539 * Running the Compiler::        Detecting language or header features
6540 * Running the Linker::          Detecting library features
6541 * Run Time::                    Testing for run-time features
6542 * Systemology::                 A zoology of operating systems
6543 * Multiple Cases::              Tests for several possible values
6544 @end menu
6546 @node Language Choice
6547 @section Language Choice
6548 @cindex Language
6550 Autoconf-generated @command{configure} scripts check for the C compiler and
6551 its features by default.  Packages that use other programming languages
6552 (maybe more than one, e.g., C and C++) need to test features of the
6553 compilers for the respective languages.  The following macros determine
6554 which programming language is used in the subsequent tests in
6555 @file{configure.ac}.
6557 @defmac AC_LANG (@var{language})
6558 Do compilation tests using the compiler, preprocessor, and file
6559 extensions for the specified @var{language}.
6561 Supported languages are:
6563 @table @samp
6564 @item C
6565 Do compilation tests using @code{CC} and @code{CPP} and use extension
6566 @file{.c} for test programs.  Use compilation flags: @code{CPPFLAGS} with
6567 @code{CPP}, and both @code{CPPFLAGS} and @code{CFLAGS} with @code{CC}.
6569 @item C++
6570 Do compilation tests using @code{CXX} and @code{CXXCPP} and use
6571 extension @file{.C} for test programs.  Use compilation flags:
6572 @code{CPPFLAGS} with @code{CXXPP}, and both @code{CPPFLAGS} and
6573 @code{CXXFLAGS} with @code{CXX}.
6575 @item Fortran 77
6576 Do compilation tests using @code{F77} and use extension @file{.f} for
6577 test programs.  Use compilation flags: @code{FFLAGS}.
6579 @item Fortran
6580 Do compilation tests using @code{FC} and use extension @file{.f} (or
6581 whatever has been set by @code{AC_FC_SRCEXT}) for test programs.  Use
6582 compilation flags: @code{FCFLAGS}.
6583 @end table
6584 @end defmac
6586 @defmac AC_LANG_PUSH (@var{language})
6587 @acindex{LANG_PUSH}
6588 Remember the current language (as set by @code{AC_LANG}) on a stack, and
6589 then select the @var{language}.  Use this macro and @code{AC_LANG_POP}
6590 in macros that need to temporarily switch to a particular language.
6591 @end defmac
6593 @defmac AC_LANG_POP (@ovar{language})
6594 @acindex{LANG_POP}
6595 Select the language that is saved on the top of the stack, as set by
6596 @code{AC_LANG_PUSH}, and remove it from the stack.
6598 If given, @var{language} specifies the language we just @emph{quit}.  It
6599 is a good idea to specify it when it's known (which should be the
6600 case@dots{}), since Autoconf will detect inconsistencies.
6602 @example
6603 AC_LANG_PUSH(Fortran 77)
6604 # Perform some tests on Fortran 77.
6605 # @dots{}
6606 AC_LANG_POP(Fortran 77)
6607 @end example
6608 @end defmac
6610 @defmac AC_LANG_ASSERT (@var{language})
6611 @acindex{LANG_ASSERT} Check statically that the current language is
6612 @var{language}.  You should use this in your language specific macros
6613 to avoid that they be called with an inappropriate language.
6615 This macro runs only at @command{autoconf} time, and incurs no cost at
6616 @command{configure} time.  Sadly enough and because Autoconf is a two
6617 layer language @footnote{Because M4 is not aware of Sh code,
6618 especially conditionals, some optimizations that look nice statically
6619 may produce incorrect results at runtime.}, the macros
6620 @code{AC_LANG_PUSH}/@code{AC_LANG_POP} cannot be ``optimizing'',
6621 therefore as much as possible you ought to avoid using them to wrap
6622 your code, rather, require from the user to run the macro with a
6623 correct current language, and check it with @code{AC_LANG_ASSERT}.
6624 And anyway, that may help the user understand she is running a Fortran
6625 macro while expecting a result about her Fortran 77 compiler...
6626 @end defmac
6629 @defmac AC_REQUIRE_CPP
6630 @acindex{REQUIRE_CPP}
6631 Ensure that whichever preprocessor would currently be used for tests has
6632 been found.  Calls @code{AC_REQUIRE} (@pxref{Prerequisite Macros}) with an
6633 argument of either @code{AC_PROG_CPP} or @code{AC_PROG_CXXCPP},
6634 depending on which language is current.
6635 @end defmac
6638 @node Writing Test Programs
6639 @section Writing Test Programs
6641 Autoconf tests follow is common scheme: feeding some program with some
6642 input, and most of the time, feeding a compiler with some source file.
6643 This section is dedicated to these source samples.
6645 @menu
6646 * Guidelines::                  General rules for writing test programs
6647 * Test Functions::              Avoiding pitfalls in test programs
6648 * Generating Sources::          Source program boilerplate
6649 @end menu
6651 @node Guidelines
6652 @subsection Guidelines for Test Programs
6654 The most important rule to follow when writing testing samples is:
6656 @center @emph{Look for realism.}
6658 This motto means that testing samples must be written with the same
6659 strictness as real programs are written.  In particular, you should
6660 avoid ``shortcuts'' and simplifications.
6662 Don't just play with the preprocessor if you want to prepare a
6663 compilation.  For instance, using @command{cpp} to check whether a header is
6664 functional might let your @command{configure} accept a header which will
6665 cause some @emph{compiler} error.  Do not hesitate checking header with
6666 other headers included before, especially required headers.
6668 Make sure the symbols you use are properly defined, i.e., refrain for
6669 simply declaring a function yourself instead of including the proper
6670 header.
6672 Test programs should not write anything to the standard output.  They
6673 should return 0 if the test succeeds, nonzero otherwise, so that success
6674 can be distinguished easily from a core dump or other failure;
6675 segmentation violations and other failures produce a nonzero exit
6676 status.  Test programs should @code{exit}, not @code{return}, from
6677 @code{main}, because on some systems (old Suns, at least) the argument
6678 to @code{return} in @code{main} is ignored.
6680 Test programs can use @code{#if} or @code{#ifdef} to check the values of
6681 preprocessor macros defined by tests that have already run.  For
6682 example, if you call @code{AC_HEADER_STDC}, then later on in
6683 @file{configure.ac} you can have a test program that includes an
6684 @acronym{ANSI} C header file conditionally:
6686 @example
6687 @group
6688 #if STDC_HEADERS
6689 # include <stdlib.h>
6690 #endif
6691 @end group
6692 @end example
6694 If a test program needs to use or create a data file, give it a name
6695 that starts with @file{conftest}, such as @file{conftest.data}.  The
6696 @command{configure} script cleans up by running @samp{rm -f -r conftest*}
6697 after running test programs and if the script is interrupted.
6699 @node Test Functions
6700 @subsection Test Functions
6702 Function declarations in test programs should have a prototype
6703 conditionalized for C++.  In practice, though, test programs rarely need
6704 functions that take arguments.
6706 @example
6707 #ifdef __cplusplus
6708 foo (int i)
6709 #else
6710 foo (i) int i;
6711 #endif
6712 @end example
6714 Functions that test programs declare should also be conditionalized for
6715 C++, which requires @samp{extern "C"} prototypes.  Make sure to not
6716 include any header files containing clashing prototypes.
6718 @example
6719 #ifdef __cplusplus
6720 extern "C" void *malloc (size_t);
6721 #else
6722 void *malloc ();
6723 #endif
6724 @end example
6726 If a test program calls a function with invalid parameters (just to see
6727 whether it exists), organize the program to ensure that it never invokes
6728 that function.  You can do this by calling it in another function that is
6729 never invoked.  You can't do it by putting it after a call to
6730 @code{exit}, because GCC version 2 knows that @code{exit} never returns
6731 and optimizes out any code that follows it in the same block.
6733 If you include any header files, be sure to call the functions
6734 relevant to them with the correct number of arguments, even if they are
6735 just 0, to avoid compilation errors due to prototypes.  GCC version 2
6736 has internal prototypes for several functions that it automatically
6737 inlines; for example, @code{memcpy}.  To avoid errors when checking for
6738 them, either pass them the correct number of arguments or redeclare them
6739 with a different return type (such as @code{char}).
6742 @node Generating Sources
6743 @subsection Generating Sources
6745 Autoconf provides a set of macros that can be used to generate test
6746 source files.  They are written to be language generic, i.e., they
6747 actually depend on the current language (@pxref{Language Choice}) to
6748 ``format'' the output properly.
6751 @defmac AC_LANG_CONFTEST (@var{source})
6752 @acindex{LANG_CONFTEST}
6753 Save the @var{source} text in the current test source file:
6754 @file{conftest.@var{extension}} where the @var{extension} depends on the
6755 current language.
6757 Note that the @var{source} is evaluated exactly once, like regular
6758 Autoconf macro arguments, and therefore (i) you may pass a macro
6759 invocation, (ii) if not, be sure to double quote if needed.
6760 @end defmac
6762 @defmac AC_LANG_SOURCE (@var{source})
6763 @acindex{LANG_SOURCE}
6764 Expands into the @var{source}, with the definition of
6765 all the @code{AC_DEFINE} performed so far.
6766 @end defmac
6768 For instance executing (observe the double quotation!):
6770 @example
6771 AC_INIT(Autoconf Documentation, @value{VERSION}, bug-autoconf@@gnu.org)
6772 AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
6773   [Greetings string.])
6774 AC_LANG_CONFTEST(
6775    [AC_LANG_SOURCE([[const char hw[] = "Hello, World\n";]])])
6776 gcc -E -dD -o - conftest.c
6777 @end example
6779 @noindent
6780 results in:
6782 @example
6783 # 1 "conftest.c"
6784 # 1169 "configure"
6786 # 1 "confdefs.h" 1
6788 #define PACKAGE_NAME "Autoconf Documentation"
6789 #define PACKAGE_TARNAME "autoconf-documentation"
6790 #define PACKAGE_VERSION "@value{VERSION}"
6791 #define PACKAGE_STRING "Autoconf Documentation @value{VERSION}"
6792 #define PACKAGE_BUGREPORT "bug-autoconf@@gnu.org"
6793 #define HELLO_WORLD "Hello, World\n"
6794 # 1170 "configure" 2
6796 const char hw[] = "Hello, World\n";
6797 @end example
6799 @defmac AC_LANG_PROGRAM (@var{prologue}, @var{body})
6800 @acindex{LANG_PROGRAM}
6801 Expands into a source file which consists of the @var{prologue}, and
6802 then @var{body} as body of the main function (e.g., @code{main} in
6803 C).  Since it uses @code{AC_LANG_SOURCE}, the feature of the latter are
6804 available.
6805 @end defmac
6807 For instance:
6809 @example
6810 AC_INIT(Autoconf Documentation, @value{VERSION}, bug-autoconf@@gnu.org)
6811 AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
6812   [Greetings string.])
6813 AC_LANG_CONFTEST(
6814 [AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]],
6815                  [[fputs (hw, stdout);]])])
6816 gcc -E -dD -o - conftest.c
6817 @end example
6819 @noindent
6820 results in:
6822 @example
6823 # 1 "conftest.c"
6824 # 1169 "configure"
6826 # 1 "confdefs.h" 1
6828 #define PACKAGE_NAME "Autoconf Documentation"
6829 #define PACKAGE_TARNAME "autoconf-documentation"
6830 #define PACKAGE_VERSION "@value{VERSION}"
6831 #define PACKAGE_STRING "Autoconf Documentation @value{VERSION}"
6832 #define PACKAGE_BUGREPORT "bug-autoconf@@gnu.org"
6833 #define HELLO_WORLD "Hello, World\n"
6834 # 1170 "configure" 2
6836 const char hw[] = "Hello, World\n";
6838 main ()
6840 fputs (hw, stdout);
6841   ;
6842   return 0;
6844 @end example
6847 @defmac AC_LANG_CALL (@var{prologue}, @var{function})
6848 @acindex{LANG_CALL}
6849 Expands into a source file which consists of the @var{prologue}, and
6850 then a call to the @var{function} as body of the main function (e.g.,
6851 @code{main} in C).  Since it uses @code{AC_LANG_PROGRAMS}, the feature
6852 of the latter are available.
6854 This function will probably be replaced in the future by a version
6855 which would enable specifying the arguments.  The use of this macro is
6856 not encouraged, as it violates strongly the typing system.
6857 @end defmac
6860 @defmac AC_LANG_FUNC_LINK_TRY (@var{function})
6861 @acindex{LANG_FUNC_LINK_TRY}
6862 Expands into a source file which consists of a pseudo use of the
6863 @var{function} as body of the main function (e.g., @code{main} in C): a
6864 simple (function pointer) assignment.  Since it uses
6865 @code{AC_LANG_PROGRAMS}, the feature of the latter are available.
6867 As @code{AC_LANG_CALL}, this macro is documented only for completeness.
6868 It is considered to be severely broken, and in the future will be
6869 removed in favor of actual function calls (with properly typed
6870 arguments).
6871 @end defmac
6873 @node Running the Preprocessor
6874 @section Running the Preprocessor
6876 Sometimes one might need to run the preprocessor on some source file.
6877 @emph{Usually it is a bad idea}, as you typically need to @emph{compile}
6878 your project, not merely run the preprocessor on it; therefore you
6879 certainly want to run the compiler, not the preprocessor.  Resist the
6880 temptation of following the easiest path.
6882 Nevertheless, if you need to run the preprocessor, then use
6883 @code{AC_PREPROC_IFELSE}.
6885 @defmac AC_PREPROC_IFELSE (@var{input}, @ovar{action-if-true}, @ovar{action-if-false})
6886 @acindex{PREPROC_IFELSE}
6887 Run the preprocessor of the current language (@pxref{Language Choice})
6888 on the @var{input}, run the shell commands @var{action-if-true} on
6889 success, @var{action-if-false} otherwise.  The @var{input} can be made
6890 by @code{AC_LANG_PROGRAM} and friends.
6892 This macro uses @code{CPPFLAGS}, but not @code{CFLAGS}, because
6893 @option{-g}, @option{-O}, etc.@: are not valid options to many C
6894 preprocessors.
6896 It is customary to report unexpected failures with
6897 @code{AC_MSG_FAILURE}.
6898 @end defmac
6900 For instance:
6902 @example
6903 AC_INIT(Autoconf Documentation, @value{VERSION}, bug-autoconf@@gnu.org)
6904 AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
6905   [Greetings string.])
6906 AC_PREPROC_IFELSE(
6907    [AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]],
6908                     [[fputs (hw, stdout);]])],
6909    [AC_MSG_RESULT([OK])],
6910    [AC_MSG_FAILURE([unexpected preprocessor failure])])
6911 @end example
6913 @noindent
6914 results in:
6916 @example
6917 checking for gcc... gcc
6918 checking for C compiler default output... a.out
6919 checking whether the C compiler works... yes
6920 checking whether we are cross compiling... no
6921 checking for suffix of executables...
6922 checking for suffix of object files... o
6923 checking whether we are using the GNU C compiler... yes
6924 checking whether gcc accepts -g... yes
6925 checking for gcc option to accept ANSI C... none needed
6926 checking how to run the C preprocessor... gcc -E
6928 @end example
6930 @sp 1
6932 The macro @code{AC_TRY_CPP} (@pxref{Obsolete Macros}) used to play the
6933 role of @code{AC_PREPROC_IFELSE}, but double quotes its argument, making
6934 it impossible to use it to elaborate sources.  You are encouraged to
6935 get rid of your old use of the macro @code{AC_TRY_CPP} in favor of
6936 @code{AC_PREPROC_IFELSE}, but, in the first place, are you sure you need
6937 to run the @emph{preprocessor} and not the compiler?
6939 @defmac AC_EGREP_HEADER (@var{pattern}, @var{header-file}, @var{action-if-found}, @ovar{action-if-not-found})
6940 @acindex{EGREP_HEADER}
6941 If the output of running the preprocessor on the system header file
6942 @var{header-file} matches the extended regular expression
6943 @var{pattern}, execute shell commands @var{action-if-found}, otherwise
6944 execute @var{action-if-not-found}.
6945 @end defmac
6947 @defmac AC_EGREP_CPP (@var{pattern}, @var{program}, @ovar{action-if-found}, @ovar{action-if-not-found})
6948 @acindex{EGREP_CPP}
6949 @var{program} is the text of a C or C++ program, on which shell
6950 variable, back quote, and backslash substitutions are performed.  If the
6951 output of running the preprocessor on @var{program} matches the
6952 extended regular expression @var{pattern}, execute shell commands
6953 @var{action-if-found}, otherwise execute @var{action-if-not-found}.
6954 @end defmac
6958 @node Running the Compiler
6959 @section Running the Compiler
6961 To check for a syntax feature of the current language's (@pxref{Language
6962 Choice}) compiler, such as whether it recognizes a certain keyword, or
6963 simply to try some library feature, use @code{AC_COMPILE_IFELSE} to try
6964 to compile a small program that uses that feature.
6966 @defmac AC_COMPILE_IFELSE (@var{input}, @ovar{action-if-found}, @ovar{action-if-not-found})
6967 @acindex{COMPILE_IFELSE}
6968 Run the compiler and compilation flags of the current language
6969 (@pxref{Language Choice}) on the @var{input}, run the shell commands
6970 @var{action-if-true} on success, @var{action-if-false} otherwise.  The
6971 @var{input} can be made by @code{AC_LANG_PROGRAM} and friends.
6973 It is customary to report unexpected failures with
6974 @code{AC_MSG_FAILURE}.  This macro does not try to link; use
6975 @code{AC_LINK_IFELSE} if you need to do that (@pxref{Running the
6976 Linker}).
6977 @end defmac
6979 @node Running the Linker
6980 @section Running the Linker
6982 To check for a library, a function, or a global variable, Autoconf
6983 @command{configure} scripts try to compile and link a small program that
6984 uses it.  This is unlike Metaconfig, which by default uses @code{nm} or
6985 @code{ar} on the C library to try to figure out which functions are
6986 available.  Trying to link with the function is usually a more reliable
6987 approach because it avoids dealing with the variations in the options
6988 and output formats of @code{nm} and @code{ar} and in the location of the
6989 standard libraries.  It also allows configuring for cross-compilation or
6990 checking a function's run-time behavior if needed.  On the other hand,
6991 it can be slower than scanning the libraries once, but accuracy is more
6992 important than speed.
6994 @code{AC_LINK_IFELSE} is used to compile test programs to test for
6995 functions and global variables.  It is also used by @code{AC_CHECK_LIB}
6996 to check for libraries (@pxref{Libraries}), by adding the library being
6997 checked for to @code{LIBS} temporarily and trying to link a small
6998 program.
7001 @defmac AC_LINK_IFELSE (@var{input}, @ovar{action-if-found}, @ovar{action-if-not-found})
7002 @acindex{LINK_IFELSE}
7003 Run the compiler (and compilation flags) and the linker of the current
7004 language (@pxref{Language Choice}) on the @var{input}, run the shell
7005 commands @var{action-if-true} on success, @var{action-if-false}
7006 otherwise.  The @var{input} can be made by @code{AC_LANG_PROGRAM} and
7007 friends.
7009 @code{LDFLAGS} and @code{LIBS} are used for linking, in addition to the
7010 current compilation flags.
7012 It is customary to report unexpected failures with
7013 @code{AC_MSG_FAILURE}.  This macro does not try to execute the program;
7014 use @code{AC_RUN_IFELSE} if you need to do that (@pxref{Run Time}).
7015 @end defmac
7019 @node Run Time
7020 @section Checking Run Time Behavior
7022 Sometimes you need to find out how a system performs at run time, such
7023 as whether a given function has a certain capability or bug.  If you
7024 can, make such checks when your program runs instead of when it is
7025 configured.  You can check for things like the machine's endianness when
7026 your program initializes itself.
7028 If you really need to test for a run-time behavior while configuring,
7029 you can write a test program to determine the result, and compile and
7030 run it using @code{AC_RUN_IFELSE}.  Avoid running test programs if
7031 possible, because this prevents people from configuring your package for
7032 cross-compiling.
7034 @defmac AC_RUN_IFELSE (@var{input}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{action-if-cross-compiling})
7035 @acindex{RUN_IFELSE}
7036 If @var{program} compiles and links successfully and returns an exit
7037 status of 0 when executed, run shell commands @var{action-if-true}.
7038 Otherwise, run shell commands @var{action-if-false}.
7040 The @var{input} can be made by @code{AC_LANG_PROGRAM} and friends.
7041 @code{LDFLAGS} and @code{LIBS} are used for linking, in addition to the
7042 compilation flags of the current language (@pxref{Language Choice}).
7044 If the compiler being used does not produce executables that run on the
7045 system where @command{configure} is being run, then the test program is
7046 not run.  If the optional shell commands @var{action-if-cross-compiling}
7047 are given, they are run instead.  Otherwise, @command{configure} prints
7048 an error message and exits.
7050 In the @var{action-if-false} section, the exit status of the program is
7051 available in the shell variable @samp{$?}, but be very careful to limit
7052 yourself to positive values smaller than 127; bigger values should be
7053 saved into a file by the @var{program}.  Note also that you have simply
7054 no guarantee that this exit status is issued by the @var{program}, or by
7055 the failure of its compilation.  In other words, use this feature if
7056 sadist only, it was reestablished because the Autoconf maintainers grew
7057 tired of receiving ``bug reports''.
7059 It is customary to report unexpected failures with
7060 @code{AC_MSG_FAILURE}.
7061 @end defmac
7063 Try to provide a pessimistic default value to use when cross-compiling
7064 makes run-time tests impossible.  You do this by passing the optional
7065 last argument to @code{AC_RUN_IFELSE}.  @command{autoconf} prints a
7066 warning message when creating @command{configure} each time it
7067 encounters a call to @code{AC_RUN_IFELSE} with no
7068 @var{action-if-cross-compiling} argument given.  You may ignore the
7069 warning, though users will not be able to configure your package for
7070 cross-compiling.  A few of the macros distributed with Autoconf produce
7071 this warning message.
7073 To configure for cross-compiling you can also choose a value for those
7074 parameters based on the canonical system name (@pxref{Manual
7075 Configuration}).  Alternatively, set up a test results cache file with
7076 the correct values for the host system (@pxref{Caching Results}).
7078 @ovindex cross_compiling
7079 To provide a default for calls of @code{AC_RUN_IFELSE} that are embedded
7080 in other macros, including a few of the ones that come with Autoconf,
7081 you can test whether the shell variable @code{cross_compiling} is set to
7082 @samp{yes}, and then use an alternate method to get the results instead
7083 of calling the macros.
7086 @node Systemology
7087 @section Systemology
7088 @cindex Systemology
7090 This section aims at presenting some systems and pointers to
7091 documentation.  It may help you addressing particular problems reported
7092 by users.
7094 The @uref{http://bhami.com/rosetta.html, Rosetta Stone for Unix}
7095 contains a lot of interesting crossed information on various
7096 Posix-conforming systems.
7098 @table @asis
7099 @item Darwin
7100 @cindex Darwin
7101 Darwin is also known as Mac OS X@.  Beware that the file system @emph{can} be
7102 case-preserving, but case insensitive.  This can cause nasty problems,
7103 since for instance the installation attempt for a package having an
7104 @file{INSTALL} file can result in @samp{make install} report that
7105 nothing was to be done!
7107 That's all dependent on whether the file system is a UFS (case
7108 sensitive) or HFS+ (case preserving).  By default Apple wants you to
7109 install the OS on HFS+.  Unfortunately, there are some pieces of
7110 software which really need to be built on UFS@.  We may want to rebuild
7111 Darwin to have both UFS and HFS+ available (and put the /local/build
7112 tree on the UFS).
7114 @item @acronym{QNX} 4.25
7115 @cindex @acronym{QNX} 4.25
7116 @c FIXME: Please, if you feel like writing something more precise,
7117 @c it'd be great.  In particular, I can't understand the difference with
7118 @c QNX Neutrino.
7119 @acronym{QNX} is a realtime operating system running on Intel architecture
7120 meant to be scalable from the small embedded systems to the hundred
7121 processor super-computer.  It claims to be Posix certified.  More
7122 information is available on the
7123 @uref{http://www.qnx.com/, @acronym{QNX} home page}.
7125 @item Tru64
7126 @cindex Tru64
7127 The @uref{http://h30097.www3.hp.com/docs/,
7128 documentation of several versions of Tru64} is available in different
7129 formats.
7131 @item Unix version 7
7132 @cindex Unix version 7
7133 @cindex V7
7134 Officially this was called the ``Seventh Edition'' of ``the @sc{unix}
7135 time-sharing system'' but we use the more-common name ``Unix version 7''.
7136 Documentation is available in the
7137 @uref{http://plan9.bell-labs.com/7thEdMan/, V7 Manual}.
7138 Previous versions of Unix are called ``Unix version 6'', etc., but
7139 they were not as widely used.
7140 @end table
7143 @node Multiple Cases
7144 @section Multiple Cases
7146 Some operations are accomplished in several possible ways, depending on
7147 the OS variant.  Checking for them essentially requires a ``case
7148 statement''.  Autoconf does not directly provide one; however, it is
7149 easy to simulate by using a shell variable to keep track of whether a
7150 way to perform the operation has been found yet.
7152 Here is an example that uses the shell variable @code{fstype} to keep
7153 track of whether the remaining cases need to be checked.
7155 @example
7156 @group
7157 AC_MSG_CHECKING([how to get file system type])
7158 fstype=no
7159 # The order of these tests is important.
7160 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/statvfs.h>
7161 #include <sys/fstyp.h>]])],
7162                   [AC_DEFINE(FSTYPE_STATVFS, 1,
7163                      [Define if statvfs exists.])
7164                    fstype=SVR4])
7165 if test $fstype = no; then
7166   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/statfs.h>
7167 #include <sys/fstyp.h>]])],
7168                   [AC_DEFINE(FSTYPE_USG_STATFS, 1,
7169                      [Define if USG statfs.])
7170                    fstype=SVR3])
7172 if test $fstype = no; then
7173   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/statfs.h>
7174 #include <sys/vmount.h>]])]),
7175                   [AC_DEFINE(FSTYPE_AIX_STATFS, 1,
7176                      [Define if AIX statfs.])
7177                    fstype=AIX])
7179 # (more cases omitted here)
7180 AC_MSG_RESULT([$fstype])
7181 @end group
7182 @end example
7184 @c ====================================================== Results of Tests.
7186 @node Results
7187 @chapter Results of Tests
7189 Once @command{configure} has determined whether a feature exists, what can
7190 it do to record that information?  There are four sorts of things it can
7191 do: define a C preprocessor symbol, set a variable in the output files,
7192 save the result in a cache file for future @command{configure} runs, and
7193 print a message letting the user know the result of the test.
7195 @menu
7196 * Defining Symbols::            Defining C preprocessor symbols
7197 * Setting Output Variables::    Replacing variables in output files
7198 * Caching Results::             Speeding up subsequent @command{configure} runs
7199 * Printing Messages::           Notifying @command{configure} users
7200 @end menu
7202 @node Defining Symbols
7203 @section Defining C Preprocessor Symbols
7205 A common action to take in response to a feature test is to define a C
7206 preprocessor symbol indicating the results of the test.  That is done by
7207 calling @code{AC_DEFINE} or @code{AC_DEFINE_UNQUOTED}.
7209 By default, @code{AC_OUTPUT} places the symbols defined by these macros
7210 into the output variable @code{DEFS}, which contains an option
7211 @option{-D@var{symbol}=@var{value}} for each symbol defined.  Unlike in
7212 Autoconf version 1, there is no variable @code{DEFS} defined while
7213 @command{configure} is running.  To check whether Autoconf macros have
7214 already defined a certain C preprocessor symbol, test the value of the
7215 appropriate cache variable, as in this example:
7217 @example
7218 AC_CHECK_FUNC(vprintf, [AC_DEFINE(HAVE_VPRINTF, 1,
7219                           [Define if vprintf exists.])])
7220 if test "$ac_cv_func_vprintf" != yes; then
7221   AC_CHECK_FUNC(_doprnt, [AC_DEFINE(HAVE_DOPRNT, 1,
7222                             [Define if _doprnt exists.])])
7224 @end example
7226 If @code{AC_CONFIG_HEADERS} has been called, then instead of creating
7227 @code{DEFS}, @code{AC_OUTPUT} creates a header file by substituting the
7228 correct values into @code{#define} statements in a template file.
7229 @xref{Configuration Headers}, for more information about this kind of
7230 output.
7232 @defmac AC_DEFINE (@var{variable}, @var{value}, @ovar{description})
7233 @defmacx AC_DEFINE (@var{variable})
7234 @acindex{DEFINE}
7235 Define the C preprocessor variable @var{variable} to @var{value} (verbatim).
7236 @var{value} should not contain literal newlines, and if you are not
7237 using @code{AC_CONFIG_HEADERS} it should not contain any @samp{#}
7238 characters, as @command{make} tends to eat them.  To use a shell variable,
7239 use @code{AC_DEFINE_UNQUOTED} instead.
7240 @var{description} is only useful if you are using
7241 @code{AC_CONFIG_HEADERS}.  In this case, @var{description} is put into
7242 the generated @file{config.h.in} as the comment before the macro define.
7243 The following example defines the C preprocessor variable
7244 @code{EQUATION} to be the string constant @samp{"$a > $b"}:
7246 @example
7247 AC_DEFINE(EQUATION, "$a > $b",
7248   [Equation string.])
7249 @end example
7251 If neither @var{value} nor @var{description} are given, then
7252 @var{value} defaults to 1 instead of to the empty string.  This is for
7253 backwards compatibility with older versions of Autoconf, but this usage
7254 is obsolescent and may be withdrawn in future versions of Autoconf.
7255 @end defmac
7257 @defmac AC_DEFINE_UNQUOTED (@var{variable}, @var{value}, @ovar{description})
7258 @defmacx AC_DEFINE_UNQUOTED (@var{variable})
7259 @acindex{DEFINE_UNQUOTED}
7260 Like @code{AC_DEFINE}, but three shell expansions are
7261 performed---once---on @var{variable} and @var{value}: variable expansion
7262 (@samp{$}), command substitution (@samp{`}), and backslash escaping
7263 (@samp{\}).  Single and double quote characters in the value have no
7264 special meaning.  Use this macro instead of @code{AC_DEFINE} when
7265 @var{variable} or @var{value} is a shell variable.  Examples:
7267 @example
7268 AC_DEFINE_UNQUOTED(config_machfile, "$machfile",
7269   [Configuration machine file.])
7270 AC_DEFINE_UNQUOTED(GETGROUPS_T, $ac_cv_type_getgroups,
7271   [getgroups return type.])
7272 AC_DEFINE_UNQUOTED($ac_tr_hdr, 1,
7273   [Translated header name.])
7274 @end example
7275 @end defmac
7277 Due to a syntactical bizarreness of the Bourne shell, do not use
7278 semicolons to separate @code{AC_DEFINE} or @code{AC_DEFINE_UNQUOTED}
7279 calls from other macro calls or shell code; that can cause syntax errors
7280 in the resulting @command{configure} script.  Use either spaces or
7281 newlines.  That is, do this:
7283 @example
7284 AC_CHECK_HEADER(elf.h,
7285   [AC_DEFINE(SVR4, 1, [System V Release 4]) LIBS="$LIBS -lelf"])
7286 @end example
7288 @noindent
7289 or this:
7291 @example
7292 AC_CHECK_HEADER(elf.h,
7293   [AC_DEFINE(SVR4, 1, [System V Release 4])
7294    LIBS="$LIBS -lelf"])
7295 @end example
7297 @noindent
7298 instead of this:
7300 @example
7301 AC_CHECK_HEADER(elf.h,
7302   [AC_DEFINE(SVR4, 1, [System V Release 4]); LIBS="$LIBS -lelf"])
7303 @end example
7305 @node Setting Output Variables
7306 @section Setting Output Variables
7307 @cindex Output variables
7309 Another way to record the results of tests is to set @dfn{output
7310 variables}, which are shell variables whose values are substituted into
7311 files that @command{configure} outputs.  The two macros below create new
7312 output variables.  @xref{Preset Output Variables}, for a list of output
7313 variables that are always available.
7315 @defmac AC_SUBST (@var{variable}, @ovar{value})
7316 @acindex{SUBST}
7317 Create an output variable from a shell variable.  Make @code{AC_OUTPUT}
7318 substitute the variable @var{variable} into output files (typically one
7319 or more @file{Makefile}s).  This means that @code{AC_OUTPUT} will
7320 replace instances of @samp{@@@var{variable}@@} in input files with the
7321 value that the shell variable @var{variable} has when @code{AC_OUTPUT}
7322 is called.  This value of @var{variable} should not contain literal
7323 newlines.  (There is currently no portable way to escape literal
7324 newlines.)
7326 If @var{value} is given, in addition assign it to @var{variable}.
7328 The string @var{variable} is passed to @code{m4_pattern_allow}
7329 (@pxref{Forbidden Patterns}).
7330 @end defmac
7332 @defmac AC_SUBST_FILE (@var{variable})
7333 @acindex{SUBST_FILE}
7334 Another way to create an output variable from a shell variable.  Make
7335 @code{AC_OUTPUT} insert (without substitutions) the contents of the file
7336 named by shell variable @var{variable} into output files.  This means
7337 that @code{AC_OUTPUT} will replace instances of
7338 @samp{@@@var{variable}@@} in output files (such as @file{Makefile.in})
7339 with the contents of the file that the shell variable @var{variable}
7340 names when @code{AC_OUTPUT} is called.  Set the variable to
7341 @file{/dev/null} for cases that do not have a file to insert.
7343 This macro is useful for inserting @file{Makefile} fragments containing
7344 special dependencies or other @code{make} directives for particular host
7345 or target types into @file{Makefile}s.  For example, @file{configure.ac}
7346 could contain:
7348 @example
7349 AC_SUBST_FILE([host_frag])
7350 host_frag=$srcdir/conf/sun4.mh
7351 @end example
7353 @noindent
7354 and then a @file{Makefile.in} could contain:
7356 @example
7357 @@host_frag@@
7358 @end example
7360 The string @var{variable} is passed to @code{m4_pattern_allow}
7361 (@pxref{Forbidden Patterns}).
7362 @end defmac
7364 @cindex Previous Variable
7365 @cindex Variable, Precious
7366 Running @command{configure} in varying environments can be extremely
7367 dangerous.  If for instance the user runs @samp{CC=bizarre-cc
7368 ./configure}, then the cache, @file{config.h}, and many other output
7369 files will depend upon @command{bizarre-cc} being the C compiler.  If
7370 for some reason the user runs @command{./configure} again, or if it is
7371 run via @samp{./config.status --recheck}, (@xref{Automatic Remaking},
7372 and @pxref{config.status Invocation}), then the configuration can be
7373 inconsistent, composed of results depending upon two different
7374 compilers.
7376 Environment variables that affect this situation, such as @samp{CC}
7377 above, are called @dfn{precious variables}, and can be declared as such
7378 by @code{AC_ARG_VAR}.
7380 @defmac AC_ARG_VAR (@var{variable}, @var{description})
7381 @acindex{ARG_VAR}
7382 Declare @var{variable} is a precious variable, and include its
7383 @var{description} in the variable section of @samp{./configure --help}.
7385 Being precious means that
7386 @itemize @minus
7387 @item
7388 @var{variable} is @code{AC_SUBST}'d.
7390 @item
7391 The value of @var{variable} when @command{configure} was launched is
7392 saved in the cache, including if it was not specified on the command
7393 line but via the environment.  Indeed, while @command{configure} can
7394 notice the definition of @code{CC} in @samp{./configure CC=bizarre-cc},
7395 it is impossible to notice it in @samp{CC=bizarre-cc ./configure},
7396 which, unfortunately, is what most users do.
7398 We emphasize that it is the @emph{initial} value of @var{variable} which
7399 is saved, not that found during the execution of @command{configure}.
7400 Indeed, specifying @samp{./configure FOO=foo} and letting
7401 @samp{./configure} guess that @code{FOO} is @code{foo} can be two very
7402 different runs.
7404 @item
7405 @var{variable} is checked for consistency between two
7406 @command{configure} runs.  For instance:
7408 @example
7409 $ @kbd{./configure --silent --config-cache}
7410 $ @kbd{CC=cc ./configure --silent --config-cache}
7411 configure: error: `CC' was not set in the previous run
7412 configure: error: changes in the environment can compromise \
7413 the build
7414 configure: error: run `make distclean' and/or \
7415 `rm config.cache' and start over
7416 @end example
7418 @noindent
7419 and similarly if the variable is unset, or if its content is changed.
7422 @item
7423 @var{variable} is kept during automatic reconfiguration
7424 (@pxref{config.status Invocation}) as if it had been passed as a command
7425 line argument, including when no cache is used:
7427 @example
7428 $ @kbd{CC=/usr/bin/cc ./configure undeclared_var=raboof --silent}
7429 $ @kbd{./config.status --recheck}
7430 running /bin/sh ./configure undeclared_var=raboof --silent \
7431   CC=/usr/bin/cc  --no-create --no-recursion
7432 @end example
7433 @end itemize
7434 @end defmac
7437 @node Caching Results
7438 @section Caching Results
7439 @cindex Cache
7441 To avoid checking for the same features repeatedly in various
7442 @command{configure} scripts (or in repeated runs of one script),
7443 @command{configure} can optionally save the results of many checks in a
7444 @dfn{cache file} (@pxref{Cache Files}).  If a @command{configure} script
7445 runs with caching enabled and finds a cache file, it reads the results
7446 of previous runs from the cache and avoids rerunning those checks.  As a
7447 result, @command{configure} can then run much faster than if it had to
7448 perform all of the checks every time.
7450 @defmac AC_CACHE_VAL (@var{cache-id}, @var{commands-to-set-it})
7451 @acindex{CACHE_VAL}
7452 Ensure that the results of the check identified by @var{cache-id} are
7453 available.  If the results of the check were in the cache file that was
7454 read, and @command{configure} was not given the @option{--quiet} or
7455 @option{--silent} option, print a message saying that the result was
7456 cached; otherwise, run the shell commands @var{commands-to-set-it}.  If
7457 the shell commands are run to determine the value, the value will be
7458 saved in the cache file just before @command{configure} creates its output
7459 files.  @xref{Cache Variable Names}, for how to choose the name of the
7460 @var{cache-id} variable.
7462 The @var{commands-to-set-it} @emph{must have no side effects} except for
7463 setting the variable @var{cache-id}, see below.
7464 @end defmac
7466 @defmac AC_CACHE_CHECK (@var{message}, @var{cache-id}, @var{commands-to-set-it})
7467 @acindex{CACHE_CHECK}
7468 A wrapper for @code{AC_CACHE_VAL} that takes care of printing the
7469 messages.  This macro provides a convenient shorthand for the most
7470 common way to use these macros.  It calls @code{AC_MSG_CHECKING} for
7471 @var{message}, then @code{AC_CACHE_VAL} with the @var{cache-id} and
7472 @var{commands} arguments, and @code{AC_MSG_RESULT} with @var{cache-id}.
7474 The @var{commands-to-set-it} @emph{must have no side effects} except for
7475 setting the variable @var{cache-id}, see below.
7476 @end defmac
7478 It is very common to find buggy macros using @code{AC_CACHE_VAL} or
7479 @code{AC_CACHE_CHECK}, because people are tempted to call
7480 @code{AC_DEFINE} in the @var{commands-to-set-it}.  Instead, the code that
7481 @emph{follows} the call to @code{AC_CACHE_VAL} should call
7482 @code{AC_DEFINE}, by examining the value of the cache variable.  For
7483 instance, the following macro is broken:
7485 @example
7486 @group
7487 AC_DEFUN([AC_SHELL_TRUE],
7488 [AC_CACHE_CHECK([whether true(1) works], [ac_cv_shell_true_works],
7489                 [ac_cv_shell_true_works=no
7490                  true && ac_cv_shell_true_works=yes
7491                  if test $ac_cv_shell_true_works = yes; then
7492                    AC_DEFINE([TRUE_WORKS], 1
7493                              [Define if `true(1)' works properly.])
7494                  fi])
7496 @end group
7497 @end example
7499 @noindent
7500 This fails if the cache is enabled: the second time this macro is run,
7501 @code{TRUE_WORKS} @emph{will not be defined}.  The proper implementation
7504 @example
7505 @group
7506 AC_DEFUN([AC_SHELL_TRUE],
7507 [AC_CACHE_CHECK([whether true(1) works], [ac_cv_shell_true_works],
7508                 [ac_cv_shell_true_works=no
7509                  true && ac_cv_shell_true_works=yes])
7510  if test $ac_cv_shell_true_works = yes; then
7511    AC_DEFINE([TRUE_WORKS], 1
7512              [Define if `true(1)' works properly.])
7513  fi
7515 @end group
7516 @end example
7518 Also, @var{commands-to-set-it} should not print any messages, for
7519 example with @code{AC_MSG_CHECKING}; do that before calling
7520 @code{AC_CACHE_VAL}, so the messages are printed regardless of whether
7521 the results of the check are retrieved from the cache or determined by
7522 running the shell commands.
7524 @menu
7525 * Cache Variable Names::        Shell variables used in caches
7526 * Cache Files::                 Files @command{configure} uses for caching
7527 * Cache Checkpointing::         Loading and saving the cache file
7528 @end menu
7530 @node Cache Variable Names
7531 @subsection Cache Variable Names
7532 @cindex Cache variable
7534 The names of cache variables should have the following format:
7536 @example
7537 @var{package-prefix}_cv_@var{value-type}_@var{specific-value}_@ovar{additional-options}
7538 @end example
7540 @noindent
7541 for example, @samp{ac_cv_header_stat_broken} or
7542 @samp{ac_cv_prog_gcc_traditional}.  The parts of the variable name are:
7544 @table @asis
7545 @item @var{package-prefix}
7546 An abbreviation for your package or organization; the same prefix you
7547 begin local Autoconf macros with, except lowercase by convention.
7548 For cache values used by the distributed Autoconf macros, this value is
7549 @samp{ac}.
7551 @item @code{_cv_}
7552 Indicates that this shell variable is a cache value.  This string
7553 @emph{must} be present in the variable name, including the leading
7554 underscore.
7556 @item @var{value-type}
7557 A convention for classifying cache values, to produce a rational naming
7558 system.  The values used in Autoconf are listed in @ref{Macro Names}.
7560 @item @var{specific-value}
7561 Which member of the class of cache values this test applies to.
7562 For example, which function (@samp{alloca}), program (@samp{gcc}), or
7563 output variable (@samp{INSTALL}).
7565 @item @var{additional-options}
7566 Any particular behavior of the specific member that this test applies to.
7567 For example, @samp{broken} or @samp{set}.  This part of the name may
7568 be omitted if it does not apply.
7569 @end table
7571 The values assigned to cache variables may not contain newlines.
7572 Usually, their values will be Boolean (@samp{yes} or @samp{no}) or the
7573 names of files or functions; so this is not an important restriction.
7575 @node Cache Files
7576 @subsection Cache Files
7578 A cache file is a shell script that caches the results of configure
7579 tests run on one system so they can be shared between configure scripts
7580 and configure runs.  It is not useful on other systems.  If its contents
7581 are invalid for some reason, the user may delete or edit it.
7583 By default, @command{configure} uses no cache file (technically, it uses
7584 @option{--cache-file=/dev/null}), to avoid problems caused by accidental
7585 use of stale cache files.
7587 To enable caching, @command{configure} accepts @option{--config-cache} (or
7588 @option{-C}) to cache results in the file @file{config.cache}.
7589 Alternatively, @option{--cache-file=@var{file}} specifies that
7590 @var{file} be the cache file.  The cache file is created if it does not
7591 exist already.  When @command{configure} calls @command{configure} scripts in
7592 subdirectories, it uses the @option{--cache-file} argument so that they
7593 share the same cache.  @xref{Subdirectories}, for information on
7594 configuring subdirectories with the @code{AC_CONFIG_SUBDIRS} macro.
7596 @file{config.status} only pays attention to the cache file if it is
7597 given the @option{--recheck} option, which makes it rerun
7598 @command{configure}.
7600 It is wrong to try to distribute cache files for particular system types.
7601 There is too much room for error in doing that, and too much
7602 administrative overhead in maintaining them.  For any features that
7603 can't be guessed automatically, use the standard method of the canonical
7604 system type and linking files (@pxref{Manual Configuration}).
7606 The site initialization script can specify a site-wide cache file to
7607 use, instead of the usual per-program cache.  In this case, the cache
7608 file will gradually accumulate information whenever someone runs a new
7609 @command{configure} script.  (Running @command{configure} merges the new cache
7610 results with the existing cache file.)  This may cause problems,
7611 however, if the system configuration (e.g., the installed libraries or
7612 compilers) changes and the stale cache file is not deleted.
7614 @node Cache Checkpointing
7615 @subsection Cache Checkpointing
7617 If your configure script, or a macro called from @file{configure.ac}, happens
7618 to abort the configure process, it may be useful to checkpoint the cache
7619 a few times at key points using @code{AC_CACHE_SAVE}.  Doing so will
7620 reduce the amount of time it takes to re-run the configure script with
7621 (hopefully) the error that caused the previous abort corrected.
7623 @c FIXME: Do we really want to document this guy?
7624 @defmac AC_CACHE_LOAD
7625 @acindex{CACHE_LOAD}
7626 Loads values from existing cache file, or creates a new cache file if a
7627 cache file is not found.  Called automatically from @code{AC_INIT}.
7628 @end defmac
7630 @defmac AC_CACHE_SAVE
7631 @acindex{CACHE_SAVE}
7632 Flushes all cached values to the cache file.  Called automatically from
7633 @code{AC_OUTPUT}, but it can be quite useful to call
7634 @code{AC_CACHE_SAVE} at key points in @file{configure.ac}.
7635 @end defmac
7637 For instance:
7639 @example
7640 @r{ @dots{} AC_INIT, etc. @dots{}}
7641 @group
7642 # Checks for programs.
7643 AC_PROG_CC
7644 AC_PROG_GCC_TRADITIONAL
7645 @r{ @dots{} more program checks @dots{}}
7646 AC_CACHE_SAVE
7647 @end group
7649 @group
7650 # Checks for libraries.
7651 AC_CHECK_LIB(nsl, gethostbyname)
7652 AC_CHECK_LIB(socket, connect)
7653 @r{ @dots{} more lib checks @dots{}}
7654 AC_CACHE_SAVE
7655 @end group
7657 @group
7658 # Might abort@dots{}
7659 AM_PATH_GTK(1.0.2,, [AC_MSG_ERROR([GTK not in path])])
7660 AM_PATH_GTKMM(0.9.5,, [AC_MSG_ERROR([GTK not in path])])
7661 @end group
7662 @r{ @dots{} AC_OUTPUT, etc. @dots{}}
7663 @end example
7665 @node Printing Messages
7666 @section Printing Messages
7667 @cindex Messages, from @command{configure}
7669 @command{configure} scripts need to give users running them several kinds
7670 of information.  The following macros print messages in ways appropriate
7671 for each kind.  The arguments to all of them get enclosed in shell
7672 double quotes, so the shell performs variable and back-quote
7673 substitution on them.
7675 These macros are all wrappers around the @command{echo} shell command,
7676 and will direct output to the appropriate file descriptor (@pxref{File
7677 Descriptor Macros}).
7678 @command{configure} scripts should rarely need to run @command{echo} directly
7679 to print messages for the user.  Using these macros makes it easy to
7680 change how and when each kind of message is printed; such changes need
7681 only be made to the macro definitions and all the callers will change
7682 automatically.
7684 To diagnose static issues, i.e., when @command{autoconf} is run, see
7685 @ref{Reporting Messages}.
7687 @defmac AC_MSG_CHECKING (@var{feature-description})
7688 @acindex{MSG_CHECKING}
7689 Notify the user that @command{configure} is checking for a particular
7690 feature.  This macro prints a message that starts with @samp{checking }
7691 and ends with @samp{...} and no newline.  It must be followed by a call
7692 to @code{AC_MSG_RESULT} to print the result of the check and the
7693 newline.  The @var{feature-description} should be something like
7694 @samp{whether the Fortran compiler accepts C++ comments} or @samp{for
7695 c89}.
7697 This macro prints nothing if @command{configure} is run with the
7698 @option{--quiet} or @option{--silent} option.
7699 @end defmac
7701 @defmac AC_MSG_RESULT (@var{result-description})
7702 @acindex{MSG_RESULT}
7703 Notify the user of the results of a check.  @var{result-description} is
7704 almost always the value of the cache variable for the check, typically
7705 @samp{yes}, @samp{no}, or a file name.  This macro should follow a call
7706 to @code{AC_MSG_CHECKING}, and the @var{result-description} should be
7707 the completion of the message printed by the call to
7708 @code{AC_MSG_CHECKING}.
7710 This macro prints nothing if @command{configure} is run with the
7711 @option{--quiet} or @option{--silent} option.
7712 @end defmac
7714 @defmac AC_MSG_NOTICE (@var{message})
7715 @acindex{MSG_NOTICE}
7716 Deliver the @var{message} to the user.  It is useful mainly to print a
7717 general description of the overall purpose of a group of feature checks,
7718 e.g.,
7720 @example
7721 AC_MSG_NOTICE([checking if stack overflow is detectable])
7722 @end example
7724 This macro prints nothing if @command{configure} is run with the
7725 @option{--quiet} or @option{--silent} option.
7726 @end defmac
7728 @defmac AC_MSG_ERROR (@var{error-description}, @ovar{exit-status})
7729 @acindex{MSG_ERROR}
7730 Notify the user of an error that prevents @command{configure} from
7731 completing.  This macro prints an error message to the standard error
7732 output and exits @command{configure} with @var{exit-status} (1 by default).
7733 @var{error-description} should be something like @samp{invalid value
7734 $HOME for \$HOME}.
7736 The @var{error-description} should start with a lower-case letter, and
7737 ``cannot'' is preferred to ``can't''.
7738 @end defmac
7740 @defmac AC_MSG_FAILURE (@var{error-description}, @ovar{exit-status})
7741 @acindex{MSG_FAILURE}
7742 This @code{AC_MSG_ERROR} wrapper notifies the user of an error that
7743 prevents @command{configure} from completing @emph{and} that additional
7744 details are provided in @file{config.log}.  This is typically used when
7745 abnormal results are found during a compilation.
7746 @end defmac
7748 @defmac AC_MSG_WARN (@var{problem-description})
7749 @acindex{MSG_WARN}
7750 Notify the @command{configure} user of a possible problem.  This macro
7751 prints the message to the standard error output; @command{configure}
7752 continues running afterward, so macros that call @code{AC_MSG_WARN} should
7753 provide a default (back-up) behavior for the situations they warn about.
7754 @var{problem-description} should be something like @samp{ln -s seems to
7755 make hard links}.
7756 @end defmac
7760 @c ====================================================== Programming in M4.
7762 @node Programming in M4
7763 @chapter Programming in M4
7764 @cindex M4
7766 Autoconf is written on top of two layers: @dfn{M4sugar}, which provides
7767 convenient macros for pure M4 programming, and @dfn{M4sh}, which
7768 provides macros dedicated to shell script generation.
7770 As of this version of Autoconf, these two layers are still experimental,
7771 and their interface might change in the future.  As a matter of fact,
7772 @emph{anything that is not documented must not be used}.
7774 @menu
7775 * M4 Quotation::                Protecting macros from unwanted expansion
7776 * Using autom4te::              The Autoconf executables backbone
7777 * Programming in M4sugar::      Convenient pure M4 macros
7778 * Programming in M4sh::         Common shell Constructs
7779 * File Descriptor Macros::      File descriptor macros for input and output
7780 @end menu
7782 @node M4 Quotation
7783 @section M4 Quotation
7784 @cindex M4 quotation
7785 @cindex quotation
7787 @c FIXME: Grmph, yet another quoting myth: quotation has *never*
7788 @c prevented `expansion' of $1.  Unless it refers to the expansion
7789 @c of the value of $1?  Anyway, we need a rewrite here@enddots{}
7791 The most common problem with existing macros is an improper quotation.
7792 This section, which users of Autoconf can skip, but which macro writers
7793 @emph{must} read, first justifies the quotation scheme that was chosen
7794 for Autoconf and then ends with a rule of thumb.  Understanding the
7795 former helps one to follow the latter.
7797 @menu
7798 * Active Characters::           Characters that change the behavior of M4
7799 * One Macro Call::              Quotation and one macro call
7800 * Quotation and Nested Macros::  Macros calling macros
7801 * Changequote is Evil::         Worse than INTERCAL: M4 + changequote
7802 * Quadrigraphs::                Another way to escape special characters
7803 * Quotation Rule Of Thumb::     One parenthesis, one quote
7804 @end menu
7806 @node Active Characters
7807 @subsection Active Characters
7809 To fully understand where proper quotation is important, you first need
7810 to know what the special characters are in Autoconf: @samp{#} introduces
7811 a comment inside which no macro expansion is performed, @samp{,}
7812 separates arguments, @samp{[} and @samp{]} are the quotes themselves,
7813 and finally @samp{(} and @samp{)} (which M4 tries to match by
7814 pairs).
7816 In order to understand the delicate case of macro calls, we first have
7817 to present some obvious failures.  Below they are ``obvious-ified'',
7818 but when you find them in real life, they are usually in disguise.
7820 Comments, introduced by a hash and running up to the newline, are opaque
7821 tokens to the top level: active characters are turned off, and there is
7822 no macro expansion:
7824 @example
7825 # define([def], ine)
7826 @result{}# define([def], ine)
7827 @end example
7829 Each time there can be a macro expansion, there is a quotation
7830 expansion, i.e., one level of quotes is stripped:
7832 @example
7833 int tab[10];
7834 @result{}int tab10;
7835 [int tab[10];]
7836 @result{}int tab[10];
7837 @end example
7839 Without this in mind, the reader will try hopelessly to use her macro
7840 @code{array}:
7842 @example
7843 define([array], [int tab[10];])
7844 array
7845 @result{}int tab10;
7846 [array]
7847 @result{}array
7848 @end example
7850 @noindent
7851 How can you correctly output the intended results@footnote{Using
7852 @code{defn}.}?
7855 @node One Macro Call
7856 @subsection One Macro Call
7858 Let's proceed on the interaction between active characters and macros
7859 with this small macro, which just returns its first argument:
7861 @example
7862 define([car], [$1])
7863 @end example
7865 @noindent
7866 The two pairs of quotes above are not part of the arguments of
7867 @code{define}; rather, they are understood by the top level when it
7868 tries to find the arguments of @code{define}.  Therefore, assuming
7869 @code{car} is not already defined, it is equivalent to write:
7871 @example
7872 define(car, $1)
7873 @end example
7875 @noindent
7876 But, while it is acceptable for a @file{configure.ac} to avoid unnecessary
7877 quotes, it is bad practice for Autoconf macros which must both be more
7878 robust and also advocate perfect style.
7880 At the top level, there are only two possibilities: either you
7881 quote or you don't:
7883 @example
7884 car(foo, bar, baz)
7885 @result{}foo
7886 [car(foo, bar, baz)]
7887 @result{}car(foo, bar, baz)
7888 @end example
7890 Let's pay attention to the special characters:
7892 @example
7893 car(#)
7894 @error{}EOF in argument list
7895 @end example
7897 The closing parenthesis is hidden in the comment; with a hypothetical
7898 quoting, the top level understood it this way:
7900 @example
7901 car([#)]
7902 @end example
7904 @noindent
7905 Proper quotation, of course, fixes the problem:
7907 @example
7908 car([#])
7909 @result{}#
7910 @end example
7912 Here are more examples:
7914 @example
7915 car(foo, bar)
7916 @result{}foo
7917 car([foo, bar])
7918 @result{}foo, bar
7919 car((foo, bar))
7920 @result{}(foo, bar)
7921 car([(foo], [bar)])
7922 @result{}(foo
7923 define([a], [b])
7924 @result{}
7925 car(a)
7926 @result{}b
7927 car([a])
7928 @result{}b
7929 car([[a]])
7930 @result{}a
7931 car([[[a]]])
7932 @result{}[a]
7933 @end example
7935 With this in mind, we can explore the cases where macros invoke
7936 macros@enddots{}
7939 @node Quotation and Nested Macros
7940 @subsection Quotation and Nested Macros
7942 The examples below use the following macros:
7944 @example
7945 define([car], [$1])
7946 define([active], [ACT, IVE])
7947 define([array], [int tab[10]])
7948 @end example
7950 Each additional embedded macro call introduces other possible
7951 interesting quotations:
7953 @example
7954 car(active)
7955 @result{}ACT
7956 car([active])
7957 @result{}ACT, IVE
7958 car([[active]])
7959 @result{}active
7960 @end example
7962 In the first case, the top level looks for the arguments of @code{car},
7963 and finds @samp{active}.  Because M4 evaluates its arguments
7964 before applying the macro, @samp{active} is expanded, which results in:
7966 @example
7967 car(ACT, IVE)
7968 @result{}ACT
7969 @end example
7971 @noindent
7972 In the second case, the top level gives @samp{active} as first and only
7973 argument of @code{car}, which results in:
7975 @example
7976 active
7977 @result{}ACT, IVE
7978 @end example
7980 @noindent
7981 i.e., the argument is evaluated @emph{after} the macro that invokes it.
7982 In the third case, @code{car} receives @samp{[active]}, which results in:
7984 @example
7985 [active]
7986 @result{}active
7987 @end example
7989 @noindent
7990 exactly as we already saw above.
7992 The example above, applied to a more realistic example, gives:
7994 @example
7995 car(int tab[10];)
7996 @result{}int tab10;
7997 car([int tab[10];])
7998 @result{}int tab10;
7999 car([[int tab[10];]])
8000 @result{}int tab[10];
8001 @end example
8003 @noindent
8004 Huh?  The first case is easily understood, but why is the second wrong,
8005 and the third right?  To understand that, you must know that after
8006 M4 expands a macro, the resulting text is immediately subjected
8007 to macro expansion and quote removal.  This means that the quote removal
8008 occurs twice---first before the argument is passed to the @code{car}
8009 macro, and second after the @code{car} macro expands to the first
8010 argument.
8012 As the author of the Autoconf macro @code{car}, you then consider it to
8013 be incorrect that your users have to double-quote the arguments of
8014 @code{car}, so you ``fix'' your macro.  Let's call it @code{qar} for
8015 quoted car:
8017 @example
8018 define([qar], [[$1]])
8019 @end example
8021 @noindent
8022 and check that @code{qar} is properly fixed:
8024 @example
8025 qar([int tab[10];])
8026 @result{}int tab[10];
8027 @end example
8029 @noindent
8030 Ahhh!  That's much better.
8032 But note what you've done: now that the arguments are literal strings,
8033 if the user wants to use the results of expansions as arguments, she has
8034 to use an @emph{unquoted} macro call:
8036 @example
8037 qar(active)
8038 @result{}ACT
8039 @end example
8041 @noindent
8042 where she wanted to reproduce what she used to do with @code{car}:
8044 @example
8045 car([active])
8046 @result{}ACT, IVE
8047 @end example
8049 @noindent
8050 Worse yet: she wants to use a macro that produces a set of @code{cpp}
8051 macros:
8053 @example
8054 define([my_includes], [#include <stdio.h>])
8055 car([my_includes])
8056 @result{}#include <stdio.h>
8057 qar(my_includes)
8058 @error{}EOF in argument list
8059 @end example
8061 This macro, @code{qar}, because it double quotes its arguments, forces
8062 its users to leave their macro calls unquoted, which is dangerous.
8063 Commas and other active symbols are interpreted by M4 before
8064 they are given to the macro, often not in the way the users expect.
8065 Also, because @code{qar} behaves differently from the other macros,
8066 it's an exception that should be avoided in Autoconf.
8068 @node Changequote is Evil
8069 @subsection @code{changequote} is Evil
8070 @cindex @code{changequote}
8072 The temptation is often high to bypass proper quotation, in particular
8073 when it's late at night.  Then, many experienced Autoconf hackers
8074 finally surrender to the dark side of the force and use the ultimate
8075 weapon: @code{changequote}.
8077 The M4 builtin @code{changequote} belongs to a set of primitives that
8078 allow one to adjust the syntax of the language to adjust it to one's
8079 needs.  For instance, by default M4 uses @samp{`} and @samp{'} as
8080 quotes, but in the context of shell programming (and actually of most
8081 programming languages), that's about the worst choice one can make:
8082 because of strings and back-quoted expressions in shell code (such as
8083 @samp{'this'} and @samp{`that`}), because of literal characters in usual
8084 programming languages (as in @samp{'0'}), there are many unbalanced
8085 @samp{`} and @samp{'}.  Proper M4 quotation then becomes a nightmare, if
8086 not impossible.  In order to make M4 useful in such a context, its
8087 designers have equipped it with @code{changequote}, which makes it
8088 possible to choose another pair of quotes.  M4sugar, M4sh, Autoconf, and
8089 Autotest all have chosen to use @samp{[} and @samp{]}.  Not especially
8090 because they are unlikely characters, but @emph{because they are
8091 characters unlikely to be unbalanced}.
8093 There are other magic primitives, such as @code{changecom} to specify
8094 what syntactic forms are comments (it is common to see
8095 @samp{changecom(<!--, -->)} when M4 is used to produce HTML pages),
8096 @code{changeword} and @code{changesyntax} to change other syntactic
8097 details (such as the character to denote the @var{n}th argument, @samp{$} by
8098 default, the parenthesis around arguments, etc.).
8100 These primitives are really meant to make M4 more useful for specific
8101 domains: they should be considered like command line options:
8102 @option{--quotes}, @option{--comments}, @option{--words}, and
8103 @code{--syntax}.  Nevertheless, they are implemented as M4 builtins, as
8104 it makes M4 libraries self contained (no need for additional options).
8106 There lies the problem@enddots{}
8108 @sp 1
8110 The problem is that it is then tempting to use them in the middle of an
8111 M4 script, as opposed to its initialization.  This, if not carefully
8112 thought out, can lead to disastrous effects: @emph{you are changing the
8113 language in the middle of the execution}.  Changing and restoring the
8114 syntax is often not enough: if you happened to invoke macros in between,
8115 these macros will be lost, as the current syntax will probably not be
8116 the one they were implemented with.
8118 @c FIXME: I've been looking for a short, real case example, but I
8119 @c lost them all :(
8122 @node Quadrigraphs
8123 @subsection Quadrigraphs
8124 @cindex quadrigraphs
8125 @cindex @samp{@@S|@@}
8126 @cindex @samp{@@&t@@}
8127 @c Info cannot handle `:' in index entries.
8128 @c @cindex @samp{@@<:@@}
8129 @c @cindex @samp{@@:>@@}
8130 @c @cindex @samp{@@%:@@}
8132 When writing an Autoconf macro you may occasionally need to generate
8133 special characters that are difficult to express with the standard
8134 Autoconf quoting rules.  For example, you may need to output the regular
8135 expression @samp{[^[]}, which matches any character other than @samp{[}.
8136 This expression contains unbalanced brackets so it cannot be put easily
8137 into an M4 macro.
8139 You can work around this problem by using one of the following
8140 @dfn{quadrigraphs}:
8142 @table @samp
8143 @item @@<:@@
8144 @samp{[}
8145 @item @@:>@@
8146 @samp{]}
8147 @item @@S|@@
8148 @samp{$}
8149 @item @@%:@@
8150 @samp{#}
8151 @item @@&t@@
8152 Expands to nothing.
8153 @end table
8155 Quadrigraphs are replaced at a late stage of the translation process,
8156 after @command{m4} is run, so they do not get in the way of M4 quoting.
8157 For example, the string @samp{^@@<:@@}, independently of its quotation,
8158 will appear as @samp{^[} in the output.
8160 The empty quadrigraph can be used:
8162 @itemize @minus
8163 @item to mark trailing spaces explicitly
8165 Trailing spaces are smashed by @command{autom4te}.  This is a feature.
8167 @item to produce other quadrigraphs
8169 For instance @samp{@@<@@&t@@:@@} produces @samp{@@<:@@}.
8171 @item to escape @emph{occurrences} of forbidden patterns
8173 For instance you might want to mention @code{AC_FOO} in a comment, while
8174 still being sure that @command{autom4te} will still catch unexpanded
8175 @samp{AC_*}.  Then write @samp{AC@@&t@@_FOO}.
8176 @end itemize
8178 The name @samp{@@&t@@} was suggested by Paul Eggert:
8180 @quotation
8181 I should give some credit to the @samp{@@&t@@} pun.  The @samp{&} is my
8182 own invention, but the @samp{t} came from the source code of the
8183 @sc{algol68c} compiler, written by Steve Bourne (of Bourne shell fame),
8184 and which used @samp{mt} to denote the empty string.  In C, it would
8185 have looked like something like:
8187 @example
8188 char const mt[] = "";
8189 @end example
8191 @noindent
8192 but of course the source code was written in Algol 68.
8194 I don't know where he got @samp{mt} from: it could have been his own
8195 invention, and I suppose it could have been a common pun around the
8196 Cambridge University computer lab at the time.
8197 @end quotation
8199 @node Quotation Rule Of Thumb
8200 @subsection Quotation Rule Of Thumb
8202 To conclude, the quotation rule of thumb is:
8204 @center @emph{One pair of quotes per pair of parentheses.}
8206 Never over-quote, never under-quote, in particular in the definition of
8207 macros.  In the few places where the macros need to use brackets
8208 (usually in C program text or regular expressions), properly quote
8209 @emph{the arguments}!
8211 It is common to read Autoconf programs with snippets like:
8213 @example
8214 AC_TRY_LINK(
8215 changequote(<<, >>)dnl
8216 <<#include <time.h>
8217 #ifndef tzname /* For SGI.  */
8218 extern char *tzname[]; /* RS6000 and others reject char **tzname.  */
8219 #endif>>,
8220 changequote([, ])dnl
8221 [atoi (*tzname);], ac_cv_var_tzname=yes, ac_cv_var_tzname=no)
8222 @end example
8224 @noindent
8225 which is incredibly useless since @code{AC_TRY_LINK} is @emph{already}
8226 double quoting, so you just need:
8228 @example
8229 AC_TRY_LINK(
8230 [#include <time.h>
8231 #ifndef tzname /* For SGI.  */
8232 extern char *tzname[]; /* RS6000 and others reject char **tzname.  */
8233 #endif],
8234             [atoi (*tzname);],
8235             [ac_cv_var_tzname=yes],
8236             [ac_cv_var_tzname=no])
8237 @end example
8239 @noindent
8240 The M4-fluent reader will note that these two examples are rigorously
8241 equivalent, since M4 swallows both the @samp{changequote(<<, >>)}
8242 and @samp{<<} @samp{>>} when it @dfn{collects} the arguments: these
8243 quotes are not part of the arguments!
8245 Simplified, the example above is just doing this:
8247 @example
8248 changequote(<<, >>)dnl
8249 <<[]>>
8250 changequote([, ])dnl
8251 @end example
8253 @noindent
8254 instead of simply:
8256 @example
8257 [[]]
8258 @end example
8260 With macros that do not double quote their arguments (which is the
8261 rule), double-quote the (risky) literals:
8263 @example
8264 AC_LINK_IFELSE([AC_LANG_PROGRAM(
8265 [[#include <time.h>
8266 #ifndef tzname /* For SGI.  */
8267 extern char *tzname[]; /* RS6000 and others reject char **tzname.  */
8268 #endif]],
8269                                 [atoi (*tzname);])],
8270                [ac_cv_var_tzname=yes],
8271                [ac_cv_var_tzname=no])
8272 @end example
8274 Please note that the macro @code{AC_TRY_LINK} is obsolete, so you really
8275 should be using @code{AC_LINK_IFELSE} instead.
8277 @xref{Quadrigraphs}, for what to do if you run into a hopeless case
8278 where quoting does not suffice.
8280 When you create a @command{configure} script using newly written macros,
8281 examine it carefully to check whether you need to add more quotes in
8282 your macros.  If one or more words have disappeared in the M4
8283 output, you need more quotes.  When in doubt, quote.
8285 However, it's also possible to put on too many layers of quotes.  If
8286 this happens, the resulting @command{configure} script may contain
8287 unexpanded macros.  The @command{autoconf} program checks for this problem
8288 by looking for the string @samp{AC_} in @file{configure}.  However, this
8289 heuristic does not work in general: for example, it does not catch
8290 overquoting in @code{AC_DEFINE} descriptions.
8293 @c ---------------------------------------- Using autom4te
8295 @node Using autom4te
8296 @section Using @command{autom4te}
8298 The Autoconf suite, including M4sugar, M4sh, and Autotest, in addition
8299 to Autoconf per se, heavily rely on M4.  All these different uses
8300 revealed common needs factored into a layer over @command{m4}:
8301 @command{autom4te}@footnote{
8303 Yet another great name from Lars J. Aas.
8307 @command{autom4te} is a preprocessor that is like @command{m4}.
8308 It supports M4 extensions designed for use in tools like Autoconf.
8310 @menu
8311 * autom4te Invocation::         A @acronym{GNU} M4 wrapper
8312 * Customizing autom4te::        Customizing the Autoconf package
8313 @end menu
8315 @node autom4te Invocation
8316 @subsection Invoking @command{autom4te}
8318 The command line arguments are modeled after M4's:
8320 @example
8321 autom4te @var{options} @var{files}
8322 @end example
8324 @noindent
8325 where the @var{files} are directly passed to @command{m4}.  In addition
8326 to the regular expansion, it handles the replacement of the quadrigraphs
8327 (@pxref{Quadrigraphs}), and of @samp{__oline__}, the current line in the
8328 output.  It supports an extended syntax for the @var{files}:
8330 @table @file
8331 @item @var{file}.m4f
8332 This file is an M4 frozen file.  Note that @emph{all the previous files
8333 are ignored}.  See the option @option{--melt} for the rationale.
8335 @item @var{file}?
8336 If found in the library path, the @var{file} is included for expansion,
8337 otherwise it is ignored instead of triggering a failure.
8338 @end table
8340 @sp 1
8342 Of course, it supports the Autoconf common subset of options:
8344 @table @option
8345 @item --help
8346 @itemx -h
8347 Print a summary of the command line options and exit.
8349 @item --version
8350 @itemx -V
8351 Print the version number of Autoconf and exit.
8353 @item --verbose
8354 @itemx -v
8355 Report processing steps.
8357 @item --debug
8358 @itemx -d
8359 Don't remove the temporary files and be even more verbose.
8361 @item --include=@var{dir}
8362 @itemx -I @var{dir}
8363 Also look for input files in @var{dir}.  Multiple invocations
8364 accumulate.
8366 @item --output=@var{file}
8367 @itemx -o @var{file}
8368 Save output (script or trace) to @var{file}.  The file @option{-} stands
8369 for the standard output.
8370 @end table
8372 @sp 1
8374 As an extension of @command{m4}, it includes the following options:
8376 @table @option
8377 @item --warnings=@var{category}
8378 @itemx -W @var{category}
8379 @evindex WARNINGS
8380 @c FIXME: Point to the M4sugar macros, not Autoconf's.
8381 Report the warnings related to @var{category} (which can actually be a
8382 comma separated list).  @xref{Reporting Messages}, macro
8383 @code{AC_DIAGNOSE}, for a comprehensive list of categories.  Special
8384 values include:
8386 @table @samp
8387 @item all
8388 report all the warnings
8390 @item none
8391 report none
8393 @item error
8394 treats warnings as errors
8396 @item no-@var{category}
8397 disable warnings falling into @var{category}
8398 @end table
8400 Warnings about @samp{syntax} are enabled by default, and the environment
8401 variable @env{WARNINGS}, a comma separated list of categories, is
8402 honored.  @command{autom4te -W @var{category}} will actually
8403 behave as if you had run:
8405 @example
8406 autom4te --warnings=syntax,$WARNINGS,@var{category}
8407 @end example
8409 @noindent
8410 If you want to disable @command{autom4te}'s defaults and
8411 @env{WARNINGS}, but (for example) enable the warnings about obsolete
8412 constructs, you would use @option{-W none,obsolete}.
8414 @cindex Back trace
8415 @cindex Macro invocation stack
8416 @command{autom4te} displays a back trace for errors, but not for
8417 warnings; if you want them, just pass @option{-W error}.  For instance,
8418 on this @file{configure.ac}:
8420 @example
8421 AC_DEFUN([INNER],
8422 [AC_RUN_IFELSE([AC_LANG_PROGRAM([exit (0)])])])
8424 AC_DEFUN([OUTER],
8425 [INNER])
8427 AC_INIT
8428 OUTER
8429 @end example
8431 @noindent
8432 you get:
8434 @example
8435 $ @kbd{autom4te -l autoconf -Wcross}
8436 configure.ac:8: warning: AC_RUN_IFELSE called without default \
8437 to allow cross compiling
8438 $ @kbd{autom4te -l autoconf -Wcross,error -f}
8439 configure.ac:8: error: AC_RUN_IFELSE called without default \
8440 to allow cross compiling
8441 acgeneral.m4:3044: AC_RUN_IFELSE is expanded from...
8442 configure.ac:2: INNER is expanded from...
8443 configure.ac:5: OUTER is expanded from...
8444 configure.ac:8: the top level
8445 @end example
8448 @item --melt
8449 @itemx -m
8450 Do not use frozen files.  Any argument @code{@var{file}.m4f} will be
8451 replaced with @code{@var{file}.m4}.  This helps tracing the macros which
8452 are executed only when the files are frozen, typically
8453 @code{m4_define}.  For instance, running:
8455 @example
8456 autom4te --melt 1.m4 2.m4f 3.m4 4.m4f input.m4
8457 @end example
8459 @noindent
8460 is roughly equivalent to running:
8462 @example
8463 m4 1.m4 2.m4 3.m4 4.m4 input.m4
8464 @end example
8466 @noindent
8467 while
8469 @example
8470 autom4te 1.m4 2.m4f 3.m4 4.m4f input.m4
8471 @end example
8473 @noindent
8474 is equivalent to:
8476 @example
8477 m4 --reload-state=4.m4f input.m4
8478 @end example
8480 @item --freeze
8481 @itemx -f
8482 Produce a frozen state file.  @command{autom4te} freezing is stricter
8483 than M4's: it must produce no warnings, and no output other than empty
8484 lines (a line with whitespace is @emph{not} empty) and comments
8485 (starting with @samp{#}).  Please, note that contrary to @command{m4},
8486 this options takes no argument:
8488 @example
8489 autom4te 1.m4 2.m4 3.m4 --freeze --output=3.m4f
8490 @end example
8492 @noindent
8493 corresponds to
8495 @example
8496 m4 1.m4 2.m4 3.m4 --freeze-state=3.m4f
8497 @end example
8499 @item --mode=@var{octal-mode}
8500 @itemx -m @var{octal-mode}
8501 Set the mode of the non-traces output to @var{octal-mode}; by default
8502 @samp{0666}.
8503 @end table
8505 @sp 1
8507 @cindex @file{autom4te.cache}
8508 As another additional feature over @command{m4}, @command{autom4te}
8509 caches its results.  @acronym{GNU} M4 is able to produce a regular
8510 output and traces at the same time.  Traces are heavily used in the
8511 @acronym{GNU} Build System: @command{autoheader} uses them to build
8512 @file{config.h.in}, @command{autoreconf} to determine what
8513 @acronym{GNU} Build System components are used, @command{automake} to
8514 ``parse'' @file{configure.ac} etc.  To save the long runs of
8515 @command{m4}, traces are cached while performing regular expansion,
8516 and conversely.  This cache is (actually, the caches are) stored in
8517 the directory @file{autom4te.cache}.  @emph{It can safely be removed}
8518 at any moment (especially if for some reason @command{autom4te}
8519 considers it is trashed).
8521 @table @option
8522 @item --cache=@var{directory}
8523 @itemx -C @var{directory}
8524 Specify the name of the directory where the result should be cached.
8525 Passing an empty value disables caching.  Be sure to pass a relative
8526 file name, as for the time being, global caches are not supported.
8528 @item --no-cache
8529 Don't cache the results.
8531 @item --force
8532 @itemx -f
8533 If a cache is used, consider it obsolete (but update it anyway).
8534 @end table
8536 @sp 1
8538 Because traces are so important to the @acronym{GNU} Build System,
8539 @command{autom4te} provides high level tracing features as compared to
8540 M4, and helps exploiting the cache:
8542 @table @option
8543 @item --trace=@var{macro}[:@var{format}]
8544 @itemx -t @var{macro}[:@var{format}]
8545 Trace the invocations of @var{macro} according to the @var{format}.
8546 Multiple @option{--trace} arguments can be used to list several macros.
8547 Multiple @option{--trace} arguments for a single macro are not
8548 cumulative; instead, you should just make @var{format} as long as
8549 needed.
8551 The @var{format} is a regular string, with newlines if desired, and
8552 several special escape codes.  It defaults to @samp{$f:$l:$n:$%}.  It can
8553 use the following special escapes:
8555 @table @samp
8556 @item $$
8557 The character @samp{$}.
8559 @item $f
8560 The file name from which @var{macro} is called.
8562 @item $l
8563 The line number from which @var{macro} is called.
8565 @item $d
8566 The depth of the @var{macro} call.  This is an M4 technical detail that
8567 you probably don't want to know about.
8569 @item $n
8570 The name of the @var{macro}.
8572 @item $@var{num}
8573 The @var{num}th argument of the call to @var{macro}.
8575 @item $@@
8576 @itemx $@var{sep}@@
8577 @itemx $@{@var{separator}@}@@
8578 All the arguments passed to @var{macro}, separated by the character
8579 @var{sep} or the string @var{separator} (@samp{,} by default).  Each
8580 argument is quoted, i.e., enclosed in a pair of square brackets.
8582 @item $*
8583 @itemx $@var{sep}*
8584 @itemx $@{@var{separator}@}*
8585 As above, but the arguments are not quoted.
8587 @item $%
8588 @itemx $@var{sep}%
8589 @itemx $@{@var{separator}@}%
8590 As above, but the arguments are not quoted, all new line characters in
8591 the arguments are smashed, and the default separator is @samp{:}.
8593 The escape @samp{$%} produces single-line trace outputs (unless you put
8594 newlines in the @samp{separator}), while @samp{$@@} and @samp{$*} do
8595 not.
8596 @end table
8598 @xref{autoconf Invocation}, for examples of trace uses.
8600 @item --preselect=@var{macro}
8601 @itemx -p @var{macro}
8602 Cache the traces of @var{macro}, but do not enable traces.  This is
8603 especially important to save CPU cycles in the future.  For instance,
8604 when invoked, @command{autoconf} preselects all the macros that
8605 @command{autoheader}, @command{automake}, @command{autoreconf} etc.@: will
8606 trace, so that running @command{m4} is not needed to trace them: the
8607 cache suffices.  This results in a huge speed-up.
8608 @end table
8610 @sp 1
8612 @cindex Autom4te Library
8613 Finally, @command{autom4te} introduces the concept of @dfn{Autom4te
8614 libraries}.  They consists in a powerful yet extremely simple feature:
8615 sets of combined command line arguments:
8617 @table @option
8618 @item --language=@var{language}
8619 @itemx -l @var{language}
8620 Use the @var{language} Autom4te library.  Current languages include:
8622 @table @code
8623 @item M4sugar
8624 create M4sugar output.
8626 @item M4sh
8627 create M4sh executable shell scripts.
8629 @item Autotest
8630 create Autotest executable test suites.
8632 @item Autoconf-without-aclocal-m4
8633 create Autoconf executable configure scripts without
8634 reading @file{aclocal.m4}.
8636 @item Autoconf
8637 create Autoconf executable configure scripts.  This language inherits
8638 all the characteristics of @code{Autoconf-without-aclocal-m4} and will
8639 additionally read @file{aclocal.m4}.
8640 @end table
8642 @item --prepend-include=@var{dir}
8643 @item -B @var{dir}
8644 Prepend directory @var{dir} to the search path.  This is used to include
8645 the language-specific files before any third-party macros.
8647 @end table
8649 @cindex @file{autom4te.cfg}
8650 As an example, if Autoconf is installed in its default location,
8651 @file{/usr/local}, running @samp{autom4te -l m4sugar foo.m4} is
8652 strictly equivalent to running @samp{autom4te --prepend-include
8653 /usr/local/share/autoconf m4sugar/m4sugar.m4f --warnings syntax foo.m4}.
8654 Recursive expansion applies: running @samp{autom4te -l m4sh foo.m4}
8655 is the same as @samp{autom4te --language M4sugar m4sugar/m4sh.m4f
8656 foo.m4}, i.e., @samp{autom4te --prepend-include /usr/local/share/autoconf
8657 m4sugar/m4sugar.m4f m4sugar/m4sh.m4f --mode 777 foo.m4}.  The definition
8658 of the languages is stored in @file{autom4te.cfg}.
8660 @node Customizing autom4te
8661 @subsection Customizing @command{autom4te}
8663 One can customize @command{autom4te} via @file{~/.autom4te.cfg} (i.e.,
8664 as found in the user home directory), and @file{./.autom4te.cfg} (i.e.,
8665 as found in the directory from which @command{autom4te} is run).  The
8666 order is first reading @file{autom4te.cfg}, then @file{~/.autom4te.cfg},
8667 then @file{./.autom4te.cfg}, and finally the command line arguments.
8669 In these text files, comments are introduced with @code{#}, and empty
8670 lines are ignored.  Customization is performed on a per-language basis,
8671 wrapped in between a @samp{begin-language: "@var{language}"},
8672 @samp{end-language: "@var{language}"} pair.
8674 Customizing a language stands for appending options (@pxref{autom4te
8675 Invocation}) to the current definition of the language.  Options, and
8676 more generally arguments, are introduced by @samp{args:
8677 @var{arguments}}.  You may use the traditional shell syntax to quote the
8678 @var{arguments}.
8680 As an example, to disable Autoconf caches (@file{autom4te.cache})
8681 globally, include the following lines in @file{~/.autom4te.cfg}:
8683 @verbatim
8684 ## ------------------ ##
8685 ## User Preferences.  ##
8686 ## ------------------ ##
8688 begin-language: "Autoconf-without-aclocal-m4"
8689 args: --no-cache
8690 end-language: "Autoconf-without-aclocal-m4"
8691 @end verbatim
8694 @node Programming in M4sugar
8695 @section Programming in M4sugar
8697 @cindex M4sugar
8698 M4 by itself provides only a small, but sufficient, set of all-purpose
8699 macros.  M4sugar introduces additional generic macros.  Its name was
8700 coined by Lars J. Aas: ``Readability And Greater Understanding Stands 4
8701 M4sugar''.
8703 @menu
8704 * Redefined M4 Macros::         M4 builtins changed in M4sugar
8705 * Evaluation Macros::           More quotation and evaluation control
8706 * Forbidden Patterns::          Catching unexpanded macros
8707 @end menu
8709 @node Redefined M4 Macros
8710 @subsection Redefined M4 Macros
8712 With a few exceptions, all the M4 native macros are moved in the
8713 @samp{m4_} pseudo-namespace, e.g., M4sugar renames @code{define} as
8714 @code{m4_define} etc.
8716 Some M4 macros are redefined, and are slightly incompatible with their
8717 native equivalent.
8719 @defmac dnl
8720 @msindex{dnl}
8721 This macro kept its original name: no @code{m4_dnl} is defined.
8722 @end defmac
8724 @defmac m4_defn (@var{macro})
8725 @msindex{defn}
8726 Contrary to the M4 builtin, this macro fails if @var{macro} is not
8727 defined.  See @code{m4_undefine}.
8728 @end defmac
8730 @defmac m4_exit (@var{exit-status})
8731 @msindex{exit}
8732 This macro corresponds to @code{m4exit}.
8733 @end defmac
8735 @defmac m4_if (@var{comment})
8736 @defmacx m4_if (@var{string-1}, @var{string-2}, @var{equal}, @ovar{not-equal})
8737 @defmacx m4_if (@var{string-1}, @var{string-2}, @var{equal}, @dots{})
8738 @msindex{if}
8739 This macro corresponds to @code{ifelse}.
8740 @end defmac
8742 @defmac m4_undefine (@var{macro})
8743 @msindex{undefine}
8744 Contrary to the M4 builtin, this macro fails if @var{macro} is not
8745 defined.  Use
8747 @example
8748 m4_ifdef([@var{macro}], [m4_undefine([@var{macro}])])
8749 @end example
8751 @noindent
8752 to recover the behavior of the builtin.
8753 @end defmac
8755 @defmac m4_bpatsubst (@var{string}, @var{regexp}, @ovar{replacement})
8756 @msindex{bpatsubst}
8757 This macro corresponds to @code{patsubst}.  The name @code{m4_patsubst}
8758 is kept for future versions of M4sh, on top of @acronym{GNU} M4 which will
8759 provide extended regular expression syntax via @code{epatsubst}.
8760 @end defmac
8762 @defmac m4_popdef (@var{macro})
8763 @msindex{popdef}
8764 Contrary to the M4 builtin, this macro fails if @var{macro} is not
8765 defined.  See @code{m4_undefine}.
8766 @end defmac
8768 @defmac m4_bregexp (@var{string}, @var{regexp}, @ovar{replacement})
8769 @msindex{bregexp}
8770 This macro corresponds to @code{regexp}.  The name @code{m4_regexp}
8771 is kept for future versions of M4sh, on top of @acronym{GNU} M4 which will
8772 provide extended regular expression syntax via @code{eregexp}.
8773 @end defmac
8775 @defmac m4_wrap (@var{text})
8776 @msindex{wrap}
8777 This macro corresponds to @code{m4wrap}.
8779 You are encouraged to end @var{text} with @samp{[]}, so that there are
8780 no risks that two consecutive invocations of @code{m4_wrap} result in an
8781 unexpected pasting of tokens, as in
8783 @example
8784 m4_define([foo], [Foo])
8785 m4_define([bar], [Bar])
8786 m4_define([foobar], [FOOBAR])
8787 m4_wrap([bar])
8788 m4_wrap([foo])
8789 @result{}FOOBAR
8790 @end example
8791 @end defmac
8793 @node Evaluation Macros
8794 @subsection Evaluation Macros
8796 The following macros give some control over the order of the evaluation
8797 by adding or removing levels of quotes.  They are meant for hard-core M4
8798 programmers.
8800 @defmac m4_dquote (@var{arg1}, @dots{})
8801 @msindex{dquote}
8802 Return the arguments as a quoted list of quoted arguments.
8803 @end defmac
8805 @defmac m4_quote (@var{arg1}, @dots{})
8806 @msindex{quote}
8807 Return the arguments as a single entity, i.e., wrap them into a pair of
8808 quotes.
8809 @end defmac
8811 The following example aims at emphasizing the difference between (i), not
8812 using these macros, (ii), using @code{m4_quote}, and (iii), using
8813 @code{m4_dquote}.
8815 @example
8816 $ @kbd{cat example.m4}
8817 # Overquote, so that quotes are visible.
8818 m4_define([show], [$[]1 = [$1], $[]@@ = [$@@]])
8819 m4_divert(0)dnl
8820 show(a, b)
8821 show(m4_quote(a, b))
8822 show(m4_dquote(a, b))
8823 $ @kbd{autom4te -l m4sugar example.m4}
8824 $1 = a, $@@ = [a],[b]
8825 $1 = a,b, $@@ = [a,b]
8826 $1 = [a],[b], $@@ = [[a],[b]]
8827 @end example
8831 @node Forbidden Patterns
8832 @subsection Forbidden Patterns
8833 @cindex Forbidden patterns
8834 @cindex Patterns, forbidden
8836 M4sugar provides a means to define suspicious patterns, patterns
8837 describing tokens which should not be found in the output.  For
8838 instance, if an Autoconf @file{configure} script includes tokens such as
8839 @samp{AC_DEFINE}, or @samp{dnl}, then most probably something went
8840 wrong (typically a macro was not evaluated because of overquotation).
8842 M4sugar forbids all the tokens matching @samp{^m4_} and @samp{^dnl$}.
8844 @defmac m4_pattern_forbid (@var{pattern})
8845 @msindex{pattern_forbid}
8846 Declare that no token matching @var{pattern} must be found in the output.
8847 Comments are not checked; this can be a problem if, for instance, you
8848 have some macro left unexpanded after an @samp{#include}.  No consensus
8849 is currently found in the Autoconf community, as some people consider it
8850 should be valid to name macros in comments (which doesn't make sense to
8851 the author of this documentation, as @samp{#}-comments should document
8852 the output, not the input, documented by @samp{dnl} comments).
8853 @end defmac
8855 Of course, you might encounter exceptions to these generic rules, for
8856 instance you might have to refer to @samp{$m4_flags}.
8858 @defmac m4_pattern_allow (@var{pattern})
8859 @msindex{pattern_allow}
8860 Any token matching @var{pattern} is allowed, including if it matches an
8861 @code{m4_pattern_forbid} pattern.
8862 @end defmac
8864 @node Programming in M4sh
8865 @section Programming in M4sh
8867 @c FIXME: Eventually will become a chapter, as it is not related to
8868 @c programming in M4 per se.
8870 M4sh, pronounced ``mash'', is aiming at producing portable Bourne shell
8871 scripts.  This name was coined by Lars J. Aas, who notes that,
8872 according to the Webster's Revised Unabridged Dictionary (1913):
8874 @quotation
8875 Mash \Mash\, n.  [Akin to G. meisch, maisch, meische, maische, mash,
8876 wash, and prob.@: to AS. miscian to mix.  See ``Mix''.]
8878 @enumerate 1
8879 @item
8880 A mass of mixed ingredients reduced to a soft pulpy state by beating or
8881 pressure@enddots{}
8883 @item
8884 A mixture of meal or bran and water fed to animals.
8886 @item
8887 A mess; trouble.  [Obs.] --Beau.@: & Fl.
8888 @end enumerate
8889 @end quotation
8892 For the time being, it is not mature enough to be widely used.
8894 M4sh provides portable alternatives for some common shell constructs
8895 that unfortunately are not portable in practice.
8897 @defmac AS_DIRNAME (@var{file-name})
8898 @asindex{DIRNAME}
8899 Return the directory portion of @var{file-name}, using the algorithm
8900 required by Posix.  @xref{Limitations of Usual Tools}, for more
8901 details about what this returns and why it is more portable than the
8902 @command{dirname} command.
8903 @end defmac
8905 @defmac AS_IF (@var{test}, @ovar{RUN-IF-TRUE}, @ovar{RUN-IF-FALSE})
8906 @asindex{IF}
8907 Run shell code TEST.  If TEST exits with a zero status then run shell code
8908 RUN-IF-TRUE, else run shell code RUN-IF-FALSE, with simplifications if either
8909 RUN-IF-TRUE or RUN-IF-FALSE is empty.
8910 @end defmac
8912 @defmac AS_MKDIR_P (@var{file-name})
8913 @asindex{MKDIR_P}
8914 Make the directory @var{file-name}, including intervening directories
8915 as necessary.  This is equivalent to @samp{mkdir -p @var{file-name}},
8916 except that it is portable to older versions of @command{mkdir} that
8917 lack support for the @option{-p} option.  Also, @code{AS_MKDIR_P}
8918 succeeds if @var{file-name} is a symbolic link to an existing directory,
8919 even though Posix is unclear whether @samp{mkdir -p} should
8920 succeed in that case.
8921 @end defmac
8923 @defmac AS_SET_CATFILE (@var{var}, @var{dir}, @var{file})
8924 @asindex{SET_CATFILE}
8925 Set the shell variable @var{var} to @var{dir}/@var{file}, but
8926 optimizing the common cases (@var{dir} or @var{file} is @samp{.},
8927 @var{file} is absolute, etc.).
8928 @end defmac
8931 @node File Descriptor Macros
8932 @section File Descriptor Macros
8933 @cindex input
8934 @cindex standard input
8935 @cindex file descriptors
8936 @cindex descriptors
8937 @cindex low-level output
8938 @cindex output, low-level
8940 The following macros define file descriptors used to output messages
8941 (or input values) from @file{configure} scripts.
8942 For example:
8944 @example
8945 echo "$wombats found" >&AS_MESSAGE_LOG_FD
8946 echo 'Enter desired kangaroo count:' >&AS_MESSAGE_FD
8947 read kangaroos <&AS_ORIGINAL_STDIN_FD`
8948 @end example
8950 @noindent
8951 However doing so is seldom needed, because Autoconf provides higher
8952 level macros as described below.
8954 @defmac AS_MESSAGE_FD
8955 @asindex{MESSAGE_FD}
8956 The file descriptor for @samp{checking for...}  messages and results.
8957 Normally this directs messages to the standard output, however when
8958 @command{configure} is run with the @code{-q} option, messages sent to
8959 @code{AS_MESSAGE_FD} will be discarded.
8961 If you want to display some messages, consider using one of the printing
8962 macros (@pxref{Printing Messages}) instead.  Copies of messages output
8963 via these macros will additionally be recorded in @file{config.log}.
8964 @end defmac
8966 @defmac AS_MESSAGE_LOG_FD
8967 @asindex{MESSAGE_LOG_FD}
8969 The file descriptor for messages logged to @file{config.log}.  Macros
8970 that run tools, like @code{AC_COMPILE_IFELSE} (@pxref{Running the
8971 Compiler}), redirect all output to this descriptor.  You may want to do
8972 so if you develop such a low-level macro.
8973 @end defmac
8975 @defmac AS_ORIGINAL_STDIN_FD
8976 @asindex{ORIGINAL_STDIN_FD}
8977 The file descriptor for the original standard input.
8979 When @command{configure} runs, it may accidentally execute an
8980 interactive command that has the same name as the non-interactive meant
8981 to be used or checked.  If the standard input was the terminal, such
8982 interactive programs would cause @command{configure} to stop, pending
8983 some user input.  Therefore @command{configure} redirects its standard
8984 input from @file{/dev/null} during its initialization.  This is not
8985 normally a problem, since @command{configure} normally does not need
8986 user input.
8988 In the extreme case where your @file{configure} script really needs to
8989 obtain some values from the original standard input, you can read them
8990 explicitly from @code{AS_ORIGINAL_STDIN_FD}.
8991 @end defmac
8994 @c=================================================== Writing Autoconf Macros.
8996 @node Writing Autoconf Macros
8997 @chapter Writing Autoconf Macros
8999 When you write a feature test that could be applicable to more than one
9000 software package, the best thing to do is encapsulate it in a new macro.
9001 Here are some instructions and guidelines for writing Autoconf macros.
9003 @menu
9004 * Macro Definitions::           Basic format of an Autoconf macro
9005 * Macro Names::                 What to call your new macros
9006 * Reporting Messages::          Notifying @command{autoconf} users
9007 * Dependencies Between Macros::  What to do when macros depend on other macros
9008 * Obsoleting Macros::           Warning about old ways of doing things
9009 * Coding Style::                Writing Autoconf macros @`a la Autoconf
9010 @end menu
9012 @node Macro Definitions
9013 @section Macro Definitions
9015 @acindex{DEFUN}
9016 Autoconf macros are defined using the @code{AC_DEFUN} macro, which is
9017 similar to the M4 builtin @code{m4_define} macro.  In addition to
9018 defining a macro, @code{AC_DEFUN} adds to it some code that is used to
9019 constrain the order in which macros are called (@pxref{Prerequisite
9020 Macros}).
9022 An Autoconf macro definition looks like this:
9024 @example
9025 AC_DEFUN(@var{macro-name}, @var{macro-body})
9026 @end example
9028 You can refer to any arguments passed to the macro as @samp{$1},
9029 @samp{$2}, etc.  @xref{Definitions,, How to define new macros, m4.info,
9030 @acronym{GNU} m4}, for more complete information on writing M4 macros.
9032 Be sure to properly quote both the @var{macro-body} @emph{and} the
9033 @var{macro-name} to avoid any problems if the macro happens to have
9034 been previously defined.
9036 Each macro should have a header comment that gives its prototype, and a
9037 brief description.  When arguments have default values, display them in
9038 the prototype.  For example:
9040 @example
9041 # AC_MSG_ERROR(ERROR, [EXIT-STATUS = 1])
9042 # --------------------------------------
9043 m4_define([AC_MSG_ERROR],
9044 [@{ _AC_ECHO([configure: error: $1], 2); exit m4_default([$2], 1); @}])
9045 @end example
9047 Comments about the macro should be left in the header comment.  Most
9048 other comments will make their way into @file{configure}, so just keep
9049 using @samp{#} to introduce comments.
9051 @cindex @code{dnl}
9052 If you have some very special comments about pure M4 code, comments
9053 that make no sense in @file{configure} and in the header comment, then
9054 use the builtin @code{dnl}: it causes M4 to discard the text
9055 through the next newline.
9057 Keep in mind that @code{dnl} is rarely needed to introduce comments;
9058 @code{dnl} is more useful to get rid of the newlines following macros
9059 that produce no output, such as @code{AC_REQUIRE}.
9062 @node Macro Names
9063 @section Macro Names
9065 All of the Autoconf macros have all-uppercase names starting with
9066 @samp{AC_} to prevent them from accidentally conflicting with other
9067 text.  All shell variables that they use for internal purposes have
9068 mostly-lowercase names starting with @samp{ac_}.  To ensure that your
9069 macros don't conflict with present or future Autoconf macros, you should
9070 prefix your own macro names and any shell variables they use with some
9071 other sequence.  Possibilities include your initials, or an abbreviation
9072 for the name of your organization or software package.
9074 Most of the Autoconf macros' names follow a structured naming convention
9075 that indicates the kind of feature check by the name.  The macro names
9076 consist of several words, separated by underscores, going from most
9077 general to most specific.  The names of their cache variables use the
9078 same convention (@pxref{Cache Variable Names}, for more information on
9079 them).
9081 The first word of the name after @samp{AC_} usually tells the category
9082 of the feature being tested.  Here are the categories used in Autoconf for
9083 specific test macros, the kind of macro that you are more likely to
9084 write.  They are also used for cache variables, in all-lowercase.  Use
9085 them where applicable; where they're not, invent your own categories.
9087 @table @code
9088 @item C
9089 C language builtin features.
9090 @item DECL
9091 Declarations of C variables in header files.
9092 @item FUNC
9093 Functions in libraries.
9094 @item GROUP
9095 Posix group owners of files.
9096 @item HEADER
9097 Header files.
9098 @item LIB
9099 C libraries.
9100 @item PATH
9101 Absolute names of files, including programs.
9102 @item PROG
9103 The base names of programs.
9104 @item MEMBER
9105 Members of aggregates.
9106 @item SYS
9107 Operating system features.
9108 @item TYPE
9109 C builtin or declared types.
9110 @item VAR
9111 C variables in libraries.
9112 @end table
9114 After the category comes the name of the particular feature being
9115 tested.  Any further words in the macro name indicate particular aspects
9116 of the feature.  For example, @code{AC_FUNC_UTIME_NULL} checks the
9117 behavior of the @code{utime} function when called with a @code{NULL}
9118 pointer.
9120 An internal macro should have a name that starts with an underscore;
9121 Autoconf internals should therefore start with @samp{_AC_}.
9122 Additionally, a macro that is an internal subroutine of another macro
9123 should have a name that starts with an underscore and the name of that
9124 other macro, followed by one or more words saying what the internal
9125 macro does.  For example, @code{AC_PATH_X} has internal macros
9126 @code{_AC_PATH_X_XMKMF} and @code{_AC_PATH_X_DIRECT}.
9128 @node Reporting Messages
9129 @section Reporting Messages
9130 @cindex Messages, from @command{autoconf}
9132 When macros statically diagnose abnormal situations, benign or fatal,
9133 they should report them using these macros.  For dynamic issues, i.e.,
9134 when @command{configure} is run, see @ref{Printing Messages}.
9136 @defmac AC_DIAGNOSE (@var{category}, @var{message})
9137 @acindex{DIAGNOSE}
9138 Report @var{message} as a warning (or as an error if requested by the
9139 user) if warnings of the @var{category} are turned on.  You are
9140 encouraged to use standard categories, which currently include:
9142 @table @samp
9143 @item all
9144 messages that don't fall into one of the following categories.  Use of an
9145 empty @var{category} is equivalent.
9147 @item cross
9148 related to cross compilation issues.
9150 @item obsolete
9151 use of an obsolete construct.
9153 @item syntax
9154 dubious syntactic constructs, incorrectly ordered macro calls.
9155 @end table
9156 @end defmac
9158 @defmac AC_WARNING (@var{message})
9159 @acindex{WARNING}
9160 Equivalent to @samp{AC_DIAGNOSE([syntax], @var{message})}, but you are
9161 strongly encouraged to use a finer grained category.
9162 @end defmac
9164 @defmac AC_FATAL (@var{message})
9165 @acindex{FATAL}
9166 Report a severe error @var{message}, and have @command{autoconf} die.
9167 @end defmac
9169 When the user runs @samp{autoconf -W error}, warnings from
9170 @code{AC_DIAGNOSE} and @code{AC_WARNING} are reported as error, see
9171 @ref{autoconf Invocation}.
9173 @node Dependencies Between Macros
9174 @section Dependencies Between Macros
9175 @cindex Dependencies between macros
9177 Some Autoconf macros depend on other macros having been called first in
9178 order to work correctly.  Autoconf provides a way to ensure that certain
9179 macros are called if needed and a way to warn the user if macros are
9180 called in an order that might cause incorrect operation.
9182 @menu
9183 * Prerequisite Macros::         Ensuring required information
9184 * Suggested Ordering::          Warning about possible ordering problems
9185 * One-Shot Macros::             Ensuring a macro is called only once
9186 @end menu
9188 @node Prerequisite Macros
9189 @subsection Prerequisite Macros
9190 @cindex Prerequisite macros
9191 @cindex Macros, prerequisites
9193 A macro that you write might need to use values that have previously
9194 been computed by other macros.  For example, @code{AC_DECL_YYTEXT}
9195 examines the output of @code{flex} or @code{lex}, so it depends on
9196 @code{AC_PROG_LEX} having been called first to set the shell variable
9197 @code{LEX}.
9199 Rather than forcing the user of the macros to keep track of the
9200 dependencies between them, you can use the @code{AC_REQUIRE} macro to do
9201 it automatically.  @code{AC_REQUIRE} can ensure that a macro is only
9202 called if it is needed, and only called once.
9204 @defmac AC_REQUIRE (@var{macro-name})
9205 @acindex{REQUIRE}
9206 If the M4 macro @var{macro-name} has not already been called, call it
9207 (without any arguments).  Make sure to quote @var{macro-name} with
9208 square brackets.  @var{macro-name} must have been defined using
9209 @code{AC_DEFUN} or else contain a call to @code{AC_PROVIDE} to indicate
9210 that it has been called.
9212 @code{AC_REQUIRE} must be used inside an @code{AC_DEFUN}'d macro; it
9213 must not be called from the top level.
9214 @end defmac
9216 @code{AC_REQUIRE} is often misunderstood.  It really implements
9217 dependencies between macros in the sense that if one macro depends upon
9218 another, the latter will be expanded @emph{before} the body of the
9219 former.  In particular, @samp{AC_REQUIRE(FOO)} is not replaced with the
9220 body of @code{FOO}.  For instance, this definition of macros:
9222 @example
9223 @group
9224 AC_DEFUN([TRAVOLTA],
9225 [test "$body_temperature_in_celsius" -gt "38" &&
9226   dance_floor=occupied])
9227 AC_DEFUN([NEWTON_JOHN],
9228 [test "$hair_style" = "curly" &&
9229   dance_floor=occupied])
9230 @end group
9232 @group
9233 AC_DEFUN([RESERVE_DANCE_FLOOR],
9234 [if date | grep '^Sat.*pm' >/dev/null 2>&1; then
9235   AC_REQUIRE([TRAVOLTA])
9236   AC_REQUIRE([NEWTON_JOHN])
9237 fi])
9238 @end group
9239 @end example
9241 @noindent
9242 with this @file{configure.ac}
9244 @example
9245 AC_INIT
9246 RESERVE_DANCE_FLOOR
9247 if test "$dance_floor" = occupied; then
9248   AC_MSG_ERROR([cannot pick up here, let's move])
9250 @end example
9252 @noindent
9253 will not leave you with a better chance to meet a kindred soul at
9254 other times than Saturday night since it expands into:
9256 @example
9257 @group
9258 test "$body_temperature_in_Celsius" -gt "38" &&
9259   dance_floor=occupied
9260 test "$hair_style" = "curly" &&
9261   dance_floor=occupied
9263 if date | grep '^Sat.*pm' >/dev/null 2>&1; then
9267 @end group
9268 @end example
9270 This behavior was chosen on purpose: (i) it prevents messages in
9271 required macros from interrupting the messages in the requiring macros;
9272 (ii) it avoids bad surprises when shell conditionals are used, as in:
9274 @example
9275 @group
9276 if @dots{}; then
9277   AC_REQUIRE([SOME_CHECK])
9279 @dots{}
9280 SOME_CHECK
9281 @end group
9282 @end example
9285 You are encouraged to put all @code{AC_REQUIRE}s at the beginning of a
9286 macro.  You can use @code{dnl} to avoid the empty lines they leave.
9288 @node Suggested Ordering
9289 @subsection Suggested Ordering
9290 @cindex Macros, ordering
9291 @cindex Ordering macros
9293 Some macros should be run before another macro if both are called, but
9294 neither @emph{requires} that the other be called.  For example, a macro
9295 that changes the behavior of the C compiler should be called before any
9296 macros that run the C compiler.  Many of these dependencies are noted in
9297 the documentation.
9299 Autoconf provides the @code{AC_BEFORE} macro to warn users when macros
9300 with this kind of dependency appear out of order in a
9301 @file{configure.ac} file.  The warning occurs when creating
9302 @command{configure} from @file{configure.ac}, not when running
9303 @command{configure}.
9305 For example, @code{AC_PROG_CPP} checks whether the C compiler
9306 can run the C preprocessor when given the @option{-E} option.  It should
9307 therefore be called after any macros that change which C compiler is
9308 being used, such as @code{AC_PROG_CC}.  So @code{AC_PROG_CC} contains:
9310 @example
9311 AC_BEFORE([$0], [AC_PROG_CPP])dnl
9312 @end example
9314 @noindent
9315 This warns the user if a call to @code{AC_PROG_CPP} has already occurred
9316 when @code{AC_PROG_CC} is called.
9318 @defmac AC_BEFORE (@var{this-macro-name}, @var{called-macro-name})
9319 @acindex{BEFORE}
9320 Make M4 print a warning message to the standard error output if
9321 @var{called-macro-name} has already been called.  @var{this-macro-name}
9322 should be the name of the macro that is calling @code{AC_BEFORE}.  The
9323 macro @var{called-macro-name} must have been defined using
9324 @code{AC_DEFUN} or else contain a call to @code{AC_PROVIDE} to indicate
9325 that it has been called.
9326 @end defmac
9328 @node One-Shot Macros
9329 @subsection One-Shot Macros
9330 @cindex One-shot macros
9331 @cindex Macros, called once
9333 Some macros should be called only once, either because calling them
9334 multiple time is unsafe, or because it is bad style.  For instance
9335 Autoconf ensures that @code{AC_CANONICAL_BUILD} and cousins
9336 (@pxref{Canonicalizing}) are evaluated only once, because it makes no
9337 sense to run these expensive checks more than once.  Such one-shot
9338 macros can be defined using @code{AC_DEFUN_ONCE}.
9340 @defmac AC_DEFUN_ONCE (@var{macro-name}, @var{macro-body})
9341 @acindex{DEFUN_ONCE}
9343 Declare macro @var{macro-name} like @code{AC_DEFUN} would (@pxref{Macro
9344 Definitions}), and emit a warning any time the macro is called more than
9345 once.
9346 @end defmac
9348 Obviously it is not sensible to evaluate a macro defined by
9349 @code{AC_DEFUN_ONCE} in a macro defined by @code{AC_DEFUN}, most of the
9350 times you will want to use @code{AC_REQUIRE} (@pxref{Prerequisite
9351 Macros}).
9353 @node Obsoleting Macros
9354 @section Obsoleting Macros
9355 @cindex Obsoleting macros
9356 @cindex Macros, obsoleting
9358 Configuration and portability technology has evolved over the years.
9359 Often better ways of solving a particular problem are developed, or
9360 ad-hoc approaches are systematized.  This process has occurred in many
9361 parts of Autoconf.  One result is that some of the macros are now
9362 considered @dfn{obsolete}; they still work, but are no longer considered
9363 the best thing to do, hence they should be replaced with more modern
9364 macros.  Ideally, @command{autoupdate} should replace the old macro calls
9365 with their modern implementation.
9367 Autoconf provides a simple means to obsolete a macro.
9369 @defmac AU_DEFUN (@var{old-macro}, @var{implementation}, @ovar{message})
9370 @auindex{DEFUN}
9371 Define @var{old-macro} as @var{implementation}.  The only difference
9372 with @code{AC_DEFUN} is that the user will be warned that
9373 @var{old-macro} is now obsolete.
9375 If she then uses @command{autoupdate}, the call to @var{old-macro} will be
9376 replaced by the modern @var{implementation}.  @var{message} should
9377 include information on what to do after running @command{autoupdate};
9378 @command{autoupdate} will print it as a warning, and include it
9379 in the updated @file{configure.ac} file.
9380 @end defmac
9382 @node Coding Style
9383 @section Coding Style
9384 @cindex Coding style
9386 The Autoconf macros follow a strict coding style.  You are encouraged to
9387 follow this style, especially if you intend to distribute your macro,
9388 either by contributing it to Autoconf itself, or via other means.
9390 The first requirement is to pay great attention to the quotation.  For
9391 more details, see @ref{Autoconf Language}, and @ref{M4 Quotation}.
9393 Do not try to invent new interfaces.  It is likely that there is a macro
9394 in Autoconf that resembles the macro you are defining: try to stick to
9395 this existing interface (order of arguments, default values, etc.).  We
9396 @emph{are} conscious that some of these interfaces are not perfect;
9397 nevertheless, when harmless, homogeneity should be preferred over
9398 creativity.
9400 Be careful about clashes both between M4 symbols and between shell
9401 variables.
9403 If you stick to the suggested M4 naming scheme (@pxref{Macro Names}),
9404 you are unlikely to generate conflicts.  Nevertheless, when you need to
9405 set a special value, @emph{avoid using a regular macro name}; rather,
9406 use an ``impossible'' name.  For instance, up to version 2.13, the macro
9407 @code{AC_SUBST} used to remember what @var{symbol}s were already defined
9408 by setting @code{AC_SUBST_@var{symbol}}, which is a regular macro name.
9409 But since there is a macro named @code{AC_SUBST_FILE}, it was just
9410 impossible to @samp{AC_SUBST(FILE)}!  In this case,
9411 @code{AC_SUBST(@var{symbol})} or @code{_AC_SUBST(@var{symbol})} should
9412 have been used (yes, with the parentheses)@dots{}or better yet, high-level
9413 macros such as @code{AC_EXPAND_ONCE}.
9415 No Autoconf macro should ever enter the user-variable name space; i.e.,
9416 except for the variables that are the actual result of running the
9417 macro, all shell variables should start with @code{ac_}.  In
9418 addition, small macros or any macro that is likely to be embedded in
9419 other macros should be careful not to use obvious names.
9421 @cindex @code{dnl}
9422 Do not use @code{dnl} to introduce comments: most of the comments you
9423 are likely to write are either header comments which are not output
9424 anyway, or comments that should make their way into @file{configure}.
9425 There are exceptional cases where you do want to comment special M4
9426 constructs, in which case @code{dnl} is right, but keep in mind that it
9427 is unlikely.
9429 M4 ignores the leading spaces before each argument, use this feature to
9430 indent in such a way that arguments are (more or less) aligned with the
9431 opening parenthesis of the macro being called.  For instance, instead of
9433 @example
9434 AC_CACHE_CHECK(for EMX OS/2 environment,
9435 ac_cv_emxos2,
9436 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __EMX__;])],
9437 [ac_cv_emxos2=yes], [ac_cv_emxos2=no])])
9438 @end example
9440 @noindent
9441 write
9443 @example
9444 AC_CACHE_CHECK([for EMX OS/2 environment], [ac_cv_emxos2],
9445 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return __EMX__;])],
9446                    [ac_cv_emxos2=yes],
9447                    [ac_cv_emxos2=no])])
9448 @end example
9450 @noindent
9451 or even
9453 @example
9454 AC_CACHE_CHECK([for EMX OS/2 environment],
9455                [ac_cv_emxos2],
9456                [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
9457                                                    [return __EMX__;])],
9458                                   [ac_cv_emxos2=yes],
9459                                   [ac_cv_emxos2=no])])
9460 @end example
9462 When using @code{AC_RUN_IFELSE} or any macro that cannot work when
9463 cross-compiling, provide a pessimistic value (typically @samp{no}).
9465 Feel free to use various tricks to prevent auxiliary tools, such as
9466 syntax-highlighting editors, from behaving improperly.  For instance,
9467 instead of:
9469 @example
9470 m4_bpatsubst([$1], [$"])
9471 @end example
9473 @noindent
9476 @example
9477 m4_bpatsubst([$1], [$""])
9478 @end example
9480 @noindent
9481 so that Emacsen do not open an endless ``string'' at the first quote.
9482 For the same reasons, avoid:
9484 @example
9485 test $[#] != 0
9486 @end example
9488 @noindent
9489 and use:
9491 @example
9492 test $[@@%:@@] != 0
9493 @end example
9495 @noindent
9496 Otherwise, the closing bracket would be hidden inside a @samp{#}-comment,
9497 breaking the bracket-matching highlighting from Emacsen.  Note the
9498 preferred style to escape from M4: @samp{$[1]}, @samp{$[@@]}, etc.  Do
9499 not escape when it is unnecessary.  Common examples of useless quotation
9500 are @samp{[$]$1} (write @samp{$$1}), @samp{[$]var} (use @samp{$var}),
9501 etc.  If you add portability issues to the picture, you'll prefer
9502 @samp{$@{1+"$[@@]"@}} to @samp{"[$]@@"}, and you'll prefer do something
9503 better than hacking Autoconf @code{:-)}.
9505 When using @command{sed}, don't use @option{-e} except for indenting
9506 purpose.  With the @code{s} command, the preferred separator is @samp{/}
9507 unless @samp{/} itself is used in the command, in which case you should
9508 use @samp{,}.
9510 @xref{Macro Definitions}, for details on how to define a macro.  If a
9511 macro doesn't use @code{AC_REQUIRE} and it is expected to never be the
9512 object of an @code{AC_REQUIRE} directive, then use @code{m4_define}.  In
9513 case of doubt, use @code{AC_DEFUN}.  All the @code{AC_REQUIRE}
9514 statements should be at the beginning of the macro, @code{dnl}'ed.
9516 You should not rely on the number of arguments: instead of checking
9517 whether an argument is missing, test that it is not empty.  It provides
9518 both a simpler and a more predictable interface to the user, and saves
9519 room for further arguments.
9521 Unless the macro is short, try to leave the closing @samp{])} at the
9522 beginning of a line, followed by a comment that repeats the name of the
9523 macro being defined.  This introduces an additional newline in
9524 @command{configure}; normally, that is not a problem, but if you want to
9525 remove it you can use @samp{[]dnl} on the last line.  You can similarly
9526 use @samp{[]dnl} after a macro call to remove its newline.  @samp{[]dnl}
9527 is recommended instead of @samp{dnl} to ensure that M4 does not
9528 interpret the @samp{dnl} as being attached to the preceding text or
9529 macro output.  For example, instead of:
9531 @example
9532 AC_DEFUN([AC_PATH_X],
9533 [AC_MSG_CHECKING([for X])
9534 AC_REQUIRE_CPP()
9535 @r{# @dots{}omitted@dots{}}
9536   AC_MSG_RESULT([libraries $x_libraries, headers $x_includes])
9537 fi])
9538 @end example
9540 @noindent
9541 you would write:
9543 @example
9544 AC_DEFUN([AC_PATH_X],
9545 [AC_REQUIRE_CPP()[]dnl
9546 AC_MSG_CHECKING([for X])
9547 @r{# @dots{}omitted@dots{}}
9548   AC_MSG_RESULT([libraries $x_libraries, headers $x_includes])
9549 fi[]dnl
9550 ])# AC_PATH_X
9551 @end example
9553 If the macro is long, try to split it into logical chunks.  Typically,
9554 macros that check for a bug in a function and prepare its
9555 @code{AC_LIBOBJ} replacement should have an auxiliary macro to perform
9556 this setup.  Do not hesitate to introduce auxiliary macros to factor
9557 your code.
9559 In order to highlight the recommended coding style, here is a macro
9560 written the old way:
9562 @example
9563 dnl Check for EMX on OS/2.
9564 dnl _AC_EMXOS2
9565 AC_DEFUN(_AC_EMXOS2,
9566 [AC_CACHE_CHECK(for EMX OS/2 environment, ac_cv_emxos2,
9567 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, return __EMX__;)],
9568 ac_cv_emxos2=yes, ac_cv_emxos2=no)])
9569 test "$ac_cv_emxos2" = yes && EMXOS2=yes])
9570 @end example
9572 @noindent
9573 and the new way:
9575 @example
9576 # _AC_EMXOS2
9577 # ----------
9578 # Check for EMX on OS/2.
9579 m4_define([_AC_EMXOS2],
9580 [AC_CACHE_CHECK([for EMX OS/2 environment], [ac_cv_emxos2],
9581 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return __EMX__;])],
9582                    [ac_cv_emxos2=yes],
9583                    [ac_cv_emxos2=no])])
9584 test "$ac_cv_emxos2" = yes && EMXOS2=yes[]dnl
9585 ])# _AC_EMXOS2
9586 @end example
9591 @c ============================================= Portable Shell Programming
9593 @node Portable Shell
9594 @chapter Portable Shell Programming
9595 @cindex Portable shell programming
9597 When writing your own checks, there are some shell-script programming
9598 techniques you should avoid in order to make your code portable.  The
9599 Bourne shell and upward-compatible shells like the Korn shell and Bash
9600 have evolved over the years, but to prevent trouble, do not take
9601 advantage of features that were added after Unix version 7, circa
9602 1977 (@pxref{Systemology}).
9604 You should not use shell functions, aliases, negated character
9605 classes, or other features that are not found in all Bourne-compatible
9606 shells; restrict yourself to the lowest common denominator.  Even
9607 @code{unset} is not supported by all shells!  Also, include a space
9608 after the exclamation point in interpreter specifications, like this:
9610 @example
9611 #! /usr/bin/perl
9612 @end example
9614 @noindent
9615 If you omit the space before the absolute file name,
9616 then 4.2@acronym{BSD} based systems
9617 (such as DYNIX) will ignore the line, because they interpret
9618 @samp{#! /} as a 4-byte magic number.  Some old systems have quite
9619 small limits on the length of the @samp{#!} line too, for instance 32
9620 bytes (not including the newline) on SunOS 4.
9622 The set of external programs you should run in a @command{configure} script
9623 is fairly small.  @xref{Utilities in Makefiles,, Utilities in
9624 Makefiles, standards, @acronym{GNU} Coding Standards}, for the list.  This
9625 restriction allows users to start out with a fairly small set of
9626 programs and build the rest, avoiding too many interdependencies between
9627 packages.
9629 Some of these external utilities have a portable subset of features; see
9630 @ref{Limitations of Usual Tools}.
9632 There are other sources of documentation about shells.  See for instance
9633 @uref{http://www.faqs.org/faqs/unix-faq/shell/, the Shell FAQs}.
9635 @menu
9636 * Shellology::                  A zoology of shells
9637 * Here-Documents::              Quirks and tricks
9638 * File Descriptors::            FDs and redirections
9639 * File System Conventions::     File names
9640 * Shell Substitutions::         Variable and command expansions
9641 * Assignments::                 Varying side effects of assignments
9642 * Parentheses::                 Parentheses in shell scripts
9643 * Slashes::                     Slashes in shell scripts
9644 * Special Shell Variables::     Variables you should not change
9645 * Limitations of Builtins::     Portable use of not so portable /bin/sh
9646 * Limitations of Usual Tools::  Portable use of portable tools
9647 * Limitations of Make::         Portable Makefiles
9648 @end menu
9650 @node Shellology
9651 @section Shellology
9652 @cindex Shellology
9654 There are several families of shells, most prominently the Bourne family
9655 and the C shell family which are deeply incompatible.  If you want to
9656 write portable shell scripts, avoid members of the C shell family.  The
9657 @uref{http://www.faqs.org/faqs/unix-faq/shell/shell-differences/, the
9658 Shell difference FAQ} includes a small history of Posix shells, and a
9659 comparison between several of them.
9661 Below we describe some of the members of the Bourne shell family.
9663 @table @asis
9664 @item Ash
9665 @cindex Ash
9666 Ash is often used on @acronym{GNU}/Linux and @acronym{BSD}
9667 systems as a light-weight Bourne-compatible shell.  Ash 0.2 has some
9668 bugs that are fixed in the 0.3.x series, but portable shell scripts
9669 should work around them, since version 0.2 is still shipped with many
9670 @acronym{GNU}/Linux distributions.
9672 To be compatible with Ash 0.2:
9674 @itemize @minus
9675 @item
9676 don't use @samp{$?} after expanding empty or unset variables:
9678 @example
9679 foo=
9680 false
9681 $foo
9682 echo "Don't use it: $?"
9683 @end example
9685 @item
9686 don't use command substitution within variable expansion:
9688 @example
9689 cat $@{FOO=`bar`@}
9690 @end example
9692 @item
9693 beware that single builtin substitutions are not performed by a
9694 subshell, hence their effect applies to the current shell!  @xref{Shell
9695 Substitutions}, item ``Command Substitution''.
9696 @end itemize
9698 @item Bash
9699 @cindex Bash
9700 To detect whether you are running Bash, test whether
9701 @code{BASH_VERSION} is set.  To require
9702 Posix compatibility, run @samp{set -o posix}.  @xref{Bash POSIX
9703 Mode,, Bash Posix Mode, bash, The @acronym{GNU} Bash Reference
9704 Manual}, for details.
9706 @item Bash 2.05 and later
9707 @cindex Bash 2.05 and later
9708 Versions 2.05 and later of Bash use a different format for the
9709 output of the @command{set} builtin, designed to make evaluating its
9710 output easier.  However, this output is not compatible with earlier
9711 versions of Bash (or with many other shells, probably).  So if
9712 you use Bash 2.05 or higher to execute @command{configure},
9713 you'll need to use Bash 2.05 for all other build tasks as well.
9715 @item Ksh
9716 @cindex Ksh
9717 @cindex Korn shell
9718 @prindex @samp{ksh}
9719 @prindex @samp{ksh88}
9720 @prindex @samp{ksh93}
9721 The Korn shell is compatible with the Bourne family and it mostly
9722 conforms to Posix.  It has two major variants commonly
9723 called @samp{ksh88} and @samp{ksh93}, named after the years of initial
9724 release.  It is usually called @command{ksh}, but is called @command{sh}
9725 on some hosts if you set your path appropriately.
9727 @itemize @minus
9728 @item
9729 Solaris systems have three variants:
9730 @prindex @command{/usr/bin/ksh} on Solaris
9731 @command{/usr/bin/ksh} is @samp{ksh88},
9732 @prindex @command{/usr/xpg4/bin/sh} on Solaris
9733 @command{/usr/xpg4/bin/sh} is a Posix-compliant variant of
9734 @samp{ksh88}, and
9735 @prindex @command{/usr/dt/bin/dtksh} on Solaris
9736 @command{/usr/dt/bin/dtksh} is @samp{ksh93}.  @command{/usr/bin/ksh}
9737 is standard on Solaris; the other variants are parts of optional
9738 packages.  There is no extra charge for these packages, but they are
9739 not part of a minimal OS install and therefore some installations may
9740 not have it.
9742 @item
9743 Starting with Tru64 Version 4.0, the Korn shell @command{/usr/bin/ksh}
9744 is also available as @command{/usr/bin/posix/sh}.  If the environment
9745 variable @env{BIN_SH} is set to @code{xpg4}, subsidiary invocations of
9746 the standard shell conform to Posix.
9748 @end itemize
9750 @item Pdksh
9751 @prindex @samp{pdksh}
9752 A public-domain clone of the Korn shell called @command{pdksh} is widely
9753 available: it has most of the @samp{ksh88} features along with a few of
9754 its own.  Similarly to Bash, you can detect whether you are
9755 running @command{pdksh} by testing whether @code{KSH_VERSION} is set,
9756 and you can require Posix compatibility by running @samp{set
9757 -o posix}.  Unfortunately, with @command{pdksh} 5.2.14 (the latest
9758 stable version as of March 2005) Posix mode is buggy and causes
9759 @command{pdksh} to depart from Posix in at least one respect:
9761 @example
9762 $ echo "`echo \"hello\"`"
9763 hello
9764 $ set -o posix
9765 $ echo "`echo \"hello\"`"
9766 "hello"
9767 @end example
9769 The last line of output contains spurious quotes.  This is yet another
9770 reason why portable shell code should not contain
9771 @code{"`@dots{}\"@dots{}\"@dots{}`"} constructs (@pxref{Shell
9772 Substitutions}).
9774 @item Zsh
9775 @cindex Zsh
9776 To detect whether you are running @command{zsh}, test whether
9777 @code{ZSH_VERSION} is set.  By default @command{zsh} is @emph{not}
9778 compatible with the Bourne shell: you must execute @samp{emulate sh},
9779 and for @command{zsh} versions before 3.1.6-dev-18 you must also
9780 set @code{NULLCMD} to @samp{:}.  @xref{Compatibility,, Compatibility,
9781 zsh, The Z Shell Manual}, for details.
9783 Zsh 3.0.8 is the native @command{sh} on Mac OS X 10.0.3.
9784 @end table
9786 The following discussion between Russ Allbery and Robert Lipe is worth
9787 reading:
9789 @noindent
9790 Russ Allbery:
9792 @quotation
9793 The @acronym{GNU} assumption that @command{/bin/sh} is the one and only shell
9794 leads to a permanent deadlock.  Vendors don't want to break users'
9795 existing shell scripts, and there are some corner cases in the Bourne
9796 shell that are not completely compatible with a Posix shell.  Thus,
9797 vendors who have taken this route will @emph{never} (OK@dots{}``never say
9798 never'') replace the Bourne shell (as @command{/bin/sh}) with a
9799 Posix shell.
9800 @end quotation
9802 @noindent
9803 Robert Lipe:
9805 @quotation
9806 This is exactly the problem.  While most (at least most System V's) do
9807 have a Bourne shell that accepts shell functions most vendor
9808 @command{/bin/sh} programs are not the Posix shell.
9810 So while most modern systems do have a shell @emph{somewhere} that meets the
9811 Posix standard, the challenge is to find it.
9812 @end quotation
9814 @node Here-Documents
9815 @section Here-Documents
9816 @cindex Here documents
9817 @cindex Shell here documents
9819 Don't rely on @samp{\} being preserved just because it has no special
9820 meaning together with the next symbol.  In the native @command{sh}
9821 on Open@acronym{BSD} 2.7 @samp{\"} expands to @samp{"} in here-documents with
9822 unquoted delimiter.  As a general rule, if @samp{\\} expands to @samp{\}
9823 use @samp{\\} to get @samp{\}.
9825 With Open@acronym{BSD} 2.7's @command{sh}
9827 @example
9828 @group
9829 $ @kbd{cat <<EOF
9830 > \" \\
9831 > EOF}
9832 " \
9833 @end group
9834 @end example
9836 @noindent
9837 and with Bash:
9839 @example
9840 @group
9841 bash-2.04$ @kbd{cat <<EOF
9842 > \" \\
9843 > EOF}
9844 \" \
9845 @end group
9846 @end example
9849 Many older shells (including the Bourne shell) implement here-documents
9850 inefficiently.  And some shells mishandle large here-documents: for
9851 example, Solaris 8 @command{dtksh}, which is derived from
9852 Korn shell version M-12/28/93d, mishandles variable expansion that occurs
9853 on 1024-byte buffer boundaries within a here-document.  Users can
9854 generally fix these problems by using a faster or more reliable
9855 shell, e.g., by using the command @samp{bash ./configure} rather than
9856 plain @samp{./configure}.
9858 Some shells can be extremely inefficient when there are a lot of
9859 here-documents inside a single statement.  For instance if your
9860 @file{configure.ac} includes something like:
9862 @example
9863 @group
9864 if <cross_compiling>; then
9865   assume this and that
9866 else
9867   check this
9868   check that
9869   check something else
9870   @dots{}
9871   on and on forever
9872   @dots{}
9874 @end group
9875 @end example
9877 A shell parses the whole @code{if}/@code{fi} construct, creating
9878 temporary files for each here document in it.  Some shells create links
9879 for such here-documents on every @code{fork}, so that the clean-up code
9880 they had installed correctly removes them.  It is creating the links
9881 that can take the shell forever.
9883 Moving the tests out of the @code{if}/@code{fi}, or creating multiple
9884 @code{if}/@code{fi} constructs, would improve the performance
9885 significantly.  Anyway, this kind of construct is not exactly the
9886 typical use of Autoconf.  In fact, it's even not recommended, because M4
9887 macros can't look into shell conditionals, so we may fail to expand a
9888 macro when it was expanded before in a conditional path, and the
9889 condition turned out to be false at run-time, and we end up not
9890 executing the macro at all.
9892 @node File Descriptors
9893 @section File Descriptors
9894 @cindex Descriptors
9895 @cindex File descriptors
9896 @cindex Shell file descriptors
9898 Some file descriptors shall not be used, since some systems, admittedly
9899 arcane, use them for special purpose:
9901 @display
9902 3 --- some systems may open it to @samp{/dev/tty}.
9903 4 --- used on the Kubota Titan.
9904 @end display
9906 Don't redirect the same file descriptor several times, as you are doomed
9907 to failure under Ultrix.
9909 @example
9910 ULTRIX V4.4 (Rev. 69) System #31: Thu Aug 10 19:42:23 GMT 1995
9911 UWS V4.4 (Rev. 11)
9912 $ @kbd{eval 'echo matter >fullness' >void}
9913 illegal io
9914 $ @kbd{eval '(echo matter >fullness)' >void}
9915 illegal io
9916 $ @kbd{(eval '(echo matter >fullness)') >void}
9917 Ambiguous output redirect.
9918 @end example
9920 @noindent
9921 In each case the expected result is of course @file{fullness} containing
9922 @samp{matter} and @file{void} being empty.
9924 Don't try to redirect the standard error of a command substitution: it
9925 must be done @emph{inside} the command substitution: when running
9926 @samp{: `cd /zorglub` 2>/dev/null} expect the error message to
9927 escape, while @samp{: `cd /zorglub 2>/dev/null`} works properly.
9929 It is worth noting that Zsh (but not Ash nor Bash) makes it possible
9930 in assignments though: @samp{foo=`cd /zorglub` 2>/dev/null}.
9932 Most shells, if not all (including Bash, Zsh, Ash), output traces on
9933 stderr, even for sub-shells.  This might result in undesirable content
9934 if you meant to capture the standard-error output of the inner command:
9936 @example
9937 $ @kbd{ash -x -c '(eval "echo foo >&2") 2>stderr'}
9938 $ @kbd{cat stderr}
9939 + eval echo foo >&2
9940 + echo foo
9942 $ @kbd{bash -x -c '(eval "echo foo >&2") 2>stderr'}
9943 $ @kbd{cat stderr}
9944 + eval 'echo foo >&2'
9945 ++ echo foo
9947 $ @kbd{zsh -x -c '(eval "echo foo >&2") 2>stderr'}
9948 @i{# Traces on startup files deleted here.}
9949 $ @kbd{cat stderr}
9950 +zsh:1> eval echo foo >&2
9951 +zsh:1> echo foo
9953 @end example
9955 @noindent
9956 You'll appreciate the various levels of detail@enddots{}
9958 One workaround is to grep out uninteresting lines, hoping not to remove
9959 good ones@enddots{}
9961 Don't try to move/delete open files, such as in @samp{exec >foo; mv foo
9962 bar}; see @ref{Limitations of Builtins}, @command{mv} for more details.
9964 @node File System Conventions
9965 @section File System Conventions
9966 @cindex File system conventions
9968 Autoconf uses shell-script processing extensively, so the file names
9969 that it processes should not contain characters that are special to the
9970 shell.  Special characters include space, tab, newline, @sc{nul}, and
9971 the following:
9973 @example
9974 " # $ & ' ( ) * ; < = > ? [ \ ` |
9975 @end example
9977 Also, file names should not begin with @samp{~} or @samp{-}, and should
9978 not contain @samp{-} immediately after @samp{/}.
9980 These restrictions apply not only to the files that you distribute, but
9981 also to the absolute file names of your source, build, and destination
9982 directories.  Autoconf-generated @command{configure} scripts warn of
9983 violations to the above restrictions.
9985 On some Posix-like platforms, @samp{!} and @samp{^} are special too, so
9986 they should be avoided.
9988 While @command{autoconf} and friends will usually be run on some Posix
9989 variety, it can and will be used on other systems, most notably @acronym{DOS}
9990 variants.  This impacts several assumptions regarding file names.
9992 @noindent
9993 For example, the following code:
9995 @example
9996 case $foo_dir in
9997   /*) # Absolute
9998      ;;
9999   *)
10000      foo_dir=$dots$foo_dir ;;
10001 esac
10002 @end example
10004 @noindent
10005 will fail to properly detect absolute file names on those systems, because
10006 they can use a drivespec, and will usually use a backslash as directory
10007 separator.  If you want to be portable to @acronym{DOS} variants (at the
10008 price of rejecting valid but oddball Posix file names like @file{a:\b}),
10009 you can check for absolute file names like this:
10011 @example
10012 case $foo_dir in
10013   [\\/]* | ?:[\\/]* ) # Absolute
10014      ;;
10015   *)
10016      foo_dir=$dots$foo_dir ;;
10017 esac
10018 @end example
10020 @noindent
10021 Make sure you quote the brackets if appropriate and keep the backslash as
10022 first character (@pxref{Limitations of Builtins}).
10024 Also, because the colon is used as part of a drivespec, these systems don't
10025 use it as path separator.  When creating or accessing paths, you can use the
10026 @code{PATH_SEPARATOR} output variable instead.  @command{configure} sets this
10027 to the appropriate value (@samp{:} or @samp{;}) when it starts up.
10029 File names need extra care as well.  While @acronym{DOS} variants
10030 that are Posixy enough to run @command{autoconf} (such as @acronym{DJGPP}) will
10031 usually be able to handle long file names properly, there are still
10032 limitations that can seriously break packages.  Several of these issues
10033 can be easily detected by the
10034 @uref{ftp://ftp.gnu.org/gnu/non-gnu/doschk/doschk-1.1.tar.gz, doschk}
10035 package.
10037 A short overview follows; problems are marked with @sc{sfn}/@sc{lfn} to
10038 indicate where they apply: @sc{sfn} means the issues are only relevant to
10039 plain @acronym{DOS}, not to @acronym{DOS} under Microsoft Windows
10040 variants, while @sc{lfn} identifies problems that exist even under
10041 Microsoft Windows variants.
10043 @table @asis
10044 @item No multiple dots (@sc{sfn})
10045 @acronym{DOS} cannot handle multiple dots in file names.  This is an especially
10046 important thing to remember when building a portable configure script,
10047 as @command{autoconf} uses a .in suffix for template files.
10049 This is perfectly OK on Posix variants:
10051 @example
10052 AC_CONFIG_HEADERS([config.h])
10053 AC_CONFIG_FILES([source.c foo.bar])
10054 AC_OUTPUT
10055 @end example
10057 @noindent
10058 but it causes problems on @acronym{DOS}, as it requires @samp{config.h.in},
10059 @samp{source.c.in} and @samp{foo.bar.in}.  To make your package more portable
10060 to @acronym{DOS}-based environments, you should use this instead:
10062 @example
10063 AC_CONFIG_HEADERS([config.h:config.hin])
10064 AC_CONFIG_FILES([source.c:source.cin foo.bar:foobar.in])
10065 AC_OUTPUT
10066 @end example
10068 @item No leading dot (@sc{sfn})
10069 @acronym{DOS} cannot handle file names that start with a dot.  This is usually
10070 not a very important issue for @command{autoconf}.
10072 @item Case insensitivity (@sc{lfn})
10073 @acronym{DOS} is case insensitive, so you cannot, for example, have both a
10074 file called @samp{INSTALL} and a directory called @samp{install}.  This
10075 also affects @command{make}; if there's a file called @samp{INSTALL} in
10076 the directory, @samp{make install} will do nothing (unless the
10077 @samp{install} target is marked as PHONY).
10079 @item The 8+3 limit (@sc{sfn})
10080 Because the @acronym{DOS} file system only stores the first 8 characters of
10081 the file name and the first 3 of the extension, those must be unique.
10082 That means that @file{foobar-part1.c}, @file{foobar-part2.c} and
10083 @file{foobar-prettybird.c} all resolve to the same file name
10084 (@file{FOOBAR-P.C}).  The same goes for @file{foo.bar} and
10085 @file{foo.bartender}.
10087 The 8+3 limit is not usually a problem under Microsoft Windows, as it
10088 uses numeric
10089 tails in the short version of file names to make them unique.  However, a
10090 registry setting can turn this behavior off.  While this makes it
10091 possible to share file trees containing long file names between @sc{sfn}
10092 and @sc{lfn} environments, it also means the above problem applies there
10093 as well.
10095 @item Invalid characters (@sc{lfn})
10096 Some characters are invalid in @acronym{DOS} file names, and should therefore
10097 be avoided.  In a @sc{lfn} environment, these are @samp{/}, @samp{\},
10098 @samp{?}, @samp{*}, @samp{:}, @samp{<}, @samp{>}, @samp{|} and @samp{"}.
10099 In a @sc{sfn} environment, other characters are also invalid.  These
10100 include @samp{+}, @samp{,}, @samp{[} and @samp{]}.
10102 @item Invalid names (@sc{lfn})
10103 Some @acronym{DOS} file names are reserved, and cause problems if you
10104 try to use files with those names.  These names include @file{CON},
10105 @file{AUX}, @file{COM1}, @file{COM2}, @file{COM3}, @file{COM4},
10106 @file{LPT1}, @file{LPT2}, @file{LPT3}, @file{NUL}, and @file{PRN}.
10107 File names are case insensitive, so even names like
10108 @file{aux/config.guess} are disallowed.
10110 @end table
10112 @node Shell Substitutions
10113 @section Shell Substitutions
10114 @cindex Shell substitutions
10116 Contrary to a persistent urban legend, the Bourne shell does not
10117 systematically split variables and back-quoted expressions, in particular
10118 on the right-hand side of assignments and in the argument of @code{case}.
10119 For instance, the following code:
10121 @example
10122 case "$given_srcdir" in
10123 .)  top_srcdir="`echo "$dots" | sed 's,/$,,'`" ;;
10124 *)  top_srcdir="$dots$given_srcdir" ;;
10125 esac
10126 @end example
10128 @noindent
10129 is more readable when written as:
10131 @example
10132 case $given_srcdir in
10133 .)  top_srcdir=`echo "$dots" | sed 's,/$,,'` ;;
10134 *)  top_srcdir=$dots$given_srcdir ;;
10135 esac
10136 @end example
10138 @noindent
10139 and in fact it is even @emph{more} portable: in the first case of the
10140 first attempt, the computation of @code{top_srcdir} is not portable,
10141 since not all shells properly understand @code{"`@dots{}"@dots{}"@dots{}`"}.
10142 Worse yet, not all shells understand @code{"`@dots{}\"@dots{}\"@dots{}`"}
10143 the same way.  There is just no portable way to use double-quoted
10144 strings inside double-quoted back-quoted expressions (pfew!).
10146 @table @code
10147 @item $@@
10148 @cindex @samp{"$@@"}
10149 One of the most famous shell-portability issues is related to
10150 @samp{"$@@"}.  When there are no positional arguments, Posix says
10151 that @samp{"$@@"} is supposed to be equivalent to nothing, but the
10152 original Unix version 7 Bourne shell treated it as equivalent to
10153 @samp{""} instead, and this behavior survives in later implementations
10154 like Digital Unix 5.0.
10156 The traditional way to work around this portability problem is to use
10157 @samp{$@{1+"$@@"@}}.  Unfortunately this method does not work with
10158 Zsh (3.x and 4.x), which is used on Mac OS X@.  When emulating
10159 the Bourne shell, Zsh performs word splitting on @samp{$@{1+"$@@"@}}:
10161 @example
10162 zsh $ @kbd{emulate sh}
10163 zsh $ @kbd{for i in "$@@"; do echo $i; done}
10164 Hello World
10166 zsh $ @kbd{for i in $@{1+"$@@"@}; do echo $i; done}
10167 Hello
10168 World
10170 @end example
10172 @noindent
10173 Zsh handles plain @samp{"$@@"} properly, but we can't use plain
10174 @samp{"$@@"} because of the portability problems mentioned above.
10175 One workaround relies on Zsh's ``global aliases'' to convert
10176 @samp{$@{1+"$@@"@}} into @samp{"$@@"} by itself:
10178 @example
10179 test "$@{ZSH_VERSION+set@}" = set && alias -g '$@{1+"$@@"@}'='"$@@"'
10180 @end example
10182 A more conservative workaround is to avoid @samp{"$@@"} if it is
10183 possible that there may be no positional arguments.  For example,
10184 instead of:
10186 @example
10187 cat conftest.c "$@@"
10188 @end example
10190 you can use this instead:
10192 @example
10193 case $# in
10194 0) cat conftest.c;;
10195 *) cat conftest.c "$@@";;
10196 esac
10197 @end example
10199 @item $@{@var{var}:-@var{value}@}
10200 @c Info cannot handle `:' in index entries.
10201 @c @cindex $@{@var{var}:-@var{value}@}
10202 Old @acronym{BSD} shells, including the Ultrix @code{sh}, don't accept the
10203 colon for any shell substitution, and complain and die.
10205 @item $@{@var{var}=@var{literal}@}
10206 @cindex $@{@var{var}=@var{literal}@}
10207 Be sure to quote:
10209 @example
10210 : $@{var='Some words'@}
10211 @end example
10213 @noindent
10214 otherwise some shells, such as on Digital Unix V 5.0, will die because
10215 of a ``bad substitution''.
10217 @sp 1
10219 The Solaris @command{sh} has a frightening bug in its interpretation
10220 of this.  Imagine you need set a variable to a string containing
10221 @samp{@}}.  This @samp{@}} character confuses the Solaris @command{sh}
10222 when the affected variable was already set.  This bug can be exercised
10223 by running:
10225 @example
10226 $ @kbd{unset foo}
10227 $ @kbd{foo=$@{foo='@}'@}}
10228 $ @kbd{echo $foo}
10230 $ @kbd{foo=$@{foo='@}'   # no error; this hints to what the bug is}
10231 $ @kbd{echo $foo}
10233 $ @kbd{foo=$@{foo='@}'@}}
10234 $ @kbd{echo $foo}
10235 @}@}
10236  ^ ugh!
10237 @end example
10239 It seems that @samp{@}} is interpreted as matching @samp{$@{}, even
10240 though it is enclosed in single quotes.  The problem doesn't happen
10241 using double quotes.
10243 @item $@{@var{var}=@var{expanded-value}@}
10244 @cindex $@{@var{var}=@var{expanded-value}@}
10245 On Ultrix,
10246 running
10248 @example
10249 default="yu,yaa"
10250 : $@{var="$default"@}
10251 @end example
10253 @noindent
10254 will set @var{var} to @samp{M-yM-uM-,M-yM-aM-a}, i.e., the 8th bit of
10255 each char will be set.  You won't observe the phenomenon using a simple
10256 @samp{echo $var} since apparently the shell resets the 8th bit when it
10257 expands $var.  Here are two means to make this shell confess its sins:
10259 @example
10260 $ @kbd{cat -v <<EOF
10261 $var
10262 EOF}
10263 @end example
10265 @noindent
10268 @example
10269 $ @kbd{set | grep '^var=' | cat -v}
10270 @end example
10272 One classic incarnation of this bug is:
10274 @example
10275 default="a b c"
10276 : $@{list="$default"@}
10277 for c in $list; do
10278   echo $c
10279 done
10280 @end example
10282 @noindent
10283 You'll get @samp{a b c} on a single line.  Why?  Because there are no
10284 spaces in @samp{$list}: there are @samp{M- }, i.e., spaces with the 8th
10285 bit set, hence no IFS splitting is performed!!!
10287 One piece of good news is that Ultrix works fine with @samp{:
10288 $@{list=$default@}}; i.e., if you @emph{don't} quote.  The bad news is
10289 then that @acronym{QNX} 4.25 then sets @var{list} to the @emph{last} item of
10290 @var{default}!
10292 The portable way out consists in using a double assignment, to switch
10293 the 8th bit twice on Ultrix:
10295 @example
10296 list=$@{list="$default"@}
10297 @end example
10299 @noindent
10300 @dots{}but beware of the @samp{@}} bug from Solaris (see above).  For safety,
10301 use:
10303 @example
10304 test "$@{var+set@}" = set || var=@var{@{value@}}
10305 @end example
10308 @item `@var{commands}`
10309 @cindex `@var{commands}`
10310 @cindex Command Substitution
10311 Posix requires shells to trim all trailing newlines from command
10312 output before substituting it, so assignments like
10313 @samp{dir=`AS_DIRNAME(["$file"])`} will not work as expected if the
10314 directory of @samp{$file} ends in a newline.
10316 While in general it makes no sense, do not substitute a single builtin
10317 with side effects, because Ash 0.2, trying to optimize, does not fork a
10318 subshell to perform the command.
10320 For instance, if you wanted to check that @command{cd} is silent, do not
10321 use @samp{test -z "`cd /`"} because the following can happen:
10323 @example
10324 $ @kbd{pwd}
10325 /tmp
10326 $ @kbd{test -z "`cd /`" && pwd}
10328 @end example
10330 @noindent
10331 The result of @samp{foo=`exit 1`} is left as an exercise to the reader.
10334 @item $(@var{commands})
10335 @cindex $(@var{commands})
10336 This construct is meant to replace @samp{`@var{commands}`},
10337 and it has most of the problems listed under @code{`@var{commands}`}.
10339 This construct can be
10340 nested while this is impossible to do portably with back quotes.
10341 Unfortunately it is not yet universally supported.  Most notably, even recent
10342 releases of Solaris don't support it:
10344 @example
10345 $ @kbd{showrev -c /bin/sh | grep version}
10346 Command version: SunOS 5.9 Generic May 2002
10347 $ @kbd{echo $(echo blah)}
10348 syntax error: `(' unexpected
10349 @end example
10351 @noindent
10352 nor does @sc{irix} 6.5's Bourne shell:
10353 @example
10354 $ @kbd{uname -a}
10355 IRIX firebird-image 6.5 07151432 IP22
10356 $ @kbd{echo $(echo blah)}
10357 $(echo blah)
10358 @end example
10360 If you do use @samp{$(@var{commands})}, make sure that the commands
10361 do not start with a parenthesis, as that would cause confusion with
10362 a different notation @samp{$((@var{expression}))} that in modern
10363 shells is an arithmetic expression not a command.  To avoid the
10364 confusion, insert a space between the two opening parentheses.
10366 @end table
10369 @node Assignments
10370 @section Assignments
10371 @cindex Shell assignments
10373 When setting several variables in a row, be aware that the order of the
10374 evaluation is undefined.  For instance @samp{foo=1 foo=2; echo $foo}
10375 gives @samp{1} with sh on Solaris, but @samp{2} with Bash.  You must use
10376 @samp{;} to enforce the order: @samp{foo=1; foo=2; echo $foo}.
10378 Don't rely on the following to find @file{subdir/program}:
10380 @example
10381 PATH=subdir$PATH_SEPARATOR$PATH program
10382 @end example
10384 @noindent
10385 as this does not work with Zsh 3.0.6.  Use something like this
10386 instead:
10388 @example
10389 (PATH=subdir$PATH_SEPARATOR$PATH; export PATH; exec program)
10390 @end example
10392 Don't rely on the exit status of an assignment: Ash 0.2 does not change
10393 the status and propagates that of the last statement:
10395 @example
10396 $ @kbd{false || foo=bar; echo $?}
10398 $ @kbd{false || foo=`:`; echo $?}
10400 @end example
10402 @noindent
10403 and to make things even worse, @acronym{QNX} 4.25 just sets the exit status
10404 to 0 in any case:
10406 @example
10407 $ @kbd{foo=`exit 1`; echo $?}
10409 @end example
10411 To assign default values, follow this algorithm:
10413 @enumerate
10414 @item
10415 If the default value is a literal and does not contain any closing
10416 brace, use:
10418 @example
10419 : $@{var='my literal'@}
10420 @end example
10422 @item
10423 If the default value contains no closing brace, has to be expanded, and
10424 the variable being initialized will never be IFS-split (i.e., it's not a
10425 list), then use:
10427 @example
10428 : $@{var="$default"@}
10429 @end example
10431 @item
10432 If the default value contains no closing brace, has to be expanded, and
10433 the variable being initialized will be IFS-split (i.e., it's a list),
10434 then use:
10436 @example
10437 var=$@{var="$default"@}
10438 @end example
10440 @item
10441 If the default value contains a closing brace, then use:
10443 @example
10444 test "$@{var+set@}" = set || var='$@{indirection@}'
10445 @end example
10446 @end enumerate
10448 In most cases @samp{var=$@{var="$default"@}} is fine, but in case of
10449 doubt, just use the latter.  @xref{Shell Substitutions}, items
10450 @samp{$@{@var{var}:-@var{value}@}} and @samp{$@{@var{var}=@var{value}@}}
10451 for the rationale.
10453 @node Parentheses
10454 @section Parentheses in Shell Scripts
10455 @cindex Shell parentheses
10457 Beware of two opening parentheses in a row, as some shell
10458 implementations mishandle them.  For example, @samp{pdksh} 5.2.14
10459 misparses the following code:
10461 @example
10462 if ((true) || false); then
10463   echo ok
10465 @end example
10467 @noindent
10468 To work around this problem, insert a space between the two opening
10469 parentheses.  There is a similar problem and workaround with
10470 @samp{$((}; see @ref{Shell Substitutions}.
10472 Posix requires support for @code{case} patterns with opening
10473 parentheses like this:
10475 @example
10476 case $file_name in
10477 (*.c) echo "C source code";;
10478 esac
10479 @end example
10481 @noindent
10482 but the @code{(} in this example is not portable to many older Bourne
10483 shell implementations.  It can be omitted safely.
10485 @node Slashes
10486 @section Slashes in Shell Scripts
10487 @cindex Shell slashes
10489 Unpatched Tru64 5.1 @command{sh} omits the last slash of command-line
10490 arguments that contain two trailing slashes:
10492 @example
10493 $ echo / // /// //// .// //.
10494 / / // /// ./ //.
10495 $ x=//
10496 $ eval "echo \$x"
10498 $ set -x
10499 $ echo abc | tr -t ab //
10500 + echo abc
10501 + tr -t ab /
10503 @end example
10505 However, our understanding is that patches are available, so perhaps
10506 it's not worth worrying about working around this horrendous bug.
10508 @node Special Shell Variables
10509 @section Special Shell Variables
10510 @cindex Shell variables
10511 @cindex Special shell variables
10513 Some shell variables should not be used, since they can have a deep
10514 influence on the behavior of the shell.  In order to recover a sane
10515 behavior from the shell, some variables should be unset, but
10516 @command{unset} is not portable (@pxref{Limitations of Builtins}) and a
10517 fallback value is needed.
10519 As a general rule, shell variable names containing a lower-case letter
10520 are safe; you can define and use these variables without worrying about
10521 their effect on the underlying system, and without worrying about
10522 whether the shell will change them unexpectedly.  (The exception is the
10523 shell variable @code{status}, as described below.)
10525 Here is a list of names that are known to cause trouble.  This list is
10526 not exhaustive, but you should be safe if you avoid the name
10527 @code{status} and names containing only upper-case letters and
10528 underscores.
10530 @c Alphabetical order, case insensitive, `A' before `a'.
10531 @table @code
10532 @item _
10533 Many shells reserve @samp{$_} for various purposes, e.g., the name of
10534 the last command executed.
10536 @item BIN_SH
10537 @evindex BIN_SH
10538 In Tru64, if @env{BIN_SH} is set to @code{xpg4}, subsidiary invocations of
10539 the standard shell conform to Posix.
10540 Autoconf-generated scripts export this variable when they start up.
10542 @item CDPATH
10543 @evindex CDPATH
10544 When this variable is set it specifies a list of directories to search
10545 when invoking @code{cd} with a relative file name.  Posix
10546 1003.1-2001 says that if a nonempty directory name from @env{CDPATH}
10547 is used successfully, @code{cd} prints the resulting absolute
10548 file name.  Unfortunately this output can break idioms like
10549 @samp{abs=`cd src && pwd`} because @code{abs} receives the name twice.
10550 Also, many shells do not conform to this part of Posix; for
10551 example, @command{zsh} prints the result only if a directory name
10552 other than @file{.} was chosen from @env{CDPATH}.
10554 In practice the shells that have this problem also support
10555 @command{unset}, so you can work around the problem as follows:
10557 @example
10558 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
10559 @end example
10561 Autoconf-generated scripts automatically unset @env{CDPATH} if
10562 possible, so you need not worry about this problem in those scripts.
10564 @item DUALCASE
10565 @evindex DUALCASE
10566 In the MKS shell, case statements and file name generation are
10567 case-insensitive unless @env{DUALCASE} is nonzero.
10568 Autoconf-generated scripts export this variable when they start up.
10570 @item ENV
10571 @itemx MAIL
10572 @itemx MAILPATH
10573 @itemx PS1
10574 @itemx PS2
10575 @itemx PS4
10576 @evindex ENV
10577 @evindex MAIL
10578 @evindex MAILPATH
10579 @evindex PS1
10580 @evindex PS2
10581 @evindex PS4
10582 These variables should not matter for shell scripts, since they are
10583 supposed to affect only interactive shells.  However, at least one
10584 shell (the pre-3.0 @sc{uwin} Korn shell) gets confused about
10585 whether it is interactive, which means that (for example) a @env{PS1}
10586 with a side effect can unexpectedly modify @samp{$?}.  To work around
10587 this bug, Autoconf-generated scripts do something like this:
10589 @example
10590 (unset ENV) >/dev/null 2>&1 && unset ENV MAIL MAILPATH
10591 PS1='$ '
10592 PS2='> '
10593 PS4='+ '
10594 @end example
10596 @item IFS
10597 @evindex IFS
10598 Long ago, shell scripts inherited @env{IFS} from the environment,
10599 but this caused many problems so modern shells ignore any environment
10600 settings for @env{IFS}.
10602 Don't set the first character of @code{IFS} to backslash.  Indeed,
10603 Bourne shells use the first character (backslash) when joining the
10604 components in @samp{"$@@"} and some shells then re-interpret (!)@: the
10605 backslash escapes, so you can end up with backspace and other strange
10606 characters.
10608 The proper value for @code{IFS} (in regular code, not when performing
10609 splits) is @samp{@key{SPC}@key{TAB}@key{RET}}.  The first character is
10610 especially important, as it is used to join the arguments in @samp{@@*}.
10612 @item LANG
10613 @itemx LC_ALL
10614 @itemx LC_COLLATE
10615 @itemx LC_CTYPE
10616 @itemx LC_MESSAGES
10617 @itemx LC_MONETARY
10618 @itemx LC_NUMERIC
10619 @itemx LC_TIME
10620 @evindex LANG
10621 @evindex LC_ALL
10622 @evindex LC_COLLATE
10623 @evindex LC_CTYPE
10624 @evindex LC_MESSAGES
10625 @evindex LC_MONETARY
10626 @evindex LC_NUMERIC
10627 @evindex LC_TIME
10629 Autoconf-generated scripts normally set all these variables to
10630 @samp{C} because so much configuration code assumes the C locale and
10631 Posix requires that locale environment variables be set to
10632 @samp{C} if the C locale is desired.  However, some older, nonstandard
10633 systems (notably @acronym{SCO}) break if locale environment variables
10634 are set to @samp{C}, so when running on these systems
10635 Autoconf-generated scripts unset the variables instead.
10637 @item LANGUAGE
10638 @evindex LANGUAGE
10640 @env{LANGUAGE} is not specified by Posix, but it is a @acronym{GNU}
10641 extension that overrides @env{LC_ALL} in some cases, so
10642 Autoconf-generated scripts set it too.
10644 @item LC_ADDRESS
10645 @itemx LC_IDENTIFICATION
10646 @itemx LC_MEASUREMENT
10647 @itemx LC_NAME
10648 @itemx LC_PAPER
10649 @itemx LC_TELEPHONE
10650 @evindex LC_ADDRESS
10651 @evindex LC_IDENTIFICATION
10652 @evindex LC_MEASUREMENT
10653 @evindex LC_NAME
10654 @evindex LC_PAPER
10655 @evindex LC_TELEPHONE
10657 These locale environment variables are @acronym{GNU} extensions.  They
10658 are treated like their Posix brethren (@env{LC_COLLATE},
10659 etc.)@: as described above.
10661 @item LINENO
10662 Most modern shells provide the current line number in @code{LINENO}.
10663 Its value is the line number of the beginning of the current command.
10664 Autoconf attempts to execute @command{configure} with a modern shell.
10665 If no such shell is available, it attempts to implement @code{LINENO}
10666 with a Sed prepass that replaces each instance of the string
10667 @code{$LINENO} (not followed by an alphanumeric character) with the
10668 line's number.
10670 You should not rely on @code{LINENO} within @command{eval}, as the
10671 behavior differs in practice.  Also, the possibility of the Sed
10672 prepass means that you should not rely on @code{$LINENO} when quoted,
10673 when in here-documents, or when in long commands that cross line
10674 boundaries.  Subshells should be OK, though.  In the following
10675 example, lines 1, 6, and 9 are portable, but the other instances of
10676 @code{LINENO} are not:
10678 @example
10679 @group
10680 $ @kbd{cat lineno}
10681 echo 1. $LINENO
10682 cat <<EOF
10683 3. $LINENO
10684 4. $LINENO
10686 ( echo 6. $LINENO )
10687 eval 'echo 7. $LINENO'
10688 echo 8. '$LINENO'
10689 echo 9. $LINENO '
10690 10.' $LINENO
10691 @end group
10692 @group
10693 $ @kbd{bash-2.05 lineno}
10694 1. 1
10695 3. 2
10696 4. 2
10697 6. 6
10698 7. 1
10699 8. $LINENO
10700 9. 9
10701 10. 9
10702 @end group
10703 @group
10704 $ @kbd{zsh-3.0.6 lineno}
10705 1. 1
10706 3. 2
10707 4. 2
10708 6. 6
10709 7. 7
10710 8. $LINENO
10711 9. 9
10712 10. 9
10713 @end group
10714 @group
10715 $ @kbd{pdksh-5.2.14 lineno}
10716 1. 1
10717 3. 2
10718 4. 2
10719 6. 6
10720 7. 0
10721 8. $LINENO
10722 9. 9
10723 10. 9
10724 @end group
10725 @group
10726 $ @kbd{sed '=' <lineno |}
10727 > @kbd{  sed '}
10728 > @kbd{    N}
10729 > @kbd{    s,$,-,}
10730 > @kbd{    : loop}
10731 > @kbd{    s,^\([0-9]*\)\(.*\)[$]LINENO\([^a-zA-Z0-9_]\),\1\2\1\3,}
10732 > @kbd{    t loop}
10733 > @kbd{    s,-$,,}
10734 > @kbd{    s,^[0-9]*\n,,}
10735 > @kbd{  ' |}
10736 > @kbd{  sh}
10737 1. 1
10738 3. 3
10739 4. 4
10740 6. 6
10741 7. 7
10742 8. 8
10743 9. 9
10744 10. 10
10745 @end group
10746 @end example
10748 @item NULLCMD
10749 @evindex NULLCMD
10750 When executing the command @samp{>foo}, @command{zsh} executes
10751 @samp{$NULLCMD >foo} unless it is operating in Bourne shell
10752 compatibility mode and the @command{zsh} version is newer
10753 than 3.1.6-dev-18.  If are using an older @command{zsh}
10754 and forget to set @env{NULLCMD},
10755 your script might be suspended waiting for data on its standard input.
10757 @item PATH_SEPARATOR
10758 @evindex PATH_SEPARATOR
10759 On @acronym{DJGPP} systems, the @env{PATH_SEPARATOR} environment
10760 variable can be set to either @samp{:} or @samp{;} to control the path
10761 separator Bash uses to set up certain environment variables (such as
10762 @env{PATH}).  You can set this variable to @samp{;} if you want
10763 @command{configure} to use @samp{;} as a separator; this might be useful
10764 if you plan to use non-Posix shells to execute files.  @xref{File System
10765 Conventions}, for more information about @code{PATH_SEPARATOR}.
10767 @item PWD
10768 @evindex PWD
10769 Posix 1003.1-2001 requires that @command{cd} and
10770 @command{pwd} must update the @env{PWD} environment variable to point
10771 to the logical name of the current directory, but traditional shells
10772 do not support this.  This can cause confusion if one shell instance
10773 maintains @env{PWD} but a subsidiary and different shell does not know
10774 about @env{PWD} and executes @command{cd}; in this case @env{PWD} will
10775 point to the wrong directory.  Use @samp{`pwd`} rather than
10776 @samp{$PWD}.
10778 @item RANDOM
10779 Many shells provide @code{RANDOM}, a variable that returns a different
10780 integer each time it is used.  Most of the time, its value does not
10781 change when it is not used, but on @sc{irix} 6.5 the value changes all
10782 the time.  This can be observed by using @command{set}.  It is common
10783 practice to use @code{$RANDOM} as part of a file name, but code
10784 shouldn't rely on @code{$RANDOM} expanding to a nonempty string.
10786 @item status
10787 This variable is an alias to @samp{$?} for @code{zsh} (at least 3.1.6),
10788 hence read-only.  Do not use it.
10789 @end table
10791 @node Limitations of Builtins
10792 @section Limitations of Shell Builtins
10793 @cindex Shell builtins
10794 @cindex Limitations of shell builtins
10796 No, no, we are serious: some shells do have limitations!  :)
10798 You should always keep in mind that any builtin or command may support
10799 options, and therefore have a very different behavior with arguments
10800 starting with a dash.  For instance, the innocent @samp{echo "$word"}
10801 can give unexpected results when @code{word} starts with a dash.  It is
10802 often possible to avoid this problem using @samp{echo "x$word"}, taking
10803 the @samp{x} into account later in the pipe.
10805 @table @asis
10806 @item @command{.}
10807 @prindex @command{.}
10808 Use @command{.} only with regular files (use @samp{test -f}).  Bash
10809 2.03, for instance, chokes on @samp{. /dev/null}.  Also, remember that
10810 @command{.} uses @env{PATH} if its argument contains no slashes, so if
10811 you want to use @command{.} on a file @file{foo} in the current
10812 directory, you must use @samp{. ./foo}.
10814 @item @command{!}
10815 @prindex @command{!}
10816 The Unix version 7 shell did not support
10817 negating the exit status of commands with @command{!}, and this feature
10818 is still absent from more modern shells (e.g., Solaris 9 @command{sh}).
10819 Shell code like this:
10821 @example
10822 if ! cmp file1 file2 >/dev/null 2>&1; then
10823   echo files differ or trouble
10825 @end example
10827 is therefore not portable in practice.  Typically it is easy to rewrite
10828 such code, e.g.:
10830 @example
10831 cmp file1 file2 >/dev/null 2>&1 || echo files differ or trouble
10832 @end example
10834 More generally, one can always rewrite @samp{! @var{command}} as:
10836 @example
10837 if @var{command}; then (exit 1); else :; fi
10838 @end example
10840 @item @command{break}
10841 @c ------------------
10842 @prindex @command{break}
10843 The use of @samp{break 2} etc.@: is safe.
10846 @item @command{case}
10847 @c -----------------
10848 @prindex @command{case}
10849 You don't need to quote the argument; no splitting is performed.
10851 You don't need the final @samp{;;}, but you should use it.
10853 Because of a bug in its @code{fnmatch}, Bash fails to properly
10854 handle backslashes in character classes:
10856 @example
10857 bash-2.02$ @kbd{case /tmp in [/\\]*) echo OK;; esac}
10858 bash-2.02$
10859 @end example
10861 @noindent
10862 This is extremely unfortunate, since you are likely to use this code to
10863 handle Posix or @sc{ms-dos} absolute file names.  To work around this
10864 bug, always put the backslash first:
10866 @example
10867 bash-2.02$ @kbd{case '\TMP' in [\\/]*) echo OK;; esac}
10869 bash-2.02$ @kbd{case /tmp in [\\/]*) echo OK;; esac}
10871 @end example
10873 Many Bourne shells cannot handle closing brackets in character classes
10874 correctly.
10876 Some shells also have problems with backslash escaping in case you do not want
10877 to match the backslash: both a backslash and the escaped character match this
10878 pattern.  To work around this, specify the character class in a variable, so
10879 that quote removal does not apply afterwards, and the special characters don't
10880 have to be backslash-escaped:
10882 @example
10883 $ @kbd{case '\' in [\<]) echo OK;; esac}
10885 $ @kbd{scanset='[<]'; case '\' in $scanset) echo OK;; esac}
10887 @end example
10889 Even with this, SunOS 5.7 ksh matches a backslash if the set contains any
10890 of the characters @samp{|}, @samp{&}, @samp{(}, or @samp{)}.
10892 Some shells, such as Ash 0.3.8, are confused by an empty
10893 @code{case}/@code{esac}:
10895 @example
10896 ash-0.3.8 $ @kbd{case foo in esac;}
10897 @error{}Syntax error: ";" unexpected (expecting ")")
10898 @end example
10900 Many shells still do not support parenthesized cases, which is a pity
10901 for those of us using tools that rely on balanced parentheses.  For
10902 instance, Solaris 8's Bourne shell:
10904 @example
10905 $ @kbd{case foo in (foo) echo foo;; esac}
10906 @error{}syntax error: `(' unexpected
10907 @end example
10910 @item @command{cd}
10911 @c ---------------
10912 @prindex @command{cd}
10913 Posix 1003.1-2001 requires that @command{cd} must support
10914 the @option{-L} (``logical'') and @option{-P} (``physical'') options,
10915 with @option{-L} being the default.  However, traditional shells do
10916 not support these options, and their @command{cd} command has the
10917 @option{-P} behavior.
10919 Portable scripts should assume neither option is supported, and should
10920 assume neither behavior is the default.  This can be a bit tricky,
10921 since the Posix default behavior means that, for example,
10922 @samp{ls ..} and @samp{cd ..} may refer to different directories if
10923 the current logical directory is a symbolic link.  It is safe to use
10924 @command{cd @var{dir}} if @var{dir} contains no @file{..} components.
10925 Also, Autoconf-generated scripts check for this problem when computing
10926 variables like @code{ac_top_srcdir} (@pxref{Configuration Actions}),
10927 so it is safe to @command{cd} to these variables.
10929 Also please see the discussion of the @command{pwd} command.
10932 @item @command{echo}
10933 @c -----------------
10934 @prindex @command{echo}
10935 The simple @command{echo} is probably the most surprising source of
10936 portability troubles.  It is not possible to use @samp{echo} portably
10937 unless both options and escape sequences are omitted.  New applications
10938 which are not aiming at portability should use @samp{printf} instead of
10939 @samp{echo}.
10941 Don't expect any option.  @xref{Preset Output Variables}, @code{ECHO_N}
10942 etc.@: for a means to simulate @option{-n}.
10944 Do not use backslashes in the arguments, as there is no consensus on
10945 their handling.  On @samp{echo '\n' | wc -l}, the @command{sh} of
10946 Digital Unix 4.0 and @acronym{MIPS RISC/OS} 4.52, answer 2, but the Solaris
10947 @command{sh}, Bash, and Zsh (in @command{sh} emulation mode) report 1.
10948 Please note that the problem is truly @command{echo}: all the shells
10949 understand @samp{'\n'} as the string composed of a backslash and an
10950 @samp{n}.
10952 Because of these problems, do not pass a string containing arbitrary
10953 characters to @command{echo}.  For example, @samp{echo "$foo"} is safe
10954 if you know that @var{foo}'s value cannot contain backslashes and cannot
10955 start with @samp{-}, but otherwise you should use a here-document like
10956 this:
10958 @example
10959 cat <<EOF
10960 $foo
10962 @end example
10965 @item @command{exit}
10966 @c -----------------
10967 @prindex @command{exit}
10968 The default value of @command{exit} is supposed to be @code{$?};
10969 unfortunately, some shells, such as the @acronym{DJGPP} port of Bash 2.04, just
10970 perform @samp{exit 0}.
10972 @example
10973 bash-2.04$ @kbd{foo=`exit 1` || echo fail}
10974 fail
10975 bash-2.04$ @kbd{foo=`(exit 1)` || echo fail}
10976 fail
10977 bash-2.04$ @kbd{foo=`(exit 1); exit` || echo fail}
10978 bash-2.04$
10979 @end example
10981 Using @samp{exit $?} restores the expected behavior.
10983 Some shell scripts, such as those generated by @command{autoconf}, use a
10984 trap to clean up before exiting.  If the last shell command exited with
10985 nonzero status, the trap also exits with nonzero status so that the
10986 invoker can tell that an error occurred.
10988 Unfortunately, in some shells, such as Solaris 8 @command{sh}, an exit
10989 trap ignores the @code{exit} command's argument.  In these shells, a trap
10990 cannot determine whether it was invoked by plain @code{exit} or by
10991 @code{exit 1}.  Instead of calling @code{exit} directly, use the
10992 @code{AC_MSG_ERROR} macro that has a workaround for this problem.
10995 @item @command{export}
10996 @c -------------------
10997 @prindex @command{export}
10998 The builtin @command{export} dubs a shell variable @dfn{environment
10999 variable}.  Each update of exported variables corresponds to an update
11000 of the environment variables.  Conversely, each environment variable
11001 received by the shell when it is launched should be imported as a shell
11002 variable marked as exported.
11004 Alas, many shells, such as Solaris 2.5, @sc{irix} 6.3, @sc{irix} 5.2,
11005 @acronym{AIX} 4.1.5, and Digital Unix 4.0, forget to
11006 @command{export} the environment variables they receive.  As a result,
11007 two variables coexist: the environment variable and the shell
11008 variable.  The following code demonstrates this failure:
11010 @example
11011 #! /bin/sh
11012 echo $FOO
11013 FOO=bar
11014 echo $FOO
11015 exec /bin/sh $0
11016 @end example
11018 @noindent
11019 when run with @samp{FOO=foo} in the environment, these shells will print
11020 alternately @samp{foo} and @samp{bar}, although it should only print
11021 @samp{foo} and then a sequence of @samp{bar}s.
11023 Therefore you should @command{export} again each environment variable
11024 that you update.
11027 @item @command{false}
11028 @c ------------------
11029 @prindex @command{false}
11030 Don't expect @command{false} to exit with status 1: in the native Bourne
11031 shell of Solaris 8 it exits with status 255.
11034 @item @command{for}
11035 @c ----------------
11036 @prindex @command{for}
11037 To loop over positional arguments, use:
11039 @example
11040 for arg
11042   echo "$arg"
11043 done
11044 @end example
11046 @noindent
11047 You may @emph{not} leave the @code{do} on the same line as @code{for},
11048 since some shells improperly grok:
11050 @example
11051 for arg; do
11052   echo "$arg"
11053 done
11054 @end example
11056 If you want to explicitly refer to the positional arguments, given the
11057 @samp{$@@} bug (@pxref{Shell Substitutions}), use:
11059 @example
11060 for arg in $@{1+"$@@"@}; do
11061   echo "$arg"
11062 done
11063 @end example
11065 @noindent
11066 But keep in mind that Zsh, even in Bourne shell emulation mode, performs
11067 word splitting on @samp{$@{1+"$@@"@}}; see @ref{Shell Substitutions},
11068 item @samp{$@@}, for more.
11071 @item @command{if}
11072 @c ---------------
11073 @prindex @command{if}
11074 Using @samp{!} is not portable.  Instead of:
11076 @example
11077 if ! cmp -s file file.new; then
11078   mv file.new file
11080 @end example
11082 @noindent
11083 use:
11085 @example
11086 if cmp -s file file.new; then :; else
11087   mv file.new file
11089 @end example
11091 There are shells that do not reset the exit status from an @command{if}:
11093 @example
11094 $ @kbd{if (exit 42); then true; fi; echo $?}
11096 @end example
11098 @noindent
11099 whereas a proper shell should have printed @samp{0}.  This is especially
11100 bad in Makefiles since it produces false failures.  This is why properly
11101 written Makefiles, such as Automake's, have such hairy constructs:
11103 @example
11104 if test -f "$file"; then
11105   install "$file" "$dest"
11106 else
11107   :
11109 @end example
11112 @item @command{printf}
11113 @c ------------------
11114 @prindex @command{printf}
11115 A format string starting with a @samp{-} can cause problems.
11116 Bash (e.g., 2.05b) will interpret it as an options string and
11117 give an error.  And @samp{--} to mark the end of options is not good
11118 in the NetBSD Almquist shell (e.g., 0.4.6) which will take that
11119 literally as the format string.  Putting the @samp{-} in a @samp{%c}
11120 or @samp{%s} is probably the easiest way to avoid doubt,
11122 @example
11123 printf %s -foo
11124 @end example
11127 @item @command{read}
11128 @c ------------------
11129 @prindex @command{read}
11130 Not all shells support @option{-r} (Solaris 9 @command{sh} for example).
11133 @item @command{pwd}
11134 @c ----------------
11135 @prindex @command{pwd}
11136 With modern shells, plain @command{pwd} outputs a ``logical''
11137 directory name, some of whose components may be symbolic links.  These
11138 directory names are in contrast to ``physical'' directory names, whose
11139 components are all directories.
11141 Posix 1003.1-2001 requires that @command{pwd} must support
11142 the @option{-L} (``logical'') and @option{-P} (``physical'') options,
11143 with @option{-L} being the default.  However, traditional shells do
11144 not support these options, and their @command{pwd} command has the
11145 @option{-P} behavior.
11147 Portable scripts should assume neither option is supported, and should
11148 assume neither behavior is the default.  Also, on many hosts
11149 @samp{/bin/pwd} is equivalent to @samp{pwd -P}, but Posix
11150 does not require this behavior and portable scripts should not rely on
11153 Typically it's best to use plain @command{pwd}.  On modern hosts this
11154 outputs logical directory names, which have the following advantages:
11156 @itemize @bullet
11157 @item
11158 Logical names are what the user specified.
11159 @item
11160 Physical names may not be portable from one installation
11161 host to another due to network filesystem gymnastics.
11162 @item
11163 On modern hosts @samp{pwd -P} may fail due to lack of permissions to
11164 some parent directory, but plain @command{pwd} cannot fail for this
11165 reason.
11166 @end itemize
11168 Also please see the discussion of the @command{cd} command.
11171 @item @command{set}
11172 @c ----------------
11173 @prindex @command{set}
11174 This builtin faces the usual problem with arguments starting with a
11175 dash.  Modern shells such as Bash or Zsh understand @option{--} to specify
11176 the end of the options (any argument after @option{--} is a parameter,
11177 even @samp{-x} for instance), but most shells simply stop the option
11178 processing as soon as a non-option argument is found.  Therefore, use
11179 @samp{dummy} or simply @samp{x} to end the option processing, and use
11180 @command{shift} to pop it out:
11182 @example
11183 set x $my_list; shift
11184 @end example
11186 Avoid @samp{set -}, e.g., @samp{set - $my_list}.  Posix no
11187 longer requires support for this command, and in traditional shells
11188 @samp{set - $my_list} resets the @samp{-v} and @samp{-x} options, which
11189 makes scripts harder to debug.
11191 Some nonstandard shells do not recognize more than one option
11192 (e.g., @samp{set -e -x} assigns @samp{-x} to the command line).  It is
11193 better to combine them:
11195 @example
11196 set -ex
11197 @end example
11200 @item @command{shift}
11201 @c ------------------
11202 @prindex @command{shift}
11203 Not only is @command{shift}ing a bad idea when there is nothing left to
11204 shift, but in addition it is not portable: the shell of @acronym{MIPS
11205 RISC/OS} 4.52 refuses to do it.
11208 @item @command{source}
11209 @c -------------------
11210 @prindex @command{source}
11211 This command is not portable, as Posix does not require it; use
11212 @command{.} instead.
11215 @item @command{test}
11216 @c -----------------
11217 @prindex @command{test}
11218 The @code{test} program is the way to perform many file and string
11219 tests.  It is often invoked by the alternate name @samp{[}, but using
11220 that name in Autoconf code is asking for trouble since it is an M4 quote
11221 character.
11223 If you need to make multiple checks using @code{test}, combine them with
11224 the shell operators @samp{&&} and @samp{||} instead of using the
11225 @code{test} operators @option{-a} and @option{-o}.  On System V, the
11226 precedence of @option{-a} and @option{-o} is wrong relative to the unary
11227 operators; consequently, Posix does not specify them, so using them
11228 is nonportable.  If you combine @samp{&&} and @samp{||} in the same
11229 statement, keep in mind that they have equal precedence.
11231 It is safe to use @samp{!} as a @command{test} operator.  For example,
11232 @samp{if test ! -d foo; @dots{}} is portable even though @samp{if ! test
11233 -d foo; @dots{}} is not.
11236 @item @command{test} (files)
11237 @c -------------------------
11238 To enable @command{configure} scripts to support cross-compilation, they
11239 shouldn't do anything that tests features of the build system instead of
11240 the host system.  But occasionally you may find it necessary to check
11241 whether some arbitrary file exists.  To do so, use @samp{test -f} or
11242 @samp{test -r}.  Do not use @samp{test -x}, because 4.3@acronym{BSD} does not
11243 have it.  Do not use @samp{test -e} either, because Solaris 2.5 does not
11244 have it.  To test for symbolic links on systems that have them, use
11245 @samp{test -h} rather than @samp{test -L}; either form conforms to
11246 Posix 1003.1-2001, but older shells like Solaris 8
11247 @code{sh} support only @option{-h}.
11249 @item @command{test} (strings)
11250 @c ---------------------------
11251 Avoid @samp{test "@var{string}"}, in particular if @var{string} might
11252 start with a dash, since @code{test} might interpret its argument as an
11253 option (e.g., @samp{@var{string} = "-n"}).
11255 Contrary to a common belief, @samp{test -n @var{string}} and
11256 @samp{test -z @var{string}} @strong{are} portable.  Nevertheless many
11257 shells (such as Solaris 2.5, @acronym{AIX} 3.2, @sc{unicos} 10.0.0.6,
11258 Digital Unix 4, etc.)@: have bizarre precedence and may be confused if
11259 @var{string} looks like an operator:
11261 @example
11262 $ @kbd{test -n =}
11263 test: argument expected
11264 @end example
11266 If there are risks, use @samp{test "x@var{string}" = x} or @samp{test
11267 "x@var{string}" != x} instead.
11269 It is common to find variations of the following idiom:
11271 @example
11272 test -n "`echo $ac_feature | sed 's/[-a-zA-Z0-9_]//g'`" &&
11273   @var{action}
11274 @end example
11276 @noindent
11277 to take an action when a token matches a given pattern.  Such constructs
11278 should always be avoided by using:
11280 @example
11281 echo "$ac_feature" | grep '[^-a-zA-Z0-9_]' >/dev/null 2>&1 &&
11282   @var{action}
11283 @end example
11285 @noindent
11286 Use @code{case} where possible since it is faster, being a shell builtin:
11289 @example
11290 case $ac_feature in
11291   *[!-a-zA-Z0-9_]*) @var{action};;
11292 esac
11293 @end example
11295 Alas, negated character classes are probably not portable, although no
11296 shell is known to not support the Posix syntax @samp{[!@dots{}]}
11297 (when in interactive mode, @command{zsh} is confused by the
11298 @samp{[!@dots{}]} syntax and looks for an event in its history because of
11299 @samp{!}).  Many shells do not support the alternative syntax
11300 @samp{[^@dots{}]} (Solaris, Digital Unix, etc.).
11302 One solution can be:
11304 @example
11305 expr "$ac_feature" : '.*[^-a-zA-Z0-9_]' >/dev/null &&
11306   @var{action}
11307 @end example
11309 @noindent
11310 or better yet
11312 @example
11313 expr "X$ac_feature" : '.*[^-a-zA-Z0-9_]' >/dev/null &&
11314   @var{action}
11315 @end example
11317 @samp{expr "X@var{foo}" : "X@var{bar}"} is more robust than @samp{echo
11318 "X@var{foo}" | grep "^X@var{bar}"}, because it avoids problems when
11319 @samp{@var{foo}} contains backslashes.
11322 @item @command{trap}
11323 @c -----------------
11324 @prindex @command{trap}
11325 It is safe to trap at least the signals 1, 2, 13, and 15.  You can also
11326 trap 0, i.e., have the @command{trap} run when the script ends (either via an
11327 explicit @command{exit}, or the end of the script).
11329 Although Posix is not absolutely clear on this point, it is widely
11330 admitted that when entering the trap @samp{$?} should be set to the exit
11331 status of the last command run before the trap.  The ambiguity can be
11332 summarized as: ``when the trap is launched by an @command{exit}, what is
11333 the @emph{last} command run: that before @command{exit}, or
11334 @command{exit} itself?''
11336 Bash considers @command{exit} to be the last command, while Zsh and
11337 Solaris 8 @command{sh} consider that when the trap is run it is
11338 @emph{still} in the @command{exit}, hence it is the previous exit status
11339 that the trap receives:
11341 @example
11342 $ @kbd{cat trap.sh}
11343 trap 'echo $?' 0
11344 (exit 42); exit 0
11345 $ @kbd{zsh trap.sh}
11347 $ @kbd{bash trap.sh}
11349 @end example
11351 The portable solution is then simple: when you want to @samp{exit 42},
11352 run @samp{(exit 42); exit 42}, the first @command{exit} being used to
11353 set the exit status to 42 for Zsh, and the second to trigger the trap
11354 and pass 42 as exit status for Bash.
11356 The shell in Free@acronym{BSD} 4.0 has the following bug: @samp{$?} is
11357 reset to 0 by empty lines if the code is inside @command{trap}.
11359 @example
11360 $ @kbd{trap 'false}
11362 echo $?' 0
11363 $ @kbd{exit}
11365 @end example
11367 @noindent
11368 Fortunately, this bug only affects @command{trap}.
11370 @item @command{true}
11371 @c -----------------
11372 @prindex @command{true}
11373 @c Info cannot handle `:' in index entries.
11374 @c @prindex @command{:}
11375 Don't worry: as far as we know @command{true} is portable.
11376 Nevertheless, it's not always a builtin (e.g., Bash 1.x), and the
11377 portable shell community tends to prefer using @command{:}.  This has a
11378 funny side effect: when asked whether @command{false} is more portable
11379 than @command{true} Alexandre Oliva answered:
11381 @quotation
11382 In a sense, yes, because if it doesn't exist, the shell will produce an
11383 exit status of failure, which is correct for @command{false}, but not
11384 for @command{true}.
11385 @end quotation
11388 @item @command{unset}
11389 @c ------------------
11390 @prindex @command{unset}
11391 You cannot assume the support of @command{unset}.  Nevertheless, because
11392 it is extremely useful to disable embarrassing variables such as
11393 @code{PS1}, you can test for its existence and use
11394 it @emph{provided} you give a neutralizing value when @command{unset} is
11395 not supported:
11397 @example
11398 if (unset FOO) >/dev/null 2>&1; then
11399   unset=unset
11400 else
11401   unset=false
11403 $unset PS1 || PS1='$ '
11404 @end example
11406 @xref{Special Shell Variables}, for some neutralizing values.  Also, see
11407 @ref{Limitations of Builtins}, documentation of @command{export}, for
11408 the case of environment variables.
11409 @end table
11411 @node Limitations of Usual Tools
11412 @section Limitations of Usual Tools
11413 @cindex Limitations of usual tools
11415 The small set of tools you can expect to find on any machine can still
11416 include some limitations you should be aware of.
11418 @table @asis
11419 @item @command{awk}
11420 @c ----------------
11421 @prindex @command{awk}
11422 Don't leave white spaces before the parentheses in user functions calls;
11423 @acronym{GNU} awk will reject it:
11425 @example
11426 $ @kbd{gawk 'function die () @{ print "Aaaaarg!"  @}
11427         BEGIN @{ die () @}'}
11428 gawk: cmd. line:2:         BEGIN @{ die () @}
11429 gawk: cmd. line:2:                      ^ parse error
11430 $ @kbd{gawk 'function die () @{ print "Aaaaarg!"  @}
11431         BEGIN @{ die() @}'}
11432 Aaaaarg!
11433 @end example
11435 If you want your program to be deterministic, don't depend on @code{for}
11436 on arrays:
11438 @example
11439 $ @kbd{cat for.awk}
11440 END @{
11441   arr["foo"] = 1
11442   arr["bar"] = 1
11443   for (i in arr)
11444     print i
11446 $ @kbd{gawk -f for.awk </dev/null}
11449 $ @kbd{nawk -f for.awk </dev/null}
11452 @end example
11454 Some AWK, such as HPUX 11.0's native one, have regex engines fragile to
11455 inner anchors:
11457 @example
11458 $ @kbd{echo xfoo | $AWK '/foo|^bar/ @{ print @}'}
11459 $ @kbd{echo bar | $AWK '/foo|^bar/ @{ print @}'}
11461 $ @kbd{echo xfoo | $AWK '/^bar|foo/ @{ print @}'}
11462 xfoo
11463 $ @kbd{echo bar | $AWK '/^bar|foo/ @{ print @}'}
11465 @end example
11467 @noindent
11468 Either do not depend on such patterns (i.e., use @samp{/^(.*foo|bar)/},
11469 or use a simple test to reject such AWK@.
11472 @item @command{cat}
11473 @c ----------------
11474 @prindex @command{cat}
11475 Don't rely on any option.  The option @option{-v}, which displays
11476 non-printing characters, @emph{seems} portable, though.
11479 @item @command{cc}
11480 @c ---------------
11481 @prindex @command{cc}
11482 The command @samp{cc -c foo.c} traditionally produces an object file
11483 named @file{foo.o}.  Most compilers allow @option{-c} to be combined
11484 with @option{-o} to specify a different object file name, but
11485 Posix does not require this combination and a few compilers
11486 lack support for it.  @xref{C Compiler}, for how @acronym{GNU} Make
11487 tests for this feature with @code{AC_PROG_CC_C_O}.
11489 When a compilation such as @samp{cc -o foo foo.c} fails, some compilers
11490 (such as @sc{cds} on Reliant Unix) leave a @file{foo.o}.
11492 HP-UX @command{cc} doesn't accept @file{.S} files to preprocess and
11493 assemble.  @samp{cc -c foo.S} will appear to succeed, but in fact does
11494 nothing.
11496 The default executable, produced by @samp{cc foo.c}, can be
11498 @itemize
11499 @item @file{a.out} --- usual Posix convention.
11500 @item @file{b.out} --- i960 compilers (including @command{gcc}).
11501 @item @file{a.exe} --- @acronym{DJGPP} port of @command{gcc}.
11502 @item @file{a_out.exe} --- GNV @command{cc} wrapper for DEC C on OpenVMS.
11503 @item @file{foo.exe} --- various MS-DOS compilers.
11504 @end itemize
11506 The C compiler's traditional name is @command{cc}, but other names like
11507 @command{gcc} are common.  Posix 1003.1-2001 specifies the
11508 name @command{c99}, but older Posix editions specified
11509 @command{c89} and anyway these standard names are rarely used in
11510 practice.  Typically the C compiler is invoked from makefiles that use
11511 @samp{$(CC)}, so the value of the @samp{CC} make variable selects the
11512 compiler name.
11515 @item @command{chmod}
11516 @c ------------------
11517 @prindex @command{chmod}
11518 Avoid usages like @samp{chmod -w file}; use @samp{chmod a-w file}
11519 instead, for two reasons.  First, plain @samp{-w} does not necessarily
11520 make the file unwriteable, since it does not affect mode bits that
11521 correspond to bits in the file mode creation mask.  Second,
11522 Posix says that the @samp{-w} might be interpreted as an
11523 implementation-specific option, not as a mode; Posix suggests
11524 using @samp{chmod -- -w file} to avoid this confusion, but unfortunately
11525 @samp{--} does not work on some older hosts.
11528 @item @command{cmp}
11529 @c ----------------
11530 @prindex @command{cmp}
11531 @command{cmp} performs a raw data comparison of two files, while
11532 @command{diff} compares two text files.  Therefore, if you might compare
11533 DOS files, even if only checking whether two files are different, use
11534 @command{diff} to avoid spurious differences due to differences of
11535 newline encoding.
11538 @item @command{cp}
11539 @c ---------------
11540 @prindex @command{cp}
11541 Avoid the @option{-r} option, since its behavior is not specified by
11542 Posix.  Use @option{-R} instead.  On @acronym{GNU} hosts the two options
11543 are equivalent, but on Solaris 9 hosts (for example) @command{cp -r}
11544 reads from pipes instead of replicating them.
11546 Some @command{cp} implementations (e.g., BSD/OS 4.2) do not allow
11547 trailing slashes at the end of nonexistent destination directories.  To
11548 avoid this problem, omit the trailing slashes.  For example, use
11549 @samp{cp -R source /tmp/newdir} rather than @samp{cp -R source
11550 /tmp/newdir/} if @file{/tmp/newdir} does not exist.
11552 @c This is thanks to Ian.
11553 SunOS @command{cp} does not support @option{-f}, although its
11554 @command{mv} does.  It's possible to deduce why @command{mv} and
11555 @command{cp} are different with respect to @option{-f}.  @command{mv}
11556 prompts by default before overwriting a read-only file.  @command{cp}
11557 does not.  Therefore, @command{mv} requires a @option{-f} option, but
11558 @command{cp} does not.  @command{mv} and @command{cp} behave differently
11559 with respect to read-only files because the simplest form of
11560 @command{cp} cannot overwrite a read-only file, but the simplest form of
11561 @command{mv} can.  This is because @command{cp} opens the target for
11562 write access, whereas @command{mv} simply calls @code{link} (or, in
11563 newer systems, @code{rename}).
11564 @c Ian said: ``I don't think -p or -r are portable''!!! How can you live
11565 @c without -r???
11567 @cindex timestamp resolution
11568 Traditionally, file timestamps had 1-second resolution, and @samp{cp
11569 -p} copied the timestamps exactly.  However, many modern filesystems
11570 have timestamps with 1-nanosecond resolution.  Unfortunately, @samp{cp
11571 -p} implementations truncate timestamps when copying files, so this
11572 can result in the destination file appearing to be older than the
11573 source.  The exact amount of truncation depends on the resolution of
11574 the system calls that @command{cp} uses; traditionally this was
11575 @code{utime}, which has 1-second resolution, but some newer
11576 @command{cp} implementations use @code{utimes}, which has
11577 1-microsecond resolution.  These newer implementations include GNU
11578 coreutils 5.0.91 or later, and Solaris 8 (sparc) patch 109933-02 or
11579 later.  Unfortunately as of September 2003 there is still no system
11580 call to set time stamps to the full nanosecond resolution.
11582 Bob Proulx notes that @samp{cp -p} always @emph{tries} to copy
11583 ownerships.  But whether it actually does copy ownerships or not is a
11584 system dependent policy decision implemented by the kernel.  If the
11585 kernel allows it then it happens.  If the kernel does not allow it then
11586 it does not happen.  It is not something @command{cp} itself has control
11587 over.
11589 In SysV any user can chown files to any other user, and SysV also had a
11590 non-sticky @file{/tmp}.  That undoubtedly derives from the heritage of
11591 SysV in a business environment without hostile users.  BSD changed this
11592 to be a more secure model where only root can @command{chown} files and
11593 a sticky @file{/tmp} is used.  That undoubtedly derives from the heritage
11594 of BSD in a campus environment.
11596 Linux by default follows BSD, but it can be configured to allow
11597 @command{chown}.  HP-UX as an alternate example follows SysV, but it can
11598 be configured to use the modern security model and disallow
11599 @command{chown}.  Since it is an administrator configurable parameter
11600 you can't use the name of the kernel as an indicator of the behavior.
11604 @item @command{date}
11605 @c -----------------
11606 @prindex @command{date}
11607 Some versions of @command{date} do not recognize special % directives,
11608 and unfortunately, instead of complaining, they just pass them through,
11609 and exit with success:
11611 @example
11612 $ @kbd{uname -a}
11613 OSF1 medusa.sis.pasteur.fr V5.1 732 alpha
11614 $ @kbd{date "+%s"}
11616 @end example
11619 @item @command{diff}
11620 @c -----------------
11621 @prindex @command{diff}
11622 Option @option{-u} is nonportable.
11624 Some implementations, such as Tru64's, fail when comparing to
11625 @file{/dev/null}.  Use an empty file instead.
11628 @item @command{dirname}
11629 @c --------------------
11630 @prindex @command{dirname}
11631 Not all hosts have a working @command{dirname}, and you should instead
11632 use @code{AS_DIRNAME} (@pxref{Programming in M4sh}).  For example:
11634 @example
11635 dir=`dirname "$file"`       # This is not portable.
11636 dir=`AS_DIRNAME(["$file"])` # This is more portable.
11637 @end example
11639 Unfortunately, neither of the above commands work if @code{$file}'s
11640 directory name ends in newline, since @samp{`@dots{}`} removes all
11641 trailing newlines.
11643 @noindent
11644 This handles a few subtleties in the standard way required by
11645 Posix.  For example, under UN*X, should @samp{dirname //1} give
11646 @samp{/}?  Paul Eggert answers:
11648 @quotation
11649 No, under some older flavors of Unix, leading @samp{//} is a special
11650 file name: it refers to a ``super-root'' and is used to access other
11651 machines' files.  Leading @samp{///}, @samp{////}, etc.@: are equivalent
11652 to @samp{/}; but leading @samp{//} is special.  This tradition
11653 started with Apollo Domain/OS, though it has largely died out in practice.
11655 Posix allows but does not require the special treatment for
11656 @samp{//}.  It says that the behavior of @command{dirname} on file names of the
11657 form @samp{//([^/]+/*)?} is implementation defined.  In these cases,
11658 @acronym{GNU} @command{dirname} returns @samp{/}, but those no-longer-used
11659 flavors of Unix returned @samp{//}.
11660 @end quotation
11663 @item @command{egrep}
11664 @c ------------------
11665 @prindex @command{egrep}
11666 Posix 1003.1-2001 no longer requires @command{egrep},
11667 but many older hosts do not yet support the Posix
11668 replacement @code{grep -E}.  Also, some traditional implementations do
11669 not work on long input lines.  To work around these problems, invoke
11670 @code{AC_PROG_EGREP} and then use @code{$EGREP}.
11672 The empty alternative is not portable, use @samp{?} instead.  For
11673 instance with Digital Unix v5.0:
11675 @example
11676 > printf "foo\n|foo\n" | $EGREP '^(|foo|bar)$'
11677 |foo
11678 > printf "bar\nbar|\n" | $EGREP '^(foo|bar|)$'
11679 bar|
11680 > printf "foo\nfoo|\n|bar\nbar\n" | $EGREP '^(foo||bar)$'
11682 |bar
11683 @end example
11685 @command{$EGREP} also suffers the limitations of @command{grep}.
11687 @item @command{expr}
11688 @c -----------------
11689 @prindex @command{expr}
11690 No @command{expr} keyword starts with @samp{X}, so use @samp{expr
11691 X"@var{word}" : 'X@var{regex}'} to keep @command{expr} from
11692 misinterpreting @var{word}.
11694 Don't use @code{length}, @code{substr}, @code{match} and @code{index}.
11696 @item @command{expr} (@samp{|})
11697 @prindex @command{expr} (@samp{|})
11698 You can use @samp{|}.  Although Posix does require that @samp{expr
11699 ''} return the empty string, it does not specify the result when you
11700 @samp{|} together the empty string (or zero) with the empty string.  For
11701 example:
11703 @example
11704 expr '' \| ''
11705 @end example
11707 Posix 1003.2-1992 returns the empty string
11708 for this case, but traditional Unix returns @samp{0} (Solaris is
11709 one such example).  In Posix 1003.1-2001, the specification was
11710 changed to match traditional Unix's behavior (which is
11711 bizarre, but it's too late to fix this).  Please note that the same
11712 problem does arise when the empty string results from a computation,
11713 as in:
11715 @example
11716 expr bar : foo \| foo : bar
11717 @end example
11719 @noindent
11720 Avoid this portability problem by avoiding the empty string.
11723 @item @command{expr} (@samp{:})
11724 @c ----------------------------
11725 @prindex @command{expr}
11726 Don't use @samp{\?}, @samp{\+} and @samp{\|} in patterns, as they are
11727 not supported on Solaris.
11729 The Posix standard is ambiguous as to whether
11730 @samp{expr 'a' : '\(b\)'} outputs @samp{0} or the empty string.
11731 In practice, it outputs the empty string on most platforms, but portable
11732 scripts should not assume this.  For instance, the @acronym{QNX} 4.25 native
11733 @command{expr} returns @samp{0}.
11735 One might think that a way to get a uniform behavior would be to use
11736 the empty string as a default value:
11738 @example
11739 expr a : '\(b\)' \| ''
11740 @end example
11742 @noindent
11743 Unfortunately this behaves exactly as the original expression; see the
11744 @samp{@command{expr} (@samp{|})} entry for more information.
11746 Older @command{expr} implementations (e.g., SunOS 4 @command{expr} and
11747 Solaris 8 @command{/usr/ucb/expr}) have a silly length limit that causes
11748 @command{expr} to fail if the matched substring is longer than 120
11749 bytes.  In this case, you might want to fall back on @samp{echo|sed} if
11750 @command{expr} fails.
11752 Don't leave, there is some more!
11754 The @acronym{QNX} 4.25 @command{expr}, in addition of preferring @samp{0} to
11755 the empty string, has a funny behavior in its exit status: it's always 1
11756 when parentheses are used!
11758 @example
11759 $ @kbd{val=`expr 'a' : 'a'`; echo "$?: $val"}
11760 0: 1
11761 $ @kbd{val=`expr 'a' : 'b'`; echo "$?: $val"}
11762 1: 0
11764 $ @kbd{val=`expr 'a' : '\(a\)'`; echo "?: $val"}
11765 1: a
11766 $ @kbd{val=`expr 'a' : '\(b\)'`; echo "?: $val"}
11767 1: 0
11768 @end example
11770 @noindent
11771 In practice this can be a big problem if you are ready to catch failures
11772 of @command{expr} programs with some other method (such as using
11773 @command{sed}), since you may get twice the result.  For instance
11775 @example
11776 $ @kbd{expr 'a' : '\(a\)' || echo 'a' | sed 's/^\(a\)$/\1/'}
11777 @end example
11779 @noindent
11780 will output @samp{a} on most hosts, but @samp{aa} on @acronym{QNX} 4.25.  A
11781 simple workaround consists in testing @command{expr} and use a variable
11782 set to @command{expr} or to @command{false} according to the result.
11785 @item @command{fgrep}
11786 @c ------------------
11787 @prindex @command{fgrep}
11788 Posix 1003.1-2001 no longer requires @command{fgrep},
11789 but many older hosts do not yet support the Posix
11790 replacement @code{grep -F}.  Also, some traditional implementations do
11791 not work on long input lines.  To work around these problems, invoke
11792 @code{AC_PROG_FGREP} and then use @code{$FGREP}.
11795 @item @command{find}
11796 @c -----------------
11797 @prindex @command{find}
11798 The option @option{-maxdepth} seems to be @acronym{GNU} specific.
11799 Tru64 v5.1, Net@acronym{BSD} 1.5 and Solaris 2.5 @command{find}
11800 commands do not understand it.
11802 The replacement of @samp{@{@}} is guaranteed only if the argument is
11803 exactly @emph{@{@}}, not if it's only a part of an argument.  For
11804 instance on DU, and HP-UX 10.20 and HP-UX 11:
11806 @example
11807 $ @kbd{touch foo}
11808 $ @kbd{find . -name foo -exec echo "@{@}-@{@}" \;}
11809 @{@}-@{@}
11810 @end example
11812 @noindent
11813 while @acronym{GNU} @command{find} reports @samp{./foo-./foo}.
11816 @item @command{grep}
11817 @c -----------------
11818 @prindex @command{grep}
11819 Don't use @samp{grep -q} to suppress output, because many @command{grep}
11820 implementations (e.g., Solaris 10) do not support @option{-q}.
11821 Don't use @samp{grep -s} to suppress output either, because Posix
11822 says @option{-s} does not suppress output, only some error messages;
11823 also, the @option{-s} option of traditional @command{grep} behaved
11824 like @option{-q} does in most modern implementations.  Instead,
11825 redirect the standard output and standard error (in case the file
11826 doesn't exist) of @code{grep} to @file{/dev/null}.  Check the exit
11827 status of @code{grep} to determine whether it found a match.
11829 Some traditional @command{grep} implementations do not work on long
11830 input lines.  Also, many implementations do not support multiple regexps
11831 with @option{-e}: they either reject @samp{-e} entirely (e.g., Solaris
11832 10) or honor only the last pattern (e.g., @acronym{IRIX} 6.5).  To
11833 work around these problems, invoke @code{AC_PROG_GREP} and then use
11834 @code{$GREP}.
11836 Don't rely on @option{-w}, as Irix 6.5.16m's @command{grep} does not
11837 support it.
11840 @item @command{join}
11841 @c -----------------
11842 @prindex @command{join}
11843 Solaris 8 @command{join} has bugs when the second operand is standard
11844 input, and when standard input is a pipe.  For example, the following
11845 shell script causes Solaris 8 @command{join} to loop forever:
11847 @example
11848 cat >file <<'EOF'
11849 1 x
11850 2 y
11852 cat file | join file -
11853 @end example
11855 Use @samp{join - file} instead.
11858 @item @command{ln}
11859 @c ---------------
11860 @prindex @command{ln}
11861 @cindex Symbolic links
11862 Don't rely on @command{ln} having a @option{-f} option.  Symbolic links
11863 are not available on old systems; use @samp{$(LN_S)} as a portable substitute.
11865 For versions of the @acronym{DJGPP} before 2.04,
11866 @command{ln} emulates symbolic links
11867 to executables by generating a stub that in turn calls the real
11868 program.  This feature also works with nonexistent files like in the
11869 Posix spec.  So @samp{ln -s file link} will generate @file{link.exe},
11870 which will attempt to call @file{file.exe} if run.  But this feature only
11871 works for executables, so @samp{cp -p} is used instead for these
11872 systems.  @acronym{DJGPP} versions 2.04 and later have full support
11873 for symbolic links.
11876 @item @command{ls}
11877 @c ---------------
11878 @prindex @command{ls}
11879 @cindex Listing directories
11880 The portable options are @option{-acdilrtu}.  Modern practice is for
11881 @option{-l} to output both owner and group, but traditional
11882 @command{ls} omits the group.
11884 @c From Bruce Lilly:
11886 @c # telnet dim
11887 @c [...]
11888 @c   Unix System V (TWG-TCP/IP) (dim.blilly.com)
11889 @c [...]
11890 @c $ mkdir foo
11891 @c $ cd foo
11892 @c $ /bin/ls a.exe 2>/dev/null
11893 @c a.exe not found
11894 @c $ what /bin/ls
11895 @c /bin/ls:
11896 @c           fndcmd:fndcmd.sl 1.68
11897 @c $ uname -a
11898 @c Unix dim SYSTEM5 3.51m mc68k
11900 @c It's an AT&T 3B1.  See http://www.faqs.org/faqs/3b1-faq/ or any
11901 @c mirror of the 3B1 FAQ.  It's actually SVR2.2.
11902 Modern practice is for all diagnostics to go to standard error, but
11903 traditional @samp{ls foo} prints the message @samp{foo not found} to
11904 standard output if @file{foo} does not exist.  Be careful when writing
11905 shell commands like @samp{sources=`ls *.c 2>/dev/null`}, since with
11906 traditional @command{ls} this is equivalent to @samp{sources="*.c not
11907 found"} if there are no @samp{.c} files.
11910 @item @command{mkdir}
11911 @c ------------------
11912 @prindex @command{mkdir}
11913 @cindex Making directories
11914 None of @command{mkdir}'s options are portable to older systems.  Instead of
11915 @samp{mkdir -p @var{file-name}}, you should use use
11916 @code{AS_MKDIR_P(@var{file-name})} (@pxref{Programming in M4sh}).
11918 Posix does not clearly specify whether @samp{mkdir -p foo}
11919 should succeed when @file{foo} is a symbolic link to an already-existing
11920 directory.  GNU Coreutils 5.1.0 @command{mkdir} succeeds, but Solaris 9
11921 @command{mkdir} fails.
11923 Not all @code{mkdir -p} implementations are thread-safe.  When it is not
11924 and you call @code{mkdir -p a/b} and @code{mkdir -p a/c} at the same
11925 time, both will detect that @file{a/} is missing, one will create
11926 @file{a/}, then the other will try to create @file{a/} and die with a
11927 @code{File exists} error.  At least Solaris 8, NetBSD 1.6, and OpenBSD
11928 3.4 have an unsafe @code{mkdir -p}.  GNU Coreutils (since Fileutils
11929 version 4.0c), FreeBSD 5.0, and NetBSD-current are known to have a
11930 race-free @code{mkdir -p}.  This possible race is harmful in parallel
11931 builds when several @file{Makefile} rules call @code{mkdir -p} to
11932 construct directories.  You may use @command{mkinstalldirs} or
11933 @code{install-sh -d} as a safe replacement, provided these scripts are
11934 recent enough (the copies shipped with Automake 1.8.3 are OK, those from
11935 older versions are not thread-safe either).
11938 @item @command{mktemp}
11939 @c -------------------
11940 @prindex @command{mktemp}
11941 @cindex Creating temporary files
11942 Shell scripts can use temporary files safely with @command{mktemp}, but
11943 it does not exist on all systems.  A portable way to create a safe
11944 temporary file name is to create a temporary directory with mode 700 and
11945 use a file inside this directory.  Both methods prevent attackers from
11946 gaining control, though @command{mktemp} is far less likely to fail
11947 gratuitously under attack.
11949 Here is sample code to create a new temporary directory safely:
11951 @example
11952 # Create a temporary directory $tmp in $TMPDIR (default /tmp).
11953 # Use mktemp if possible; otherwise fall back on mkdir,
11954 # with $RANDOM to make collisions less likely.
11955 : $@{TMPDIR=/tmp@}
11957   tmp=`
11958     (umask 077 && mktemp -d "$TMPDIR/fooXXXXXX") 2>/dev/null
11959   ` &&
11960   test -n "$tmp" && test -d "$tmp"
11961 @} || @{
11962   tmp=$TMPDIR/foo$$-$RANDOM
11963   (umask 077 && mkdir "$tmp")
11964 @} || exit $?
11965 @end example
11968 @item @command{mv}
11969 @c ---------------
11970 @prindex @command{mv}
11971 @cindex Moving open files
11972 The only portable options are @option{-f} and @option{-i}.
11974 Moving individual files between file systems is portable (it was in Unix
11975 version 6),
11976 but it is not always atomic: when doing @samp{mv new existing}, there's
11977 a critical section where neither the old nor the new version of
11978 @file{existing} actually exists.
11980 Be aware that moving files from @file{/tmp} can sometimes cause
11981 undesirable (but perfectly valid) warnings, even if you created these
11982 files.  On some systems, creating the file in @file{/tmp} is setting a
11983 guid @code{wheel} which you may not be part of.  So the file is copied,
11984 and then the @code{chgrp} fails:
11986 @example
11987 $ @kbd{touch /tmp/foo}
11988 $ @kbd{mv /tmp/foo .}
11989 @error{}mv: ./foo: set owner/group (was: 3830/0): Operation not permitted
11990 $ @kbd{echo $?}
11992 $ @kbd{ls foo}
11994 @end example
11996 @noindent
11997 This behavior conforms to Posix:
11999 @quotation
12000 If the duplication of the file characteristics fails for any reason, mv
12001 shall write a diagnostic message to standard error, but this failure
12002 shall not cause mv to modify its exit status.''
12003 @end quotation
12005 Moving directories across mount points is not portable, use @command{cp}
12006 and @command{rm}.
12008 Moving/Deleting open files isn't portable.  The following can't be done
12009 on @acronym{DOS} variants:
12011 @example
12012 exec > foo
12013 mv foo bar
12014 @end example
12016 @noindent
12017 nor can
12019 @example
12020 exec > foo
12021 rm -f foo
12022 @end example
12024 @item @command{sed}
12025 @c ----------------
12026 @prindex @command{sed}
12027 Patterns should not include the separator (unless escaped), even as part
12028 of a character class.  In conformance with Posix, the Cray
12029 @command{sed} will reject @samp{s/[^/]*$//}: use @samp{s,[^/]*$,,}.
12031 Avoid empty patterns within parentheses (i.e., @samp{\(\)}).  Posix is
12032 silent on whether they are allowed, and Unicos 9 @command{sed} rejects
12033 them.
12035 Unicos 9 @command{sed} loops endlessly on patterns like @samp{.*\n.*}.
12037 Sed scripts should not use branch labels longer than 8 characters and
12038 should not contain comments.
12040 Don't include extra @samp{;}, as some @command{sed}, such as Net@acronym{BSD}
12041 1.4.2's, try to interpret the second as a command:
12043 @example
12044 $ @kbd{echo a | sed 's/x/x/;;s/x/x/'}
12045 sed: 1: "s/x/x/;;s/x/x/": invalid command code ;
12046 @end example
12048 Input should have reasonably long lines, since some @command{sed} have
12049 an input buffer limited to 4000 bytes.
12051 Alternation, @samp{\|}, is common but Posix does not require its
12052 support, so it should be avoided in portable scripts.  Solaris 8
12053 @command{sed} does not support alternation; e.g., @samp{sed '/a\|b/d'}
12054 deletes only lines that contain the literal string @samp{a|b}.
12056 Anchors (@samp{^} and @samp{$}) inside groups are not portable.
12058 Nested parenthesization in patterns (e.g., @samp{\(\(a*\)b*)\)}) is
12059 quite portable to modern hosts, but is not supported by some older
12060 @command{sed} implementations like SVR3.
12062 The @option{-e} option is portable.
12063 Some people prefer to use it:
12065 @example
12066 sed -e '@var{command-1}' \
12067     -e '@var{command-2}'
12068 @end example
12070 @noindent
12071 as opposed to the equivalent:
12073 @example
12074 sed '
12075   @var{command-1}
12076   @var{command-2}
12078 @end example
12080 @noindent
12081 The following usage is sometimes equivalent:
12083 @example
12084 sed '@var{command-1};@var{command-2}'
12085 @end example
12087 but Posix says that this use of a semicolon has undefined effect if
12088 @var{command-1}'s verb is @samp{@{}, @samp{a}, @samp{b}, @samp{c},
12089 @samp{i}, @samp{r}, @samp{t}, @samp{w}, @samp{:}, or @samp{#}, so you
12090 should use semicolon only with simple scripts that do not use these
12091 verbs.
12093 Contrary to yet another urban legend, you may portably use @samp{&} in
12094 the replacement part of the @code{s} command to mean ``what was
12095 matched''.  All descendants of Unix version 7 @command{sed}
12096 (at least; we
12097 don't have first hand experience with older @command{sed}s) have
12098 supported it.
12100 Posix requires that you must not have any white space between
12101 @samp{!}  and the following command.  It is OK to have blanks between
12102 the address and the @samp{!}.  For instance, on Solaris 8:
12104 @example
12105 $ @kbd{echo "foo" | sed -n '/bar/ ! p'}
12106 @error{}Unrecognized command: /bar/ ! p
12107 $ @kbd{echo "foo" | sed -n '/bar/! p'}
12108 @error{}Unrecognized command: /bar/! p
12109 $ @kbd{echo "foo" | sed -n '/bar/ !p'}
12111 @end example
12113 @item @command{sed} (@samp{t})
12114 @c ---------------------------
12115 @prindex @command{sed} (@samp{t})
12116 Some old systems have @command{sed} that ``forget'' to reset their
12117 @samp{t} flag when starting a new cycle.  For instance on @acronym{MIPS
12118 RISC/OS}, and on @sc{irix} 5.3, if you run the following @command{sed}
12119 script (the line numbers are not actual part of the texts):
12121 @example
12122 s/keep me/kept/g  # a
12123 t end             # b
12124 s/.*/deleted/g    # c
12125 : end             # d
12126 @end example
12128 @noindent
12131 @example
12132 delete me         # 1
12133 delete me         # 2
12134 keep me           # 3
12135 delete me         # 4
12136 @end example
12138 @noindent
12139 you get
12141 @example
12142 deleted
12143 delete me
12144 kept
12145 deleted
12146 @end example
12148 @noindent
12149 instead of
12151 @example
12152 deleted
12153 deleted
12154 kept
12155 deleted
12156 @end example
12158 Why?  When processing 1, a matches, therefore sets the t flag, b jumps to
12159 d, and the output is produced.  When processing line 2, the t flag is
12160 still set (this is the bug).  Line a fails to match, but @command{sed}
12161 is not supposed to clear the t flag when a substitution fails.  Line b
12162 sees that the flag is set, therefore it clears it, and jumps to d, hence
12163 you get @samp{delete me} instead of @samp{deleted}.  When processing 3, t
12164 is clear, a matches, so the flag is set, hence b clears the flags and
12165 jumps.  Finally, since the flag is clear, 4 is processed properly.
12167 There are two things one should remember about @samp{t} in @command{sed}.
12168 Firstly, always remember that @samp{t} jumps if @emph{some} substitution
12169 succeeded, not only the immediately preceding substitution.  Therefore,
12170 always use a fake @samp{t clear; : clear} to reset the t flag where
12171 needed.
12173 Secondly, you cannot rely on @command{sed} to clear the flag at each new
12174 cycle.
12176 One portable implementation of the script above is:
12178 @example
12179 t clear
12180 : clear
12181 s/keep me/kept/g
12182 t end
12183 s/.*/deleted/g
12184 : end
12185 @end example
12187 @item @command{touch}
12188 @c ------------------
12189 @prindex @command{touch}
12190 @cindex timestamp resolution
12191 If you specify the desired timestamp (e.g., with the @option{-r}
12192 option), @command{touch} typically uses the @code{utime} or
12193 @code{utimes} system call, which can result in the same kind of
12194 timestamp truncation problems that @samp{cp -p} has.
12196 On some old @acronym{BSD} systems, @command{touch} or any command that
12197 results in an empty file does not update the timestamps, so use a
12198 command like @command{echo} as a workaround.
12200 @acronym{GNU} @command{touch} 3.16r (and presumably all before that)
12201 fails to work on SunOS 4.1.3 when the empty file is on an
12202 @acronym{NFS}-mounted 4.2 volume.
12204 @end table
12207 @node Limitations of Make
12208 @section Limitations of Make
12209 @prindex @command{make}
12210 @cindex Limitations of @command{make}
12212 @command{make} itself suffers a great number of limitations, only a few
12213 of which are listed here.  First of all, remember that since commands
12214 are executed by the shell, all its weaknesses are inherited@enddots{}
12216 @table @asis
12218 @item @code{$<}
12219 Posix says that the @samp{$<} construct in makefiles can be
12220 used only in inference rules and in the @samp{.DEFAULT} rule; its
12221 meaning in ordinary rules is unspecified.  Solaris 8's @command{make}
12222 for instance will replace it with the empty string.  OpenBSD (3.0 and
12223 later) @command{make} will diagnose these uses and error out.
12225 @item Command execution
12226 Since 1992 Posix has required that @command{make} must invoke
12227 each command with the equivalent of a @samp{sh -c} subshell.  However,
12228 many @command{make} implementations, including BSD make through 2004,
12229 use @samp{sh -e -c} instead, and the @option{-e} option causes the
12230 subshell to exit immediately if a subsidiary simple-command fails.  For
12231 example, the command @samp{touch T; rm -f U} will always attempt to
12232 remove @file{U} with Posix make, but incompatible
12233 @command{make} implementations skip the @command{rm} if the
12234 @command{touch} fails.  One way to work around this is to reword the
12235 affected simple-commands so that they always succeed, e.g., @samp{touch
12236 T || :; rm -f U}.
12238 @item Leading underscore in macro names
12239 Some @command{make}s don't support leading underscores in macro names,
12240 such as on NEWS-OS 4.2R.
12242 @example
12243 $ @kbd{cat Makefile}
12244 _am_include = #
12245 _am_quote =
12246 all:; @@echo this is test
12247 $ @kbd{make}
12248 Make: Must be a separator on rules line 2.  Stop.
12249 $ @kbd{cat Makefile2}
12250 am_include = #
12251 am_quote =
12252 all:; @@echo this is test
12253 $ @kbd{make -f Makefile2}
12254 this is test
12255 @end example
12257 @item Trailing backslash in macro
12258 @c  This has been seen on ia64 hpux 11.20, and on one hppa hpux 10.20,
12259 @c  but another hppa hpux 10.20 didn't have it.  Bob Proulx
12260 @c  <bob@proulx.com> thinks it was in hpux 8.0 too.
12261 On some versions of HP-UX, @command{make} will read multiple newlines
12262 following a backslash, continuing to the next non-empty line.  For
12263 example,
12265 @example
12266 FOO = one \
12268 BAR = two
12270 test:
12271         : FOO is "$(FOO)"
12272         : BAR is "$(BAR)"
12273 @end example
12275 @noindent
12276 shows @code{FOO} equal to @code{one BAR = two}.  Other @command{make}s
12277 sensibly let a backslash continue only to the immediately following
12278 line.
12280 @item Escaped newline in comments
12282 According to Posix, @file{Makefile} comments start with @code{#}
12283 and continue until an unescaped newline is reached.
12285 @example
12286 % @kbd{cat Makefile}
12287 # A = foo \
12288       bar \
12289       baz
12291 all:
12292         @@echo ok
12293 % @kbd{make}   # GNU make
12295 @end example
12297 @noindent
12298 However in Real World this is not always the case.  Some implementations
12299 discards anything from @code{#} up to the end of line, ignoring any
12300 trailing backslash.
12302 @example
12303 % @kbd{pmake}  # BSD make
12304 "Makefile", line 3: Need an operator
12305 Fatal errors encountered -- cannot continue
12306 @end example
12308 @noindent
12309 Therefore, if you want to comment out a multi-line definition, prefix each
12310 line with @code{#}, not only the first.
12312 @example
12313 # A = foo \
12314 #     bar \
12315 #     baz
12316 @end example
12318 @item Long lines.
12320 OSF/1 4.0d's @command{make} cannot process @file{Makefile}s with lines
12321 longer than 38912 bytes.  It exits with a @code{Line too long}
12322 diagnostic.  A later version, Tru64 5.1's @command{make} has been
12323 reported to crash with lines around 20KB.
12325 @item @code{make macro=value} and sub-@command{make}s.
12327 A command-line variable definition such as @code{foo=bar} overrides any
12328 definition of @code{foo} in the @file{Makefile}.  Some @command{make}
12329 implementations (such as @acronym{GNU} @command{make}) will propagate this
12330 override to sub-invocations of @command{make}.  Some other implementation
12331 will not pass the substitution along to sub-@command{make}s.
12333 @example
12334 % @kbd{cat Makefile}
12335 foo = foo
12336 one:
12337         @@echo $(foo)
12338         $(MAKE) two
12339 two:
12340         @@echo $(foo)
12341 % @kbd{make foo=bar}            # GNU make 3.79.1
12343 make two
12344 make[1]: Entering directory `/home/adl'
12346 make[1]: Leaving directory `/home/adl'
12347 % @kbd{pmake foo=bar}           # BSD make
12349 pmake two
12351 @end example
12353 You have a few possibilities if you do want the @code{foo=bar} override
12354 to propagate to sub-@command{make}s.  One is to use the @code{-e}
12355 option, which causes all environment variables to have precedence over
12356 the @file{Makefile} macro definitions, and declare foo as an environment
12357 variable:
12359 @example
12360 % @kbd{env foo=bar make -e}
12361 @end example
12363 The @code{-e} option is propagated to sub-@command{make}s automatically,
12364 and since the environment is inherited between @command{make}
12365 invocations, the @code{foo} macro will be overridden in
12366 sub-@code{make}s as expected.
12368 This syntax (@code{foo=bar make -e}) is portable only when used
12369 outside a @file{Makefile}, for instance from a script or from the
12370 command line.  When run inside a @command{make} rule, GNU
12371 @command{make} 3.80 and prior versions forget to propagate the
12372 @code{-e} option to sub-@command{make}s.
12374 Moreover, using @code{-e} could have unexpected side-effects if your
12375 environment contains some other macros usually defined by the
12376 Makefile.  (See also the note about @code{make -e} and @code{SHELL}
12377 below.)
12379 Another way to propagate overrides to sub-@command{make}s is to do it
12380 manually, from your @file{Makefile}:
12382 @example
12383 foo = foo
12384 one:
12385         @@echo $(foo)
12386         $(MAKE) foo=$(foo) two
12387 two:
12388         @@echo $(foo)
12389 @end example
12391 You need to foresee all macros that a user might want to override if
12392 you do that.
12394 @item The @code{SHELL} macro
12395 @cindex @code{SHELL} and @command{make}
12396 @cindex @command{make} and @code{SHELL}
12398 Posix-compliant @command{make}s internally use the @code{$(SHELL)}
12399 macro to spawn shell processes and execute @file{Makefile} rules.  This
12400 is a builtin macro supplied by @command{make}, but it can be modified
12401 from the @file{Makefile} or a command-line argument.
12403 Not all @command{make}s will define this @code{SHELL} macro.  OSF/Tru64
12404 @command{make} is an example; this implementation will always use
12405 @code{/bin/sh}.  So it's a good idea to always define @code{SHELL} in
12406 your @file{Makefile}s.  If you use Autoconf, do
12408 @example
12409 SHELL = @@SHELL@@
12410 @end example
12412 Do not force @code{SHELL = /bin/sh} because that is not correct
12413 everywhere.  For instance @acronym{DJGPP} lacks @code{/bin/sh}, and when
12414 its GNU @code{make} port sees such a setting it enters a special
12415 emulation mode where features like pipes and redirections are emulated
12416 on top of DOS's @command{command.com}.  Unfortunately this emulation is
12417 incomplete; for instance it does not handle command substitutions.
12418 On @acronym{DJGPP} @code{SHELL} should point to Bash.
12420 Posix-compliant @command{make}s should never acquire the value of
12421 $(SHELL) from the environment, even when @code{make -e} is used
12422 (otherwise, think about what would happen to your rules if
12423 @code{SHELL=/bin/tcsh}).
12425 However not all @command{make} implementations will make this exception.
12426 For instance it's not surprising that OSF/Tru64 @command{make} doesn't
12427 protect @code{SHELL}, since it doesn't use it.
12429 @example
12430 % @kbd{cat Makefile}
12431 SHELL = /bin/sh
12432 FOO = foo
12433 all:
12434         @@echo $(SHELL)
12435         @@echo $(FOO)
12436 % @kbd{env SHELL=/bin/tcsh FOO=bar make -e}   # OSF1 V4.0 Make
12437 /bin/tcsh
12439 % @kbd{env SHELL=/bin/tcsh FOO=bar gmake -e}  # GNU make
12440 /bin/sh
12442 @end example
12444 @item Comments in rules
12445 @cindex Comments in @file{Makefile} rules
12446 @cindex @file{Makefile} rules and comments
12448 Never put comments in a rule.
12450 Some @command{make} treat anything starting with a tab as a command for
12451 the current rule, even if the tab is immediately followed by a @code{#}.
12452 The @command{make} from Tru64 Unix V5.1 is one of them.  The following
12453 @file{Makefile} will run @code{# foo} through the shell.
12455 @example
12456 all:
12457         # foo
12458 @end example
12460 @item The @file{obj/} subdirectory.
12461 @cindex @file{obj/}, subdirectory
12462 @cindex BSD @command{make} and @file{obj/}
12464 Never name one of your subdirectories @file{obj/} if you don't like
12465 surprises.
12467 If an @file{obj/} directory exists, BSD @command{make} will enter it
12468 before reading @file{Makefile}.  Hence the @file{Makefile} in the
12469 current directory will not be read.
12471 @example
12472 % @kbd{cat Makefile}
12473 all:
12474         echo Hello
12475 % @kbd{cat obj/Makefile}
12476 all:
12477         echo World
12478 % @kbd{make}      # GNU make
12479 echo Hello
12480 Hello
12481 % @kbd{pmake}     # BSD make
12482 echo World
12483 World
12484 @end example
12486 @item @code{make -k}
12487 @cindex @code{make -k}
12489 Do not rely on the exit status of @code{make -k}.  Some implementations
12490 reflect whether they encountered an error in their exit status; other
12491 implementations always succeed.
12493 @example
12494 % @kbd{cat Makefile}
12495 all:
12496         false
12497 % @kbd{make -k; echo exit status: $?}    # GNU make
12498 false
12499 make: *** [all] Error 1
12500 exit status: 2
12501 % @kbd{pmake -k; echo exit status: $?}   # BSD make
12502 false
12503 *** Error code 1 (continuing)
12504 exit status: 0
12505 @end example
12507 @item @code{VPATH}
12508 @cindex @code{VPATH}
12510 There is no @code{VPATH} support specified in Posix.  Many
12511 @command{make}s have a form of @code{VPATH} support, but its
12512 implementation is not consistent amongst @command{make}s.
12514 Maybe the best suggestion to give to people who need the @code{VPATH}
12515 feature is to choose a @command{make} implementation and stick to it.
12516 Since the resulting @file{Makefile}s are not portable anyway, better
12517 choose a portable @command{make} (hint, hint).
12519 Here are a couple of known issues with some @code{VPATH}
12520 implementations.
12522 @table @asis
12524 @item @code{VPATH} and double-colon rules
12525 @cindex @code{VPATH} and double-colon rules
12526 @cindex double-colon rules and @code{VPATH}
12528 Any assignment to @code{VPATH} causes Sun @command{make} to only execute
12529 the first set of double-colon rules.  (This comment has been here since
12530 1994 and the context has been lost.  It's probably about SunOS 4.  If
12531 you can reproduce this, please send us a test case for illustration.)
12533 @item @code{$<} not supported in explicit rules
12534 @cindex explicit rules, @code{$<}, and @code{VPATH}
12535 @cindex @code{$<}, explicit rules, and @code{VPATH}
12536 @cindex @code{VPATH}, explicit rules, and @code{$<}
12538 As said elsewhere, using @code{$<} in explicit rules is not portable.
12539 The prerequisite file must be named explicitly in the rule.  If you want
12540 to find the prerequisite via a @code{VPATH} search, you have to code the
12541 whole thing manually.  For instance, using the following pattern:
12543 @example
12544 VPATH = ../pkg/src
12545 foo.c: ifoo.c
12546         cp `test -f ifoo.c || echo ../pkg/src/`ifoo.c foo.c
12547 @end example
12549 @item Automatic rule rewriting
12550 @cindex @code{VPATH} and automatic rule rewriting
12551 @cindex automatic rule rewriting and @code{VPATH}
12553 Some @command{make} implementations, such as SunOS @command{make} or
12554 OSF1/Tru64 @command{make}, will search prerequisites in @code{VPATH} and
12555 rewrite all their occurrences in the rule appropriately.
12557 For instance
12559 @example
12560 VPATH = ../pkg/src
12561 foo.c: ifoo.c
12562         cp ifoo.c foo.c
12563 @end example
12565 @noindent
12566 would execute @code{cp ../pkg/src/ifoo.c foo.c} if @file{ifoo.c} was
12567 found in @file{../pkg/src}.  That sounds great.
12569 However, for the sake of other @command{make} implementations, we can't
12570 rely on this, and we have to search @code{VPATH} manually:
12572 @example
12573 VPATH = ../pkg/src
12574 foo.c: ifoo.c
12575         cp `test -f ifoo.c || echo ../pkg/src/`ifoo.c foo.c
12576 @end example
12578 @noindent
12579 However the "prerequisite rewriting" still applies here.  So if
12580 @file{ifoo.c} is in @file{../pkg/src}, SunOS @command{make} and OSF1/Tru64
12581 @command{make} will execute
12583 @example
12584 @code{cp `test -f ../pkg/src/ifoo.c || echo ../pkg/src/`ifoo.c foo.c}
12585 @end example
12587 @noindent
12588 which reduces to
12590 @example
12591 cp ifoo.c foo.c
12592 @end example
12594 @noindent
12595 and thus fails.  Oops.
12597 One workaround is to make sure that ifoo.c never appears as a plain word
12598 in the rule.  For instance these three rules would be safe.
12600 @example
12601 VPATH = ../pkg/src
12602 foo.c: ifoo.c
12603         cp `test -f ./ifoo.c || echo ../pkg/src/`ifoo.c foo.c
12604 foo2.c: ifoo2.c
12605         cp `test -f 'ifoo2.c' || echo ../pkg/src/`ifoo2.c foo2.c
12606 foo3.c: ifoo3.c
12607         cp `test -f "ifoo3.c" || echo ../pkg/src/`ifoo3.c foo3.c
12608 @end example
12610 Things get worse when your prerequisites are in a macro.
12612 @example
12613 VPATH = ../pkg/src
12614 HEADERS = foo.h foo2.h foo3.h
12615 install-HEADERS: $(HEADERS)
12616         for i in $(HEADERS); do \
12617           $(INSTALL) -m 644 `test -f $$i || echo ../pkg/src/`$$i \
12618             $(DESTDIR)$(includedir)/$$i; \
12619         done
12620 @end example
12622 The above @code{install-HEADERS} rule is not SunOS-proof because @code{for
12623 i in $(HEADERS);} will be expanded as @code{for i in foo.h foo2.h foo3.h;}
12624 where @code{foo.h} and @code{foo2.h} are plain words and are hence
12625 subject to @code{VPATH} adjustments.
12627 If the three files are in @file{../pkg/src}, the rule is run as:
12629 @example
12630 for i in ../pkg/src/foo.h ../pkg/src/foo2.h foo3.h; do \
12631   install -m 644 `test -f $i || echo ../pkg/src/`$i \
12632      /usr/local/include/$i; \
12633 done
12634 @end example
12636 where the two first @command{install} calls will fail.  For instance,
12637 consider the @code{foo.h} installation:
12639 @example
12640 install -m 644 `test -f ../pkg/src/foo.h || echo ../pkg/src/`../pkg/src/foo.h \
12641   /usr/local/include/../pkg/src/foo.h;
12642 @end example
12643 @noindent
12644 It reduces to:
12646 @example
12647 install -m 644 ../pkg/src/foo.h /usr/local/include/../pkg/src/foo.h;
12648 @end example
12650 Note that the manual @code{VPATH} search did not cause any problems here;
12651 however this command installs @file{foo.h} in an incorrect directory.
12653 Trying to quote @code{$(HEADERS)} in some way, as we did for
12654 @code{foo.c} a few @file{Makefile}s ago, does not help:
12656 @example
12657 install-HEADERS: $(HEADERS)
12658         headers='$(HEADERS)'; for i in $$headers; do \
12659           $(INSTALL) -m 644 `test -f $$i || echo ../pkg/src/`$$i \
12660             $(DESTDIR)$(includedir)/$$i; \
12661         done
12662 @end example
12664 Indeed, @code{headers='$(HEADERS)'} expands to @code{headers='foo.h
12665 foo2.h foo3.h'} where @code{foo2.h} is still a plain word.  (Aside: the
12666 @code{headers='$(HEADERS)'; for i in $$headers;} idiom is a good
12667 idea if @code{$(HEADERS)} can be empty, because some shells diagnose a
12668 syntax error on @code{for i in;}.)
12670 One workaround is to strip this unwanted @file{../pkg/src/} prefix manually:
12671 @example
12672 VPATH = ../pkg/src
12673 HEADERS = foo.h foo2.h foo3.h
12674 install-HEADERS: $(HEADERS)
12675         headers='$(HEADERS)'; for i in $$headers; do \
12676           i=`expr "$$i" : '../pkg/src/\(.*\)'`;
12677           $(INSTALL) -m 644 `test -f $$i || echo ../pkg/src/`$$i \
12678             $(DESTDIR)$(includedir)/$$i; \
12679         done
12680 @end example
12682 Automake does something similar.  However the above hack works only if
12683 the files listed in @code{HEADERS} are in the current directory or a
12684 subdirectory; they should not be in an enclosing directory.  If we had
12685 @code{HEADERS = ../foo.h}, the above fragment would fail in a VPATH
12686 build with OSF1/Tru64 @command{make}.  The reason is that not only does
12687 OSF1/Tru64 @command{make} rewrite dependencies, but it also simplifies
12688 them.  Hence @code{../foo.h} will become @code{../pkg/foo.h} instead of
12689 @code{../pkg/src/../foo.h}.  This obviously defeats any attempt to strip
12690 a leading @file{../pkg/src/} component.
12692 The following example makes the behavior of OSF1/Tru64 @command{make}
12693 more apparent.
12694 @example
12695 % cat Makefile
12696 VPATH = sub
12697 all: ../foo
12698         echo ../foo
12699 % ls
12700 Makefile foo
12701 % make
12702 echo foo
12704 @end example
12705 @noindent
12706 Dependency @file{../foo} was found in @file{sub/../foo}, but OSF1/Tru64
12707 @command{make} simplified it as @file{foo}.  (Note that the @file{sub/}
12708 directory does not even exist, this just means that the simplification
12709 occurred before the file was checked for.)
12711 For the records here is how SunOS @command{make} behaves on this
12712 very same example.
12713 @example
12714 % make
12715 make: Fatal error: Don't know how to make target `../foo'
12716 % mkdir sub
12717 % make
12718 echo sub/../foo
12719 sub/../foo
12720 @end example
12723 @item OSF/Tru64 @command{make} creates prerequisite directories magically
12724 @cindex @code{VPATH} and prerequisite directories
12725 @cindex prerequisite directories and @code{VPATH}
12727 When a prerequisite is a sub-directory of @code{VPATH}, Tru64
12728 @command{make} will create it in the current directory.
12730 @example
12731 % @kbd{mkdir -p foo/bar build}
12732 % @kbd{cd build}
12733 % @kbd{cat >Makefile <<END
12734 VPATH = ..
12735 all: foo/bar
12736 END}
12737 % @kbd{make}
12738 mkdir foo
12739 mkdir foo/bar
12740 @end example
12742 This can yield unexpected results if a rule uses a manual @code{VPATH}
12743 search as presented before.
12745 @example
12746 VPATH = ..
12747 all : foo/bar
12748         command `test -d foo/bar || echo ../`foo/bar
12749 @end example
12751 The above @command{command} will be run on the empty @file{foo/bar}
12752 directory that was created in the current directory.
12754 @item target lookup
12755 @cindex @code{VPATH}, resolving target pathnames
12757 @acronym{GNU} @command{make} uses a rather complex algorithm to decide when it
12758 should use files found via a @code{VPATH} search.  @xref{Search
12759 Algorithm,, How Directory Searches are Performed, make, The @acronym{GNU} Make
12760 Manual}.
12762 If a target needs to be rebuilt, @acronym{GNU} @command{make} discards the
12763 file name found during the @code{VPATH} search for this target, and
12764 builds the file locally using the file name given in the @file{Makefile}.
12765 If a target does not need to be rebuilt, @acronym{GNU} @command{make} uses the
12766 file name found during the @code{VPATH} search.
12768 Other @command{make} implementations, like NetBSD @command{make}, are
12769 easier to describe: the file name found during the @code{VPATH} search
12770 will be used whether the target needs to be rebuilt or not.  Therefore
12771 new files are created locally, but existing files are updated at their
12772 @code{VPATH} location.
12774 OpenBSD and FreeBSD @command{make}s, however, will never perform a
12775 @code{VPATH} search for a dependency which has an explicit rule.
12776 This is extremely annoying.
12778 When attempting a @code{VPATH} build for an autoconfiscated package
12779 (e.g,, @code{mkdir build && cd build && ../configure}), this means the
12780 @acronym{GNU}
12781 @command{make} will build everything locally in the @file{build}
12782 directory, while BSD @command{make} will build new files locally and
12783 update existing files in the source directory.
12785 @example
12786 % @kbd{cat Makefile}
12787 VPATH = ..
12788 all: foo.x bar.x
12789 foo.x bar.x: newer.x
12790         @@echo Building $@@
12791 % @kbd{touch ../bar.x}
12792 % @kbd{touch ../newer.x}
12793 % @kbd{make}        # GNU make
12794 Building foo.x
12795 Building bar.x
12796 % @kbd{pmake}       # NetBSD make
12797 Building foo.x
12798 Building ../bar.x
12799 % @kbd{fmake}       # FreeBSD make, OpenBSD make
12800 Building foo.x
12801 Building bar.x
12802 % @kbd{tmake}       # Tru64 make
12803 Building foo.x
12804 Building bar.x
12805 % @kbd{touch ../bar.x}
12806 % @kbd{make}        # GNU make
12807 Building foo.x
12808 % @kbd{pmake}       # NetBSD make
12809 Building foo.x
12810 % @kbd{fmake}       # FreeBSD make, OpenBSD make
12811 Building foo.x
12812 Building bar.x
12813 % @kbd{tmake}       # Tru64 make
12814 Building foo.x
12815 Building bar.x
12816 @end example
12818 Note how NetBSD @command{make} updates @file{../bar.x} in its VPATH
12819 location, and how FreeBSD, OpenBSD, and Tru64 @command{make} always
12820 update @file{bar.x}, even when @file{../bar.x} is up to date.
12822 Another point worth mentioning is that once @acronym{GNU} @command{make} has
12823 decided to ignore a @code{VPATH} file name (e.g., it ignored
12824 @file{../bar.x} in the above example) it will continue to ignore it when
12825 the target occurs as a prerequisite of another rule.
12827 The following example shows that @acronym{GNU} @command{make} does not look up
12828 @file{bar.x} in @code{VPATH} before performing the @code{.x.y} rule,
12829 because it ignored the @code{VPATH} result of @file{bar.x} while running
12830 the @code{bar.x: newer.x} rule.
12832 @example
12833 % @kbd{cat Makefile}
12834 VPATH = ..
12835 all: bar.y
12836 bar.x: newer.x
12837         @@echo Building $@@
12838 .SUFFIXES: .x .y
12839 .x.y:
12840         cp $< $@@
12841 % @kbd{touch ../bar.x}
12842 % @kbd{touch ../newer.x}
12843 % @kbd{make}        # GNU make
12844 Building bar.x
12845 cp bar.x bar.y
12846 cp: cannot stat `bar.x': No such file or directory
12847 make: *** [bar.y] Error 1
12848 % @kbd{pmake}       # NetBSD make
12849 Building ../bar.x
12850 cp ../bar.x bar.y
12851 % @kbd{rm bar.y}
12852 % @kbd{fmake}       # FreeBSD make, OpenBSD make
12853 echo Building bar.x
12854 cp bar.x bar.y
12855 cp: cannot stat `bar.x': No such file or directory
12856 *** Error code 1
12857 % @kbd{tmake}       # Tru64 make
12858 Building bar.x
12859 cp: bar.x: No such file or directory
12860 *** Exit 1
12861 @end example
12863 Note that if you drop away the command from the @code{bar.x: newer.x}
12864 rule, @acronym{GNU} @command{make} will magically start to work: it
12865 knows that @code{bar.x} hasn't been updated, therefore it doesn't
12866 discard the result from @code{VPATH} (@file{../bar.x}) in succeeding
12867 uses.  Tru64 will also work, but FreeBSD and OpenBSD still don't.
12869 @example
12870 % @kbd{cat Makefile}
12871 VPATH = ..
12872 all: bar.y
12873 bar.x: newer.x
12874 .SUFFIXES: .x .y
12875 .x.y:
12876         cp $< $@@
12877 % @kbd{touch ../bar.x}
12878 % @kbd{touch ../newer.x}
12879 % @kbd{make}        # GNU make
12880 cp ../bar.x bar.y
12881 % @kbd{rm bar.y}
12882 % @kbd{pmake}       # NetBSD make
12883 cp ../bar.x bar.y
12884 % @kbd{rm bar.y}
12885 % @kbd{fmake}       # FreeBSD make, OpenBSD make
12886 cp bar.x bar.y
12887 cp: cannot stat `bar.x': No such file or directory
12888 *** Error code 1
12889 % @kbd{tmake}       # True64 make
12890 cp ../bar.x bar.y
12891 @end example
12893 It seems the sole solution that would please every @command{make}
12894 implementation is to never rely on @code{VPATH} searches for targets.
12895 In other words, @code{VPATH} should be reserved to unbuilt sources.
12897 @end table
12898 @c end item about VPATH
12900 @item Single Suffix Rules and Separated Dependencies
12901 @cindex Single Suffix Inference Rule
12902 @cindex Rule, Single Suffix Inference
12903 A @dfn{Single Suffix Rule} is basically a usual suffix (inference) rule
12904 (@samp{.from.to:}), but which @emph{destination} suffix is empty
12905 (@samp{.from:}).
12907 @cindex Separated Dependencies
12908 @dfn{Separated dependencies} simply refers to listing the prerequisite
12909 of a target, without defining a rule.  Usually one can list on the one
12910 hand side, the rules, and on the other hand side, the dependencies.
12912 Solaris @command{make} does not support separated dependencies for
12913 targets defined by single suffix rules:
12915 @example
12916 $ @kbd{cat Makefile}
12917 .SUFFIXES: .in
12918 foo: foo.in
12919 .in:
12920         cp $< $@
12921 $ @kbd{touch foo.in}
12922 $ @kbd{make}
12923 $ @kbd{ls}
12924 Makefile  foo.in
12925 @end example
12927 @noindent
12928 while @acronym{GNU} Make does:
12930 @example
12931 $ @kbd{gmake}
12932 cp foo.in foo
12933 $ @kbd{ls}
12934 Makefile  foo       foo.in
12935 @end example
12937 Note it works without the @samp{foo: foo.in} dependency.
12939 @example
12940 $ @kbd{cat Makefile}
12941 .SUFFIXES: .in
12942 .in:
12943         cp $< $@
12944 $ @kbd{make foo}
12945 cp foo.in foo
12946 @end example
12948 @noindent
12949 and it works with double suffix inference rules:
12951 @example
12952 $ @kbd{cat Makefile}
12953 foo.out: foo.in
12954 .SUFFIXES: .in .out
12955 .in.out:
12956         cp $< $@
12957 $ @kbd{make}
12958 cp foo.in foo.out
12959 @end example
12961 As a result, in such a case, you have to write target rules.
12963 @item Timestamp Resolution
12964 @cindex timestamp resolution
12965 Traditionally, file timestamps had 1-second resolution, and
12966 @command{make} used those timestamps to determine whether one file was
12967 newer than the other.  However, many modern filesystems have
12968 timestamps with 1-nanosecond resolution.  Some @command{make}
12969 implementations look at the entire timestamp; others ignore the
12970 fractional part, which can lead to incorrect results.  Normally this
12971 is not a problem, but in some extreme cases you may need to use tricks
12972 like @samp{sleep 1} to work around timestamp truncation bugs.
12974 Commands like @samp{cp -p} and @samp{touch -r} typically do not copy
12975 file timestamps to their full resolutions (@pxref{Limitations of Usual
12976 Tools}).  Hence you should be wary of rules like this:
12978 @example
12979 dest: src
12980         cp -p src dest
12981 @end example
12983 as @file{dest} will often appear to be older than @file{src} after the
12984 timestamp is truncated, and this can cause @command{make} to do
12985 needless rework the next time it is invoked.  To work around this
12986 problem, you can use a timestamp file, e.g.:
12988 @example
12989 dest-stamp: src
12990         cp -p src dest
12991         date >dest-stamp
12992 @end example
12994 @end table
12999 @c ================================================== Manual Configuration
13001 @node Manual Configuration
13002 @chapter Manual Configuration
13004 A few kinds of features can't be guessed automatically by running test
13005 programs.  For example, the details of the object-file format, or
13006 special options that need to be passed to the compiler or linker.  You
13007 can check for such features using ad-hoc means, such as having
13008 @command{configure} check the output of the @code{uname} program, or
13009 looking for libraries that are unique to particular systems.  However,
13010 Autoconf provides a uniform method for handling unguessable features.
13012 @menu
13013 * Specifying Names::            Specifying the system type
13014 * Canonicalizing::              Getting the canonical system type
13015 * Using System Type::           What to do with the system type
13016 @end menu
13018 @node Specifying Names
13019 @section Specifying the System Type
13020 @cindex System type
13022 Like other @acronym{GNU} @command{configure} scripts, Autoconf-generated
13023 @command{configure} scripts can make decisions based on a canonical name
13024 for the system type, which has the form:
13025 @samp{@var{cpu}-@var{vendor}-@var{os}}, where @var{os} can be
13026 @samp{@var{system}} or @samp{@var{kernel}-@var{system}}
13028 @command{configure} can usually guess the canonical name for the type of
13029 system it's running on.  To do so it runs a script called
13030 @command{config.guess}, which infers the name using the @code{uname}
13031 command or symbols predefined by the C preprocessor.
13033 Alternately, the user can specify the system type with command line
13034 arguments to @command{configure}.  Doing so is necessary when
13035 cross-compiling.  In the most complex case of cross-compiling, three
13036 system types are involved.  The options to specify them are:
13038 @table @option
13039 @item --build=@var{build-type}
13040 the type of system on which the package is being configured and
13041 compiled.  It defaults to the result of running @command{config.guess}.
13043 @item --host=@var{host-type}
13044 the type of system on which the package will run.  By default it is the
13045 same as the build machine.  Specifying it enables the cross-compilation
13046 mode.
13048 @item --target=@var{target-type}
13049 the type of system for which any compiler tools in the package will
13050 produce code (rarely needed).  By default, it is the same as host.
13051 @end table
13053 If you mean to override the result of @command{config.guess}, use
13054 @option{--build}, not @option{--host}, since the latter enables
13055 cross-compilation.  For historical reasons, passing @option{--host} also
13056 changes the build type.  Therefore, whenever you specify @code{--host},
13057 be sure to specify @code{--build} too; this will be fixed in the
13058 future.  So, to enter cross-compilation mode, use a command like this
13060 @example
13061 ./configure --build=i686-pc-linux-gnu --host=m68k-coff
13062 @end example
13064 @noindent
13065 Note that if you do not specify @option{--host}, @command{configure} will
13066 fail if it can't run the code generated by the specified compiler.  For
13067 example, configuring as follows will fail:
13069 @example
13070 ./configure CC=m68k-coff-gcc
13071 @end example
13073 In the future, when cross-compiling Autoconf will @emph{not}
13074 accept tools (compilers, linkers, assemblers) whose name is not
13075 prefixed with the host type.  The only case when this may be
13076 useful is when you really are not cross-compiling, but only
13077 building for a least-common-denominator architecture: an example
13078 is building for @code{i386-pc-linux-gnu} while running on an
13079 @code{i686-pc-linux-gnu} architecture.  In this case, some particular
13080 pairs might be similar enough to let you get away with the system
13081 compilers, but in general the compiler might make bogus assumptions
13082 on the host: if you know what you are doing, please create symbolic
13083 links from the host compiler to the build compiler.
13085 @cindex @command{config.sub}
13086 @command{configure} recognizes short aliases for many system types; for
13087 example, @samp{decstation} can be used instead of
13088 @samp{mips-dec-ultrix4.2}.  @command{configure} runs a script called
13089 @command{config.sub} to canonicalize system type aliases.
13091 This section deliberately omits the description of the obsolete
13092 interface; see @ref{Hosts and Cross-Compilation}.
13095 @node Canonicalizing
13096 @section Getting the Canonical System Type
13097 @cindex System type
13098 @cindex Canonical system type
13100 The following macros make the system type available to @command{configure}
13101 scripts.
13103 @ovindex build_alias
13104 @ovindex host_alias
13105 @ovindex target_alias
13107 The variables @samp{build_alias}, @samp{host_alias}, and
13108 @samp{target_alias} are always exactly the arguments of @option{--build},
13109 @option{--host}, and @option{--target}; in particular, they are left empty
13110 if the user did not use them, even if the corresponding
13111 @code{AC_CANONICAL} macro was run.  Any configure script may use these
13112 variables anywhere.  These are the variables that should be used when in
13113 interaction with the user.
13115 If you need to recognize some special environments based on their system
13116 type, run the following macros to get canonical system names.  These
13117 variables are not set before the macro call.
13119 If you use these macros, you must distribute @command{config.guess} and
13120 @command{config.sub} along with your source code.  @xref{Output}, for
13121 information about the @code{AC_CONFIG_AUX_DIR} macro which you can use
13122 to control in which directory @command{configure} looks for those scripts.
13125 @defmac AC_CANONICAL_BUILD
13126 @acindex{CANONICAL_BUILD}
13127 @ovindex build
13128 @ovindex build_cpu
13129 @ovindex build_vendor
13130 @ovindex build_os
13131 Compute the canonical build-system type variable, @code{build}, and its
13132 three individual parts @code{build_cpu}, @code{build_vendor}, and
13133 @code{build_os}.
13135 If @option{--build} was specified, then @code{build} is the
13136 canonicalization of @code{build_alias} by @command{config.sub},
13137 otherwise it is determined by the shell script @command{config.guess}.
13138 @end defmac
13140 @defmac AC_CANONICAL_HOST
13141 @acindex{CANONICAL_HOST}
13142 @ovindex host
13143 @ovindex host_cpu
13144 @ovindex host_vendor
13145 @ovindex host_os
13146 Compute the canonical host-system type variable, @code{host}, and its
13147 three individual parts @code{host_cpu}, @code{host_vendor}, and
13148 @code{host_os}.
13150 If @option{--host} was specified, then @code{host} is the
13151 canonicalization of @code{host_alias} by @command{config.sub},
13152 otherwise it defaults to @code{build}.
13153 @end defmac
13155 @defmac AC_CANONICAL_TARGET
13156 @acindex{CANONICAL_TARGET}
13157 @ovindex target
13158 @ovindex target_cpu
13159 @ovindex target_vendor
13160 @ovindex target_os
13161 Compute the canonical target-system type variable, @code{target}, and its
13162 three individual parts @code{target_cpu}, @code{target_vendor}, and
13163 @code{target_os}.
13165 If @option{--target} was specified, then @code{target} is the
13166 canonicalization of @code{target_alias} by @command{config.sub},
13167 otherwise it defaults to @code{host}.
13168 @end defmac
13170 Note that there can be artifacts due to the backward compatibility
13171 code.  See @xref{Hosts and Cross-Compilation}, for more.
13173 @node Using System Type
13174 @section Using the System Type
13176 In @file{configure.ac} the system type is generally used by one or more
13177 @code{case} statements to select system-specifics.  Shell wildcards can
13178 be used to match a group of system types.
13180 For example, an extra assembler code object file could be chosen, giving
13181 access to a CPU cycle counter register.  @code{$(CYCLE_OBJ)} in the
13182 following would be used in a @file{Makefile} to add the object to a
13183 program or library.
13185 @example
13186 case $host in
13187   alpha*-*-*) CYCLE_OBJ=rpcc.o ;;
13188   i?86-*-*)   CYCLE_OBJ=rdtsc.o ;;
13189   *)          CYCLE_OBJ= ;;
13190 esac
13191 AC_SUBST(CYCLE_OBJ)
13192 @end example
13194 @code{AC_CONFIG_LINKS} (@pxref{Configuration Links}) is another good way
13195 to select variant source files, for example optimized code for some
13196 CPUs.  The configured CPU type doesn't always indicate exact CPU types,
13197 so some run-time capability checks may be necessary too.
13199 @example
13200 case $host in
13201   alpha*-*-*)   AC_CONFIG_LINKS(dither.c:alpha/dither.c) ;;
13202   powerpc*-*-*) AC_CONFIG_LINKS(dither.c:powerpc/dither.c) ;;
13203   *-*-*)        AC_CONFIG_LINKS(dither.c:generic/dither.c) ;;
13204 esac
13205 @end example
13207 The host system type can also be used to find cross-compilation tools
13208 with @code{AC_CHECK_TOOL} (@pxref{Generic Programs}).
13210 The above examples all show @samp{$host}, since this is where the code
13211 is going to run.  Only rarely is it necessary to test @samp{$build}
13212 (which is where the build is being done).
13214 Whenever you're tempted to use @samp{$host} it's worth considering
13215 whether some sort of probe would be better.  New system types come along
13216 periodically or previously missing features are added.  Well-written
13217 probes can adapt themselves to such things, but hard-coded lists of
13218 names won't.  Here are some guidelines,
13220 @itemize @bullet
13221 @item
13222 Availability of libraries and library functions should always be checked
13223 by probing.
13224 @item
13225 Variant behaviour of system calls is best identified with runtime tests
13226 if possible, but bug workarounds or obscure difficulties might have to
13227 be driven from @samp{$host}.
13228 @item
13229 Assembler code is inevitably highly CPU-specific and is best selected
13230 according to @samp{$host_cpu}.
13231 @item
13232 Assembler variations like underscore prefix on globals or ELF versus
13233 COFF type directives are however best determined by probing, perhaps
13234 even examining the compiler output.
13235 @end itemize
13237 @samp{$target} is for use by a package creating a compiler or similar.
13238 For ordinary packages it's meaningless and should not be used.  It
13239 indicates what the created compiler should generate code for, if it can
13240 cross-compile.  @samp{$target} generally selects various hard-coded CPU
13241 and system conventions, since usually the compiler or tools under
13242 construction will themselves determine how the target will work.
13245 @c ===================================================== Site Configuration.
13247 @node Site Configuration
13248 @chapter Site Configuration
13250 @command{configure} scripts support several kinds of local configuration
13251 decisions.  There are ways for users to specify where external software
13252 packages are, include or exclude optional features, install programs
13253 under modified names, and set default values for @command{configure}
13254 options.
13256 @menu
13257 * External Software::           Working with other optional software
13258 * Package Options::             Selecting optional features
13259 * Pretty Help Strings::         Formatting help string
13260 * Site Details::                Configuring site details
13261 * Transforming Names::          Changing program names when installing
13262 * Site Defaults::               Giving @command{configure} local defaults
13263 @end menu
13265 @node External Software
13266 @section Working With External Software
13267 @cindex External software
13269 Some packages require, or can optionally use, other software packages
13270 that are already installed.  The user can give @command{configure}
13271 command line options to specify which such external software to use.
13272 The options have one of these forms:
13274 @c FIXME: Can't use @ovar here, Texinfo 4.0 goes lunatic and emits something
13275 @c awful.
13276 @example
13277 --with-@var{package}[=@var{arg}]
13278 --without-@var{package}
13279 @end example
13281 For example, @option{--with-gnu-ld} means work with the @acronym{GNU} linker
13282 instead of some other linker.  @option{--with-x} means work with The X
13283 Window System.
13285 The user can give an argument by following the package name with
13286 @samp{=} and the argument.  Giving an argument of @samp{no} is for
13287 packages that are used by default; it says to @emph{not} use the
13288 package.  An argument that is neither @samp{yes} nor @samp{no} could
13289 include a name or number of a version of the other package, to specify
13290 more precisely which other package this program is supposed to work
13291 with.  If no argument is given, it defaults to @samp{yes}.
13292 @option{--without-@var{package}} is equivalent to
13293 @option{--with-@var{package}=no}.
13295 @command{configure} scripts do not complain about
13296 @option{--with-@var{package}} options that they do not support.  This
13297 behavior permits configuring a source tree containing multiple packages
13298 with a top-level @command{configure} script when the packages support
13299 different options, without spurious error messages about options that
13300 some of the packages support.  An unfortunate side effect is that option
13301 spelling errors are not diagnosed.  No better approach to this problem
13302 has been suggested so far.
13304 For each external software package that may be used, @file{configure.ac}
13305 should call @code{AC_ARG_WITH} to detect whether the @command{configure}
13306 user asked to use it.  Whether each package is used or not by default,
13307 and which arguments are valid, is up to you.
13309 @defmac AC_ARG_WITH (@var{package}, @var{help-string}, @ovar{action-if-given}, @ovar{action-if-not-given})
13310 @acindex{ARG_WITH}
13311 If the user gave @command{configure} the option @option{--with-@var{package}}
13312 or @option{--without-@var{package}}, run shell commands
13313 @var{action-if-given}.  If neither option was given, run shell commands
13314 @var{action-if-not-given}.  The name @var{package} indicates another
13315 software package that this program should work with.  It should consist
13316 only of alphanumeric characters and dashes.
13318 The option's argument is available to the shell commands
13319 @var{action-if-given} in the shell variable @code{withval}, which is
13320 actually just the value of the shell variable @code{with_@var{package}},
13321 with any @option{-} characters changed into @samp{_}.  You may use that
13322 variable instead, if you wish.
13324 The argument @var{help-string} is a description of the option that
13325 looks like this:
13326 @example
13327   --with-readline         support fancy command line editing
13328 @end example
13330 @noindent
13331 @var{help-string} may be more than one line long, if more detail is
13332 needed.  Just make sure the columns line up in @samp{configure
13333 --help}.  Avoid tabs in the help string.  You'll need to enclose the
13334 help string in @samp{[} and @samp{]} in order to produce the leading
13335 spaces.
13337 You should format your @var{help-string} with the macro
13338 @code{AS_HELP_STRING} (@pxref{Pretty Help Strings}).
13340 The following example shows how to use the @code{AC_ARG_WITH} macro in
13341 a common situation.  You want to let the user decide whether to enable
13342 support for an external library (e.g., the readline library); if the user
13343 specified neither @option{--with-readline} nor @option{--without-readline},
13344 you want to enable support for readline only if the library is available
13345 on the system.
13347 @c FIXME: Remove AS_IF when the problem of AC_REQUIRE within `if' is solved.
13348 @example
13349 AC_ARG_WITH(readline,
13350   [AS_HELP_STRING(--with-readline,
13351     [support fancy command line editing @@<:@@default=check@@:>@@])],
13352   [],
13353   with_readline=check)
13355 LIBREADLINE=
13356 AS_IF([test "x$with_readline" != xno],
13357   [AC_CHECK_LIB(readline, main,
13358     [AC_SUBST(LIBREADLINE, "-lreadline -lncurses")
13359      AC_DEFINE(HAVE_LIBREADLINE, 1, [Define if you have libreadline])
13360     ],
13361     [if test "x$with_readline" != xcheck; then
13362        AC_MSG_FAILURE([--with-readline was given, but test for readline failed])
13363      fi
13364     ], -lncurses)])
13365 @end example
13367 The next example shows how to use @code{AC_ARG_WITH} to give the user the
13368 possibility to enable support for the readline library, in case it is still
13369 experimental and not well tested, and is therefore disabled by default.
13371 @c FIXME: Remove AS_IF when the problem of AC_REQUIRE within `if' is solved.
13372 @example
13373 AC_ARG_WITH(readline,
13374   [AS_HELP_STRING(--with-readline,
13375     [enable experimental support for readline])],
13376   [],
13377   with_readline=no)
13379 LIBREADLINE=
13380 AS_IF([test "x$with_readline" != xno],
13381   [AC_CHECK_LIB(readline, main,
13382     [AC_SUBST(LIBREADLINE, "-lreadline -lncurses")
13383      AC_DEFINE(HAVE_LIBREADLINE, 1, [Define if you have libreadline])
13384     ],
13385     [AC_MSG_FAILURE([--with-readline was given, but test for readline failed])],
13386     -lncurses)])
13387 @end example
13389 The last example shows how to use @code{AC_ARG_WITH} to give the user the
13390 possibility to disable support for the readline library, given that it is
13391 an important feature and that it should be enabled by default.
13393 @c FIXME: Remove AS_IF when the problem of AC_REQUIRE within `if' is solved.
13394 @example
13395 AC_ARG_WITH(readline,
13396   [AS_HELP_STRING(--without-readline,
13397     [disable support for readline])],
13398   [],
13399   with_readline=yes)
13401 LIBREADLINE=
13402 AS_IF([test "x$with_readline" != xno],
13403   [AC_CHECK_LIB(readline, main,
13404     [AC_SUBST(LIBREADLINE, "-lreadline -lncurses")
13405      AC_DEFINE(HAVE_LIBREADLINE, 1, [Define if you have libreadline])
13406     ],
13407     [AC_MSG_FAILURE([test for readline failed, use --without-readline if you want to force readline support off])],
13408     -lncurses)])
13409 @end example
13411 These three examples can be easily adapted to the case where
13412 @code{AC_ARG_ENABLE} should be preferred to @code{AC_ARG_WITH} (see
13413 @ref{Package Options}).
13414 @end defmac
13416 @defmac AC_WITH (@var{package}, @var{action-if-given}, @ovar{action-if-not-given})
13417 @acindex{WITH}
13418 This is an obsolete version of @code{AC_ARG_WITH} that does not
13419 support providing a help string.
13420 @end defmac
13422 @node Package Options
13423 @section Choosing Package Options
13424 @cindex Package options
13425 @cindex Options, package
13427 If a software package has optional compile-time features, the user can
13428 give @command{configure} command line options to specify whether to
13429 compile them.  The options have one of these forms:
13431 @c FIXME: Can't use @ovar here, Texinfo 4.0 goes lunatic and emits something
13432 @c awful.
13433 @example
13434 --enable-@var{feature}[=@var{arg}]
13435 --disable-@var{feature}
13436 @end example
13438 These options allow users to choose which optional features to build and
13439 install.  @option{--enable-@var{feature}} options should never make a
13440 feature behave differently or cause one feature to replace another.
13441 They should only cause parts of the program to be built rather than left
13442 out.
13444 The user can give an argument by following the feature name with
13445 @samp{=} and the argument.  Giving an argument of @samp{no} requests
13446 that the feature @emph{not} be made available.  A feature with an
13447 argument looks like @option{--enable-debug=stabs}.  If no argument is
13448 given, it defaults to @samp{yes}.  @option{--disable-@var{feature}} is
13449 equivalent to @option{--enable-@var{feature}=no}.
13451 @command{configure} scripts do not complain about
13452 @option{--enable-@var{feature}} options that they do not support.
13453 This behavior permits configuring a source tree containing multiple
13454 packages with a top-level @command{configure} script when the packages
13455 support different options, without spurious error messages about options
13456 that some of the packages support.
13457 An unfortunate side effect is that option spelling errors are not diagnosed.
13458 No better approach to this problem has been suggested so far.
13460 For each optional feature, @file{configure.ac} should call
13461 @code{AC_ARG_ENABLE} to detect whether the @command{configure} user asked
13462 to include it.  Whether each feature is included or not by default, and
13463 which arguments are valid, is up to you.
13465 @defmac AC_ARG_ENABLE (@var{feature}, @var{help-string}, @ovar{action-if-given}, @ovar{action-if-not-given})
13466 @acindex{ARG_ENABLE}
13467 If the user gave @command{configure} the option
13468 @option{--enable-@var{feature}} or @option{--disable-@var{feature}}, run
13469 shell commands @var{action-if-given}.  If neither option was given, run
13470 shell commands @var{action-if-not-given}.  The name @var{feature}
13471 indicates an optional user-level facility.  It should consist only of
13472 alphanumeric characters and dashes.
13474 The option's argument is available to the shell commands
13475 @var{action-if-given} in the shell variable @code{enableval}, which is
13476 actually just the value of the shell variable
13477 @code{enable_@var{feature}}, with any @option{-} characters changed into
13478 @samp{_}.  You may use that variable instead, if you wish.  The
13479 @var{help-string} argument is like that of @code{AC_ARG_WITH}
13480 (@pxref{External Software}).
13482 You should format your @var{help-string} with the macro
13483 @code{AS_HELP_STRING} (@pxref{Pretty Help Strings}).
13485 See the examples suggested with the definition of @code{AC_ARG_WITH}
13486 (@pxref{External Software}) to get an idea of possible utilizations of
13487 @code{AC_ARG_ENABLE}.
13488 @end defmac
13490 @defmac AC_ENABLE (@var{feature}, @var{action-if-given}, @ovar{action-if-not-given})
13491 @acindex{ENABLE}
13492 This is an obsolete version of @code{AC_ARG_ENABLE} that does not
13493 support providing a help string.
13494 @end defmac
13497 @node Pretty Help Strings
13498 @section Making Your Help Strings Look Pretty
13499 @cindex Help strings
13501 Properly formatting the @samp{help strings} which are used in
13502 @code{AC_ARG_WITH} (@pxref{External Software}) and @code{AC_ARG_ENABLE}
13503 (@pxref{Package Options}) can be challenging.  Specifically, you want
13504 your own @samp{help strings} to line up in the appropriate columns of
13505 @samp{configure --help} just like the standard Autoconf @samp{help
13506 strings} do.  This is the purpose of the @code{AS_HELP_STRING} macro.
13508 @defmac AS_HELP_STRING (@var{left-hand-side}, @var{right-hand-side})
13509 @acindex{HELP_STRING}
13511 Expands into an help string that looks pretty when the user executes
13512 @samp{configure --help}.  It is typically used in @code{AC_ARG_WITH}
13513 (@pxref{External Software}) or @code{AC_ARG_ENABLE} (@pxref{Package
13514 Options}).  The following example will make this clearer.
13516 @example
13517 AC_ARG_WITH(foo,
13518   [AS_HELP_STRING(--with-foo,
13519      [use foo (default is no)])],
13520   [ac_cv_use_foo=$withval],
13521   [ac_cv_use_foo=no])
13522 @end example
13524 The second argument of @code{AS_HELP_STRING} is
13525 not a literal, and should not be double quoted. @xref{Autoconf
13526 Language}, for a more detailed explanation.
13527 Then the last few lines of @samp{configure --help} will appear like
13528 this:
13530 @example
13531 --enable and --with options recognized:
13532   --with-foo              use foo (default is no)
13533 @end example
13535 The @code{AS_HELP_STRING} macro is particularly helpful when the
13536 @var{left-hand-side} and/or @var{right-hand-side} are composed of macro
13537 arguments, as shown in the following example.
13539 @example
13540 AC_DEFUN([MY_ARG_WITH],
13541   [AC_ARG_WITH([$1],
13542      [AS_HELP_STRING([--with-$1], [use $1 (default is $2)])],
13543      [ac_cv_use_[]$1=$withval],
13544      [ac_cv_use_[]$1=$2])])
13545 @end example
13546 @end defmac
13549 @node Site Details
13550 @section Configuring Site Details
13551 @cindex Site details
13553 Some software packages require complex site-specific information.  Some
13554 examples are host names to use for certain services, company names, and
13555 email addresses to contact.  Since some configuration scripts generated
13556 by Metaconfig ask for such information interactively, people sometimes
13557 wonder how to get that information in Autoconf-generated configuration
13558 scripts, which aren't interactive.
13560 Such site configuration information should be put in a file that is
13561 edited @emph{only by users}, not by programs.  The location of the file
13562 can either be based on the @code{prefix} variable, or be a standard
13563 location such as the user's home directory.  It could even be specified
13564 by an environment variable.  The programs should examine that file at
13565 run time, rather than at compile time.  Run-time configuration is more
13566 convenient for users and makes the configuration process simpler than
13567 getting the information while configuring.  @xref{Directory Variables,,
13568 Variables for Installation Directories, standards, @acronym{GNU} Coding
13569 Standards}, for more information on where to put data files.
13571 @node Transforming Names
13572 @section Transforming Program Names When Installing
13573 @cindex Transforming program names
13574 @cindex Program names, transforming
13576 Autoconf supports changing the names of programs when installing them.
13577 In order to use these transformations, @file{configure.ac} must call the
13578 macro @code{AC_ARG_PROGRAM}.
13580 @defmac AC_ARG_PROGRAM
13581 @acindex{ARG_PROGRAM}
13582 @ovindex program_transform_name
13583 Place in output variable @code{program_transform_name} a sequence of
13584 @code{sed} commands for changing the names of installed programs.
13586 If any of the options described below are given to @command{configure},
13587 program names are transformed accordingly.  Otherwise, if
13588 @code{AC_CANONICAL_TARGET} has been called and a @option{--target} value
13589 is given, the target type followed by a dash is used as a prefix.
13590 Otherwise, no program name transformation is done.
13591 @end defmac
13593 @menu
13594 * Transformation Options::      @command{configure} options to transform names
13595 * Transformation Examples::     Sample uses of transforming names
13596 * Transformation Rules::        @file{Makefile} uses of transforming names
13597 @end menu
13599 @node Transformation Options
13600 @subsection Transformation Options
13602 You can specify name transformations by giving @command{configure} these
13603 command line options:
13605 @table @option
13606 @item --program-prefix=@var{prefix}
13607 prepend @var{prefix} to the names;
13609 @item --program-suffix=@var{suffix}
13610 append @var{suffix} to the names;
13612 @item --program-transform-name=@var{expression}
13613 perform @code{sed} substitution @var{expression} on the names.
13614 @end table
13616 @node Transformation Examples
13617 @subsection Transformation Examples
13619 These transformations are useful with programs that can be part of a
13620 cross-compilation development environment.  For example, a
13621 cross-assembler running on a Sun 4 configured with
13622 @option{--target=i960-vxworks} is normally installed as
13623 @file{i960-vxworks-as}, rather than @file{as}, which could be confused
13624 with a native Sun 4 assembler.
13626 You can force a program name to begin with @file{g}, if you don't want
13627 @acronym{GNU} programs installed on your system to shadow other programs with
13628 the same name.  For example, if you configure @acronym{GNU} @code{diff} with
13629 @option{--program-prefix=g}, then when you run @samp{make install} it is
13630 installed as @file{/usr/local/bin/gdiff}.
13632 As a more sophisticated example, you could use
13634 @example
13635 --program-transform-name='s/^/g/; s/^gg/g/; s/^gless/less/'
13636 @end example
13637 @noindent
13639 to prepend @samp{g} to most of the program names in a source tree,
13640 excepting those like @code{gdb} that already have one and those like
13641 @code{less} and @code{lesskey} that aren't @acronym{GNU} programs.  (That is
13642 assuming that you have a source tree containing those programs that is
13643 set up to use this feature.)
13645 One way to install multiple versions of some programs simultaneously is
13646 to append a version number to the name of one or both.  For example, if
13647 you want to keep Autoconf version 1 around for awhile, you can configure
13648 Autoconf version 2 using @option{--program-suffix=2} to install the
13649 programs as @file{/usr/local/bin/autoconf2},
13650 @file{/usr/local/bin/autoheader2}, etc.  Nevertheless, pay attention
13651 that only the binaries are renamed, therefore you'd have problems with
13652 the library files which might overlap.
13654 @node Transformation Rules
13655 @subsection Transformation Rules
13657 Here is how to use the variable @code{program_transform_name} in a
13658 @file{Makefile.in}:
13660 @example
13661 PROGRAMS = cp ls rm
13662 transform = @@program_transform_name@@
13663 install:
13664         for p in $(PROGRAMS); do \
13665           $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p | \
13666                                               sed '$(transform)'`; \
13667         done
13669 uninstall:
13670         for p in $(PROGRAMS); do \
13671           rm -f $(DESTDIR)$(bindir)/`echo $$p | sed '$(transform)'`; \
13672         done
13673 @end example
13675 It is guaranteed that @code{program_transform_name} is never empty, and
13676 that there are no useless separators.  Therefore you may safely embed
13677 @code{program_transform_name} within a sed program using @samp{;}:
13679 @example
13680 transform = @@program_transform_name@@
13681 transform_exe = s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/
13682 @end example
13684 Whether to do the transformations on documentation files (Texinfo or
13685 @code{man}) is a tricky question; there seems to be no perfect answer,
13686 due to the several reasons for name transforming.  Documentation is not
13687 usually particular to a specific architecture, and Texinfo files do not
13688 conflict with system documentation.  But they might conflict with
13689 earlier versions of the same files, and @code{man} pages sometimes do
13690 conflict with system documentation.  As a compromise, it is probably
13691 best to do name transformations on @code{man} pages but not on Texinfo
13692 manuals.
13694 @node Site Defaults
13695 @section Setting Site Defaults
13696 @cindex Site defaults
13698 Autoconf-generated @command{configure} scripts allow your site to provide
13699 default values for some configuration values.  You do this by creating
13700 site- and system-wide initialization files.
13702 @evindex CONFIG_SITE
13703 If the environment variable @code{CONFIG_SITE} is set, @command{configure}
13704 uses its value as the name of a shell script to read.  Otherwise, it
13705 reads the shell script @file{@var{prefix}/share/config.site} if it exists,
13706 then @file{@var{prefix}/etc/config.site} if it exists.  Thus,
13707 settings in machine-specific files override those in machine-independent
13708 ones in case of conflict.
13710 Site files can be arbitrary shell scripts, but only certain kinds of
13711 code are really appropriate to be in them.  Because @command{configure}
13712 reads any cache file after it has read any site files, a site file can
13713 define a default cache file to be shared between all Autoconf-generated
13714 @command{configure} scripts run on that system (@pxref{Cache Files}).  If
13715 you set a default cache file in a site file, it is a good idea to also
13716 set the output variable @code{CC} in that site file, because the cache
13717 file is only valid for a particular compiler, but many systems have
13718 several available.
13720 You can examine or override the value set by a command line option to
13721 @command{configure} in a site file; options set shell variables that have
13722 the same names as the options, with any dashes turned into underscores.
13723 The exceptions are that @option{--without-} and @option{--disable-} options
13724 are like giving the corresponding @option{--with-} or @option{--enable-}
13725 option and the value @samp{no}.  Thus, @option{--cache-file=localcache}
13726 sets the variable @code{cache_file} to the value @samp{localcache};
13727 @option{--enable-warnings=no} or @option{--disable-warnings} sets the variable
13728 @code{enable_warnings} to the value @samp{no}; @option{--prefix=/usr} sets the
13729 variable @code{prefix} to the value @samp{/usr}; etc.
13731 Site files are also good places to set default values for other output
13732 variables, such as @code{CFLAGS}, if you need to give them non-default
13733 values: anything you would normally do, repetitively, on the command
13734 line.  If you use non-default values for @var{prefix} or
13735 @var{exec_prefix} (wherever you locate the site file), you can set them
13736 in the site file if you specify it with the @code{CONFIG_SITE}
13737 environment variable.
13739 You can set some cache values in the site file itself.  Doing this is
13740 useful if you are cross-compiling, where it is impossible to check features
13741 that require running a test program.  You could ``prime the cache'' by
13742 setting those values correctly for that system in
13743 @file{@var{prefix}/etc/config.site}.  To find out the names of the cache
13744 variables you need to set, look for shell variables with @samp{_cv_} in
13745 their names in the affected @command{configure} scripts, or in the Autoconf
13746 M4 source code for those macros.
13748 The cache file is careful to not override any variables set in the site
13749 files.  Similarly, you should not override command-line options in the
13750 site files.  Your code should check that variables such as @code{prefix}
13751 and @code{cache_file} have their default values (as set near the top of
13752 @command{configure}) before changing them.
13754 Here is a sample file @file{/usr/share/local/gnu/share/config.site}.  The
13755 command @samp{configure --prefix=/usr/share/local/gnu} would read this
13756 file (if @code{CONFIG_SITE} is not set to a different file).
13758 @example
13759 # config.site for configure
13761 # Change some defaults.
13762 test "$prefix" = NONE && prefix=/usr/share/local/gnu
13763 test "$exec_prefix" = NONE && exec_prefix=/usr/local/gnu
13764 test "$sharedstatedir" = '$prefix/com' && sharedstatedir=/var
13765 test "$localstatedir" = '$prefix/var' && localstatedir=/var
13767 # Give Autoconf 2.x generated configure scripts a shared default
13768 # cache file for feature test results, architecture-specific.
13769 if test "$cache_file" = /dev/null; then
13770   cache_file="$prefix/var/config.cache"
13771   # A cache file is only valid for one C compiler.
13772   CC=gcc
13774 @end example
13777 @c ============================================== Running configure Scripts.
13779 @node Running configure Scripts
13780 @chapter Running @command{configure} Scripts
13781 @cindex @command{configure}
13783 Below are instructions on how to configure a package that uses a
13784 @command{configure} script, suitable for inclusion as an @file{INSTALL}
13785 file in the package.  A plain-text version of @file{INSTALL} which you
13786 may use comes with Autoconf.
13788 @menu
13789 * Basic Installation::          Instructions for typical cases
13790 * Compilers and Options::       Selecting compilers and optimization
13791 * Multiple Architectures::      Compiling for multiple architectures at once
13792 * Installation Names::          Installing in different directories
13793 * Optional Features::           Selecting optional features
13794 * System Type::                 Specifying the system type
13795 * Sharing Defaults::            Setting site-wide defaults for @command{configure}
13796 * Defining Variables::          Specifying the compiler etc.
13797 * configure Invocation::        Changing how @command{configure} runs
13798 @end menu
13800 @set autoconf
13801 @include install.texi
13804 @c ============================================== Recreating a Configuration
13806 @node config.status Invocation
13807 @chapter Recreating a Configuration
13808 @cindex @command{config.status}
13810 The @command{configure} script creates a file named @file{config.status},
13811 which actually configures, @dfn{instantiates}, the template files.  It
13812 also records the configuration options that were specified when the
13813 package was last configured in case reconfiguring is needed.
13815 Synopsis:
13816 @example
13817 ./config.status @var{option}@dots{} [@var{file}@dots{}]
13818 @end example
13820 It configures the @var{files}; if none are specified, all the templates
13821 are instantiated.  The files must be specified without their
13822 dependencies, as in
13824 @example
13825 ./config.status foobar
13826 @end example
13828 @noindent
13831 @example
13832 ./config.status foobar:foo.in:bar.in
13833 @end example
13835 The supported @var{option}s are:
13837 @table @option
13838 @item --help
13839 @itemx -h
13840 Print a summary of the command line options, the list of the template
13841 files, and exit.
13843 @item --version
13844 @itemx -V
13845 Print the version number of Autoconf and exit.
13847 @item --silent
13848 @itemx --quiet
13849 @itemx -q
13850 Do not print progress messages.
13852 @item --debug
13853 @itemx -d
13854 Don't remove the temporary files.
13856 @item --file=@var{file}[:@var{template}]
13857 Require that @var{file} be instantiated as if
13858 @samp{AC_CONFIG_FILES(@var{file}:@var{template})} was used.  Both
13859 @var{file} and @var{template} may be @samp{-} in which case the standard
13860 output and/or standard input, respectively, is used.  If a
13861 @var{template} file name is relative, it is first looked for in the build
13862 tree, and then in the source tree.  @xref{Configuration Actions}, for
13863 more details.
13865 This option and the following ones provide one way for separately
13866 distributed packages to share the values computed by @command{configure}.
13867 Doing so can be useful if some of the packages need a superset of the
13868 features that one of them, perhaps a common library, does.  These
13869 options allow a @file{config.status} file to create files other than the
13870 ones that its @file{configure.ac} specifies, so it can be used for a
13871 different package.
13873 @item --header=@var{file}[:@var{template}]
13874 Same as @option{--file} above, but with @samp{AC_CONFIG_HEADERS}.
13876 @item --recheck
13877 Ask @file{config.status} to update itself and exit (no instantiation).
13878 This option is useful if you change @command{configure}, so that the
13879 results of some tests might be different from the previous run.  The
13880 @option{--recheck} option re-runs @command{configure} with the same arguments
13881 you used before, plus the @option{--no-create} option, which prevents
13882 @command{configure} from running @file{config.status} and creating
13883 @file{Makefile} and other files, and the @option{--no-recursion} option,
13884 which prevents @command{configure} from running other @command{configure}
13885 scripts in subdirectories.  (This is so other @file{Makefile} rules can
13886 run @file{config.status} when it changes; @pxref{Automatic Remaking},
13887 for an example).
13888 @end table
13890 @file{config.status} checks several optional environment variables that
13891 can alter its behavior:
13893 @defvar CONFIG_SHELL
13894 @evindex CONFIG_SHELL
13895 The shell with which to run @command{configure} for the @option{--recheck}
13896 option.  It must be Bourne-compatible.  The default is a shell that
13897 supports @code{LINENO} if available, and @file{/bin/sh} otherwise.
13898 Invoking @command{configure} by hand bypasses this setting, so you may
13899 need to use a command like @samp{/bin/bash ./configure
13900 CONFIG_SHELL=/bin/bash} to insure that the same shell is used
13901 everywhere.
13902 @end defvar
13904 @defvar CONFIG_STATUS
13905 @evindex CONFIG_STATUS
13906 The file name to use for the shell script that records the
13907 configuration.  The default is @file{./config.status}.  This variable is
13908 useful when one package uses parts of another and the @command{configure}
13909 scripts shouldn't be merged because they are maintained separately.
13910 @end defvar
13912 You can use @file{./config.status} in your Makefiles.  For example, in
13913 the dependencies given above (@pxref{Automatic Remaking}),
13914 @file{config.status} is run twice when @file{configure.ac} has changed.
13915 If that bothers you, you can make each run only regenerate the files for
13916 that rule:
13917 @example
13918 @group
13919 config.h: stamp-h
13920 stamp-h: config.h.in config.status
13921         ./config.status config.h
13922         echo > stamp-h
13924 Makefile: Makefile.in config.status
13925         ./config.status Makefile
13926 @end group
13927 @end example
13929 The calling convention of @file{config.status} has changed; see
13930 @ref{Obsolete config.status Use}, for details.
13933 @c =================================================== Obsolete Constructs
13935 @node Obsolete Constructs
13936 @chapter Obsolete Constructs
13937 @cindex Obsolete constructs
13939 Autoconf changes, and throughout the years some constructs have been
13940 obsoleted.  Most of the changes involve the macros, but in some cases
13941 the tools themselves, or even some concepts, are now considered
13942 obsolete.
13944 You may completely skip this chapter if you are new to Autoconf.  Its
13945 intention is mainly to help maintainers updating their packages by
13946 understanding how to move to more modern constructs.
13948 @menu
13949 * Obsolete config.status Use::  Different calling convention
13950 * acconfig.h::                  Additional entries in @file{config.h.in}
13951 * autoupdate Invocation::       Automatic update of @file{configure.ac}
13952 * Obsolete Macros::             Backward compatibility macros
13953 * Autoconf 1::                  Tips for upgrading your files
13954 * Autoconf 2.13::               Some fresher tips
13955 @end menu
13957 @node Obsolete config.status Use
13958 @section Obsolete @file{config.status} Invocation
13960 @file{config.status} now supports arguments to specify the files to
13961 instantiate; see @ref{config.status Invocation}, for more details.
13962 Before, environment variables had to be used.
13964 @defvar CONFIG_COMMANDS
13965 @evindex CONFIG_COMMANDS
13966 The tags of the commands to execute.  The default is the arguments given
13967 to @code{AC_OUTPUT} and @code{AC_CONFIG_COMMANDS} in
13968 @file{configure.ac}.
13969 @end defvar
13971 @defvar CONFIG_FILES
13972 @evindex CONFIG_FILES
13973 The files in which to perform @samp{@@@var{variable}@@} substitutions.
13974 The default is the arguments given to @code{AC_OUTPUT} and
13975 @code{AC_CONFIG_FILES} in @file{configure.ac}.
13976 @end defvar
13978 @defvar CONFIG_HEADERS
13979 @evindex CONFIG_HEADERS
13980 The files in which to substitute C @code{#define} statements.  The
13981 default is the arguments given to @code{AC_CONFIG_HEADERS}; if that
13982 macro was not called, @file{config.status} ignores this variable.
13983 @end defvar
13985 @defvar CONFIG_LINKS
13986 @evindex CONFIG_LINKS
13987 The symbolic links to establish.  The default is the arguments given to
13988 @code{AC_CONFIG_LINKS}; if that macro was not called,
13989 @file{config.status} ignores this variable.
13990 @end defvar
13992 In @ref{config.status Invocation}, using this old interface, the example
13993 would be:
13995 @example
13996 @group
13997 config.h: stamp-h
13998 stamp-h: config.h.in config.status
13999         CONFIG_COMMANDS= CONFIG_LINKS= CONFIG_FILES= \
14000           CONFIG_HEADERS=config.h ./config.status
14001         echo > stamp-h
14003 Makefile: Makefile.in config.status
14004         CONFIG_COMMANDS= CONFIG_LINKS= CONFIG_HEADERS= \
14005           CONFIG_FILES=Makefile ./config.status
14006 @end group
14007 @end example
14009 @noindent
14010 (If @file{configure.ac} does not call @code{AC_CONFIG_HEADERS}, there is
14011 no need to set @code{CONFIG_HEADERS} in the @code{make} rules.  Equally
14012 for @code{CONFIG_COMMANDS}, etc.)
14015 @node acconfig.h
14016 @section @file{acconfig.h}
14018 @cindex @file{acconfig.h}
14019 @cindex @file{config.h.top}
14020 @cindex @file{config.h.bot}
14022 In order to produce @file{config.h.in}, @command{autoheader} needs to
14023 build or to find templates for each symbol.  Modern releases of Autoconf
14024 use @code{AH_VERBATIM} and @code{AH_TEMPLATE} (@pxref{Autoheader
14025 Macros}), but in older releases a file, @file{acconfig.h}, contained the
14026 list of needed templates.  @command{autoheader} copied comments and
14027 @code{#define} and @code{#undef} statements from @file{acconfig.h} in
14028 the current directory, if present.  This file used to be mandatory if
14029 you @code{AC_DEFINE} any additional symbols.
14031 Modern releases of Autoconf also provide @code{AH_TOP} and
14032 @code{AH_BOTTOM} if you need to prepend/append some information to
14033 @file{config.h.in}.  Ancient versions of Autoconf had a similar feature:
14034 if @file{./acconfig.h} contains the string @samp{@@TOP@@},
14035 @command{autoheader} copies the lines before the line containing
14036 @samp{@@TOP@@} into the top of the file that it generates.  Similarly,
14037 if @file{./acconfig.h} contains the string @samp{@@BOTTOM@@},
14038 @command{autoheader} copies the lines after that line to the end of the
14039 file it generates.  Either or both of those strings may be omitted.  An
14040 even older alternate way to produce the same effect in ancient versions
14041 of Autoconf is to create the files @file{@var{file}.top} (typically
14042 @file{config.h.top}) and/or @file{@var{file}.bot} in the current
14043 directory.  If they exist, @command{autoheader} copies them to the
14044 beginning and end, respectively, of its output.
14046 In former versions of Autoconf, the files used in preparing a software
14047 package for distribution were:
14048 @example
14049 @group
14050 configure.ac --.   .------> autoconf* -----> configure
14051                +---+
14052 [aclocal.m4] --+   `---.
14053 [acsite.m4] ---'       |
14054                        +--> [autoheader*] -> [config.h.in]
14055 [acconfig.h] ----.     |
14056                  +-----'
14057 [config.h.top] --+
14058 [config.h.bot] --'
14059 @end group
14060 @end example
14062 Using only the @code{AH_} macros, @file{configure.ac} should be
14063 self-contained, and should not depend upon @file{acconfig.h} etc.
14066 @node autoupdate Invocation
14067 @section Using @command{autoupdate} to Modernize @file{configure.ac}
14068 @cindex @command{autoupdate}
14070 The @command{autoupdate} program updates a @file{configure.ac} file that
14071 calls Autoconf macros by their old names to use the current macro names.
14072 In version 2 of Autoconf, most of the macros were renamed to use a more
14073 uniform and descriptive naming scheme.  @xref{Macro Names}, for a
14074 description of the new scheme.  Although the old names still work
14075 (@pxref{Obsolete Macros}, for a list of the old macros and the corresponding
14076 new names), you can make your @file{configure.ac} files more readable
14077 and make it easier to use the current Autoconf documentation if you
14078 update them to use the new macro names.
14080 @evindex SIMPLE_BACKUP_SUFFIX
14081 If given no arguments, @command{autoupdate} updates @file{configure.ac},
14082 backing up the original version with the suffix @file{~} (or the value
14083 of the environment variable @code{SIMPLE_BACKUP_SUFFIX}, if that is
14084 set).  If you give @command{autoupdate} an argument, it reads that file
14085 instead of @file{configure.ac} and writes the updated file to the
14086 standard output.
14088 @noindent
14089 @command{autoupdate} accepts the following options:
14091 @table @option
14092 @item --help
14093 @itemx -h
14094 Print a summary of the command line options and exit.
14096 @item --version
14097 @itemx -V
14098 Print the version number of Autoconf and exit.
14100 @item --verbose
14101 @itemx -v
14102 Report processing steps.
14104 @item --debug
14105 @itemx -d
14106 Don't remove the temporary files.
14108 @item --force
14109 @itemx -f
14110 Force the update even if the file has not changed.  Disregard the cache.
14112 @item --include=@var{dir}
14113 @itemx -I @var{dir}
14114 Also look for input files in @var{dir}.  Multiple invocations accumulate.
14115 Directories are browsed from last to first.
14116 @end table
14118 @node Obsolete Macros
14119 @section Obsolete Macros
14121 Several macros are obsoleted in Autoconf, for various reasons (typically
14122 they failed to quote properly, couldn't be extended for more recent
14123 issues, etc.).  They are still supported, but deprecated: their use
14124 should be avoided.
14126 During the jump from Autoconf version 1 to version 2, most of the
14127 macros were renamed to use a more uniform and descriptive naming scheme,
14128 but their signature did not change.  @xref{Macro Names}, for a
14129 description of the new naming scheme.  Below, if there is just the mapping
14130 from old names to new names for these macros, the reader is invited to
14131 refer to the definition of the new macro for the signature and the
14132 description.
14134 @defmac AC_ALLOCA
14135 @acindex{ALLOCA}
14136 @code{AC_FUNC_ALLOCA}
14137 @end defmac
14139 @defmac AC_ARG_ARRAY
14140 @acindex{ARG_ARRAY}
14141 removed because of limited usefulness
14142 @end defmac
14144 @defmac AC_C_CROSS
14145 @acindex{C_CROSS}
14146 This macro is obsolete; it does nothing.
14147 @end defmac
14149 @defmac AC_CANONICAL_SYSTEM
14150 @acindex{CANONICAL_SYSTEM}
14151 Determine the system type and set output variables to the names of the
14152 canonical system types.  @xref{Canonicalizing}, for details about the
14153 variables this macro sets.
14155 The user is encouraged to use either @code{AC_CANONICAL_BUILD}, or
14156 @code{AC_CANONICAL_HOST}, or @code{AC_CANONICAL_TARGET}, depending on
14157 the needs.  Using @code{AC_CANONICAL_TARGET} is enough to run the two
14158 other macros.
14159 @end defmac
14161 @defmac AC_CHAR_UNSIGNED
14162 @acindex{CHAR_UNSIGNED}
14163 @code{AC_C_CHAR_UNSIGNED}
14164 @end defmac
14166 @defmac AC_CHECK_TYPE (@var{type}, @var{default})
14167 @acindex{CHECK_TYPE}
14168 Autoconf, up to 2.13, used to provide this version of
14169 @code{AC_CHECK_TYPE}, deprecated because of its flaws.  Firstly, although
14170 it is a member of the @code{CHECK} clan, singular sub-family, it does
14171 more than just checking.  Secondly, missing types are not
14172 @code{typedef}'d, they are @code{#define}'d, which can lead to
14173 incompatible code in the case of pointer types.
14175 This use of @code{AC_CHECK_TYPE} is obsolete and discouraged; see
14176 @ref{Generic Types}, for the description of the current macro.
14178 If the type @var{type} is not defined, define it to be the C (or C++)
14179 builtin type @var{default}, e.g., @samp{short int} or @samp{unsigned int}.
14181 This macro is equivalent to:
14183 @example
14184 AC_CHECK_TYPE([@var{type}],,
14185               [AC_DEFINE_UNQUOTED([@var{type}], [@var{default}],
14186                                   [Define to `@var{default}' if
14187                                    <sys/types.h> does not define.])])
14188 @end example
14190 In order to keep backward compatibility, the two versions of
14191 @code{AC_CHECK_TYPE} are implemented, selected by a simple heuristics:
14193 @enumerate
14194 @item
14195 If there are three or four arguments, the modern version is used.
14197 @item
14198 If the second argument appears to be a C or C++ type, then the
14199 obsolete version is used.  This happens if the argument is a C or C++
14200 @emph{builtin} type or a C identifier ending in @samp{_t}, optionally
14201 followed by one of @samp{[(* } and then by a string of zero or more
14202 characters taken from the set @samp{[]()* _a-zA-Z0-9}.
14204 @item
14205 If the second argument is spelled with the alphabet of valid C and C++
14206 types, the user is warned and the modern version is used.
14208 @item
14209 Otherwise, the modern version is used.
14210 @end enumerate
14212 @noindent
14213 You are encouraged either to use a valid builtin type, or to use the
14214 equivalent modern code (see above), or better yet, to use
14215 @code{AC_CHECK_TYPES} together with
14217 @example
14218 #if !HAVE_LOFF_T
14219 typedef loff_t off_t;
14220 #endif
14221 @end example
14222 @end defmac
14223 @c end of AC_CHECK_TYPE
14225 @defmac AC_CHECKING (@var{feature-description})
14226 @acindex{CHECKING}
14227 Same as @samp{AC_MSG_NOTICE([checking @var{feature-description}@dots{}]}.
14228 @end defmac
14230 @defmac AC_COMPILE_CHECK (@var{echo-text}, @var{includes}, @var{function-body}, @var{action-if-found}, @ovar{action-if-not-found})
14231 @acindex{COMPILE_CHECK}
14232 This is an obsolete version of @code{AC_TRY_COMPILE} itself replaced by
14233 @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}), with the
14234 addition that it prints @samp{checking for @var{echo-text}} to the
14235 standard output first, if @var{echo-text} is non-empty.  Use
14236 @code{AC_MSG_CHECKING} and @code{AC_MSG_RESULT} instead to print
14237 messages (@pxref{Printing Messages}).
14238 @end defmac
14240 @defmac AC_CONST
14241 @acindex{CONST}
14242 @code{AC_C_CONST}
14243 @end defmac
14245 @defmac AC_CROSS_CHECK
14246 @acindex{CROSS_CHECK}
14247 Same as @code{AC_C_CROSS}, which is obsolete too, and does nothing
14248 @code{:-)}.
14249 @end defmac
14251 @defmac AC_CYGWIN
14252 @acindex{CYGWIN}
14253 Check for the Cygwin environment in which case the shell variable
14254 @code{CYGWIN} is set to @samp{yes}.  Don't use this macro, the dignified
14255 means to check the nature of the host is using
14256 @code{AC_CANONICAL_HOST}.  As a matter of fact this macro is defined as:
14258 @example
14259 AC_REQUIRE([AC_CANONICAL_HOST])[]dnl
14260 case $host_os in
14261   *cygwin* ) CYGWIN=yes;;
14262          * ) CYGWIN=no;;
14263 esac
14264 @end example
14266 Beware that the variable @code{CYGWIN} has a very special meaning when
14267 running CygWin32, and should not be changed.  That's yet another reason
14268 not to use this macro.
14269 @end defmac
14271 @defmac AC_DECL_SYS_SIGLIST
14272 @acindex{DECL_SYS_SIGLIST}
14273 @cvindex SYS_SIGLIST_DECLARED
14274 Same as:
14276 @example
14277 AC_CHECK_DECLS([sys_siglist],,,
14278 [#include <signal.h>
14279 /* NetBSD declares sys_siglist in unistd.h.  */
14280 #if HAVE_UNISTD_H
14281 # include <unistd.h>
14282 #endif
14284 @end example
14285 @end defmac
14287 @defmac AC_DECL_YYTEXT
14288 @acindex{DECL_YYTEXT}
14289 Does nothing, now integrated in @code{AC_PROG_LEX}.
14290 @end defmac
14292 @defmac AC_DIR_HEADER
14293 @acindex{DIR_HEADER}
14294 @cvindex DIRENT
14295 @cvindex SYSNDIR
14296 @cvindex SYSDIR
14297 @cvindex NDIR
14298 Like calling @code{AC_FUNC_CLOSEDIR_VOID} and@code{AC_HEADER_DIRENT},
14299 but defines a different set of C preprocessor macros to indicate which
14300 header file is found:
14302 @multitable {@file{sys/ndir.h}} {Old Symbol} {@code{HAVE_SYS_NDIR_H}}
14303 @item Header            @tab Old Symbol     @tab New Symbol
14304 @item @file{dirent.h}   @tab @code{DIRENT}  @tab @code{HAVE_DIRENT_H}
14305 @item @file{sys/ndir.h} @tab @code{SYSNDIR} @tab @code{HAVE_SYS_NDIR_H}
14306 @item @file{sys/dir.h}  @tab @code{SYSDIR}  @tab @code{HAVE_SYS_DIR_H}
14307 @item @file{ndir.h}     @tab @code{NDIR}    @tab @code{HAVE_NDIR_H}
14308 @end multitable
14309 @end defmac
14311 @defmac AC_DYNIX_SEQ
14312 @acindex{DYNIX_SEQ}
14313 If on DYNIX/ptx, add @option{-lseq} to output variable
14314 @code{LIBS}.  This macro used to be defined as
14316 @example
14317 AC_CHECK_LIB(seq, getmntent, LIBS="-lseq $LIBS")
14318 @end example
14320 @noindent
14321 now it is just @code{AC_FUNC_GETMNTENT}.
14322 @end defmac
14324 @defmac AC_EXEEXT
14325 @acindex{EXEEXT}
14326 @ovindex EXEEXT
14327 Defined the output variable @code{EXEEXT} based on the output of the
14328 compiler, which is now done automatically.  Typically set to empty
14329 string if Posix and @samp{.exe} if a @acronym{DOS} variant.
14330 @end defmac
14332 @defmac AC_EMXOS2
14333 @acindex{EMXOS2}
14334 Similar to @code{AC_CYGWIN} but checks for the EMX environment on OS/2
14335 and sets @code{EMXOS2}.
14336 @end defmac
14338 @defmac AC_ERROR
14339 @acindex{ERROR}
14340 @code{AC_MSG_ERROR}
14341 @end defmac
14343 @defmac AC_FIND_X
14344 @acindex{FIND_X}
14345 @code{AC_PATH_X}
14346 @end defmac
14348 @defmac AC_FIND_XTRA
14349 @acindex{FIND_XTRA}
14350 @code{AC_PATH_XTRA}
14351 @end defmac
14353 @defmac AC_FUNC_CHECK
14354 @acindex{FUNC_CHECK}
14355 @code{AC_CHECK_FUNC}
14356 @end defmac
14358 @defmac AC_FUNC_WAIT3
14359 @acindex{FUNC_WAIT3}
14360 @cvindex HAVE_WAIT3
14361 If @code{wait3} is found and fills in the contents of its third argument
14362 (a @samp{struct rusage *}), which HP-UX does not do, define
14363 @code{HAVE_WAIT3}.
14365 These days portable programs should use @code{waitpid}, not
14366 @code{wait3}, as @code{wait3} has been removed from Posix.
14367 @end defmac
14369 @defmac AC_GCC_TRADITIONAL
14370 @acindex{GCC_TRADITIONAL}
14371 @code{AC_PROG_GCC_TRADITIONAL}
14372 @end defmac
14374 @defmac AC_GETGROUPS_T
14375 @acindex{GETGROUPS_T}
14376 @code{AC_TYPE_GETGROUPS}
14377 @end defmac
14379 @defmac AC_GETLOADAVG
14380 @acindex{GETLOADAVG}
14381 @code{AC_FUNC_GETLOADAVG}
14382 @end defmac
14384 @defmac AC_HAVE_FUNCS
14385 @acindex{HAVE_FUNCS}
14386 @code{AC_CHECK_FUNCS}
14387 @end defmac
14389 @defmac AC_HAVE_HEADERS
14390 @acindex{HAVE_HEADERS}
14391 @code{AC_CHECK_HEADERS}
14392 @end defmac
14394 @defmac AC_HAVE_LIBRARY (@var{library}, @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{other-libraries})
14395 @acindex{HAVE_LIBRARY}
14396 This macro is equivalent to calling @code{AC_CHECK_LIB} with a
14397 @var{function} argument of @code{main}.  In addition, @var{library} can
14398 be written as any of @samp{foo}, @option{-lfoo}, or @samp{libfoo.a}.  In
14399 all of those cases, the compiler is passed @option{-lfoo}.  However,
14400 @var{library} cannot be a shell variable; it must be a literal name.
14401 @end defmac
14403 @defmac AC_HAVE_POUNDBANG
14404 @acindex{HAVE_POUNDBANG}
14405 @code{AC_SYS_INTERPRETER} (different calling convention)
14406 @end defmac
14408 @defmac AC_HEADER_CHECK
14409 @acindex{HEADER_CHECK}
14410 @code{AC_CHECK_HEADER}
14411 @end defmac
14413 @defmac AC_HEADER_EGREP
14414 @acindex{HEADER_EGREP}
14415 @code{AC_EGREP_HEADER}
14416 @end defmac
14418 @defmac AC_HELP_STRING
14419 @acindex{HELP_STRING}
14420 @code{AS_HELP_STRING}
14421 @end defmac
14423 @defmac AC_INIT (@var{unique-file-in-source-dir})
14424 @acindex{INIT}
14425 Formerly @code{AC_INIT} used to have a single argument, and was
14426 equivalent to:
14428 @example
14429 AC_INIT
14430 AC_CONFIG_SRCDIR(@var{unique-file-in-source-dir})
14431 @end example
14432 @end defmac
14434 @defmac AC_INLINE
14435 @acindex{INLINE}
14436 @code{AC_C_INLINE}
14437 @end defmac
14439 @defmac AC_INT_16_BITS
14440 @acindex{INT_16_BITS}
14441 @cvindex INT_16_BITS
14442 If the C type @code{int} is 16 bits wide, define @code{INT_16_BITS}.
14443 Use @samp{AC_CHECK_SIZEOF(int)} instead.
14444 @end defmac
14446 @defmac AC_IRIX_SUN
14447 @acindex{IRIX_SUN}
14448 If on @sc{irix} (Silicon Graphics Unix), add @option{-lsun} to output
14449 @code{LIBS}.  If you were using it to get @code{getmntent}, use
14450 @code{AC_FUNC_GETMNTENT} instead.  If you used it for the NIS versions
14451 of the password and group functions, use @samp{AC_CHECK_LIB(sun,
14452 getpwnam)}.  Up to Autoconf 2.13, it used to be
14454 @example
14455 AC_CHECK_LIB(sun, getmntent, LIBS="-lsun $LIBS")
14456 @end example
14458 @noindent
14459 now it is defined as
14461 @example
14462 AC_FUNC_GETMNTENT
14463 AC_CHECK_LIB(sun, getpwnam)
14464 @end example
14465 @end defmac
14467 @defmac AC_LANG_C
14468 @acindex{LANG_C}
14469 Same as @samp{AC_LANG(C)}.
14470 @end defmac
14472 @defmac AC_LANG_CPLUSPLUS
14473 @acindex{LANG_CPLUSPLUS}
14474 Same as @samp{AC_LANG(C++)}.
14475 @end defmac
14477 @defmac AC_LANG_FORTRAN77
14478 @acindex{LANG_FORTRAN77}
14479 Same as @samp{AC_LANG(Fortran 77)}.
14480 @end defmac
14482 @defmac AC_LANG_RESTORE
14483 @acindex{LANG_RESTORE}
14484 Select the @var{language} that is saved on the top of the stack, as set
14485 by @code{AC_LANG_SAVE}, remove it from the stack, and call
14486 @code{AC_LANG(@var{language})}.
14487 @end defmac
14489 @defmac AC_LANG_SAVE
14490 @acindex{LANG_SAVE}
14491 Remember the current language (as set by @code{AC_LANG}) on a stack.
14492 The current language does not change.  @code{AC_LANG_PUSH} is preferred.
14493 @end defmac
14495 @defmac AC_LINK_FILES (@var{source}@dots{}, @var{dest}@dots{})
14496 @acindex{LINK_FILES}
14497 This is an obsolete version of @code{AC_CONFIG_LINKS}.  An updated
14498 version of:
14500 @example
14501 AC_LINK_FILES(config/$machine.h config/$obj_format.h,
14502               host.h            object.h)
14503 @end example
14505 @noindent
14508 @example
14509 AC_CONFIG_LINKS(host.h:config/$machine.h
14510                 object.h:config/$obj_format.h)
14511 @end example
14512 @end defmac
14514 @defmac AC_LN_S
14515 @acindex{LN_S}
14516 @code{AC_PROG_LN_S}
14517 @end defmac
14519 @defmac AC_LONG_64_BITS
14520 @acindex{LONG_64_BITS}
14521 @cvindex LONG_64_BITS
14522 Define @code{LONG_64_BITS} if the C type @code{long int} is 64 bits wide.
14523 Use the generic macro @samp{AC_CHECK_SIZEOF([long int])} instead.
14524 @end defmac
14526 @defmac AC_LONG_DOUBLE
14527 @acindex{LONG_DOUBLE}
14528 @code{AC_C_LONG_DOUBLE}
14529 @end defmac
14531 @defmac AC_LONG_FILE_NAMES
14532 @acindex{LONG_FILE_NAMES}
14533 @code{AC_SYS_LONG_FILE_NAMES}
14534 @end defmac
14536 @defmac AC_MAJOR_HEADER
14537 @acindex{MAJOR_HEADER}
14538 @code{AC_HEADER_MAJOR}
14539 @end defmac
14541 @defmac AC_MEMORY_H
14542 @acindex{MEMORY_H}
14543 @cvindex NEED_MEMORY_H
14544 Used to define @code{NEED_MEMORY_H} if the @code{mem} functions were
14545 defined in @file{memory.h}.  Today it is equivalent to
14546 @samp{AC_CHECK_HEADERS(memory.h)}.  Adjust your code to depend upon
14547 @code{HAVE_MEMORY_H}, not @code{NEED_MEMORY_H}; see @ref{Standard
14548 Symbols}.
14549 @end defmac
14551 @defmac AC_MINGW32
14552 @acindex{MINGW32}
14553 Similar to @code{AC_CYGWIN} but checks for the MingW32 compiler
14554 environment and sets @code{MINGW32}.
14555 @end defmac
14557 @defmac AC_MINUS_C_MINUS_O
14558 @acindex{MINUS_C_MINUS_O}
14559 @code{AC_PROG_CC_C_O}
14560 @end defmac
14562 @defmac AC_MMAP
14563 @acindex{MMAP}
14564 @code{AC_FUNC_MMAP}
14565 @end defmac
14567 @defmac AC_MODE_T
14568 @acindex{MODE_T}
14569 @code{AC_TYPE_MODE_T}
14570 @end defmac
14572 @defmac AC_OBJEXT
14573 @acindex{OBJEXT}
14574 @ovindex OBJEXT
14575 Defined the output variable @code{OBJEXT} based on the output of the
14576 compiler, after .c files have been excluded.  Typically set to @samp{o}
14577 if Posix, @samp{obj} if a @acronym{DOS} variant.
14578 Now the compiler checking macros handle
14579 this automatically.
14580 @end defmac
14582 @defmac AC_OBSOLETE (@var{this-macro-name}, @ovar{suggestion})
14583 @acindex{OBSOLETE}
14584 Make M4 print a message to the standard error output warning that
14585 @var{this-macro-name} is obsolete, and giving the file and line number
14586 where it was called.  @var{this-macro-name} should be the name of the
14587 macro that is calling @code{AC_OBSOLETE}.  If @var{suggestion} is given,
14588 it is printed at the end of the warning message; for example, it can be
14589 a suggestion for what to use instead of @var{this-macro-name}.
14591 For instance
14593 @example
14594 AC_OBSOLETE([$0], [; use AC_CHECK_HEADERS(unistd.h) instead])dnl
14595 @end example
14597 You are encouraged to use @code{AU_DEFUN} instead, since it gives better
14598 services to the user.
14599 @end defmac
14601 @defmac AC_OFF_T
14602 @acindex{OFF_T}
14603 @code{AC_TYPE_OFF_T}
14604 @end defmac
14606 @defmac AC_OUTPUT (@ovar{file}@dots{}, @ovar{extra-cmds}, @ovar{init-cmds})
14607 @acindex{OUTPUT}
14608 The use of @code{AC_OUTPUT} with argument is deprecated.  This obsoleted
14609 interface is equivalent to:
14611 @example
14612 @group
14613 AC_CONFIG_FILES(@var{file}@dots{})
14614 AC_CONFIG_COMMANDS([default],
14615                    @var{extra-cmds}, @var{init-cmds})
14616 AC_OUTPUT
14617 @end group
14618 @end example
14619 @end defmac
14621 @defmac AC_OUTPUT_COMMANDS (@var{extra-cmds}, @ovar{init-cmds})
14622 @acindex{OUTPUT_COMMANDS}
14623 Specify additional shell commands to run at the end of
14624 @file{config.status}, and shell commands to initialize any variables
14625 from @command{configure}.  This macro may be called multiple times.  It is
14626 obsolete, replaced by @code{AC_CONFIG_COMMANDS}.
14628 Here is an unrealistic example:
14630 @example
14631 fubar=27
14632 AC_OUTPUT_COMMANDS([echo this is extra $fubar, and so on.],
14633                    [fubar=$fubar])
14634 AC_OUTPUT_COMMANDS([echo this is another, extra, bit],
14635                    [echo init bit])
14636 @end example
14638 Aside from the fact that @code{AC_CONFIG_COMMANDS} requires an
14639 additional key, an important difference is that
14640 @code{AC_OUTPUT_COMMANDS} is quoting its arguments twice, unlike
14641 @code{AC_CONFIG_COMMANDS}.  This means that @code{AC_CONFIG_COMMANDS}
14642 can safely be given macro calls as arguments:
14644 @example
14645 AC_CONFIG_COMMANDS(foo, [my_FOO()])
14646 @end example
14648 @noindent
14649 Conversely, where one level of quoting was enough for literal strings
14650 with @code{AC_OUTPUT_COMMANDS}, you need two with
14651 @code{AC_CONFIG_COMMANDS}.  The following lines are equivalent:
14653 @example
14654 @group
14655 AC_OUTPUT_COMMANDS([echo "Square brackets: []"])
14656 AC_CONFIG_COMMANDS([default], [[echo "Square brackets: []"]])
14657 @end group
14658 @end example
14659 @end defmac
14661 @defmac AC_PID_T
14662 @acindex{PID_T}
14663 @code{AC_TYPE_PID_T}
14664 @end defmac
14666 @defmac AC_PREFIX
14667 @acindex{PREFIX}
14668 @code{AC_PREFIX_PROGRAM}
14669 @end defmac
14671 @defmac AC_PROGRAMS_CHECK
14672 @acindex{PROGRAMS_CHECK}
14673 @code{AC_CHECK_PROGS}
14674 @end defmac
14676 @defmac AC_PROGRAMS_PATH
14677 @acindex{PROGRAMS_PATH}
14678 @code{AC_PATH_PROGS}
14679 @end defmac
14681 @defmac AC_PROGRAM_CHECK
14682 @acindex{PROGRAM_CHECK}
14683 @code{AC_CHECK_PROG}
14684 @end defmac
14686 @defmac AC_PROGRAM_EGREP
14687 @acindex{PROGRAM_EGREP}
14688 @code{AC_EGREP_CPP}
14689 @end defmac
14691 @defmac AC_PROGRAM_PATH
14692 @acindex{PROGRAM_PATH}
14693 @code{AC_PATH_PROG}
14694 @end defmac
14696 @defmac AC_REMOTE_TAPE
14697 @acindex{REMOTE_TAPE}
14698 removed because of limited usefulness
14699 @end defmac
14701 @defmac AC_RESTARTABLE_SYSCALLS
14702 @acindex{RESTARTABLE_SYSCALLS}
14703 @code{AC_SYS_RESTARTABLE_SYSCALLS}
14704 @end defmac
14706 @defmac AC_RETSIGTYPE
14707 @acindex{RETSIGTYPE}
14708 @code{AC_TYPE_SIGNAL}
14709 @end defmac
14711 @defmac AC_RSH
14712 @acindex{RSH}
14713 removed because of limited usefulness
14714 @end defmac
14716 @defmac AC_SCO_INTL
14717 @acindex{SCO_INTL}
14718 @ovindex LIBS
14719 If on SCO Unix, add @option{-lintl} to output variable @code{LIBS}.  This
14720 macro used to do this:
14722 @example
14723 AC_CHECK_LIB(intl, strftime, LIBS="-lintl $LIBS")
14724 @end example
14726 @noindent
14727 Now it just calls @code{AC_FUNC_STRFTIME} instead.
14728 @end defmac
14730 @defmac AC_SETVBUF_REVERSED
14731 @acindex{SETVBUF_REVERSED}
14732 @code{AC_FUNC_SETVBUF_REVERSED}
14733 @end defmac
14735 @defmac AC_SET_MAKE
14736 @acindex{SET_MAKE}
14737 @code{AC_PROG_MAKE_SET}
14738 @end defmac
14740 @defmac AC_SIZEOF_TYPE
14741 @acindex{SIZEOF_TYPE}
14742 @code{AC_CHECK_SIZEOF}
14743 @end defmac
14745 @defmac AC_SIZE_T
14746 @acindex{SIZE_T}
14747 @code{AC_TYPE_SIZE_T}
14748 @end defmac
14750 @defmac AC_STAT_MACROS_BROKEN
14751 @acindex{STAT_MACROS_BROKEN}
14752 @code{AC_HEADER_STAT}
14753 @end defmac
14755 @defmac AC_STDC_HEADERS
14756 @acindex{STDC_HEADERS}
14757 @code{AC_HEADER_STDC}
14758 @end defmac
14760 @defmac AC_STRCOLL
14761 @acindex{STRCOLL}
14762 @code{AC_FUNC_STRCOLL}
14763 @end defmac
14765 @defmac AC_ST_BLKSIZE
14766 @acindex{ST_BLKSIZE}
14767 @code{AC_CHECK_MEMBERS}
14768 @end defmac
14770 @defmac AC_ST_BLOCKS
14771 @acindex{ST_BLOCKS}
14772 @code{AC_STRUCT_ST_BLOCKS}
14773 @end defmac
14775 @defmac AC_ST_RDEV
14776 @acindex{ST_RDEV}
14777 @code{AC_CHECK_MEMBERS}
14778 @end defmac
14780 @defmac AC_SYS_RESTARTABLE_SYSCALLS
14781 @acindex{SYS_RESTARTABLE_SYSCALLS}
14782 @cvindex HAVE_RESTARTABLE_SYSCALLS
14783 If the system automatically restarts a system call that is interrupted
14784 by a signal, define @code{HAVE_RESTARTABLE_SYSCALLS}.  This macro does
14785 not check whether system calls are restarted in general---it checks whether a
14786 signal handler installed with @code{signal} (but not @code{sigaction})
14787 causes system calls to be restarted.  It does not check whether system calls
14788 can be restarted when interrupted by signals that have no handler.
14790 These days portable programs should use @code{sigaction} with
14791 @code{SA_RESTART} if they want restartable system calls.  They should
14792 not rely on @code{HAVE_RESTARTABLE_SYSCALLS}, since nowadays whether a
14793 system call is restartable is a dynamic issue, not a configuration-time
14794 issue.
14795 @end defmac
14797 @defmac AC_SYS_SIGLIST_DECLARED
14798 @acindex{SYS_SIGLIST_DECLARED}
14799 @code{AC_DECL_SYS_SIGLIST}
14800 @end defmac
14802 @defmac AC_TEST_CPP
14803 @acindex{TEST_CPP}
14804 @code{AC_TRY_CPP}, replaced by @code{AC_PREPROC_IFELSE}.
14805 @end defmac
14807 @defmac AC_TEST_PROGRAM
14808 @acindex{TEST_PROGRAM}
14809 @code{AC_TRY_RUN}, replaced by @code{AC_RUN_IFELSE}.
14810 @end defmac
14812 @defmac AC_TIMEZONE
14813 @acindex{TIMEZONE}
14814 @code{AC_STRUCT_TIMEZONE}
14815 @end defmac
14817 @defmac AC_TIME_WITH_SYS_TIME
14818 @acindex{TIME_WITH_SYS_TIME}
14819 @code{AC_HEADER_TIME}
14820 @end defmac
14822 @defmac AC_TRY_COMPILE (@var{includes}, @var{function-body}, @ovar{action-if-found}, @ovar{action-if-not-found})
14823 @acindex{TRY_COMPILE}
14824 Same as @samp{AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@var{includes}]],
14825 [[@var{function-body}]])], [@var{action-if-true}],
14826 [@var{action-if-false}])} (@pxref{Running the Compiler}).
14828 This macro double quotes both @var{includes} and @var{function-body}.
14830 For C and C++, @var{includes} is any @code{#include} statements needed
14831 by the code in @var{function-body} (@var{includes} will be ignored if
14832 the currently selected language is Fortran or Fortran 77).  The compiler
14833 and compilation flags are determined by the current language
14834 (@pxref{Language Choice}).
14835 @end defmac
14837 @defmac AC_TRY_CPP (@var{input}, @ovar{action-if-true}, @ovar{action-if-false})
14838 @acindex{TRY_CPP}
14839 Same as @samp{AC_PREPROC_IFELSE([AC_LANG_SOURCE([[@var{input}]])],
14840 [@var{action-if-true}], [@var{action-if-false}])} (@pxref{Running the
14841 Preprocessor}).
14843 This macro double quotes the @var{input}.
14844 @end defmac
14846 @defmac AC_TRY_LINK (@var{includes}, @var{function-body}, @ovar{action-if-found}, @ovar{action-if-not-found})
14847 @acindex{TRY_LINK}
14848 Same as @samp{AC_LINK_IFELSE([AC_LANG_PROGRAM([[@var{includes}]],
14849 [[@var{function-body}]])], [@var{action-if-true}],
14850 [@var{action-if-false}])} (@pxref{Running the Compiler}).
14852 This macro double quotes both @var{includes} and @var{function-body}.
14854 Depending on the current language (@pxref{Language Choice}), create a
14855 test program to see whether a function whose body consists of
14856 @var{function-body} can be compiled and linked.  If the file compiles
14857 and links successfully, run shell commands @var{action-if-found},
14858 otherwise run @var{action-if-not-found}.
14860 This macro double quotes both @var{includes} and @var{function-body}.
14862 For C and C++, @var{includes} is any @code{#include} statements needed
14863 by the code in @var{function-body} (@var{includes} will be ignored if
14864 the currently selected language is Fortran or Fortran 77).  The compiler
14865 and compilation flags are determined by the current language
14866 (@pxref{Language Choice}), and in addition @code{LDFLAGS} and
14867 @code{LIBS} are used for linking.
14868 @end defmac
14870 @defmac AC_TRY_LINK_FUNC (@var{function}, @ovar{action-if-found}, @ovar{action-if-not-found})
14871 @acindex{TRY_LINK_FUNC}
14872 This macro is equivalent to
14873 @samp{AC_LINK_IFELSE([AC_LANG_CALL([[@var{includes}]],
14874 [[@var{function-body}]])], [@var{action-if-true}],
14875 [@var{action-if-false}])}.
14876 @end defmac
14878 @defmac AC_TRY_RUN (@var{program}, @ovar{action-if-true}, @ovar{action-if-false}, @ovar{action-if-cross-compiling})
14879 @acindex{TRY_RUN}
14880 Same as @samp{AC_RUN_IFELSE([AC_LANG_SOURCE([[@var{program}]],
14881 [@var{action-if-true}], [@var{action-if-false}],
14882 [@var{action-if-cross-compiling}])} (@pxref{Run Time}).
14883 @end defmac
14886 @defmac AC_UID_T
14887 @acindex{UID_T}
14888 @code{AC_TYPE_UID_T}
14889 @end defmac
14891 @defmac AC_UNISTD_H
14892 @acindex{UNISTD_H}
14893 Same as @samp{AC_CHECK_HEADERS(unistd.h)}.
14894 @end defmac
14896 @defmac AC_USG
14897 @acindex{USG}
14898 @cvindex USG
14899 Define @code{USG} if the @acronym{BSD} string functions are defined in
14900 @file{strings.h}.  You should no longer depend upon @code{USG}, but on
14901 @code{HAVE_STRING_H}; see @ref{Standard Symbols}.
14902 @end defmac
14904 @defmac AC_UTIME_NULL
14905 @acindex{UTIME_NULL}
14906 @code{AC_FUNC_UTIME_NULL}
14907 @end defmac
14909 @defmac AC_VALIDATE_CACHED_SYSTEM_TUPLE (@ovar{cmd})
14910 @acindex{VALIDATE_CACHED_SYSTEM_TUPLE}
14911 If the cache file is inconsistent with the current host, target and
14912 build system types, it used to execute @var{cmd} or print a default
14913 error message.  This is now handled by default.
14914 @end defmac
14916 @defmac AC_VERBOSE (@var{result-description})
14917 @acindex{VERBOSE}
14918 @code{AC_MSG_RESULT}.
14919 @end defmac
14921 @defmac AC_VFORK
14922 @acindex{VFORK}
14923 @code{AC_FUNC_VFORK}
14924 @end defmac
14926 @defmac AC_VPRINTF
14927 @acindex{VPRINTF}
14928 @code{AC_FUNC_VPRINTF}
14929 @end defmac
14931 @defmac AC_WAIT3
14932 @acindex{WAIT3}
14933 @code{AC_FUNC_WAIT3}
14934 @end defmac
14936 @defmac AC_WARN
14937 @acindex{WARN}
14938 @code{AC_MSG_WARN}
14939 @end defmac
14941 @defmac AC_WORDS_BIGENDIAN
14942 @acindex{WORDS_BIGENDIAN}
14943 @code{AC_C_BIGENDIAN}
14944 @end defmac
14946 @defmac AC_XENIX_DIR
14947 @acindex{XENIX_DIR}
14948 @ovindex LIBS
14949 This macro used to add @option{-lx} to output variable @code{LIBS} if on
14950 Xenix.  Also, if @file{dirent.h} is being checked for, added
14951 @option{-ldir} to @code{LIBS}.  Now it is merely an alias of
14952 @code{AC_HEADER_DIRENT} instead, plus some code to detect whether
14953 running @sc{xenix} on which you should not depend:
14955 @example
14956 AC_MSG_CHECKING([for Xenix])
14957 AC_EGREP_CPP(yes,
14958 [#if defined M_XENIX && !defined M_UNIX
14959   yes
14960 #endif],
14961              [AC_MSG_RESULT([yes]); XENIX=yes],
14962              [AC_MSG_RESULT([no]); XENIX=])
14963 @end example
14964 @end defmac
14966 @defmac AC_YYTEXT_POINTER
14967 @acindex{YYTEXT_POINTER}
14968 @code{AC_DECL_YYTEXT}
14969 @end defmac
14971 @node Autoconf 1
14972 @section Upgrading From Version 1
14973 @cindex Upgrading autoconf
14974 @cindex Autoconf upgrading
14976 Autoconf version 2 is mostly backward compatible with version 1.
14977 However, it introduces better ways to do some things, and doesn't
14978 support some of the ugly things in version 1.  So, depending on how
14979 sophisticated your @file{configure.ac} files are, you might have to do
14980 some manual work in order to upgrade to version 2.  This chapter points
14981 out some problems to watch for when upgrading.  Also, perhaps your
14982 @command{configure} scripts could benefit from some of the new features in
14983 version 2; the changes are summarized in the file @file{NEWS} in the
14984 Autoconf distribution.
14986 @menu
14987 * Changed File Names::          Files you might rename
14988 * Changed Makefiles::           New things to put in @file{Makefile.in}
14989 * Changed Macros::              Macro calls you might replace
14990 * Changed Results::             Changes in how to check test results
14991 * Changed Macro Writing::       Better ways to write your own macros
14992 @end menu
14994 @node Changed File Names
14995 @subsection Changed File Names
14997 If you have an @file{aclocal.m4} installed with Autoconf (as opposed to
14998 in a particular package's source directory), you must rename it to
14999 @file{acsite.m4}.  @xref{autoconf Invocation}.
15001 If you distribute @file{install.sh} with your package, rename it to
15002 @file{install-sh} so @code{make} builtin rules won't inadvertently
15003 create a file called @file{install} from it.  @code{AC_PROG_INSTALL}
15004 looks for the script under both names, but it is best to use the new name.
15006 If you were using @file{config.h.top}, @file{config.h.bot}, or
15007 @file{acconfig.h}, you still can, but you will have less clutter if you
15008 use the @code{AH_} macros.  @xref{Autoheader Macros}.
15010 @node Changed Makefiles
15011 @subsection Changed Makefiles
15013 Add @samp{@@CFLAGS@@}, @samp{@@CPPFLAGS@@}, and @samp{@@LDFLAGS@@} in
15014 your @file{Makefile.in} files, so they can take advantage of the values
15015 of those variables in the environment when @command{configure} is run.
15016 Doing this isn't necessary, but it's a convenience for users.
15018 Also add @samp{@@configure_input@@} in a comment to each input file for
15019 @code{AC_OUTPUT}, so that the output files will contain a comment saying
15020 they were produced by @command{configure}.  Automatically selecting the
15021 right comment syntax for all the kinds of files that people call
15022 @code{AC_OUTPUT} on became too much work.
15024 Add @file{config.log} and @file{config.cache} to the list of files you
15025 remove in @code{distclean} targets.
15027 If you have the following in @file{Makefile.in}:
15029 @example
15030 prefix = /usr/local
15031 exec_prefix = $(prefix)
15032 @end example
15034 @noindent
15035 you must change it to:
15037 @example
15038 prefix = @@prefix@@
15039 exec_prefix = @@exec_prefix@@
15040 @end example
15042 @noindent
15043 The old behavior of replacing those variables without @samp{@@}
15044 characters around them has been removed.
15046 @node Changed Macros
15047 @subsection Changed Macros
15049 Many of the macros were renamed in Autoconf version 2.  You can still
15050 use the old names, but the new ones are clearer, and it's easier to find
15051 the documentation for them.  @xref{Obsolete Macros}, for a table showing the
15052 new names for the old macros.  Use the @command{autoupdate} program to
15053 convert your @file{configure.ac} to using the new macro names.
15054 @xref{autoupdate Invocation}.
15056 Some macros have been superseded by similar ones that do the job better,
15057 but are not call-compatible.  If you get warnings about calling obsolete
15058 macros while running @command{autoconf}, you may safely ignore them, but
15059 your @command{configure} script will generally work better if you follow
15060 the advice that is printed about what to replace the obsolete macros with.  In
15061 particular, the mechanism for reporting the results of tests has
15062 changed.  If you were using @command{echo} or @code{AC_VERBOSE} (perhaps
15063 via @code{AC_COMPILE_CHECK}), your @command{configure} script's output will
15064 look better if you switch to @code{AC_MSG_CHECKING} and
15065 @code{AC_MSG_RESULT}.  @xref{Printing Messages}.  Those macros work best
15066 in conjunction with cache variables.  @xref{Caching Results}.
15070 @node Changed Results
15071 @subsection Changed Results
15073 If you were checking the results of previous tests by examining the
15074 shell variable @code{DEFS}, you need to switch to checking the values of
15075 the cache variables for those tests.  @code{DEFS} no longer exists while
15076 @command{configure} is running; it is only created when generating output
15077 files.  This difference from version 1 is because properly quoting the
15078 contents of that variable turned out to be too cumbersome and
15079 inefficient to do every time @code{AC_DEFINE} is called.  @xref{Cache
15080 Variable Names}.
15082 For example, here is a @file{configure.ac} fragment written for Autoconf
15083 version 1:
15085 @example
15086 AC_HAVE_FUNCS(syslog)
15087 case "$DEFS" in
15088 *-DHAVE_SYSLOG*) ;;
15089 *) # syslog is not in the default libraries.  See if it's in some other.
15090   saved_LIBS="$LIBS"
15091   for lib in bsd socket inet; do
15092     AC_CHECKING(for syslog in -l$lib)
15093     LIBS="$saved_LIBS -l$lib"
15094     AC_HAVE_FUNCS(syslog)
15095     case "$DEFS" in
15096     *-DHAVE_SYSLOG*) break ;;
15097     *) ;;
15098     esac
15099     LIBS="$saved_LIBS"
15100   done ;;
15101 esac
15102 @end example
15104 Here is a way to write it for version 2:
15106 @example
15107 AC_CHECK_FUNCS(syslog)
15108 if test $ac_cv_func_syslog = no; then
15109   # syslog is not in the default libraries.  See if it's in some other.
15110   for lib in bsd socket inet; do
15111     AC_CHECK_LIB($lib, syslog, [AC_DEFINE(HAVE_SYSLOG)
15112       LIBS="$LIBS -l$lib"; break])
15113   done
15115 @end example
15117 If you were working around bugs in @code{AC_DEFINE_UNQUOTED} by adding
15118 backslashes before quotes, you need to remove them.  It now works
15119 predictably, and does not treat quotes (except back quotes) specially.
15120 @xref{Setting Output Variables}.
15122 All of the Boolean shell variables set by Autoconf macros now use
15123 @samp{yes} for the true value.  Most of them use @samp{no} for false,
15124 though for backward compatibility some use the empty string instead.  If
15125 you were relying on a shell variable being set to something like 1 or
15126 @samp{t} for true, you need to change your tests.
15128 @node Changed Macro Writing
15129 @subsection Changed Macro Writing
15131 When defining your own macros, you should now use @code{AC_DEFUN}
15132 instead of @code{define}.  @code{AC_DEFUN} automatically calls
15133 @code{AC_PROVIDE} and ensures that macros called via @code{AC_REQUIRE}
15134 do not interrupt other macros, to prevent nested @samp{checking@dots{}}
15135 messages on the screen.  There's no actual harm in continuing to use the
15136 older way, but it's less convenient and attractive.  @xref{Macro
15137 Definitions}.
15139 You probably looked at the macros that came with Autoconf as a guide for
15140 how to do things.  It would be a good idea to take a look at the new
15141 versions of them, as the style is somewhat improved and they take
15142 advantage of some new features.
15144 If you were doing tricky things with undocumented Autoconf internals
15145 (macros, variables, diversions), check whether you need to change
15146 anything to account for changes that have been made.  Perhaps you can
15147 even use an officially supported technique in version 2 instead of
15148 kludging.  Or perhaps not.
15150 To speed up your locally written feature tests, add caching to them.
15151 See whether any of your tests are of general enough usefulness to
15152 encapsulate them into macros that you can share.
15155 @node Autoconf 2.13
15156 @section Upgrading From Version 2.13
15157 @cindex Upgrading autoconf
15158 @cindex Autoconf upgrading
15160 The introduction of the previous section (@pxref{Autoconf 1}) perfectly
15161 suits this section@enddots{}
15163 @quotation
15164 Autoconf version 2.50 is mostly backward compatible with version 2.13.
15165 However, it introduces better ways to do some things, and doesn't
15166 support some of the ugly things in version 2.13.  So, depending on how
15167 sophisticated your @file{configure.ac} files are, you might have to do
15168 some manual work in order to upgrade to version 2.50.  This chapter
15169 points out some problems to watch for when upgrading.  Also, perhaps
15170 your @command{configure} scripts could benefit from some of the new
15171 features in version 2.50; the changes are summarized in the file
15172 @file{NEWS} in the Autoconf distribution.
15173 @end quotation
15175 @menu
15176 * Changed Quotation::           Broken code which used to work
15177 * New Macros::                  Interaction with foreign macros
15178 * Hosts and Cross-Compilation::  Bugward compatibility kludges
15179 * AC_LIBOBJ vs LIBOBJS::        LIBOBJS is a forbidden token
15180 * AC_FOO_IFELSE vs AC_TRY_FOO::  A more generic scheme for testing sources
15181 @end menu
15183 @node Changed Quotation
15184 @subsection Changed Quotation
15186 The most important changes are invisible to you: the implementation of
15187 most macros have completely changed.  This allowed more factorization of
15188 the code, better error messages, a higher uniformity of the user's
15189 interface etc.  Unfortunately, as a side effect, some construct which
15190 used to (miraculously) work might break starting with Autoconf 2.50.
15191 The most common culprit is bad quotation.
15193 For instance, in the following example, the message is not properly
15194 quoted:
15196 @example
15197 AC_INIT
15198 AC_CHECK_HEADERS(foo.h,,
15199 AC_MSG_ERROR(cannot find foo.h, bailing out))
15200 AC_OUTPUT
15201 @end example
15203 @noindent
15204 Autoconf 2.13 simply ignores it:
15206 @example
15207 $ @kbd{autoconf-2.13; ./configure --silent}
15208 creating cache ./config.cache
15209 configure: error: cannot find foo.h
15211 @end example
15213 @noindent
15214 while Autoconf 2.50 will produce a broken @file{configure}:
15216 @example
15217 $ @kbd{autoconf-2.50; ./configure --silent}
15218 configure: error: cannot find foo.h
15219 ./configure: exit: bad non-numeric arg `bailing'
15220 ./configure: exit: bad non-numeric arg `bailing'
15222 @end example
15224 The message needs to be quoted, and the @code{AC_MSG_ERROR} invocation
15225 too!
15227 @example
15228 AC_INIT
15229 AC_CHECK_HEADERS(foo.h,,
15230                  [AC_MSG_ERROR([cannot find foo.h, bailing out])])
15231 AC_OUTPUT
15232 @end example
15234 Many many (and many more) Autoconf macros were lacking proper quotation,
15235 including no less than@dots{} @code{AC_DEFUN} itself!
15237 @example
15238 $ @kbd{cat configure.in}
15239 AC_DEFUN([AC_PROG_INSTALL],
15240 [# My own much better version
15242 AC_INIT
15243 AC_PROG_INSTALL
15244 AC_OUTPUT
15245 $ @kbd{autoconf-2.13}
15246 autoconf: Undefined macros:
15247 ***BUG in Autoconf--please report*** AC_FD_MSG
15248 ***BUG in Autoconf--please report*** AC_EPI
15249 configure.in:1:AC_DEFUN([AC_PROG_INSTALL],
15250 configure.in:5:AC_PROG_INSTALL
15251 $ @kbd{autoconf-2.50}
15253 @end example
15256 @node New Macros
15257 @subsection New Macros
15259 @cindex undefined macro
15260 @cindex @code{_m4_divert_diversion}
15262 Because Autoconf has been dormant for years, Automake provided
15263 Autoconf-like macros for a while.  Autoconf 2.50 now provides better
15264 versions of these macros, integrated in the @code{AC_} namespace,
15265 instead of @code{AM_}.  But in order to ease the upgrading via
15266 @command{autoupdate}, bindings to such @code{AM_} macros are provided.
15268 Unfortunately Automake did not quote the names of these macros!
15269 Therefore, when @command{m4} finds something like
15270 @samp{AC_DEFUN(AM_TYPE_PTRDIFF_T, @dots{})} in @file{aclocal.m4},
15271 @code{AM_TYPE_PTRDIFF_T} is
15272 expanded, replaced with its Autoconf definition.
15274 Fortunately Autoconf catches pre-@code{AC_INIT} expansions, and will
15275 complain, in its own words:
15277 @example
15278 $ @kbd{cat configure.in}
15279 AC_INIT
15280 AM_TYPE_PTRDIFF_T
15281 $ @kbd{aclocal-1.4}
15282 $ @kbd{autoconf}
15283 ./aclocal.m4:17: error: m4_defn: undefined macro: _m4_divert_diversion
15284 actypes.m4:289: AM_TYPE_PTRDIFF_T is expanded from...
15285 ./aclocal.m4:17: the top level
15287 @end example
15289 Future versions of Automake will simply no longer define most of these
15290 macros, and will properly quote the names of the remaining macros.
15291 But you don't have to wait for it to happen to do the right thing right
15292 now: do not depend upon macros from Automake as it is simply not its job
15293 to provide macros (but the one it requires itself):
15295 @example
15296 $ @kbd{cat configure.in}
15297 AC_INIT
15298 AM_TYPE_PTRDIFF_T
15299 $ @kbd{rm aclocal.m4}
15300 $ @kbd{autoupdate}
15301 autoupdate: `configure.in' is updated
15302 $ @kbd{cat configure.in}
15303 AC_INIT
15304 AC_CHECK_TYPES([ptrdiff_t])
15305 $ @kbd{aclocal-1.4}
15306 $ @kbd{autoconf}
15308 @end example
15311 @node Hosts and Cross-Compilation
15312 @subsection Hosts and Cross-Compilation
15313 @cindex Cross compilation
15315 Based on the experience of compiler writers, and after long public
15316 debates, many aspects of the cross-compilation chain have changed:
15318 @itemize @minus
15319 @item
15320 the relationship between the build, host, and target architecture types,
15322 @item
15323 the command line interface for specifying them to @command{configure},
15325 @item
15326 the variables defined in @command{configure},
15328 @item
15329 the enabling of cross-compilation mode.
15330 @end itemize
15332 @sp 1
15334 The relationship between build, host, and target have been cleaned up:
15335 the chain of default is now simply: target defaults to host, host to
15336 build, and build to the result of @command{config.guess}.  Nevertheless,
15337 in order to ease the transition from 2.13 to 2.50, the following
15338 transition scheme is implemented.  @emph{Do not rely on it}, as it will
15339 be completely disabled in a couple of releases (we cannot keep it, as it
15340 proves to cause more problems than it cures).
15342 They all default to the result of running @command{config.guess}, unless
15343 you specify either @option{--build} or @option{--host}.  In this case,
15344 the default becomes the system type you specified.  If you specify both,
15345 and they're different, @command{configure} will enter cross compilation
15346 mode, so it won't run any tests that require execution.
15348 Hint: if you mean to override the result of @command{config.guess},
15349 prefer @option{--build} over @option{--host}.  In the future,
15350 @option{--host} will not override the name of the build system type.
15351 Whenever you specify @code{--host}, be sure to specify @code{--build}
15352 too.
15354 @sp 1
15356 For backward compatibility, @command{configure} will accept a system
15357 type as an option by itself.  Such an option will override the
15358 defaults for build, host, and target system types.  The following
15359 configure statement will configure a cross toolchain that will run on
15360 Net@acronym{BSD}/alpha but generate code for @acronym{GNU} Hurd/sparc, which is
15361 also the build platform.
15363 @example
15364 ./configure --host=alpha-netbsd sparc-gnu
15365 @end example
15367 @sp 1
15369 In Autoconf 2.13 and before, the variables @code{build}, @code{host},
15370 and @code{target} had a different semantics before and after the
15371 invocation of @code{AC_CANONICAL_BUILD} etc.  Now, the argument of
15372 @option{--build} is strictly copied into @code{build_alias}, and is left
15373 empty otherwise.  After the @code{AC_CANONICAL_BUILD}, @code{build} is
15374 set to the canonicalized build type.  To ease the transition, before,
15375 its contents is the same as that of @code{build_alias}.  Do @emph{not}
15376 rely on this broken feature.
15378 For consistency with the backward compatibility scheme exposed above,
15379 when @option{--host} is specified but @option{--build} isn't, the build
15380 system will be assumed to be the same as @option{--host}, and
15381 @samp{build_alias} will be set to that value.  Eventually, this
15382 historically incorrect behavior will go away.
15384 @sp 1
15386 The former scheme to enable cross-compilation proved to cause more harm
15387 than good, in particular, it used to be triggered too easily, leaving
15388 regular end users puzzled in front of cryptic error messages.
15389 @command{configure} could even enter cross-compilation mode only
15390 because the compiler was not functional.  This is mainly because
15391 @command{configure} used to try to detect cross-compilation, instead of
15392 waiting for an explicit flag from the user.
15394 Now, @command{configure} enters cross-compilation mode if and only if
15395 @option{--host} is passed.
15397 That's the short documentation.  To ease the transition between 2.13 and
15398 its successors, a more complicated scheme is implemented.  @emph{Do not
15399 rely on the following}, as it will be removed in the near future.
15401 If you specify @option{--host}, but not @option{--build}, when
15402 @command{configure} performs the first compiler test it will try to run
15403 an executable produced by the compiler.  If the execution fails, it will
15404 enter cross-compilation mode.  This is fragile.  Moreover, by the time
15405 the compiler test is performed, it may be too late to modify the
15406 build-system type: other tests may have already been performed.
15407 Therefore, whenever you specify @code{--host}, be sure to specify
15408 @code{--build} too.
15410 @example
15411 ./configure --build=i686-pc-linux-gnu --host=m68k-coff
15412 @end example
15414 @noindent
15415 will enter cross-compilation mode.  The former interface, which
15416 consisted in setting the compiler to a cross-compiler without informing
15417 @command{configure} is obsolete.  For instance, @command{configure} will
15418 fail if it can't run the code generated by the specified compiler if you
15419 configure as follows:
15421 @example
15422 ./configure CC=m68k-coff-gcc
15423 @end example
15426 @node AC_LIBOBJ vs LIBOBJS
15427 @subsection @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}
15429 Up to Autoconf 2.13, the replacement of functions was triggered via the
15430 variable @code{LIBOBJS}.  Since Autoconf 2.50, the macro
15431 @code{AC_LIBOBJ} should be used instead (@pxref{Generic Functions}).
15432 Starting at Autoconf 2.53, the use of @code{LIBOBJS} is an error.
15434 This change is mandated by the unification of the @acronym{GNU} Build System
15435 components.  In particular, the various fragile techniques used to parse
15436 a @file{configure.ac} are all replaced with the use of traces.  As a
15437 consequence, any action must be traceable, which obsoletes critical
15438 variable assignments.  Fortunately, @code{LIBOBJS} was the only problem,
15439 and it can even be handled gracefully (read, ``without your having to
15440 change something'').
15442 There were two typical uses of @code{LIBOBJS}: asking for a replacement
15443 function, and adjusting @code{LIBOBJS} for Automake and/or Libtool.
15445 @sp 1
15447 As for function replacement, the fix is immediate: use
15448 @code{AC_LIBOBJ}.  For instance:
15450 @example
15451 LIBOBJS="$LIBOBJS fnmatch.o"
15452 LIBOBJS="$LIBOBJS malloc.$ac_objext"
15453 @end example
15455 @noindent
15456 should be replaced with:
15458 @example
15459 AC_LIBOBJ([fnmatch])
15460 AC_LIBOBJ([malloc])
15461 @end example
15463 @sp 1
15465 @ovindex U
15466 @cindex @code{$U}
15467 When asked for automatic de-ANSI-fication, Automake needs
15468 @code{LIBOBJS}'ed file names to have @samp{$U} appended to the base
15469 names.  Libtool requires the definition of @code{LTLIBOBJS}, whose
15470 suffixes are mapped to @samp{.lo}.  People used to run snippets such as:
15472 @example
15473 # This is necessary so that .o files in LIBOBJS are also built via
15474 # the ANSI2KNR-filtering rules.
15475 LIBOBJS=`echo "$LIBOBJS" | sed 's/\.o /\$U.o /g;s/\.o$/\$U.o/'`
15476 LTLIBOBJS=`echo "$LIBOBJS" | sed 's/\.o/\.lo/g'`
15477 AC_SUBST(LTLIBOBJS)
15478 @end example
15480 @noindent
15481 Note that this code is @emph{wrong}, because @samp{.o} is not the only
15482 possible extension@footnote{
15484 Yet another reason why assigning @code{LIBOBJS} directly is discouraged.
15486 }!  It should have read:
15488 @example
15489 # This is necessary so that .o files in LIBOBJS are also built via
15490 # the ANSI2KNR-filtering rules.
15491 LIB@@&t@@OBJS=`echo "$LIB@@&t@@OBJS" |
15492              sed 's,\.[[^.]]* ,$U&,g;s,\.[[^.]]*$,$U&,'`
15493 LTLIBOBJS=`echo "$LIB@@&t@@OBJS" |
15494            sed 's,\.[[^.]]* ,.lo ,g;s,\.[[^.]]*$,.lo,'`
15495 AC_SUBST(LTLIBOBJS)
15496 @end example
15498 @sp 1
15500 You no longer have to use this: @code{AC_OUTPUT} normalizes
15501 @code{LIBOBJS} and @code{LTLIBOBJS} (hence it works with any version of
15502 Automake and Libtool).  Just remove these lines (@command{autoupdate}
15503 cannot handle this task, since this is not a macro).
15505 Note that @code{U} must not be used in your Makefiles.
15507 @ovindex LIBOBJDIR
15508 When used with Automake 1.10 or newer, a suitable value for
15509 @code{LIBOBJDIR} is set so that the @code{LIBOBJS} and @code{LTLIBOBJS}
15510 can be referenced from any @file{Makefile.am}.  Even without Automake,
15511 arranging for @code{LIBOBJDIR} to be set correctly will enable
15512 referencing @code{LIBOBJS} and @code{LTLIBOBJS} in another directory.
15515 @node AC_FOO_IFELSE vs AC_TRY_FOO
15516 @subsection @code{AC_FOO_IFELSE} vs.@: @code{AC_TRY_FOO}
15518 Since Autoconf 2.50, internal codes uses @code{AC_PREPROC_IFELSE},
15519 @code{AC_COMPILE_IFELSE}, @code{AC_LINK_IFELSE}, and
15520 @code{AC_RUN_IFELSE} on one hand and @code{AC_LANG_SOURCES},
15521 and @code{AC_LANG_PROGRAM} on the other hand instead of the deprecated
15522 @code{AC_TRY_CPP}, @code{AC_TRY_COMPILE}, @code{AC_TRY_LINK}, and
15523 @code{AC_TRY_RUN}.  The motivations where:
15524 @itemize @minus
15525 @item
15526 a more consistent interface: @code{AC_TRY_COMPILE} etc.@: were double
15527 quoting their arguments;
15529 @item
15530 the combinatoric explosion is solved by decomposing on the one hand the
15531 generation of sources, and on the other hand executing the program;
15533 @item
15534 this scheme helps supporting more languages than plain C and C++.
15535 @end itemize
15537 In addition to the change of syntax, the philosphy has changed too:
15538 while emphasis was put on speed at the expense of accuracy, today's
15539 Autoconf promotes accuracy of the testing framework at, ahem..., the
15540 expense of speed.
15543 As a perfect example of what is @emph{not} to be done, here is how to
15544 find out whether a header file contains a particular declaration, such
15545 as a typedef, a structure, a structure member, or a function.  Use
15546 @code{AC_EGREP_HEADER} instead of running @code{grep} directly on the
15547 header file; on some systems the symbol might be defined in another
15548 header file that the file you are checking @samp{#include}s.
15550 As a (bad) example, here is how you should not check for C preprocessor
15551 symbols, either defined by header files or predefined by the C
15552 preprocessor: using @code{AC_EGREP_CPP}:
15554 @example
15555 @group
15556 AC_EGREP_CPP(yes,
15557 [#ifdef _AIX
15558   yes
15559 #endif
15560 ], is_aix=yes, is_aix=no)
15561 @end group
15562 @end example
15564 The above example, properly written would (i) use
15565 @code{AC_LANG_PROGRAM}, and (ii) run the compiler:
15567 @example
15568 @group
15569 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
15570 [[#if !defined _AIX
15571 # error _AIX not defined
15572 #endif
15573 ]])],
15574                    [is_aix=yes],
15575                    [is_aix=no])
15576 @end group
15577 @end example
15580 @c ============================= Generating Test Suites with Autotest
15582 @node Using Autotest
15583 @chapter Generating Test Suites with Autotest
15585 @cindex Autotest
15587 @display
15588 @strong{N.B.: This section describes an experimental feature which will
15589 be part of Autoconf in a forthcoming release.  Although we believe
15590 Autotest is stabilizing, this documentation describes an interface which
15591 might change in the future: do not depend upon Autotest without
15592 subscribing to the Autoconf mailing lists.}
15593 @end display
15595 It is paradoxical that portable projects depend on nonportable tools
15596 to run their test suite.  Autoconf by itself is the paragon of this
15597 problem: although it aims at perfectly portability, up to 2.13, its
15598 test suite was using Deja@acronym{GNU}, a rich and complex testing
15599 framework, but which is far from being standard on Posix systems.
15600 Worse yet, it was likely to be missing on the most fragile platforms,
15601 the very platforms that are most likely to torture Autoconf and
15602 exhibit deficiencies.
15604 To circumvent this problem many package maintainers have developed their
15605 own testing framework, based on simple shell scripts whose sole outputs
15606 are exit status values describing whether the test succeeded.  Most of
15607 these tests share common patterns, and this can result in lots of
15608 duplicated code and tedious maintenance.
15610 Following exactly the same reasoning that yielded to the inception of
15611 Autoconf, Autotest provides a test suite generation frame work, based on
15612 M4 macros, building a portable shell script.  The suite itself is
15613 equipped with automatic logging and tracing facilities which greatly
15614 diminish the interaction with bug reporters, and simple timing reports.
15616 Autoconf itself has been using Autotest for years, and we do attest that
15617 it has considerably improved the strength of the test suite, and the
15618 quality of bug reports.  Other projects are known to use some generation
15619 of Autotest, such as Bison, Free Recode, Free Wdiff, @acronym{GNU} Tar, each of
15620 them with different needs, and this usage has validated Autotest as a general
15621 testing framework.
15623 Nonetheless, compared to Deja@acronym{GNU}, Autotest is inadequate for
15624 interactive tool testing, which is probably its main limitation.
15626 @menu
15627 * Using an Autotest Test Suite::  Autotest and the user
15628 * Writing testsuite.at::        Autotest macros
15629 * testsuite Invocation::        Running @command{testsuite} scripts
15630 * Making testsuite Scripts::    Using autom4te to create @command{testsuite}
15631 @end menu
15633 @node Using an Autotest Test Suite
15634 @section Using an Autotest Test Suite
15636 @menu
15637 * testsuite Scripts::           The concepts of Autotest
15638 * Autotest Logs::               Their contents
15639 @end menu
15641 @node testsuite Scripts
15642 @subsection @command{testsuite} Scripts
15644 @cindex @command{testsuite}
15646 Generating testing or validation suites using Autotest is rather easy.
15647 The whole validation suite is held in a file to be processed through
15648 @command{autom4te}, itself using @acronym{GNU} M4 under the scene, to
15649 produce a stand-alone Bourne shell script which then gets distributed.
15650 Neither @command{autom4te} nor @acronym{GNU} M4 are needed at
15651 the installer end.
15653 @cindex test group
15654 Each test of the validation suite should be part of some test group.  A
15655 @dfn{test group} is a sequence of interwoven tests that ought to be
15656 executed together, usually because one test in the group creates data
15657 files than a later test in the same group needs to read.  Complex test
15658 groups make later debugging more tedious.  It is much better to
15659 keep only a few tests per test group.  Ideally there is only one test
15660 per test group.
15662 For all but the simplest packages, some file such as @file{testsuite.at}
15663 does not fully hold all test sources, as these are often easier to
15664 maintain in separate files.  Each of these separate files holds a single
15665 test group, or a sequence of test groups all addressing some common
15666 functionality in the package.  In such cases, @file{testsuite.at}
15667 merely initializes the validation suite, and sometimes does elementary
15668 health checking, before listing include statements for all other test
15669 files.  The special file @file{package.m4}, containing the
15670 identification of the package, is automatically included if found.
15672 A convenient alternative consists in moving all the global issues
15673 (local Autotest macros, elementary health checking, and @code{AT_INIT}
15674 invocation) into the file @code{local.at}, and making
15675 @file{testsuite.at} be a simple list of @code{m4_include} of sub test
15676 suites.  In such case, generating the whole test suite or pieces of it
15677 is only a matter of choosing the @command{autom4te} command line
15678 arguments.
15680 The validation scripts that Autotest produces are by convention called
15681 @command{testsuite}.  When run, @command{testsuite} executes each test
15682 group in turn, producing only one summary line per test to say if that
15683 particular test succeeded or failed.  At end of all tests, summarizing
15684 counters get printed.  One debugging directory is left for each test
15685 group which failed, if any: such directories are named
15686 @file{testsuite.dir/@var{nn}}, where @var{nn} is the sequence number of
15687 the test group, and they include:
15689 @itemize @bullet
15690 @item a debugging script named @file{run} which reruns the test in
15691 @dfn{debug mode} (@pxref{testsuite Invocation}).  The automatic generation
15692 of debugging scripts has the purpose of easing the chase for bugs.
15694 @item all the files created with @code{AT_DATA}
15696 @item a log of the run, named @file{testsuite.log}
15697 @end itemize
15699 In the ideal situation, none of the tests fail, and consequently, no
15700 debugging directory is left behind for validation.
15702 It often happens in practice that individual tests in the validation
15703 suite need to get information coming out of the configuration process.
15704 Some of this information, common for all validation suites, is provided
15705 through the file @file{atconfig}, automatically created by
15706 @code{AC_CONFIG_TESTDIR}.  For configuration informations which your
15707 testing environment specifically needs, you might prepare an optional
15708 file named @file{atlocal.in}, instantiated by @code{AC_CONFIG_FILES}.
15709 The configuration process produces @file{atconfig} and @file{atlocal}
15710 out of these two input files, and these two produced files are
15711 automatically read by the @file{testsuite} script.
15713 Here is a diagram showing the relationship between files.
15715 @noindent
15716 Files used in preparing a software package for distribution:
15718 @example
15719                 [package.m4] -->.
15720                                  \
15721 subfile-1.at ->.  [local.at] ---->+
15722     ...         \                  \
15723 subfile-i.at ---->-- testsuite.at -->-- autom4te* -->testsuite
15724     ...         /
15725 subfile-n.at ->'
15726 @end example
15728 @noindent
15729 Files used in configuring a software package:
15731 @example
15732                                      .--> atconfig
15733                                     /
15734 [atlocal.in] -->  config.status* --<
15735                                     \
15736                                      `--> [atlocal]
15737 @end example
15739 @noindent
15740 Files created during the test suite execution:
15742 @example
15743 atconfig -->.                    .--> testsuite.log
15744              \                  /
15745               >-- testsuite* --<
15746              /                  \
15747 [atlocal] ->'                    `--> [testsuite.dir]
15748 @end example
15751 @node Autotest Logs
15752 @subsection Autotest Logs
15754 When run, the test suite creates a log file named after itself, e.g., a
15755 test suite named @command{testsuite} creates @file{testsuite.log}.  It
15756 contains a lot of information, usually more than maintainers actually
15757 need, but therefore most of the time it contains all that is needed:
15759 @table @asis
15760 @item command line arguments
15761 @c akim s/to consist in/to consist of/
15762 A very bad Posix habit which is unfortunately widespread consists of
15763 setting environment variables before the command, such as in
15764 @samp{CC=my-home-grown-cc ./testsuite}.  This results in the test suite
15765 not knowing this change, hence (i) it can't report it to you, and (ii)
15766 it cannot preserve the value of @code{CC} for subsequent runs.
15767 Autoconf faced exactly the same problem, and solved it by asking
15768 users to pass the variable definitions as command line arguments.
15769 Autotest requires this rule too, but has no means to enforce it; the log
15770 then contains a trace of the variables the user changed.
15772 @item @file{ChangeLog} excerpts
15773 The topmost lines of all the @file{ChangeLog}s found in the source
15774 hierarchy.  This is especially useful when bugs are reported against
15775 development versions of the package, since the version string does not
15776 provide sufficient information to know the exact state of the sources
15777 the user compiled.  Of course this relies on the use of a
15778 @file{ChangeLog}.
15780 @item build machine
15781 Running a test suite in a cross-compile environment is not an easy task,
15782 since it would mean having the test suite run on a machine @var{build},
15783 while running programs on a machine @var{host}.  It is much simpler to
15784 run both the test suite and the programs on @var{host}, but then, from
15785 the point of view of the test suite, there remains a single environment,
15786 @var{host} = @var{build}.  The log contains relevant information on the
15787 state of the build machine, including some important environment
15788 variables.
15789 @c FIXME: How about having an M4sh macro to say `hey, log the value
15790 @c of `@dots{}'?  This would help both Autoconf and Autotest.
15792 @item tested programs
15793 The absolute file name and answers to @option{--version} of the tested
15794 programs (see @ref{Writing testsuite.at}, @code{AT_TESTED}).
15796 @item configuration log
15797 The contents of @file{config.log}, as created by @command{configure},
15798 are appended.  It contains the configuration flags and a detailed report
15799 on the configuration itself.
15800 @end table
15803 @node Writing testsuite.at
15804 @section Writing @file{testsuite.at}
15806 The @file{testsuite.at} is a Bourne shell script making use of special
15807 Autotest M4 macros.  It often contains a call to @code{AT_INIT} nears
15808 its beginning followed by one call to @code{m4_include} per source file
15809 for tests.  Each such included file, or the remainder of
15810 @file{testsuite.at} if include files are not used, contain a sequence of
15811 test groups.  Each test group begins with one call to @code{AT_SETUP},
15812 it contains an arbitrary number of shell commands or calls to
15813 @code{AT_CHECK}, and it completes with one call to @code{AT_CLEANUP}.
15815 @defmac AT_INIT (@ovar{name})
15816 @atindex{INIT}
15817 @c FIXME: Not clear, plus duplication of the information.
15818 Initialize Autotest.  Giving a @var{name} to the test suite is
15819 encouraged if your package includes several test suites.  In any case,
15820 the test suite always displays the package name and version.  It also
15821 inherits the package bug report address.
15822 @end defmac
15824 @defmac AT_COPYRIGHT (@var{copyright-notice})
15825 @atindex{COPYRIGHT}
15826 @cindex Copyright Notice
15827 State that, in addition to the Free Software Foundation's copyright on
15828 the Autotest macros, parts of your test suite are covered by
15829 @var{copyright-notice}.
15831 The @var{copyright-notice} will show up in both the head of
15832 @command{testsuite} and in @samp{testsuite --version}.
15833 @end defmac
15835 @defmac AT_TESTED (@var{executables})
15836 @atindex{TESTED}
15837 Log the file name and answer to @option{--version} of each program in
15838 space-separated list @var{executables}.  Several invocations register
15839 new executables, in other words, don't fear registering one program
15840 several times.
15841 @end defmac
15843 Autotest test suites rely on @env{PATH} to find the tested program.
15844 This avoids the need to generate absolute names of the various tools, and
15845 makes it possible to test installed programs.  Therefore, knowing which
15846 programs are being exercised is crucial to understanding problems in
15847 the test suite itself, or its occasional misuses.  It is a good idea to
15848 also subscribe foreign programs you depend upon, to avoid incompatible
15849 diagnostics.
15851 @sp 1
15853 @defmac AT_SETUP (@var{test-group-name})
15854 @atindex{SETUP}
15855 This macro starts a group of related tests, all to be executed in the
15856 same subshell.  It accepts a single argument, which holds a few words
15857 (no more than about 30 or 40 characters) quickly describing the purpose
15858 of the test group being started.
15859 @end defmac
15861 @defmac AT_KEYWORDS (@var{keywords})
15862 @atindex{KEYWORDS}
15863 Associate the space-separated list of @var{keywords} to the enclosing
15864 test group.  This makes it possible to run ``slices'' of the test suite.
15865 For instance if some of your test groups exercise some @samp{foo}
15866 feature, then using @samp{AT_KEYWORDS(foo)} lets you run
15867 @samp{./testsuite -k foo} to run exclusively these test groups.  The
15868 @var{title} of the test group is automatically recorded to
15869 @code{AT_KEYWORDS}.
15871 Several invocations within a test group accumulate new keywords.  In
15872 other words, don't fear registering several times the same keyword in a
15873 test group.
15874 @end defmac
15876 @defmac AT_CAPTURE_FILE (@var{file})
15877 @atindex{CAPTURE_FILE}
15878 If the current test group fails, log the contents of @var{file}.
15879 Several identical calls within one test group have no additional effect.
15880 @end defmac
15882 @defmac AT_XFAIL_IF (@var{shell-condition})
15883 @atindex{XFAIL_IF}
15884 Determine whether the test is expected to fail because it is a known
15885 bug (for unsupported features, you should skip the test).
15886 @var{shell-condition} is a shell expression such as a @code{test}
15887 command; you can instantiate this macro many times from within the
15888 same test group, and one of the conditions will be enough to turn
15889 the test into an expected failure.
15890 @end defmac
15892 @defmac AT_CLEANUP
15893 @atindex{CLEANUP}
15894 End the current test group.
15895 @end defmac
15897 @sp 1
15899 @defmac AT_DATA (@var{file}, @var{contents})
15900 @atindex{DATA}
15901 Initialize an input data @var{file} with given @var{contents}.  Of
15902 course, the @var{contents} have to be properly quoted between square
15903 brackets to protect against included commas or spurious M4
15904 expansion.  The contents ought to end with an end of line.
15905 @end defmac
15907 @defmac AT_CHECK (@var{commands}, @dvar{status, @samp{0}}, @dvar{stdout, @samp{}}, @dvar{stderr, @samp{}}, @ovar{run-if-fail}, @ovar{run-if-pass})
15908 @atindex{CHECK}
15909 Execute a test by performing given shell @var{commands}.  These commands
15910 should normally exit with @var{status}, while producing expected
15911 @var{stdout} and @var{stderr} contents.  If @var{commands} exit with
15912 status 77, then the whole test group is skipped.  Otherwise, if this test
15913 fails, run shell commands @var{run-if-fail} or, if this test passes, run shell
15914 commands @var{run-if-pass}.
15916 The @var{commands} @emph{must not} redirect the standard output, nor the
15917 standard error.
15919 If @var{status}, or @var{stdout}, or @var{stderr} is @samp{ignore}, then
15920 the corresponding value is not checked.
15922 The special value @samp{expout} for @var{stdout} means the expected
15923 output of the @var{commands} is the content of the file @file{expout}.
15924 If @var{stdout} is @samp{stdout}, then the standard output of the
15925 @var{commands} is available for further tests in the file @file{stdout}.
15926 Similarly for @var{stderr} with @samp{expout} and @samp{stderr}.
15927 @end defmac
15930 @node testsuite Invocation
15931 @section Running @command{testsuite} Scripts
15932 @cindex @command{testsuite}
15934 Autotest test suites support the following arguments:
15936 @table @option
15937 @item --help
15938 @itemx -h
15939 Display the list of options and exit successfully.
15941 @item --version
15942 @itemx -V
15943 Display the version of the test suite and exit successfully.
15945 @item --clean
15946 @itemx -c
15947 Remove all the files the test suite might have created and exit.  Meant
15948 for @code{clean} Makefile targets.
15950 @item --list
15951 @itemx -l
15952 List all the tests (or only the selection), including their possible
15953 keywords.
15954 @end table
15956 @sp 1
15958 By default all the tests are performed (or described with
15959 @option{--list}) in the default environment first silently, then
15960 verbosely, but the environment, set of tests, and verbosity level can be
15961 tuned:
15963 @table @samp
15964 @item @var{variable}=@var{value}
15965 Set the environment @var{variable} to @var{value}.  Do not run
15966 @samp{FOO=foo ./testsuite} as debugging scripts would then run in a
15967 different environment.
15969 @cindex @code{AUTOTEST_PATH}
15970 The variable @code{AUTOTEST_PATH} specifies the testing path to prepend
15971 to @env{PATH}.  Relative directory names (not starting with
15972 @samp{/}) are considered to be relative to the top level of the
15973 package being built.  All the directories are made absolute, first
15974 starting from the top level @emph{build} tree, then from the
15975 @emph{source} tree.  For instance @samp{./testsuite
15976 AUTOTEST_PATH=tests:bin} for a @file{/src/foo-1.0} source package built
15977 in @file{/tmp/foo} results in @samp{/tmp/foo/tests:/tmp/foo/bin} and
15978 then @samp{/src/foo-1.0/tests:/src/foo-1.0/bin} being prepended to
15979 @env{PATH}.
15981 @item @var{number}
15982 @itemx @var{number}-@var{number}
15983 @itemx @var{number}-
15984 @itemx -@var{number}
15985 Add the corresponding test groups, with obvious semantics, to the
15986 selection.
15988 @item --keywords=@var{keywords}
15989 @itemx -k @var{keywords}
15990 Add to the selection the test groups which title or keywords (arguments
15991 to @code{AT_SETUP} or @code{AT_KEYWORDS}) match @emph{all} the keywords
15992 of the comma separated list @var{keywords}.
15994 Running @samp{./testsuite -k autoupdate,FUNC} will select all the tests
15995 tagged with @samp{autoupdate} @emph{and} @samp{FUNC} (as in
15996 @samp{AC_CHECK_FUNC}, @samp{AC_FUNC_FNMATCH}, etc.)@: while
15997 @samp{./testsuite -k autoupdate -k FUNC} runs all the tests tagged with
15998 @samp{autoupdate} @emph{or} @samp{FUNC}.
16000 @item --errexit
16001 @itemx -e
16002 If any test fails, immediately abort testing.  It implies
16003 @option{--debug}: post test group clean up, debugging script generation,
16004 and logging are inhibited.  This option is meant for the full test
16005 suite, it is not really useful for generated debugging scripts.
16007 @item --verbose
16008 @itemx -v
16009 Force more verbosity in the detailed output of what is being done.  This
16010 is the default for debugging scripts.
16012 @item --debug
16013 @itemx -d
16014 Do not remove the files after a test group was performed ---but they are
16015 still removed @emph{before}, therefore using this option is sane when
16016 running several test groups.  Do not create debugging scripts.  Do not
16017 log (in order to preserve supposedly existing full log file).  This is
16018 the default for debugging scripts, but it can also be useful to debug
16019 the testsuite itself.
16021 @item --trace
16022 @itemx -x
16023 Trigger shell tracing of the test groups.
16024 @end table
16027 @node Making testsuite Scripts
16028 @section Making @command{testsuite} Scripts
16030 For putting Autotest into movement, you need some configuration and
16031 Makefile machinery.  We recommend, at least if your package uses deep or
16032 shallow hierarchies, that you use @file{tests/} as the name of the
16033 directory holding all your tests and their @file{Makefile}.  Here is a
16034 check list of things to do.
16036 @itemize @minus
16038 @item
16039 @cindex @file{package.m4}
16040 Make sure to create the file @file{package.m4}, which defines the
16041 identity of the package.  It must define @code{AT_PACKAGE_STRING}, the
16042 full signature of the package, and @code{AT_PACKAGE_BUGREPORT}, the
16043 address to which bug reports should be sent.  For sake of completeness,
16044 we suggest that you also define @code{AT_PACKAGE_NAME},
16045 @code{AT_PACKAGE_TARNAME}, and @code{AT_PACKAGE_VERSION}.
16046 @xref{Initializing configure}, for a description of these variables.  We
16047 suggest the following Makefile excerpt:
16049 @smallexample
16050 $(srcdir)/package.m4: $(top_srcdir)/configure.ac
16051         @{                                      \
16052           echo '# Signature of the current package.'; \
16053           echo 'm4_define([AT_PACKAGE_NAME],      [@@PACKAGE_NAME@@])'; \
16054           echo 'm4_define([AT_PACKAGE_TARNAME],   [@@PACKAGE_TARNAME@@])'; \
16055           echo 'm4_define([AT_PACKAGE_VERSION],   [@@PACKAGE_VERSION@@])'; \
16056           echo 'm4_define([AT_PACKAGE_STRING],    [@@PACKAGE_STRING@@])'; \
16057           echo 'm4_define([AT_PACKAGE_BUGREPORT], [@@PACKAGE_BUGREPORT@@])'; \
16058         @} >$(srcdir)/package.m4
16059 @end smallexample
16061 @noindent
16062 Be sure to distribute @file{package.m4} and to put it into the source
16063 hierarchy: the test suite ought to be shipped!
16065 @item
16066 Invoke @code{AC_CONFIG_TESTDIR}.
16068 @defmac AC_CONFIG_TESTDIR (@var{directory}, @dvar{test-path, @var{directory}})
16069 @acindex{CONFIG_TESTDIR}
16070 An Autotest test suite is to be configured in @var{directory}.  This
16071 macro requires the instantiation of @file{@var{directory}/atconfig} from
16072 @file{@var{directory}/atconfig.in}, and sets the default
16073 @code{AUTOTEST_PATH} to @var{test-path} (@pxref{testsuite Invocation}).
16074 @end defmac
16076 @item
16077 Still within @file{configure.ac}, as appropriate, ensure that some
16078 @code{AC_CONFIG_FILES} command includes substitution for
16079 @file{tests/atlocal}.
16081 @item
16082 The @file{tests/Makefile.in} should be modified so the validation in
16083 your package is triggered by @samp{make check}.  An example is provided
16084 below.
16085 @end itemize
16087 With Automake, here is a minimal example about how to link @samp{make
16088 check} with a validation suite.
16090 @example
16091 EXTRA_DIST = testsuite.at $(TESTSUITE) atlocal.in
16092 TESTSUITE = $(srcdir)/testsuite
16094 check-local: atconfig atlocal $(TESTSUITE)
16095         $(SHELL) $(TESTSUITE) $(TESTSUITEFLAGS)
16097 installcheck-local: atconfig atlocal $(TESTSUITE)
16098         $(SHELL) $(TESTSUITE) AUTOTEST_PATH="$(bindir)" $(TESTSUITEFLAGS)
16100 AUTOTEST = $(AUTOM4TE) --language=autotest
16101 $(TESTSUITE): $(srcdir)/testsuite.at
16102         $(AUTOTEST) -I $(srcdir) -o $@@.tmp $@@.at
16103         mv $@@.tmp $@@
16104 @end example
16106 You might want to list explicitly the dependencies, i.e., the list of
16107 the files @file{testsuite.at} includes.
16109 With strict Autoconf, you might need to add lines inspired from the
16110 following:
16112 @example
16113 subdir = tests
16115 atconfig: $(top_builddir)/config.status
16116         cd $(top_builddir) && \
16117            $(SHELL) ./config.status $(subdir)/$@@
16119 atlocal: $(srcdir)/atlocal.in $(top_builddir)/config.status
16120         cd $(top_builddir) && \
16121            $(SHELL) ./config.status $(subdir)/$@@
16122 @end example
16124 @noindent
16125 and manage to have @file{atconfig.in} and @code{$(EXTRA_DIST)}
16126 distributed.
16130 @c =============================== Frequent Autoconf Questions, with answers
16132 @node FAQ
16133 @chapter Frequent Autoconf Questions, with answers
16135 Several questions about Autoconf come up occasionally.  Here some of them
16136 are addressed.
16138 @menu
16139 * Distributing::                Distributing @command{configure} scripts
16140 * Why GNU m4::                  Why not use the standard M4?
16141 * Bootstrapping::               Autoconf and @acronym{GNU} M4 require each other?
16142 * Why Not Imake::               Why @acronym{GNU} uses @command{configure} instead of Imake
16143 * Defining Directories::        Passing @code{datadir} to program
16144 * autom4te.cache::              What is it?  Can I remove it?
16145 * Present But Cannot Be Compiled::  Compiler and Preprocessor Disagree
16146 @end menu
16148 @node Distributing
16149 @section Distributing @command{configure} Scripts
16150 @cindex License
16152 @display
16153 What are the restrictions on distributing @command{configure}
16154 scripts that Autoconf generates?  How does that affect my
16155 programs that use them?
16156 @end display
16158 There are no restrictions on how the configuration scripts that Autoconf
16159 produces may be distributed or used.  In Autoconf version 1, they were
16160 covered by the @acronym{GNU} General Public License.  We still encourage
16161 software authors to distribute their work under terms like those of the
16162 GPL, but doing so is not required to use Autoconf.
16164 Of the other files that might be used with @command{configure},
16165 @file{config.h.in} is under whatever copyright you use for your
16166 @file{configure.ac}.  @file{config.sub} and @file{config.guess} have an
16167 exception to the GPL when they are used with an Autoconf-generated
16168 @command{configure} script, which permits you to distribute them under the
16169 same terms as the rest of your package.  @file{install-sh} is from the X
16170 Consortium and is not copyrighted.
16172 @node Why GNU m4
16173 @section Why Require @acronym{GNU} M4?
16175 @display
16176 Why does Autoconf require @acronym{GNU} M4?
16177 @end display
16179 Many M4 implementations have hard-coded limitations on the size and
16180 number of macros that Autoconf exceeds.  They also lack several
16181 builtin macros that it would be difficult to get along without in a
16182 sophisticated application like Autoconf, including:
16184 @example
16185 m4_builtin
16186 m4_indir
16187 m4_bpatsubst
16188 __file__
16189 __line__
16190 @end example
16192 Autoconf requires version 1.4 or above of @acronym{GNU} M4 because it uses
16193 frozen state files.
16195 Since only software maintainers need to use Autoconf, and since @acronym{GNU}
16196 M4 is simple to configure and install, it seems reasonable to require
16197 @acronym{GNU} M4 to be installed also.  Many maintainers of @acronym{GNU} and
16198 other free software already have most of the @acronym{GNU} utilities
16199 installed, since they prefer them.
16201 @node Bootstrapping
16202 @section How Can I Bootstrap?
16203 @cindex Bootstrap
16205 @display
16206 If Autoconf requires @acronym{GNU} M4 and @acronym{GNU} M4 has an Autoconf
16207 @command{configure} script, how do I bootstrap?  It seems like a chicken
16208 and egg problem!
16209 @end display
16211 This is a misunderstanding.  Although @acronym{GNU} M4 does come with a
16212 @command{configure} script produced by Autoconf, Autoconf is not required
16213 in order to run the script and install @acronym{GNU} M4.  Autoconf is only
16214 required if you want to change the M4 @command{configure} script, which few
16215 people have to do (mainly its maintainer).
16217 @node Why Not Imake
16218 @section Why Not Imake?
16219 @cindex Imake
16221 @display
16222 Why not use Imake instead of @command{configure} scripts?
16223 @end display
16225 Several people have written addressing this question, so I include
16226 adaptations of their explanations here.
16228 The following answer is based on one written by Richard Pixley:
16230 @quotation
16231 Autoconf generated scripts frequently work on machines that it has
16232 never been set up to handle before.  That is, it does a good job of
16233 inferring a configuration for a new system.  Imake cannot do this.
16235 Imake uses a common database of host specific data.  For X11, this makes
16236 sense because the distribution is made as a collection of tools, by one
16237 central authority who has control over the database.
16239 @acronym{GNU} tools are not released this way.  Each @acronym{GNU} tool has a
16240 maintainer; these maintainers are scattered across the world.  Using a
16241 common database would be a maintenance nightmare.  Autoconf may appear
16242 to be this kind of database, but in fact it is not.  Instead of listing
16243 host dependencies, it lists program requirements.
16245 If you view the @acronym{GNU} suite as a collection of native tools, then the
16246 problems are similar.  But the @acronym{GNU} development tools can be
16247 configured as cross tools in almost any host+target permutation.  All of
16248 these configurations can be installed concurrently.  They can even be
16249 configured to share host independent files across hosts.  Imake doesn't
16250 address these issues.
16252 Imake templates are a form of standardization.  The @acronym{GNU} coding
16253 standards address the same issues without necessarily imposing the same
16254 restrictions.
16255 @end quotation
16258 Here is some further explanation, written by Per Bothner:
16260 @quotation
16261 One of the advantages of Imake is that it easy to generate large
16262 Makefiles using @code{cpp}'s @samp{#include} and macro mechanisms.
16263 However, @code{cpp} is not programmable: it has limited conditional
16264 facilities, and no looping.  And @code{cpp} cannot inspect its
16265 environment.
16267 All of these problems are solved by using @code{sh} instead of
16268 @code{cpp}.  The shell is fully programmable, has macro substitution,
16269 can execute (or source) other shell scripts, and can inspect its
16270 environment.
16271 @end quotation
16274 Paul Eggert elaborates more:
16276 @quotation
16277 With Autoconf, installers need not assume that Imake itself is already
16278 installed and working well.  This may not seem like much of an advantage
16279 to people who are accustomed to Imake.  But on many hosts Imake is not
16280 installed or the default installation is not working well, and requiring
16281 Imake to install a package hinders the acceptance of that package on
16282 those hosts.  For example, the Imake template and configuration files
16283 might not be installed properly on a host, or the Imake build procedure
16284 might wrongly assume that all source files are in one big directory
16285 tree, or the Imake configuration might assume one compiler whereas the
16286 package or the installer needs to use another, or there might be a
16287 version mismatch between the Imake expected by the package and the Imake
16288 supported by the host.  These problems are much rarer with Autoconf,
16289 where each package comes with its own independent configuration
16290 processor.
16292 Also, Imake often suffers from unexpected interactions between
16293 @command{make} and the installer's C preprocessor.  The fundamental problem
16294 here is that the C preprocessor was designed to preprocess C programs,
16295 not @file{Makefile}s.  This is much less of a problem with Autoconf,
16296 which uses the general-purpose preprocessor M4, and where the
16297 package's author (rather than the installer) does the preprocessing in a
16298 standard way.
16299 @end quotation
16302 Finally, Mark Eichin notes:
16304 @quotation
16305 Imake isn't all that extensible, either.  In order to add new features to
16306 Imake, you need to provide your own project template, and duplicate most
16307 of the features of the existing one.  This means that for a sophisticated
16308 project, using the vendor-provided Imake templates fails to provide any
16309 leverage---since they don't cover anything that your own project needs
16310 (unless it is an X11 program).
16312 On the other side, though:
16314 The one advantage that Imake has over @command{configure}:
16315 @file{Imakefile}s tend to be much shorter (likewise, less redundant)
16316 than @file{Makefile.in}s.  There is a fix to this, however---at least
16317 for the Kerberos V5 tree, we've modified things to call in common
16318 @file{post.in} and @file{pre.in} @file{Makefile} fragments for the
16319 entire tree.  This means that a lot of common things don't have to be
16320 duplicated, even though they normally are in @command{configure} setups.
16321 @end quotation
16324 @node Defining Directories
16325 @section How Do I @code{#define} Installation Directories?
16327 @display
16328 My program needs library files, installed in @code{datadir} and
16329 similar.  If I use
16331 @example
16332 AC_DEFINE_UNQUOTED([DATADIR], [$datadir],
16333                    [Define to the read-only architecture-independent
16334                     data directory.])
16335 @end example
16337 @noindent
16338 I get
16340 @example
16341 #define DATADIR "$@{prefix@}/share"
16342 @end example
16343 @end display
16345 As already explained, this behavior is on purpose, mandated by the
16346 @acronym{GNU} Coding Standards, see @ref{Installation Directory
16347 Variables}.  There are several means to achieve a similar goal:
16349 @itemize @minus
16350 @item
16351 Do not use @code{AC_DEFINE} but use your @file{Makefile} to pass the
16352 actual value of @code{datadir} via compilation flags, see
16353 @ref{Installation Directory Variables}, for the details.
16355 @item
16356 This solution can be simplified when compiling a program: you may either
16357 extend the @code{CPPFLAGS}:
16359 @example
16360 CPPFLAGS = -DDATADIR=\"$(datadir)\" @@CPPFLAGS@@
16361 @end example
16363 @noindent
16364 or create a dedicated header file:
16366 @example
16367 DISTCLEANFILES = datadir.h
16368 datadir.h: Makefile
16369         echo '#define DATADIR "$(datadir)"' >$@@
16370 @end example
16372 @item
16373 Use @code{AC_DEFINE} but have @command{configure} compute the literal
16374 value of @code{datadir} and others.  Many people have wrapped macros to
16375 automate this task.  For instance, the macro @code{AC_DEFINE_DIR} from
16376 the @uref{http://www.gnu.org/software/ac-archive/, @acronym{GNU} Autoconf Macro
16377 Archive}.
16379 This solution does not conform to the @acronym{GNU} Coding Standards.
16381 @item
16382 Note that all the previous solutions hard wire the absolute name of
16383 these directories in the executables, which is not a good property.  You
16384 may try to compute the names relative to @code{prefix}, and try to
16385 find @code{prefix} at runtime, this way your package is relocatable.
16386 Some macros are already available to address this issue: see
16387 @code{adl_COMPUTE_RELATIVE_PATHS} and
16388 @code{adl_COMPUTE_STANDARD_RELATIVE_PATHS} on the
16389 @uref{http://www.gnu.org/software/ac-archive/,
16390 @acronym{GNU} Autoconf Macro Archive}.
16391 @end itemize
16394 @node autom4te.cache
16395 @section What is @file{autom4te.cache}?
16397 @display
16398 What is this directory @file{autom4te.cache}?  Can I safely remove it?
16399 @end display
16401 In the @acronym{GNU} Build System, @file{configure.ac} plays a central
16402 role and is read by many tools: @command{autoconf} to create
16403 @file{configure}, @command{autoheader} to create @file{config.h.in},
16404 @command{automake} to create @file{Makefile.in}, @command{autoscan} to
16405 check the completeness of @file{configure.ac}, @command{autoreconf} to
16406 check the @acronym{GNU} Build System components that are used.  To
16407 ``read @file{configure.ac}'' actually means to compile it with M4,
16408 which can be a very long process for complex @file{configure.ac}.
16410 This is why all these tools, instead of running directly M4, invoke
16411 @command{autom4te} (@pxref{autom4te Invocation}) which, while answering to
16412 a specific demand, stores additional information in
16413 @file{autom4te.cache} for future runs.  For instance, if you run
16414 @command{autoconf}, behind the scenes, @command{autom4te} will also
16415 store information for the other tools, so that when you invoke
16416 @command{autoheader} or @command{automake} etc., re-processing
16417 @file{configure.ac} is not needed.  The speed up is frequently of 30%,
16418 and is increasing with the size of @file{configure.ac}.
16420 But it is and remains being simply a cache: you can safely remove it.
16422 @sp 1
16424 @display
16425 Can I permanently get rid of it?
16426 @end display
16428 The creation of this cache can be disabled from
16429 @file{~/.autom4te.cfg}, see @ref{Customizing autom4te}, for more
16430 details.  You should be aware that disabling the cache slows down the
16431 Autoconf test suite by 40%.  The more @acronym{GNU} Build System
16432 components are used, the more the cache is useful; for instance
16433 running @samp{autoreconf -f} on the Coreutils is twice slower without
16434 the cache @emph{although @option{--force} implies that the cache is
16435 not fully exploited}, and eight times slower than without
16436 @option{--force}.
16439 @node Present But Cannot Be Compiled
16440 @section Header Present But Cannot Be Compiled
16442 The most important guideline to bear in mind when checking for
16443 features is to mimic as much as possible the intended use.
16444 Unfortunately, old versions of @code{AC_CHECK_HEADER} and
16445 @code{AC_CHECK_HEADERS} failed to follow this idea, and called
16446 the preprocessor, instead of the compiler, to check for headers.  As a
16447 result, incompatibilities between headers went unnoticed during
16448 configuration, and maintainers finally had to deal with this issue
16449 elsewhere.
16451 As of Autoconf 2.56 both checks are performed, and @code{configure}
16452 complains loudly if the compiler and the preprocessor do not agree.
16453 For the time being the result used is that of the preprocessor, to give
16454 maintainers time to adjust their @file{configure.ac}, but in the near
16455 future, only the compiler will be considered.
16457 Consider the following example:
16459 @example
16460 $ @kbd{cat number.h}
16461 typedef int number;
16462 $ @kbd{cat pi.h}
16463 const number pi = 3;
16464 $ @kbd{cat configure.ac}
16465 AC_INIT
16466 AC_CHECK_HEADERS(pi.h)
16467 $ @kbd{autoconf -Wall}
16468 $ @kbd{./configure}
16469 checking for gcc... gcc
16470 checking for C compiler default output... a.out
16471 checking whether the C compiler works... yes
16472 checking whether we are cross compiling... no
16473 checking for suffix of executables...
16474 checking for suffix of object files... o
16475 checking whether we are using the GNU C compiler... yes
16476 checking whether gcc accepts -g... yes
16477 checking for gcc option to accept ANSI C... none needed
16478 checking how to run the C preprocessor... gcc -E
16479 checking for egrep... grep -E
16480 checking for ANSI C header files... yes
16481 checking for sys/types.h... yes
16482 checking for sys/stat.h... yes
16483 checking for stdlib.h... yes
16484 checking for string.h... yes
16485 checking for memory.h... yes
16486 checking for strings.h... yes
16487 checking for inttypes.h... yes
16488 checking for stdint.h... yes
16489 checking for unistd.h... yes
16490 checking pi.h usability... no
16491 checking pi.h presence... yes
16492 configure: WARNING: pi.h: present but cannot be compiled
16493 configure: WARNING: pi.h: check for missing prerequisite headers?
16494 configure: WARNING: pi.h: proceeding with the preprocessor's result
16495 configure: WARNING:     ## ------------------------------------ ##
16496 configure: WARNING:     ## Report this to bug-autoconf@@gnu.org. ##
16497 configure: WARNING:     ## ------------------------------------ ##
16498 checking for pi.h... yes
16499 @end example
16501 @noindent
16502 The proper way the handle this case is using the fourth argument
16503 (@pxref{Generic Headers}):
16505 @example
16506 $ @kbd{cat configure.ac}
16507 AC_INIT
16508 AC_CHECK_HEADERS(number.h pi.h,,,
16509 [[#if HAVE_NUMBER_H
16510 # include <number.h>
16511 #endif
16513 $ @kbd{autoconf -Wall}
16514 $ @kbd{./configure}
16515 checking for gcc... gcc
16516 checking for C compiler default output... a.out
16517 checking whether the C compiler works... yes
16518 checking whether we are cross compiling... no
16519 checking for suffix of executables...
16520 checking for suffix of object files... o
16521 checking whether we are using the GNU C compiler... yes
16522 checking whether gcc accepts -g... yes
16523 checking for gcc option to accept ANSI C... none needed
16524 checking for number.h... yes
16525 checking for pi.h... yes
16526 @end example
16528 See @ref{Particular Headers}, for a list of headers with their
16529 prerequisite.
16531 @c ===================================================== History of Autoconf.
16533 @node History
16534 @chapter History of Autoconf
16535 @cindex History of autoconf
16537 You may be wondering, Why was Autoconf originally written?  How did it
16538 get into its present form?  (Why does it look like gorilla spit?)  If
16539 you're not wondering, then this chapter contains no information useful
16540 to you, and you might as well skip it.  If you @emph{are} wondering,
16541 then let there be light@enddots{}
16543 @menu
16544 * Genesis::                     Prehistory and naming of @command{configure}
16545 * Exodus::                      The plagues of M4 and Perl
16546 * Leviticus::                   The priestly code of portability arrives
16547 * Numbers::                     Growth and contributors
16548 * Deuteronomy::                 Approaching the promises of easy configuration
16549 @end menu
16551 @node Genesis
16552 @section Genesis
16554 In June 1991 I was maintaining many of the @acronym{GNU} utilities for the
16555 Free Software Foundation.  As they were ported to more platforms and
16556 more programs were added, the number of @option{-D} options that users
16557 had to select in the @file{Makefile} (around 20) became burdensome.
16558 Especially for me---I had to test each new release on a bunch of
16559 different systems.  So I wrote a little shell script to guess some of
16560 the correct settings for the fileutils package, and released it as part
16561 of fileutils 2.0.  That @command{configure} script worked well enough that
16562 the next month I adapted it (by hand) to create similar @command{configure}
16563 scripts for several other @acronym{GNU} utilities packages.  Brian Berliner
16564 also adapted one of my scripts for his @acronym{CVS} revision control system.
16566 Later that summer, I learned that Richard Stallman and Richard Pixley
16567 were developing similar scripts to use in the @acronym{GNU} compiler tools;
16568 so I adapted my @command{configure} scripts to support their evolving
16569 interface: using the file name @file{Makefile.in} as the templates;
16570 adding @samp{+srcdir}, the first option (of many); and creating
16571 @file{config.status} files.
16573 @node Exodus
16574 @section Exodus
16576 As I got feedback from users, I incorporated many improvements, using
16577 Emacs to search and replace, cut and paste, similar changes in each of
16578 the scripts.  As I adapted more @acronym{GNU} utilities packages to use
16579 @command{configure} scripts, updating them all by hand became impractical.
16580 Rich Murphey, the maintainer of the @acronym{GNU} graphics utilities, sent me
16581 mail saying that the @command{configure} scripts were great, and asking if
16582 I had a tool for generating them that I could send him.  No, I thought,
16583 but I should!  So I started to work out how to generate them.  And the
16584 journey from the slavery of hand-written @command{configure} scripts to the
16585 abundance and ease of Autoconf began.
16587 Cygnus @command{configure}, which was being developed at around that time,
16588 is table driven; it is meant to deal mainly with a discrete number of
16589 system types with a small number of mainly unguessable features (such as
16590 details of the object file format).  The automatic configuration system
16591 that Brian Fox had developed for Bash takes a similar approach.  For
16592 general use, it seems to me a hopeless cause to try to maintain an
16593 up-to-date database of which features each variant of each operating
16594 system has.  It's easier and more reliable to check for most features on
16595 the fly---especially on hybrid systems that people have hacked on
16596 locally or that have patches from vendors installed.
16598 I considered using an architecture similar to that of Cygnus
16599 @command{configure}, where there is a single @command{configure} script that
16600 reads pieces of @file{configure.in} when run.  But I didn't want to have
16601 to distribute all of the feature tests with every package, so I settled
16602 on having a different @command{configure} made from each
16603 @file{configure.in} by a preprocessor.  That approach also offered more
16604 control and flexibility.
16606 I looked briefly into using the Metaconfig package, by Larry Wall,
16607 Harlan Stenn, and Raphael Manfredi, but I decided not to for several
16608 reasons.  The @command{Configure} scripts it produces are interactive,
16609 which I find quite inconvenient; I didn't like the ways it checked for
16610 some features (such as library functions); I didn't know that it was
16611 still being maintained, and the @command{Configure} scripts I had
16612 seen didn't work on many modern systems (such as System V R4 and NeXT);
16613 it wasn't very flexible in what it could do in response to a feature's
16614 presence or absence; I found it confusing to learn; and it was too big
16615 and complex for my needs (I didn't realize then how much Autoconf would
16616 eventually have to grow).
16618 I considered using Perl to generate my style of @command{configure}
16619 scripts, but decided that M4 was better suited to the job of simple
16620 textual substitutions: it gets in the way less, because output is
16621 implicit.  Plus, everyone already has it.  (Initially I didn't rely on
16622 the @acronym{GNU} extensions to M4.)  Also, some of my friends at the
16623 University of Maryland had recently been putting M4 front ends on
16624 several programs, including @code{tvtwm}, and I was interested in trying
16625 out a new language.
16627 @node Leviticus
16628 @section Leviticus
16630 Since my @command{configure} scripts determine the system's capabilities
16631 automatically, with no interactive user intervention, I decided to call
16632 the program that generates them Autoconfig.  But with a version number
16633 tacked on, that name would be too long for old Unix file systems,
16634 so I shortened it to Autoconf.
16636 In the fall of 1991 I called together a group of fellow questers after
16637 the Holy Grail of portability (er, that is, alpha testers) to give me
16638 feedback as I encapsulated pieces of my handwritten scripts in M4 macros
16639 and continued to add features and improve the techniques used in the
16640 checks.  Prominent among the testers were Fran@,cois Pinard, who came up
16641 with the idea of making an Autoconf shell script to run M4
16642 and check for unresolved macro calls; Richard Pixley, who suggested
16643 running the compiler instead of searching the file system to find
16644 include files and symbols, for more accurate results; Karl Berry, who
16645 got Autoconf to configure @TeX{} and added the macro index to the
16646 documentation; and Ian Lance Taylor, who added support for creating a C
16647 header file as an alternative to putting @option{-D} options in a
16648 @file{Makefile}, so he could use Autoconf for his @acronym{UUCP} package.
16649 The alpha testers cheerfully adjusted their files again and again as the
16650 names and calling conventions of the Autoconf macros changed from
16651 release to release.  They all contributed many specific checks, great
16652 ideas, and bug fixes.
16654 @node Numbers
16655 @section Numbers
16657 In July 1992, after months of alpha testing, I released Autoconf 1.0,
16658 and converted many @acronym{GNU} packages to use it.  I was surprised by how
16659 positive the reaction to it was.  More people started using it than I
16660 could keep track of, including people working on software that wasn't
16661 part of the @acronym{GNU} Project (such as TCL, FSP, and Kerberos V5).
16662 Autoconf continued to improve rapidly, as many people using the
16663 @command{configure} scripts reported problems they encountered.
16665 Autoconf turned out to be a good torture test for M4 implementations.
16666 Unix M4 started to dump core because of the length of the
16667 macros that Autoconf defined, and several bugs showed up in @acronym{GNU}
16668 M4 as well.  Eventually, we realized that we needed to use some
16669 features that only @acronym{GNU} M4 has.  4.3@acronym{BSD} M4, in
16670 particular, has an impoverished set of builtin macros; the System V
16671 version is better, but still doesn't provide everything we need.
16673 More development occurred as people put Autoconf under more stresses
16674 (and to uses I hadn't anticipated).  Karl Berry added checks for X11.
16675 david zuhn contributed C++ support.  Fran@,cois Pinard made it diagnose
16676 invalid arguments.  Jim Blandy bravely coerced it into configuring
16677 @acronym{GNU} Emacs, laying the groundwork for several later improvements.
16678 Roland McGrath got it to configure the @acronym{GNU} C Library, wrote the
16679 @command{autoheader} script to automate the creation of C header file
16680 templates, and added a @option{--verbose} option to @command{configure}.
16681 Noah Friedman added the @option{--autoconf-dir} option and
16682 @code{AC_MACRODIR} environment variable.  (He also coined the term
16683 @dfn{autoconfiscate} to mean ``adapt a software package to use
16684 Autoconf''.)  Roland and Noah improved the quoting protection in
16685 @code{AC_DEFINE} and fixed many bugs, especially when I got sick of
16686 dealing with portability problems from February through June, 1993.
16688 @node Deuteronomy
16689 @section Deuteronomy
16691 A long wish list for major features had accumulated, and the effect of
16692 several years of patching by various people had left some residual
16693 cruft.  In April 1994, while working for Cygnus Support, I began a major
16694 revision of Autoconf.  I added most of the features of the Cygnus
16695 @command{configure} that Autoconf had lacked, largely by adapting the
16696 relevant parts of Cygnus @command{configure} with the help of david zuhn
16697 and Ken Raeburn.  These features include support for using
16698 @file{config.sub}, @file{config.guess}, @option{--host}, and
16699 @option{--target}; making links to files; and running @command{configure}
16700 scripts in subdirectories.  Adding these features enabled Ken to convert
16701 @acronym{GNU} @code{as}, and Rob Savoye to convert Deja@acronym{GNU}, to using
16702 Autoconf.
16704 I added more features in response to other peoples' requests.  Many
16705 people had asked for @command{configure} scripts to share the results of
16706 the checks between runs, because (particularly when configuring a large
16707 source tree, like Cygnus does) they were frustratingly slow.  Mike
16708 Haertel suggested adding site-specific initialization scripts.  People
16709 distributing software that had to unpack on MS-DOS asked for a way to
16710 override the @file{.in} extension on the file names, which produced file
16711 names like @file{config.h.in} containing two dots.  Jim Avera did an
16712 extensive examination of the problems with quoting in @code{AC_DEFINE}
16713 and @code{AC_SUBST}; his insights led to significant improvements.
16714 Richard Stallman asked that compiler output be sent to @file{config.log}
16715 instead of @file{/dev/null}, to help people debug the Emacs
16716 @command{configure} script.
16718 I made some other changes because of my dissatisfaction with the quality
16719 of the program.  I made the messages showing results of the checks less
16720 ambiguous, always printing a result.  I regularized the names of the
16721 macros and cleaned up coding style inconsistencies.  I added some
16722 auxiliary utilities that I had developed to help convert source code
16723 packages to use Autoconf.  With the help of Fran@,cois Pinard, I made
16724 the macros not interrupt each others' messages.  (That feature revealed
16725 some performance bottlenecks in @acronym{GNU} M4, which he hastily
16726 corrected!)  I reorganized the documentation around problems people want
16727 to solve.  And I began a test suite, because experience had shown that
16728 Autoconf has a pronounced tendency to regress when we change it.
16730 Again, several alpha testers gave invaluable feedback, especially
16731 Fran@,cois Pinard, Jim Meyering, Karl Berry, Rob Savoye, Ken Raeburn,
16732 and Mark Eichin.
16734 Finally, version 2.0 was ready.  And there was much rejoicing.  (And I
16735 have free time again.  I think.  Yeah, right.)
16738 @c ========================================================== Appendices
16740 @node Copying This Manual
16741 @appendix Copying This Manual
16742 @cindex License
16744 @menu
16745 * GNU Free Documentation License::  License for copying this manual
16746 @end menu
16748 @include fdl.texi
16750 @node Indices
16751 @appendix Indices
16753 @menu
16754 * Environment Variable Index::  Index of environment variables used
16755 * Output Variable Index::       Index of variables set in output files
16756 * Preprocessor Symbol Index::   Index of C preprocessor symbols defined
16757 * Autoconf Macro Index::        Index of Autoconf macros
16758 * M4 Macro Index::              Index of M4, M4sugar, and M4sh macros
16759 * Autotest Macro Index::        Index of Autotest macros
16760 * Program & Function Index::    Index of those with portability problems
16761 * Concept Index::               General index
16762 @end menu
16764 @node Environment Variable Index
16765 @appendixsec Environment Variable Index
16767 This is an alphabetical list of the environment variables that Autoconf
16768 checks.
16770 @printindex ev
16772 @node Output Variable Index
16773 @appendixsec Output Variable Index
16775 This is an alphabetical list of the variables that Autoconf can
16776 substitute into files that it creates, typically one or more
16777 @file{Makefile}s.  @xref{Setting Output Variables}, for more information
16778 on how this is done.
16780 @printindex ov
16782 @node Preprocessor Symbol Index
16783 @appendixsec Preprocessor Symbol Index
16785 This is an alphabetical list of the C preprocessor symbols that the
16786 Autoconf macros define.  To work with Autoconf, C source code needs to
16787 use these names in @code{#if} directives.
16789 @printindex cv
16791 @node Autoconf Macro Index
16792 @appendixsec Autoconf Macro Index
16794 This is an alphabetical list of the Autoconf macros.
16795 @ifset shortindexflag
16796 To make the list easier to use, the macros are listed without their
16797 preceding @samp{AC_}.
16798 @end ifset
16800 @printindex AC
16802 @node M4 Macro Index
16803 @appendixsec M4 Macro Index
16805 This is an alphabetical list of the M4, M4sugar, and M4sh macros.
16806 @ifset shortindexflag
16807 To make the list easier to use, the macros are listed without their
16808 preceding @samp{m4_} or @samp{AS_}.
16809 @end ifset
16811 @printindex MS
16813 @node Autotest Macro Index
16814 @appendixsec Autotest Macro Index
16816 This is an alphabetical list of the Autotest macros.
16817 @ifset shortindexflag
16818 To make the list easier to use, the macros are listed without their
16819 preceding @samp{AT_}.
16820 @end ifset
16822 @printindex AT
16824 @node Program & Function Index
16825 @appendixsec Program and Function Index
16827 This is an alphabetical list of the programs and functions which
16828 portability is discussed in this document.
16830 @printindex pr
16832 @node Concept Index
16833 @appendixsec Concept Index
16835 This is an alphabetical list of the files, tools, and concepts
16836 introduced in this document.
16838 @printindex cp
16840 @bye
16842 @c Local Variables:
16843 @c fill-column: 72
16844 @c ispell-local-dictionary: "american"
16845 @c End: